]> Pileus Git - ~andy/linux/blobdiff - net/nfc/nci/core.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless
[~andy/linux] / net / nfc / nci / core.c
index 3925c6578767ea61be8cc66933d38a6c500cd1d2..c55f233a5e2c76bda9184918f909d941afe9e98f 100644 (file)
@@ -25,6 +25,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/types.h>
 #include <linux/workqueue.h>
 #include <linux/completion.h>
@@ -69,7 +71,7 @@ static int __nci_request(struct nci_dev *ndev,
        __u32 timeout)
 {
        int rc = 0;
-       unsigned long completion_rc;
+       long completion_rc;
 
        ndev->req_status = NCI_REQ_PEND;
 
@@ -79,7 +81,7 @@ static int __nci_request(struct nci_dev *ndev,
                                                        &ndev->req_completion,
                                                        timeout);
 
-       nfc_dbg("wait_for_completion return %ld", completion_rc);
+       pr_debug("wait_for_completion return %ld\n", completion_rc);
 
        if (completion_rc > 0) {
                switch (ndev->req_status) {
@@ -96,8 +98,8 @@ static int __nci_request(struct nci_dev *ndev,
                        break;
                }
        } else {
-               nfc_err("wait_for_completion_interruptible_timeout failed %ld",
-                       completion_rc);
+               pr_err("wait_for_completion_interruptible_timeout failed %ld\n",
+                      completion_rc);
 
                rc = ((completion_rc == 0) ? (-ETIMEDOUT) : (completion_rc));
        }
@@ -126,7 +128,10 @@ static inline int nci_request(struct nci_dev *ndev,
 
 static void nci_reset_req(struct nci_dev *ndev, unsigned long opt)
 {
-       nci_send_cmd(ndev, NCI_OP_CORE_RESET_CMD, 0, NULL);
+       struct nci_core_reset_cmd cmd;
+
+       cmd.reset_type = NCI_RESET_TYPE_RESET_CONFIG;
+       nci_send_cmd(ndev, NCI_OP_CORE_RESET_CMD, 1, &cmd);
 }
 
 static void nci_init_req(struct nci_dev *ndev, unsigned long opt)
@@ -136,17 +141,11 @@ static void nci_init_req(struct nci_dev *ndev, unsigned long opt)
 
 static void nci_init_complete_req(struct nci_dev *ndev, unsigned long opt)
 {
-       struct nci_core_conn_create_cmd conn_cmd;
        struct nci_rf_disc_map_cmd cmd;
        struct disc_map_config *cfg = cmd.mapping_configs;
        __u8 *num = &cmd.num_mapping_configs;
        int i;
 
-       /* create static rf connection */
-       conn_cmd.target_handle = 0;
-       conn_cmd.num_target_specific_params = 0;
-       nci_send_cmd(ndev, NCI_OP_CORE_CONN_CREATE_CMD, 2, &conn_cmd);
-
        /* set rf mapping configurations */
        *num = 0;
 
@@ -326,8 +325,6 @@ static void nci_cmd_timer(unsigned long arg)
 {
        struct nci_dev *ndev = (void *) arg;
 
-       nfc_dbg("entry");
-
        atomic_set(&ndev->cmd_cnt, 1);
        queue_work(ndev->cmd_wq, &ndev->cmd_work);
 }
@@ -336,8 +333,6 @@ static int nci_dev_up(struct nfc_dev *nfc_dev)
 {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
 
-       nfc_dbg("entry");
-
        return nci_open_device(ndev);
 }
 
@@ -345,8 +340,6 @@ static int nci_dev_down(struct nfc_dev *nfc_dev)
 {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
 
-       nfc_dbg("entry");
-
        return nci_close_device(ndev);
 }
 
@@ -355,20 +348,18 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols)
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
        int rc;
 
-       nfc_dbg("entry");
-
        if (test_bit(NCI_DISCOVERY, &ndev->flags)) {
-               nfc_err("unable to start poll, since poll is already active");
+               pr_err("unable to start poll, since poll is already active\n");
                return -EBUSY;
        }
 
        if (ndev->target_active_prot) {
-               nfc_err("there is an active target");
+               pr_err("there is an active target\n");
                return -EBUSY;
        }
 
        if (test_bit(NCI_POLL_ACTIVE, &ndev->flags)) {
-               nfc_dbg("target is active, implicitly deactivate...");
+               pr_debug("target is active, implicitly deactivate...\n");
 
                rc = nci_request(ndev, nci_rf_deactivate_req, 0,
                        msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
@@ -389,10 +380,8 @@ static void nci_stop_poll(struct nfc_dev *nfc_dev)
 {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
 
-       nfc_dbg("entry");
-
        if (!test_bit(NCI_DISCOVERY, &ndev->flags)) {
-               nfc_err("unable to stop poll, since poll is not active");
+               pr_err("unable to stop poll, since poll is not active\n");
                return;
        }
 
@@ -405,21 +394,21 @@ static int nci_activate_target(struct nfc_dev *nfc_dev, __u32 target_idx,
 {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
 
-       nfc_dbg("entry, target_idx %d, protocol 0x%x", target_idx, protocol);
+       pr_debug("target_idx %d, protocol 0x%x\n", target_idx, protocol);
 
        if (!test_bit(NCI_POLL_ACTIVE, &ndev->flags)) {
-               nfc_err("there is no available target to activate");
+               pr_err("there is no available target to activate\n");
                return -EINVAL;
        }
 
        if (ndev->target_active_prot) {
-               nfc_err("there is already an active target");
+               pr_err("there is already an active target\n");
                return -EBUSY;
        }
 
        if (!(ndev->target_available_prots & (1 << protocol))) {
-               nfc_err("target does not support the requested protocol 0x%x",
-                       protocol);
+               pr_err("target does not support the requested protocol 0x%x\n",
+                      protocol);
                return -EINVAL;
        }
 
@@ -433,10 +422,10 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev, __u32 target_idx)
 {
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
 
-       nfc_dbg("entry, target_idx %d", target_idx);
+       pr_debug("target_idx %d\n", target_idx);
 
        if (!ndev->target_active_prot) {
-               nfc_err("unable to deactivate target, no active target");
+               pr_err("unable to deactivate target, no active target\n");
                return;
        }
 
@@ -456,10 +445,10 @@ static int nci_data_exchange(struct nfc_dev *nfc_dev, __u32 target_idx,
        struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
        int rc;
 
-       nfc_dbg("entry, target_idx %d, len %d", target_idx, skb->len);
+       pr_debug("target_idx %d, len %d\n", target_idx, skb->len);
 
        if (!ndev->target_active_prot) {
-               nfc_err("unable to exchange data, no active target");
+               pr_err("unable to exchange data, no active target\n");
                return -EINVAL;
        }
 
@@ -470,7 +459,7 @@ static int nci_data_exchange(struct nfc_dev *nfc_dev, __u32 target_idx,
        ndev->data_exchange_cb = cb;
        ndev->data_exchange_cb_context = cb_context;
 
-       rc = nci_send_data(ndev, ndev->conn_id, skb);
+       rc = nci_send_data(ndev, NCI_STATIC_RF_CONN_ID, skb);
        if (rc)
                clear_bit(NCI_DATA_EXCHANGE, &ndev->flags);
 
@@ -502,7 +491,7 @@ struct nci_dev *nci_allocate_device(struct nci_ops *ops,
 {
        struct nci_dev *ndev;
 
-       nfc_dbg("entry, supported_protocols 0x%x", supported_protocols);
+       pr_debug("supported_protocols 0x%x\n", supported_protocols);
 
        if (!ops->open || !ops->close || !ops->send)
                return NULL;
@@ -542,8 +531,6 @@ EXPORT_SYMBOL(nci_allocate_device);
  */
 void nci_free_device(struct nci_dev *ndev)
 {
-       nfc_dbg("entry");
-
        nfc_free_device(ndev->nfc_dev);
        kfree(ndev);
 }
@@ -560,8 +547,6 @@ int nci_register_device(struct nci_dev *ndev)
        struct device *dev = &ndev->nfc_dev->dev;
        char name[32];
 
-       nfc_dbg("entry");
-
        rc = nfc_register_device(ndev->nfc_dev);
        if (rc)
                goto exit;
@@ -624,8 +609,6 @@ EXPORT_SYMBOL(nci_register_device);
  */
 void nci_unregister_device(struct nci_dev *ndev)
 {
-       nfc_dbg("entry");
-
        nci_close_device(ndev);
 
        destroy_workqueue(ndev->cmd_wq);
@@ -645,7 +628,7 @@ int nci_recv_frame(struct sk_buff *skb)
 {
        struct nci_dev *ndev = (struct nci_dev *) skb->dev;
 
-       nfc_dbg("entry, len %d", skb->len);
+       pr_debug("len %d\n", skb->len);
 
        if (!ndev || (!test_bit(NCI_UP, &ndev->flags)
                && !test_bit(NCI_INIT, &ndev->flags))) {
@@ -665,7 +648,7 @@ static int nci_send_frame(struct sk_buff *skb)
 {
        struct nci_dev *ndev = (struct nci_dev *) skb->dev;
 
-       nfc_dbg("entry, len %d", skb->len);
+       pr_debug("len %d\n", skb->len);
 
        if (!ndev) {
                kfree_skb(skb);
@@ -684,11 +667,11 @@ int nci_send_cmd(struct nci_dev *ndev, __u16 opcode, __u8 plen, void *payload)
        struct nci_ctrl_hdr *hdr;
        struct sk_buff *skb;
 
-       nfc_dbg("entry, opcode 0x%x, plen %d", opcode, plen);
+       pr_debug("opcode 0x%x, plen %d\n", opcode, plen);
 
        skb = nci_skb_alloc(ndev, (NCI_CTRL_HDR_SIZE + plen), GFP_KERNEL);
        if (!skb) {
-               nfc_err("no memory for command");
+               pr_err("no memory for command\n");
                return -ENOMEM;
        }
 
@@ -718,7 +701,7 @@ static void nci_tx_work(struct work_struct *work)
        struct nci_dev *ndev = container_of(work, struct nci_dev, tx_work);
        struct sk_buff *skb;
 
-       nfc_dbg("entry, credits_cnt %d", atomic_read(&ndev->credits_cnt));
+       pr_debug("credits_cnt %d\n", atomic_read(&ndev->credits_cnt));
 
        /* Send queued tx data */
        while (atomic_read(&ndev->credits_cnt)) {
@@ -726,12 +709,15 @@ static void nci_tx_work(struct work_struct *work)
                if (!skb)
                        return;
 
-               atomic_dec(&ndev->credits_cnt);
+               /* Check if data flow control is used */
+               if (atomic_read(&ndev->credits_cnt) !=
+                               NCI_DATA_FLOW_CONTROL_NOT_USED)
+                       atomic_dec(&ndev->credits_cnt);
 
-               nfc_dbg("NCI TX: MT=data, PBF=%d, conn_id=%d, plen=%d",
-                               nci_pbf(skb->data),
-                               nci_conn_id(skb->data),
-                               nci_plen(skb->data));
+               pr_debug("NCI TX: MT=data, PBF=%d, conn_id=%d, plen=%d\n",
+                        nci_pbf(skb->data),
+                        nci_conn_id(skb->data),
+                        nci_plen(skb->data));
 
                nci_send_frame(skb);
        }
@@ -760,7 +746,7 @@ static void nci_rx_work(struct work_struct *work)
                        break;
 
                default:
-                       nfc_err("unknown MT 0x%x", nci_mt(skb->data));
+                       pr_err("unknown MT 0x%x\n", nci_mt(skb->data));
                        kfree_skb(skb);
                        break;
                }
@@ -774,7 +760,7 @@ static void nci_cmd_work(struct work_struct *work)
        struct nci_dev *ndev = container_of(work, struct nci_dev, cmd_work);
        struct sk_buff *skb;
 
-       nfc_dbg("entry, cmd_cnt %d", atomic_read(&ndev->cmd_cnt));
+       pr_debug("cmd_cnt %d\n", atomic_read(&ndev->cmd_cnt));
 
        /* Send queued command */
        if (atomic_read(&ndev->cmd_cnt)) {
@@ -784,11 +770,11 @@ static void nci_cmd_work(struct work_struct *work)
 
                atomic_dec(&ndev->cmd_cnt);
 
-               nfc_dbg("NCI TX: MT=cmd, PBF=%d, GID=0x%x, OID=0x%x, plen=%d",
-                               nci_pbf(skb->data),
-                               nci_opcode_gid(nci_opcode(skb->data)),
-                               nci_opcode_oid(nci_opcode(skb->data)),
-                               nci_plen(skb->data));
+               pr_debug("NCI TX: MT=cmd, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
+                        nci_pbf(skb->data),
+                        nci_opcode_gid(nci_opcode(skb->data)),
+                        nci_opcode_oid(nci_opcode(skb->data)),
+                        nci_plen(skb->data));
 
                nci_send_frame(skb);