tlb_uv.c 55 KB

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