tlb_uv.c 23 KB

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