Lines Matching +full:first +full:- +full:generation
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net>
14 #include <linux/firewire-constants.h>
36 ci->p = p + 1; in fw_csr_iterator_init()
37 ci->end = ci->p + (p[0] >> 16); in fw_csr_iterator_init()
43 *key = *ci->p >> 24; in fw_csr_iterator_next()
44 *value = *ci->p & 0xffffff; in fw_csr_iterator_next()
46 return ci->p++ < ci->end; in fw_csr_iterator_next()
59 return ci.p - 1 + value; in search_leaf()
73 return -EINVAL; in textual_leaf_to_string()
77 return -ENODATA; in textual_leaf_to_string()
81 return -ENODATA; in textual_leaf_to_string()
84 quadlets -= 2; in textual_leaf_to_string()
85 for (i = 0; i < quadlets * 4 && i < size - 1; i++) { in textual_leaf_to_string()
86 c = block[i / 4] >> (24 - 8 * (i % 4)); in textual_leaf_to_string()
97 * fw_csr_string() - reads a string from the configuration ROM
104 * the immediate entry with @key. The string is zero-terminated.
114 return -ENOENT; in fw_csr_string()
138 get_ids(&fw_parent_device(unit)->config_rom[5], id); in get_modalias_ids()
139 get_ids(unit->directory, id); in get_modalias_ids()
146 if (id[0] == id_table->vendor_id) in match_ids()
148 if (id[1] == id_table->model_id) in match_ids()
150 if (id[2] == id_table->specifier_id) in match_ids()
152 if (id[3] == id_table->version) in match_ids()
155 return (match & id_table->match_flags) == id_table->match_flags; in match_ids()
162 container_of(drv, struct fw_driver, driver)->id_table; in unit_match()
167 for (; id_table->match_flags != 0; id_table++) in unit_match()
185 container_of(dev->driver, struct fw_driver, driver); in fw_unit_probe()
187 return driver->probe(fw_unit(dev), unit_match(dev, dev->driver)); in fw_unit_probe()
193 container_of(dev->driver, struct fw_driver, driver); in fw_unit_remove()
195 driver->remove(fw_unit(dev)); in fw_unit_remove()
217 return -ENOMEM; in fw_unit_uevent()
232 int generation = device->generation; in fw_device_enable_phys_dma() local
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()
239 generation); in fw_device_enable_phys_dma()
255 int key, value, ret = -ENOENT; in show_immediate()
260 dir = fw_unit(dev)->directory; in show_immediate()
262 dir = fw_device(dev)->config_rom + 5; in show_immediate()
266 if (attr->key == key) { in show_immediate()
293 dir = fw_unit(dev)->directory; in show_text_leaf()
295 dir = fw_device(dev)->config_rom + 5; in show_text_leaf()
298 bufsize = PAGE_SIZE - 1; in show_text_leaf()
304 ret = fw_csr_string(dir, attr->key, buf, bufsize); in show_text_leaf()
308 while (ret > 0 && isspace(buf[ret - 1])) in show_text_leaf()
309 ret--; in show_text_leaf()
341 group->attrs[j] = &attrs[j].attr; in init_fw_attribute_group()
345 if (attr->show(dev, attr, NULL) < 0) in init_fw_attribute_group()
347 group->attrs[j++] = &attr->attr; in init_fw_attribute_group()
350 group->attrs[j] = NULL; in init_fw_attribute_group()
351 group->groups[0] = &group->group; in init_fw_attribute_group()
352 group->groups[1] = NULL; in init_fw_attribute_group()
353 group->group.attrs = group->attrs; in init_fw_attribute_group()
354 dev->groups = (const struct attribute_group **) group->groups; in init_fw_attribute_group()
372 struct fw_device *device = fw_device(dev->parent); in rom_index_show()
375 return sysfs_emit(buf, "%td\n", unit->directory - device->config_rom); in rom_index_show()
391 length = device->config_rom_length * 4; in config_rom_show()
392 memcpy(buf, device->config_rom, length); in config_rom_show()
405 ret = sysfs_emit(buf, "0x%08x%08x\n", device->config_rom[3], device->config_rom[4]); in guid_show()
416 return sprintf(buf, "%u\n", device->is_local); in is_local_show()
449 fw_csr_iterator_init(&ci, &device->config_rom[5]); in units_show()
453 i += units_sprintf(&buf[i], ci.p + value - 1); in units_show()
454 if (i >= PAGE_SIZE - (8 + 1 + 8 + 1)) in units_show()
460 buf[i - 1] = '\n'; in units_show()
474 int generation, int index, u32 *data) in read_rom() argument
479 /* device->node_id, accessed below, must not be older than generation */ in read_rom()
483 rcode = fw_run_transaction(device->card, in read_rom()
484 TCODE_READ_QUADLET_REQUEST, device->node_id, in read_rom()
485 generation, device->max_speed, offset, data, 4); in read_rom()
499 * the config ROM. We do all this with a cached bus generation. If the bus
500 * generation changes under us, read_config_rom will fail and get retried.
505 static int read_config_rom(struct fw_device *device, int generation) in read_config_rom() argument
507 struct fw_card *card = device->card; in read_config_rom()
516 return -ENOMEM; in read_config_rom()
521 device->max_speed = SCODE_100; in read_config_rom()
523 /* First read the bus info block. */ in read_config_rom()
525 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
530 * reply with a 0 for the first quadlet of the config in read_config_rom()
542 device->max_speed = device->node->max_speed; in read_config_rom()
546 * - devices with link speed less than PHY speed, in read_config_rom()
547 * - devices with 1394b PHY (unless only connected to 1394a PHYs), in read_config_rom()
548 * - all devices if there are 1394b repeaters. in read_config_rom()
551 * 1394-1995 nodes do not have the field. in read_config_rom()
553 if ((rom[2] & 0x7) < device->max_speed || in read_config_rom()
554 device->max_speed == SCODE_BETA || in read_config_rom()
555 card->beta_repeaters_present) { in read_config_rom()
559 if (device->max_speed == SCODE_BETA) in read_config_rom()
560 device->max_speed = card->link_speed; in read_config_rom()
562 while (device->max_speed > SCODE_100) { in read_config_rom()
563 if (read_rom(device, generation, 0, &dummy) == in read_config_rom()
566 device->max_speed--; in read_config_rom()
587 key = stack[--sp]; in read_config_rom()
590 ret = -ENXIO; in read_config_rom()
595 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
619 ret = read_rom(device, generation, i, &rom[i]); in read_config_rom()
627 * bug or an Extended ROM entry (IEEE 1212-2001 clause in read_config_rom()
646 old_rom = device->config_rom; in read_config_rom()
649 ret = -ENOMEM; in read_config_rom()
654 device->config_rom = new_rom; in read_config_rom()
655 device->config_rom_length = length; in read_config_rom()
660 device->max_rec = rom[2] >> 12 & 0xf; in read_config_rom()
661 device->cmc = rom[2] >> 30 & 1; in read_config_rom()
662 device->irmc = rom[2] >> 31 & 1; in read_config_rom()
684 return dev->type == &fw_unit_type; in is_fw_unit()
694 fw_csr_iterator_init(&ci, &device->config_rom[5]); in create_units()
707 unit->directory = ci.p + value - 1; in create_units()
708 unit->device.bus = &fw_bus_type; in create_units()
709 unit->device.type = &fw_unit_type; in create_units()
710 unit->device.parent = &device->device; in create_units()
711 dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++); in create_units()
713 BUILD_BUG_ON(ARRAY_SIZE(unit->attribute_group.attrs) < in create_units()
716 init_fw_attribute_group(&unit->device, in create_units()
718 &unit->attribute_group); in create_units()
720 if (device_register(&unit->device) < 0) in create_units()
740 * - serializes accesses to fw_device_idr,
741 * - serializes accesses to fw_device.config_rom/.config_rom_length and
768 queue_delayed_work(fw_workqueue, &device->work, delay); in fw_schedule_device_work()
791 int minor = MINOR(device->device.devt); in fw_device_shutdown()
794 device->card->reset_jiffies + SHUTDOWN_DELAY) in fw_device_shutdown()
795 && !list_empty(&device->card->link)) { in fw_device_shutdown()
800 if (atomic_cmpxchg(&device->state, in fw_device_shutdown()
806 device_for_each_child(&device->device, NULL, shutdown_unit); in fw_device_shutdown()
807 device_unregister(&device->device); in fw_device_shutdown()
819 struct fw_card *card = device->card; in fw_device_release()
827 spin_lock_irqsave(&card->lock, flags); in fw_device_release()
828 device->node->data = NULL; in fw_device_release()
829 spin_unlock_irqrestore(&card->lock, flags); in fw_device_release()
831 fw_node_put(device->node); in fw_device_release()
832 kfree(device->config_rom); in fw_device_release()
843 return dev->type == &fw_device_type; in is_fw_device()
849 struct fw_driver *driver = (struct fw_driver *)dev->driver; in update_unit()
851 if (is_fw_unit(dev) && driver != NULL && driver->update != NULL) { in update_unit()
853 driver->update(unit); in update_unit()
866 device_for_each_child(&device->device, NULL, update_unit); in fw_device_update()
879 struct fw_card *card = new->card; in lookup_existing_device()
886 spin_lock_irq(&card->lock); /* serialize node access */ in lookup_existing_device()
888 if (memcmp(old->config_rom, new->config_rom, 6 * 4) == 0 && in lookup_existing_device()
889 atomic_cmpxchg(&old->state, in lookup_existing_device()
892 struct fw_node *current_node = new->node; in lookup_existing_device()
893 struct fw_node *obsolete_node = old->node; in lookup_existing_device()
895 new->node = obsolete_node; in lookup_existing_device()
896 new->node->data = new; in lookup_existing_device()
897 old->node = current_node; in lookup_existing_device()
898 old->node->data = old; in lookup_existing_device()
900 old->max_speed = new->max_speed; in lookup_existing_device()
901 old->node_id = current_node->node_id; in lookup_existing_device()
902 smp_wmb(); /* update node_id before generation */ in lookup_existing_device()
903 old->generation = card->generation; in lookup_existing_device()
904 old->config_rom_retries = 0; in lookup_existing_device()
907 old->workfn = fw_device_update; in lookup_existing_device()
910 if (current_node == card->root_node) in lookup_existing_device()
916 spin_unlock_irq(&card->lock); in lookup_existing_device()
924 static void set_broadcast_channel(struct fw_device *device, int generation) in set_broadcast_channel() argument
926 struct fw_card *card = device->card; in set_broadcast_channel()
930 if (!card->broadcast_channel_allocated) in set_broadcast_channel()
940 if (!device->irmc || device->max_rec < 8) in set_broadcast_channel()
944 * Some 1394-1995 nodes crash if this 1394a-2000 register is written. in set_broadcast_channel()
945 * Perform a read test first. in set_broadcast_channel()
947 if (device->bc_implemented == BC_UNKNOWN) { in set_broadcast_channel()
949 device->node_id, generation, device->max_speed, in set_broadcast_channel()
955 device->bc_implemented = BC_IMPLEMENTED; in set_broadcast_channel()
960 device->bc_implemented = BC_UNIMPLEMENTED; in set_broadcast_channel()
964 if (device->bc_implemented == BC_IMPLEMENTED) { in set_broadcast_channel()
968 device->node_id, generation, device->max_speed, in set_broadcast_channel()
986 struct fw_card *card = device->card; in fw_device_init()
991 * All failure paths here set node->data to NULL, so that we in fw_device_init()
996 ret = read_config_rom(device, device->generation); in fw_device_init()
998 if (device->config_rom_retries < MAX_RETRIES && in fw_device_init()
999 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) { in fw_device_init()
1000 device->config_rom_retries++; in fw_device_init()
1003 if (device->node->link_on) in fw_device_init()
1005 device->node_id, in fw_device_init()
1007 if (device->node == card->root_node) in fw_device_init()
1009 fw_device_release(&device->device); in fw_device_init()
1014 revived_dev = device_find_child(card->device, in fw_device_init()
1018 fw_device_release(&device->device); in fw_device_init()
1023 device_initialize(&device->device); in fw_device_init()
1034 device->device.bus = &fw_bus_type; in fw_device_init()
1035 device->device.type = &fw_device_type; in fw_device_init()
1036 device->device.parent = card->device; in fw_device_init()
1037 device->device.devt = MKDEV(fw_cdev_major, minor); in fw_device_init()
1038 dev_set_name(&device->device, "fw%d", minor); in fw_device_init()
1040 BUILD_BUG_ON(ARRAY_SIZE(device->attribute_group.attrs) < in fw_device_init()
1043 init_fw_attribute_group(&device->device, in fw_device_init()
1045 &device->attribute_group); in fw_device_init()
1047 if (device_add(&device->device)) { in fw_device_init()
1063 if (atomic_cmpxchg(&device->state, in fw_device_init()
1066 device->workfn = fw_device_shutdown; in fw_device_init()
1070 dev_name(&device->device), in fw_device_init()
1071 device->config_rom[3], device->config_rom[4], in fw_device_init()
1072 1 << device->max_speed); in fw_device_init()
1073 device->config_rom_retries = 0; in fw_device_init()
1075 set_broadcast_channel(device, device->generation); in fw_device_init()
1077 add_device_randomness(&device->config_rom[3], 8); in fw_device_init()
1083 * just end up running the IRM work a couple of extra times - in fw_device_init()
1086 if (device->node == card->root_node) in fw_device_init()
1098 put_device(&device->device); /* our reference */ in fw_device_init()
1102 static int reread_config_rom(struct fw_device *device, int generation, in reread_config_rom() argument
1109 rcode = read_rom(device, generation, i, &q); in reread_config_rom()
1117 if (q != device->config_rom[i]) { in reread_config_rom()
1131 struct fw_card *card = device->card; in fw_device_refresh()
1132 int ret, node_id = device->node_id; in fw_device_refresh()
1135 ret = reread_config_rom(device, device->generation, &changed); in fw_device_refresh()
1140 if (atomic_cmpxchg(&device->state, in fw_device_refresh()
1146 device->config_rom_retries = 0; in fw_device_refresh()
1154 device_for_each_child(&device->device, NULL, shutdown_unit); in fw_device_refresh()
1156 ret = read_config_rom(device, device->generation); in fw_device_refresh()
1163 /* Userspace may want to re-read attributes. */ in fw_device_refresh()
1164 kobject_uevent(&device->device.kobj, KOBJ_CHANGE); in fw_device_refresh()
1166 if (atomic_cmpxchg(&device->state, in fw_device_refresh()
1171 fw_notice(card, "refreshed device %s\n", dev_name(&device->device)); in fw_device_refresh()
1172 device->config_rom_retries = 0; in fw_device_refresh()
1176 if (device->config_rom_retries < MAX_RETRIES && in fw_device_refresh()
1177 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) { in fw_device_refresh()
1178 device->config_rom_retries++; in fw_device_refresh()
1184 dev_name(&device->device), fw_rcode_string(ret)); in fw_device_refresh()
1186 atomic_set(&device->state, FW_DEVICE_GONE); in fw_device_refresh()
1187 device->workfn = fw_device_shutdown; in fw_device_refresh()
1190 if (node_id == card->root_node->node_id) in fw_device_refresh()
1198 device->workfn(work); in fw_device_workfn()
1210 * send L=0 but have an up-and-running link; others send L=1 in fw_node_event()
1224 * You can basically just check device->state and in fw_node_event()
1226 * card->lock. in fw_node_event()
1228 atomic_set(&device->state, FW_DEVICE_INITIALIZING); in fw_node_event()
1229 device->card = fw_card_get(card); in fw_node_event()
1230 device->node = fw_node_get(node); in fw_node_event()
1231 device->node_id = node->node_id; in fw_node_event()
1232 device->generation = card->generation; in fw_node_event()
1233 device->is_local = node == card->local_node; in fw_node_event()
1234 mutex_init(&device->client_list_mutex); in fw_node_event()
1235 INIT_LIST_HEAD(&device->client_list); in fw_node_event()
1240 * and generation for the device. in fw_node_event()
1242 node->data = device; in fw_node_event()
1247 * power-up after getting plugged in. We schedule the in fw_node_event()
1248 * first config rom scan half a second after bus reset. in fw_node_event()
1250 device->workfn = fw_device_init; in fw_node_event()
1251 INIT_DELAYED_WORK(&device->work, fw_device_workfn); in fw_node_event()
1257 device = node->data; in fw_node_event()
1261 device->node_id = node->node_id; in fw_node_event()
1262 smp_wmb(); /* update node_id before generation */ in fw_node_event()
1263 device->generation = card->generation; in fw_node_event()
1264 if (atomic_cmpxchg(&device->state, in fw_node_event()
1267 device->workfn = fw_device_refresh; in fw_node_event()
1269 device->is_local ? 0 : INITIAL_DELAY); in fw_node_event()
1274 device = node->data; in fw_node_event()
1278 device->node_id = node->node_id; in fw_node_event()
1279 smp_wmb(); /* update node_id before generation */ in fw_node_event()
1280 device->generation = card->generation; in fw_node_event()
1281 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) { in fw_node_event()
1282 device->workfn = fw_device_update; in fw_node_event()
1289 if (!node->data) in fw_node_event()
1298 * initialized we can reuse device->work to schedule a in fw_node_event()
1304 device = node->data; in fw_node_event()
1305 if (atomic_xchg(&device->state, in fw_node_event()
1307 device->workfn = fw_device_shutdown; in fw_node_event()
1309 list_empty(&card->link) ? 0 : SHUTDOWN_DELAY); in fw_node_event()