Lines Matching refs:dev
33 int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) in nfc_fw_download() argument
37 pr_debug("%s do firmware %s\n", dev_name(&dev->dev), firmware_name); in nfc_fw_download()
39 device_lock(&dev->dev); in nfc_fw_download()
41 if (dev->shutting_down) { in nfc_fw_download()
46 if (dev->dev_up) { in nfc_fw_download()
51 if (!dev->ops->fw_download) { in nfc_fw_download()
56 dev->fw_download_in_progress = true; in nfc_fw_download()
57 rc = dev->ops->fw_download(dev, firmware_name); in nfc_fw_download()
59 dev->fw_download_in_progress = false; in nfc_fw_download()
62 device_unlock(&dev->dev); in nfc_fw_download()
73 int nfc_fw_download_done(struct nfc_dev *dev, const char *firmware_name, in nfc_fw_download_done() argument
76 dev->fw_download_in_progress = false; in nfc_fw_download_done()
78 return nfc_genl_fw_download_done(dev, firmware_name, result); in nfc_fw_download_done()
89 int nfc_dev_up(struct nfc_dev *dev) in nfc_dev_up() argument
93 pr_debug("dev_name=%s\n", dev_name(&dev->dev)); in nfc_dev_up()
95 device_lock(&dev->dev); in nfc_dev_up()
97 if (dev->shutting_down) { in nfc_dev_up()
102 if (dev->rfkill && rfkill_blocked(dev->rfkill)) { in nfc_dev_up()
107 if (dev->fw_download_in_progress) { in nfc_dev_up()
112 if (dev->dev_up) { in nfc_dev_up()
117 if (dev->ops->dev_up) in nfc_dev_up()
118 rc = dev->ops->dev_up(dev); in nfc_dev_up()
121 dev->dev_up = true; in nfc_dev_up()
124 if (dev->ops->discover_se && dev->ops->discover_se(dev)) in nfc_dev_up()
128 device_unlock(&dev->dev); in nfc_dev_up()
137 int nfc_dev_down(struct nfc_dev *dev) in nfc_dev_down() argument
141 pr_debug("dev_name=%s\n", dev_name(&dev->dev)); in nfc_dev_down()
143 device_lock(&dev->dev); in nfc_dev_down()
145 if (dev->shutting_down) { in nfc_dev_down()
150 if (!dev->dev_up) { in nfc_dev_down()
155 if (dev->polling || dev->active_target) { in nfc_dev_down()
160 if (dev->ops->dev_down) in nfc_dev_down()
161 dev->ops->dev_down(dev); in nfc_dev_down()
163 dev->dev_up = false; in nfc_dev_down()
166 device_unlock(&dev->dev); in nfc_dev_down()
172 struct nfc_dev *dev = data; in nfc_rfkill_set_block() local
174 pr_debug("%s blocked %d", dev_name(&dev->dev), blocked); in nfc_rfkill_set_block()
179 nfc_dev_down(dev); in nfc_rfkill_set_block()
198 int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols) in nfc_start_poll() argument
203 dev_name(&dev->dev), im_protocols, tm_protocols); in nfc_start_poll()
208 device_lock(&dev->dev); in nfc_start_poll()
210 if (dev->shutting_down) { in nfc_start_poll()
215 if (!dev->dev_up) { in nfc_start_poll()
220 if (dev->polling) { in nfc_start_poll()
225 rc = dev->ops->start_poll(dev, im_protocols, tm_protocols); in nfc_start_poll()
227 dev->polling = true; in nfc_start_poll()
228 dev->rf_mode = NFC_RF_NONE; in nfc_start_poll()
232 device_unlock(&dev->dev); in nfc_start_poll()
241 int nfc_stop_poll(struct nfc_dev *dev) in nfc_stop_poll() argument
245 pr_debug("dev_name=%s\n", dev_name(&dev->dev)); in nfc_stop_poll()
247 device_lock(&dev->dev); in nfc_stop_poll()
249 if (dev->shutting_down) { in nfc_stop_poll()
254 if (!dev->polling) { in nfc_stop_poll()
259 dev->ops->stop_poll(dev); in nfc_stop_poll()
260 dev->polling = false; in nfc_stop_poll()
261 dev->rf_mode = NFC_RF_NONE; in nfc_stop_poll()
264 device_unlock(&dev->dev); in nfc_stop_poll()
268 static struct nfc_target *nfc_find_target(struct nfc_dev *dev, u32 target_idx) in nfc_find_target() argument
272 for (i = 0; i < dev->n_targets; i++) { in nfc_find_target()
273 if (dev->targets[i].idx == target_idx) in nfc_find_target()
274 return &dev->targets[i]; in nfc_find_target()
280 int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode) in nfc_dep_link_up() argument
287 pr_debug("dev_name=%s comm %d\n", dev_name(&dev->dev), comm_mode); in nfc_dep_link_up()
289 if (!dev->ops->dep_link_up) in nfc_dep_link_up()
292 device_lock(&dev->dev); in nfc_dep_link_up()
294 if (dev->shutting_down) { in nfc_dep_link_up()
299 if (dev->dep_link_up == true) { in nfc_dep_link_up()
304 gb = nfc_llcp_general_bytes(dev, &gb_len); in nfc_dep_link_up()
310 target = nfc_find_target(dev, target_index); in nfc_dep_link_up()
316 rc = dev->ops->dep_link_up(dev, target, comm_mode, gb, gb_len); in nfc_dep_link_up()
318 dev->active_target = target; in nfc_dep_link_up()
319 dev->rf_mode = NFC_RF_INITIATOR; in nfc_dep_link_up()
323 device_unlock(&dev->dev); in nfc_dep_link_up()
327 int nfc_dep_link_down(struct nfc_dev *dev) in nfc_dep_link_down() argument
331 pr_debug("dev_name=%s\n", dev_name(&dev->dev)); in nfc_dep_link_down()
333 if (!dev->ops->dep_link_down) in nfc_dep_link_down()
336 device_lock(&dev->dev); in nfc_dep_link_down()
338 if (dev->shutting_down) { in nfc_dep_link_down()
343 if (dev->dep_link_up == false) { in nfc_dep_link_down()
348 rc = dev->ops->dep_link_down(dev); in nfc_dep_link_down()
350 dev->dep_link_up = false; in nfc_dep_link_down()
351 dev->active_target = NULL; in nfc_dep_link_down()
352 dev->rf_mode = NFC_RF_NONE; in nfc_dep_link_down()
353 nfc_llcp_mac_is_down(dev); in nfc_dep_link_down()
354 nfc_genl_dep_link_down_event(dev); in nfc_dep_link_down()
358 device_unlock(&dev->dev); in nfc_dep_link_down()
363 int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx, in nfc_dep_link_is_up() argument
366 dev->dep_link_up = true; in nfc_dep_link_is_up()
368 if (!dev->active_target && rf_mode == NFC_RF_INITIATOR) { in nfc_dep_link_is_up()
371 target = nfc_find_target(dev, target_idx); in nfc_dep_link_is_up()
375 dev->active_target = target; in nfc_dep_link_is_up()
378 dev->polling = false; in nfc_dep_link_is_up()
379 dev->rf_mode = rf_mode; in nfc_dep_link_is_up()
381 nfc_llcp_mac_is_up(dev, target_idx, comm_mode, rf_mode); in nfc_dep_link_is_up()
383 return nfc_genl_dep_link_up_event(dev, target_idx, comm_mode, rf_mode); in nfc_dep_link_is_up()
394 int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol) in nfc_activate_target() argument
400 dev_name(&dev->dev), target_idx, protocol); in nfc_activate_target()
402 device_lock(&dev->dev); in nfc_activate_target()
404 if (dev->shutting_down) { in nfc_activate_target()
409 if (dev->active_target) { in nfc_activate_target()
414 target = nfc_find_target(dev, target_idx); in nfc_activate_target()
420 rc = dev->ops->activate_target(dev, target, protocol); in nfc_activate_target()
422 dev->active_target = target; in nfc_activate_target()
423 dev->rf_mode = NFC_RF_INITIATOR; in nfc_activate_target()
425 if (dev->ops->check_presence && !dev->shutting_down) in nfc_activate_target()
426 mod_timer(&dev->check_pres_timer, jiffies + in nfc_activate_target()
431 device_unlock(&dev->dev); in nfc_activate_target()
442 int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx, u8 mode) in nfc_deactivate_target() argument
447 dev_name(&dev->dev), target_idx); in nfc_deactivate_target()
449 device_lock(&dev->dev); in nfc_deactivate_target()
451 if (dev->shutting_down) { in nfc_deactivate_target()
456 if (dev->active_target == NULL) { in nfc_deactivate_target()
461 if (dev->active_target->idx != target_idx) { in nfc_deactivate_target()
466 if (dev->ops->check_presence) in nfc_deactivate_target()
467 del_timer_sync(&dev->check_pres_timer); in nfc_deactivate_target()
469 dev->ops->deactivate_target(dev, dev->active_target, mode); in nfc_deactivate_target()
470 dev->active_target = NULL; in nfc_deactivate_target()
473 device_unlock(&dev->dev); in nfc_deactivate_target()
488 int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb, in nfc_data_exchange() argument
494 dev_name(&dev->dev), target_idx, skb->len); in nfc_data_exchange()
496 device_lock(&dev->dev); in nfc_data_exchange()
498 if (dev->shutting_down) { in nfc_data_exchange()
504 if (dev->rf_mode == NFC_RF_INITIATOR && dev->active_target != NULL) { in nfc_data_exchange()
505 if (dev->active_target->idx != target_idx) { in nfc_data_exchange()
511 if (dev->ops->check_presence) in nfc_data_exchange()
512 del_timer_sync(&dev->check_pres_timer); in nfc_data_exchange()
514 rc = dev->ops->im_transceive(dev, dev->active_target, skb, cb, in nfc_data_exchange()
517 if (!rc && dev->ops->check_presence && !dev->shutting_down) in nfc_data_exchange()
518 mod_timer(&dev->check_pres_timer, jiffies + in nfc_data_exchange()
520 } else if (dev->rf_mode == NFC_RF_TARGET && dev->ops->tm_send != NULL) { in nfc_data_exchange()
521 rc = dev->ops->tm_send(dev, skb); in nfc_data_exchange()
530 device_unlock(&dev->dev); in nfc_data_exchange()
534 struct nfc_se *nfc_find_se(struct nfc_dev *dev, u32 se_idx) in nfc_find_se() argument
538 list_for_each_entry(se, &dev->secure_elements, list) in nfc_find_se()
546 int nfc_enable_se(struct nfc_dev *dev, u32 se_idx) in nfc_enable_se() argument
551 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); in nfc_enable_se()
553 device_lock(&dev->dev); in nfc_enable_se()
555 if (dev->shutting_down) { in nfc_enable_se()
560 if (!dev->dev_up) { in nfc_enable_se()
565 if (dev->polling) { in nfc_enable_se()
570 if (!dev->ops->enable_se || !dev->ops->disable_se) { in nfc_enable_se()
575 se = nfc_find_se(dev, se_idx); in nfc_enable_se()
586 rc = dev->ops->enable_se(dev, se_idx); in nfc_enable_se()
591 device_unlock(&dev->dev); in nfc_enable_se()
595 int nfc_disable_se(struct nfc_dev *dev, u32 se_idx) in nfc_disable_se() argument
600 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); in nfc_disable_se()
602 device_lock(&dev->dev); in nfc_disable_se()
604 if (dev->shutting_down) { in nfc_disable_se()
609 if (!dev->dev_up) { in nfc_disable_se()
614 if (!dev->ops->enable_se || !dev->ops->disable_se) { in nfc_disable_se()
619 se = nfc_find_se(dev, se_idx); in nfc_disable_se()
630 rc = dev->ops->disable_se(dev, se_idx); in nfc_disable_se()
635 device_unlock(&dev->dev); in nfc_disable_se()
639 int nfc_set_remote_general_bytes(struct nfc_dev *dev, const u8 *gb, u8 gb_len) in nfc_set_remote_general_bytes() argument
641 pr_debug("dev_name=%s gb_len=%d\n", dev_name(&dev->dev), gb_len); in nfc_set_remote_general_bytes()
643 return nfc_llcp_set_remote_gb(dev, gb, gb_len); in nfc_set_remote_general_bytes()
647 u8 *nfc_get_local_general_bytes(struct nfc_dev *dev, size_t *gb_len) in nfc_get_local_general_bytes() argument
649 pr_debug("dev_name=%s\n", dev_name(&dev->dev)); in nfc_get_local_general_bytes()
651 return nfc_llcp_general_bytes(dev, gb_len); in nfc_get_local_general_bytes()
655 int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb) in nfc_tm_data_received() argument
658 if (dev->dep_link_up == false) { in nfc_tm_data_received()
663 return nfc_llcp_data_received(dev, skb); in nfc_tm_data_received()
667 int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode, in nfc_tm_activated() argument
672 device_lock(&dev->dev); in nfc_tm_activated()
674 dev->polling = false; in nfc_tm_activated()
677 rc = nfc_set_remote_general_bytes(dev, gb, gb_len); in nfc_tm_activated()
682 dev->rf_mode = NFC_RF_TARGET; in nfc_tm_activated()
685 nfc_dep_link_is_up(dev, 0, comm_mode, NFC_RF_TARGET); in nfc_tm_activated()
687 rc = nfc_genl_tm_activated(dev, protocol); in nfc_tm_activated()
690 device_unlock(&dev->dev); in nfc_tm_activated()
696 int nfc_tm_deactivated(struct nfc_dev *dev) in nfc_tm_deactivated() argument
698 dev->dep_link_up = false; in nfc_tm_deactivated()
699 dev->rf_mode = NFC_RF_NONE; in nfc_tm_deactivated()
701 return nfc_genl_tm_deactivated(dev); in nfc_tm_deactivated()
714 struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk, in nfc_alloc_send_skb() argument
722 dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE; in nfc_alloc_send_skb()
726 skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE); in nfc_alloc_send_skb()
768 int nfc_targets_found(struct nfc_dev *dev, in nfc_targets_found() argument
773 pr_debug("dev_name=%s n_targets=%d\n", dev_name(&dev->dev), n_targets); in nfc_targets_found()
776 targets[i].idx = dev->target_next_idx++; in nfc_targets_found()
778 device_lock(&dev->dev); in nfc_targets_found()
780 if (dev->polling == false) { in nfc_targets_found()
781 device_unlock(&dev->dev); in nfc_targets_found()
785 dev->polling = false; in nfc_targets_found()
787 dev->targets_generation++; in nfc_targets_found()
789 kfree(dev->targets); in nfc_targets_found()
790 dev->targets = NULL; in nfc_targets_found()
793 dev->targets = kmemdup(targets, in nfc_targets_found()
797 if (!dev->targets) { in nfc_targets_found()
798 dev->n_targets = 0; in nfc_targets_found()
799 device_unlock(&dev->dev); in nfc_targets_found()
804 dev->n_targets = n_targets; in nfc_targets_found()
805 device_unlock(&dev->dev); in nfc_targets_found()
807 nfc_genl_targets_found(dev); in nfc_targets_found()
825 int nfc_target_lost(struct nfc_dev *dev, u32 target_idx) in nfc_target_lost() argument
830 pr_debug("dev_name %s n_target %d\n", dev_name(&dev->dev), target_idx); in nfc_target_lost()
832 device_lock(&dev->dev); in nfc_target_lost()
834 for (i = 0; i < dev->n_targets; i++) { in nfc_target_lost()
835 tg = &dev->targets[i]; in nfc_target_lost()
840 if (i == dev->n_targets) { in nfc_target_lost()
841 device_unlock(&dev->dev); in nfc_target_lost()
845 dev->targets_generation++; in nfc_target_lost()
846 dev->n_targets--; in nfc_target_lost()
847 dev->active_target = NULL; in nfc_target_lost()
849 if (dev->n_targets) { in nfc_target_lost()
850 memcpy(&dev->targets[i], &dev->targets[i + 1], in nfc_target_lost()
851 (dev->n_targets - i) * sizeof(struct nfc_target)); in nfc_target_lost()
853 kfree(dev->targets); in nfc_target_lost()
854 dev->targets = NULL; in nfc_target_lost()
857 device_unlock(&dev->dev); in nfc_target_lost()
859 nfc_genl_target_lost(dev, target_idx); in nfc_target_lost()
865 inline void nfc_driver_failure(struct nfc_dev *dev, int err) in nfc_driver_failure() argument
867 nfc_targets_found(dev, NULL, 0); in nfc_driver_failure()
871 int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type) in nfc_add_se() argument
876 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); in nfc_add_se()
878 se = nfc_find_se(dev, se_idx); in nfc_add_se()
891 list_add(&se->list, &dev->secure_elements); in nfc_add_se()
893 rc = nfc_genl_se_added(dev, se_idx, type); in nfc_add_se()
905 int nfc_remove_se(struct nfc_dev *dev, u32 se_idx) in nfc_remove_se() argument
910 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); in nfc_remove_se()
912 list_for_each_entry_safe(se, n, &dev->secure_elements, list) in nfc_remove_se()
914 rc = nfc_genl_se_removed(dev, se_idx); in nfc_remove_se()
928 int nfc_se_transaction(struct nfc_dev *dev, u8 se_idx, in nfc_se_transaction() argument
935 device_lock(&dev->dev); in nfc_se_transaction()
942 rc = nfc_genl_se_transaction(dev, se_idx, evt_transaction); in nfc_se_transaction()
944 device_unlock(&dev->dev); in nfc_se_transaction()
949 int nfc_se_connectivity(struct nfc_dev *dev, u8 se_idx) in nfc_se_connectivity() argument
955 device_lock(&dev->dev); in nfc_se_connectivity()
956 rc = nfc_genl_se_connectivity(dev, se_idx); in nfc_se_connectivity()
957 device_unlock(&dev->dev); in nfc_se_connectivity()
964 struct nfc_dev *dev = to_nfc_dev(d); in nfc_release() local
967 pr_debug("dev_name=%s\n", dev_name(&dev->dev)); in nfc_release()
969 nfc_genl_data_exit(&dev->genl_data); in nfc_release()
970 kfree(dev->targets); in nfc_release()
972 list_for_each_entry_safe(se, n, &dev->secure_elements, list) { in nfc_release()
973 nfc_genl_se_removed(dev, se->idx); in nfc_release()
978 ida_free(&nfc_index_ida, dev->idx); in nfc_release()
980 kfree(dev); in nfc_release()
985 struct nfc_dev *dev = container_of(work, struct nfc_dev, in nfc_check_pres_work() local
989 device_lock(&dev->dev); in nfc_check_pres_work()
991 if (dev->active_target && timer_pending(&dev->check_pres_timer) == 0) { in nfc_check_pres_work()
992 rc = dev->ops->check_presence(dev, dev->active_target); in nfc_check_pres_work()
996 u32 active_target_idx = dev->active_target->idx; in nfc_check_pres_work()
997 device_unlock(&dev->dev); in nfc_check_pres_work()
998 nfc_target_lost(dev, active_target_idx); in nfc_check_pres_work()
1002 if (!dev->shutting_down) in nfc_check_pres_work()
1003 mod_timer(&dev->check_pres_timer, jiffies + in nfc_check_pres_work()
1008 device_unlock(&dev->dev); in nfc_check_pres_work()
1013 struct nfc_dev *dev = from_timer(dev, t, check_pres_timer); in nfc_check_pres_timeout() local
1015 schedule_work(&dev->check_pres_work); in nfc_check_pres_timeout()
1026 struct nfc_dev *dev = to_nfc_dev(d); in match_idx() local
1029 return dev->idx == *idx; in match_idx()
1055 struct nfc_dev *dev; in nfc_allocate_device() local
1065 dev = kzalloc(sizeof(struct nfc_dev), GFP_KERNEL); in nfc_allocate_device()
1066 if (!dev) in nfc_allocate_device()
1072 dev->idx = rc; in nfc_allocate_device()
1074 dev->dev.class = &nfc_class; in nfc_allocate_device()
1075 dev_set_name(&dev->dev, "nfc%d", dev->idx); in nfc_allocate_device()
1076 device_initialize(&dev->dev); in nfc_allocate_device()
1078 dev->ops = ops; in nfc_allocate_device()
1079 dev->supported_protocols = supported_protocols; in nfc_allocate_device()
1080 dev->tx_headroom = tx_headroom; in nfc_allocate_device()
1081 dev->tx_tailroom = tx_tailroom; in nfc_allocate_device()
1082 INIT_LIST_HEAD(&dev->secure_elements); in nfc_allocate_device()
1084 nfc_genl_data_init(&dev->genl_data); in nfc_allocate_device()
1086 dev->rf_mode = NFC_RF_NONE; in nfc_allocate_device()
1089 dev->targets_generation = 1; in nfc_allocate_device()
1092 timer_setup(&dev->check_pres_timer, nfc_check_pres_timeout, 0); in nfc_allocate_device()
1093 INIT_WORK(&dev->check_pres_work, nfc_check_pres_work); in nfc_allocate_device()
1096 return dev; in nfc_allocate_device()
1099 kfree(dev); in nfc_allocate_device()
1110 int nfc_register_device(struct nfc_dev *dev) in nfc_register_device() argument
1114 pr_debug("dev_name=%s\n", dev_name(&dev->dev)); in nfc_register_device()
1118 rc = device_add(&dev->dev); in nfc_register_device()
1124 rc = nfc_llcp_register_device(dev); in nfc_register_device()
1128 device_lock(&dev->dev); in nfc_register_device()
1129 dev->rfkill = rfkill_alloc(dev_name(&dev->dev), &dev->dev, in nfc_register_device()
1130 RFKILL_TYPE_NFC, &nfc_rfkill_ops, dev); in nfc_register_device()
1131 if (dev->rfkill) { in nfc_register_device()
1132 if (rfkill_register(dev->rfkill) < 0) { in nfc_register_device()
1133 rfkill_destroy(dev->rfkill); in nfc_register_device()
1134 dev->rfkill = NULL; in nfc_register_device()
1137 dev->shutting_down = false; in nfc_register_device()
1138 device_unlock(&dev->dev); in nfc_register_device()
1140 rc = nfc_genl_device_added(dev); in nfc_register_device()
1143 dev_name(&dev->dev)); in nfc_register_device()
1154 void nfc_unregister_device(struct nfc_dev *dev) in nfc_unregister_device() argument
1158 pr_debug("dev_name=%s\n", dev_name(&dev->dev)); in nfc_unregister_device()
1160 rc = nfc_genl_device_removed(dev); in nfc_unregister_device()
1163 "was removed\n", dev_name(&dev->dev)); in nfc_unregister_device()
1165 device_lock(&dev->dev); in nfc_unregister_device()
1166 if (dev->rfkill) { in nfc_unregister_device()
1167 rfkill_unregister(dev->rfkill); in nfc_unregister_device()
1168 rfkill_destroy(dev->rfkill); in nfc_unregister_device()
1169 dev->rfkill = NULL; in nfc_unregister_device()
1171 dev->shutting_down = true; in nfc_unregister_device()
1172 device_unlock(&dev->dev); in nfc_unregister_device()
1174 if (dev->ops->check_presence) { in nfc_unregister_device()
1175 del_timer_sync(&dev->check_pres_timer); in nfc_unregister_device()
1176 cancel_work_sync(&dev->check_pres_work); in nfc_unregister_device()
1179 nfc_llcp_unregister_device(dev); in nfc_unregister_device()
1183 device_del(&dev->dev); in nfc_unregister_device()