nodemgr.c 51 KB

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