Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ilan Elias and committed by
John W. Linville
8939e47f 6d810f10

+22 -16
+10 -4
include/net/nfc/nci_core.h
··· 34 34 #include <net/nfc/nfc.h> 35 35 #include <net/nfc/nci.h> 36 36 37 - /* NCI device state */ 38 - enum { 37 + /* NCI device flags */ 38 + enum nci_flag { 39 39 NCI_INIT, 40 40 NCI_UP, 41 - NCI_DISCOVERY, 42 - NCI_POLL_ACTIVE, 43 41 NCI_DATA_EXCHANGE, 44 42 NCI_DATA_EXCHANGE_TO, 43 + }; 44 + 45 + /* NCI device states */ 46 + enum nci_state { 47 + NCI_IDLE, 48 + NCI_DISCOVERY, 49 + NCI_POLL_ACTIVE, 45 50 }; 46 51 47 52 /* NCI timeouts */ ··· 75 70 int tx_headroom; 76 71 int tx_tailroom; 77 72 73 + atomic_t state; 78 74 unsigned long flags; 79 75 80 76 atomic_t cmd_cnt;
+6 -5
net/nfc/nci/core.c
··· 264 264 265 265 if (!rc) { 266 266 set_bit(NCI_UP, &ndev->flags); 267 + atomic_set(&ndev->state, NCI_IDLE); 267 268 } else { 268 269 /* Init failed, cleanup */ 269 270 skb_queue_purge(&ndev->cmd_q); ··· 361 360 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); 362 361 int rc; 363 362 364 - if (test_bit(NCI_DISCOVERY, &ndev->flags)) { 363 + if (atomic_read(&ndev->state) == NCI_DISCOVERY) { 365 364 pr_err("unable to start poll, since poll is already active\n"); 366 365 return -EBUSY; 367 366 } ··· 371 370 return -EBUSY; 372 371 } 373 372 374 - if (test_bit(NCI_POLL_ACTIVE, &ndev->flags)) { 373 + if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) { 375 374 pr_debug("target is active, implicitly deactivate...\n"); 376 375 377 376 rc = nci_request(ndev, nci_rf_deactivate_req, 0, ··· 393 392 { 394 393 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); 395 394 396 - if (!test_bit(NCI_DISCOVERY, &ndev->flags)) { 395 + if (atomic_read(&ndev->state) != NCI_DISCOVERY) { 397 396 pr_err("unable to stop poll, since poll is not active\n"); 398 397 return; 399 398 } ··· 409 408 410 409 pr_debug("target_idx %d, protocol 0x%x\n", target_idx, protocol); 411 410 412 - if (!test_bit(NCI_POLL_ACTIVE, &ndev->flags)) { 411 + if (atomic_read(&ndev->state) != NCI_POLL_ACTIVE) { 413 412 pr_err("there is no available target to activate\n"); 414 413 return -EINVAL; 415 414 } ··· 444 443 445 444 ndev->target_active_prot = 0; 446 445 447 - if (test_bit(NCI_POLL_ACTIVE, &ndev->flags)) { 446 + if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) { 448 447 nci_request(ndev, nci_rf_deactivate_req, 0, 449 448 msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); 450 449 }
+2 -3
net/nfc/nci/ntf.c
··· 261 261 __u8 *data = skb->data; 262 262 int err = 0; 263 263 264 - clear_bit(NCI_DISCOVERY, &ndev->flags); 265 - set_bit(NCI_POLL_ACTIVE, &ndev->flags); 264 + atomic_set(&ndev->state, NCI_POLL_ACTIVE); 266 265 267 266 ntf.rf_discovery_id = *data++; 268 267 ntf.rf_interface = *data++; ··· 349 350 350 351 pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason); 351 352 352 - clear_bit(NCI_POLL_ACTIVE, &ndev->flags); 353 + atomic_set(&ndev->state, NCI_IDLE); 353 354 ndev->target_active_prot = 0; 354 355 355 356 /* drop tx data queue */
+4 -4
net/nfc/nci/rsp.c
··· 137 137 pr_debug("status 0x%x\n", status); 138 138 139 139 if (status == NCI_STATUS_OK) 140 - set_bit(NCI_DISCOVERY, &ndev->flags); 140 + atomic_set(&ndev->state, NCI_DISCOVERY); 141 141 142 142 nci_req_complete(ndev, status); 143 143 } ··· 149 149 150 150 pr_debug("status 0x%x\n", status); 151 151 152 - clear_bit(NCI_DISCOVERY, &ndev->flags); 153 - 154 152 /* If target was active, complete the request only in deactivate_ntf */ 155 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 156 nci_req_complete(ndev, status); 157 + } 158 158 } 159 159 160 160 void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)