Lines Matching +full:d +full:- +full:link
1 // SPDX-License-Identifier: GPL-2.0-only
16 #define NFCSIM_ERR(d, fmt, args...) nfc_err(&d->nfc_digital_dev->nfc_dev->dev, \ argument
19 #define NFCSIM_DBG(d, fmt, args...) dev_dbg(&d->nfc_digital_dev->nfc_dev->dev, \ argument
67 struct nfcsim_link *link; in nfcsim_link_new() local
69 link = kzalloc(sizeof(struct nfcsim_link), GFP_KERNEL); in nfcsim_link_new()
70 if (!link) in nfcsim_link_new()
73 mutex_init(&link->lock); in nfcsim_link_new()
74 init_waitqueue_head(&link->recv_wait); in nfcsim_link_new()
76 return link; in nfcsim_link_new()
79 static void nfcsim_link_free(struct nfcsim_link *link) in nfcsim_link_free() argument
81 dev_kfree_skb(link->skb); in nfcsim_link_free()
82 kfree(link); in nfcsim_link_free()
85 static void nfcsim_link_recv_wake(struct nfcsim_link *link) in nfcsim_link_recv_wake() argument
87 link->cond = 1; in nfcsim_link_recv_wake()
88 wake_up_interruptible(&link->recv_wait); in nfcsim_link_recv_wake()
91 static void nfcsim_link_set_skb(struct nfcsim_link *link, struct sk_buff *skb, in nfcsim_link_set_skb() argument
94 mutex_lock(&link->lock); in nfcsim_link_set_skb()
96 dev_kfree_skb(link->skb); in nfcsim_link_set_skb()
97 link->skb = skb; in nfcsim_link_set_skb()
98 link->rf_tech = rf_tech; in nfcsim_link_set_skb()
99 link->mode = mode; in nfcsim_link_set_skb()
101 mutex_unlock(&link->lock); in nfcsim_link_set_skb()
104 static void nfcsim_link_recv_cancel(struct nfcsim_link *link) in nfcsim_link_recv_cancel() argument
106 mutex_lock(&link->lock); in nfcsim_link_recv_cancel()
108 link->mode = NFCSIM_MODE_NONE; in nfcsim_link_recv_cancel()
110 mutex_unlock(&link->lock); in nfcsim_link_recv_cancel()
112 nfcsim_link_recv_wake(link); in nfcsim_link_recv_cancel()
115 static void nfcsim_link_shutdown(struct nfcsim_link *link) in nfcsim_link_shutdown() argument
117 mutex_lock(&link->lock); in nfcsim_link_shutdown()
119 link->shutdown = 1; in nfcsim_link_shutdown()
120 link->mode = NFCSIM_MODE_NONE; in nfcsim_link_shutdown()
122 mutex_unlock(&link->lock); in nfcsim_link_shutdown()
124 nfcsim_link_recv_wake(link); in nfcsim_link_shutdown()
127 static struct sk_buff *nfcsim_link_recv_skb(struct nfcsim_link *link, in nfcsim_link_recv_skb() argument
133 rc = wait_event_interruptible_timeout(link->recv_wait, in nfcsim_link_recv_skb()
134 link->cond, in nfcsim_link_recv_skb()
137 mutex_lock(&link->lock); in nfcsim_link_recv_skb()
139 skb = link->skb; in nfcsim_link_recv_skb()
140 link->skb = NULL; in nfcsim_link_recv_skb()
143 rc = -ETIMEDOUT; in nfcsim_link_recv_skb()
147 if (!skb || link->rf_tech != rf_tech || link->mode == mode) { in nfcsim_link_recv_skb()
148 rc = -EINVAL; in nfcsim_link_recv_skb()
152 if (link->shutdown) { in nfcsim_link_recv_skb()
153 rc = -ENODEV; in nfcsim_link_recv_skb()
158 mutex_unlock(&link->lock); in nfcsim_link_recv_skb()
165 link->cond = 0; in nfcsim_link_recv_skb()
177 * stored in the dev->link_out through nfcsim_link_set_skb(). in nfcsim_send_wq()
179 nfcsim_link_recv_wake(dev->link_out); in nfcsim_send_wq()
187 skb = nfcsim_link_recv_skb(dev->link_in, dev->recv_timeout, in nfcsim_recv_wq()
188 dev->rf_tech, dev->mode); in nfcsim_recv_wq()
190 if (!dev->up) { in nfcsim_recv_wq()
198 dev->cb(dev->nfc_digital_dev, dev->arg, skb); in nfcsim_recv_wq()
207 if (!dev->up) { in nfcsim_send()
209 return -ENODEV; in nfcsim_send()
212 dev->recv_timeout = timeout; in nfcsim_send()
213 dev->cb = cb; in nfcsim_send()
214 dev->arg = arg; in nfcsim_send()
216 schedule_work(&dev->recv_work); in nfcsim_send()
218 if (dev->dropframe) { in nfcsim_send()
219 NFCSIM_DBG(dev, "dropping frame (out of %d)\n", dev->dropframe); in nfcsim_send()
221 dev->dropframe--; in nfcsim_send()
227 nfcsim_link_set_skb(dev->link_out, skb, dev->rf_tech, in nfcsim_send()
228 dev->mode); in nfcsim_send()
234 schedule_delayed_work(&dev->send_work, msecs_to_jiffies(delay)); in nfcsim_send()
244 nfcsim_link_recv_cancel(dev->link_in); in nfcsim_abort_cmd()
251 dev->up = on; in nfcsim_switch_rf()
263 dev->up = true; in nfcsim_in_configure_hw()
264 dev->mode = NFCSIM_MODE_INITIATOR; in nfcsim_in_configure_hw()
265 dev->rf_tech = param; in nfcsim_in_configure_hw()
272 NFCSIM_ERR(dev, "Invalid configuration type: %d\n", type); in nfcsim_in_configure_hw()
273 return -EINVAL; in nfcsim_in_configure_hw()
293 dev->up = true; in nfcsim_tg_configure_hw()
294 dev->mode = NFCSIM_MODE_TARGET; in nfcsim_tg_configure_hw()
295 dev->rf_tech = param; in nfcsim_tg_configure_hw()
302 NFCSIM_ERR(dev, "Invalid configuration type: %d\n", type); in nfcsim_tg_configure_hw()
303 return -EINVAL; in nfcsim_tg_configure_hw()
358 idx = dev->nfc_digital_dev->nfc_dev->idx; in nfcsim_debugfs_init_dev()
359 n = snprintf(devname, sizeof(devname), "nfc%d", idx); in nfcsim_debugfs_init_dev()
361 NFCSIM_ERR(dev, "Could not compute dev name for dev %d\n", idx); in nfcsim_debugfs_init_dev()
367 debugfs_create_u8("dropframe", 0664, dev_dir, &dev->dropframe); in nfcsim_debugfs_init_dev()
378 return ERR_PTR(-ENOMEM); in nfcsim_device_new()
380 INIT_DELAYED_WORK(&dev->send_work, nfcsim_send_wq); in nfcsim_device_new()
381 INIT_WORK(&dev->recv_work, nfcsim_recv_wq); in nfcsim_device_new()
383 dev->nfc_digital_dev = in nfcsim_device_new()
388 if (!dev->nfc_digital_dev) { in nfcsim_device_new()
390 return ERR_PTR(-ENOMEM); in nfcsim_device_new()
393 nfc_digital_set_drvdata(dev->nfc_digital_dev, dev); in nfcsim_device_new()
395 dev->link_in = link_in; in nfcsim_device_new()
396 dev->link_out = link_out; in nfcsim_device_new()
398 rc = nfc_digital_register_device(dev->nfc_digital_dev); in nfcsim_device_new()
400 pr_err("Could not register digital device (%d)\n", rc); in nfcsim_device_new()
401 nfc_digital_free_device(dev->nfc_digital_dev); in nfcsim_device_new()
414 nfc_digital_unregister_device(dev->nfc_digital_dev); in nfcsim_device_free()
416 dev->up = false; in nfcsim_device_free()
418 nfcsim_link_shutdown(dev->link_in); in nfcsim_device_free()
420 cancel_delayed_work_sync(&dev->send_work); in nfcsim_device_free()
421 cancel_work_sync(&dev->recv_work); in nfcsim_device_free()
423 nfc_digital_free_device(dev->nfc_digital_dev); in nfcsim_device_free()
439 rc = -ENOMEM; in nfcsim_init()
464 pr_err("Failed to initialize nfcsim driver (%d)\n", rc); in nfcsim_init()
478 link0 = dev0->link_in; in nfcsim_exit()
479 link1 = dev0->link_out; in nfcsim_exit()