Lines Matching full:device

3  * Device probing and sysfs code.
11 #include <linux/device.h>
191 static const struct ieee1394_device_id *unit_match(struct device *dev, in unit_match()
207 static bool is_fw_unit(const struct device *dev);
209 static int fw_unit_match(struct device *dev, const struct device_driver *drv) in fw_unit_match()
215 static int fw_unit_probe(struct device *dev) in fw_unit_probe()
223 static void fw_unit_remove(struct device *dev) in fw_unit_remove()
242 static int fw_unit_uevent(const struct device *dev, struct kobj_uevent_env *env) in fw_unit_uevent()
263 int fw_device_enable_phys_dma(struct fw_device *device) in fw_device_enable_phys_dma() argument
265 int generation = device->generation; in fw_device_enable_phys_dma()
267 /* device->node_id, accessed below, must not be older than generation */ in fw_device_enable_phys_dma()
270 return device->card->driver->enable_phys_dma(device->card, in fw_device_enable_phys_dma()
271 device->node_id, in fw_device_enable_phys_dma()
281 static ssize_t show_immediate(struct device *dev, in show_immediate()
329 static ssize_t show_text_leaf(struct device *dev, in show_text_leaf()
408 static void init_fw_attribute_group(struct device *dev, in init_fw_attribute_group()
432 static ssize_t modalias_show(struct device *dev, in modalias_show()
444 static ssize_t rom_index_show(struct device *dev, in rom_index_show()
447 struct fw_device *device = fw_device(dev->parent); in rom_index_show() local
450 return sysfs_emit(buf, "%td\n", unit->directory - device->config_rom); in rom_index_show()
459 static ssize_t config_rom_show(struct device *dev, in config_rom_show()
462 struct fw_device *device = fw_device(dev); in config_rom_show() local
467 length = device->config_rom_length * 4; in config_rom_show()
468 memcpy(buf, device->config_rom, length); in config_rom_show()
473 static ssize_t guid_show(struct device *dev, in guid_show()
476 struct fw_device *device = fw_device(dev); in guid_show() local
480 return sysfs_emit(buf, "0x%08x%08x\n", device->config_rom[3], device->config_rom[4]); in guid_show()
483 static ssize_t is_local_show(struct device *dev, in is_local_show()
486 struct fw_device *device = fw_device(dev); in is_local_show() local
488 return sysfs_emit(buf, "%u\n", device->is_local); in is_local_show()
513 static ssize_t units_show(struct device *dev, in units_show()
516 struct fw_device *device = fw_device(dev); in units_show() local
522 fw_csr_iterator_init(&ci, &device->config_rom[ROOT_DIR_OFFSET]); in units_show()
545 static int read_rom(struct fw_device *device, in read_rom() argument
551 /* device->node_id, accessed below, must not be older than generation */ in read_rom()
555 rcode = fw_run_transaction(device->card, in read_rom()
556 TCODE_READ_QUADLET_REQUEST, device->node_id, in read_rom()
557 generation, device->max_speed, offset, data, 4); in read_rom()
578 static int read_config_rom(struct fw_device *device, int generation) in read_config_rom() argument
580 struct fw_card *card = device->card; in read_config_rom()
594 device->max_speed = SCODE_100; in read_config_rom()
598 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
615 device->max_speed = device->node->max_speed; in read_config_rom()
626 if ((rom[2] & 0x7) < device->max_speed || in read_config_rom()
627 device->max_speed == SCODE_BETA || in read_config_rom()
632 if (device->max_speed == SCODE_BETA) in read_config_rom()
633 device->max_speed = card->link_speed; in read_config_rom()
635 while (device->max_speed > SCODE_100) { in read_config_rom()
636 if (read_rom(device, generation, 0, &dummy) == in read_config_rom()
639 device->max_speed--; in read_config_rom()
668 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
692 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
719 old_rom = device->config_rom; in read_config_rom()
727 device->config_rom = new_rom; in read_config_rom()
728 device->config_rom_length = length; in read_config_rom()
733 device->max_rec = rom[2] >> 12 & 0xf; in read_config_rom()
734 device->cmc = rom[2] >> 30 & 1; in read_config_rom()
735 device->irmc = rom[2] >> 31 & 1; in read_config_rom()
742 static void fw_unit_release(struct device *dev) in fw_unit_release()
755 static bool is_fw_unit(const struct device *dev) in is_fw_unit()
760 static void create_units(struct fw_device *device) in create_units() argument
767 fw_csr_iterator_init(&ci, &device->config_rom[ROOT_DIR_OFFSET]); in create_units()
781 unit->device.bus = &fw_bus_type; in create_units()
782 unit->device.type = &fw_unit_type; in create_units()
783 unit->device.parent = &device->device; in create_units()
784 dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++); in create_units()
789 init_fw_attribute_group(&unit->device, in create_units()
793 fw_device_get(device); in create_units()
794 if (device_register(&unit->device) < 0) { in create_units()
795 put_device(&unit->device); in create_units()
801 static int shutdown_unit(struct device *device, void *data) in shutdown_unit() argument
803 device_unregister(device); in shutdown_unit()
820 struct fw_device *device; in fw_device_get_by_devt() local
822 device = xa_load(&fw_device_xa, MINOR(devt)); in fw_device_get_by_devt()
823 if (device) in fw_device_get_by_devt()
824 fw_device_get(device); in fw_device_get_by_devt()
826 return device; in fw_device_get_by_devt()
832 static void fw_schedule_device_work(struct fw_device *device, in fw_schedule_device_work() argument
835 queue_delayed_work(fw_workqueue, &device->work, delay); in fw_schedule_device_work()
840 * rom. It shouldn't be necessary to tweak these; if the device
856 struct fw_device *device = from_work(device, work, work.work); in fw_device_shutdown() local
859 device->card->reset_jiffies + SHUTDOWN_DELAY) in fw_device_shutdown()
860 && !list_empty(&device->card->link)) { in fw_device_shutdown()
861 fw_schedule_device_work(device, SHUTDOWN_DELAY); in fw_device_shutdown()
865 if (atomic_cmpxchg(&device->state, in fw_device_shutdown()
870 fw_device_cdev_remove(device); in fw_device_shutdown()
871 device_for_each_child(&device->device, NULL, shutdown_unit); in fw_device_shutdown()
872 device_unregister(&device->device); in fw_device_shutdown()
874 xa_erase(&fw_device_xa, MINOR(device->device.devt)); in fw_device_shutdown()
876 fw_device_put(device); in fw_device_shutdown()
879 static void fw_device_release(struct device *dev) in fw_device_release()
881 struct fw_device *device = fw_device(dev); in fw_device_release() local
882 struct fw_card *card = device->card; in fw_device_release()
890 device->node->data = NULL; in fw_device_release()
892 fw_node_put(device->node); in fw_device_release()
893 kfree(device->config_rom); in fw_device_release()
894 kfree(device); in fw_device_release()
902 static bool is_fw_device(const struct device *dev) in is_fw_device()
907 static int update_unit(struct device *dev, void *data) in update_unit()
923 struct fw_device *device = from_work(device, work, work.work); in fw_device_update() local
925 fw_device_cdev_update(device); in fw_device_update()
926 device_for_each_child(&device->device, NULL, update_unit); in fw_device_update()
931 static void set_broadcast_channel(struct fw_device *device, int generation) in set_broadcast_channel() argument
933 struct fw_card *card = device->card; in set_broadcast_channel()
947 if (!device->irmc || device->max_rec < 8) in set_broadcast_channel()
954 if (device->bc_implemented == BC_UNKNOWN) { in set_broadcast_channel()
956 device->node_id, generation, device->max_speed, in set_broadcast_channel()
962 device->bc_implemented = BC_IMPLEMENTED; in set_broadcast_channel()
967 device->bc_implemented = BC_UNIMPLEMENTED; in set_broadcast_channel()
971 if (device->bc_implemented == BC_IMPLEMENTED) { in set_broadcast_channel()
975 device->node_id, generation, device->max_speed, in set_broadcast_channel()
981 int fw_device_set_broadcast_channel(struct device *dev, void *gen) in fw_device_set_broadcast_channel()
989 static int compare_configuration_rom(struct device *dev, const void *data) in compare_configuration_rom()
1003 struct fw_device *device = from_work(device, work, work.work); in fw_device_init() local
1004 struct fw_card *card = device->card; in fw_device_init()
1005 struct device *found; in fw_device_init()
1012 * device. in fw_device_init()
1015 ret = read_config_rom(device, device->generation); in fw_device_init()
1017 if (device->config_rom_retries < MAX_RETRIES && in fw_device_init()
1018 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) { in fw_device_init()
1019 device->config_rom_retries++; in fw_device_init()
1020 fw_schedule_device_work(device, RETRY_DELAY); in fw_device_init()
1022 if (device->node->link_on) in fw_device_init()
1024 device->node_id, in fw_device_init()
1026 if (device->node == card->root_node) in fw_device_init()
1028 fw_device_release(&device->device); in fw_device_init()
1033 // If a device was pending for deletion because its node went away but its bus info block in fw_device_init()
1034 // and root directory header matches that of a newly discovered device, revive the in fw_device_init()
1039 found = device_find_child(card->device, device->config_rom, in fw_device_init()
1050 struct fw_node *current_node = device->node; in fw_device_init()
1053 device->node = obsolete_node; in fw_device_init()
1054 device->node->data = device; in fw_device_init()
1058 reused->max_speed = device->max_speed; in fw_device_init()
1063 fw_notice(card, "rediscovered device %s\n", in fw_device_init()
1074 fw_device_release(&device->device); in fw_device_init()
1082 device_initialize(&device->device); in fw_device_init()
1084 fw_device_get(device); in fw_device_init()
1086 // The index of allocated entry is used for minor identifier of device node. in fw_device_init()
1087 ret = xa_alloc(&fw_device_xa, &minor, device, XA_LIMIT(0, MINORMASK), GFP_KERNEL); in fw_device_init()
1091 device->device.bus = &fw_bus_type; in fw_device_init()
1092 device->device.type = &fw_device_type; in fw_device_init()
1093 device->device.parent = card->device; in fw_device_init()
1094 device->device.devt = MKDEV(fw_cdev_major, minor); in fw_device_init()
1095 dev_set_name(&device->device, "fw%d", minor); in fw_device_init()
1097 BUILD_BUG_ON(ARRAY_SIZE(device->attribute_group.attrs) < in fw_device_init()
1100 init_fw_attribute_group(&device->device, in fw_device_init()
1102 &device->attribute_group); in fw_device_init()
1104 if (device_add(&device->device)) { in fw_device_init()
1105 fw_err(card, "failed to add device\n"); in fw_device_init()
1109 create_units(device); in fw_device_init()
1112 * Transition the device to running state. If it got pulled in fw_device_init()
1114 * have to shut down the device again here. Normally, though, in fw_device_init()
1120 if (atomic_cmpxchg(&device->state, in fw_device_init()
1123 device->workfn = fw_device_shutdown; in fw_device_init()
1124 fw_schedule_device_work(device, SHUTDOWN_DELAY); in fw_device_init()
1126 fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n", in fw_device_init()
1127 dev_name(&device->device), in fw_device_init()
1128 device->config_rom[3], device->config_rom[4], in fw_device_init()
1129 1 << device->max_speed); in fw_device_init()
1130 device->config_rom_retries = 0; in fw_device_init()
1132 set_broadcast_channel(device, device->generation); in fw_device_init()
1134 add_device_randomness(&device->config_rom[3], 8); in fw_device_init()
1143 if (device->node == card->root_node) in fw_device_init()
1151 fw_device_put(device); // fw_device_xa's reference. in fw_device_init()
1153 put_device(&device->device); /* our reference */ in fw_device_init()
1157 static int reread_config_rom(struct fw_device *device, int generation, in reread_config_rom() argument
1164 rcode = read_rom(device, generation, i, &q); in reread_config_rom()
1172 if (q != device->config_rom[i]) { in reread_config_rom()
1184 struct fw_device *device = from_work(device, work, work.work); in fw_device_refresh() local
1185 struct fw_card *card = device->card; in fw_device_refresh()
1186 int ret, node_id = device->node_id; in fw_device_refresh()
1189 ret = reread_config_rom(device, device->generation, &changed); in fw_device_refresh()
1194 if (atomic_cmpxchg(&device->state, in fw_device_refresh()
1200 device->config_rom_retries = 0; in fw_device_refresh()
1208 device_for_each_child(&device->device, NULL, shutdown_unit); in fw_device_refresh()
1210 ret = read_config_rom(device, device->generation); in fw_device_refresh()
1214 fw_device_cdev_update(device); in fw_device_refresh()
1215 create_units(device); in fw_device_refresh()
1218 kobject_uevent(&device->device.kobj, KOBJ_CHANGE); in fw_device_refresh()
1220 if (atomic_cmpxchg(&device->state, in fw_device_refresh()
1225 fw_notice(card, "refreshed device %s\n", dev_name(&device->device)); in fw_device_refresh()
1226 device->config_rom_retries = 0; in fw_device_refresh()
1230 if (device->config_rom_retries < MAX_RETRIES && in fw_device_refresh()
1231 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) { in fw_device_refresh()
1232 device->config_rom_retries++; in fw_device_refresh()
1233 fw_schedule_device_work(device, RETRY_DELAY); in fw_device_refresh()
1237 fw_notice(card, "giving up on refresh of device %s: %s\n", in fw_device_refresh()
1238 dev_name(&device->device), fw_rcode_string(ret)); in fw_device_refresh()
1240 atomic_set(&device->state, FW_DEVICE_GONE); in fw_device_refresh()
1241 device->workfn = fw_device_shutdown; in fw_device_refresh()
1242 fw_schedule_device_work(device, SHUTDOWN_DELAY); in fw_device_refresh()
1250 struct fw_device *device = from_work(device, to_delayed_work(work), work); in fw_device_workfn() local
1251 device->workfn(work); in fw_device_workfn()
1256 struct fw_device *device; in fw_node_event() local
1267 device = kzalloc(sizeof(*device), GFP_ATOMIC); in fw_node_event()
1268 if (device == NULL) in fw_node_event()
1272 * Do minimal initialization of the device here, the in fw_node_event()
1277 * You can basically just check device->state and in fw_node_event()
1281 atomic_set(&device->state, FW_DEVICE_INITIALIZING); in fw_node_event()
1282 device->card = fw_card_get(card); in fw_node_event()
1283 device->node = fw_node_get(node); in fw_node_event()
1284 device->node_id = node->node_id; in fw_node_event()
1285 device->generation = card->generation; in fw_node_event()
1286 device->is_local = node == card->local_node; in fw_node_event()
1287 mutex_init(&device->client_list_mutex); in fw_node_event()
1288 INIT_LIST_HEAD(&device->client_list); in fw_node_event()
1291 * Set the node data to point back to this device so in fw_node_event()
1293 * and generation for the device. in fw_node_event()
1295 node->data = device; in fw_node_event()
1303 device->workfn = fw_device_init; in fw_node_event()
1304 INIT_DELAYED_WORK(&device->work, fw_device_workfn); in fw_node_event()
1305 fw_schedule_device_work(device, INITIAL_DELAY); in fw_node_event()
1310 device = node->data; in fw_node_event()
1311 if (device == NULL) in fw_node_event()
1314 device->node_id = node->node_id; in fw_node_event()
1316 device->generation = card->generation; in fw_node_event()
1317 if (atomic_cmpxchg(&device->state, in fw_node_event()
1320 device->workfn = fw_device_refresh; in fw_node_event()
1321 fw_schedule_device_work(device, in fw_node_event()
1322 device->is_local ? 0 : INITIAL_DELAY); in fw_node_event()
1327 device = node->data; in fw_node_event()
1328 if (device == NULL) in fw_node_event()
1331 device->node_id = node->node_id; in fw_node_event()
1333 device->generation = card->generation; in fw_node_event()
1334 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) { in fw_node_event()
1335 device->workfn = fw_device_update; in fw_node_event()
1336 fw_schedule_device_work(device, 0); in fw_node_event()
1346 * Destroy the device associated with the node. There in fw_node_event()
1347 * are two cases here: either the device is fully in fw_node_event()
1351 * initialized we can reuse device->work to schedule a in fw_node_event()
1354 * the device in shutdown state to have that code fail in fw_node_event()
1355 * to create the device. in fw_node_event()
1357 device = node->data; in fw_node_event()
1358 if (atomic_xchg(&device->state, in fw_node_event()
1360 device->workfn = fw_device_shutdown; in fw_node_event()
1361 fw_schedule_device_work(device, in fw_node_event()
1369 #include "device-attribute-test.c"