nodemgr.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798
  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. #include <linux/kernel.h>
  11. #include <linux/config.h>
  12. #include <linux/list.h>
  13. #include <linux/slab.h>
  14. #include <linux/smp_lock.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kmod.h>
  17. #include <linux/completion.h>
  18. #include <linux/delay.h>
  19. #include <linux/pci.h>
  20. #include <linux/moduleparam.h>
  21. #include <asm/atomic.h>
  22. #include "ieee1394_types.h"
  23. #include "ieee1394.h"
  24. #include "ieee1394_core.h"
  25. #include "hosts.h"
  26. #include "ieee1394_transactions.h"
  27. #include "highlevel.h"
  28. #include "csr.h"
  29. #include "nodemgr.h"
  30. static int ignore_drivers;
  31. module_param(ignore_drivers, int, 0444);
  32. MODULE_PARM_DESC(ignore_drivers, "Disable automatic probing for drivers.");
  33. struct nodemgr_csr_info {
  34. struct hpsb_host *host;
  35. nodeid_t nodeid;
  36. unsigned int generation;
  37. };
  38. static char *nodemgr_find_oui_name(int oui)
  39. {
  40. #ifdef CONFIG_IEEE1394_OUI_DB
  41. extern struct oui_list_struct {
  42. int oui;
  43. char *name;
  44. } oui_list[];
  45. int i;
  46. for (i = 0; oui_list[i].name; i++)
  47. if (oui_list[i].oui == oui)
  48. return oui_list[i].name;
  49. #endif
  50. return NULL;
  51. }
  52. static int nodemgr_bus_read(struct csr1212_csr *csr, u64 addr, u16 length,
  53. void *buffer, void *__ci)
  54. {
  55. struct nodemgr_csr_info *ci = (struct nodemgr_csr_info*)__ci;
  56. int i, ret = 0;
  57. for (i = 1; ; i++) {
  58. ret = hpsb_read(ci->host, ci->nodeid, ci->generation, addr,
  59. buffer, length);
  60. if (!ret || i == 3)
  61. break;
  62. if (msleep_interruptible(334))
  63. return -EINTR;
  64. }
  65. return ret;
  66. }
  67. static int nodemgr_get_max_rom(quadlet_t *bus_info_data, void *__ci)
  68. {
  69. return (CSR1212_BE32_TO_CPU(bus_info_data[2]) >> 8) & 0x3;
  70. }
  71. static struct csr1212_bus_ops nodemgr_csr_ops = {
  72. .bus_read = nodemgr_bus_read,
  73. .get_max_rom = nodemgr_get_max_rom
  74. };
  75. /*
  76. * Basically what we do here is start off retrieving the bus_info block.
  77. * From there will fill in some info about the node, verify it is of IEEE
  78. * 1394 type, and that the crc checks out ok. After that we start off with
  79. * the root directory, and subdirectories. To do this, we retrieve the
  80. * quadlet header for a directory, find out the length, and retrieve the
  81. * complete directory entry (be it a leaf or a directory). We then process
  82. * it and add the info to our structure for that particular node.
  83. *
  84. * We verify CRC's along the way for each directory/block/leaf. The entire
  85. * node structure is generic, and simply stores the information in a way
  86. * that's easy to parse by the protocol interface.
  87. */
  88. /*
  89. * The nodemgr relies heavily on the Driver Model for device callbacks and
  90. * driver/device mappings. The old nodemgr used to handle all this itself,
  91. * but now we are much simpler because of the LDM.
  92. */
  93. static DECLARE_MUTEX(nodemgr_serialize);
  94. struct host_info {
  95. struct hpsb_host *host;
  96. struct list_head list;
  97. struct completion exited;
  98. struct semaphore reset_sem;
  99. int pid;
  100. char daemon_name[15];
  101. int kill_me;
  102. };
  103. static int nodemgr_bus_match(struct device * dev, struct device_driver * drv);
  104. static int nodemgr_uevent(struct class_device *cdev, char **envp, int num_envp,
  105. char *buffer, int buffer_size);
  106. static void nodemgr_resume_ne(struct node_entry *ne);
  107. static void nodemgr_remove_ne(struct node_entry *ne);
  108. static struct node_entry *find_entry_by_guid(u64 guid);
  109. struct bus_type ieee1394_bus_type = {
  110. .name = "ieee1394",
  111. .match = nodemgr_bus_match,
  112. };
  113. static void host_cls_release(struct class_device *class_dev)
  114. {
  115. put_device(&container_of((class_dev), struct hpsb_host, class_dev)->device);
  116. }
  117. struct class hpsb_host_class = {
  118. .name = "ieee1394_host",
  119. .release = host_cls_release,
  120. };
  121. static void ne_cls_release(struct class_device *class_dev)
  122. {
  123. put_device(&container_of((class_dev), struct node_entry, class_dev)->device);
  124. }
  125. static struct class nodemgr_ne_class = {
  126. .name = "ieee1394_node",
  127. .release = ne_cls_release,
  128. };
  129. static void ud_cls_release(struct class_device *class_dev)
  130. {
  131. put_device(&container_of((class_dev), struct unit_directory, class_dev)->device);
  132. }
  133. /* The name here is only so that unit directory hotplug works with old
  134. * style hotplug, which only ever did unit directories anyway. */
  135. static struct class nodemgr_ud_class = {
  136. .name = "ieee1394",
  137. .release = ud_cls_release,
  138. .uevent = nodemgr_uevent,
  139. };
  140. static struct hpsb_highlevel nodemgr_highlevel;
  141. static void nodemgr_release_ud(struct device *dev)
  142. {
  143. struct unit_directory *ud = container_of(dev, struct unit_directory, device);
  144. if (ud->vendor_name_kv)
  145. csr1212_release_keyval(ud->vendor_name_kv);
  146. if (ud->model_name_kv)
  147. csr1212_release_keyval(ud->model_name_kv);
  148. kfree(ud);
  149. }
  150. static void nodemgr_release_ne(struct device *dev)
  151. {
  152. struct node_entry *ne = container_of(dev, struct node_entry, device);
  153. if (ne->vendor_name_kv)
  154. csr1212_release_keyval(ne->vendor_name_kv);
  155. kfree(ne);
  156. }
  157. static void nodemgr_release_host(struct device *dev)
  158. {
  159. struct hpsb_host *host = container_of(dev, struct hpsb_host, device);
  160. csr1212_destroy_csr(host->csr.rom);
  161. kfree(host);
  162. }
  163. static int nodemgr_ud_platform_data;
  164. static struct device nodemgr_dev_template_ud = {
  165. .bus = &ieee1394_bus_type,
  166. .release = nodemgr_release_ud,
  167. .platform_data = &nodemgr_ud_platform_data,
  168. };
  169. static struct device nodemgr_dev_template_ne = {
  170. .bus = &ieee1394_bus_type,
  171. .release = nodemgr_release_ne,
  172. };
  173. struct device nodemgr_dev_template_host = {
  174. .bus = &ieee1394_bus_type,
  175. .release = nodemgr_release_host,
  176. };
  177. #define fw_attr(class, class_type, field, type, format_string) \
  178. static ssize_t fw_show_##class##_##field (struct device *dev, struct device_attribute *attr, char *buf)\
  179. { \
  180. class_type *class; \
  181. class = container_of(dev, class_type, device); \
  182. return sprintf(buf, format_string, (type)class->field); \
  183. } \
  184. static struct device_attribute dev_attr_##class##_##field = { \
  185. .attr = {.name = __stringify(field), .mode = S_IRUGO }, \
  186. .show = fw_show_##class##_##field, \
  187. };
  188. #define fw_attr_td(class, class_type, td_kv) \
  189. static ssize_t fw_show_##class##_##td_kv (struct device *dev, struct device_attribute *attr, char *buf)\
  190. { \
  191. int len; \
  192. class_type *class = container_of(dev, class_type, device); \
  193. len = (class->td_kv->value.leaf.len - 2) * sizeof(quadlet_t); \
  194. memcpy(buf, \
  195. CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(class->td_kv), \
  196. len); \
  197. while ((buf + len - 1) == '\0') \
  198. len--; \
  199. buf[len++] = '\n'; \
  200. buf[len] = '\0'; \
  201. return len; \
  202. } \
  203. static struct device_attribute dev_attr_##class##_##td_kv = { \
  204. .attr = {.name = __stringify(td_kv), .mode = S_IRUGO }, \
  205. .show = fw_show_##class##_##td_kv, \
  206. };
  207. #define fw_drv_attr(field, type, format_string) \
  208. static ssize_t fw_drv_show_##field (struct device_driver *drv, char *buf) \
  209. { \
  210. struct hpsb_protocol_driver *driver; \
  211. driver = container_of(drv, struct hpsb_protocol_driver, driver); \
  212. return sprintf(buf, format_string, (type)driver->field);\
  213. } \
  214. static struct driver_attribute driver_attr_drv_##field = { \
  215. .attr = {.name = __stringify(field), .mode = S_IRUGO }, \
  216. .show = fw_drv_show_##field, \
  217. };
  218. static ssize_t fw_show_ne_bus_options(struct device *dev, struct device_attribute *attr, char *buf)
  219. {
  220. struct node_entry *ne = container_of(dev, struct node_entry, device);
  221. return sprintf(buf, "IRMC(%d) CMC(%d) ISC(%d) BMC(%d) PMC(%d) GEN(%d) "
  222. "LSPD(%d) MAX_REC(%d) MAX_ROM(%d) CYC_CLK_ACC(%d)\n",
  223. ne->busopt.irmc,
  224. ne->busopt.cmc, ne->busopt.isc, ne->busopt.bmc,
  225. ne->busopt.pmc, ne->busopt.generation, ne->busopt.lnkspd,
  226. ne->busopt.max_rec,
  227. ne->busopt.max_rom,
  228. ne->busopt.cyc_clk_acc);
  229. }
  230. static DEVICE_ATTR(bus_options,S_IRUGO,fw_show_ne_bus_options,NULL);
  231. static ssize_t fw_show_ne_tlabels_free(struct device *dev, struct device_attribute *attr, char *buf)
  232. {
  233. struct node_entry *ne = container_of(dev, struct node_entry, device);
  234. return sprintf(buf, "%d\n", atomic_read(&ne->tpool->count.count) + 1);
  235. }
  236. static DEVICE_ATTR(tlabels_free,S_IRUGO,fw_show_ne_tlabels_free,NULL);
  237. static ssize_t fw_show_ne_tlabels_allocations(struct device *dev, struct device_attribute *attr, char *buf)
  238. {
  239. struct node_entry *ne = container_of(dev, struct node_entry, device);
  240. return sprintf(buf, "%u\n", ne->tpool->allocations);
  241. }
  242. static DEVICE_ATTR(tlabels_allocations,S_IRUGO,fw_show_ne_tlabels_allocations,NULL);
  243. static ssize_t fw_show_ne_tlabels_mask(struct device *dev, struct device_attribute *attr, char *buf)
  244. {
  245. struct node_entry *ne = container_of(dev, struct node_entry, device);
  246. #if (BITS_PER_LONG <= 32)
  247. return sprintf(buf, "0x%08lx%08lx\n", ne->tpool->pool[0], ne->tpool->pool[1]);
  248. #else
  249. return sprintf(buf, "0x%016lx\n", ne->tpool->pool[0]);
  250. #endif
  251. }
  252. static DEVICE_ATTR(tlabels_mask, S_IRUGO, fw_show_ne_tlabels_mask, NULL);
  253. static ssize_t fw_set_ignore_driver(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  254. {
  255. struct unit_directory *ud = container_of(dev, struct unit_directory, device);
  256. int state = simple_strtoul(buf, NULL, 10);
  257. if (state == 1) {
  258. down_write(&dev->bus->subsys.rwsem);
  259. device_release_driver(dev);
  260. ud->ignore_driver = 1;
  261. up_write(&dev->bus->subsys.rwsem);
  262. } else if (!state)
  263. ud->ignore_driver = 0;
  264. return count;
  265. }
  266. static ssize_t fw_get_ignore_driver(struct device *dev, struct device_attribute *attr, char *buf)
  267. {
  268. struct unit_directory *ud = container_of(dev, struct unit_directory, device);
  269. return sprintf(buf, "%d\n", ud->ignore_driver);
  270. }
  271. static DEVICE_ATTR(ignore_driver, S_IWUSR | S_IRUGO, fw_get_ignore_driver, fw_set_ignore_driver);
  272. static ssize_t fw_set_destroy_node(struct bus_type *bus, const char *buf, size_t count)
  273. {
  274. struct node_entry *ne;
  275. u64 guid = (u64)simple_strtoull(buf, NULL, 16);
  276. ne = find_entry_by_guid(guid);
  277. if (ne == NULL || !ne->in_limbo)
  278. return -EINVAL;
  279. nodemgr_remove_ne(ne);
  280. return count;
  281. }
  282. static ssize_t fw_get_destroy_node(struct bus_type *bus, char *buf)
  283. {
  284. return sprintf(buf, "You can destroy in_limbo nodes by writing their GUID to this file\n");
  285. }
  286. static BUS_ATTR(destroy_node, S_IWUSR | S_IRUGO, fw_get_destroy_node, fw_set_destroy_node);
  287. static int nodemgr_rescan_bus_thread(void *__unused)
  288. {
  289. /* No userlevel access needed */
  290. daemonize("kfwrescan");
  291. bus_rescan_devices(&ieee1394_bus_type);
  292. return 0;
  293. }
  294. static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, size_t count)
  295. {
  296. int state = simple_strtoul(buf, NULL, 10);
  297. /* Don't wait for this, or care about errors. Root could do
  298. * something stupid and spawn this a lot of times, but that's
  299. * root's fault. */
  300. if (state == 1)
  301. kernel_thread(nodemgr_rescan_bus_thread, NULL, CLONE_KERNEL);
  302. return count;
  303. }
  304. static ssize_t fw_get_rescan(struct bus_type *bus, char *buf)
  305. {
  306. return sprintf(buf, "You can force a rescan of the bus for "
  307. "drivers by writing a 1 to this file\n");
  308. }
  309. static BUS_ATTR(rescan, S_IWUSR | S_IRUGO, fw_get_rescan, fw_set_rescan);
  310. static ssize_t fw_set_ignore_drivers(struct bus_type *bus, const char *buf, size_t count)
  311. {
  312. int state = simple_strtoul(buf, NULL, 10);
  313. if (state == 1)
  314. ignore_drivers = 1;
  315. else if (!state)
  316. ignore_drivers = 0;
  317. return count;
  318. }
  319. static ssize_t fw_get_ignore_drivers(struct bus_type *bus, char *buf)
  320. {
  321. return sprintf(buf, "%d\n", ignore_drivers);
  322. }
  323. static BUS_ATTR(ignore_drivers, S_IWUSR | S_IRUGO, fw_get_ignore_drivers, fw_set_ignore_drivers);
  324. struct bus_attribute *const fw_bus_attrs[] = {
  325. &bus_attr_destroy_node,
  326. &bus_attr_rescan,
  327. &bus_attr_ignore_drivers,
  328. NULL
  329. };
  330. fw_attr(ne, struct node_entry, capabilities, unsigned int, "0x%06x\n")
  331. fw_attr(ne, struct node_entry, nodeid, unsigned int, "0x%04x\n")
  332. fw_attr(ne, struct node_entry, vendor_id, unsigned int, "0x%06x\n")
  333. fw_attr_td(ne, struct node_entry, vendor_name_kv)
  334. fw_attr(ne, struct node_entry, vendor_oui, const char *, "%s\n")
  335. fw_attr(ne, struct node_entry, guid, unsigned long long, "0x%016Lx\n")
  336. fw_attr(ne, struct node_entry, guid_vendor_id, unsigned int, "0x%06x\n")
  337. fw_attr(ne, struct node_entry, guid_vendor_oui, const char *, "%s\n")
  338. fw_attr(ne, struct node_entry, in_limbo, int, "%d\n");
  339. static struct device_attribute *const fw_ne_attrs[] = {
  340. &dev_attr_ne_guid,
  341. &dev_attr_ne_guid_vendor_id,
  342. &dev_attr_ne_capabilities,
  343. &dev_attr_ne_vendor_id,
  344. &dev_attr_ne_nodeid,
  345. &dev_attr_bus_options,
  346. &dev_attr_tlabels_free,
  347. &dev_attr_tlabels_allocations,
  348. &dev_attr_tlabels_mask,
  349. };
  350. fw_attr(ud, struct unit_directory, address, unsigned long long, "0x%016Lx\n")
  351. fw_attr(ud, struct unit_directory, length, int, "%d\n")
  352. /* These are all dependent on the value being provided */
  353. fw_attr(ud, struct unit_directory, vendor_id, unsigned int, "0x%06x\n")
  354. fw_attr(ud, struct unit_directory, model_id, unsigned int, "0x%06x\n")
  355. fw_attr(ud, struct unit_directory, specifier_id, unsigned int, "0x%06x\n")
  356. fw_attr(ud, struct unit_directory, version, unsigned int, "0x%06x\n")
  357. fw_attr_td(ud, struct unit_directory, vendor_name_kv)
  358. fw_attr(ud, struct unit_directory, vendor_oui, const char *, "%s\n")
  359. fw_attr_td(ud, struct unit_directory, model_name_kv)
  360. static struct device_attribute *const fw_ud_attrs[] = {
  361. &dev_attr_ud_address,
  362. &dev_attr_ud_length,
  363. &dev_attr_ignore_driver,
  364. };
  365. fw_attr(host, struct hpsb_host, node_count, int, "%d\n")
  366. fw_attr(host, struct hpsb_host, selfid_count, int, "%d\n")
  367. fw_attr(host, struct hpsb_host, nodes_active, int, "%d\n")
  368. fw_attr(host, struct hpsb_host, in_bus_reset, int, "%d\n")
  369. fw_attr(host, struct hpsb_host, is_root, int, "%d\n")
  370. fw_attr(host, struct hpsb_host, is_cycmst, int, "%d\n")
  371. fw_attr(host, struct hpsb_host, is_irm, int, "%d\n")
  372. fw_attr(host, struct hpsb_host, is_busmgr, int, "%d\n")
  373. static struct device_attribute *const fw_host_attrs[] = {
  374. &dev_attr_host_node_count,
  375. &dev_attr_host_selfid_count,
  376. &dev_attr_host_nodes_active,
  377. &dev_attr_host_in_bus_reset,
  378. &dev_attr_host_is_root,
  379. &dev_attr_host_is_cycmst,
  380. &dev_attr_host_is_irm,
  381. &dev_attr_host_is_busmgr,
  382. };
  383. static ssize_t fw_show_drv_device_ids(struct device_driver *drv, char *buf)
  384. {
  385. struct hpsb_protocol_driver *driver;
  386. struct ieee1394_device_id *id;
  387. int length = 0;
  388. char *scratch = buf;
  389. driver = container_of(drv, struct hpsb_protocol_driver, driver);
  390. for (id = driver->id_table; id->match_flags != 0; id++) {
  391. int need_coma = 0;
  392. if (id->match_flags & IEEE1394_MATCH_VENDOR_ID) {
  393. length += sprintf(scratch, "vendor_id=0x%06x", id->vendor_id);
  394. scratch = buf + length;
  395. need_coma++;
  396. }
  397. if (id->match_flags & IEEE1394_MATCH_MODEL_ID) {
  398. length += sprintf(scratch, "%smodel_id=0x%06x",
  399. need_coma++ ? "," : "",
  400. id->model_id);
  401. scratch = buf + length;
  402. }
  403. if (id->match_flags & IEEE1394_MATCH_SPECIFIER_ID) {
  404. length += sprintf(scratch, "%sspecifier_id=0x%06x",
  405. need_coma++ ? "," : "",
  406. id->specifier_id);
  407. scratch = buf + length;
  408. }
  409. if (id->match_flags & IEEE1394_MATCH_VERSION) {
  410. length += sprintf(scratch, "%sversion=0x%06x",
  411. need_coma++ ? "," : "",
  412. id->version);
  413. scratch = buf + length;
  414. }
  415. if (need_coma) {
  416. *scratch++ = '\n';
  417. length++;
  418. }
  419. }
  420. return length;
  421. }
  422. static DRIVER_ATTR(device_ids,S_IRUGO,fw_show_drv_device_ids,NULL);
  423. fw_drv_attr(name, const char *, "%s\n")
  424. static struct driver_attribute *const fw_drv_attrs[] = {
  425. &driver_attr_drv_name,
  426. &driver_attr_device_ids,
  427. };
  428. static void nodemgr_create_drv_files(struct hpsb_protocol_driver *driver)
  429. {
  430. struct device_driver *drv = &driver->driver;
  431. int i;
  432. for (i = 0; i < ARRAY_SIZE(fw_drv_attrs); i++)
  433. driver_create_file(drv, fw_drv_attrs[i]);
  434. }
  435. static void nodemgr_remove_drv_files(struct hpsb_protocol_driver *driver)
  436. {
  437. struct device_driver *drv = &driver->driver;
  438. int i;
  439. for (i = 0; i < ARRAY_SIZE(fw_drv_attrs); i++)
  440. driver_remove_file(drv, fw_drv_attrs[i]);
  441. }
  442. static void nodemgr_create_ne_dev_files(struct node_entry *ne)
  443. {
  444. struct device *dev = &ne->device;
  445. int i;
  446. for (i = 0; i < ARRAY_SIZE(fw_ne_attrs); i++)
  447. device_create_file(dev, fw_ne_attrs[i]);
  448. }
  449. static void nodemgr_create_host_dev_files(struct hpsb_host *host)
  450. {
  451. struct device *dev = &host->device;
  452. int i;
  453. for (i = 0; i < ARRAY_SIZE(fw_host_attrs); i++)
  454. device_create_file(dev, fw_host_attrs[i]);
  455. }
  456. static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, nodeid_t nodeid);
  457. static void nodemgr_update_host_dev_links(struct hpsb_host *host)
  458. {
  459. struct device *dev = &host->device;
  460. struct node_entry *ne;
  461. sysfs_remove_link(&dev->kobj, "irm_id");
  462. sysfs_remove_link(&dev->kobj, "busmgr_id");
  463. sysfs_remove_link(&dev->kobj, "host_id");
  464. if ((ne = find_entry_by_nodeid(host, host->irm_id)))
  465. sysfs_create_link(&dev->kobj, &ne->device.kobj, "irm_id");
  466. if ((ne = find_entry_by_nodeid(host, host->busmgr_id)))
  467. sysfs_create_link(&dev->kobj, &ne->device.kobj, "busmgr_id");
  468. if ((ne = find_entry_by_nodeid(host, host->node_id)))
  469. sysfs_create_link(&dev->kobj, &ne->device.kobj, "host_id");
  470. }
  471. static void nodemgr_create_ud_dev_files(struct unit_directory *ud)
  472. {
  473. struct device *dev = &ud->device;
  474. int i;
  475. for (i = 0; i < ARRAY_SIZE(fw_ud_attrs); i++)
  476. device_create_file(dev, fw_ud_attrs[i]);
  477. if (ud->flags & UNIT_DIRECTORY_SPECIFIER_ID)
  478. device_create_file(dev, &dev_attr_ud_specifier_id);
  479. if (ud->flags & UNIT_DIRECTORY_VERSION)
  480. device_create_file(dev, &dev_attr_ud_version);
  481. if (ud->flags & UNIT_DIRECTORY_VENDOR_ID) {
  482. device_create_file(dev, &dev_attr_ud_vendor_id);
  483. if (ud->vendor_name_kv)
  484. device_create_file(dev, &dev_attr_ud_vendor_name_kv);
  485. }
  486. if (ud->flags & UNIT_DIRECTORY_MODEL_ID) {
  487. device_create_file(dev, &dev_attr_ud_model_id);
  488. if (ud->model_name_kv)
  489. device_create_file(dev, &dev_attr_ud_model_name_kv);
  490. }
  491. }
  492. static int nodemgr_bus_match(struct device * dev, struct device_driver * drv)
  493. {
  494. struct hpsb_protocol_driver *driver;
  495. struct unit_directory *ud;
  496. struct ieee1394_device_id *id;
  497. /* We only match unit directories */
  498. if (dev->platform_data != &nodemgr_ud_platform_data)
  499. return 0;
  500. ud = container_of(dev, struct unit_directory, device);
  501. driver = container_of(drv, struct hpsb_protocol_driver, driver);
  502. if (ud->ne->in_limbo || ud->ignore_driver)
  503. return 0;
  504. for (id = driver->id_table; id->match_flags != 0; id++) {
  505. if ((id->match_flags & IEEE1394_MATCH_VENDOR_ID) &&
  506. id->vendor_id != ud->vendor_id)
  507. continue;
  508. if ((id->match_flags & IEEE1394_MATCH_MODEL_ID) &&
  509. id->model_id != ud->model_id)
  510. continue;
  511. if ((id->match_flags & IEEE1394_MATCH_SPECIFIER_ID) &&
  512. id->specifier_id != ud->specifier_id)
  513. continue;
  514. if ((id->match_flags & IEEE1394_MATCH_VERSION) &&
  515. id->version != ud->version)
  516. continue;
  517. return 1;
  518. }
  519. return 0;
  520. }
  521. static void nodemgr_remove_uds(struct node_entry *ne)
  522. {
  523. struct class_device *cdev, *next;
  524. struct unit_directory *ud;
  525. list_for_each_entry_safe(cdev, next, &nodemgr_ud_class.children, node) {
  526. ud = container_of(cdev, struct unit_directory, class_dev);
  527. if (ud->ne != ne)
  528. continue;
  529. class_device_unregister(&ud->class_dev);
  530. device_unregister(&ud->device);
  531. }
  532. }
  533. static void nodemgr_remove_ne(struct node_entry *ne)
  534. {
  535. struct device *dev = &ne->device;
  536. dev = get_device(&ne->device);
  537. if (!dev)
  538. return;
  539. HPSB_DEBUG("Node removed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
  540. NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
  541. nodemgr_remove_uds(ne);
  542. class_device_unregister(&ne->class_dev);
  543. device_unregister(dev);
  544. put_device(dev);
  545. }
  546. static int __nodemgr_remove_host_dev(struct device *dev, void *data)
  547. {
  548. nodemgr_remove_ne(container_of(dev, struct node_entry, device));
  549. return 0;
  550. }
  551. static void nodemgr_remove_host_dev(struct device *dev)
  552. {
  553. device_for_each_child(dev, NULL, __nodemgr_remove_host_dev);
  554. sysfs_remove_link(&dev->kobj, "irm_id");
  555. sysfs_remove_link(&dev->kobj, "busmgr_id");
  556. sysfs_remove_link(&dev->kobj, "host_id");
  557. }
  558. static void nodemgr_update_bus_options(struct node_entry *ne)
  559. {
  560. #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
  561. static const u16 mr[] = { 4, 64, 1024, 0};
  562. #endif
  563. quadlet_t busoptions = be32_to_cpu(ne->csr->bus_info_data[2]);
  564. ne->busopt.irmc = (busoptions >> 31) & 1;
  565. ne->busopt.cmc = (busoptions >> 30) & 1;
  566. ne->busopt.isc = (busoptions >> 29) & 1;
  567. ne->busopt.bmc = (busoptions >> 28) & 1;
  568. ne->busopt.pmc = (busoptions >> 27) & 1;
  569. ne->busopt.cyc_clk_acc = (busoptions >> 16) & 0xff;
  570. ne->busopt.max_rec = 1 << (((busoptions >> 12) & 0xf) + 1);
  571. ne->busopt.max_rom = (busoptions >> 8) & 0x3;
  572. ne->busopt.generation = (busoptions >> 4) & 0xf;
  573. ne->busopt.lnkspd = busoptions & 0x7;
  574. HPSB_VERBOSE("NodeMgr: raw=0x%08x irmc=%d cmc=%d isc=%d bmc=%d pmc=%d "
  575. "cyc_clk_acc=%d max_rec=%d max_rom=%d gen=%d lspd=%d",
  576. busoptions, ne->busopt.irmc, ne->busopt.cmc,
  577. ne->busopt.isc, ne->busopt.bmc, ne->busopt.pmc,
  578. ne->busopt.cyc_clk_acc, ne->busopt.max_rec,
  579. mr[ne->busopt.max_rom],
  580. ne->busopt.generation, ne->busopt.lnkspd);
  581. }
  582. static struct node_entry *nodemgr_create_node(octlet_t guid, struct csr1212_csr *csr,
  583. struct host_info *hi, nodeid_t nodeid,
  584. unsigned int generation)
  585. {
  586. struct hpsb_host *host = hi->host;
  587. struct node_entry *ne;
  588. ne = kzalloc(sizeof(*ne), GFP_KERNEL);
  589. if (!ne)
  590. return NULL;
  591. ne->tpool = &host->tpool[nodeid & NODE_MASK];
  592. ne->host = host;
  593. ne->nodeid = nodeid;
  594. ne->generation = generation;
  595. ne->needs_probe = 1;
  596. ne->guid = guid;
  597. ne->guid_vendor_id = (guid >> 40) & 0xffffff;
  598. ne->guid_vendor_oui = nodemgr_find_oui_name(ne->guid_vendor_id);
  599. ne->csr = csr;
  600. memcpy(&ne->device, &nodemgr_dev_template_ne,
  601. sizeof(ne->device));
  602. ne->device.parent = &host->device;
  603. snprintf(ne->device.bus_id, BUS_ID_SIZE, "%016Lx",
  604. (unsigned long long)(ne->guid));
  605. ne->class_dev.dev = &ne->device;
  606. ne->class_dev.class = &nodemgr_ne_class;
  607. snprintf(ne->class_dev.class_id, BUS_ID_SIZE, "%016Lx",
  608. (unsigned long long)(ne->guid));
  609. device_register(&ne->device);
  610. class_device_register(&ne->class_dev);
  611. get_device(&ne->device);
  612. if (ne->guid_vendor_oui)
  613. device_create_file(&ne->device, &dev_attr_ne_guid_vendor_oui);
  614. nodemgr_create_ne_dev_files(ne);
  615. nodemgr_update_bus_options(ne);
  616. HPSB_DEBUG("%s added: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
  617. (host->node_id == nodeid) ? "Host" : "Node",
  618. NODE_BUS_ARGS(host, nodeid), (unsigned long long)guid);
  619. return ne;
  620. }
  621. static struct node_entry *find_entry_by_guid(u64 guid)
  622. {
  623. struct class *class = &nodemgr_ne_class;
  624. struct class_device *cdev;
  625. struct node_entry *ne, *ret_ne = NULL;
  626. down_read(&class->subsys.rwsem);
  627. list_for_each_entry(cdev, &class->children, node) {
  628. ne = container_of(cdev, struct node_entry, class_dev);
  629. if (ne->guid == guid) {
  630. ret_ne = ne;
  631. break;
  632. }
  633. }
  634. up_read(&class->subsys.rwsem);
  635. return ret_ne;
  636. }
  637. static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, nodeid_t nodeid)
  638. {
  639. struct class *class = &nodemgr_ne_class;
  640. struct class_device *cdev;
  641. struct node_entry *ne, *ret_ne = NULL;
  642. down_read(&class->subsys.rwsem);
  643. list_for_each_entry(cdev, &class->children, node) {
  644. ne = container_of(cdev, struct node_entry, class_dev);
  645. if (ne->host == host && ne->nodeid == nodeid) {
  646. ret_ne = ne;
  647. break;
  648. }
  649. }
  650. up_read(&class->subsys.rwsem);
  651. return ret_ne;
  652. }
  653. static void nodemgr_register_device(struct node_entry *ne,
  654. struct unit_directory *ud, struct device *parent)
  655. {
  656. memcpy(&ud->device, &nodemgr_dev_template_ud,
  657. sizeof(ud->device));
  658. ud->device.parent = parent;
  659. snprintf(ud->device.bus_id, BUS_ID_SIZE, "%s-%u",
  660. ne->device.bus_id, ud->id);
  661. ud->class_dev.dev = &ud->device;
  662. ud->class_dev.class = &nodemgr_ud_class;
  663. snprintf(ud->class_dev.class_id, BUS_ID_SIZE, "%s-%u",
  664. ne->device.bus_id, ud->id);
  665. device_register(&ud->device);
  666. class_device_register(&ud->class_dev);
  667. get_device(&ud->device);
  668. if (ud->vendor_oui)
  669. device_create_file(&ud->device, &dev_attr_ud_vendor_oui);
  670. nodemgr_create_ud_dev_files(ud);
  671. }
  672. /* This implementation currently only scans the config rom and its
  673. * immediate unit directories looking for software_id and
  674. * software_version entries, in order to get driver autoloading working. */
  675. static struct unit_directory *nodemgr_process_unit_directory
  676. (struct host_info *hi, struct node_entry *ne, struct csr1212_keyval *ud_kv,
  677. unsigned int *id, struct unit_directory *parent)
  678. {
  679. struct unit_directory *ud;
  680. struct unit_directory *ud_child = NULL;
  681. struct csr1212_dentry *dentry;
  682. struct csr1212_keyval *kv;
  683. u8 last_key_id = 0;
  684. ud = kzalloc(sizeof(*ud), GFP_KERNEL);
  685. if (!ud)
  686. goto unit_directory_error;
  687. ud->ne = ne;
  688. ud->ignore_driver = ignore_drivers;
  689. ud->address = ud_kv->offset + CSR1212_CONFIG_ROM_SPACE_BASE;
  690. ud->ud_kv = ud_kv;
  691. ud->id = (*id)++;
  692. csr1212_for_each_dir_entry(ne->csr, kv, ud_kv, dentry) {
  693. switch (kv->key.id) {
  694. case CSR1212_KV_ID_VENDOR:
  695. if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) {
  696. ud->vendor_id = kv->value.immediate;
  697. ud->flags |= UNIT_DIRECTORY_VENDOR_ID;
  698. if (ud->vendor_id)
  699. ud->vendor_oui = nodemgr_find_oui_name(ud->vendor_id);
  700. }
  701. break;
  702. case CSR1212_KV_ID_MODEL:
  703. ud->model_id = kv->value.immediate;
  704. ud->flags |= UNIT_DIRECTORY_MODEL_ID;
  705. break;
  706. case CSR1212_KV_ID_SPECIFIER_ID:
  707. ud->specifier_id = kv->value.immediate;
  708. ud->flags |= UNIT_DIRECTORY_SPECIFIER_ID;
  709. break;
  710. case CSR1212_KV_ID_VERSION:
  711. ud->version = kv->value.immediate;
  712. ud->flags |= UNIT_DIRECTORY_VERSION;
  713. break;
  714. case CSR1212_KV_ID_DESCRIPTOR:
  715. if (kv->key.type == CSR1212_KV_TYPE_LEAF &&
  716. CSR1212_DESCRIPTOR_LEAF_TYPE(kv) == 0 &&
  717. CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) == 0 &&
  718. CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) == 0 &&
  719. CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) == 0 &&
  720. CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0) {
  721. switch (last_key_id) {
  722. case CSR1212_KV_ID_VENDOR:
  723. ud->vendor_name_kv = kv;
  724. csr1212_keep_keyval(kv);
  725. break;
  726. case CSR1212_KV_ID_MODEL:
  727. ud->model_name_kv = kv;
  728. csr1212_keep_keyval(kv);
  729. break;
  730. }
  731. } /* else if (kv->key.type == CSR1212_KV_TYPE_DIRECTORY) ... */
  732. break;
  733. case CSR1212_KV_ID_DEPENDENT_INFO:
  734. /* Logical Unit Number */
  735. if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) {
  736. if (ud->flags & UNIT_DIRECTORY_HAS_LUN) {
  737. ud_child = kmalloc(sizeof(*ud_child), GFP_KERNEL);
  738. if (!ud_child)
  739. goto unit_directory_error;
  740. memcpy(ud_child, ud, sizeof(*ud_child));
  741. nodemgr_register_device(ne, ud_child, &ne->device);
  742. ud_child = NULL;
  743. ud->id = (*id)++;
  744. }
  745. ud->lun = kv->value.immediate;
  746. ud->flags |= UNIT_DIRECTORY_HAS_LUN;
  747. /* Logical Unit Directory */
  748. } else if (kv->key.type == CSR1212_KV_TYPE_DIRECTORY) {
  749. /* This should really be done in SBP2 as this is
  750. * doing SBP2 specific parsing.
  751. */
  752. /* first register the parent unit */
  753. ud->flags |= UNIT_DIRECTORY_HAS_LUN_DIRECTORY;
  754. if (ud->device.bus != &ieee1394_bus_type)
  755. nodemgr_register_device(ne, ud, &ne->device);
  756. /* process the child unit */
  757. ud_child = nodemgr_process_unit_directory(hi, ne, kv, id, ud);
  758. if (ud_child == NULL)
  759. break;
  760. /* inherit unspecified values, the driver core picks it up */
  761. if ((ud->flags & UNIT_DIRECTORY_MODEL_ID) &&
  762. !(ud_child->flags & UNIT_DIRECTORY_MODEL_ID))
  763. {
  764. ud_child->flags |= UNIT_DIRECTORY_MODEL_ID;
  765. ud_child->model_id = ud->model_id;
  766. }
  767. if ((ud->flags & UNIT_DIRECTORY_SPECIFIER_ID) &&
  768. !(ud_child->flags & UNIT_DIRECTORY_SPECIFIER_ID))
  769. {
  770. ud_child->flags |= UNIT_DIRECTORY_SPECIFIER_ID;
  771. ud_child->specifier_id = ud->specifier_id;
  772. }
  773. if ((ud->flags & UNIT_DIRECTORY_VERSION) &&
  774. !(ud_child->flags & UNIT_DIRECTORY_VERSION))
  775. {
  776. ud_child->flags |= UNIT_DIRECTORY_VERSION;
  777. ud_child->version = ud->version;
  778. }
  779. /* register the child unit */
  780. ud_child->flags |= UNIT_DIRECTORY_LUN_DIRECTORY;
  781. nodemgr_register_device(ne, ud_child, &ud->device);
  782. }
  783. break;
  784. default:
  785. break;
  786. }
  787. last_key_id = kv->key.id;
  788. }
  789. /* do not process child units here and only if not already registered */
  790. if (!parent && ud->device.bus != &ieee1394_bus_type)
  791. nodemgr_register_device(ne, ud, &ne->device);
  792. return ud;
  793. unit_directory_error:
  794. kfree(ud);
  795. return NULL;
  796. }
  797. static void nodemgr_process_root_directory(struct host_info *hi, struct node_entry *ne)
  798. {
  799. unsigned int ud_id = 0;
  800. struct csr1212_dentry *dentry;
  801. struct csr1212_keyval *kv;
  802. u8 last_key_id = 0;
  803. ne->needs_probe = 0;
  804. csr1212_for_each_dir_entry(ne->csr, kv, ne->csr->root_kv, dentry) {
  805. switch (kv->key.id) {
  806. case CSR1212_KV_ID_VENDOR:
  807. ne->vendor_id = kv->value.immediate;
  808. if (ne->vendor_id)
  809. ne->vendor_oui = nodemgr_find_oui_name(ne->vendor_id);
  810. break;
  811. case CSR1212_KV_ID_NODE_CAPABILITIES:
  812. ne->capabilities = kv->value.immediate;
  813. break;
  814. case CSR1212_KV_ID_UNIT:
  815. nodemgr_process_unit_directory(hi, ne, kv, &ud_id, NULL);
  816. break;
  817. case CSR1212_KV_ID_DESCRIPTOR:
  818. if (last_key_id == CSR1212_KV_ID_VENDOR) {
  819. if (kv->key.type == CSR1212_KV_TYPE_LEAF &&
  820. CSR1212_DESCRIPTOR_LEAF_TYPE(kv) == 0 &&
  821. CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) == 0 &&
  822. CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) == 0 &&
  823. CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) == 0 &&
  824. CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0) {
  825. ne->vendor_name_kv = kv;
  826. csr1212_keep_keyval(kv);
  827. }
  828. }
  829. break;
  830. }
  831. last_key_id = kv->key.id;
  832. }
  833. if (ne->vendor_oui)
  834. device_create_file(&ne->device, &dev_attr_ne_vendor_oui);
  835. if (ne->vendor_name_kv)
  836. device_create_file(&ne->device, &dev_attr_ne_vendor_name_kv);
  837. }
  838. #ifdef CONFIG_HOTPLUG
  839. static int nodemgr_uevent(struct class_device *cdev, char **envp, int num_envp,
  840. char *buffer, int buffer_size)
  841. {
  842. struct unit_directory *ud;
  843. int i = 0;
  844. int length = 0;
  845. /* ieee1394:venNmoNspNverN */
  846. char buf[8 + 1 + 3 + 8 + 2 + 8 + 2 + 8 + 3 + 8 + 1];
  847. if (!cdev)
  848. return -ENODEV;
  849. ud = container_of(cdev, struct unit_directory, class_dev);
  850. if (ud->ne->in_limbo || ud->ignore_driver)
  851. return -ENODEV;
  852. #define PUT_ENVP(fmt,val) \
  853. do { \
  854. int printed; \
  855. envp[i++] = buffer; \
  856. printed = snprintf(buffer, buffer_size - length, \
  857. fmt, val); \
  858. if ((buffer_size - (length+printed) <= 0) || (i >= num_envp)) \
  859. return -ENOMEM; \
  860. length += printed+1; \
  861. buffer += printed+1; \
  862. } while (0)
  863. PUT_ENVP("VENDOR_ID=%06x", ud->vendor_id);
  864. PUT_ENVP("MODEL_ID=%06x", ud->model_id);
  865. PUT_ENVP("GUID=%016Lx", (unsigned long long)ud->ne->guid);
  866. PUT_ENVP("SPECIFIER_ID=%06x", ud->specifier_id);
  867. PUT_ENVP("VERSION=%06x", ud->version);
  868. snprintf(buf, sizeof(buf), "ieee1394:ven%08Xmo%08Xsp%08Xver%08X",
  869. ud->vendor_id,
  870. ud->model_id,
  871. ud->specifier_id,
  872. ud->version);
  873. PUT_ENVP("MODALIAS=%s", buf);
  874. #undef PUT_ENVP
  875. envp[i] = NULL;
  876. return 0;
  877. }
  878. #else
  879. static int nodemgr_uevent(struct class_device *cdev, char **envp, int num_envp,
  880. char *buffer, int buffer_size)
  881. {
  882. return -ENODEV;
  883. }
  884. #endif /* CONFIG_HOTPLUG */
  885. int hpsb_register_protocol(struct hpsb_protocol_driver *driver)
  886. {
  887. int ret;
  888. /* This will cause a probe for devices */
  889. ret = driver_register(&driver->driver);
  890. if (!ret)
  891. nodemgr_create_drv_files(driver);
  892. return ret;
  893. }
  894. void hpsb_unregister_protocol(struct hpsb_protocol_driver *driver)
  895. {
  896. nodemgr_remove_drv_files(driver);
  897. /* This will subsequently disconnect all devices that our driver
  898. * is attached to. */
  899. driver_unregister(&driver->driver);
  900. }
  901. /*
  902. * This function updates nodes that were present on the bus before the
  903. * reset and still are after the reset. The nodeid and the config rom
  904. * may have changed, and the drivers managing this device must be
  905. * informed that this device just went through a bus reset, to allow
  906. * the to take whatever actions required.
  907. */
  908. static void nodemgr_update_node(struct node_entry *ne, struct csr1212_csr *csr,
  909. struct host_info *hi, nodeid_t nodeid,
  910. unsigned int generation)
  911. {
  912. if (ne->nodeid != nodeid) {
  913. HPSB_DEBUG("Node changed: " NODE_BUS_FMT " -> " NODE_BUS_FMT,
  914. NODE_BUS_ARGS(ne->host, ne->nodeid),
  915. NODE_BUS_ARGS(ne->host, nodeid));
  916. ne->nodeid = nodeid;
  917. }
  918. if (ne->busopt.generation != ((be32_to_cpu(csr->bus_info_data[2]) >> 4) & 0xf)) {
  919. kfree(ne->csr->private);
  920. csr1212_destroy_csr(ne->csr);
  921. ne->csr = csr;
  922. /* If the node's configrom generation has changed, we
  923. * unregister all the unit directories. */
  924. nodemgr_remove_uds(ne);
  925. nodemgr_update_bus_options(ne);
  926. /* Mark the node as new, so it gets re-probed */
  927. ne->needs_probe = 1;
  928. } else {
  929. /* old cache is valid, so update its generation */
  930. struct nodemgr_csr_info *ci = ne->csr->private;
  931. ci->generation = generation;
  932. /* free the partially filled now unneeded new cache */
  933. kfree(csr->private);
  934. csr1212_destroy_csr(csr);
  935. }
  936. if (ne->in_limbo)
  937. nodemgr_resume_ne(ne);
  938. /* Mark the node current */
  939. ne->generation = generation;
  940. }
  941. static void nodemgr_node_scan_one(struct host_info *hi,
  942. nodeid_t nodeid, int generation)
  943. {
  944. struct hpsb_host *host = hi->host;
  945. struct node_entry *ne;
  946. octlet_t guid;
  947. struct csr1212_csr *csr;
  948. struct nodemgr_csr_info *ci;
  949. ci = kmalloc(sizeof(*ci), GFP_KERNEL);
  950. if (!ci)
  951. return;
  952. ci->host = host;
  953. ci->nodeid = nodeid;
  954. ci->generation = generation;
  955. /* We need to detect when the ConfigROM's generation has changed,
  956. * so we only update the node's info when it needs to be. */
  957. csr = csr1212_create_csr(&nodemgr_csr_ops, 5 * sizeof(quadlet_t), ci);
  958. if (!csr || csr1212_parse_csr(csr) != CSR1212_SUCCESS) {
  959. HPSB_ERR("Error parsing configrom for node " NODE_BUS_FMT,
  960. NODE_BUS_ARGS(host, nodeid));
  961. if (csr)
  962. csr1212_destroy_csr(csr);
  963. kfree(ci);
  964. return;
  965. }
  966. if (csr->bus_info_data[1] != IEEE1394_BUSID_MAGIC) {
  967. /* This isn't a 1394 device, but we let it slide. There
  968. * was a report of a device with broken firmware which
  969. * reported '2394' instead of '1394', which is obviously a
  970. * mistake. One would hope that a non-1394 device never
  971. * gets connected to Firewire bus. If someone does, we
  972. * shouldn't be held responsible, so we'll allow it with a
  973. * warning. */
  974. HPSB_WARN("Node " NODE_BUS_FMT " has invalid busID magic [0x%08x]",
  975. NODE_BUS_ARGS(host, nodeid), csr->bus_info_data[1]);
  976. }
  977. guid = ((u64)be32_to_cpu(csr->bus_info_data[3]) << 32) | be32_to_cpu(csr->bus_info_data[4]);
  978. ne = find_entry_by_guid(guid);
  979. if (ne && ne->host != host && ne->in_limbo) {
  980. /* Must have moved this device from one host to another */
  981. nodemgr_remove_ne(ne);
  982. ne = NULL;
  983. }
  984. if (!ne)
  985. nodemgr_create_node(guid, csr, hi, nodeid, generation);
  986. else
  987. nodemgr_update_node(ne, csr, hi, nodeid, generation);
  988. return;
  989. }
  990. static void nodemgr_node_scan(struct host_info *hi, int generation)
  991. {
  992. int count;
  993. struct hpsb_host *host = hi->host;
  994. struct selfid *sid = (struct selfid *)host->topology_map;
  995. nodeid_t nodeid = LOCAL_BUS;
  996. /* Scan each node on the bus */
  997. for (count = host->selfid_count; count; count--, sid++) {
  998. if (sid->extended)
  999. continue;
  1000. if (!sid->link_active) {
  1001. nodeid++;
  1002. continue;
  1003. }
  1004. nodemgr_node_scan_one(hi, nodeid++, generation);
  1005. }
  1006. }
  1007. static void nodemgr_suspend_ne(struct node_entry *ne)
  1008. {
  1009. struct class_device *cdev;
  1010. struct unit_directory *ud;
  1011. HPSB_DEBUG("Node suspended: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
  1012. NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
  1013. ne->in_limbo = 1;
  1014. device_create_file(&ne->device, &dev_attr_ne_in_limbo);
  1015. down_write(&ne->device.bus->subsys.rwsem);
  1016. list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
  1017. ud = container_of(cdev, struct unit_directory, class_dev);
  1018. if (ud->ne != ne)
  1019. continue;
  1020. if (ud->device.driver &&
  1021. (!ud->device.driver->suspend ||
  1022. ud->device.driver->suspend(&ud->device, PMSG_SUSPEND)))
  1023. device_release_driver(&ud->device);
  1024. }
  1025. up_write(&ne->device.bus->subsys.rwsem);
  1026. }
  1027. static void nodemgr_resume_ne(struct node_entry *ne)
  1028. {
  1029. struct class_device *cdev;
  1030. struct unit_directory *ud;
  1031. ne->in_limbo = 0;
  1032. device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
  1033. down_read(&ne->device.bus->subsys.rwsem);
  1034. list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
  1035. ud = container_of(cdev, struct unit_directory, class_dev);
  1036. if (ud->ne != ne)
  1037. continue;
  1038. if (ud->device.driver && ud->device.driver->resume)
  1039. ud->device.driver->resume(&ud->device);
  1040. }
  1041. up_read(&ne->device.bus->subsys.rwsem);
  1042. HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
  1043. NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
  1044. }
  1045. static void nodemgr_update_pdrv(struct node_entry *ne)
  1046. {
  1047. struct unit_directory *ud;
  1048. struct hpsb_protocol_driver *pdrv;
  1049. struct class *class = &nodemgr_ud_class;
  1050. struct class_device *cdev;
  1051. down_read(&class->subsys.rwsem);
  1052. list_for_each_entry(cdev, &class->children, node) {
  1053. ud = container_of(cdev, struct unit_directory, class_dev);
  1054. if (ud->ne != ne || !ud->device.driver)
  1055. continue;
  1056. pdrv = container_of(ud->device.driver, struct hpsb_protocol_driver, driver);
  1057. if (pdrv->update && pdrv->update(ud)) {
  1058. down_write(&ud->device.bus->subsys.rwsem);
  1059. device_release_driver(&ud->device);
  1060. up_write(&ud->device.bus->subsys.rwsem);
  1061. }
  1062. }
  1063. up_read(&class->subsys.rwsem);
  1064. }
  1065. /* Write the BROADCAST_CHANNEL as per IEEE1394a 8.3.2.3.11 and 8.4.2.3. This
  1066. * seems like an optional service but in the end it is practically mandatory
  1067. * as a consequence of these clauses.
  1068. *
  1069. * Note that we cannot do a broadcast write to all nodes at once because some
  1070. * pre-1394a devices would hang. */
  1071. static void nodemgr_irm_write_bc(struct node_entry *ne, int generation)
  1072. {
  1073. const u64 bc_addr = (CSR_REGISTER_BASE | CSR_BROADCAST_CHANNEL);
  1074. quadlet_t bc_remote, bc_local;
  1075. int ret;
  1076. if (!ne->host->is_irm || ne->generation != generation ||
  1077. ne->nodeid == ne->host->node_id)
  1078. return;
  1079. bc_local = cpu_to_be32(ne->host->csr.broadcast_channel);
  1080. /* Check if the register is implemented and 1394a compliant. */
  1081. ret = hpsb_read(ne->host, ne->nodeid, generation, bc_addr, &bc_remote,
  1082. sizeof(bc_remote));
  1083. if (!ret && bc_remote & cpu_to_be32(0x80000000) &&
  1084. bc_remote != bc_local)
  1085. hpsb_node_write(ne, bc_addr, &bc_local, sizeof(bc_local));
  1086. }
  1087. static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int generation)
  1088. {
  1089. struct device *dev;
  1090. if (ne->host != hi->host || ne->in_limbo)
  1091. return;
  1092. dev = get_device(&ne->device);
  1093. if (!dev)
  1094. return;
  1095. nodemgr_irm_write_bc(ne, generation);
  1096. /* If "needs_probe", then this is either a new or changed node we
  1097. * rescan totally. If the generation matches for an existing node
  1098. * (one that existed prior to the bus reset) we send update calls
  1099. * down to the drivers. Otherwise, this is a dead node and we
  1100. * suspend it. */
  1101. if (ne->needs_probe)
  1102. nodemgr_process_root_directory(hi, ne);
  1103. else if (ne->generation == generation)
  1104. nodemgr_update_pdrv(ne);
  1105. else
  1106. nodemgr_suspend_ne(ne);
  1107. put_device(dev);
  1108. }
  1109. static void nodemgr_node_probe(struct host_info *hi, int generation)
  1110. {
  1111. struct hpsb_host *host = hi->host;
  1112. struct class *class = &nodemgr_ne_class;
  1113. struct class_device *cdev;
  1114. struct node_entry *ne;
  1115. /* Do some processing of the nodes we've probed. This pulls them
  1116. * into the sysfs layer if needed, and can result in processing of
  1117. * unit-directories, or just updating the node and it's
  1118. * unit-directories.
  1119. *
  1120. * Run updates before probes. Usually, updates are time-critical
  1121. * while probes are time-consuming. (Well, those probes need some
  1122. * improvement...) */
  1123. down_read(&class->subsys.rwsem);
  1124. list_for_each_entry(cdev, &class->children, node) {
  1125. ne = container_of(cdev, struct node_entry, class_dev);
  1126. if (!ne->needs_probe)
  1127. nodemgr_probe_ne(hi, ne, generation);
  1128. }
  1129. list_for_each_entry(cdev, &class->children, node) {
  1130. ne = container_of(cdev, struct node_entry, class_dev);
  1131. if (ne->needs_probe)
  1132. nodemgr_probe_ne(hi, ne, generation);
  1133. }
  1134. up_read(&class->subsys.rwsem);
  1135. /* If we had a bus reset while we were scanning the bus, it is
  1136. * possible that we did not probe all nodes. In that case, we
  1137. * skip the clean up for now, since we could remove nodes that
  1138. * were still on the bus. The bus reset increased hi->reset_sem,
  1139. * so there's a bus scan pending which will do the clean up
  1140. * eventually.
  1141. *
  1142. * Now let's tell the bus to rescan our devices. This may seem
  1143. * like overhead, but the driver-model core will only scan a
  1144. * device for a driver when either the device is added, or when a
  1145. * new driver is added. A bus reset is a good reason to rescan
  1146. * devices that were there before. For example, an sbp2 device
  1147. * may become available for login, if the host that held it was
  1148. * just removed. */
  1149. if (generation == get_hpsb_generation(host))
  1150. bus_rescan_devices(&ieee1394_bus_type);
  1151. return;
  1152. }
  1153. static int nodemgr_send_resume_packet(struct hpsb_host *host)
  1154. {
  1155. struct hpsb_packet *packet;
  1156. int ret = 1;
  1157. packet = hpsb_make_phypacket(host,
  1158. EXTPHYPACKET_TYPE_RESUME |
  1159. NODEID_TO_NODE(host->node_id) << PHYPACKET_PORT_SHIFT);
  1160. if (packet) {
  1161. packet->no_waiter = 1;
  1162. packet->generation = get_hpsb_generation(host);
  1163. ret = hpsb_send_packet(packet);
  1164. }
  1165. if (ret)
  1166. HPSB_WARN("fw-host%d: Failed to broadcast resume packet",
  1167. host->id);
  1168. return ret;
  1169. }
  1170. /* Perform a few high-level IRM responsibilities. */
  1171. static int nodemgr_do_irm_duties(struct hpsb_host *host, int cycles)
  1172. {
  1173. quadlet_t bc;
  1174. /* if irm_id == -1 then there is no IRM on this bus */
  1175. if (!host->is_irm || host->irm_id == (nodeid_t)-1)
  1176. return 1;
  1177. /* We are a 1394a-2000 compliant IRM. Set the validity bit. */
  1178. host->csr.broadcast_channel |= 0x40000000;
  1179. /* If there is no bus manager then we should set the root node's
  1180. * force_root bit to promote bus stability per the 1394
  1181. * spec. (8.4.2.6) */
  1182. if (host->busmgr_id == 0xffff && host->node_count > 1)
  1183. {
  1184. u16 root_node = host->node_count - 1;
  1185. /* get cycle master capability flag from root node */
  1186. if (host->is_cycmst ||
  1187. (!hpsb_read(host, LOCAL_BUS | root_node, get_hpsb_generation(host),
  1188. (CSR_REGISTER_BASE + CSR_CONFIG_ROM + 2 * sizeof(quadlet_t)),
  1189. &bc, sizeof(quadlet_t)) &&
  1190. be32_to_cpu(bc) & 1 << CSR_CMC_SHIFT))
  1191. hpsb_send_phy_config(host, root_node, -1);
  1192. else {
  1193. HPSB_DEBUG("The root node is not cycle master capable; "
  1194. "selecting a new root node and resetting...");
  1195. if (cycles >= 5) {
  1196. /* Oh screw it! Just leave the bus as it is */
  1197. HPSB_DEBUG("Stopping reset loop for IRM sanity");
  1198. return 1;
  1199. }
  1200. hpsb_send_phy_config(host, NODEID_TO_NODE(host->node_id), -1);
  1201. hpsb_reset_bus(host, LONG_RESET_FORCE_ROOT);
  1202. return 0;
  1203. }
  1204. }
  1205. /* Some devices suspend their ports while being connected to an inactive
  1206. * host adapter, i.e. if connected before the low-level driver is
  1207. * loaded. They become visible either when physically unplugged and
  1208. * replugged, or when receiving a resume packet. Send one once. */
  1209. if (!host->resume_packet_sent && !nodemgr_send_resume_packet(host))
  1210. host->resume_packet_sent = 1;
  1211. return 1;
  1212. }
  1213. /* We need to ensure that if we are not the IRM, that the IRM node is capable of
  1214. * everything we can do, otherwise issue a bus reset and try to become the IRM
  1215. * ourselves. */
  1216. static int nodemgr_check_irm_capability(struct hpsb_host *host, int cycles)
  1217. {
  1218. quadlet_t bc;
  1219. int status;
  1220. if (hpsb_disable_irm || host->is_irm)
  1221. return 1;
  1222. status = hpsb_read(host, LOCAL_BUS | (host->irm_id),
  1223. get_hpsb_generation(host),
  1224. (CSR_REGISTER_BASE | CSR_BROADCAST_CHANNEL),
  1225. &bc, sizeof(quadlet_t));
  1226. if (status < 0 || !(be32_to_cpu(bc) & 0x80000000)) {
  1227. /* The current irm node does not have a valid BROADCAST_CHANNEL
  1228. * register and we do, so reset the bus with force_root set */
  1229. HPSB_DEBUG("Current remote IRM is not 1394a-2000 compliant, resetting...");
  1230. if (cycles >= 5) {
  1231. /* Oh screw it! Just leave the bus as it is */
  1232. HPSB_DEBUG("Stopping reset loop for IRM sanity");
  1233. return 1;
  1234. }
  1235. hpsb_send_phy_config(host, NODEID_TO_NODE(host->node_id), -1);
  1236. hpsb_reset_bus(host, LONG_RESET_FORCE_ROOT);
  1237. return 0;
  1238. }
  1239. return 1;
  1240. }
  1241. static int nodemgr_host_thread(void *__hi)
  1242. {
  1243. struct host_info *hi = (struct host_info *)__hi;
  1244. struct hpsb_host *host = hi->host;
  1245. int reset_cycles = 0;
  1246. /* No userlevel access needed */
  1247. daemonize(hi->daemon_name);
  1248. /* Setup our device-model entries */
  1249. nodemgr_create_host_dev_files(host);
  1250. /* Sit and wait for a signal to probe the nodes on the bus. This
  1251. * happens when we get a bus reset. */
  1252. while (1) {
  1253. unsigned int generation = 0;
  1254. int i;
  1255. if (down_interruptible(&hi->reset_sem) ||
  1256. down_interruptible(&nodemgr_serialize)) {
  1257. if (try_to_freeze())
  1258. continue;
  1259. printk("NodeMgr: received unexpected signal?!\n" );
  1260. break;
  1261. }
  1262. if (hi->kill_me) {
  1263. up(&nodemgr_serialize);
  1264. break;
  1265. }
  1266. /* Pause for 1/4 second in 1/16 second intervals,
  1267. * to make sure things settle down. */
  1268. for (i = 0; i < 4 ; i++) {
  1269. set_current_state(TASK_INTERRUPTIBLE);
  1270. if (msleep_interruptible(63)) {
  1271. up(&nodemgr_serialize);
  1272. goto caught_signal;
  1273. }
  1274. /* Now get the generation in which the node ID's we collect
  1275. * are valid. During the bus scan we will use this generation
  1276. * for the read transactions, so that if another reset occurs
  1277. * during the scan the transactions will fail instead of
  1278. * returning bogus data. */
  1279. generation = get_hpsb_generation(host);
  1280. /* If we get a reset before we are done waiting, then
  1281. * start the the waiting over again */
  1282. while (!down_trylock(&hi->reset_sem))
  1283. i = 0;
  1284. /* Check the kill_me again */
  1285. if (hi->kill_me) {
  1286. up(&nodemgr_serialize);
  1287. goto caught_signal;
  1288. }
  1289. }
  1290. if (!nodemgr_check_irm_capability(host, reset_cycles) ||
  1291. !nodemgr_do_irm_duties(host, reset_cycles)) {
  1292. reset_cycles++;
  1293. up(&nodemgr_serialize);
  1294. continue;
  1295. }
  1296. reset_cycles = 0;
  1297. /* Scan our nodes to get the bus options and create node
  1298. * entries. This does not do the sysfs stuff, since that
  1299. * would trigger uevents and such, which is a bad idea at
  1300. * this point. */
  1301. nodemgr_node_scan(hi, generation);
  1302. /* This actually does the full probe, with sysfs
  1303. * registration. */
  1304. nodemgr_node_probe(hi, generation);
  1305. /* Update some of our sysfs symlinks */
  1306. nodemgr_update_host_dev_links(host);
  1307. up(&nodemgr_serialize);
  1308. }
  1309. caught_signal:
  1310. HPSB_VERBOSE("NodeMgr: Exiting thread");
  1311. complete_and_exit(&hi->exited, 0);
  1312. }
  1313. int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *))
  1314. {
  1315. struct class *class = &hpsb_host_class;
  1316. struct class_device *cdev;
  1317. struct hpsb_host *host;
  1318. int error = 0;
  1319. down_read(&class->subsys.rwsem);
  1320. list_for_each_entry(cdev, &class->children, node) {
  1321. host = container_of(cdev, struct hpsb_host, class_dev);
  1322. if ((error = cb(host, __data)))
  1323. break;
  1324. }
  1325. up_read(&class->subsys.rwsem);
  1326. return error;
  1327. }
  1328. /* The following four convenience functions use a struct node_entry
  1329. * for addressing a node on the bus. They are intended for use by any
  1330. * process context, not just the nodemgr thread, so we need to be a
  1331. * little careful when reading out the node ID and generation. The
  1332. * thing that can go wrong is that we get the node ID, then a bus
  1333. * reset occurs, and then we read the generation. The node ID is
  1334. * possibly invalid, but the generation is current, and we end up
  1335. * sending a packet to a the wrong node.
  1336. *
  1337. * The solution is to make sure we read the generation first, so that
  1338. * if a reset occurs in the process, we end up with a stale generation
  1339. * and the transactions will fail instead of silently using wrong node
  1340. * ID's.
  1341. */
  1342. void hpsb_node_fill_packet(struct node_entry *ne, struct hpsb_packet *pkt)
  1343. {
  1344. pkt->host = ne->host;
  1345. pkt->generation = ne->generation;
  1346. barrier();
  1347. pkt->node_id = ne->nodeid;
  1348. }
  1349. int hpsb_node_write(struct node_entry *ne, u64 addr,
  1350. quadlet_t *buffer, size_t length)
  1351. {
  1352. unsigned int generation = ne->generation;
  1353. barrier();
  1354. return hpsb_write(ne->host, ne->nodeid, generation,
  1355. addr, buffer, length);
  1356. }
  1357. static void nodemgr_add_host(struct hpsb_host *host)
  1358. {
  1359. struct host_info *hi;
  1360. hi = hpsb_create_hostinfo(&nodemgr_highlevel, host, sizeof(*hi));
  1361. if (!hi) {
  1362. HPSB_ERR ("NodeMgr: out of memory in add host");
  1363. return;
  1364. }
  1365. hi->host = host;
  1366. init_completion(&hi->exited);
  1367. sema_init(&hi->reset_sem, 0);
  1368. sprintf(hi->daemon_name, "knodemgrd_%d", host->id);
  1369. hi->pid = kernel_thread(nodemgr_host_thread, hi, CLONE_KERNEL);
  1370. if (hi->pid < 0) {
  1371. HPSB_ERR ("NodeMgr: failed to start %s thread for %s",
  1372. hi->daemon_name, host->driver->name);
  1373. hpsb_destroy_hostinfo(&nodemgr_highlevel, host);
  1374. return;
  1375. }
  1376. return;
  1377. }
  1378. static void nodemgr_host_reset(struct hpsb_host *host)
  1379. {
  1380. struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host);
  1381. if (hi != NULL) {
  1382. HPSB_VERBOSE("NodeMgr: Processing host reset for %s", hi->daemon_name);
  1383. up(&hi->reset_sem);
  1384. } else
  1385. HPSB_ERR ("NodeMgr: could not process reset of unused host");
  1386. return;
  1387. }
  1388. static void nodemgr_remove_host(struct hpsb_host *host)
  1389. {
  1390. struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host);
  1391. if (hi) {
  1392. if (hi->pid >= 0) {
  1393. hi->kill_me = 1;
  1394. mb();
  1395. up(&hi->reset_sem);
  1396. wait_for_completion(&hi->exited);
  1397. nodemgr_remove_host_dev(&host->device);
  1398. }
  1399. } else
  1400. HPSB_ERR("NodeMgr: host %s does not exist, cannot remove",
  1401. host->driver->name);
  1402. return;
  1403. }
  1404. static struct hpsb_highlevel nodemgr_highlevel = {
  1405. .name = "Node manager",
  1406. .add_host = nodemgr_add_host,
  1407. .host_reset = nodemgr_host_reset,
  1408. .remove_host = nodemgr_remove_host,
  1409. };
  1410. int init_ieee1394_nodemgr(void)
  1411. {
  1412. int ret;
  1413. ret = class_register(&nodemgr_ne_class);
  1414. if (ret < 0)
  1415. return ret;
  1416. ret = class_register(&nodemgr_ud_class);
  1417. if (ret < 0) {
  1418. class_unregister(&nodemgr_ne_class);
  1419. return ret;
  1420. }
  1421. hpsb_register_highlevel(&nodemgr_highlevel);
  1422. return 0;
  1423. }
  1424. void cleanup_ieee1394_nodemgr(void)
  1425. {
  1426. hpsb_unregister_highlevel(&nodemgr_highlevel);
  1427. class_unregister(&nodemgr_ud_class);
  1428. class_unregister(&nodemgr_ne_class);
  1429. }