Thread: [Linux1394-cvslog] rev 825 - trunk
Brought to you by:
aeb,
bencollins
From: SVN U. <ben...@li...> - 2003-03-08 03:28:23
|
Author: bencollins Date: 2003-03-07 22:27:27 -0500 (Fri, 07 Mar 2003) New Revision: 825 Modified: trunk/nodemgr.c trunk/nodemgr.h trunk/sbp2.c Log: Go Ben, Go Ben! All of the old /proc/bus/ieee1394/devices information is now stuffed into sysfs attributes. I feel like I am programming hardware in a database environment. The sysfs stuff is really cool. Now on to the next major change of converting the drivers over to the driver-model for register/probe/bind. Modified: trunk/nodemgr.c ============================================================================== --- trunk/nodemgr.c (original) +++ trunk/nodemgr.c 2003-03-07 22:27:28.000000000 -0500 @@ -17,7 +17,6 @@ #include <linux/kmod.h> #include <linux/completion.h> #include <linux/delay.h> -#include <linux/proc_fs.h> #include <linux/pci.h> #include <asm/atomic.h> #include <asm/byteorder.h> @@ -38,17 +37,22 @@ }; extern struct oui_list_struct oui_list[]; +#endif -static char *nodemgr_find_oui_name(int oui) { +/* Shitty part is, 0x0 can just mean it wasn't set, but that matches an + * OUI entry. We don't want that, so we take a chance and never match 0x0. + * Sorry XEROX. */ +static char *nodemgr_find_oui_name(int oui) +{ +#ifdef CONFIG_IEEE1394_OUI_DB int i; - for (i = 0; oui_list[i].name; i++) + for (i = 1; oui_list[i].name; i++) if (oui_list[i].oui == oui) return oui_list[i].name; - +#endif return NULL; } -#endif /* * Basically what we do here is start off retrieving the bus_info block. @@ -93,7 +97,7 @@ struct completion exited; struct semaphore reset_sem; int pid; - unsigned int id; + int id; char daemon_name[15]; }; @@ -103,128 +107,165 @@ .add = NULL, }; -#ifdef CONFIG_PROC_FS +#define fw_ne_attr(field, type, format_string) \ +static ssize_t fw_ne_show_##field (struct device *dev, char *buf)\ +{ \ + struct node_entry *ne; \ + ne = container_of(dev, struct node_entry, device); \ + return sprintf (buf, format_string, (type)ne->field); \ +} \ +static struct device_attribute dev_attr_ne_##field = { \ + .attr = {.name = __stringify(field), .mode = S_IRUGO }, \ + .show = fw_ne_show_##field, \ +}; + +#define fw_ud_attr(field, type, format_string) \ +static ssize_t fw_ud_show_##field (struct device *dev, char *buf) \ +{ \ + struct unit_directory *ud; \ + ud = container_of(dev, struct unit_directory, device); \ + return sprintf (buf, format_string, (type)ud->field); \ +} \ +static struct device_attribute dev_attr_ud_##field = { \ + .attr = {.name = __stringify(field), .mode = S_IRUGO }, \ + .show = fw_ud_show_##field, \ +}; + +#define fw_host_attr(field, type, format_string) \ +static ssize_t fw_host_show_##field (struct device *dev, char *buf) \ +{ \ + struct hpsb_host *host; \ + host = container_of(dev, struct hpsb_host, device); \ + return sprintf (buf, format_string, (type)host->field); \ +} \ +static struct device_attribute dev_attr_host_##field = { \ + .attr = {.name = __stringify(field), .mode = S_IRUGO }, \ + .show = fw_host_show_##field, \ +}; + -#define PUTF(fmt, args...) out += sprintf(out, fmt, ## args) +fw_ne_attr(guid, unsigned long long, "0x%016Lx\n") +fw_ne_attr(capabilities, unsigned int, "0x%06x\n") +fw_ne_attr(vendor_id, unsigned int, "0x%06x\n") +fw_ne_attr(nodeid, unsigned int, "0x%04x\n") +fw_ne_attr(vendor_name, const char *, "%s\n") +fw_ne_attr(oui_name, const char *, "%s\n") -static int raw1394_read_proc(char *page, char **start, off_t off, - int count, int *eof, void *data) + +fw_ud_attr(address, unsigned long long, "0x%016Lx\n") +fw_ud_attr(vendor_id, unsigned int, "0x%06x\n") +fw_ud_attr(model_id, unsigned int, "0x%06x\n") +fw_ud_attr(specifier_id, unsigned int, "0x%06x\n") +fw_ud_attr(version, unsigned int, "0x%06x\n") +fw_ud_attr(length, int, "%d\n") +fw_ud_attr(vendor_name, const char *, "%s\n") +fw_ud_attr(model_name, const char *, "%s\n") + + +fw_host_attr(node_count, int, "%d\n") +fw_host_attr(selfid_count, int, "%d\n") +fw_host_attr(nodes_active, int, "%d\n") +fw_host_attr(in_bus_reset, int, "%d\n") +fw_host_attr(is_root, int, "%d\n") +fw_host_attr(is_cycmst, int, "%d\n") +fw_host_attr(is_irm, int, "%d\n") +fw_host_attr(is_busmgr, int, "%d\n") + + +static ssize_t fw_ne_show_bus_options(struct device *dev, char *buf) { - struct list_head *lh; - struct node_entry *ne; - int len; - char *out = page; - unsigned long flags; + struct node_entry *ne = container_of(dev, struct node_entry, device); - if (down_interruptible(&nodemgr_serialize)) - return -EINTR; + return sprintf (buf, "IRMC(%d) CMC(%d) ISC(%d) BMC(%d) PMC(%d) GEN(%d) " + "LSPD(%d) MAX_REC(%d) CYC_CLK_ACC(%d)\n", ne->busopt.irmc, + ne->busopt.cmc, ne->busopt.isc, ne->busopt.bmc, + ne->busopt.pmc, ne->busopt.generation, ne->busopt.lnkspd, + ne->busopt.max_rec, ne->busopt.cyc_clk_acc); +} +static DEVICE_ATTR(bus_options,S_IRUGO,fw_ne_show_bus_options,NULL); - list_for_each(lh, &node_list) { - struct list_head *l; - int ud_count = 0; - ne = list_entry(lh, struct node_entry, list); - if (!ne) - continue; +static ssize_t fw_ne_show_tlabels_free(struct device *dev, char *buf) +{ + struct node_entry *ne = container_of(dev, struct node_entry, device); + return sprintf (buf, "%d\n", atomic_read(&ne->tpool->count.count) + 1); +} +static DEVICE_ATTR(tlabels_free,S_IRUGO,fw_ne_show_tlabels_free,NULL); - PUTF("Node[" NODE_BUS_FMT "] GUID[%016Lx]:\n", - NODE_BUS_ARGS(ne->nodeid), (unsigned long long)ne->guid); - /* Generic Node information */ - PUTF(" Vendor ID : `%s' [0x%06x]\n", ne->oui_name, ne->vendor_id); - if (ne->vendor_name) - PUTF(" Vendor text : `%s'\n", ne->vendor_name); - PUTF(" Capabilities: 0x%06x\n", ne->capabilities); - PUTF(" Tlabel stats:\n"); - spin_lock_irqsave(&ne->tpool->lock, flags); - PUTF(" Free : %d\n", atomic_read(&ne->tpool->count.count) + 1); - PUTF(" Total : %u\n", ne->tpool->allocations); - PUTF(" Mask0 : %0lx\n", ne->tpool->pool[0]); +static ssize_t fw_ne_show_tlabels_allocations(struct device *dev, char *buf) +{ + struct node_entry *ne = container_of(dev, struct node_entry, device); + return sprintf (buf, "%u\n", ne->tpool->allocations); +} +static DEVICE_ATTR(tlabels_allocations,S_IRUGO,fw_ne_show_tlabels_allocations,NULL); + + +static ssize_t fw_ne_show_tlabels_mask(struct device *dev, char *buf) +{ + struct node_entry *ne = container_of(dev, struct node_entry, device); #if (BITS_PER_LONG <= 32) - PUTF(" Mask1 : %0lx\n", ne->tpool->pool[1]); + return sprintf (buf, "0x%08lx%08lx\n", ne->tpool->pool[0], ne->tpool->pool[1]); +#else + return sprintf (buf, "0x%016lx\n", ne->tpool->pool[0]); #endif - spin_unlock_irqrestore(&ne->tpool->lock, flags); - PUTF(" Bus Options :\n"); - PUTF(" IRMC(%d) CMC(%d) ISC(%d) BMC(%d) PMC(%d) GEN(%d)\n" - " LSPD(%d) MAX_REC(%d) CYC_CLK_ACC(%d)\n", - ne->busopt.irmc, ne->busopt.cmc, ne->busopt.isc, ne->busopt.bmc, - ne->busopt.pmc, ne->busopt.generation, ne->busopt.lnkspd, - ne->busopt.max_rec, ne->busopt.cyc_clk_acc); - - /* If this is the host entry, output some info about it aswell */ - if (ne->host != NULL && ne->host->node_id == ne->nodeid) { - PUTF(" Host Node Status:\n"); - PUTF(" Host Driver : %s\n", ne->host->driver->name); - PUTF(" Nodes connected : %d\n", ne->host->node_count); - PUTF(" Nodes active : %d\n", ne->host->nodes_active); - PUTF(" SelfIDs received: %d\n", ne->host->selfid_count); - PUTF(" Irm ID : [" NODE_BUS_FMT "]\n", - NODE_BUS_ARGS(ne->host->irm_id)); - PUTF(" BusMgr ID : [" NODE_BUS_FMT "]\n", - NODE_BUS_ARGS(ne->host->busmgr_id)); - PUTF(" In Bus Reset : %s\n", ne->host->in_bus_reset ? "yes" : "no"); - PUTF(" Root : %s\n", ne->host->is_root ? "yes" : "no"); - PUTF(" Cycle Master : %s\n", ne->host->is_cycmst ? "yes" : "no"); - PUTF(" IRM : %s\n", ne->host->is_irm ? "yes" : "no"); - PUTF(" Bus Manager : %s\n", ne->host->is_busmgr ? "yes" : "no"); - } +} +static DEVICE_ATTR(tlabels_mask,S_IRUGO,fw_ne_show_tlabels_mask,NULL); - /* Now the unit directories */ - list_for_each (l, &ne->unit_directories) { - struct unit_directory *ud = list_entry (l, struct unit_directory, node_list); - int printed = 0; // small hack - - PUTF(" Unit Directory %d:\n", ud_count++); - - if (ud->flags & UNIT_DIRECTORY_VENDOR_ID || - ud->flags & UNIT_DIRECTORY_MODEL_ID) { - PUTF(" Vendor/Model ID : "); - } - if (ud->flags & UNIT_DIRECTORY_VENDOR_ID) { - PUTF("%s [%06x]", ud->vendor_name ?: "Unknown", - ud->vendor_id); - printed = 1; - } - if (ud->flags & UNIT_DIRECTORY_MODEL_ID) { - if (!printed) { - PUTF("%s [%06x]", ne->vendor_name ?: "Unknown", - ne->vendor_id); - } - PUTF(" / %s [%06x]", ud->model_name ?: "Unknown", ud->model_id); - printed = 1; - } - if (printed) - PUTF("\n"); - if (ud->flags & UNIT_DIRECTORY_SPECIFIER_ID) - PUTF(" Software Spec ID : %06x\n", ud->specifier_id); - if (ud->flags & UNIT_DIRECTORY_VERSION) - PUTF(" Software Version : %06x\n", ud->version); - if (ud->driver) - PUTF(" Driver : %s\n", ud->driver->name); - PUTF(" Length (in quads): %d\n", ud->count); - } +static void nodemgr_create_ne_dev_files(struct node_entry *ne) +{ + struct device *dev = &ne->device; - } + device_create_file(dev, &dev_attr_ne_guid); + device_create_file(dev, &dev_attr_ne_capabilities); + device_create_file(dev, &dev_attr_ne_vendor_id); + device_create_file(dev, &dev_attr_ne_nodeid); + device_create_file(dev, &dev_attr_bus_options); + device_create_file(dev, &dev_attr_tlabels_free); + device_create_file(dev, &dev_attr_tlabels_allocations); + device_create_file(dev, &dev_attr_tlabels_mask); +} - up(&nodemgr_serialize); +static void nodemgr_create_host_dev_files(struct hpsb_host *host) +{ + struct device *dev = &host->device; - len = out - page; - len -= off; - if (len < count) { - *eof = 1; - if (len <= 0) - return 0; - } else - len = count; + device_create_file(dev, &dev_attr_host_node_count); + device_create_file(dev, &dev_attr_host_selfid_count); + device_create_file(dev, &dev_attr_host_nodes_active); + device_create_file(dev, &dev_attr_host_in_bus_reset); + device_create_file(dev, &dev_attr_host_is_root); + device_create_file(dev, &dev_attr_host_is_cycmst); + device_create_file(dev, &dev_attr_host_is_irm); + device_create_file(dev, &dev_attr_host_is_busmgr); +} - *start = page + off; +static void nodemgr_create_ud_dev_files(struct unit_directory *ud) +{ + struct device *dev = &ud->device; - return len; -} + device_create_file(dev, &dev_attr_ud_address); + device_create_file(dev, &dev_attr_ud_length); + + if (ud->flags & UNIT_DIRECTORY_SPECIFIER_ID) + device_create_file(dev, &dev_attr_ud_specifier_id); -#undef PUTF -#endif /* CONFIG_PROC_FS */ + if (ud->flags & UNIT_DIRECTORY_VERSION) + device_create_file(dev, &dev_attr_ud_version); + + if (ud->flags & UNIT_DIRECTORY_VENDOR_ID) { + device_create_file(dev, &dev_attr_ud_vendor_id); + if (ud->flags & UNIT_DIRECTORY_VENDOR_TEXT) + device_create_file(dev, &dev_attr_ud_vendor_name); + } + + if (ud->flags & UNIT_DIRECTORY_MODEL_ID) { + device_create_file(dev, &dev_attr_ud_model_id); + if (ud->flags & UNIT_DIRECTORY_MODEL_TEXT) + device_create_file(dev, &dev_attr_ud_model_name); + } +} static void nodemgr_process_config_rom(struct node_entry *ne, quadlet_t busoptions); @@ -396,11 +437,12 @@ list_add_tail(&ne->list, &node_list); ne->device.parent = &host->device; - sprintf(ne->device.bus_id, "%u-" NODE_BUS_FMT, hi->id, NODE_BUS_ARGS(nodeid)); + sprintf(ne->device.bus_id, "%d-" NODE_BUS_FMT, hi->id, NODE_BUS_ARGS(nodeid)); sprintf(ne->device.name, "IEEE-1394 device %s", ne->device.bus_id); ne->device.bus = &ieee1394_bus_type; device_register(&ne->device); + nodemgr_create_ne_dev_files(ne); nodemgr_process_config_rom (ne, busoptions); @@ -527,12 +569,9 @@ if (ud != NULL) { memset (ud, 0, total_size); ud->flags = flags; - ud->count = count; + ud->length = count; ud->vendor_name_size = vendor_name_size; ud->model_name_size = model_name_size; - /* If there is no vendor name in the unit directory, - use the one in the root directory. */ - ud->vendor_name = ne->vendor_name; } return ud; @@ -583,11 +622,9 @@ if ((ud->flags & UNIT_DIRECTORY_VENDOR_TEXT) != 0) { length--; address += 4; - quadp = &(ud->quadlets[ud->count]); - if (nodemgr_read_text_leaf(ne, address, - quadp) == 0 - && quadp[0] == 0 - && quadp[1] == 0) { + quadp = &(ud->quadlets[ud->length]); + if (nodemgr_read_text_leaf(ne, address, quadp) == 0 + && quadp[0] == 0 && quadp[1] == 0) { /* We only support minimal ASCII and English. */ quadp[ud->vendor_name_size] = 0; @@ -603,11 +640,9 @@ if ((ud->flags & UNIT_DIRECTORY_MODEL_TEXT) != 0) { length--; address += 4; - quadp = &(ud->quadlets[ud->count + ud->vendor_name_size + 1]); - if (nodemgr_read_text_leaf(ne, address, - quadp) == 0 - && quadp[0] == 0 - && quadp[1] == 0) { + quadp = &(ud->quadlets[ud->length + ud->vendor_name_size + 1]); + if (nodemgr_read_text_leaf(ne, address, quadp) == 0 + && quadp[0] == 0 && quadp[1] == 0) { /* We only support minimal ASCII and English. */ quadp[ud->model_name_size] = 0; @@ -652,6 +687,7 @@ ud->device.bus = &ieee1394_bus_type; device_register(&ud->device); + nodemgr_create_ud_dev_files(ud); return; @@ -720,24 +756,24 @@ switch (code) { case CONFIG_ROM_VENDOR_ID: ne->vendor_id = value; -#ifdef CONFIG_IEEE1394_OUI_DB + ne->oui_name = nodemgr_find_oui_name(value); -#else - ne->oui_name = "Unknown"; -#endif + if (ne->oui_name) + device_create_file(&ne->device, &dev_attr_ne_oui_name); + /* Now check if there is a vendor name text string. */ if (ne->vendor_name != NULL) { length--; address += 4; - if (nodemgr_read_text_leaf(ne, address, - ne->quadlets) - != 0 - || ne->quadlets [0] != 0 - || ne->quadlets [1] != 0) + if (nodemgr_read_text_leaf(ne, address, ne->quadlets) != 0 + || ne->quadlets[0] != 0 || ne->quadlets[1] != 0) /* We only support minimal ASCII and English. */ ne->vendor_name = NULL; + else + device_create_file(&ne->device, + &dev_attr_ne_vendor_name); } break; @@ -838,6 +874,39 @@ #endif /* CONFIG_HOTPLUG */ + +static struct host_info *nodemgr_find_host_by_num(int hostnum) +{ + unsigned long flags; + struct list_head *lh; + struct host_info *hi = NULL; + + spin_lock_irqsave (&host_info_lock, flags); + list_for_each(lh, &host_info_list) { + struct host_info *myhi = list_entry(lh, struct host_info, list); + if (hi->id == hostnum) { + hi = myhi; + break; + } + } + spin_unlock_irqrestore (&host_info_lock, flags); + + return hi; +} + + +static int nodemgr_alloc_host_num(void) +{ + int hostnum = 0; + + while (1) { + if (!nodemgr_find_host_by_num(hostnum)) + return hostnum; + + hostnum++; + } +} + static void nodemgr_claim_unit_directory(struct unit_directory *ud, struct hpsb_protocol_driver *driver) { @@ -848,7 +917,6 @@ static void nodemgr_release_unit_directory(struct unit_directory *ud) { - device_unregister(&ud->device); ud->driver = NULL; list_del(&ud->driver_list); list_add_tail(&ud->driver_list, &unit_directory_list); @@ -875,6 +943,7 @@ nodemgr_release_unit_directory(ud); nodemgr_call_policy("remove", ud); list_del(&ud->driver_list); + device_unregister(&ud->device); kfree(ud); } } @@ -1414,7 +1483,6 @@ { struct host_info *hi; unsigned long flags; - static unsigned int host_id = 0; hi = kmalloc(sizeof (struct host_info), in_interrupt() ? SLAB_ATOMIC : SLAB_KERNEL); @@ -1431,16 +1499,17 @@ init_completion(&hi->exited); sema_init(&hi->reset_sem, 0); - hi->id = host_id++; + hi->id = nodemgr_alloc_host_num(); host->device.parent = &host->pdev->dev; - sprintf(host->device.bus_id, "fw-host%u", hi->id); - sprintf(host->device.name, "IEEE-1394 Host %s-%u", host->driver->name, hi->id); + sprintf(host->device.bus_id, "fw-host%d", hi->id); + sprintf(host->device.name, "IEEE-1394 Host %s-%d", host->driver->name, hi->id); host->device.bus = &ieee1394_bus_type; - sprintf(hi->daemon_name, "knodemgrd/%u", hi->id); + sprintf(hi->daemon_name, "knodemgrd/%d", hi->id); device_register(&host->device); + nodemgr_create_host_dev_files(host); hi->pid = kernel_thread(nodemgr_host_thread, hi, CLONE_FS | CLONE_FILES | CLONE_SIGHAND); @@ -1543,20 +1612,12 @@ static struct hpsb_highlevel *hl; -#define PROC_ENTRY "devices" - void init_ieee1394_nodemgr(int disable_hotplug) { nodemgr_disable_hotplug = disable_hotplug; bus_register(&ieee1394_bus_type); -#ifdef CONFIG_PROC_FS - if (!create_proc_read_entry(PROC_ENTRY, 0444, ieee1394_procfs_entry, - raw1394_read_proc, NULL)) - HPSB_ERR("Can't create devices procfs entry"); -#endif - hl = hpsb_register_highlevel("Node manager", &nodemgr_ops); if (!hl) { HPSB_ERR("NodeMgr: out of memory during ieee1394 initialization"); @@ -1566,9 +1627,6 @@ void cleanup_ieee1394_nodemgr(void) { hpsb_unregister_highlevel(hl); -#ifdef CONFIG_PROC_FS - remove_proc_entry(PROC_ENTRY, ieee1394_procfs_entry); -#endif bus_unregister(&ieee1394_bus_type); } Modified: trunk/nodemgr.h ============================================================================== --- trunk/nodemgr.h (original) +++ trunk/nodemgr.h 2003-03-07 22:27:28.000000000 -0500 @@ -119,7 +119,7 @@ unsigned int id; - int count; /* Number of quadlets */ + int length; /* Number of quadlets */ struct device device; Modified: trunk/sbp2.c ============================================================================== --- trunk/sbp2.c (original) +++ trunk/sbp2.c 2003-03-07 22:27:28.000000000 -0500 @@ -926,11 +926,10 @@ list_add_tail(&hi->list, &sbp2_host_info_list); spin_unlock_irqrestore(&sbp2_host_info_lock, flags); - /* - * XXX(hch): Hopefully the ieee1394 code will be converted - * to the driver model at some point. Until that happens - * we'll have to pass in NULL here. - */ + /* XXX We need a device to pass here as the scsi-host class. Can't + * use the PCI device, since it is already bound to the ieee1394 + * host. Can't use the fw-host device since it is multi-class + * enabled (scsi-host uses classdata member of the device). */ if (scsi_add_host(hi->scsi_host, NULL)) { SBP2_ERR("failed to add scsi host"); @@ -1603,7 +1602,7 @@ ud = scsi_id->ud; /* Handle different fields in the unit directory, based on keys */ - for (i = 0; i < ud->count; i++) { + for (i = 0; i < ud->length; i++) { switch (CONFIG_ROM_KEY(ud->quadlets[i])) { case SBP2_CSR_OFFSET_KEY: /* Save off the management agent address */ |