Lines Matching refs:dev
33 int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)
37 pr_debug("%s do firmware %s\n", dev_name(&dev->dev), firmware_name);
39 device_lock(&dev->dev);
41 if (dev->shutting_down) {
46 if (dev->dev_up) {
51 if (!dev->ops->fw_download) {
56 dev->fw_download_in_progress = true;
57 rc = dev->ops->fw_download(dev, firmware_name);
59 dev->fw_download_in_progress = false;
62 device_unlock(&dev->dev);
69 * @dev: The nfc device to which firmware was downloaded
73 int nfc_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
76 dev->fw_download_in_progress = false;
78 return nfc_genl_fw_download_done(dev, firmware_name, result);
85 * @dev: The nfc device to be turned on
89 int nfc_dev_up(struct nfc_dev *dev)
93 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
95 device_lock(&dev->dev);
97 if (dev->shutting_down) {
102 if (dev->rfkill && rfkill_blocked(dev->rfkill)) {
107 if (dev->fw_download_in_progress) {
112 if (dev->dev_up) {
117 if (dev->ops->dev_up)
118 rc = dev->ops->dev_up(dev);
121 dev->dev_up = true;
124 if (dev->ops->discover_se && dev->ops->discover_se(dev))
128 device_unlock(&dev->dev);
135 * @dev: The nfc device to be turned off
137 int nfc_dev_down(struct nfc_dev *dev)
141 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
143 device_lock(&dev->dev);
145 if (dev->shutting_down) {
150 if (!dev->dev_up) {
155 if (dev->polling || dev->active_target) {
160 if (dev->ops->dev_down)
161 dev->ops->dev_down(dev);
163 dev->dev_up = false;
166 device_unlock(&dev->dev);
172 struct nfc_dev *dev = data;
174 pr_debug("%s blocked %d", dev_name(&dev->dev), blocked);
179 nfc_dev_down(dev);
191 * @dev: The nfc device that must start polling
197 int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols)
202 dev_name(&dev->dev), im_protocols, tm_protocols);
207 device_lock(&dev->dev);
209 if (dev->shutting_down) {
214 if (!dev->dev_up) {
219 if (dev->polling) {
224 rc = dev->ops->start_poll(dev, im_protocols, tm_protocols);
226 dev->polling = true;
227 dev->rf_mode = NFC_RF_NONE;
231 device_unlock(&dev->dev);
238 * @dev: The nfc device that must stop polling
240 int nfc_stop_poll(struct nfc_dev *dev)
244 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
246 device_lock(&dev->dev);
248 if (dev->shutting_down) {
253 if (!dev->polling) {
258 dev->ops->stop_poll(dev);
259 dev->polling = false;
260 dev->rf_mode = NFC_RF_NONE;
263 device_unlock(&dev->dev);
267 static struct nfc_target *nfc_find_target(struct nfc_dev *dev, u32 target_idx)
271 for (i = 0; i < dev->n_targets; i++) {
272 if (dev->targets[i].idx == target_idx)
273 return &dev->targets[i];
279 int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode)
286 pr_debug("dev_name=%s comm %d\n", dev_name(&dev->dev), comm_mode);
288 if (!dev->ops->dep_link_up)
291 device_lock(&dev->dev);
293 if (dev->shutting_down) {
298 if (dev->dep_link_up == true) {
303 gb = nfc_llcp_general_bytes(dev, &gb_len);
309 target = nfc_find_target(dev, target_index);
315 rc = dev->ops->dep_link_up(dev, target, comm_mode, gb, gb_len);
317 dev->active_target = target;
318 dev->rf_mode = NFC_RF_INITIATOR;
322 device_unlock(&dev->dev);
326 int nfc_dep_link_down(struct nfc_dev *dev)
330 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
332 if (!dev->ops->dep_link_down)
335 device_lock(&dev->dev);
337 if (dev->shutting_down) {
342 if (dev->dep_link_up == false) {
347 rc = dev->ops->dep_link_down(dev);
349 dev->dep_link_up = false;
350 dev->active_target = NULL;
351 dev->rf_mode = NFC_RF_NONE;
352 nfc_llcp_mac_is_down(dev);
353 nfc_genl_dep_link_down_event(dev);
357 device_unlock(&dev->dev);
362 int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
365 dev->dep_link_up = true;
367 if (!dev->active_target && rf_mode == NFC_RF_INITIATOR) {
370 target = nfc_find_target(dev, target_idx);
374 dev->active_target = target;
377 dev->polling = false;
378 dev->rf_mode = rf_mode;
380 nfc_llcp_mac_is_up(dev, target_idx, comm_mode, rf_mode);
382 return nfc_genl_dep_link_up_event(dev, target_idx, comm_mode, rf_mode);
389 * @dev: The nfc device that found the target
393 int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)
399 dev_name(&dev->dev), target_idx, protocol);
401 device_lock(&dev->dev);
403 if (dev->shutting_down) {
408 if (dev->active_target) {
413 target = nfc_find_target(dev, target_idx);
419 rc = dev->ops->activate_target(dev, target, protocol);
421 dev->active_target = target;
422 dev->rf_mode = NFC_RF_INITIATOR;
424 if (dev->ops->check_presence && !dev->shutting_down)
425 mod_timer(&dev->check_pres_timer, jiffies +
430 device_unlock(&dev->dev);
437 * @dev: The nfc device that found the target
440 int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx, u8 mode)
445 dev_name(&dev->dev), target_idx);
447 device_lock(&dev->dev);
449 if (dev->shutting_down) {
454 if (dev->active_target == NULL) {
459 if (dev->active_target->idx != target_idx) {
464 if (dev->ops->check_presence)
465 del_timer_sync(&dev->check_pres_timer);
467 dev->ops->deactivate_target(dev, dev->active_target, mode);
468 dev->active_target = NULL;
471 device_unlock(&dev->dev);
478 * @dev: The nfc device that found the target
486 int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
492 dev_name(&dev->dev), target_idx, skb->len);
494 device_lock(&dev->dev);
496 if (dev->shutting_down) {
502 if (dev->rf_mode == NFC_RF_INITIATOR && dev->active_target != NULL) {
503 if (dev->active_target->idx != target_idx) {
509 if (dev->ops->check_presence)
510 del_timer_sync(&dev->check_pres_timer);
512 rc = dev->ops->im_transceive(dev, dev->active_target, skb, cb,
515 if (!rc && dev->ops->check_presence && !dev->shutting_down)
516 mod_timer(&dev->check_pres_timer, jiffies +
518 } else if (dev->rf_mode == NFC_RF_TARGET && dev->ops->tm_send != NULL) {
519 rc = dev->ops->tm_send(dev, skb);
528 device_unlock(&dev->dev);
532 struct nfc_se *nfc_find_se(struct nfc_dev *dev, u32 se_idx)
536 list_for_each_entry(se, &dev->secure_elements, list)
544 int nfc_enable_se(struct nfc_dev *dev, u32 se_idx)
549 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
551 device_lock(&dev->dev);
553 if (dev->shutting_down) {
558 if (!dev->dev_up) {
563 if (dev->polling) {
568 if (!dev->ops->enable_se || !dev->ops->disable_se) {
573 se = nfc_find_se(dev, se_idx);
584 rc = dev->ops->enable_se(dev, se_idx);
589 device_unlock(&dev->dev);
593 int nfc_disable_se(struct nfc_dev *dev, u32 se_idx)
598 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
600 device_lock(&dev->dev);
602 if (dev->shutting_down) {
607 if (!dev->dev_up) {
612 if (!dev->ops->enable_se || !dev->ops->disable_se) {
617 se = nfc_find_se(dev, se_idx);
628 rc = dev->ops->disable_se(dev, se_idx);
633 device_unlock(&dev->dev);
637 int nfc_set_remote_general_bytes(struct nfc_dev *dev, const u8 *gb, u8 gb_len)
639 pr_debug("dev_name=%s gb_len=%d\n", dev_name(&dev->dev), gb_len);
641 return nfc_llcp_set_remote_gb(dev, gb, gb_len);
645 u8 *nfc_get_local_general_bytes(struct nfc_dev *dev, size_t *gb_len)
647 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
649 return nfc_llcp_general_bytes(dev, gb_len);
653 int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb)
656 if (dev->dep_link_up == false) {
661 return nfc_llcp_data_received(dev, skb);
665 int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode,
670 device_lock(&dev->dev);
672 dev->polling = false;
675 rc = nfc_set_remote_general_bytes(dev, gb, gb_len);
680 dev->rf_mode = NFC_RF_TARGET;
683 nfc_dep_link_is_up(dev, 0, comm_mode, NFC_RF_TARGET);
685 rc = nfc_genl_tm_activated(dev, protocol);
688 device_unlock(&dev->dev);
694 int nfc_tm_deactivated(struct nfc_dev *dev)
696 dev->dep_link_up = false;
697 dev->rf_mode = NFC_RF_NONE;
699 return nfc_genl_tm_deactivated(dev);
708 struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk,
716 dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE;
720 skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE);
749 * @dev: The nfc device that found the targets
762 int nfc_targets_found(struct nfc_dev *dev,
767 pr_debug("dev_name=%s n_targets=%d\n", dev_name(&dev->dev), n_targets);
770 targets[i].idx = dev->target_next_idx++;
772 device_lock(&dev->dev);
774 if (dev->polling == false) {
775 device_unlock(&dev->dev);
779 dev->polling = false;
781 dev->targets_generation++;
783 kfree(dev->targets);
784 dev->targets = NULL;
787 dev->targets = kmemdup(targets,
791 if (!dev->targets) {
792 dev->n_targets = 0;
793 device_unlock(&dev->dev);
798 dev->n_targets = n_targets;
799 device_unlock(&dev->dev);
801 nfc_genl_targets_found(dev);
810 * @dev: The nfc device that had the activated target in field
819 int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)
824 pr_debug("dev_name %s n_target %d\n", dev_name(&dev->dev), target_idx);
826 device_lock(&dev->dev);
828 for (i = 0; i < dev->n_targets; i++) {
829 tg = &dev->targets[i];
834 if (i == dev->n_targets) {
835 device_unlock(&dev->dev);
839 dev->targets_generation++;
840 dev->n_targets--;
841 dev->active_target = NULL;
843 if (dev->n_targets) {
844 memcpy(&dev->targets[i], &dev->targets[i + 1],
845 (dev->n_targets - i) * sizeof(struct nfc_target));
847 kfree(dev->targets);
848 dev->targets = NULL;
851 device_unlock(&dev->dev);
853 nfc_genl_target_lost(dev, target_idx);
859 inline void nfc_driver_failure(struct nfc_dev *dev, int err)
861 nfc_targets_found(dev, NULL, 0);
865 int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type)
870 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
872 se = nfc_find_se(dev, se_idx);
885 list_add(&se->list, &dev->secure_elements);
887 rc = nfc_genl_se_added(dev, se_idx, type);
899 int nfc_remove_se(struct nfc_dev *dev, u32 se_idx)
904 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
906 list_for_each_entry_safe(se, n, &dev->secure_elements, list)
908 rc = nfc_genl_se_removed(dev, se_idx);
922 int nfc_se_transaction(struct nfc_dev *dev, u8 se_idx,
929 device_lock(&dev->dev);
936 rc = nfc_genl_se_transaction(dev, se_idx, evt_transaction);
938 device_unlock(&dev->dev);
943 int nfc_se_connectivity(struct nfc_dev *dev, u8 se_idx)
949 device_lock(&dev->dev);
950 rc = nfc_genl_se_connectivity(dev, se_idx);
951 device_unlock(&dev->dev);
958 struct nfc_dev *dev = to_nfc_dev(d);
961 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
963 nfc_genl_data_exit(&dev->genl_data);
964 kfree(dev->targets);
966 list_for_each_entry_safe(se, n, &dev->secure_elements, list) {
967 nfc_genl_se_removed(dev, se->idx);
972 ida_simple_remove(&nfc_index_ida, dev->idx);
974 kfree(dev);
979 struct nfc_dev *dev = container_of(work, struct nfc_dev,
983 device_lock(&dev->dev);
985 if (dev->active_target && timer_pending(&dev->check_pres_timer) == 0) {
986 rc = dev->ops->check_presence(dev, dev->active_target);
990 u32 active_target_idx = dev->active_target->idx;
991 device_unlock(&dev->dev);
992 nfc_target_lost(dev, active_target_idx);
996 if (!dev->shutting_down)
997 mod_timer(&dev->check_pres_timer, jiffies +
1002 device_unlock(&dev->dev);
1007 struct nfc_dev *dev = from_timer(dev, t, check_pres_timer);
1009 schedule_work(&dev->check_pres_work);
1020 struct nfc_dev *dev = to_nfc_dev(d);
1023 return dev->idx == *idx;
1047 struct nfc_dev *dev;
1057 dev = kzalloc(sizeof(struct nfc_dev), GFP_KERNEL);
1058 if (!dev)
1064 dev->idx = rc;
1066 dev->dev.class = &nfc_class;
1067 dev_set_name(&dev->dev, "nfc%d", dev->idx);
1068 device_initialize(&dev->dev);
1070 dev->ops = ops;
1071 dev->supported_protocols = supported_protocols;
1072 dev->tx_headroom = tx_headroom;
1073 dev->tx_tailroom = tx_tailroom;
1074 INIT_LIST_HEAD(&dev->secure_elements);
1076 nfc_genl_data_init(&dev->genl_data);
1078 dev->rf_mode = NFC_RF_NONE;
1081 dev->targets_generation = 1;
1084 timer_setup(&dev->check_pres_timer, nfc_check_pres_timeout, 0);
1085 INIT_WORK(&dev->check_pres_work, nfc_check_pres_work);
1088 return dev;
1091 kfree(dev);
1100 * @dev: The nfc device to register
1102 int nfc_register_device(struct nfc_dev *dev)
1106 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
1110 rc = device_add(&dev->dev);
1116 rc = nfc_llcp_register_device(dev);
1120 device_lock(&dev->dev);
1121 dev->rfkill = rfkill_alloc(dev_name(&dev->dev), &dev->dev,
1122 RFKILL_TYPE_NFC, &nfc_rfkill_ops, dev);
1123 if (dev->rfkill) {
1124 if (rfkill_register(dev->rfkill) < 0) {
1125 rfkill_destroy(dev->rfkill);
1126 dev->rfkill = NULL;
1129 dev->shutting_down = false;
1130 device_unlock(&dev->dev);
1132 rc = nfc_genl_device_added(dev);
1135 dev_name(&dev->dev));
1144 * @dev: The nfc device to unregister
1146 void nfc_unregister_device(struct nfc_dev *dev)
1150 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
1152 rc = nfc_genl_device_removed(dev);
1155 "was removed\n", dev_name(&dev->dev));
1157 device_lock(&dev->dev);
1158 if (dev->rfkill) {
1159 rfkill_unregister(dev->rfkill);
1160 rfkill_destroy(dev->rfkill);
1161 dev->rfkill = NULL;
1163 dev->shutting_down = true;
1164 device_unlock(&dev->dev);
1166 if (dev->ops->check_presence) {
1167 del_timer_sync(&dev->check_pres_timer);
1168 cancel_work_sync(&dev->check_pres_work);
1171 nfc_llcp_unregister_device(dev);
1175 device_del(&dev->dev);