tlb_uv.c 21 KB

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