blob: 414f7c4fe76c9b9e762fb925cdc71154b992331f [file] [log] [blame]
Cliff Wickman18129242008-06-02 08:56:14 -05001/*
2 * SGI UltraViolet TLB flush routines.
3 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05004 * (c) 2008-2010 Cliff Wickman <cpw@sgi.com>, SGI.
Cliff Wickman18129242008-06-02 08:56:14 -05005 *
6 * This code is released under the GNU General Public License version 2 or
7 * later.
8 */
Jeremy Fitzhardingeaef8f5b2008-10-14 21:43:43 -07009#include <linux/seq_file.h>
Cliff Wickman18129242008-06-02 08:56:14 -050010#include <linux/proc_fs.h>
11#include <linux/kernel.h>
12
Cliff Wickman18129242008-06-02 08:56:14 -050013#include <asm/mmu_context.h>
Tejun Heobdbcdd42009-01-21 17:26:06 +090014#include <asm/uv/uv.h>
Cliff Wickman18129242008-06-02 08:56:14 -050015#include <asm/uv/uv_mmrs.h>
Ingo Molnarb4c286e2008-06-18 14:28:19 +020016#include <asm/uv/uv_hub.h>
Cliff Wickman18129242008-06-02 08:56:14 -050017#include <asm/uv/uv_bau.h>
Ingo Molnar7b6aa332009-02-17 13:58:15 +010018#include <asm/apic.h>
Ingo Molnarb4c286e2008-06-18 14:28:19 +020019#include <asm/idle.h>
Cliff Wickmanb194b122008-06-12 08:23:48 -050020#include <asm/tsc.h>
Cliff Wickman99dd8712008-08-19 12:51:59 -050021#include <asm/irq_vectors.h>
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050022#include <asm/timer.h>
23
24struct msg_desc {
25 struct bau_payload_queue_entry *msg;
26 int msg_slot;
27 int sw_ack_slot;
28 struct bau_payload_queue_entry *va_queue_first;
29 struct bau_payload_queue_entry *va_queue_last;
30};
Cliff Wickman18129242008-06-02 08:56:14 -050031
Jack Steiner6f4edd62010-03-10 14:44:58 -060032#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x000000000bUL
33
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050034static int uv_bau_max_concurrent __read_mostly;
35
36static int nobau;
37static int __init setup_nobau(char *arg)
38{
39 nobau = 1;
40 return 0;
41}
42early_param("nobau", setup_nobau);
Ingo Molnarb4c286e2008-06-18 14:28:19 +020043
Cliff Wickman94ca8e42009-04-14 10:56:48 -050044/* base pnode in this partition */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050045static int uv_partition_base_pnode __read_mostly;
46/* position of pnode (which is nasid>>1): */
47static int uv_nshift __read_mostly;
48static unsigned long uv_mmask __read_mostly;
Cliff Wickman18129242008-06-02 08:56:14 -050049
Ingo Molnardc163a42008-06-18 14:15:43 +020050static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
51static DEFINE_PER_CPU(struct bau_control, bau_control);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050052static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
53
54struct reset_args {
55 int sender;
56};
Cliff Wickman18129242008-06-02 08:56:14 -050057
58/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050059 * Determine the first node on a uvhub. 'Nodes' are used for kernel
60 * memory allocation.
Cliff Wickman9674f352009-04-03 08:34:05 -050061 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050062static int __init uvhub_to_first_node(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -050063{
64 int node, b;
65
66 for_each_online_node(node) {
67 b = uv_node_to_blade_id(node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050068 if (uvhub == b)
Cliff Wickman9674f352009-04-03 08:34:05 -050069 return node;
70 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050071 return -1;
Cliff Wickman9674f352009-04-03 08:34:05 -050072}
73
74/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050075 * Determine the apicid of the first cpu on a uvhub.
Cliff Wickman9674f352009-04-03 08:34:05 -050076 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050077static int __init uvhub_to_first_apicid(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -050078{
79 int cpu;
80
81 for_each_present_cpu(cpu)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050082 if (uvhub == uv_cpu_to_blade_id(cpu))
Cliff Wickman9674f352009-04-03 08:34:05 -050083 return per_cpu(x86_cpu_to_apicid, cpu);
84 return -1;
85}
86
87/*
Cliff Wickman18129242008-06-02 08:56:14 -050088 * Free a software acknowledge hardware resource by clearing its Pending
89 * bit. This will return a reply to the sender.
90 * If the message has timed out, a reply has already been sent by the
91 * hardware but the resource has not been released. In that case our
92 * clear of the Timeout bit (as well) will free the resource. No reply will
93 * be sent (the hardware will only do one reply per message).
94 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050095static inline void uv_reply_to_message(struct msg_desc *mdp,
96 struct bau_control *bcp)
Cliff Wickman18129242008-06-02 08:56:14 -050097{
Cliff Wickmanb194b122008-06-12 08:23:48 -050098 unsigned long dw;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050099 struct bau_payload_queue_entry *msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500100
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500101 msg = mdp->msg;
102 if (!msg->canceled) {
103 dw = (msg->sw_ack_vector << UV_SW_ACK_NPENDING) |
104 msg->sw_ack_vector;
105 uv_write_local_mmr(
106 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw);
107 }
Cliff Wickman18129242008-06-02 08:56:14 -0500108 msg->replied_to = 1;
109 msg->sw_ack_vector = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500110}
111
112/*
113 * Process the receipt of a RETRY message
114 */
115static inline void uv_bau_process_retry_msg(struct msg_desc *mdp,
116 struct bau_control *bcp)
117{
118 int i;
119 int cancel_count = 0;
120 int slot2;
121 unsigned long msg_res;
122 unsigned long mmr = 0;
123 struct bau_payload_queue_entry *msg;
124 struct bau_payload_queue_entry *msg2;
125 struct ptc_stats *stat;
126
127 msg = mdp->msg;
128 stat = &per_cpu(ptcstats, bcp->cpu);
129 stat->d_retries++;
130 /*
131 * cancel any message from msg+1 to the retry itself
132 */
133 for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
134 if (msg2 > mdp->va_queue_last)
135 msg2 = mdp->va_queue_first;
136 if (msg2 == msg)
137 break;
138
139 /* same conditions for cancellation as uv_do_reset */
140 if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
141 (msg2->sw_ack_vector) && ((msg2->sw_ack_vector &
142 msg->sw_ack_vector) == 0) &&
143 (msg2->sending_cpu == msg->sending_cpu) &&
144 (msg2->msg_type != MSG_NOOP)) {
145 slot2 = msg2 - mdp->va_queue_first;
146 mmr = uv_read_local_mmr
147 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
148 msg_res = ((msg2->sw_ack_vector << 8) |
149 msg2->sw_ack_vector);
150 /*
151 * This is a message retry; clear the resources held
152 * by the previous message only if they timed out.
153 * If it has not timed out we have an unexpected
154 * situation to report.
155 */
156 if (mmr & (msg_res << 8)) {
157 /*
158 * is the resource timed out?
159 * make everyone ignore the cancelled message.
160 */
161 msg2->canceled = 1;
162 stat->d_canceled++;
163 cancel_count++;
164 uv_write_local_mmr(
165 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
166 (msg_res << 8) | msg_res);
167 } else
168 printk(KERN_INFO "note bau retry: no effect\n");
169 }
170 }
171 if (!cancel_count)
172 stat->d_nocanceled++;
Cliff Wickman18129242008-06-02 08:56:14 -0500173}
174
175/*
176 * Do all the things a cpu should do for a TLB shootdown message.
177 * Other cpu's may come here at the same time for this message.
178 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500179static void uv_bau_process_message(struct msg_desc *mdp,
180 struct bau_control *bcp)
Cliff Wickman18129242008-06-02 08:56:14 -0500181{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500182 int msg_ack_count;
183 short socket_ack_count = 0;
184 struct ptc_stats *stat;
185 struct bau_payload_queue_entry *msg;
186 struct bau_control *smaster = bcp->socket_master;
Cliff Wickman18129242008-06-02 08:56:14 -0500187
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500188 /*
189 * This must be a normal message, or retry of a normal message
190 */
191 msg = mdp->msg;
192 stat = &per_cpu(ptcstats, bcp->cpu);
Cliff Wickman18129242008-06-02 08:56:14 -0500193 if (msg->address == TLB_FLUSH_ALL) {
194 local_flush_tlb();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500195 stat->d_alltlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500196 } else {
197 __flush_tlb_one(msg->address);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500198 stat->d_onetlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500199 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500200 stat->d_requestee++;
Cliff Wickman18129242008-06-02 08:56:14 -0500201
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500202 /*
203 * One cpu on each uvhub has the additional job on a RETRY
204 * of releasing the resource held by the message that is
205 * being retried. That message is identified by sending
206 * cpu number.
207 */
208 if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
209 uv_bau_process_retry_msg(mdp, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500210
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500211 /*
212 * This is a sw_ack message, so we have to reply to it.
213 * Count each responding cpu on the socket. This avoids
214 * pinging the count's cache line back and forth between
215 * the sockets.
216 */
217 socket_ack_count = atomic_add_short_return(1, (struct atomic_short *)
218 &smaster->socket_acknowledge_count[mdp->msg_slot]);
219 if (socket_ack_count == bcp->cpus_in_socket) {
220 /*
221 * Both sockets dump their completed count total into
222 * the message's count.
223 */
224 smaster->socket_acknowledge_count[mdp->msg_slot] = 0;
225 msg_ack_count = atomic_add_short_return(socket_ack_count,
226 (struct atomic_short *)&msg->acknowledge_count);
Ingo Molnardc163a42008-06-18 14:15:43 +0200227
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500228 if (msg_ack_count == bcp->cpus_in_uvhub) {
229 /*
230 * All cpus in uvhub saw it; reply
231 */
232 uv_reply_to_message(mdp, bcp);
Ingo Molnardc163a42008-06-18 14:15:43 +0200233 }
234 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500235
236 return;
Cliff Wickman18129242008-06-02 08:56:14 -0500237}
238
239/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500240 * Determine the first cpu on a uvhub.
Cliff Wickman18129242008-06-02 08:56:14 -0500241 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500242static int uvhub_to_first_cpu(int uvhub)
Cliff Wickman18129242008-06-02 08:56:14 -0500243{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500244 int cpu;
245 for_each_present_cpu(cpu)
246 if (uvhub == uv_cpu_to_blade_id(cpu))
247 return cpu;
248 return -1;
Cliff Wickman18129242008-06-02 08:56:14 -0500249}
250
Cliff Wickmanb194b122008-06-12 08:23:48 -0500251/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500252 * Last resort when we get a large number of destination timeouts is
253 * to clear resources held by a given cpu.
254 * Do this with IPI so that all messages in the BAU message queue
255 * can be identified by their nonzero sw_ack_vector field.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500256 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500257 * This is entered for a single cpu on the uvhub.
258 * The sender want's this uvhub to free a specific message's
259 * sw_ack resources.
260 */
261static void
262uv_do_reset(void *ptr)
263{
264 int i;
265 int slot;
266 int count = 0;
267 unsigned long mmr;
268 unsigned long msg_res;
269 struct bau_control *bcp;
270 struct reset_args *rap;
271 struct bau_payload_queue_entry *msg;
272 struct ptc_stats *stat;
273
274 bcp = &per_cpu(bau_control, smp_processor_id());
275 rap = (struct reset_args *)ptr;
276 stat = &per_cpu(ptcstats, bcp->cpu);
277 stat->d_resets++;
278
279 /*
280 * We're looking for the given sender, and
281 * will free its sw_ack resource.
282 * If all cpu's finally responded after the timeout, its
283 * message 'replied_to' was set.
284 */
285 for (msg = bcp->va_queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
286 /* uv_do_reset: same conditions for cancellation as
287 uv_bau_process_retry_msg() */
288 if ((msg->replied_to == 0) &&
289 (msg->canceled == 0) &&
290 (msg->sending_cpu == rap->sender) &&
291 (msg->sw_ack_vector) &&
292 (msg->msg_type != MSG_NOOP)) {
293 /*
294 * make everyone else ignore this message
295 */
296 msg->canceled = 1;
297 slot = msg - bcp->va_queue_first;
298 count++;
299 /*
300 * only reset the resource if it is still pending
301 */
302 mmr = uv_read_local_mmr
303 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
304 msg_res = ((msg->sw_ack_vector << 8) |
305 msg->sw_ack_vector);
306 if (mmr & msg_res) {
307 stat->d_rcanceled++;
308 uv_write_local_mmr(
309 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
310 msg_res);
311 }
312 }
313 }
314 return;
315}
316
317/*
318 * Use IPI to get all target uvhubs to release resources held by
319 * a given sending cpu number.
320 */
321static void uv_reset_with_ipi(struct bau_target_uvhubmask *distribution,
322 int sender)
323{
324 int uvhub;
325 int cpu;
326 cpumask_t mask;
327 struct reset_args reset_args;
328
329 reset_args.sender = sender;
330
331 cpus_clear(mask);
332 /* find a single cpu for each uvhub in this distribution mask */
333 for (uvhub = 0;
334 uvhub < sizeof(struct bau_target_uvhubmask) * BITSPERBYTE;
335 uvhub++) {
336 if (!bau_uvhub_isset(uvhub, distribution))
337 continue;
338 /* find a cpu for this uvhub */
339 cpu = uvhub_to_first_cpu(uvhub);
340 cpu_set(cpu, mask);
341 }
342 /* IPI all cpus; Preemption is already disabled */
343 smp_call_function_many(&mask, uv_do_reset, (void *)&reset_args, 1);
344 return;
345}
346
347static inline unsigned long
348cycles_2_us(unsigned long long cyc)
349{
350 unsigned long long ns;
351 unsigned long us;
352 ns = (cyc * per_cpu(cyc2ns, smp_processor_id()))
353 >> CYC2NS_SCALE_FACTOR;
354 us = ns / 1000;
355 return us;
356}
357
358/*
359 * wait for all cpus on this hub to finish their sends and go quiet
360 * leaves uvhub_quiesce set so that no new broadcasts are started by
361 * bau_flush_send_and_wait()
362 */
363static inline void
364quiesce_local_uvhub(struct bau_control *hmaster)
365{
366 atomic_add_short_return(1, (struct atomic_short *)
367 &hmaster->uvhub_quiesce);
368}
369
370/*
371 * mark this quiet-requestor as done
372 */
373static inline void
374end_uvhub_quiesce(struct bau_control *hmaster)
375{
376 atomic_add_short_return(-1, (struct atomic_short *)
377 &hmaster->uvhub_quiesce);
378}
379
380/*
381 * Wait for completion of a broadcast software ack message
382 * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
Cliff Wickmanb194b122008-06-12 08:23:48 -0500383 */
Ingo Molnardc163a42008-06-18 14:15:43 +0200384static int uv_wait_completion(struct bau_desc *bau_desc,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500385 unsigned long mmr_offset, int right_shift, int this_cpu,
386 struct bau_control *bcp, struct bau_control *smaster, long try)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500387{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500388 int relaxes = 0;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500389 unsigned long descriptor_status;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500390 unsigned long mmr;
391 unsigned long mask;
392 cycles_t ttime;
393 cycles_t timeout_time;
394 struct ptc_stats *stat = &per_cpu(ptcstats, this_cpu);
395 struct bau_control *hmaster;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500396
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500397 hmaster = bcp->uvhub_master;
398 timeout_time = get_cycles() + bcp->timeout_interval;
399
400 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500401 while ((descriptor_status = (((unsigned long)
402 uv_read_local_mmr(mmr_offset) >>
403 right_shift) & UV_ACT_STATUS_MASK)) !=
404 DESC_STATUS_IDLE) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500405 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500406 * Our software ack messages may be blocked because there are
407 * no swack resources available. As long as none of them
408 * has timed out hardware will NACK our message and its
409 * state will stay IDLE.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500410 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500411 if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
412 stat->s_stimeout++;
413 return FLUSH_GIVEUP;
414 } else if (descriptor_status ==
415 DESC_STATUS_DESTINATION_TIMEOUT) {
416 stat->s_dtimeout++;
417 ttime = get_cycles();
418
419 /*
420 * Our retries may be blocked by all destination
421 * swack resources being consumed, and a timeout
422 * pending. In that case hardware returns the
423 * ERROR that looks like a destination timeout.
424 */
425 if (cycles_2_us(ttime - bcp->send_message) < BIOS_TO) {
426 bcp->conseccompletes = 0;
427 return FLUSH_RETRY_PLUGGED;
428 }
429
430 bcp->conseccompletes = 0;
431 return FLUSH_RETRY_TIMEOUT;
432 } else {
433 /*
434 * descriptor_status is still BUSY
435 */
436 cpu_relax();
437 relaxes++;
438 if (relaxes >= 10000) {
439 relaxes = 0;
440 if (get_cycles() > timeout_time) {
441 quiesce_local_uvhub(hmaster);
442
443 /* single-thread the register change */
444 spin_lock(&hmaster->masks_lock);
445 mmr = uv_read_local_mmr(mmr_offset);
446 mask = 0UL;
447 mask |= (3UL < right_shift);
448 mask = ~mask;
449 mmr &= mask;
450 uv_write_local_mmr(mmr_offset, mmr);
451 spin_unlock(&hmaster->masks_lock);
452 end_uvhub_quiesce(hmaster);
453 stat->s_busy++;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500454 return FLUSH_GIVEUP;
455 }
Cliff Wickmanb194b122008-06-12 08:23:48 -0500456 }
457 }
458 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500459 bcp->conseccompletes++;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500460 return FLUSH_COMPLETE;
461}
462
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500463static inline cycles_t
464sec_2_cycles(unsigned long sec)
465{
466 unsigned long ns;
467 cycles_t cyc;
468
469 ns = sec * 1000000000;
470 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
471 return cyc;
472}
473
474/*
475 * conditionally add 1 to *v, unless *v is >= u
476 * return 0 if we cannot add 1 to *v because it is >= u
477 * return 1 if we can add 1 to *v because it is < u
478 * the add is atomic
479 *
480 * This is close to atomic_add_unless(), but this allows the 'u' value
481 * to be lowered below the current 'v'. atomic_add_unless can only stop
482 * on equal.
483 */
484static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
485{
486 spin_lock(lock);
487 if (atomic_read(v) >= u) {
488 spin_unlock(lock);
489 return 0;
490 }
491 atomic_inc(v);
492 spin_unlock(lock);
493 return 1;
494}
495
Cliff Wickmanb194b122008-06-12 08:23:48 -0500496/**
497 * uv_flush_send_and_wait
498 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500499 * Send a broadcast and wait for it to complete.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500500 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500501 * The flush_mask contains the cpus the broadcast is to be sent to, plus
502 * cpus that are on the local uvhub.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500503 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500504 * Returns NULL if all flushing represented in the mask was done. The mask
505 * is zeroed.
Tejun Heobdbcdd42009-01-21 17:26:06 +0900506 * Returns @flush_mask if some remote flushing remains to be done. The
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500507 * mask will have some bits still set, representing any cpus on the local
508 * uvhub (not current cpu) and any on remote uvhubs if the broadcast failed.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500509 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500510const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc,
511 struct cpumask *flush_mask,
512 struct bau_control *bcp)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500513{
Cliff Wickmanb194b122008-06-12 08:23:48 -0500514 int right_shift;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500515 int uvhub;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200516 int bit;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500517 int completion_status = 0;
518 int seq_number = 0;
519 long try = 0;
520 int cpu = bcp->uvhub_cpu;
521 int this_cpu = bcp->cpu;
522 int this_uvhub = bcp->uvhub;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500523 unsigned long mmr_offset;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200524 unsigned long index;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500525 cycles_t time1;
526 cycles_t time2;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500527 struct ptc_stats *stat = &per_cpu(ptcstats, bcp->cpu);
528 struct bau_control *smaster = bcp->socket_master;
529 struct bau_control *hmaster = bcp->uvhub_master;
530
531 /*
532 * Spin here while there are hmaster->max_concurrent or more active
533 * descriptors. This is the per-uvhub 'throttle'.
534 */
535 if (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
536 &hmaster->active_descriptor_count,
537 hmaster->max_concurrent)) {
538 stat->s_throttles++;
539 do {
540 cpu_relax();
541 } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
542 &hmaster->active_descriptor_count,
543 hmaster->max_concurrent));
544 }
545
546 while (hmaster->uvhub_quiesce)
547 cpu_relax();
Cliff Wickmanb194b122008-06-12 08:23:48 -0500548
549 if (cpu < UV_CPUS_PER_ACT_STATUS) {
550 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
551 right_shift = cpu * UV_ACT_STATUS_SIZE;
552 } else {
553 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
554 right_shift =
555 ((cpu - UV_CPUS_PER_ACT_STATUS) * UV_ACT_STATUS_SIZE);
556 }
557 time1 = get_cycles();
558 do {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500559 /*
560 * Every message from any given cpu gets a unique message
561 * sequence number. But retries use that same number.
562 * Our message may have timed out at the destination because
563 * all sw-ack resources are in use and there is a timeout
564 * pending there. In that case, our last send never got
565 * placed into the queue and we need to persist until it
566 * does.
567 *
568 * Make any retry a type MSG_RETRY so that the destination will
569 * free any resource held by a previous message from this cpu.
570 */
571 if (try == 0) {
572 /* use message type set by the caller the first time */
573 seq_number = bcp->message_number++;
574 } else {
575 /* use RETRY type on all the rest; same sequence */
576 bau_desc->header.msg_type = MSG_RETRY;
577 stat->s_retry_messages++;
578 }
579 bau_desc->header.sequence = seq_number;
Ingo Molnardc163a42008-06-18 14:15:43 +0200580 index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) |
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500581 bcp->uvhub_cpu;
582 bcp->send_message = get_cycles();
Cliff Wickmanb194b122008-06-12 08:23:48 -0500583
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500584 uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
585
586 try++;
587 completion_status = uv_wait_completion(bau_desc, mmr_offset,
588 right_shift, this_cpu, bcp, smaster, try);
589
590 if (completion_status == FLUSH_RETRY_PLUGGED) {
591 /*
592 * Our retries may be blocked by all destination swack
593 * resources being consumed, and a timeout pending. In
594 * that case hardware immediately returns the ERROR
595 * that looks like a destination timeout.
596 */
597 udelay(TIMEOUT_DELAY);
598 bcp->plugged_tries++;
599 if (bcp->plugged_tries >= PLUGSB4RESET) {
600 bcp->plugged_tries = 0;
601 quiesce_local_uvhub(hmaster);
602 spin_lock(&hmaster->queue_lock);
603 uv_reset_with_ipi(&bau_desc->distribution,
604 this_cpu);
605 spin_unlock(&hmaster->queue_lock);
606 end_uvhub_quiesce(hmaster);
607 bcp->ipi_attempts++;
608 stat->s_resets_plug++;
609 }
610 } else if (completion_status == FLUSH_RETRY_TIMEOUT) {
611 hmaster->max_concurrent = 1;
612 bcp->timeout_tries++;
613 udelay(TIMEOUT_DELAY);
614 if (bcp->timeout_tries >= TIMEOUTSB4RESET) {
615 bcp->timeout_tries = 0;
616 quiesce_local_uvhub(hmaster);
617 spin_lock(&hmaster->queue_lock);
618 uv_reset_with_ipi(&bau_desc->distribution,
619 this_cpu);
620 spin_unlock(&hmaster->queue_lock);
621 end_uvhub_quiesce(hmaster);
622 bcp->ipi_attempts++;
623 stat->s_resets_timeout++;
624 }
625 }
626 if (bcp->ipi_attempts >= 3) {
627 bcp->ipi_attempts = 0;
628 completion_status = FLUSH_GIVEUP;
629 break;
630 }
631 cpu_relax();
632 } while ((completion_status == FLUSH_RETRY_PLUGGED) ||
633 (completion_status == FLUSH_RETRY_TIMEOUT));
634 time2 = get_cycles();
635
636 if ((completion_status == FLUSH_COMPLETE) && (bcp->conseccompletes > 5)
637 && (hmaster->max_concurrent < hmaster->max_concurrent_constant))
638 hmaster->max_concurrent++;
639
640 /*
641 * hold any cpu not timing out here; no other cpu currently held by
642 * the 'throttle' should enter the activation code
643 */
644 while (hmaster->uvhub_quiesce)
645 cpu_relax();
646 atomic_dec(&hmaster->active_descriptor_count);
647
648 /* guard against cycles wrap */
649 if (time2 > time1)
650 stat->s_time += (time2 - time1);
651 else
652 stat->s_requestor--; /* don't count this one */
653 if (completion_status == FLUSH_COMPLETE && try > 1)
654 stat->s_retriesok++;
655 else if (completion_status == FLUSH_GIVEUP) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500656 /*
657 * Cause the caller to do an IPI-style TLB shootdown on
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500658 * the target cpu's, all of which are still in the mask.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500659 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500660 stat->s_giveup++;
Cliff Wickman2749ebe2009-01-29 15:35:26 -0600661 return flush_mask;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500662 }
663
664 /*
665 * Success, so clear the remote cpu's from the mask so we don't
666 * use the IPI method of shootdown on them.
667 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900668 for_each_cpu(bit, flush_mask) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500669 uvhub = uv_cpu_to_blade_id(bit);
670 if (uvhub == this_uvhub)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500671 continue;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900672 cpumask_clear_cpu(bit, flush_mask);
Cliff Wickmanb194b122008-06-12 08:23:48 -0500673 }
Tejun Heobdbcdd42009-01-21 17:26:06 +0900674 if (!cpumask_empty(flush_mask))
675 return flush_mask;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500676
Tejun Heobdbcdd42009-01-21 17:26:06 +0900677 return NULL;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500678}
679
Cliff Wickman18129242008-06-02 08:56:14 -0500680/**
681 * uv_flush_tlb_others - globally purge translation cache of a virtual
682 * address or all TLB's
Tejun Heobdbcdd42009-01-21 17:26:06 +0900683 * @cpumask: mask of all cpu's in which the address is to be removed
Cliff Wickman18129242008-06-02 08:56:14 -0500684 * @mm: mm_struct containing virtual address range
685 * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
Tejun Heobdbcdd42009-01-21 17:26:06 +0900686 * @cpu: the current cpu
Cliff Wickman18129242008-06-02 08:56:14 -0500687 *
688 * This is the entry point for initiating any UV global TLB shootdown.
689 *
690 * Purges the translation caches of all specified processors of the given
691 * virtual address, or purges all TLB's on specified processors.
692 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900693 * The caller has derived the cpumask from the mm_struct. This function
694 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
Cliff Wickman18129242008-06-02 08:56:14 -0500695 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500696 * The cpumask is converted into a uvhubmask of the uvhubs containing
697 * those cpus.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500698 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900699 * Note that this function should be called with preemption disabled.
700 *
701 * Returns NULL if all remote flushing was done.
702 * Returns pointer to cpumask if some remote flushing remains to be
703 * done. The returned pointer is valid till preemption is re-enabled.
Cliff Wickman18129242008-06-02 08:56:14 -0500704 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900705const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
706 struct mm_struct *mm,
707 unsigned long va, unsigned int cpu)
Cliff Wickman18129242008-06-02 08:56:14 -0500708{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500709 int remotes;
710 int tcpu;
711 int uvhub;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500712 int locals = 0;
Ingo Molnardc163a42008-06-18 14:15:43 +0200713 struct bau_desc *bau_desc;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500714 struct cpumask *flush_mask;
715 struct ptc_stats *stat;
716 struct bau_control *bcp;
Cliff Wickman18129242008-06-02 08:56:14 -0500717
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500718 if (nobau)
719 return cpumask;
720
721 bcp = &per_cpu(bau_control, cpu);
722 /*
723 * Each sending cpu has a per-cpu mask which it fills from the caller's
724 * cpu mask. Only remote cpus are converted to uvhubs and copied.
725 */
726 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
727 /*
728 * copy cpumask to flush_mask, removing current cpu
729 * (current cpu should already have been flushed by the caller and
730 * should never be returned if we return flush_mask)
731 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900732 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500733 if (cpu_isset(cpu, *cpumask))
734 locals++; /* current cpu was targeted */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900735
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500736 bau_desc = bcp->descriptor_base;
737 bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu;
Cliff Wickman18129242008-06-02 08:56:14 -0500738
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500739 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
740 remotes = 0;
741 for_each_cpu(tcpu, flush_mask) {
742 uvhub = uv_cpu_to_blade_id(tcpu);
743 if (uvhub == bcp->uvhub) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500744 locals++;
Cliff Wickman18129242008-06-02 08:56:14 -0500745 continue;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500746 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500747 bau_uvhub_set(uvhub, &bau_desc->distribution);
748 remotes++;
Cliff Wickman18129242008-06-02 08:56:14 -0500749 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500750 if (remotes == 0) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500751 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500752 * No off_hub flushing; return status for local hub.
753 * Return the caller's mask if all were local (the current
754 * cpu may be in that mask).
Cliff Wickmanb194b122008-06-12 08:23:48 -0500755 */
756 if (locals)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500757 return cpumask;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500758 else
Tejun Heobdbcdd42009-01-21 17:26:06 +0900759 return NULL;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500760 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500761 stat = &per_cpu(ptcstats, cpu);
762 stat->s_requestor++;
763 stat->s_ntargcpu += remotes;
764 remotes = bau_uvhub_weight(&bau_desc->distribution);
765 stat->s_ntarguvhub += remotes;
766 if (remotes >= 16)
767 stat->s_ntarguvhub16++;
768 else if (remotes >= 8)
769 stat->s_ntarguvhub8++;
770 else if (remotes >= 4)
771 stat->s_ntarguvhub4++;
772 else if (remotes >= 2)
773 stat->s_ntarguvhub2++;
774 else
775 stat->s_ntarguvhub1++;
Cliff Wickman18129242008-06-02 08:56:14 -0500776
777 bau_desc->payload.address = va;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900778 bau_desc->payload.sending_cpu = cpu;
Cliff Wickman18129242008-06-02 08:56:14 -0500779
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500780 /*
781 * uv_flush_send_and_wait returns null if all cpu's were messaged, or
782 * the adjusted flush_mask if any cpu's were not messaged.
783 */
784 return uv_flush_send_and_wait(bau_desc, flush_mask, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500785}
786
787/*
788 * The BAU message interrupt comes here. (registered by set_intr_gate)
789 * See entry_64.S
790 *
791 * We received a broadcast assist message.
792 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500793 * Interrupts are disabled; this interrupt could represent
Cliff Wickman18129242008-06-02 08:56:14 -0500794 * the receipt of several messages.
795 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500796 * All cores/threads on this hub get this interrupt.
797 * The last one to see it does the software ack.
Cliff Wickman18129242008-06-02 08:56:14 -0500798 * (the resource will not be freed until noninterruptable cpus see this
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500799 * interrupt; hardware may timeout the s/w ack and reply ERROR)
Cliff Wickman18129242008-06-02 08:56:14 -0500800 */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500801void uv_bau_message_interrupt(struct pt_regs *regs)
Cliff Wickman18129242008-06-02 08:56:14 -0500802{
Cliff Wickman18129242008-06-02 08:56:14 -0500803 int count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500804 cycles_t time_start;
805 struct bau_payload_queue_entry *msg;
806 struct bau_control *bcp;
807 struct ptc_stats *stat;
808 struct msg_desc msgdesc;
Cliff Wickman18129242008-06-02 08:56:14 -0500809
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500810 time_start = get_cycles();
811 bcp = &per_cpu(bau_control, smp_processor_id());
812 stat = &per_cpu(ptcstats, smp_processor_id());
813 msgdesc.va_queue_first = bcp->va_queue_first;
814 msgdesc.va_queue_last = bcp->va_queue_last;
815 msg = bcp->bau_msg_head;
Cliff Wickman18129242008-06-02 08:56:14 -0500816 while (msg->sw_ack_vector) {
817 count++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500818 msgdesc.msg_slot = msg - msgdesc.va_queue_first;
819 msgdesc.sw_ack_slot = ffs(msg->sw_ack_vector) - 1;
820 msgdesc.msg = msg;
821 uv_bau_process_message(&msgdesc, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500822 msg++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500823 if (msg > msgdesc.va_queue_last)
824 msg = msgdesc.va_queue_first;
825 bcp->bau_msg_head = msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500826 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500827 stat->d_time += (get_cycles() - time_start);
Cliff Wickman18129242008-06-02 08:56:14 -0500828 if (!count)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500829 stat->d_nomsg++;
Cliff Wickman18129242008-06-02 08:56:14 -0500830 else if (count > 1)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500831 stat->d_multmsg++;
832 ack_APIC_irq();
Cliff Wickman18129242008-06-02 08:56:14 -0500833}
834
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500835/*
836 * uv_enable_timeouts
837 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500838 * Each target uvhub (i.e. a uvhub that has no cpu's) needs to have
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500839 * shootdown message timeouts enabled. The timeout does not cause
840 * an interrupt, but causes an error message to be returned to
841 * the sender.
842 */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500843static void uv_enable_timeouts(void)
Cliff Wickman18129242008-06-02 08:56:14 -0500844{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500845 int uvhub;
846 int nuvhubs;
Cliff Wickman18129242008-06-02 08:56:14 -0500847 int pnode;
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500848 unsigned long mmr_image;
Cliff Wickman18129242008-06-02 08:56:14 -0500849
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500850 nuvhubs = uv_num_possible_blades();
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500851
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500852 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
853 if (!uv_blade_nr_possible_cpus(uvhub))
Cliff Wickman18129242008-06-02 08:56:14 -0500854 continue;
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500855
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500856 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500857 mmr_image =
858 uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL);
859 /*
860 * Set the timeout period and then lock it in, in three
861 * steps; captures and locks in the period.
862 *
863 * To program the period, the SOFT_ACK_MODE must be off.
864 */
865 mmr_image &= ~((unsigned long)1 <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600866 UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500867 uv_write_global_mmr64
868 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
869 /*
870 * Set the 4-bit period.
871 */
872 mmr_image &= ~((unsigned long)0xf <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600873 UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500874 mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600875 UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500876 uv_write_global_mmr64
877 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
878 /*
879 * Subsequent reversals of the timebase bit (3) cause an
880 * immediate timeout of one or all INTD resources as
881 * indicated in bits 2:0 (7 causes all of them to timeout).
882 */
883 mmr_image |= ((unsigned long)1 <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600884 UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500885 uv_write_global_mmr64
886 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
Cliff Wickman18129242008-06-02 08:56:14 -0500887 }
Cliff Wickman18129242008-06-02 08:56:14 -0500888}
889
Cliff Wickmanb194b122008-06-12 08:23:48 -0500890static void *uv_ptc_seq_start(struct seq_file *file, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -0500891{
892 if (*offset < num_possible_cpus())
893 return offset;
894 return NULL;
895}
896
Cliff Wickmanb194b122008-06-12 08:23:48 -0500897static void *uv_ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -0500898{
899 (*offset)++;
900 if (*offset < num_possible_cpus())
901 return offset;
902 return NULL;
903}
904
Cliff Wickmanb194b122008-06-12 08:23:48 -0500905static void uv_ptc_seq_stop(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -0500906{
907}
908
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500909static inline unsigned long long
910millisec_2_cycles(unsigned long millisec)
911{
912 unsigned long ns;
913 unsigned long long cyc;
914
915 ns = millisec * 1000;
916 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
917 return cyc;
918}
919
Cliff Wickman18129242008-06-02 08:56:14 -0500920/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500921 * Display the statistics thru /proc.
922 * 'data' points to the cpu number
Cliff Wickman18129242008-06-02 08:56:14 -0500923 */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500924static int uv_ptc_seq_show(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -0500925{
926 struct ptc_stats *stat;
927 int cpu;
928
929 cpu = *(loff_t *)data;
930
931 if (!cpu) {
932 seq_printf(file,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500933 "# cpu sent stime numuvhubs numuvhubs16 numuvhubs8 ");
Cliff Wickman18129242008-06-02 08:56:14 -0500934 seq_printf(file,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500935 "numuvhubs4 numuvhubs2 numuvhubs1 numcpus dto ");
936 seq_printf(file,
937 "retries rok resetp resett giveup sto bz throt ");
938 seq_printf(file,
939 "sw_ack recv rtime all ");
940 seq_printf(file,
941 "one mult none retry canc nocan reset rcan\n");
Cliff Wickman18129242008-06-02 08:56:14 -0500942 }
943 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
944 stat = &per_cpu(ptcstats, cpu);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500945 /* source side statistics */
946 seq_printf(file,
947 "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
948 cpu, stat->s_requestor, cycles_2_us(stat->s_time),
949 stat->s_ntarguvhub, stat->s_ntarguvhub16,
950 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
951 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
952 stat->s_ntargcpu, stat->s_dtimeout);
953 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
954 stat->s_retry_messages, stat->s_retriesok,
955 stat->s_resets_plug, stat->s_resets_timeout,
956 stat->s_giveup, stat->s_stimeout,
957 stat->s_busy, stat->s_throttles);
958 /* destination side statistics */
959 seq_printf(file,
960 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
Cliff Wickman9674f352009-04-03 08:34:05 -0500961 uv_read_global_mmr64(uv_cpu_to_pnode(cpu),
Cliff Wickman18129242008-06-02 08:56:14 -0500962 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500963 stat->d_requestee, cycles_2_us(stat->d_time),
964 stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
965 stat->d_nomsg, stat->d_retries, stat->d_canceled,
966 stat->d_nocanceled, stat->d_resets,
967 stat->d_rcanceled);
Cliff Wickman18129242008-06-02 08:56:14 -0500968 }
969
970 return 0;
971}
972
973/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500974 * -1: resetf the statistics
Cliff Wickman18129242008-06-02 08:56:14 -0500975 * 0: display meaning of the statistics
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500976 * >0: maximum concurrent active descriptors per uvhub (throttle)
Cliff Wickman18129242008-06-02 08:56:14 -0500977 */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500978static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200979 size_t count, loff_t *data)
Cliff Wickman18129242008-06-02 08:56:14 -0500980{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500981 int cpu;
982 long input_arg;
Cliff Wickman18129242008-06-02 08:56:14 -0500983 char optstr[64];
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500984 struct ptc_stats *stat;
985 struct bau_control *bcp;
Cliff Wickman18129242008-06-02 08:56:14 -0500986
Cliff Wickmane7eb8722008-06-23 08:32:25 -0500987 if (count == 0 || count > sizeof(optstr))
Cliff Wickmancef53272008-06-19 11:16:24 -0500988 return -EINVAL;
Cliff Wickman18129242008-06-02 08:56:14 -0500989 if (copy_from_user(optstr, user, count))
990 return -EFAULT;
991 optstr[count - 1] = '\0';
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500992 if (strict_strtol(optstr, 10, &input_arg) < 0) {
Cliff Wickman18129242008-06-02 08:56:14 -0500993 printk(KERN_DEBUG "%s is invalid\n", optstr);
994 return -EINVAL;
995 }
996
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500997 if (input_arg == 0) {
Cliff Wickman18129242008-06-02 08:56:14 -0500998 printk(KERN_DEBUG "# cpu: cpu number\n");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500999 printk(KERN_DEBUG "Sender statistics:\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001000 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001001 "sent: number of shootdown messages sent\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001002 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001003 "stime: time spent sending messages\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001004 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001005 "numuvhubs: number of hubs targeted with shootdown\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001006 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001007 "numuvhubs16: number times 16 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001008 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001009 "numuvhubs8: number times 8 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001010 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001011 "numuvhubs4: number times 4 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001012 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001013 "numuvhubs2: number times 2 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001014 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001015 "numuvhubs1: number times 1 hub targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001016 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001017 "numcpus: number of cpus targeted with shootdown\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001018 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001019 "dto: number of destination timeouts\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001020 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001021 "retries: destination timeout retries sent\n");
1022 printk(KERN_DEBUG
1023 "rok: : destination timeouts successfully retried\n");
1024 printk(KERN_DEBUG
1025 "resetp: ipi-style resource resets for plugs\n");
1026 printk(KERN_DEBUG
1027 "resett: ipi-style resource resets for timeouts\n");
1028 printk(KERN_DEBUG
1029 "giveup: fall-backs to ipi-style shootdowns\n");
1030 printk(KERN_DEBUG
1031 "sto: number of source timeouts\n");
1032 printk(KERN_DEBUG
1033 "bz: number of stay-busy's\n");
1034 printk(KERN_DEBUG
1035 "throt: number times spun in throttle\n");
1036 printk(KERN_DEBUG "Destination side statistics:\n");
1037 printk(KERN_DEBUG
1038 "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
1039 printk(KERN_DEBUG
1040 "recv: shootdown messages received\n");
1041 printk(KERN_DEBUG
1042 "rtime: time spent processing messages\n");
1043 printk(KERN_DEBUG
1044 "all: shootdown all-tlb messages\n");
1045 printk(KERN_DEBUG
1046 "one: shootdown one-tlb messages\n");
1047 printk(KERN_DEBUG
1048 "mult: interrupts that found multiple messages\n");
1049 printk(KERN_DEBUG
1050 "none: interrupts that found no messages\n");
1051 printk(KERN_DEBUG
1052 "retry: number of retry messages processed\n");
1053 printk(KERN_DEBUG
1054 "canc: number messages canceled by retries\n");
1055 printk(KERN_DEBUG
1056 "nocan: number retries that found nothing to cancel\n");
1057 printk(KERN_DEBUG
1058 "reset: number of ipi-style reset requests processed\n");
1059 printk(KERN_DEBUG
1060 "rcan: number messages canceled by reset requests\n");
1061 } else if (input_arg == -1) {
1062 for_each_present_cpu(cpu) {
1063 stat = &per_cpu(ptcstats, cpu);
1064 memset(stat, 0, sizeof(struct ptc_stats));
1065 }
Cliff Wickman18129242008-06-02 08:56:14 -05001066 } else {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001067 uv_bau_max_concurrent = input_arg;
1068 bcp = &per_cpu(bau_control, smp_processor_id());
1069 if (uv_bau_max_concurrent < 1 ||
1070 uv_bau_max_concurrent > bcp->cpus_in_uvhub) {
1071 printk(KERN_DEBUG
1072 "Error: BAU max concurrent %d; %d is invalid\n",
1073 bcp->max_concurrent, uv_bau_max_concurrent);
1074 return -EINVAL;
1075 }
1076 printk(KERN_DEBUG "Set BAU max concurrent:%d\n",
1077 uv_bau_max_concurrent);
1078 for_each_present_cpu(cpu) {
1079 bcp = &per_cpu(bau_control, cpu);
1080 bcp->max_concurrent = uv_bau_max_concurrent;
1081 }
Cliff Wickman18129242008-06-02 08:56:14 -05001082 }
1083
1084 return count;
1085}
1086
1087static const struct seq_operations uv_ptc_seq_ops = {
Ingo Molnardc163a42008-06-18 14:15:43 +02001088 .start = uv_ptc_seq_start,
1089 .next = uv_ptc_seq_next,
1090 .stop = uv_ptc_seq_stop,
1091 .show = uv_ptc_seq_show
Cliff Wickman18129242008-06-02 08:56:14 -05001092};
1093
Cliff Wickmanb194b122008-06-12 08:23:48 -05001094static int uv_ptc_proc_open(struct inode *inode, struct file *file)
Cliff Wickman18129242008-06-02 08:56:14 -05001095{
1096 return seq_open(file, &uv_ptc_seq_ops);
1097}
1098
1099static const struct file_operations proc_uv_ptc_operations = {
Cliff Wickmanb194b122008-06-12 08:23:48 -05001100 .open = uv_ptc_proc_open,
1101 .read = seq_read,
1102 .write = uv_ptc_proc_write,
1103 .llseek = seq_lseek,
1104 .release = seq_release,
Cliff Wickman18129242008-06-02 08:56:14 -05001105};
1106
Cliff Wickmanb194b122008-06-12 08:23:48 -05001107static int __init uv_ptc_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001108{
Cliff Wickmanb194b122008-06-12 08:23:48 -05001109 struct proc_dir_entry *proc_uv_ptc;
Cliff Wickman18129242008-06-02 08:56:14 -05001110
1111 if (!is_uv_system())
1112 return 0;
1113
Alexey Dobriyan10f02d112009-08-23 23:17:27 +04001114 proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
1115 &proc_uv_ptc_operations);
Cliff Wickman18129242008-06-02 08:56:14 -05001116 if (!proc_uv_ptc) {
1117 printk(KERN_ERR "unable to create %s proc entry\n",
1118 UV_PTC_BASENAME);
1119 return -EINVAL;
1120 }
Cliff Wickman18129242008-06-02 08:56:14 -05001121 return 0;
1122}
1123
Cliff Wickmanb194b122008-06-12 08:23:48 -05001124/*
Cliff Wickmanb194b122008-06-12 08:23:48 -05001125 * initialize the sending side's sending buffers
1126 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001127static void
Cliff Wickmanb194b122008-06-12 08:23:48 -05001128uv_activation_descriptor_init(int node, int pnode)
1129{
1130 int i;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001131 int cpu;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001132 unsigned long pa;
1133 unsigned long m;
1134 unsigned long n;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001135 struct bau_desc *bau_desc;
1136 struct bau_desc *bd2;
1137 struct bau_control *bcp;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001138
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001139 /*
1140 * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001141 * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per uvhub
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001142 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001143 bau_desc = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)*
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001144 UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001145 BUG_ON(!bau_desc);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001146
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001147 pa = uv_gpa(bau_desc); /* need the real nasid*/
1148 n = pa >> uv_nshift;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001149 m = pa & uv_mmask;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001150
Cliff Wickman9c26f522009-06-24 09:41:59 -05001151 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE,
1152 (n << UV_DESC_BASE_PNODE_SHIFT | m));
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001153
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001154 /*
1155 * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each
1156 * cpu even though we only use the first one; one descriptor can
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001157 * describe a broadcast to 256 uv hubs.
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001158 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001159 for (i = 0, bd2 = bau_desc; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR);
1160 i++, bd2++) {
1161 memset(bd2, 0, sizeof(struct bau_desc));
1162 bd2->header.sw_ack_flag = 1;
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001163 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001164 * base_dest_nodeid is the nasid (pnode<<1) of the first uvhub
1165 * in the partition. The bit map will indicate uvhub numbers,
1166 * which are 0-N in a partition. Pnodes are unique system-wide.
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001167 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001168 bd2->header.base_dest_nodeid = uv_partition_base_pnode << 1;
1169 bd2->header.dest_subnodeid = 0x10; /* the LB */
1170 bd2->header.command = UV_NET_ENDPOINT_INTD;
1171 bd2->header.int_both = 1;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001172 /*
1173 * all others need to be set to zero:
1174 * fairness chaining multilevel count replied_to
1175 */
1176 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001177 for_each_present_cpu(cpu) {
1178 if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
1179 continue;
1180 bcp = &per_cpu(bau_control, cpu);
1181 bcp->descriptor_base = bau_desc;
1182 }
Cliff Wickmanb194b122008-06-12 08:23:48 -05001183}
1184
1185/*
1186 * initialize the destination side's receiving buffers
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001187 * entered for each uvhub in the partition
1188 * - node is first node (kernel memory notion) on the uvhub
1189 * - pnode is the uvhub's physical identifier
Cliff Wickmanb194b122008-06-12 08:23:48 -05001190 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001191static void
1192uv_payload_queue_init(int node, int pnode)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001193{
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001194 int pn;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001195 int cpu;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001196 char *cp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001197 unsigned long pa;
1198 struct bau_payload_queue_entry *pqp;
1199 struct bau_payload_queue_entry *pqp_malloc;
1200 struct bau_control *bcp;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001201
Ingo Molnardc163a42008-06-18 14:15:43 +02001202 pqp = (struct bau_payload_queue_entry *) kmalloc_node(
1203 (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry),
1204 GFP_KERNEL, node);
1205 BUG_ON(!pqp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001206 pqp_malloc = pqp;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001207
Cliff Wickmanb194b122008-06-12 08:23:48 -05001208 cp = (char *)pqp + 31;
1209 pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001210
1211 for_each_present_cpu(cpu) {
1212 if (pnode != uv_cpu_to_pnode(cpu))
1213 continue;
1214 /* for every cpu on this pnode: */
1215 bcp = &per_cpu(bau_control, cpu);
1216 bcp->va_queue_first = pqp;
1217 bcp->bau_msg_head = pqp;
1218 bcp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
1219 }
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001220 /*
1221 * need the pnode of where the memory was really allocated
1222 */
1223 pa = uv_gpa(pqp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001224 pn = pa >> uv_nshift;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001225 uv_write_global_mmr64(pnode,
1226 UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001227 ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) |
Cliff Wickmanb194b122008-06-12 08:23:48 -05001228 uv_physnodeaddr(pqp));
1229 uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
1230 uv_physnodeaddr(pqp));
Cliff Wickmanb194b122008-06-12 08:23:48 -05001231 uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
1232 (unsigned long)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001233 uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1)));
1234 /* in effect, all msg_type's are set to MSG_NOOP */
Ingo Molnardc163a42008-06-18 14:15:43 +02001235 memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001236}
1237
1238/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001239 * Initialization of each UV hub's structures
Cliff Wickmanb194b122008-06-12 08:23:48 -05001240 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001241static void __init uv_init_uvhub(int uvhub, int vector)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001242{
Cliff Wickman9674f352009-04-03 08:34:05 -05001243 int node;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001244 int pnode;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001245 unsigned long apicid;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001246
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001247 node = uvhub_to_first_node(uvhub);
1248 pnode = uv_blade_to_pnode(uvhub);
1249 uv_activation_descriptor_init(node, pnode);
1250 uv_payload_queue_init(node, pnode);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001251 /*
1252 * the below initialization can't be in firmware because the
1253 * messaging IRQ will be determined by the OS
1254 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001255 apicid = uvhub_to_first_apicid(uvhub);
Cliff Wickmane38e2af2009-11-19 17:12:43 -06001256 uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001257 ((apicid << 32) | vector));
1258}
1259
1260/*
1261 * initialize the bau_control structure for each cpu
1262 */
1263static void uv_init_per_cpu(int nuvhubs)
1264{
1265 int i, j, k;
1266 int cpu;
1267 int pnode;
1268 int uvhub;
1269 short socket = 0;
1270 struct bau_control *bcp;
1271 struct uvhub_desc *bdp;
1272 struct socket_desc *sdp;
1273 struct bau_control *hmaster = NULL;
1274 struct bau_control *smaster = NULL;
1275 struct socket_desc {
1276 short num_cpus;
1277 short cpu_number[16];
1278 };
1279 struct uvhub_desc {
1280 short num_sockets;
1281 short num_cpus;
1282 short uvhub;
1283 short pnode;
1284 struct socket_desc socket[2];
1285 };
1286 struct uvhub_desc *uvhub_descs;
1287
1288 uvhub_descs = (struct uvhub_desc *)
1289 kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1290 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
1291 for_each_present_cpu(cpu) {
1292 bcp = &per_cpu(bau_control, cpu);
1293 memset(bcp, 0, sizeof(struct bau_control));
1294 spin_lock_init(&bcp->masks_lock);
1295 bcp->max_concurrent = uv_bau_max_concurrent;
1296 pnode = uv_cpu_hub_info(cpu)->pnode;
1297 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
1298 bdp = &uvhub_descs[uvhub];
1299 bdp->num_cpus++;
1300 bdp->uvhub = uvhub;
1301 bdp->pnode = pnode;
1302 /* time interval to catch a hardware stay-busy bug */
1303 bcp->timeout_interval = millisec_2_cycles(3);
1304 /* kludge: assume uv_hub.h is constant */
1305 socket = (cpu_physical_id(cpu)>>5)&1;
1306 if (socket >= bdp->num_sockets)
1307 bdp->num_sockets = socket+1;
1308 sdp = &bdp->socket[socket];
1309 sdp->cpu_number[sdp->num_cpus] = cpu;
1310 sdp->num_cpus++;
1311 }
1312 socket = 0;
1313 for_each_possible_blade(uvhub) {
1314 bdp = &uvhub_descs[uvhub];
1315 for (i = 0; i < bdp->num_sockets; i++) {
1316 sdp = &bdp->socket[i];
1317 for (j = 0; j < sdp->num_cpus; j++) {
1318 cpu = sdp->cpu_number[j];
1319 bcp = &per_cpu(bau_control, cpu);
1320 bcp->cpu = cpu;
1321 if (j == 0) {
1322 smaster = bcp;
1323 if (i == 0)
1324 hmaster = bcp;
1325 }
1326 bcp->cpus_in_uvhub = bdp->num_cpus;
1327 bcp->cpus_in_socket = sdp->num_cpus;
1328 bcp->socket_master = smaster;
1329 bcp->uvhub_master = hmaster;
1330 for (k = 0; k < DEST_Q_SIZE; k++)
1331 bcp->socket_acknowledge_count[k] = 0;
1332 bcp->uvhub_cpu =
1333 uv_cpu_hub_info(cpu)->blade_processor_id;
1334 }
1335 socket++;
1336 }
1337 }
1338 kfree(uvhub_descs);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001339}
Cliff Wickman18129242008-06-02 08:56:14 -05001340
1341/*
1342 * Initialization of BAU-related structures
1343 */
Cliff Wickmanb194b122008-06-12 08:23:48 -05001344static int __init uv_bau_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001345{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001346 int uvhub;
1347 int pnode;
1348 int nuvhubs;
Rusty Russell2c74d662009-03-18 08:22:30 +10301349 int cur_cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001350 int vector;
1351 unsigned long mmr;
Cliff Wickman18129242008-06-02 08:56:14 -05001352
1353 if (!is_uv_system())
1354 return 0;
1355
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001356 if (nobau)
1357 return 0;
1358
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301359 for_each_possible_cpu(cur_cpu)
Yinghai Lueaa958402009-06-06 14:51:36 -07001360 zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu),
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301361 GFP_KERNEL, cpu_to_node(cur_cpu));
1362
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001363 uv_bau_max_concurrent = MAX_BAU_CONCURRENT;
1364 uv_nshift = uv_hub_info->m_val;
Robin Holt036ed8b2009-10-15 17:40:00 -05001365 uv_mmask = (1UL << uv_hub_info->m_val) - 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001366 nuvhubs = uv_num_possible_blades();
Cliff Wickman9674f352009-04-03 08:34:05 -05001367
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001368 uv_init_per_cpu(nuvhubs);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001369
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001370 uv_partition_base_pnode = 0x7fffffff;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001371 for (uvhub = 0; uvhub < nuvhubs; uvhub++)
1372 if (uv_blade_nr_possible_cpus(uvhub) &&
1373 (uv_blade_to_pnode(uvhub) < uv_partition_base_pnode))
1374 uv_partition_base_pnode = uv_blade_to_pnode(uvhub);
Cliff Wickman9674f352009-04-03 08:34:05 -05001375
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001376 vector = UV_BAU_MESSAGE;
1377 for_each_possible_blade(uvhub)
1378 if (uv_blade_nr_possible_cpus(uvhub))
1379 uv_init_uvhub(uvhub, vector);
1380
Cliff Wickman18129242008-06-02 08:56:14 -05001381 uv_enable_timeouts();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001382 alloc_intr_gate(vector, uv_bau_message_intr1);
1383
1384 for_each_possible_blade(uvhub) {
1385 pnode = uv_blade_to_pnode(uvhub);
1386 /* INIT the bau */
1387 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL,
1388 ((unsigned long)1 << 63));
1389 mmr = 1; /* should be 1 to broadcast to both sockets */
1390 uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST, mmr);
1391 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001392
Cliff Wickman18129242008-06-02 08:56:14 -05001393 return 0;
1394}
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001395core_initcall(uv_bau_init);
1396core_initcall(uv_ptc_init);