}
+static void nodemgr_release_host(struct device *dev)
+{
+ kfree(container_of(dev, struct hpsb_host, device));
+}
+
+
static void nodemgr_remove_ud(struct unit_directory *ud)
{
struct device *dev = &ud->device;
static struct device nodemgr_dev_template_host = {
.bus = &ieee1394_bus_type,
+ .release = nodemgr_release_host,
.driver = &nodemgr_driver_host,
.driver_data = &nodemgr_driverdata_host,
};
}
-static void nodemgr_process_config_rom(struct host_info *hi,
- struct node_entry *ne, quadlet_t busoptions);
+static void nodemgr_update_bus_options(struct node_entry *ne,
+ quadlet_t busoptions)
+{
+ ne->busopt.irmc = (busoptions >> 31) & 1;
+ ne->busopt.cmc = (busoptions >> 30) & 1;
+ ne->busopt.isc = (busoptions >> 29) & 1;
+ ne->busopt.bmc = (busoptions >> 28) & 1;
+ ne->busopt.pmc = (busoptions >> 27) & 1;
+ ne->busopt.cyc_clk_acc = (busoptions >> 16) & 0xff;
+ ne->busopt.max_rec = 1 << (((busoptions >> 12) & 0xf) + 1);
+ ne->busopt.generation = (busoptions >> 4) & 0xf;
+ ne->busopt.lnkspd = busoptions & 0x7;
+
+ HPSB_VERBOSE("NodeMgr: raw=0x%08x irmc=%d cmc=%d isc=%d bmc=%d pmc=%d "
+ "cyc_clk_acc=%d max_rec=%d gen=%d lspd=%d",
+ busoptions, ne->busopt.irmc, ne->busopt.cmc,
+ ne->busopt.isc, ne->busopt.bmc, ne->busopt.pmc,
+ ne->busopt.cyc_clk_acc, ne->busopt.max_rec,
+ ne->busopt.generation, ne->busopt.lnkspd);
+}
+
static struct node_entry *nodemgr_create_node(octlet_t guid, quadlet_t busoptions,
struct host_info *hi, nodeid_t nodeid,
ne->host = host;
ne->nodeid = nodeid;
ne->generation = generation;
+ ne->needs_probe = 1;
ne->guid = guid;
ne->guid_vendor_id = (guid >> 40) & 0xffffff;
device_create_file(&ne->device, &dev_attr_ne_guid_vendor_oui);
nodemgr_create_ne_dev_files(ne);
- nodemgr_process_config_rom (hi, ne, busoptions);
+ nodemgr_update_bus_options(ne, busoptions);
HPSB_DEBUG("%s added: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
(host->node_id == nodeid) ? "Host" : "Node",
if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation, address, &quad))
return NULL;
+
length = CONFIG_ROM_DIRECTORY_LENGTH(quad) ;
address += 4;
return ud;
-unit_directory_error:
+unit_directory_error:
if (ud != NULL)
kfree(ud);
return NULL;
int length;
unsigned int ud_id = 0;
+ device_remove_file(&ne->device, &dev_attr_ne_vendor_oui);
+
address = CSR_REGISTER_BASE + CSR_CONFIG_ROM;
if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation,
break;
}
}
+
+ if (ne->vendor_oui)
+ device_create_file(&ne->device, &dev_attr_ne_vendor_oui);
}
#ifdef CONFIG_HOTPLUG
driver_unregister(&driver->driver);
}
-static void nodemgr_process_config_rom(struct host_info *hi,
- struct node_entry *ne, quadlet_t busoptions)
-{
- ne->busopt.irmc = (busoptions >> 31) & 1;
- ne->busopt.cmc = (busoptions >> 30) & 1;
- ne->busopt.isc = (busoptions >> 29) & 1;
- ne->busopt.bmc = (busoptions >> 28) & 1;
- ne->busopt.pmc = (busoptions >> 27) & 1;
- ne->busopt.cyc_clk_acc = (busoptions >> 16) & 0xff;
- ne->busopt.max_rec = 1 << (((busoptions >> 12) & 0xf) + 1);
- ne->busopt.generation = (busoptions >> 4) & 0xf;
- ne->busopt.lnkspd = busoptions & 0x7;
-
- HPSB_VERBOSE("NodeMgr: raw=0x%08x irmc=%d cmc=%d isc=%d bmc=%d pmc=%d "
- "cyc_clk_acc=%d max_rec=%d gen=%d lspd=%d",
- busoptions, ne->busopt.irmc, ne->busopt.cmc,
- ne->busopt.isc, ne->busopt.bmc, ne->busopt.pmc,
- ne->busopt.cyc_clk_acc, ne->busopt.max_rec,
- ne->busopt.generation, ne->busopt.lnkspd);
-
- device_remove_file(&ne->device, &dev_attr_ne_vendor_oui);
-
- nodemgr_process_root_directory(hi, ne);
-
- if (ne->vendor_oui)
- device_create_file(&ne->device, &dev_attr_ne_vendor_oui);
-}
-
/* Searches the list of ud's that match a ne as the parent. If the ud has
* a driver associated with it, we call that driver's update function
* unregister all the unit directories. */
nodemgr_remove_node_uds(ne);
- /* With all the ud's gone, mark the generation current,
- * this way the probe will succeed. */
- ne->generation = generation;
+ nodemgr_update_bus_options(ne, busoptions);
- /* This will re-register our unitdir's */
- nodemgr_process_config_rom (hi, ne, busoptions);
- } else
- ne->generation = generation;
+ /* Mark the node as new, so it gets re-probed */
+ ne->needs_probe = 1;
+ }
- /* Update unit_dirs with attached drivers */
- bus_for_each_dev(&ieee1394_bus_type, NULL, ne,
- nodemgr_driver_search_cb);
+ /* Mark the node current */
+ ne->generation = generation;
}
static int read_businfo_block(struct hpsb_host *host, nodeid_t nodeid, unsigned int generation,
}
-/* This is where we probe the nodes for their information and provided
- * features. */
-static void nodemgr_node_probe_one(struct host_info *hi,
- nodeid_t nodeid, int generation)
+static void nodemgr_node_scan_one(struct host_info *hi,
+ nodeid_t nodeid, int generation)
{
struct hpsb_host *host = hi->host;
struct node_entry *ne;
* shouldn't be held responsible, so we'll allow it with a
* warning. */
HPSB_WARN("Node " NODE_BUS_FMT " has invalid busID magic [0x%08x]",
- NODE_BUS_ARGS(host, nodeid), buffer[1]);
+ NODE_BUS_ARGS(host, nodeid), buffer[1]);
}
guid = ((u64)buffer[3] << 32) | buffer[4];
return 0;
}
+struct ne_cb_data_struct {
+ struct host_info *hi;
+ struct node_entry *ne;
+};
-static void nodemgr_node_probe(struct host_info *hi, int generation)
+static int nodemgr_probe_ne_cb(struct device *dev, void *__data)
{
- int count;
- struct hpsb_host *host = hi->host;
- struct selfid *sid = (struct selfid *)host->topology_map;
- nodeid_t nodeid = LOCAL_BUS;
+ struct ne_cb_data_struct *ne_cb_data = __data;
+ struct host_info *hi = ne_cb_data->hi;
+ struct node_entry *ne;
- /* Scan each node on the bus */
- for (count = host->selfid_count; count; count--, sid++) {
- if (sid->extended)
- continue;
+ if (dev->driver_data != &nodemgr_driverdata_ne)
+ return 0;
- if (!sid->link_active) {
- nodeid++;
- continue;
+ ne = ne_cb_data->ne = container_of(dev, struct node_entry, device);
+
+ if (ne->host != hi->host)
+ return 0;
+
+ /* We can't call nodemgr_process_root_directory() here because
+ * that can call device_register. Since this callback is under a
+ * rwsem, the device_register would deadlock. So, we signal back
+ * to the callback, and process things there. */
+
+ if (ne->needs_probe) {
+ ne->needs_probe = 0;
+ return 1;
+ } else {
+ /* Update unit_dirs with attached drivers */
+ bus_for_each_dev(&ieee1394_bus_type, NULL, ne,
+ nodemgr_driver_search_cb);
+ }
+ return 0;
+}
+
+
+static void nodemgr_node_scan(struct host_info *hi, int generation)
+{
+ int count;
+ struct hpsb_host *host = hi->host;
+ struct selfid *sid = (struct selfid *)host->topology_map;
+ nodeid_t nodeid = LOCAL_BUS;
+
+ /* Scan each node on the bus */
+ for (count = host->selfid_count; count; count--, sid++) {
+ if (sid->extended)
+ continue;
+
+ if (!sid->link_active) {
+ nodeid++;
+ continue;
+ }
+ nodemgr_node_scan_one(hi, nodeid++, generation);
+ }
+}
+
+static void nodemgr_node_probe(struct host_info *hi, int generation)
+{
+ struct hpsb_host *host = hi->host;
+ struct ne_cb_data_struct ne_cb_data;
+
+ ne_cb_data.hi = hi;
+ ne_cb_data.ne = NULL;
+
+ /* Do some processing of the nodes we've probed. This pulls them
+ * into the sysfs layer if needed, and can result in processing of
+ * unit-directories, or just updating the node and it's
+ * unit-directories. */
+ while (bus_for_each_dev(&ieee1394_bus_type, ne_cb_data.ne ? &ne_cb_data.ne->device : NULL,
+ &ne_cb_data, nodemgr_probe_ne_cb)) {
+ /* If we get in here, we've got a node that needs it's
+ * unit directories processed. */
+ struct device *dev = get_device(&ne_cb_data.ne->device);
+
+ if (dev) {
+ nodemgr_process_root_directory(hi, ne_cb_data.ne);
+ put_device(dev);
}
- nodemgr_node_probe_one(hi, nodeid++, generation);
}
/* If we had a bus reset while we were scanning the bus, it is
/* Because we are a 1394a-2000 compliant IRM, we need to inform all the other
* nodes of the broadcast channel. (Really we're only setting the validity
* bit). Other IRM responsibilities go in here as well. */
-static void nodemgr_do_irm_duties(struct hpsb_host *host)
+static int nodemgr_do_irm_duties(struct hpsb_host *host, int cycles)
{
quadlet_t bc;
if (!host->is_irm)
- return;
+ return 1;
host->csr.broadcast_channel |= 0x40000000; /* set validity bit */
else {
HPSB_DEBUG("The root node is not cycle master capable; "
"selecting a new root node and resetting...");
+
+ if (cycles >= 5) {
+ /* Oh screw it! Just leave the bus as it is */
+ HPSB_DEBUG("Stopping reset loop for IRM sanity");
+ return 1;
+ }
+
hpsb_send_phy_config(host, NODEID_TO_NODE(host->node_id), -1);
hpsb_reset_bus(host, LONG_RESET_FORCE_ROOT);
+
+ return 0;
}
}
+
+ return 1;
}
/* We need to ensure that if we are not the IRM, that the IRM node is capable of
* to make sure things settle down. */
for (i = 0; i < 4 ; i++) {
set_current_state(TASK_INTERRUPTIBLE);
- if (schedule_timeout(HZ/16))
+ if (schedule_timeout(HZ/16)) {
+ up(&nodemgr_serialize);
goto caught_signal;
+ }
/* Now get the generation in which the node ID's we collect
* are valid. During the bus scan we will use this generation
i = 0;
}
- if (!nodemgr_check_irm_capability(host, reset_cycles++)) {
- /* Do nothing, we are resetting */
+ if (!nodemgr_check_irm_capability(host, reset_cycles)) {
+ reset_cycles++;
+ up(&nodemgr_serialize);
+ continue;
+ }
+
+ /* Scan our nodes to get the bus options and create node
+ * entries. This does not do the sysfs stuff, since that
+ * would trigger hotplug callbacks and such, which is a
+ * bad idea at this point. */
+ nodemgr_node_scan(hi, generation);
+ if (!nodemgr_do_irm_duties(host, reset_cycles)) {
+ reset_cycles++;
up(&nodemgr_serialize);
continue;
}
reset_cycles = 0;
+ /* This actually does the full probe, with sysfs
+ * registration. */
nodemgr_node_probe(hi, generation);
- nodemgr_do_irm_duties(host);
/* Update some of our sysfs symlinks */
nodemgr_update_host_dev_links(host);
kill_proc(hi->pid, SIGTERM, 1);
wait_for_completion(&hi->exited);
nodemgr_remove_host_dev(&host->device);
- device_unregister(&host->device);
}
} else
HPSB_ERR("NodeMgr: host %s does not exist, cannot remove",