tlb_uv.c 49 KB

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