tlb_uv.c 44 KB

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