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