Lines Matching full:device
3 * Device probing and sysfs code.
11 #include <linux/device.h>
158 static const struct ieee1394_device_id *unit_match(struct device *dev, in unit_match()
174 static bool is_fw_unit(struct device *dev);
176 static int fw_unit_match(struct device *dev, struct device_driver *drv) in fw_unit_match()
182 static int fw_unit_probe(struct device *dev) in fw_unit_probe()
190 static int fw_unit_remove(struct device *dev) in fw_unit_remove()
209 static int fw_unit_uevent(struct device *dev, struct kobj_uevent_env *env) in fw_unit_uevent()
230 int fw_device_enable_phys_dma(struct fw_device *device) in fw_device_enable_phys_dma() argument
232 int generation = device->generation; in fw_device_enable_phys_dma()
234 /* device->node_id, accessed below, must not be older than generation */ in fw_device_enable_phys_dma()
237 return device->card->driver->enable_phys_dma(device->card, in fw_device_enable_phys_dma()
238 device->node_id, in fw_device_enable_phys_dma()
248 static ssize_t show_immediate(struct device *dev, in show_immediate()
280 static ssize_t show_text_leaf(struct device *dev, in show_text_leaf()
333 static void init_fw_attribute_group(struct device *dev, in init_fw_attribute_group()
357 static ssize_t modalias_show(struct device *dev, in modalias_show()
369 static ssize_t rom_index_show(struct device *dev, in rom_index_show()
372 struct fw_device *device = fw_device(dev->parent); in rom_index_show() local
376 (int)(unit->directory - device->config_rom)); in rom_index_show()
385 static ssize_t config_rom_show(struct device *dev, in config_rom_show()
388 struct fw_device *device = fw_device(dev); in config_rom_show() local
392 length = device->config_rom_length * 4; in config_rom_show()
393 memcpy(buf, device->config_rom, length); in config_rom_show()
399 static ssize_t guid_show(struct device *dev, in guid_show()
402 struct fw_device *device = fw_device(dev); in guid_show() local
407 device->config_rom[3], device->config_rom[4]); in guid_show()
413 static ssize_t is_local_show(struct device *dev, in is_local_show()
416 struct fw_device *device = fw_device(dev); in is_local_show() local
418 return sprintf(buf, "%u\n", device->is_local); in is_local_show()
443 static ssize_t units_show(struct device *dev, in units_show()
446 struct fw_device *device = fw_device(dev); in units_show() local
451 fw_csr_iterator_init(&ci, &device->config_rom[5]); in units_show()
475 static int read_rom(struct fw_device *device, in read_rom() argument
481 /* device->node_id, accessed below, must not be older than generation */ in read_rom()
485 rcode = fw_run_transaction(device->card, in read_rom()
486 TCODE_READ_QUADLET_REQUEST, device->node_id, in read_rom()
487 generation, device->max_speed, offset, data, 4); in read_rom()
507 static int read_config_rom(struct fw_device *device, int generation) in read_config_rom() argument
509 struct fw_card *card = device->card; in read_config_rom()
523 device->max_speed = SCODE_100; in read_config_rom()
527 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
544 device->max_speed = device->node->max_speed; in read_config_rom()
555 if ((rom[2] & 0x7) < device->max_speed || in read_config_rom()
556 device->max_speed == SCODE_BETA || in read_config_rom()
561 if (device->max_speed == SCODE_BETA) in read_config_rom()
562 device->max_speed = card->link_speed; in read_config_rom()
564 while (device->max_speed > SCODE_100) { in read_config_rom()
565 if (read_rom(device, generation, 0, &dummy) == in read_config_rom()
568 device->max_speed--; in read_config_rom()
597 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
621 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
648 old_rom = device->config_rom; in read_config_rom()
656 device->config_rom = new_rom; in read_config_rom()
657 device->config_rom_length = length; in read_config_rom()
662 device->max_rec = rom[2] >> 12 & 0xf; in read_config_rom()
663 device->cmc = rom[2] >> 30 & 1; in read_config_rom()
664 device->irmc = rom[2] >> 31 & 1; in read_config_rom()
671 static void fw_unit_release(struct device *dev) in fw_unit_release()
684 static bool is_fw_unit(struct device *dev) in is_fw_unit()
689 static void create_units(struct fw_device *device) in create_units() argument
696 fw_csr_iterator_init(&ci, &device->config_rom[5]); in create_units()
710 unit->device.bus = &fw_bus_type; in create_units()
711 unit->device.type = &fw_unit_type; in create_units()
712 unit->device.parent = &device->device; in create_units()
713 dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++); in create_units()
718 init_fw_attribute_group(&unit->device, in create_units()
722 if (device_register(&unit->device) < 0) in create_units()
725 fw_device_get(device); in create_units()
733 static int shutdown_unit(struct device *device, void *data) in shutdown_unit() argument
735 device_unregister(device); in shutdown_unit()
753 struct fw_device *device; in fw_device_get_by_devt() local
756 device = idr_find(&fw_device_idr, MINOR(devt)); in fw_device_get_by_devt()
757 if (device) in fw_device_get_by_devt()
758 fw_device_get(device); in fw_device_get_by_devt()
761 return device; in fw_device_get_by_devt()
767 static void fw_schedule_device_work(struct fw_device *device, in fw_schedule_device_work() argument
770 queue_delayed_work(fw_workqueue, &device->work, delay); in fw_schedule_device_work()
775 * rom. It shouldn't be necessary to tweak these; if the device
791 struct fw_device *device = in fw_device_shutdown() local
793 int minor = MINOR(device->device.devt); in fw_device_shutdown()
796 device->card->reset_jiffies + SHUTDOWN_DELAY) in fw_device_shutdown()
797 && !list_empty(&device->card->link)) { in fw_device_shutdown()
798 fw_schedule_device_work(device, SHUTDOWN_DELAY); in fw_device_shutdown()
802 if (atomic_cmpxchg(&device->state, in fw_device_shutdown()
807 fw_device_cdev_remove(device); in fw_device_shutdown()
808 device_for_each_child(&device->device, NULL, shutdown_unit); in fw_device_shutdown()
809 device_unregister(&device->device); in fw_device_shutdown()
815 fw_device_put(device); in fw_device_shutdown()
818 static void fw_device_release(struct device *dev) in fw_device_release()
820 struct fw_device *device = fw_device(dev); in fw_device_release() local
821 struct fw_card *card = device->card; in fw_device_release()
830 device->node->data = NULL; in fw_device_release()
833 fw_node_put(device->node); in fw_device_release()
834 kfree(device->config_rom); in fw_device_release()
835 kfree(device); in fw_device_release()
843 static bool is_fw_device(struct device *dev) in is_fw_device()
848 static int update_unit(struct device *dev, void *data) in update_unit()
864 struct fw_device *device = in fw_device_update() local
867 fw_device_cdev_update(device); in fw_device_update()
868 device_for_each_child(&device->device, NULL, update_unit); in fw_device_update()
872 * If a device was pending for deletion because its node went away but its
874 * device, revive the existing fw_device.
877 static int lookup_existing_device(struct device *dev, void *data) in lookup_existing_device()
907 fw_notice(card, "rediscovered device %s\n", dev_name(dev)); in lookup_existing_device()
926 static void set_broadcast_channel(struct fw_device *device, int generation) in set_broadcast_channel() argument
928 struct fw_card *card = device->card; in set_broadcast_channel()
942 if (!device->irmc || device->max_rec < 8) in set_broadcast_channel()
949 if (device->bc_implemented == BC_UNKNOWN) { in set_broadcast_channel()
951 device->node_id, generation, device->max_speed, in set_broadcast_channel()
957 device->bc_implemented = BC_IMPLEMENTED; in set_broadcast_channel()
962 device->bc_implemented = BC_UNIMPLEMENTED; in set_broadcast_channel()
966 if (device->bc_implemented == BC_IMPLEMENTED) { in set_broadcast_channel()
970 device->node_id, generation, device->max_speed, in set_broadcast_channel()
976 int fw_device_set_broadcast_channel(struct device *dev, void *gen) in fw_device_set_broadcast_channel()
986 struct fw_device *device = in fw_device_init() local
988 struct fw_card *card = device->card; in fw_device_init()
989 struct device *revived_dev; in fw_device_init()
995 * device. in fw_device_init()
998 ret = read_config_rom(device, device->generation); in fw_device_init()
1000 if (device->config_rom_retries < MAX_RETRIES && in fw_device_init()
1001 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) { in fw_device_init()
1002 device->config_rom_retries++; in fw_device_init()
1003 fw_schedule_device_work(device, RETRY_DELAY); in fw_device_init()
1005 if (device->node->link_on) in fw_device_init()
1007 device->node_id, in fw_device_init()
1009 if (device->node == card->root_node) in fw_device_init()
1011 fw_device_release(&device->device); in fw_device_init()
1016 revived_dev = device_find_child(card->device, in fw_device_init()
1017 device, lookup_existing_device); in fw_device_init()
1020 fw_device_release(&device->device); in fw_device_init()
1025 device_initialize(&device->device); in fw_device_init()
1027 fw_device_get(device); in fw_device_init()
1029 minor = idr_alloc(&fw_device_idr, device, 0, 1 << MINORBITS, in fw_device_init()
1036 device->device.bus = &fw_bus_type; in fw_device_init()
1037 device->device.type = &fw_device_type; in fw_device_init()
1038 device->device.parent = card->device; in fw_device_init()
1039 device->device.devt = MKDEV(fw_cdev_major, minor); in fw_device_init()
1040 dev_set_name(&device->device, "fw%d", minor); in fw_device_init()
1042 BUILD_BUG_ON(ARRAY_SIZE(device->attribute_group.attrs) < in fw_device_init()
1045 init_fw_attribute_group(&device->device, in fw_device_init()
1047 &device->attribute_group); in fw_device_init()
1049 if (device_add(&device->device)) { in fw_device_init()
1050 fw_err(card, "failed to add device\n"); in fw_device_init()
1054 create_units(device); in fw_device_init()
1057 * Transition the device to running state. If it got pulled in fw_device_init()
1059 * have to shut down the device again here. Normally, though, in fw_device_init()
1065 if (atomic_cmpxchg(&device->state, in fw_device_init()
1068 device->workfn = fw_device_shutdown; in fw_device_init()
1069 fw_schedule_device_work(device, SHUTDOWN_DELAY); in fw_device_init()
1071 fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n", in fw_device_init()
1072 dev_name(&device->device), in fw_device_init()
1073 device->config_rom[3], device->config_rom[4], in fw_device_init()
1074 1 << device->max_speed); in fw_device_init()
1075 device->config_rom_retries = 0; in fw_device_init()
1077 set_broadcast_channel(device, device->generation); in fw_device_init()
1079 add_device_randomness(&device->config_rom[3], 8); in fw_device_init()
1088 if (device->node == card->root_node) in fw_device_init()
1098 fw_device_put(device); /* fw_device_idr's reference */ in fw_device_init()
1100 put_device(&device->device); /* our reference */ in fw_device_init()
1104 static int reread_config_rom(struct fw_device *device, int generation, in reread_config_rom() argument
1111 rcode = read_rom(device, generation, i, &q); in reread_config_rom()
1119 if (q != device->config_rom[i]) { in reread_config_rom()
1131 struct fw_device *device = in fw_device_refresh() local
1133 struct fw_card *card = device->card; in fw_device_refresh()
1134 int ret, node_id = device->node_id; in fw_device_refresh()
1137 ret = reread_config_rom(device, device->generation, &changed); in fw_device_refresh()
1142 if (atomic_cmpxchg(&device->state, in fw_device_refresh()
1148 device->config_rom_retries = 0; in fw_device_refresh()
1156 device_for_each_child(&device->device, NULL, shutdown_unit); in fw_device_refresh()
1158 ret = read_config_rom(device, device->generation); in fw_device_refresh()
1162 fw_device_cdev_update(device); in fw_device_refresh()
1163 create_units(device); in fw_device_refresh()
1166 kobject_uevent(&device->device.kobj, KOBJ_CHANGE); in fw_device_refresh()
1168 if (atomic_cmpxchg(&device->state, in fw_device_refresh()
1173 fw_notice(card, "refreshed device %s\n", dev_name(&device->device)); in fw_device_refresh()
1174 device->config_rom_retries = 0; in fw_device_refresh()
1178 if (device->config_rom_retries < MAX_RETRIES && in fw_device_refresh()
1179 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) { in fw_device_refresh()
1180 device->config_rom_retries++; in fw_device_refresh()
1181 fw_schedule_device_work(device, RETRY_DELAY); in fw_device_refresh()
1185 fw_notice(card, "giving up on refresh of device %s: %s\n", in fw_device_refresh()
1186 dev_name(&device->device), fw_rcode_string(ret)); in fw_device_refresh()
1188 atomic_set(&device->state, FW_DEVICE_GONE); in fw_device_refresh()
1189 device->workfn = fw_device_shutdown; in fw_device_refresh()
1190 fw_schedule_device_work(device, SHUTDOWN_DELAY); in fw_device_refresh()
1198 struct fw_device *device = container_of(to_delayed_work(work), in fw_device_workfn() local
1200 device->workfn(work); in fw_device_workfn()
1205 struct fw_device *device; in fw_node_event() local
1216 device = kzalloc(sizeof(*device), GFP_ATOMIC); in fw_node_event()
1217 if (device == NULL) in fw_node_event()
1221 * Do minimal initialization of the device here, the in fw_node_event()
1226 * You can basically just check device->state and in fw_node_event()
1230 atomic_set(&device->state, FW_DEVICE_INITIALIZING); in fw_node_event()
1231 device->card = fw_card_get(card); in fw_node_event()
1232 device->node = fw_node_get(node); in fw_node_event()
1233 device->node_id = node->node_id; in fw_node_event()
1234 device->generation = card->generation; in fw_node_event()
1235 device->is_local = node == card->local_node; in fw_node_event()
1236 mutex_init(&device->client_list_mutex); in fw_node_event()
1237 INIT_LIST_HEAD(&device->client_list); in fw_node_event()
1240 * Set the node data to point back to this device so in fw_node_event()
1242 * and generation for the device. in fw_node_event()
1244 node->data = device; in fw_node_event()
1252 device->workfn = fw_device_init; in fw_node_event()
1253 INIT_DELAYED_WORK(&device->work, fw_device_workfn); in fw_node_event()
1254 fw_schedule_device_work(device, INITIAL_DELAY); in fw_node_event()
1259 device = node->data; in fw_node_event()
1260 if (device == NULL) in fw_node_event()
1263 device->node_id = node->node_id; in fw_node_event()
1265 device->generation = card->generation; in fw_node_event()
1266 if (atomic_cmpxchg(&device->state, in fw_node_event()
1269 device->workfn = fw_device_refresh; in fw_node_event()
1270 fw_schedule_device_work(device, in fw_node_event()
1271 device->is_local ? 0 : INITIAL_DELAY); in fw_node_event()
1276 device = node->data; in fw_node_event()
1277 if (device == NULL) in fw_node_event()
1280 device->node_id = node->node_id; in fw_node_event()
1282 device->generation = card->generation; in fw_node_event()
1283 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) { in fw_node_event()
1284 device->workfn = fw_device_update; in fw_node_event()
1285 fw_schedule_device_work(device, 0); in fw_node_event()
1295 * Destroy the device associated with the node. There in fw_node_event()
1296 * are two cases here: either the device is fully in fw_node_event()
1300 * initialized we can reuse device->work to schedule a in fw_node_event()
1303 * the device in shutdown state to have that code fail in fw_node_event()
1304 * to create the device. in fw_node_event()
1306 device = node->data; in fw_node_event()
1307 if (atomic_xchg(&device->state, in fw_node_event()
1309 device->workfn = fw_device_shutdown; in fw_node_event()
1310 fw_schedule_device_work(device, in fw_node_event()