blob: 4cb14dbd7fa3e1e9d6c0185e806b6b17092baef4 [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 Wickmanb194b1202008-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 Wickman12a66112010-06-02 16:22:01 -050026/* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
27static int timeout_base_ns[] = {
28 20,
29 160,
30 1280,
31 10240,
32 81920,
33 655360,
34 5242880,
35 167772160
36};
37static int timeout_us;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050038static int nobau;
Cliff Wickman50fb55a2010-06-02 16:22:02 -050039static int baudisabled;
40static spinlock_t disable_lock;
41static cycles_t congested_cycles;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050042
43/* tunables: */
44static int max_bau_concurrent = MAX_BAU_CONCURRENT;
45static int max_bau_concurrent_constant = MAX_BAU_CONCURRENT;
46static int plugged_delay = PLUGGED_DELAY;
47static int plugsb4reset = PLUGSB4RESET;
48static int timeoutsb4reset = TIMEOUTSB4RESET;
49static int ipi_reset_limit = IPI_RESET_LIMIT;
50static int complete_threshold = COMPLETE_THRESHOLD;
51static int congested_response_us = CONGESTED_RESPONSE_US;
52static int congested_reps = CONGESTED_REPS;
53static int congested_period = CONGESTED_PERIOD;
54static struct dentry *tunables_dir;
55static struct dentry *tunables_file;
56
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050057static int __init setup_nobau(char *arg)
58{
59 nobau = 1;
60 return 0;
61}
62early_param("nobau", setup_nobau);
Ingo Molnarb4c286e2008-06-18 14:28:19 +020063
Cliff Wickman94ca8e42009-04-14 10:56:48 -050064/* base pnode in this partition */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050065static int uv_partition_base_pnode __read_mostly;
66/* position of pnode (which is nasid>>1): */
67static int uv_nshift __read_mostly;
68static unsigned long uv_mmask __read_mostly;
Cliff Wickman18129242008-06-02 08:56:14 -050069
Ingo Molnardc163a42008-06-18 14:15:43 +020070static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
71static DEFINE_PER_CPU(struct bau_control, bau_control);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050072static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
73
Cliff Wickman18129242008-06-02 08:56:14 -050074/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050075 * Determine the first node on a uvhub. 'Nodes' are used for kernel
76 * memory allocation.
Cliff Wickman9674f352009-04-03 08:34:05 -050077 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050078static int __init uvhub_to_first_node(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -050079{
80 int node, b;
81
82 for_each_online_node(node) {
83 b = uv_node_to_blade_id(node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050084 if (uvhub == b)
Cliff Wickman9674f352009-04-03 08:34:05 -050085 return node;
86 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050087 return -1;
Cliff Wickman9674f352009-04-03 08:34:05 -050088}
89
90/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050091 * Determine the apicid of the first cpu on a uvhub.
Cliff Wickman9674f352009-04-03 08:34:05 -050092 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050093static int __init uvhub_to_first_apicid(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -050094{
95 int cpu;
96
97 for_each_present_cpu(cpu)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050098 if (uvhub == uv_cpu_to_blade_id(cpu))
Cliff Wickman9674f352009-04-03 08:34:05 -050099 return per_cpu(x86_cpu_to_apicid, cpu);
100 return -1;
101}
102
103/*
Cliff Wickman18129242008-06-02 08:56:14 -0500104 * Free a software acknowledge hardware resource by clearing its Pending
105 * bit. This will return a reply to the sender.
106 * If the message has timed out, a reply has already been sent by the
107 * hardware but the resource has not been released. In that case our
108 * clear of the Timeout bit (as well) will free the resource. No reply will
109 * be sent (the hardware will only do one reply per message).
110 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500111static inline void uv_reply_to_message(struct msg_desc *mdp,
112 struct bau_control *bcp)
Cliff Wickman18129242008-06-02 08:56:14 -0500113{
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500114 unsigned long dw;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500115 struct bau_payload_queue_entry *msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500116
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500117 msg = mdp->msg;
118 if (!msg->canceled) {
119 dw = (msg->sw_ack_vector << UV_SW_ACK_NPENDING) |
120 msg->sw_ack_vector;
121 uv_write_local_mmr(
122 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw);
123 }
Cliff Wickman18129242008-06-02 08:56:14 -0500124 msg->replied_to = 1;
125 msg->sw_ack_vector = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500126}
127
128/*
129 * Process the receipt of a RETRY message
130 */
131static inline void uv_bau_process_retry_msg(struct msg_desc *mdp,
132 struct bau_control *bcp)
133{
134 int i;
135 int cancel_count = 0;
136 int slot2;
137 unsigned long msg_res;
138 unsigned long mmr = 0;
139 struct bau_payload_queue_entry *msg;
140 struct bau_payload_queue_entry *msg2;
141 struct ptc_stats *stat;
142
143 msg = mdp->msg;
Cliff Wickman712157a2010-06-02 16:22:02 -0500144 stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500145 stat->d_retries++;
146 /*
147 * cancel any message from msg+1 to the retry itself
148 */
149 for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
150 if (msg2 > mdp->va_queue_last)
151 msg2 = mdp->va_queue_first;
152 if (msg2 == msg)
153 break;
154
155 /* same conditions for cancellation as uv_do_reset */
156 if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
157 (msg2->sw_ack_vector) && ((msg2->sw_ack_vector &
158 msg->sw_ack_vector) == 0) &&
159 (msg2->sending_cpu == msg->sending_cpu) &&
160 (msg2->msg_type != MSG_NOOP)) {
161 slot2 = msg2 - mdp->va_queue_first;
162 mmr = uv_read_local_mmr
163 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
Cliff Wickman39847e72010-06-02 16:22:02 -0500164 msg_res = msg2->sw_ack_vector;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500165 /*
166 * This is a message retry; clear the resources held
167 * by the previous message only if they timed out.
168 * If it has not timed out we have an unexpected
169 * situation to report.
170 */
Cliff Wickman39847e72010-06-02 16:22:02 -0500171 if (mmr & (msg_res << UV_SW_ACK_NPENDING)) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500172 /*
173 * is the resource timed out?
174 * make everyone ignore the cancelled message.
175 */
176 msg2->canceled = 1;
177 stat->d_canceled++;
178 cancel_count++;
179 uv_write_local_mmr(
180 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
Cliff Wickman39847e72010-06-02 16:22:02 -0500181 (msg_res << UV_SW_ACK_NPENDING) |
182 msg_res);
183 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500184 }
185 }
186 if (!cancel_count)
187 stat->d_nocanceled++;
Cliff Wickman18129242008-06-02 08:56:14 -0500188}
189
190/*
191 * Do all the things a cpu should do for a TLB shootdown message.
192 * Other cpu's may come here at the same time for this message.
193 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500194static void uv_bau_process_message(struct msg_desc *mdp,
195 struct bau_control *bcp)
Cliff Wickman18129242008-06-02 08:56:14 -0500196{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500197 int msg_ack_count;
198 short socket_ack_count = 0;
199 struct ptc_stats *stat;
200 struct bau_payload_queue_entry *msg;
201 struct bau_control *smaster = bcp->socket_master;
Cliff Wickman18129242008-06-02 08:56:14 -0500202
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500203 /*
204 * This must be a normal message, or retry of a normal message
205 */
206 msg = mdp->msg;
Cliff Wickman712157a2010-06-02 16:22:02 -0500207 stat = bcp->statp;
Cliff Wickman18129242008-06-02 08:56:14 -0500208 if (msg->address == TLB_FLUSH_ALL) {
209 local_flush_tlb();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500210 stat->d_alltlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500211 } else {
212 __flush_tlb_one(msg->address);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500213 stat->d_onetlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500214 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500215 stat->d_requestee++;
Cliff Wickman18129242008-06-02 08:56:14 -0500216
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500217 /*
218 * One cpu on each uvhub has the additional job on a RETRY
219 * of releasing the resource held by the message that is
220 * being retried. That message is identified by sending
221 * cpu number.
222 */
223 if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
224 uv_bau_process_retry_msg(mdp, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500225
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500226 /*
227 * This is a sw_ack message, so we have to reply to it.
228 * Count each responding cpu on the socket. This avoids
229 * pinging the count's cache line back and forth between
230 * the sockets.
231 */
232 socket_ack_count = atomic_add_short_return(1, (struct atomic_short *)
233 &smaster->socket_acknowledge_count[mdp->msg_slot]);
234 if (socket_ack_count == bcp->cpus_in_socket) {
235 /*
236 * Both sockets dump their completed count total into
237 * the message's count.
238 */
239 smaster->socket_acknowledge_count[mdp->msg_slot] = 0;
240 msg_ack_count = atomic_add_short_return(socket_ack_count,
241 (struct atomic_short *)&msg->acknowledge_count);
Ingo Molnardc163a42008-06-18 14:15:43 +0200242
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500243 if (msg_ack_count == bcp->cpus_in_uvhub) {
244 /*
245 * All cpus in uvhub saw it; reply
246 */
247 uv_reply_to_message(mdp, bcp);
Ingo Molnardc163a42008-06-18 14:15:43 +0200248 }
249 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500250
251 return;
Cliff Wickman18129242008-06-02 08:56:14 -0500252}
253
254/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500255 * Determine the first cpu on a uvhub.
Cliff Wickman18129242008-06-02 08:56:14 -0500256 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500257static int uvhub_to_first_cpu(int uvhub)
Cliff Wickman18129242008-06-02 08:56:14 -0500258{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500259 int cpu;
260 for_each_present_cpu(cpu)
261 if (uvhub == uv_cpu_to_blade_id(cpu))
262 return cpu;
263 return -1;
Cliff Wickman18129242008-06-02 08:56:14 -0500264}
265
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500266/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500267 * Last resort when we get a large number of destination timeouts is
268 * to clear resources held by a given cpu.
269 * Do this with IPI so that all messages in the BAU message queue
270 * can be identified by their nonzero sw_ack_vector field.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500271 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500272 * This is entered for a single cpu on the uvhub.
273 * The sender want's this uvhub to free a specific message's
274 * sw_ack resources.
275 */
276static void
277uv_do_reset(void *ptr)
278{
279 int i;
280 int slot;
281 int count = 0;
282 unsigned long mmr;
283 unsigned long msg_res;
284 struct bau_control *bcp;
285 struct reset_args *rap;
286 struct bau_payload_queue_entry *msg;
287 struct ptc_stats *stat;
288
289 bcp = &per_cpu(bau_control, smp_processor_id());
290 rap = (struct reset_args *)ptr;
Cliff Wickman712157a2010-06-02 16:22:02 -0500291 stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500292 stat->d_resets++;
293
294 /*
295 * We're looking for the given sender, and
296 * will free its sw_ack resource.
297 * If all cpu's finally responded after the timeout, its
298 * message 'replied_to' was set.
299 */
300 for (msg = bcp->va_queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
301 /* uv_do_reset: same conditions for cancellation as
302 uv_bau_process_retry_msg() */
303 if ((msg->replied_to == 0) &&
304 (msg->canceled == 0) &&
305 (msg->sending_cpu == rap->sender) &&
306 (msg->sw_ack_vector) &&
307 (msg->msg_type != MSG_NOOP)) {
308 /*
309 * make everyone else ignore this message
310 */
311 msg->canceled = 1;
312 slot = msg - bcp->va_queue_first;
313 count++;
314 /*
315 * only reset the resource if it is still pending
316 */
317 mmr = uv_read_local_mmr
318 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
Cliff Wickman39847e72010-06-02 16:22:02 -0500319 msg_res = msg->sw_ack_vector;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500320 if (mmr & msg_res) {
321 stat->d_rcanceled++;
322 uv_write_local_mmr(
323 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
Cliff Wickman39847e72010-06-02 16:22:02 -0500324 (msg_res << UV_SW_ACK_NPENDING) |
325 msg_res);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500326 }
327 }
328 }
329 return;
330}
331
332/*
333 * Use IPI to get all target uvhubs to release resources held by
334 * a given sending cpu number.
335 */
336static void uv_reset_with_ipi(struct bau_target_uvhubmask *distribution,
337 int sender)
338{
339 int uvhub;
340 int cpu;
341 cpumask_t mask;
342 struct reset_args reset_args;
343
344 reset_args.sender = sender;
345
346 cpus_clear(mask);
347 /* find a single cpu for each uvhub in this distribution mask */
348 for (uvhub = 0;
349 uvhub < sizeof(struct bau_target_uvhubmask) * BITSPERBYTE;
350 uvhub++) {
351 if (!bau_uvhub_isset(uvhub, distribution))
352 continue;
353 /* find a cpu for this uvhub */
354 cpu = uvhub_to_first_cpu(uvhub);
355 cpu_set(cpu, mask);
356 }
357 /* IPI all cpus; Preemption is already disabled */
358 smp_call_function_many(&mask, uv_do_reset, (void *)&reset_args, 1);
359 return;
360}
361
362static inline unsigned long
363cycles_2_us(unsigned long long cyc)
364{
365 unsigned long long ns;
366 unsigned long us;
367 ns = (cyc * per_cpu(cyc2ns, smp_processor_id()))
368 >> CYC2NS_SCALE_FACTOR;
369 us = ns / 1000;
370 return us;
371}
372
373/*
374 * wait for all cpus on this hub to finish their sends and go quiet
375 * leaves uvhub_quiesce set so that no new broadcasts are started by
376 * bau_flush_send_and_wait()
377 */
378static inline void
379quiesce_local_uvhub(struct bau_control *hmaster)
380{
381 atomic_add_short_return(1, (struct atomic_short *)
382 &hmaster->uvhub_quiesce);
383}
384
385/*
386 * mark this quiet-requestor as done
387 */
388static inline void
389end_uvhub_quiesce(struct bau_control *hmaster)
390{
391 atomic_add_short_return(-1, (struct atomic_short *)
392 &hmaster->uvhub_quiesce);
393}
394
395/*
396 * Wait for completion of a broadcast software ack message
397 * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500398 */
Ingo Molnardc163a42008-06-18 14:15:43 +0200399static int uv_wait_completion(struct bau_desc *bau_desc,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500400 unsigned long mmr_offset, int right_shift, int this_cpu,
401 struct bau_control *bcp, struct bau_control *smaster, long try)
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500402{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500403 int relaxes = 0;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500404 unsigned long descriptor_status;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500405 unsigned long mmr;
406 unsigned long mask;
407 cycles_t ttime;
Cliff Wickman712157a2010-06-02 16:22:02 -0500408 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500409 struct bau_control *hmaster;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500410
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500411 hmaster = bcp->uvhub_master;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500412
413 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500414 while ((descriptor_status = (((unsigned long)
415 uv_read_local_mmr(mmr_offset) >>
416 right_shift) & UV_ACT_STATUS_MASK)) !=
417 DESC_STATUS_IDLE) {
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500418 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500419 * Our software ack messages may be blocked because there are
420 * no swack resources available. As long as none of them
421 * has timed out hardware will NACK our message and its
422 * state will stay IDLE.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500423 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500424 if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
425 stat->s_stimeout++;
426 return FLUSH_GIVEUP;
427 } else if (descriptor_status ==
428 DESC_STATUS_DESTINATION_TIMEOUT) {
429 stat->s_dtimeout++;
430 ttime = get_cycles();
431
432 /*
433 * Our retries may be blocked by all destination
434 * swack resources being consumed, and a timeout
435 * pending. In that case hardware returns the
436 * ERROR that looks like a destination timeout.
437 */
Cliff Wickman12a66112010-06-02 16:22:01 -0500438 if (cycles_2_us(ttime - bcp->send_message) <
439 timeout_us) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500440 bcp->conseccompletes = 0;
441 return FLUSH_RETRY_PLUGGED;
442 }
443
444 bcp->conseccompletes = 0;
445 return FLUSH_RETRY_TIMEOUT;
446 } else {
447 /*
448 * descriptor_status is still BUSY
449 */
450 cpu_relax();
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500451 }
452 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500453 bcp->conseccompletes++;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500454 return FLUSH_COMPLETE;
455}
456
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500457static inline cycles_t
458sec_2_cycles(unsigned long sec)
459{
460 unsigned long ns;
461 cycles_t cyc;
462
463 ns = sec * 1000000000;
464 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
465 return cyc;
466}
467
468/*
469 * conditionally add 1 to *v, unless *v is >= u
470 * return 0 if we cannot add 1 to *v because it is >= u
471 * return 1 if we can add 1 to *v because it is < u
472 * the add is atomic
473 *
474 * This is close to atomic_add_unless(), but this allows the 'u' value
475 * to be lowered below the current 'v'. atomic_add_unless can only stop
476 * on equal.
477 */
478static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
479{
480 spin_lock(lock);
481 if (atomic_read(v) >= u) {
482 spin_unlock(lock);
483 return 0;
484 }
485 atomic_inc(v);
486 spin_unlock(lock);
487 return 1;
488}
489
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500490/*
491 * Completions are taking a very long time due to a congested numalink
492 * network.
493 */
494static void
495disable_for_congestion(struct bau_control *bcp, struct ptc_stats *stat)
496{
497 int tcpu;
498 struct bau_control *tbcp;
499
500 /* let only one cpu do this disabling */
501 spin_lock(&disable_lock);
502 if (!baudisabled && bcp->period_requests &&
503 ((bcp->period_time / bcp->period_requests) > congested_cycles)) {
504 /* it becomes this cpu's job to turn on the use of the
505 BAU again */
506 baudisabled = 1;
507 bcp->set_bau_off = 1;
508 bcp->set_bau_on_time = get_cycles() +
509 sec_2_cycles(bcp->congested_period);
510 stat->s_bau_disabled++;
511 for_each_present_cpu(tcpu) {
512 tbcp = &per_cpu(bau_control, tcpu);
513 tbcp->baudisabled = 1;
514 }
515 }
516 spin_unlock(&disable_lock);
517}
518
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500519/**
520 * uv_flush_send_and_wait
521 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500522 * Send a broadcast and wait for it to complete.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500523 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500524 * The flush_mask contains the cpus the broadcast is to be sent to, plus
525 * cpus that are on the local uvhub.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500526 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500527 * Returns NULL if all flushing represented in the mask was done. The mask
528 * is zeroed.
Tejun Heobdbcdd42009-01-21 17:26:06 +0900529 * Returns @flush_mask if some remote flushing remains to be done. The
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500530 * mask will have some bits still set, representing any cpus on the local
531 * uvhub (not current cpu) and any on remote uvhubs if the broadcast failed.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500532 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500533const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc,
534 struct cpumask *flush_mask,
535 struct bau_control *bcp)
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500536{
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500537 int right_shift;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500538 int uvhub;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200539 int bit;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500540 int completion_status = 0;
541 int seq_number = 0;
542 long try = 0;
543 int cpu = bcp->uvhub_cpu;
544 int this_cpu = bcp->cpu;
545 int this_uvhub = bcp->uvhub;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500546 unsigned long mmr_offset;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200547 unsigned long index;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500548 cycles_t time1;
549 cycles_t time2;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500550 cycles_t elapsed;
Cliff Wickman712157a2010-06-02 16:22:02 -0500551 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500552 struct bau_control *smaster = bcp->socket_master;
553 struct bau_control *hmaster = bcp->uvhub_master;
554
555 /*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500556 * Spin here while there are hmaster->max_bau_concurrent or more active
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500557 * descriptors. This is the per-uvhub 'throttle'.
558 */
559 if (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
560 &hmaster->active_descriptor_count,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500561 hmaster->max_bau_concurrent)) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500562 stat->s_throttles++;
563 do {
564 cpu_relax();
565 } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
566 &hmaster->active_descriptor_count,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500567 hmaster->max_bau_concurrent));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500568 }
569
570 while (hmaster->uvhub_quiesce)
571 cpu_relax();
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500572
573 if (cpu < UV_CPUS_PER_ACT_STATUS) {
574 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
575 right_shift = cpu * UV_ACT_STATUS_SIZE;
576 } else {
577 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
578 right_shift =
579 ((cpu - UV_CPUS_PER_ACT_STATUS) * UV_ACT_STATUS_SIZE);
580 }
581 time1 = get_cycles();
582 do {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500583 if (try == 0) {
Cliff Wickman7fba1bc2010-06-02 16:22:02 -0500584 bau_desc->header.msg_type = MSG_REGULAR;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500585 seq_number = bcp->message_number++;
586 } else {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500587 bau_desc->header.msg_type = MSG_RETRY;
588 stat->s_retry_messages++;
589 }
590 bau_desc->header.sequence = seq_number;
Ingo Molnardc163a42008-06-18 14:15:43 +0200591 index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) |
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500592 bcp->uvhub_cpu;
593 bcp->send_message = get_cycles();
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500594
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500595 uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
596
597 try++;
598 completion_status = uv_wait_completion(bau_desc, mmr_offset,
599 right_shift, this_cpu, bcp, smaster, try);
600
601 if (completion_status == FLUSH_RETRY_PLUGGED) {
602 /*
603 * Our retries may be blocked by all destination swack
604 * resources being consumed, and a timeout pending. In
605 * that case hardware immediately returns the ERROR
606 * that looks like a destination timeout.
607 */
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500608 udelay(bcp->plugged_delay);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500609 bcp->plugged_tries++;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500610 if (bcp->plugged_tries >= bcp->plugsb4reset) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500611 bcp->plugged_tries = 0;
612 quiesce_local_uvhub(hmaster);
613 spin_lock(&hmaster->queue_lock);
614 uv_reset_with_ipi(&bau_desc->distribution,
615 this_cpu);
616 spin_unlock(&hmaster->queue_lock);
617 end_uvhub_quiesce(hmaster);
618 bcp->ipi_attempts++;
619 stat->s_resets_plug++;
620 }
621 } else if (completion_status == FLUSH_RETRY_TIMEOUT) {
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500622 hmaster->max_bau_concurrent = 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500623 bcp->timeout_tries++;
624 udelay(TIMEOUT_DELAY);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500625 if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500626 bcp->timeout_tries = 0;
627 quiesce_local_uvhub(hmaster);
628 spin_lock(&hmaster->queue_lock);
629 uv_reset_with_ipi(&bau_desc->distribution,
630 this_cpu);
631 spin_unlock(&hmaster->queue_lock);
632 end_uvhub_quiesce(hmaster);
633 bcp->ipi_attempts++;
634 stat->s_resets_timeout++;
635 }
636 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500637 if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500638 bcp->ipi_attempts = 0;
639 completion_status = FLUSH_GIVEUP;
640 break;
641 }
642 cpu_relax();
643 } while ((completion_status == FLUSH_RETRY_PLUGGED) ||
644 (completion_status == FLUSH_RETRY_TIMEOUT));
645 time2 = get_cycles();
646
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500647 bcp->plugged_tries = 0;
648 bcp->timeout_tries = 0;
649
650 if ((completion_status == FLUSH_COMPLETE) &&
651 (bcp->conseccompletes > bcp->complete_threshold) &&
652 (hmaster->max_bau_concurrent <
653 hmaster->max_bau_concurrent_constant))
654 hmaster->max_bau_concurrent++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500655
656 /*
657 * hold any cpu not timing out here; no other cpu currently held by
658 * the 'throttle' should enter the activation code
659 */
660 while (hmaster->uvhub_quiesce)
661 cpu_relax();
662 atomic_dec(&hmaster->active_descriptor_count);
663
664 /* guard against cycles wrap */
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500665 if (time2 > time1) {
666 elapsed = time2 - time1;
667 stat->s_time += elapsed;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500668 if ((completion_status == FLUSH_COMPLETE) && (try == 1)) {
669 bcp->period_requests++;
670 bcp->period_time += elapsed;
671 if ((elapsed > congested_cycles) &&
672 (bcp->period_requests > bcp->congested_reps)) {
673 disable_for_congestion(bcp, stat);
674 }
675 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500676 } else
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500677 stat->s_requestor--; /* don't count this one */
678 if (completion_status == FLUSH_COMPLETE && try > 1)
679 stat->s_retriesok++;
680 else if (completion_status == FLUSH_GIVEUP) {
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500681 /*
682 * Cause the caller to do an IPI-style TLB shootdown on
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500683 * the target cpu's, all of which are still in the mask.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500684 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500685 stat->s_giveup++;
Cliff Wickman2749ebe2009-01-29 15:35:26 -0600686 return flush_mask;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500687 }
688
689 /*
690 * Success, so clear the remote cpu's from the mask so we don't
691 * use the IPI method of shootdown on them.
692 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900693 for_each_cpu(bit, flush_mask) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500694 uvhub = uv_cpu_to_blade_id(bit);
695 if (uvhub == this_uvhub)
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500696 continue;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900697 cpumask_clear_cpu(bit, flush_mask);
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500698 }
Tejun Heobdbcdd42009-01-21 17:26:06 +0900699 if (!cpumask_empty(flush_mask))
700 return flush_mask;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500701
Tejun Heobdbcdd42009-01-21 17:26:06 +0900702 return NULL;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500703}
704
Cliff Wickman18129242008-06-02 08:56:14 -0500705/**
706 * uv_flush_tlb_others - globally purge translation cache of a virtual
707 * address or all TLB's
Tejun Heobdbcdd42009-01-21 17:26:06 +0900708 * @cpumask: mask of all cpu's in which the address is to be removed
Cliff Wickman18129242008-06-02 08:56:14 -0500709 * @mm: mm_struct containing virtual address range
710 * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
Tejun Heobdbcdd42009-01-21 17:26:06 +0900711 * @cpu: the current cpu
Cliff Wickman18129242008-06-02 08:56:14 -0500712 *
713 * This is the entry point for initiating any UV global TLB shootdown.
714 *
715 * Purges the translation caches of all specified processors of the given
716 * virtual address, or purges all TLB's on specified processors.
717 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900718 * The caller has derived the cpumask from the mm_struct. This function
719 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
Cliff Wickman18129242008-06-02 08:56:14 -0500720 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500721 * The cpumask is converted into a uvhubmask of the uvhubs containing
722 * those cpus.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500723 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900724 * Note that this function should be called with preemption disabled.
725 *
726 * Returns NULL if all remote flushing was done.
727 * Returns pointer to cpumask if some remote flushing remains to be
728 * done. The returned pointer is valid till preemption is re-enabled.
Cliff Wickman18129242008-06-02 08:56:14 -0500729 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900730const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
731 struct mm_struct *mm,
732 unsigned long va, unsigned int cpu)
Cliff Wickman18129242008-06-02 08:56:14 -0500733{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500734 int remotes;
735 int tcpu;
736 int uvhub;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500737 int locals = 0;
Ingo Molnardc163a42008-06-18 14:15:43 +0200738 struct bau_desc *bau_desc;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500739 struct cpumask *flush_mask;
740 struct ptc_stats *stat;
741 struct bau_control *bcp;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500742 struct bau_control *tbcp;
Cliff Wickman18129242008-06-02 08:56:14 -0500743
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500744 /* kernel was booted 'nobau' */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500745 if (nobau)
746 return cpumask;
747
748 bcp = &per_cpu(bau_control, cpu);
Cliff Wickman712157a2010-06-02 16:22:02 -0500749 stat = bcp->statp;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500750
751 /* bau was disabled due to slow response */
752 if (bcp->baudisabled) {
753 /* the cpu that disabled it must re-enable it */
754 if (bcp->set_bau_off) {
755 if (get_cycles() >= bcp->set_bau_on_time) {
756 stat->s_bau_reenabled++;
757 baudisabled = 0;
758 for_each_present_cpu(tcpu) {
759 tbcp = &per_cpu(bau_control, tcpu);
760 tbcp->baudisabled = 0;
761 tbcp->period_requests = 0;
762 tbcp->period_time = 0;
763 }
764 }
765 }
766 return cpumask;
767 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500768
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500769 /*
770 * Each sending cpu has a per-cpu mask which it fills from the caller's
771 * cpu mask. Only remote cpus are converted to uvhubs and copied.
772 */
773 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
774 /*
775 * copy cpumask to flush_mask, removing current cpu
776 * (current cpu should already have been flushed by the caller and
777 * should never be returned if we return flush_mask)
778 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900779 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500780 if (cpu_isset(cpu, *cpumask))
781 locals++; /* current cpu was targeted */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900782
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500783 bau_desc = bcp->descriptor_base;
784 bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu;
Cliff Wickman18129242008-06-02 08:56:14 -0500785
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500786 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
787 remotes = 0;
788 for_each_cpu(tcpu, flush_mask) {
789 uvhub = uv_cpu_to_blade_id(tcpu);
790 if (uvhub == bcp->uvhub) {
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500791 locals++;
Cliff Wickman18129242008-06-02 08:56:14 -0500792 continue;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500793 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500794 bau_uvhub_set(uvhub, &bau_desc->distribution);
795 remotes++;
Cliff Wickman18129242008-06-02 08:56:14 -0500796 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500797 if (remotes == 0) {
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500798 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500799 * No off_hub flushing; return status for local hub.
800 * Return the caller's mask if all were local (the current
801 * cpu may be in that mask).
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500802 */
803 if (locals)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500804 return cpumask;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500805 else
Tejun Heobdbcdd42009-01-21 17:26:06 +0900806 return NULL;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500807 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500808 stat->s_requestor++;
809 stat->s_ntargcpu += remotes;
810 remotes = bau_uvhub_weight(&bau_desc->distribution);
811 stat->s_ntarguvhub += remotes;
812 if (remotes >= 16)
813 stat->s_ntarguvhub16++;
814 else if (remotes >= 8)
815 stat->s_ntarguvhub8++;
816 else if (remotes >= 4)
817 stat->s_ntarguvhub4++;
818 else if (remotes >= 2)
819 stat->s_ntarguvhub2++;
820 else
821 stat->s_ntarguvhub1++;
Cliff Wickman18129242008-06-02 08:56:14 -0500822
823 bau_desc->payload.address = va;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900824 bau_desc->payload.sending_cpu = cpu;
Cliff Wickman18129242008-06-02 08:56:14 -0500825
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500826 /*
827 * uv_flush_send_and_wait returns null if all cpu's were messaged, or
828 * the adjusted flush_mask if any cpu's were not messaged.
829 */
830 return uv_flush_send_and_wait(bau_desc, flush_mask, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500831}
832
833/*
834 * The BAU message interrupt comes here. (registered by set_intr_gate)
835 * See entry_64.S
836 *
837 * We received a broadcast assist message.
838 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500839 * Interrupts are disabled; this interrupt could represent
Cliff Wickman18129242008-06-02 08:56:14 -0500840 * the receipt of several messages.
841 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500842 * All cores/threads on this hub get this interrupt.
843 * The last one to see it does the software ack.
Cliff Wickman18129242008-06-02 08:56:14 -0500844 * (the resource will not be freed until noninterruptable cpus see this
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500845 * interrupt; hardware may timeout the s/w ack and reply ERROR)
Cliff Wickman18129242008-06-02 08:56:14 -0500846 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500847void uv_bau_message_interrupt(struct pt_regs *regs)
Cliff Wickman18129242008-06-02 08:56:14 -0500848{
Cliff Wickman18129242008-06-02 08:56:14 -0500849 int count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500850 cycles_t time_start;
851 struct bau_payload_queue_entry *msg;
852 struct bau_control *bcp;
853 struct ptc_stats *stat;
854 struct msg_desc msgdesc;
Cliff Wickman18129242008-06-02 08:56:14 -0500855
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500856 time_start = get_cycles();
857 bcp = &per_cpu(bau_control, smp_processor_id());
Cliff Wickman712157a2010-06-02 16:22:02 -0500858 stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500859 msgdesc.va_queue_first = bcp->va_queue_first;
860 msgdesc.va_queue_last = bcp->va_queue_last;
861 msg = bcp->bau_msg_head;
Cliff Wickman18129242008-06-02 08:56:14 -0500862 while (msg->sw_ack_vector) {
863 count++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500864 msgdesc.msg_slot = msg - msgdesc.va_queue_first;
865 msgdesc.sw_ack_slot = ffs(msg->sw_ack_vector) - 1;
866 msgdesc.msg = msg;
867 uv_bau_process_message(&msgdesc, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500868 msg++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500869 if (msg > msgdesc.va_queue_last)
870 msg = msgdesc.va_queue_first;
871 bcp->bau_msg_head = msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500872 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500873 stat->d_time += (get_cycles() - time_start);
Cliff Wickman18129242008-06-02 08:56:14 -0500874 if (!count)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500875 stat->d_nomsg++;
Cliff Wickman18129242008-06-02 08:56:14 -0500876 else if (count > 1)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500877 stat->d_multmsg++;
878 ack_APIC_irq();
Cliff Wickman18129242008-06-02 08:56:14 -0500879}
880
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500881/*
882 * uv_enable_timeouts
883 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500884 * Each target uvhub (i.e. a uvhub that has no cpu's) needs to have
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500885 * shootdown message timeouts enabled. The timeout does not cause
886 * an interrupt, but causes an error message to be returned to
887 * the sender.
888 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500889static void uv_enable_timeouts(void)
Cliff Wickman18129242008-06-02 08:56:14 -0500890{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500891 int uvhub;
892 int nuvhubs;
Cliff Wickman18129242008-06-02 08:56:14 -0500893 int pnode;
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500894 unsigned long mmr_image;
Cliff Wickman18129242008-06-02 08:56:14 -0500895
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500896 nuvhubs = uv_num_possible_blades();
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500897
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500898 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
899 if (!uv_blade_nr_possible_cpus(uvhub))
Cliff Wickman18129242008-06-02 08:56:14 -0500900 continue;
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500901
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500902 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500903 mmr_image =
904 uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL);
905 /*
906 * Set the timeout period and then lock it in, in three
907 * steps; captures and locks in the period.
908 *
909 * To program the period, the SOFT_ACK_MODE must be off.
910 */
911 mmr_image &= ~((unsigned long)1 <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600912 UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500913 uv_write_global_mmr64
914 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
915 /*
916 * Set the 4-bit period.
917 */
918 mmr_image &= ~((unsigned long)0xf <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600919 UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500920 mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600921 UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500922 uv_write_global_mmr64
923 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
924 /*
925 * Subsequent reversals of the timebase bit (3) cause an
926 * immediate timeout of one or all INTD resources as
927 * indicated in bits 2:0 (7 causes all of them to timeout).
928 */
929 mmr_image |= ((unsigned long)1 <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600930 UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500931 uv_write_global_mmr64
932 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
Cliff Wickman18129242008-06-02 08:56:14 -0500933 }
Cliff Wickman18129242008-06-02 08:56:14 -0500934}
935
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500936static void *uv_ptc_seq_start(struct seq_file *file, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -0500937{
938 if (*offset < num_possible_cpus())
939 return offset;
940 return NULL;
941}
942
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500943static void *uv_ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -0500944{
945 (*offset)++;
946 if (*offset < num_possible_cpus())
947 return offset;
948 return NULL;
949}
950
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500951static void uv_ptc_seq_stop(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -0500952{
953}
954
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500955static inline unsigned long long
Cliff Wickman12a66112010-06-02 16:22:01 -0500956microsec_2_cycles(unsigned long microsec)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500957{
958 unsigned long ns;
959 unsigned long long cyc;
960
Cliff Wickman12a66112010-06-02 16:22:01 -0500961 ns = microsec * 1000;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500962 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
963 return cyc;
964}
965
Cliff Wickman18129242008-06-02 08:56:14 -0500966/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500967 * Display the statistics thru /proc.
968 * 'data' points to the cpu number
Cliff Wickman18129242008-06-02 08:56:14 -0500969 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500970static int uv_ptc_seq_show(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -0500971{
972 struct ptc_stats *stat;
973 int cpu;
974
975 cpu = *(loff_t *)data;
976
977 if (!cpu) {
978 seq_printf(file,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500979 "# cpu sent stime numuvhubs numuvhubs16 numuvhubs8 ");
Cliff Wickman18129242008-06-02 08:56:14 -0500980 seq_printf(file,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500981 "numuvhubs4 numuvhubs2 numuvhubs1 numcpus dto ");
982 seq_printf(file,
983 "retries rok resetp resett giveup sto bz throt ");
984 seq_printf(file,
985 "sw_ack recv rtime all ");
986 seq_printf(file,
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500987 "one mult none retry canc nocan reset rcan ");
988 seq_printf(file,
989 "disable enable\n");
Cliff Wickman18129242008-06-02 08:56:14 -0500990 }
991 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
992 stat = &per_cpu(ptcstats, cpu);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500993 /* source side statistics */
994 seq_printf(file,
995 "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
996 cpu, stat->s_requestor, cycles_2_us(stat->s_time),
997 stat->s_ntarguvhub, stat->s_ntarguvhub16,
998 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
999 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
1000 stat->s_ntargcpu, stat->s_dtimeout);
1001 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
1002 stat->s_retry_messages, stat->s_retriesok,
1003 stat->s_resets_plug, stat->s_resets_timeout,
1004 stat->s_giveup, stat->s_stimeout,
1005 stat->s_busy, stat->s_throttles);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001006
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001007 /* destination side statistics */
1008 seq_printf(file,
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001009 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
Cliff Wickman9674f352009-04-03 08:34:05 -05001010 uv_read_global_mmr64(uv_cpu_to_pnode(cpu),
Cliff Wickman18129242008-06-02 08:56:14 -05001011 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001012 stat->d_requestee, cycles_2_us(stat->d_time),
1013 stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
1014 stat->d_nomsg, stat->d_retries, stat->d_canceled,
1015 stat->d_nocanceled, stat->d_resets,
1016 stat->d_rcanceled);
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001017 seq_printf(file, "%ld %ld\n",
1018 stat->s_bau_disabled, stat->s_bau_reenabled);
Cliff Wickman18129242008-06-02 08:56:14 -05001019 }
1020
1021 return 0;
1022}
1023
1024/*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001025 * Display the tunables thru debugfs
1026 */
1027static ssize_t tunables_read(struct file *file, char __user *userbuf,
1028 size_t count, loff_t *ppos)
1029{
1030 char buf[300];
1031 int ret;
1032
1033 ret = snprintf(buf, 300, "%s %s %s\n%d %d %d %d %d %d %d %d %d\n",
1034 "max_bau_concurrent plugged_delay plugsb4reset",
1035 "timeoutsb4reset ipi_reset_limit complete_threshold",
1036 "congested_response_us congested_reps congested_period",
1037 max_bau_concurrent, plugged_delay, plugsb4reset,
1038 timeoutsb4reset, ipi_reset_limit, complete_threshold,
1039 congested_response_us, congested_reps, congested_period);
1040
1041 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
1042}
1043
1044/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001045 * -1: resetf the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001046 * 0: display meaning of the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001047 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001048static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001049 size_t count, loff_t *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001050{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001051 int cpu;
1052 long input_arg;
Cliff Wickman18129242008-06-02 08:56:14 -05001053 char optstr[64];
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001054 struct ptc_stats *stat;
Cliff Wickman18129242008-06-02 08:56:14 -05001055
Cliff Wickmane7eb8722008-06-23 08:32:25 -05001056 if (count == 0 || count > sizeof(optstr))
Cliff Wickmancef53272008-06-19 11:16:24 -05001057 return -EINVAL;
Cliff Wickman18129242008-06-02 08:56:14 -05001058 if (copy_from_user(optstr, user, count))
1059 return -EFAULT;
1060 optstr[count - 1] = '\0';
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001061 if (strict_strtol(optstr, 10, &input_arg) < 0) {
Cliff Wickman18129242008-06-02 08:56:14 -05001062 printk(KERN_DEBUG "%s is invalid\n", optstr);
1063 return -EINVAL;
1064 }
1065
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001066 if (input_arg == 0) {
Cliff Wickman18129242008-06-02 08:56:14 -05001067 printk(KERN_DEBUG "# cpu: cpu number\n");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001068 printk(KERN_DEBUG "Sender statistics:\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001069 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001070 "sent: number of shootdown messages sent\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001071 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001072 "stime: time spent sending messages\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001073 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001074 "numuvhubs: number of hubs targeted with shootdown\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001075 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001076 "numuvhubs16: number times 16 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001077 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001078 "numuvhubs8: number times 8 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001079 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001080 "numuvhubs4: number times 4 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001081 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001082 "numuvhubs2: number times 2 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001083 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001084 "numuvhubs1: number times 1 hub targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001085 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001086 "numcpus: number of cpus targeted with shootdown\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001087 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001088 "dto: number of destination timeouts\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001089 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001090 "retries: destination timeout retries sent\n");
1091 printk(KERN_DEBUG
1092 "rok: : destination timeouts successfully retried\n");
1093 printk(KERN_DEBUG
1094 "resetp: ipi-style resource resets for plugs\n");
1095 printk(KERN_DEBUG
1096 "resett: ipi-style resource resets for timeouts\n");
1097 printk(KERN_DEBUG
1098 "giveup: fall-backs to ipi-style shootdowns\n");
1099 printk(KERN_DEBUG
1100 "sto: number of source timeouts\n");
1101 printk(KERN_DEBUG
1102 "bz: number of stay-busy's\n");
1103 printk(KERN_DEBUG
1104 "throt: number times spun in throttle\n");
1105 printk(KERN_DEBUG "Destination side statistics:\n");
1106 printk(KERN_DEBUG
1107 "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
1108 printk(KERN_DEBUG
1109 "recv: shootdown messages received\n");
1110 printk(KERN_DEBUG
1111 "rtime: time spent processing messages\n");
1112 printk(KERN_DEBUG
1113 "all: shootdown all-tlb messages\n");
1114 printk(KERN_DEBUG
1115 "one: shootdown one-tlb messages\n");
1116 printk(KERN_DEBUG
1117 "mult: interrupts that found multiple messages\n");
1118 printk(KERN_DEBUG
1119 "none: interrupts that found no messages\n");
1120 printk(KERN_DEBUG
1121 "retry: number of retry messages processed\n");
1122 printk(KERN_DEBUG
1123 "canc: number messages canceled by retries\n");
1124 printk(KERN_DEBUG
1125 "nocan: number retries that found nothing to cancel\n");
1126 printk(KERN_DEBUG
1127 "reset: number of ipi-style reset requests processed\n");
1128 printk(KERN_DEBUG
1129 "rcan: number messages canceled by reset requests\n");
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001130 printk(KERN_DEBUG
1131 "disable: number times use of the BAU was disabled\n");
1132 printk(KERN_DEBUG
1133 "enable: number times use of the BAU was re-enabled\n");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001134 } else if (input_arg == -1) {
1135 for_each_present_cpu(cpu) {
1136 stat = &per_cpu(ptcstats, cpu);
1137 memset(stat, 0, sizeof(struct ptc_stats));
1138 }
Cliff Wickman18129242008-06-02 08:56:14 -05001139 }
1140
1141 return count;
1142}
1143
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001144static int local_atoi(const char *name)
1145{
1146 int val = 0;
1147
1148 for (;; name++) {
1149 switch (*name) {
1150 case '0' ... '9':
1151 val = 10*val+(*name-'0');
1152 break;
1153 default:
1154 return val;
1155 }
1156 }
1157}
1158
1159/*
1160 * set the tunables
1161 * 0 values reset them to defaults
1162 */
1163static ssize_t tunables_write(struct file *file, const char __user *user,
1164 size_t count, loff_t *data)
1165{
1166 int cpu;
1167 int cnt = 0;
1168 int val;
1169 char *p;
1170 char *q;
1171 char instr[64];
1172 struct bau_control *bcp;
1173
1174 if (count == 0 || count > sizeof(instr)-1)
1175 return -EINVAL;
1176 if (copy_from_user(instr, user, count))
1177 return -EFAULT;
1178
1179 instr[count] = '\0';
1180 /* count the fields */
1181 p = instr + strspn(instr, WHITESPACE);
1182 q = p;
1183 for (; *p; p = q + strspn(q, WHITESPACE)) {
1184 q = p + strcspn(p, WHITESPACE);
1185 cnt++;
1186 if (q == p)
1187 break;
1188 }
1189 if (cnt != 9) {
1190 printk(KERN_INFO "bau tunable error: should be 9 numbers\n");
1191 return -EINVAL;
1192 }
1193
1194 p = instr + strspn(instr, WHITESPACE);
1195 q = p;
1196 for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
1197 q = p + strcspn(p, WHITESPACE);
1198 val = local_atoi(p);
1199 switch (cnt) {
1200 case 0:
1201 if (val == 0) {
1202 max_bau_concurrent = MAX_BAU_CONCURRENT;
1203 max_bau_concurrent_constant =
1204 MAX_BAU_CONCURRENT;
1205 continue;
1206 }
1207 bcp = &per_cpu(bau_control, smp_processor_id());
1208 if (val < 1 || val > bcp->cpus_in_uvhub) {
1209 printk(KERN_DEBUG
1210 "Error: BAU max concurrent %d is invalid\n",
1211 val);
1212 return -EINVAL;
1213 }
1214 max_bau_concurrent = val;
1215 max_bau_concurrent_constant = val;
1216 continue;
1217 case 1:
1218 if (val == 0)
1219 plugged_delay = PLUGGED_DELAY;
1220 else
1221 plugged_delay = val;
1222 continue;
1223 case 2:
1224 if (val == 0)
1225 plugsb4reset = PLUGSB4RESET;
1226 else
1227 plugsb4reset = val;
1228 continue;
1229 case 3:
1230 if (val == 0)
1231 timeoutsb4reset = TIMEOUTSB4RESET;
1232 else
1233 timeoutsb4reset = val;
1234 continue;
1235 case 4:
1236 if (val == 0)
1237 ipi_reset_limit = IPI_RESET_LIMIT;
1238 else
1239 ipi_reset_limit = val;
1240 continue;
1241 case 5:
1242 if (val == 0)
1243 complete_threshold = COMPLETE_THRESHOLD;
1244 else
1245 complete_threshold = val;
1246 continue;
1247 case 6:
1248 if (val == 0)
1249 congested_response_us = CONGESTED_RESPONSE_US;
1250 else
1251 congested_response_us = val;
1252 continue;
1253 case 7:
1254 if (val == 0)
1255 congested_reps = CONGESTED_REPS;
1256 else
1257 congested_reps = val;
1258 continue;
1259 case 8:
1260 if (val == 0)
1261 congested_period = CONGESTED_PERIOD;
1262 else
1263 congested_period = val;
1264 continue;
1265 }
1266 if (q == p)
1267 break;
1268 }
1269 for_each_present_cpu(cpu) {
1270 bcp = &per_cpu(bau_control, cpu);
1271 bcp->max_bau_concurrent = max_bau_concurrent;
1272 bcp->max_bau_concurrent_constant = max_bau_concurrent;
1273 bcp->plugged_delay = plugged_delay;
1274 bcp->plugsb4reset = plugsb4reset;
1275 bcp->timeoutsb4reset = timeoutsb4reset;
1276 bcp->ipi_reset_limit = ipi_reset_limit;
1277 bcp->complete_threshold = complete_threshold;
1278 bcp->congested_response_us = congested_response_us;
1279 bcp->congested_reps = congested_reps;
1280 bcp->congested_period = congested_period;
1281 }
1282 return count;
1283}
1284
Cliff Wickman18129242008-06-02 08:56:14 -05001285static const struct seq_operations uv_ptc_seq_ops = {
Ingo Molnardc163a42008-06-18 14:15:43 +02001286 .start = uv_ptc_seq_start,
1287 .next = uv_ptc_seq_next,
1288 .stop = uv_ptc_seq_stop,
1289 .show = uv_ptc_seq_show
Cliff Wickman18129242008-06-02 08:56:14 -05001290};
1291
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001292static int uv_ptc_proc_open(struct inode *inode, struct file *file)
Cliff Wickman18129242008-06-02 08:56:14 -05001293{
1294 return seq_open(file, &uv_ptc_seq_ops);
1295}
1296
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001297static int tunables_open(struct inode *inode, struct file *file)
1298{
1299 return 0;
1300}
1301
Cliff Wickman18129242008-06-02 08:56:14 -05001302static const struct file_operations proc_uv_ptc_operations = {
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001303 .open = uv_ptc_proc_open,
1304 .read = seq_read,
1305 .write = uv_ptc_proc_write,
1306 .llseek = seq_lseek,
1307 .release = seq_release,
Cliff Wickman18129242008-06-02 08:56:14 -05001308};
1309
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001310static const struct file_operations tunables_fops = {
1311 .open = tunables_open,
1312 .read = tunables_read,
1313 .write = tunables_write,
1314};
1315
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001316static int __init uv_ptc_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001317{
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001318 struct proc_dir_entry *proc_uv_ptc;
Cliff Wickman18129242008-06-02 08:56:14 -05001319
1320 if (!is_uv_system())
1321 return 0;
1322
Alexey Dobriyan10f02d112009-08-23 23:17:27 +04001323 proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
1324 &proc_uv_ptc_operations);
Cliff Wickman18129242008-06-02 08:56:14 -05001325 if (!proc_uv_ptc) {
1326 printk(KERN_ERR "unable to create %s proc entry\n",
1327 UV_PTC_BASENAME);
1328 return -EINVAL;
1329 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001330
1331 tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
1332 if (!tunables_dir) {
1333 printk(KERN_ERR "unable to create debugfs directory %s\n",
1334 UV_BAU_TUNABLES_DIR);
1335 return -EINVAL;
1336 }
1337 tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
1338 tunables_dir, NULL, &tunables_fops);
1339 if (!tunables_file) {
1340 printk(KERN_ERR "unable to create debugfs file %s\n",
1341 UV_BAU_TUNABLES_FILE);
1342 return -EINVAL;
1343 }
Cliff Wickman18129242008-06-02 08:56:14 -05001344 return 0;
1345}
1346
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001347/*
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001348 * initialize the sending side's sending buffers
1349 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001350static void
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001351uv_activation_descriptor_init(int node, int pnode)
1352{
1353 int i;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001354 int cpu;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001355 unsigned long pa;
1356 unsigned long m;
1357 unsigned long n;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001358 struct bau_desc *bau_desc;
1359 struct bau_desc *bd2;
1360 struct bau_control *bcp;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001361
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001362 /*
1363 * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001364 * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per uvhub
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001365 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001366 bau_desc = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)*
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001367 UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001368 BUG_ON(!bau_desc);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001369
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001370 pa = uv_gpa(bau_desc); /* need the real nasid*/
1371 n = pa >> uv_nshift;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001372 m = pa & uv_mmask;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001373
Cliff Wickman9c26f522009-06-24 09:41:59 -05001374 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE,
1375 (n << UV_DESC_BASE_PNODE_SHIFT | m));
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001376
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001377 /*
1378 * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each
1379 * cpu even though we only use the first one; one descriptor can
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001380 * describe a broadcast to 256 uv hubs.
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001381 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001382 for (i = 0, bd2 = bau_desc; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR);
1383 i++, bd2++) {
1384 memset(bd2, 0, sizeof(struct bau_desc));
1385 bd2->header.sw_ack_flag = 1;
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001386 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001387 * base_dest_nodeid is the nasid (pnode<<1) of the first uvhub
1388 * in the partition. The bit map will indicate uvhub numbers,
1389 * which are 0-N in a partition. Pnodes are unique system-wide.
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001390 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001391 bd2->header.base_dest_nodeid = uv_partition_base_pnode << 1;
1392 bd2->header.dest_subnodeid = 0x10; /* the LB */
1393 bd2->header.command = UV_NET_ENDPOINT_INTD;
1394 bd2->header.int_both = 1;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001395 /*
1396 * all others need to be set to zero:
1397 * fairness chaining multilevel count replied_to
1398 */
1399 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001400 for_each_present_cpu(cpu) {
1401 if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
1402 continue;
1403 bcp = &per_cpu(bau_control, cpu);
1404 bcp->descriptor_base = bau_desc;
1405 }
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001406}
1407
1408/*
1409 * initialize the destination side's receiving buffers
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001410 * entered for each uvhub in the partition
1411 * - node is first node (kernel memory notion) on the uvhub
1412 * - pnode is the uvhub's physical identifier
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001413 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001414static void
1415uv_payload_queue_init(int node, int pnode)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001416{
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001417 int pn;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001418 int cpu;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001419 char *cp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001420 unsigned long pa;
1421 struct bau_payload_queue_entry *pqp;
1422 struct bau_payload_queue_entry *pqp_malloc;
1423 struct bau_control *bcp;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001424
Ingo Molnardc163a42008-06-18 14:15:43 +02001425 pqp = (struct bau_payload_queue_entry *) kmalloc_node(
1426 (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry),
1427 GFP_KERNEL, node);
1428 BUG_ON(!pqp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001429 pqp_malloc = pqp;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001430
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001431 cp = (char *)pqp + 31;
1432 pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001433
1434 for_each_present_cpu(cpu) {
1435 if (pnode != uv_cpu_to_pnode(cpu))
1436 continue;
1437 /* for every cpu on this pnode: */
1438 bcp = &per_cpu(bau_control, cpu);
1439 bcp->va_queue_first = pqp;
1440 bcp->bau_msg_head = pqp;
1441 bcp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
1442 }
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001443 /*
1444 * need the pnode of where the memory was really allocated
1445 */
1446 pa = uv_gpa(pqp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001447 pn = pa >> uv_nshift;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001448 uv_write_global_mmr64(pnode,
1449 UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001450 ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) |
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001451 uv_physnodeaddr(pqp));
1452 uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
1453 uv_physnodeaddr(pqp));
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001454 uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
1455 (unsigned long)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001456 uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1)));
1457 /* in effect, all msg_type's are set to MSG_NOOP */
Ingo Molnardc163a42008-06-18 14:15:43 +02001458 memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE);
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001459}
1460
1461/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001462 * Initialization of each UV hub's structures
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001463 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001464static void __init uv_init_uvhub(int uvhub, int vector)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001465{
Cliff Wickman9674f352009-04-03 08:34:05 -05001466 int node;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001467 int pnode;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001468 unsigned long apicid;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001469
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001470 node = uvhub_to_first_node(uvhub);
1471 pnode = uv_blade_to_pnode(uvhub);
1472 uv_activation_descriptor_init(node, pnode);
1473 uv_payload_queue_init(node, pnode);
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001474 /*
1475 * the below initialization can't be in firmware because the
1476 * messaging IRQ will be determined by the OS
1477 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001478 apicid = uvhub_to_first_apicid(uvhub);
Cliff Wickmane38e2af2009-11-19 17:12:43 -06001479 uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001480 ((apicid << 32) | vector));
1481}
1482
1483/*
Cliff Wickman12a66112010-06-02 16:22:01 -05001484 * We will set BAU_MISC_CONTROL with a timeout period.
1485 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
1486 * So the destination timeout period has be be calculated from them.
1487 */
1488static int
1489calculate_destination_timeout(void)
1490{
1491 unsigned long mmr_image;
1492 int mult1;
1493 int mult2;
1494 int index;
1495 int base;
1496 int ret;
1497 unsigned long ts_ns;
1498
1499 mult1 = UV_INTD_SOFT_ACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
1500 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1501 index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
1502 mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
1503 mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
1504 base = timeout_base_ns[index];
1505 ts_ns = base * mult1 * mult2;
1506 ret = ts_ns / 1000;
1507 return ret;
1508}
1509
1510/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001511 * initialize the bau_control structure for each cpu
1512 */
1513static void uv_init_per_cpu(int nuvhubs)
1514{
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001515 int i;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001516 int cpu;
1517 int pnode;
1518 int uvhub;
1519 short socket = 0;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001520 unsigned short socket_mask;
1521 unsigned int uvhub_mask;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001522 struct bau_control *bcp;
1523 struct uvhub_desc *bdp;
1524 struct socket_desc *sdp;
1525 struct bau_control *hmaster = NULL;
1526 struct bau_control *smaster = NULL;
1527 struct socket_desc {
1528 short num_cpus;
1529 short cpu_number[16];
1530 };
1531 struct uvhub_desc {
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001532 unsigned short socket_mask;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001533 short num_cpus;
1534 short uvhub;
1535 short pnode;
1536 struct socket_desc socket[2];
1537 };
1538 struct uvhub_desc *uvhub_descs;
1539
Cliff Wickman12a66112010-06-02 16:22:01 -05001540 timeout_us = calculate_destination_timeout();
1541
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001542 uvhub_descs = (struct uvhub_desc *)
1543 kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1544 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
1545 for_each_present_cpu(cpu) {
1546 bcp = &per_cpu(bau_control, cpu);
1547 memset(bcp, 0, sizeof(struct bau_control));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001548 pnode = uv_cpu_hub_info(cpu)->pnode;
1549 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001550 uvhub_mask |= (1 << uvhub);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001551 bdp = &uvhub_descs[uvhub];
1552 bdp->num_cpus++;
1553 bdp->uvhub = uvhub;
1554 bdp->pnode = pnode;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001555 /* kludge: 'assuming' one node per socket, and assuming that
1556 disabling a socket just leaves a gap in node numbers */
1557 socket = (cpu_to_node(cpu) & 1);;
1558 bdp->socket_mask |= (1 << socket);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001559 sdp = &bdp->socket[socket];
1560 sdp->cpu_number[sdp->num_cpus] = cpu;
1561 sdp->num_cpus++;
1562 }
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001563 uvhub = 0;
1564 while (uvhub_mask) {
1565 if (!(uvhub_mask & 1))
1566 goto nexthub;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001567 bdp = &uvhub_descs[uvhub];
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001568 socket_mask = bdp->socket_mask;
1569 socket = 0;
1570 while (socket_mask) {
1571 if (!(socket_mask & 1))
1572 goto nextsocket;
1573 sdp = &bdp->socket[socket];
1574 for (i = 0; i < sdp->num_cpus; i++) {
1575 cpu = sdp->cpu_number[i];
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001576 bcp = &per_cpu(bau_control, cpu);
1577 bcp->cpu = cpu;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001578 if (i == 0) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001579 smaster = bcp;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001580 if (socket == 0)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001581 hmaster = bcp;
1582 }
1583 bcp->cpus_in_uvhub = bdp->num_cpus;
1584 bcp->cpus_in_socket = sdp->num_cpus;
1585 bcp->socket_master = smaster;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001586 bcp->uvhub = bdp->uvhub;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001587 bcp->uvhub_master = hmaster;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001588 bcp->uvhub_cpu = uv_cpu_hub_info(cpu)->
1589 blade_processor_id;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001590 }
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001591nextsocket:
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001592 socket++;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001593 socket_mask = (socket_mask >> 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001594 }
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001595nexthub:
1596 uvhub++;
1597 uvhub_mask = (uvhub_mask >> 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001598 }
1599 kfree(uvhub_descs);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001600 for_each_present_cpu(cpu) {
1601 bcp = &per_cpu(bau_control, cpu);
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001602 bcp->baudisabled = 0;
Cliff Wickman712157a2010-06-02 16:22:02 -05001603 bcp->statp = &per_cpu(ptcstats, cpu);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001604 /* time interval to catch a hardware stay-busy bug */
1605 bcp->timeout_interval = microsec_2_cycles(2*timeout_us);
1606 bcp->max_bau_concurrent = max_bau_concurrent;
1607 bcp->max_bau_concurrent_constant = max_bau_concurrent;
1608 bcp->plugged_delay = plugged_delay;
1609 bcp->plugsb4reset = plugsb4reset;
1610 bcp->timeoutsb4reset = timeoutsb4reset;
1611 bcp->ipi_reset_limit = ipi_reset_limit;
1612 bcp->complete_threshold = complete_threshold;
1613 bcp->congested_response_us = congested_response_us;
1614 bcp->congested_reps = congested_reps;
1615 bcp->congested_period = congested_period;
1616 }
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001617}
Cliff Wickman18129242008-06-02 08:56:14 -05001618
1619/*
1620 * Initialization of BAU-related structures
1621 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001622static int __init uv_bau_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001623{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001624 int uvhub;
1625 int pnode;
1626 int nuvhubs;
Rusty Russell2c74d662009-03-18 08:22:30 +10301627 int cur_cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001628 int vector;
1629 unsigned long mmr;
Cliff Wickman18129242008-06-02 08:56:14 -05001630
1631 if (!is_uv_system())
1632 return 0;
1633
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001634 if (nobau)
1635 return 0;
1636
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301637 for_each_possible_cpu(cur_cpu)
Yinghai Lueaa95842009-06-06 14:51:36 -07001638 zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu),
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301639 GFP_KERNEL, cpu_to_node(cur_cpu));
1640
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001641 uv_nshift = uv_hub_info->m_val;
Robin Holt036ed8b2009-10-15 17:40:00 -05001642 uv_mmask = (1UL << uv_hub_info->m_val) - 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001643 nuvhubs = uv_num_possible_blades();
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001644 spin_lock_init(&disable_lock);
1645 congested_cycles = microsec_2_cycles(congested_response_us);
Cliff Wickman9674f352009-04-03 08:34:05 -05001646
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001647 uv_init_per_cpu(nuvhubs);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001648
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001649 uv_partition_base_pnode = 0x7fffffff;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001650 for (uvhub = 0; uvhub < nuvhubs; uvhub++)
1651 if (uv_blade_nr_possible_cpus(uvhub) &&
1652 (uv_blade_to_pnode(uvhub) < uv_partition_base_pnode))
1653 uv_partition_base_pnode = uv_blade_to_pnode(uvhub);
Cliff Wickman9674f352009-04-03 08:34:05 -05001654
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001655 vector = UV_BAU_MESSAGE;
1656 for_each_possible_blade(uvhub)
1657 if (uv_blade_nr_possible_cpus(uvhub))
1658 uv_init_uvhub(uvhub, vector);
1659
Cliff Wickman18129242008-06-02 08:56:14 -05001660 uv_enable_timeouts();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001661 alloc_intr_gate(vector, uv_bau_message_intr1);
1662
1663 for_each_possible_blade(uvhub) {
1664 pnode = uv_blade_to_pnode(uvhub);
1665 /* INIT the bau */
1666 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL,
1667 ((unsigned long)1 << 63));
1668 mmr = 1; /* should be 1 to broadcast to both sockets */
1669 uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST, mmr);
1670 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001671
Cliff Wickman18129242008-06-02 08:56:14 -05001672 return 0;
1673}
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001674core_initcall(uv_bau_init);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001675fs_initcall(uv_ptc_init);