tlb_uv.c 49 KB

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