blob: c8661779c51e638bf66a2cd254ae8f690ab8b3f7 [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>
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050011#include <linux/debugfs.h>
Cliff Wickman18129242008-06-02 08:56:14 -050012#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Cliff Wickman18129242008-06-02 08:56:14 -050014
Cliff Wickman18129242008-06-02 08:56:14 -050015#include <asm/mmu_context.h>
Tejun Heobdbcdd42009-01-21 17:26:06 +090016#include <asm/uv/uv.h>
Cliff Wickman18129242008-06-02 08:56:14 -050017#include <asm/uv/uv_mmrs.h>
Ingo Molnarb4c286e2008-06-18 14:28:19 +020018#include <asm/uv/uv_hub.h>
Cliff Wickman18129242008-06-02 08:56:14 -050019#include <asm/uv/uv_bau.h>
Ingo Molnar7b6aa332009-02-17 13:58:15 +010020#include <asm/apic.h>
Ingo Molnarb4c286e2008-06-18 14:28:19 +020021#include <asm/idle.h>
Cliff Wickmanb194b122008-06-12 08:23:48 -050022#include <asm/tsc.h>
Cliff Wickman99dd8712008-08-19 12:51:59 -050023#include <asm/irq_vectors.h>
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050024#include <asm/timer.h>
Cliff Wickman18129242008-06-02 08:56:14 -050025
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050026struct msg_desc {
27 struct bau_payload_queue_entry *msg;
28 int msg_slot;
29 int sw_ack_slot;
30 struct bau_payload_queue_entry *va_queue_first;
31 struct bau_payload_queue_entry *va_queue_last;
32};
Cliff Wickman18129242008-06-02 08:56:14 -050033
Cliff Wickman12a66112010-06-02 16:22:01 -050034/* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
35static int timeout_base_ns[] = {
36 20,
37 160,
38 1280,
39 10240,
40 81920,
41 655360,
42 5242880,
43 167772160
44};
45static int timeout_us;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050046static int nobau;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050047
48/* tunables: */
49static int max_bau_concurrent = MAX_BAU_CONCURRENT;
50static int max_bau_concurrent_constant = MAX_BAU_CONCURRENT;
51static int plugged_delay = PLUGGED_DELAY;
52static int plugsb4reset = PLUGSB4RESET;
53static int timeoutsb4reset = TIMEOUTSB4RESET;
54static int ipi_reset_limit = IPI_RESET_LIMIT;
55static int complete_threshold = COMPLETE_THRESHOLD;
56static int congested_response_us = CONGESTED_RESPONSE_US;
57static int congested_reps = CONGESTED_REPS;
58static int congested_period = CONGESTED_PERIOD;
59static struct dentry *tunables_dir;
60static struct dentry *tunables_file;
61
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050062static int __init setup_nobau(char *arg)
63{
64 nobau = 1;
65 return 0;
66}
67early_param("nobau", setup_nobau);
Ingo Molnarb4c286e2008-06-18 14:28:19 +020068
Cliff Wickman94ca8e42009-04-14 10:56:48 -050069/* base pnode in this partition */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050070static int uv_partition_base_pnode __read_mostly;
71/* position of pnode (which is nasid>>1): */
72static int uv_nshift __read_mostly;
73static unsigned long uv_mmask __read_mostly;
Cliff Wickman18129242008-06-02 08:56:14 -050074
Ingo Molnardc163a42008-06-18 14:15:43 +020075static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
76static DEFINE_PER_CPU(struct bau_control, bau_control);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050077static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
78
79struct reset_args {
80 int sender;
81};
Cliff Wickman18129242008-06-02 08:56:14 -050082
83/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050084 * Determine the first node on a uvhub. 'Nodes' are used for kernel
85 * memory allocation.
Cliff Wickman9674f352009-04-03 08:34:05 -050086 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050087static int __init uvhub_to_first_node(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -050088{
89 int node, b;
90
91 for_each_online_node(node) {
92 b = uv_node_to_blade_id(node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050093 if (uvhub == b)
Cliff Wickman9674f352009-04-03 08:34:05 -050094 return node;
95 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050096 return -1;
Cliff Wickman9674f352009-04-03 08:34:05 -050097}
98
99/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500100 * Determine the apicid of the first cpu on a uvhub.
Cliff Wickman9674f352009-04-03 08:34:05 -0500101 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500102static int __init uvhub_to_first_apicid(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -0500103{
104 int cpu;
105
106 for_each_present_cpu(cpu)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500107 if (uvhub == uv_cpu_to_blade_id(cpu))
Cliff Wickman9674f352009-04-03 08:34:05 -0500108 return per_cpu(x86_cpu_to_apicid, cpu);
109 return -1;
110}
111
112/*
Cliff Wickman18129242008-06-02 08:56:14 -0500113 * Free a software acknowledge hardware resource by clearing its Pending
114 * bit. This will return a reply to the sender.
115 * If the message has timed out, a reply has already been sent by the
116 * hardware but the resource has not been released. In that case our
117 * clear of the Timeout bit (as well) will free the resource. No reply will
118 * be sent (the hardware will only do one reply per message).
119 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500120static inline void uv_reply_to_message(struct msg_desc *mdp,
121 struct bau_control *bcp)
Cliff Wickman18129242008-06-02 08:56:14 -0500122{
Cliff Wickmanb194b122008-06-12 08:23:48 -0500123 unsigned long dw;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500124 struct bau_payload_queue_entry *msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500125
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500126 msg = mdp->msg;
127 if (!msg->canceled) {
128 dw = (msg->sw_ack_vector << UV_SW_ACK_NPENDING) |
129 msg->sw_ack_vector;
130 uv_write_local_mmr(
131 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw);
132 }
Cliff Wickman18129242008-06-02 08:56:14 -0500133 msg->replied_to = 1;
134 msg->sw_ack_vector = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500135}
136
137/*
138 * Process the receipt of a RETRY message
139 */
140static inline void uv_bau_process_retry_msg(struct msg_desc *mdp,
141 struct bau_control *bcp)
142{
143 int i;
144 int cancel_count = 0;
145 int slot2;
146 unsigned long msg_res;
147 unsigned long mmr = 0;
148 struct bau_payload_queue_entry *msg;
149 struct bau_payload_queue_entry *msg2;
150 struct ptc_stats *stat;
151
152 msg = mdp->msg;
153 stat = &per_cpu(ptcstats, bcp->cpu);
154 stat->d_retries++;
155 /*
156 * cancel any message from msg+1 to the retry itself
157 */
158 for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
159 if (msg2 > mdp->va_queue_last)
160 msg2 = mdp->va_queue_first;
161 if (msg2 == msg)
162 break;
163
164 /* same conditions for cancellation as uv_do_reset */
165 if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
166 (msg2->sw_ack_vector) && ((msg2->sw_ack_vector &
167 msg->sw_ack_vector) == 0) &&
168 (msg2->sending_cpu == msg->sending_cpu) &&
169 (msg2->msg_type != MSG_NOOP)) {
170 slot2 = msg2 - mdp->va_queue_first;
171 mmr = uv_read_local_mmr
172 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
173 msg_res = ((msg2->sw_ack_vector << 8) |
174 msg2->sw_ack_vector);
175 /*
176 * This is a message retry; clear the resources held
177 * by the previous message only if they timed out.
178 * If it has not timed out we have an unexpected
179 * situation to report.
180 */
181 if (mmr & (msg_res << 8)) {
182 /*
183 * is the resource timed out?
184 * make everyone ignore the cancelled message.
185 */
186 msg2->canceled = 1;
187 stat->d_canceled++;
188 cancel_count++;
189 uv_write_local_mmr(
190 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
191 (msg_res << 8) | msg_res);
192 } else
193 printk(KERN_INFO "note bau retry: no effect\n");
194 }
195 }
196 if (!cancel_count)
197 stat->d_nocanceled++;
Cliff Wickman18129242008-06-02 08:56:14 -0500198}
199
200/*
201 * Do all the things a cpu should do for a TLB shootdown message.
202 * Other cpu's may come here at the same time for this message.
203 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500204static void uv_bau_process_message(struct msg_desc *mdp,
205 struct bau_control *bcp)
Cliff Wickman18129242008-06-02 08:56:14 -0500206{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500207 int msg_ack_count;
208 short socket_ack_count = 0;
209 struct ptc_stats *stat;
210 struct bau_payload_queue_entry *msg;
211 struct bau_control *smaster = bcp->socket_master;
Cliff Wickman18129242008-06-02 08:56:14 -0500212
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500213 /*
214 * This must be a normal message, or retry of a normal message
215 */
216 msg = mdp->msg;
217 stat = &per_cpu(ptcstats, bcp->cpu);
Cliff Wickman18129242008-06-02 08:56:14 -0500218 if (msg->address == TLB_FLUSH_ALL) {
219 local_flush_tlb();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500220 stat->d_alltlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500221 } else {
222 __flush_tlb_one(msg->address);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500223 stat->d_onetlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500224 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500225 stat->d_requestee++;
Cliff Wickman18129242008-06-02 08:56:14 -0500226
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500227 /*
228 * One cpu on each uvhub has the additional job on a RETRY
229 * of releasing the resource held by the message that is
230 * being retried. That message is identified by sending
231 * cpu number.
232 */
233 if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
234 uv_bau_process_retry_msg(mdp, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500235
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500236 /*
237 * This is a sw_ack message, so we have to reply to it.
238 * Count each responding cpu on the socket. This avoids
239 * pinging the count's cache line back and forth between
240 * the sockets.
241 */
242 socket_ack_count = atomic_add_short_return(1, (struct atomic_short *)
243 &smaster->socket_acknowledge_count[mdp->msg_slot]);
244 if (socket_ack_count == bcp->cpus_in_socket) {
245 /*
246 * Both sockets dump their completed count total into
247 * the message's count.
248 */
249 smaster->socket_acknowledge_count[mdp->msg_slot] = 0;
250 msg_ack_count = atomic_add_short_return(socket_ack_count,
251 (struct atomic_short *)&msg->acknowledge_count);
Ingo Molnardc163a42008-06-18 14:15:43 +0200252
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500253 if (msg_ack_count == bcp->cpus_in_uvhub) {
254 /*
255 * All cpus in uvhub saw it; reply
256 */
257 uv_reply_to_message(mdp, bcp);
Ingo Molnardc163a42008-06-18 14:15:43 +0200258 }
259 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500260
261 return;
Cliff Wickman18129242008-06-02 08:56:14 -0500262}
263
264/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500265 * Determine the first cpu on a uvhub.
Cliff Wickman18129242008-06-02 08:56:14 -0500266 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500267static int uvhub_to_first_cpu(int uvhub)
Cliff Wickman18129242008-06-02 08:56:14 -0500268{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500269 int cpu;
270 for_each_present_cpu(cpu)
271 if (uvhub == uv_cpu_to_blade_id(cpu))
272 return cpu;
273 return -1;
Cliff Wickman18129242008-06-02 08:56:14 -0500274}
275
Cliff Wickmanb194b122008-06-12 08:23:48 -0500276/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500277 * Last resort when we get a large number of destination timeouts is
278 * to clear resources held by a given cpu.
279 * Do this with IPI so that all messages in the BAU message queue
280 * can be identified by their nonzero sw_ack_vector field.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500281 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500282 * This is entered for a single cpu on the uvhub.
283 * The sender want's this uvhub to free a specific message's
284 * sw_ack resources.
285 */
286static void
287uv_do_reset(void *ptr)
288{
289 int i;
290 int slot;
291 int count = 0;
292 unsigned long mmr;
293 unsigned long msg_res;
294 struct bau_control *bcp;
295 struct reset_args *rap;
296 struct bau_payload_queue_entry *msg;
297 struct ptc_stats *stat;
298
299 bcp = &per_cpu(bau_control, smp_processor_id());
300 rap = (struct reset_args *)ptr;
301 stat = &per_cpu(ptcstats, bcp->cpu);
302 stat->d_resets++;
303
304 /*
305 * We're looking for the given sender, and
306 * will free its sw_ack resource.
307 * If all cpu's finally responded after the timeout, its
308 * message 'replied_to' was set.
309 */
310 for (msg = bcp->va_queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
311 /* uv_do_reset: same conditions for cancellation as
312 uv_bau_process_retry_msg() */
313 if ((msg->replied_to == 0) &&
314 (msg->canceled == 0) &&
315 (msg->sending_cpu == rap->sender) &&
316 (msg->sw_ack_vector) &&
317 (msg->msg_type != MSG_NOOP)) {
318 /*
319 * make everyone else ignore this message
320 */
321 msg->canceled = 1;
322 slot = msg - bcp->va_queue_first;
323 count++;
324 /*
325 * only reset the resource if it is still pending
326 */
327 mmr = uv_read_local_mmr
328 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
329 msg_res = ((msg->sw_ack_vector << 8) |
330 msg->sw_ack_vector);
331 if (mmr & msg_res) {
332 stat->d_rcanceled++;
333 uv_write_local_mmr(
334 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
335 msg_res);
336 }
337 }
338 }
339 return;
340}
341
342/*
343 * Use IPI to get all target uvhubs to release resources held by
344 * a given sending cpu number.
345 */
346static void uv_reset_with_ipi(struct bau_target_uvhubmask *distribution,
347 int sender)
348{
349 int uvhub;
350 int cpu;
351 cpumask_t mask;
352 struct reset_args reset_args;
353
354 reset_args.sender = sender;
355
356 cpus_clear(mask);
357 /* find a single cpu for each uvhub in this distribution mask */
358 for (uvhub = 0;
359 uvhub < sizeof(struct bau_target_uvhubmask) * BITSPERBYTE;
360 uvhub++) {
361 if (!bau_uvhub_isset(uvhub, distribution))
362 continue;
363 /* find a cpu for this uvhub */
364 cpu = uvhub_to_first_cpu(uvhub);
365 cpu_set(cpu, mask);
366 }
367 /* IPI all cpus; Preemption is already disabled */
368 smp_call_function_many(&mask, uv_do_reset, (void *)&reset_args, 1);
369 return;
370}
371
372static inline unsigned long
373cycles_2_us(unsigned long long cyc)
374{
375 unsigned long long ns;
376 unsigned long us;
377 ns = (cyc * per_cpu(cyc2ns, smp_processor_id()))
378 >> CYC2NS_SCALE_FACTOR;
379 us = ns / 1000;
380 return us;
381}
382
383/*
384 * wait for all cpus on this hub to finish their sends and go quiet
385 * leaves uvhub_quiesce set so that no new broadcasts are started by
386 * bau_flush_send_and_wait()
387 */
388static inline void
389quiesce_local_uvhub(struct bau_control *hmaster)
390{
391 atomic_add_short_return(1, (struct atomic_short *)
392 &hmaster->uvhub_quiesce);
393}
394
395/*
396 * mark this quiet-requestor as done
397 */
398static inline void
399end_uvhub_quiesce(struct bau_control *hmaster)
400{
401 atomic_add_short_return(-1, (struct atomic_short *)
402 &hmaster->uvhub_quiesce);
403}
404
405/*
406 * Wait for completion of a broadcast software ack message
407 * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
Cliff Wickmanb194b122008-06-12 08:23:48 -0500408 */
Ingo Molnardc163a42008-06-18 14:15:43 +0200409static int uv_wait_completion(struct bau_desc *bau_desc,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500410 unsigned long mmr_offset, int right_shift, int this_cpu,
411 struct bau_control *bcp, struct bau_control *smaster, long try)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500412{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500413 int relaxes = 0;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500414 unsigned long descriptor_status;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500415 unsigned long mmr;
416 unsigned long mask;
417 cycles_t ttime;
418 cycles_t timeout_time;
419 struct ptc_stats *stat = &per_cpu(ptcstats, this_cpu);
420 struct bau_control *hmaster;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500421
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500422 hmaster = bcp->uvhub_master;
423 timeout_time = get_cycles() + bcp->timeout_interval;
424
425 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500426 while ((descriptor_status = (((unsigned long)
427 uv_read_local_mmr(mmr_offset) >>
428 right_shift) & UV_ACT_STATUS_MASK)) !=
429 DESC_STATUS_IDLE) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500430 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500431 * Our software ack messages may be blocked because there are
432 * no swack resources available. As long as none of them
433 * has timed out hardware will NACK our message and its
434 * state will stay IDLE.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500435 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500436 if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
437 stat->s_stimeout++;
438 return FLUSH_GIVEUP;
439 } else if (descriptor_status ==
440 DESC_STATUS_DESTINATION_TIMEOUT) {
441 stat->s_dtimeout++;
442 ttime = get_cycles();
443
444 /*
445 * Our retries may be blocked by all destination
446 * swack resources being consumed, and a timeout
447 * pending. In that case hardware returns the
448 * ERROR that looks like a destination timeout.
449 */
Cliff Wickman12a66112010-06-02 16:22:01 -0500450 if (cycles_2_us(ttime - bcp->send_message) <
451 timeout_us) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500452 bcp->conseccompletes = 0;
453 return FLUSH_RETRY_PLUGGED;
454 }
455
456 bcp->conseccompletes = 0;
457 return FLUSH_RETRY_TIMEOUT;
458 } else {
459 /*
460 * descriptor_status is still BUSY
461 */
462 cpu_relax();
463 relaxes++;
464 if (relaxes >= 10000) {
465 relaxes = 0;
466 if (get_cycles() > timeout_time) {
467 quiesce_local_uvhub(hmaster);
468
469 /* single-thread the register change */
470 spin_lock(&hmaster->masks_lock);
471 mmr = uv_read_local_mmr(mmr_offset);
472 mask = 0UL;
473 mask |= (3UL < right_shift);
474 mask = ~mask;
475 mmr &= mask;
476 uv_write_local_mmr(mmr_offset, mmr);
477 spin_unlock(&hmaster->masks_lock);
478 end_uvhub_quiesce(hmaster);
479 stat->s_busy++;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500480 return FLUSH_GIVEUP;
481 }
Cliff Wickmanb194b122008-06-12 08:23:48 -0500482 }
483 }
484 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500485 bcp->conseccompletes++;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500486 return FLUSH_COMPLETE;
487}
488
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500489static inline cycles_t
490sec_2_cycles(unsigned long sec)
491{
492 unsigned long ns;
493 cycles_t cyc;
494
495 ns = sec * 1000000000;
496 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
497 return cyc;
498}
499
500/*
501 * conditionally add 1 to *v, unless *v is >= u
502 * return 0 if we cannot add 1 to *v because it is >= u
503 * return 1 if we can add 1 to *v because it is < u
504 * the add is atomic
505 *
506 * This is close to atomic_add_unless(), but this allows the 'u' value
507 * to be lowered below the current 'v'. atomic_add_unless can only stop
508 * on equal.
509 */
510static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
511{
512 spin_lock(lock);
513 if (atomic_read(v) >= u) {
514 spin_unlock(lock);
515 return 0;
516 }
517 atomic_inc(v);
518 spin_unlock(lock);
519 return 1;
520}
521
Cliff Wickmanb194b122008-06-12 08:23:48 -0500522/**
523 * uv_flush_send_and_wait
524 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500525 * Send a broadcast and wait for it to complete.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500526 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500527 * The flush_mask contains the cpus the broadcast is to be sent to, plus
528 * cpus that are on the local uvhub.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500529 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500530 * Returns NULL if all flushing represented in the mask was done. The mask
531 * is zeroed.
Tejun Heobdbcdd42009-01-21 17:26:06 +0900532 * Returns @flush_mask if some remote flushing remains to be done. The
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500533 * mask will have some bits still set, representing any cpus on the local
534 * uvhub (not current cpu) and any on remote uvhubs if the broadcast failed.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500535 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500536const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc,
537 struct cpumask *flush_mask,
538 struct bau_control *bcp)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500539{
Cliff Wickmanb194b122008-06-12 08:23:48 -0500540 int right_shift;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500541 int uvhub;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200542 int bit;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500543 int completion_status = 0;
544 int seq_number = 0;
545 long try = 0;
546 int cpu = bcp->uvhub_cpu;
547 int this_cpu = bcp->cpu;
548 int this_uvhub = bcp->uvhub;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500549 unsigned long mmr_offset;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200550 unsigned long index;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500551 cycles_t time1;
552 cycles_t time2;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500553 cycles_t elapsed;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500554 struct ptc_stats *stat = &per_cpu(ptcstats, bcp->cpu);
555 struct bau_control *smaster = bcp->socket_master;
556 struct bau_control *hmaster = bcp->uvhub_master;
557
558 /*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500559 * Spin here while there are hmaster->max_bau_concurrent or more active
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500560 * descriptors. This is the per-uvhub 'throttle'.
561 */
562 if (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
563 &hmaster->active_descriptor_count,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500564 hmaster->max_bau_concurrent)) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500565 stat->s_throttles++;
566 do {
567 cpu_relax();
568 } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
569 &hmaster->active_descriptor_count,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500570 hmaster->max_bau_concurrent));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500571 }
572
573 while (hmaster->uvhub_quiesce)
574 cpu_relax();
Cliff Wickmanb194b122008-06-12 08:23:48 -0500575
576 if (cpu < UV_CPUS_PER_ACT_STATUS) {
577 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
578 right_shift = cpu * UV_ACT_STATUS_SIZE;
579 } else {
580 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
581 right_shift =
582 ((cpu - UV_CPUS_PER_ACT_STATUS) * UV_ACT_STATUS_SIZE);
583 }
584 time1 = get_cycles();
585 do {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500586 /*
587 * Every message from any given cpu gets a unique message
588 * sequence number. But retries use that same number.
589 * Our message may have timed out at the destination because
590 * all sw-ack resources are in use and there is a timeout
591 * pending there. In that case, our last send never got
592 * placed into the queue and we need to persist until it
593 * does.
594 *
595 * Make any retry a type MSG_RETRY so that the destination will
596 * free any resource held by a previous message from this cpu.
597 */
598 if (try == 0) {
599 /* use message type set by the caller the first time */
600 seq_number = bcp->message_number++;
601 } else {
602 /* use RETRY type on all the rest; same sequence */
603 bau_desc->header.msg_type = MSG_RETRY;
604 stat->s_retry_messages++;
605 }
606 bau_desc->header.sequence = seq_number;
Ingo Molnardc163a42008-06-18 14:15:43 +0200607 index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) |
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500608 bcp->uvhub_cpu;
609 bcp->send_message = get_cycles();
Cliff Wickmanb194b122008-06-12 08:23:48 -0500610
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500611 uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
612
613 try++;
614 completion_status = uv_wait_completion(bau_desc, mmr_offset,
615 right_shift, this_cpu, bcp, smaster, try);
616
617 if (completion_status == FLUSH_RETRY_PLUGGED) {
618 /*
619 * Our retries may be blocked by all destination swack
620 * resources being consumed, and a timeout pending. In
621 * that case hardware immediately returns the ERROR
622 * that looks like a destination timeout.
623 */
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500624 udelay(bcp->plugged_delay);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500625 bcp->plugged_tries++;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500626 if (bcp->plugged_tries >= bcp->plugsb4reset) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500627 bcp->plugged_tries = 0;
628 quiesce_local_uvhub(hmaster);
629 spin_lock(&hmaster->queue_lock);
630 uv_reset_with_ipi(&bau_desc->distribution,
631 this_cpu);
632 spin_unlock(&hmaster->queue_lock);
633 end_uvhub_quiesce(hmaster);
634 bcp->ipi_attempts++;
635 stat->s_resets_plug++;
636 }
637 } else if (completion_status == FLUSH_RETRY_TIMEOUT) {
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500638 hmaster->max_bau_concurrent = 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500639 bcp->timeout_tries++;
640 udelay(TIMEOUT_DELAY);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500641 if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500642 bcp->timeout_tries = 0;
643 quiesce_local_uvhub(hmaster);
644 spin_lock(&hmaster->queue_lock);
645 uv_reset_with_ipi(&bau_desc->distribution,
646 this_cpu);
647 spin_unlock(&hmaster->queue_lock);
648 end_uvhub_quiesce(hmaster);
649 bcp->ipi_attempts++;
650 stat->s_resets_timeout++;
651 }
652 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500653 if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500654 bcp->ipi_attempts = 0;
655 completion_status = FLUSH_GIVEUP;
656 break;
657 }
658 cpu_relax();
659 } while ((completion_status == FLUSH_RETRY_PLUGGED) ||
660 (completion_status == FLUSH_RETRY_TIMEOUT));
661 time2 = get_cycles();
662
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500663 bcp->plugged_tries = 0;
664 bcp->timeout_tries = 0;
665
666 if ((completion_status == FLUSH_COMPLETE) &&
667 (bcp->conseccompletes > bcp->complete_threshold) &&
668 (hmaster->max_bau_concurrent <
669 hmaster->max_bau_concurrent_constant))
670 hmaster->max_bau_concurrent++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500671
672 /*
673 * hold any cpu not timing out here; no other cpu currently held by
674 * the 'throttle' should enter the activation code
675 */
676 while (hmaster->uvhub_quiesce)
677 cpu_relax();
678 atomic_dec(&hmaster->active_descriptor_count);
679
680 /* guard against cycles wrap */
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500681 if (time2 > time1) {
682 elapsed = time2 - time1;
683 stat->s_time += elapsed;
684 } else
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500685 stat->s_requestor--; /* don't count this one */
686 if (completion_status == FLUSH_COMPLETE && try > 1)
687 stat->s_retriesok++;
688 else if (completion_status == FLUSH_GIVEUP) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500689 /*
690 * Cause the caller to do an IPI-style TLB shootdown on
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500691 * the target cpu's, all of which are still in the mask.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500692 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500693 stat->s_giveup++;
Cliff Wickman2749ebe2009-01-29 15:35:26 -0600694 return flush_mask;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500695 }
696
697 /*
698 * Success, so clear the remote cpu's from the mask so we don't
699 * use the IPI method of shootdown on them.
700 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900701 for_each_cpu(bit, flush_mask) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500702 uvhub = uv_cpu_to_blade_id(bit);
703 if (uvhub == this_uvhub)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500704 continue;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900705 cpumask_clear_cpu(bit, flush_mask);
Cliff Wickmanb194b122008-06-12 08:23:48 -0500706 }
Tejun Heobdbcdd42009-01-21 17:26:06 +0900707 if (!cpumask_empty(flush_mask))
708 return flush_mask;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500709
Tejun Heobdbcdd42009-01-21 17:26:06 +0900710 return NULL;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500711}
712
Cliff Wickman18129242008-06-02 08:56:14 -0500713/**
714 * uv_flush_tlb_others - globally purge translation cache of a virtual
715 * address or all TLB's
Tejun Heobdbcdd42009-01-21 17:26:06 +0900716 * @cpumask: mask of all cpu's in which the address is to be removed
Cliff Wickman18129242008-06-02 08:56:14 -0500717 * @mm: mm_struct containing virtual address range
718 * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
Tejun Heobdbcdd42009-01-21 17:26:06 +0900719 * @cpu: the current cpu
Cliff Wickman18129242008-06-02 08:56:14 -0500720 *
721 * This is the entry point for initiating any UV global TLB shootdown.
722 *
723 * Purges the translation caches of all specified processors of the given
724 * virtual address, or purges all TLB's on specified processors.
725 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900726 * The caller has derived the cpumask from the mm_struct. This function
727 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
Cliff Wickman18129242008-06-02 08:56:14 -0500728 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500729 * The cpumask is converted into a uvhubmask of the uvhubs containing
730 * those cpus.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500731 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900732 * Note that this function should be called with preemption disabled.
733 *
734 * Returns NULL if all remote flushing was done.
735 * Returns pointer to cpumask if some remote flushing remains to be
736 * done. The returned pointer is valid till preemption is re-enabled.
Cliff Wickman18129242008-06-02 08:56:14 -0500737 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900738const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
739 struct mm_struct *mm,
740 unsigned long va, unsigned int cpu)
Cliff Wickman18129242008-06-02 08:56:14 -0500741{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500742 int remotes;
743 int tcpu;
744 int uvhub;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500745 int locals = 0;
Ingo Molnardc163a42008-06-18 14:15:43 +0200746 struct bau_desc *bau_desc;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500747 struct cpumask *flush_mask;
748 struct ptc_stats *stat;
749 struct bau_control *bcp;
Cliff Wickman18129242008-06-02 08:56:14 -0500750
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500751 /* kernel was booted 'nobau' */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500752 if (nobau)
753 return cpumask;
754
755 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500756
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500757 /*
758 * Each sending cpu has a per-cpu mask which it fills from the caller's
759 * cpu mask. Only remote cpus are converted to uvhubs and copied.
760 */
761 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
762 /*
763 * copy cpumask to flush_mask, removing current cpu
764 * (current cpu should already have been flushed by the caller and
765 * should never be returned if we return flush_mask)
766 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900767 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500768 if (cpu_isset(cpu, *cpumask))
769 locals++; /* current cpu was targeted */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900770
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500771 bau_desc = bcp->descriptor_base;
772 bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu;
Cliff Wickman18129242008-06-02 08:56:14 -0500773
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500774 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
775 remotes = 0;
776 for_each_cpu(tcpu, flush_mask) {
777 uvhub = uv_cpu_to_blade_id(tcpu);
778 if (uvhub == bcp->uvhub) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500779 locals++;
Cliff Wickman18129242008-06-02 08:56:14 -0500780 continue;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500781 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500782 bau_uvhub_set(uvhub, &bau_desc->distribution);
783 remotes++;
Cliff Wickman18129242008-06-02 08:56:14 -0500784 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500785 if (remotes == 0) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500786 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500787 * No off_hub flushing; return status for local hub.
788 * Return the caller's mask if all were local (the current
789 * cpu may be in that mask).
Cliff Wickmanb194b122008-06-12 08:23:48 -0500790 */
791 if (locals)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500792 return cpumask;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500793 else
Tejun Heobdbcdd42009-01-21 17:26:06 +0900794 return NULL;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500795 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500796 stat = &per_cpu(ptcstats, cpu);
797 stat->s_requestor++;
798 stat->s_ntargcpu += remotes;
799 remotes = bau_uvhub_weight(&bau_desc->distribution);
800 stat->s_ntarguvhub += remotes;
801 if (remotes >= 16)
802 stat->s_ntarguvhub16++;
803 else if (remotes >= 8)
804 stat->s_ntarguvhub8++;
805 else if (remotes >= 4)
806 stat->s_ntarguvhub4++;
807 else if (remotes >= 2)
808 stat->s_ntarguvhub2++;
809 else
810 stat->s_ntarguvhub1++;
Cliff Wickman18129242008-06-02 08:56:14 -0500811
812 bau_desc->payload.address = va;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900813 bau_desc->payload.sending_cpu = cpu;
Cliff Wickman18129242008-06-02 08:56:14 -0500814
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500815 /*
816 * uv_flush_send_and_wait returns null if all cpu's were messaged, or
817 * the adjusted flush_mask if any cpu's were not messaged.
818 */
819 return uv_flush_send_and_wait(bau_desc, flush_mask, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500820}
821
822/*
823 * The BAU message interrupt comes here. (registered by set_intr_gate)
824 * See entry_64.S
825 *
826 * We received a broadcast assist message.
827 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500828 * Interrupts are disabled; this interrupt could represent
Cliff Wickman18129242008-06-02 08:56:14 -0500829 * the receipt of several messages.
830 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500831 * All cores/threads on this hub get this interrupt.
832 * The last one to see it does the software ack.
Cliff Wickman18129242008-06-02 08:56:14 -0500833 * (the resource will not be freed until noninterruptable cpus see this
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500834 * interrupt; hardware may timeout the s/w ack and reply ERROR)
Cliff Wickman18129242008-06-02 08:56:14 -0500835 */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500836void uv_bau_message_interrupt(struct pt_regs *regs)
Cliff Wickman18129242008-06-02 08:56:14 -0500837{
Cliff Wickman18129242008-06-02 08:56:14 -0500838 int count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500839 cycles_t time_start;
840 struct bau_payload_queue_entry *msg;
841 struct bau_control *bcp;
842 struct ptc_stats *stat;
843 struct msg_desc msgdesc;
Cliff Wickman18129242008-06-02 08:56:14 -0500844
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500845 time_start = get_cycles();
846 bcp = &per_cpu(bau_control, smp_processor_id());
847 stat = &per_cpu(ptcstats, smp_processor_id());
848 msgdesc.va_queue_first = bcp->va_queue_first;
849 msgdesc.va_queue_last = bcp->va_queue_last;
850 msg = bcp->bau_msg_head;
Cliff Wickman18129242008-06-02 08:56:14 -0500851 while (msg->sw_ack_vector) {
852 count++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500853 msgdesc.msg_slot = msg - msgdesc.va_queue_first;
854 msgdesc.sw_ack_slot = ffs(msg->sw_ack_vector) - 1;
855 msgdesc.msg = msg;
856 uv_bau_process_message(&msgdesc, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500857 msg++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500858 if (msg > msgdesc.va_queue_last)
859 msg = msgdesc.va_queue_first;
860 bcp->bau_msg_head = msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500861 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500862 stat->d_time += (get_cycles() - time_start);
Cliff Wickman18129242008-06-02 08:56:14 -0500863 if (!count)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500864 stat->d_nomsg++;
Cliff Wickman18129242008-06-02 08:56:14 -0500865 else if (count > 1)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500866 stat->d_multmsg++;
867 ack_APIC_irq();
Cliff Wickman18129242008-06-02 08:56:14 -0500868}
869
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500870/*
871 * uv_enable_timeouts
872 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500873 * Each target uvhub (i.e. a uvhub that has no cpu's) needs to have
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500874 * shootdown message timeouts enabled. The timeout does not cause
875 * an interrupt, but causes an error message to be returned to
876 * the sender.
877 */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500878static void uv_enable_timeouts(void)
Cliff Wickman18129242008-06-02 08:56:14 -0500879{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500880 int uvhub;
881 int nuvhubs;
Cliff Wickman18129242008-06-02 08:56:14 -0500882 int pnode;
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500883 unsigned long mmr_image;
Cliff Wickman18129242008-06-02 08:56:14 -0500884
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500885 nuvhubs = uv_num_possible_blades();
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500886
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500887 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
888 if (!uv_blade_nr_possible_cpus(uvhub))
Cliff Wickman18129242008-06-02 08:56:14 -0500889 continue;
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500890
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500891 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500892 mmr_image =
893 uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL);
894 /*
895 * Set the timeout period and then lock it in, in three
896 * steps; captures and locks in the period.
897 *
898 * To program the period, the SOFT_ACK_MODE must be off.
899 */
900 mmr_image &= ~((unsigned long)1 <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600901 UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500902 uv_write_global_mmr64
903 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
904 /*
905 * Set the 4-bit period.
906 */
907 mmr_image &= ~((unsigned long)0xf <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600908 UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500909 mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600910 UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500911 uv_write_global_mmr64
912 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
913 /*
914 * Subsequent reversals of the timebase bit (3) cause an
915 * immediate timeout of one or all INTD resources as
916 * indicated in bits 2:0 (7 causes all of them to timeout).
917 */
918 mmr_image |= ((unsigned long)1 <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600919 UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500920 uv_write_global_mmr64
921 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
Cliff Wickman18129242008-06-02 08:56:14 -0500922 }
Cliff Wickman18129242008-06-02 08:56:14 -0500923}
924
Cliff Wickmanb194b122008-06-12 08:23:48 -0500925static void *uv_ptc_seq_start(struct seq_file *file, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -0500926{
927 if (*offset < num_possible_cpus())
928 return offset;
929 return NULL;
930}
931
Cliff Wickmanb194b122008-06-12 08:23:48 -0500932static void *uv_ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -0500933{
934 (*offset)++;
935 if (*offset < num_possible_cpus())
936 return offset;
937 return NULL;
938}
939
Cliff Wickmanb194b122008-06-12 08:23:48 -0500940static void uv_ptc_seq_stop(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -0500941{
942}
943
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500944static inline unsigned long long
Cliff Wickman12a66112010-06-02 16:22:01 -0500945microsec_2_cycles(unsigned long microsec)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500946{
947 unsigned long ns;
948 unsigned long long cyc;
949
Cliff Wickman12a66112010-06-02 16:22:01 -0500950 ns = microsec * 1000;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500951 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
952 return cyc;
953}
954
Cliff Wickman18129242008-06-02 08:56:14 -0500955/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500956 * Display the statistics thru /proc.
957 * 'data' points to the cpu number
Cliff Wickman18129242008-06-02 08:56:14 -0500958 */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500959static int uv_ptc_seq_show(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -0500960{
961 struct ptc_stats *stat;
962 int cpu;
963
964 cpu = *(loff_t *)data;
965
966 if (!cpu) {
967 seq_printf(file,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500968 "# cpu sent stime numuvhubs numuvhubs16 numuvhubs8 ");
Cliff Wickman18129242008-06-02 08:56:14 -0500969 seq_printf(file,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500970 "numuvhubs4 numuvhubs2 numuvhubs1 numcpus dto ");
971 seq_printf(file,
972 "retries rok resetp resett giveup sto bz throt ");
973 seq_printf(file,
974 "sw_ack recv rtime all ");
975 seq_printf(file,
976 "one mult none retry canc nocan reset rcan\n");
Cliff Wickman18129242008-06-02 08:56:14 -0500977 }
978 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
979 stat = &per_cpu(ptcstats, cpu);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500980 /* source side statistics */
981 seq_printf(file,
982 "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
983 cpu, stat->s_requestor, cycles_2_us(stat->s_time),
984 stat->s_ntarguvhub, stat->s_ntarguvhub16,
985 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
986 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
987 stat->s_ntargcpu, stat->s_dtimeout);
988 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
989 stat->s_retry_messages, stat->s_retriesok,
990 stat->s_resets_plug, stat->s_resets_timeout,
991 stat->s_giveup, stat->s_stimeout,
992 stat->s_busy, stat->s_throttles);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500993
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500994 /* destination side statistics */
995 seq_printf(file,
996 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
Cliff Wickman9674f352009-04-03 08:34:05 -0500997 uv_read_global_mmr64(uv_cpu_to_pnode(cpu),
Cliff Wickman18129242008-06-02 08:56:14 -0500998 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500999 stat->d_requestee, cycles_2_us(stat->d_time),
1000 stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
1001 stat->d_nomsg, stat->d_retries, stat->d_canceled,
1002 stat->d_nocanceled, stat->d_resets,
1003 stat->d_rcanceled);
Cliff Wickman18129242008-06-02 08:56:14 -05001004 }
1005
1006 return 0;
1007}
1008
1009/*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001010 * Display the tunables thru debugfs
1011 */
1012static ssize_t tunables_read(struct file *file, char __user *userbuf,
1013 size_t count, loff_t *ppos)
1014{
1015 char buf[300];
1016 int ret;
1017
1018 ret = snprintf(buf, 300, "%s %s %s\n%d %d %d %d %d %d %d %d %d\n",
1019 "max_bau_concurrent plugged_delay plugsb4reset",
1020 "timeoutsb4reset ipi_reset_limit complete_threshold",
1021 "congested_response_us congested_reps congested_period",
1022 max_bau_concurrent, plugged_delay, plugsb4reset,
1023 timeoutsb4reset, ipi_reset_limit, complete_threshold,
1024 congested_response_us, congested_reps, congested_period);
1025
1026 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
1027}
1028
1029/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001030 * -1: resetf the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001031 * 0: display meaning of the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001032 */
Cliff Wickmanb194b122008-06-12 08:23:48 -05001033static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001034 size_t count, loff_t *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001035{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001036 int cpu;
1037 long input_arg;
Cliff Wickman18129242008-06-02 08:56:14 -05001038 char optstr[64];
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001039 struct ptc_stats *stat;
Cliff Wickman18129242008-06-02 08:56:14 -05001040
Cliff Wickmane7eb8722008-06-23 08:32:25 -05001041 if (count == 0 || count > sizeof(optstr))
Cliff Wickmancef53272008-06-19 11:16:24 -05001042 return -EINVAL;
Cliff Wickman18129242008-06-02 08:56:14 -05001043 if (copy_from_user(optstr, user, count))
1044 return -EFAULT;
1045 optstr[count - 1] = '\0';
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001046 if (strict_strtol(optstr, 10, &input_arg) < 0) {
Cliff Wickman18129242008-06-02 08:56:14 -05001047 printk(KERN_DEBUG "%s is invalid\n", optstr);
1048 return -EINVAL;
1049 }
1050
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001051 if (input_arg == 0) {
Cliff Wickman18129242008-06-02 08:56:14 -05001052 printk(KERN_DEBUG "# cpu: cpu number\n");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001053 printk(KERN_DEBUG "Sender statistics:\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001054 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001055 "sent: number of shootdown messages sent\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001056 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001057 "stime: time spent sending messages\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001058 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001059 "numuvhubs: number of hubs targeted with shootdown\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001060 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001061 "numuvhubs16: number times 16 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001062 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001063 "numuvhubs8: number times 8 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001064 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001065 "numuvhubs4: number times 4 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001066 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001067 "numuvhubs2: number times 2 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001068 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001069 "numuvhubs1: number times 1 hub targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001070 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001071 "numcpus: number of cpus targeted with shootdown\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001072 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001073 "dto: number of destination timeouts\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001074 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001075 "retries: destination timeout retries sent\n");
1076 printk(KERN_DEBUG
1077 "rok: : destination timeouts successfully retried\n");
1078 printk(KERN_DEBUG
1079 "resetp: ipi-style resource resets for plugs\n");
1080 printk(KERN_DEBUG
1081 "resett: ipi-style resource resets for timeouts\n");
1082 printk(KERN_DEBUG
1083 "giveup: fall-backs to ipi-style shootdowns\n");
1084 printk(KERN_DEBUG
1085 "sto: number of source timeouts\n");
1086 printk(KERN_DEBUG
1087 "bz: number of stay-busy's\n");
1088 printk(KERN_DEBUG
1089 "throt: number times spun in throttle\n");
1090 printk(KERN_DEBUG "Destination side statistics:\n");
1091 printk(KERN_DEBUG
1092 "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
1093 printk(KERN_DEBUG
1094 "recv: shootdown messages received\n");
1095 printk(KERN_DEBUG
1096 "rtime: time spent processing messages\n");
1097 printk(KERN_DEBUG
1098 "all: shootdown all-tlb messages\n");
1099 printk(KERN_DEBUG
1100 "one: shootdown one-tlb messages\n");
1101 printk(KERN_DEBUG
1102 "mult: interrupts that found multiple messages\n");
1103 printk(KERN_DEBUG
1104 "none: interrupts that found no messages\n");
1105 printk(KERN_DEBUG
1106 "retry: number of retry messages processed\n");
1107 printk(KERN_DEBUG
1108 "canc: number messages canceled by retries\n");
1109 printk(KERN_DEBUG
1110 "nocan: number retries that found nothing to cancel\n");
1111 printk(KERN_DEBUG
1112 "reset: number of ipi-style reset requests processed\n");
1113 printk(KERN_DEBUG
1114 "rcan: number messages canceled by reset requests\n");
1115 } else if (input_arg == -1) {
1116 for_each_present_cpu(cpu) {
1117 stat = &per_cpu(ptcstats, cpu);
1118 memset(stat, 0, sizeof(struct ptc_stats));
1119 }
Cliff Wickman18129242008-06-02 08:56:14 -05001120 }
1121
1122 return count;
1123}
1124
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001125static int local_atoi(const char *name)
1126{
1127 int val = 0;
1128
1129 for (;; name++) {
1130 switch (*name) {
1131 case '0' ... '9':
1132 val = 10*val+(*name-'0');
1133 break;
1134 default:
1135 return val;
1136 }
1137 }
1138}
1139
1140/*
1141 * set the tunables
1142 * 0 values reset them to defaults
1143 */
1144static ssize_t tunables_write(struct file *file, const char __user *user,
1145 size_t count, loff_t *data)
1146{
1147 int cpu;
1148 int cnt = 0;
1149 int val;
1150 char *p;
1151 char *q;
1152 char instr[64];
1153 struct bau_control *bcp;
1154
1155 if (count == 0 || count > sizeof(instr)-1)
1156 return -EINVAL;
1157 if (copy_from_user(instr, user, count))
1158 return -EFAULT;
1159
1160 instr[count] = '\0';
1161 /* count the fields */
1162 p = instr + strspn(instr, WHITESPACE);
1163 q = p;
1164 for (; *p; p = q + strspn(q, WHITESPACE)) {
1165 q = p + strcspn(p, WHITESPACE);
1166 cnt++;
1167 if (q == p)
1168 break;
1169 }
1170 if (cnt != 9) {
1171 printk(KERN_INFO "bau tunable error: should be 9 numbers\n");
1172 return -EINVAL;
1173 }
1174
1175 p = instr + strspn(instr, WHITESPACE);
1176 q = p;
1177 for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
1178 q = p + strcspn(p, WHITESPACE);
1179 val = local_atoi(p);
1180 switch (cnt) {
1181 case 0:
1182 if (val == 0) {
1183 max_bau_concurrent = MAX_BAU_CONCURRENT;
1184 max_bau_concurrent_constant =
1185 MAX_BAU_CONCURRENT;
1186 continue;
1187 }
1188 bcp = &per_cpu(bau_control, smp_processor_id());
1189 if (val < 1 || val > bcp->cpus_in_uvhub) {
1190 printk(KERN_DEBUG
1191 "Error: BAU max concurrent %d is invalid\n",
1192 val);
1193 return -EINVAL;
1194 }
1195 max_bau_concurrent = val;
1196 max_bau_concurrent_constant = val;
1197 continue;
1198 case 1:
1199 if (val == 0)
1200 plugged_delay = PLUGGED_DELAY;
1201 else
1202 plugged_delay = val;
1203 continue;
1204 case 2:
1205 if (val == 0)
1206 plugsb4reset = PLUGSB4RESET;
1207 else
1208 plugsb4reset = val;
1209 continue;
1210 case 3:
1211 if (val == 0)
1212 timeoutsb4reset = TIMEOUTSB4RESET;
1213 else
1214 timeoutsb4reset = val;
1215 continue;
1216 case 4:
1217 if (val == 0)
1218 ipi_reset_limit = IPI_RESET_LIMIT;
1219 else
1220 ipi_reset_limit = val;
1221 continue;
1222 case 5:
1223 if (val == 0)
1224 complete_threshold = COMPLETE_THRESHOLD;
1225 else
1226 complete_threshold = val;
1227 continue;
1228 case 6:
1229 if (val == 0)
1230 congested_response_us = CONGESTED_RESPONSE_US;
1231 else
1232 congested_response_us = val;
1233 continue;
1234 case 7:
1235 if (val == 0)
1236 congested_reps = CONGESTED_REPS;
1237 else
1238 congested_reps = val;
1239 continue;
1240 case 8:
1241 if (val == 0)
1242 congested_period = CONGESTED_PERIOD;
1243 else
1244 congested_period = val;
1245 continue;
1246 }
1247 if (q == p)
1248 break;
1249 }
1250 for_each_present_cpu(cpu) {
1251 bcp = &per_cpu(bau_control, cpu);
1252 bcp->max_bau_concurrent = max_bau_concurrent;
1253 bcp->max_bau_concurrent_constant = max_bau_concurrent;
1254 bcp->plugged_delay = plugged_delay;
1255 bcp->plugsb4reset = plugsb4reset;
1256 bcp->timeoutsb4reset = timeoutsb4reset;
1257 bcp->ipi_reset_limit = ipi_reset_limit;
1258 bcp->complete_threshold = complete_threshold;
1259 bcp->congested_response_us = congested_response_us;
1260 bcp->congested_reps = congested_reps;
1261 bcp->congested_period = congested_period;
1262 }
1263 return count;
1264}
1265
Cliff Wickman18129242008-06-02 08:56:14 -05001266static const struct seq_operations uv_ptc_seq_ops = {
Ingo Molnardc163a42008-06-18 14:15:43 +02001267 .start = uv_ptc_seq_start,
1268 .next = uv_ptc_seq_next,
1269 .stop = uv_ptc_seq_stop,
1270 .show = uv_ptc_seq_show
Cliff Wickman18129242008-06-02 08:56:14 -05001271};
1272
Cliff Wickmanb194b122008-06-12 08:23:48 -05001273static int uv_ptc_proc_open(struct inode *inode, struct file *file)
Cliff Wickman18129242008-06-02 08:56:14 -05001274{
1275 return seq_open(file, &uv_ptc_seq_ops);
1276}
1277
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001278static int tunables_open(struct inode *inode, struct file *file)
1279{
1280 return 0;
1281}
1282
Cliff Wickman18129242008-06-02 08:56:14 -05001283static const struct file_operations proc_uv_ptc_operations = {
Cliff Wickmanb194b122008-06-12 08:23:48 -05001284 .open = uv_ptc_proc_open,
1285 .read = seq_read,
1286 .write = uv_ptc_proc_write,
1287 .llseek = seq_lseek,
1288 .release = seq_release,
Cliff Wickman18129242008-06-02 08:56:14 -05001289};
1290
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001291static const struct file_operations tunables_fops = {
1292 .open = tunables_open,
1293 .read = tunables_read,
1294 .write = tunables_write,
1295};
1296
Cliff Wickmanb194b122008-06-12 08:23:48 -05001297static int __init uv_ptc_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001298{
Cliff Wickmanb194b122008-06-12 08:23:48 -05001299 struct proc_dir_entry *proc_uv_ptc;
Cliff Wickman18129242008-06-02 08:56:14 -05001300
1301 if (!is_uv_system())
1302 return 0;
1303
Alexey Dobriyan10f02d112009-08-23 23:17:27 +04001304 proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
1305 &proc_uv_ptc_operations);
Cliff Wickman18129242008-06-02 08:56:14 -05001306 if (!proc_uv_ptc) {
1307 printk(KERN_ERR "unable to create %s proc entry\n",
1308 UV_PTC_BASENAME);
1309 return -EINVAL;
1310 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001311
1312 tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
1313 if (!tunables_dir) {
1314 printk(KERN_ERR "unable to create debugfs directory %s\n",
1315 UV_BAU_TUNABLES_DIR);
1316 return -EINVAL;
1317 }
1318 tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
1319 tunables_dir, NULL, &tunables_fops);
1320 if (!tunables_file) {
1321 printk(KERN_ERR "unable to create debugfs file %s\n",
1322 UV_BAU_TUNABLES_FILE);
1323 return -EINVAL;
1324 }
Cliff Wickman18129242008-06-02 08:56:14 -05001325 return 0;
1326}
1327
Cliff Wickmanb194b122008-06-12 08:23:48 -05001328/*
Cliff Wickmanb194b122008-06-12 08:23:48 -05001329 * initialize the sending side's sending buffers
1330 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001331static void
Cliff Wickmanb194b122008-06-12 08:23:48 -05001332uv_activation_descriptor_init(int node, int pnode)
1333{
1334 int i;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001335 int cpu;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001336 unsigned long pa;
1337 unsigned long m;
1338 unsigned long n;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001339 struct bau_desc *bau_desc;
1340 struct bau_desc *bd2;
1341 struct bau_control *bcp;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001342
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001343 /*
1344 * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001345 * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per uvhub
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001346 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001347 bau_desc = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)*
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001348 UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001349 BUG_ON(!bau_desc);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001350
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001351 pa = uv_gpa(bau_desc); /* need the real nasid*/
1352 n = pa >> uv_nshift;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001353 m = pa & uv_mmask;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001354
Cliff Wickman9c26f522009-06-24 09:41:59 -05001355 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE,
1356 (n << UV_DESC_BASE_PNODE_SHIFT | m));
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001357
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001358 /*
1359 * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each
1360 * cpu even though we only use the first one; one descriptor can
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001361 * describe a broadcast to 256 uv hubs.
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001362 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001363 for (i = 0, bd2 = bau_desc; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR);
1364 i++, bd2++) {
1365 memset(bd2, 0, sizeof(struct bau_desc));
1366 bd2->header.sw_ack_flag = 1;
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001367 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001368 * base_dest_nodeid is the nasid (pnode<<1) of the first uvhub
1369 * in the partition. The bit map will indicate uvhub numbers,
1370 * which are 0-N in a partition. Pnodes are unique system-wide.
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001371 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001372 bd2->header.base_dest_nodeid = uv_partition_base_pnode << 1;
1373 bd2->header.dest_subnodeid = 0x10; /* the LB */
1374 bd2->header.command = UV_NET_ENDPOINT_INTD;
1375 bd2->header.int_both = 1;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001376 /*
1377 * all others need to be set to zero:
1378 * fairness chaining multilevel count replied_to
1379 */
1380 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001381 for_each_present_cpu(cpu) {
1382 if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
1383 continue;
1384 bcp = &per_cpu(bau_control, cpu);
1385 bcp->descriptor_base = bau_desc;
1386 }
Cliff Wickmanb194b122008-06-12 08:23:48 -05001387}
1388
1389/*
1390 * initialize the destination side's receiving buffers
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001391 * entered for each uvhub in the partition
1392 * - node is first node (kernel memory notion) on the uvhub
1393 * - pnode is the uvhub's physical identifier
Cliff Wickmanb194b122008-06-12 08:23:48 -05001394 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001395static void
1396uv_payload_queue_init(int node, int pnode)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001397{
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001398 int pn;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001399 int cpu;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001400 char *cp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001401 unsigned long pa;
1402 struct bau_payload_queue_entry *pqp;
1403 struct bau_payload_queue_entry *pqp_malloc;
1404 struct bau_control *bcp;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001405
Ingo Molnardc163a42008-06-18 14:15:43 +02001406 pqp = (struct bau_payload_queue_entry *) kmalloc_node(
1407 (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry),
1408 GFP_KERNEL, node);
1409 BUG_ON(!pqp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001410 pqp_malloc = pqp;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001411
Cliff Wickmanb194b122008-06-12 08:23:48 -05001412 cp = (char *)pqp + 31;
1413 pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001414
1415 for_each_present_cpu(cpu) {
1416 if (pnode != uv_cpu_to_pnode(cpu))
1417 continue;
1418 /* for every cpu on this pnode: */
1419 bcp = &per_cpu(bau_control, cpu);
1420 bcp->va_queue_first = pqp;
1421 bcp->bau_msg_head = pqp;
1422 bcp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
1423 }
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001424 /*
1425 * need the pnode of where the memory was really allocated
1426 */
1427 pa = uv_gpa(pqp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001428 pn = pa >> uv_nshift;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001429 uv_write_global_mmr64(pnode,
1430 UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001431 ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) |
Cliff Wickmanb194b122008-06-12 08:23:48 -05001432 uv_physnodeaddr(pqp));
1433 uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
1434 uv_physnodeaddr(pqp));
Cliff Wickmanb194b122008-06-12 08:23:48 -05001435 uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
1436 (unsigned long)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001437 uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1)));
1438 /* in effect, all msg_type's are set to MSG_NOOP */
Ingo Molnardc163a42008-06-18 14:15:43 +02001439 memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001440}
1441
1442/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001443 * Initialization of each UV hub's structures
Cliff Wickmanb194b122008-06-12 08:23:48 -05001444 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001445static void __init uv_init_uvhub(int uvhub, int vector)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001446{
Cliff Wickman9674f352009-04-03 08:34:05 -05001447 int node;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001448 int pnode;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001449 unsigned long apicid;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001450
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001451 node = uvhub_to_first_node(uvhub);
1452 pnode = uv_blade_to_pnode(uvhub);
1453 uv_activation_descriptor_init(node, pnode);
1454 uv_payload_queue_init(node, pnode);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001455 /*
1456 * the below initialization can't be in firmware because the
1457 * messaging IRQ will be determined by the OS
1458 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001459 apicid = uvhub_to_first_apicid(uvhub);
Cliff Wickmane38e2af2009-11-19 17:12:43 -06001460 uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001461 ((apicid << 32) | vector));
1462}
1463
1464/*
Cliff Wickman12a66112010-06-02 16:22:01 -05001465 * We will set BAU_MISC_CONTROL with a timeout period.
1466 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
1467 * So the destination timeout period has be be calculated from them.
1468 */
1469static int
1470calculate_destination_timeout(void)
1471{
1472 unsigned long mmr_image;
1473 int mult1;
1474 int mult2;
1475 int index;
1476 int base;
1477 int ret;
1478 unsigned long ts_ns;
1479
1480 mult1 = UV_INTD_SOFT_ACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
1481 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1482 index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
1483 mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
1484 mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
1485 base = timeout_base_ns[index];
1486 ts_ns = base * mult1 * mult2;
1487 ret = ts_ns / 1000;
1488 return ret;
1489}
1490
1491/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001492 * initialize the bau_control structure for each cpu
1493 */
1494static void uv_init_per_cpu(int nuvhubs)
1495{
1496 int i, j, k;
1497 int cpu;
1498 int pnode;
1499 int uvhub;
1500 short socket = 0;
1501 struct bau_control *bcp;
1502 struct uvhub_desc *bdp;
1503 struct socket_desc *sdp;
1504 struct bau_control *hmaster = NULL;
1505 struct bau_control *smaster = NULL;
1506 struct socket_desc {
1507 short num_cpus;
1508 short cpu_number[16];
1509 };
1510 struct uvhub_desc {
1511 short num_sockets;
1512 short num_cpus;
1513 short uvhub;
1514 short pnode;
1515 struct socket_desc socket[2];
1516 };
1517 struct uvhub_desc *uvhub_descs;
1518
Cliff Wickman12a66112010-06-02 16:22:01 -05001519 timeout_us = calculate_destination_timeout();
1520
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001521 uvhub_descs = (struct uvhub_desc *)
1522 kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1523 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
1524 for_each_present_cpu(cpu) {
1525 bcp = &per_cpu(bau_control, cpu);
1526 memset(bcp, 0, sizeof(struct bau_control));
1527 spin_lock_init(&bcp->masks_lock);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001528 pnode = uv_cpu_hub_info(cpu)->pnode;
1529 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
1530 bdp = &uvhub_descs[uvhub];
1531 bdp->num_cpus++;
1532 bdp->uvhub = uvhub;
1533 bdp->pnode = pnode;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001534 /* kludge: assume uv_hub.h is constant */
1535 socket = (cpu_physical_id(cpu)>>5)&1;
1536 if (socket >= bdp->num_sockets)
1537 bdp->num_sockets = socket+1;
1538 sdp = &bdp->socket[socket];
1539 sdp->cpu_number[sdp->num_cpus] = cpu;
1540 sdp->num_cpus++;
1541 }
1542 socket = 0;
1543 for_each_possible_blade(uvhub) {
1544 bdp = &uvhub_descs[uvhub];
1545 for (i = 0; i < bdp->num_sockets; i++) {
1546 sdp = &bdp->socket[i];
1547 for (j = 0; j < sdp->num_cpus; j++) {
1548 cpu = sdp->cpu_number[j];
1549 bcp = &per_cpu(bau_control, cpu);
1550 bcp->cpu = cpu;
1551 if (j == 0) {
1552 smaster = bcp;
1553 if (i == 0)
1554 hmaster = bcp;
1555 }
1556 bcp->cpus_in_uvhub = bdp->num_cpus;
1557 bcp->cpus_in_socket = sdp->num_cpus;
1558 bcp->socket_master = smaster;
1559 bcp->uvhub_master = hmaster;
1560 for (k = 0; k < DEST_Q_SIZE; k++)
1561 bcp->socket_acknowledge_count[k] = 0;
1562 bcp->uvhub_cpu =
1563 uv_cpu_hub_info(cpu)->blade_processor_id;
1564 }
1565 socket++;
1566 }
1567 }
1568 kfree(uvhub_descs);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001569 for_each_present_cpu(cpu) {
1570 bcp = &per_cpu(bau_control, cpu);
1571 /* time interval to catch a hardware stay-busy bug */
1572 bcp->timeout_interval = microsec_2_cycles(2*timeout_us);
1573 bcp->max_bau_concurrent = max_bau_concurrent;
1574 bcp->max_bau_concurrent_constant = max_bau_concurrent;
1575 bcp->plugged_delay = plugged_delay;
1576 bcp->plugsb4reset = plugsb4reset;
1577 bcp->timeoutsb4reset = timeoutsb4reset;
1578 bcp->ipi_reset_limit = ipi_reset_limit;
1579 bcp->complete_threshold = complete_threshold;
1580 bcp->congested_response_us = congested_response_us;
1581 bcp->congested_reps = congested_reps;
1582 bcp->congested_period = congested_period;
1583 }
Cliff Wickmanb194b122008-06-12 08:23:48 -05001584}
Cliff Wickman18129242008-06-02 08:56:14 -05001585
1586/*
1587 * Initialization of BAU-related structures
1588 */
Cliff Wickmanb194b122008-06-12 08:23:48 -05001589static int __init uv_bau_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001590{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001591 int uvhub;
1592 int pnode;
1593 int nuvhubs;
Rusty Russell2c74d662009-03-18 08:22:30 +10301594 int cur_cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001595 int vector;
1596 unsigned long mmr;
Cliff Wickman18129242008-06-02 08:56:14 -05001597
1598 if (!is_uv_system())
1599 return 0;
1600
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001601 if (nobau)
1602 return 0;
1603
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301604 for_each_possible_cpu(cur_cpu)
Yinghai Lueaa958402009-06-06 14:51:36 -07001605 zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu),
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301606 GFP_KERNEL, cpu_to_node(cur_cpu));
1607
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001608 max_bau_concurrent = MAX_BAU_CONCURRENT;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001609 uv_nshift = uv_hub_info->m_val;
Robin Holt036ed8b2009-10-15 17:40:00 -05001610 uv_mmask = (1UL << uv_hub_info->m_val) - 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001611 nuvhubs = uv_num_possible_blades();
Cliff Wickman9674f352009-04-03 08:34:05 -05001612
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001613 uv_init_per_cpu(nuvhubs);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001614
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001615 uv_partition_base_pnode = 0x7fffffff;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001616 for (uvhub = 0; uvhub < nuvhubs; uvhub++)
1617 if (uv_blade_nr_possible_cpus(uvhub) &&
1618 (uv_blade_to_pnode(uvhub) < uv_partition_base_pnode))
1619 uv_partition_base_pnode = uv_blade_to_pnode(uvhub);
Cliff Wickman9674f352009-04-03 08:34:05 -05001620
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001621 vector = UV_BAU_MESSAGE;
1622 for_each_possible_blade(uvhub)
1623 if (uv_blade_nr_possible_cpus(uvhub))
1624 uv_init_uvhub(uvhub, vector);
1625
Cliff Wickman18129242008-06-02 08:56:14 -05001626 uv_enable_timeouts();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001627 alloc_intr_gate(vector, uv_bau_message_intr1);
1628
1629 for_each_possible_blade(uvhub) {
1630 pnode = uv_blade_to_pnode(uvhub);
1631 /* INIT the bau */
1632 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL,
1633 ((unsigned long)1 << 63));
1634 mmr = 1; /* should be 1 to broadcast to both sockets */
1635 uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST, mmr);
1636 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001637
Cliff Wickman18129242008-06-02 08:56:14 -05001638 return 0;
1639}
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001640core_initcall(uv_bau_init);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001641fs_initcall(uv_ptc_init);