nodemgr.c 51 KB

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