tlb_uv.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  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 (bcp->uvhub_version == 1)
  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. int uv1 = 0;
  686. long try = 0;
  687. unsigned long index;
  688. cycles_t time1;
  689. cycles_t time2;
  690. struct ptc_stats *stat = bcp->statp;
  691. struct bau_control *hmaster = bcp->uvhub_master;
  692. struct uv1_bau_msg_header *uv1_hdr = NULL;
  693. struct uv2_bau_msg_header *uv2_hdr = NULL;
  694. if (bcp->uvhub_version == 1) {
  695. uv1 = 1;
  696. uv1_throttle(hmaster, stat);
  697. uv1_hdr = &bau_desc->header.uv1_hdr;
  698. } else
  699. uv2_hdr = &bau_desc->header.uv2_hdr;
  700. while (hmaster->uvhub_quiesce)
  701. cpu_relax();
  702. time1 = get_cycles();
  703. do {
  704. if (try == 0) {
  705. if (uv1)
  706. uv1_hdr->msg_type = MSG_REGULAR;
  707. else
  708. uv2_hdr->msg_type = MSG_REGULAR;
  709. seq_number = bcp->message_number++;
  710. } else {
  711. if (uv1)
  712. uv1_hdr->msg_type = MSG_RETRY;
  713. else
  714. uv2_hdr->msg_type = MSG_RETRY;
  715. stat->s_retry_messages++;
  716. }
  717. if (uv1)
  718. uv1_hdr->sequence = seq_number;
  719. else
  720. uv2_hdr->sequence = seq_number;
  721. index = (1UL << AS_PUSH_SHIFT) | bcp->uvhub_cpu;
  722. bcp->send_message = get_cycles();
  723. write_mmr_activation(index);
  724. try++;
  725. completion_stat = wait_completion(bau_desc, bcp, try);
  726. handle_cmplt(completion_stat, bau_desc, bcp, hmaster, stat);
  727. if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
  728. bcp->ipi_attempts = 0;
  729. completion_stat = FLUSH_GIVEUP;
  730. break;
  731. }
  732. cpu_relax();
  733. } while ((completion_stat == FLUSH_RETRY_PLUGGED) ||
  734. (completion_stat == FLUSH_RETRY_TIMEOUT));
  735. time2 = get_cycles();
  736. count_max_concurr(completion_stat, bcp, hmaster);
  737. while (hmaster->uvhub_quiesce)
  738. cpu_relax();
  739. atomic_dec(&hmaster->active_descriptor_count);
  740. record_send_stats(time1, time2, bcp, stat, completion_stat, try);
  741. if (completion_stat == FLUSH_GIVEUP)
  742. return 1;
  743. return 0;
  744. }
  745. /*
  746. * The BAU is disabled. When the disabled time period has expired, the cpu
  747. * that disabled it must re-enable it.
  748. * Return 0 if it is re-enabled for all cpus.
  749. */
  750. static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
  751. {
  752. int tcpu;
  753. struct bau_control *tbcp;
  754. if (bcp->set_bau_off) {
  755. if (get_cycles() >= bcp->set_bau_on_time) {
  756. stat->s_bau_reenabled++;
  757. baudisabled = 0;
  758. for_each_present_cpu(tcpu) {
  759. tbcp = &per_cpu(bau_control, tcpu);
  760. tbcp->baudisabled = 0;
  761. tbcp->period_requests = 0;
  762. tbcp->period_time = 0;
  763. }
  764. return 0;
  765. }
  766. }
  767. return -1;
  768. }
  769. static void record_send_statistics(struct ptc_stats *stat, int locals, int hubs,
  770. int remotes, struct bau_desc *bau_desc)
  771. {
  772. stat->s_requestor++;
  773. stat->s_ntargcpu += remotes + locals;
  774. stat->s_ntargremotes += remotes;
  775. stat->s_ntarglocals += locals;
  776. /* uvhub statistics */
  777. hubs = bau_uvhub_weight(&bau_desc->distribution);
  778. if (locals) {
  779. stat->s_ntarglocaluvhub++;
  780. stat->s_ntargremoteuvhub += (hubs - 1);
  781. } else
  782. stat->s_ntargremoteuvhub += hubs;
  783. stat->s_ntarguvhub += hubs;
  784. if (hubs >= 16)
  785. stat->s_ntarguvhub16++;
  786. else if (hubs >= 8)
  787. stat->s_ntarguvhub8++;
  788. else if (hubs >= 4)
  789. stat->s_ntarguvhub4++;
  790. else if (hubs >= 2)
  791. stat->s_ntarguvhub2++;
  792. else
  793. stat->s_ntarguvhub1++;
  794. }
  795. /*
  796. * Translate a cpu mask to the uvhub distribution mask in the BAU
  797. * activation descriptor.
  798. */
  799. static int set_distrib_bits(struct cpumask *flush_mask, struct bau_control *bcp,
  800. struct bau_desc *bau_desc, int *localsp, int *remotesp)
  801. {
  802. int cpu;
  803. int pnode;
  804. int cnt = 0;
  805. struct hub_and_pnode *hpp;
  806. for_each_cpu(cpu, flush_mask) {
  807. /*
  808. * The distribution vector is a bit map of pnodes, relative
  809. * to the partition base pnode (and the partition base nasid
  810. * in the header).
  811. * Translate cpu to pnode and hub using a local memory array.
  812. */
  813. hpp = &bcp->socket_master->thp[cpu];
  814. pnode = hpp->pnode - bcp->partition_base_pnode;
  815. bau_uvhub_set(pnode, &bau_desc->distribution);
  816. cnt++;
  817. if (hpp->uvhub == bcp->uvhub)
  818. (*localsp)++;
  819. else
  820. (*remotesp)++;
  821. }
  822. if (!cnt)
  823. return 1;
  824. return 0;
  825. }
  826. /*
  827. * globally purge translation cache of a virtual address or all TLB's
  828. * @cpumask: mask of all cpu's in which the address is to be removed
  829. * @mm: mm_struct containing virtual address range
  830. * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
  831. * @cpu: the current cpu
  832. *
  833. * This is the entry point for initiating any UV global TLB shootdown.
  834. *
  835. * Purges the translation caches of all specified processors of the given
  836. * virtual address, or purges all TLB's on specified processors.
  837. *
  838. * The caller has derived the cpumask from the mm_struct. This function
  839. * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
  840. *
  841. * The cpumask is converted into a uvhubmask of the uvhubs containing
  842. * those cpus.
  843. *
  844. * Note that this function should be called with preemption disabled.
  845. *
  846. * Returns NULL if all remote flushing was done.
  847. * Returns pointer to cpumask if some remote flushing remains to be
  848. * done. The returned pointer is valid till preemption is re-enabled.
  849. */
  850. const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
  851. struct mm_struct *mm, unsigned long va,
  852. unsigned int cpu)
  853. {
  854. int locals = 0;
  855. int remotes = 0;
  856. int hubs = 0;
  857. struct bau_desc *bau_desc;
  858. struct cpumask *flush_mask;
  859. struct ptc_stats *stat;
  860. struct bau_control *bcp;
  861. /* kernel was booted 'nobau' */
  862. if (nobau)
  863. return cpumask;
  864. bcp = &per_cpu(bau_control, cpu);
  865. stat = bcp->statp;
  866. /* bau was disabled due to slow response */
  867. if (bcp->baudisabled) {
  868. if (check_enable(bcp, stat))
  869. return cpumask;
  870. }
  871. /*
  872. * Each sending cpu has a per-cpu mask which it fills from the caller's
  873. * cpu mask. All cpus are converted to uvhubs and copied to the
  874. * activation descriptor.
  875. */
  876. flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
  877. /* don't actually do a shootdown of the local cpu */
  878. cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
  879. if (cpu_isset(cpu, *cpumask))
  880. stat->s_ntargself++;
  881. bau_desc = bcp->descriptor_base;
  882. bau_desc += (ITEMS_PER_DESC * bcp->uvhub_cpu);
  883. bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
  884. if (set_distrib_bits(flush_mask, bcp, bau_desc, &locals, &remotes))
  885. return NULL;
  886. record_send_statistics(stat, locals, hubs, remotes, bau_desc);
  887. bau_desc->payload.address = va;
  888. bau_desc->payload.sending_cpu = cpu;
  889. /*
  890. * uv_flush_send_and_wait returns 0 if all cpu's were messaged,
  891. * or 1 if it gave up and the original cpumask should be returned.
  892. */
  893. if (!uv_flush_send_and_wait(bau_desc, flush_mask, bcp))
  894. return NULL;
  895. else
  896. return cpumask;
  897. }
  898. /*
  899. * The BAU message interrupt comes here. (registered by set_intr_gate)
  900. * See entry_64.S
  901. *
  902. * We received a broadcast assist message.
  903. *
  904. * Interrupts are disabled; this interrupt could represent
  905. * the receipt of several messages.
  906. *
  907. * All cores/threads on this hub get this interrupt.
  908. * The last one to see it does the software ack.
  909. * (the resource will not be freed until noninterruptable cpus see this
  910. * interrupt; hardware may timeout the s/w ack and reply ERROR)
  911. */
  912. void uv_bau_message_interrupt(struct pt_regs *regs)
  913. {
  914. int count = 0;
  915. cycles_t time_start;
  916. struct bau_pq_entry *msg;
  917. struct bau_control *bcp;
  918. struct ptc_stats *stat;
  919. struct msg_desc msgdesc;
  920. time_start = get_cycles();
  921. bcp = &per_cpu(bau_control, smp_processor_id());
  922. stat = bcp->statp;
  923. msgdesc.queue_first = bcp->queue_first;
  924. msgdesc.queue_last = bcp->queue_last;
  925. msg = bcp->bau_msg_head;
  926. while (msg->swack_vec) {
  927. count++;
  928. msgdesc.msg_slot = msg - msgdesc.queue_first;
  929. msgdesc.swack_slot = ffs(msg->swack_vec) - 1;
  930. msgdesc.msg = msg;
  931. bau_process_message(&msgdesc, bcp);
  932. msg++;
  933. if (msg > msgdesc.queue_last)
  934. msg = msgdesc.queue_first;
  935. bcp->bau_msg_head = msg;
  936. }
  937. stat->d_time += (get_cycles() - time_start);
  938. if (!count)
  939. stat->d_nomsg++;
  940. else if (count > 1)
  941. stat->d_multmsg++;
  942. ack_APIC_irq();
  943. }
  944. /*
  945. * Each target uvhub (i.e. a uvhub that has cpu's) needs to have
  946. * shootdown message timeouts enabled. The timeout does not cause
  947. * an interrupt, but causes an error message to be returned to
  948. * the sender.
  949. */
  950. static void __init enable_timeouts(void)
  951. {
  952. int uvhub;
  953. int nuvhubs;
  954. int pnode;
  955. unsigned long mmr_image;
  956. nuvhubs = uv_num_possible_blades();
  957. for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
  958. if (!uv_blade_nr_possible_cpus(uvhub))
  959. continue;
  960. pnode = uv_blade_to_pnode(uvhub);
  961. mmr_image = read_mmr_misc_control(pnode);
  962. /*
  963. * Set the timeout period and then lock it in, in three
  964. * steps; captures and locks in the period.
  965. *
  966. * To program the period, the SOFT_ACK_MODE must be off.
  967. */
  968. mmr_image &= ~(1L << SOFTACK_MSHIFT);
  969. write_mmr_misc_control(pnode, mmr_image);
  970. /*
  971. * Set the 4-bit period.
  972. */
  973. mmr_image &= ~((unsigned long)0xf << SOFTACK_PSHIFT);
  974. mmr_image |= (SOFTACK_TIMEOUT_PERIOD << SOFTACK_PSHIFT);
  975. write_mmr_misc_control(pnode, mmr_image);
  976. /*
  977. * UV1:
  978. * Subsequent reversals of the timebase bit (3) cause an
  979. * immediate timeout of one or all INTD resources as
  980. * indicated in bits 2:0 (7 causes all of them to timeout).
  981. */
  982. mmr_image |= (1L << SOFTACK_MSHIFT);
  983. if (is_uv2_hub()) {
  984. mmr_image &= ~(1L << UV2_LEG_SHFT);
  985. mmr_image |= (1L << UV2_EXT_SHFT);
  986. }
  987. write_mmr_misc_control(pnode, mmr_image);
  988. }
  989. }
  990. static void *ptc_seq_start(struct seq_file *file, loff_t *offset)
  991. {
  992. if (*offset < num_possible_cpus())
  993. return offset;
  994. return NULL;
  995. }
  996. static void *ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
  997. {
  998. (*offset)++;
  999. if (*offset < num_possible_cpus())
  1000. return offset;
  1001. return NULL;
  1002. }
  1003. static void ptc_seq_stop(struct seq_file *file, void *data)
  1004. {
  1005. }
  1006. static inline unsigned long long usec_2_cycles(unsigned long microsec)
  1007. {
  1008. unsigned long ns;
  1009. unsigned long long cyc;
  1010. ns = microsec * 1000;
  1011. cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
  1012. return cyc;
  1013. }
  1014. /*
  1015. * Display the statistics thru /proc/sgi_uv/ptc_statistics
  1016. * 'data' points to the cpu number
  1017. * Note: see the descriptions in stat_description[].
  1018. */
  1019. static int ptc_seq_show(struct seq_file *file, void *data)
  1020. {
  1021. struct ptc_stats *stat;
  1022. int cpu;
  1023. cpu = *(loff_t *)data;
  1024. if (!cpu) {
  1025. seq_printf(file,
  1026. "# cpu sent stime self locals remotes ncpus localhub ");
  1027. seq_printf(file,
  1028. "remotehub numuvhubs numuvhubs16 numuvhubs8 ");
  1029. seq_printf(file,
  1030. "numuvhubs4 numuvhubs2 numuvhubs1 dto retries rok ");
  1031. seq_printf(file,
  1032. "resetp resett giveup sto bz throt swack recv rtime ");
  1033. seq_printf(file,
  1034. "all one mult none retry canc nocan reset rcan ");
  1035. seq_printf(file,
  1036. "disable enable\n");
  1037. }
  1038. if (cpu < num_possible_cpus() && cpu_online(cpu)) {
  1039. stat = &per_cpu(ptcstats, cpu);
  1040. /* source side statistics */
  1041. seq_printf(file,
  1042. "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
  1043. cpu, stat->s_requestor, cycles_2_us(stat->s_time),
  1044. stat->s_ntargself, stat->s_ntarglocals,
  1045. stat->s_ntargremotes, stat->s_ntargcpu,
  1046. stat->s_ntarglocaluvhub, stat->s_ntargremoteuvhub,
  1047. stat->s_ntarguvhub, stat->s_ntarguvhub16);
  1048. seq_printf(file, "%ld %ld %ld %ld %ld ",
  1049. stat->s_ntarguvhub8, stat->s_ntarguvhub4,
  1050. stat->s_ntarguvhub2, stat->s_ntarguvhub1,
  1051. stat->s_dtimeout);
  1052. seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
  1053. stat->s_retry_messages, stat->s_retriesok,
  1054. stat->s_resets_plug, stat->s_resets_timeout,
  1055. stat->s_giveup, stat->s_stimeout,
  1056. stat->s_busy, stat->s_throttles);
  1057. /* destination side statistics */
  1058. seq_printf(file,
  1059. "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
  1060. read_gmmr_sw_ack(uv_cpu_to_pnode(cpu)),
  1061. stat->d_requestee, cycles_2_us(stat->d_time),
  1062. stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
  1063. stat->d_nomsg, stat->d_retries, stat->d_canceled,
  1064. stat->d_nocanceled, stat->d_resets,
  1065. stat->d_rcanceled);
  1066. seq_printf(file, "%ld %ld\n",
  1067. stat->s_bau_disabled, stat->s_bau_reenabled);
  1068. }
  1069. return 0;
  1070. }
  1071. /*
  1072. * Display the tunables thru debugfs
  1073. */
  1074. static ssize_t tunables_read(struct file *file, char __user *userbuf,
  1075. size_t count, loff_t *ppos)
  1076. {
  1077. char *buf;
  1078. int ret;
  1079. buf = kasprintf(GFP_KERNEL, "%s %s %s\n%d %d %d %d %d %d %d %d %d\n",
  1080. "max_concur plugged_delay plugsb4reset",
  1081. "timeoutsb4reset ipi_reset_limit complete_threshold",
  1082. "congested_response_us congested_reps congested_period",
  1083. max_concurr, plugged_delay, plugsb4reset,
  1084. timeoutsb4reset, ipi_reset_limit, complete_threshold,
  1085. congested_respns_us, congested_reps, congested_period);
  1086. if (!buf)
  1087. return -ENOMEM;
  1088. ret = simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
  1089. kfree(buf);
  1090. return ret;
  1091. }
  1092. /*
  1093. * handle a write to /proc/sgi_uv/ptc_statistics
  1094. * -1: reset the statistics
  1095. * 0: display meaning of the statistics
  1096. */
  1097. static ssize_t ptc_proc_write(struct file *file, const char __user *user,
  1098. size_t count, loff_t *data)
  1099. {
  1100. int cpu;
  1101. int i;
  1102. int elements;
  1103. long input_arg;
  1104. char optstr[64];
  1105. struct ptc_stats *stat;
  1106. if (count == 0 || count > sizeof(optstr))
  1107. return -EINVAL;
  1108. if (copy_from_user(optstr, user, count))
  1109. return -EFAULT;
  1110. optstr[count - 1] = '\0';
  1111. if (strict_strtol(optstr, 10, &input_arg) < 0) {
  1112. printk(KERN_DEBUG "%s is invalid\n", optstr);
  1113. return -EINVAL;
  1114. }
  1115. if (input_arg == 0) {
  1116. elements = sizeof(stat_description)/sizeof(*stat_description);
  1117. printk(KERN_DEBUG "# cpu: cpu number\n");
  1118. printk(KERN_DEBUG "Sender statistics:\n");
  1119. for (i = 0; i < elements; i++)
  1120. printk(KERN_DEBUG "%s\n", stat_description[i]);
  1121. } else if (input_arg == -1) {
  1122. for_each_present_cpu(cpu) {
  1123. stat = &per_cpu(ptcstats, cpu);
  1124. memset(stat, 0, sizeof(struct ptc_stats));
  1125. }
  1126. }
  1127. return count;
  1128. }
  1129. static int local_atoi(const char *name)
  1130. {
  1131. int val = 0;
  1132. for (;; name++) {
  1133. switch (*name) {
  1134. case '0' ... '9':
  1135. val = 10*val+(*name-'0');
  1136. break;
  1137. default:
  1138. return val;
  1139. }
  1140. }
  1141. }
  1142. /*
  1143. * Parse the values written to /sys/kernel/debug/sgi_uv/bau_tunables.
  1144. * Zero values reset them to defaults.
  1145. */
  1146. static int parse_tunables_write(struct bau_control *bcp, char *instr,
  1147. int count)
  1148. {
  1149. char *p;
  1150. char *q;
  1151. int cnt = 0;
  1152. int val;
  1153. int e = sizeof(tunables) / sizeof(*tunables);
  1154. p = instr + strspn(instr, WHITESPACE);
  1155. q = p;
  1156. for (; *p; p = q + strspn(q, WHITESPACE)) {
  1157. q = p + strcspn(p, WHITESPACE);
  1158. cnt++;
  1159. if (q == p)
  1160. break;
  1161. }
  1162. if (cnt != e) {
  1163. printk(KERN_INFO "bau tunable error: should be %d values\n", e);
  1164. return -EINVAL;
  1165. }
  1166. p = instr + strspn(instr, WHITESPACE);
  1167. q = p;
  1168. for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
  1169. q = p + strcspn(p, WHITESPACE);
  1170. val = local_atoi(p);
  1171. switch (cnt) {
  1172. case 0:
  1173. if (val == 0) {
  1174. max_concurr = MAX_BAU_CONCURRENT;
  1175. max_concurr_const = MAX_BAU_CONCURRENT;
  1176. continue;
  1177. }
  1178. if (val < 1 || val > bcp->cpus_in_uvhub) {
  1179. printk(KERN_DEBUG
  1180. "Error: BAU max concurrent %d is invalid\n",
  1181. val);
  1182. return -EINVAL;
  1183. }
  1184. max_concurr = val;
  1185. max_concurr_const = val;
  1186. continue;
  1187. default:
  1188. if (val == 0)
  1189. *tunables[cnt].tunp = tunables[cnt].deflt;
  1190. else
  1191. *tunables[cnt].tunp = val;
  1192. continue;
  1193. }
  1194. if (q == p)
  1195. break;
  1196. }
  1197. return 0;
  1198. }
  1199. /*
  1200. * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
  1201. */
  1202. static ssize_t tunables_write(struct file *file, const char __user *user,
  1203. size_t count, loff_t *data)
  1204. {
  1205. int cpu;
  1206. int ret;
  1207. char instr[100];
  1208. struct bau_control *bcp;
  1209. if (count == 0 || count > sizeof(instr)-1)
  1210. return -EINVAL;
  1211. if (copy_from_user(instr, user, count))
  1212. return -EFAULT;
  1213. instr[count] = '\0';
  1214. cpu = get_cpu();
  1215. bcp = &per_cpu(bau_control, cpu);
  1216. ret = parse_tunables_write(bcp, instr, count);
  1217. put_cpu();
  1218. if (ret)
  1219. return ret;
  1220. for_each_present_cpu(cpu) {
  1221. bcp = &per_cpu(bau_control, cpu);
  1222. bcp->max_concurr = max_concurr;
  1223. bcp->max_concurr_const = max_concurr;
  1224. bcp->plugged_delay = plugged_delay;
  1225. bcp->plugsb4reset = plugsb4reset;
  1226. bcp->timeoutsb4reset = timeoutsb4reset;
  1227. bcp->ipi_reset_limit = ipi_reset_limit;
  1228. bcp->complete_threshold = complete_threshold;
  1229. bcp->cong_response_us = congested_respns_us;
  1230. bcp->cong_reps = congested_reps;
  1231. bcp->cong_period = congested_period;
  1232. }
  1233. return count;
  1234. }
  1235. static const struct seq_operations uv_ptc_seq_ops = {
  1236. .start = ptc_seq_start,
  1237. .next = ptc_seq_next,
  1238. .stop = ptc_seq_stop,
  1239. .show = ptc_seq_show
  1240. };
  1241. static int ptc_proc_open(struct inode *inode, struct file *file)
  1242. {
  1243. return seq_open(file, &uv_ptc_seq_ops);
  1244. }
  1245. static int tunables_open(struct inode *inode, struct file *file)
  1246. {
  1247. return 0;
  1248. }
  1249. static const struct file_operations proc_uv_ptc_operations = {
  1250. .open = ptc_proc_open,
  1251. .read = seq_read,
  1252. .write = ptc_proc_write,
  1253. .llseek = seq_lseek,
  1254. .release = seq_release,
  1255. };
  1256. static const struct file_operations tunables_fops = {
  1257. .open = tunables_open,
  1258. .read = tunables_read,
  1259. .write = tunables_write,
  1260. .llseek = default_llseek,
  1261. };
  1262. static int __init uv_ptc_init(void)
  1263. {
  1264. struct proc_dir_entry *proc_uv_ptc;
  1265. if (!is_uv_system())
  1266. return 0;
  1267. proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
  1268. &proc_uv_ptc_operations);
  1269. if (!proc_uv_ptc) {
  1270. printk(KERN_ERR "unable to create %s proc entry\n",
  1271. UV_PTC_BASENAME);
  1272. return -EINVAL;
  1273. }
  1274. tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
  1275. if (!tunables_dir) {
  1276. printk(KERN_ERR "unable to create debugfs directory %s\n",
  1277. UV_BAU_TUNABLES_DIR);
  1278. return -EINVAL;
  1279. }
  1280. tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
  1281. tunables_dir, NULL, &tunables_fops);
  1282. if (!tunables_file) {
  1283. printk(KERN_ERR "unable to create debugfs file %s\n",
  1284. UV_BAU_TUNABLES_FILE);
  1285. return -EINVAL;
  1286. }
  1287. return 0;
  1288. }
  1289. /*
  1290. * Initialize the sending side's sending buffers.
  1291. */
  1292. static void activation_descriptor_init(int node, int pnode, int base_pnode)
  1293. {
  1294. int i;
  1295. int cpu;
  1296. int uv1 = 0;
  1297. unsigned long gpa;
  1298. unsigned long m;
  1299. unsigned long n;
  1300. size_t dsize;
  1301. struct bau_desc *bau_desc;
  1302. struct bau_desc *bd2;
  1303. struct uv1_bau_msg_header *uv1_hdr;
  1304. struct uv2_bau_msg_header *uv2_hdr;
  1305. struct bau_control *bcp;
  1306. /*
  1307. * each bau_desc is 64 bytes; there are 8 (ITEMS_PER_DESC)
  1308. * per cpu; and one per cpu on the uvhub (ADP_SZ)
  1309. */
  1310. dsize = sizeof(struct bau_desc) * ADP_SZ * ITEMS_PER_DESC;
  1311. bau_desc = kmalloc_node(dsize, GFP_KERNEL, node);
  1312. BUG_ON(!bau_desc);
  1313. gpa = uv_gpa(bau_desc);
  1314. n = uv_gpa_to_gnode(gpa);
  1315. m = uv_gpa_to_offset(gpa);
  1316. if (is_uv1_hub())
  1317. uv1 = 1;
  1318. /* the 14-bit pnode */
  1319. write_mmr_descriptor_base(pnode, (n << UV_DESC_PSHIFT | m));
  1320. /*
  1321. * Initializing all 8 (ITEMS_PER_DESC) descriptors for each
  1322. * cpu even though we only use the first one; one descriptor can
  1323. * describe a broadcast to 256 uv hubs.
  1324. */
  1325. for (i = 0, bd2 = bau_desc; i < (ADP_SZ * ITEMS_PER_DESC); i++, bd2++) {
  1326. memset(bd2, 0, sizeof(struct bau_desc));
  1327. if (uv1) {
  1328. uv1_hdr = &bd2->header.uv1_hdr;
  1329. uv1_hdr->swack_flag = 1;
  1330. /*
  1331. * The base_dest_nasid set in the message header
  1332. * is the nasid of the first uvhub in the partition.
  1333. * The bit map will indicate destination pnode numbers
  1334. * relative to that base. They may not be consecutive
  1335. * if nasid striding is being used.
  1336. */
  1337. uv1_hdr->base_dest_nasid =
  1338. UV_PNODE_TO_NASID(base_pnode);
  1339. uv1_hdr->dest_subnodeid = UV_LB_SUBNODEID;
  1340. uv1_hdr->command = UV_NET_ENDPOINT_INTD;
  1341. uv1_hdr->int_both = 1;
  1342. /*
  1343. * all others need to be set to zero:
  1344. * fairness chaining multilevel count replied_to
  1345. */
  1346. } else {
  1347. uv2_hdr = &bd2->header.uv2_hdr;
  1348. uv2_hdr->swack_flag = 1;
  1349. uv2_hdr->base_dest_nasid =
  1350. UV_PNODE_TO_NASID(base_pnode);
  1351. uv2_hdr->dest_subnodeid = UV_LB_SUBNODEID;
  1352. uv2_hdr->command = UV_NET_ENDPOINT_INTD;
  1353. }
  1354. }
  1355. for_each_present_cpu(cpu) {
  1356. if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
  1357. continue;
  1358. bcp = &per_cpu(bau_control, cpu);
  1359. bcp->descriptor_base = bau_desc;
  1360. }
  1361. }
  1362. /*
  1363. * initialize the destination side's receiving buffers
  1364. * entered for each uvhub in the partition
  1365. * - node is first node (kernel memory notion) on the uvhub
  1366. * - pnode is the uvhub's physical identifier
  1367. */
  1368. static void pq_init(int node, int pnode)
  1369. {
  1370. int cpu;
  1371. size_t plsize;
  1372. char *cp;
  1373. void *vp;
  1374. unsigned long pn;
  1375. unsigned long first;
  1376. unsigned long pn_first;
  1377. unsigned long last;
  1378. struct bau_pq_entry *pqp;
  1379. struct bau_control *bcp;
  1380. plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
  1381. vp = kmalloc_node(plsize, GFP_KERNEL, node);
  1382. pqp = (struct bau_pq_entry *)vp;
  1383. BUG_ON(!pqp);
  1384. cp = (char *)pqp + 31;
  1385. pqp = (struct bau_pq_entry *)(((unsigned long)cp >> 5) << 5);
  1386. for_each_present_cpu(cpu) {
  1387. if (pnode != uv_cpu_to_pnode(cpu))
  1388. continue;
  1389. /* for every cpu on this pnode: */
  1390. bcp = &per_cpu(bau_control, cpu);
  1391. bcp->queue_first = pqp;
  1392. bcp->bau_msg_head = pqp;
  1393. bcp->queue_last = pqp + (DEST_Q_SIZE - 1);
  1394. }
  1395. /*
  1396. * need the gnode of where the memory was really allocated
  1397. */
  1398. pn = uv_gpa_to_gnode(uv_gpa(pqp));
  1399. first = uv_physnodeaddr(pqp);
  1400. pn_first = ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) | first;
  1401. last = uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1));
  1402. write_mmr_payload_first(pnode, pn_first);
  1403. write_mmr_payload_tail(pnode, first);
  1404. write_mmr_payload_last(pnode, last);
  1405. /* in effect, all msg_type's are set to MSG_NOOP */
  1406. memset(pqp, 0, sizeof(struct bau_pq_entry) * DEST_Q_SIZE);
  1407. }
  1408. /*
  1409. * Initialization of each UV hub's structures
  1410. */
  1411. static void __init init_uvhub(int uvhub, int vector, int base_pnode)
  1412. {
  1413. int node;
  1414. int pnode;
  1415. unsigned long apicid;
  1416. node = uvhub_to_first_node(uvhub);
  1417. pnode = uv_blade_to_pnode(uvhub);
  1418. activation_descriptor_init(node, pnode, base_pnode);
  1419. pq_init(node, pnode);
  1420. /*
  1421. * The below initialization can't be in firmware because the
  1422. * messaging IRQ will be determined by the OS.
  1423. */
  1424. apicid = uvhub_to_first_apicid(uvhub) | uv_apicid_hibits;
  1425. write_mmr_data_config(pnode, ((apicid << 32) | vector));
  1426. }
  1427. /*
  1428. * We will set BAU_MISC_CONTROL with a timeout period.
  1429. * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
  1430. * So the destination timeout period has to be calculated from them.
  1431. */
  1432. static int calculate_destination_timeout(void)
  1433. {
  1434. unsigned long mmr_image;
  1435. int mult1;
  1436. int mult2;
  1437. int index;
  1438. int base;
  1439. int ret;
  1440. unsigned long ts_ns;
  1441. if (is_uv1_hub()) {
  1442. mult1 = SOFTACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
  1443. mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
  1444. index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
  1445. mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
  1446. mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
  1447. base = timeout_base_ns[index];
  1448. ts_ns = base * mult1 * mult2;
  1449. ret = ts_ns / 1000;
  1450. } else {
  1451. /* 4 bits 0/1 for 10/80us, 3 bits of multiplier */
  1452. mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
  1453. mmr_image = (mmr_image & UV_SA_MASK) >> UV_SA_SHFT;
  1454. if (mmr_image & (1L << UV2_ACK_UNITS_SHFT))
  1455. mult1 = 80;
  1456. else
  1457. mult1 = 10;
  1458. base = mmr_image & UV2_ACK_MASK;
  1459. ret = mult1 * base;
  1460. }
  1461. return ret;
  1462. }
  1463. static void __init init_per_cpu_tunables(void)
  1464. {
  1465. int cpu;
  1466. struct bau_control *bcp;
  1467. for_each_present_cpu(cpu) {
  1468. bcp = &per_cpu(bau_control, cpu);
  1469. bcp->baudisabled = 0;
  1470. bcp->statp = &per_cpu(ptcstats, cpu);
  1471. /* time interval to catch a hardware stay-busy bug */
  1472. bcp->timeout_interval = usec_2_cycles(2*timeout_us);
  1473. bcp->max_concurr = max_concurr;
  1474. bcp->max_concurr_const = max_concurr;
  1475. bcp->plugged_delay = plugged_delay;
  1476. bcp->plugsb4reset = plugsb4reset;
  1477. bcp->timeoutsb4reset = timeoutsb4reset;
  1478. bcp->ipi_reset_limit = ipi_reset_limit;
  1479. bcp->complete_threshold = complete_threshold;
  1480. bcp->cong_response_us = congested_respns_us;
  1481. bcp->cong_reps = congested_reps;
  1482. bcp->cong_period = congested_period;
  1483. }
  1484. }
  1485. /*
  1486. * Scan all cpus to collect blade and socket summaries.
  1487. */
  1488. static int __init get_cpu_topology(int base_pnode,
  1489. struct uvhub_desc *uvhub_descs,
  1490. unsigned char *uvhub_mask)
  1491. {
  1492. int cpu;
  1493. int pnode;
  1494. int uvhub;
  1495. int socket;
  1496. struct bau_control *bcp;
  1497. struct uvhub_desc *bdp;
  1498. struct socket_desc *sdp;
  1499. for_each_present_cpu(cpu) {
  1500. bcp = &per_cpu(bau_control, cpu);
  1501. memset(bcp, 0, sizeof(struct bau_control));
  1502. pnode = uv_cpu_hub_info(cpu)->pnode;
  1503. if ((pnode - base_pnode) >= UV_DISTRIBUTION_SIZE) {
  1504. printk(KERN_EMERG
  1505. "cpu %d pnode %d-%d beyond %d; BAU disabled\n",
  1506. cpu, pnode, base_pnode, UV_DISTRIBUTION_SIZE);
  1507. return 1;
  1508. }
  1509. bcp->osnode = cpu_to_node(cpu);
  1510. bcp->partition_base_pnode = base_pnode;
  1511. uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
  1512. *(uvhub_mask + (uvhub/8)) |= (1 << (uvhub%8));
  1513. bdp = &uvhub_descs[uvhub];
  1514. bdp->num_cpus++;
  1515. bdp->uvhub = uvhub;
  1516. bdp->pnode = pnode;
  1517. /* kludge: 'assuming' one node per socket, and assuming that
  1518. disabling a socket just leaves a gap in node numbers */
  1519. socket = bcp->osnode & 1;
  1520. bdp->socket_mask |= (1 << socket);
  1521. sdp = &bdp->socket[socket];
  1522. sdp->cpu_number[sdp->num_cpus] = cpu;
  1523. sdp->num_cpus++;
  1524. if (sdp->num_cpus > MAX_CPUS_PER_SOCKET) {
  1525. printk(KERN_EMERG "%d cpus per socket invalid\n",
  1526. sdp->num_cpus);
  1527. return 1;
  1528. }
  1529. }
  1530. return 0;
  1531. }
  1532. /*
  1533. * Each socket is to get a local array of pnodes/hubs.
  1534. */
  1535. static void make_per_cpu_thp(struct bau_control *smaster)
  1536. {
  1537. int cpu;
  1538. size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
  1539. smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
  1540. memset(smaster->thp, 0, hpsz);
  1541. for_each_present_cpu(cpu) {
  1542. smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
  1543. smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
  1544. }
  1545. }
  1546. /*
  1547. * Each uvhub is to get a local cpumask.
  1548. */
  1549. static void make_per_hub_cpumask(struct bau_control *hmaster)
  1550. {
  1551. int sz = sizeof(cpumask_t);
  1552. hmaster->cpumask = kzalloc_node(sz, GFP_KERNEL, hmaster->osnode);
  1553. }
  1554. /*
  1555. * Initialize all the per_cpu information for the cpu's on a given socket,
  1556. * given what has been gathered into the socket_desc struct.
  1557. * And reports the chosen hub and socket masters back to the caller.
  1558. */
  1559. static int scan_sock(struct socket_desc *sdp, struct uvhub_desc *bdp,
  1560. struct bau_control **smasterp,
  1561. struct bau_control **hmasterp)
  1562. {
  1563. int i;
  1564. int cpu;
  1565. struct bau_control *bcp;
  1566. for (i = 0; i < sdp->num_cpus; i++) {
  1567. cpu = sdp->cpu_number[i];
  1568. bcp = &per_cpu(bau_control, cpu);
  1569. bcp->cpu = cpu;
  1570. if (i == 0) {
  1571. *smasterp = bcp;
  1572. if (!(*hmasterp))
  1573. *hmasterp = bcp;
  1574. }
  1575. bcp->cpus_in_uvhub = bdp->num_cpus;
  1576. bcp->cpus_in_socket = sdp->num_cpus;
  1577. bcp->socket_master = *smasterp;
  1578. bcp->uvhub = bdp->uvhub;
  1579. if (is_uv1_hub())
  1580. bcp->uvhub_version = 1;
  1581. else if (is_uv2_hub())
  1582. bcp->uvhub_version = 2;
  1583. else {
  1584. printk(KERN_EMERG "uvhub version not 1 or 2\n");
  1585. return 1;
  1586. }
  1587. bcp->uvhub_master = *hmasterp;
  1588. bcp->uvhub_cpu = uv_cpu_hub_info(cpu)->blade_processor_id;
  1589. if (bcp->uvhub_cpu >= MAX_CPUS_PER_UVHUB) {
  1590. printk(KERN_EMERG "%d cpus per uvhub invalid\n",
  1591. bcp->uvhub_cpu);
  1592. return 1;
  1593. }
  1594. }
  1595. return 0;
  1596. }
  1597. /*
  1598. * Summarize the blade and socket topology into the per_cpu structures.
  1599. */
  1600. static int __init summarize_uvhub_sockets(int nuvhubs,
  1601. struct uvhub_desc *uvhub_descs,
  1602. unsigned char *uvhub_mask)
  1603. {
  1604. int socket;
  1605. int uvhub;
  1606. unsigned short socket_mask;
  1607. for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
  1608. struct uvhub_desc *bdp;
  1609. struct bau_control *smaster = NULL;
  1610. struct bau_control *hmaster = NULL;
  1611. if (!(*(uvhub_mask + (uvhub/8)) & (1 << (uvhub%8))))
  1612. continue;
  1613. bdp = &uvhub_descs[uvhub];
  1614. socket_mask = bdp->socket_mask;
  1615. socket = 0;
  1616. while (socket_mask) {
  1617. struct socket_desc *sdp;
  1618. if ((socket_mask & 1)) {
  1619. sdp = &bdp->socket[socket];
  1620. if (scan_sock(sdp, bdp, &smaster, &hmaster))
  1621. return 1;
  1622. make_per_cpu_thp(smaster);
  1623. }
  1624. socket++;
  1625. socket_mask = (socket_mask >> 1);
  1626. }
  1627. make_per_hub_cpumask(hmaster);
  1628. }
  1629. return 0;
  1630. }
  1631. /*
  1632. * initialize the bau_control structure for each cpu
  1633. */
  1634. static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
  1635. {
  1636. unsigned char *uvhub_mask;
  1637. void *vp;
  1638. struct uvhub_desc *uvhub_descs;
  1639. timeout_us = calculate_destination_timeout();
  1640. vp = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
  1641. uvhub_descs = (struct uvhub_desc *)vp;
  1642. memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
  1643. uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
  1644. if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask))
  1645. goto fail;
  1646. if (summarize_uvhub_sockets(nuvhubs, uvhub_descs, uvhub_mask))
  1647. goto fail;
  1648. kfree(uvhub_descs);
  1649. kfree(uvhub_mask);
  1650. init_per_cpu_tunables();
  1651. return 0;
  1652. fail:
  1653. kfree(uvhub_descs);
  1654. kfree(uvhub_mask);
  1655. return 1;
  1656. }
  1657. /*
  1658. * Initialization of BAU-related structures
  1659. */
  1660. static int __init uv_bau_init(void)
  1661. {
  1662. int uvhub;
  1663. int pnode;
  1664. int nuvhubs;
  1665. int cur_cpu;
  1666. int cpus;
  1667. int vector;
  1668. cpumask_var_t *mask;
  1669. if (!is_uv_system())
  1670. return 0;
  1671. if (nobau)
  1672. return 0;
  1673. for_each_possible_cpu(cur_cpu) {
  1674. mask = &per_cpu(uv_flush_tlb_mask, cur_cpu);
  1675. zalloc_cpumask_var_node(mask, GFP_KERNEL, cpu_to_node(cur_cpu));
  1676. }
  1677. nuvhubs = uv_num_possible_blades();
  1678. spin_lock_init(&disable_lock);
  1679. congested_cycles = usec_2_cycles(congested_respns_us);
  1680. uv_base_pnode = 0x7fffffff;
  1681. for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
  1682. cpus = uv_blade_nr_possible_cpus(uvhub);
  1683. if (cpus && (uv_blade_to_pnode(uvhub) < uv_base_pnode))
  1684. uv_base_pnode = uv_blade_to_pnode(uvhub);
  1685. }
  1686. if (init_per_cpu(nuvhubs, uv_base_pnode)) {
  1687. nobau = 1;
  1688. return 0;
  1689. }
  1690. vector = UV_BAU_MESSAGE;
  1691. for_each_possible_blade(uvhub)
  1692. if (uv_blade_nr_possible_cpus(uvhub))
  1693. init_uvhub(uvhub, vector, uv_base_pnode);
  1694. enable_timeouts();
  1695. alloc_intr_gate(vector, uv_bau_message_intr1);
  1696. for_each_possible_blade(uvhub) {
  1697. if (uv_blade_nr_possible_cpus(uvhub)) {
  1698. unsigned long val;
  1699. unsigned long mmr;
  1700. pnode = uv_blade_to_pnode(uvhub);
  1701. /* INIT the bau */
  1702. val = 1L << 63;
  1703. write_gmmr_activation(pnode, val);
  1704. mmr = 1; /* should be 1 to broadcast to both sockets */
  1705. if (!is_uv1_hub())
  1706. write_mmr_data_broadcast(pnode, mmr);
  1707. }
  1708. }
  1709. return 0;
  1710. }
  1711. core_initcall(uv_bau_init);
  1712. fs_initcall(uv_ptc_init);