tlb_uv.c 21 KB

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