tlb_uv.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. /*
  2. * SGI UltraViolet TLB flush routines.
  3. *
  4. * (c) 2008 Cliff Wickman <cpw@sgi.com>, SGI.
  5. *
  6. * This code is released under the GNU General Public License version 2 or
  7. * later.
  8. */
  9. #include <linux/seq_file.h>
  10. #include <linux/proc_fs.h>
  11. #include <linux/kernel.h>
  12. #include <asm/mmu_context.h>
  13. #include <asm/uv/uv.h>
  14. #include <asm/uv/uv_mmrs.h>
  15. #include <asm/uv/uv_hub.h>
  16. #include <asm/uv/uv_bau.h>
  17. #include <asm/apic.h>
  18. #include <asm/idle.h>
  19. #include <asm/tsc.h>
  20. #include <asm/irq_vectors.h>
  21. static struct bau_control **uv_bau_table_bases __read_mostly;
  22. static int uv_bau_retry_limit __read_mostly;
  23. /* position of pnode (which is nasid>>1): */
  24. static int uv_nshift __read_mostly;
  25. static unsigned long uv_mmask __read_mostly;
  26. static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
  27. static DEFINE_PER_CPU(struct bau_control, bau_control);
  28. /*
  29. * 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. BUG();
  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. /**
  279. * uv_flush_tlb_others - globally purge translation cache of a virtual
  280. * address or all TLB's
  281. * @cpumask: mask of all cpu's in which the address is to be removed
  282. * @mm: mm_struct containing virtual address range
  283. * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
  284. * @cpu: the current cpu
  285. *
  286. * This is the entry point for initiating any UV global TLB shootdown.
  287. *
  288. * Purges the translation caches of all specified processors of the given
  289. * virtual address, or purges all TLB's on specified processors.
  290. *
  291. * The caller has derived the cpumask from the mm_struct. This function
  292. * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
  293. *
  294. * The cpumask is converted into a nodemask of the nodes containing
  295. * the cpus.
  296. *
  297. * Note that this function should be called with preemption disabled.
  298. *
  299. * Returns NULL if all remote flushing was done.
  300. * Returns pointer to cpumask if some remote flushing remains to be
  301. * done. The returned pointer is valid till preemption is re-enabled.
  302. */
  303. const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
  304. struct mm_struct *mm,
  305. unsigned long va, unsigned int cpu)
  306. {
  307. static DEFINE_PER_CPU(cpumask_t, flush_tlb_mask);
  308. struct cpumask *flush_mask = &__get_cpu_var(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, &bau_desc->distribution);
  331. i++;
  332. }
  333. if (i == 0) {
  334. /*
  335. * no off_node flushing; return status for local node
  336. */
  337. if (locals)
  338. return flush_mask;
  339. else
  340. return NULL;
  341. }
  342. __get_cpu_var(ptcstats).requestor++;
  343. __get_cpu_var(ptcstats).ntargeted += i;
  344. bau_desc->payload.address = va;
  345. bau_desc->payload.sending_cpu = cpu;
  346. return uv_flush_send_and_wait(uv_cpu, this_pnode, bau_desc, flush_mask);
  347. }
  348. /*
  349. * The BAU message interrupt comes here. (registered by set_intr_gate)
  350. * See entry_64.S
  351. *
  352. * We received a broadcast assist message.
  353. *
  354. * Interrupts may have been disabled; this interrupt could represent
  355. * the receipt of several messages.
  356. *
  357. * All cores/threads on this node get this interrupt.
  358. * The last one to see it does the s/w ack.
  359. * (the resource will not be freed until noninterruptable cpus see this
  360. * interrupt; hardware will timeout the s/w ack and reply ERROR)
  361. */
  362. void uv_bau_message_interrupt(struct pt_regs *regs)
  363. {
  364. struct bau_payload_queue_entry *va_queue_first;
  365. struct bau_payload_queue_entry *va_queue_last;
  366. struct bau_payload_queue_entry *msg;
  367. struct pt_regs *old_regs = set_irq_regs(regs);
  368. cycles_t time1;
  369. cycles_t time2;
  370. int msg_slot;
  371. int sw_ack_slot;
  372. int fw;
  373. int count = 0;
  374. unsigned long local_pnode;
  375. ack_APIC_irq();
  376. exit_idle();
  377. irq_enter();
  378. time1 = get_cycles();
  379. local_pnode = uv_blade_to_pnode(uv_numa_blade_id());
  380. va_queue_first = __get_cpu_var(bau_control).va_queue_first;
  381. va_queue_last = __get_cpu_var(bau_control).va_queue_last;
  382. msg = __get_cpu_var(bau_control).bau_msg_head;
  383. while (msg->sw_ack_vector) {
  384. count++;
  385. fw = msg->sw_ack_vector;
  386. msg_slot = msg - va_queue_first;
  387. sw_ack_slot = ffs(fw) - 1;
  388. uv_bau_process_message(msg, msg_slot, sw_ack_slot);
  389. msg++;
  390. if (msg > va_queue_last)
  391. msg = va_queue_first;
  392. __get_cpu_var(bau_control).bau_msg_head = msg;
  393. }
  394. if (!count)
  395. __get_cpu_var(ptcstats).nomsg++;
  396. else if (count > 1)
  397. __get_cpu_var(ptcstats).multmsg++;
  398. time2 = get_cycles();
  399. __get_cpu_var(ptcstats).dflush += (time2 - time1);
  400. irq_exit();
  401. set_irq_regs(old_regs);
  402. }
  403. /*
  404. * uv_enable_timeouts
  405. *
  406. * Each target blade (i.e. blades that have cpu's) needs to have
  407. * shootdown message timeouts enabled. The timeout does not cause
  408. * an interrupt, but causes an error message to be returned to
  409. * the sender.
  410. */
  411. static void uv_enable_timeouts(void)
  412. {
  413. int blade;
  414. int nblades;
  415. int pnode;
  416. unsigned long mmr_image;
  417. nblades = uv_num_possible_blades();
  418. for (blade = 0; blade < nblades; blade++) {
  419. if (!uv_blade_nr_possible_cpus(blade))
  420. continue;
  421. pnode = uv_blade_to_pnode(blade);
  422. mmr_image =
  423. uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL);
  424. /*
  425. * Set the timeout period and then lock it in, in three
  426. * steps; captures and locks in the period.
  427. *
  428. * To program the period, the SOFT_ACK_MODE must be off.
  429. */
  430. mmr_image &= ~((unsigned long)1 <<
  431. UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT);
  432. uv_write_global_mmr64
  433. (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
  434. /*
  435. * Set the 4-bit period.
  436. */
  437. mmr_image &= ~((unsigned long)0xf <<
  438. UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT);
  439. mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD <<
  440. UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT);
  441. uv_write_global_mmr64
  442. (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
  443. /*
  444. * Subsequent reversals of the timebase bit (3) cause an
  445. * immediate timeout of one or all INTD resources as
  446. * indicated in bits 2:0 (7 causes all of them to timeout).
  447. */
  448. mmr_image |= ((unsigned long)1 <<
  449. UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT);
  450. uv_write_global_mmr64
  451. (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
  452. }
  453. }
  454. static void *uv_ptc_seq_start(struct seq_file *file, loff_t *offset)
  455. {
  456. if (*offset < num_possible_cpus())
  457. return offset;
  458. return NULL;
  459. }
  460. static void *uv_ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
  461. {
  462. (*offset)++;
  463. if (*offset < num_possible_cpus())
  464. return offset;
  465. return NULL;
  466. }
  467. static void uv_ptc_seq_stop(struct seq_file *file, void *data)
  468. {
  469. }
  470. /*
  471. * Display the statistics thru /proc
  472. * data points to the cpu number
  473. */
  474. static int uv_ptc_seq_show(struct seq_file *file, void *data)
  475. {
  476. struct ptc_stats *stat;
  477. int cpu;
  478. cpu = *(loff_t *)data;
  479. if (!cpu) {
  480. seq_printf(file,
  481. "# cpu requestor requestee one all sretry dretry ptc_i ");
  482. seq_printf(file,
  483. "sw_ack sflush dflush sok dnomsg dmult starget\n");
  484. }
  485. if (cpu < num_possible_cpus() && cpu_online(cpu)) {
  486. stat = &per_cpu(ptcstats, cpu);
  487. seq_printf(file, "cpu %d %ld %ld %ld %ld %ld %ld %ld ",
  488. cpu, stat->requestor,
  489. stat->requestee, stat->onetlb, stat->alltlb,
  490. stat->s_retry, stat->d_retry, stat->ptc_i);
  491. seq_printf(file, "%lx %ld %ld %ld %ld %ld %ld\n",
  492. uv_read_global_mmr64(uv_cpu_to_pnode(cpu),
  493. UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
  494. stat->sflush, stat->dflush,
  495. stat->retriesok, stat->nomsg,
  496. stat->multmsg, stat->ntargeted);
  497. }
  498. return 0;
  499. }
  500. /*
  501. * 0: display meaning of the statistics
  502. * >0: retry limit
  503. */
  504. static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
  505. size_t count, loff_t *data)
  506. {
  507. long newmode;
  508. char optstr[64];
  509. if (count == 0 || count > sizeof(optstr))
  510. return -EINVAL;
  511. if (copy_from_user(optstr, user, count))
  512. return -EFAULT;
  513. optstr[count - 1] = '\0';
  514. if (strict_strtoul(optstr, 10, &newmode) < 0) {
  515. printk(KERN_DEBUG "%s is invalid\n", optstr);
  516. return -EINVAL;
  517. }
  518. if (newmode == 0) {
  519. printk(KERN_DEBUG "# cpu: cpu number\n");
  520. printk(KERN_DEBUG
  521. "requestor: times this cpu was the flush requestor\n");
  522. printk(KERN_DEBUG
  523. "requestee: times this cpu was requested to flush its TLBs\n");
  524. printk(KERN_DEBUG
  525. "one: times requested to flush a single address\n");
  526. printk(KERN_DEBUG
  527. "all: times requested to flush all TLB's\n");
  528. printk(KERN_DEBUG
  529. "sretry: number of retries of source-side timeouts\n");
  530. printk(KERN_DEBUG
  531. "dretry: number of retries of destination-side timeouts\n");
  532. printk(KERN_DEBUG
  533. "ptc_i: times UV fell through to IPI-style flushes\n");
  534. printk(KERN_DEBUG
  535. "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
  536. printk(KERN_DEBUG
  537. "sflush_us: cycles spent in uv_flush_tlb_others()\n");
  538. printk(KERN_DEBUG
  539. "dflush_us: cycles spent in handling flush requests\n");
  540. printk(KERN_DEBUG "sok: successes on retry\n");
  541. printk(KERN_DEBUG "dnomsg: interrupts with no message\n");
  542. printk(KERN_DEBUG
  543. "dmult: interrupts with multiple messages\n");
  544. printk(KERN_DEBUG "starget: nodes targeted\n");
  545. } else {
  546. uv_bau_retry_limit = newmode;
  547. printk(KERN_DEBUG "timeout retry limit:%d\n",
  548. uv_bau_retry_limit);
  549. }
  550. return count;
  551. }
  552. static const struct seq_operations uv_ptc_seq_ops = {
  553. .start = uv_ptc_seq_start,
  554. .next = uv_ptc_seq_next,
  555. .stop = uv_ptc_seq_stop,
  556. .show = uv_ptc_seq_show
  557. };
  558. static int uv_ptc_proc_open(struct inode *inode, struct file *file)
  559. {
  560. return seq_open(file, &uv_ptc_seq_ops);
  561. }
  562. static const struct file_operations proc_uv_ptc_operations = {
  563. .open = uv_ptc_proc_open,
  564. .read = seq_read,
  565. .write = uv_ptc_proc_write,
  566. .llseek = seq_lseek,
  567. .release = seq_release,
  568. };
  569. static int __init uv_ptc_init(void)
  570. {
  571. struct proc_dir_entry *proc_uv_ptc;
  572. if (!is_uv_system())
  573. return 0;
  574. proc_uv_ptc = create_proc_entry(UV_PTC_BASENAME, 0444, NULL);
  575. if (!proc_uv_ptc) {
  576. printk(KERN_ERR "unable to create %s proc entry\n",
  577. UV_PTC_BASENAME);
  578. return -EINVAL;
  579. }
  580. proc_uv_ptc->proc_fops = &proc_uv_ptc_operations;
  581. return 0;
  582. }
  583. /*
  584. * begin the initialization of the per-blade control structures
  585. */
  586. static struct bau_control * __init uv_table_bases_init(int blade, int node)
  587. {
  588. int i;
  589. struct bau_msg_status *msp;
  590. struct bau_control *bau_tabp;
  591. bau_tabp =
  592. kmalloc_node(sizeof(struct bau_control), GFP_KERNEL, node);
  593. BUG_ON(!bau_tabp);
  594. bau_tabp->msg_statuses =
  595. kmalloc_node(sizeof(struct bau_msg_status) *
  596. DEST_Q_SIZE, GFP_KERNEL, node);
  597. BUG_ON(!bau_tabp->msg_statuses);
  598. for (i = 0, msp = bau_tabp->msg_statuses; i < DEST_Q_SIZE; i++, msp++)
  599. bau_cpubits_clear(&msp->seen_by, (int)
  600. uv_blade_nr_possible_cpus(blade));
  601. uv_bau_table_bases[blade] = bau_tabp;
  602. return bau_tabp;
  603. }
  604. /*
  605. * finish the initialization of the per-blade control structures
  606. */
  607. static void __init
  608. uv_table_bases_finish(int blade,
  609. struct bau_control *bau_tablesp,
  610. struct bau_desc *adp)
  611. {
  612. struct bau_control *bcp;
  613. int cpu;
  614. for_each_present_cpu(cpu) {
  615. if (blade != uv_cpu_to_blade_id(cpu))
  616. continue;
  617. bcp = (struct bau_control *)&per_cpu(bau_control, cpu);
  618. bcp->bau_msg_head = bau_tablesp->va_queue_first;
  619. bcp->va_queue_first = bau_tablesp->va_queue_first;
  620. bcp->va_queue_last = bau_tablesp->va_queue_last;
  621. bcp->msg_statuses = bau_tablesp->msg_statuses;
  622. bcp->descriptor_base = adp;
  623. }
  624. }
  625. /*
  626. * initialize the sending side's sending buffers
  627. */
  628. static struct bau_desc * __init
  629. uv_activation_descriptor_init(int node, int pnode)
  630. {
  631. int i;
  632. unsigned long pa;
  633. unsigned long m;
  634. unsigned long n;
  635. unsigned long mmr_image;
  636. struct bau_desc *adp;
  637. struct bau_desc *ad2;
  638. adp = (struct bau_desc *)kmalloc_node(16384, GFP_KERNEL, node);
  639. BUG_ON(!adp);
  640. pa = __pa((unsigned long)adp);
  641. n = pa >> uv_nshift;
  642. m = pa & uv_mmask;
  643. mmr_image = uv_read_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE);
  644. if (mmr_image) {
  645. uv_write_global_mmr64(pnode, (unsigned long)
  646. UVH_LB_BAU_SB_DESCRIPTOR_BASE,
  647. (n << UV_DESC_BASE_PNODE_SHIFT | m));
  648. }
  649. for (i = 0, ad2 = adp; i < UV_ACTIVATION_DESCRIPTOR_SIZE; i++, ad2++) {
  650. memset(ad2, 0, sizeof(struct bau_desc));
  651. ad2->header.sw_ack_flag = 1;
  652. ad2->header.base_dest_nodeid = uv_cpu_to_pnode(0);
  653. ad2->header.command = UV_NET_ENDPOINT_INTD;
  654. ad2->header.int_both = 1;
  655. /*
  656. * all others need to be set to zero:
  657. * fairness chaining multilevel count replied_to
  658. */
  659. }
  660. return adp;
  661. }
  662. /*
  663. * initialize the destination side's receiving buffers
  664. */
  665. static struct bau_payload_queue_entry * __init
  666. uv_payload_queue_init(int node, int pnode, struct bau_control *bau_tablesp)
  667. {
  668. struct bau_payload_queue_entry *pqp;
  669. char *cp;
  670. pqp = (struct bau_payload_queue_entry *) kmalloc_node(
  671. (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry),
  672. GFP_KERNEL, node);
  673. BUG_ON(!pqp);
  674. cp = (char *)pqp + 31;
  675. pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5);
  676. bau_tablesp->va_queue_first = pqp;
  677. uv_write_global_mmr64(pnode,
  678. UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
  679. ((unsigned long)pnode <<
  680. UV_PAYLOADQ_PNODE_SHIFT) |
  681. uv_physnodeaddr(pqp));
  682. uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
  683. uv_physnodeaddr(pqp));
  684. bau_tablesp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
  685. uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
  686. (unsigned long)
  687. uv_physnodeaddr(bau_tablesp->va_queue_last));
  688. memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE);
  689. return pqp;
  690. }
  691. /*
  692. * Initialization of each UV blade's structures
  693. */
  694. static int __init uv_init_blade(int blade)
  695. {
  696. int node;
  697. int pnode;
  698. unsigned long pa;
  699. unsigned long apicid;
  700. struct bau_desc *adp;
  701. struct bau_payload_queue_entry *pqp;
  702. struct bau_control *bau_tablesp;
  703. node = blade_to_first_node(blade);
  704. bau_tablesp = uv_table_bases_init(blade, node);
  705. pnode = uv_blade_to_pnode(blade);
  706. adp = uv_activation_descriptor_init(node, pnode);
  707. pqp = uv_payload_queue_init(node, pnode, bau_tablesp);
  708. uv_table_bases_finish(blade, bau_tablesp, adp);
  709. /*
  710. * the below initialization can't be in firmware because the
  711. * messaging IRQ will be determined by the OS
  712. */
  713. apicid = blade_to_first_apicid(blade);
  714. pa = uv_read_global_mmr64(pnode, UVH_BAU_DATA_CONFIG);
  715. if ((pa & 0xff) != UV_BAU_MESSAGE) {
  716. uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
  717. ((apicid << 32) | UV_BAU_MESSAGE));
  718. }
  719. return 0;
  720. }
  721. /*
  722. * Initialization of BAU-related structures
  723. */
  724. static int __init uv_bau_init(void)
  725. {
  726. int blade;
  727. int nblades;
  728. int cur_cpu;
  729. if (!is_uv_system())
  730. return 0;
  731. uv_bau_retry_limit = 1;
  732. uv_nshift = uv_hub_info->n_val;
  733. uv_mmask = (1UL << uv_hub_info->n_val) - 1;
  734. nblades = uv_num_possible_blades();
  735. uv_bau_table_bases = (struct bau_control **)
  736. kmalloc(nblades * sizeof(struct bau_control *), GFP_KERNEL);
  737. BUG_ON(!uv_bau_table_bases);
  738. for (blade = 0; blade < nblades; blade++)
  739. if (uv_blade_nr_possible_cpus(blade))
  740. uv_init_blade(blade);
  741. alloc_intr_gate(UV_BAU_MESSAGE, uv_bau_message_intr1);
  742. uv_enable_timeouts();
  743. return 0;
  744. }
  745. __initcall(uv_bau_init);
  746. __initcall(uv_ptc_init);