nfc: Convert nfc_dbg to pr_debug
[pohmelfs.git] / net / nfc / nci / core.c
blob3faceb02a392f09b43412e526434551656032476
1 /*
2 * The NFC Controller Interface is the communication protocol between an
3 * NFC Controller (NFCC) and a Device Host (DH).
5 * Copyright (C) 2011 Texas Instruments, Inc.
7 * Written by Ilan Elias <ilane@ti.com>
9 * Acknowledgements:
10 * This file is based on hci_core.c, which was written
11 * by Maxim Krasnyansky.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2
15 * as published by the Free Software Foundation
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/types.h>
31 #include <linux/workqueue.h>
32 #include <linux/completion.h>
33 #include <linux/export.h>
34 #include <linux/sched.h>
35 #include <linux/bitops.h>
36 #include <linux/skbuff.h>
38 #include "../nfc.h"
39 #include <net/nfc/nci.h>
40 #include <net/nfc/nci_core.h>
41 #include <linux/nfc.h>
43 static void nci_cmd_work(struct work_struct *work);
44 static void nci_rx_work(struct work_struct *work);
45 static void nci_tx_work(struct work_struct *work);
47 /* ---- NCI requests ---- */
49 void nci_req_complete(struct nci_dev *ndev, int result)
51 if (ndev->req_status == NCI_REQ_PEND) {
52 ndev->req_result = result;
53 ndev->req_status = NCI_REQ_DONE;
54 complete(&ndev->req_completion);
58 static void nci_req_cancel(struct nci_dev *ndev, int err)
60 if (ndev->req_status == NCI_REQ_PEND) {
61 ndev->req_result = err;
62 ndev->req_status = NCI_REQ_CANCELED;
63 complete(&ndev->req_completion);
67 /* Execute request and wait for completion. */
68 static int __nci_request(struct nci_dev *ndev,
69 void (*req)(struct nci_dev *ndev, unsigned long opt),
70 unsigned long opt,
71 __u32 timeout)
73 int rc = 0;
74 unsigned long completion_rc;
76 ndev->req_status = NCI_REQ_PEND;
78 init_completion(&ndev->req_completion);
79 req(ndev, opt);
80 completion_rc = wait_for_completion_interruptible_timeout(
81 &ndev->req_completion,
82 timeout);
84 pr_debug("wait_for_completion return %ld\n", completion_rc);
86 if (completion_rc > 0) {
87 switch (ndev->req_status) {
88 case NCI_REQ_DONE:
89 rc = nci_to_errno(ndev->req_result);
90 break;
92 case NCI_REQ_CANCELED:
93 rc = -ndev->req_result;
94 break;
96 default:
97 rc = -ETIMEDOUT;
98 break;
100 } else {
101 pr_err("wait_for_completion_interruptible_timeout failed %ld\n",
102 completion_rc);
104 rc = ((completion_rc == 0) ? (-ETIMEDOUT) : (completion_rc));
107 ndev->req_status = ndev->req_result = 0;
109 return rc;
112 static inline int nci_request(struct nci_dev *ndev,
113 void (*req)(struct nci_dev *ndev, unsigned long opt),
114 unsigned long opt, __u32 timeout)
116 int rc;
118 if (!test_bit(NCI_UP, &ndev->flags))
119 return -ENETDOWN;
121 /* Serialize all requests */
122 mutex_lock(&ndev->req_lock);
123 rc = __nci_request(ndev, req, opt, timeout);
124 mutex_unlock(&ndev->req_lock);
126 return rc;
129 static void nci_reset_req(struct nci_dev *ndev, unsigned long opt)
131 struct nci_core_reset_cmd cmd;
133 cmd.reset_type = NCI_RESET_TYPE_RESET_CONFIG;
134 nci_send_cmd(ndev, NCI_OP_CORE_RESET_CMD, 1, &cmd);
137 static void nci_init_req(struct nci_dev *ndev, unsigned long opt)
139 nci_send_cmd(ndev, NCI_OP_CORE_INIT_CMD, 0, NULL);
142 static void nci_init_complete_req(struct nci_dev *ndev, unsigned long opt)
144 struct nci_rf_disc_map_cmd cmd;
145 struct disc_map_config *cfg = cmd.mapping_configs;
146 __u8 *num = &cmd.num_mapping_configs;
147 int i;
149 /* set rf mapping configurations */
150 *num = 0;
152 /* by default mapping is set to NCI_RF_INTERFACE_FRAME */
153 for (i = 0; i < ndev->num_supported_rf_interfaces; i++) {
154 if (ndev->supported_rf_interfaces[i] ==
155 NCI_RF_INTERFACE_ISO_DEP) {
156 cfg[*num].rf_protocol = NCI_RF_PROTOCOL_ISO_DEP;
157 cfg[*num].mode = NCI_DISC_MAP_MODE_BOTH;
158 cfg[*num].rf_interface_type = NCI_RF_INTERFACE_ISO_DEP;
159 (*num)++;
160 } else if (ndev->supported_rf_interfaces[i] ==
161 NCI_RF_INTERFACE_NFC_DEP) {
162 cfg[*num].rf_protocol = NCI_RF_PROTOCOL_NFC_DEP;
163 cfg[*num].mode = NCI_DISC_MAP_MODE_BOTH;
164 cfg[*num].rf_interface_type = NCI_RF_INTERFACE_NFC_DEP;
165 (*num)++;
168 if (*num == NCI_MAX_NUM_MAPPING_CONFIGS)
169 break;
172 nci_send_cmd(ndev, NCI_OP_RF_DISCOVER_MAP_CMD,
173 (1 + ((*num)*sizeof(struct disc_map_config))),
174 &cmd);
177 static void nci_rf_discover_req(struct nci_dev *ndev, unsigned long opt)
179 struct nci_rf_disc_cmd cmd;
180 __u32 protocols = opt;
182 cmd.num_disc_configs = 0;
184 if ((cmd.num_disc_configs < NCI_MAX_NUM_RF_CONFIGS) &&
185 (protocols & NFC_PROTO_JEWEL_MASK
186 || protocols & NFC_PROTO_MIFARE_MASK
187 || protocols & NFC_PROTO_ISO14443_MASK
188 || protocols & NFC_PROTO_NFC_DEP_MASK)) {
189 cmd.disc_configs[cmd.num_disc_configs].type =
190 NCI_DISCOVERY_TYPE_POLL_A_PASSIVE;
191 cmd.disc_configs[cmd.num_disc_configs].frequency = 1;
192 cmd.num_disc_configs++;
195 if ((cmd.num_disc_configs < NCI_MAX_NUM_RF_CONFIGS) &&
196 (protocols & NFC_PROTO_ISO14443_MASK)) {
197 cmd.disc_configs[cmd.num_disc_configs].type =
198 NCI_DISCOVERY_TYPE_POLL_B_PASSIVE;
199 cmd.disc_configs[cmd.num_disc_configs].frequency = 1;
200 cmd.num_disc_configs++;
203 if ((cmd.num_disc_configs < NCI_MAX_NUM_RF_CONFIGS) &&
204 (protocols & NFC_PROTO_FELICA_MASK
205 || protocols & NFC_PROTO_NFC_DEP_MASK)) {
206 cmd.disc_configs[cmd.num_disc_configs].type =
207 NCI_DISCOVERY_TYPE_POLL_F_PASSIVE;
208 cmd.disc_configs[cmd.num_disc_configs].frequency = 1;
209 cmd.num_disc_configs++;
212 nci_send_cmd(ndev, NCI_OP_RF_DISCOVER_CMD,
213 (1 + (cmd.num_disc_configs*sizeof(struct disc_config))),
214 &cmd);
217 static void nci_rf_deactivate_req(struct nci_dev *ndev, unsigned long opt)
219 struct nci_rf_deactivate_cmd cmd;
221 cmd.type = NCI_DEACTIVATE_TYPE_IDLE_MODE;
223 nci_send_cmd(ndev, NCI_OP_RF_DEACTIVATE_CMD,
224 sizeof(struct nci_rf_deactivate_cmd),
225 &cmd);
228 static int nci_open_device(struct nci_dev *ndev)
230 int rc = 0;
232 mutex_lock(&ndev->req_lock);
234 if (test_bit(NCI_UP, &ndev->flags)) {
235 rc = -EALREADY;
236 goto done;
239 if (ndev->ops->open(ndev)) {
240 rc = -EIO;
241 goto done;
244 atomic_set(&ndev->cmd_cnt, 1);
246 set_bit(NCI_INIT, &ndev->flags);
248 rc = __nci_request(ndev, nci_reset_req, 0,
249 msecs_to_jiffies(NCI_RESET_TIMEOUT));
251 if (!rc) {
252 rc = __nci_request(ndev, nci_init_req, 0,
253 msecs_to_jiffies(NCI_INIT_TIMEOUT));
256 if (!rc) {
257 rc = __nci_request(ndev, nci_init_complete_req, 0,
258 msecs_to_jiffies(NCI_INIT_TIMEOUT));
261 clear_bit(NCI_INIT, &ndev->flags);
263 if (!rc) {
264 set_bit(NCI_UP, &ndev->flags);
265 } else {
266 /* Init failed, cleanup */
267 skb_queue_purge(&ndev->cmd_q);
268 skb_queue_purge(&ndev->rx_q);
269 skb_queue_purge(&ndev->tx_q);
271 ndev->ops->close(ndev);
272 ndev->flags = 0;
275 done:
276 mutex_unlock(&ndev->req_lock);
277 return rc;
280 static int nci_close_device(struct nci_dev *ndev)
282 nci_req_cancel(ndev, ENODEV);
283 mutex_lock(&ndev->req_lock);
285 if (!test_and_clear_bit(NCI_UP, &ndev->flags)) {
286 del_timer_sync(&ndev->cmd_timer);
287 mutex_unlock(&ndev->req_lock);
288 return 0;
291 /* Drop RX and TX queues */
292 skb_queue_purge(&ndev->rx_q);
293 skb_queue_purge(&ndev->tx_q);
295 /* Flush RX and TX wq */
296 flush_workqueue(ndev->rx_wq);
297 flush_workqueue(ndev->tx_wq);
299 /* Reset device */
300 skb_queue_purge(&ndev->cmd_q);
301 atomic_set(&ndev->cmd_cnt, 1);
303 set_bit(NCI_INIT, &ndev->flags);
304 __nci_request(ndev, nci_reset_req, 0,
305 msecs_to_jiffies(NCI_RESET_TIMEOUT));
306 clear_bit(NCI_INIT, &ndev->flags);
308 /* Flush cmd wq */
309 flush_workqueue(ndev->cmd_wq);
311 /* After this point our queues are empty
312 * and no works are scheduled. */
313 ndev->ops->close(ndev);
315 /* Clear flags */
316 ndev->flags = 0;
318 mutex_unlock(&ndev->req_lock);
320 return 0;
323 /* NCI command timer function */
324 static void nci_cmd_timer(unsigned long arg)
326 struct nci_dev *ndev = (void *) arg;
328 pr_debug("entry\n");
330 atomic_set(&ndev->cmd_cnt, 1);
331 queue_work(ndev->cmd_wq, &ndev->cmd_work);
334 static int nci_dev_up(struct nfc_dev *nfc_dev)
336 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
338 pr_debug("entry\n");
340 return nci_open_device(ndev);
343 static int nci_dev_down(struct nfc_dev *nfc_dev)
345 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
347 pr_debug("entry\n");
349 return nci_close_device(ndev);
352 static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols)
354 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
355 int rc;
357 pr_debug("entry\n");
359 if (test_bit(NCI_DISCOVERY, &ndev->flags)) {
360 pr_err("unable to start poll, since poll is already active\n");
361 return -EBUSY;
364 if (ndev->target_active_prot) {
365 pr_err("there is an active target\n");
366 return -EBUSY;
369 if (test_bit(NCI_POLL_ACTIVE, &ndev->flags)) {
370 pr_debug("target is active, implicitly deactivate...\n");
372 rc = nci_request(ndev, nci_rf_deactivate_req, 0,
373 msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
374 if (rc)
375 return -EBUSY;
378 rc = nci_request(ndev, nci_rf_discover_req, protocols,
379 msecs_to_jiffies(NCI_RF_DISC_TIMEOUT));
381 if (!rc)
382 ndev->poll_prots = protocols;
384 return rc;
387 static void nci_stop_poll(struct nfc_dev *nfc_dev)
389 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
391 pr_debug("entry\n");
393 if (!test_bit(NCI_DISCOVERY, &ndev->flags)) {
394 pr_err("unable to stop poll, since poll is not active\n");
395 return;
398 nci_request(ndev, nci_rf_deactivate_req, 0,
399 msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
402 static int nci_activate_target(struct nfc_dev *nfc_dev, __u32 target_idx,
403 __u32 protocol)
405 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
407 pr_debug("entry, target_idx %d, protocol 0x%x\n", target_idx, protocol);
409 if (!test_bit(NCI_POLL_ACTIVE, &ndev->flags)) {
410 pr_err("there is no available target to activate\n");
411 return -EINVAL;
414 if (ndev->target_active_prot) {
415 pr_err("there is already an active target\n");
416 return -EBUSY;
419 if (!(ndev->target_available_prots & (1 << protocol))) {
420 pr_err("target does not support the requested protocol 0x%x\n",
421 protocol);
422 return -EINVAL;
425 ndev->target_active_prot = protocol;
426 ndev->target_available_prots = 0;
428 return 0;
431 static void nci_deactivate_target(struct nfc_dev *nfc_dev, __u32 target_idx)
433 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
435 pr_debug("entry, target_idx %d\n", target_idx);
437 if (!ndev->target_active_prot) {
438 pr_err("unable to deactivate target, no active target\n");
439 return;
442 ndev->target_active_prot = 0;
444 if (test_bit(NCI_POLL_ACTIVE, &ndev->flags)) {
445 nci_request(ndev, nci_rf_deactivate_req, 0,
446 msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
450 static int nci_data_exchange(struct nfc_dev *nfc_dev, __u32 target_idx,
451 struct sk_buff *skb,
452 data_exchange_cb_t cb,
453 void *cb_context)
455 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
456 int rc;
458 pr_debug("entry, target_idx %d, len %d\n", target_idx, skb->len);
460 if (!ndev->target_active_prot) {
461 pr_err("unable to exchange data, no active target\n");
462 return -EINVAL;
465 if (test_and_set_bit(NCI_DATA_EXCHANGE, &ndev->flags))
466 return -EBUSY;
468 /* store cb and context to be used on receiving data */
469 ndev->data_exchange_cb = cb;
470 ndev->data_exchange_cb_context = cb_context;
472 rc = nci_send_data(ndev, NCI_STATIC_RF_CONN_ID, skb);
473 if (rc)
474 clear_bit(NCI_DATA_EXCHANGE, &ndev->flags);
476 return rc;
479 static struct nfc_ops nci_nfc_ops = {
480 .dev_up = nci_dev_up,
481 .dev_down = nci_dev_down,
482 .start_poll = nci_start_poll,
483 .stop_poll = nci_stop_poll,
484 .activate_target = nci_activate_target,
485 .deactivate_target = nci_deactivate_target,
486 .data_exchange = nci_data_exchange,
489 /* ---- Interface to NCI drivers ---- */
492 * nci_allocate_device - allocate a new nci device
494 * @ops: device operations
495 * @supported_protocols: NFC protocols supported by the device
497 struct nci_dev *nci_allocate_device(struct nci_ops *ops,
498 __u32 supported_protocols,
499 int tx_headroom,
500 int tx_tailroom)
502 struct nci_dev *ndev;
504 pr_debug("entry, supported_protocols 0x%x\n", supported_protocols);
506 if (!ops->open || !ops->close || !ops->send)
507 return NULL;
509 if (!supported_protocols)
510 return NULL;
512 ndev = kzalloc(sizeof(struct nci_dev), GFP_KERNEL);
513 if (!ndev)
514 return NULL;
516 ndev->ops = ops;
517 ndev->tx_headroom = tx_headroom;
518 ndev->tx_tailroom = tx_tailroom;
520 ndev->nfc_dev = nfc_allocate_device(&nci_nfc_ops,
521 supported_protocols,
522 tx_headroom + NCI_DATA_HDR_SIZE,
523 tx_tailroom);
524 if (!ndev->nfc_dev)
525 goto free_exit;
527 nfc_set_drvdata(ndev->nfc_dev, ndev);
529 return ndev;
531 free_exit:
532 kfree(ndev);
533 return NULL;
535 EXPORT_SYMBOL(nci_allocate_device);
538 * nci_free_device - deallocate nci device
540 * @ndev: The nci device to deallocate
542 void nci_free_device(struct nci_dev *ndev)
544 pr_debug("entry\n");
546 nfc_free_device(ndev->nfc_dev);
547 kfree(ndev);
549 EXPORT_SYMBOL(nci_free_device);
552 * nci_register_device - register a nci device in the nfc subsystem
554 * @dev: The nci device to register
556 int nci_register_device(struct nci_dev *ndev)
558 int rc;
559 struct device *dev = &ndev->nfc_dev->dev;
560 char name[32];
562 pr_debug("entry\n");
564 rc = nfc_register_device(ndev->nfc_dev);
565 if (rc)
566 goto exit;
568 ndev->flags = 0;
570 INIT_WORK(&ndev->cmd_work, nci_cmd_work);
571 snprintf(name, sizeof(name), "%s_nci_cmd_wq", dev_name(dev));
572 ndev->cmd_wq = create_singlethread_workqueue(name);
573 if (!ndev->cmd_wq) {
574 rc = -ENOMEM;
575 goto unreg_exit;
578 INIT_WORK(&ndev->rx_work, nci_rx_work);
579 snprintf(name, sizeof(name), "%s_nci_rx_wq", dev_name(dev));
580 ndev->rx_wq = create_singlethread_workqueue(name);
581 if (!ndev->rx_wq) {
582 rc = -ENOMEM;
583 goto destroy_cmd_wq_exit;
586 INIT_WORK(&ndev->tx_work, nci_tx_work);
587 snprintf(name, sizeof(name), "%s_nci_tx_wq", dev_name(dev));
588 ndev->tx_wq = create_singlethread_workqueue(name);
589 if (!ndev->tx_wq) {
590 rc = -ENOMEM;
591 goto destroy_rx_wq_exit;
594 skb_queue_head_init(&ndev->cmd_q);
595 skb_queue_head_init(&ndev->rx_q);
596 skb_queue_head_init(&ndev->tx_q);
598 setup_timer(&ndev->cmd_timer, nci_cmd_timer,
599 (unsigned long) ndev);
601 mutex_init(&ndev->req_lock);
603 goto exit;
605 destroy_rx_wq_exit:
606 destroy_workqueue(ndev->rx_wq);
608 destroy_cmd_wq_exit:
609 destroy_workqueue(ndev->cmd_wq);
611 unreg_exit:
612 nfc_unregister_device(ndev->nfc_dev);
614 exit:
615 return rc;
617 EXPORT_SYMBOL(nci_register_device);
620 * nci_unregister_device - unregister a nci device in the nfc subsystem
622 * @dev: The nci device to unregister
624 void nci_unregister_device(struct nci_dev *ndev)
626 pr_debug("entry\n");
628 nci_close_device(ndev);
630 destroy_workqueue(ndev->cmd_wq);
631 destroy_workqueue(ndev->rx_wq);
632 destroy_workqueue(ndev->tx_wq);
634 nfc_unregister_device(ndev->nfc_dev);
636 EXPORT_SYMBOL(nci_unregister_device);
639 * nci_recv_frame - receive frame from NCI drivers
641 * @skb: The sk_buff to receive
643 int nci_recv_frame(struct sk_buff *skb)
645 struct nci_dev *ndev = (struct nci_dev *) skb->dev;
647 pr_debug("entry, len %d\n", skb->len);
649 if (!ndev || (!test_bit(NCI_UP, &ndev->flags)
650 && !test_bit(NCI_INIT, &ndev->flags))) {
651 kfree_skb(skb);
652 return -ENXIO;
655 /* Queue frame for rx worker thread */
656 skb_queue_tail(&ndev->rx_q, skb);
657 queue_work(ndev->rx_wq, &ndev->rx_work);
659 return 0;
661 EXPORT_SYMBOL(nci_recv_frame);
663 static int nci_send_frame(struct sk_buff *skb)
665 struct nci_dev *ndev = (struct nci_dev *) skb->dev;
667 pr_debug("entry, len %d\n", skb->len);
669 if (!ndev) {
670 kfree_skb(skb);
671 return -ENODEV;
674 /* Get rid of skb owner, prior to sending to the driver. */
675 skb_orphan(skb);
677 return ndev->ops->send(skb);
680 /* Send NCI command */
681 int nci_send_cmd(struct nci_dev *ndev, __u16 opcode, __u8 plen, void *payload)
683 struct nci_ctrl_hdr *hdr;
684 struct sk_buff *skb;
686 pr_debug("entry, opcode 0x%x, plen %d\n", opcode, plen);
688 skb = nci_skb_alloc(ndev, (NCI_CTRL_HDR_SIZE + plen), GFP_KERNEL);
689 if (!skb) {
690 pr_err("no memory for command\n");
691 return -ENOMEM;
694 hdr = (struct nci_ctrl_hdr *) skb_put(skb, NCI_CTRL_HDR_SIZE);
695 hdr->gid = nci_opcode_gid(opcode);
696 hdr->oid = nci_opcode_oid(opcode);
697 hdr->plen = plen;
699 nci_mt_set((__u8 *)hdr, NCI_MT_CMD_PKT);
700 nci_pbf_set((__u8 *)hdr, NCI_PBF_LAST);
702 if (plen)
703 memcpy(skb_put(skb, plen), payload, plen);
705 skb->dev = (void *) ndev;
707 skb_queue_tail(&ndev->cmd_q, skb);
708 queue_work(ndev->cmd_wq, &ndev->cmd_work);
710 return 0;
713 /* ---- NCI TX Data worker thread ---- */
715 static void nci_tx_work(struct work_struct *work)
717 struct nci_dev *ndev = container_of(work, struct nci_dev, tx_work);
718 struct sk_buff *skb;
720 pr_debug("entry, credits_cnt %d\n", atomic_read(&ndev->credits_cnt));
722 /* Send queued tx data */
723 while (atomic_read(&ndev->credits_cnt)) {
724 skb = skb_dequeue(&ndev->tx_q);
725 if (!skb)
726 return;
728 /* Check if data flow control is used */
729 if (atomic_read(&ndev->credits_cnt) !=
730 NCI_DATA_FLOW_CONTROL_NOT_USED)
731 atomic_dec(&ndev->credits_cnt);
733 pr_debug("NCI TX: MT=data, PBF=%d, conn_id=%d, plen=%d\n",
734 nci_pbf(skb->data),
735 nci_conn_id(skb->data),
736 nci_plen(skb->data));
738 nci_send_frame(skb);
742 /* ----- NCI RX worker thread (data & control) ----- */
744 static void nci_rx_work(struct work_struct *work)
746 struct nci_dev *ndev = container_of(work, struct nci_dev, rx_work);
747 struct sk_buff *skb;
749 while ((skb = skb_dequeue(&ndev->rx_q))) {
750 /* Process frame */
751 switch (nci_mt(skb->data)) {
752 case NCI_MT_RSP_PKT:
753 nci_rsp_packet(ndev, skb);
754 break;
756 case NCI_MT_NTF_PKT:
757 nci_ntf_packet(ndev, skb);
758 break;
760 case NCI_MT_DATA_PKT:
761 nci_rx_data_packet(ndev, skb);
762 break;
764 default:
765 pr_err("unknown MT 0x%x\n", nci_mt(skb->data));
766 kfree_skb(skb);
767 break;
772 /* ----- NCI TX CMD worker thread ----- */
774 static void nci_cmd_work(struct work_struct *work)
776 struct nci_dev *ndev = container_of(work, struct nci_dev, cmd_work);
777 struct sk_buff *skb;
779 pr_debug("entry, cmd_cnt %d\n", atomic_read(&ndev->cmd_cnt));
781 /* Send queued command */
782 if (atomic_read(&ndev->cmd_cnt)) {
783 skb = skb_dequeue(&ndev->cmd_q);
784 if (!skb)
785 return;
787 atomic_dec(&ndev->cmd_cnt);
789 pr_debug("NCI TX: MT=cmd, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
790 nci_pbf(skb->data),
791 nci_opcode_gid(nci_opcode(skb->data)),
792 nci_opcode_oid(nci_opcode(skb->data)),
793 nci_plen(skb->data));
795 nci_send_frame(skb);
797 mod_timer(&ndev->cmd_timer,
798 jiffies + msecs_to_jiffies(NCI_CMD_TIMEOUT));