tlb_uv.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285
  1. /*
  2. * SGI UltraViolet TLB flush routines.
  3. *
  4. * (c) 2008-2014 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 <linux/delay.h>
  15. #include <asm/mmu_context.h>
  16. #include <asm/uv/uv.h>
  17. #include <asm/uv/uv_mmrs.h>
  18. #include <asm/uv/uv_hub.h>
  19. #include <asm/uv/uv_bau.h>
  20. #include <asm/apic.h>
  21. #include <asm/tsc.h>
  22. #include <asm/irq_vectors.h>
  23. #include <asm/timer.h>
  24. static struct bau_operations ops __ro_after_init;
  25. /* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
  26. static const int timeout_base_ns[] = {
  27. 20,
  28. 160,
  29. 1280,
  30. 10240,
  31. 81920,
  32. 655360,
  33. 5242880,
  34. 167772160
  35. };
  36. static int timeout_us;
  37. static bool nobau = true;
  38. static int nobau_perm;
  39. /* tunables: */
  40. static int max_concurr = MAX_BAU_CONCURRENT;
  41. static int max_concurr_const = MAX_BAU_CONCURRENT;
  42. static int plugged_delay = PLUGGED_DELAY;
  43. static int plugsb4reset = PLUGSB4RESET;
  44. static int giveup_limit = GIVEUP_LIMIT;
  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_respns_us = CONGESTED_RESPONSE_US;
  49. static int congested_reps = CONGESTED_REPS;
  50. static int disabled_period = DISABLED_PERIOD;
  51. static struct tunables tunables[] = {
  52. {&max_concurr, MAX_BAU_CONCURRENT}, /* must be [0] */
  53. {&plugged_delay, PLUGGED_DELAY},
  54. {&plugsb4reset, PLUGSB4RESET},
  55. {&timeoutsb4reset, TIMEOUTSB4RESET},
  56. {&ipi_reset_limit, IPI_RESET_LIMIT},
  57. {&complete_threshold, COMPLETE_THRESHOLD},
  58. {&congested_respns_us, CONGESTED_RESPONSE_US},
  59. {&congested_reps, CONGESTED_REPS},
  60. {&disabled_period, DISABLED_PERIOD},
  61. {&giveup_limit, GIVEUP_LIMIT}
  62. };
  63. static struct dentry *tunables_dir;
  64. static struct dentry *tunables_file;
  65. /* these correspond to the statistics printed by ptc_seq_show() */
  66. static char *stat_description[] = {
  67. "sent: number of shootdown messages sent",
  68. "stime: time spent sending messages",
  69. "numuvhubs: number of hubs targeted with shootdown",
  70. "numuvhubs16: number times 16 or more hubs targeted",
  71. "numuvhubs8: number times 8 or more hubs targeted",
  72. "numuvhubs4: number times 4 or more hubs targeted",
  73. "numuvhubs2: number times 2 or more hubs targeted",
  74. "numuvhubs1: number times 1 hub targeted",
  75. "numcpus: number of cpus targeted with shootdown",
  76. "dto: number of destination timeouts",
  77. "retries: destination timeout retries sent",
  78. "rok: : destination timeouts successfully retried",
  79. "resetp: ipi-style resource resets for plugs",
  80. "resett: ipi-style resource resets for timeouts",
  81. "giveup: fall-backs to ipi-style shootdowns",
  82. "sto: number of source timeouts",
  83. "bz: number of stay-busy's",
  84. "throt: number times spun in throttle",
  85. "swack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE",
  86. "recv: shootdown messages received",
  87. "rtime: time spent processing messages",
  88. "all: shootdown all-tlb messages",
  89. "one: shootdown one-tlb messages",
  90. "mult: interrupts that found multiple messages",
  91. "none: interrupts that found no messages",
  92. "retry: number of retry messages processed",
  93. "canc: number messages canceled by retries",
  94. "nocan: number retries that found nothing to cancel",
  95. "reset: number of ipi-style reset requests processed",
  96. "rcan: number messages canceled by reset requests",
  97. "disable: number times use of the BAU was disabled",
  98. "enable: number times use of the BAU was re-enabled"
  99. };
  100. static int __init setup_bau(char *arg)
  101. {
  102. int result;
  103. if (!arg)
  104. return -EINVAL;
  105. result = strtobool(arg, &nobau);
  106. if (result)
  107. return result;
  108. /* we need to flip the logic here, so that bau=y sets nobau to false */
  109. nobau = !nobau;
  110. if (!nobau)
  111. pr_info("UV BAU Enabled\n");
  112. else
  113. pr_info("UV BAU Disabled\n");
  114. return 0;
  115. }
  116. early_param("bau", setup_bau);
  117. /* base pnode in this partition */
  118. static int uv_base_pnode __read_mostly;
  119. static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
  120. static DEFINE_PER_CPU(struct bau_control, bau_control);
  121. static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
  122. static void
  123. set_bau_on(void)
  124. {
  125. int cpu;
  126. struct bau_control *bcp;
  127. if (nobau_perm) {
  128. pr_info("BAU not initialized; cannot be turned on\n");
  129. return;
  130. }
  131. nobau = false;
  132. for_each_present_cpu(cpu) {
  133. bcp = &per_cpu(bau_control, cpu);
  134. bcp->nobau = false;
  135. }
  136. pr_info("BAU turned on\n");
  137. return;
  138. }
  139. static void
  140. set_bau_off(void)
  141. {
  142. int cpu;
  143. struct bau_control *bcp;
  144. nobau = true;
  145. for_each_present_cpu(cpu) {
  146. bcp = &per_cpu(bau_control, cpu);
  147. bcp->nobau = true;
  148. }
  149. pr_info("BAU turned off\n");
  150. return;
  151. }
  152. /*
  153. * Determine the first node on a uvhub. 'Nodes' are used for kernel
  154. * memory allocation.
  155. */
  156. static int __init uvhub_to_first_node(int uvhub)
  157. {
  158. int node, b;
  159. for_each_online_node(node) {
  160. b = uv_node_to_blade_id(node);
  161. if (uvhub == b)
  162. return node;
  163. }
  164. return -1;
  165. }
  166. /*
  167. * Determine the apicid of the first cpu on a uvhub.
  168. */
  169. static int __init uvhub_to_first_apicid(int uvhub)
  170. {
  171. int cpu;
  172. for_each_present_cpu(cpu)
  173. if (uvhub == uv_cpu_to_blade_id(cpu))
  174. return per_cpu(x86_cpu_to_apicid, cpu);
  175. return -1;
  176. }
  177. /*
  178. * Free a software acknowledge hardware resource by clearing its Pending
  179. * bit. This will return a reply to the sender.
  180. * If the message has timed out, a reply has already been sent by the
  181. * hardware but the resource has not been released. In that case our
  182. * clear of the Timeout bit (as well) will free the resource. No reply will
  183. * be sent (the hardware will only do one reply per message).
  184. */
  185. static void reply_to_message(struct msg_desc *mdp, struct bau_control *bcp,
  186. int do_acknowledge)
  187. {
  188. unsigned long dw;
  189. struct bau_pq_entry *msg;
  190. msg = mdp->msg;
  191. if (!msg->canceled && do_acknowledge) {
  192. dw = (msg->swack_vec << UV_SW_ACK_NPENDING) | msg->swack_vec;
  193. ops.write_l_sw_ack(dw);
  194. }
  195. msg->replied_to = 1;
  196. msg->swack_vec = 0;
  197. }
  198. /*
  199. * Process the receipt of a RETRY message
  200. */
  201. static void bau_process_retry_msg(struct msg_desc *mdp,
  202. struct bau_control *bcp)
  203. {
  204. int i;
  205. int cancel_count = 0;
  206. unsigned long msg_res;
  207. unsigned long mmr = 0;
  208. struct bau_pq_entry *msg = mdp->msg;
  209. struct bau_pq_entry *msg2;
  210. struct ptc_stats *stat = bcp->statp;
  211. stat->d_retries++;
  212. /*
  213. * cancel any message from msg+1 to the retry itself
  214. */
  215. for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
  216. if (msg2 > mdp->queue_last)
  217. msg2 = mdp->queue_first;
  218. if (msg2 == msg)
  219. break;
  220. /* same conditions for cancellation as do_reset */
  221. if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
  222. (msg2->swack_vec) && ((msg2->swack_vec &
  223. msg->swack_vec) == 0) &&
  224. (msg2->sending_cpu == msg->sending_cpu) &&
  225. (msg2->msg_type != MSG_NOOP)) {
  226. mmr = ops.read_l_sw_ack();
  227. msg_res = msg2->swack_vec;
  228. /*
  229. * This is a message retry; clear the resources held
  230. * by the previous message only if they timed out.
  231. * If it has not timed out we have an unexpected
  232. * situation to report.
  233. */
  234. if (mmr & (msg_res << UV_SW_ACK_NPENDING)) {
  235. unsigned long mr;
  236. /*
  237. * Is the resource timed out?
  238. * Make everyone ignore the cancelled message.
  239. */
  240. msg2->canceled = 1;
  241. stat->d_canceled++;
  242. cancel_count++;
  243. mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
  244. ops.write_l_sw_ack(mr);
  245. }
  246. }
  247. }
  248. if (!cancel_count)
  249. stat->d_nocanceled++;
  250. }
  251. /*
  252. * Do all the things a cpu should do for a TLB shootdown message.
  253. * Other cpu's may come here at the same time for this message.
  254. */
  255. static void bau_process_message(struct msg_desc *mdp, struct bau_control *bcp,
  256. int do_acknowledge)
  257. {
  258. short socket_ack_count = 0;
  259. short *sp;
  260. struct atomic_short *asp;
  261. struct ptc_stats *stat = bcp->statp;
  262. struct bau_pq_entry *msg = mdp->msg;
  263. struct bau_control *smaster = bcp->socket_master;
  264. /*
  265. * This must be a normal message, or retry of a normal message
  266. */
  267. if (msg->address == TLB_FLUSH_ALL) {
  268. local_flush_tlb();
  269. stat->d_alltlb++;
  270. } else {
  271. __flush_tlb_one_user(msg->address);
  272. stat->d_onetlb++;
  273. }
  274. stat->d_requestee++;
  275. /*
  276. * One cpu on each uvhub has the additional job on a RETRY
  277. * of releasing the resource held by the message that is
  278. * being retried. That message is identified by sending
  279. * cpu number.
  280. */
  281. if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
  282. bau_process_retry_msg(mdp, bcp);
  283. /*
  284. * This is a swack message, so we have to reply to it.
  285. * Count each responding cpu on the socket. This avoids
  286. * pinging the count's cache line back and forth between
  287. * the sockets.
  288. */
  289. sp = &smaster->socket_acknowledge_count[mdp->msg_slot];
  290. asp = (struct atomic_short *)sp;
  291. socket_ack_count = atom_asr(1, asp);
  292. if (socket_ack_count == bcp->cpus_in_socket) {
  293. int msg_ack_count;
  294. /*
  295. * Both sockets dump their completed count total into
  296. * the message's count.
  297. */
  298. *sp = 0;
  299. asp = (struct atomic_short *)&msg->acknowledge_count;
  300. msg_ack_count = atom_asr(socket_ack_count, asp);
  301. if (msg_ack_count == bcp->cpus_in_uvhub) {
  302. /*
  303. * All cpus in uvhub saw it; reply
  304. * (unless we are in the UV2 workaround)
  305. */
  306. reply_to_message(mdp, bcp, do_acknowledge);
  307. }
  308. }
  309. return;
  310. }
  311. /*
  312. * Determine the first cpu on a pnode.
  313. */
  314. static int pnode_to_first_cpu(int pnode, struct bau_control *smaster)
  315. {
  316. int cpu;
  317. struct hub_and_pnode *hpp;
  318. for_each_present_cpu(cpu) {
  319. hpp = &smaster->thp[cpu];
  320. if (pnode == hpp->pnode)
  321. return cpu;
  322. }
  323. return -1;
  324. }
  325. /*
  326. * Last resort when we get a large number of destination timeouts is
  327. * to clear resources held by a given cpu.
  328. * Do this with IPI so that all messages in the BAU message queue
  329. * can be identified by their nonzero swack_vec field.
  330. *
  331. * This is entered for a single cpu on the uvhub.
  332. * The sender want's this uvhub to free a specific message's
  333. * swack resources.
  334. */
  335. static void do_reset(void *ptr)
  336. {
  337. int i;
  338. struct bau_control *bcp = &per_cpu(bau_control, smp_processor_id());
  339. struct reset_args *rap = (struct reset_args *)ptr;
  340. struct bau_pq_entry *msg;
  341. struct ptc_stats *stat = bcp->statp;
  342. stat->d_resets++;
  343. /*
  344. * We're looking for the given sender, and
  345. * will free its swack resource.
  346. * If all cpu's finally responded after the timeout, its
  347. * message 'replied_to' was set.
  348. */
  349. for (msg = bcp->queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
  350. unsigned long msg_res;
  351. /* do_reset: same conditions for cancellation as
  352. bau_process_retry_msg() */
  353. if ((msg->replied_to == 0) &&
  354. (msg->canceled == 0) &&
  355. (msg->sending_cpu == rap->sender) &&
  356. (msg->swack_vec) &&
  357. (msg->msg_type != MSG_NOOP)) {
  358. unsigned long mmr;
  359. unsigned long mr;
  360. /*
  361. * make everyone else ignore this message
  362. */
  363. msg->canceled = 1;
  364. /*
  365. * only reset the resource if it is still pending
  366. */
  367. mmr = ops.read_l_sw_ack();
  368. msg_res = msg->swack_vec;
  369. mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
  370. if (mmr & msg_res) {
  371. stat->d_rcanceled++;
  372. ops.write_l_sw_ack(mr);
  373. }
  374. }
  375. }
  376. return;
  377. }
  378. /*
  379. * Use IPI to get all target uvhubs to release resources held by
  380. * a given sending cpu number.
  381. */
  382. static void reset_with_ipi(struct pnmask *distribution, struct bau_control *bcp)
  383. {
  384. int pnode;
  385. int apnode;
  386. int maskbits;
  387. int sender = bcp->cpu;
  388. cpumask_t *mask = bcp->uvhub_master->cpumask;
  389. struct bau_control *smaster = bcp->socket_master;
  390. struct reset_args reset_args;
  391. reset_args.sender = sender;
  392. cpumask_clear(mask);
  393. /* find a single cpu for each uvhub in this distribution mask */
  394. maskbits = sizeof(struct pnmask) * BITSPERBYTE;
  395. /* each bit is a pnode relative to the partition base pnode */
  396. for (pnode = 0; pnode < maskbits; pnode++) {
  397. int cpu;
  398. if (!bau_uvhub_isset(pnode, distribution))
  399. continue;
  400. apnode = pnode + bcp->partition_base_pnode;
  401. cpu = pnode_to_first_cpu(apnode, smaster);
  402. cpumask_set_cpu(cpu, mask);
  403. }
  404. /* IPI all cpus; preemption is already disabled */
  405. smp_call_function_many(mask, do_reset, (void *)&reset_args, 1);
  406. return;
  407. }
  408. /*
  409. * Not to be confused with cycles_2_ns() from tsc.c; this gives a relative
  410. * number, not an absolute. It converts a duration in cycles to a duration in
  411. * ns.
  412. */
  413. static inline unsigned long long cycles_2_ns(unsigned long long cyc)
  414. {
  415. struct cyc2ns_data data;
  416. unsigned long long ns;
  417. cyc2ns_read_begin(&data);
  418. ns = mul_u64_u32_shr(cyc, data.cyc2ns_mul, data.cyc2ns_shift);
  419. cyc2ns_read_end();
  420. return ns;
  421. }
  422. /*
  423. * The reverse of the above; converts a duration in ns to a duration in cycles.
  424. */
  425. static inline unsigned long long ns_2_cycles(unsigned long long ns)
  426. {
  427. struct cyc2ns_data data;
  428. unsigned long long cyc;
  429. cyc2ns_read_begin(&data);
  430. cyc = (ns << data.cyc2ns_shift) / data.cyc2ns_mul;
  431. cyc2ns_read_end();
  432. return cyc;
  433. }
  434. static inline unsigned long cycles_2_us(unsigned long long cyc)
  435. {
  436. return cycles_2_ns(cyc) / NSEC_PER_USEC;
  437. }
  438. static inline cycles_t sec_2_cycles(unsigned long sec)
  439. {
  440. return ns_2_cycles(sec * NSEC_PER_SEC);
  441. }
  442. static inline unsigned long long usec_2_cycles(unsigned long usec)
  443. {
  444. return ns_2_cycles(usec * NSEC_PER_USEC);
  445. }
  446. /*
  447. * wait for all cpus on this hub to finish their sends and go quiet
  448. * leaves uvhub_quiesce set so that no new broadcasts are started by
  449. * bau_flush_send_and_wait()
  450. */
  451. static inline void quiesce_local_uvhub(struct bau_control *hmaster)
  452. {
  453. atom_asr(1, (struct atomic_short *)&hmaster->uvhub_quiesce);
  454. }
  455. /*
  456. * mark this quiet-requestor as done
  457. */
  458. static inline void end_uvhub_quiesce(struct bau_control *hmaster)
  459. {
  460. atom_asr(-1, (struct atomic_short *)&hmaster->uvhub_quiesce);
  461. }
  462. static unsigned long uv1_read_status(unsigned long mmr_offset, int right_shift)
  463. {
  464. unsigned long descriptor_status;
  465. descriptor_status = uv_read_local_mmr(mmr_offset);
  466. descriptor_status >>= right_shift;
  467. descriptor_status &= UV_ACT_STATUS_MASK;
  468. return descriptor_status;
  469. }
  470. /*
  471. * Wait for completion of a broadcast software ack message
  472. * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
  473. */
  474. static int uv1_wait_completion(struct bau_desc *bau_desc,
  475. struct bau_control *bcp, long try)
  476. {
  477. unsigned long descriptor_status;
  478. cycles_t ttm;
  479. u64 mmr_offset = bcp->status_mmr;
  480. int right_shift = bcp->status_index;
  481. struct ptc_stats *stat = bcp->statp;
  482. descriptor_status = uv1_read_status(mmr_offset, right_shift);
  483. /* spin on the status MMR, waiting for it to go idle */
  484. while ((descriptor_status != DS_IDLE)) {
  485. /*
  486. * Our software ack messages may be blocked because
  487. * there are no swack resources available. As long
  488. * as none of them has timed out hardware will NACK
  489. * our message and its state will stay IDLE.
  490. */
  491. if (descriptor_status == DS_SOURCE_TIMEOUT) {
  492. stat->s_stimeout++;
  493. return FLUSH_GIVEUP;
  494. } else if (descriptor_status == DS_DESTINATION_TIMEOUT) {
  495. stat->s_dtimeout++;
  496. ttm = get_cycles();
  497. /*
  498. * Our retries may be blocked by all destination
  499. * swack resources being consumed, and a timeout
  500. * pending. In that case hardware returns the
  501. * ERROR that looks like a destination timeout.
  502. */
  503. if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
  504. bcp->conseccompletes = 0;
  505. return FLUSH_RETRY_PLUGGED;
  506. }
  507. bcp->conseccompletes = 0;
  508. return FLUSH_RETRY_TIMEOUT;
  509. } else {
  510. /*
  511. * descriptor_status is still BUSY
  512. */
  513. cpu_relax();
  514. }
  515. descriptor_status = uv1_read_status(mmr_offset, right_shift);
  516. }
  517. bcp->conseccompletes++;
  518. return FLUSH_COMPLETE;
  519. }
  520. /*
  521. * UV2 could have an extra bit of status in the ACTIVATION_STATUS_2 register.
  522. * But not currently used.
  523. */
  524. static unsigned long uv2_3_read_status(unsigned long offset, int rshft, int desc)
  525. {
  526. return ((read_lmmr(offset) >> rshft) & UV_ACT_STATUS_MASK) << 1;
  527. }
  528. /*
  529. * Entered when a bau descriptor has gone into a permanent busy wait because
  530. * of a hardware bug.
  531. * Workaround the bug.
  532. */
  533. static int handle_uv2_busy(struct bau_control *bcp)
  534. {
  535. struct ptc_stats *stat = bcp->statp;
  536. stat->s_uv2_wars++;
  537. bcp->busy = 1;
  538. return FLUSH_GIVEUP;
  539. }
  540. static int uv2_3_wait_completion(struct bau_desc *bau_desc,
  541. struct bau_control *bcp, long try)
  542. {
  543. unsigned long descriptor_stat;
  544. cycles_t ttm;
  545. u64 mmr_offset = bcp->status_mmr;
  546. int right_shift = bcp->status_index;
  547. int desc = bcp->uvhub_cpu;
  548. long busy_reps = 0;
  549. struct ptc_stats *stat = bcp->statp;
  550. descriptor_stat = uv2_3_read_status(mmr_offset, right_shift, desc);
  551. /* spin on the status MMR, waiting for it to go idle */
  552. while (descriptor_stat != UV2H_DESC_IDLE) {
  553. if (descriptor_stat == UV2H_DESC_SOURCE_TIMEOUT) {
  554. /*
  555. * A h/w bug on the destination side may
  556. * have prevented the message being marked
  557. * pending, thus it doesn't get replied to
  558. * and gets continually nacked until it times
  559. * out with a SOURCE_TIMEOUT.
  560. */
  561. stat->s_stimeout++;
  562. return FLUSH_GIVEUP;
  563. } else if (descriptor_stat == UV2H_DESC_DEST_TIMEOUT) {
  564. ttm = get_cycles();
  565. /*
  566. * Our retries may be blocked by all destination
  567. * swack resources being consumed, and a timeout
  568. * pending. In that case hardware returns the
  569. * ERROR that looks like a destination timeout.
  570. * Without using the extended status we have to
  571. * deduce from the short time that this was a
  572. * strong nack.
  573. */
  574. if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
  575. bcp->conseccompletes = 0;
  576. stat->s_plugged++;
  577. /* FLUSH_RETRY_PLUGGED causes hang on boot */
  578. return FLUSH_GIVEUP;
  579. }
  580. stat->s_dtimeout++;
  581. bcp->conseccompletes = 0;
  582. /* FLUSH_RETRY_TIMEOUT causes hang on boot */
  583. return FLUSH_GIVEUP;
  584. } else {
  585. busy_reps++;
  586. if (busy_reps > 1000000) {
  587. /* not to hammer on the clock */
  588. busy_reps = 0;
  589. ttm = get_cycles();
  590. if ((ttm - bcp->send_message) > bcp->timeout_interval)
  591. return handle_uv2_busy(bcp);
  592. }
  593. /*
  594. * descriptor_stat is still BUSY
  595. */
  596. cpu_relax();
  597. }
  598. descriptor_stat = uv2_3_read_status(mmr_offset, right_shift, desc);
  599. }
  600. bcp->conseccompletes++;
  601. return FLUSH_COMPLETE;
  602. }
  603. /*
  604. * Returns the status of current BAU message for cpu desc as a bit field
  605. * [Error][Busy][Aux]
  606. */
  607. static u64 read_status(u64 status_mmr, int index, int desc)
  608. {
  609. u64 stat;
  610. stat = ((read_lmmr(status_mmr) >> index) & UV_ACT_STATUS_MASK) << 1;
  611. stat |= (read_lmmr(UVH_LB_BAU_SB_ACTIVATION_STATUS_2) >> desc) & 0x1;
  612. return stat;
  613. }
  614. static int uv4_wait_completion(struct bau_desc *bau_desc,
  615. struct bau_control *bcp, long try)
  616. {
  617. struct ptc_stats *stat = bcp->statp;
  618. u64 descriptor_stat;
  619. u64 mmr = bcp->status_mmr;
  620. int index = bcp->status_index;
  621. int desc = bcp->uvhub_cpu;
  622. descriptor_stat = read_status(mmr, index, desc);
  623. /* spin on the status MMR, waiting for it to go idle */
  624. while (descriptor_stat != UV2H_DESC_IDLE) {
  625. switch (descriptor_stat) {
  626. case UV2H_DESC_SOURCE_TIMEOUT:
  627. stat->s_stimeout++;
  628. return FLUSH_GIVEUP;
  629. case UV2H_DESC_DEST_TIMEOUT:
  630. stat->s_dtimeout++;
  631. bcp->conseccompletes = 0;
  632. return FLUSH_RETRY_TIMEOUT;
  633. case UV2H_DESC_DEST_STRONG_NACK:
  634. stat->s_plugged++;
  635. bcp->conseccompletes = 0;
  636. return FLUSH_RETRY_PLUGGED;
  637. case UV2H_DESC_DEST_PUT_ERR:
  638. bcp->conseccompletes = 0;
  639. return FLUSH_GIVEUP;
  640. default:
  641. /* descriptor_stat is still BUSY */
  642. cpu_relax();
  643. }
  644. descriptor_stat = read_status(mmr, index, desc);
  645. }
  646. bcp->conseccompletes++;
  647. return FLUSH_COMPLETE;
  648. }
  649. /*
  650. * Our retries are blocked by all destination sw ack resources being
  651. * in use, and a timeout is pending. In that case hardware immediately
  652. * returns the ERROR that looks like a destination timeout.
  653. */
  654. static void destination_plugged(struct bau_desc *bau_desc,
  655. struct bau_control *bcp,
  656. struct bau_control *hmaster, struct ptc_stats *stat)
  657. {
  658. udelay(bcp->plugged_delay);
  659. bcp->plugged_tries++;
  660. if (bcp->plugged_tries >= bcp->plugsb4reset) {
  661. bcp->plugged_tries = 0;
  662. quiesce_local_uvhub(hmaster);
  663. spin_lock(&hmaster->queue_lock);
  664. reset_with_ipi(&bau_desc->distribution, bcp);
  665. spin_unlock(&hmaster->queue_lock);
  666. end_uvhub_quiesce(hmaster);
  667. bcp->ipi_attempts++;
  668. stat->s_resets_plug++;
  669. }
  670. }
  671. static void destination_timeout(struct bau_desc *bau_desc,
  672. struct bau_control *bcp, struct bau_control *hmaster,
  673. struct ptc_stats *stat)
  674. {
  675. hmaster->max_concurr = 1;
  676. bcp->timeout_tries++;
  677. if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
  678. bcp->timeout_tries = 0;
  679. quiesce_local_uvhub(hmaster);
  680. spin_lock(&hmaster->queue_lock);
  681. reset_with_ipi(&bau_desc->distribution, bcp);
  682. spin_unlock(&hmaster->queue_lock);
  683. end_uvhub_quiesce(hmaster);
  684. bcp->ipi_attempts++;
  685. stat->s_resets_timeout++;
  686. }
  687. }
  688. /*
  689. * Stop all cpus on a uvhub from using the BAU for a period of time.
  690. * This is reversed by check_enable.
  691. */
  692. static void disable_for_period(struct bau_control *bcp, struct ptc_stats *stat)
  693. {
  694. int tcpu;
  695. struct bau_control *tbcp;
  696. struct bau_control *hmaster;
  697. cycles_t tm1;
  698. hmaster = bcp->uvhub_master;
  699. spin_lock(&hmaster->disable_lock);
  700. if (!bcp->baudisabled) {
  701. stat->s_bau_disabled++;
  702. tm1 = get_cycles();
  703. for_each_present_cpu(tcpu) {
  704. tbcp = &per_cpu(bau_control, tcpu);
  705. if (tbcp->uvhub_master == hmaster) {
  706. tbcp->baudisabled = 1;
  707. tbcp->set_bau_on_time =
  708. tm1 + bcp->disabled_period;
  709. }
  710. }
  711. }
  712. spin_unlock(&hmaster->disable_lock);
  713. }
  714. static void count_max_concurr(int stat, struct bau_control *bcp,
  715. struct bau_control *hmaster)
  716. {
  717. bcp->plugged_tries = 0;
  718. bcp->timeout_tries = 0;
  719. if (stat != FLUSH_COMPLETE)
  720. return;
  721. if (bcp->conseccompletes <= bcp->complete_threshold)
  722. return;
  723. if (hmaster->max_concurr >= hmaster->max_concurr_const)
  724. return;
  725. hmaster->max_concurr++;
  726. }
  727. static void record_send_stats(cycles_t time1, cycles_t time2,
  728. struct bau_control *bcp, struct ptc_stats *stat,
  729. int completion_status, int try)
  730. {
  731. cycles_t elapsed;
  732. if (time2 > time1) {
  733. elapsed = time2 - time1;
  734. stat->s_time += elapsed;
  735. if ((completion_status == FLUSH_COMPLETE) && (try == 1)) {
  736. bcp->period_requests++;
  737. bcp->period_time += elapsed;
  738. if ((elapsed > usec_2_cycles(bcp->cong_response_us)) &&
  739. (bcp->period_requests > bcp->cong_reps) &&
  740. ((bcp->period_time / bcp->period_requests) >
  741. usec_2_cycles(bcp->cong_response_us))) {
  742. stat->s_congested++;
  743. disable_for_period(bcp, stat);
  744. }
  745. }
  746. } else
  747. stat->s_requestor--;
  748. if (completion_status == FLUSH_COMPLETE && try > 1)
  749. stat->s_retriesok++;
  750. else if (completion_status == FLUSH_GIVEUP) {
  751. stat->s_giveup++;
  752. if (get_cycles() > bcp->period_end)
  753. bcp->period_giveups = 0;
  754. bcp->period_giveups++;
  755. if (bcp->period_giveups == 1)
  756. bcp->period_end = get_cycles() + bcp->disabled_period;
  757. if (bcp->period_giveups > bcp->giveup_limit) {
  758. disable_for_period(bcp, stat);
  759. stat->s_giveuplimit++;
  760. }
  761. }
  762. }
  763. /*
  764. * Because of a uv1 hardware bug only a limited number of concurrent
  765. * requests can be made.
  766. */
  767. static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
  768. {
  769. spinlock_t *lock = &hmaster->uvhub_lock;
  770. atomic_t *v;
  771. v = &hmaster->active_descriptor_count;
  772. if (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr)) {
  773. stat->s_throttles++;
  774. do {
  775. cpu_relax();
  776. } while (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr));
  777. }
  778. }
  779. /*
  780. * Handle the completion status of a message send.
  781. */
  782. static void handle_cmplt(int completion_status, struct bau_desc *bau_desc,
  783. struct bau_control *bcp, struct bau_control *hmaster,
  784. struct ptc_stats *stat)
  785. {
  786. if (completion_status == FLUSH_RETRY_PLUGGED)
  787. destination_plugged(bau_desc, bcp, hmaster, stat);
  788. else if (completion_status == FLUSH_RETRY_TIMEOUT)
  789. destination_timeout(bau_desc, bcp, hmaster, stat);
  790. }
  791. /*
  792. * Send a broadcast and wait for it to complete.
  793. *
  794. * The flush_mask contains the cpus the broadcast is to be sent to including
  795. * cpus that are on the local uvhub.
  796. *
  797. * Returns 0 if all flushing represented in the mask was done.
  798. * Returns 1 if it gives up entirely and the original cpu mask is to be
  799. * returned to the kernel.
  800. */
  801. static int uv_flush_send_and_wait(struct cpumask *flush_mask,
  802. struct bau_control *bcp,
  803. struct bau_desc *bau_desc)
  804. {
  805. int seq_number = 0;
  806. int completion_stat = 0;
  807. int uv1 = 0;
  808. long try = 0;
  809. unsigned long index;
  810. cycles_t time1;
  811. cycles_t time2;
  812. struct ptc_stats *stat = bcp->statp;
  813. struct bau_control *hmaster = bcp->uvhub_master;
  814. struct uv1_bau_msg_header *uv1_hdr = NULL;
  815. struct uv2_3_bau_msg_header *uv2_3_hdr = NULL;
  816. if (bcp->uvhub_version == UV_BAU_V1) {
  817. uv1 = 1;
  818. uv1_throttle(hmaster, stat);
  819. }
  820. while (hmaster->uvhub_quiesce)
  821. cpu_relax();
  822. time1 = get_cycles();
  823. if (uv1)
  824. uv1_hdr = &bau_desc->header.uv1_hdr;
  825. else
  826. /* uv2 and uv3 */
  827. uv2_3_hdr = &bau_desc->header.uv2_3_hdr;
  828. do {
  829. if (try == 0) {
  830. if (uv1)
  831. uv1_hdr->msg_type = MSG_REGULAR;
  832. else
  833. uv2_3_hdr->msg_type = MSG_REGULAR;
  834. seq_number = bcp->message_number++;
  835. } else {
  836. if (uv1)
  837. uv1_hdr->msg_type = MSG_RETRY;
  838. else
  839. uv2_3_hdr->msg_type = MSG_RETRY;
  840. stat->s_retry_messages++;
  841. }
  842. if (uv1)
  843. uv1_hdr->sequence = seq_number;
  844. else
  845. uv2_3_hdr->sequence = seq_number;
  846. index = (1UL << AS_PUSH_SHIFT) | bcp->uvhub_cpu;
  847. bcp->send_message = get_cycles();
  848. write_mmr_activation(index);
  849. try++;
  850. completion_stat = ops.wait_completion(bau_desc, bcp, try);
  851. handle_cmplt(completion_stat, bau_desc, bcp, hmaster, stat);
  852. if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
  853. bcp->ipi_attempts = 0;
  854. stat->s_overipilimit++;
  855. completion_stat = FLUSH_GIVEUP;
  856. break;
  857. }
  858. cpu_relax();
  859. } while ((completion_stat == FLUSH_RETRY_PLUGGED) ||
  860. (completion_stat == FLUSH_RETRY_TIMEOUT));
  861. time2 = get_cycles();
  862. count_max_concurr(completion_stat, bcp, hmaster);
  863. while (hmaster->uvhub_quiesce)
  864. cpu_relax();
  865. atomic_dec(&hmaster->active_descriptor_count);
  866. record_send_stats(time1, time2, bcp, stat, completion_stat, try);
  867. if (completion_stat == FLUSH_GIVEUP)
  868. /* FLUSH_GIVEUP will fall back to using IPI's for tlb flush */
  869. return 1;
  870. return 0;
  871. }
  872. /*
  873. * The BAU is disabled for this uvhub. When the disabled time period has
  874. * expired re-enable it.
  875. * Return 0 if it is re-enabled for all cpus on this uvhub.
  876. */
  877. static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
  878. {
  879. int tcpu;
  880. struct bau_control *tbcp;
  881. struct bau_control *hmaster;
  882. hmaster = bcp->uvhub_master;
  883. spin_lock(&hmaster->disable_lock);
  884. if (bcp->baudisabled && (get_cycles() >= bcp->set_bau_on_time)) {
  885. stat->s_bau_reenabled++;
  886. for_each_present_cpu(tcpu) {
  887. tbcp = &per_cpu(bau_control, tcpu);
  888. if (tbcp->uvhub_master == hmaster) {
  889. tbcp->baudisabled = 0;
  890. tbcp->period_requests = 0;
  891. tbcp->period_time = 0;
  892. tbcp->period_giveups = 0;
  893. }
  894. }
  895. spin_unlock(&hmaster->disable_lock);
  896. return 0;
  897. }
  898. spin_unlock(&hmaster->disable_lock);
  899. return -1;
  900. }
  901. static void record_send_statistics(struct ptc_stats *stat, int locals, int hubs,
  902. int remotes, struct bau_desc *bau_desc)
  903. {
  904. stat->s_requestor++;
  905. stat->s_ntargcpu += remotes + locals;
  906. stat->s_ntargremotes += remotes;
  907. stat->s_ntarglocals += locals;
  908. /* uvhub statistics */
  909. hubs = bau_uvhub_weight(&bau_desc->distribution);
  910. if (locals) {
  911. stat->s_ntarglocaluvhub++;
  912. stat->s_ntargremoteuvhub += (hubs - 1);
  913. } else
  914. stat->s_ntargremoteuvhub += hubs;
  915. stat->s_ntarguvhub += hubs;
  916. if (hubs >= 16)
  917. stat->s_ntarguvhub16++;
  918. else if (hubs >= 8)
  919. stat->s_ntarguvhub8++;
  920. else if (hubs >= 4)
  921. stat->s_ntarguvhub4++;
  922. else if (hubs >= 2)
  923. stat->s_ntarguvhub2++;
  924. else
  925. stat->s_ntarguvhub1++;
  926. }
  927. /*
  928. * Translate a cpu mask to the uvhub distribution mask in the BAU
  929. * activation descriptor.
  930. */
  931. static int set_distrib_bits(struct cpumask *flush_mask, struct bau_control *bcp,
  932. struct bau_desc *bau_desc, int *localsp, int *remotesp)
  933. {
  934. int cpu;
  935. int pnode;
  936. int cnt = 0;
  937. struct hub_and_pnode *hpp;
  938. for_each_cpu(cpu, flush_mask) {
  939. /*
  940. * The distribution vector is a bit map of pnodes, relative
  941. * to the partition base pnode (and the partition base nasid
  942. * in the header).
  943. * Translate cpu to pnode and hub using a local memory array.
  944. */
  945. hpp = &bcp->socket_master->thp[cpu];
  946. pnode = hpp->pnode - bcp->partition_base_pnode;
  947. bau_uvhub_set(pnode, &bau_desc->distribution);
  948. cnt++;
  949. if (hpp->uvhub == bcp->uvhub)
  950. (*localsp)++;
  951. else
  952. (*remotesp)++;
  953. }
  954. if (!cnt)
  955. return 1;
  956. return 0;
  957. }
  958. /*
  959. * globally purge translation cache of a virtual address or all TLB's
  960. * @cpumask: mask of all cpu's in which the address is to be removed
  961. * @mm: mm_struct containing virtual address range
  962. * @start: start virtual address to be removed from TLB
  963. * @end: end virtual address to be remove from TLB
  964. * @cpu: the current cpu
  965. *
  966. * This is the entry point for initiating any UV global TLB shootdown.
  967. *
  968. * Purges the translation caches of all specified processors of the given
  969. * virtual address, or purges all TLB's on specified processors.
  970. *
  971. * The caller has derived the cpumask from the mm_struct. This function
  972. * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
  973. *
  974. * The cpumask is converted into a uvhubmask of the uvhubs containing
  975. * those cpus.
  976. *
  977. * Note that this function should be called with preemption disabled.
  978. *
  979. * Returns NULL if all remote flushing was done.
  980. * Returns pointer to cpumask if some remote flushing remains to be
  981. * done. The returned pointer is valid till preemption is re-enabled.
  982. */
  983. const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
  984. const struct flush_tlb_info *info)
  985. {
  986. unsigned int cpu = smp_processor_id();
  987. int locals = 0, remotes = 0, hubs = 0;
  988. struct bau_desc *bau_desc;
  989. struct cpumask *flush_mask;
  990. struct ptc_stats *stat;
  991. struct bau_control *bcp;
  992. unsigned long descriptor_status, status, address;
  993. bcp = &per_cpu(bau_control, cpu);
  994. if (bcp->nobau)
  995. return cpumask;
  996. stat = bcp->statp;
  997. stat->s_enters++;
  998. if (bcp->busy) {
  999. descriptor_status =
  1000. read_lmmr(UVH_LB_BAU_SB_ACTIVATION_STATUS_0);
  1001. status = ((descriptor_status >> (bcp->uvhub_cpu *
  1002. UV_ACT_STATUS_SIZE)) & UV_ACT_STATUS_MASK) << 1;
  1003. if (status == UV2H_DESC_BUSY)
  1004. return cpumask;
  1005. bcp->busy = 0;
  1006. }
  1007. /* bau was disabled due to slow response */
  1008. if (bcp->baudisabled) {
  1009. if (check_enable(bcp, stat)) {
  1010. stat->s_ipifordisabled++;
  1011. return cpumask;
  1012. }
  1013. }
  1014. /*
  1015. * Each sending cpu has a per-cpu mask which it fills from the caller's
  1016. * cpu mask. All cpus are converted to uvhubs and copied to the
  1017. * activation descriptor.
  1018. */
  1019. flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
  1020. /* don't actually do a shootdown of the local cpu */
  1021. cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
  1022. if (cpumask_test_cpu(cpu, cpumask))
  1023. stat->s_ntargself++;
  1024. bau_desc = bcp->descriptor_base;
  1025. bau_desc += (ITEMS_PER_DESC * bcp->uvhub_cpu);
  1026. bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
  1027. if (set_distrib_bits(flush_mask, bcp, bau_desc, &locals, &remotes))
  1028. return NULL;
  1029. record_send_statistics(stat, locals, hubs, remotes, bau_desc);
  1030. if (!info->end || (info->end - info->start) <= PAGE_SIZE)
  1031. address = info->start;
  1032. else
  1033. address = TLB_FLUSH_ALL;
  1034. switch (bcp->uvhub_version) {
  1035. case UV_BAU_V1:
  1036. case UV_BAU_V2:
  1037. case UV_BAU_V3:
  1038. bau_desc->payload.uv1_2_3.address = address;
  1039. bau_desc->payload.uv1_2_3.sending_cpu = cpu;
  1040. break;
  1041. case UV_BAU_V4:
  1042. bau_desc->payload.uv4.address = address;
  1043. bau_desc->payload.uv4.sending_cpu = cpu;
  1044. bau_desc->payload.uv4.qualifier = BAU_DESC_QUALIFIER;
  1045. break;
  1046. }
  1047. /*
  1048. * uv_flush_send_and_wait returns 0 if all cpu's were messaged,
  1049. * or 1 if it gave up and the original cpumask should be returned.
  1050. */
  1051. if (!uv_flush_send_and_wait(flush_mask, bcp, bau_desc))
  1052. return NULL;
  1053. else
  1054. return cpumask;
  1055. }
  1056. /*
  1057. * Search the message queue for any 'other' unprocessed message with the
  1058. * same software acknowledge resource bit vector as the 'msg' message.
  1059. */
  1060. static struct bau_pq_entry *find_another_by_swack(struct bau_pq_entry *msg,
  1061. struct bau_control *bcp)
  1062. {
  1063. struct bau_pq_entry *msg_next = msg + 1;
  1064. unsigned char swack_vec = msg->swack_vec;
  1065. if (msg_next > bcp->queue_last)
  1066. msg_next = bcp->queue_first;
  1067. while (msg_next != msg) {
  1068. if ((msg_next->canceled == 0) && (msg_next->replied_to == 0) &&
  1069. (msg_next->swack_vec == swack_vec))
  1070. return msg_next;
  1071. msg_next++;
  1072. if (msg_next > bcp->queue_last)
  1073. msg_next = bcp->queue_first;
  1074. }
  1075. return NULL;
  1076. }
  1077. /*
  1078. * UV2 needs to work around a bug in which an arriving message has not
  1079. * set a bit in the UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE register.
  1080. * Such a message must be ignored.
  1081. */
  1082. static void process_uv2_message(struct msg_desc *mdp, struct bau_control *bcp)
  1083. {
  1084. unsigned long mmr_image;
  1085. unsigned char swack_vec;
  1086. struct bau_pq_entry *msg = mdp->msg;
  1087. struct bau_pq_entry *other_msg;
  1088. mmr_image = ops.read_l_sw_ack();
  1089. swack_vec = msg->swack_vec;
  1090. if ((swack_vec & mmr_image) == 0) {
  1091. /*
  1092. * This message was assigned a swack resource, but no
  1093. * reserved acknowlegment is pending.
  1094. * The bug has prevented this message from setting the MMR.
  1095. */
  1096. /*
  1097. * Some message has set the MMR 'pending' bit; it might have
  1098. * been another message. Look for that message.
  1099. */
  1100. other_msg = find_another_by_swack(msg, bcp);
  1101. if (other_msg) {
  1102. /*
  1103. * There is another. Process this one but do not
  1104. * ack it.
  1105. */
  1106. bau_process_message(mdp, bcp, 0);
  1107. /*
  1108. * Let the natural processing of that other message
  1109. * acknowledge it. Don't get the processing of sw_ack's
  1110. * out of order.
  1111. */
  1112. return;
  1113. }
  1114. }
  1115. /*
  1116. * Either the MMR shows this one pending a reply or there is no
  1117. * other message using this sw_ack, so it is safe to acknowledge it.
  1118. */
  1119. bau_process_message(mdp, bcp, 1);
  1120. return;
  1121. }
  1122. /*
  1123. * The BAU message interrupt comes here. (registered by set_intr_gate)
  1124. * See entry_64.S
  1125. *
  1126. * We received a broadcast assist message.
  1127. *
  1128. * Interrupts are disabled; this interrupt could represent
  1129. * the receipt of several messages.
  1130. *
  1131. * All cores/threads on this hub get this interrupt.
  1132. * The last one to see it does the software ack.
  1133. * (the resource will not be freed until noninterruptable cpus see this
  1134. * interrupt; hardware may timeout the s/w ack and reply ERROR)
  1135. */
  1136. void uv_bau_message_interrupt(struct pt_regs *regs)
  1137. {
  1138. int count = 0;
  1139. cycles_t time_start;
  1140. struct bau_pq_entry *msg;
  1141. struct bau_control *bcp;
  1142. struct ptc_stats *stat;
  1143. struct msg_desc msgdesc;
  1144. ack_APIC_irq();
  1145. kvm_set_cpu_l1tf_flush_l1d();
  1146. time_start = get_cycles();
  1147. bcp = &per_cpu(bau_control, smp_processor_id());
  1148. stat = bcp->statp;
  1149. msgdesc.queue_first = bcp->queue_first;
  1150. msgdesc.queue_last = bcp->queue_last;
  1151. msg = bcp->bau_msg_head;
  1152. while (msg->swack_vec) {
  1153. count++;
  1154. msgdesc.msg_slot = msg - msgdesc.queue_first;
  1155. msgdesc.msg = msg;
  1156. if (bcp->uvhub_version == UV_BAU_V2)
  1157. process_uv2_message(&msgdesc, bcp);
  1158. else
  1159. /* no error workaround for uv1 or uv3 */
  1160. bau_process_message(&msgdesc, bcp, 1);
  1161. msg++;
  1162. if (msg > msgdesc.queue_last)
  1163. msg = msgdesc.queue_first;
  1164. bcp->bau_msg_head = msg;
  1165. }
  1166. stat->d_time += (get_cycles() - time_start);
  1167. if (!count)
  1168. stat->d_nomsg++;
  1169. else if (count > 1)
  1170. stat->d_multmsg++;
  1171. }
  1172. /*
  1173. * Each target uvhub (i.e. a uvhub that has cpu's) needs to have
  1174. * shootdown message timeouts enabled. The timeout does not cause
  1175. * an interrupt, but causes an error message to be returned to
  1176. * the sender.
  1177. */
  1178. static void __init enable_timeouts(void)
  1179. {
  1180. int uvhub;
  1181. int nuvhubs;
  1182. int pnode;
  1183. unsigned long mmr_image;
  1184. nuvhubs = uv_num_possible_blades();
  1185. for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
  1186. if (!uv_blade_nr_possible_cpus(uvhub))
  1187. continue;
  1188. pnode = uv_blade_to_pnode(uvhub);
  1189. mmr_image = read_mmr_misc_control(pnode);
  1190. /*
  1191. * Set the timeout period and then lock it in, in three
  1192. * steps; captures and locks in the period.
  1193. *
  1194. * To program the period, the SOFT_ACK_MODE must be off.
  1195. */
  1196. mmr_image &= ~(1L << SOFTACK_MSHIFT);
  1197. write_mmr_misc_control(pnode, mmr_image);
  1198. /*
  1199. * Set the 4-bit period.
  1200. */
  1201. mmr_image &= ~((unsigned long)0xf << SOFTACK_PSHIFT);
  1202. mmr_image |= (SOFTACK_TIMEOUT_PERIOD << SOFTACK_PSHIFT);
  1203. write_mmr_misc_control(pnode, mmr_image);
  1204. /*
  1205. * UV1:
  1206. * Subsequent reversals of the timebase bit (3) cause an
  1207. * immediate timeout of one or all INTD resources as
  1208. * indicated in bits 2:0 (7 causes all of them to timeout).
  1209. */
  1210. mmr_image |= (1L << SOFTACK_MSHIFT);
  1211. if (is_uv2_hub()) {
  1212. /* do not touch the legacy mode bit */
  1213. /* hw bug workaround; do not use extended status */
  1214. mmr_image &= ~(1L << UV2_EXT_SHFT);
  1215. } else if (is_uv3_hub()) {
  1216. mmr_image &= ~(1L << PREFETCH_HINT_SHFT);
  1217. mmr_image |= (1L << SB_STATUS_SHFT);
  1218. }
  1219. write_mmr_misc_control(pnode, mmr_image);
  1220. }
  1221. }
  1222. static void *ptc_seq_start(struct seq_file *file, loff_t *offset)
  1223. {
  1224. if (*offset < num_possible_cpus())
  1225. return offset;
  1226. return NULL;
  1227. }
  1228. static void *ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
  1229. {
  1230. (*offset)++;
  1231. if (*offset < num_possible_cpus())
  1232. return offset;
  1233. return NULL;
  1234. }
  1235. static void ptc_seq_stop(struct seq_file *file, void *data)
  1236. {
  1237. }
  1238. /*
  1239. * Display the statistics thru /proc/sgi_uv/ptc_statistics
  1240. * 'data' points to the cpu number
  1241. * Note: see the descriptions in stat_description[].
  1242. */
  1243. static int ptc_seq_show(struct seq_file *file, void *data)
  1244. {
  1245. struct ptc_stats *stat;
  1246. struct bau_control *bcp;
  1247. int cpu;
  1248. cpu = *(loff_t *)data;
  1249. if (!cpu) {
  1250. seq_puts(file,
  1251. "# cpu bauoff sent stime self locals remotes ncpus localhub ");
  1252. seq_puts(file, "remotehub numuvhubs numuvhubs16 numuvhubs8 ");
  1253. seq_puts(file,
  1254. "numuvhubs4 numuvhubs2 numuvhubs1 dto snacks retries ");
  1255. seq_puts(file,
  1256. "rok resetp resett giveup sto bz throt disable ");
  1257. seq_puts(file,
  1258. "enable wars warshw warwaits enters ipidis plugged ");
  1259. seq_puts(file,
  1260. "ipiover glim cong swack recv rtime all one mult ");
  1261. seq_puts(file, "none retry canc nocan reset rcan\n");
  1262. }
  1263. if (cpu < num_possible_cpus() && cpu_online(cpu)) {
  1264. bcp = &per_cpu(bau_control, cpu);
  1265. if (bcp->nobau) {
  1266. seq_printf(file, "cpu %d bau disabled\n", cpu);
  1267. return 0;
  1268. }
  1269. stat = bcp->statp;
  1270. /* source side statistics */
  1271. seq_printf(file,
  1272. "cpu %d %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
  1273. cpu, bcp->nobau, stat->s_requestor,
  1274. cycles_2_us(stat->s_time),
  1275. stat->s_ntargself, stat->s_ntarglocals,
  1276. stat->s_ntargremotes, stat->s_ntargcpu,
  1277. stat->s_ntarglocaluvhub, stat->s_ntargremoteuvhub,
  1278. stat->s_ntarguvhub, stat->s_ntarguvhub16);
  1279. seq_printf(file, "%ld %ld %ld %ld %ld %ld ",
  1280. stat->s_ntarguvhub8, stat->s_ntarguvhub4,
  1281. stat->s_ntarguvhub2, stat->s_ntarguvhub1,
  1282. stat->s_dtimeout, stat->s_strongnacks);
  1283. seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
  1284. stat->s_retry_messages, stat->s_retriesok,
  1285. stat->s_resets_plug, stat->s_resets_timeout,
  1286. stat->s_giveup, stat->s_stimeout,
  1287. stat->s_busy, stat->s_throttles);
  1288. seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
  1289. stat->s_bau_disabled, stat->s_bau_reenabled,
  1290. stat->s_uv2_wars, stat->s_uv2_wars_hw,
  1291. stat->s_uv2_war_waits, stat->s_enters,
  1292. stat->s_ipifordisabled, stat->s_plugged,
  1293. stat->s_overipilimit, stat->s_giveuplimit,
  1294. stat->s_congested);
  1295. /* destination side statistics */
  1296. seq_printf(file,
  1297. "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
  1298. ops.read_g_sw_ack(uv_cpu_to_pnode(cpu)),
  1299. stat->d_requestee, cycles_2_us(stat->d_time),
  1300. stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
  1301. stat->d_nomsg, stat->d_retries, stat->d_canceled,
  1302. stat->d_nocanceled, stat->d_resets,
  1303. stat->d_rcanceled);
  1304. }
  1305. return 0;
  1306. }
  1307. /*
  1308. * Display the tunables thru debugfs
  1309. */
  1310. static ssize_t tunables_read(struct file *file, char __user *userbuf,
  1311. size_t count, loff_t *ppos)
  1312. {
  1313. char *buf;
  1314. int ret;
  1315. buf = kasprintf(GFP_KERNEL, "%s %s %s\n%d %d %d %d %d %d %d %d %d %d\n",
  1316. "max_concur plugged_delay plugsb4reset timeoutsb4reset",
  1317. "ipi_reset_limit complete_threshold congested_response_us",
  1318. "congested_reps disabled_period giveup_limit",
  1319. max_concurr, plugged_delay, plugsb4reset,
  1320. timeoutsb4reset, ipi_reset_limit, complete_threshold,
  1321. congested_respns_us, congested_reps, disabled_period,
  1322. giveup_limit);
  1323. if (!buf)
  1324. return -ENOMEM;
  1325. ret = simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
  1326. kfree(buf);
  1327. return ret;
  1328. }
  1329. /*
  1330. * handle a write to /proc/sgi_uv/ptc_statistics
  1331. * -1: reset the statistics
  1332. * 0: display meaning of the statistics
  1333. */
  1334. static ssize_t ptc_proc_write(struct file *file, const char __user *user,
  1335. size_t count, loff_t *data)
  1336. {
  1337. int cpu;
  1338. int i;
  1339. int elements;
  1340. long input_arg;
  1341. char optstr[64];
  1342. struct ptc_stats *stat;
  1343. if (count == 0 || count > sizeof(optstr))
  1344. return -EINVAL;
  1345. if (copy_from_user(optstr, user, count))
  1346. return -EFAULT;
  1347. optstr[count - 1] = '\0';
  1348. if (!strcmp(optstr, "on")) {
  1349. set_bau_on();
  1350. return count;
  1351. } else if (!strcmp(optstr, "off")) {
  1352. set_bau_off();
  1353. return count;
  1354. }
  1355. if (kstrtol(optstr, 10, &input_arg) < 0) {
  1356. pr_debug("%s is invalid\n", optstr);
  1357. return -EINVAL;
  1358. }
  1359. if (input_arg == 0) {
  1360. elements = ARRAY_SIZE(stat_description);
  1361. pr_debug("# cpu: cpu number\n");
  1362. pr_debug("Sender statistics:\n");
  1363. for (i = 0; i < elements; i++)
  1364. pr_debug("%s\n", stat_description[i]);
  1365. } else if (input_arg == -1) {
  1366. for_each_present_cpu(cpu) {
  1367. stat = &per_cpu(ptcstats, cpu);
  1368. memset(stat, 0, sizeof(struct ptc_stats));
  1369. }
  1370. }
  1371. return count;
  1372. }
  1373. static int local_atoi(const char *name)
  1374. {
  1375. int val = 0;
  1376. for (;; name++) {
  1377. switch (*name) {
  1378. case '0' ... '9':
  1379. val = 10*val+(*name-'0');
  1380. break;
  1381. default:
  1382. return val;
  1383. }
  1384. }
  1385. }
  1386. /*
  1387. * Parse the values written to /sys/kernel/debug/sgi_uv/bau_tunables.
  1388. * Zero values reset them to defaults.
  1389. */
  1390. static int parse_tunables_write(struct bau_control *bcp, char *instr,
  1391. int count)
  1392. {
  1393. char *p;
  1394. char *q;
  1395. int cnt = 0;
  1396. int val;
  1397. int e = ARRAY_SIZE(tunables);
  1398. p = instr + strspn(instr, WHITESPACE);
  1399. q = p;
  1400. for (; *p; p = q + strspn(q, WHITESPACE)) {
  1401. q = p + strcspn(p, WHITESPACE);
  1402. cnt++;
  1403. if (q == p)
  1404. break;
  1405. }
  1406. if (cnt != e) {
  1407. pr_info("bau tunable error: should be %d values\n", e);
  1408. return -EINVAL;
  1409. }
  1410. p = instr + strspn(instr, WHITESPACE);
  1411. q = p;
  1412. for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
  1413. q = p + strcspn(p, WHITESPACE);
  1414. val = local_atoi(p);
  1415. switch (cnt) {
  1416. case 0:
  1417. if (val == 0) {
  1418. max_concurr = MAX_BAU_CONCURRENT;
  1419. max_concurr_const = MAX_BAU_CONCURRENT;
  1420. continue;
  1421. }
  1422. if (val < 1 || val > bcp->cpus_in_uvhub) {
  1423. pr_debug(
  1424. "Error: BAU max concurrent %d is invalid\n",
  1425. val);
  1426. return -EINVAL;
  1427. }
  1428. max_concurr = val;
  1429. max_concurr_const = val;
  1430. continue;
  1431. default:
  1432. if (val == 0)
  1433. *tunables[cnt].tunp = tunables[cnt].deflt;
  1434. else
  1435. *tunables[cnt].tunp = val;
  1436. continue;
  1437. }
  1438. }
  1439. return 0;
  1440. }
  1441. /*
  1442. * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
  1443. */
  1444. static ssize_t tunables_write(struct file *file, const char __user *user,
  1445. size_t count, loff_t *data)
  1446. {
  1447. int cpu;
  1448. int ret;
  1449. char instr[100];
  1450. struct bau_control *bcp;
  1451. if (count == 0 || count > sizeof(instr)-1)
  1452. return -EINVAL;
  1453. if (copy_from_user(instr, user, count))
  1454. return -EFAULT;
  1455. instr[count] = '\0';
  1456. cpu = get_cpu();
  1457. bcp = &per_cpu(bau_control, cpu);
  1458. ret = parse_tunables_write(bcp, instr, count);
  1459. put_cpu();
  1460. if (ret)
  1461. return ret;
  1462. for_each_present_cpu(cpu) {
  1463. bcp = &per_cpu(bau_control, cpu);
  1464. bcp->max_concurr = max_concurr;
  1465. bcp->max_concurr_const = max_concurr;
  1466. bcp->plugged_delay = plugged_delay;
  1467. bcp->plugsb4reset = plugsb4reset;
  1468. bcp->timeoutsb4reset = timeoutsb4reset;
  1469. bcp->ipi_reset_limit = ipi_reset_limit;
  1470. bcp->complete_threshold = complete_threshold;
  1471. bcp->cong_response_us = congested_respns_us;
  1472. bcp->cong_reps = congested_reps;
  1473. bcp->disabled_period = sec_2_cycles(disabled_period);
  1474. bcp->giveup_limit = giveup_limit;
  1475. }
  1476. return count;
  1477. }
  1478. static const struct seq_operations uv_ptc_seq_ops = {
  1479. .start = ptc_seq_start,
  1480. .next = ptc_seq_next,
  1481. .stop = ptc_seq_stop,
  1482. .show = ptc_seq_show
  1483. };
  1484. static int ptc_proc_open(struct inode *inode, struct file *file)
  1485. {
  1486. return seq_open(file, &uv_ptc_seq_ops);
  1487. }
  1488. static int tunables_open(struct inode *inode, struct file *file)
  1489. {
  1490. return 0;
  1491. }
  1492. static const struct file_operations proc_uv_ptc_operations = {
  1493. .open = ptc_proc_open,
  1494. .read = seq_read,
  1495. .write = ptc_proc_write,
  1496. .llseek = seq_lseek,
  1497. .release = seq_release,
  1498. };
  1499. static const struct file_operations tunables_fops = {
  1500. .open = tunables_open,
  1501. .read = tunables_read,
  1502. .write = tunables_write,
  1503. .llseek = default_llseek,
  1504. };
  1505. static int __init uv_ptc_init(void)
  1506. {
  1507. struct proc_dir_entry *proc_uv_ptc;
  1508. if (!is_uv_system())
  1509. return 0;
  1510. proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
  1511. &proc_uv_ptc_operations);
  1512. if (!proc_uv_ptc) {
  1513. pr_err("unable to create %s proc entry\n",
  1514. UV_PTC_BASENAME);
  1515. return -EINVAL;
  1516. }
  1517. tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
  1518. if (!tunables_dir) {
  1519. pr_err("unable to create debugfs directory %s\n",
  1520. UV_BAU_TUNABLES_DIR);
  1521. return -EINVAL;
  1522. }
  1523. tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
  1524. tunables_dir, NULL, &tunables_fops);
  1525. if (!tunables_file) {
  1526. pr_err("unable to create debugfs file %s\n",
  1527. UV_BAU_TUNABLES_FILE);
  1528. return -EINVAL;
  1529. }
  1530. return 0;
  1531. }
  1532. /*
  1533. * Initialize the sending side's sending buffers.
  1534. */
  1535. static void activation_descriptor_init(int node, int pnode, int base_pnode)
  1536. {
  1537. int i;
  1538. int cpu;
  1539. int uv1 = 0;
  1540. unsigned long gpa;
  1541. unsigned long m;
  1542. unsigned long n;
  1543. size_t dsize;
  1544. struct bau_desc *bau_desc;
  1545. struct bau_desc *bd2;
  1546. struct uv1_bau_msg_header *uv1_hdr;
  1547. struct uv2_3_bau_msg_header *uv2_3_hdr;
  1548. struct bau_control *bcp;
  1549. /*
  1550. * each bau_desc is 64 bytes; there are 8 (ITEMS_PER_DESC)
  1551. * per cpu; and one per cpu on the uvhub (ADP_SZ)
  1552. */
  1553. dsize = sizeof(struct bau_desc) * ADP_SZ * ITEMS_PER_DESC;
  1554. bau_desc = kmalloc_node(dsize, GFP_KERNEL, node);
  1555. BUG_ON(!bau_desc);
  1556. gpa = uv_gpa(bau_desc);
  1557. n = uv_gpa_to_gnode(gpa);
  1558. m = ops.bau_gpa_to_offset(gpa);
  1559. if (is_uv1_hub())
  1560. uv1 = 1;
  1561. /* the 14-bit pnode */
  1562. write_mmr_descriptor_base(pnode,
  1563. (n << UVH_LB_BAU_SB_DESCRIPTOR_BASE_NODE_ID_SHFT | m));
  1564. /*
  1565. * Initializing all 8 (ITEMS_PER_DESC) descriptors for each
  1566. * cpu even though we only use the first one; one descriptor can
  1567. * describe a broadcast to 256 uv hubs.
  1568. */
  1569. for (i = 0, bd2 = bau_desc; i < (ADP_SZ * ITEMS_PER_DESC); i++, bd2++) {
  1570. memset(bd2, 0, sizeof(struct bau_desc));
  1571. if (uv1) {
  1572. uv1_hdr = &bd2->header.uv1_hdr;
  1573. uv1_hdr->swack_flag = 1;
  1574. /*
  1575. * The base_dest_nasid set in the message header
  1576. * is the nasid of the first uvhub in the partition.
  1577. * The bit map will indicate destination pnode numbers
  1578. * relative to that base. They may not be consecutive
  1579. * if nasid striding is being used.
  1580. */
  1581. uv1_hdr->base_dest_nasid =
  1582. UV_PNODE_TO_NASID(base_pnode);
  1583. uv1_hdr->dest_subnodeid = UV_LB_SUBNODEID;
  1584. uv1_hdr->command = UV_NET_ENDPOINT_INTD;
  1585. uv1_hdr->int_both = 1;
  1586. /*
  1587. * all others need to be set to zero:
  1588. * fairness chaining multilevel count replied_to
  1589. */
  1590. } else {
  1591. /*
  1592. * BIOS uses legacy mode, but uv2 and uv3 hardware always
  1593. * uses native mode for selective broadcasts.
  1594. */
  1595. uv2_3_hdr = &bd2->header.uv2_3_hdr;
  1596. uv2_3_hdr->swack_flag = 1;
  1597. uv2_3_hdr->base_dest_nasid =
  1598. UV_PNODE_TO_NASID(base_pnode);
  1599. uv2_3_hdr->dest_subnodeid = UV_LB_SUBNODEID;
  1600. uv2_3_hdr->command = UV_NET_ENDPOINT_INTD;
  1601. }
  1602. }
  1603. for_each_present_cpu(cpu) {
  1604. if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
  1605. continue;
  1606. bcp = &per_cpu(bau_control, cpu);
  1607. bcp->descriptor_base = bau_desc;
  1608. }
  1609. }
  1610. /*
  1611. * initialize the destination side's receiving buffers
  1612. * entered for each uvhub in the partition
  1613. * - node is first node (kernel memory notion) on the uvhub
  1614. * - pnode is the uvhub's physical identifier
  1615. */
  1616. static void pq_init(int node, int pnode)
  1617. {
  1618. int cpu;
  1619. size_t plsize;
  1620. char *cp;
  1621. void *vp;
  1622. unsigned long gnode, first, last, tail;
  1623. struct bau_pq_entry *pqp;
  1624. struct bau_control *bcp;
  1625. plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
  1626. vp = kmalloc_node(plsize, GFP_KERNEL, node);
  1627. pqp = (struct bau_pq_entry *)vp;
  1628. BUG_ON(!pqp);
  1629. cp = (char *)pqp + 31;
  1630. pqp = (struct bau_pq_entry *)(((unsigned long)cp >> 5) << 5);
  1631. for_each_present_cpu(cpu) {
  1632. if (pnode != uv_cpu_to_pnode(cpu))
  1633. continue;
  1634. /* for every cpu on this pnode: */
  1635. bcp = &per_cpu(bau_control, cpu);
  1636. bcp->queue_first = pqp;
  1637. bcp->bau_msg_head = pqp;
  1638. bcp->queue_last = pqp + (DEST_Q_SIZE - 1);
  1639. }
  1640. first = ops.bau_gpa_to_offset(uv_gpa(pqp));
  1641. last = ops.bau_gpa_to_offset(uv_gpa(pqp + (DEST_Q_SIZE - 1)));
  1642. /*
  1643. * Pre UV4, the gnode is required to locate the payload queue
  1644. * and the payload queue tail must be maintained by the kernel.
  1645. */
  1646. bcp = &per_cpu(bau_control, smp_processor_id());
  1647. if (bcp->uvhub_version <= UV_BAU_V3) {
  1648. tail = first;
  1649. gnode = uv_gpa_to_gnode(uv_gpa(pqp));
  1650. first = (gnode << UV_PAYLOADQ_GNODE_SHIFT) | tail;
  1651. write_mmr_payload_tail(pnode, tail);
  1652. }
  1653. ops.write_payload_first(pnode, first);
  1654. ops.write_payload_last(pnode, last);
  1655. /* in effect, all msg_type's are set to MSG_NOOP */
  1656. memset(pqp, 0, sizeof(struct bau_pq_entry) * DEST_Q_SIZE);
  1657. }
  1658. /*
  1659. * Initialization of each UV hub's structures
  1660. */
  1661. static void __init init_uvhub(int uvhub, int vector, int base_pnode)
  1662. {
  1663. int node;
  1664. int pnode;
  1665. unsigned long apicid;
  1666. node = uvhub_to_first_node(uvhub);
  1667. pnode = uv_blade_to_pnode(uvhub);
  1668. activation_descriptor_init(node, pnode, base_pnode);
  1669. pq_init(node, pnode);
  1670. /*
  1671. * The below initialization can't be in firmware because the
  1672. * messaging IRQ will be determined by the OS.
  1673. */
  1674. apicid = uvhub_to_first_apicid(uvhub) | uv_apicid_hibits;
  1675. write_mmr_data_config(pnode, ((apicid << 32) | vector));
  1676. }
  1677. /*
  1678. * We will set BAU_MISC_CONTROL with a timeout period.
  1679. * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
  1680. * So the destination timeout period has to be calculated from them.
  1681. */
  1682. static int calculate_destination_timeout(void)
  1683. {
  1684. unsigned long mmr_image;
  1685. int mult1;
  1686. int mult2;
  1687. int index;
  1688. int base;
  1689. int ret;
  1690. unsigned long ts_ns;
  1691. if (is_uv1_hub()) {
  1692. mult1 = SOFTACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
  1693. mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
  1694. index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
  1695. mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
  1696. mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
  1697. ts_ns = timeout_base_ns[index];
  1698. ts_ns *= (mult1 * mult2);
  1699. ret = ts_ns / 1000;
  1700. } else {
  1701. /* same destination timeout for uv2 and uv3 */
  1702. /* 4 bits 0/1 for 10/80us base, 3 bits of multiplier */
  1703. mmr_image = uv_read_local_mmr(UVH_LB_BAU_MISC_CONTROL);
  1704. mmr_image = (mmr_image & UV_SA_MASK) >> UV_SA_SHFT;
  1705. if (mmr_image & (1L << UV2_ACK_UNITS_SHFT))
  1706. base = 80;
  1707. else
  1708. base = 10;
  1709. mult1 = mmr_image & UV2_ACK_MASK;
  1710. ret = mult1 * base;
  1711. }
  1712. return ret;
  1713. }
  1714. static void __init init_per_cpu_tunables(void)
  1715. {
  1716. int cpu;
  1717. struct bau_control *bcp;
  1718. for_each_present_cpu(cpu) {
  1719. bcp = &per_cpu(bau_control, cpu);
  1720. bcp->baudisabled = 0;
  1721. if (nobau)
  1722. bcp->nobau = true;
  1723. bcp->statp = &per_cpu(ptcstats, cpu);
  1724. /* time interval to catch a hardware stay-busy bug */
  1725. bcp->timeout_interval = usec_2_cycles(2*timeout_us);
  1726. bcp->max_concurr = max_concurr;
  1727. bcp->max_concurr_const = max_concurr;
  1728. bcp->plugged_delay = plugged_delay;
  1729. bcp->plugsb4reset = plugsb4reset;
  1730. bcp->timeoutsb4reset = timeoutsb4reset;
  1731. bcp->ipi_reset_limit = ipi_reset_limit;
  1732. bcp->complete_threshold = complete_threshold;
  1733. bcp->cong_response_us = congested_respns_us;
  1734. bcp->cong_reps = congested_reps;
  1735. bcp->disabled_period = sec_2_cycles(disabled_period);
  1736. bcp->giveup_limit = giveup_limit;
  1737. spin_lock_init(&bcp->queue_lock);
  1738. spin_lock_init(&bcp->uvhub_lock);
  1739. spin_lock_init(&bcp->disable_lock);
  1740. }
  1741. }
  1742. /*
  1743. * Scan all cpus to collect blade and socket summaries.
  1744. */
  1745. static int __init get_cpu_topology(int base_pnode,
  1746. struct uvhub_desc *uvhub_descs,
  1747. unsigned char *uvhub_mask)
  1748. {
  1749. int cpu;
  1750. int pnode;
  1751. int uvhub;
  1752. int socket;
  1753. struct bau_control *bcp;
  1754. struct uvhub_desc *bdp;
  1755. struct socket_desc *sdp;
  1756. for_each_present_cpu(cpu) {
  1757. bcp = &per_cpu(bau_control, cpu);
  1758. memset(bcp, 0, sizeof(struct bau_control));
  1759. pnode = uv_cpu_hub_info(cpu)->pnode;
  1760. if ((pnode - base_pnode) >= UV_DISTRIBUTION_SIZE) {
  1761. pr_emerg(
  1762. "cpu %d pnode %d-%d beyond %d; BAU disabled\n",
  1763. cpu, pnode, base_pnode, UV_DISTRIBUTION_SIZE);
  1764. return 1;
  1765. }
  1766. bcp->osnode = cpu_to_node(cpu);
  1767. bcp->partition_base_pnode = base_pnode;
  1768. uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
  1769. *(uvhub_mask + (uvhub/8)) |= (1 << (uvhub%8));
  1770. bdp = &uvhub_descs[uvhub];
  1771. bdp->num_cpus++;
  1772. bdp->uvhub = uvhub;
  1773. bdp->pnode = pnode;
  1774. /* kludge: 'assuming' one node per socket, and assuming that
  1775. disabling a socket just leaves a gap in node numbers */
  1776. socket = bcp->osnode & 1;
  1777. bdp->socket_mask |= (1 << socket);
  1778. sdp = &bdp->socket[socket];
  1779. sdp->cpu_number[sdp->num_cpus] = cpu;
  1780. sdp->num_cpus++;
  1781. if (sdp->num_cpus > MAX_CPUS_PER_SOCKET) {
  1782. pr_emerg("%d cpus per socket invalid\n",
  1783. sdp->num_cpus);
  1784. return 1;
  1785. }
  1786. }
  1787. return 0;
  1788. }
  1789. /*
  1790. * Each socket is to get a local array of pnodes/hubs.
  1791. */
  1792. static void make_per_cpu_thp(struct bau_control *smaster)
  1793. {
  1794. int cpu;
  1795. size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
  1796. smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
  1797. memset(smaster->thp, 0, hpsz);
  1798. for_each_present_cpu(cpu) {
  1799. smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
  1800. smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
  1801. }
  1802. }
  1803. /*
  1804. * Each uvhub is to get a local cpumask.
  1805. */
  1806. static void make_per_hub_cpumask(struct bau_control *hmaster)
  1807. {
  1808. int sz = sizeof(cpumask_t);
  1809. hmaster->cpumask = kzalloc_node(sz, GFP_KERNEL, hmaster->osnode);
  1810. }
  1811. /*
  1812. * Initialize all the per_cpu information for the cpu's on a given socket,
  1813. * given what has been gathered into the socket_desc struct.
  1814. * And reports the chosen hub and socket masters back to the caller.
  1815. */
  1816. static int scan_sock(struct socket_desc *sdp, struct uvhub_desc *bdp,
  1817. struct bau_control **smasterp,
  1818. struct bau_control **hmasterp)
  1819. {
  1820. int i, cpu, uvhub_cpu;
  1821. struct bau_control *bcp;
  1822. for (i = 0; i < sdp->num_cpus; i++) {
  1823. cpu = sdp->cpu_number[i];
  1824. bcp = &per_cpu(bau_control, cpu);
  1825. bcp->cpu = cpu;
  1826. if (i == 0) {
  1827. *smasterp = bcp;
  1828. if (!(*hmasterp))
  1829. *hmasterp = bcp;
  1830. }
  1831. bcp->cpus_in_uvhub = bdp->num_cpus;
  1832. bcp->cpus_in_socket = sdp->num_cpus;
  1833. bcp->socket_master = *smasterp;
  1834. bcp->uvhub = bdp->uvhub;
  1835. if (is_uv1_hub())
  1836. bcp->uvhub_version = UV_BAU_V1;
  1837. else if (is_uv2_hub())
  1838. bcp->uvhub_version = UV_BAU_V2;
  1839. else if (is_uv3_hub())
  1840. bcp->uvhub_version = UV_BAU_V3;
  1841. else if (is_uv4_hub())
  1842. bcp->uvhub_version = UV_BAU_V4;
  1843. else {
  1844. pr_emerg("uvhub version not 1, 2, 3, or 4\n");
  1845. return 1;
  1846. }
  1847. bcp->uvhub_master = *hmasterp;
  1848. uvhub_cpu = uv_cpu_blade_processor_id(cpu);
  1849. bcp->uvhub_cpu = uvhub_cpu;
  1850. /*
  1851. * The ERROR and BUSY status registers are located pairwise over
  1852. * the STATUS_0 and STATUS_1 mmrs; each an array[32] of 2 bits.
  1853. */
  1854. if (uvhub_cpu < UV_CPUS_PER_AS) {
  1855. bcp->status_mmr = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
  1856. bcp->status_index = uvhub_cpu * UV_ACT_STATUS_SIZE;
  1857. } else {
  1858. bcp->status_mmr = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
  1859. bcp->status_index = (uvhub_cpu - UV_CPUS_PER_AS)
  1860. * UV_ACT_STATUS_SIZE;
  1861. }
  1862. if (bcp->uvhub_cpu >= MAX_CPUS_PER_UVHUB) {
  1863. pr_emerg("%d cpus per uvhub invalid\n",
  1864. bcp->uvhub_cpu);
  1865. return 1;
  1866. }
  1867. }
  1868. return 0;
  1869. }
  1870. /*
  1871. * Summarize the blade and socket topology into the per_cpu structures.
  1872. */
  1873. static int __init summarize_uvhub_sockets(int nuvhubs,
  1874. struct uvhub_desc *uvhub_descs,
  1875. unsigned char *uvhub_mask)
  1876. {
  1877. int socket;
  1878. int uvhub;
  1879. unsigned short socket_mask;
  1880. for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
  1881. struct uvhub_desc *bdp;
  1882. struct bau_control *smaster = NULL;
  1883. struct bau_control *hmaster = NULL;
  1884. if (!(*(uvhub_mask + (uvhub/8)) & (1 << (uvhub%8))))
  1885. continue;
  1886. bdp = &uvhub_descs[uvhub];
  1887. socket_mask = bdp->socket_mask;
  1888. socket = 0;
  1889. while (socket_mask) {
  1890. struct socket_desc *sdp;
  1891. if ((socket_mask & 1)) {
  1892. sdp = &bdp->socket[socket];
  1893. if (scan_sock(sdp, bdp, &smaster, &hmaster))
  1894. return 1;
  1895. make_per_cpu_thp(smaster);
  1896. }
  1897. socket++;
  1898. socket_mask = (socket_mask >> 1);
  1899. }
  1900. make_per_hub_cpumask(hmaster);
  1901. }
  1902. return 0;
  1903. }
  1904. /*
  1905. * initialize the bau_control structure for each cpu
  1906. */
  1907. static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
  1908. {
  1909. unsigned char *uvhub_mask;
  1910. void *vp;
  1911. struct uvhub_desc *uvhub_descs;
  1912. if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub())
  1913. timeout_us = calculate_destination_timeout();
  1914. vp = kmalloc_array(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL);
  1915. uvhub_descs = (struct uvhub_desc *)vp;
  1916. memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
  1917. uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
  1918. if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask))
  1919. goto fail;
  1920. if (summarize_uvhub_sockets(nuvhubs, uvhub_descs, uvhub_mask))
  1921. goto fail;
  1922. kfree(uvhub_descs);
  1923. kfree(uvhub_mask);
  1924. init_per_cpu_tunables();
  1925. return 0;
  1926. fail:
  1927. kfree(uvhub_descs);
  1928. kfree(uvhub_mask);
  1929. return 1;
  1930. }
  1931. static const struct bau_operations uv1_bau_ops __initconst = {
  1932. .bau_gpa_to_offset = uv_gpa_to_offset,
  1933. .read_l_sw_ack = read_mmr_sw_ack,
  1934. .read_g_sw_ack = read_gmmr_sw_ack,
  1935. .write_l_sw_ack = write_mmr_sw_ack,
  1936. .write_g_sw_ack = write_gmmr_sw_ack,
  1937. .write_payload_first = write_mmr_payload_first,
  1938. .write_payload_last = write_mmr_payload_last,
  1939. .wait_completion = uv1_wait_completion,
  1940. };
  1941. static const struct bau_operations uv2_3_bau_ops __initconst = {
  1942. .bau_gpa_to_offset = uv_gpa_to_offset,
  1943. .read_l_sw_ack = read_mmr_sw_ack,
  1944. .read_g_sw_ack = read_gmmr_sw_ack,
  1945. .write_l_sw_ack = write_mmr_sw_ack,
  1946. .write_g_sw_ack = write_gmmr_sw_ack,
  1947. .write_payload_first = write_mmr_payload_first,
  1948. .write_payload_last = write_mmr_payload_last,
  1949. .wait_completion = uv2_3_wait_completion,
  1950. };
  1951. static const struct bau_operations uv4_bau_ops __initconst = {
  1952. .bau_gpa_to_offset = uv_gpa_to_soc_phys_ram,
  1953. .read_l_sw_ack = read_mmr_proc_sw_ack,
  1954. .read_g_sw_ack = read_gmmr_proc_sw_ack,
  1955. .write_l_sw_ack = write_mmr_proc_sw_ack,
  1956. .write_g_sw_ack = write_gmmr_proc_sw_ack,
  1957. .write_payload_first = write_mmr_proc_payload_first,
  1958. .write_payload_last = write_mmr_proc_payload_last,
  1959. .wait_completion = uv4_wait_completion,
  1960. };
  1961. /*
  1962. * Initialization of BAU-related structures
  1963. */
  1964. static int __init uv_bau_init(void)
  1965. {
  1966. int uvhub;
  1967. int pnode;
  1968. int nuvhubs;
  1969. int cur_cpu;
  1970. int cpus;
  1971. int vector;
  1972. cpumask_var_t *mask;
  1973. if (!is_uv_system())
  1974. return 0;
  1975. if (is_uv4_hub())
  1976. ops = uv4_bau_ops;
  1977. else if (is_uv3_hub())
  1978. ops = uv2_3_bau_ops;
  1979. else if (is_uv2_hub())
  1980. ops = uv2_3_bau_ops;
  1981. else if (is_uv1_hub())
  1982. ops = uv1_bau_ops;
  1983. nuvhubs = uv_num_possible_blades();
  1984. if (nuvhubs < 2) {
  1985. pr_crit("UV: BAU disabled - insufficient hub count\n");
  1986. goto err_bau_disable;
  1987. }
  1988. for_each_possible_cpu(cur_cpu) {
  1989. mask = &per_cpu(uv_flush_tlb_mask, cur_cpu);
  1990. zalloc_cpumask_var_node(mask, GFP_KERNEL, cpu_to_node(cur_cpu));
  1991. }
  1992. uv_base_pnode = 0x7fffffff;
  1993. for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
  1994. cpus = uv_blade_nr_possible_cpus(uvhub);
  1995. if (cpus && (uv_blade_to_pnode(uvhub) < uv_base_pnode))
  1996. uv_base_pnode = uv_blade_to_pnode(uvhub);
  1997. }
  1998. /* software timeouts are not supported on UV4 */
  1999. if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub())
  2000. enable_timeouts();
  2001. if (init_per_cpu(nuvhubs, uv_base_pnode)) {
  2002. pr_crit("UV: BAU disabled - per CPU init failed\n");
  2003. goto err_bau_disable;
  2004. }
  2005. vector = UV_BAU_MESSAGE;
  2006. for_each_possible_blade(uvhub) {
  2007. if (uv_blade_nr_possible_cpus(uvhub))
  2008. init_uvhub(uvhub, vector, uv_base_pnode);
  2009. }
  2010. for_each_possible_blade(uvhub) {
  2011. if (uv_blade_nr_possible_cpus(uvhub)) {
  2012. unsigned long val;
  2013. unsigned long mmr;
  2014. pnode = uv_blade_to_pnode(uvhub);
  2015. /* INIT the bau */
  2016. val = 1L << 63;
  2017. write_gmmr_activation(pnode, val);
  2018. mmr = 1; /* should be 1 to broadcast to both sockets */
  2019. if (!is_uv1_hub())
  2020. write_mmr_data_broadcast(pnode, mmr);
  2021. }
  2022. }
  2023. return 0;
  2024. err_bau_disable:
  2025. for_each_possible_cpu(cur_cpu)
  2026. free_cpumask_var(per_cpu(uv_flush_tlb_mask, cur_cpu));
  2027. set_bau_off();
  2028. nobau_perm = 1;
  2029. return -EINVAL;
  2030. }
  2031. core_initcall(uv_bau_init);
  2032. fs_initcall(uv_ptc_init);