tlb_uv.c 23 KB

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