tlb_uv.c 49 KB

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