tlb_uv.c 21 KB

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