aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlan Elias <ilane@ti.com>2012-01-18 06:16:12 -0500
committerJohn W. Linville <linville@tuxdriver.com>2012-01-24 14:32:28 -0500
commit8939e47fc953cce6ef53e79e9ff9b53319d1a72d (patch)
treefba0ffe539b4d6937bfb2bd9986fe989917b8039
parent6d810f10325522cfcf498dc6d64b9f96e1f5153f (diff)
NFC: Clearly separate NCI states from flags
Make a clear separation between NCI states and flags. This is required in order to support more NCI states (e.g. for multiple targets support). Signed-off-by: Ilan Elias <ilane@ti.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--include/net/nfc/nci_core.h14
-rw-r--r--net/nfc/nci/core.c11
-rw-r--r--net/nfc/nci/ntf.c5
-rw-r--r--net/nfc/nci/rsp.c8
4 files changed, 22 insertions, 16 deletions
diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h
index 9154663b606b..b9c3f8de13dd 100644
--- a/include/net/nfc/nci_core.h
+++ b/include/net/nfc/nci_core.h
@@ -34,16 +34,21 @@
34#include <net/nfc/nfc.h> 34#include <net/nfc/nfc.h>
35#include <net/nfc/nci.h> 35#include <net/nfc/nci.h>
36 36
37/* NCI device state */ 37/* NCI device flags */
38enum { 38enum nci_flag {
39 NCI_INIT, 39 NCI_INIT,
40 NCI_UP, 40 NCI_UP,
41 NCI_DISCOVERY,
42 NCI_POLL_ACTIVE,
43 NCI_DATA_EXCHANGE, 41 NCI_DATA_EXCHANGE,
44 NCI_DATA_EXCHANGE_TO, 42 NCI_DATA_EXCHANGE_TO,
45}; 43};
46 44
45/* NCI device states */
46enum nci_state {
47 NCI_IDLE,
48 NCI_DISCOVERY,
49 NCI_POLL_ACTIVE,
50};
51
47/* NCI timeouts */ 52/* NCI timeouts */
48#define NCI_RESET_TIMEOUT 5000 53#define NCI_RESET_TIMEOUT 5000
49#define NCI_INIT_TIMEOUT 5000 54#define NCI_INIT_TIMEOUT 5000
@@ -70,6 +75,7 @@ struct nci_dev {
70 int tx_headroom; 75 int tx_headroom;
71 int tx_tailroom; 76 int tx_tailroom;
72 77
78 atomic_t state;
73 unsigned long flags; 79 unsigned long flags;
74 80
75 atomic_t cmd_cnt; 81 atomic_t cmd_cnt;
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 815d28a0ed9d..629b76845973 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -264,6 +264,7 @@ static int nci_open_device(struct nci_dev *ndev)
264 264
265 if (!rc) { 265 if (!rc) {
266 set_bit(NCI_UP, &ndev->flags); 266 set_bit(NCI_UP, &ndev->flags);
267 atomic_set(&ndev->state, NCI_IDLE);
267 } else { 268 } else {
268 /* Init failed, cleanup */ 269 /* Init failed, cleanup */
269 skb_queue_purge(&ndev->cmd_q); 270 skb_queue_purge(&ndev->cmd_q);
@@ -360,7 +361,7 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols)
360 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); 361 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
361 int rc; 362 int rc;
362 363
363 if (test_bit(NCI_DISCOVERY, &ndev->flags)) { 364 if (atomic_read(&ndev->state) == NCI_DISCOVERY) {
364 pr_err("unable to start poll, since poll is already active\n"); 365 pr_err("unable to start poll, since poll is already active\n");
365 return -EBUSY; 366 return -EBUSY;
366 } 367 }
@@ -370,7 +371,7 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols)
370 return -EBUSY; 371 return -EBUSY;
371 } 372 }
372 373
373 if (test_bit(NCI_POLL_ACTIVE, &ndev->flags)) { 374 if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) {
374 pr_debug("target is active, implicitly deactivate...\n"); 375 pr_debug("target is active, implicitly deactivate...\n");
375 376
376 rc = nci_request(ndev, nci_rf_deactivate_req, 0, 377 rc = nci_request(ndev, nci_rf_deactivate_req, 0,
@@ -392,7 +393,7 @@ static void nci_stop_poll(struct nfc_dev *nfc_dev)
392{ 393{
393 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); 394 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
394 395
395 if (!test_bit(NCI_DISCOVERY, &ndev->flags)) { 396 if (atomic_read(&ndev->state) != NCI_DISCOVERY) {
396 pr_err("unable to stop poll, since poll is not active\n"); 397 pr_err("unable to stop poll, since poll is not active\n");
397 return; 398 return;
398 } 399 }
@@ -408,7 +409,7 @@ static int nci_activate_target(struct nfc_dev *nfc_dev, __u32 target_idx,
408 409
409 pr_debug("target_idx %d, protocol 0x%x\n", target_idx, protocol); 410 pr_debug("target_idx %d, protocol 0x%x\n", target_idx, protocol);
410 411
411 if (!test_bit(NCI_POLL_ACTIVE, &ndev->flags)) { 412 if (atomic_read(&ndev->state) != NCI_POLL_ACTIVE) {
412 pr_err("there is no available target to activate\n"); 413 pr_err("there is no available target to activate\n");
413 return -EINVAL; 414 return -EINVAL;
414 } 415 }
@@ -443,7 +444,7 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev, __u32 target_idx)
443 444
444 ndev->target_active_prot = 0; 445 ndev->target_active_prot = 0;
445 446
446 if (test_bit(NCI_POLL_ACTIVE, &ndev->flags)) { 447 if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) {
447 nci_request(ndev, nci_rf_deactivate_req, 0, 448 nci_request(ndev, nci_rf_deactivate_req, 0,
448 msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); 449 msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
449 } 450 }
diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c
index a88be91e973f..8ec39464cea5 100644
--- a/net/nfc/nci/ntf.c
+++ b/net/nfc/nci/ntf.c
@@ -261,8 +261,7 @@ static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
261 __u8 *data = skb->data; 261 __u8 *data = skb->data;
262 int err = 0; 262 int err = 0;
263 263
264 clear_bit(NCI_DISCOVERY, &ndev->flags); 264 atomic_set(&ndev->state, NCI_POLL_ACTIVE);
265 set_bit(NCI_POLL_ACTIVE, &ndev->flags);
266 265
267 ntf.rf_discovery_id = *data++; 266 ntf.rf_discovery_id = *data++;
268 ntf.rf_interface = *data++; 267 ntf.rf_interface = *data++;
@@ -350,7 +349,7 @@ static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,
350 349
351 pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason); 350 pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason);
352 351
353 clear_bit(NCI_POLL_ACTIVE, &ndev->flags); 352 atomic_set(&ndev->state, NCI_IDLE);
354 ndev->target_active_prot = 0; 353 ndev->target_active_prot = 0;
355 354
356 /* drop tx data queue */ 355 /* drop tx data queue */
diff --git a/net/nfc/nci/rsp.c b/net/nfc/nci/rsp.c
index 3c73e92eb625..cb8bce6899cf 100644
--- a/net/nfc/nci/rsp.c
+++ b/net/nfc/nci/rsp.c
@@ -137,7 +137,7 @@ static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
137 pr_debug("status 0x%x\n", status); 137 pr_debug("status 0x%x\n", status);
138 138
139 if (status == NCI_STATUS_OK) 139 if (status == NCI_STATUS_OK)
140 set_bit(NCI_DISCOVERY, &ndev->flags); 140 atomic_set(&ndev->state, NCI_DISCOVERY);
141 141
142 nci_req_complete(ndev, status); 142 nci_req_complete(ndev, status);
143} 143}
@@ -149,12 +149,12 @@ static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev,
149 149
150 pr_debug("status 0x%x\n", status); 150 pr_debug("status 0x%x\n", status);
151 151
152 clear_bit(NCI_DISCOVERY, &ndev->flags);
153
154 /* If target was active, complete the request only in deactivate_ntf */ 152 /* If target was active, complete the request only in deactivate_ntf */
155 if ((status != NCI_STATUS_OK) || 153 if ((status != NCI_STATUS_OK) ||
156 (!test_bit(NCI_POLL_ACTIVE, &ndev->flags))) 154 (atomic_read(&ndev->state) != NCI_POLL_ACTIVE)) {
155 atomic_set(&ndev->state, NCI_IDLE);
157 nci_req_complete(ndev, status); 156 nci_req_complete(ndev, status);
157 }
158} 158}
159 159
160void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb) 160void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)