tlb_uv.c 56 KB

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