Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 1 | /* |
| 2 | * NFC Digital Protocol stack |
| 3 | * Copyright (c) 2013, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | */ |
| 15 | |
Samuel Ortiz | c5da0e4 | 2013-09-20 09:05:48 +0200 | [diff] [blame] | 16 | #define pr_fmt(fmt) "digital: %s: " fmt, __func__ |
| 17 | |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | |
| 20 | #include "digital.h" |
| 21 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 22 | #define DIGITAL_PROTO_NFCA_RF_TECH \ |
Thierry Escande | 7d0911c | 2013-09-19 17:55:29 +0200 | [diff] [blame] | 23 | (NFC_PROTO_JEWEL_MASK | NFC_PROTO_MIFARE_MASK | NFC_PROTO_NFC_DEP_MASK) |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 24 | |
Thierry Escande | 7d0911c | 2013-09-19 17:55:29 +0200 | [diff] [blame] | 25 | #define DIGITAL_PROTO_NFCF_RF_TECH \ |
| 26 | (NFC_PROTO_FELICA_MASK | NFC_PROTO_NFC_DEP_MASK) |
Thierry Escande | 8c0695e4 | 2013-09-19 17:55:28 +0200 | [diff] [blame] | 27 | |
Mark A. Greer | a381d48 | 2014-01-21 16:23:59 -0700 | [diff] [blame] | 28 | #define DIGITAL_PROTO_ISO15693_RF_TECH NFC_PROTO_ISO15693_MASK |
| 29 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 30 | struct digital_cmd { |
| 31 | struct list_head queue; |
| 32 | |
| 33 | u8 type; |
| 34 | u8 pending; |
| 35 | |
| 36 | u16 timeout; |
| 37 | struct sk_buff *req; |
| 38 | struct sk_buff *resp; |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 39 | struct digital_tg_mdaa_params *mdaa_params; |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 40 | |
| 41 | nfc_digital_cmd_complete_t cmd_cb; |
| 42 | void *cb_context; |
| 43 | }; |
| 44 | |
| 45 | struct sk_buff *digital_skb_alloc(struct nfc_digital_dev *ddev, |
| 46 | unsigned int len) |
| 47 | { |
| 48 | struct sk_buff *skb; |
| 49 | |
| 50 | skb = alloc_skb(len + ddev->tx_headroom + ddev->tx_tailroom, |
| 51 | GFP_KERNEL); |
| 52 | if (skb) |
| 53 | skb_reserve(skb, ddev->tx_headroom); |
| 54 | |
| 55 | return skb; |
| 56 | } |
| 57 | |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 58 | void digital_skb_add_crc(struct sk_buff *skb, crc_func_t crc_func, u16 init, |
| 59 | u8 bitwise_inv, u8 msb_first) |
| 60 | { |
| 61 | u16 crc; |
| 62 | |
| 63 | crc = crc_func(init, skb->data, skb->len); |
| 64 | |
| 65 | if (bitwise_inv) |
| 66 | crc = ~crc; |
| 67 | |
| 68 | if (msb_first) |
| 69 | crc = __fswab16(crc); |
| 70 | |
| 71 | *skb_put(skb, 1) = crc & 0xFF; |
| 72 | *skb_put(skb, 1) = (crc >> 8) & 0xFF; |
| 73 | } |
| 74 | |
| 75 | int digital_skb_check_crc(struct sk_buff *skb, crc_func_t crc_func, |
| 76 | u16 crc_init, u8 bitwise_inv, u8 msb_first) |
| 77 | { |
| 78 | int rc; |
| 79 | u16 crc; |
| 80 | |
| 81 | if (skb->len <= 2) |
| 82 | return -EIO; |
| 83 | |
| 84 | crc = crc_func(crc_init, skb->data, skb->len - 2); |
| 85 | |
| 86 | if (bitwise_inv) |
| 87 | crc = ~crc; |
| 88 | |
| 89 | if (msb_first) |
| 90 | crc = __swab16(crc); |
| 91 | |
| 92 | rc = (skb->data[skb->len - 2] - (crc & 0xFF)) + |
| 93 | (skb->data[skb->len - 1] - ((crc >> 8) & 0xFF)); |
| 94 | |
| 95 | if (rc) |
| 96 | return -EIO; |
| 97 | |
| 98 | skb_trim(skb, skb->len - 2); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 103 | static inline void digital_switch_rf(struct nfc_digital_dev *ddev, bool on) |
| 104 | { |
| 105 | ddev->ops->switch_rf(ddev, on); |
| 106 | } |
| 107 | |
| 108 | static inline void digital_abort_cmd(struct nfc_digital_dev *ddev) |
| 109 | { |
| 110 | ddev->ops->abort_cmd(ddev); |
| 111 | } |
| 112 | |
| 113 | static void digital_wq_cmd_complete(struct work_struct *work) |
| 114 | { |
| 115 | struct digital_cmd *cmd; |
| 116 | struct nfc_digital_dev *ddev = container_of(work, |
| 117 | struct nfc_digital_dev, |
| 118 | cmd_complete_work); |
| 119 | |
| 120 | mutex_lock(&ddev->cmd_lock); |
| 121 | |
| 122 | cmd = list_first_entry_or_null(&ddev->cmd_queue, struct digital_cmd, |
| 123 | queue); |
| 124 | if (!cmd) { |
| 125 | mutex_unlock(&ddev->cmd_lock); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | list_del(&cmd->queue); |
| 130 | |
| 131 | mutex_unlock(&ddev->cmd_lock); |
| 132 | |
| 133 | if (!IS_ERR(cmd->resp)) |
| 134 | print_hex_dump_debug("DIGITAL RX: ", DUMP_PREFIX_NONE, 16, 1, |
| 135 | cmd->resp->data, cmd->resp->len, false); |
| 136 | |
| 137 | cmd->cmd_cb(ddev, cmd->cb_context, cmd->resp); |
| 138 | |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 139 | kfree(cmd->mdaa_params); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 140 | kfree(cmd); |
| 141 | |
| 142 | schedule_work(&ddev->cmd_work); |
| 143 | } |
| 144 | |
| 145 | static void digital_send_cmd_complete(struct nfc_digital_dev *ddev, |
| 146 | void *arg, struct sk_buff *resp) |
| 147 | { |
| 148 | struct digital_cmd *cmd = arg; |
| 149 | |
| 150 | cmd->resp = resp; |
| 151 | |
| 152 | schedule_work(&ddev->cmd_complete_work); |
| 153 | } |
| 154 | |
| 155 | static void digital_wq_cmd(struct work_struct *work) |
| 156 | { |
| 157 | int rc; |
| 158 | struct digital_cmd *cmd; |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 159 | struct digital_tg_mdaa_params *params; |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 160 | struct nfc_digital_dev *ddev = container_of(work, |
| 161 | struct nfc_digital_dev, |
| 162 | cmd_work); |
| 163 | |
| 164 | mutex_lock(&ddev->cmd_lock); |
| 165 | |
| 166 | cmd = list_first_entry_or_null(&ddev->cmd_queue, struct digital_cmd, |
| 167 | queue); |
| 168 | if (!cmd || cmd->pending) { |
| 169 | mutex_unlock(&ddev->cmd_lock); |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | mutex_unlock(&ddev->cmd_lock); |
| 174 | |
| 175 | if (cmd->req) |
| 176 | print_hex_dump_debug("DIGITAL TX: ", DUMP_PREFIX_NONE, 16, 1, |
| 177 | cmd->req->data, cmd->req->len, false); |
| 178 | |
| 179 | switch (cmd->type) { |
| 180 | case DIGITAL_CMD_IN_SEND: |
| 181 | rc = ddev->ops->in_send_cmd(ddev, cmd->req, cmd->timeout, |
| 182 | digital_send_cmd_complete, cmd); |
| 183 | break; |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 184 | |
| 185 | case DIGITAL_CMD_TG_SEND: |
| 186 | rc = ddev->ops->tg_send_cmd(ddev, cmd->req, cmd->timeout, |
| 187 | digital_send_cmd_complete, cmd); |
| 188 | break; |
| 189 | |
| 190 | case DIGITAL_CMD_TG_LISTEN: |
| 191 | rc = ddev->ops->tg_listen(ddev, cmd->timeout, |
| 192 | digital_send_cmd_complete, cmd); |
| 193 | break; |
| 194 | |
| 195 | case DIGITAL_CMD_TG_LISTEN_MDAA: |
| 196 | params = cmd->mdaa_params; |
| 197 | |
| 198 | rc = ddev->ops->tg_listen_mdaa(ddev, params, cmd->timeout, |
| 199 | digital_send_cmd_complete, cmd); |
| 200 | break; |
| 201 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 202 | default: |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 203 | pr_err("Unknown cmd type %d\n", cmd->type); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 204 | return; |
| 205 | } |
| 206 | |
| 207 | if (!rc) |
| 208 | return; |
| 209 | |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 210 | pr_err("in_send_command returned err %d\n", rc); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 211 | |
| 212 | mutex_lock(&ddev->cmd_lock); |
| 213 | list_del(&cmd->queue); |
| 214 | mutex_unlock(&ddev->cmd_lock); |
| 215 | |
| 216 | kfree_skb(cmd->req); |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 217 | kfree(cmd->mdaa_params); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 218 | kfree(cmd); |
| 219 | |
| 220 | schedule_work(&ddev->cmd_work); |
| 221 | } |
| 222 | |
| 223 | int digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type, |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 224 | struct sk_buff *skb, struct digital_tg_mdaa_params *params, |
| 225 | u16 timeout, nfc_digital_cmd_complete_t cmd_cb, |
| 226 | void *cb_context) |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 227 | { |
| 228 | struct digital_cmd *cmd; |
| 229 | |
| 230 | cmd = kzalloc(sizeof(struct digital_cmd), GFP_KERNEL); |
| 231 | if (!cmd) |
| 232 | return -ENOMEM; |
| 233 | |
| 234 | cmd->type = cmd_type; |
| 235 | cmd->timeout = timeout; |
| 236 | cmd->req = skb; |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 237 | cmd->mdaa_params = params; |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 238 | cmd->cmd_cb = cmd_cb; |
| 239 | cmd->cb_context = cb_context; |
| 240 | INIT_LIST_HEAD(&cmd->queue); |
| 241 | |
| 242 | mutex_lock(&ddev->cmd_lock); |
| 243 | list_add_tail(&cmd->queue, &ddev->cmd_queue); |
| 244 | mutex_unlock(&ddev->cmd_lock); |
| 245 | |
| 246 | schedule_work(&ddev->cmd_work); |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | int digital_in_configure_hw(struct nfc_digital_dev *ddev, int type, int param) |
| 252 | { |
| 253 | int rc; |
| 254 | |
| 255 | rc = ddev->ops->in_configure_hw(ddev, type, param); |
| 256 | if (rc) |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 257 | pr_err("in_configure_hw failed: %d\n", rc); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 258 | |
| 259 | return rc; |
| 260 | } |
| 261 | |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 262 | int digital_tg_configure_hw(struct nfc_digital_dev *ddev, int type, int param) |
| 263 | { |
| 264 | int rc; |
| 265 | |
| 266 | rc = ddev->ops->tg_configure_hw(ddev, type, param); |
| 267 | if (rc) |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 268 | pr_err("tg_configure_hw failed: %d\n", rc); |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 269 | |
| 270 | return rc; |
| 271 | } |
| 272 | |
| 273 | static int digital_tg_listen_mdaa(struct nfc_digital_dev *ddev, u8 rf_tech) |
| 274 | { |
| 275 | struct digital_tg_mdaa_params *params; |
| 276 | |
| 277 | params = kzalloc(sizeof(struct digital_tg_mdaa_params), GFP_KERNEL); |
| 278 | if (!params) |
| 279 | return -ENOMEM; |
| 280 | |
| 281 | params->sens_res = DIGITAL_SENS_RES_NFC_DEP; |
| 282 | get_random_bytes(params->nfcid1, sizeof(params->nfcid1)); |
| 283 | params->sel_res = DIGITAL_SEL_RES_NFC_DEP; |
| 284 | |
| 285 | params->nfcid2[0] = DIGITAL_SENSF_NFCID2_NFC_DEP_B1; |
| 286 | params->nfcid2[1] = DIGITAL_SENSF_NFCID2_NFC_DEP_B2; |
| 287 | get_random_bytes(params->nfcid2 + 2, NFC_NFCID2_MAXSIZE - 2); |
| 288 | params->sc = DIGITAL_SENSF_FELICA_SC; |
| 289 | |
| 290 | return digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MDAA, NULL, params, |
| 291 | 500, digital_tg_recv_atr_req, NULL); |
| 292 | } |
| 293 | |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 294 | int digital_target_found(struct nfc_digital_dev *ddev, |
| 295 | struct nfc_target *target, u8 protocol) |
| 296 | { |
| 297 | int rc; |
| 298 | u8 framing; |
| 299 | u8 rf_tech; |
| 300 | int (*check_crc)(struct sk_buff *skb); |
| 301 | void (*add_crc)(struct sk_buff *skb); |
| 302 | |
| 303 | rf_tech = ddev->poll_techs[ddev->poll_tech_index].rf_tech; |
| 304 | |
| 305 | switch (protocol) { |
| 306 | case NFC_PROTO_JEWEL: |
| 307 | framing = NFC_DIGITAL_FRAMING_NFCA_T1T; |
| 308 | check_crc = digital_skb_check_crc_b; |
| 309 | add_crc = digital_skb_add_crc_b; |
| 310 | break; |
| 311 | |
| 312 | case NFC_PROTO_MIFARE: |
| 313 | framing = NFC_DIGITAL_FRAMING_NFCA_T2T; |
| 314 | check_crc = digital_skb_check_crc_a; |
| 315 | add_crc = digital_skb_add_crc_a; |
| 316 | break; |
| 317 | |
Thierry Escande | 8c0695e4 | 2013-09-19 17:55:28 +0200 | [diff] [blame] | 318 | case NFC_PROTO_FELICA: |
| 319 | framing = NFC_DIGITAL_FRAMING_NFCF_T3T; |
| 320 | check_crc = digital_skb_check_crc_f; |
| 321 | add_crc = digital_skb_add_crc_f; |
| 322 | break; |
| 323 | |
Thierry Escande | 7d0911c | 2013-09-19 17:55:29 +0200 | [diff] [blame] | 324 | case NFC_PROTO_NFC_DEP: |
| 325 | if (rf_tech == NFC_DIGITAL_RF_TECH_106A) { |
| 326 | framing = NFC_DIGITAL_FRAMING_NFCA_NFC_DEP; |
| 327 | check_crc = digital_skb_check_crc_a; |
| 328 | add_crc = digital_skb_add_crc_a; |
| 329 | } else { |
| 330 | framing = NFC_DIGITAL_FRAMING_NFCF_NFC_DEP; |
| 331 | check_crc = digital_skb_check_crc_f; |
| 332 | add_crc = digital_skb_add_crc_f; |
| 333 | } |
| 334 | break; |
| 335 | |
Mark A. Greer | a381d48 | 2014-01-21 16:23:59 -0700 | [diff] [blame] | 336 | case NFC_PROTO_ISO15693: |
| 337 | framing = NFC_DIGITAL_FRAMING_ISO15693_TVT; |
| 338 | check_crc = digital_skb_check_crc_b; |
| 339 | add_crc = digital_skb_add_crc_b; |
Thierry Escande | 564af14 | 2014-02-12 12:13:23 +0100 | [diff] [blame] | 340 | break; |
Thierry Escande | 12e3d24 | 2014-01-27 00:31:31 +0100 | [diff] [blame] | 341 | |
| 342 | case NFC_PROTO_ISO14443: |
| 343 | framing = NFC_DIGITAL_FRAMING_NFCA_T4T; |
| 344 | check_crc = digital_skb_check_crc_a; |
| 345 | add_crc = digital_skb_add_crc_a; |
Mark A. Greer | a381d48 | 2014-01-21 16:23:59 -0700 | [diff] [blame] | 346 | break; |
| 347 | |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 348 | default: |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 349 | pr_err("Invalid protocol %d\n", protocol); |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 350 | return -EINVAL; |
| 351 | } |
| 352 | |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 353 | pr_debug("rf_tech=%d, protocol=%d\n", rf_tech, protocol); |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 354 | |
| 355 | ddev->curr_rf_tech = rf_tech; |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 356 | |
| 357 | if (DIGITAL_DRV_CAPS_IN_CRC(ddev)) { |
| 358 | ddev->skb_add_crc = digital_skb_add_crc_none; |
| 359 | ddev->skb_check_crc = digital_skb_check_crc_none; |
| 360 | } else { |
| 361 | ddev->skb_add_crc = add_crc; |
| 362 | ddev->skb_check_crc = check_crc; |
| 363 | } |
| 364 | |
| 365 | rc = digital_in_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING, framing); |
| 366 | if (rc) |
| 367 | return rc; |
| 368 | |
| 369 | target->supported_protocols = (1 << protocol); |
| 370 | rc = nfc_targets_found(ddev->nfc_dev, target, 1); |
| 371 | if (rc) |
| 372 | return rc; |
| 373 | |
| 374 | ddev->poll_tech_count = 0; |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 379 | void digital_poll_next_tech(struct nfc_digital_dev *ddev) |
| 380 | { |
| 381 | digital_switch_rf(ddev, 0); |
| 382 | |
| 383 | mutex_lock(&ddev->poll_lock); |
| 384 | |
| 385 | if (!ddev->poll_tech_count) { |
| 386 | mutex_unlock(&ddev->poll_lock); |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | ddev->poll_tech_index = (ddev->poll_tech_index + 1) % |
| 391 | ddev->poll_tech_count; |
| 392 | |
| 393 | mutex_unlock(&ddev->poll_lock); |
| 394 | |
| 395 | schedule_work(&ddev->poll_work); |
| 396 | } |
| 397 | |
| 398 | static void digital_wq_poll(struct work_struct *work) |
| 399 | { |
| 400 | int rc; |
| 401 | struct digital_poll_tech *poll_tech; |
| 402 | struct nfc_digital_dev *ddev = container_of(work, |
| 403 | struct nfc_digital_dev, |
| 404 | poll_work); |
| 405 | mutex_lock(&ddev->poll_lock); |
| 406 | |
| 407 | if (!ddev->poll_tech_count) { |
| 408 | mutex_unlock(&ddev->poll_lock); |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | poll_tech = &ddev->poll_techs[ddev->poll_tech_index]; |
| 413 | |
| 414 | mutex_unlock(&ddev->poll_lock); |
| 415 | |
| 416 | rc = poll_tech->poll_func(ddev, poll_tech->rf_tech); |
| 417 | if (rc) |
| 418 | digital_poll_next_tech(ddev); |
| 419 | } |
| 420 | |
| 421 | static void digital_add_poll_tech(struct nfc_digital_dev *ddev, u8 rf_tech, |
| 422 | digital_poll_t poll_func) |
| 423 | { |
| 424 | struct digital_poll_tech *poll_tech; |
| 425 | |
| 426 | if (ddev->poll_tech_count >= NFC_DIGITAL_POLL_MODE_COUNT_MAX) |
| 427 | return; |
| 428 | |
| 429 | poll_tech = &ddev->poll_techs[ddev->poll_tech_count++]; |
| 430 | |
| 431 | poll_tech->rf_tech = rf_tech; |
| 432 | poll_tech->poll_func = poll_func; |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * start_poll operation |
| 437 | * |
| 438 | * For every supported protocol, the corresponding polling function is added |
| 439 | * to the table of polling technologies (ddev->poll_techs[]) using |
| 440 | * digital_add_poll_tech(). |
| 441 | * When a polling function fails (by timeout or protocol error) the next one is |
| 442 | * schedule by digital_poll_next_tech() on the poll workqueue (ddev->poll_work). |
| 443 | */ |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 444 | static int digital_start_poll(struct nfc_dev *nfc_dev, __u32 im_protocols, |
| 445 | __u32 tm_protocols) |
| 446 | { |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 447 | struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev); |
| 448 | u32 matching_im_protocols, matching_tm_protocols; |
| 449 | |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 450 | pr_debug("protocols: im 0x%x, tm 0x%x, supported 0x%x\n", im_protocols, |
Samuel Ortiz | c5da0e4 | 2013-09-20 09:05:48 +0200 | [diff] [blame] | 451 | tm_protocols, ddev->protocols); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 452 | |
| 453 | matching_im_protocols = ddev->protocols & im_protocols; |
| 454 | matching_tm_protocols = ddev->protocols & tm_protocols; |
| 455 | |
| 456 | if (!matching_im_protocols && !matching_tm_protocols) { |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 457 | pr_err("Unknown protocol\n"); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 458 | return -EINVAL; |
| 459 | } |
| 460 | |
| 461 | if (ddev->poll_tech_count) { |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 462 | pr_err("Already polling\n"); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 463 | return -EBUSY; |
| 464 | } |
| 465 | |
| 466 | if (ddev->curr_protocol) { |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 467 | pr_err("A target is already active\n"); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 468 | return -EBUSY; |
| 469 | } |
| 470 | |
| 471 | ddev->poll_tech_count = 0; |
| 472 | ddev->poll_tech_index = 0; |
| 473 | |
| 474 | if (matching_im_protocols & DIGITAL_PROTO_NFCA_RF_TECH) |
| 475 | digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_106A, |
| 476 | digital_in_send_sens_req); |
| 477 | |
Thierry Escande | 8c0695e4 | 2013-09-19 17:55:28 +0200 | [diff] [blame] | 478 | if (im_protocols & DIGITAL_PROTO_NFCF_RF_TECH) { |
| 479 | digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_212F, |
| 480 | digital_in_send_sensf_req); |
| 481 | |
| 482 | digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_424F, |
| 483 | digital_in_send_sensf_req); |
| 484 | } |
| 485 | |
Mark A. Greer | a381d48 | 2014-01-21 16:23:59 -0700 | [diff] [blame] | 486 | if (matching_im_protocols & DIGITAL_PROTO_ISO15693_RF_TECH) |
| 487 | digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_ISO15693, |
| 488 | digital_in_send_iso15693_inv_req); |
| 489 | |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 490 | if (tm_protocols & NFC_PROTO_NFC_DEP_MASK) { |
| 491 | if (ddev->ops->tg_listen_mdaa) { |
| 492 | digital_add_poll_tech(ddev, 0, |
| 493 | digital_tg_listen_mdaa); |
| 494 | } else { |
| 495 | digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_106A, |
| 496 | digital_tg_listen_nfca); |
| 497 | |
| 498 | digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_212F, |
| 499 | digital_tg_listen_nfcf); |
| 500 | |
| 501 | digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_424F, |
| 502 | digital_tg_listen_nfcf); |
| 503 | } |
| 504 | } |
| 505 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 506 | if (!ddev->poll_tech_count) { |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 507 | pr_err("Unsupported protocols: im=0x%x, tm=0x%x\n", |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 508 | matching_im_protocols, matching_tm_protocols); |
| 509 | return -EINVAL; |
| 510 | } |
| 511 | |
| 512 | schedule_work(&ddev->poll_work); |
| 513 | |
| 514 | return 0; |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static void digital_stop_poll(struct nfc_dev *nfc_dev) |
| 518 | { |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 519 | struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev); |
| 520 | |
| 521 | mutex_lock(&ddev->poll_lock); |
| 522 | |
| 523 | if (!ddev->poll_tech_count) { |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 524 | pr_err("Polling operation was not running\n"); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 525 | mutex_unlock(&ddev->poll_lock); |
| 526 | return; |
| 527 | } |
| 528 | |
| 529 | ddev->poll_tech_count = 0; |
| 530 | |
| 531 | mutex_unlock(&ddev->poll_lock); |
| 532 | |
| 533 | cancel_work_sync(&ddev->poll_work); |
| 534 | |
| 535 | digital_abort_cmd(ddev); |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static int digital_dev_up(struct nfc_dev *nfc_dev) |
| 539 | { |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 540 | struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev); |
| 541 | |
| 542 | digital_switch_rf(ddev, 1); |
| 543 | |
| 544 | return 0; |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | static int digital_dev_down(struct nfc_dev *nfc_dev) |
| 548 | { |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 549 | struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev); |
| 550 | |
| 551 | digital_switch_rf(ddev, 0); |
| 552 | |
| 553 | return 0; |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static int digital_dep_link_up(struct nfc_dev *nfc_dev, |
| 557 | struct nfc_target *target, |
| 558 | __u8 comm_mode, __u8 *gb, size_t gb_len) |
| 559 | { |
Thierry Escande | 7d0911c | 2013-09-19 17:55:29 +0200 | [diff] [blame] | 560 | struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev); |
Thierry Escande | 48e1044 | 2014-01-06 23:34:37 +0100 | [diff] [blame] | 561 | int rc; |
Thierry Escande | 7d0911c | 2013-09-19 17:55:29 +0200 | [diff] [blame] | 562 | |
Thierry Escande | 48e1044 | 2014-01-06 23:34:37 +0100 | [diff] [blame] | 563 | rc = digital_in_send_atr_req(ddev, target, comm_mode, gb, gb_len); |
| 564 | |
| 565 | if (!rc) |
| 566 | ddev->curr_protocol = NFC_PROTO_NFC_DEP; |
| 567 | |
| 568 | return rc; |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | static int digital_dep_link_down(struct nfc_dev *nfc_dev) |
| 572 | { |
Thierry Escande | 7d0911c | 2013-09-19 17:55:29 +0200 | [diff] [blame] | 573 | struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev); |
| 574 | |
| 575 | ddev->curr_protocol = 0; |
| 576 | |
| 577 | return 0; |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static int digital_activate_target(struct nfc_dev *nfc_dev, |
| 581 | struct nfc_target *target, __u32 protocol) |
| 582 | { |
Thierry Escande | 48e1044 | 2014-01-06 23:34:37 +0100 | [diff] [blame] | 583 | struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev); |
| 584 | |
| 585 | if (ddev->poll_tech_count) { |
| 586 | pr_err("Can't activate a target while polling\n"); |
| 587 | return -EBUSY; |
| 588 | } |
| 589 | |
| 590 | if (ddev->curr_protocol) { |
| 591 | pr_err("A target is already active\n"); |
| 592 | return -EBUSY; |
| 593 | } |
| 594 | |
| 595 | ddev->curr_protocol = protocol; |
| 596 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 597 | return 0; |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static void digital_deactivate_target(struct nfc_dev *nfc_dev, |
| 601 | struct nfc_target *target) |
| 602 | { |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 603 | struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev); |
| 604 | |
Thierry Escande | 48e1044 | 2014-01-06 23:34:37 +0100 | [diff] [blame] | 605 | if (!ddev->curr_protocol) { |
| 606 | pr_err("No active target\n"); |
| 607 | return; |
| 608 | } |
| 609 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 610 | ddev->curr_protocol = 0; |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | static int digital_tg_send(struct nfc_dev *dev, struct sk_buff *skb) |
| 614 | { |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 615 | struct nfc_digital_dev *ddev = nfc_get_drvdata(dev); |
| 616 | |
| 617 | return digital_tg_send_dep_res(ddev, skb); |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 618 | } |
| 619 | |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 620 | static void digital_in_send_complete(struct nfc_digital_dev *ddev, void *arg, |
| 621 | struct sk_buff *resp) |
| 622 | { |
| 623 | struct digital_data_exch *data_exch = arg; |
| 624 | int rc; |
| 625 | |
| 626 | if (IS_ERR(resp)) { |
| 627 | rc = PTR_ERR(resp); |
Thierry Escande | c813007 | 2014-01-27 00:31:32 +0100 | [diff] [blame] | 628 | resp = NULL; |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 629 | goto done; |
| 630 | } |
| 631 | |
Thierry Escande | c813007 | 2014-01-27 00:31:32 +0100 | [diff] [blame] | 632 | if (ddev->curr_protocol == NFC_PROTO_MIFARE) { |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 633 | rc = digital_in_recv_mifare_res(resp); |
Thierry Escande | c813007 | 2014-01-27 00:31:32 +0100 | [diff] [blame] | 634 | /* crc check is done in digital_in_recv_mifare_res() */ |
| 635 | goto done; |
| 636 | } |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 637 | |
Thierry Escande | c813007 | 2014-01-27 00:31:32 +0100 | [diff] [blame] | 638 | if (ddev->curr_protocol == NFC_PROTO_ISO14443) { |
| 639 | rc = digital_in_iso_dep_pull_sod(ddev, resp); |
| 640 | if (rc) |
| 641 | goto done; |
| 642 | } |
| 643 | |
| 644 | rc = ddev->skb_check_crc(resp); |
| 645 | |
| 646 | done: |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 647 | if (rc) { |
| 648 | kfree_skb(resp); |
| 649 | resp = NULL; |
| 650 | } |
| 651 | |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 652 | data_exch->cb(data_exch->cb_context, resp, rc); |
| 653 | |
| 654 | kfree(data_exch); |
| 655 | } |
| 656 | |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 657 | static int digital_in_send(struct nfc_dev *nfc_dev, struct nfc_target *target, |
| 658 | struct sk_buff *skb, data_exchange_cb_t cb, |
| 659 | void *cb_context) |
| 660 | { |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 661 | struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev); |
| 662 | struct digital_data_exch *data_exch; |
Thierry Escande | c813007 | 2014-01-27 00:31:32 +0100 | [diff] [blame] | 663 | int rc; |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 664 | |
| 665 | data_exch = kzalloc(sizeof(struct digital_data_exch), GFP_KERNEL); |
| 666 | if (!data_exch) { |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 667 | pr_err("Failed to allocate data_exch struct\n"); |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 668 | return -ENOMEM; |
| 669 | } |
| 670 | |
| 671 | data_exch->cb = cb; |
| 672 | data_exch->cb_context = cb_context; |
| 673 | |
Thierry Escande | 6ea7398 | 2014-02-12 14:27:51 +0100 | [diff] [blame^] | 674 | if (ddev->curr_protocol == NFC_PROTO_NFC_DEP) { |
| 675 | rc = digital_in_send_dep_req(ddev, target, skb, data_exch); |
| 676 | goto exit; |
| 677 | } |
Thierry Escande | 7d0911c | 2013-09-19 17:55:29 +0200 | [diff] [blame] | 678 | |
Thierry Escande | c813007 | 2014-01-27 00:31:32 +0100 | [diff] [blame] | 679 | if (ddev->curr_protocol == NFC_PROTO_ISO14443) { |
| 680 | rc = digital_in_iso_dep_push_sod(ddev, skb); |
| 681 | if (rc) |
Thierry Escande | 6ea7398 | 2014-02-12 14:27:51 +0100 | [diff] [blame^] | 682 | goto exit; |
Thierry Escande | c813007 | 2014-01-27 00:31:32 +0100 | [diff] [blame] | 683 | } |
| 684 | |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame] | 685 | ddev->skb_add_crc(skb); |
| 686 | |
Thierry Escande | 6ea7398 | 2014-02-12 14:27:51 +0100 | [diff] [blame^] | 687 | rc = digital_in_send_cmd(ddev, skb, 500, digital_in_send_complete, |
| 688 | data_exch); |
| 689 | |
| 690 | exit: |
| 691 | if (rc) |
| 692 | kfree(data_exch); |
| 693 | |
| 694 | return rc; |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | static struct nfc_ops digital_nfc_ops = { |
| 698 | .dev_up = digital_dev_up, |
| 699 | .dev_down = digital_dev_down, |
| 700 | .start_poll = digital_start_poll, |
| 701 | .stop_poll = digital_stop_poll, |
| 702 | .dep_link_up = digital_dep_link_up, |
| 703 | .dep_link_down = digital_dep_link_down, |
| 704 | .activate_target = digital_activate_target, |
| 705 | .deactivate_target = digital_deactivate_target, |
| 706 | .tm_send = digital_tg_send, |
| 707 | .im_transceive = digital_in_send, |
| 708 | }; |
| 709 | |
| 710 | struct nfc_digital_dev *nfc_digital_allocate_device(struct nfc_digital_ops *ops, |
| 711 | __u32 supported_protocols, |
| 712 | __u32 driver_capabilities, |
| 713 | int tx_headroom, int tx_tailroom) |
| 714 | { |
| 715 | struct nfc_digital_dev *ddev; |
| 716 | |
| 717 | if (!ops->in_configure_hw || !ops->in_send_cmd || !ops->tg_listen || |
| 718 | !ops->tg_configure_hw || !ops->tg_send_cmd || !ops->abort_cmd || |
| 719 | !ops->switch_rf) |
| 720 | return NULL; |
| 721 | |
| 722 | ddev = kzalloc(sizeof(struct nfc_digital_dev), GFP_KERNEL); |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 723 | if (!ddev) |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 724 | return NULL; |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 725 | |
| 726 | ddev->driver_capabilities = driver_capabilities; |
| 727 | ddev->ops = ops; |
| 728 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 729 | mutex_init(&ddev->cmd_lock); |
| 730 | INIT_LIST_HEAD(&ddev->cmd_queue); |
| 731 | |
| 732 | INIT_WORK(&ddev->cmd_work, digital_wq_cmd); |
| 733 | INIT_WORK(&ddev->cmd_complete_work, digital_wq_cmd_complete); |
| 734 | |
| 735 | mutex_init(&ddev->poll_lock); |
| 736 | INIT_WORK(&ddev->poll_work, digital_wq_poll); |
| 737 | |
| 738 | if (supported_protocols & NFC_PROTO_JEWEL_MASK) |
| 739 | ddev->protocols |= NFC_PROTO_JEWEL_MASK; |
| 740 | if (supported_protocols & NFC_PROTO_MIFARE_MASK) |
| 741 | ddev->protocols |= NFC_PROTO_MIFARE_MASK; |
Thierry Escande | 8c0695e4 | 2013-09-19 17:55:28 +0200 | [diff] [blame] | 742 | if (supported_protocols & NFC_PROTO_FELICA_MASK) |
| 743 | ddev->protocols |= NFC_PROTO_FELICA_MASK; |
Thierry Escande | 7d0911c | 2013-09-19 17:55:29 +0200 | [diff] [blame] | 744 | if (supported_protocols & NFC_PROTO_NFC_DEP_MASK) |
| 745 | ddev->protocols |= NFC_PROTO_NFC_DEP_MASK; |
Mark A. Greer | a381d48 | 2014-01-21 16:23:59 -0700 | [diff] [blame] | 746 | if (supported_protocols & NFC_PROTO_ISO15693_MASK) |
| 747 | ddev->protocols |= NFC_PROTO_ISO15693_MASK; |
Thierry Escande | 12e3d24 | 2014-01-27 00:31:31 +0100 | [diff] [blame] | 748 | if (supported_protocols & NFC_PROTO_ISO14443_MASK) |
| 749 | ddev->protocols |= NFC_PROTO_ISO14443_MASK; |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 750 | |
| 751 | ddev->tx_headroom = tx_headroom + DIGITAL_MAX_HEADER_LEN; |
| 752 | ddev->tx_tailroom = tx_tailroom + DIGITAL_CRC_LEN; |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 753 | |
| 754 | ddev->nfc_dev = nfc_allocate_device(&digital_nfc_ops, ddev->protocols, |
| 755 | ddev->tx_headroom, |
| 756 | ddev->tx_tailroom); |
| 757 | if (!ddev->nfc_dev) { |
Samuel Ortiz | 2604253 | 2013-09-20 16:56:40 +0200 | [diff] [blame] | 758 | pr_err("nfc_allocate_device failed\n"); |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 759 | goto free_dev; |
| 760 | } |
| 761 | |
| 762 | nfc_set_drvdata(ddev->nfc_dev, ddev); |
| 763 | |
| 764 | return ddev; |
| 765 | |
| 766 | free_dev: |
| 767 | kfree(ddev); |
| 768 | |
| 769 | return NULL; |
| 770 | } |
| 771 | EXPORT_SYMBOL(nfc_digital_allocate_device); |
| 772 | |
| 773 | void nfc_digital_free_device(struct nfc_digital_dev *ddev) |
| 774 | { |
| 775 | nfc_free_device(ddev->nfc_dev); |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 776 | kfree(ddev); |
| 777 | } |
| 778 | EXPORT_SYMBOL(nfc_digital_free_device); |
| 779 | |
| 780 | int nfc_digital_register_device(struct nfc_digital_dev *ddev) |
| 781 | { |
| 782 | return nfc_register_device(ddev->nfc_dev); |
| 783 | } |
| 784 | EXPORT_SYMBOL(nfc_digital_register_device); |
| 785 | |
| 786 | void nfc_digital_unregister_device(struct nfc_digital_dev *ddev) |
| 787 | { |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 788 | struct digital_cmd *cmd, *n; |
| 789 | |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 790 | nfc_unregister_device(ddev->nfc_dev); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 791 | |
| 792 | mutex_lock(&ddev->poll_lock); |
| 793 | ddev->poll_tech_count = 0; |
| 794 | mutex_unlock(&ddev->poll_lock); |
| 795 | |
| 796 | cancel_work_sync(&ddev->poll_work); |
| 797 | cancel_work_sync(&ddev->cmd_work); |
| 798 | cancel_work_sync(&ddev->cmd_complete_work); |
| 799 | |
| 800 | list_for_each_entry_safe(cmd, n, &ddev->cmd_queue, queue) { |
| 801 | list_del(&cmd->queue); |
Thierry Escande | 1c7a4c2 | 2013-09-19 17:55:30 +0200 | [diff] [blame] | 802 | kfree(cmd->mdaa_params); |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 803 | kfree(cmd); |
| 804 | } |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 805 | } |
| 806 | EXPORT_SYMBOL(nfc_digital_unregister_device); |
| 807 | |
| 808 | MODULE_LICENSE("GPL"); |