Lines Matching refs:dev
22 #define DEV_ERR(_dev, fmt, args...) nfc_err(&_dev->nfc_dev->dev, \
25 #define DEV_DBG(_dev, fmt, args...) dev_dbg(&_dev->nfc_dev->dev, \
65 static void nfcsim_cleanup_dev(struct nfcsim *dev, u8 shutdown) in nfcsim_cleanup_dev() argument
67 DEV_DBG(dev, "shutdown=%d\n", shutdown); in nfcsim_cleanup_dev()
69 mutex_lock(&dev->lock); in nfcsim_cleanup_dev()
71 dev->polling_mode = NFCSIM_POLL_NONE; in nfcsim_cleanup_dev()
72 dev->shutting_down = shutdown; in nfcsim_cleanup_dev()
73 dev->cb = NULL; in nfcsim_cleanup_dev()
74 dev_kfree_skb(dev->clone_skb); in nfcsim_cleanup_dev()
75 dev->clone_skb = NULL; in nfcsim_cleanup_dev()
77 mutex_unlock(&dev->lock); in nfcsim_cleanup_dev()
79 cancel_delayed_work_sync(&dev->poll_work); in nfcsim_cleanup_dev()
80 cancel_delayed_work_sync(&dev->recv_work); in nfcsim_cleanup_dev()
83 static int nfcsim_target_found(struct nfcsim *dev) in nfcsim_target_found() argument
87 DEV_DBG(dev, "\n"); in nfcsim_target_found()
92 nfc_targets_found(dev->nfc_dev, &nfc_tgt, 1); in nfcsim_target_found()
99 struct nfcsim *dev = nfc_get_drvdata(nfc_dev); in nfcsim_dev_up() local
101 DEV_DBG(dev, "\n"); in nfcsim_dev_up()
103 mutex_lock(&dev->lock); in nfcsim_dev_up()
105 dev->up = 1; in nfcsim_dev_up()
107 mutex_unlock(&dev->lock); in nfcsim_dev_up()
114 struct nfcsim *dev = nfc_get_drvdata(nfc_dev); in nfcsim_dev_down() local
116 DEV_DBG(dev, "\n"); in nfcsim_dev_down()
118 mutex_lock(&dev->lock); in nfcsim_dev_down()
120 dev->up = 0; in nfcsim_dev_down()
122 mutex_unlock(&dev->lock); in nfcsim_dev_down()
132 struct nfcsim *dev = nfc_get_drvdata(nfc_dev); in nfcsim_dep_link_up() local
133 struct nfcsim *peer = dev->peer_dev; in nfcsim_dep_link_up()
137 DEV_DBG(dev, "target_idx: %d, comm_mode: %d\n", target->idx, comm_mode); in nfcsim_dep_link_up()
154 mutex_lock(&dev->lock); in nfcsim_dep_link_up()
158 DEV_ERR(dev, "Can't set remote general bytes\n"); in nfcsim_dep_link_up()
159 mutex_unlock(&dev->lock); in nfcsim_dep_link_up()
166 mutex_unlock(&dev->lock); in nfcsim_dep_link_up()
173 struct nfcsim *dev = nfc_get_drvdata(nfc_dev); in nfcsim_dep_link_down() local
175 DEV_DBG(dev, "\n"); in nfcsim_dep_link_down()
177 nfcsim_cleanup_dev(dev, 0); in nfcsim_dep_link_down()
185 struct nfcsim *dev = nfc_get_drvdata(nfc_dev); in nfcsim_start_poll() local
188 mutex_lock(&dev->lock); in nfcsim_start_poll()
190 if (dev->polling_mode != NFCSIM_POLL_NONE) { in nfcsim_start_poll()
191 DEV_ERR(dev, "Already in polling mode\n"); in nfcsim_start_poll()
197 dev->polling_mode |= NFCSIM_POLL_INITIATOR; in nfcsim_start_poll()
200 dev->polling_mode |= NFCSIM_POLL_TARGET; in nfcsim_start_poll()
202 if (dev->polling_mode == NFCSIM_POLL_NONE) { in nfcsim_start_poll()
203 DEV_ERR(dev, "Unsupported polling mode\n"); in nfcsim_start_poll()
208 dev->initiator = 0; in nfcsim_start_poll()
209 dev->curr_polling_mode = NFCSIM_POLL_NONE; in nfcsim_start_poll()
211 queue_delayed_work(wq, &dev->poll_work, 0); in nfcsim_start_poll()
213 DEV_DBG(dev, "Start polling: im: 0x%X, tm: 0x%X\n", im_protocols, in nfcsim_start_poll()
218 mutex_unlock(&dev->lock); in nfcsim_start_poll()
225 struct nfcsim *dev = nfc_get_drvdata(nfc_dev); in nfcsim_stop_poll() local
227 DEV_DBG(dev, "Stop poll\n"); in nfcsim_stop_poll()
229 mutex_lock(&dev->lock); in nfcsim_stop_poll()
231 dev->polling_mode = NFCSIM_POLL_NONE; in nfcsim_stop_poll()
233 mutex_unlock(&dev->lock); in nfcsim_stop_poll()
235 cancel_delayed_work_sync(&dev->poll_work); in nfcsim_stop_poll()
241 struct nfcsim *dev = nfc_get_drvdata(nfc_dev); in nfcsim_activate_target() local
243 DEV_DBG(dev, "\n"); in nfcsim_activate_target()
251 struct nfcsim *dev = nfc_get_drvdata(nfc_dev); in nfcsim_deactivate_target() local
253 DEV_DBG(dev, "\n"); in nfcsim_deactivate_target()
258 struct nfcsim *dev = container_of(work, struct nfcsim, in nfcsim_wq_recv() local
261 mutex_lock(&dev->lock); in nfcsim_wq_recv()
263 if (dev->shutting_down || !dev->up || !dev->clone_skb) { in nfcsim_wq_recv()
264 dev_kfree_skb(dev->clone_skb); in nfcsim_wq_recv()
268 if (dev->initiator) { in nfcsim_wq_recv()
269 if (!dev->cb) { in nfcsim_wq_recv()
270 DEV_ERR(dev, "Null recv callback\n"); in nfcsim_wq_recv()
271 dev_kfree_skb(dev->clone_skb); in nfcsim_wq_recv()
275 dev->cb(dev->cb_context, dev->clone_skb, 0); in nfcsim_wq_recv()
276 dev->cb = NULL; in nfcsim_wq_recv()
278 nfc_tm_data_received(dev->nfc_dev, dev->clone_skb); in nfcsim_wq_recv()
282 dev->clone_skb = NULL; in nfcsim_wq_recv()
284 mutex_unlock(&dev->lock); in nfcsim_wq_recv()
291 struct nfcsim *dev = nfc_get_drvdata(nfc_dev); in nfcsim_tx() local
292 struct nfcsim *peer = dev->peer_dev; in nfcsim_tx()
295 mutex_lock(&dev->lock); in nfcsim_tx()
297 if (dev->shutting_down || !dev->up) { in nfcsim_tx()
298 mutex_unlock(&dev->lock); in nfcsim_tx()
303 dev->cb = cb; in nfcsim_tx()
304 dev->cb_context = cb_context; in nfcsim_tx()
306 mutex_unlock(&dev->lock); in nfcsim_tx()
313 DEV_ERR(dev, "skb_clone failed\n"); in nfcsim_tx()
362 static void nfcsim_set_polling_mode(struct nfcsim *dev) in nfcsim_set_polling_mode() argument
364 if (dev->polling_mode == NFCSIM_POLL_NONE) { in nfcsim_set_polling_mode()
365 dev->curr_polling_mode = NFCSIM_POLL_NONE; in nfcsim_set_polling_mode()
369 if (dev->curr_polling_mode == NFCSIM_POLL_NONE) { in nfcsim_set_polling_mode()
370 if (dev->polling_mode & NFCSIM_POLL_INITIATOR) in nfcsim_set_polling_mode()
371 dev->curr_polling_mode = NFCSIM_POLL_INITIATOR; in nfcsim_set_polling_mode()
373 dev->curr_polling_mode = NFCSIM_POLL_TARGET; in nfcsim_set_polling_mode()
378 if (dev->polling_mode == NFCSIM_POLL_DUAL) { in nfcsim_set_polling_mode()
379 if (dev->curr_polling_mode == NFCSIM_POLL_TARGET) in nfcsim_set_polling_mode()
380 dev->curr_polling_mode = NFCSIM_POLL_INITIATOR; in nfcsim_set_polling_mode()
382 dev->curr_polling_mode = NFCSIM_POLL_TARGET; in nfcsim_set_polling_mode()
388 struct nfcsim *dev = container_of(work, struct nfcsim, poll_work.work); in nfcsim_wq_poll() local
389 struct nfcsim *peer = dev->peer_dev; in nfcsim_wq_poll()
394 mutex_lock(&dev->lock); in nfcsim_wq_poll()
397 nfcsim_set_polling_mode(dev); in nfcsim_wq_poll()
399 if (dev->curr_polling_mode == NFCSIM_POLL_NONE) { in nfcsim_wq_poll()
400 DEV_DBG(dev, "Not polling\n"); in nfcsim_wq_poll()
404 DEV_DBG(dev, "Polling as %s", in nfcsim_wq_poll()
405 dev->curr_polling_mode == NFCSIM_POLL_INITIATOR ? in nfcsim_wq_poll()
408 if (dev->curr_polling_mode == NFCSIM_POLL_TARGET) in nfcsim_wq_poll()
413 dev->polling_mode = NFCSIM_POLL_NONE; in nfcsim_wq_poll()
415 dev->initiator = 1; in nfcsim_wq_poll()
417 nfcsim_target_found(dev); in nfcsim_wq_poll()
431 queue_delayed_work(wq, &dev->poll_work, msecs_to_jiffies(200)); in nfcsim_wq_poll()
435 mutex_unlock(&dev->lock); in nfcsim_wq_poll()
440 struct nfcsim *dev; in nfcsim_init_dev() local
443 dev = kzalloc(sizeof(*dev), GFP_KERNEL); in nfcsim_init_dev()
444 if (dev == NULL) in nfcsim_init_dev()
447 mutex_init(&dev->lock); in nfcsim_init_dev()
449 INIT_DELAYED_WORK(&dev->recv_work, nfcsim_wq_recv); in nfcsim_init_dev()
450 INIT_DELAYED_WORK(&dev->poll_work, nfcsim_wq_poll); in nfcsim_init_dev()
452 dev->nfc_dev = nfc_allocate_device(&nfcsim_nfc_ops, in nfcsim_init_dev()
455 if (!dev->nfc_dev) in nfcsim_init_dev()
458 nfc_set_drvdata(dev->nfc_dev, dev); in nfcsim_init_dev()
460 rc = nfc_register_device(dev->nfc_dev); in nfcsim_init_dev()
464 return dev; in nfcsim_init_dev()
467 nfc_free_device(dev->nfc_dev); in nfcsim_init_dev()
470 kfree(dev); in nfcsim_init_dev()
475 static void nfcsim_free_device(struct nfcsim *dev) in nfcsim_free_device() argument
477 nfc_unregister_device(dev->nfc_dev); in nfcsim_free_device()
479 nfc_free_device(dev->nfc_dev); in nfcsim_free_device()
481 kfree(dev); in nfcsim_free_device()