nodemgr.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:37k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Node information (ConfigROM) collection and management.
  3.  *
  4.  * Copyright (C) 2000 Andreas E. Bombe
  5.  *               2001 Ben Collins <bcollins@debian.net>
  6.  *
  7.  * This code is licensed under the GPL.  See the file COPYING in the root
  8.  * directory of the kernel sources for details.
  9.  */
  10. #include <linux/kernel.h>
  11. #include <linux/list.h>
  12. #include <linux/slab.h>
  13. #include <asm/byteorder.h>
  14. #include <linux/smp_lock.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kmod.h>
  17. #include <linux/completion.h>
  18. #include <linux/delay.h>
  19. #ifdef CONFIG_PROC_FS
  20. #include <linux/proc_fs.h>
  21. #endif
  22. #include "ieee1394_types.h"
  23. #include "ieee1394.h"
  24. #include "hosts.h"
  25. #include "ieee1394_transactions.h"
  26. #include "ieee1394_hotplug.h"
  27. #include "highlevel.h"
  28. #include "csr.h"
  29. #include "nodemgr.h"
  30. /* 
  31.  * Basically what we do here is start off retrieving the bus_info block.
  32.  * From there will fill in some info about the node, verify it is of IEEE
  33.  * 1394 type, and that the crc checks out ok. After that we start off with
  34.  * the root directory, and subdirectories. To do this, we retrieve the
  35.  * quadlet header for a directory, find out the length, and retrieve the
  36.  * complete directory entry (be it a leaf or a directory). We then process
  37.  * it and add the info to our structure for that particular node.
  38.  *
  39.  * We verify CRC's along the way for each directory/block/leaf. The
  40.  * entire node structure is generic, and simply stores the information in
  41.  * a way that's easy to parse by the protocol interface.
  42.  */
  43. /* The nodemgr maintains a number of data structures: the node list,
  44.  * the driver list, unit directory list and the host info list.  The
  45.  * first three lists are accessed from process context only: /proc
  46.  * readers, insmod and rmmod, and the nodemgr thread.  Access to these
  47.  * lists are serialized by means of the nodemgr_serialize mutex, which
  48.  * must be taken before accessing the structures and released
  49.  * afterwards.  The host info list is only accessed during insmod,
  50.  * rmmod and from interrupt and allways only for a short period of
  51.  * time, so a spinlock is used to protect this list.
  52.  */
  53. static DECLARE_MUTEX(nodemgr_serialize);
  54. static LIST_HEAD(node_list);
  55. static LIST_HEAD(driver_list);
  56. static LIST_HEAD(unit_directory_list);
  57. static LIST_HEAD(host_info_list);
  58. static spinlock_t host_info_lock = SPIN_LOCK_UNLOCKED;
  59. /* Disables use of the hotplug calls.  */
  60. static int nodemgr_disable_hotplug = 0;
  61. struct host_info {
  62. struct hpsb_host *host;
  63. struct list_head list;
  64. struct completion exited;
  65. struct semaphore reset_sem;
  66. int pid;
  67. };
  68. #ifdef CONFIG_PROC_FS
  69. #define PUTF(fmt, args...) out += sprintf(out, fmt, ## args)
  70. static int raw1394_read_proc(char *page, char **start, off_t off,
  71.      int count, int *eof, void *data)
  72. {
  73. struct list_head *lh;
  74. struct node_entry *ne;
  75. int len;
  76. char *out = page;
  77. if (down_interruptible(&nodemgr_serialize))
  78. return -EINTR;
  79. list_for_each(lh, &node_list) {
  80. struct list_head *l;
  81. int ud_count = 0;
  82. ne = list_entry(lh, struct node_entry, list);
  83. if (!ne)
  84. continue;
  85. PUTF("Node[" NODE_BUS_FMT "]  GUID[%016Lx]:n",
  86.      NODE_BUS_ARGS(ne->nodeid), (unsigned long long)ne->guid);
  87. /* Generic Node information */
  88. PUTF("  Vendor ID: `%s' [0x%06x]n",
  89.      ne->vendor_name ?: "Unknown", ne->vendor_id);
  90. PUTF("  Capabilities: 0x%06xn", ne->capabilities);
  91. PUTF("  Bus Options:n");
  92. PUTF("    IRMC(%d) CMC(%d) ISC(%d) BMC(%d) PMC(%d) GEN(%d)n"
  93.      "    LSPD(%d) MAX_REC(%d) CYC_CLK_ACC(%d)n",
  94.      ne->busopt.irmc, ne->busopt.cmc, ne->busopt.isc, ne->busopt.bmc,
  95.      ne->busopt.pmc, ne->busopt.generation, ne->busopt.lnkspd,
  96.      ne->busopt.max_rec, ne->busopt.cyc_clk_acc);
  97. /* If this is the host entry, output some info about it aswell */
  98. if (ne->host != NULL && ne->host->node_id == ne->nodeid) {
  99. PUTF("  Host Node Status:n");
  100. PUTF("    Host Driver     : %sn", ne->host->driver->name);
  101. PUTF("    Nodes connected : %dn", ne->host->node_count);
  102. PUTF("    Nodes active    : %dn", ne->host->nodes_active);
  103. PUTF("    SelfIDs received: %dn", ne->host->selfid_count);
  104. PUTF("    Irm ID          : [" NODE_BUS_FMT "]n",
  105.      NODE_BUS_ARGS(ne->host->irm_id));
  106. PUTF("    BusMgr ID       : [" NODE_BUS_FMT "]n",
  107.      NODE_BUS_ARGS(ne->host->busmgr_id));
  108. PUTF("    In Bus Reset    : %sn", ne->host->in_bus_reset ? "yes" : "no");
  109. PUTF("    Root            : %sn", ne->host->is_root ? "yes" : "no");
  110. PUTF("    Cycle Master    : %sn", ne->host->is_cycmst ? "yes" : "no");
  111. PUTF("    IRM             : %sn", ne->host->is_irm ? "yes" : "no");
  112. PUTF("    Bus Manager     : %sn", ne->host->is_busmgr ? "yes" : "no");
  113. }
  114. /* Now the unit directories */
  115. list_for_each (l, &ne->unit_directories) {
  116. struct unit_directory *ud = list_entry (l, struct unit_directory, node_list);
  117. int printed = 0; // small hack
  118. PUTF("  Unit Directory %d:n", ud_count++);
  119. if (ud->flags & UNIT_DIRECTORY_VENDOR_ID) {
  120. PUTF("    Vendor/Model ID: %s [%06x]",
  121.      ud->vendor_name ?: "Unknown", ud->vendor_id);
  122. printed = 1;
  123. }
  124. if (ud->flags & UNIT_DIRECTORY_MODEL_ID) {
  125. if (!printed)
  126. PUTF("    Vendor/Model ID: %s [%06x]",
  127.      ne->vendor_name ?: "Unknown", ne->vendor_id);
  128. PUTF(" / %s [%06x]", ud->model_name ?: "Unknown", ud->model_id);
  129. printed = 1;
  130. }
  131. if (printed)
  132. PUTF("n");
  133. if (ud->flags & UNIT_DIRECTORY_SPECIFIER_ID)
  134. PUTF("    Software Specifier ID: %06xn", ud->specifier_id);
  135. if (ud->flags & UNIT_DIRECTORY_VERSION)
  136. PUTF("    Software Version: %06xn", ud->version);
  137. if (ud->driver)
  138. PUTF("    Driver: %sn", ud->driver->name);
  139. PUTF("    Length (in quads): %dn", ud->count);
  140. }
  141. }
  142. up(&nodemgr_serialize);
  143. len = out - page;
  144. len -= off;
  145. if (len < count) {
  146. *eof = 1;
  147. if (len <= 0)
  148. return 0;
  149. } else
  150. len = count;
  151.         *start = page + off;
  152. return len;
  153. }
  154. #undef PUTF
  155. #endif /* CONFIG_PROC_FS */
  156. static void nodemgr_process_config_rom(struct node_entry *ne, 
  157.        quadlet_t busoptions);
  158. static int nodemgr_read_quadlet(struct hpsb_host *host,
  159. nodeid_t nodeid, unsigned int generation,
  160. octlet_t address, quadlet_t *quad)
  161. {
  162. int i;
  163. int ret = 0;
  164. for (i = 0; i < 3; i++) {
  165. ret = hpsb_read(host, nodeid, generation, address, quad, 4);
  166. if (!ret)
  167. break;
  168. set_current_state(TASK_INTERRUPTIBLE);
  169. if (schedule_timeout (HZ/3))
  170. return -1;
  171. }
  172. *quad = be32_to_cpu(*quad);
  173. return ret;
  174. }
  175. static int nodemgr_size_text_leaf(struct hpsb_host *host,
  176.   nodeid_t nodeid, unsigned int generation,
  177.   octlet_t address)
  178. {
  179. quadlet_t quad;
  180. int size = 0;
  181. if (nodemgr_read_quadlet(host, nodeid, generation, address, &quad))
  182. return -1;
  183. if (CONFIG_ROM_KEY(quad) == CONFIG_ROM_DESCRIPTOR_LEAF) {
  184. /* This is the offset.  */
  185. address += 4 * CONFIG_ROM_VALUE(quad); 
  186. if (nodemgr_read_quadlet(host, nodeid, generation, address, &quad))
  187. return -1;
  188. /* Now we got the size of the text descriptor leaf. */
  189. size = CONFIG_ROM_LEAF_LENGTH(quad);
  190. }
  191. return size;
  192. }
  193. static int nodemgr_read_text_leaf(struct node_entry *ne,
  194.   octlet_t address,
  195.   quadlet_t *quadp)
  196. {
  197. quadlet_t quad;
  198. int i, size, ret;
  199. if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation, address, &quad)
  200.     || CONFIG_ROM_KEY(quad) != CONFIG_ROM_DESCRIPTOR_LEAF)
  201. return -1;
  202. /* This is the offset.  */
  203. address += 4 * CONFIG_ROM_VALUE(quad);
  204. if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation, address, &quad))
  205. return -1;
  206. /* Now we got the size of the text descriptor leaf. */
  207. size = CONFIG_ROM_LEAF_LENGTH(quad) - 2;
  208. if (size <= 0)
  209. return -1;
  210. address += 4;
  211. for (i = 0; i < 2; i++, address += 4, quadp++) {
  212. if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation, address, quadp))
  213. return -1;
  214. }
  215. /* Now read the text string.  */
  216. ret = -ENXIO;
  217. for (; size > 0; size--, address += 4, quadp++) {
  218. for (i = 0; i < 3; i++) {
  219. ret = hpsb_read(ne->host, ne->nodeid, ne->generation, address, quadp, 4);
  220. if (ret != -EAGAIN)
  221. break;
  222. }
  223. if (ret)
  224. break;
  225. }
  226. return ret;
  227. }
  228. static struct node_entry *nodemgr_scan_root_directory
  229. (struct hpsb_host *host, nodeid_t nodeid, unsigned int generation)
  230. {
  231. octlet_t address;
  232. quadlet_t quad;
  233. int length;
  234. int code, size, total_size;
  235. struct node_entry *ne;
  236. address = CSR_REGISTER_BASE + CSR_CONFIG_ROM;
  237. if (nodemgr_read_quadlet(host, nodeid, generation, address, &quad))
  238. return NULL;
  239. address += 4 + CONFIG_ROM_BUS_INFO_LENGTH(quad) * 4;
  240. if (nodemgr_read_quadlet(host, nodeid, generation, address, &quad))
  241. return NULL;
  242. length = CONFIG_ROM_ROOT_LENGTH(quad);
  243. address += 4;
  244. size = 0;
  245. total_size = sizeof(struct node_entry);
  246. for (; length > 0; length--, address += 4) {
  247. if (nodemgr_read_quadlet(host, nodeid, generation, address, &quad))
  248. return NULL;
  249. code = CONFIG_ROM_KEY(quad);
  250. if (code == CONFIG_ROM_VENDOR_ID && length > 0) {
  251. /* Check if there is a text descriptor leaf
  252.    immediately after this.  */
  253. size = nodemgr_size_text_leaf(host, nodeid, generation,
  254.       address + 4);
  255. if (size > 0) {
  256. address += 4;
  257. length--;
  258. total_size += (size + 1) * sizeof (quadlet_t);
  259. }
  260. else if (size < 0)
  261. return NULL;
  262. }
  263. }
  264. ne = kmalloc(total_size, SLAB_ATOMIC);
  265. if (ne != NULL) {
  266. if (size != 0) {
  267. ne->vendor_name
  268. = (const char *) &(ne->quadlets[2]);
  269. ne->quadlets[size] = 0;
  270. }
  271. else {
  272. ne->vendor_name = NULL;
  273. }
  274. }
  275. return ne; 
  276. }
  277. static struct node_entry *nodemgr_create_node(octlet_t guid, quadlet_t busoptions,
  278.       struct hpsb_host *host,
  279.       nodeid_t nodeid, unsigned int generation)
  280. {
  281.         struct node_entry *ne;
  282. ne = nodemgr_scan_root_directory (host, nodeid, generation);
  283.         if (!ne) return NULL;
  284.         INIT_LIST_HEAD(&ne->list);
  285. INIT_LIST_HEAD(&ne->unit_directories);
  286.         ne->host = host;
  287.         ne->nodeid = nodeid;
  288.         ne->guid = guid;
  289. ne->generation = generation;
  290.         list_add_tail(&ne->list, &node_list);
  291. nodemgr_process_config_rom (ne, busoptions);
  292. HPSB_DEBUG("%s added: Node[" NODE_BUS_FMT "]  GUID[%016Lx]  [%s]",
  293.    (host->node_id == nodeid) ? "Host" : "Device",
  294.    NODE_BUS_ARGS(nodeid), (unsigned long long)guid,
  295.    ne->vendor_name ?: "Unknown");
  296.         return ne;
  297. }
  298. static struct node_entry *find_entry_by_guid(u64 guid)
  299. {
  300.         struct list_head *lh;
  301.         struct node_entry *ne;
  302.         
  303.         list_for_each(lh, &node_list) {
  304.                 ne = list_entry(lh, struct node_entry, list);
  305.                 if (ne->guid == guid) return ne;
  306.         }
  307.         return NULL;
  308. }
  309. static struct node_entry *find_entry_by_nodeid(nodeid_t nodeid)
  310. {
  311. struct list_head *lh;
  312. struct node_entry *ne;
  313. list_for_each(lh, &node_list) {
  314. ne = list_entry(lh, struct node_entry, list);
  315. if (ne->nodeid == nodeid) return ne;
  316. }
  317. return NULL;
  318. }
  319. static struct unit_directory *nodemgr_scan_unit_directory
  320. (struct node_entry *ne, octlet_t address)
  321. {
  322. struct unit_directory *ud;
  323. quadlet_t quad;
  324. u8 flags, todo;
  325. int length, size, total_size, count;
  326. int vendor_name_size, model_name_size;
  327. if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation, address, &quad))
  328. return NULL;
  329. length = CONFIG_ROM_DIRECTORY_LENGTH(quad) ;
  330. address += 4;
  331. size = 0;
  332. total_size = sizeof (struct unit_directory);
  333. flags = 0;
  334. count = 0;
  335. vendor_name_size = 0;
  336. model_name_size = 0;
  337. for (; length > 0; length--, address += 4) {
  338. int code;
  339. quadlet_t value;
  340. if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation,
  341.  address, &quad))
  342. return NULL;
  343. code = CONFIG_ROM_KEY(quad);
  344. value = CONFIG_ROM_VALUE(quad);
  345. todo = 0;
  346. switch (code) {
  347. case CONFIG_ROM_VENDOR_ID:
  348. todo = UNIT_DIRECTORY_VENDOR_TEXT;
  349. break;
  350. case CONFIG_ROM_MODEL_ID:
  351. todo = UNIT_DIRECTORY_MODEL_TEXT;
  352. break;
  353. case CONFIG_ROM_SPECIFIER_ID:
  354. case CONFIG_ROM_UNIT_SW_VERSION:
  355. break;
  356. case CONFIG_ROM_DESCRIPTOR_LEAF:
  357. case CONFIG_ROM_DESCRIPTOR_DIRECTORY:
  358. /* TODO: read strings... icons? */
  359. break;
  360. default:
  361. /* Which types of quadlets do we want to
  362.    store?  Only count immediate values and
  363.    CSR offsets for now.  */
  364. code &= CONFIG_ROM_KEY_TYPE_MASK;
  365. if ((code & 0x80) == 0)
  366. count++;
  367. break;
  368. }
  369. if (todo && length > 0) {
  370. /* Check if there is a text descriptor leaf
  371.    immediately after this.  */
  372. size = nodemgr_size_text_leaf(ne->host,
  373.       ne->nodeid,
  374.       ne->generation,
  375.       address + 4);
  376. if (todo == UNIT_DIRECTORY_VENDOR_TEXT)
  377. vendor_name_size = size;
  378. else
  379. model_name_size = size;
  380. if (size > 0) {
  381. address += 4;
  382. length--;
  383. flags |= todo;
  384. total_size += (size + 1) * sizeof (quadlet_t);
  385. }
  386. else if (size < 0)
  387. return NULL;
  388. }
  389. }
  390. total_size += count * sizeof (quadlet_t);
  391. ud = kmalloc (total_size, GFP_KERNEL);
  392. if (ud != NULL) {
  393. memset (ud, 0, sizeof *ud);
  394. ud->flags = flags;
  395. ud->count = count;
  396. ud->vendor_name_size = vendor_name_size;
  397. ud->model_name_size = model_name_size;
  398. /* If there is no vendor name in the unit directory,
  399.    use the one in the root directory.  */
  400. ud->vendor_name = ne->vendor_name;
  401. }
  402. return ud;
  403. }
  404. /* This implementation currently only scans the config rom and its
  405.  * immediate unit directories looking for software_id and
  406.  * software_version entries, in order to get driver autoloading working.
  407.  */
  408. static void nodemgr_process_unit_directory(struct node_entry *ne, 
  409.    octlet_t address)
  410. {
  411. struct unit_directory *ud;
  412. quadlet_t quad;
  413. quadlet_t *infop;
  414. int length;
  415. if (!(ud = nodemgr_scan_unit_directory(ne, address)))
  416. goto unit_directory_error;
  417. ud->ne = ne;
  418. ud->address = address;
  419. if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation,
  420.  address, &quad))
  421. goto unit_directory_error;
  422. length = CONFIG_ROM_DIRECTORY_LENGTH(quad) ;
  423. address += 4;
  424. infop = (quadlet_t *) ud->quadlets;
  425. for (; length > 0; length--, address += 4, infop++) {
  426. int code;
  427. quadlet_t value;
  428. quadlet_t *quadp;
  429. if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation,
  430.  address, &quad))
  431. goto unit_directory_error;
  432. code = CONFIG_ROM_KEY(quad) ;
  433. value = CONFIG_ROM_VALUE(quad);
  434. switch (code) {
  435. case CONFIG_ROM_VENDOR_ID:
  436. ud->vendor_id = value;
  437. ud->flags |= UNIT_DIRECTORY_VENDOR_ID;
  438. if ((ud->flags & UNIT_DIRECTORY_VENDOR_TEXT) != 0) {
  439. length--;
  440. address += 4;
  441. quadp = &(ud->quadlets[ud->count]);
  442. if (nodemgr_read_text_leaf(ne, address,
  443.    quadp) == 0
  444.     && quadp[0] == 0
  445.     && quadp[1] == 0) {
  446.      /* We only support minimal
  447.    ASCII and English. */
  448. quadp[ud->vendor_name_size] = 0;
  449. ud->vendor_name
  450. = (const char *) &(quadp[2]);
  451. }
  452. }
  453. break;
  454. case CONFIG_ROM_MODEL_ID:
  455. ud->model_id = value;
  456. ud->flags |= UNIT_DIRECTORY_MODEL_ID;
  457. if ((ud->flags & UNIT_DIRECTORY_MODEL_TEXT) != 0) {
  458. length--;
  459. address += 4;
  460. quadp = &(ud->quadlets[ud->count + ud->vendor_name_size + 1]);
  461. if (nodemgr_read_text_leaf(ne, address,
  462.    quadp) == 0
  463.     && quadp[0] == 0
  464.     && quadp[1] == 0) {
  465.      /* We only support minimal
  466.    ASCII and English. */
  467. quadp[ud->model_name_size] = 0;
  468. ud->model_name
  469. = (const char *) &(quadp[2]);
  470. }
  471. }
  472. break;
  473. case CONFIG_ROM_SPECIFIER_ID:
  474. ud->specifier_id = value;
  475. ud->flags |= UNIT_DIRECTORY_SPECIFIER_ID;
  476. break;
  477. case CONFIG_ROM_UNIT_SW_VERSION:
  478. ud->version = value;
  479. ud->flags |= UNIT_DIRECTORY_VERSION;
  480. break;
  481. case CONFIG_ROM_DESCRIPTOR_LEAF:
  482. case CONFIG_ROM_DESCRIPTOR_DIRECTORY:
  483. /* TODO: read strings... icons? */
  484. break;
  485. default:
  486. /* Which types of quadlets do we want to
  487.    store?  Only count immediate values and
  488.    CSR offsets for now.  */
  489. code &= CONFIG_ROM_KEY_TYPE_MASK;
  490. if ((code & 0x80) == 0)
  491. *infop = quad;
  492. break;
  493. }
  494. }
  495. list_add_tail(&ud->node_list, &ne->unit_directories);
  496. list_add_tail(&ud->driver_list, &unit_directory_list);
  497. return;
  498. unit_directory_error:
  499. if (ud != NULL)
  500. kfree(ud);
  501. }
  502. static void dump_directories (struct node_entry *ne)
  503. {
  504. #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
  505. struct list_head *l;
  506. HPSB_DEBUG("vendor_id=0x%06x [%s], capabilities=0x%06x",
  507.    ne->vendor_id, ne->vendor_name ?: "Unknown",
  508.    ne->capabilities);
  509. list_for_each (l, &ne->unit_directories) {
  510. struct unit_directory *ud = list_entry (l, struct unit_directory, node_list);
  511. HPSB_DEBUG("unit directory:");
  512. if (ud->flags & UNIT_DIRECTORY_VENDOR_ID)
  513. HPSB_DEBUG("  vendor_id=0x%06x [%s]",
  514.    ud->vendor_id,
  515.    ud->vendor_name ?: "Unknown");
  516. if (ud->flags & UNIT_DIRECTORY_MODEL_ID)
  517. HPSB_DEBUG("  model_id=0x%06x [%s]",
  518.    ud->model_id,
  519.    ud->model_name ?: "Unknown");
  520. if (ud->flags & UNIT_DIRECTORY_SPECIFIER_ID)
  521. HPSB_DEBUG("  sw_specifier_id=0x%06x ", ud->specifier_id);
  522. if (ud->flags & UNIT_DIRECTORY_VERSION)
  523. HPSB_DEBUG("  sw_version=0x%06x ", ud->version);
  524. }
  525. #endif
  526. return;
  527. }
  528. static void nodemgr_process_root_directory(struct node_entry *ne)
  529. {
  530. octlet_t address;
  531. quadlet_t quad;
  532. int length;
  533. address = CSR_REGISTER_BASE + CSR_CONFIG_ROM;
  534. if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation,
  535.  address, &quad))
  536. return;
  537. address += 4 + CONFIG_ROM_BUS_INFO_LENGTH(quad) * 4;
  538. if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation,
  539.  address, &quad))
  540. return;
  541. length = CONFIG_ROM_ROOT_LENGTH(quad);
  542. address += 4;
  543. for (; length > 0; length--, address += 4) {
  544. int code, value;
  545. if (nodemgr_read_quadlet(ne->host, ne->nodeid, ne->generation,
  546.  address, &quad))
  547. return;
  548. code = CONFIG_ROM_KEY(quad);
  549. value = CONFIG_ROM_VALUE(quad);
  550. switch (code) {
  551. case CONFIG_ROM_VENDOR_ID:
  552. ne->vendor_id = value;
  553. /* Now check if there is a vendor name text
  554.    string.  */
  555. if (ne->vendor_name != NULL) {
  556. length--;
  557. address += 4;
  558. if (nodemgr_read_text_leaf(ne, address,
  559.    ne->quadlets)
  560.     != 0
  561.     || ne->quadlets [0] != 0
  562.     || ne->quadlets [1] != 0)
  563.      /* We only support minimal
  564.    ASCII and English. */
  565. ne->vendor_name = NULL;
  566. }
  567. break;
  568. case CONFIG_ROM_NODE_CAPABILITES:
  569. ne->capabilities = value;
  570. break;
  571. case CONFIG_ROM_UNIT_DIRECTORY:
  572. nodemgr_process_unit_directory(ne, address + value * 4);
  573. break;
  574. case CONFIG_ROM_DESCRIPTOR_LEAF:
  575. case CONFIG_ROM_DESCRIPTOR_DIRECTORY:
  576. /* TODO: read strings... icons? */
  577. break;
  578. }
  579. }
  580. dump_directories(ne);
  581. }
  582. #ifdef CONFIG_HOTPLUG
  583. static void nodemgr_call_policy(char *verb, struct unit_directory *ud)
  584. {
  585. char *argv [3], **envp, *buf, *scratch;
  586. int i = 0, value;
  587. /* User requested to disable hotplug when module was loaded. */
  588. if (nodemgr_disable_hotplug)
  589. return;
  590. if (!hotplug_path [0])
  591. return;
  592. if (!current->fs->root)
  593. return;
  594. if (!(envp = (char **) kmalloc(20 * sizeof (char *), GFP_KERNEL))) {
  595. HPSB_DEBUG ("ENOMEM");
  596. return;
  597. }
  598. if (!(buf = kmalloc(256, GFP_KERNEL))) {
  599. kfree(envp);
  600. HPSB_DEBUG("ENOMEM2");
  601. return;
  602. }
  603. /* only one standardized param to hotplug command: type */
  604. argv[0] = hotplug_path;
  605. argv[1] = "ieee1394";
  606. argv[2] = 0;
  607. /* minimal command environment */
  608. envp[i++] = "HOME=/";
  609. envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
  610. #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
  611. /* hint that policy agent should enter no-stdout debug mode */
  612. envp[i++] = "DEBUG=kernel";
  613. #endif
  614. /* extensible set of named bus-specific parameters,
  615.  * supporting multiple driver selection algorithms.
  616.  */
  617. scratch = buf;
  618. envp[i++] = scratch;
  619. scratch += sprintf(scratch, "ACTION=%s", verb) + 1;
  620. envp[i++] = scratch;
  621. scratch += sprintf(scratch, "VENDOR_ID=%06x", ud->ne->vendor_id) + 1;
  622. envp[i++] = scratch;
  623. scratch += sprintf(scratch, "GUID=%016Lx", (long long unsigned)ud->ne->guid) + 1;
  624. envp[i++] = scratch;
  625. scratch += sprintf(scratch, "SPECIFIER_ID=%06x", ud->specifier_id) + 1;
  626. envp[i++] = scratch;
  627. scratch += sprintf(scratch, "VERSION=%06x", ud->version) + 1;
  628. envp[i++] = 0;
  629. /* NOTE: user mode daemons can call the agents too */
  630. #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
  631. HPSB_DEBUG("NodeMgr: %s %s %016Lx", argv[0], verb, (long long unsigned)ud->ne->guid);
  632. #endif
  633. value = call_usermodehelper(argv[0], argv, envp);
  634. kfree(buf);
  635. kfree(envp);
  636. if (value != 0)
  637. HPSB_DEBUG("NodeMgr: hotplug policy returned %d", value);
  638. }
  639. #else
  640. static inline void
  641. nodemgr_call_policy(char *verb, struct unit_directory *ud)
  642. {
  643. #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
  644. HPSB_DEBUG("NodeMgr: nodemgr_call_policy(): hotplug not enabled");
  645. #endif
  646. return;
  647. #endif /* CONFIG_HOTPLUG */
  648. static void nodemgr_claim_unit_directory(struct unit_directory *ud,
  649.  struct hpsb_protocol_driver *driver)
  650. {
  651. ud->driver = driver;
  652. list_del(&ud->driver_list);
  653. list_add_tail(&ud->driver_list, &driver->unit_directories);
  654. }
  655. static void nodemgr_release_unit_directory(struct unit_directory *ud)
  656. {
  657. ud->driver = NULL;
  658. list_del(&ud->driver_list);
  659. list_add_tail(&ud->driver_list, &unit_directory_list);
  660. }
  661. void hpsb_release_unit_directory(struct unit_directory *ud)
  662. {
  663. down(&nodemgr_serialize);
  664. nodemgr_release_unit_directory(ud);
  665. up(&nodemgr_serialize);
  666. }
  667. static void nodemgr_free_unit_directories(struct node_entry *ne)
  668. {
  669. struct list_head *lh;
  670. struct unit_directory *ud;
  671. lh = ne->unit_directories.next;
  672. while (lh != &ne->unit_directories) {
  673. ud = list_entry(lh, struct unit_directory, node_list);
  674. lh = lh->next;
  675. if (ud->driver && ud->driver->disconnect)
  676. ud->driver->disconnect(ud);
  677. nodemgr_release_unit_directory(ud);
  678. nodemgr_call_policy("remove", ud);
  679. list_del(&ud->driver_list);
  680. kfree(ud);
  681. }
  682. }
  683. static struct ieee1394_device_id *
  684. nodemgr_match_driver(struct hpsb_protocol_driver *driver, 
  685.      struct unit_directory *ud)
  686. {
  687. struct ieee1394_device_id *id;
  688. for (id = driver->id_table; id->match_flags != 0; id++) {
  689. if ((id->match_flags & IEEE1394_MATCH_VENDOR_ID) &&
  690.     id->vendor_id != ud->vendor_id)
  691. continue;
  692. if ((id->match_flags & IEEE1394_MATCH_MODEL_ID) &&
  693.     id->model_id != ud->model_id)
  694. continue;
  695. if ((id->match_flags & IEEE1394_MATCH_SPECIFIER_ID) &&
  696.     id->specifier_id != ud->specifier_id)
  697. continue;
  698. if ((id->match_flags & IEEE1394_MATCH_VERSION) &&
  699.     id->version != ud->version)
  700. continue;
  701. return id;
  702. }
  703. return NULL;
  704. }
  705. static struct hpsb_protocol_driver *
  706. nodemgr_find_driver(struct unit_directory *ud)
  707. {
  708. struct list_head *l;
  709. struct hpsb_protocol_driver *match, *driver;
  710. struct ieee1394_device_id *device_id;
  711. match = NULL;
  712. list_for_each(l, &driver_list) {
  713. driver = list_entry(l, struct hpsb_protocol_driver, list);
  714. device_id = nodemgr_match_driver(driver, ud);
  715. if (device_id != NULL) {
  716. match = driver;
  717. break;
  718. }
  719. }
  720. return match;
  721. }
  722. static void nodemgr_bind_drivers (struct node_entry *ne)
  723. {
  724. struct list_head *lh;
  725. struct hpsb_protocol_driver *driver;
  726. struct unit_directory *ud;
  727. list_for_each(lh, &ne->unit_directories) {
  728. ud = list_entry(lh, struct unit_directory, node_list);
  729. driver = nodemgr_find_driver(ud);
  730. if (driver != NULL && driver->probe(ud) == 0)
  731. nodemgr_claim_unit_directory(ud, driver);
  732. nodemgr_call_policy("add", ud);
  733. }
  734. }
  735. int hpsb_register_protocol(struct hpsb_protocol_driver *driver)
  736. {
  737. struct unit_directory *ud;
  738. struct list_head *lh;
  739. if (down_interruptible(&nodemgr_serialize))
  740. return -EINTR;
  741. list_add_tail(&driver->list, &driver_list);
  742. INIT_LIST_HEAD(&driver->unit_directories);
  743. lh = unit_directory_list.next;
  744. while (lh != &unit_directory_list) {
  745. ud = list_entry(lh, struct unit_directory, driver_list);
  746. lh = lh->next;
  747. if (nodemgr_match_driver(driver, ud) && driver->probe(ud) == 0)
  748. nodemgr_claim_unit_directory(ud, driver);
  749. }
  750. up(&nodemgr_serialize);
  751. /*
  752.  * Right now registration always succeeds, but maybe we should
  753.  * detect clashes in protocols handled by other drivers.
  754.  */
  755. return 0;
  756. }
  757. void hpsb_unregister_protocol(struct hpsb_protocol_driver *driver)
  758. {
  759. struct list_head *lh;
  760. struct unit_directory *ud;
  761. down(&nodemgr_serialize);
  762. list_del(&driver->list);
  763. lh = driver->unit_directories.next;
  764. while (lh != &driver->unit_directories) {
  765. ud = list_entry(lh, struct unit_directory, driver_list);
  766. lh = lh->next;
  767. if (ud->driver && ud->driver->disconnect)
  768. ud->driver->disconnect(ud);
  769. nodemgr_release_unit_directory(ud);
  770. }
  771. up(&nodemgr_serialize);
  772. }
  773. static void nodemgr_process_config_rom(struct node_entry *ne, 
  774.        quadlet_t busoptions)
  775. {
  776. ne->busopt.irmc = (busoptions >> 31) & 1;
  777. ne->busopt.cmc = (busoptions >> 30) & 1;
  778. ne->busopt.isc = (busoptions >> 29) & 1;
  779. ne->busopt.bmc = (busoptions >> 28) & 1;
  780. ne->busopt.pmc = (busoptions >> 27) & 1;
  781. ne->busopt.cyc_clk_acc = (busoptions >> 16) & 0xff;
  782. ne->busopt.max_rec = 1 << (((busoptions >> 12) & 0xf) + 1);
  783. ne->busopt.generation = (busoptions >> 4) & 0xf;
  784. ne->busopt.lnkspd = busoptions & 0x7;
  785. #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
  786. HPSB_DEBUG("NodeMgr: raw=0x%08x irmc=%d cmc=%d isc=%d bmc=%d pmc=%d "
  787.    "cyc_clk_acc=%d max_rec=%d gen=%d lspd=%d",
  788.    busoptions, ne->busopt.irmc, ne->busopt.cmc,
  789.    ne->busopt.isc, ne->busopt.bmc, ne->busopt.pmc,
  790.    ne->busopt.cyc_clk_acc, ne->busopt.max_rec,
  791.    ne->busopt.generation, ne->busopt.lnkspd);
  792. #endif
  793. /*
  794.  * When the config rom changes we disconnect all drivers and
  795.  * free the cached unit directories and reread the whole
  796.  * thing.  If this was a new device, the call to
  797.  * nodemgr_disconnect_drivers is a no-op and all is well.
  798.  */
  799. nodemgr_free_unit_directories(ne);
  800. nodemgr_process_root_directory(ne);
  801. nodemgr_bind_drivers(ne);
  802. }
  803. /*
  804.  * This function updates nodes that were present on the bus before the
  805.  * reset and still are after the reset.  The nodeid and the config rom
  806.  * may have changed, and the drivers managing this device must be
  807.  * informed that this device just went through a bus reset, to allow
  808.  * the to take whatever actions required.
  809.  */
  810. static void nodemgr_update_node(struct node_entry *ne, quadlet_t busoptions,
  811.                                struct hpsb_host *host,
  812. nodeid_t nodeid, unsigned int generation)
  813. {
  814. struct list_head *lh;
  815. struct unit_directory *ud;
  816. if (ne->nodeid != nodeid) {
  817. HPSB_DEBUG("Node " NODE_BUS_FMT " changed to " NODE_BUS_FMT,
  818.    NODE_BUS_ARGS(ne->nodeid), NODE_BUS_ARGS(nodeid));
  819. ne->nodeid = nodeid;
  820. }
  821. if (ne->busopt.generation != ((busoptions >> 4) & 0xf))
  822. nodemgr_process_config_rom (ne, busoptions);
  823. /* Since that's done, we can declare this record current */
  824. ne->generation = generation;
  825. list_for_each (lh, &ne->unit_directories) {
  826. ud = list_entry (lh, struct unit_directory, node_list);
  827. if (ud->driver != NULL && ud->driver->update != NULL)
  828. ud->driver->update(ud);
  829. }
  830. }
  831. static int read_businfo_block(struct hpsb_host *host, nodeid_t nodeid, unsigned int generation,
  832.       quadlet_t *buffer, int buffer_length)
  833. {
  834. octlet_t addr = CSR_REGISTER_BASE + CSR_CONFIG_ROM;
  835. unsigned header_size;
  836. int i;
  837. /* IEEE P1212 says that devices should support 64byte block
  838.  * reads, aligned on 64byte boundaries. That doesn't seem to
  839.  * work though, and we are forced to doing quadlet sized
  840.  * reads.  */
  841. #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
  842. HPSB_INFO("Initiating ConfigROM request for node " NODE_BUS_FMT,
  843.   NODE_BUS_ARGS(nodeid));
  844. #endif
  845. /* 
  846.  * Must retry a few times if config rom read returns zero (how long?). Will
  847.  * not normally occur, but we should do the right thing. For example, with
  848.  * some sbp2 devices, the bridge chipset cannot return valid config rom reads
  849.  * immediately after power-on, since they need to detect the type of 
  850.  * device attached (disk or CD-ROM).
  851.  */
  852. for (i = 0; i < 4; i++) {
  853. if (nodemgr_read_quadlet(host, nodeid, generation,
  854.  addr, &buffer[0]) < 0) {
  855. HPSB_ERR("ConfigROM quadlet transaction error for node "
  856.  NODE_BUS_FMT, NODE_BUS_ARGS(nodeid));
  857. return -1;
  858. }
  859. if (buffer[0])
  860. break;
  861. set_current_state(TASK_INTERRUPTIBLE);
  862. if (schedule_timeout (HZ/4))
  863. return -1;
  864. }
  865. header_size = buffer[0] >> 24;
  866. addr += 4;
  867. if (header_size < 4) {
  868. HPSB_INFO("Node " NODE_BUS_FMT " has non-standard ROM "
  869.   "format (%d quads), cannot parse",
  870.   NODE_BUS_ARGS(nodeid), header_size);
  871. return -1;
  872. }
  873. for (i = 1; i < buffer_length; i++, addr += 4) {
  874. if (nodemgr_read_quadlet(host, nodeid, generation,
  875.  addr, &buffer[i]) < 0) {
  876. HPSB_ERR("ConfigROM quadlet transaction "
  877.  "error for node " NODE_BUS_FMT,
  878.  NODE_BUS_ARGS(nodeid));
  879. return -1;
  880. }
  881. }
  882. return 0;
  883. }
  884. static void nodemgr_remove_node(struct node_entry *ne)
  885. {
  886. HPSB_DEBUG("%s removed: Node[" NODE_BUS_FMT "]  GUID[%016Lx]  [%s]",
  887.    (ne->host->node_id == ne->nodeid) ? "Host" : "Device",
  888.    NODE_BUS_ARGS(ne->nodeid), (unsigned long long)ne->guid,
  889.    ne->vendor_name ?: "Unknown");
  890. nodemgr_free_unit_directories(ne);
  891. list_del(&ne->list);
  892. kfree(ne);
  893. return;
  894. }
  895. /* This is where we probe the nodes for their information and provided
  896.  * features.  */
  897. static void nodemgr_node_probe_one(struct hpsb_host *host,
  898.    nodeid_t nodeid, int generation)
  899. {
  900. struct node_entry *ne;
  901. quadlet_t buffer[5];
  902. octlet_t guid;
  903. /* We need to detect when the ConfigROM's generation has changed,
  904.  * so we only update the node's info when it needs to be.  */
  905. if (read_businfo_block (host, nodeid, generation,
  906. buffer, sizeof(buffer) >> 2))
  907. return;
  908. if (buffer[1] != IEEE1394_BUSID_MAGIC) {
  909. /* This isn't a 1394 device, but we let it slide. There
  910.  * was a report of a device with broken firmware which
  911.  * reported '2394' instead of '1394', which is obviously a
  912.  * mistake. One would hope that a non-1394 device never
  913.  * gets connected to Firewire bus. If someone does, we
  914.  * shouldn't be held responsible, so we'll allow it with a
  915.  * warning.  */
  916. HPSB_WARN("Node " NODE_BUS_FMT " has invalid busID magic [0x%08x]",
  917.  NODE_BUS_ARGS(nodeid), buffer[1]);
  918. }
  919. guid = ((u64)buffer[3] << 32) | buffer[4];
  920. ne = find_entry_by_guid(guid);
  921. if (!ne)
  922. nodemgr_create_node(guid, buffer[2], host, nodeid, generation);
  923. else
  924. nodemgr_update_node(ne, buffer[2], host, nodeid, generation);
  925. return;
  926. }
  927. static void nodemgr_node_probe_cleanup(struct hpsb_host *host, unsigned int generation)
  928. {
  929. struct list_head *lh, *next;
  930. struct node_entry *ne;
  931. /* Now check to see if we have any nodes that aren't referenced
  932.  * any longer.  */
  933. list_for_each_safe(lh, next, &node_list) {
  934. ne = list_entry(lh, struct node_entry, list);
  935. /* Only checking this host */
  936. if (ne->host != host)
  937. continue;
  938. /* If the generation didn't get updated, then either the
  939.  * node was removed, or it failed the above probe. Either
  940.  * way, we remove references to it, since they are
  941.  * invalid.  */
  942. if (ne->generation != generation)
  943. nodemgr_remove_node(ne);
  944. }
  945. return;
  946. }
  947. static void nodemgr_node_probe(struct hpsb_host *host)
  948. {
  949. int count;
  950. struct selfid *sid = (struct selfid *)host->topology_map;
  951. nodeid_t nodeid = LOCAL_BUS;
  952. unsigned int generation;
  953. /* Pause for 1/4 second, to make sure things settle down. If
  954.  * schedule_timeout returns non-zero, it means we caught a signal
  955.  * and need to return. */
  956. set_current_state(TASK_INTERRUPTIBLE);
  957. if (schedule_timeout (HZ/4))
  958. return;
  959. /* Now get the generation in which the node ID's we collect
  960.  * are valid.  During the bus scan we will use this generation
  961.  * for the read transactions, so that if another reset occurs
  962.  * during the scan the transactions will fail instead of
  963.  * returning bogus data. */
  964. generation = get_hpsb_generation(host);
  965. /* Scan each node on the bus */
  966. for (count = host->selfid_count; count; count--, sid++) {
  967. if (sid->extended)
  968. continue;
  969. if (!sid->link_active) {
  970. nodeid++;
  971. continue;
  972. }
  973. nodemgr_node_probe_one(host, nodeid++, generation);
  974. }
  975. /* If we had a bus reset while we were scanning the bus, it is
  976.  * possible that we did not probe all nodes.  In that case, we
  977.  * skip the clean up for now, since we could remove nodes that
  978.  * were still on the bus.  The bus reset increased
  979.  * hi->reset_sem, so there's a bus scan pending which will do
  980.  * the clean up eventually. */
  981. if (generation == get_hpsb_generation(host))
  982. nodemgr_node_probe_cleanup(host, generation);
  983. return;
  984. }
  985. static int nodemgr_host_thread(void *__hi)
  986. {
  987. struct host_info *hi = (struct host_info *)__hi;
  988. /* No userlevel access needed */
  989. daemonize();
  990. strcpy(current->comm, "knodemgrd");
  991. /* Sit and wait for a signal to probe the nodes on the bus. This
  992.  * happens when we get a bus reset. */
  993. while (!down_interruptible(&hi->reset_sem) &&
  994.        !down_interruptible(&nodemgr_serialize)) {
  995. nodemgr_node_probe(hi->host);
  996. up(&nodemgr_serialize);
  997. }
  998. #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
  999. HPSB_DEBUG ("NodeMgr: Exiting thread for %s", hi->host->driver->name);
  1000. #endif
  1001. complete_and_exit(&hi->exited, 0);
  1002. }
  1003. struct node_entry *hpsb_guid_get_entry(u64 guid)
  1004. {
  1005.         struct node_entry *ne;
  1006. down(&nodemgr_serialize);
  1007.         ne = find_entry_by_guid(guid);
  1008. up(&nodemgr_serialize);
  1009.         return ne;
  1010. }
  1011. struct node_entry *hpsb_nodeid_get_entry(nodeid_t nodeid)
  1012. {
  1013. struct node_entry *ne;
  1014. down(&nodemgr_serialize);
  1015. ne = find_entry_by_nodeid(nodeid);
  1016. up(&nodemgr_serialize);
  1017. return ne;
  1018. }
  1019. /* The following four convenience functions use a struct node_entry
  1020.  * for addressing a node on the bus.  They are intended for use by any
  1021.  * process context, not just the nodemgr thread, so we need to be a
  1022.  * little careful when reading out the node ID and generation.  The
  1023.  * thing that can go wrong is that we get the node ID, then a bus
  1024.  * reset occurs, and then we read the generation.  The node ID is
  1025.  * possibly invalid, but the generation is current, and we end up
  1026.  * sending a packet to a the wrong node.
  1027.  *
  1028.  * The solution is to make sure we read the generation first, so that
  1029.  * if a reset occurs in the process, we end up with a stale generation
  1030.  * and the transactions will fail instead of silently using wrong node
  1031.  * ID's.
  1032.  */
  1033. void hpsb_node_fill_packet(struct node_entry *ne, struct hpsb_packet *pkt)
  1034. {
  1035.         pkt->host = ne->host;
  1036.         pkt->generation = ne->generation;
  1037. barrier();
  1038.         pkt->node_id = ne->nodeid;
  1039. }
  1040. int hpsb_node_read(struct node_entry *ne, u64 addr,
  1041.    quadlet_t *buffer, size_t length)
  1042. {
  1043. unsigned int generation = ne->generation;
  1044. barrier();
  1045. return hpsb_read(ne->host, ne->nodeid, generation,
  1046.  addr, buffer, length);
  1047. }
  1048. int hpsb_node_write(struct node_entry *ne, u64 addr, 
  1049.     quadlet_t *buffer, size_t length)
  1050. {
  1051. unsigned int generation = ne->generation;
  1052. barrier();
  1053. return hpsb_write(ne->host, ne->nodeid, generation,
  1054.   addr, buffer, length);
  1055. }
  1056. int hpsb_node_lock(struct node_entry *ne, u64 addr, 
  1057.    int extcode, quadlet_t *data, quadlet_t arg)
  1058. {
  1059. unsigned int generation = ne->generation;
  1060. barrier();
  1061. return hpsb_lock(ne->host, ne->nodeid, generation,
  1062.  addr, extcode, data, arg);
  1063. }
  1064. static void nodemgr_add_host(struct hpsb_host *host)
  1065. {
  1066. struct host_info *hi = kmalloc (sizeof (struct host_info), GFP_KERNEL);
  1067. unsigned long flags;
  1068. if (!hi) {
  1069. HPSB_ERR ("NodeMgr: out of memory in add host");
  1070. return;
  1071. }
  1072. /* Initialize the hostinfo here and start the thread.  The
  1073.  * thread blocks on the reset semaphore until a bus reset
  1074.  * happens. */
  1075. hi->host = host;
  1076. INIT_LIST_HEAD(&hi->list);
  1077. init_completion(&hi->exited);
  1078.         sema_init(&hi->reset_sem, 0);
  1079. hi->pid = kernel_thread(nodemgr_host_thread, hi,
  1080. CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
  1081. if (hi->pid < 0) {
  1082. HPSB_ERR ("NodeMgr: failed to start NodeMgr thread for %s",
  1083.   host->driver->name);
  1084. kfree(hi);
  1085. return;
  1086. }
  1087. spin_lock_irqsave (&host_info_lock, flags);
  1088. list_add_tail (&hi->list, &host_info_list);
  1089. spin_unlock_irqrestore (&host_info_lock, flags);
  1090. return;
  1091. }
  1092. static void nodemgr_host_reset(struct hpsb_host *host)
  1093. {
  1094. struct list_head *lh;
  1095. struct host_info *hi = NULL;
  1096. unsigned long flags;
  1097. spin_lock_irqsave (&host_info_lock, flags);
  1098. list_for_each(lh, &host_info_list) {
  1099. struct host_info *myhi = list_entry(lh, struct host_info, list);
  1100. if (myhi->host == host) {
  1101. hi = myhi;
  1102. break;
  1103. }
  1104. }
  1105. if (hi != NULL) {
  1106. #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
  1107. HPSB_DEBUG ("NodeMgr: Processing host reset for %s", host->driver->name);
  1108. #endif
  1109. up(&hi->reset_sem);
  1110. } else
  1111. HPSB_ERR ("NodeMgr: could not process reset of non-existent host");
  1112. spin_unlock_irqrestore (&host_info_lock, flags);
  1113. return;
  1114. }
  1115. static void nodemgr_remove_host(struct hpsb_host *host)
  1116. {
  1117. struct list_head *lh, *next;
  1118. struct node_entry *ne;
  1119. unsigned long flags;
  1120. struct host_info *hi = NULL;
  1121. spin_lock_irqsave (&host_info_lock, flags);
  1122. list_for_each_safe(lh, next, &host_info_list) {
  1123. struct host_info *myhi = list_entry(lh, struct host_info, list);
  1124. if (myhi->host == host) {
  1125. list_del(&myhi->list);
  1126. hi = myhi;
  1127. break;
  1128. }
  1129. }
  1130. spin_unlock_irqrestore (&host_info_lock, flags);
  1131. if (hi) {
  1132. if (hi->pid >= 0) {
  1133. kill_proc(hi->pid, SIGTERM, 1);
  1134. wait_for_completion(&hi->exited);
  1135. }
  1136. kfree(hi);
  1137. }
  1138. else
  1139. HPSB_ERR("NodeMgr: host %s does not exist, cannot remove",
  1140.  host->driver->name);
  1141. down(&nodemgr_serialize);
  1142. /* Even if we fail the host_info part, remove all the node
  1143.  * entries.  */
  1144. list_for_each_safe(lh, next, &node_list) {
  1145. ne = list_entry(lh, struct node_entry, list);
  1146. if (ne->host == host)
  1147. nodemgr_remove_node(ne);
  1148. }
  1149. up(&nodemgr_serialize);
  1150. return;
  1151. }
  1152. static struct hpsb_highlevel_ops nodemgr_ops = {
  1153. .add_host = nodemgr_add_host,
  1154. .host_reset = nodemgr_host_reset,
  1155. .remove_host = nodemgr_remove_host,
  1156. };
  1157. static struct hpsb_highlevel *hl;
  1158. #define PROC_ENTRY "devices"
  1159. void init_ieee1394_nodemgr(int disable_hotplug)
  1160. {
  1161. nodemgr_disable_hotplug = disable_hotplug;
  1162. #ifdef CONFIG_PROC_FS
  1163. if (!create_proc_read_entry(PROC_ENTRY, 0444, ieee1394_procfs_entry, raw1394_read_proc, NULL))
  1164. HPSB_ERR("Can't create devices procfs entry");
  1165. #endif
  1166.         hl = hpsb_register_highlevel("Node manager", &nodemgr_ops);
  1167.         if (!hl) {
  1168. HPSB_ERR("NodeMgr: out of memory during ieee1394 initialization");
  1169.         }
  1170. }
  1171. void cleanup_ieee1394_nodemgr(void)
  1172. {
  1173.         hpsb_unregister_highlevel(hl);
  1174. #ifdef CONFIG_PROC_FS
  1175. remove_proc_entry(PROC_ENTRY, ieee1394_procfs_entry);
  1176. #endif
  1177. }