tlb_uv.c 48 KB

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