Lines Matching refs:device

11 #include <linux/device.h>
157 static const struct ieee1394_device_id *unit_match(struct device *dev,
173 static bool is_fw_unit(struct device *dev);
175 static int fw_unit_match(struct device *dev, struct device_driver *drv)
181 static int fw_unit_probe(struct device *dev)
189 static int fw_unit_remove(struct device *dev)
208 static int fw_unit_uevent(struct device *dev, struct kobj_uevent_env *env)
229 int fw_device_enable_phys_dma(struct fw_device *device)
231 int generation = device->generation;
233 /* device->node_id, accessed below, must not be older than generation */
236 return device->card->driver->enable_phys_dma(device->card,
237 device->node_id,
247 static ssize_t show_immediate(struct device *dev,
279 static ssize_t show_text_leaf(struct device *dev,
332 static void init_fw_attribute_group(struct device *dev,
356 static ssize_t modalias_show(struct device *dev,
368 static ssize_t rom_index_show(struct device *dev,
371 struct fw_device *device = fw_device(dev->parent);
375 (int)(unit->directory - device->config_rom));
384 static ssize_t config_rom_show(struct device *dev,
387 struct fw_device *device = fw_device(dev);
391 length = device->config_rom_length * 4;
392 memcpy(buf, device->config_rom, length);
398 static ssize_t guid_show(struct device *dev,
401 struct fw_device *device = fw_device(dev);
406 device->config_rom[3], device->config_rom[4]);
412 static ssize_t is_local_show(struct device *dev,
415 struct fw_device *device = fw_device(dev);
417 return sprintf(buf, "%u\n", device->is_local);
442 static ssize_t units_show(struct device *dev,
445 struct fw_device *device = fw_device(dev);
450 fw_csr_iterator_init(&ci, &device->config_rom[5]);
474 static int read_rom(struct fw_device *device,
480 /* device->node_id, accessed below, must not be older than generation */
484 rcode = fw_run_transaction(device->card,
485 TCODE_READ_QUADLET_REQUEST, device->node_id,
486 generation, device->max_speed, offset, data, 4);
506 static int read_config_rom(struct fw_device *device, int generation)
508 struct fw_card *card = device->card;
522 device->max_speed = SCODE_100;
526 ret = read_rom(device, generation, i, &rom[i]);
543 device->max_speed = device->node->max_speed;
554 if ((rom[2] & 0x7) < device->max_speed ||
555 device->max_speed == SCODE_BETA ||
560 if (device->max_speed == SCODE_BETA)
561 device->max_speed = card->link_speed;
563 while (device->max_speed > SCODE_100) {
564 if (read_rom(device, generation, 0, &dummy) ==
567 device->max_speed--;
596 ret = read_rom(device, generation, i, &rom[i]);
620 ret = read_rom(device, generation, i, &rom[i]);
647 old_rom = device->config_rom;
655 device->config_rom = new_rom;
656 device->config_rom_length = length;
661 device->max_rec = rom[2] >> 12 & 0xf;
662 device->cmc = rom[2] >> 30 & 1;
663 device->irmc = rom[2] >> 31 & 1;
670 static void fw_unit_release(struct device *dev)
683 static bool is_fw_unit(struct device *dev)
688 static void create_units(struct fw_device *device)
695 fw_csr_iterator_init(&ci, &device->config_rom[5]);
709 unit->device.bus = &fw_bus_type;
710 unit->device.type = &fw_unit_type;
711 unit->device.parent = &device->device;
712 dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++);
717 init_fw_attribute_group(&unit->device,
721 fw_device_get(device);
722 if (device_register(&unit->device) < 0) {
723 put_device(&unit->device);
729 static int shutdown_unit(struct device *device, void *data)
731 device_unregister(device);
749 struct fw_device *device;
752 device = idr_find(&fw_device_idr, MINOR(devt));
753 if (device)
754 fw_device_get(device);
757 return device;
763 static void fw_schedule_device_work(struct fw_device *device,
766 queue_delayed_work(fw_workqueue, &device->work, delay);
771 * rom. It shouldn't be necessary to tweak these; if the device
787 struct fw_device *device =
789 int minor = MINOR(device->device.devt);
792 device->card->reset_jiffies + SHUTDOWN_DELAY)
793 && !list_empty(&device->card->link)) {
794 fw_schedule_device_work(device, SHUTDOWN_DELAY);
798 if (atomic_cmpxchg(&device->state,
803 fw_device_cdev_remove(device);
804 device_for_each_child(&device->device, NULL, shutdown_unit);
805 device_unregister(&device->device);
811 fw_device_put(device);
814 static void fw_device_release(struct device *dev)
816 struct fw_device *device = fw_device(dev);
817 struct fw_card *card = device->card;
826 device->node->data = NULL;
829 fw_node_put(device->node);
830 kfree(device->config_rom);
831 kfree(device);
839 static bool is_fw_device(struct device *dev)
844 static int update_unit(struct device *dev, void *data)
860 struct fw_device *device =
863 fw_device_cdev_update(device);
864 device_for_each_child(&device->device, NULL, update_unit);
868 * If a device was pending for deletion because its node went away but its
870 * device, revive the existing fw_device.
873 static int lookup_existing_device(struct device *dev, void *data)
903 fw_notice(card, "rediscovered device %s\n", dev_name(dev));
922 static void set_broadcast_channel(struct fw_device *device, int generation)
924 struct fw_card *card = device->card;
938 if (!device->irmc || device->max_rec < 8)
945 if (device->bc_implemented == BC_UNKNOWN) {
947 device->node_id, generation, device->max_speed,
953 device->bc_implemented = BC_IMPLEMENTED;
958 device->bc_implemented = BC_UNIMPLEMENTED;
962 if (device->bc_implemented == BC_IMPLEMENTED) {
966 device->node_id, generation, device->max_speed,
972 int fw_device_set_broadcast_channel(struct device *dev, void *gen)
982 struct fw_device *device =
984 struct fw_card *card = device->card;
985 struct device *revived_dev;
991 * device.
994 ret = read_config_rom(device, device->generation);
996 if (device->config_rom_retries < MAX_RETRIES &&
997 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) {
998 device->config_rom_retries++;
999 fw_schedule_device_work(device, RETRY_DELAY);
1001 if (device->node->link_on)
1003 device->node_id,
1005 if (device->node == card->root_node)
1007 fw_device_release(&device->device);
1012 revived_dev = device_find_child(card->device,
1013 device, lookup_existing_device);
1016 fw_device_release(&device->device);
1021 device_initialize(&device->device);
1023 fw_device_get(device);
1025 minor = idr_alloc(&fw_device_idr, device, 0, 1 << MINORBITS,
1032 device->device.bus = &fw_bus_type;
1033 device->device.type = &fw_device_type;
1034 device->device.parent = card->device;
1035 device->device.devt = MKDEV(fw_cdev_major, minor);
1036 dev_set_name(&device->device, "fw%d", minor);
1038 BUILD_BUG_ON(ARRAY_SIZE(device->attribute_group.attrs) <
1041 init_fw_attribute_group(&device->device,
1043 &device->attribute_group);
1045 if (device_add(&device->device)) {
1046 fw_err(card, "failed to add device\n");
1050 create_units(device);
1053 * Transition the device to running state. If it got pulled
1055 * have to shut down the device again here. Normally, though,
1061 if (atomic_cmpxchg(&device->state,
1064 device->workfn = fw_device_shutdown;
1065 fw_schedule_device_work(device, SHUTDOWN_DELAY);
1067 fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n",
1068 dev_name(&device->device),
1069 device->config_rom[3], device->config_rom[4],
1070 1 << device->max_speed);
1071 device->config_rom_retries = 0;
1073 set_broadcast_channel(device, device->generation);
1075 add_device_randomness(&device->config_rom[3], 8);
1084 if (device->node == card->root_node)
1094 fw_device_put(device); /* fw_device_idr's reference */
1096 put_device(&device->device); /* our reference */
1100 static int reread_config_rom(struct fw_device *device, int generation,
1107 rcode = read_rom(device, generation, i, &q);
1115 if (q != device->config_rom[i]) {
1127 struct fw_device *device =
1129 struct fw_card *card = device->card;
1130 int ret, node_id = device->node_id;
1133 ret = reread_config_rom(device, device->generation, &changed);
1138 if (atomic_cmpxchg(&device->state,
1144 device->config_rom_retries = 0;
1152 device_for_each_child(&device->device, NULL, shutdown_unit);
1154 ret = read_config_rom(device, device->generation);
1158 fw_device_cdev_update(device);
1159 create_units(device);
1162 kobject_uevent(&device->device.kobj, KOBJ_CHANGE);
1164 if (atomic_cmpxchg(&device->state,
1169 fw_notice(card, "refreshed device %s\n", dev_name(&device->device));
1170 device->config_rom_retries = 0;
1174 if (device->config_rom_retries < MAX_RETRIES &&
1175 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) {
1176 device->config_rom_retries++;
1177 fw_schedule_device_work(device, RETRY_DELAY);
1181 fw_notice(card, "giving up on refresh of device %s: %s\n",
1182 dev_name(&device->device), fw_rcode_string(ret));
1184 atomic_set(&device->state, FW_DEVICE_GONE);
1185 device->workfn = fw_device_shutdown;
1186 fw_schedule_device_work(device, SHUTDOWN_DELAY);
1194 struct fw_device *device = container_of(to_delayed_work(work),
1196 device->workfn(work);
1201 struct fw_device *device;
1212 device = kzalloc(sizeof(*device), GFP_ATOMIC);
1213 if (device == NULL)
1217 * Do minimal initialization of the device here, the
1222 * You can basically just check device->state and
1226 atomic_set(&device->state, FW_DEVICE_INITIALIZING);
1227 device->card = fw_card_get(card);
1228 device->node = fw_node_get(node);
1229 device->node_id = node->node_id;
1230 device->generation = card->generation;
1231 device->is_local = node == card->local_node;
1232 mutex_init(&device->client_list_mutex);
1233 INIT_LIST_HEAD(&device->client_list);
1236 * Set the node data to point back to this device so
1238 * and generation for the device.
1240 node->data = device;
1248 device->workfn = fw_device_init;
1249 INIT_DELAYED_WORK(&device->work, fw_device_workfn);
1250 fw_schedule_device_work(device, INITIAL_DELAY);
1255 device = node->data;
1256 if (device == NULL)
1259 device->node_id = node->node_id;
1261 device->generation = card->generation;
1262 if (atomic_cmpxchg(&device->state,
1265 device->workfn = fw_device_refresh;
1266 fw_schedule_device_work(device,
1267 device->is_local ? 0 : INITIAL_DELAY);
1272 device = node->data;
1273 if (device == NULL)
1276 device->node_id = node->node_id;
1278 device->generation = card->generation;
1279 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) {
1280 device->workfn = fw_device_update;
1281 fw_schedule_device_work(device, 0);
1291 * Destroy the device associated with the node. There
1292 * are two cases here: either the device is fully
1296 * initialized we can reuse device->work to schedule a
1299 * the device in shutdown state to have that code fail
1300 * to create the device.
1302 device = node->data;
1303 if (atomic_xchg(&device->state,
1305 device->workfn = fw_device_shutdown;
1306 fw_schedule_device_work(device,