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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * This file is subject to the terms and conditions of the GNU General
  3.  * Public License.  See the file "COPYING" in the main directory of this
  4.  * archive for more details.
  5.  *
  6.  * Copyright (C) 2000 - 2001 by Kanoj Sarcar (kanoj@sgi.com)
  7.  * Copyright (C) 2000 - 2001 by Silicon Graphics, Inc.
  8.  */
  9. #include <linux/config.h>
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/sched.h>
  13. #include <linux/mmzone.h> /* for numnodes */
  14. #include <linux/mm.h>
  15. #include <asm/cpu.h>
  16. #include <asm/pgalloc.h>
  17. #include <asm/pgtable.h>
  18. #include <asm/sn/types.h>
  19. #include <asm/sn/sn0/addrs.h>
  20. #include <asm/sn/sn0/hubni.h>
  21. #include <asm/sn/sn0/hubio.h>
  22. #include <asm/sn/klconfig.h>
  23. #include <asm/sn/ioc3.h>
  24. #include <asm/mipsregs.h>
  25. #include <asm/sn/gda.h>
  26. #include <asm/sn/intr.h>
  27. #include <asm/current.h>
  28. #include <asm/smp.h>
  29. #include <asm/processor.h>
  30. #include <asm/mmu_context.h>
  31. #include <asm/sn/launch.h>
  32. #include <asm/sn/sn_private.h>
  33. #include <asm/sn/sn0/ip27.h>
  34. #include <asm/sn/mapped_kernel.h>
  35. #include <asm/sn/sn0/addrs.h>
  36. #include <asm/sn/gda.h>
  37. #define CPU_NONE (cpuid_t)-1
  38. /*
  39.  * The following should work till 64 nodes, ie 128p SN0s.
  40.  */
  41. #define CNODEMASK_CLRALL(p) (p) = 0
  42. #define CNODEMASK_TSTB(p, bit) ((p) & (1ULL << (bit)))
  43. #define CNODEMASK_SETB(p, bit) ((p) |= 1ULL << (bit))
  44. cpumask_t boot_cpumask;
  45. hubreg_t region_mask = 0;
  46. static int fine_mode = 0;
  47. int maxcpus;
  48. static spinlock_t hub_mask_lock = SPIN_LOCK_UNLOCKED;
  49. static cnodemask_t hub_init_mask;
  50. static atomic_t numstarted = ATOMIC_INIT(1);
  51. static int router_distance;
  52. nasid_t master_nasid = INVALID_NASID;
  53. cnodeid_t nasid_to_compact_node[MAX_NASIDS];
  54. nasid_t compact_to_nasid_node[MAX_COMPACT_NODES];
  55. cnodeid_t cpuid_to_compact_node[MAXCPUS];
  56. char node_distances[MAX_COMPACT_NODES][MAX_COMPACT_NODES];
  57. hubreg_t get_region(cnodeid_t cnode)
  58. {
  59. if (fine_mode)
  60. return COMPACT_TO_NASID_NODEID(cnode) >> NASID_TO_FINEREG_SHFT;
  61. else
  62. return COMPACT_TO_NASID_NODEID(cnode) >> NASID_TO_COARSEREG_SHFT;
  63. }
  64. static void gen_region_mask(hubreg_t *region_mask, int maxnodes)
  65. {
  66. cnodeid_t cnode;
  67. (*region_mask) = 0;
  68. for (cnode = 0; cnode < maxnodes; cnode++) {
  69. (*region_mask) |= 1ULL << get_region(cnode);
  70. }
  71. }
  72. int is_fine_dirmode(void)
  73. {
  74. return (((LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_REGIONSIZE_MASK)
  75. >> NSRI_REGIONSIZE_SHFT) & REGIONSIZE_FINE);
  76. }
  77. nasid_t get_actual_nasid(lboard_t *brd)
  78. {
  79. klhub_t *hub;
  80. if (!brd)
  81. return INVALID_NASID;
  82. /* find out if we are a completely disabled brd. */
  83. hub  = (klhub_t *)find_first_component(brd, KLSTRUCT_HUB);
  84. if (!hub)
  85. return INVALID_NASID;
  86. if (!(hub->hub_info.flags & KLINFO_ENABLE)) /* disabled node brd */
  87. return hub->hub_info.physid;
  88. else
  89. return brd->brd_nasid;
  90. }
  91. /* Tweak this for maximum number of CPUs to activate */
  92. static int max_cpus = NR_CPUS;
  93. int do_cpumask(cnodeid_t cnode, nasid_t nasid, cpumask_t *boot_cpumask,
  94. int *highest)
  95. {
  96. static int tot_cpus_found = 0;
  97. lboard_t *brd;
  98. klcpu_t *acpu;
  99. int cpus_found = 0;
  100. cpuid_t cpuid;
  101. brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
  102. do {
  103. acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU);
  104. while (acpu) {
  105. cpuid = acpu->cpu_info.virtid;
  106. /* cnode is not valid for completely disabled brds */
  107. if (get_actual_nasid(brd) == brd->brd_nasid)
  108. cpuid_to_compact_node[cpuid] = cnode;
  109. if (cpuid > *highest)
  110. *highest = cpuid;
  111. /* Only let it join in if it's marked enabled */
  112. if ((acpu->cpu_info.flags & KLINFO_ENABLE) &&
  113. (tot_cpus_found != max_cpus)) {
  114. CPUMASK_SETB(*boot_cpumask, cpuid);
  115. cpus_found++;
  116. tot_cpus_found++;
  117. }
  118. acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
  119. KLSTRUCT_CPU);
  120. }
  121. brd = KLCF_NEXT(brd);
  122. if (brd)
  123. brd = find_lboard(brd,KLTYPE_IP27);
  124. else
  125. break;
  126. } while (brd);
  127. return cpus_found;
  128. }
  129. cpuid_t cpu_node_probe(cpumask_t *boot_cpumask, int *numnodes)
  130. {
  131. int i, cpus = 0, highest = 0;
  132. gda_t *gdap = GDA;
  133. nasid_t nasid;
  134. /*
  135.  * Initialize the arrays to invalid nodeid (-1)
  136.  */
  137. for (i = 0; i < MAX_COMPACT_NODES; i++)
  138. compact_to_nasid_node[i] = INVALID_NASID;
  139. for (i = 0; i < MAX_NASIDS; i++)
  140. nasid_to_compact_node[i] = INVALID_CNODEID;
  141. for (i = 0; i < MAXCPUS; i++)
  142. cpuid_to_compact_node[i] = INVALID_CNODEID;
  143. *numnodes = 0;
  144. for (i = 0; i < MAX_COMPACT_NODES; i++) {
  145. if ((nasid = gdap->g_nasidtable[i]) == INVALID_NASID) {
  146. break;
  147. } else {
  148. compact_to_nasid_node[i] = nasid;
  149. nasid_to_compact_node[nasid] = i;
  150. (*numnodes)++;
  151. cpus += do_cpumask(i, nasid, boot_cpumask, &highest);
  152. }
  153. }
  154. /*
  155.  * Cpus are numbered in order of cnodes. Currently, disabled
  156.  * cpus are not numbered.
  157.  */
  158. return(highest + 1);
  159. }
  160. int cpu_enabled(cpuid_t cpu)
  161. {
  162. if (cpu == CPU_NONE)
  163. return 0;
  164. return (CPUMASK_TSTB(boot_cpumask, cpu) != 0);
  165. }
  166. void mlreset (void)
  167. {
  168. int i;
  169. void init_topology_matrix(void);
  170. void dump_topology(void);
  171. master_nasid = get_nasid();
  172. fine_mode = is_fine_dirmode();
  173. /*
  174.  * Probe for all CPUs - this creates the cpumask and
  175.  * sets up the mapping tables.
  176.  */
  177. CPUMASK_CLRALL(boot_cpumask);
  178. maxcpus = cpu_node_probe(&boot_cpumask, &numnodes);
  179. printk("Discovered %d cpus on %d nodesn", maxcpus, numnodes);
  180. init_topology_matrix();
  181. dump_topology();
  182. gen_region_mask(&region_mask, numnodes);
  183. CNODEMASK_CLRALL(hub_init_mask);
  184. setup_replication_mask(numnodes);
  185. /*
  186.  * Set all nodes' calias sizes to 8k
  187.  */
  188. for (i = 0; i < numnodes; i++) {
  189. nasid_t nasid;
  190. nasid = COMPACT_TO_NASID_NODEID(i);
  191. /*
  192.  * Always have node 0 in the region mask, otherwise
  193.  * CALIAS accesses get exceptions since the hub
  194.  * thinks it is a node 0 address.
  195.  */
  196. REMOTE_HUB_S(nasid, PI_REGION_PRESENT, (region_mask | 1));
  197. #ifdef CONFIG_REPLICATE_EXHANDLERS
  198. REMOTE_HUB_S(nasid, PI_CALIAS_SIZE, PI_CALIAS_SIZE_8K);
  199. #else
  200. REMOTE_HUB_S(nasid, PI_CALIAS_SIZE, PI_CALIAS_SIZE_0);
  201. #endif
  202. #ifdef LATER
  203. /*
  204.  * Set up all hubs to have a big window pointing at
  205.  * widget 0. Memory mode, widget 0, offset 0
  206.  */
  207. REMOTE_HUB_S(nasid, IIO_ITTE(SWIN0_BIGWIN),
  208. ((HUB_PIO_MAP_TO_MEM << IIO_ITTE_IOSP_SHIFT) |
  209. (0 << IIO_ITTE_WIDGET_SHIFT)));
  210. #endif
  211. }
  212. }
  213. void intr_clear_bits(nasid_t nasid, volatile hubreg_t *pend, int base_level,
  214. char *name)
  215. {
  216. volatile hubreg_t bits;
  217. int i;
  218. /* Check pending interrupts */
  219. if ((bits = HUB_L(pend)) != 0)
  220. for (i = 0; i < N_INTPEND_BITS; i++)
  221. if (bits & (1 << i))
  222. LOCAL_HUB_CLR_INTR(base_level + i);
  223. }
  224. void intr_clear_all(nasid_t nasid)
  225. {
  226. REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
  227. REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
  228. REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
  229. REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
  230. intr_clear_bits(nasid, REMOTE_HUB_ADDR(nasid, PI_INT_PEND0),
  231. INT_PEND0_BASELVL, "INT_PEND0");
  232. intr_clear_bits(nasid, REMOTE_HUB_ADDR(nasid, PI_INT_PEND1),
  233. INT_PEND1_BASELVL, "INT_PEND1");
  234. }
  235. void sn_mp_setup(void)
  236. {
  237. cnodeid_t cnode;
  238. #if 0
  239. cpuid_t cpu;
  240. #endif
  241. for (cnode = 0; cnode < numnodes; cnode++) {
  242. #if 0
  243. init_platform_nodepda();
  244. #endif
  245. intr_clear_all(COMPACT_TO_NASID_NODEID(cnode));
  246. }
  247. #if 0
  248. for (cpu = 0; cpu < maxcpus; cpu++) {
  249. init_platform_pda();
  250. }
  251. #endif
  252. }
  253. void per_hub_init(cnodeid_t cnode)
  254. {
  255. extern void pcibr_setup(cnodeid_t);
  256. cnodemask_t done;
  257. nasid_t nasid;
  258. nasid = COMPACT_TO_NASID_NODEID(cnode);
  259. spin_lock(&hub_mask_lock);
  260. /* Test our bit. */
  261. if (!(done = CNODEMASK_TSTB(hub_init_mask, cnode))) {
  262. /* Turn our bit on in the mask. */
  263. CNODEMASK_SETB(hub_init_mask, cnode);
  264. /*
  265.    * Do the actual initialization if it hasn't been done yet.
  266.    * We don't need to hold a lock for this work.
  267.    */
  268. /*
  269.  * Set CRB timeout at 5ms, (< PI timeout of 10ms)
  270.  */
  271. REMOTE_HUB_S(nasid, IIO_ICTP, 0x800);
  272. REMOTE_HUB_S(nasid, IIO_ICTO, 0xff);
  273. hub_rtc_init(cnode);
  274. pcibr_setup(cnode);
  275. #ifdef CONFIG_REPLICATE_EXHANDLERS
  276. /*
  277.  * If this is not a headless node initialization,
  278.  * copy over the caliased exception handlers.
  279.  */
  280. if (get_compact_nodeid() == cnode) {
  281. extern char except_vec0, except_vec1_r10k;
  282. extern char except_vec2_generic, except_vec3_generic;
  283. memcpy((void *)(KSEG0 + 0x100), &except_vec2_generic,
  284. 0x80);
  285. memcpy((void *)(KSEG0 + 0x180), &except_vec3_generic,
  286. 0x80);
  287. memcpy((void *)KSEG0, &except_vec0, 0x80);
  288. memcpy((void *)KSEG0 + 0x080, &except_vec1_r10k, 0x80);
  289. memcpy((void *)(KSEG0 + 0x100), (void *) KSEG0, 0x80);
  290. memcpy((void *)(KSEG0 + 0x180), &except_vec3_generic,
  291. 0x100);
  292. flush_cache_l1();
  293. flush_cache_l2();
  294. }
  295. #endif
  296. }
  297. spin_unlock(&hub_mask_lock);
  298. }
  299. /*
  300.  * This is similar to hard_smp_processor_id().
  301.  */
  302. cpuid_t getcpuid(void)
  303. {
  304. klcpu_t *klcpu;
  305. klcpu = nasid_slice_to_cpuinfo(get_nasid(),LOCAL_HUB_L(PI_CPU_NUM));
  306. return klcpu->cpu_info.virtid;
  307. }
  308. void per_cpu_init(void)
  309. {
  310. extern void install_cpu_nmi_handler(int slice);
  311. extern void load_mmu(void);
  312. static int is_slave = 0;
  313. int cpu = smp_processor_id();
  314. cnodeid_t cnode = get_compact_nodeid();
  315. TLBMISS_HANDLER_SETUP();
  316. #if 0
  317. intr_init();
  318. #endif
  319. clear_cp0_status(ST0_IM);
  320. per_hub_init(cnode);
  321. cpu_time_init();
  322. if (smp_processor_id()) /* master can't do this early, no kmalloc */
  323. install_cpuintr(cpu);
  324. /* Install our NMI handler if symmon hasn't installed one. */
  325. install_cpu_nmi_handler(cputoslice(cpu));
  326. #if 0
  327. install_tlbintr(cpu);
  328. #endif
  329. set_cp0_status(SRB_DEV0 | SRB_DEV1);
  330. if (is_slave) {
  331. clear_cp0_status(ST0_BEV);
  332. if (mips_cpu.isa_level == MIPS_CPU_ISA_IV)
  333. set_cp0_status(ST0_XX);
  334. set_cp0_status(ST0_KX|ST0_SX|ST0_UX);
  335. sti();
  336. load_mmu();
  337. atomic_inc(&numstarted);
  338. } else {
  339. is_slave = 1;
  340. }
  341. }
  342. cnodeid_t get_compact_nodeid(void)
  343. {
  344. nasid_t nasid;
  345. nasid = get_nasid();
  346. /*
  347.  * Map the physical node id to a virtual node id (virtual node ids
  348.  * are contiguous).
  349.  */
  350. return NASID_TO_COMPACT_NODEID(nasid);
  351. }
  352. #ifdef CONFIG_SMP
  353. /*
  354.  * Takes as first input the PROM assigned cpu id, and the kernel
  355.  * assigned cpu id as the second.
  356.  */
  357. static void alloc_cpupda(cpuid_t cpu, int cpunum)
  358. {
  359. cnodeid_t node;
  360. nasid_t nasid;
  361. node = get_cpu_cnode(cpu);
  362. nasid = COMPACT_TO_NASID_NODEID(node);
  363. cputonasid(cpunum) = nasid;
  364. cputocnode(cpunum) = node;
  365. cputoslice(cpunum) = get_cpu_slice(cpu);
  366. cpu_data[cpunum].p_cpuid = cpu;
  367. }
  368. static volatile cpumask_t boot_barrier;
  369. void __init start_secondary(void)
  370. {
  371. CPUMASK_CLRB(boot_barrier, getcpuid()); /* needs atomicity */
  372. per_cpu_init();
  373. per_cpu_trap_init();
  374. #if 0
  375. ecc_init();
  376. bte_lateinit();
  377. init_mfhi_war();
  378. #endif
  379. local_flush_tlb_all();
  380. flush_cache_l1();
  381. flush_cache_l2();
  382. start_secondary();
  383. }
  384. __init void allowboot(void)
  385. {
  386. int num_cpus = 0;
  387. cpuid_t cpu, mycpuid = getcpuid();
  388. cnodeid_t cnode;
  389. extern void smp_bootstrap(void);
  390. sn_mp_setup();
  391. /* Master has already done per_cpu_init() */
  392. install_cpuintr(smp_processor_id());
  393. #if 0
  394. bte_lateinit();
  395. ecc_init();
  396. #endif
  397. replicate_kernel_text(numnodes);
  398. boot_barrier = boot_cpumask;
  399. /* Launch slaves. */
  400. for (cpu = 0; cpu < maxcpus; cpu++) {
  401. if (cpu == mycpuid) {
  402. alloc_cpupda(cpu, num_cpus);
  403. num_cpus++;
  404. /* We're already started, clear our bit */
  405. CPUMASK_CLRB(boot_barrier, cpu);
  406. continue;
  407. }
  408. /* Skip holes in CPU space */
  409. if (CPUMASK_TSTB(boot_cpumask, cpu)) {
  410. struct task_struct *p;
  411. /*
  412.  * The following code is purely to make sure
  413.  * Linux can schedule processes on this slave.
  414.  */
  415. kernel_thread(0, NULL, CLONE_PID);
  416. p = init_task.prev_task;
  417. sprintf(p->comm, "%s%d", "Idle", num_cpus);
  418. init_tasks[num_cpus] = p;
  419. alloc_cpupda(cpu, num_cpus);
  420. del_from_runqueue(p);
  421. p->processor = num_cpus;
  422. p->cpus_runnable = 1 << num_cpus; /* we schedule the first task manually */
  423. unhash_process(p);
  424. /* Attach to the address space of init_task. */
  425. atomic_inc(&init_mm.mm_count);
  426. p->active_mm = &init_mm;
  427. /*
  428.    * Launch a slave into smp_bootstrap().
  429.    * It doesn't take an argument, and we
  430.  * set sp to the kernel stack of the newly
  431.  * created idle process, gp to the proc struct
  432.  * (so that current-> works).
  433.    */
  434. LAUNCH_SLAVE(cputonasid(num_cpus),cputoslice(num_cpus),
  435. (launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
  436. 0, (void *)((unsigned long)p +
  437. KERNEL_STACK_SIZE - 32), (void *)p);
  438. /*
  439.  * Now optimistically set the mapping arrays. We
  440.  * need to wait here, verify the cpu booted up, then
  441.  * fire up the next cpu.
  442.  */
  443. __cpu_number_map[cpu] = num_cpus;
  444. __cpu_logical_map[num_cpus] = cpu;
  445. CPUMASK_SETB(cpu_online_map, cpu);
  446. num_cpus++;
  447. /*
  448.  * Wait this cpu to start up and initialize its hub,
  449.  * and discover the io devices it will control.
  450.  *
  451.  * XXX: We really want to fire up launch all the CPUs
  452.  * at once.  We have to preserve the order of the
  453.  * devices on the bridges first though.
  454.  */
  455. while(atomic_read(&numstarted) != num_cpus);
  456. }
  457. }
  458. #ifdef LATER
  459. Wait logic goes here.
  460. #endif
  461. for (cnode = 0; cnode < numnodes; cnode++) {
  462. #if 0
  463. if (cnodetocpu(cnode) == -1) {
  464. printk("Initializing headless hub,cnode %d", cnode);
  465. per_hub_init(cnode);
  466. }
  467. #endif
  468. }
  469. #if 0
  470. cpu_io_setup();
  471. init_mfhi_war();
  472. #endif
  473. smp_num_cpus = num_cpus;
  474. }
  475. void __init smp_boot_cpus(void)
  476. {
  477. extern void allowboot(void);
  478. init_new_context(current, &init_mm);
  479. current->processor = 0;
  480. init_idle();
  481. smp_tune_scheduling();
  482. allowboot();
  483. }
  484. #else /* CONFIG_SMP */
  485. void __init start_secondary(void)
  486. {
  487. /* XXX Why do we need this empty definition at all?  */
  488. }
  489. #endif /* CONFIG_SMP */
  490. #define rou_rflag rou_flags
  491. void
  492. router_recurse(klrou_t *router_a, klrou_t *router_b, int depth)
  493. {
  494. klrou_t *router;
  495. lboard_t *brd;
  496. int port;
  497. if (router_a->rou_rflag == 1)
  498. return;
  499. if (depth >= router_distance)
  500. return;
  501. router_a->rou_rflag = 1;
  502. for (port = 1; port <= MAX_ROUTER_PORTS; port++) {
  503. if (router_a->rou_port[port].port_nasid == INVALID_NASID)
  504. continue;
  505. brd = (lboard_t *)NODE_OFFSET_TO_K0(
  506. router_a->rou_port[port].port_nasid,
  507. router_a->rou_port[port].port_offset);
  508. if (brd->brd_type == KLTYPE_ROUTER) {
  509. router = (klrou_t *)NODE_OFFSET_TO_K0(NASID_GET(brd), brd->brd_compts[0]);
  510. if (router == router_b) {
  511. if (depth < router_distance)
  512. router_distance = depth;
  513. }
  514. else
  515. router_recurse(router, router_b, depth + 1);
  516. }
  517. }
  518. router_a->rou_rflag = 0;
  519. }
  520. int
  521. node_distance(nasid_t nasid_a, nasid_t nasid_b)
  522. {
  523. nasid_t nasid;
  524. cnodeid_t cnode;
  525. lboard_t *brd, *dest_brd;
  526. int port;
  527. klrou_t *router, *router_a = NULL, *router_b = NULL;
  528. /* Figure out which routers nodes in question are connected to */
  529. for (cnode = 0; cnode < numnodes; cnode++) {
  530. nasid = COMPACT_TO_NASID_NODEID(cnode);
  531. if (nasid == -1) continue;
  532. brd = find_lboard_class((lboard_t *)KL_CONFIG_INFO(nasid),
  533. KLTYPE_ROUTER);
  534. if (!brd)
  535. continue;
  536. do {
  537. if (brd->brd_flags & DUPLICATE_BOARD)
  538. continue;
  539. router = (klrou_t *)NODE_OFFSET_TO_K0(NASID_GET(brd), brd->brd_compts[0]);
  540. router->rou_rflag = 0;
  541. for (port = 1; port <= MAX_ROUTER_PORTS; port++) {
  542. if (router->rou_port[port].port_nasid == INVALID_NASID)
  543. continue;
  544. dest_brd = (lboard_t *)NODE_OFFSET_TO_K0(
  545. router->rou_port[port].port_nasid,
  546. router->rou_port[port].port_offset);
  547. if (dest_brd->brd_type == KLTYPE_IP27) {
  548. if (dest_brd->brd_nasid == nasid_a)
  549. router_a = router;
  550. if (dest_brd->brd_nasid == nasid_b)
  551. router_b = router;
  552. }
  553. }
  554. } while ( (brd = find_lboard_class(KLCF_NEXT(brd), KLTYPE_ROUTER)) );
  555. }
  556. if (router_a == NULL) {
  557. printk("node_distance: router_a NULLn");
  558. return -1;
  559. }
  560. if (router_b == NULL) {
  561. printk("node_distance: router_b NULLn");
  562. return -1;
  563. }
  564. if (nasid_a == nasid_b)
  565. return 0;
  566. if (router_a == router_b)
  567. return 1;
  568. router_distance = 100;
  569. router_recurse(router_a, router_b, 2);
  570. return router_distance;
  571. }
  572. void
  573. init_topology_matrix(void)
  574. {
  575. nasid_t nasid, nasid2;
  576. cnodeid_t row, col;
  577. for (row = 0; row < MAX_COMPACT_NODES; row++)
  578. for (col = 0; col < MAX_COMPACT_NODES; col++)
  579. node_distances[row][col] = -1;
  580. for (row = 0; row < numnodes; row++) {
  581. nasid = COMPACT_TO_NASID_NODEID(row);
  582. for (col = 0; col < numnodes; col++) {
  583. nasid2 = COMPACT_TO_NASID_NODEID(col);
  584. node_distances[row][col] = node_distance(nasid, nasid2);
  585. }
  586. }
  587. }
  588. void
  589. dump_topology(void)
  590. {
  591. nasid_t nasid;
  592. cnodeid_t cnode;
  593. lboard_t *brd, *dest_brd;
  594. int port;
  595. int router_num = 0;
  596. klrou_t *router;
  597. cnodeid_t row, col;
  598. printk("************** Topology ********************n");
  599. printk("    ");
  600. for (col = 0; col < numnodes; col++)
  601. printk("%02d ", col);
  602. printk("n");
  603. for (row = 0; row < numnodes; row++) {
  604. printk("%02d  ", row);
  605. for (col = 0; col < numnodes; col++)
  606. printk("%2d ", node_distances[row][col]);
  607. printk("n");
  608. }
  609. for (cnode = 0; cnode < numnodes; cnode++) {
  610. nasid = COMPACT_TO_NASID_NODEID(cnode);
  611. if (nasid == -1) continue;
  612. brd = find_lboard_class((lboard_t *)KL_CONFIG_INFO(nasid),
  613. KLTYPE_ROUTER);
  614. if (!brd)
  615. continue;
  616. do {
  617. if (brd->brd_flags & DUPLICATE_BOARD)
  618. continue;
  619. printk("Router %d:", router_num);
  620. router_num++;
  621. router = (klrou_t *)NODE_OFFSET_TO_K0(NASID_GET(brd), brd->brd_compts[0]);
  622. for (port = 1; port <= MAX_ROUTER_PORTS; port++) {
  623. if (router->rou_port[port].port_nasid == INVALID_NASID)
  624. continue;
  625. dest_brd = (lboard_t *)NODE_OFFSET_TO_K0(
  626. router->rou_port[port].port_nasid,
  627. router->rou_port[port].port_offset);
  628. if (dest_brd->brd_type == KLTYPE_IP27)
  629. printk(" %d", dest_brd->brd_nasid);
  630. if (dest_brd->brd_type == KLTYPE_ROUTER)
  631. printk(" r");
  632. }
  633. printk("n");
  634. } while ( (brd = find_lboard_class(KLCF_NEXT(brd), KLTYPE_ROUTER)) );
  635. }
  636. }
  637. #if 0
  638. #define brd_widgetnum brd_slot
  639. #define NODE_OFFSET_TO_KLINFO(n,off)    ((klinfo_t*) TO_NODE_CAC(n,off))
  640. void
  641. dump_klcfg(void)
  642. {
  643. cnodeid_t       cnode;
  644. int i;
  645. nasid_t         nasid;
  646. lboard_t        *lbptr;
  647. gda_t           *gdap;
  648. gdap = (gda_t *)GDA_ADDR(get_nasid());
  649. if (gdap->g_magic != GDA_MAGIC) {
  650. printk("dumpklcfg_cmd: Invalid GDA MAGICn");
  651. return;
  652. }
  653. for (cnode = 0; cnode < MAX_COMPACT_NODES; cnode ++) {
  654. nasid = gdap->g_nasidtable[cnode];
  655. if (nasid == INVALID_NASID)
  656. continue;
  657. printk("nDumpping klconfig Nasid %d:n", nasid);
  658. lbptr = KL_CONFIG_INFO(nasid);
  659. while (lbptr) {
  660. printk("    %s, Nasid %d, Module %d, widget 0x%x, partition %d, NIC 0x%x lboard 0x%lx",
  661. "board name here", /* BOARD_NAME(lbptr->brd_type), */
  662. lbptr->brd_nasid, lbptr->brd_module,
  663. lbptr->brd_widgetnum,
  664. lbptr->brd_partition,
  665. (lbptr->brd_nic), lbptr);
  666. if (lbptr->brd_flags & DUPLICATE_BOARD)
  667. printk(" -D");
  668. printk("n");
  669. for (i = 0; i < lbptr->brd_numcompts; i++) {
  670. klinfo_t *kli;
  671. kli = NODE_OFFSET_TO_KLINFO(NASID_GET(lbptr), lbptr->brd_compts[i]);
  672. printk("        type %2d, flags 0x%04x, diagval %3d, physid %4d, virtid %2d: %sn",
  673. kli->struct_type,
  674. kli->flags,
  675. kli->diagval,
  676. kli->physid,
  677. kli->virtid,
  678. "comp. name here");
  679. /* COMPONENT_NAME(kli->struct_type)); */
  680. }
  681. lbptr = KLCF_NEXT(lbptr);
  682. }
  683. }
  684. printk("n");
  685. /* Useful to print router maps also */
  686. for (cnode = 0; cnode < MAX_COMPACT_NODES; cnode ++) {
  687. klrou_t *kr;
  688. int i;
  689.          nasid = gdap->g_nasidtable[cnode];
  690.          if (nasid == INVALID_NASID)
  691.              continue;
  692.          lbptr = KL_CONFIG_INFO(nasid);
  693.          while (lbptr) {
  694. lbptr = find_lboard_class(lbptr, KLCLASS_ROUTER);
  695. if(!lbptr)
  696. break;
  697. if (!KL_CONFIG_DUPLICATE_BOARD(lbptr)) {
  698. printk("%llx -> n", lbptr->brd_nic);
  699. kr = (klrou_t *)find_first_component(lbptr,
  700. KLSTRUCT_ROU);
  701. for (i = 1; i <= MAX_ROUTER_PORTS; i++) {
  702. printk("[%d, %llx]; ",
  703. kr->rou_port[i].port_nasid,
  704. kr->rou_port[i].port_offset);
  705. }
  706. printk("n");
  707. }
  708. lbptr = KLCF_NEXT(lbptr);
  709.          }
  710.          printk("n");
  711.      }
  712. dump_topology();
  713. }
  714. #endif