blob: 295a41122da12974e3b2c870e279cf82f6e8dcc5 [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 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 Wickmanb194b122008-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 Wickmanb194b122008-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 Wickmanb194b122008-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 Wickmanb194b122008-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 Wickmanb194b122008-06-12 08:23:48 -0500402{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500403 int relaxes = 0;
Cliff Wickmanb194b122008-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;
408 cycles_t timeout_time;
Cliff Wickman712157a2010-06-02 16:22:02 -0500409 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500410 struct bau_control *hmaster;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500411
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500412 hmaster = bcp->uvhub_master;
413 timeout_time = get_cycles() + bcp->timeout_interval;
414
415 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500416 while ((descriptor_status = (((unsigned long)
417 uv_read_local_mmr(mmr_offset) >>
418 right_shift) & UV_ACT_STATUS_MASK)) !=
419 DESC_STATUS_IDLE) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500420 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500421 * Our software ack messages may be blocked because there are
422 * no swack resources available. As long as none of them
423 * has timed out hardware will NACK our message and its
424 * state will stay IDLE.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500425 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500426 if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
427 stat->s_stimeout++;
428 return FLUSH_GIVEUP;
429 } else if (descriptor_status ==
430 DESC_STATUS_DESTINATION_TIMEOUT) {
431 stat->s_dtimeout++;
432 ttime = get_cycles();
433
434 /*
435 * Our retries may be blocked by all destination
436 * swack resources being consumed, and a timeout
437 * pending. In that case hardware returns the
438 * ERROR that looks like a destination timeout.
439 */
Cliff Wickman12a66112010-06-02 16:22:01 -0500440 if (cycles_2_us(ttime - bcp->send_message) <
441 timeout_us) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500442 bcp->conseccompletes = 0;
443 return FLUSH_RETRY_PLUGGED;
444 }
445
446 bcp->conseccompletes = 0;
447 return FLUSH_RETRY_TIMEOUT;
448 } else {
449 /*
450 * descriptor_status is still BUSY
451 */
452 cpu_relax();
453 relaxes++;
454 if (relaxes >= 10000) {
455 relaxes = 0;
456 if (get_cycles() > timeout_time) {
457 quiesce_local_uvhub(hmaster);
458
459 /* single-thread the register change */
460 spin_lock(&hmaster->masks_lock);
461 mmr = uv_read_local_mmr(mmr_offset);
462 mask = 0UL;
463 mask |= (3UL < right_shift);
464 mask = ~mask;
465 mmr &= mask;
466 uv_write_local_mmr(mmr_offset, mmr);
467 spin_unlock(&hmaster->masks_lock);
468 end_uvhub_quiesce(hmaster);
469 stat->s_busy++;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500470 return FLUSH_GIVEUP;
471 }
Cliff Wickmanb194b122008-06-12 08:23:48 -0500472 }
473 }
474 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500475 bcp->conseccompletes++;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500476 return FLUSH_COMPLETE;
477}
478
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500479static inline cycles_t
480sec_2_cycles(unsigned long sec)
481{
482 unsigned long ns;
483 cycles_t cyc;
484
485 ns = sec * 1000000000;
486 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
487 return cyc;
488}
489
490/*
491 * conditionally add 1 to *v, unless *v is >= u
492 * return 0 if we cannot add 1 to *v because it is >= u
493 * return 1 if we can add 1 to *v because it is < u
494 * the add is atomic
495 *
496 * This is close to atomic_add_unless(), but this allows the 'u' value
497 * to be lowered below the current 'v'. atomic_add_unless can only stop
498 * on equal.
499 */
500static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
501{
502 spin_lock(lock);
503 if (atomic_read(v) >= u) {
504 spin_unlock(lock);
505 return 0;
506 }
507 atomic_inc(v);
508 spin_unlock(lock);
509 return 1;
510}
511
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500512/*
513 * Completions are taking a very long time due to a congested numalink
514 * network.
515 */
516static void
517disable_for_congestion(struct bau_control *bcp, struct ptc_stats *stat)
518{
519 int tcpu;
520 struct bau_control *tbcp;
521
522 /* let only one cpu do this disabling */
523 spin_lock(&disable_lock);
524 if (!baudisabled && bcp->period_requests &&
525 ((bcp->period_time / bcp->period_requests) > congested_cycles)) {
526 /* it becomes this cpu's job to turn on the use of the
527 BAU again */
528 baudisabled = 1;
529 bcp->set_bau_off = 1;
530 bcp->set_bau_on_time = get_cycles() +
531 sec_2_cycles(bcp->congested_period);
532 stat->s_bau_disabled++;
533 for_each_present_cpu(tcpu) {
534 tbcp = &per_cpu(bau_control, tcpu);
535 tbcp->baudisabled = 1;
536 }
537 }
538 spin_unlock(&disable_lock);
539}
540
Cliff Wickmanb194b122008-06-12 08:23:48 -0500541/**
542 * uv_flush_send_and_wait
543 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500544 * Send a broadcast and wait for it to complete.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500545 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500546 * The flush_mask contains the cpus the broadcast is to be sent to, plus
547 * cpus that are on the local uvhub.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500548 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500549 * Returns NULL if all flushing represented in the mask was done. The mask
550 * is zeroed.
Tejun Heobdbcdd42009-01-21 17:26:06 +0900551 * Returns @flush_mask if some remote flushing remains to be done. The
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500552 * mask will have some bits still set, representing any cpus on the local
553 * uvhub (not current cpu) and any on remote uvhubs if the broadcast failed.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500554 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500555const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc,
556 struct cpumask *flush_mask,
557 struct bau_control *bcp)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500558{
Cliff Wickmanb194b122008-06-12 08:23:48 -0500559 int right_shift;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500560 int uvhub;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200561 int bit;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500562 int completion_status = 0;
563 int seq_number = 0;
564 long try = 0;
565 int cpu = bcp->uvhub_cpu;
566 int this_cpu = bcp->cpu;
567 int this_uvhub = bcp->uvhub;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500568 unsigned long mmr_offset;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200569 unsigned long index;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500570 cycles_t time1;
571 cycles_t time2;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500572 cycles_t elapsed;
Cliff Wickman712157a2010-06-02 16:22:02 -0500573 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500574 struct bau_control *smaster = bcp->socket_master;
575 struct bau_control *hmaster = bcp->uvhub_master;
576
577 /*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500578 * Spin here while there are hmaster->max_bau_concurrent or more active
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500579 * descriptors. This is the per-uvhub 'throttle'.
580 */
581 if (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
582 &hmaster->active_descriptor_count,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500583 hmaster->max_bau_concurrent)) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500584 stat->s_throttles++;
585 do {
586 cpu_relax();
587 } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
588 &hmaster->active_descriptor_count,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500589 hmaster->max_bau_concurrent));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500590 }
591
592 while (hmaster->uvhub_quiesce)
593 cpu_relax();
Cliff Wickmanb194b122008-06-12 08:23:48 -0500594
595 if (cpu < UV_CPUS_PER_ACT_STATUS) {
596 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
597 right_shift = cpu * UV_ACT_STATUS_SIZE;
598 } else {
599 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
600 right_shift =
601 ((cpu - UV_CPUS_PER_ACT_STATUS) * UV_ACT_STATUS_SIZE);
602 }
603 time1 = get_cycles();
604 do {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500605 /*
606 * Every message from any given cpu gets a unique message
607 * sequence number. But retries use that same number.
608 * Our message may have timed out at the destination because
609 * all sw-ack resources are in use and there is a timeout
610 * pending there. In that case, our last send never got
611 * placed into the queue and we need to persist until it
612 * does.
613 *
614 * Make any retry a type MSG_RETRY so that the destination will
615 * free any resource held by a previous message from this cpu.
616 */
617 if (try == 0) {
618 /* use message type set by the caller the first time */
619 seq_number = bcp->message_number++;
620 } else {
621 /* use RETRY type on all the rest; same sequence */
622 bau_desc->header.msg_type = MSG_RETRY;
623 stat->s_retry_messages++;
624 }
625 bau_desc->header.sequence = seq_number;
Ingo Molnardc163a42008-06-18 14:15:43 +0200626 index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) |
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500627 bcp->uvhub_cpu;
628 bcp->send_message = get_cycles();
Cliff Wickmanb194b122008-06-12 08:23:48 -0500629
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500630 uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
631
632 try++;
633 completion_status = uv_wait_completion(bau_desc, mmr_offset,
634 right_shift, this_cpu, bcp, smaster, try);
635
636 if (completion_status == FLUSH_RETRY_PLUGGED) {
637 /*
638 * Our retries may be blocked by all destination swack
639 * resources being consumed, and a timeout pending. In
640 * that case hardware immediately returns the ERROR
641 * that looks like a destination timeout.
642 */
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500643 udelay(bcp->plugged_delay);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500644 bcp->plugged_tries++;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500645 if (bcp->plugged_tries >= bcp->plugsb4reset) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500646 bcp->plugged_tries = 0;
647 quiesce_local_uvhub(hmaster);
648 spin_lock(&hmaster->queue_lock);
649 uv_reset_with_ipi(&bau_desc->distribution,
650 this_cpu);
651 spin_unlock(&hmaster->queue_lock);
652 end_uvhub_quiesce(hmaster);
653 bcp->ipi_attempts++;
654 stat->s_resets_plug++;
655 }
656 } else if (completion_status == FLUSH_RETRY_TIMEOUT) {
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500657 hmaster->max_bau_concurrent = 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500658 bcp->timeout_tries++;
659 udelay(TIMEOUT_DELAY);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500660 if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500661 bcp->timeout_tries = 0;
662 quiesce_local_uvhub(hmaster);
663 spin_lock(&hmaster->queue_lock);
664 uv_reset_with_ipi(&bau_desc->distribution,
665 this_cpu);
666 spin_unlock(&hmaster->queue_lock);
667 end_uvhub_quiesce(hmaster);
668 bcp->ipi_attempts++;
669 stat->s_resets_timeout++;
670 }
671 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500672 if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500673 bcp->ipi_attempts = 0;
674 completion_status = FLUSH_GIVEUP;
675 break;
676 }
677 cpu_relax();
678 } while ((completion_status == FLUSH_RETRY_PLUGGED) ||
679 (completion_status == FLUSH_RETRY_TIMEOUT));
680 time2 = get_cycles();
681
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500682 bcp->plugged_tries = 0;
683 bcp->timeout_tries = 0;
684
685 if ((completion_status == FLUSH_COMPLETE) &&
686 (bcp->conseccompletes > bcp->complete_threshold) &&
687 (hmaster->max_bau_concurrent <
688 hmaster->max_bau_concurrent_constant))
689 hmaster->max_bau_concurrent++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500690
691 /*
692 * hold any cpu not timing out here; no other cpu currently held by
693 * the 'throttle' should enter the activation code
694 */
695 while (hmaster->uvhub_quiesce)
696 cpu_relax();
697 atomic_dec(&hmaster->active_descriptor_count);
698
699 /* guard against cycles wrap */
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500700 if (time2 > time1) {
701 elapsed = time2 - time1;
702 stat->s_time += elapsed;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500703 if ((completion_status == FLUSH_COMPLETE) && (try == 1)) {
704 bcp->period_requests++;
705 bcp->period_time += elapsed;
706 if ((elapsed > congested_cycles) &&
707 (bcp->period_requests > bcp->congested_reps)) {
708 disable_for_congestion(bcp, stat);
709 }
710 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500711 } else
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500712 stat->s_requestor--; /* don't count this one */
713 if (completion_status == FLUSH_COMPLETE && try > 1)
714 stat->s_retriesok++;
715 else if (completion_status == FLUSH_GIVEUP) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500716 /*
717 * Cause the caller to do an IPI-style TLB shootdown on
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500718 * the target cpu's, all of which are still in the mask.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500719 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500720 stat->s_giveup++;
Cliff Wickman2749ebe2009-01-29 15:35:26 -0600721 return flush_mask;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500722 }
723
724 /*
725 * Success, so clear the remote cpu's from the mask so we don't
726 * use the IPI method of shootdown on them.
727 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900728 for_each_cpu(bit, flush_mask) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500729 uvhub = uv_cpu_to_blade_id(bit);
730 if (uvhub == this_uvhub)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500731 continue;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900732 cpumask_clear_cpu(bit, flush_mask);
Cliff Wickmanb194b122008-06-12 08:23:48 -0500733 }
Tejun Heobdbcdd42009-01-21 17:26:06 +0900734 if (!cpumask_empty(flush_mask))
735 return flush_mask;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500736
Tejun Heobdbcdd42009-01-21 17:26:06 +0900737 return NULL;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500738}
739
Cliff Wickman18129242008-06-02 08:56:14 -0500740/**
741 * uv_flush_tlb_others - globally purge translation cache of a virtual
742 * address or all TLB's
Tejun Heobdbcdd42009-01-21 17:26:06 +0900743 * @cpumask: mask of all cpu's in which the address is to be removed
Cliff Wickman18129242008-06-02 08:56:14 -0500744 * @mm: mm_struct containing virtual address range
745 * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
Tejun Heobdbcdd42009-01-21 17:26:06 +0900746 * @cpu: the current cpu
Cliff Wickman18129242008-06-02 08:56:14 -0500747 *
748 * This is the entry point for initiating any UV global TLB shootdown.
749 *
750 * Purges the translation caches of all specified processors of the given
751 * virtual address, or purges all TLB's on specified processors.
752 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900753 * The caller has derived the cpumask from the mm_struct. This function
754 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
Cliff Wickman18129242008-06-02 08:56:14 -0500755 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500756 * The cpumask is converted into a uvhubmask of the uvhubs containing
757 * those cpus.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500758 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900759 * Note that this function should be called with preemption disabled.
760 *
761 * Returns NULL if all remote flushing was done.
762 * Returns pointer to cpumask if some remote flushing remains to be
763 * done. The returned pointer is valid till preemption is re-enabled.
Cliff Wickman18129242008-06-02 08:56:14 -0500764 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900765const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
766 struct mm_struct *mm,
767 unsigned long va, unsigned int cpu)
Cliff Wickman18129242008-06-02 08:56:14 -0500768{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500769 int remotes;
770 int tcpu;
771 int uvhub;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500772 int locals = 0;
Ingo Molnardc163a42008-06-18 14:15:43 +0200773 struct bau_desc *bau_desc;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500774 struct cpumask *flush_mask;
775 struct ptc_stats *stat;
776 struct bau_control *bcp;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500777 struct bau_control *tbcp;
Cliff Wickman18129242008-06-02 08:56:14 -0500778
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500779 /* kernel was booted 'nobau' */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500780 if (nobau)
781 return cpumask;
782
783 bcp = &per_cpu(bau_control, cpu);
Cliff Wickman712157a2010-06-02 16:22:02 -0500784 stat = bcp->statp;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500785
786 /* bau was disabled due to slow response */
787 if (bcp->baudisabled) {
788 /* the cpu that disabled it must re-enable it */
789 if (bcp->set_bau_off) {
790 if (get_cycles() >= bcp->set_bau_on_time) {
791 stat->s_bau_reenabled++;
792 baudisabled = 0;
793 for_each_present_cpu(tcpu) {
794 tbcp = &per_cpu(bau_control, tcpu);
795 tbcp->baudisabled = 0;
796 tbcp->period_requests = 0;
797 tbcp->period_time = 0;
798 }
799 }
800 }
801 return cpumask;
802 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500803
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500804 /*
805 * Each sending cpu has a per-cpu mask which it fills from the caller's
806 * cpu mask. Only remote cpus are converted to uvhubs and copied.
807 */
808 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
809 /*
810 * copy cpumask to flush_mask, removing current cpu
811 * (current cpu should already have been flushed by the caller and
812 * should never be returned if we return flush_mask)
813 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900814 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500815 if (cpu_isset(cpu, *cpumask))
816 locals++; /* current cpu was targeted */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900817
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500818 bau_desc = bcp->descriptor_base;
819 bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu;
Cliff Wickman18129242008-06-02 08:56:14 -0500820
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500821 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
822 remotes = 0;
823 for_each_cpu(tcpu, flush_mask) {
824 uvhub = uv_cpu_to_blade_id(tcpu);
825 if (uvhub == bcp->uvhub) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500826 locals++;
Cliff Wickman18129242008-06-02 08:56:14 -0500827 continue;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500828 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500829 bau_uvhub_set(uvhub, &bau_desc->distribution);
830 remotes++;
Cliff Wickman18129242008-06-02 08:56:14 -0500831 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500832 if (remotes == 0) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500833 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500834 * No off_hub flushing; return status for local hub.
835 * Return the caller's mask if all were local (the current
836 * cpu may be in that mask).
Cliff Wickmanb194b122008-06-12 08:23:48 -0500837 */
838 if (locals)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500839 return cpumask;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500840 else
Tejun Heobdbcdd42009-01-21 17:26:06 +0900841 return NULL;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500842 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500843 stat->s_requestor++;
844 stat->s_ntargcpu += remotes;
845 remotes = bau_uvhub_weight(&bau_desc->distribution);
846 stat->s_ntarguvhub += remotes;
847 if (remotes >= 16)
848 stat->s_ntarguvhub16++;
849 else if (remotes >= 8)
850 stat->s_ntarguvhub8++;
851 else if (remotes >= 4)
852 stat->s_ntarguvhub4++;
853 else if (remotes >= 2)
854 stat->s_ntarguvhub2++;
855 else
856 stat->s_ntarguvhub1++;
Cliff Wickman18129242008-06-02 08:56:14 -0500857
858 bau_desc->payload.address = va;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900859 bau_desc->payload.sending_cpu = cpu;
Cliff Wickman18129242008-06-02 08:56:14 -0500860
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500861 /*
862 * uv_flush_send_and_wait returns null if all cpu's were messaged, or
863 * the adjusted flush_mask if any cpu's were not messaged.
864 */
865 return uv_flush_send_and_wait(bau_desc, flush_mask, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500866}
867
868/*
869 * The BAU message interrupt comes here. (registered by set_intr_gate)
870 * See entry_64.S
871 *
872 * We received a broadcast assist message.
873 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500874 * Interrupts are disabled; this interrupt could represent
Cliff Wickman18129242008-06-02 08:56:14 -0500875 * the receipt of several messages.
876 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500877 * All cores/threads on this hub get this interrupt.
878 * The last one to see it does the software ack.
Cliff Wickman18129242008-06-02 08:56:14 -0500879 * (the resource will not be freed until noninterruptable cpus see this
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500880 * interrupt; hardware may timeout the s/w ack and reply ERROR)
Cliff Wickman18129242008-06-02 08:56:14 -0500881 */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500882void uv_bau_message_interrupt(struct pt_regs *regs)
Cliff Wickman18129242008-06-02 08:56:14 -0500883{
Cliff Wickman18129242008-06-02 08:56:14 -0500884 int count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500885 cycles_t time_start;
886 struct bau_payload_queue_entry *msg;
887 struct bau_control *bcp;
888 struct ptc_stats *stat;
889 struct msg_desc msgdesc;
Cliff Wickman18129242008-06-02 08:56:14 -0500890
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500891 time_start = get_cycles();
892 bcp = &per_cpu(bau_control, smp_processor_id());
Cliff Wickman712157a2010-06-02 16:22:02 -0500893 stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500894 msgdesc.va_queue_first = bcp->va_queue_first;
895 msgdesc.va_queue_last = bcp->va_queue_last;
896 msg = bcp->bau_msg_head;
Cliff Wickman18129242008-06-02 08:56:14 -0500897 while (msg->sw_ack_vector) {
898 count++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500899 msgdesc.msg_slot = msg - msgdesc.va_queue_first;
900 msgdesc.sw_ack_slot = ffs(msg->sw_ack_vector) - 1;
901 msgdesc.msg = msg;
902 uv_bau_process_message(&msgdesc, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500903 msg++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500904 if (msg > msgdesc.va_queue_last)
905 msg = msgdesc.va_queue_first;
906 bcp->bau_msg_head = msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500907 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500908 stat->d_time += (get_cycles() - time_start);
Cliff Wickman18129242008-06-02 08:56:14 -0500909 if (!count)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500910 stat->d_nomsg++;
Cliff Wickman18129242008-06-02 08:56:14 -0500911 else if (count > 1)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500912 stat->d_multmsg++;
913 ack_APIC_irq();
Cliff Wickman18129242008-06-02 08:56:14 -0500914}
915
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500916/*
917 * uv_enable_timeouts
918 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500919 * Each target uvhub (i.e. a uvhub that has no cpu's) needs to have
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500920 * shootdown message timeouts enabled. The timeout does not cause
921 * an interrupt, but causes an error message to be returned to
922 * the sender.
923 */
Cliff Wickmanb194b122008-06-12 08:23:48 -0500924static void uv_enable_timeouts(void)
Cliff Wickman18129242008-06-02 08:56:14 -0500925{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500926 int uvhub;
927 int nuvhubs;
Cliff Wickman18129242008-06-02 08:56:14 -0500928 int pnode;
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500929 unsigned long mmr_image;
Cliff Wickman18129242008-06-02 08:56:14 -0500930
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500931 nuvhubs = uv_num_possible_blades();
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500932
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500933 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
934 if (!uv_blade_nr_possible_cpus(uvhub))
Cliff Wickman18129242008-06-02 08:56:14 -0500935 continue;
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500936
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500937 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500938 mmr_image =
939 uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL);
940 /*
941 * Set the timeout period and then lock it in, in three
942 * steps; captures and locks in the period.
943 *
944 * To program the period, the SOFT_ACK_MODE must be off.
945 */
946 mmr_image &= ~((unsigned long)1 <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600947 UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500948 uv_write_global_mmr64
949 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
950 /*
951 * Set the 4-bit period.
952 */
953 mmr_image &= ~((unsigned long)0xf <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600954 UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500955 mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600956 UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500957 uv_write_global_mmr64
958 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
959 /*
960 * Subsequent reversals of the timebase bit (3) cause an
961 * immediate timeout of one or all INTD resources as
962 * indicated in bits 2:0 (7 causes all of them to timeout).
963 */
964 mmr_image |= ((unsigned long)1 <<
Jack Steiner6f4edd62010-03-10 14:44:58 -0600965 UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
Cliff Wickmanc4c46882009-04-03 08:34:32 -0500966 uv_write_global_mmr64
967 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
Cliff Wickman18129242008-06-02 08:56:14 -0500968 }
Cliff Wickman18129242008-06-02 08:56:14 -0500969}
970
Cliff Wickmanb194b122008-06-12 08:23:48 -0500971static void *uv_ptc_seq_start(struct seq_file *file, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -0500972{
973 if (*offset < num_possible_cpus())
974 return offset;
975 return NULL;
976}
977
Cliff Wickmanb194b122008-06-12 08:23:48 -0500978static void *uv_ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -0500979{
980 (*offset)++;
981 if (*offset < num_possible_cpus())
982 return offset;
983 return NULL;
984}
985
Cliff Wickmanb194b122008-06-12 08:23:48 -0500986static void uv_ptc_seq_stop(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -0500987{
988}
989
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500990static inline unsigned long long
Cliff Wickman12a66112010-06-02 16:22:01 -0500991microsec_2_cycles(unsigned long microsec)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500992{
993 unsigned long ns;
994 unsigned long long cyc;
995
Cliff Wickman12a66112010-06-02 16:22:01 -0500996 ns = microsec * 1000;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500997 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
998 return cyc;
999}
1000
Cliff Wickman18129242008-06-02 08:56:14 -05001001/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001002 * Display the statistics thru /proc.
1003 * 'data' points to the cpu number
Cliff Wickman18129242008-06-02 08:56:14 -05001004 */
Cliff Wickmanb194b122008-06-12 08:23:48 -05001005static int uv_ptc_seq_show(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001006{
1007 struct ptc_stats *stat;
1008 int cpu;
1009
1010 cpu = *(loff_t *)data;
1011
1012 if (!cpu) {
1013 seq_printf(file,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001014 "# cpu sent stime numuvhubs numuvhubs16 numuvhubs8 ");
Cliff Wickman18129242008-06-02 08:56:14 -05001015 seq_printf(file,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001016 "numuvhubs4 numuvhubs2 numuvhubs1 numcpus dto ");
1017 seq_printf(file,
1018 "retries rok resetp resett giveup sto bz throt ");
1019 seq_printf(file,
1020 "sw_ack recv rtime all ");
1021 seq_printf(file,
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001022 "one mult none retry canc nocan reset rcan ");
1023 seq_printf(file,
1024 "disable enable\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001025 }
1026 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
1027 stat = &per_cpu(ptcstats, cpu);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001028 /* source side statistics */
1029 seq_printf(file,
1030 "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
1031 cpu, stat->s_requestor, cycles_2_us(stat->s_time),
1032 stat->s_ntarguvhub, stat->s_ntarguvhub16,
1033 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
1034 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
1035 stat->s_ntargcpu, stat->s_dtimeout);
1036 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
1037 stat->s_retry_messages, stat->s_retriesok,
1038 stat->s_resets_plug, stat->s_resets_timeout,
1039 stat->s_giveup, stat->s_stimeout,
1040 stat->s_busy, stat->s_throttles);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001041
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001042 /* destination side statistics */
1043 seq_printf(file,
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001044 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
Cliff Wickman9674f352009-04-03 08:34:05 -05001045 uv_read_global_mmr64(uv_cpu_to_pnode(cpu),
Cliff Wickman18129242008-06-02 08:56:14 -05001046 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001047 stat->d_requestee, cycles_2_us(stat->d_time),
1048 stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
1049 stat->d_nomsg, stat->d_retries, stat->d_canceled,
1050 stat->d_nocanceled, stat->d_resets,
1051 stat->d_rcanceled);
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001052 seq_printf(file, "%ld %ld\n",
1053 stat->s_bau_disabled, stat->s_bau_reenabled);
Cliff Wickman18129242008-06-02 08:56:14 -05001054 }
1055
1056 return 0;
1057}
1058
1059/*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001060 * Display the tunables thru debugfs
1061 */
1062static ssize_t tunables_read(struct file *file, char __user *userbuf,
1063 size_t count, loff_t *ppos)
1064{
1065 char buf[300];
1066 int ret;
1067
1068 ret = snprintf(buf, 300, "%s %s %s\n%d %d %d %d %d %d %d %d %d\n",
1069 "max_bau_concurrent plugged_delay plugsb4reset",
1070 "timeoutsb4reset ipi_reset_limit complete_threshold",
1071 "congested_response_us congested_reps congested_period",
1072 max_bau_concurrent, plugged_delay, plugsb4reset,
1073 timeoutsb4reset, ipi_reset_limit, complete_threshold,
1074 congested_response_us, congested_reps, congested_period);
1075
1076 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
1077}
1078
1079/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001080 * -1: resetf the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001081 * 0: display meaning of the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001082 */
Cliff Wickmanb194b122008-06-12 08:23:48 -05001083static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001084 size_t count, loff_t *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001085{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001086 int cpu;
1087 long input_arg;
Cliff Wickman18129242008-06-02 08:56:14 -05001088 char optstr[64];
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001089 struct ptc_stats *stat;
Cliff Wickman18129242008-06-02 08:56:14 -05001090
Cliff Wickmane7eb8722008-06-23 08:32:25 -05001091 if (count == 0 || count > sizeof(optstr))
Cliff Wickmancef53272008-06-19 11:16:24 -05001092 return -EINVAL;
Cliff Wickman18129242008-06-02 08:56:14 -05001093 if (copy_from_user(optstr, user, count))
1094 return -EFAULT;
1095 optstr[count - 1] = '\0';
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001096 if (strict_strtol(optstr, 10, &input_arg) < 0) {
Cliff Wickman18129242008-06-02 08:56:14 -05001097 printk(KERN_DEBUG "%s is invalid\n", optstr);
1098 return -EINVAL;
1099 }
1100
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001101 if (input_arg == 0) {
Cliff Wickman18129242008-06-02 08:56:14 -05001102 printk(KERN_DEBUG "# cpu: cpu number\n");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001103 printk(KERN_DEBUG "Sender statistics:\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001104 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001105 "sent: number of shootdown messages sent\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001106 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001107 "stime: time spent sending messages\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001108 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001109 "numuvhubs: number of hubs targeted with shootdown\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001110 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001111 "numuvhubs16: number times 16 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001112 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001113 "numuvhubs8: number times 8 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001114 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001115 "numuvhubs4: number times 4 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001116 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001117 "numuvhubs2: number times 2 or more hubs targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001118 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001119 "numuvhubs1: number times 1 hub targeted\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001120 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001121 "numcpus: number of cpus targeted with shootdown\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001122 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001123 "dto: number of destination timeouts\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001124 printk(KERN_DEBUG
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001125 "retries: destination timeout retries sent\n");
1126 printk(KERN_DEBUG
1127 "rok: : destination timeouts successfully retried\n");
1128 printk(KERN_DEBUG
1129 "resetp: ipi-style resource resets for plugs\n");
1130 printk(KERN_DEBUG
1131 "resett: ipi-style resource resets for timeouts\n");
1132 printk(KERN_DEBUG
1133 "giveup: fall-backs to ipi-style shootdowns\n");
1134 printk(KERN_DEBUG
1135 "sto: number of source timeouts\n");
1136 printk(KERN_DEBUG
1137 "bz: number of stay-busy's\n");
1138 printk(KERN_DEBUG
1139 "throt: number times spun in throttle\n");
1140 printk(KERN_DEBUG "Destination side statistics:\n");
1141 printk(KERN_DEBUG
1142 "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
1143 printk(KERN_DEBUG
1144 "recv: shootdown messages received\n");
1145 printk(KERN_DEBUG
1146 "rtime: time spent processing messages\n");
1147 printk(KERN_DEBUG
1148 "all: shootdown all-tlb messages\n");
1149 printk(KERN_DEBUG
1150 "one: shootdown one-tlb messages\n");
1151 printk(KERN_DEBUG
1152 "mult: interrupts that found multiple messages\n");
1153 printk(KERN_DEBUG
1154 "none: interrupts that found no messages\n");
1155 printk(KERN_DEBUG
1156 "retry: number of retry messages processed\n");
1157 printk(KERN_DEBUG
1158 "canc: number messages canceled by retries\n");
1159 printk(KERN_DEBUG
1160 "nocan: number retries that found nothing to cancel\n");
1161 printk(KERN_DEBUG
1162 "reset: number of ipi-style reset requests processed\n");
1163 printk(KERN_DEBUG
1164 "rcan: number messages canceled by reset requests\n");
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001165 printk(KERN_DEBUG
1166 "disable: number times use of the BAU was disabled\n");
1167 printk(KERN_DEBUG
1168 "enable: number times use of the BAU was re-enabled\n");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001169 } else if (input_arg == -1) {
1170 for_each_present_cpu(cpu) {
1171 stat = &per_cpu(ptcstats, cpu);
1172 memset(stat, 0, sizeof(struct ptc_stats));
1173 }
Cliff Wickman18129242008-06-02 08:56:14 -05001174 }
1175
1176 return count;
1177}
1178
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001179static int local_atoi(const char *name)
1180{
1181 int val = 0;
1182
1183 for (;; name++) {
1184 switch (*name) {
1185 case '0' ... '9':
1186 val = 10*val+(*name-'0');
1187 break;
1188 default:
1189 return val;
1190 }
1191 }
1192}
1193
1194/*
1195 * set the tunables
1196 * 0 values reset them to defaults
1197 */
1198static ssize_t tunables_write(struct file *file, const char __user *user,
1199 size_t count, loff_t *data)
1200{
1201 int cpu;
1202 int cnt = 0;
1203 int val;
1204 char *p;
1205 char *q;
1206 char instr[64];
1207 struct bau_control *bcp;
1208
1209 if (count == 0 || count > sizeof(instr)-1)
1210 return -EINVAL;
1211 if (copy_from_user(instr, user, count))
1212 return -EFAULT;
1213
1214 instr[count] = '\0';
1215 /* count the fields */
1216 p = instr + strspn(instr, WHITESPACE);
1217 q = p;
1218 for (; *p; p = q + strspn(q, WHITESPACE)) {
1219 q = p + strcspn(p, WHITESPACE);
1220 cnt++;
1221 if (q == p)
1222 break;
1223 }
1224 if (cnt != 9) {
1225 printk(KERN_INFO "bau tunable error: should be 9 numbers\n");
1226 return -EINVAL;
1227 }
1228
1229 p = instr + strspn(instr, WHITESPACE);
1230 q = p;
1231 for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
1232 q = p + strcspn(p, WHITESPACE);
1233 val = local_atoi(p);
1234 switch (cnt) {
1235 case 0:
1236 if (val == 0) {
1237 max_bau_concurrent = MAX_BAU_CONCURRENT;
1238 max_bau_concurrent_constant =
1239 MAX_BAU_CONCURRENT;
1240 continue;
1241 }
1242 bcp = &per_cpu(bau_control, smp_processor_id());
1243 if (val < 1 || val > bcp->cpus_in_uvhub) {
1244 printk(KERN_DEBUG
1245 "Error: BAU max concurrent %d is invalid\n",
1246 val);
1247 return -EINVAL;
1248 }
1249 max_bau_concurrent = val;
1250 max_bau_concurrent_constant = val;
1251 continue;
1252 case 1:
1253 if (val == 0)
1254 plugged_delay = PLUGGED_DELAY;
1255 else
1256 plugged_delay = val;
1257 continue;
1258 case 2:
1259 if (val == 0)
1260 plugsb4reset = PLUGSB4RESET;
1261 else
1262 plugsb4reset = val;
1263 continue;
1264 case 3:
1265 if (val == 0)
1266 timeoutsb4reset = TIMEOUTSB4RESET;
1267 else
1268 timeoutsb4reset = val;
1269 continue;
1270 case 4:
1271 if (val == 0)
1272 ipi_reset_limit = IPI_RESET_LIMIT;
1273 else
1274 ipi_reset_limit = val;
1275 continue;
1276 case 5:
1277 if (val == 0)
1278 complete_threshold = COMPLETE_THRESHOLD;
1279 else
1280 complete_threshold = val;
1281 continue;
1282 case 6:
1283 if (val == 0)
1284 congested_response_us = CONGESTED_RESPONSE_US;
1285 else
1286 congested_response_us = val;
1287 continue;
1288 case 7:
1289 if (val == 0)
1290 congested_reps = CONGESTED_REPS;
1291 else
1292 congested_reps = val;
1293 continue;
1294 case 8:
1295 if (val == 0)
1296 congested_period = CONGESTED_PERIOD;
1297 else
1298 congested_period = val;
1299 continue;
1300 }
1301 if (q == p)
1302 break;
1303 }
1304 for_each_present_cpu(cpu) {
1305 bcp = &per_cpu(bau_control, cpu);
1306 bcp->max_bau_concurrent = max_bau_concurrent;
1307 bcp->max_bau_concurrent_constant = max_bau_concurrent;
1308 bcp->plugged_delay = plugged_delay;
1309 bcp->plugsb4reset = plugsb4reset;
1310 bcp->timeoutsb4reset = timeoutsb4reset;
1311 bcp->ipi_reset_limit = ipi_reset_limit;
1312 bcp->complete_threshold = complete_threshold;
1313 bcp->congested_response_us = congested_response_us;
1314 bcp->congested_reps = congested_reps;
1315 bcp->congested_period = congested_period;
1316 }
1317 return count;
1318}
1319
Cliff Wickman18129242008-06-02 08:56:14 -05001320static const struct seq_operations uv_ptc_seq_ops = {
Ingo Molnardc163a42008-06-18 14:15:43 +02001321 .start = uv_ptc_seq_start,
1322 .next = uv_ptc_seq_next,
1323 .stop = uv_ptc_seq_stop,
1324 .show = uv_ptc_seq_show
Cliff Wickman18129242008-06-02 08:56:14 -05001325};
1326
Cliff Wickmanb194b122008-06-12 08:23:48 -05001327static int uv_ptc_proc_open(struct inode *inode, struct file *file)
Cliff Wickman18129242008-06-02 08:56:14 -05001328{
1329 return seq_open(file, &uv_ptc_seq_ops);
1330}
1331
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001332static int tunables_open(struct inode *inode, struct file *file)
1333{
1334 return 0;
1335}
1336
Cliff Wickman18129242008-06-02 08:56:14 -05001337static const struct file_operations proc_uv_ptc_operations = {
Cliff Wickmanb194b122008-06-12 08:23:48 -05001338 .open = uv_ptc_proc_open,
1339 .read = seq_read,
1340 .write = uv_ptc_proc_write,
1341 .llseek = seq_lseek,
1342 .release = seq_release,
Cliff Wickman18129242008-06-02 08:56:14 -05001343};
1344
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001345static const struct file_operations tunables_fops = {
1346 .open = tunables_open,
1347 .read = tunables_read,
1348 .write = tunables_write,
1349};
1350
Cliff Wickmanb194b122008-06-12 08:23:48 -05001351static int __init uv_ptc_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001352{
Cliff Wickmanb194b122008-06-12 08:23:48 -05001353 struct proc_dir_entry *proc_uv_ptc;
Cliff Wickman18129242008-06-02 08:56:14 -05001354
1355 if (!is_uv_system())
1356 return 0;
1357
Alexey Dobriyan10f02d112009-08-23 23:17:27 +04001358 proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
1359 &proc_uv_ptc_operations);
Cliff Wickman18129242008-06-02 08:56:14 -05001360 if (!proc_uv_ptc) {
1361 printk(KERN_ERR "unable to create %s proc entry\n",
1362 UV_PTC_BASENAME);
1363 return -EINVAL;
1364 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001365
1366 tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
1367 if (!tunables_dir) {
1368 printk(KERN_ERR "unable to create debugfs directory %s\n",
1369 UV_BAU_TUNABLES_DIR);
1370 return -EINVAL;
1371 }
1372 tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
1373 tunables_dir, NULL, &tunables_fops);
1374 if (!tunables_file) {
1375 printk(KERN_ERR "unable to create debugfs file %s\n",
1376 UV_BAU_TUNABLES_FILE);
1377 return -EINVAL;
1378 }
Cliff Wickman18129242008-06-02 08:56:14 -05001379 return 0;
1380}
1381
Cliff Wickmanb194b122008-06-12 08:23:48 -05001382/*
Cliff Wickmanb194b122008-06-12 08:23:48 -05001383 * initialize the sending side's sending buffers
1384 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001385static void
Cliff Wickmanb194b122008-06-12 08:23:48 -05001386uv_activation_descriptor_init(int node, int pnode)
1387{
1388 int i;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001389 int cpu;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001390 unsigned long pa;
1391 unsigned long m;
1392 unsigned long n;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001393 struct bau_desc *bau_desc;
1394 struct bau_desc *bd2;
1395 struct bau_control *bcp;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001396
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001397 /*
1398 * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001399 * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per uvhub
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001400 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001401 bau_desc = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)*
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001402 UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001403 BUG_ON(!bau_desc);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001404
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001405 pa = uv_gpa(bau_desc); /* need the real nasid*/
1406 n = pa >> uv_nshift;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001407 m = pa & uv_mmask;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001408
Cliff Wickman9c26f522009-06-24 09:41:59 -05001409 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE,
1410 (n << UV_DESC_BASE_PNODE_SHIFT | m));
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001411
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001412 /*
1413 * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each
1414 * cpu even though we only use the first one; one descriptor can
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001415 * describe a broadcast to 256 uv hubs.
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001416 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001417 for (i = 0, bd2 = bau_desc; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR);
1418 i++, bd2++) {
1419 memset(bd2, 0, sizeof(struct bau_desc));
1420 bd2->header.sw_ack_flag = 1;
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001421 /*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001422 * base_dest_nodeid is the nasid (pnode<<1) of the first uvhub
1423 * in the partition. The bit map will indicate uvhub numbers,
1424 * which are 0-N in a partition. Pnodes are unique system-wide.
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001425 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001426 bd2->header.base_dest_nodeid = uv_partition_base_pnode << 1;
1427 bd2->header.dest_subnodeid = 0x10; /* the LB */
1428 bd2->header.command = UV_NET_ENDPOINT_INTD;
1429 bd2->header.int_both = 1;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001430 /*
1431 * all others need to be set to zero:
1432 * fairness chaining multilevel count replied_to
1433 */
1434 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001435 for_each_present_cpu(cpu) {
1436 if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
1437 continue;
1438 bcp = &per_cpu(bau_control, cpu);
1439 bcp->descriptor_base = bau_desc;
1440 }
Cliff Wickmanb194b122008-06-12 08:23:48 -05001441}
1442
1443/*
1444 * initialize the destination side's receiving buffers
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001445 * entered for each uvhub in the partition
1446 * - node is first node (kernel memory notion) on the uvhub
1447 * - pnode is the uvhub's physical identifier
Cliff Wickmanb194b122008-06-12 08:23:48 -05001448 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001449static void
1450uv_payload_queue_init(int node, int pnode)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001451{
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001452 int pn;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001453 int cpu;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001454 char *cp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001455 unsigned long pa;
1456 struct bau_payload_queue_entry *pqp;
1457 struct bau_payload_queue_entry *pqp_malloc;
1458 struct bau_control *bcp;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001459
Ingo Molnardc163a42008-06-18 14:15:43 +02001460 pqp = (struct bau_payload_queue_entry *) kmalloc_node(
1461 (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry),
1462 GFP_KERNEL, node);
1463 BUG_ON(!pqp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001464 pqp_malloc = pqp;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001465
Cliff Wickmanb194b122008-06-12 08:23:48 -05001466 cp = (char *)pqp + 31;
1467 pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001468
1469 for_each_present_cpu(cpu) {
1470 if (pnode != uv_cpu_to_pnode(cpu))
1471 continue;
1472 /* for every cpu on this pnode: */
1473 bcp = &per_cpu(bau_control, cpu);
1474 bcp->va_queue_first = pqp;
1475 bcp->bau_msg_head = pqp;
1476 bcp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
1477 }
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001478 /*
1479 * need the pnode of where the memory was really allocated
1480 */
1481 pa = uv_gpa(pqp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001482 pn = pa >> uv_nshift;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001483 uv_write_global_mmr64(pnode,
1484 UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001485 ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) |
Cliff Wickmanb194b122008-06-12 08:23:48 -05001486 uv_physnodeaddr(pqp));
1487 uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
1488 uv_physnodeaddr(pqp));
Cliff Wickmanb194b122008-06-12 08:23:48 -05001489 uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
1490 (unsigned long)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001491 uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1)));
1492 /* in effect, all msg_type's are set to MSG_NOOP */
Ingo Molnardc163a42008-06-18 14:15:43 +02001493 memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001494}
1495
1496/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001497 * Initialization of each UV hub's structures
Cliff Wickmanb194b122008-06-12 08:23:48 -05001498 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001499static void __init uv_init_uvhub(int uvhub, int vector)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001500{
Cliff Wickman9674f352009-04-03 08:34:05 -05001501 int node;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001502 int pnode;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001503 unsigned long apicid;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001504
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001505 node = uvhub_to_first_node(uvhub);
1506 pnode = uv_blade_to_pnode(uvhub);
1507 uv_activation_descriptor_init(node, pnode);
1508 uv_payload_queue_init(node, pnode);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001509 /*
1510 * the below initialization can't be in firmware because the
1511 * messaging IRQ will be determined by the OS
1512 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001513 apicid = uvhub_to_first_apicid(uvhub);
Cliff Wickmane38e2af2009-11-19 17:12:43 -06001514 uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001515 ((apicid << 32) | vector));
1516}
1517
1518/*
Cliff Wickman12a66112010-06-02 16:22:01 -05001519 * We will set BAU_MISC_CONTROL with a timeout period.
1520 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
1521 * So the destination timeout period has be be calculated from them.
1522 */
1523static int
1524calculate_destination_timeout(void)
1525{
1526 unsigned long mmr_image;
1527 int mult1;
1528 int mult2;
1529 int index;
1530 int base;
1531 int ret;
1532 unsigned long ts_ns;
1533
1534 mult1 = UV_INTD_SOFT_ACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
1535 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1536 index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
1537 mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
1538 mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
1539 base = timeout_base_ns[index];
1540 ts_ns = base * mult1 * mult2;
1541 ret = ts_ns / 1000;
1542 return ret;
1543}
1544
1545/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001546 * initialize the bau_control structure for each cpu
1547 */
1548static void uv_init_per_cpu(int nuvhubs)
1549{
1550 int i, j, k;
1551 int cpu;
1552 int pnode;
1553 int uvhub;
1554 short socket = 0;
1555 struct bau_control *bcp;
1556 struct uvhub_desc *bdp;
1557 struct socket_desc *sdp;
1558 struct bau_control *hmaster = NULL;
1559 struct bau_control *smaster = NULL;
1560 struct socket_desc {
1561 short num_cpus;
1562 short cpu_number[16];
1563 };
1564 struct uvhub_desc {
1565 short num_sockets;
1566 short num_cpus;
1567 short uvhub;
1568 short pnode;
1569 struct socket_desc socket[2];
1570 };
1571 struct uvhub_desc *uvhub_descs;
1572
Cliff Wickman12a66112010-06-02 16:22:01 -05001573 timeout_us = calculate_destination_timeout();
1574
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001575 uvhub_descs = (struct uvhub_desc *)
1576 kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1577 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
1578 for_each_present_cpu(cpu) {
1579 bcp = &per_cpu(bau_control, cpu);
1580 memset(bcp, 0, sizeof(struct bau_control));
1581 spin_lock_init(&bcp->masks_lock);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001582 pnode = uv_cpu_hub_info(cpu)->pnode;
1583 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
1584 bdp = &uvhub_descs[uvhub];
1585 bdp->num_cpus++;
1586 bdp->uvhub = uvhub;
1587 bdp->pnode = pnode;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001588 /* kludge: assume uv_hub.h is constant */
1589 socket = (cpu_physical_id(cpu)>>5)&1;
1590 if (socket >= bdp->num_sockets)
1591 bdp->num_sockets = socket+1;
1592 sdp = &bdp->socket[socket];
1593 sdp->cpu_number[sdp->num_cpus] = cpu;
1594 sdp->num_cpus++;
1595 }
1596 socket = 0;
1597 for_each_possible_blade(uvhub) {
1598 bdp = &uvhub_descs[uvhub];
1599 for (i = 0; i < bdp->num_sockets; i++) {
1600 sdp = &bdp->socket[i];
1601 for (j = 0; j < sdp->num_cpus; j++) {
1602 cpu = sdp->cpu_number[j];
1603 bcp = &per_cpu(bau_control, cpu);
1604 bcp->cpu = cpu;
1605 if (j == 0) {
1606 smaster = bcp;
1607 if (i == 0)
1608 hmaster = bcp;
1609 }
1610 bcp->cpus_in_uvhub = bdp->num_cpus;
1611 bcp->cpus_in_socket = sdp->num_cpus;
1612 bcp->socket_master = smaster;
1613 bcp->uvhub_master = hmaster;
1614 for (k = 0; k < DEST_Q_SIZE; k++)
1615 bcp->socket_acknowledge_count[k] = 0;
1616 bcp->uvhub_cpu =
1617 uv_cpu_hub_info(cpu)->blade_processor_id;
1618 }
1619 socket++;
1620 }
1621 }
1622 kfree(uvhub_descs);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001623 for_each_present_cpu(cpu) {
1624 bcp = &per_cpu(bau_control, cpu);
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001625 bcp->baudisabled = 0;
Cliff Wickman712157a2010-06-02 16:22:02 -05001626 bcp->statp = &per_cpu(ptcstats, cpu);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001627 /* time interval to catch a hardware stay-busy bug */
1628 bcp->timeout_interval = microsec_2_cycles(2*timeout_us);
1629 bcp->max_bau_concurrent = max_bau_concurrent;
1630 bcp->max_bau_concurrent_constant = max_bau_concurrent;
1631 bcp->plugged_delay = plugged_delay;
1632 bcp->plugsb4reset = plugsb4reset;
1633 bcp->timeoutsb4reset = timeoutsb4reset;
1634 bcp->ipi_reset_limit = ipi_reset_limit;
1635 bcp->complete_threshold = complete_threshold;
1636 bcp->congested_response_us = congested_response_us;
1637 bcp->congested_reps = congested_reps;
1638 bcp->congested_period = congested_period;
1639 }
Cliff Wickmanb194b122008-06-12 08:23:48 -05001640}
Cliff Wickman18129242008-06-02 08:56:14 -05001641
1642/*
1643 * Initialization of BAU-related structures
1644 */
Cliff Wickmanb194b122008-06-12 08:23:48 -05001645static int __init uv_bau_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001646{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001647 int uvhub;
1648 int pnode;
1649 int nuvhubs;
Rusty Russell2c74d662009-03-18 08:22:30 +10301650 int cur_cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001651 int vector;
1652 unsigned long mmr;
Cliff Wickman18129242008-06-02 08:56:14 -05001653
1654 if (!is_uv_system())
1655 return 0;
1656
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001657 if (nobau)
1658 return 0;
1659
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301660 for_each_possible_cpu(cur_cpu)
Yinghai Lueaa958402009-06-06 14:51:36 -07001661 zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu),
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301662 GFP_KERNEL, cpu_to_node(cur_cpu));
1663
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001664 uv_nshift = uv_hub_info->m_val;
Robin Holt036ed8b2009-10-15 17:40:00 -05001665 uv_mmask = (1UL << uv_hub_info->m_val) - 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001666 nuvhubs = uv_num_possible_blades();
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001667 spin_lock_init(&disable_lock);
1668 congested_cycles = microsec_2_cycles(congested_response_us);
Cliff Wickman9674f352009-04-03 08:34:05 -05001669
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001670 uv_init_per_cpu(nuvhubs);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001671
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001672 uv_partition_base_pnode = 0x7fffffff;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001673 for (uvhub = 0; uvhub < nuvhubs; uvhub++)
1674 if (uv_blade_nr_possible_cpus(uvhub) &&
1675 (uv_blade_to_pnode(uvhub) < uv_partition_base_pnode))
1676 uv_partition_base_pnode = uv_blade_to_pnode(uvhub);
Cliff Wickman9674f352009-04-03 08:34:05 -05001677
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001678 vector = UV_BAU_MESSAGE;
1679 for_each_possible_blade(uvhub)
1680 if (uv_blade_nr_possible_cpus(uvhub))
1681 uv_init_uvhub(uvhub, vector);
1682
Cliff Wickman18129242008-06-02 08:56:14 -05001683 uv_enable_timeouts();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001684 alloc_intr_gate(vector, uv_bau_message_intr1);
1685
1686 for_each_possible_blade(uvhub) {
1687 pnode = uv_blade_to_pnode(uvhub);
1688 /* INIT the bau */
1689 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL,
1690 ((unsigned long)1 << 63));
1691 mmr = 1; /* should be 1 to broadcast to both sockets */
1692 uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST, mmr);
1693 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001694
Cliff Wickman18129242008-06-02 08:56:14 -05001695 return 0;
1696}
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001697core_initcall(uv_bau_init);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001698fs_initcall(uv_ptc_init);