tlb_uv.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /*
  2. * SGI UltraViolet TLB flush routines.
  3. *
  4. * (c) 2008 Cliff Wickman <cpw@sgi.com>, SGI.
  5. *
  6. * This code is released under the GNU General Public License version 2 or
  7. * later.
  8. */
  9. #include <linux/mc146818rtc.h>
  10. #include <linux/proc_fs.h>
  11. #include <linux/kernel.h>
  12. #include <asm/mach-bigsmp/mach_apic.h>
  13. #include <asm/mmu_context.h>
  14. #include <asm/idle.h>
  15. #include <asm/genapic.h>
  16. #include <asm/uv/uv_hub.h>
  17. #include <asm/uv/uv_mmrs.h>
  18. #include <asm/uv/uv_bau.h>
  19. struct bau_control **uv_bau_table_bases;
  20. static int uv_bau_retry_limit;
  21. static int uv_nshift; /* position of pnode (which is nasid>>1) */
  22. static unsigned long uv_mmask;
  23. char *status_table[] = {
  24. "IDLE",
  25. "ACTIVE",
  26. "DESTINATION TIMEOUT",
  27. "SOURCE TIMEOUT"
  28. };
  29. DEFINE_PER_CPU(struct ptc_stats, ptcstats);
  30. DEFINE_PER_CPU(struct bau_control, bau_control);
  31. /*
  32. * Free a software acknowledge hardware resource by clearing its Pending
  33. * bit. This will return a reply to the sender.
  34. * If the message has timed out, a reply has already been sent by the
  35. * hardware but the resource has not been released. In that case our
  36. * clear of the Timeout bit (as well) will free the resource. No reply will
  37. * be sent (the hardware will only do one reply per message).
  38. */
  39. static void
  40. uv_reply_to_message(int resource,
  41. struct bau_payload_queue_entry *msg,
  42. struct bau_msg_status *msp)
  43. {
  44. int fw;
  45. fw = (1 << (resource + UV_SW_ACK_NPENDING)) | (1 << resource);
  46. msg->replied_to = 1;
  47. msg->sw_ack_vector = 0;
  48. if (msp)
  49. msp->seen_by.bits = 0;
  50. uv_write_local_mmr(UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, fw);
  51. return;
  52. }
  53. /*
  54. * Do all the things a cpu should do for a TLB shootdown message.
  55. * Other cpu's may come here at the same time for this message.
  56. */
  57. static void
  58. uv_bau_process_message(struct bau_payload_queue_entry *msg,
  59. int msg_slot, int sw_ack_slot)
  60. {
  61. int cpu;
  62. unsigned long this_cpu_mask;
  63. struct bau_msg_status *msp;
  64. msp = __get_cpu_var(bau_control).msg_statuses + msg_slot;
  65. cpu = uv_blade_processor_id();
  66. msg->number_of_cpus =
  67. uv_blade_nr_online_cpus(uv_node_to_blade_id(numa_node_id()));
  68. this_cpu_mask = (unsigned long)1 << cpu;
  69. if (msp->seen_by.bits & this_cpu_mask)
  70. return;
  71. atomic_or_long(&msp->seen_by.bits, this_cpu_mask);
  72. if (msg->replied_to == 1)
  73. return;
  74. if (msg->address == TLB_FLUSH_ALL) {
  75. local_flush_tlb();
  76. __get_cpu_var(ptcstats).alltlb++;
  77. } else {
  78. __flush_tlb_one(msg->address);
  79. __get_cpu_var(ptcstats).onetlb++;
  80. }
  81. __get_cpu_var(ptcstats).requestee++;
  82. atomic_inc_short(&msg->acknowledge_count);
  83. if (msg->number_of_cpus == msg->acknowledge_count)
  84. uv_reply_to_message(sw_ack_slot, msg, msp);
  85. return;
  86. }
  87. /*
  88. * Examine the payload queue on all the distribution nodes to see
  89. * which messages have not been seen, and which cpu(s) have not seen them.
  90. *
  91. * Returns the number of cpu's that have not responded.
  92. */
  93. static int
  94. uv_examine_destinations(struct bau_target_nodemask *distribution)
  95. {
  96. int sender;
  97. int i;
  98. int j;
  99. int k;
  100. int count = 0;
  101. struct bau_control *bau_tablesp;
  102. struct bau_payload_queue_entry *msg;
  103. struct bau_msg_status *msp;
  104. sender = smp_processor_id();
  105. for (i = 0; i < (sizeof(struct bau_target_nodemask) * BITSPERBYTE);
  106. i++) {
  107. if (bau_node_isset(i, distribution)) {
  108. bau_tablesp = uv_bau_table_bases[i];
  109. for (msg = bau_tablesp->va_queue_first, j = 0;
  110. j < DESTINATION_PAYLOAD_QUEUE_SIZE; msg++, j++) {
  111. if ((msg->sending_cpu == sender) &&
  112. (!msg->replied_to)) {
  113. msp = bau_tablesp->msg_statuses + j;
  114. printk(KERN_DEBUG
  115. "blade %d: address:%#lx %d of %d, not cpu(s): ",
  116. i, msg->address,
  117. msg->acknowledge_count,
  118. msg->number_of_cpus);
  119. for (k = 0; k < msg->number_of_cpus;
  120. k++) {
  121. if (!((long)1 << k & msp->
  122. seen_by.bits)) {
  123. count++;
  124. printk("%d ", k);
  125. }
  126. }
  127. printk("\n");
  128. }
  129. }
  130. }
  131. }
  132. return count;
  133. }
  134. /**
  135. * uv_flush_tlb_others - globally purge translation cache of a virtual
  136. * address or all TLB's
  137. * @cpumaskp: mask of all cpu's in which the address is to be removed
  138. * @mm: mm_struct containing virtual address range
  139. * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
  140. *
  141. * This is the entry point for initiating any UV global TLB shootdown.
  142. *
  143. * Purges the translation caches of all specified processors of the given
  144. * virtual address, or purges all TLB's on specified processors.
  145. *
  146. * The caller has derived the cpumaskp from the mm_struct and has subtracted
  147. * the local cpu from the mask. This function is called only if there
  148. * are bits set in the mask. (e.g. flush_tlb_page())
  149. *
  150. * The cpumaskp is converted into a nodemask of the nodes containing
  151. * the cpus.
  152. */
  153. int
  154. uv_flush_tlb_others(cpumask_t *cpumaskp, struct mm_struct *mm, unsigned long va)
  155. {
  156. int i;
  157. int blade;
  158. int cpu;
  159. int bit;
  160. int right_shift;
  161. int this_blade;
  162. int exams = 0;
  163. int tries = 0;
  164. long source_timeouts = 0;
  165. long destination_timeouts = 0;
  166. unsigned long index;
  167. unsigned long mmr_offset;
  168. unsigned long descriptor_status;
  169. struct bau_activation_descriptor *bau_desc;
  170. ktime_t time1, time2;
  171. cpu = uv_blade_processor_id();
  172. this_blade = uv_numa_blade_id();
  173. bau_desc = __get_cpu_var(bau_control).descriptor_base;
  174. bau_desc += (UV_ITEMS_PER_DESCRIPTOR * cpu);
  175. bau_nodes_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
  176. i = 0;
  177. for_each_cpu_mask(bit, *cpumaskp) {
  178. blade = uv_cpu_to_blade_id(bit);
  179. if (blade > (UV_DISTRIBUTION_SIZE - 1))
  180. BUG();
  181. if (blade == this_blade)
  182. continue;
  183. bau_node_set(blade, &bau_desc->distribution);
  184. /* leave the bits for the remote cpu's in the mask until
  185. success; on failure we fall back to the IPI method */
  186. i++;
  187. }
  188. if (i == 0)
  189. goto none_to_flush;
  190. __get_cpu_var(ptcstats).requestor++;
  191. __get_cpu_var(ptcstats).ntargeted += i;
  192. bau_desc->payload.address = va;
  193. bau_desc->payload.sending_cpu = smp_processor_id();
  194. if (cpu < UV_CPUS_PER_ACT_STATUS) {
  195. mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
  196. right_shift = cpu * UV_ACT_STATUS_SIZE;
  197. } else {
  198. mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
  199. right_shift =
  200. ((cpu - UV_CPUS_PER_ACT_STATUS) * UV_ACT_STATUS_SIZE);
  201. }
  202. time1 = ktime_get();
  203. retry:
  204. tries++;
  205. index = ((unsigned long)
  206. 1 << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) | cpu;
  207. uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
  208. while ((descriptor_status = (((unsigned long)
  209. uv_read_local_mmr(mmr_offset) >>
  210. right_shift) & UV_ACT_STATUS_MASK)) !=
  211. DESC_STATUS_IDLE) {
  212. if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
  213. source_timeouts++;
  214. if (source_timeouts > SOURCE_TIMEOUT_LIMIT)
  215. source_timeouts = 0;
  216. __get_cpu_var(ptcstats).s_retry++;
  217. goto retry;
  218. }
  219. /* spin here looking for progress at the destinations */
  220. if (descriptor_status == DESC_STATUS_DESTINATION_TIMEOUT) {
  221. destination_timeouts++;
  222. if (destination_timeouts > DESTINATION_TIMEOUT_LIMIT) {
  223. /* returns # of cpus not responding */
  224. if (uv_examine_destinations
  225. (&bau_desc->distribution) == 0) {
  226. __get_cpu_var(ptcstats).d_retry++;
  227. goto retry;
  228. }
  229. exams++;
  230. if (exams >= uv_bau_retry_limit) {
  231. printk(KERN_DEBUG
  232. "uv_flush_tlb_others");
  233. printk("giving up on cpu %d\n",
  234. smp_processor_id());
  235. goto unsuccessful;
  236. }
  237. /* delays can hang up the simulator
  238. udelay(1000);
  239. */
  240. destination_timeouts = 0;
  241. }
  242. }
  243. }
  244. if (tries > 1)
  245. __get_cpu_var(ptcstats).retriesok++;
  246. /* on success, clear the remote cpu's from the mask so we don't
  247. use the IPI method of shootdown on them */
  248. for_each_cpu_mask(bit, *cpumaskp) {
  249. blade = uv_cpu_to_blade_id(bit);
  250. if (blade == this_blade)
  251. continue;
  252. cpu_clear(bit, *cpumaskp);
  253. }
  254. unsuccessful:
  255. time2 = ktime_get();
  256. __get_cpu_var(ptcstats).sflush_ns += (time2.tv64 - time1.tv64);
  257. none_to_flush:
  258. if (cpus_empty(*cpumaskp))
  259. return 1;
  260. /* Cause the caller to do an IPI-style TLB shootdown on
  261. the cpu's still in the mask */
  262. __get_cpu_var(ptcstats).ptc_i++;
  263. return 0;
  264. }
  265. /*
  266. * The BAU message interrupt comes here. (registered by set_intr_gate)
  267. * See entry_64.S
  268. *
  269. * We received a broadcast assist message.
  270. *
  271. * Interrupts may have been disabled; this interrupt could represent
  272. * the receipt of several messages.
  273. *
  274. * All cores/threads on this node get this interrupt.
  275. * The last one to see it does the s/w ack.
  276. * (the resource will not be freed until noninterruptable cpus see this
  277. * interrupt; hardware will timeout the s/w ack and reply ERROR)
  278. */
  279. void
  280. uv_bau_message_interrupt(struct pt_regs *regs)
  281. {
  282. struct bau_payload_queue_entry *pqp;
  283. struct bau_payload_queue_entry *msg;
  284. struct pt_regs *old_regs = set_irq_regs(regs);
  285. ktime_t time1, time2;
  286. int msg_slot;
  287. int sw_ack_slot;
  288. int fw;
  289. int count = 0;
  290. unsigned long local_pnode;
  291. ack_APIC_irq();
  292. exit_idle();
  293. irq_enter();
  294. time1 = ktime_get();
  295. local_pnode = uv_blade_to_pnode(uv_numa_blade_id());
  296. pqp = __get_cpu_var(bau_control).va_queue_first;
  297. msg = __get_cpu_var(bau_control).bau_msg_head;
  298. while (msg->sw_ack_vector) {
  299. count++;
  300. fw = msg->sw_ack_vector;
  301. msg_slot = msg - pqp;
  302. sw_ack_slot = ffs(fw) - 1;
  303. uv_bau_process_message(msg, msg_slot, sw_ack_slot);
  304. msg++;
  305. if (msg > __get_cpu_var(bau_control).va_queue_last)
  306. msg = __get_cpu_var(bau_control).va_queue_first;
  307. __get_cpu_var(bau_control).bau_msg_head = msg;
  308. }
  309. if (!count)
  310. __get_cpu_var(ptcstats).nomsg++;
  311. else if (count > 1)
  312. __get_cpu_var(ptcstats).multmsg++;
  313. time2 = ktime_get();
  314. __get_cpu_var(ptcstats).dflush_ns += (time2.tv64 - time1.tv64);
  315. irq_exit();
  316. set_irq_regs(old_regs);
  317. return;
  318. }
  319. static void
  320. uv_enable_timeouts(void)
  321. {
  322. int i;
  323. int blade;
  324. int last_blade;
  325. int pnode;
  326. int cur_cpu = 0;
  327. unsigned long apicid;
  328. /* better if we had each_online_blade */
  329. last_blade = -1;
  330. for_each_online_node(i) {
  331. blade = uv_node_to_blade_id(i);
  332. if (blade == last_blade)
  333. continue;
  334. last_blade = blade;
  335. apicid = per_cpu(x86_cpu_to_apicid, cur_cpu);
  336. pnode = uv_blade_to_pnode(blade);
  337. cur_cpu += uv_blade_nr_possible_cpus(i);
  338. }
  339. return;
  340. }
  341. static void *
  342. uv_ptc_seq_start(struct seq_file *file, loff_t *offset)
  343. {
  344. if (*offset < num_possible_cpus())
  345. return offset;
  346. return NULL;
  347. }
  348. static void *
  349. uv_ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
  350. {
  351. (*offset)++;
  352. if (*offset < num_possible_cpus())
  353. return offset;
  354. return NULL;
  355. }
  356. static void
  357. uv_ptc_seq_stop(struct seq_file *file, void *data)
  358. {
  359. }
  360. /*
  361. * Display the statistics thru /proc
  362. * data points to the cpu number
  363. */
  364. static int
  365. uv_ptc_seq_show(struct seq_file *file, void *data)
  366. {
  367. struct ptc_stats *stat;
  368. int cpu;
  369. cpu = *(loff_t *)data;
  370. if (!cpu) {
  371. seq_printf(file,
  372. "# cpu requestor requestee one all sretry dretry ptc_i ");
  373. seq_printf(file,
  374. "sw_ack sflush_us dflush_us sok dnomsg dmult starget\n");
  375. }
  376. if (cpu < num_possible_cpus() && cpu_online(cpu)) {
  377. stat = &per_cpu(ptcstats, cpu);
  378. seq_printf(file, "cpu %d %ld %ld %ld %ld %ld %ld %ld ",
  379. cpu, stat->requestor,
  380. stat->requestee, stat->onetlb, stat->alltlb,
  381. stat->s_retry, stat->d_retry, stat->ptc_i);
  382. seq_printf(file, "%lx %ld %ld %ld %ld %ld %ld\n",
  383. uv_read_global_mmr64(uv_blade_to_pnode
  384. (uv_cpu_to_blade_id(cpu)),
  385. UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
  386. stat->sflush_ns / 1000, stat->dflush_ns / 1000,
  387. stat->retriesok, stat->nomsg,
  388. stat->multmsg, stat->ntargeted);
  389. }
  390. return 0;
  391. }
  392. /*
  393. * 0: display meaning of the statistics
  394. * >0: retry limit
  395. */
  396. static ssize_t
  397. uv_ptc_proc_write(struct file *file, const char __user *user,
  398. size_t count, loff_t *data)
  399. {
  400. long newmode;
  401. char optstr[64];
  402. if (copy_from_user(optstr, user, count))
  403. return -EFAULT;
  404. optstr[count - 1] = '\0';
  405. if (strict_strtoul(optstr, 10, &newmode) < 0) {
  406. printk(KERN_DEBUG "%s is invalid\n", optstr);
  407. return -EINVAL;
  408. }
  409. if (newmode == 0) {
  410. printk(KERN_DEBUG "# cpu: cpu number\n");
  411. printk(KERN_DEBUG
  412. "requestor: times this cpu was the flush requestor\n");
  413. printk(KERN_DEBUG
  414. "requestee: times this cpu was requested to flush its TLBs\n");
  415. printk(KERN_DEBUG
  416. "one: times requested to flush a single address\n");
  417. printk(KERN_DEBUG
  418. "all: times requested to flush all TLB's\n");
  419. printk(KERN_DEBUG
  420. "sretry: number of retries of source-side timeouts\n");
  421. printk(KERN_DEBUG
  422. "dretry: number of retries of destination-side timeouts\n");
  423. printk(KERN_DEBUG
  424. "ptc_i: times UV fell through to IPI-style flushes\n");
  425. printk(KERN_DEBUG
  426. "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
  427. printk(KERN_DEBUG
  428. "sflush_us: microseconds spent in uv_flush_tlb_others()\n");
  429. printk(KERN_DEBUG
  430. "dflush_us: microseconds spent in handling flush requests\n");
  431. printk(KERN_DEBUG "sok: successes on retry\n");
  432. printk(KERN_DEBUG "dnomsg: interrupts with no message\n");
  433. printk(KERN_DEBUG
  434. "dmult: interrupts with multiple messages\n");
  435. printk(KERN_DEBUG "starget: nodes targeted\n");
  436. } else {
  437. uv_bau_retry_limit = newmode;
  438. printk(KERN_DEBUG "timeout retry limit:%d\n",
  439. uv_bau_retry_limit);
  440. }
  441. return count;
  442. }
  443. static const struct seq_operations uv_ptc_seq_ops = {
  444. .start = uv_ptc_seq_start,
  445. .next = uv_ptc_seq_next,
  446. .stop = uv_ptc_seq_stop,
  447. .show = uv_ptc_seq_show
  448. };
  449. static int
  450. uv_ptc_proc_open(struct inode *inode, struct file *file)
  451. {
  452. return seq_open(file, &uv_ptc_seq_ops);
  453. }
  454. static const struct file_operations proc_uv_ptc_operations = {
  455. .open = uv_ptc_proc_open,
  456. .read = seq_read,
  457. .write = uv_ptc_proc_write,
  458. .llseek = seq_lseek,
  459. .release = seq_release,
  460. };
  461. static struct proc_dir_entry *proc_uv_ptc;
  462. static int __init
  463. uv_ptc_init(void)
  464. {
  465. static struct proc_dir_entry *sgi_proc_dir;
  466. sgi_proc_dir = NULL;
  467. if (!is_uv_system())
  468. return 0;
  469. sgi_proc_dir = proc_mkdir("sgi_uv", NULL);
  470. if (!sgi_proc_dir)
  471. return -EINVAL;
  472. proc_uv_ptc = create_proc_entry(UV_PTC_BASENAME, 0444, NULL);
  473. if (!proc_uv_ptc) {
  474. printk(KERN_ERR "unable to create %s proc entry\n",
  475. UV_PTC_BASENAME);
  476. return -EINVAL;
  477. }
  478. proc_uv_ptc->proc_fops = &proc_uv_ptc_operations;
  479. return 0;
  480. }
  481. static void __exit
  482. uv_ptc_exit(void)
  483. {
  484. remove_proc_entry(UV_PTC_BASENAME, NULL);
  485. }
  486. module_init(uv_ptc_init);
  487. module_exit(uv_ptc_exit);
  488. /*
  489. * Initialization of BAU-related structures
  490. */
  491. int __init
  492. uv_bau_init(void)
  493. {
  494. int i;
  495. int j;
  496. int blade;
  497. int nblades;
  498. int *ip;
  499. int pnode;
  500. int last_blade;
  501. int cur_cpu = 0;
  502. unsigned long pa;
  503. unsigned long n;
  504. unsigned long m;
  505. unsigned long mmr_image;
  506. unsigned long apicid;
  507. char *cp;
  508. struct bau_control *bau_tablesp;
  509. struct bau_activation_descriptor *adp, *ad2;
  510. struct bau_payload_queue_entry *pqp;
  511. struct bau_msg_status *msp;
  512. struct bau_control *bcp;
  513. if (!is_uv_system())
  514. return 0;
  515. uv_bau_retry_limit = 1;
  516. if ((sizeof(struct bau_local_cpumask) * BITSPERBYTE) <
  517. MAX_CPUS_PER_NODE) {
  518. printk(KERN_ERR
  519. "uv_bau_init: bau_local_cpumask.bits too small\n");
  520. BUG();
  521. }
  522. uv_nshift = uv_hub_info->n_val;
  523. uv_mmask = ((unsigned long)1 << uv_hub_info->n_val) - 1;
  524. nblades = 0;
  525. last_blade = -1;
  526. for_each_online_node(i) {
  527. blade = uv_node_to_blade_id(i);
  528. if (blade == last_blade)
  529. continue;
  530. last_blade = blade;
  531. nblades++;
  532. }
  533. uv_bau_table_bases = (struct bau_control **)
  534. kmalloc(nblades * sizeof(struct bau_control *), GFP_KERNEL);
  535. if (!uv_bau_table_bases)
  536. BUG();
  537. /* better if we had each_online_blade */
  538. last_blade = -1;
  539. for_each_online_node(i) {
  540. blade = uv_node_to_blade_id(i);
  541. if (blade == last_blade)
  542. continue;
  543. last_blade = blade;
  544. bau_tablesp =
  545. kmalloc_node(sizeof(struct bau_control), GFP_KERNEL, i);
  546. if (!bau_tablesp)
  547. BUG();
  548. bau_tablesp->msg_statuses =
  549. kmalloc_node(sizeof(struct bau_msg_status) *
  550. DESTINATION_PAYLOAD_QUEUE_SIZE, GFP_KERNEL, i);
  551. if (!bau_tablesp->msg_statuses)
  552. BUG();
  553. for (j = 0, msp = bau_tablesp->msg_statuses;
  554. j < DESTINATION_PAYLOAD_QUEUE_SIZE; j++, msp++) {
  555. bau_cpubits_clear(&msp->seen_by, (int)
  556. uv_blade_nr_possible_cpus(blade));
  557. }
  558. bau_tablesp->watching =
  559. kmalloc_node(sizeof(int) * DESTINATION_NUM_RESOURCES,
  560. GFP_KERNEL, i);
  561. if (!bau_tablesp->watching)
  562. BUG();
  563. for (j = 0, ip = bau_tablesp->watching;
  564. j < DESTINATION_PAYLOAD_QUEUE_SIZE; j++, ip++) {
  565. *ip = 0;
  566. }
  567. uv_bau_table_bases[i] = bau_tablesp;
  568. pnode = uv_blade_to_pnode(blade);
  569. if (sizeof(struct bau_activation_descriptor) != 64)
  570. BUG();
  571. adp = (struct bau_activation_descriptor *)
  572. kmalloc_node(16384, GFP_KERNEL, i);
  573. if (!adp)
  574. BUG();
  575. if ((unsigned long)adp & 0xfff)
  576. BUG();
  577. pa = __pa((unsigned long)adp);
  578. n = pa >> uv_nshift;
  579. m = pa & uv_mmask;
  580. mmr_image = uv_read_global_mmr64(pnode,
  581. UVH_LB_BAU_SB_DESCRIPTOR_BASE);
  582. if (mmr_image)
  583. uv_write_global_mmr64(pnode, (unsigned long)
  584. UVH_LB_BAU_SB_DESCRIPTOR_BASE,
  585. (n << UV_DESC_BASE_PNODE_SHIFT |
  586. m));
  587. for (j = 0, ad2 = adp; j < UV_ACTIVATION_DESCRIPTOR_SIZE;
  588. j++, ad2++) {
  589. memset(ad2, 0,
  590. sizeof(struct bau_activation_descriptor));
  591. ad2->header.sw_ack_flag = 1;
  592. ad2->header.base_dest_nodeid =
  593. uv_blade_to_pnode(uv_cpu_to_blade_id(0));
  594. ad2->header.command = UV_NET_ENDPOINT_INTD;
  595. ad2->header.int_both = 1;
  596. /* all others need to be set to zero:
  597. fairness chaining multilevel count replied_to */
  598. }
  599. pqp = (struct bau_payload_queue_entry *)
  600. kmalloc_node((DESTINATION_PAYLOAD_QUEUE_SIZE + 1) *
  601. sizeof(struct bau_payload_queue_entry),
  602. GFP_KERNEL, i);
  603. if (!pqp)
  604. BUG();
  605. if (sizeof(struct bau_payload_queue_entry) != 32)
  606. BUG();
  607. if ((unsigned long)(&((struct bau_payload_queue_entry *)0)->
  608. sw_ack_vector) != 15)
  609. BUG();
  610. cp = (char *)pqp + 31;
  611. pqp = (struct bau_payload_queue_entry *)
  612. (((unsigned long)cp >> 5) << 5);
  613. bau_tablesp->va_queue_first = pqp;
  614. uv_write_global_mmr64(pnode,
  615. UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
  616. ((unsigned long)pnode <<
  617. UV_PAYLOADQ_PNODE_SHIFT) |
  618. uv_physnodeaddr(pqp));
  619. uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
  620. uv_physnodeaddr(pqp));
  621. bau_tablesp->va_queue_last =
  622. pqp + (DESTINATION_PAYLOAD_QUEUE_SIZE - 1);
  623. uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
  624. (unsigned long)
  625. uv_physnodeaddr(bau_tablesp->
  626. va_queue_last));
  627. memset(pqp, 0, sizeof(struct bau_payload_queue_entry) *
  628. DESTINATION_PAYLOAD_QUEUE_SIZE);
  629. /* this initialization can't be in firmware because the
  630. messaging IRQ will be determined by the OS */
  631. apicid = per_cpu(x86_cpu_to_apicid, cur_cpu);
  632. pa = uv_read_global_mmr64(pnode, UVH_BAU_DATA_CONFIG);
  633. if ((pa & 0xff) != UV_BAU_MESSAGE) {
  634. uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
  635. ((apicid << 32) |
  636. UV_BAU_MESSAGE));
  637. }
  638. for (j = cur_cpu; j < (cur_cpu + uv_blade_nr_possible_cpus(i));
  639. j++) {
  640. bcp = (struct bau_control *)&per_cpu(bau_control, j);
  641. bcp->bau_msg_head = bau_tablesp->va_queue_first;
  642. bcp->va_queue_first = bau_tablesp->va_queue_first;
  643. bcp->va_queue_last = bau_tablesp->va_queue_last;
  644. bcp->watching = bau_tablesp->watching;
  645. bcp->msg_statuses = bau_tablesp->msg_statuses;
  646. bcp->descriptor_base = adp;
  647. }
  648. cur_cpu += uv_blade_nr_possible_cpus(i);
  649. }
  650. set_intr_gate(UV_BAU_MESSAGE, uv_bau_message_intr1);
  651. uv_enable_timeouts();
  652. return 0;
  653. }
  654. __initcall(uv_bau_init);