| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Node information (ConfigROM) collection and management. | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2000		Andreas E. Bombe | 
|  | 5 | *               2001-2003	Ben Collins <bcollins@debian.net> | 
|  | 6 | * | 
|  | 7 | * This code is licensed under the GPL.  See the file COPYING in the root | 
|  | 8 | * directory of the kernel sources for details. | 
|  | 9 | */ | 
|  | 10 |  | 
| Stefan Richter | 09a9a45 | 2006-06-25 05:46:44 -0700 | [diff] [blame] | 11 | #include <linux/bitmap.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/kernel.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/list.h> | 
|  | 14 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/delay.h> | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 16 | #include <linux/kthread.h> | 
| Stefan Richter | 8252bbb | 2006-11-22 21:09:42 +0100 | [diff] [blame] | 17 | #include <linux/module.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/moduleparam.h> | 
| Stefan Richter | 9543a93 | 2007-04-10 02:39:07 +0200 | [diff] [blame] | 19 | #include <linux/mutex.h> | 
| Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 20 | #include <linux/freezer.h> | 
| Matthew Wilcox | 6188e10 | 2008-04-18 22:21:05 -0400 | [diff] [blame] | 21 | #include <linux/semaphore.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/atomic.h> | 
|  | 23 |  | 
| Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 24 | #include "csr.h" | 
|  | 25 | #include "highlevel.h" | 
|  | 26 | #include "hosts.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "ieee1394.h" | 
|  | 28 | #include "ieee1394_core.h" | 
| Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 29 | #include "ieee1394_hotplug.h" | 
|  | 30 | #include "ieee1394_types.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "ieee1394_transactions.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "nodemgr.h" | 
|  | 33 |  | 
| Ben Collins | 1934b8b | 2005-07-09 20:01:23 -0400 | [diff] [blame] | 34 | static int ignore_drivers; | 
| Stefan Richter | 3a632fe | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 35 | module_param(ignore_drivers, int, S_IRUGO | S_IWUSR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | MODULE_PARM_DESC(ignore_drivers, "Disable automatic probing for drivers."); | 
|  | 37 |  | 
|  | 38 | struct nodemgr_csr_info { | 
|  | 39 | struct hpsb_host *host; | 
|  | 40 | nodeid_t nodeid; | 
|  | 41 | unsigned int generation; | 
| Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 42 | unsigned int speed_unverified:1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | }; | 
|  | 44 |  | 
|  | 45 |  | 
| Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 46 | /* | 
|  | 47 | * Correct the speed map entry.  This is necessary | 
|  | 48 | *  - for nodes with link speed < phy speed, | 
|  | 49 | *  - for 1394b nodes with negotiated phy port speed < IEEE1394_SPEED_MAX. | 
|  | 50 | * A possible speed is determined by trial and error, using quadlet reads. | 
|  | 51 | */ | 
|  | 52 | static int nodemgr_check_speed(struct nodemgr_csr_info *ci, u64 addr, | 
|  | 53 | quadlet_t *buffer) | 
|  | 54 | { | 
|  | 55 | quadlet_t q; | 
|  | 56 | u8 i, *speed, old_speed, good_speed; | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 57 | int error; | 
| Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 58 |  | 
| Stefan Richter | d7530a1 | 2006-07-03 00:58:01 +0200 | [diff] [blame] | 59 | speed = &(ci->host->speed[NODEID_TO_NODE(ci->nodeid)]); | 
| Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 60 | old_speed = *speed; | 
|  | 61 | good_speed = IEEE1394_SPEED_MAX + 1; | 
|  | 62 |  | 
|  | 63 | /* Try every speed from S100 to old_speed. | 
|  | 64 | * If we did it the other way around, a too low speed could be caught | 
|  | 65 | * if the retry succeeded for some other reason, e.g. because the link | 
|  | 66 | * just finished its initialization. */ | 
|  | 67 | for (i = IEEE1394_SPEED_100; i <= old_speed; i++) { | 
|  | 68 | *speed = i; | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 69 | error = hpsb_read(ci->host, ci->nodeid, ci->generation, addr, | 
| Stefan Richter | 0bed181 | 2008-12-13 23:12:06 +0100 | [diff] [blame] | 70 | &q, 4); | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 71 | if (error) | 
| Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 72 | break; | 
|  | 73 | *buffer = q; | 
|  | 74 | good_speed = i; | 
|  | 75 | } | 
|  | 76 | if (good_speed <= IEEE1394_SPEED_MAX) { | 
|  | 77 | HPSB_DEBUG("Speed probe of node " NODE_BUS_FMT " yields %s", | 
|  | 78 | NODE_BUS_ARGS(ci->host, ci->nodeid), | 
|  | 79 | hpsb_speedto_str[good_speed]); | 
|  | 80 | *speed = good_speed; | 
|  | 81 | ci->speed_unverified = 0; | 
|  | 82 | return 0; | 
|  | 83 | } | 
|  | 84 | *speed = old_speed; | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 85 | return error; | 
| Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 86 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 |  | 
| Stefan Richter | 0bed181 | 2008-12-13 23:12:06 +0100 | [diff] [blame] | 88 | static int nodemgr_bus_read(struct csr1212_csr *csr, u64 addr, | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 89 | void *buffer, void *__ci) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { | 
|  | 91 | struct nodemgr_csr_info *ci = (struct nodemgr_csr_info*)__ci; | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 92 | int i, error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 |  | 
| Jody McIntyre | e31a127 | 2005-09-30 11:59:09 -0700 | [diff] [blame] | 94 | for (i = 1; ; i++) { | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 95 | error = hpsb_read(ci->host, ci->nodeid, ci->generation, addr, | 
| Stefan Richter | 0bed181 | 2008-12-13 23:12:06 +0100 | [diff] [blame] | 96 | buffer, 4); | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 97 | if (!error) { | 
| Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 98 | ci->speed_unverified = 0; | 
|  | 99 | break; | 
|  | 100 | } | 
|  | 101 | /* Give up after 3rd failure. */ | 
|  | 102 | if (i == 3) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | break; | 
|  | 104 |  | 
| Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 105 | /* The ieee1394_core guessed the node's speed capability from | 
|  | 106 | * the self ID.  Check whether a lower speed works. */ | 
| Stefan Richter | 0bed181 | 2008-12-13 23:12:06 +0100 | [diff] [blame] | 107 | if (ci->speed_unverified) { | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 108 | error = nodemgr_check_speed(ci, addr, buffer); | 
|  | 109 | if (!error) | 
| Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 110 | break; | 
|  | 111 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | if (msleep_interruptible(334)) | 
|  | 113 | return -EINTR; | 
|  | 114 | } | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 115 | return error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } | 
|  | 117 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | static struct csr1212_bus_ops nodemgr_csr_ops = { | 
|  | 119 | .bus_read =	nodemgr_bus_read, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | }; | 
|  | 121 |  | 
|  | 122 |  | 
|  | 123 | /* | 
|  | 124 | * Basically what we do here is start off retrieving the bus_info block. | 
|  | 125 | * From there will fill in some info about the node, verify it is of IEEE | 
|  | 126 | * 1394 type, and that the crc checks out ok. After that we start off with | 
|  | 127 | * the root directory, and subdirectories. To do this, we retrieve the | 
|  | 128 | * quadlet header for a directory, find out the length, and retrieve the | 
|  | 129 | * complete directory entry (be it a leaf or a directory). We then process | 
|  | 130 | * it and add the info to our structure for that particular node. | 
|  | 131 | * | 
|  | 132 | * We verify CRC's along the way for each directory/block/leaf. The entire | 
|  | 133 | * node structure is generic, and simply stores the information in a way | 
|  | 134 | * that's easy to parse by the protocol interface. | 
|  | 135 | */ | 
|  | 136 |  | 
|  | 137 | /* | 
|  | 138 | * The nodemgr relies heavily on the Driver Model for device callbacks and | 
|  | 139 | * driver/device mappings. The old nodemgr used to handle all this itself, | 
|  | 140 | * but now we are much simpler because of the LDM. | 
|  | 141 | */ | 
|  | 142 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | struct host_info { | 
|  | 144 | struct hpsb_host *host; | 
|  | 145 | struct list_head list; | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 146 | struct task_struct *thread; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | }; | 
|  | 148 |  | 
|  | 149 | static int nodemgr_bus_match(struct device * dev, struct device_driver * drv); | 
| Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 150 | static int nodemgr_uevent(struct device *dev, struct kobj_uevent_env *env); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 |  | 
|  | 152 | struct bus_type ieee1394_bus_type = { | 
|  | 153 | .name		= "ieee1394", | 
|  | 154 | .match		= nodemgr_bus_match, | 
|  | 155 | }; | 
|  | 156 |  | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 157 | static void host_cls_release(struct device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 159 | put_device(&container_of((dev), struct hpsb_host, host_dev)->device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } | 
|  | 161 |  | 
|  | 162 | struct class hpsb_host_class = { | 
|  | 163 | .name		= "ieee1394_host", | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 164 | .dev_release	= host_cls_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | }; | 
|  | 166 |  | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 167 | static void ne_cls_release(struct device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 169 | put_device(&container_of((dev), struct node_entry, node_dev)->device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } | 
|  | 171 |  | 
|  | 172 | static struct class nodemgr_ne_class = { | 
|  | 173 | .name		= "ieee1394_node", | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 174 | .dev_release	= ne_cls_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | }; | 
|  | 176 |  | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 177 | static void ud_cls_release(struct device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 179 | put_device(&container_of((dev), struct unit_directory, unit_dev)->device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } | 
|  | 181 |  | 
|  | 182 | /* The name here is only so that unit directory hotplug works with old | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 183 | * style hotplug, which only ever did unit directories anyway. | 
|  | 184 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | static struct class nodemgr_ud_class = { | 
|  | 186 | .name		= "ieee1394", | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 187 | .dev_release	= ud_cls_release, | 
|  | 188 | .dev_uevent	= nodemgr_uevent, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | }; | 
|  | 190 |  | 
|  | 191 | static struct hpsb_highlevel nodemgr_highlevel; | 
|  | 192 |  | 
|  | 193 |  | 
|  | 194 | static void nodemgr_release_ud(struct device *dev) | 
|  | 195 | { | 
|  | 196 | struct unit_directory *ud = container_of(dev, struct unit_directory, device); | 
|  | 197 |  | 
|  | 198 | if (ud->vendor_name_kv) | 
|  | 199 | csr1212_release_keyval(ud->vendor_name_kv); | 
|  | 200 | if (ud->model_name_kv) | 
|  | 201 | csr1212_release_keyval(ud->model_name_kv); | 
|  | 202 |  | 
|  | 203 | kfree(ud); | 
|  | 204 | } | 
|  | 205 |  | 
|  | 206 | static void nodemgr_release_ne(struct device *dev) | 
|  | 207 | { | 
|  | 208 | struct node_entry *ne = container_of(dev, struct node_entry, device); | 
|  | 209 |  | 
|  | 210 | if (ne->vendor_name_kv) | 
|  | 211 | csr1212_release_keyval(ne->vendor_name_kv); | 
|  | 212 |  | 
|  | 213 | kfree(ne); | 
|  | 214 | } | 
|  | 215 |  | 
|  | 216 |  | 
|  | 217 | static void nodemgr_release_host(struct device *dev) | 
|  | 218 | { | 
|  | 219 | struct hpsb_host *host = container_of(dev, struct hpsb_host, device); | 
|  | 220 |  | 
|  | 221 | csr1212_destroy_csr(host->csr.rom); | 
|  | 222 |  | 
|  | 223 | kfree(host); | 
|  | 224 | } | 
|  | 225 |  | 
|  | 226 | static int nodemgr_ud_platform_data; | 
|  | 227 |  | 
|  | 228 | static struct device nodemgr_dev_template_ud = { | 
|  | 229 | .bus		= &ieee1394_bus_type, | 
|  | 230 | .release	= nodemgr_release_ud, | 
|  | 231 | .platform_data	= &nodemgr_ud_platform_data, | 
|  | 232 | }; | 
|  | 233 |  | 
|  | 234 | static struct device nodemgr_dev_template_ne = { | 
|  | 235 | .bus		= &ieee1394_bus_type, | 
|  | 236 | .release	= nodemgr_release_ne, | 
|  | 237 | }; | 
|  | 238 |  | 
| Stefan Richter | 8252bbb | 2006-11-22 21:09:42 +0100 | [diff] [blame] | 239 | /* This dummy driver prevents the host devices from being scanned. We have no | 
|  | 240 | * useful drivers for them yet, and there would be a deadlock possible if the | 
|  | 241 | * driver core scans the host device while the host's low-level driver (i.e. | 
|  | 242 | * the host's parent device) is being removed. */ | 
|  | 243 | static struct device_driver nodemgr_mid_layer_driver = { | 
|  | 244 | .bus		= &ieee1394_bus_type, | 
|  | 245 | .name		= "nodemgr", | 
|  | 246 | .owner		= THIS_MODULE, | 
|  | 247 | }; | 
|  | 248 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | struct device nodemgr_dev_template_host = { | 
|  | 250 | .bus		= &ieee1394_bus_type, | 
|  | 251 | .release	= nodemgr_release_host, | 
|  | 252 | }; | 
|  | 253 |  | 
|  | 254 |  | 
|  | 255 | #define fw_attr(class, class_type, field, type, format_string)		\ | 
| Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 256 | static ssize_t fw_show_##class##_##field (struct device *dev, struct device_attribute *attr, char *buf)\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | {									\ | 
|  | 258 | class_type *class;						\ | 
|  | 259 | class = container_of(dev, class_type, device);			\ | 
|  | 260 | return sprintf(buf, format_string, (type)class->field);		\ | 
|  | 261 | }									\ | 
|  | 262 | static struct device_attribute dev_attr_##class##_##field = {		\ | 
|  | 263 | .attr = {.name = __stringify(field), .mode = S_IRUGO },		\ | 
|  | 264 | .show   = fw_show_##class##_##field,				\ | 
|  | 265 | }; | 
|  | 266 |  | 
|  | 267 | #define fw_attr_td(class, class_type, td_kv)				\ | 
| Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 268 | static ssize_t fw_show_##class##_##td_kv (struct device *dev, struct device_attribute *attr, char *buf)\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | {									\ | 
|  | 270 | int len;							\ | 
|  | 271 | class_type *class = container_of(dev, class_type, device);	\ | 
|  | 272 | len = (class->td_kv->value.leaf.len - 2) * sizeof(quadlet_t);	\ | 
|  | 273 | memcpy(buf,							\ | 
|  | 274 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(class->td_kv),	\ | 
|  | 275 | len);							\ | 
| Al Viro | 51ec138 | 2007-07-15 20:59:51 +0100 | [diff] [blame] | 276 | while (buf[len - 1] == '\0')					\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | len--;							\ | 
|  | 278 | buf[len++] = '\n';						\ | 
|  | 279 | buf[len] = '\0';						\ | 
|  | 280 | return len;							\ | 
|  | 281 | }									\ | 
|  | 282 | static struct device_attribute dev_attr_##class##_##td_kv = {		\ | 
|  | 283 | .attr = {.name = __stringify(td_kv), .mode = S_IRUGO },		\ | 
|  | 284 | .show   = fw_show_##class##_##td_kv,				\ | 
|  | 285 | }; | 
|  | 286 |  | 
|  | 287 |  | 
|  | 288 | #define fw_drv_attr(field, type, format_string)			\ | 
|  | 289 | static ssize_t fw_drv_show_##field (struct device_driver *drv, char *buf) \ | 
|  | 290 | {								\ | 
|  | 291 | struct hpsb_protocol_driver *driver;			\ | 
|  | 292 | driver = container_of(drv, struct hpsb_protocol_driver, driver); \ | 
|  | 293 | return sprintf(buf, format_string, (type)driver->field);\ | 
|  | 294 | }								\ | 
|  | 295 | static struct driver_attribute driver_attr_drv_##field = {	\ | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 296 | .attr = {.name = __stringify(field), .mode = S_IRUGO },	\ | 
|  | 297 | .show   = fw_drv_show_##field,				\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | }; | 
|  | 299 |  | 
|  | 300 |  | 
| Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 301 | static ssize_t fw_show_ne_bus_options(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { | 
|  | 303 | struct node_entry *ne = container_of(dev, struct node_entry, device); | 
|  | 304 |  | 
|  | 305 | return sprintf(buf, "IRMC(%d) CMC(%d) ISC(%d) BMC(%d) PMC(%d) GEN(%d) " | 
|  | 306 | "LSPD(%d) MAX_REC(%d) MAX_ROM(%d) CYC_CLK_ACC(%d)\n", | 
|  | 307 | ne->busopt.irmc, | 
|  | 308 | ne->busopt.cmc, ne->busopt.isc, ne->busopt.bmc, | 
|  | 309 | ne->busopt.pmc, ne->busopt.generation, ne->busopt.lnkspd, | 
|  | 310 | ne->busopt.max_rec, | 
|  | 311 | ne->busopt.max_rom, | 
|  | 312 | ne->busopt.cyc_clk_acc); | 
|  | 313 | } | 
|  | 314 | static DEVICE_ATTR(bus_options,S_IRUGO,fw_show_ne_bus_options,NULL); | 
|  | 315 |  | 
|  | 316 |  | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 317 | #ifdef HPSB_DEBUG_TLABELS | 
|  | 318 | static ssize_t fw_show_ne_tlabels_free(struct device *dev, | 
|  | 319 | struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { | 
|  | 321 | struct node_entry *ne = container_of(dev, struct node_entry, device); | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 322 | unsigned long flags; | 
|  | 323 | unsigned long *tp = ne->host->tl_pool[NODEID_TO_NODE(ne->nodeid)].map; | 
|  | 324 | int tf; | 
|  | 325 |  | 
|  | 326 | spin_lock_irqsave(&hpsb_tlabel_lock, flags); | 
|  | 327 | tf = 64 - bitmap_weight(tp, 64); | 
|  | 328 | spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); | 
|  | 329 |  | 
|  | 330 | return sprintf(buf, "%d\n", tf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } | 
|  | 332 | static DEVICE_ATTR(tlabels_free,S_IRUGO,fw_show_ne_tlabels_free,NULL); | 
|  | 333 |  | 
|  | 334 |  | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 335 | static ssize_t fw_show_ne_tlabels_mask(struct device *dev, | 
|  | 336 | struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { | 
|  | 338 | struct node_entry *ne = container_of(dev, struct node_entry, device); | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 339 | unsigned long flags; | 
|  | 340 | unsigned long *tp = ne->host->tl_pool[NODEID_TO_NODE(ne->nodeid)].map; | 
|  | 341 | u64 tm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 |  | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 343 | spin_lock_irqsave(&hpsb_tlabel_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | #if (BITS_PER_LONG <= 32) | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 345 | tm = ((u64)tp[0] << 32) + tp[1]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | #else | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 347 | tm = tp[0]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | #endif | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 349 | spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); | 
|  | 350 |  | 
| Randy Dunlap | 7f58803 | 2006-10-23 21:44:36 -0700 | [diff] [blame] | 351 | return sprintf(buf, "0x%016llx\n", (unsigned long long)tm); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } | 
|  | 353 | static DEVICE_ATTR(tlabels_mask, S_IRUGO, fw_show_ne_tlabels_mask, NULL); | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 354 | #endif /* HPSB_DEBUG_TLABELS */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 |  | 
|  | 356 |  | 
| Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 357 | static ssize_t fw_set_ignore_driver(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { | 
|  | 359 | struct unit_directory *ud = container_of(dev, struct unit_directory, device); | 
|  | 360 | int state = simple_strtoul(buf, NULL, 10); | 
|  | 361 |  | 
|  | 362 | if (state == 1) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | ud->ignore_driver = 1; | 
| Stefan Richter | b07375b | 2006-10-22 16:16:27 +0200 | [diff] [blame] | 364 | device_release_driver(dev); | 
| Stefan Richter | b07375b | 2006-10-22 16:16:27 +0200 | [diff] [blame] | 365 | } else if (state == 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | ud->ignore_driver = 0; | 
|  | 367 |  | 
|  | 368 | return count; | 
|  | 369 | } | 
| Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 370 | static ssize_t fw_get_ignore_driver(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { | 
|  | 372 | struct unit_directory *ud = container_of(dev, struct unit_directory, device); | 
|  | 373 |  | 
|  | 374 | return sprintf(buf, "%d\n", ud->ignore_driver); | 
|  | 375 | } | 
|  | 376 | static DEVICE_ATTR(ignore_driver, S_IWUSR | S_IRUGO, fw_get_ignore_driver, fw_set_ignore_driver); | 
|  | 377 |  | 
|  | 378 |  | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 379 | static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, | 
|  | 380 | size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 382 | int error = 0; | 
|  | 383 |  | 
| Stefan Richter | 40fd89c | 2006-07-03 12:02:34 -0400 | [diff] [blame] | 384 | if (simple_strtoul(buf, NULL, 10) == 1) | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 385 | error = bus_rescan_devices(&ieee1394_bus_type); | 
|  | 386 | return error ? error : count; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } | 
|  | 388 | static ssize_t fw_get_rescan(struct bus_type *bus, char *buf) | 
|  | 389 | { | 
|  | 390 | return sprintf(buf, "You can force a rescan of the bus for " | 
|  | 391 | "drivers by writing a 1 to this file\n"); | 
|  | 392 | } | 
|  | 393 | static BUS_ATTR(rescan, S_IWUSR | S_IRUGO, fw_get_rescan, fw_set_rescan); | 
|  | 394 |  | 
|  | 395 |  | 
|  | 396 | static ssize_t fw_set_ignore_drivers(struct bus_type *bus, const char *buf, size_t count) | 
|  | 397 | { | 
|  | 398 | int state = simple_strtoul(buf, NULL, 10); | 
|  | 399 |  | 
|  | 400 | if (state == 1) | 
|  | 401 | ignore_drivers = 1; | 
| Stefan Richter | b07375b | 2006-10-22 16:16:27 +0200 | [diff] [blame] | 402 | else if (state == 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | ignore_drivers = 0; | 
|  | 404 |  | 
|  | 405 | return count; | 
|  | 406 | } | 
|  | 407 | static ssize_t fw_get_ignore_drivers(struct bus_type *bus, char *buf) | 
|  | 408 | { | 
|  | 409 | return sprintf(buf, "%d\n", ignore_drivers); | 
|  | 410 | } | 
|  | 411 | static BUS_ATTR(ignore_drivers, S_IWUSR | S_IRUGO, fw_get_ignore_drivers, fw_set_ignore_drivers); | 
|  | 412 |  | 
|  | 413 |  | 
|  | 414 | struct bus_attribute *const fw_bus_attrs[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | &bus_attr_rescan, | 
|  | 416 | &bus_attr_ignore_drivers, | 
|  | 417 | NULL | 
|  | 418 | }; | 
|  | 419 |  | 
|  | 420 |  | 
|  | 421 | fw_attr(ne, struct node_entry, capabilities, unsigned int, "0x%06x\n") | 
|  | 422 | fw_attr(ne, struct node_entry, nodeid, unsigned int, "0x%04x\n") | 
|  | 423 |  | 
|  | 424 | fw_attr(ne, struct node_entry, vendor_id, unsigned int, "0x%06x\n") | 
|  | 425 | fw_attr_td(ne, struct node_entry, vendor_name_kv) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 |  | 
|  | 427 | fw_attr(ne, struct node_entry, guid, unsigned long long, "0x%016Lx\n") | 
|  | 428 | fw_attr(ne, struct node_entry, guid_vendor_id, unsigned int, "0x%06x\n") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | fw_attr(ne, struct node_entry, in_limbo, int, "%d\n"); | 
|  | 430 |  | 
|  | 431 | static struct device_attribute *const fw_ne_attrs[] = { | 
|  | 432 | &dev_attr_ne_guid, | 
|  | 433 | &dev_attr_ne_guid_vendor_id, | 
|  | 434 | &dev_attr_ne_capabilities, | 
|  | 435 | &dev_attr_ne_vendor_id, | 
|  | 436 | &dev_attr_ne_nodeid, | 
|  | 437 | &dev_attr_bus_options, | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 438 | #ifdef HPSB_DEBUG_TLABELS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | &dev_attr_tlabels_free, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | &dev_attr_tlabels_mask, | 
| Stefan Richter | 9951903 | 2006-07-02 14:17:00 +0200 | [diff] [blame] | 441 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | }; | 
|  | 443 |  | 
|  | 444 |  | 
|  | 445 |  | 
|  | 446 | fw_attr(ud, struct unit_directory, address, unsigned long long, "0x%016Lx\n") | 
|  | 447 | fw_attr(ud, struct unit_directory, length, int, "%d\n") | 
|  | 448 | /* These are all dependent on the value being provided */ | 
|  | 449 | fw_attr(ud, struct unit_directory, vendor_id, unsigned int, "0x%06x\n") | 
|  | 450 | fw_attr(ud, struct unit_directory, model_id, unsigned int, "0x%06x\n") | 
|  | 451 | fw_attr(ud, struct unit_directory, specifier_id, unsigned int, "0x%06x\n") | 
|  | 452 | fw_attr(ud, struct unit_directory, version, unsigned int, "0x%06x\n") | 
|  | 453 | fw_attr_td(ud, struct unit_directory, vendor_name_kv) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | fw_attr_td(ud, struct unit_directory, model_name_kv) | 
|  | 455 |  | 
|  | 456 | static struct device_attribute *const fw_ud_attrs[] = { | 
|  | 457 | &dev_attr_ud_address, | 
|  | 458 | &dev_attr_ud_length, | 
|  | 459 | &dev_attr_ignore_driver, | 
|  | 460 | }; | 
|  | 461 |  | 
|  | 462 |  | 
|  | 463 | fw_attr(host, struct hpsb_host, node_count, int, "%d\n") | 
|  | 464 | fw_attr(host, struct hpsb_host, selfid_count, int, "%d\n") | 
|  | 465 | fw_attr(host, struct hpsb_host, nodes_active, int, "%d\n") | 
|  | 466 | fw_attr(host, struct hpsb_host, in_bus_reset, int, "%d\n") | 
|  | 467 | fw_attr(host, struct hpsb_host, is_root, int, "%d\n") | 
|  | 468 | fw_attr(host, struct hpsb_host, is_cycmst, int, "%d\n") | 
|  | 469 | fw_attr(host, struct hpsb_host, is_irm, int, "%d\n") | 
|  | 470 | fw_attr(host, struct hpsb_host, is_busmgr, int, "%d\n") | 
|  | 471 |  | 
|  | 472 | static struct device_attribute *const fw_host_attrs[] = { | 
|  | 473 | &dev_attr_host_node_count, | 
|  | 474 | &dev_attr_host_selfid_count, | 
|  | 475 | &dev_attr_host_nodes_active, | 
|  | 476 | &dev_attr_host_in_bus_reset, | 
|  | 477 | &dev_attr_host_is_root, | 
|  | 478 | &dev_attr_host_is_cycmst, | 
|  | 479 | &dev_attr_host_is_irm, | 
|  | 480 | &dev_attr_host_is_busmgr, | 
|  | 481 | }; | 
|  | 482 |  | 
|  | 483 |  | 
|  | 484 | static ssize_t fw_show_drv_device_ids(struct device_driver *drv, char *buf) | 
|  | 485 | { | 
|  | 486 | struct hpsb_protocol_driver *driver; | 
| Stefan Richter | c640946 | 2009-02-15 23:11:38 +0100 | [diff] [blame] | 487 | const struct ieee1394_device_id *id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | int length = 0; | 
|  | 489 | char *scratch = buf; | 
|  | 490 |  | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 491 | driver = container_of(drv, struct hpsb_protocol_driver, driver); | 
| Stefan Richter | 07c7224 | 2008-05-01 10:43:04 +0200 | [diff] [blame] | 492 | id = driver->id_table; | 
|  | 493 | if (!id) | 
|  | 494 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 |  | 
| Stefan Richter | 07c7224 | 2008-05-01 10:43:04 +0200 | [diff] [blame] | 496 | for (; id->match_flags != 0; id++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | int need_coma = 0; | 
|  | 498 |  | 
|  | 499 | if (id->match_flags & IEEE1394_MATCH_VENDOR_ID) { | 
|  | 500 | length += sprintf(scratch, "vendor_id=0x%06x", id->vendor_id); | 
|  | 501 | scratch = buf + length; | 
|  | 502 | need_coma++; | 
|  | 503 | } | 
|  | 504 |  | 
|  | 505 | if (id->match_flags & IEEE1394_MATCH_MODEL_ID) { | 
|  | 506 | length += sprintf(scratch, "%smodel_id=0x%06x", | 
|  | 507 | need_coma++ ? "," : "", | 
|  | 508 | id->model_id); | 
|  | 509 | scratch = buf + length; | 
|  | 510 | } | 
|  | 511 |  | 
|  | 512 | if (id->match_flags & IEEE1394_MATCH_SPECIFIER_ID) { | 
|  | 513 | length += sprintf(scratch, "%sspecifier_id=0x%06x", | 
|  | 514 | need_coma++ ? "," : "", | 
|  | 515 | id->specifier_id); | 
|  | 516 | scratch = buf + length; | 
|  | 517 | } | 
|  | 518 |  | 
|  | 519 | if (id->match_flags & IEEE1394_MATCH_VERSION) { | 
|  | 520 | length += sprintf(scratch, "%sversion=0x%06x", | 
|  | 521 | need_coma++ ? "," : "", | 
|  | 522 | id->version); | 
|  | 523 | scratch = buf + length; | 
|  | 524 | } | 
|  | 525 |  | 
|  | 526 | if (need_coma) { | 
|  | 527 | *scratch++ = '\n'; | 
|  | 528 | length++; | 
|  | 529 | } | 
|  | 530 | } | 
|  | 531 |  | 
|  | 532 | return length; | 
|  | 533 | } | 
|  | 534 | static DRIVER_ATTR(device_ids,S_IRUGO,fw_show_drv_device_ids,NULL); | 
|  | 535 |  | 
|  | 536 |  | 
|  | 537 | fw_drv_attr(name, const char *, "%s\n") | 
|  | 538 |  | 
|  | 539 | static struct driver_attribute *const fw_drv_attrs[] = { | 
|  | 540 | &driver_attr_drv_name, | 
|  | 541 | &driver_attr_device_ids, | 
|  | 542 | }; | 
|  | 543 |  | 
|  | 544 |  | 
|  | 545 | static void nodemgr_create_drv_files(struct hpsb_protocol_driver *driver) | 
|  | 546 | { | 
|  | 547 | struct device_driver *drv = &driver->driver; | 
|  | 548 | int i; | 
|  | 549 |  | 
|  | 550 | for (i = 0; i < ARRAY_SIZE(fw_drv_attrs); i++) | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 551 | if (driver_create_file(drv, fw_drv_attrs[i])) | 
|  | 552 | goto fail; | 
|  | 553 | return; | 
|  | 554 | fail: | 
| Stefan Richter | 9be51c5 | 2007-03-30 19:21:05 +0200 | [diff] [blame] | 555 | HPSB_ERR("Failed to add sysfs attribute"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } | 
|  | 557 |  | 
|  | 558 |  | 
|  | 559 | static void nodemgr_remove_drv_files(struct hpsb_protocol_driver *driver) | 
|  | 560 | { | 
|  | 561 | struct device_driver *drv = &driver->driver; | 
|  | 562 | int i; | 
|  | 563 |  | 
|  | 564 | for (i = 0; i < ARRAY_SIZE(fw_drv_attrs); i++) | 
|  | 565 | driver_remove_file(drv, fw_drv_attrs[i]); | 
|  | 566 | } | 
|  | 567 |  | 
|  | 568 |  | 
|  | 569 | static void nodemgr_create_ne_dev_files(struct node_entry *ne) | 
|  | 570 | { | 
|  | 571 | struct device *dev = &ne->device; | 
|  | 572 | int i; | 
|  | 573 |  | 
|  | 574 | for (i = 0; i < ARRAY_SIZE(fw_ne_attrs); i++) | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 575 | if (device_create_file(dev, fw_ne_attrs[i])) | 
|  | 576 | goto fail; | 
|  | 577 | return; | 
|  | 578 | fail: | 
| Stefan Richter | 9be51c5 | 2007-03-30 19:21:05 +0200 | [diff] [blame] | 579 | HPSB_ERR("Failed to add sysfs attribute"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } | 
|  | 581 |  | 
|  | 582 |  | 
|  | 583 | static void nodemgr_create_host_dev_files(struct hpsb_host *host) | 
|  | 584 | { | 
|  | 585 | struct device *dev = &host->device; | 
|  | 586 | int i; | 
|  | 587 |  | 
|  | 588 | for (i = 0; i < ARRAY_SIZE(fw_host_attrs); i++) | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 589 | if (device_create_file(dev, fw_host_attrs[i])) | 
|  | 590 | goto fail; | 
|  | 591 | return; | 
|  | 592 | fail: | 
| Stefan Richter | 9be51c5 | 2007-03-30 19:21:05 +0200 | [diff] [blame] | 593 | HPSB_ERR("Failed to add sysfs attribute"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | } | 
|  | 595 |  | 
|  | 596 |  | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 597 | static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, | 
|  | 598 | nodeid_t nodeid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 |  | 
|  | 600 | static void nodemgr_update_host_dev_links(struct hpsb_host *host) | 
|  | 601 | { | 
|  | 602 | struct device *dev = &host->device; | 
|  | 603 | struct node_entry *ne; | 
|  | 604 |  | 
|  | 605 | sysfs_remove_link(&dev->kobj, "irm_id"); | 
|  | 606 | sysfs_remove_link(&dev->kobj, "busmgr_id"); | 
|  | 607 | sysfs_remove_link(&dev->kobj, "host_id"); | 
|  | 608 |  | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 609 | if ((ne = find_entry_by_nodeid(host, host->irm_id)) && | 
|  | 610 | sysfs_create_link(&dev->kobj, &ne->device.kobj, "irm_id")) | 
|  | 611 | goto fail; | 
|  | 612 | if ((ne = find_entry_by_nodeid(host, host->busmgr_id)) && | 
|  | 613 | sysfs_create_link(&dev->kobj, &ne->device.kobj, "busmgr_id")) | 
|  | 614 | goto fail; | 
|  | 615 | if ((ne = find_entry_by_nodeid(host, host->node_id)) && | 
|  | 616 | sysfs_create_link(&dev->kobj, &ne->device.kobj, "host_id")) | 
|  | 617 | goto fail; | 
|  | 618 | return; | 
|  | 619 | fail: | 
|  | 620 | HPSB_ERR("Failed to update sysfs attributes for host %d", host->id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } | 
|  | 622 |  | 
|  | 623 | static void nodemgr_create_ud_dev_files(struct unit_directory *ud) | 
|  | 624 | { | 
|  | 625 | struct device *dev = &ud->device; | 
|  | 626 | int i; | 
|  | 627 |  | 
|  | 628 | for (i = 0; i < ARRAY_SIZE(fw_ud_attrs); i++) | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 629 | if (device_create_file(dev, fw_ud_attrs[i])) | 
|  | 630 | goto fail; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | if (ud->flags & UNIT_DIRECTORY_SPECIFIER_ID) | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 632 | if (device_create_file(dev, &dev_attr_ud_specifier_id)) | 
|  | 633 | goto fail; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | if (ud->flags & UNIT_DIRECTORY_VERSION) | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 635 | if (device_create_file(dev, &dev_attr_ud_version)) | 
|  | 636 | goto fail; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | if (ud->flags & UNIT_DIRECTORY_VENDOR_ID) { | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 638 | if (device_create_file(dev, &dev_attr_ud_vendor_id)) | 
|  | 639 | goto fail; | 
|  | 640 | if (ud->vendor_name_kv && | 
|  | 641 | device_create_file(dev, &dev_attr_ud_vendor_name_kv)) | 
|  | 642 | goto fail; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | if (ud->flags & UNIT_DIRECTORY_MODEL_ID) { | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 645 | if (device_create_file(dev, &dev_attr_ud_model_id)) | 
|  | 646 | goto fail; | 
|  | 647 | if (ud->model_name_kv && | 
|  | 648 | device_create_file(dev, &dev_attr_ud_model_name_kv)) | 
|  | 649 | goto fail; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | } | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 651 | return; | 
|  | 652 | fail: | 
| Stefan Richter | 9be51c5 | 2007-03-30 19:21:05 +0200 | [diff] [blame] | 653 | HPSB_ERR("Failed to add sysfs attribute"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } | 
|  | 655 |  | 
|  | 656 |  | 
|  | 657 | static int nodemgr_bus_match(struct device * dev, struct device_driver * drv) | 
|  | 658 | { | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 659 | struct hpsb_protocol_driver *driver; | 
|  | 660 | struct unit_directory *ud; | 
| Stefan Richter | c640946 | 2009-02-15 23:11:38 +0100 | [diff] [blame] | 661 | const struct ieee1394_device_id *id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 |  | 
|  | 663 | /* We only match unit directories */ | 
|  | 664 | if (dev->platform_data != &nodemgr_ud_platform_data) | 
|  | 665 | return 0; | 
|  | 666 |  | 
|  | 667 | ud = container_of(dev, struct unit_directory, device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | if (ud->ne->in_limbo || ud->ignore_driver) | 
|  | 669 | return 0; | 
|  | 670 |  | 
| Stefan Richter | 8252bbb | 2006-11-22 21:09:42 +0100 | [diff] [blame] | 671 | /* We only match drivers of type hpsb_protocol_driver */ | 
|  | 672 | if (drv == &nodemgr_mid_layer_driver) | 
|  | 673 | return 0; | 
|  | 674 |  | 
|  | 675 | driver = container_of(drv, struct hpsb_protocol_driver, driver); | 
| Stefan Richter | d2ace29 | 2008-02-18 21:11:07 +0100 | [diff] [blame] | 676 | id = driver->id_table; | 
|  | 677 | if (!id) | 
|  | 678 | return 0; | 
|  | 679 |  | 
|  | 680 | for (; id->match_flags != 0; id++) { | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 681 | if ((id->match_flags & IEEE1394_MATCH_VENDOR_ID) && | 
|  | 682 | id->vendor_id != ud->vendor_id) | 
|  | 683 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 |  | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 685 | if ((id->match_flags & IEEE1394_MATCH_MODEL_ID) && | 
|  | 686 | id->model_id != ud->model_id) | 
|  | 687 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 |  | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 689 | if ((id->match_flags & IEEE1394_MATCH_SPECIFIER_ID) && | 
|  | 690 | id->specifier_id != ud->specifier_id) | 
|  | 691 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 |  | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 693 | if ((id->match_flags & IEEE1394_MATCH_VERSION) && | 
|  | 694 | id->version != ud->version) | 
|  | 695 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 |  | 
|  | 697 | return 1; | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 698 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 |  | 
|  | 700 | return 0; | 
|  | 701 | } | 
|  | 702 |  | 
|  | 703 |  | 
| Stefan Richter | b07375b | 2006-10-22 16:16:27 +0200 | [diff] [blame] | 704 | static DEFINE_MUTEX(nodemgr_serialize_remove_uds); | 
|  | 705 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 706 | static int match_ne(struct device *dev, void *data) | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 707 | { | 
|  | 708 | struct unit_directory *ud; | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 709 | struct node_entry *ne = data; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 710 |  | 
|  | 711 | ud = container_of(dev, struct unit_directory, unit_dev); | 
|  | 712 | return ud->ne == ne; | 
|  | 713 | } | 
|  | 714 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | static void nodemgr_remove_uds(struct node_entry *ne) | 
|  | 716 | { | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 717 | struct device *dev; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 718 | struct unit_directory *ud; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 |  | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 720 | /* Use class_find device to iterate the devices. Since this code | 
|  | 721 | * may be called from other contexts besides the knodemgrds, | 
|  | 722 | * protect it by nodemgr_serialize_remove_uds. | 
| Stefan Richter | b07375b | 2006-10-22 16:16:27 +0200 | [diff] [blame] | 723 | */ | 
| Stefan Richter | b07375b | 2006-10-22 16:16:27 +0200 | [diff] [blame] | 724 | mutex_lock(&nodemgr_serialize_remove_uds); | 
| Stefan Richter | 1e4f7bc | 2006-12-02 22:23:34 +0100 | [diff] [blame] | 725 | for (;;) { | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 726 | dev = class_find_device(&nodemgr_ud_class, NULL, ne, match_ne); | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 727 | if (!dev) | 
| Stefan Richter | 1e4f7bc | 2006-12-02 22:23:34 +0100 | [diff] [blame] | 728 | break; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 729 | ud = container_of(dev, struct unit_directory, unit_dev); | 
|  | 730 | put_device(dev); | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 731 | device_unregister(&ud->unit_dev); | 
| Stefan Richter | 1e4f7bc | 2006-12-02 22:23:34 +0100 | [diff] [blame] | 732 | device_unregister(&ud->device); | 
| Stefan Richter | b07375b | 2006-10-22 16:16:27 +0200 | [diff] [blame] | 733 | } | 
| Stefan Richter | b07375b | 2006-10-22 16:16:27 +0200 | [diff] [blame] | 734 | mutex_unlock(&nodemgr_serialize_remove_uds); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } | 
|  | 736 |  | 
|  | 737 |  | 
|  | 738 | static void nodemgr_remove_ne(struct node_entry *ne) | 
|  | 739 | { | 
| Stefan Richter | cec1a31 | 2006-11-18 23:16:11 +0100 | [diff] [blame] | 740 | struct device *dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 |  | 
|  | 742 | dev = get_device(&ne->device); | 
|  | 743 | if (!dev) | 
|  | 744 | return; | 
|  | 745 |  | 
|  | 746 | HPSB_DEBUG("Node removed: ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]", | 
|  | 747 | NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | nodemgr_remove_uds(ne); | 
|  | 749 |  | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 750 | device_unregister(&ne->node_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | device_unregister(dev); | 
|  | 752 |  | 
|  | 753 | put_device(dev); | 
|  | 754 | } | 
|  | 755 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 756 | static int remove_host_dev(struct device *dev, void *data) | 
| gregkh@suse.de | 6436032 | 2005-03-25 11:45:31 -0800 | [diff] [blame] | 757 | { | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 758 | if (dev->bus == &ieee1394_bus_type) | 
|  | 759 | nodemgr_remove_ne(container_of(dev, struct node_entry, | 
|  | 760 | device)); | 
| gregkh@suse.de | 6436032 | 2005-03-25 11:45:31 -0800 | [diff] [blame] | 761 | return 0; | 
|  | 762 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 |  | 
|  | 764 | static void nodemgr_remove_host_dev(struct device *dev) | 
|  | 765 | { | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 766 | device_for_each_child(dev, NULL, remove_host_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | sysfs_remove_link(&dev->kobj, "irm_id"); | 
|  | 768 | sysfs_remove_link(&dev->kobj, "busmgr_id"); | 
|  | 769 | sysfs_remove_link(&dev->kobj, "host_id"); | 
|  | 770 | } | 
|  | 771 |  | 
|  | 772 |  | 
|  | 773 | static void nodemgr_update_bus_options(struct node_entry *ne) | 
|  | 774 | { | 
|  | 775 | #ifdef CONFIG_IEEE1394_VERBOSEDEBUG | 
|  | 776 | static const u16 mr[] = { 4, 64, 1024, 0}; | 
|  | 777 | #endif | 
|  | 778 | quadlet_t busoptions = be32_to_cpu(ne->csr->bus_info_data[2]); | 
|  | 779 |  | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 780 | ne->busopt.irmc		= (busoptions >> 31) & 1; | 
|  | 781 | ne->busopt.cmc		= (busoptions >> 30) & 1; | 
|  | 782 | ne->busopt.isc		= (busoptions >> 29) & 1; | 
|  | 783 | ne->busopt.bmc		= (busoptions >> 28) & 1; | 
|  | 784 | ne->busopt.pmc		= (busoptions >> 27) & 1; | 
|  | 785 | ne->busopt.cyc_clk_acc	= (busoptions >> 16) & 0xff; | 
|  | 786 | ne->busopt.max_rec	= 1 << (((busoptions >> 12) & 0xf) + 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | ne->busopt.max_rom	= (busoptions >> 8) & 0x3; | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 788 | ne->busopt.generation	= (busoptions >> 4) & 0xf; | 
|  | 789 | ne->busopt.lnkspd	= busoptions & 0x7; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 |  | 
|  | 791 | HPSB_VERBOSE("NodeMgr: raw=0x%08x irmc=%d cmc=%d isc=%d bmc=%d pmc=%d " | 
|  | 792 | "cyc_clk_acc=%d max_rec=%d max_rom=%d gen=%d lspd=%d", | 
|  | 793 | busoptions, ne->busopt.irmc, ne->busopt.cmc, | 
|  | 794 | ne->busopt.isc, ne->busopt.bmc, ne->busopt.pmc, | 
|  | 795 | ne->busopt.cyc_clk_acc, ne->busopt.max_rec, | 
|  | 796 | mr[ne->busopt.max_rom], | 
|  | 797 | ne->busopt.generation, ne->busopt.lnkspd); | 
|  | 798 | } | 
|  | 799 |  | 
|  | 800 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 801 | static struct node_entry *nodemgr_create_node(octlet_t guid, | 
|  | 802 | struct csr1212_csr *csr, struct hpsb_host *host, | 
|  | 803 | nodeid_t nodeid, unsigned int generation) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { | 
| Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 805 | struct node_entry *ne; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 |  | 
| Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 807 | ne = kzalloc(sizeof(*ne), GFP_KERNEL); | 
|  | 808 | if (!ne) | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 809 | goto fail_alloc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 |  | 
| Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 811 | ne->host = host; | 
|  | 812 | ne->nodeid = nodeid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | ne->generation = generation; | 
| Stefan Richter | 6848408 | 2008-08-16 13:36:47 +0200 | [diff] [blame] | 814 | ne->needs_probe = true; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 |  | 
| Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 816 | ne->guid = guid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | ne->guid_vendor_id = (guid >> 40) & 0xffffff; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | ne->csr = csr; | 
|  | 819 |  | 
|  | 820 | memcpy(&ne->device, &nodemgr_dev_template_ne, | 
|  | 821 | sizeof(ne->device)); | 
|  | 822 | ne->device.parent = &host->device; | 
| Kay Sievers | 233976e | 2008-10-30 01:49:20 +0100 | [diff] [blame] | 823 | dev_set_name(&ne->device, "%016Lx", (unsigned long long)(ne->guid)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 |  | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 825 | ne->node_dev.parent = &ne->device; | 
|  | 826 | ne->node_dev.class = &nodemgr_ne_class; | 
| Kay Sievers | 233976e | 2008-10-30 01:49:20 +0100 | [diff] [blame] | 827 | dev_set_name(&ne->node_dev, "%016Lx", (unsigned long long)(ne->guid)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 |  | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 829 | if (device_register(&ne->device)) | 
|  | 830 | goto fail_devreg; | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 831 | if (device_register(&ne->node_dev)) | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 832 | goto fail_classdevreg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | get_device(&ne->device); | 
|  | 834 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | nodemgr_create_ne_dev_files(ne); | 
|  | 836 |  | 
|  | 837 | nodemgr_update_bus_options(ne); | 
|  | 838 |  | 
|  | 839 | HPSB_DEBUG("%s added: ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]", | 
|  | 840 | (host->node_id == nodeid) ? "Host" : "Node", | 
|  | 841 | NODE_BUS_ARGS(host, nodeid), (unsigned long long)guid); | 
|  | 842 |  | 
| Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 843 | return ne; | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 844 |  | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 845 | fail_classdevreg: | 
|  | 846 | device_unregister(&ne->device); | 
|  | 847 | fail_devreg: | 
|  | 848 | kfree(ne); | 
|  | 849 | fail_alloc: | 
|  | 850 | HPSB_ERR("Failed to create node ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]", | 
|  | 851 | NODE_BUS_ARGS(host, nodeid), (unsigned long long)guid); | 
|  | 852 |  | 
|  | 853 | return NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | } | 
|  | 855 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 856 | static int match_ne_guid(struct device *dev, void *data) | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 857 | { | 
|  | 858 | struct node_entry *ne; | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 859 | u64 *guid = data; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 860 |  | 
|  | 861 | ne = container_of(dev, struct node_entry, node_dev); | 
|  | 862 | return ne->guid == *guid; | 
|  | 863 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 |  | 
|  | 865 | static struct node_entry *find_entry_by_guid(u64 guid) | 
|  | 866 | { | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 867 | struct device *dev; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 868 | struct node_entry *ne; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 870 | dev = class_find_device(&nodemgr_ne_class, NULL, &guid, match_ne_guid); | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 871 | if (!dev) | 
|  | 872 | return NULL; | 
|  | 873 | ne = container_of(dev, struct node_entry, node_dev); | 
|  | 874 | put_device(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 |  | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 876 | return ne; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | } | 
|  | 878 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 879 | struct match_nodeid_parameter { | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 880 | struct hpsb_host *host; | 
|  | 881 | nodeid_t nodeid; | 
|  | 882 | }; | 
|  | 883 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 884 | static int match_ne_nodeid(struct device *dev, void *data) | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 885 | { | 
|  | 886 | int found = 0; | 
|  | 887 | struct node_entry *ne; | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 888 | struct match_nodeid_parameter *p = data; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 889 |  | 
|  | 890 | if (!dev) | 
|  | 891 | goto ret; | 
|  | 892 | ne = container_of(dev, struct node_entry, node_dev); | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 893 | if (ne->host == p->host && ne->nodeid == p->nodeid) | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 894 | found = 1; | 
|  | 895 | ret: | 
|  | 896 | return found; | 
|  | 897 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 |  | 
| Stefan Richter | b07375b | 2006-10-22 16:16:27 +0200 | [diff] [blame] | 899 | static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, | 
|  | 900 | nodeid_t nodeid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | { | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 902 | struct device *dev; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 903 | struct node_entry *ne; | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 904 | struct match_nodeid_parameter p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 906 | p.host = host; | 
|  | 907 | p.nodeid = nodeid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 909 | dev = class_find_device(&nodemgr_ne_class, NULL, &p, match_ne_nodeid); | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 910 | if (!dev) | 
|  | 911 | return NULL; | 
|  | 912 | ne = container_of(dev, struct node_entry, node_dev); | 
|  | 913 | put_device(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 |  | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 915 | return ne; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | } | 
|  | 917 |  | 
|  | 918 |  | 
|  | 919 | static void nodemgr_register_device(struct node_entry *ne, | 
|  | 920 | struct unit_directory *ud, struct device *parent) | 
|  | 921 | { | 
|  | 922 | memcpy(&ud->device, &nodemgr_dev_template_ud, | 
|  | 923 | sizeof(ud->device)); | 
|  | 924 |  | 
|  | 925 | ud->device.parent = parent; | 
|  | 926 |  | 
| Kay Sievers | 233976e | 2008-10-30 01:49:20 +0100 | [diff] [blame] | 927 | dev_set_name(&ud->device, "%s-%u", dev_name(&ne->device), ud->id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 |  | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 929 | ud->unit_dev.parent = &ud->device; | 
|  | 930 | ud->unit_dev.class = &nodemgr_ud_class; | 
| Kay Sievers | 233976e | 2008-10-30 01:49:20 +0100 | [diff] [blame] | 931 | dev_set_name(&ud->unit_dev, "%s-%u", dev_name(&ne->device), ud->id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 |  | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 933 | if (device_register(&ud->device)) | 
|  | 934 | goto fail_devreg; | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 935 | if (device_register(&ud->unit_dev)) | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 936 | goto fail_classdevreg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | get_device(&ud->device); | 
|  | 938 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | nodemgr_create_ud_dev_files(ud); | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 940 |  | 
|  | 941 | return; | 
|  | 942 |  | 
| Stefan Richter | c1c9c7c | 2006-10-10 21:19:21 +0200 | [diff] [blame] | 943 | fail_classdevreg: | 
|  | 944 | device_unregister(&ud->device); | 
|  | 945 | fail_devreg: | 
| Kay Sievers | 233976e | 2008-10-30 01:49:20 +0100 | [diff] [blame] | 946 | HPSB_ERR("Failed to create unit %s", dev_name(&ud->device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } | 
|  | 948 |  | 
|  | 949 |  | 
|  | 950 | /* This implementation currently only scans the config rom and its | 
|  | 951 | * immediate unit directories looking for software_id and | 
|  | 952 | * software_version entries, in order to get driver autoloading working. */ | 
|  | 953 | static struct unit_directory *nodemgr_process_unit_directory | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 954 | (struct node_entry *ne, struct csr1212_keyval *ud_kv, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | unsigned int *id, struct unit_directory *parent) | 
|  | 956 | { | 
|  | 957 | struct unit_directory *ud; | 
|  | 958 | struct unit_directory *ud_child = NULL; | 
|  | 959 | struct csr1212_dentry *dentry; | 
|  | 960 | struct csr1212_keyval *kv; | 
|  | 961 | u8 last_key_id = 0; | 
|  | 962 |  | 
| Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 963 | ud = kzalloc(sizeof(*ud), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | if (!ud) | 
|  | 965 | goto unit_directory_error; | 
|  | 966 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | ud->ne = ne; | 
|  | 968 | ud->ignore_driver = ignore_drivers; | 
| Stefan Richter | a52938f | 2007-05-27 13:11:47 +0200 | [diff] [blame] | 969 | ud->address = ud_kv->offset + CSR1212_REGISTER_SPACE_BASE; | 
| Stefan Richter | d7794c8 | 2007-05-27 13:17:15 +0200 | [diff] [blame] | 970 | ud->directory_id = ud->address & 0xffffff; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | ud->ud_kv = ud_kv; | 
|  | 972 | ud->id = (*id)++; | 
|  | 973 |  | 
| Stefan Richter | 9c939e4 | 2008-08-27 01:24:25 +0200 | [diff] [blame] | 974 | /* inherit vendor_id from root directory if none exists in unit dir */ | 
|  | 975 | ud->vendor_id = ne->vendor_id; | 
|  | 976 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | csr1212_for_each_dir_entry(ne->csr, kv, ud_kv, dentry) { | 
|  | 978 | switch (kv->key.id) { | 
|  | 979 | case CSR1212_KV_ID_VENDOR: | 
|  | 980 | if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) { | 
|  | 981 | ud->vendor_id = kv->value.immediate; | 
|  | 982 | ud->flags |= UNIT_DIRECTORY_VENDOR_ID; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } | 
|  | 984 | break; | 
|  | 985 |  | 
|  | 986 | case CSR1212_KV_ID_MODEL: | 
|  | 987 | ud->model_id = kv->value.immediate; | 
|  | 988 | ud->flags |= UNIT_DIRECTORY_MODEL_ID; | 
|  | 989 | break; | 
|  | 990 |  | 
|  | 991 | case CSR1212_KV_ID_SPECIFIER_ID: | 
|  | 992 | ud->specifier_id = kv->value.immediate; | 
|  | 993 | ud->flags |= UNIT_DIRECTORY_SPECIFIER_ID; | 
|  | 994 | break; | 
|  | 995 |  | 
|  | 996 | case CSR1212_KV_ID_VERSION: | 
|  | 997 | ud->version = kv->value.immediate; | 
|  | 998 | ud->flags |= UNIT_DIRECTORY_VERSION; | 
|  | 999 | break; | 
|  | 1000 |  | 
|  | 1001 | case CSR1212_KV_ID_DESCRIPTOR: | 
|  | 1002 | if (kv->key.type == CSR1212_KV_TYPE_LEAF && | 
|  | 1003 | CSR1212_DESCRIPTOR_LEAF_TYPE(kv) == 0 && | 
|  | 1004 | CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) == 0 && | 
|  | 1005 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) == 0 && | 
|  | 1006 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) == 0 && | 
|  | 1007 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0) { | 
|  | 1008 | switch (last_key_id) { | 
|  | 1009 | case CSR1212_KV_ID_VENDOR: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | csr1212_keep_keyval(kv); | 
| Stefan Richter | 17a19b7 | 2007-09-15 14:50:25 +0200 | [diff] [blame] | 1011 | ud->vendor_name_kv = kv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | break; | 
|  | 1013 |  | 
|  | 1014 | case CSR1212_KV_ID_MODEL: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | csr1212_keep_keyval(kv); | 
| Stefan Richter | 17a19b7 | 2007-09-15 14:50:25 +0200 | [diff] [blame] | 1016 | ud->model_name_kv = kv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | break; | 
|  | 1018 |  | 
|  | 1019 | } | 
|  | 1020 | } /* else if (kv->key.type == CSR1212_KV_TYPE_DIRECTORY) ... */ | 
|  | 1021 | break; | 
|  | 1022 |  | 
|  | 1023 | case CSR1212_KV_ID_DEPENDENT_INFO: | 
|  | 1024 | /* Logical Unit Number */ | 
|  | 1025 | if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) { | 
|  | 1026 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN) { | 
| Eric Sesterhenn | bfe89d7 | 2006-10-29 23:13:40 +0300 | [diff] [blame] | 1027 | ud_child = kmemdup(ud, sizeof(*ud_child), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | if (!ud_child) | 
|  | 1029 | goto unit_directory_error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | nodemgr_register_device(ne, ud_child, &ne->device); | 
|  | 1031 | ud_child = NULL; | 
|  | 1032 |  | 
|  | 1033 | ud->id = (*id)++; | 
|  | 1034 | } | 
|  | 1035 | ud->lun = kv->value.immediate; | 
|  | 1036 | ud->flags |= UNIT_DIRECTORY_HAS_LUN; | 
|  | 1037 |  | 
|  | 1038 | /* Logical Unit Directory */ | 
|  | 1039 | } else if (kv->key.type == CSR1212_KV_TYPE_DIRECTORY) { | 
|  | 1040 | /* This should really be done in SBP2 as this is | 
|  | 1041 | * doing SBP2 specific parsing. | 
|  | 1042 | */ | 
|  | 1043 |  | 
|  | 1044 | /* first register the parent unit */ | 
|  | 1045 | ud->flags |= UNIT_DIRECTORY_HAS_LUN_DIRECTORY; | 
|  | 1046 | if (ud->device.bus != &ieee1394_bus_type) | 
|  | 1047 | nodemgr_register_device(ne, ud, &ne->device); | 
|  | 1048 |  | 
|  | 1049 | /* process the child unit */ | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1050 | ud_child = nodemgr_process_unit_directory(ne, kv, id, ud); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 |  | 
|  | 1052 | if (ud_child == NULL) | 
|  | 1053 | break; | 
|  | 1054 |  | 
| Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 1055 | /* inherit unspecified values, the driver core picks it up */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | if ((ud->flags & UNIT_DIRECTORY_MODEL_ID) && | 
|  | 1057 | !(ud_child->flags & UNIT_DIRECTORY_MODEL_ID)) | 
|  | 1058 | { | 
|  | 1059 | ud_child->flags |=  UNIT_DIRECTORY_MODEL_ID; | 
|  | 1060 | ud_child->model_id = ud->model_id; | 
|  | 1061 | } | 
|  | 1062 | if ((ud->flags & UNIT_DIRECTORY_SPECIFIER_ID) && | 
|  | 1063 | !(ud_child->flags & UNIT_DIRECTORY_SPECIFIER_ID)) | 
|  | 1064 | { | 
|  | 1065 | ud_child->flags |=  UNIT_DIRECTORY_SPECIFIER_ID; | 
|  | 1066 | ud_child->specifier_id = ud->specifier_id; | 
|  | 1067 | } | 
|  | 1068 | if ((ud->flags & UNIT_DIRECTORY_VERSION) && | 
|  | 1069 | !(ud_child->flags & UNIT_DIRECTORY_VERSION)) | 
|  | 1070 | { | 
|  | 1071 | ud_child->flags |=  UNIT_DIRECTORY_VERSION; | 
|  | 1072 | ud_child->version = ud->version; | 
|  | 1073 | } | 
|  | 1074 |  | 
|  | 1075 | /* register the child unit */ | 
|  | 1076 | ud_child->flags |= UNIT_DIRECTORY_LUN_DIRECTORY; | 
|  | 1077 | nodemgr_register_device(ne, ud_child, &ud->device); | 
|  | 1078 | } | 
|  | 1079 |  | 
|  | 1080 | break; | 
|  | 1081 |  | 
| Stefan Richter | d7794c8 | 2007-05-27 13:17:15 +0200 | [diff] [blame] | 1082 | case CSR1212_KV_ID_DIRECTORY_ID: | 
|  | 1083 | ud->directory_id = kv->value.immediate; | 
|  | 1084 | break; | 
|  | 1085 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | default: | 
|  | 1087 | break; | 
|  | 1088 | } | 
|  | 1089 | last_key_id = kv->key.id; | 
|  | 1090 | } | 
|  | 1091 |  | 
|  | 1092 | /* do not process child units here and only if not already registered */ | 
|  | 1093 | if (!parent && ud->device.bus != &ieee1394_bus_type) | 
|  | 1094 | nodemgr_register_device(ne, ud, &ne->device); | 
|  | 1095 |  | 
|  | 1096 | return ud; | 
|  | 1097 |  | 
|  | 1098 | unit_directory_error: | 
| Jody McIntyre | 616b859 | 2005-05-16 21:54:01 -0700 | [diff] [blame] | 1099 | kfree(ud); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | return NULL; | 
|  | 1101 | } | 
|  | 1102 |  | 
|  | 1103 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1104 | static void nodemgr_process_root_directory(struct node_entry *ne) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | { | 
|  | 1106 | unsigned int ud_id = 0; | 
|  | 1107 | struct csr1212_dentry *dentry; | 
| Stefan Richter | 638d5bb | 2007-09-15 14:45:53 +0200 | [diff] [blame] | 1108 | struct csr1212_keyval *kv, *vendor_name_kv = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | u8 last_key_id = 0; | 
|  | 1110 |  | 
| Stefan Richter | 6848408 | 2008-08-16 13:36:47 +0200 | [diff] [blame] | 1111 | ne->needs_probe = false; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 |  | 
|  | 1113 | csr1212_for_each_dir_entry(ne->csr, kv, ne->csr->root_kv, dentry) { | 
|  | 1114 | switch (kv->key.id) { | 
|  | 1115 | case CSR1212_KV_ID_VENDOR: | 
|  | 1116 | ne->vendor_id = kv->value.immediate; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | break; | 
|  | 1118 |  | 
|  | 1119 | case CSR1212_KV_ID_NODE_CAPABILITIES: | 
|  | 1120 | ne->capabilities = kv->value.immediate; | 
|  | 1121 | break; | 
|  | 1122 |  | 
|  | 1123 | case CSR1212_KV_ID_UNIT: | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1124 | nodemgr_process_unit_directory(ne, kv, &ud_id, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | break; | 
|  | 1126 |  | 
|  | 1127 | case CSR1212_KV_ID_DESCRIPTOR: | 
|  | 1128 | if (last_key_id == CSR1212_KV_ID_VENDOR) { | 
|  | 1129 | if (kv->key.type == CSR1212_KV_TYPE_LEAF && | 
|  | 1130 | CSR1212_DESCRIPTOR_LEAF_TYPE(kv) == 0 && | 
|  | 1131 | CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) == 0 && | 
|  | 1132 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) == 0 && | 
|  | 1133 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) == 0 && | 
|  | 1134 | CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | csr1212_keep_keyval(kv); | 
| Stefan Richter | 638d5bb | 2007-09-15 14:45:53 +0200 | [diff] [blame] | 1136 | vendor_name_kv = kv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | } | 
|  | 1138 | } | 
|  | 1139 | break; | 
|  | 1140 | } | 
|  | 1141 | last_key_id = kv->key.id; | 
|  | 1142 | } | 
|  | 1143 |  | 
| Stefan Richter | 9324547 | 2007-03-30 19:19:55 +0200 | [diff] [blame] | 1144 | if (ne->vendor_name_kv) { | 
| Stefan Richter | 638d5bb | 2007-09-15 14:45:53 +0200 | [diff] [blame] | 1145 | kv = ne->vendor_name_kv; | 
|  | 1146 | ne->vendor_name_kv = vendor_name_kv; | 
|  | 1147 | csr1212_release_keyval(kv); | 
|  | 1148 | } else if (vendor_name_kv) { | 
|  | 1149 | ne->vendor_name_kv = vendor_name_kv; | 
|  | 1150 | if (device_create_file(&ne->device, | 
|  | 1151 | &dev_attr_ne_vendor_name_kv) != 0) | 
| Stefan Richter | 9be51c5 | 2007-03-30 19:21:05 +0200 | [diff] [blame] | 1152 | HPSB_ERR("Failed to add sysfs attribute"); | 
| Stefan Richter | 9324547 | 2007-03-30 19:19:55 +0200 | [diff] [blame] | 1153 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | } | 
|  | 1155 |  | 
|  | 1156 | #ifdef CONFIG_HOTPLUG | 
|  | 1157 |  | 
| Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1158 | static int nodemgr_uevent(struct device *dev, struct kobj_uevent_env *env) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | { | 
|  | 1160 | struct unit_directory *ud; | 
| Eric Rannaud | bf62456 | 2007-03-30 22:23:12 -0700 | [diff] [blame] | 1161 | int retval = 0; | 
| Olaf Hering | 9b19d85 | 2005-09-06 15:18:18 -0700 | [diff] [blame] | 1162 | /* ieee1394:venNmoNspNverN */ | 
|  | 1163 | char buf[8 + 1 + 3 + 8 + 2 + 8 + 2 + 8 + 3 + 8 + 1]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 |  | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 1165 | if (!dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | return -ENODEV; | 
|  | 1167 |  | 
| Kay Sievers | dd7f292 | 2007-05-25 11:50:53 +0200 | [diff] [blame] | 1168 | ud = container_of(dev, struct unit_directory, unit_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 |  | 
|  | 1170 | if (ud->ne->in_limbo || ud->ignore_driver) | 
|  | 1171 | return -ENODEV; | 
|  | 1172 |  | 
|  | 1173 | #define PUT_ENVP(fmt,val) 					\ | 
|  | 1174 | do {								\ | 
| Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1175 | retval = add_uevent_var(env, fmt, val);		\ | 
| Eric Rannaud | bf62456 | 2007-03-30 22:23:12 -0700 | [diff] [blame] | 1176 | if (retval)						\ | 
|  | 1177 | return retval;					\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } while (0) | 
|  | 1179 |  | 
|  | 1180 | PUT_ENVP("VENDOR_ID=%06x", ud->vendor_id); | 
|  | 1181 | PUT_ENVP("MODEL_ID=%06x", ud->model_id); | 
|  | 1182 | PUT_ENVP("GUID=%016Lx", (unsigned long long)ud->ne->guid); | 
|  | 1183 | PUT_ENVP("SPECIFIER_ID=%06x", ud->specifier_id); | 
|  | 1184 | PUT_ENVP("VERSION=%06x", ud->version); | 
| Olaf Hering | 9b19d85 | 2005-09-06 15:18:18 -0700 | [diff] [blame] | 1185 | snprintf(buf, sizeof(buf), "ieee1394:ven%08Xmo%08Xsp%08Xver%08X", | 
|  | 1186 | ud->vendor_id, | 
|  | 1187 | ud->model_id, | 
|  | 1188 | ud->specifier_id, | 
|  | 1189 | ud->version); | 
|  | 1190 | PUT_ENVP("MODALIAS=%s", buf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 |  | 
|  | 1192 | #undef PUT_ENVP | 
|  | 1193 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | return 0; | 
|  | 1195 | } | 
|  | 1196 |  | 
|  | 1197 | #else | 
|  | 1198 |  | 
| Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1199 | static int nodemgr_uevent(struct device *dev, struct kobj_uevent_env *env) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | { | 
|  | 1201 | return -ENODEV; | 
|  | 1202 | } | 
|  | 1203 |  | 
|  | 1204 | #endif /* CONFIG_HOTPLUG */ | 
|  | 1205 |  | 
|  | 1206 |  | 
| Ben Collins | ed30c26 | 2006-11-23 13:59:48 -0500 | [diff] [blame] | 1207 | int __hpsb_register_protocol(struct hpsb_protocol_driver *drv, | 
|  | 1208 | struct module *owner) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | { | 
| Ben Collins | ed30c26 | 2006-11-23 13:59:48 -0500 | [diff] [blame] | 1210 | int error; | 
|  | 1211 |  | 
|  | 1212 | drv->driver.bus = &ieee1394_bus_type; | 
|  | 1213 | drv->driver.owner = owner; | 
|  | 1214 | drv->driver.name = drv->name; | 
|  | 1215 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | /* This will cause a probe for devices */ | 
| Ben Collins | ed30c26 | 2006-11-23 13:59:48 -0500 | [diff] [blame] | 1217 | error = driver_register(&drv->driver); | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1218 | if (!error) | 
| Ben Collins | ed30c26 | 2006-11-23 13:59:48 -0500 | [diff] [blame] | 1219 | nodemgr_create_drv_files(drv); | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1220 | return error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | } | 
|  | 1222 |  | 
|  | 1223 | void hpsb_unregister_protocol(struct hpsb_protocol_driver *driver) | 
|  | 1224 | { | 
|  | 1225 | nodemgr_remove_drv_files(driver); | 
|  | 1226 | /* This will subsequently disconnect all devices that our driver | 
|  | 1227 | * is attached to. */ | 
|  | 1228 | driver_unregister(&driver->driver); | 
|  | 1229 | } | 
|  | 1230 |  | 
|  | 1231 |  | 
|  | 1232 | /* | 
|  | 1233 | * This function updates nodes that were present on the bus before the | 
|  | 1234 | * reset and still are after the reset.  The nodeid and the config rom | 
|  | 1235 | * may have changed, and the drivers managing this device must be | 
|  | 1236 | * informed that this device just went through a bus reset, to allow | 
|  | 1237 | * the to take whatever actions required. | 
|  | 1238 | */ | 
|  | 1239 | static void nodemgr_update_node(struct node_entry *ne, struct csr1212_csr *csr, | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1240 | nodeid_t nodeid, unsigned int generation) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | { | 
|  | 1242 | if (ne->nodeid != nodeid) { | 
|  | 1243 | HPSB_DEBUG("Node changed: " NODE_BUS_FMT " -> " NODE_BUS_FMT, | 
|  | 1244 | NODE_BUS_ARGS(ne->host, ne->nodeid), | 
|  | 1245 | NODE_BUS_ARGS(ne->host, nodeid)); | 
|  | 1246 | ne->nodeid = nodeid; | 
|  | 1247 | } | 
|  | 1248 |  | 
|  | 1249 | if (ne->busopt.generation != ((be32_to_cpu(csr->bus_info_data[2]) >> 4) & 0xf)) { | 
|  | 1250 | kfree(ne->csr->private); | 
|  | 1251 | csr1212_destroy_csr(ne->csr); | 
|  | 1252 | ne->csr = csr; | 
|  | 1253 |  | 
|  | 1254 | /* If the node's configrom generation has changed, we | 
|  | 1255 | * unregister all the unit directories. */ | 
|  | 1256 | nodemgr_remove_uds(ne); | 
|  | 1257 |  | 
|  | 1258 | nodemgr_update_bus_options(ne); | 
|  | 1259 |  | 
|  | 1260 | /* Mark the node as new, so it gets re-probed */ | 
| Stefan Richter | 6848408 | 2008-08-16 13:36:47 +0200 | [diff] [blame] | 1261 | ne->needs_probe = true; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | } else { | 
|  | 1263 | /* old cache is valid, so update its generation */ | 
|  | 1264 | struct nodemgr_csr_info *ci = ne->csr->private; | 
|  | 1265 | ci->generation = generation; | 
|  | 1266 | /* free the partially filled now unneeded new cache */ | 
|  | 1267 | kfree(csr->private); | 
|  | 1268 | csr1212_destroy_csr(csr); | 
|  | 1269 | } | 
|  | 1270 |  | 
| Stefan Richter | 29f8ea8 | 2008-08-27 01:18:32 +0200 | [diff] [blame] | 1271 | /* Finally, mark the node current */ | 
|  | 1272 | smp_wmb(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | ne->generation = generation; | 
| Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 1274 |  | 
|  | 1275 | if (ne->in_limbo) { | 
|  | 1276 | device_remove_file(&ne->device, &dev_attr_ne_in_limbo); | 
|  | 1277 | ne->in_limbo = false; | 
|  | 1278 |  | 
|  | 1279 | HPSB_DEBUG("Node reactivated: " | 
|  | 1280 | "ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]", | 
|  | 1281 | NODE_BUS_ARGS(ne->host, ne->nodeid), | 
|  | 1282 | (unsigned long long)ne->guid); | 
|  | 1283 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | } | 
|  | 1285 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1286 | static void nodemgr_node_scan_one(struct hpsb_host *host, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | nodeid_t nodeid, int generation) | 
|  | 1288 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | struct node_entry *ne; | 
|  | 1290 | octlet_t guid; | 
|  | 1291 | struct csr1212_csr *csr; | 
|  | 1292 | struct nodemgr_csr_info *ci; | 
| Stefan Richter | d7530a1 | 2006-07-03 00:58:01 +0200 | [diff] [blame] | 1293 | u8 *speed; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 |  | 
| Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 1295 | ci = kmalloc(sizeof(*ci), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | if (!ci) | 
|  | 1297 | return; | 
|  | 1298 |  | 
|  | 1299 | ci->host = host; | 
|  | 1300 | ci->nodeid = nodeid; | 
|  | 1301 | ci->generation = generation; | 
| Stefan Richter | d7530a1 | 2006-07-03 00:58:01 +0200 | [diff] [blame] | 1302 |  | 
|  | 1303 | /* Prepare for speed probe which occurs when reading the ROM */ | 
|  | 1304 | speed = &(host->speed[NODEID_TO_NODE(nodeid)]); | 
|  | 1305 | if (*speed > host->csr.lnk_spd) | 
|  | 1306 | *speed = host->csr.lnk_spd; | 
|  | 1307 | ci->speed_unverified = *speed > IEEE1394_SPEED_100; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 |  | 
|  | 1309 | /* We need to detect when the ConfigROM's generation has changed, | 
|  | 1310 | * so we only update the node's info when it needs to be.  */ | 
|  | 1311 |  | 
|  | 1312 | csr = csr1212_create_csr(&nodemgr_csr_ops, 5 * sizeof(quadlet_t), ci); | 
|  | 1313 | if (!csr || csr1212_parse_csr(csr) != CSR1212_SUCCESS) { | 
|  | 1314 | HPSB_ERR("Error parsing configrom for node " NODE_BUS_FMT, | 
|  | 1315 | NODE_BUS_ARGS(host, nodeid)); | 
|  | 1316 | if (csr) | 
|  | 1317 | csr1212_destroy_csr(csr); | 
|  | 1318 | kfree(ci); | 
|  | 1319 | return; | 
|  | 1320 | } | 
|  | 1321 |  | 
|  | 1322 | if (csr->bus_info_data[1] != IEEE1394_BUSID_MAGIC) { | 
|  | 1323 | /* This isn't a 1394 device, but we let it slide. There | 
|  | 1324 | * was a report of a device with broken firmware which | 
|  | 1325 | * reported '2394' instead of '1394', which is obviously a | 
|  | 1326 | * mistake. One would hope that a non-1394 device never | 
|  | 1327 | * gets connected to Firewire bus. If someone does, we | 
|  | 1328 | * shouldn't be held responsible, so we'll allow it with a | 
|  | 1329 | * warning.  */ | 
|  | 1330 | HPSB_WARN("Node " NODE_BUS_FMT " has invalid busID magic [0x%08x]", | 
|  | 1331 | NODE_BUS_ARGS(host, nodeid), csr->bus_info_data[1]); | 
|  | 1332 | } | 
|  | 1333 |  | 
|  | 1334 | guid = ((u64)be32_to_cpu(csr->bus_info_data[3]) << 32) | be32_to_cpu(csr->bus_info_data[4]); | 
|  | 1335 | ne = find_entry_by_guid(guid); | 
|  | 1336 |  | 
|  | 1337 | if (ne && ne->host != host && ne->in_limbo) { | 
|  | 1338 | /* Must have moved this device from one host to another */ | 
|  | 1339 | nodemgr_remove_ne(ne); | 
|  | 1340 | ne = NULL; | 
|  | 1341 | } | 
|  | 1342 |  | 
|  | 1343 | if (!ne) | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1344 | nodemgr_create_node(guid, csr, host, nodeid, generation); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | else | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1346 | nodemgr_update_node(ne, csr, nodeid, generation); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | } | 
|  | 1348 |  | 
|  | 1349 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1350 | static void nodemgr_node_scan(struct hpsb_host *host, int generation) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | { | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 1352 | int count; | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 1353 | struct selfid *sid = (struct selfid *)host->topology_map; | 
|  | 1354 | nodeid_t nodeid = LOCAL_BUS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 |  | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 1356 | /* Scan each node on the bus */ | 
|  | 1357 | for (count = host->selfid_count; count; count--, sid++) { | 
|  | 1358 | if (sid->extended) | 
|  | 1359 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 |  | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 1361 | if (!sid->link_active) { | 
|  | 1362 | nodeid++; | 
|  | 1363 | continue; | 
|  | 1364 | } | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1365 | nodemgr_node_scan_one(host, nodeid++, generation); | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 1366 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | } | 
|  | 1368 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1369 | static void nodemgr_pause_ne(struct node_entry *ne) | 
|  | 1370 | { | 
| Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 1371 | HPSB_DEBUG("Node paused: ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]", | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1372 | NODE_BUS_ARGS(ne->host, ne->nodeid), | 
|  | 1373 | (unsigned long long)ne->guid); | 
|  | 1374 |  | 
| Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 1375 | ne->in_limbo = true; | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1376 | WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | } | 
|  | 1378 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1379 | static int update_pdrv(struct device *dev, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | { | 
| Stefan Richter | a0e857e | 2007-06-17 23:47:45 +0200 | [diff] [blame] | 1381 | struct unit_directory *ud; | 
|  | 1382 | struct device_driver *drv; | 
|  | 1383 | struct hpsb_protocol_driver *pdrv; | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1384 | struct node_entry *ne = data; | 
| Stefan Richter | a0e857e | 2007-06-17 23:47:45 +0200 | [diff] [blame] | 1385 | int error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 |  | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1387 | ud = container_of(dev, struct unit_directory, unit_dev); | 
|  | 1388 | if (ud->ne == ne) { | 
| Stefan Richter | a0e857e | 2007-06-17 23:47:45 +0200 | [diff] [blame] | 1389 | drv = get_driver(ud->device.driver); | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1390 | if (drv) { | 
|  | 1391 | error = 0; | 
|  | 1392 | pdrv = container_of(drv, struct hpsb_protocol_driver, | 
|  | 1393 | driver); | 
|  | 1394 | if (pdrv->update) { | 
|  | 1395 | down(&ud->device.sem); | 
|  | 1396 | error = pdrv->update(ud); | 
|  | 1397 | up(&ud->device.sem); | 
|  | 1398 | } | 
|  | 1399 | if (error) | 
|  | 1400 | device_release_driver(&ud->device); | 
|  | 1401 | put_driver(drv); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | } | 
|  | 1403 | } | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1404 |  | 
|  | 1405 | return 0; | 
|  | 1406 | } | 
|  | 1407 |  | 
|  | 1408 | static void nodemgr_update_pdrv(struct node_entry *ne) | 
|  | 1409 | { | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1410 | class_for_each_device(&nodemgr_ud_class, NULL, ne, update_pdrv); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | } | 
|  | 1412 |  | 
| Stefan Richter | 61c7f77 | 2005-12-05 16:28:59 -0500 | [diff] [blame] | 1413 | /* Write the BROADCAST_CHANNEL as per IEEE1394a 8.3.2.3.11 and 8.4.2.3.  This | 
|  | 1414 | * seems like an optional service but in the end it is practically mandatory | 
|  | 1415 | * as a consequence of these clauses. | 
|  | 1416 | * | 
|  | 1417 | * Note that we cannot do a broadcast write to all nodes at once because some | 
|  | 1418 | * pre-1394a devices would hang. */ | 
|  | 1419 | static void nodemgr_irm_write_bc(struct node_entry *ne, int generation) | 
|  | 1420 | { | 
|  | 1421 | const u64 bc_addr = (CSR_REGISTER_BASE | CSR_BROADCAST_CHANNEL); | 
|  | 1422 | quadlet_t bc_remote, bc_local; | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1423 | int error; | 
| Stefan Richter | 61c7f77 | 2005-12-05 16:28:59 -0500 | [diff] [blame] | 1424 |  | 
|  | 1425 | if (!ne->host->is_irm || ne->generation != generation || | 
|  | 1426 | ne->nodeid == ne->host->node_id) | 
|  | 1427 | return; | 
|  | 1428 |  | 
|  | 1429 | bc_local = cpu_to_be32(ne->host->csr.broadcast_channel); | 
|  | 1430 |  | 
|  | 1431 | /* Check if the register is implemented and 1394a compliant. */ | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1432 | error = hpsb_read(ne->host, ne->nodeid, generation, bc_addr, &bc_remote, | 
|  | 1433 | sizeof(bc_remote)); | 
|  | 1434 | if (!error && bc_remote & cpu_to_be32(0x80000000) && | 
| Stefan Richter | 61c7f77 | 2005-12-05 16:28:59 -0500 | [diff] [blame] | 1435 | bc_remote != bc_local) | 
|  | 1436 | hpsb_node_write(ne, bc_addr, &bc_local, sizeof(bc_local)); | 
|  | 1437 | } | 
|  | 1438 |  | 
|  | 1439 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1440 | static void nodemgr_probe_ne(struct hpsb_host *host, struct node_entry *ne, | 
|  | 1441 | int generation) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | { | 
|  | 1443 | struct device *dev; | 
|  | 1444 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1445 | if (ne->host != host || ne->in_limbo) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | return; | 
|  | 1447 |  | 
|  | 1448 | dev = get_device(&ne->device); | 
|  | 1449 | if (!dev) | 
|  | 1450 | return; | 
|  | 1451 |  | 
| Stefan Richter | 61c7f77 | 2005-12-05 16:28:59 -0500 | [diff] [blame] | 1452 | nodemgr_irm_write_bc(ne, generation); | 
|  | 1453 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | /* If "needs_probe", then this is either a new or changed node we | 
|  | 1455 | * rescan totally. If the generation matches for an existing node | 
|  | 1456 | * (one that existed prior to the bus reset) we send update calls | 
|  | 1457 | * down to the drivers. Otherwise, this is a dead node and we | 
|  | 1458 | * suspend it. */ | 
|  | 1459 | if (ne->needs_probe) | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1460 | nodemgr_process_root_directory(ne); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | else if (ne->generation == generation) | 
|  | 1462 | nodemgr_update_pdrv(ne); | 
|  | 1463 | else | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1464 | nodemgr_pause_ne(ne); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 |  | 
|  | 1466 | put_device(dev); | 
|  | 1467 | } | 
|  | 1468 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1469 | struct node_probe_parameter { | 
|  | 1470 | struct hpsb_host *host; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1471 | int generation; | 
| Stefan Richter | 6848408 | 2008-08-16 13:36:47 +0200 | [diff] [blame] | 1472 | bool probe_now; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1473 | }; | 
|  | 1474 |  | 
| Stefan Richter | 6848408 | 2008-08-16 13:36:47 +0200 | [diff] [blame] | 1475 | static int node_probe(struct device *dev, void *data) | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1476 | { | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1477 | struct node_probe_parameter *p = data; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1478 | struct node_entry *ne; | 
|  | 1479 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1480 | if (p->generation != get_hpsb_generation(p->host)) | 
| Stefan Richter | c921a97 | 2008-08-16 13:38:11 +0200 | [diff] [blame] | 1481 | return -EAGAIN; | 
|  | 1482 |  | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1483 | ne = container_of(dev, struct node_entry, node_dev); | 
| Stefan Richter | 6848408 | 2008-08-16 13:36:47 +0200 | [diff] [blame] | 1484 | if (ne->needs_probe == p->probe_now) | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1485 | nodemgr_probe_ne(p->host, ne, p->generation); | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1486 | return 0; | 
|  | 1487 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 |  | 
| Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 1489 | static int nodemgr_node_probe(struct hpsb_host *host, int generation) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | { | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1491 | struct node_probe_parameter p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1493 | p.host = host; | 
| Stefan Richter | 6848408 | 2008-08-16 13:36:47 +0200 | [diff] [blame] | 1494 | p.generation = generation; | 
| Stefan Richter | c921a97 | 2008-08-16 13:38:11 +0200 | [diff] [blame] | 1495 | /* | 
|  | 1496 | * Do some processing of the nodes we've probed. This pulls them | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | * into the sysfs layer if needed, and can result in processing of | 
|  | 1498 | * unit-directories, or just updating the node and it's | 
| Stefan Richter | 51c1d80 | 2005-12-12 23:03:19 -0500 | [diff] [blame] | 1499 | * unit-directories. | 
|  | 1500 | * | 
|  | 1501 | * Run updates before probes. Usually, updates are time-critical | 
| Stefan Richter | c921a97 | 2008-08-16 13:38:11 +0200 | [diff] [blame] | 1502 | * while probes are time-consuming. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | * | 
| Stefan Richter | c921a97 | 2008-08-16 13:38:11 +0200 | [diff] [blame] | 1504 | * Meanwhile, another bus reset may have happened. In this case we | 
|  | 1505 | * skip everything here and let the next bus scan handle it. | 
|  | 1506 | * Otherwise we may prematurely remove nodes which are still there. | 
|  | 1507 | */ | 
|  | 1508 | p.probe_now = false; | 
|  | 1509 | if (class_for_each_device(&nodemgr_ne_class, NULL, &p, node_probe) != 0) | 
| Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 1510 | return 0; | 
| Stefan Richter | c921a97 | 2008-08-16 13:38:11 +0200 | [diff] [blame] | 1511 |  | 
|  | 1512 | p.probe_now = true; | 
|  | 1513 | if (class_for_each_device(&nodemgr_ne_class, NULL, &p, node_probe) != 0) | 
| Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 1514 | return 0; | 
| Stefan Richter | c921a97 | 2008-08-16 13:38:11 +0200 | [diff] [blame] | 1515 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | * Now let's tell the bus to rescan our devices. This may seem | 
|  | 1517 | * like overhead, but the driver-model core will only scan a | 
|  | 1518 | * device for a driver when either the device is added, or when a | 
|  | 1519 | * new driver is added. A bus reset is a good reason to rescan | 
|  | 1520 | * devices that were there before.  For example, an sbp2 device | 
|  | 1521 | * may become available for login, if the host that held it was | 
| Stefan Richter | c921a97 | 2008-08-16 13:38:11 +0200 | [diff] [blame] | 1522 | * just removed. | 
|  | 1523 | */ | 
|  | 1524 | if (bus_rescan_devices(&ieee1394_bus_type) != 0) | 
|  | 1525 | HPSB_DEBUG("bus_rescan_devices had an error"); | 
| Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 1526 |  | 
|  | 1527 | return 1; | 
|  | 1528 | } | 
|  | 1529 |  | 
|  | 1530 | static int remove_nodes_in_limbo(struct device *dev, void *data) | 
|  | 1531 | { | 
|  | 1532 | struct node_entry *ne; | 
|  | 1533 |  | 
|  | 1534 | if (dev->bus != &ieee1394_bus_type) | 
|  | 1535 | return 0; | 
|  | 1536 |  | 
|  | 1537 | ne = container_of(dev, struct node_entry, device); | 
|  | 1538 | if (ne->in_limbo) | 
|  | 1539 | nodemgr_remove_ne(ne); | 
|  | 1540 |  | 
|  | 1541 | return 0; | 
|  | 1542 | } | 
|  | 1543 |  | 
|  | 1544 | static void nodemgr_remove_nodes_in_limbo(struct hpsb_host *host) | 
|  | 1545 | { | 
|  | 1546 | device_for_each_child(&host->device, NULL, remove_nodes_in_limbo); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | } | 
|  | 1548 |  | 
| Stefan Richter | 14c0fa2 | 2005-12-01 18:51:52 -0500 | [diff] [blame] | 1549 | static int nodemgr_send_resume_packet(struct hpsb_host *host) | 
|  | 1550 | { | 
|  | 1551 | struct hpsb_packet *packet; | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1552 | int error = -ENOMEM; | 
| Stefan Richter | 14c0fa2 | 2005-12-01 18:51:52 -0500 | [diff] [blame] | 1553 |  | 
|  | 1554 | packet = hpsb_make_phypacket(host, | 
| Stefan Richter | d775846 | 2005-12-01 18:51:56 -0500 | [diff] [blame] | 1555 | EXTPHYPACKET_TYPE_RESUME | | 
|  | 1556 | NODEID_TO_NODE(host->node_id) << PHYPACKET_PORT_SHIFT); | 
| Stefan Richter | 14c0fa2 | 2005-12-01 18:51:52 -0500 | [diff] [blame] | 1557 | if (packet) { | 
|  | 1558 | packet->no_waiter = 1; | 
|  | 1559 | packet->generation = get_hpsb_generation(host); | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1560 | error = hpsb_send_packet(packet); | 
| Stefan Richter | 14c0fa2 | 2005-12-01 18:51:52 -0500 | [diff] [blame] | 1561 | } | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1562 | if (error) | 
| Stefan Richter | 14c0fa2 | 2005-12-01 18:51:52 -0500 | [diff] [blame] | 1563 | HPSB_WARN("fw-host%d: Failed to broadcast resume packet", | 
|  | 1564 | host->id); | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1565 | return error; | 
| Stefan Richter | 14c0fa2 | 2005-12-01 18:51:52 -0500 | [diff] [blame] | 1566 | } | 
|  | 1567 |  | 
| Stefan Richter | 61c7f77 | 2005-12-05 16:28:59 -0500 | [diff] [blame] | 1568 | /* Perform a few high-level IRM responsibilities. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | static int nodemgr_do_irm_duties(struct hpsb_host *host, int cycles) | 
|  | 1570 | { | 
|  | 1571 | quadlet_t bc; | 
|  | 1572 |  | 
|  | 1573 | /* if irm_id == -1 then there is no IRM on this bus */ | 
|  | 1574 | if (!host->is_irm || host->irm_id == (nodeid_t)-1) | 
|  | 1575 | return 1; | 
|  | 1576 |  | 
| Stefan Richter | 61c7f77 | 2005-12-05 16:28:59 -0500 | [diff] [blame] | 1577 | /* We are a 1394a-2000 compliant IRM. Set the validity bit. */ | 
|  | 1578 | host->csr.broadcast_channel |= 0x40000000; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 |  | 
|  | 1580 | /* If there is no bus manager then we should set the root node's | 
|  | 1581 | * force_root bit to promote bus stability per the 1394 | 
|  | 1582 | * spec. (8.4.2.6) */ | 
|  | 1583 | if (host->busmgr_id == 0xffff && host->node_count > 1) | 
|  | 1584 | { | 
|  | 1585 | u16 root_node = host->node_count - 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 |  | 
| Jody McIntyre | 328699b | 2005-09-30 11:59:08 -0700 | [diff] [blame] | 1587 | /* get cycle master capability flag from root node */ | 
|  | 1588 | if (host->is_cycmst || | 
|  | 1589 | (!hpsb_read(host, LOCAL_BUS | root_node, get_hpsb_generation(host), | 
|  | 1590 | (CSR_REGISTER_BASE + CSR_CONFIG_ROM + 2 * sizeof(quadlet_t)), | 
|  | 1591 | &bc, sizeof(quadlet_t)) && | 
|  | 1592 | be32_to_cpu(bc) & 1 << CSR_CMC_SHIFT)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | hpsb_send_phy_config(host, root_node, -1); | 
|  | 1594 | else { | 
|  | 1595 | HPSB_DEBUG("The root node is not cycle master capable; " | 
|  | 1596 | "selecting a new root node and resetting..."); | 
|  | 1597 |  | 
|  | 1598 | if (cycles >= 5) { | 
|  | 1599 | /* Oh screw it! Just leave the bus as it is */ | 
|  | 1600 | HPSB_DEBUG("Stopping reset loop for IRM sanity"); | 
|  | 1601 | return 1; | 
|  | 1602 | } | 
|  | 1603 |  | 
|  | 1604 | hpsb_send_phy_config(host, NODEID_TO_NODE(host->node_id), -1); | 
|  | 1605 | hpsb_reset_bus(host, LONG_RESET_FORCE_ROOT); | 
|  | 1606 |  | 
|  | 1607 | return 0; | 
|  | 1608 | } | 
|  | 1609 | } | 
|  | 1610 |  | 
| Stefan Richter | 14c0fa2 | 2005-12-01 18:51:52 -0500 | [diff] [blame] | 1611 | /* Some devices suspend their ports while being connected to an inactive | 
|  | 1612 | * host adapter, i.e. if connected before the low-level driver is | 
|  | 1613 | * loaded.  They become visible either when physically unplugged and | 
|  | 1614 | * replugged, or when receiving a resume packet.  Send one once. */ | 
|  | 1615 | if (!host->resume_packet_sent && !nodemgr_send_resume_packet(host)) | 
|  | 1616 | host->resume_packet_sent = 1; | 
|  | 1617 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | return 1; | 
|  | 1619 | } | 
|  | 1620 |  | 
|  | 1621 | /* We need to ensure that if we are not the IRM, that the IRM node is capable of | 
|  | 1622 | * everything we can do, otherwise issue a bus reset and try to become the IRM | 
|  | 1623 | * ourselves. */ | 
|  | 1624 | static int nodemgr_check_irm_capability(struct hpsb_host *host, int cycles) | 
|  | 1625 | { | 
|  | 1626 | quadlet_t bc; | 
|  | 1627 | int status; | 
|  | 1628 |  | 
|  | 1629 | if (hpsb_disable_irm || host->is_irm) | 
|  | 1630 | return 1; | 
|  | 1631 |  | 
|  | 1632 | status = hpsb_read(host, LOCAL_BUS | (host->irm_id), | 
|  | 1633 | get_hpsb_generation(host), | 
|  | 1634 | (CSR_REGISTER_BASE | CSR_BROADCAST_CHANNEL), | 
|  | 1635 | &bc, sizeof(quadlet_t)); | 
|  | 1636 |  | 
|  | 1637 | if (status < 0 || !(be32_to_cpu(bc) & 0x80000000)) { | 
|  | 1638 | /* The current irm node does not have a valid BROADCAST_CHANNEL | 
|  | 1639 | * register and we do, so reset the bus with force_root set */ | 
|  | 1640 | HPSB_DEBUG("Current remote IRM is not 1394a-2000 compliant, resetting..."); | 
|  | 1641 |  | 
|  | 1642 | if (cycles >= 5) { | 
|  | 1643 | /* Oh screw it! Just leave the bus as it is */ | 
|  | 1644 | HPSB_DEBUG("Stopping reset loop for IRM sanity"); | 
|  | 1645 | return 1; | 
|  | 1646 | } | 
|  | 1647 |  | 
|  | 1648 | hpsb_send_phy_config(host, NODEID_TO_NODE(host->node_id), -1); | 
|  | 1649 | hpsb_reset_bus(host, LONG_RESET_FORCE_ROOT); | 
|  | 1650 |  | 
|  | 1651 | return 0; | 
|  | 1652 | } | 
|  | 1653 |  | 
|  | 1654 | return 1; | 
|  | 1655 | } | 
|  | 1656 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1657 | static int nodemgr_host_thread(void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | { | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1659 | struct hpsb_host *host = data; | 
| Stefan Richter | b7a7179 | 2006-10-06 19:49:52 +0200 | [diff] [blame] | 1660 | unsigned int g, generation = 0; | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1661 | int i, reset_cycles = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 |  | 
| Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 1663 | set_freezable(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | /* Setup our device-model entries */ | 
|  | 1665 | nodemgr_create_host_dev_files(host); | 
|  | 1666 |  | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1667 | for (;;) { | 
|  | 1668 | /* Sleep until next bus reset */ | 
|  | 1669 | set_current_state(TASK_INTERRUPTIBLE); | 
| Stefan Richter | a65421e | 2007-02-10 22:06:18 +0100 | [diff] [blame] | 1670 | if (get_hpsb_generation(host) == generation && | 
|  | 1671 | !kthread_should_stop()) | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1672 | schedule(); | 
|  | 1673 | __set_current_state(TASK_RUNNING); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 |  | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1675 | /* Thread may have been woken up to freeze or to exit */ | 
|  | 1676 | if (try_to_freeze()) | 
|  | 1677 | continue; | 
|  | 1678 | if (kthread_should_stop()) | 
|  | 1679 | goto exit; | 
|  | 1680 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | /* Pause for 1/4 second in 1/16 second intervals, | 
|  | 1682 | * to make sure things settle down. */ | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1683 | g = get_hpsb_generation(host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | for (i = 0; i < 4 ; i++) { | 
| Satyam Sharma | 69e2b60 | 2007-08-15 20:05:38 +0530 | [diff] [blame] | 1685 | msleep_interruptible(63); | 
| Nigel Cunningham | ec9a13c | 2008-12-09 22:40:20 +1100 | [diff] [blame] | 1686 | try_to_freeze(); | 
| Satyam Sharma | 69e2b60 | 2007-08-15 20:05:38 +0530 | [diff] [blame] | 1687 | if (kthread_should_stop()) | 
| Stefan Richter | a0e857e | 2007-06-17 23:47:45 +0200 | [diff] [blame] | 1688 | goto exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 |  | 
|  | 1690 | /* Now get the generation in which the node ID's we collect | 
|  | 1691 | * are valid.  During the bus scan we will use this generation | 
|  | 1692 | * for the read transactions, so that if another reset occurs | 
|  | 1693 | * during the scan the transactions will fail instead of | 
|  | 1694 | * returning bogus data. */ | 
|  | 1695 | generation = get_hpsb_generation(host); | 
|  | 1696 |  | 
|  | 1697 | /* If we get a reset before we are done waiting, then | 
| Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 1698 | * start the waiting over again */ | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1699 | if (generation != g) | 
|  | 1700 | g = generation, i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | } | 
|  | 1702 |  | 
| Jody McIntyre | 328699b | 2005-09-30 11:59:08 -0700 | [diff] [blame] | 1703 | if (!nodemgr_check_irm_capability(host, reset_cycles) || | 
|  | 1704 | !nodemgr_do_irm_duties(host, reset_cycles)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | reset_cycles++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | continue; | 
|  | 1707 | } | 
| Jody McIntyre | 328699b | 2005-09-30 11:59:08 -0700 | [diff] [blame] | 1708 | reset_cycles = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 |  | 
|  | 1710 | /* Scan our nodes to get the bus options and create node | 
|  | 1711 | * entries. This does not do the sysfs stuff, since that | 
| Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 1712 | * would trigger uevents and such, which is a bad idea at | 
|  | 1713 | * this point. */ | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1714 | nodemgr_node_scan(host, generation); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 |  | 
|  | 1716 | /* This actually does the full probe, with sysfs | 
|  | 1717 | * registration. */ | 
| Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 1718 | if (!nodemgr_node_probe(host, generation)) | 
|  | 1719 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 |  | 
|  | 1721 | /* Update some of our sysfs symlinks */ | 
|  | 1722 | nodemgr_update_host_dev_links(host); | 
| Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 1723 |  | 
|  | 1724 | /* Sleep 3 seconds */ | 
|  | 1725 | for (i = 3000/200; i; i--) { | 
|  | 1726 | msleep_interruptible(200); | 
| Nigel Cunningham | ec9a13c | 2008-12-09 22:40:20 +1100 | [diff] [blame] | 1727 | try_to_freeze(); | 
| Stefan Richter | fc392fe | 2008-08-19 21:30:17 +0200 | [diff] [blame] | 1728 | if (kthread_should_stop()) | 
|  | 1729 | goto exit; | 
|  | 1730 |  | 
|  | 1731 | if (generation != get_hpsb_generation(host)) | 
|  | 1732 | break; | 
|  | 1733 | } | 
|  | 1734 | /* Remove nodes which are gone, unless a bus reset happened */ | 
|  | 1735 | if (!i) | 
|  | 1736 | nodemgr_remove_nodes_in_limbo(host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | } | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1738 | exit: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | HPSB_VERBOSE("NodeMgr: Exiting thread"); | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1740 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | } | 
|  | 1742 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1743 | struct per_host_parameter { | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1744 | void *data; | 
|  | 1745 | int (*cb)(struct hpsb_host *, void *); | 
|  | 1746 | }; | 
|  | 1747 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1748 | static int per_host(struct device *dev, void *data) | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1749 | { | 
|  | 1750 | struct hpsb_host *host; | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1751 | struct per_host_parameter *p = data; | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1752 |  | 
|  | 1753 | host = container_of(dev, struct hpsb_host, host_dev); | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1754 | return p->cb(host, p->data); | 
| Dave Young | 73cf602 | 2008-01-22 13:56:32 +0800 | [diff] [blame] | 1755 | } | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1756 |  | 
| Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 1757 | /** | 
|  | 1758 | * nodemgr_for_each_host - call a function for each IEEE 1394 host | 
|  | 1759 | * @data: an address to supply to the callback | 
|  | 1760 | * @cb: function to call for each host | 
|  | 1761 | * | 
|  | 1762 | * Iterate the hosts, calling a given function with supplied data for each host. | 
|  | 1763 | * If the callback fails on a host, i.e. if it returns a non-zero value, the | 
|  | 1764 | * iteration is stopped. | 
|  | 1765 | * | 
|  | 1766 | * Return value: 0 on success, non-zero on failure (same as returned by last run | 
|  | 1767 | * of the callback). | 
|  | 1768 | */ | 
|  | 1769 | int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | { | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1771 | struct per_host_parameter p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 |  | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1773 | p.cb = cb; | 
|  | 1774 | p.data = data; | 
|  | 1775 | return class_for_each_device(&hpsb_host_class, NULL, &p, per_host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | } | 
|  | 1777 |  | 
| Stefan Richter | ef81533 | 2007-03-05 03:05:32 +0100 | [diff] [blame] | 1778 | /* The following two convenience functions use a struct node_entry | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | * for addressing a node on the bus.  They are intended for use by any | 
|  | 1780 | * process context, not just the nodemgr thread, so we need to be a | 
|  | 1781 | * little careful when reading out the node ID and generation.  The | 
|  | 1782 | * thing that can go wrong is that we get the node ID, then a bus | 
|  | 1783 | * reset occurs, and then we read the generation.  The node ID is | 
|  | 1784 | * possibly invalid, but the generation is current, and we end up | 
|  | 1785 | * sending a packet to a the wrong node. | 
|  | 1786 | * | 
|  | 1787 | * The solution is to make sure we read the generation first, so that | 
|  | 1788 | * if a reset occurs in the process, we end up with a stale generation | 
|  | 1789 | * and the transactions will fail instead of silently using wrong node | 
|  | 1790 | * ID's. | 
|  | 1791 | */ | 
|  | 1792 |  | 
| Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 1793 | /** | 
|  | 1794 | * hpsb_node_fill_packet - fill some destination information into a packet | 
|  | 1795 | * @ne: destination node | 
|  | 1796 | * @packet: packet to fill in | 
|  | 1797 | * | 
|  | 1798 | * This will fill in the given, pre-initialised hpsb_packet with the current | 
|  | 1799 | * information from the node entry (host, node ID, bus generation number). | 
|  | 1800 | */ | 
|  | 1801 | void hpsb_node_fill_packet(struct node_entry *ne, struct hpsb_packet *packet) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | { | 
| Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 1803 | packet->host = ne->host; | 
|  | 1804 | packet->generation = ne->generation; | 
| Stefan Richter | 29f8ea8 | 2008-08-27 01:18:32 +0200 | [diff] [blame] | 1805 | smp_rmb(); | 
| Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 1806 | packet->node_id = ne->nodeid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | } | 
|  | 1808 |  | 
|  | 1809 | int hpsb_node_write(struct node_entry *ne, u64 addr, | 
|  | 1810 | quadlet_t *buffer, size_t length) | 
|  | 1811 | { | 
|  | 1812 | unsigned int generation = ne->generation; | 
|  | 1813 |  | 
| Stefan Richter | 29f8ea8 | 2008-08-27 01:18:32 +0200 | [diff] [blame] | 1814 | smp_rmb(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | return hpsb_write(ne->host, ne->nodeid, generation, | 
|  | 1816 | addr, buffer, length); | 
|  | 1817 | } | 
|  | 1818 |  | 
|  | 1819 | static void nodemgr_add_host(struct hpsb_host *host) | 
|  | 1820 | { | 
|  | 1821 | struct host_info *hi; | 
|  | 1822 |  | 
|  | 1823 | hi = hpsb_create_hostinfo(&nodemgr_highlevel, host, sizeof(*hi)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | if (!hi) { | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1825 | HPSB_ERR("NodeMgr: out of memory in add host"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | return; | 
|  | 1827 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | hi->host = host; | 
| Stefan Richter | 11305c3 | 2008-08-19 21:29:23 +0200 | [diff] [blame] | 1829 | hi->thread = kthread_run(nodemgr_host_thread, host, "knodemgrd_%d", | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1830 | host->id); | 
|  | 1831 | if (IS_ERR(hi->thread)) { | 
|  | 1832 | HPSB_ERR("NodeMgr: cannot start thread for host %d", host->id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | hpsb_destroy_hostinfo(&nodemgr_highlevel, host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | } | 
|  | 1836 |  | 
|  | 1837 | static void nodemgr_host_reset(struct hpsb_host *host) | 
|  | 1838 | { | 
|  | 1839 | struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host); | 
|  | 1840 |  | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1841 | if (hi) { | 
|  | 1842 | HPSB_VERBOSE("NodeMgr: Processing reset for host %d", host->id); | 
|  | 1843 | wake_up_process(hi->thread); | 
|  | 1844 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | } | 
|  | 1846 |  | 
|  | 1847 | static void nodemgr_remove_host(struct hpsb_host *host) | 
|  | 1848 | { | 
|  | 1849 | struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host); | 
|  | 1850 |  | 
|  | 1851 | if (hi) { | 
| Stefan Richter | d2f119f | 2006-07-03 12:02:35 -0400 | [diff] [blame] | 1852 | kthread_stop(hi->thread); | 
|  | 1853 | nodemgr_remove_host_dev(&host->device); | 
|  | 1854 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | } | 
|  | 1856 |  | 
|  | 1857 | static struct hpsb_highlevel nodemgr_highlevel = { | 
|  | 1858 | .name =		"Node manager", | 
|  | 1859 | .add_host =	nodemgr_add_host, | 
|  | 1860 | .host_reset =	nodemgr_host_reset, | 
|  | 1861 | .remove_host =	nodemgr_remove_host, | 
|  | 1862 | }; | 
|  | 1863 |  | 
|  | 1864 | int init_ieee1394_nodemgr(void) | 
|  | 1865 | { | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1866 | int error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 |  | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1868 | error = class_register(&nodemgr_ne_class); | 
|  | 1869 | if (error) | 
| Stefan Richter | 91efa46 | 2007-02-06 02:34:45 +0100 | [diff] [blame] | 1870 | goto fail_ne; | 
| Stefan Richter | 7fdfc90 | 2006-10-21 01:23:56 +0200 | [diff] [blame] | 1871 | error = class_register(&nodemgr_ud_class); | 
| Stefan Richter | 91efa46 | 2007-02-06 02:34:45 +0100 | [diff] [blame] | 1872 | if (error) | 
|  | 1873 | goto fail_ud; | 
| Stefan Richter | 8252bbb | 2006-11-22 21:09:42 +0100 | [diff] [blame] | 1874 | error = driver_register(&nodemgr_mid_layer_driver); | 
| Stefan Richter | 91efa46 | 2007-02-06 02:34:45 +0100 | [diff] [blame] | 1875 | if (error) | 
|  | 1876 | goto fail_ml; | 
|  | 1877 | /* This driver is not used if nodemgr is off (disable_nodemgr=1). */ | 
|  | 1878 | nodemgr_dev_template_host.driver = &nodemgr_mid_layer_driver; | 
|  | 1879 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | hpsb_register_highlevel(&nodemgr_highlevel); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | return 0; | 
| Stefan Richter | 91efa46 | 2007-02-06 02:34:45 +0100 | [diff] [blame] | 1882 |  | 
|  | 1883 | fail_ml: | 
|  | 1884 | class_unregister(&nodemgr_ud_class); | 
|  | 1885 | fail_ud: | 
|  | 1886 | class_unregister(&nodemgr_ne_class); | 
|  | 1887 | fail_ne: | 
|  | 1888 | return error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | } | 
|  | 1890 |  | 
|  | 1891 | void cleanup_ieee1394_nodemgr(void) | 
|  | 1892 | { | 
| Stefan Richter | d41bba2 | 2006-11-22 21:28:19 +0100 | [diff] [blame] | 1893 | hpsb_unregister_highlevel(&nodemgr_highlevel); | 
| Stefan Richter | 91efa46 | 2007-02-06 02:34:45 +0100 | [diff] [blame] | 1894 | driver_unregister(&nodemgr_mid_layer_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | class_unregister(&nodemgr_ud_class); | 
|  | 1896 | class_unregister(&nodemgr_ne_class); | 
|  | 1897 | } |