2 * Node information (ConfigROM) collection and management.
4 * Copyright (C) 2000 Andreas E. Bombe
5 * 2001-2003 Ben Collins <bcollins@debian.net>
7 * This code is licensed under the GPL. See the file COPYING in the root
8 * directory of the kernel sources for details.
11 #include <linux/kernel.h>
12 #include <linux/config.h>
13 #include <linux/list.h>
14 #include <linux/slab.h>
15 #include <linux/smp_lock.h>
16 #include <linux/interrupt.h>
17 #include <linux/kmod.h>
18 #include <linux/completion.h>
19 #include <linux/delay.h>
20 #include <linux/pci.h>
21 #include <linux/moduleparam.h>
22 #include <asm/atomic.h>
24 #include "ieee1394_types.h"
27 #include "ieee1394_transactions.h"
28 #include "highlevel.h"
32 static int ignore_drivers = 0;
33 module_param(ignore_drivers, int, 0444);
34 MODULE_PARM_DESC(ignore_drivers, "Disable automatic probing for drivers.");
36 struct nodemgr_csr_info {
37 struct hpsb_host *host;
39 unsigned int generation;
43 static char *nodemgr_find_oui_name(int oui)
45 #ifdef CONFIG_IEEE1394_OUI_DB
46 extern struct oui_list_struct {
52 for (i = 0; oui_list[i].name; i++)
53 if (oui_list[i].oui == oui)
54 return oui_list[i].name;
60 static int nodemgr_bus_read(struct csr1212_csr *csr, u64 addr, u16 length,
61 void *buffer, void *__ci)
63 struct nodemgr_csr_info *ci = (struct nodemgr_csr_info*)__ci;
66 for (i = 0; i < 3; i++) {
67 ret = hpsb_read(ci->host, ci->nodeid, ci->generation, addr,
72 if (msleep_interruptible(334))
79 static int nodemgr_get_max_rom(quadlet_t *bus_info_data, void *__ci)
81 return (CSR1212_BE32_TO_CPU(bus_info_data[2]) >> 8) & 0x3;
84 static struct csr1212_bus_ops nodemgr_csr_ops = {
85 .bus_read = nodemgr_bus_read,
86 .get_max_rom = nodemgr_get_max_rom
91 * Basically what we do here is start off retrieving the bus_info block.
92 * From there will fill in some info about the node, verify it is of IEEE
93 * 1394 type, and that the crc checks out ok. After that we start off with
94 * the root directory, and subdirectories. To do this, we retrieve the
95 * quadlet header for a directory, find out the length, and retrieve the
96 * complete directory entry (be it a leaf or a directory). We then process
97 * it and add the info to our structure for that particular node.
99 * We verify CRC's along the way for each directory/block/leaf. The entire
100 * node structure is generic, and simply stores the information in a way
101 * that's easy to parse by the protocol interface.
105 * The nodemgr relies heavily on the Driver Model for device callbacks and
106 * driver/device mappings. The old nodemgr used to handle all this itself,
107 * but now we are much simpler because of the LDM.
110 static DECLARE_MUTEX(nodemgr_serialize);
113 struct hpsb_host *host;
114 struct list_head list;
115 struct completion exited;
116 struct semaphore reset_sem;
118 char daemon_name[15];
122 static int nodemgr_bus_match(struct device * dev, struct device_driver * drv);
123 static int nodemgr_hotplug(struct class_device *cdev, char **envp, int num_envp,
124 char *buffer, int buffer_size);
125 static void nodemgr_resume_ne(struct node_entry *ne);
126 static void nodemgr_remove_ne(struct node_entry *ne);
127 static struct node_entry *find_entry_by_guid(u64 guid);
129 struct bus_type ieee1394_bus_type = {
131 .match = nodemgr_bus_match,
134 static void host_cls_release(struct class_device *class_dev)
136 put_device(&container_of((class_dev), struct hpsb_host, class_dev)->device);
139 struct class hpsb_host_class = {
140 .name = "ieee1394_host",
141 .release = host_cls_release,
144 static void ne_cls_release(struct class_device *class_dev)
146 put_device(&container_of((class_dev), struct node_entry, class_dev)->device);
149 struct class nodemgr_ne_class = {
150 .name = "ieee1394_node",
151 .release = ne_cls_release,
154 static void ud_cls_release(struct class_device *class_dev)
156 put_device(&container_of((class_dev), struct unit_directory, class_dev)->device);
159 /* The name here is only so that unit directory hotplug works with old
160 * style hotplug, which only ever did unit directories anyway. */
161 struct class nodemgr_ud_class = {
163 .release = ud_cls_release,
164 .hotplug = nodemgr_hotplug,
167 static struct hpsb_highlevel nodemgr_highlevel;
170 static void nodemgr_release_ud(struct device *dev)
172 struct unit_directory *ud = container_of(dev, struct unit_directory, device);
174 if (ud->vendor_name_kv)
175 csr1212_release_keyval(ud->vendor_name_kv);
176 if (ud->model_name_kv)
177 csr1212_release_keyval(ud->model_name_kv);
182 static void nodemgr_release_ne(struct device *dev)
184 struct node_entry *ne = container_of(dev, struct node_entry, device);
186 if (ne->vendor_name_kv)
187 csr1212_release_keyval(ne->vendor_name_kv);
193 static void nodemgr_release_host(struct device *dev)
195 struct hpsb_host *host = container_of(dev, struct hpsb_host, device);
197 csr1212_destroy_csr(host->csr.rom);
202 static int nodemgr_ud_platform_data;
204 static struct device nodemgr_dev_template_ud = {
205 .bus = &ieee1394_bus_type,
206 .release = nodemgr_release_ud,
207 .platform_data = &nodemgr_ud_platform_data,
210 static struct device nodemgr_dev_template_ne = {
211 .bus = &ieee1394_bus_type,
212 .release = nodemgr_release_ne,
215 struct device nodemgr_dev_template_host = {
216 .bus = &ieee1394_bus_type,
217 .release = nodemgr_release_host,
221 #define fw_attr(class, class_type, field, type, format_string) \
222 static ssize_t fw_show_##class##_##field (struct device *dev, char *buf)\
225 class = container_of(dev, class_type, device); \
226 return sprintf(buf, format_string, (type)class->field); \
228 static struct device_attribute dev_attr_##class##_##field = { \
229 .attr = {.name = __stringify(field), .mode = S_IRUGO }, \
230 .show = fw_show_##class##_##field, \
233 #define fw_attr_td(class, class_type, td_kv) \
234 static ssize_t fw_show_##class##_##td_kv (struct device *dev, char *buf)\
237 class_type *class = container_of(dev, class_type, device); \
238 len = (class->td_kv->value.leaf.len - 2) * sizeof(quadlet_t); \
240 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(class->td_kv), \
242 while ((buf + len - 1) == '\0') \
248 static struct device_attribute dev_attr_##class##_##td_kv = { \
249 .attr = {.name = __stringify(td_kv), .mode = S_IRUGO }, \
250 .show = fw_show_##class##_##td_kv, \
254 #define fw_drv_attr(field, type, format_string) \
255 static ssize_t fw_drv_show_##field (struct device_driver *drv, char *buf) \
257 struct hpsb_protocol_driver *driver; \
258 driver = container_of(drv, struct hpsb_protocol_driver, driver); \
259 return sprintf(buf, format_string, (type)driver->field);\
261 static struct driver_attribute driver_attr_drv_##field = { \
262 .attr = {.name = __stringify(field), .mode = S_IRUGO }, \
263 .show = fw_drv_show_##field, \
267 static ssize_t fw_show_ne_bus_options(struct device *dev, char *buf)
269 struct node_entry *ne = container_of(dev, struct node_entry, device);
271 return sprintf(buf, "IRMC(%d) CMC(%d) ISC(%d) BMC(%d) PMC(%d) GEN(%d) "
272 "LSPD(%d) MAX_REC(%d) MAX_ROM(%d) CYC_CLK_ACC(%d)\n",
274 ne->busopt.cmc, ne->busopt.isc, ne->busopt.bmc,
275 ne->busopt.pmc, ne->busopt.generation, ne->busopt.lnkspd,
278 ne->busopt.cyc_clk_acc);
280 static DEVICE_ATTR(bus_options,S_IRUGO,fw_show_ne_bus_options,NULL);
283 static ssize_t fw_show_ne_tlabels_free(struct device *dev, char *buf)
285 struct node_entry *ne = container_of(dev, struct node_entry, device);
286 return sprintf(buf, "%d\n", atomic_read(&ne->tpool->count.count) + 1);
288 static DEVICE_ATTR(tlabels_free,S_IRUGO,fw_show_ne_tlabels_free,NULL);
291 static ssize_t fw_show_ne_tlabels_allocations(struct device *dev, char *buf)
293 struct node_entry *ne = container_of(dev, struct node_entry, device);
294 return sprintf(buf, "%u\n", ne->tpool->allocations);
296 static DEVICE_ATTR(tlabels_allocations,S_IRUGO,fw_show_ne_tlabels_allocations,NULL);
299 static ssize_t fw_show_ne_tlabels_mask(struct device *dev, char *buf)
301 struct node_entry *ne = container_of(dev, struct node_entry, device);
302 #if (BITS_PER_LONG <= 32)
303 return sprintf(buf, "0x%08lx%08lx\n", ne->tpool->pool[0], ne->tpool->pool[1]);
305 return sprintf(buf, "0x%016lx\n", ne->tpool->pool[0]);
308 static DEVICE_ATTR(tlabels_mask, S_IRUGO, fw_show_ne_tlabels_mask, NULL);
311 static ssize_t fw_set_ignore_driver(struct device *dev, const char *buf, size_t count)
313 struct unit_directory *ud = container_of(dev, struct unit_directory, device);
314 int state = simple_strtoul(buf, NULL, 10);
317 down_write(&dev->bus->subsys.rwsem);
318 device_release_driver(dev);
319 ud->ignore_driver = 1;
320 up_write(&dev->bus->subsys.rwsem);
322 ud->ignore_driver = 0;
326 static ssize_t fw_get_ignore_driver(struct device *dev, char *buf)
328 struct unit_directory *ud = container_of(dev, struct unit_directory, device);
330 return sprintf(buf, "%d\n", ud->ignore_driver);
332 static DEVICE_ATTR(ignore_driver, S_IWUSR | S_IRUGO, fw_get_ignore_driver, fw_set_ignore_driver);
335 static ssize_t fw_set_destroy_node(struct bus_type *bus, const char *buf, size_t count)
337 struct node_entry *ne;
338 u64 guid = (u64)simple_strtoull(buf, NULL, 16);
340 ne = find_entry_by_guid(guid);
342 if (ne == NULL || !ne->in_limbo)
345 nodemgr_remove_ne(ne);
349 static ssize_t fw_get_destroy_node(struct bus_type *bus, char *buf)
351 return sprintf(buf, "You can destroy in_limbo nodes by writing their GUID to this file\n");
353 static BUS_ATTR(destroy_node, S_IWUSR | S_IRUGO, fw_get_destroy_node, fw_set_destroy_node);
355 static int nodemgr_rescan_bus_thread(void *__unused)
357 /* No userlevel access needed */
358 daemonize("kfwrescan");
360 bus_rescan_devices(&ieee1394_bus_type);
365 static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, size_t count)
367 int state = simple_strtoul(buf, NULL, 10);
369 /* Don't wait for this, or care about errors. Root could do
370 * something stupid and spawn this a lot of times, but that's
373 kernel_thread(nodemgr_rescan_bus_thread, NULL, CLONE_KERNEL);
377 static ssize_t fw_get_rescan(struct bus_type *bus, char *buf)
379 return sprintf(buf, "You can force a rescan of the bus for "
380 "drivers by writing a 1 to this file\n");
382 static BUS_ATTR(rescan, S_IWUSR | S_IRUGO, fw_get_rescan, fw_set_rescan);
385 static ssize_t fw_set_ignore_drivers(struct bus_type *bus, const char *buf, size_t count)
387 int state = simple_strtoul(buf, NULL, 10);
396 static ssize_t fw_get_ignore_drivers(struct bus_type *bus, char *buf)
398 return sprintf(buf, "%d\n", ignore_drivers);
400 static BUS_ATTR(ignore_drivers, S_IWUSR | S_IRUGO, fw_get_ignore_drivers, fw_set_ignore_drivers);
403 struct bus_attribute *const fw_bus_attrs[] = {
404 &bus_attr_destroy_node,
406 &bus_attr_ignore_drivers,
411 fw_attr(ne, struct node_entry, capabilities, unsigned int, "0x%06x\n")
412 fw_attr(ne, struct node_entry, nodeid, unsigned int, "0x%04x\n")
414 fw_attr(ne, struct node_entry, vendor_id, unsigned int, "0x%06x\n")
415 fw_attr_td(ne, struct node_entry, vendor_name_kv)
416 fw_attr(ne, struct node_entry, vendor_oui, const char *, "%s\n")
418 fw_attr(ne, struct node_entry, guid, unsigned long long, "0x%016Lx\n")
419 fw_attr(ne, struct node_entry, guid_vendor_id, unsigned int, "0x%06x\n")
420 fw_attr(ne, struct node_entry, guid_vendor_oui, const char *, "%s\n")
421 fw_attr(ne, struct node_entry, in_limbo, int, "%d\n");
423 static struct device_attribute *const fw_ne_attrs[] = {
425 &dev_attr_ne_guid_vendor_id,
426 &dev_attr_ne_capabilities,
427 &dev_attr_ne_vendor_id,
429 &dev_attr_bus_options,
430 &dev_attr_tlabels_free,
431 &dev_attr_tlabels_allocations,
432 &dev_attr_tlabels_mask,
437 fw_attr(ud, struct unit_directory, address, unsigned long long, "0x%016Lx\n")
438 fw_attr(ud, struct unit_directory, length, int, "%d\n")
439 /* These are all dependent on the value being provided */
440 fw_attr(ud, struct unit_directory, vendor_id, unsigned int, "0x%06x\n")
441 fw_attr(ud, struct unit_directory, model_id, unsigned int, "0x%06x\n")
442 fw_attr(ud, struct unit_directory, specifier_id, unsigned int, "0x%06x\n")
443 fw_attr(ud, struct unit_directory, version, unsigned int, "0x%06x\n")
444 fw_attr_td(ud, struct unit_directory, vendor_name_kv)
445 fw_attr(ud, struct unit_directory, vendor_oui, const char *, "%s\n")
446 fw_attr_td(ud, struct unit_directory, model_name_kv)
448 static struct device_attribute *const fw_ud_attrs[] = {
449 &dev_attr_ud_address,
451 &dev_attr_ignore_driver,
455 fw_attr(host, struct hpsb_host, node_count, int, "%d\n")
456 fw_attr(host, struct hpsb_host, selfid_count, int, "%d\n")
457 fw_attr(host, struct hpsb_host, nodes_active, int, "%d\n")
458 fw_attr(host, struct hpsb_host, in_bus_reset, int, "%d\n")
459 fw_attr(host, struct hpsb_host, is_root, int, "%d\n")
460 fw_attr(host, struct hpsb_host, is_cycmst, int, "%d\n")
461 fw_attr(host, struct hpsb_host, is_irm, int, "%d\n")
462 fw_attr(host, struct hpsb_host, is_busmgr, int, "%d\n")
464 static struct device_attribute *const fw_host_attrs[] = {
465 &dev_attr_host_node_count,
466 &dev_attr_host_selfid_count,
467 &dev_attr_host_nodes_active,
468 &dev_attr_host_in_bus_reset,
469 &dev_attr_host_is_root,
470 &dev_attr_host_is_cycmst,
471 &dev_attr_host_is_irm,
472 &dev_attr_host_is_busmgr,
476 static ssize_t fw_show_drv_device_ids(struct device_driver *drv, char *buf)
478 struct hpsb_protocol_driver *driver;
479 struct ieee1394_device_id *id;
483 driver = container_of(drv, struct hpsb_protocol_driver, driver);
485 for (id = driver->id_table; id->match_flags != 0; id++) {
488 if (id->match_flags & IEEE1394_MATCH_VENDOR_ID) {
489 length += sprintf(scratch, "vendor_id=0x%06x", id->vendor_id);
490 scratch = buf + length;
494 if (id->match_flags & IEEE1394_MATCH_MODEL_ID) {
495 length += sprintf(scratch, "%smodel_id=0x%06x",
496 need_coma++ ? "," : "",
498 scratch = buf + length;
501 if (id->match_flags & IEEE1394_MATCH_SPECIFIER_ID) {
502 length += sprintf(scratch, "%sspecifier_id=0x%06x",
503 need_coma++ ? "," : "",
505 scratch = buf + length;
508 if (id->match_flags & IEEE1394_MATCH_VERSION) {
509 length += sprintf(scratch, "%sversion=0x%06x",
510 need_coma++ ? "," : "",
512 scratch = buf + length;
523 static DRIVER_ATTR(device_ids,S_IRUGO,fw_show_drv_device_ids,NULL);
526 fw_drv_attr(name, const char *, "%s\n")
528 static struct driver_attribute *const fw_drv_attrs[] = {
529 &driver_attr_drv_name,
530 &driver_attr_device_ids,
534 static void nodemgr_create_drv_files(struct hpsb_protocol_driver *driver)
536 struct device_driver *drv = &driver->driver;
539 for (i = 0; i < ARRAY_SIZE(fw_drv_attrs); i++)
540 driver_create_file(drv, fw_drv_attrs[i]);
544 static void nodemgr_remove_drv_files(struct hpsb_protocol_driver *driver)
546 struct device_driver *drv = &driver->driver;
549 for (i = 0; i < ARRAY_SIZE(fw_drv_attrs); i++)
550 driver_remove_file(drv, fw_drv_attrs[i]);
554 static void nodemgr_create_ne_dev_files(struct node_entry *ne)
556 struct device *dev = &ne->device;
559 for (i = 0; i < ARRAY_SIZE(fw_ne_attrs); i++)
560 device_create_file(dev, fw_ne_attrs[i]);
564 static void nodemgr_create_host_dev_files(struct hpsb_host *host)
566 struct device *dev = &host->device;
569 for (i = 0; i < ARRAY_SIZE(fw_host_attrs); i++)
570 device_create_file(dev, fw_host_attrs[i]);
574 static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, nodeid_t nodeid);
576 static void nodemgr_update_host_dev_links(struct hpsb_host *host)
578 struct device *dev = &host->device;
579 struct node_entry *ne;
581 sysfs_remove_link(&dev->kobj, "irm_id");
582 sysfs_remove_link(&dev->kobj, "busmgr_id");
583 sysfs_remove_link(&dev->kobj, "host_id");
585 if ((ne = find_entry_by_nodeid(host, host->irm_id)))
586 sysfs_create_link(&dev->kobj, &ne->device.kobj, "irm_id");
587 if ((ne = find_entry_by_nodeid(host, host->busmgr_id)))
588 sysfs_create_link(&dev->kobj, &ne->device.kobj, "busmgr_id");
589 if ((ne = find_entry_by_nodeid(host, host->node_id)))
590 sysfs_create_link(&dev->kobj, &ne->device.kobj, "host_id");
593 static void nodemgr_create_ud_dev_files(struct unit_directory *ud)
595 struct device *dev = &ud->device;
598 for (i = 0; i < ARRAY_SIZE(fw_ud_attrs); i++)
599 device_create_file(dev, fw_ud_attrs[i]);
601 if (ud->flags & UNIT_DIRECTORY_SPECIFIER_ID)
602 device_create_file(dev, &dev_attr_ud_specifier_id);
604 if (ud->flags & UNIT_DIRECTORY_VERSION)
605 device_create_file(dev, &dev_attr_ud_version);
607 if (ud->flags & UNIT_DIRECTORY_VENDOR_ID) {
608 device_create_file(dev, &dev_attr_ud_vendor_id);
609 if (ud->vendor_name_kv)
610 device_create_file(dev, &dev_attr_ud_vendor_name_kv);
613 if (ud->flags & UNIT_DIRECTORY_MODEL_ID) {
614 device_create_file(dev, &dev_attr_ud_model_id);
615 if (ud->model_name_kv)
616 device_create_file(dev, &dev_attr_ud_model_name_kv);
621 static int nodemgr_bus_match(struct device * dev, struct device_driver * drv)
623 struct hpsb_protocol_driver *driver;
624 struct unit_directory *ud;
625 struct ieee1394_device_id *id;
627 /* We only match unit directories */
628 if (dev->platform_data != &nodemgr_ud_platform_data)
631 ud = container_of(dev, struct unit_directory, device);
632 driver = container_of(drv, struct hpsb_protocol_driver, driver);
634 if (ud->ne->in_limbo || ud->ignore_driver)
637 for (id = driver->id_table; id->match_flags != 0; id++) {
638 if ((id->match_flags & IEEE1394_MATCH_VENDOR_ID) &&
639 id->vendor_id != ud->vendor_id)
642 if ((id->match_flags & IEEE1394_MATCH_MODEL_ID) &&
643 id->model_id != ud->model_id)
646 if ((id->match_flags & IEEE1394_MATCH_SPECIFIER_ID) &&
647 id->specifier_id != ud->specifier_id)
650 if ((id->match_flags & IEEE1394_MATCH_VERSION) &&
651 id->version != ud->version)
661 static void nodemgr_remove_uds(struct node_entry *ne)
663 struct class_device *cdev, *next;
664 struct unit_directory *ud;
666 list_for_each_entry_safe(cdev, next, &nodemgr_ud_class.children, node) {
667 ud = container_of(cdev, struct unit_directory, class_dev);
672 class_device_unregister(&ud->class_dev);
673 device_unregister(&ud->device);
678 static void nodemgr_remove_ne(struct node_entry *ne)
680 struct device *dev = &ne->device;
682 dev = get_device(&ne->device);
686 HPSB_DEBUG("Node removed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
687 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
689 nodemgr_remove_uds(ne);
691 class_device_unregister(&ne->class_dev);
692 device_unregister(dev);
698 static void nodemgr_remove_host_dev(struct device *dev)
700 struct device *ne_dev, *next;
702 list_for_each_entry_safe(ne_dev, next, &dev->children, node)
703 nodemgr_remove_ne(container_of(ne_dev, struct node_entry, device));
705 sysfs_remove_link(&dev->kobj, "irm_id");
706 sysfs_remove_link(&dev->kobj, "busmgr_id");
707 sysfs_remove_link(&dev->kobj, "host_id");
711 static void nodemgr_update_bus_options(struct node_entry *ne)
713 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
714 static const u16 mr[] = { 4, 64, 1024, 0};
716 quadlet_t busoptions = be32_to_cpu(ne->csr->bus_info_data[2]);
718 ne->busopt.irmc = (busoptions >> 31) & 1;
719 ne->busopt.cmc = (busoptions >> 30) & 1;
720 ne->busopt.isc = (busoptions >> 29) & 1;
721 ne->busopt.bmc = (busoptions >> 28) & 1;
722 ne->busopt.pmc = (busoptions >> 27) & 1;
723 ne->busopt.cyc_clk_acc = (busoptions >> 16) & 0xff;
724 ne->busopt.max_rec = 1 << (((busoptions >> 12) & 0xf) + 1);
725 ne->busopt.max_rom = (busoptions >> 8) & 0x3;
726 ne->busopt.generation = (busoptions >> 4) & 0xf;
727 ne->busopt.lnkspd = busoptions & 0x7;
729 HPSB_VERBOSE("NodeMgr: raw=0x%08x irmc=%d cmc=%d isc=%d bmc=%d pmc=%d "
730 "cyc_clk_acc=%d max_rec=%d max_rom=%d gen=%d lspd=%d",
731 busoptions, ne->busopt.irmc, ne->busopt.cmc,
732 ne->busopt.isc, ne->busopt.bmc, ne->busopt.pmc,
733 ne->busopt.cyc_clk_acc, ne->busopt.max_rec,
734 mr[ne->busopt.max_rom],
735 ne->busopt.generation, ne->busopt.lnkspd);
739 static struct node_entry *nodemgr_create_node(octlet_t guid, struct csr1212_csr *csr,
740 struct host_info *hi, nodeid_t nodeid,
741 unsigned int generation)
743 struct hpsb_host *host = hi->host;
744 struct node_entry *ne;
746 ne = kmalloc(sizeof(struct node_entry), GFP_KERNEL);
747 if (!ne) return NULL;
749 memset(ne, 0, sizeof(struct node_entry));
751 ne->tpool = &host->tpool[nodeid & NODE_MASK];
755 ne->generation = generation;
759 ne->guid_vendor_id = (guid >> 40) & 0xffffff;
760 ne->guid_vendor_oui = nodemgr_find_oui_name(ne->guid_vendor_id);
763 memcpy(&ne->device, &nodemgr_dev_template_ne,
765 ne->device.parent = &host->device;
766 snprintf(ne->device.bus_id, BUS_ID_SIZE, "%016Lx",
767 (unsigned long long)(ne->guid));
769 ne->class_dev.dev = &ne->device;
770 ne->class_dev.class = &nodemgr_ne_class;
771 snprintf(ne->class_dev.class_id, BUS_ID_SIZE, "%016Lx",
772 (unsigned long long)(ne->guid));
774 device_register(&ne->device);
775 class_device_register(&ne->class_dev);
776 get_device(&ne->device);
778 if (ne->guid_vendor_oui)
779 device_create_file(&ne->device, &dev_attr_ne_guid_vendor_oui);
780 nodemgr_create_ne_dev_files(ne);
782 nodemgr_update_bus_options(ne);
784 HPSB_DEBUG("%s added: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
785 (host->node_id == nodeid) ? "Host" : "Node",
786 NODE_BUS_ARGS(host, nodeid), (unsigned long long)guid);
792 static struct node_entry *find_entry_by_guid(u64 guid)
794 struct class *class = &nodemgr_ne_class;
795 struct class_device *cdev;
796 struct node_entry *ne, *ret_ne = NULL;
798 down_read(&class->subsys.rwsem);
799 list_for_each_entry(cdev, &class->children, node) {
800 ne = container_of(cdev, struct node_entry, class_dev);
802 if (ne->guid == guid) {
807 up_read(&class->subsys.rwsem);
813 static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, nodeid_t nodeid)
815 struct class *class = &nodemgr_ne_class;
816 struct class_device *cdev;
817 struct node_entry *ne, *ret_ne = NULL;
819 down_read(&class->subsys.rwsem);
820 list_for_each_entry(cdev, &class->children, node) {
821 ne = container_of(cdev, struct node_entry, class_dev);
823 if (ne->host == host && ne->nodeid == nodeid) {
828 up_read(&class->subsys.rwsem);
835 /* This implementation currently only scans the config rom and its
836 * immediate unit directories looking for software_id and
837 * software_version entries, in order to get driver autoloading working. */
838 static struct unit_directory *nodemgr_process_unit_directory
839 (struct host_info *hi, struct node_entry *ne, struct csr1212_keyval *ud_kv,
840 unsigned int *id, struct unit_directory *parent)
842 struct unit_directory *ud;
843 struct unit_directory *ud_temp = NULL;
844 struct csr1212_dentry *dentry;
845 struct csr1212_keyval *kv;
848 ud = kmalloc(sizeof(struct unit_directory), GFP_KERNEL);
850 goto unit_directory_error;
852 memset (ud, 0, sizeof(struct unit_directory));
855 ud->ignore_driver = ignore_drivers;
856 ud->address = ud_kv->offset + CSR1212_CONFIG_ROM_SPACE_BASE;
860 csr1212_for_each_dir_entry(ne->csr, kv, ud_kv, dentry) {
861 switch (kv->key.id) {
862 case CSR1212_KV_ID_VENDOR:
863 if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) {
864 ud->vendor_id = kv->value.immediate;
865 ud->flags |= UNIT_DIRECTORY_VENDOR_ID;
868 ud->vendor_oui = nodemgr_find_oui_name(ud->vendor_id);
872 case CSR1212_KV_ID_MODEL:
873 ud->model_id = kv->value.immediate;
874 ud->flags |= UNIT_DIRECTORY_MODEL_ID;
877 case CSR1212_KV_ID_SPECIFIER_ID:
878 ud->specifier_id = kv->value.immediate;
879 ud->flags |= UNIT_DIRECTORY_SPECIFIER_ID;
882 case CSR1212_KV_ID_VERSION:
883 ud->version = kv->value.immediate;
884 ud->flags |= UNIT_DIRECTORY_VERSION;
887 case CSR1212_KV_ID_DESCRIPTOR:
888 if (kv->key.type == CSR1212_KV_TYPE_LEAF &&
889 CSR1212_DESCRIPTOR_LEAF_TYPE(kv) == 0 &&
890 CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) == 0 &&
891 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) == 0 &&
892 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) == 0 &&
893 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0) {
894 switch (last_key_id) {
895 case CSR1212_KV_ID_VENDOR:
896 ud->vendor_name_kv = kv;
897 csr1212_keep_keyval(kv);
900 case CSR1212_KV_ID_MODEL:
901 ud->model_name_kv = kv;
902 csr1212_keep_keyval(kv);
906 } /* else if (kv->key.type == CSR1212_KV_TYPE_DIRECTORY) ... */
909 case CSR1212_KV_ID_DEPENDENT_INFO:
910 if (kv->key.type == CSR1212_KV_TYPE_DIRECTORY) {
911 /* This should really be done in SBP2 as this is
912 * doing SBP2 specific parsing. */
913 ud->flags |= UNIT_DIRECTORY_HAS_LUN_DIRECTORY;
914 ud_temp = nodemgr_process_unit_directory(hi, ne, kv, id,
920 /* inherit unspecified values */
921 if ((ud->flags & UNIT_DIRECTORY_VENDOR_ID) &&
922 !(ud_temp->flags & UNIT_DIRECTORY_VENDOR_ID))
924 ud_temp->flags |= UNIT_DIRECTORY_VENDOR_ID;
925 ud_temp->vendor_id = ud->vendor_id;
926 ud_temp->vendor_oui = ud->vendor_oui;
928 if ((ud->flags & UNIT_DIRECTORY_MODEL_ID) &&
929 !(ud_temp->flags & UNIT_DIRECTORY_MODEL_ID))
931 ud_temp->flags |= UNIT_DIRECTORY_MODEL_ID;
932 ud_temp->model_id = ud->model_id;
934 if ((ud->flags & UNIT_DIRECTORY_SPECIFIER_ID) &&
935 !(ud_temp->flags & UNIT_DIRECTORY_SPECIFIER_ID))
937 ud_temp->flags |= UNIT_DIRECTORY_SPECIFIER_ID;
938 ud_temp->specifier_id = ud->specifier_id;
940 if ((ud->flags & UNIT_DIRECTORY_VERSION) &&
941 !(ud_temp->flags & UNIT_DIRECTORY_VERSION))
943 ud_temp->flags |= UNIT_DIRECTORY_VERSION;
944 ud_temp->version = ud->version;
953 last_key_id = kv->key.id;
956 memcpy(&ud->device, &nodemgr_dev_template_ud,
960 ud->flags |= UNIT_DIRECTORY_LUN_DIRECTORY;
961 ud->device.parent = &parent->device;
963 ud->device.parent = &ne->device;
965 snprintf(ud->device.bus_id, BUS_ID_SIZE, "%s-%u",
966 ne->device.bus_id, ud->id);
968 ud->class_dev.dev = &ud->device;
969 ud->class_dev.class = &nodemgr_ud_class;
970 snprintf(ud->class_dev.class_id, BUS_ID_SIZE, "%s-%u",
971 ne->device.bus_id, ud->id);
973 device_register(&ud->device);
974 class_device_register(&ud->class_dev);
975 get_device(&ud->device);
978 device_create_file(&ud->device, &dev_attr_ud_vendor_oui);
979 nodemgr_create_ud_dev_files(ud);
983 unit_directory_error:
990 static void nodemgr_process_root_directory(struct host_info *hi, struct node_entry *ne)
992 unsigned int ud_id = 0;
993 struct csr1212_dentry *dentry;
994 struct csr1212_keyval *kv;
999 csr1212_for_each_dir_entry(ne->csr, kv, ne->csr->root_kv, dentry) {
1000 switch (kv->key.id) {
1001 case CSR1212_KV_ID_VENDOR:
1002 ne->vendor_id = kv->value.immediate;
1005 ne->vendor_oui = nodemgr_find_oui_name(ne->vendor_id);
1008 case CSR1212_KV_ID_NODE_CAPABILITIES:
1009 ne->capabilities = kv->value.immediate;
1012 case CSR1212_KV_ID_UNIT:
1013 nodemgr_process_unit_directory(hi, ne, kv, &ud_id, NULL);
1016 case CSR1212_KV_ID_DESCRIPTOR:
1017 if (last_key_id == CSR1212_KV_ID_VENDOR) {
1018 if (kv->key.type == CSR1212_KV_TYPE_LEAF &&
1019 CSR1212_DESCRIPTOR_LEAF_TYPE(kv) == 0 &&
1020 CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) == 0 &&
1021 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) == 0 &&
1022 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) == 0 &&
1023 CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0) {
1024 ne->vendor_name_kv = kv;
1025 csr1212_keep_keyval(kv);
1030 last_key_id = kv->key.id;
1034 device_create_file(&ne->device, &dev_attr_ne_vendor_oui);
1035 if (ne->vendor_name_kv)
1036 device_create_file(&ne->device, &dev_attr_ne_vendor_name_kv);
1039 #ifdef CONFIG_HOTPLUG
1041 static int nodemgr_hotplug(struct class_device *cdev, char **envp, int num_envp,
1042 char *buffer, int buffer_size)
1044 struct unit_directory *ud;
1051 ud = container_of(cdev, struct unit_directory, class_dev);
1053 if (ud->ne->in_limbo || ud->ignore_driver)
1056 #define PUT_ENVP(fmt,val) \
1059 envp[i++] = buffer; \
1060 printed = snprintf(buffer, buffer_size - length, \
1062 if ((buffer_size - (length+printed) <= 0) || (i >= num_envp)) \
1064 length += printed+1; \
1065 buffer += printed+1; \
1068 PUT_ENVP("VENDOR_ID=%06x", ud->vendor_id);
1069 PUT_ENVP("MODEL_ID=%06x", ud->model_id);
1070 PUT_ENVP("GUID=%016Lx", (unsigned long long)ud->ne->guid);
1071 PUT_ENVP("SPECIFIER_ID=%06x", ud->specifier_id);
1072 PUT_ENVP("VERSION=%06x", ud->version);
1083 static int nodemgr_hotplug(struct class_device *cdev, char **envp, int num_envp,
1084 char *buffer, int buffer_size)
1089 #endif /* CONFIG_HOTPLUG */
1092 int hpsb_register_protocol(struct hpsb_protocol_driver *driver)
1096 /* This will cause a probe for devices */
1097 ret = driver_register(&driver->driver);
1099 nodemgr_create_drv_files(driver);
1104 void hpsb_unregister_protocol(struct hpsb_protocol_driver *driver)
1106 nodemgr_remove_drv_files(driver);
1107 /* This will subsequently disconnect all devices that our driver
1108 * is attached to. */
1109 driver_unregister(&driver->driver);
1114 * This function updates nodes that were present on the bus before the
1115 * reset and still are after the reset. The nodeid and the config rom
1116 * may have changed, and the drivers managing this device must be
1117 * informed that this device just went through a bus reset, to allow
1118 * the to take whatever actions required.
1120 static void nodemgr_update_node(struct node_entry *ne, struct csr1212_csr *csr,
1121 struct host_info *hi, nodeid_t nodeid,
1122 unsigned int generation)
1124 if (ne->nodeid != nodeid) {
1125 HPSB_DEBUG("Node changed: " NODE_BUS_FMT " -> " NODE_BUS_FMT,
1126 NODE_BUS_ARGS(ne->host, ne->nodeid),
1127 NODE_BUS_ARGS(ne->host, nodeid));
1128 ne->nodeid = nodeid;
1131 if (ne->busopt.generation != ((be32_to_cpu(csr->bus_info_data[2]) >> 4) & 0xf)) {
1132 kfree(ne->csr->private);
1133 csr1212_destroy_csr(ne->csr);
1136 /* If the node's configrom generation has changed, we
1137 * unregister all the unit directories. */
1138 nodemgr_remove_uds(ne);
1140 nodemgr_update_bus_options(ne);
1142 /* Mark the node as new, so it gets re-probed */
1143 ne->needs_probe = 1;
1147 nodemgr_resume_ne(ne);
1149 /* Mark the node current */
1150 ne->generation = generation;
1155 static void nodemgr_node_scan_one(struct host_info *hi,
1156 nodeid_t nodeid, int generation)
1158 struct hpsb_host *host = hi->host;
1159 struct node_entry *ne;
1161 struct csr1212_csr *csr;
1162 struct nodemgr_csr_info *ci;
1164 ci = kmalloc(sizeof(struct nodemgr_csr_info), GFP_KERNEL);
1169 ci->nodeid = nodeid;
1170 ci->generation = generation;
1172 /* We need to detect when the ConfigROM's generation has changed,
1173 * so we only update the node's info when it needs to be. */
1175 csr = csr1212_create_csr(&nodemgr_csr_ops, 5 * sizeof(quadlet_t), ci);
1176 if (!csr || csr1212_parse_csr(csr) != CSR1212_SUCCESS) {
1177 HPSB_ERR("Error parsing configrom for node " NODE_BUS_FMT,
1178 NODE_BUS_ARGS(host, nodeid));
1180 csr1212_destroy_csr(csr);
1185 if (csr->bus_info_data[1] != IEEE1394_BUSID_MAGIC) {
1186 /* This isn't a 1394 device, but we let it slide. There
1187 * was a report of a device with broken firmware which
1188 * reported '2394' instead of '1394', which is obviously a
1189 * mistake. One would hope that a non-1394 device never
1190 * gets connected to Firewire bus. If someone does, we
1191 * shouldn't be held responsible, so we'll allow it with a
1193 HPSB_WARN("Node " NODE_BUS_FMT " has invalid busID magic [0x%08x]",
1194 NODE_BUS_ARGS(host, nodeid), csr->bus_info_data[1]);
1197 guid = ((u64)be32_to_cpu(csr->bus_info_data[3]) << 32) | be32_to_cpu(csr->bus_info_data[4]);
1198 ne = find_entry_by_guid(guid);
1200 if (ne && ne->host != host && ne->in_limbo) {
1201 /* Must have moved this device from one host to another */
1202 nodemgr_remove_ne(ne);
1207 nodemgr_create_node(guid, csr, hi, nodeid, generation);
1209 nodemgr_update_node(ne, csr, hi, nodeid, generation);
1215 static void nodemgr_node_scan(struct host_info *hi, int generation)
1218 struct hpsb_host *host = hi->host;
1219 struct selfid *sid = (struct selfid *)host->topology_map;
1220 nodeid_t nodeid = LOCAL_BUS;
1222 /* Scan each node on the bus */
1223 for (count = host->selfid_count; count; count--, sid++) {
1227 if (!sid->link_active) {
1231 nodemgr_node_scan_one(hi, nodeid++, generation);
1236 static void nodemgr_suspend_ne(struct node_entry *ne)
1238 struct class_device *cdev;
1239 struct unit_directory *ud;
1241 HPSB_DEBUG("Node suspended: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
1242 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
1245 device_create_file(&ne->device, &dev_attr_ne_in_limbo);
1247 down_write(&ne->device.bus->subsys.rwsem);
1248 list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
1249 ud = container_of(cdev, struct unit_directory, class_dev);
1254 if (ud->device.driver &&
1255 (!ud->device.driver->suspend ||
1256 ud->device.driver->suspend(&ud->device, 0, 0)))
1257 device_release_driver(&ud->device);
1259 up_write(&ne->device.bus->subsys.rwsem);
1263 static void nodemgr_resume_ne(struct node_entry *ne)
1265 struct class_device *cdev;
1266 struct unit_directory *ud;
1269 device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
1271 down_read(&ne->device.bus->subsys.rwsem);
1272 list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
1273 ud = container_of(cdev, struct unit_directory, class_dev);
1278 if (ud->device.driver && ud->device.driver->resume)
1279 ud->device.driver->resume(&ud->device, 0);
1281 up_read(&ne->device.bus->subsys.rwsem);
1283 HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
1284 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
1288 static void nodemgr_update_pdrv(struct node_entry *ne)
1290 struct unit_directory *ud;
1291 struct hpsb_protocol_driver *pdrv;
1292 struct class *class = &nodemgr_ud_class;
1293 struct class_device *cdev;
1295 down_read(&class->subsys.rwsem);
1296 list_for_each_entry(cdev, &class->children, node) {
1297 ud = container_of(cdev, struct unit_directory, class_dev);
1298 if (ud->ne != ne || !ud->device.driver)
1301 pdrv = container_of(ud->device.driver, struct hpsb_protocol_driver, driver);
1303 if (pdrv->update && pdrv->update(ud)) {
1304 down_write(&ud->device.bus->subsys.rwsem);
1305 device_release_driver(&ud->device);
1306 up_write(&ud->device.bus->subsys.rwsem);
1309 up_read(&class->subsys.rwsem);
1313 static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int generation)
1317 if (ne->host != hi->host || ne->in_limbo)
1320 dev = get_device(&ne->device);
1324 /* If "needs_probe", then this is either a new or changed node we
1325 * rescan totally. If the generation matches for an existing node
1326 * (one that existed prior to the bus reset) we send update calls
1327 * down to the drivers. Otherwise, this is a dead node and we
1329 if (ne->needs_probe)
1330 nodemgr_process_root_directory(hi, ne);
1331 else if (ne->generation == generation)
1332 nodemgr_update_pdrv(ne);
1334 nodemgr_suspend_ne(ne);
1340 static void nodemgr_node_probe(struct host_info *hi, int generation)
1342 struct hpsb_host *host = hi->host;
1343 struct class *class = &nodemgr_ne_class;
1344 struct class_device *cdev;
1346 /* Do some processing of the nodes we've probed. This pulls them
1347 * into the sysfs layer if needed, and can result in processing of
1348 * unit-directories, or just updating the node and it's
1349 * unit-directories. */
1350 down_read(&class->subsys.rwsem);
1351 list_for_each_entry(cdev, &class->children, node)
1352 nodemgr_probe_ne(hi, container_of(cdev, struct node_entry, class_dev), generation);
1353 up_read(&class->subsys.rwsem);
1356 /* If we had a bus reset while we were scanning the bus, it is
1357 * possible that we did not probe all nodes. In that case, we
1358 * skip the clean up for now, since we could remove nodes that
1359 * were still on the bus. The bus reset increased hi->reset_sem,
1360 * so there's a bus scan pending which will do the clean up
1363 * Now let's tell the bus to rescan our devices. This may seem
1364 * like overhead, but the driver-model core will only scan a
1365 * device for a driver when either the device is added, or when a
1366 * new driver is added. A bus reset is a good reason to rescan
1367 * devices that were there before. For example, an sbp2 device
1368 * may become available for login, if the host that held it was
1371 if (generation == get_hpsb_generation(host))
1372 bus_rescan_devices(&ieee1394_bus_type);
1377 /* Because we are a 1394a-2000 compliant IRM, we need to inform all the other
1378 * nodes of the broadcast channel. (Really we're only setting the validity
1379 * bit). Other IRM responsibilities go in here as well. */
1380 static int nodemgr_do_irm_duties(struct hpsb_host *host, int cycles)
1384 /* if irm_id == -1 then there is no IRM on this bus */
1385 if (!host->is_irm || host->irm_id == (nodeid_t)-1)
1388 host->csr.broadcast_channel |= 0x40000000; /* set validity bit */
1390 bc = cpu_to_be32(host->csr.broadcast_channel);
1392 hpsb_write(host, LOCAL_BUS | ALL_NODES, get_hpsb_generation(host),
1393 (CSR_REGISTER_BASE | CSR_BROADCAST_CHANNEL),
1394 &bc, sizeof(quadlet_t));
1396 /* If there is no bus manager then we should set the root node's
1397 * force_root bit to promote bus stability per the 1394
1398 * spec. (8.4.2.6) */
1399 if (host->busmgr_id == 0xffff && host->node_count > 1)
1401 u16 root_node = host->node_count - 1;
1402 struct node_entry *ne = find_entry_by_nodeid(host, root_node | LOCAL_BUS);
1404 if (ne && ne->busopt.cmc)
1405 hpsb_send_phy_config(host, root_node, -1);
1407 HPSB_DEBUG("The root node is not cycle master capable; "
1408 "selecting a new root node and resetting...");
1411 /* Oh screw it! Just leave the bus as it is */
1412 HPSB_DEBUG("Stopping reset loop for IRM sanity");
1416 hpsb_send_phy_config(host, NODEID_TO_NODE(host->node_id), -1);
1417 hpsb_reset_bus(host, LONG_RESET_FORCE_ROOT);
1426 /* We need to ensure that if we are not the IRM, that the IRM node is capable of
1427 * everything we can do, otherwise issue a bus reset and try to become the IRM
1429 static int nodemgr_check_irm_capability(struct hpsb_host *host, int cycles)
1437 status = hpsb_read(host, LOCAL_BUS | (host->irm_id),
1438 get_hpsb_generation(host),
1439 (CSR_REGISTER_BASE | CSR_BROADCAST_CHANNEL),
1440 &bc, sizeof(quadlet_t));
1442 if (status < 0 || !(be32_to_cpu(bc) & 0x80000000)) {
1443 /* The current irm node does not have a valid BROADCAST_CHANNEL
1444 * register and we do, so reset the bus with force_root set */
1445 HPSB_DEBUG("Current remote IRM is not 1394a-2000 compliant, resetting...");
1448 /* Oh screw it! Just leave the bus as it is */
1449 HPSB_DEBUG("Stopping reset loop for IRM sanity");
1453 hpsb_send_phy_config(host, NODEID_TO_NODE(host->node_id), -1);
1454 hpsb_reset_bus(host, LONG_RESET_FORCE_ROOT);
1462 static int nodemgr_host_thread(void *__hi)
1464 struct host_info *hi = (struct host_info *)__hi;
1465 struct hpsb_host *host = hi->host;
1466 int reset_cycles = 0;
1468 /* No userlevel access needed */
1469 daemonize(hi->daemon_name);
1471 /* Setup our device-model entries */
1472 nodemgr_create_host_dev_files(host);
1474 /* Sit and wait for a signal to probe the nodes on the bus. This
1475 * happens when we get a bus reset. */
1477 unsigned int generation = 0;
1480 if (down_interruptible(&hi->reset_sem) ||
1481 down_interruptible(&nodemgr_serialize)) {
1482 if (try_to_freeze(PF_FREEZE))
1484 printk("NodeMgr: received unexpected signal?!\n" );
1489 up(&nodemgr_serialize);
1493 /* Pause for 1/4 second in 1/16 second intervals,
1494 * to make sure things settle down. */
1495 for (i = 0; i < 4 ; i++) {
1496 set_current_state(TASK_INTERRUPTIBLE);
1497 if (msleep_interruptible(63)) {
1498 up(&nodemgr_serialize);
1502 /* Now get the generation in which the node ID's we collect
1503 * are valid. During the bus scan we will use this generation
1504 * for the read transactions, so that if another reset occurs
1505 * during the scan the transactions will fail instead of
1506 * returning bogus data. */
1507 generation = get_hpsb_generation(host);
1509 /* If we get a reset before we are done waiting, then
1510 * start the the waiting over again */
1511 while (!down_trylock(&hi->reset_sem))
1514 /* Check the kill_me again */
1516 up(&nodemgr_serialize);
1521 if (!nodemgr_check_irm_capability(host, reset_cycles)) {
1523 up(&nodemgr_serialize);
1527 /* Scan our nodes to get the bus options and create node
1528 * entries. This does not do the sysfs stuff, since that
1529 * would trigger hotplug callbacks and such, which is a
1530 * bad idea at this point. */
1531 nodemgr_node_scan(hi, generation);
1532 if (!nodemgr_do_irm_duties(host, reset_cycles)) {
1534 up(&nodemgr_serialize);
1540 /* This actually does the full probe, with sysfs
1542 nodemgr_node_probe(hi, generation);
1544 /* Update some of our sysfs symlinks */
1545 nodemgr_update_host_dev_links(host);
1547 up(&nodemgr_serialize);
1551 HPSB_VERBOSE("NodeMgr: Exiting thread");
1553 complete_and_exit(&hi->exited, 0);
1556 struct node_entry *hpsb_guid_get_entry(u64 guid)
1558 struct node_entry *ne;
1560 down(&nodemgr_serialize);
1561 ne = find_entry_by_guid(guid);
1562 up(&nodemgr_serialize);
1567 struct node_entry *hpsb_nodeid_get_entry(struct hpsb_host *host, nodeid_t nodeid)
1569 struct node_entry *ne;
1571 down(&nodemgr_serialize);
1572 ne = find_entry_by_nodeid(host, nodeid);
1573 up(&nodemgr_serialize);
1579 int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *))
1581 struct class *class = &hpsb_host_class;
1582 struct class_device *cdev;
1583 struct hpsb_host *host;
1586 down_read(&class->subsys.rwsem);
1587 list_for_each_entry(cdev, &class->children, node) {
1588 host = container_of(cdev, struct hpsb_host, class_dev);
1590 if ((error = cb(host, __data)))
1593 up_read(&class->subsys.rwsem);
1598 /* The following four convenience functions use a struct node_entry
1599 * for addressing a node on the bus. They are intended for use by any
1600 * process context, not just the nodemgr thread, so we need to be a
1601 * little careful when reading out the node ID and generation. The
1602 * thing that can go wrong is that we get the node ID, then a bus
1603 * reset occurs, and then we read the generation. The node ID is
1604 * possibly invalid, but the generation is current, and we end up
1605 * sending a packet to a the wrong node.
1607 * The solution is to make sure we read the generation first, so that
1608 * if a reset occurs in the process, we end up with a stale generation
1609 * and the transactions will fail instead of silently using wrong node
1613 void hpsb_node_fill_packet(struct node_entry *ne, struct hpsb_packet *pkt)
1615 pkt->host = ne->host;
1616 pkt->generation = ne->generation;
1618 pkt->node_id = ne->nodeid;
1621 int hpsb_node_read(struct node_entry *ne, u64 addr,
1622 quadlet_t *buffer, size_t length)
1624 unsigned int generation = ne->generation;
1627 return hpsb_read(ne->host, ne->nodeid, generation,
1628 addr, buffer, length);
1631 int hpsb_node_write(struct node_entry *ne, u64 addr,
1632 quadlet_t *buffer, size_t length)
1634 unsigned int generation = ne->generation;
1637 return hpsb_write(ne->host, ne->nodeid, generation,
1638 addr, buffer, length);
1641 int hpsb_node_lock(struct node_entry *ne, u64 addr,
1642 int extcode, quadlet_t *data, quadlet_t arg)
1644 unsigned int generation = ne->generation;
1647 return hpsb_lock(ne->host, ne->nodeid, generation,
1648 addr, extcode, data, arg);
1651 static void nodemgr_add_host(struct hpsb_host *host)
1653 struct host_info *hi;
1655 hi = hpsb_create_hostinfo(&nodemgr_highlevel, host, sizeof(*hi));
1658 HPSB_ERR ("NodeMgr: out of memory in add host");
1663 init_completion(&hi->exited);
1664 sema_init(&hi->reset_sem, 0);
1666 sprintf(hi->daemon_name, "knodemgrd_%d", host->id);
1668 hi->pid = kernel_thread(nodemgr_host_thread, hi, CLONE_KERNEL);
1671 HPSB_ERR ("NodeMgr: failed to start %s thread for %s",
1672 hi->daemon_name, host->driver->name);
1673 hpsb_destroy_hostinfo(&nodemgr_highlevel, host);
1680 static void nodemgr_host_reset(struct hpsb_host *host)
1682 struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host);
1685 HPSB_VERBOSE("NodeMgr: Processing host reset for %s", hi->daemon_name);
1688 HPSB_ERR ("NodeMgr: could not process reset of unused host");
1693 static void nodemgr_remove_host(struct hpsb_host *host)
1695 struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host);
1702 wait_for_completion(&hi->exited);
1703 nodemgr_remove_host_dev(&host->device);
1706 HPSB_ERR("NodeMgr: host %s does not exist, cannot remove",
1707 host->driver->name);
1712 static struct hpsb_highlevel nodemgr_highlevel = {
1713 .name = "Node manager",
1714 .add_host = nodemgr_add_host,
1715 .host_reset = nodemgr_host_reset,
1716 .remove_host = nodemgr_remove_host,
1719 int init_ieee1394_nodemgr(void)
1723 ret = class_register(&nodemgr_ne_class);
1727 ret = class_register(&nodemgr_ud_class);
1729 class_unregister(&nodemgr_ne_class);
1733 hpsb_register_highlevel(&nodemgr_highlevel);
1738 void cleanup_ieee1394_nodemgr(void)
1740 hpsb_unregister_highlevel(&nodemgr_highlevel);
1742 class_unregister(&nodemgr_ud_class);
1743 class_unregister(&nodemgr_ne_class);