tlb_uv.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  1. /*
  2. * SGI UltraViolet TLB flush routines.
  3. *
  4. * (c) 2008-2010 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 <linux/slab.h>
  13. #include <asm/mmu_context.h>
  14. #include <asm/uv/uv.h>
  15. #include <asm/uv/uv_mmrs.h>
  16. #include <asm/uv/uv_hub.h>
  17. #include <asm/uv/uv_bau.h>
  18. #include <asm/apic.h>
  19. #include <asm/idle.h>
  20. #include <asm/tsc.h>
  21. #include <asm/irq_vectors.h>
  22. #include <asm/timer.h>
  23. struct msg_desc {
  24. struct bau_payload_queue_entry *msg;
  25. int msg_slot;
  26. int sw_ack_slot;
  27. struct bau_payload_queue_entry *va_queue_first;
  28. struct bau_payload_queue_entry *va_queue_last;
  29. };
  30. #define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x000000000bUL
  31. static int uv_bau_max_concurrent __read_mostly;
  32. static int nobau;
  33. static int __init setup_nobau(char *arg)
  34. {
  35. nobau = 1;
  36. return 0;
  37. }
  38. early_param("nobau", setup_nobau);
  39. /* base pnode in this partition */
  40. static int uv_partition_base_pnode __read_mostly;
  41. /* position of pnode (which is nasid>>1): */
  42. static int uv_nshift __read_mostly;
  43. static unsigned long uv_mmask __read_mostly;
  44. static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
  45. static DEFINE_PER_CPU(struct bau_control, bau_control);
  46. static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
  47. struct reset_args {
  48. int sender;
  49. };
  50. /*
  51. * Determine the first node on a uvhub. 'Nodes' are used for kernel
  52. * memory allocation.
  53. */
  54. static int __init uvhub_to_first_node(int uvhub)
  55. {
  56. int node, b;
  57. for_each_online_node(node) {
  58. b = uv_node_to_blade_id(node);
  59. if (uvhub == b)
  60. return node;
  61. }
  62. return -1;
  63. }
  64. /*
  65. * Determine the apicid of the first cpu on a uvhub.
  66. */
  67. static int __init uvhub_to_first_apicid(int uvhub)
  68. {
  69. int cpu;
  70. for_each_present_cpu(cpu)
  71. if (uvhub == uv_cpu_to_blade_id(cpu))
  72. return per_cpu(x86_cpu_to_apicid, cpu);
  73. return -1;
  74. }
  75. /*
  76. * Free a software acknowledge hardware resource by clearing its Pending
  77. * bit. This will return a reply to the sender.
  78. * If the message has timed out, a reply has already been sent by the
  79. * hardware but the resource has not been released. In that case our
  80. * clear of the Timeout bit (as well) will free the resource. No reply will
  81. * be sent (the hardware will only do one reply per message).
  82. */
  83. static inline void uv_reply_to_message(struct msg_desc *mdp,
  84. struct bau_control *bcp)
  85. {
  86. unsigned long dw;
  87. struct bau_payload_queue_entry *msg;
  88. msg = mdp->msg;
  89. if (!msg->canceled) {
  90. dw = (msg->sw_ack_vector << UV_SW_ACK_NPENDING) |
  91. msg->sw_ack_vector;
  92. uv_write_local_mmr(
  93. UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw);
  94. }
  95. msg->replied_to = 1;
  96. msg->sw_ack_vector = 0;
  97. }
  98. /*
  99. * Process the receipt of a RETRY message
  100. */
  101. static inline void uv_bau_process_retry_msg(struct msg_desc *mdp,
  102. struct bau_control *bcp)
  103. {
  104. int i;
  105. int cancel_count = 0;
  106. int slot2;
  107. unsigned long msg_res;
  108. unsigned long mmr = 0;
  109. struct bau_payload_queue_entry *msg;
  110. struct bau_payload_queue_entry *msg2;
  111. struct ptc_stats *stat;
  112. msg = mdp->msg;
  113. stat = &per_cpu(ptcstats, bcp->cpu);
  114. stat->d_retries++;
  115. /*
  116. * cancel any message from msg+1 to the retry itself
  117. */
  118. for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
  119. if (msg2 > mdp->va_queue_last)
  120. msg2 = mdp->va_queue_first;
  121. if (msg2 == msg)
  122. break;
  123. /* same conditions for cancellation as uv_do_reset */
  124. if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
  125. (msg2->sw_ack_vector) && ((msg2->sw_ack_vector &
  126. msg->sw_ack_vector) == 0) &&
  127. (msg2->sending_cpu == msg->sending_cpu) &&
  128. (msg2->msg_type != MSG_NOOP)) {
  129. slot2 = msg2 - mdp->va_queue_first;
  130. mmr = uv_read_local_mmr
  131. (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
  132. msg_res = ((msg2->sw_ack_vector << 8) |
  133. msg2->sw_ack_vector);
  134. /*
  135. * This is a message retry; clear the resources held
  136. * by the previous message only if they timed out.
  137. * If it has not timed out we have an unexpected
  138. * situation to report.
  139. */
  140. if (mmr & (msg_res << 8)) {
  141. /*
  142. * is the resource timed out?
  143. * make everyone ignore the cancelled message.
  144. */
  145. msg2->canceled = 1;
  146. stat->d_canceled++;
  147. cancel_count++;
  148. uv_write_local_mmr(
  149. UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
  150. (msg_res << 8) | msg_res);
  151. } else
  152. printk(KERN_INFO "note bau retry: no effect\n");
  153. }
  154. }
  155. if (!cancel_count)
  156. stat->d_nocanceled++;
  157. }
  158. /*
  159. * Do all the things a cpu should do for a TLB shootdown message.
  160. * Other cpu's may come here at the same time for this message.
  161. */
  162. static void uv_bau_process_message(struct msg_desc *mdp,
  163. struct bau_control *bcp)
  164. {
  165. int msg_ack_count;
  166. short socket_ack_count = 0;
  167. struct ptc_stats *stat;
  168. struct bau_payload_queue_entry *msg;
  169. struct bau_control *smaster = bcp->socket_master;
  170. /*
  171. * This must be a normal message, or retry of a normal message
  172. */
  173. msg = mdp->msg;
  174. stat = &per_cpu(ptcstats, bcp->cpu);
  175. if (msg->address == TLB_FLUSH_ALL) {
  176. local_flush_tlb();
  177. stat->d_alltlb++;
  178. } else {
  179. __flush_tlb_one(msg->address);
  180. stat->d_onetlb++;
  181. }
  182. stat->d_requestee++;
  183. /*
  184. * One cpu on each uvhub has the additional job on a RETRY
  185. * of releasing the resource held by the message that is
  186. * being retried. That message is identified by sending
  187. * cpu number.
  188. */
  189. if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
  190. uv_bau_process_retry_msg(mdp, bcp);
  191. /*
  192. * This is a sw_ack message, so we have to reply to it.
  193. * Count each responding cpu on the socket. This avoids
  194. * pinging the count's cache line back and forth between
  195. * the sockets.
  196. */
  197. socket_ack_count = atomic_add_short_return(1, (struct atomic_short *)
  198. &smaster->socket_acknowledge_count[mdp->msg_slot]);
  199. if (socket_ack_count == bcp->cpus_in_socket) {
  200. /*
  201. * Both sockets dump their completed count total into
  202. * the message's count.
  203. */
  204. smaster->socket_acknowledge_count[mdp->msg_slot] = 0;
  205. msg_ack_count = atomic_add_short_return(socket_ack_count,
  206. (struct atomic_short *)&msg->acknowledge_count);
  207. if (msg_ack_count == bcp->cpus_in_uvhub) {
  208. /*
  209. * All cpus in uvhub saw it; reply
  210. */
  211. uv_reply_to_message(mdp, bcp);
  212. }
  213. }
  214. return;
  215. }
  216. /*
  217. * Determine the first cpu on a uvhub.
  218. */
  219. static int uvhub_to_first_cpu(int uvhub)
  220. {
  221. int cpu;
  222. for_each_present_cpu(cpu)
  223. if (uvhub == uv_cpu_to_blade_id(cpu))
  224. return cpu;
  225. return -1;
  226. }
  227. /*
  228. * Last resort when we get a large number of destination timeouts is
  229. * to clear resources held by a given cpu.
  230. * Do this with IPI so that all messages in the BAU message queue
  231. * can be identified by their nonzero sw_ack_vector field.
  232. *
  233. * This is entered for a single cpu on the uvhub.
  234. * The sender want's this uvhub to free a specific message's
  235. * sw_ack resources.
  236. */
  237. static void
  238. uv_do_reset(void *ptr)
  239. {
  240. int i;
  241. int slot;
  242. int count = 0;
  243. unsigned long mmr;
  244. unsigned long msg_res;
  245. struct bau_control *bcp;
  246. struct reset_args *rap;
  247. struct bau_payload_queue_entry *msg;
  248. struct ptc_stats *stat;
  249. bcp = &per_cpu(bau_control, smp_processor_id());
  250. rap = (struct reset_args *)ptr;
  251. stat = &per_cpu(ptcstats, bcp->cpu);
  252. stat->d_resets++;
  253. /*
  254. * We're looking for the given sender, and
  255. * will free its sw_ack resource.
  256. * If all cpu's finally responded after the timeout, its
  257. * message 'replied_to' was set.
  258. */
  259. for (msg = bcp->va_queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
  260. /* uv_do_reset: same conditions for cancellation as
  261. uv_bau_process_retry_msg() */
  262. if ((msg->replied_to == 0) &&
  263. (msg->canceled == 0) &&
  264. (msg->sending_cpu == rap->sender) &&
  265. (msg->sw_ack_vector) &&
  266. (msg->msg_type != MSG_NOOP)) {
  267. /*
  268. * make everyone else ignore this message
  269. */
  270. msg->canceled = 1;
  271. slot = msg - bcp->va_queue_first;
  272. count++;
  273. /*
  274. * only reset the resource if it is still pending
  275. */
  276. mmr = uv_read_local_mmr
  277. (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
  278. msg_res = ((msg->sw_ack_vector << 8) |
  279. msg->sw_ack_vector);
  280. if (mmr & msg_res) {
  281. stat->d_rcanceled++;
  282. uv_write_local_mmr(
  283. UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
  284. msg_res);
  285. }
  286. }
  287. }
  288. return;
  289. }
  290. /*
  291. * Use IPI to get all target uvhubs to release resources held by
  292. * a given sending cpu number.
  293. */
  294. static void uv_reset_with_ipi(struct bau_target_uvhubmask *distribution,
  295. int sender)
  296. {
  297. int uvhub;
  298. int cpu;
  299. cpumask_t mask;
  300. struct reset_args reset_args;
  301. reset_args.sender = sender;
  302. cpus_clear(mask);
  303. /* find a single cpu for each uvhub in this distribution mask */
  304. for (uvhub = 0;
  305. uvhub < sizeof(struct bau_target_uvhubmask) * BITSPERBYTE;
  306. uvhub++) {
  307. if (!bau_uvhub_isset(uvhub, distribution))
  308. continue;
  309. /* find a cpu for this uvhub */
  310. cpu = uvhub_to_first_cpu(uvhub);
  311. cpu_set(cpu, mask);
  312. }
  313. /* IPI all cpus; Preemption is already disabled */
  314. smp_call_function_many(&mask, uv_do_reset, (void *)&reset_args, 1);
  315. return;
  316. }
  317. static inline unsigned long
  318. cycles_2_us(unsigned long long cyc)
  319. {
  320. unsigned long long ns;
  321. unsigned long us;
  322. ns = (cyc * per_cpu(cyc2ns, smp_processor_id()))
  323. >> CYC2NS_SCALE_FACTOR;
  324. us = ns / 1000;
  325. return us;
  326. }
  327. /*
  328. * wait for all cpus on this hub to finish their sends and go quiet
  329. * leaves uvhub_quiesce set so that no new broadcasts are started by
  330. * bau_flush_send_and_wait()
  331. */
  332. static inline void
  333. quiesce_local_uvhub(struct bau_control *hmaster)
  334. {
  335. atomic_add_short_return(1, (struct atomic_short *)
  336. &hmaster->uvhub_quiesce);
  337. }
  338. /*
  339. * mark this quiet-requestor as done
  340. */
  341. static inline void
  342. end_uvhub_quiesce(struct bau_control *hmaster)
  343. {
  344. atomic_add_short_return(-1, (struct atomic_short *)
  345. &hmaster->uvhub_quiesce);
  346. }
  347. /*
  348. * Wait for completion of a broadcast software ack message
  349. * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
  350. */
  351. static int uv_wait_completion(struct bau_desc *bau_desc,
  352. unsigned long mmr_offset, int right_shift, int this_cpu,
  353. struct bau_control *bcp, struct bau_control *smaster, long try)
  354. {
  355. int relaxes = 0;
  356. unsigned long descriptor_status;
  357. unsigned long mmr;
  358. unsigned long mask;
  359. cycles_t ttime;
  360. cycles_t timeout_time;
  361. struct ptc_stats *stat = &per_cpu(ptcstats, this_cpu);
  362. struct bau_control *hmaster;
  363. hmaster = bcp->uvhub_master;
  364. timeout_time = get_cycles() + bcp->timeout_interval;
  365. /* spin on the status MMR, waiting for it to go idle */
  366. while ((descriptor_status = (((unsigned long)
  367. uv_read_local_mmr(mmr_offset) >>
  368. right_shift) & UV_ACT_STATUS_MASK)) !=
  369. DESC_STATUS_IDLE) {
  370. /*
  371. * Our software ack messages may be blocked because there are
  372. * no swack resources available. As long as none of them
  373. * has timed out hardware will NACK our message and its
  374. * state will stay IDLE.
  375. */
  376. if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
  377. stat->s_stimeout++;
  378. return FLUSH_GIVEUP;
  379. } else if (descriptor_status ==
  380. DESC_STATUS_DESTINATION_TIMEOUT) {
  381. stat->s_dtimeout++;
  382. ttime = get_cycles();
  383. /*
  384. * Our retries may be blocked by all destination
  385. * swack resources being consumed, and a timeout
  386. * pending. In that case hardware returns the
  387. * ERROR that looks like a destination timeout.
  388. */
  389. if (cycles_2_us(ttime - bcp->send_message) < BIOS_TO) {
  390. bcp->conseccompletes = 0;
  391. return FLUSH_RETRY_PLUGGED;
  392. }
  393. bcp->conseccompletes = 0;
  394. return FLUSH_RETRY_TIMEOUT;
  395. } else {
  396. /*
  397. * descriptor_status is still BUSY
  398. */
  399. cpu_relax();
  400. relaxes++;
  401. if (relaxes >= 10000) {
  402. relaxes = 0;
  403. if (get_cycles() > timeout_time) {
  404. quiesce_local_uvhub(hmaster);
  405. /* single-thread the register change */
  406. spin_lock(&hmaster->masks_lock);
  407. mmr = uv_read_local_mmr(mmr_offset);
  408. mask = 0UL;
  409. mask |= (3UL < right_shift);
  410. mask = ~mask;
  411. mmr &= mask;
  412. uv_write_local_mmr(mmr_offset, mmr);
  413. spin_unlock(&hmaster->masks_lock);
  414. end_uvhub_quiesce(hmaster);
  415. stat->s_busy++;
  416. return FLUSH_GIVEUP;
  417. }
  418. }
  419. }
  420. }
  421. bcp->conseccompletes++;
  422. return FLUSH_COMPLETE;
  423. }
  424. static inline cycles_t
  425. sec_2_cycles(unsigned long sec)
  426. {
  427. unsigned long ns;
  428. cycles_t cyc;
  429. ns = sec * 1000000000;
  430. cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
  431. return cyc;
  432. }
  433. /*
  434. * conditionally add 1 to *v, unless *v is >= u
  435. * return 0 if we cannot add 1 to *v because it is >= u
  436. * return 1 if we can add 1 to *v because it is < u
  437. * the add is atomic
  438. *
  439. * This is close to atomic_add_unless(), but this allows the 'u' value
  440. * to be lowered below the current 'v'. atomic_add_unless can only stop
  441. * on equal.
  442. */
  443. static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
  444. {
  445. spin_lock(lock);
  446. if (atomic_read(v) >= u) {
  447. spin_unlock(lock);
  448. return 0;
  449. }
  450. atomic_inc(v);
  451. spin_unlock(lock);
  452. return 1;
  453. }
  454. /**
  455. * uv_flush_send_and_wait
  456. *
  457. * Send a broadcast and wait for it to complete.
  458. *
  459. * The flush_mask contains the cpus the broadcast is to be sent to, plus
  460. * cpus that are on the local uvhub.
  461. *
  462. * Returns NULL if all flushing represented in the mask was done. The mask
  463. * is zeroed.
  464. * Returns @flush_mask if some remote flushing remains to be done. The
  465. * mask will have some bits still set, representing any cpus on the local
  466. * uvhub (not current cpu) and any on remote uvhubs if the broadcast failed.
  467. */
  468. const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc,
  469. struct cpumask *flush_mask,
  470. struct bau_control *bcp)
  471. {
  472. int right_shift;
  473. int uvhub;
  474. int bit;
  475. int completion_status = 0;
  476. int seq_number = 0;
  477. long try = 0;
  478. int cpu = bcp->uvhub_cpu;
  479. int this_cpu = bcp->cpu;
  480. int this_uvhub = bcp->uvhub;
  481. unsigned long mmr_offset;
  482. unsigned long index;
  483. cycles_t time1;
  484. cycles_t time2;
  485. struct ptc_stats *stat = &per_cpu(ptcstats, bcp->cpu);
  486. struct bau_control *smaster = bcp->socket_master;
  487. struct bau_control *hmaster = bcp->uvhub_master;
  488. /*
  489. * Spin here while there are hmaster->max_concurrent or more active
  490. * descriptors. This is the per-uvhub 'throttle'.
  491. */
  492. if (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
  493. &hmaster->active_descriptor_count,
  494. hmaster->max_concurrent)) {
  495. stat->s_throttles++;
  496. do {
  497. cpu_relax();
  498. } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
  499. &hmaster->active_descriptor_count,
  500. hmaster->max_concurrent));
  501. }
  502. while (hmaster->uvhub_quiesce)
  503. cpu_relax();
  504. if (cpu < UV_CPUS_PER_ACT_STATUS) {
  505. mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
  506. right_shift = cpu * UV_ACT_STATUS_SIZE;
  507. } else {
  508. mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
  509. right_shift =
  510. ((cpu - UV_CPUS_PER_ACT_STATUS) * UV_ACT_STATUS_SIZE);
  511. }
  512. time1 = get_cycles();
  513. do {
  514. /*
  515. * Every message from any given cpu gets a unique message
  516. * sequence number. But retries use that same number.
  517. * Our message may have timed out at the destination because
  518. * all sw-ack resources are in use and there is a timeout
  519. * pending there. In that case, our last send never got
  520. * placed into the queue and we need to persist until it
  521. * does.
  522. *
  523. * Make any retry a type MSG_RETRY so that the destination will
  524. * free any resource held by a previous message from this cpu.
  525. */
  526. if (try == 0) {
  527. /* use message type set by the caller the first time */
  528. seq_number = bcp->message_number++;
  529. } else {
  530. /* use RETRY type on all the rest; same sequence */
  531. bau_desc->header.msg_type = MSG_RETRY;
  532. stat->s_retry_messages++;
  533. }
  534. bau_desc->header.sequence = seq_number;
  535. index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) |
  536. bcp->uvhub_cpu;
  537. bcp->send_message = get_cycles();
  538. uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
  539. try++;
  540. completion_status = uv_wait_completion(bau_desc, mmr_offset,
  541. right_shift, this_cpu, bcp, smaster, try);
  542. if (completion_status == FLUSH_RETRY_PLUGGED) {
  543. /*
  544. * Our retries may be blocked by all destination swack
  545. * resources being consumed, and a timeout pending. In
  546. * that case hardware immediately returns the ERROR
  547. * that looks like a destination timeout.
  548. */
  549. udelay(TIMEOUT_DELAY);
  550. bcp->plugged_tries++;
  551. if (bcp->plugged_tries >= PLUGSB4RESET) {
  552. bcp->plugged_tries = 0;
  553. quiesce_local_uvhub(hmaster);
  554. spin_lock(&hmaster->queue_lock);
  555. uv_reset_with_ipi(&bau_desc->distribution,
  556. this_cpu);
  557. spin_unlock(&hmaster->queue_lock);
  558. end_uvhub_quiesce(hmaster);
  559. bcp->ipi_attempts++;
  560. stat->s_resets_plug++;
  561. }
  562. } else if (completion_status == FLUSH_RETRY_TIMEOUT) {
  563. hmaster->max_concurrent = 1;
  564. bcp->timeout_tries++;
  565. udelay(TIMEOUT_DELAY);
  566. if (bcp->timeout_tries >= TIMEOUTSB4RESET) {
  567. bcp->timeout_tries = 0;
  568. quiesce_local_uvhub(hmaster);
  569. spin_lock(&hmaster->queue_lock);
  570. uv_reset_with_ipi(&bau_desc->distribution,
  571. this_cpu);
  572. spin_unlock(&hmaster->queue_lock);
  573. end_uvhub_quiesce(hmaster);
  574. bcp->ipi_attempts++;
  575. stat->s_resets_timeout++;
  576. }
  577. }
  578. if (bcp->ipi_attempts >= 3) {
  579. bcp->ipi_attempts = 0;
  580. completion_status = FLUSH_GIVEUP;
  581. break;
  582. }
  583. cpu_relax();
  584. } while ((completion_status == FLUSH_RETRY_PLUGGED) ||
  585. (completion_status == FLUSH_RETRY_TIMEOUT));
  586. time2 = get_cycles();
  587. if ((completion_status == FLUSH_COMPLETE) && (bcp->conseccompletes > 5)
  588. && (hmaster->max_concurrent < hmaster->max_concurrent_constant))
  589. hmaster->max_concurrent++;
  590. /*
  591. * hold any cpu not timing out here; no other cpu currently held by
  592. * the 'throttle' should enter the activation code
  593. */
  594. while (hmaster->uvhub_quiesce)
  595. cpu_relax();
  596. atomic_dec(&hmaster->active_descriptor_count);
  597. /* guard against cycles wrap */
  598. if (time2 > time1)
  599. stat->s_time += (time2 - time1);
  600. else
  601. stat->s_requestor--; /* don't count this one */
  602. if (completion_status == FLUSH_COMPLETE && try > 1)
  603. stat->s_retriesok++;
  604. else if (completion_status == FLUSH_GIVEUP) {
  605. /*
  606. * Cause the caller to do an IPI-style TLB shootdown on
  607. * the target cpu's, all of which are still in the mask.
  608. */
  609. stat->s_giveup++;
  610. return flush_mask;
  611. }
  612. /*
  613. * Success, so clear the remote cpu's from the mask so we don't
  614. * use the IPI method of shootdown on them.
  615. */
  616. for_each_cpu(bit, flush_mask) {
  617. uvhub = uv_cpu_to_blade_id(bit);
  618. if (uvhub == this_uvhub)
  619. continue;
  620. cpumask_clear_cpu(bit, flush_mask);
  621. }
  622. if (!cpumask_empty(flush_mask))
  623. return flush_mask;
  624. return NULL;
  625. }
  626. /**
  627. * uv_flush_tlb_others - globally purge translation cache of a virtual
  628. * address or all TLB's
  629. * @cpumask: mask of all cpu's in which the address is to be removed
  630. * @mm: mm_struct containing virtual address range
  631. * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
  632. * @cpu: the current cpu
  633. *
  634. * This is the entry point for initiating any UV global TLB shootdown.
  635. *
  636. * Purges the translation caches of all specified processors of the given
  637. * virtual address, or purges all TLB's on specified processors.
  638. *
  639. * The caller has derived the cpumask from the mm_struct. This function
  640. * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
  641. *
  642. * The cpumask is converted into a uvhubmask of the uvhubs containing
  643. * those cpus.
  644. *
  645. * Note that this function should be called with preemption disabled.
  646. *
  647. * Returns NULL if all remote flushing was done.
  648. * Returns pointer to cpumask if some remote flushing remains to be
  649. * done. The returned pointer is valid till preemption is re-enabled.
  650. */
  651. const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
  652. struct mm_struct *mm,
  653. unsigned long va, unsigned int cpu)
  654. {
  655. int remotes;
  656. int tcpu;
  657. int uvhub;
  658. int locals = 0;
  659. struct bau_desc *bau_desc;
  660. struct cpumask *flush_mask;
  661. struct ptc_stats *stat;
  662. struct bau_control *bcp;
  663. if (nobau)
  664. return cpumask;
  665. bcp = &per_cpu(bau_control, cpu);
  666. /*
  667. * Each sending cpu has a per-cpu mask which it fills from the caller's
  668. * cpu mask. Only remote cpus are converted to uvhubs and copied.
  669. */
  670. flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
  671. /*
  672. * copy cpumask to flush_mask, removing current cpu
  673. * (current cpu should already have been flushed by the caller and
  674. * should never be returned if we return flush_mask)
  675. */
  676. cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
  677. if (cpu_isset(cpu, *cpumask))
  678. locals++; /* current cpu was targeted */
  679. bau_desc = bcp->descriptor_base;
  680. bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu;
  681. bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
  682. remotes = 0;
  683. for_each_cpu(tcpu, flush_mask) {
  684. uvhub = uv_cpu_to_blade_id(tcpu);
  685. if (uvhub == bcp->uvhub) {
  686. locals++;
  687. continue;
  688. }
  689. bau_uvhub_set(uvhub, &bau_desc->distribution);
  690. remotes++;
  691. }
  692. if (remotes == 0) {
  693. /*
  694. * No off_hub flushing; return status for local hub.
  695. * Return the caller's mask if all were local (the current
  696. * cpu may be in that mask).
  697. */
  698. if (locals)
  699. return cpumask;
  700. else
  701. return NULL;
  702. }
  703. stat = &per_cpu(ptcstats, cpu);
  704. stat->s_requestor++;
  705. stat->s_ntargcpu += remotes;
  706. remotes = bau_uvhub_weight(&bau_desc->distribution);
  707. stat->s_ntarguvhub += remotes;
  708. if (remotes >= 16)
  709. stat->s_ntarguvhub16++;
  710. else if (remotes >= 8)
  711. stat->s_ntarguvhub8++;
  712. else if (remotes >= 4)
  713. stat->s_ntarguvhub4++;
  714. else if (remotes >= 2)
  715. stat->s_ntarguvhub2++;
  716. else
  717. stat->s_ntarguvhub1++;
  718. bau_desc->payload.address = va;
  719. bau_desc->payload.sending_cpu = cpu;
  720. /*
  721. * uv_flush_send_and_wait returns null if all cpu's were messaged, or
  722. * the adjusted flush_mask if any cpu's were not messaged.
  723. */
  724. return uv_flush_send_and_wait(bau_desc, flush_mask, bcp);
  725. }
  726. /*
  727. * The BAU message interrupt comes here. (registered by set_intr_gate)
  728. * See entry_64.S
  729. *
  730. * We received a broadcast assist message.
  731. *
  732. * Interrupts are disabled; this interrupt could represent
  733. * the receipt of several messages.
  734. *
  735. * All cores/threads on this hub get this interrupt.
  736. * The last one to see it does the software ack.
  737. * (the resource will not be freed until noninterruptable cpus see this
  738. * interrupt; hardware may timeout the s/w ack and reply ERROR)
  739. */
  740. void uv_bau_message_interrupt(struct pt_regs *regs)
  741. {
  742. int count = 0;
  743. cycles_t time_start;
  744. struct bau_payload_queue_entry *msg;
  745. struct bau_control *bcp;
  746. struct ptc_stats *stat;
  747. struct msg_desc msgdesc;
  748. time_start = get_cycles();
  749. bcp = &per_cpu(bau_control, smp_processor_id());
  750. stat = &per_cpu(ptcstats, smp_processor_id());
  751. msgdesc.va_queue_first = bcp->va_queue_first;
  752. msgdesc.va_queue_last = bcp->va_queue_last;
  753. msg = bcp->bau_msg_head;
  754. while (msg->sw_ack_vector) {
  755. count++;
  756. msgdesc.msg_slot = msg - msgdesc.va_queue_first;
  757. msgdesc.sw_ack_slot = ffs(msg->sw_ack_vector) - 1;
  758. msgdesc.msg = msg;
  759. uv_bau_process_message(&msgdesc, bcp);
  760. msg++;
  761. if (msg > msgdesc.va_queue_last)
  762. msg = msgdesc.va_queue_first;
  763. bcp->bau_msg_head = msg;
  764. }
  765. stat->d_time += (get_cycles() - time_start);
  766. if (!count)
  767. stat->d_nomsg++;
  768. else if (count > 1)
  769. stat->d_multmsg++;
  770. ack_APIC_irq();
  771. }
  772. /*
  773. * uv_enable_timeouts
  774. *
  775. * Each target uvhub (i.e. a uvhub that has no cpu's) needs to have
  776. * shootdown message timeouts enabled. The timeout does not cause
  777. * an interrupt, but causes an error message to be returned to
  778. * the sender.
  779. */
  780. static void uv_enable_timeouts(void)
  781. {
  782. int uvhub;
  783. int nuvhubs;
  784. int pnode;
  785. unsigned long mmr_image;
  786. nuvhubs = uv_num_possible_blades();
  787. for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
  788. if (!uv_blade_nr_possible_cpus(uvhub))
  789. continue;
  790. pnode = uv_blade_to_pnode(uvhub);
  791. mmr_image =
  792. uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL);
  793. /*
  794. * Set the timeout period and then lock it in, in three
  795. * steps; captures and locks in the period.
  796. *
  797. * To program the period, the SOFT_ACK_MODE must be off.
  798. */
  799. mmr_image &= ~((unsigned long)1 <<
  800. UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
  801. uv_write_global_mmr64
  802. (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
  803. /*
  804. * Set the 4-bit period.
  805. */
  806. mmr_image &= ~((unsigned long)0xf <<
  807. UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
  808. mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD <<
  809. UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
  810. uv_write_global_mmr64
  811. (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
  812. /*
  813. * Subsequent reversals of the timebase bit (3) cause an
  814. * immediate timeout of one or all INTD resources as
  815. * indicated in bits 2:0 (7 causes all of them to timeout).
  816. */
  817. mmr_image |= ((unsigned long)1 <<
  818. UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
  819. uv_write_global_mmr64
  820. (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
  821. }
  822. }
  823. static void *uv_ptc_seq_start(struct seq_file *file, loff_t *offset)
  824. {
  825. if (*offset < num_possible_cpus())
  826. return offset;
  827. return NULL;
  828. }
  829. static void *uv_ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
  830. {
  831. (*offset)++;
  832. if (*offset < num_possible_cpus())
  833. return offset;
  834. return NULL;
  835. }
  836. static void uv_ptc_seq_stop(struct seq_file *file, void *data)
  837. {
  838. }
  839. static inline unsigned long long
  840. millisec_2_cycles(unsigned long millisec)
  841. {
  842. unsigned long ns;
  843. unsigned long long cyc;
  844. ns = millisec * 1000;
  845. cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
  846. return cyc;
  847. }
  848. /*
  849. * Display the statistics thru /proc.
  850. * 'data' points to the cpu number
  851. */
  852. static int uv_ptc_seq_show(struct seq_file *file, void *data)
  853. {
  854. struct ptc_stats *stat;
  855. int cpu;
  856. cpu = *(loff_t *)data;
  857. if (!cpu) {
  858. seq_printf(file,
  859. "# cpu sent stime numuvhubs numuvhubs16 numuvhubs8 ");
  860. seq_printf(file,
  861. "numuvhubs4 numuvhubs2 numuvhubs1 numcpus dto ");
  862. seq_printf(file,
  863. "retries rok resetp resett giveup sto bz throt ");
  864. seq_printf(file,
  865. "sw_ack recv rtime all ");
  866. seq_printf(file,
  867. "one mult none retry canc nocan reset rcan\n");
  868. }
  869. if (cpu < num_possible_cpus() && cpu_online(cpu)) {
  870. stat = &per_cpu(ptcstats, cpu);
  871. /* source side statistics */
  872. seq_printf(file,
  873. "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
  874. cpu, stat->s_requestor, cycles_2_us(stat->s_time),
  875. stat->s_ntarguvhub, stat->s_ntarguvhub16,
  876. stat->s_ntarguvhub8, stat->s_ntarguvhub4,
  877. stat->s_ntarguvhub2, stat->s_ntarguvhub1,
  878. stat->s_ntargcpu, stat->s_dtimeout);
  879. seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
  880. stat->s_retry_messages, stat->s_retriesok,
  881. stat->s_resets_plug, stat->s_resets_timeout,
  882. stat->s_giveup, stat->s_stimeout,
  883. stat->s_busy, stat->s_throttles);
  884. /* destination side statistics */
  885. seq_printf(file,
  886. "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
  887. uv_read_global_mmr64(uv_cpu_to_pnode(cpu),
  888. UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
  889. stat->d_requestee, cycles_2_us(stat->d_time),
  890. stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
  891. stat->d_nomsg, stat->d_retries, stat->d_canceled,
  892. stat->d_nocanceled, stat->d_resets,
  893. stat->d_rcanceled);
  894. }
  895. return 0;
  896. }
  897. /*
  898. * -1: resetf the statistics
  899. * 0: display meaning of the statistics
  900. * >0: maximum concurrent active descriptors per uvhub (throttle)
  901. */
  902. static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
  903. size_t count, loff_t *data)
  904. {
  905. int cpu;
  906. long input_arg;
  907. char optstr[64];
  908. struct ptc_stats *stat;
  909. struct bau_control *bcp;
  910. if (count == 0 || count > sizeof(optstr))
  911. return -EINVAL;
  912. if (copy_from_user(optstr, user, count))
  913. return -EFAULT;
  914. optstr[count - 1] = '\0';
  915. if (strict_strtol(optstr, 10, &input_arg) < 0) {
  916. printk(KERN_DEBUG "%s is invalid\n", optstr);
  917. return -EINVAL;
  918. }
  919. if (input_arg == 0) {
  920. printk(KERN_DEBUG "# cpu: cpu number\n");
  921. printk(KERN_DEBUG "Sender statistics:\n");
  922. printk(KERN_DEBUG
  923. "sent: number of shootdown messages sent\n");
  924. printk(KERN_DEBUG
  925. "stime: time spent sending messages\n");
  926. printk(KERN_DEBUG
  927. "numuvhubs: number of hubs targeted with shootdown\n");
  928. printk(KERN_DEBUG
  929. "numuvhubs16: number times 16 or more hubs targeted\n");
  930. printk(KERN_DEBUG
  931. "numuvhubs8: number times 8 or more hubs targeted\n");
  932. printk(KERN_DEBUG
  933. "numuvhubs4: number times 4 or more hubs targeted\n");
  934. printk(KERN_DEBUG
  935. "numuvhubs2: number times 2 or more hubs targeted\n");
  936. printk(KERN_DEBUG
  937. "numuvhubs1: number times 1 hub targeted\n");
  938. printk(KERN_DEBUG
  939. "numcpus: number of cpus targeted with shootdown\n");
  940. printk(KERN_DEBUG
  941. "dto: number of destination timeouts\n");
  942. printk(KERN_DEBUG
  943. "retries: destination timeout retries sent\n");
  944. printk(KERN_DEBUG
  945. "rok: : destination timeouts successfully retried\n");
  946. printk(KERN_DEBUG
  947. "resetp: ipi-style resource resets for plugs\n");
  948. printk(KERN_DEBUG
  949. "resett: ipi-style resource resets for timeouts\n");
  950. printk(KERN_DEBUG
  951. "giveup: fall-backs to ipi-style shootdowns\n");
  952. printk(KERN_DEBUG
  953. "sto: number of source timeouts\n");
  954. printk(KERN_DEBUG
  955. "bz: number of stay-busy's\n");
  956. printk(KERN_DEBUG
  957. "throt: number times spun in throttle\n");
  958. printk(KERN_DEBUG "Destination side statistics:\n");
  959. printk(KERN_DEBUG
  960. "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
  961. printk(KERN_DEBUG
  962. "recv: shootdown messages received\n");
  963. printk(KERN_DEBUG
  964. "rtime: time spent processing messages\n");
  965. printk(KERN_DEBUG
  966. "all: shootdown all-tlb messages\n");
  967. printk(KERN_DEBUG
  968. "one: shootdown one-tlb messages\n");
  969. printk(KERN_DEBUG
  970. "mult: interrupts that found multiple messages\n");
  971. printk(KERN_DEBUG
  972. "none: interrupts that found no messages\n");
  973. printk(KERN_DEBUG
  974. "retry: number of retry messages processed\n");
  975. printk(KERN_DEBUG
  976. "canc: number messages canceled by retries\n");
  977. printk(KERN_DEBUG
  978. "nocan: number retries that found nothing to cancel\n");
  979. printk(KERN_DEBUG
  980. "reset: number of ipi-style reset requests processed\n");
  981. printk(KERN_DEBUG
  982. "rcan: number messages canceled by reset requests\n");
  983. } else if (input_arg == -1) {
  984. for_each_present_cpu(cpu) {
  985. stat = &per_cpu(ptcstats, cpu);
  986. memset(stat, 0, sizeof(struct ptc_stats));
  987. }
  988. } else {
  989. uv_bau_max_concurrent = input_arg;
  990. bcp = &per_cpu(bau_control, smp_processor_id());
  991. if (uv_bau_max_concurrent < 1 ||
  992. uv_bau_max_concurrent > bcp->cpus_in_uvhub) {
  993. printk(KERN_DEBUG
  994. "Error: BAU max concurrent %d; %d is invalid\n",
  995. bcp->max_concurrent, uv_bau_max_concurrent);
  996. return -EINVAL;
  997. }
  998. printk(KERN_DEBUG "Set BAU max concurrent:%d\n",
  999. uv_bau_max_concurrent);
  1000. for_each_present_cpu(cpu) {
  1001. bcp = &per_cpu(bau_control, cpu);
  1002. bcp->max_concurrent = uv_bau_max_concurrent;
  1003. }
  1004. }
  1005. return count;
  1006. }
  1007. static const struct seq_operations uv_ptc_seq_ops = {
  1008. .start = uv_ptc_seq_start,
  1009. .next = uv_ptc_seq_next,
  1010. .stop = uv_ptc_seq_stop,
  1011. .show = uv_ptc_seq_show
  1012. };
  1013. static int uv_ptc_proc_open(struct inode *inode, struct file *file)
  1014. {
  1015. return seq_open(file, &uv_ptc_seq_ops);
  1016. }
  1017. static const struct file_operations proc_uv_ptc_operations = {
  1018. .open = uv_ptc_proc_open,
  1019. .read = seq_read,
  1020. .write = uv_ptc_proc_write,
  1021. .llseek = seq_lseek,
  1022. .release = seq_release,
  1023. };
  1024. static int __init uv_ptc_init(void)
  1025. {
  1026. struct proc_dir_entry *proc_uv_ptc;
  1027. if (!is_uv_system())
  1028. return 0;
  1029. proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
  1030. &proc_uv_ptc_operations);
  1031. if (!proc_uv_ptc) {
  1032. printk(KERN_ERR "unable to create %s proc entry\n",
  1033. UV_PTC_BASENAME);
  1034. return -EINVAL;
  1035. }
  1036. return 0;
  1037. }
  1038. /*
  1039. * initialize the sending side's sending buffers
  1040. */
  1041. static void
  1042. uv_activation_descriptor_init(int node, int pnode)
  1043. {
  1044. int i;
  1045. int cpu;
  1046. unsigned long pa;
  1047. unsigned long m;
  1048. unsigned long n;
  1049. struct bau_desc *bau_desc;
  1050. struct bau_desc *bd2;
  1051. struct bau_control *bcp;
  1052. /*
  1053. * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR)
  1054. * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per uvhub
  1055. */
  1056. bau_desc = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)*
  1057. UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node);
  1058. BUG_ON(!bau_desc);
  1059. pa = uv_gpa(bau_desc); /* need the real nasid*/
  1060. n = pa >> uv_nshift;
  1061. m = pa & uv_mmask;
  1062. uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE,
  1063. (n << UV_DESC_BASE_PNODE_SHIFT | m));
  1064. /*
  1065. * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each
  1066. * cpu even though we only use the first one; one descriptor can
  1067. * describe a broadcast to 256 uv hubs.
  1068. */
  1069. for (i = 0, bd2 = bau_desc; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR);
  1070. i++, bd2++) {
  1071. memset(bd2, 0, sizeof(struct bau_desc));
  1072. bd2->header.sw_ack_flag = 1;
  1073. /*
  1074. * base_dest_nodeid is the nasid (pnode<<1) of the first uvhub
  1075. * in the partition. The bit map will indicate uvhub numbers,
  1076. * which are 0-N in a partition. Pnodes are unique system-wide.
  1077. */
  1078. bd2->header.base_dest_nodeid = uv_partition_base_pnode << 1;
  1079. bd2->header.dest_subnodeid = 0x10; /* the LB */
  1080. bd2->header.command = UV_NET_ENDPOINT_INTD;
  1081. bd2->header.int_both = 1;
  1082. /*
  1083. * all others need to be set to zero:
  1084. * fairness chaining multilevel count replied_to
  1085. */
  1086. }
  1087. for_each_present_cpu(cpu) {
  1088. if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
  1089. continue;
  1090. bcp = &per_cpu(bau_control, cpu);
  1091. bcp->descriptor_base = bau_desc;
  1092. }
  1093. }
  1094. /*
  1095. * initialize the destination side's receiving buffers
  1096. * entered for each uvhub in the partition
  1097. * - node is first node (kernel memory notion) on the uvhub
  1098. * - pnode is the uvhub's physical identifier
  1099. */
  1100. static void
  1101. uv_payload_queue_init(int node, int pnode)
  1102. {
  1103. int pn;
  1104. int cpu;
  1105. char *cp;
  1106. unsigned long pa;
  1107. struct bau_payload_queue_entry *pqp;
  1108. struct bau_payload_queue_entry *pqp_malloc;
  1109. struct bau_control *bcp;
  1110. pqp = (struct bau_payload_queue_entry *) kmalloc_node(
  1111. (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry),
  1112. GFP_KERNEL, node);
  1113. BUG_ON(!pqp);
  1114. pqp_malloc = pqp;
  1115. cp = (char *)pqp + 31;
  1116. pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5);
  1117. for_each_present_cpu(cpu) {
  1118. if (pnode != uv_cpu_to_pnode(cpu))
  1119. continue;
  1120. /* for every cpu on this pnode: */
  1121. bcp = &per_cpu(bau_control, cpu);
  1122. bcp->va_queue_first = pqp;
  1123. bcp->bau_msg_head = pqp;
  1124. bcp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
  1125. }
  1126. /*
  1127. * need the pnode of where the memory was really allocated
  1128. */
  1129. pa = uv_gpa(pqp);
  1130. pn = pa >> uv_nshift;
  1131. uv_write_global_mmr64(pnode,
  1132. UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
  1133. ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) |
  1134. uv_physnodeaddr(pqp));
  1135. uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
  1136. uv_physnodeaddr(pqp));
  1137. uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
  1138. (unsigned long)
  1139. uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1)));
  1140. /* in effect, all msg_type's are set to MSG_NOOP */
  1141. memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE);
  1142. }
  1143. /*
  1144. * Initialization of each UV hub's structures
  1145. */
  1146. static void __init uv_init_uvhub(int uvhub, int vector)
  1147. {
  1148. int node;
  1149. int pnode;
  1150. unsigned long apicid;
  1151. node = uvhub_to_first_node(uvhub);
  1152. pnode = uv_blade_to_pnode(uvhub);
  1153. uv_activation_descriptor_init(node, pnode);
  1154. uv_payload_queue_init(node, pnode);
  1155. /*
  1156. * the below initialization can't be in firmware because the
  1157. * messaging IRQ will be determined by the OS
  1158. */
  1159. apicid = uvhub_to_first_apicid(uvhub);
  1160. uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
  1161. ((apicid << 32) | vector));
  1162. }
  1163. /*
  1164. * initialize the bau_control structure for each cpu
  1165. */
  1166. static void uv_init_per_cpu(int nuvhubs)
  1167. {
  1168. int i, j, k;
  1169. int cpu;
  1170. int pnode;
  1171. int uvhub;
  1172. short socket = 0;
  1173. struct bau_control *bcp;
  1174. struct uvhub_desc *bdp;
  1175. struct socket_desc *sdp;
  1176. struct bau_control *hmaster = NULL;
  1177. struct bau_control *smaster = NULL;
  1178. struct socket_desc {
  1179. short num_cpus;
  1180. short cpu_number[16];
  1181. };
  1182. struct uvhub_desc {
  1183. short num_sockets;
  1184. short num_cpus;
  1185. short uvhub;
  1186. short pnode;
  1187. struct socket_desc socket[2];
  1188. };
  1189. struct uvhub_desc *uvhub_descs;
  1190. uvhub_descs = (struct uvhub_desc *)
  1191. kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
  1192. memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
  1193. for_each_present_cpu(cpu) {
  1194. bcp = &per_cpu(bau_control, cpu);
  1195. memset(bcp, 0, sizeof(struct bau_control));
  1196. spin_lock_init(&bcp->masks_lock);
  1197. bcp->max_concurrent = uv_bau_max_concurrent;
  1198. pnode = uv_cpu_hub_info(cpu)->pnode;
  1199. uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
  1200. bdp = &uvhub_descs[uvhub];
  1201. bdp->num_cpus++;
  1202. bdp->uvhub = uvhub;
  1203. bdp->pnode = pnode;
  1204. /* time interval to catch a hardware stay-busy bug */
  1205. bcp->timeout_interval = millisec_2_cycles(3);
  1206. /* kludge: assume uv_hub.h is constant */
  1207. socket = (cpu_physical_id(cpu)>>5)&1;
  1208. if (socket >= bdp->num_sockets)
  1209. bdp->num_sockets = socket+1;
  1210. sdp = &bdp->socket[socket];
  1211. sdp->cpu_number[sdp->num_cpus] = cpu;
  1212. sdp->num_cpus++;
  1213. }
  1214. socket = 0;
  1215. for_each_possible_blade(uvhub) {
  1216. bdp = &uvhub_descs[uvhub];
  1217. for (i = 0; i < bdp->num_sockets; i++) {
  1218. sdp = &bdp->socket[i];
  1219. for (j = 0; j < sdp->num_cpus; j++) {
  1220. cpu = sdp->cpu_number[j];
  1221. bcp = &per_cpu(bau_control, cpu);
  1222. bcp->cpu = cpu;
  1223. if (j == 0) {
  1224. smaster = bcp;
  1225. if (i == 0)
  1226. hmaster = bcp;
  1227. }
  1228. bcp->cpus_in_uvhub = bdp->num_cpus;
  1229. bcp->cpus_in_socket = sdp->num_cpus;
  1230. bcp->socket_master = smaster;
  1231. bcp->uvhub_master = hmaster;
  1232. for (k = 0; k < DEST_Q_SIZE; k++)
  1233. bcp->socket_acknowledge_count[k] = 0;
  1234. bcp->uvhub_cpu =
  1235. uv_cpu_hub_info(cpu)->blade_processor_id;
  1236. }
  1237. socket++;
  1238. }
  1239. }
  1240. kfree(uvhub_descs);
  1241. }
  1242. /*
  1243. * Initialization of BAU-related structures
  1244. */
  1245. static int __init uv_bau_init(void)
  1246. {
  1247. int uvhub;
  1248. int pnode;
  1249. int nuvhubs;
  1250. int cur_cpu;
  1251. int vector;
  1252. unsigned long mmr;
  1253. if (!is_uv_system())
  1254. return 0;
  1255. if (nobau)
  1256. return 0;
  1257. for_each_possible_cpu(cur_cpu)
  1258. zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu),
  1259. GFP_KERNEL, cpu_to_node(cur_cpu));
  1260. uv_bau_max_concurrent = MAX_BAU_CONCURRENT;
  1261. uv_nshift = uv_hub_info->m_val;
  1262. uv_mmask = (1UL << uv_hub_info->m_val) - 1;
  1263. nuvhubs = uv_num_possible_blades();
  1264. uv_init_per_cpu(nuvhubs);
  1265. uv_partition_base_pnode = 0x7fffffff;
  1266. for (uvhub = 0; uvhub < nuvhubs; uvhub++)
  1267. if (uv_blade_nr_possible_cpus(uvhub) &&
  1268. (uv_blade_to_pnode(uvhub) < uv_partition_base_pnode))
  1269. uv_partition_base_pnode = uv_blade_to_pnode(uvhub);
  1270. vector = UV_BAU_MESSAGE;
  1271. for_each_possible_blade(uvhub)
  1272. if (uv_blade_nr_possible_cpus(uvhub))
  1273. uv_init_uvhub(uvhub, vector);
  1274. uv_enable_timeouts();
  1275. alloc_intr_gate(vector, uv_bau_message_intr1);
  1276. for_each_possible_blade(uvhub) {
  1277. pnode = uv_blade_to_pnode(uvhub);
  1278. /* INIT the bau */
  1279. uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL,
  1280. ((unsigned long)1 << 63));
  1281. mmr = 1; /* should be 1 to broadcast to both sockets */
  1282. uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST, mmr);
  1283. }
  1284. return 0;
  1285. }
  1286. core_initcall(uv_bau_init);
  1287. core_initcall(uv_ptc_init);