tlb_uv.c 56 KB

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