blob: 7623b08eab1e8a54802e4ca96f51cda108462e9e [file] [log] [blame]
Cliff Wickman18129242008-06-02 08:56:14 -05001/*
2 * SGI UltraViolet TLB flush routines.
3 *
Cliff Wickmanf073cc82011-05-24 13:07:36 -05004 * (c) 2008-2011 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>
Jean Delvareca4445642011-03-25 15:20:14 +010014#include <linux/delay.h>
Cliff Wickman18129242008-06-02 08:56:14 -050015
Cliff Wickman18129242008-06-02 08:56:14 -050016#include <asm/mmu_context.h>
Tejun Heobdbcdd42009-01-21 17:26:06 +090017#include <asm/uv/uv.h>
Cliff Wickman18129242008-06-02 08:56:14 -050018#include <asm/uv/uv_mmrs.h>
Ingo Molnarb4c286e2008-06-18 14:28:19 +020019#include <asm/uv/uv_hub.h>
Cliff Wickman18129242008-06-02 08:56:14 -050020#include <asm/uv/uv_bau.h>
Ingo Molnar7b6aa332009-02-17 13:58:15 +010021#include <asm/apic.h>
Ingo Molnarb4c286e2008-06-18 14:28:19 +020022#include <asm/idle.h>
Cliff Wickmanb194b1202008-06-12 08:23:48 -050023#include <asm/tsc.h>
Cliff Wickman99dd8712008-08-19 12:51:59 -050024#include <asm/irq_vectors.h>
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050025#include <asm/timer.h>
Cliff Wickman18129242008-06-02 08:56:14 -050026
Cliff Wickman12a66112010-06-02 16:22:01 -050027/* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
28static int timeout_base_ns[] = {
29 20,
30 160,
31 1280,
32 10240,
33 81920,
34 655360,
35 5242880,
36 167772160
37};
Cliff Wickmanf073cc82011-05-24 13:07:36 -050038
Cliff Wickman12a66112010-06-02 16:22:01 -050039static int timeout_us;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050040static int nobau;
Cliff Wickman50fb55a2010-06-02 16:22:02 -050041static int baudisabled;
42static spinlock_t disable_lock;
43static cycles_t congested_cycles;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050044
45/* tunables: */
Cliff Wickmanf073cc82011-05-24 13:07:36 -050046static int max_concurr = MAX_BAU_CONCURRENT;
47static int max_concurr_const = MAX_BAU_CONCURRENT;
48static int plugged_delay = PLUGGED_DELAY;
49static int plugsb4reset = PLUGSB4RESET;
50static int timeoutsb4reset = TIMEOUTSB4RESET;
51static int ipi_reset_limit = IPI_RESET_LIMIT;
52static int complete_threshold = COMPLETE_THRESHOLD;
53static int congested_respns_us = CONGESTED_RESPONSE_US;
54static int congested_reps = CONGESTED_REPS;
55static int congested_period = CONGESTED_PERIOD;
56
57static struct tunables tunables[] = {
58 {&max_concurr, MAX_BAU_CONCURRENT}, /* must be [0] */
59 {&plugged_delay, PLUGGED_DELAY},
60 {&plugsb4reset, PLUGSB4RESET},
61 {&timeoutsb4reset, TIMEOUTSB4RESET},
62 {&ipi_reset_limit, IPI_RESET_LIMIT},
63 {&complete_threshold, COMPLETE_THRESHOLD},
64 {&congested_respns_us, CONGESTED_RESPONSE_US},
65 {&congested_reps, CONGESTED_REPS},
66 {&congested_period, CONGESTED_PERIOD}
67};
68
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050069static struct dentry *tunables_dir;
70static struct dentry *tunables_file;
71
Cliff Wickmanf073cc82011-05-24 13:07:36 -050072/* these correspond to the statistics printed by ptc_seq_show() */
73static char *stat_description[] = {
74 "sent: number of shootdown messages sent",
75 "stime: time spent sending messages",
76 "numuvhubs: number of hubs targeted with shootdown",
77 "numuvhubs16: number times 16 or more hubs targeted",
78 "numuvhubs8: number times 8 or more hubs targeted",
79 "numuvhubs4: number times 4 or more hubs targeted",
80 "numuvhubs2: number times 2 or more hubs targeted",
81 "numuvhubs1: number times 1 hub targeted",
82 "numcpus: number of cpus targeted with shootdown",
83 "dto: number of destination timeouts",
84 "retries: destination timeout retries sent",
85 "rok: : destination timeouts successfully retried",
86 "resetp: ipi-style resource resets for plugs",
87 "resett: ipi-style resource resets for timeouts",
88 "giveup: fall-backs to ipi-style shootdowns",
89 "sto: number of source timeouts",
90 "bz: number of stay-busy's",
91 "throt: number times spun in throttle",
92 "swack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE",
93 "recv: shootdown messages received",
94 "rtime: time spent processing messages",
95 "all: shootdown all-tlb messages",
96 "one: shootdown one-tlb messages",
97 "mult: interrupts that found multiple messages",
98 "none: interrupts that found no messages",
99 "retry: number of retry messages processed",
100 "canc: number messages canceled by retries",
101 "nocan: number retries that found nothing to cancel",
102 "reset: number of ipi-style reset requests processed",
103 "rcan: number messages canceled by reset requests",
104 "disable: number times use of the BAU was disabled",
105 "enable: number times use of the BAU was re-enabled"
106};
107
108static int __init
109setup_nobau(char *arg)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500110{
111 nobau = 1;
112 return 0;
113}
114early_param("nobau", setup_nobau);
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200115
Cliff Wickman94ca8e42009-04-14 10:56:48 -0500116/* base pnode in this partition */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500117static int uv_base_pnode __read_mostly;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500118/* position of pnode (which is nasid>>1): */
119static int uv_nshift __read_mostly;
120static unsigned long uv_mmask __read_mostly;
Cliff Wickman18129242008-06-02 08:56:14 -0500121
Ingo Molnardc163a42008-06-18 14:15:43 +0200122static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
123static DEFINE_PER_CPU(struct bau_control, bau_control);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500124static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
125
Cliff Wickman18129242008-06-02 08:56:14 -0500126/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500127 * Determine the first node on a uvhub. 'Nodes' are used for kernel
128 * memory allocation.
Cliff Wickman9674f352009-04-03 08:34:05 -0500129 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500130static int __init uvhub_to_first_node(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -0500131{
132 int node, b;
133
134 for_each_online_node(node) {
135 b = uv_node_to_blade_id(node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500136 if (uvhub == b)
Cliff Wickman9674f352009-04-03 08:34:05 -0500137 return node;
138 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500139 return -1;
Cliff Wickman9674f352009-04-03 08:34:05 -0500140}
141
142/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500143 * Determine the apicid of the first cpu on a uvhub.
Cliff Wickman9674f352009-04-03 08:34:05 -0500144 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500145static int __init uvhub_to_first_apicid(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -0500146{
147 int cpu;
148
149 for_each_present_cpu(cpu)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500150 if (uvhub == uv_cpu_to_blade_id(cpu))
Cliff Wickman9674f352009-04-03 08:34:05 -0500151 return per_cpu(x86_cpu_to_apicid, cpu);
152 return -1;
153}
154
155/*
Cliff Wickman18129242008-06-02 08:56:14 -0500156 * Free a software acknowledge hardware resource by clearing its Pending
157 * bit. This will return a reply to the sender.
158 * If the message has timed out, a reply has already been sent by the
159 * hardware but the resource has not been released. In that case our
160 * clear of the Timeout bit (as well) will free the resource. No reply will
161 * be sent (the hardware will only do one reply per message).
162 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500163static void reply_to_message(struct msg_desc *mdp, struct bau_control *bcp)
Cliff Wickman18129242008-06-02 08:56:14 -0500164{
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500165 unsigned long dw;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500166 struct bau_pq_entry *msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500167
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500168 msg = mdp->msg;
169 if (!msg->canceled) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500170 dw = (msg->swack_vec << UV_SW_ACK_NPENDING) | msg->swack_vec;
171 write_mmr_sw_ack(dw);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500172 }
Cliff Wickman18129242008-06-02 08:56:14 -0500173 msg->replied_to = 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500174 msg->swack_vec = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500175}
176
177/*
178 * Process the receipt of a RETRY message
179 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500180static void bau_process_retry_msg(struct msg_desc *mdp,
181 struct bau_control *bcp)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500182{
183 int i;
184 int cancel_count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500185 unsigned long msg_res;
186 unsigned long mmr = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500187 struct bau_pq_entry *msg = mdp->msg;
188 struct bau_pq_entry *msg2;
189 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500190
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500191 stat->d_retries++;
192 /*
193 * cancel any message from msg+1 to the retry itself
194 */
195 for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500196 if (msg2 > mdp->queue_last)
197 msg2 = mdp->queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500198 if (msg2 == msg)
199 break;
200
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500201 /* same conditions for cancellation as do_reset */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500202 if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500203 (msg2->swack_vec) && ((msg2->swack_vec &
204 msg->swack_vec) == 0) &&
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500205 (msg2->sending_cpu == msg->sending_cpu) &&
206 (msg2->msg_type != MSG_NOOP)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500207 mmr = read_mmr_sw_ack();
208 msg_res = msg2->swack_vec;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500209 /*
210 * This is a message retry; clear the resources held
211 * by the previous message only if they timed out.
212 * If it has not timed out we have an unexpected
213 * situation to report.
214 */
Cliff Wickman39847e72010-06-02 16:22:02 -0500215 if (mmr & (msg_res << UV_SW_ACK_NPENDING)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500216 unsigned long mr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500217 /*
218 * is the resource timed out?
219 * make everyone ignore the cancelled message.
220 */
221 msg2->canceled = 1;
222 stat->d_canceled++;
223 cancel_count++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500224 mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
225 write_mmr_sw_ack(mr);
Cliff Wickman39847e72010-06-02 16:22:02 -0500226 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500227 }
228 }
229 if (!cancel_count)
230 stat->d_nocanceled++;
Cliff Wickman18129242008-06-02 08:56:14 -0500231}
232
233/*
234 * Do all the things a cpu should do for a TLB shootdown message.
235 * Other cpu's may come here at the same time for this message.
236 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500237static void bau_process_message(struct msg_desc *mdp,
238 struct bau_control *bcp)
Cliff Wickman18129242008-06-02 08:56:14 -0500239{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500240 short socket_ack_count = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500241 short *sp;
242 struct atomic_short *asp;
243 struct ptc_stats *stat = bcp->statp;
244 struct bau_pq_entry *msg = mdp->msg;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500245 struct bau_control *smaster = bcp->socket_master;
Cliff Wickman18129242008-06-02 08:56:14 -0500246
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500247 /*
248 * This must be a normal message, or retry of a normal message
249 */
Cliff Wickman18129242008-06-02 08:56:14 -0500250 if (msg->address == TLB_FLUSH_ALL) {
251 local_flush_tlb();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500252 stat->d_alltlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500253 } else {
254 __flush_tlb_one(msg->address);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500255 stat->d_onetlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500256 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500257 stat->d_requestee++;
Cliff Wickman18129242008-06-02 08:56:14 -0500258
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500259 /*
260 * One cpu on each uvhub has the additional job on a RETRY
261 * of releasing the resource held by the message that is
262 * being retried. That message is identified by sending
263 * cpu number.
264 */
265 if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500266 bau_process_retry_msg(mdp, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500267
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500268 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500269 * This is a swack message, so we have to reply to it.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500270 * Count each responding cpu on the socket. This avoids
271 * pinging the count's cache line back and forth between
272 * the sockets.
273 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500274 sp = &smaster->socket_acknowledge_count[mdp->msg_slot];
275 asp = (struct atomic_short *)sp;
276 socket_ack_count = atom_asr(1, asp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500277 if (socket_ack_count == bcp->cpus_in_socket) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500278 int msg_ack_count;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500279 /*
280 * Both sockets dump their completed count total into
281 * the message's count.
282 */
283 smaster->socket_acknowledge_count[mdp->msg_slot] = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500284 asp = (struct atomic_short *)&msg->acknowledge_count;
285 msg_ack_count = atom_asr(socket_ack_count, asp);
Ingo Molnardc163a42008-06-18 14:15:43 +0200286
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500287 if (msg_ack_count == bcp->cpus_in_uvhub) {
288 /*
289 * All cpus in uvhub saw it; reply
290 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500291 reply_to_message(mdp, bcp);
Ingo Molnardc163a42008-06-18 14:15:43 +0200292 }
293 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500294
295 return;
Cliff Wickman18129242008-06-02 08:56:14 -0500296}
297
298/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500299 * Determine the first cpu on a uvhub.
Cliff Wickman18129242008-06-02 08:56:14 -0500300 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500301static int uvhub_to_first_cpu(int uvhub)
Cliff Wickman18129242008-06-02 08:56:14 -0500302{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500303 int cpu;
304 for_each_present_cpu(cpu)
305 if (uvhub == uv_cpu_to_blade_id(cpu))
306 return cpu;
307 return -1;
Cliff Wickman18129242008-06-02 08:56:14 -0500308}
309
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500310/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500311 * Last resort when we get a large number of destination timeouts is
312 * to clear resources held by a given cpu.
313 * Do this with IPI so that all messages in the BAU message queue
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500314 * can be identified by their nonzero swack_vec field.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500315 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500316 * This is entered for a single cpu on the uvhub.
317 * The sender want's this uvhub to free a specific message's
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500318 * swack resources.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500319 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500320static void do_reset(void *ptr)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500321{
322 int i;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500323 struct bau_control *bcp = &per_cpu(bau_control, smp_processor_id());
324 struct reset_args *rap = (struct reset_args *)ptr;
325 struct bau_pq_entry *msg;
326 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500327
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500328 stat->d_resets++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500329 /*
330 * We're looking for the given sender, and
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500331 * will free its swack resource.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500332 * If all cpu's finally responded after the timeout, its
333 * message 'replied_to' was set.
334 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500335 for (msg = bcp->queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
336 unsigned long msg_res;
337 /* do_reset: same conditions for cancellation as
338 bau_process_retry_msg() */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500339 if ((msg->replied_to == 0) &&
340 (msg->canceled == 0) &&
341 (msg->sending_cpu == rap->sender) &&
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500342 (msg->swack_vec) &&
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500343 (msg->msg_type != MSG_NOOP)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500344 unsigned long mmr;
345 unsigned long mr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500346 /*
347 * make everyone else ignore this message
348 */
349 msg->canceled = 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500350 /*
351 * only reset the resource if it is still pending
352 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500353 mmr = read_mmr_sw_ack();
354 msg_res = msg->swack_vec;
355 mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500356 if (mmr & msg_res) {
357 stat->d_rcanceled++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500358 write_mmr_sw_ack(mr);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500359 }
360 }
361 }
362 return;
363}
364
365/*
366 * Use IPI to get all target uvhubs to release resources held by
367 * a given sending cpu number.
368 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500369static void reset_with_ipi(struct bau_targ_hubmask *distribution, int sender)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500370{
371 int uvhub;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500372 int maskbits;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500373 cpumask_t mask;
374 struct reset_args reset_args;
375
376 reset_args.sender = sender;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500377 cpus_clear(mask);
378 /* find a single cpu for each uvhub in this distribution mask */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500379 maskbits = sizeof(struct bau_targ_hubmask) * BITSPERBYTE;
380 for (uvhub = 0; uvhub < maskbits; uvhub++) {
381 int cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500382 if (!bau_uvhub_isset(uvhub, distribution))
383 continue;
384 /* find a cpu for this uvhub */
385 cpu = uvhub_to_first_cpu(uvhub);
386 cpu_set(cpu, mask);
387 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500388
389 /* IPI all cpus; preemption is already disabled */
390 smp_call_function_many(&mask, do_reset, (void *)&reset_args, 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500391 return;
392}
393
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500394static inline unsigned long cycles_2_us(unsigned long long cyc)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500395{
396 unsigned long long ns;
397 unsigned long us;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500398 int cpu = smp_processor_id();
399
400 ns = (cyc * per_cpu(cyc2ns, cpu)) >> CYC2NS_SCALE_FACTOR;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500401 us = ns / 1000;
402 return us;
403}
404
405/*
406 * wait for all cpus on this hub to finish their sends and go quiet
407 * leaves uvhub_quiesce set so that no new broadcasts are started by
408 * bau_flush_send_and_wait()
409 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500410static inline void quiesce_local_uvhub(struct bau_control *hmaster)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500411{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500412 atom_asr(1, (struct atomic_short *)&hmaster->uvhub_quiesce);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500413}
414
415/*
416 * mark this quiet-requestor as done
417 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500418static inline void end_uvhub_quiesce(struct bau_control *hmaster)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500419{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500420 atom_asr(-1, (struct atomic_short *)&hmaster->uvhub_quiesce);
421}
422
423static unsigned long uv1_read_status(unsigned long mmr_offset, int right_shift)
424{
425 unsigned long descriptor_status;
426
427 descriptor_status = uv_read_local_mmr(mmr_offset);
428 descriptor_status >>= right_shift;
429 descriptor_status &= UV_ACT_STATUS_MASK;
430 return descriptor_status;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500431}
432
433/*
434 * Wait for completion of a broadcast software ack message
435 * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500436 */
Jack Steiner2a919592011-05-11 12:50:28 -0500437static int uv1_wait_completion(struct bau_desc *bau_desc,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500438 unsigned long mmr_offset, int right_shift,
439 struct bau_control *bcp, long try)
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500440{
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500441 unsigned long descriptor_status;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500442 cycles_t ttm;
Cliff Wickman712157a2010-06-02 16:22:02 -0500443 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500444
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500445 descriptor_status = uv1_read_status(mmr_offset, right_shift);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500446 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500447 while ((descriptor_status != DS_IDLE)) {
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500448 /*
Jack Steiner2a919592011-05-11 12:50:28 -0500449 * Our software ack messages may be blocked because
450 * there are no swack resources available. As long
451 * as none of them has timed out hardware will NACK
452 * our message and its state will stay IDLE.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500453 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500454 if (descriptor_status == DS_SOURCE_TIMEOUT) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500455 stat->s_stimeout++;
456 return FLUSH_GIVEUP;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500457 } else if (descriptor_status == DS_DESTINATION_TIMEOUT) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500458 stat->s_dtimeout++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500459 ttm = get_cycles();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500460
461 /*
462 * Our retries may be blocked by all destination
463 * swack resources being consumed, and a timeout
464 * pending. In that case hardware returns the
465 * ERROR that looks like a destination timeout.
466 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500467 if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500468 bcp->conseccompletes = 0;
469 return FLUSH_RETRY_PLUGGED;
470 }
471
472 bcp->conseccompletes = 0;
473 return FLUSH_RETRY_TIMEOUT;
474 } else {
475 /*
476 * descriptor_status is still BUSY
477 */
478 cpu_relax();
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500479 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500480 descriptor_status = uv1_read_status(mmr_offset, right_shift);
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500481 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500482 bcp->conseccompletes++;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500483 return FLUSH_COMPLETE;
484}
485
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500486/*
487 * UV2 has an extra bit of status in the ACTIVATION_STATUS_2 register.
488 */
489static unsigned long uv2_read_status(unsigned long offset, int rshft, int cpu)
Jack Steiner2a919592011-05-11 12:50:28 -0500490{
491 unsigned long descriptor_status;
492 unsigned long descriptor_status2;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500493
494 descriptor_status = ((read_lmmr(offset) >> rshft) & UV_ACT_STATUS_MASK);
495 descriptor_status2 = (read_mmr_uv2_status() >> cpu) & 0x1UL;
496 descriptor_status = (descriptor_status << 1) | descriptor_status2;
497 return descriptor_status;
498}
499
500static int uv2_wait_completion(struct bau_desc *bau_desc,
501 unsigned long mmr_offset, int right_shift,
502 struct bau_control *bcp, long try)
503{
504 unsigned long descriptor_stat;
505 cycles_t ttm;
506 int cpu = bcp->uvhub_cpu;
Jack Steiner2a919592011-05-11 12:50:28 -0500507 struct ptc_stats *stat = bcp->statp;
508
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500509 descriptor_stat = uv2_read_status(mmr_offset, right_shift, cpu);
510
Jack Steiner2a919592011-05-11 12:50:28 -0500511 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500512 while (descriptor_stat != UV2H_DESC_IDLE) {
Jack Steiner2a919592011-05-11 12:50:28 -0500513 /*
514 * Our software ack messages may be blocked because
515 * there are no swack resources available. As long
516 * as none of them has timed out hardware will NACK
517 * our message and its state will stay IDLE.
518 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500519 if ((descriptor_stat == UV2H_DESC_SOURCE_TIMEOUT) ||
520 (descriptor_stat == UV2H_DESC_DEST_STRONG_NACK) ||
521 (descriptor_stat == UV2H_DESC_DEST_PUT_ERR)) {
Jack Steiner2a919592011-05-11 12:50:28 -0500522 stat->s_stimeout++;
523 return FLUSH_GIVEUP;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500524 } else if (descriptor_stat == UV2H_DESC_DEST_TIMEOUT) {
Jack Steiner2a919592011-05-11 12:50:28 -0500525 stat->s_dtimeout++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500526 ttm = get_cycles();
Jack Steiner2a919592011-05-11 12:50:28 -0500527 /*
528 * Our retries may be blocked by all destination
529 * swack resources being consumed, and a timeout
530 * pending. In that case hardware returns the
531 * ERROR that looks like a destination timeout.
532 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500533 if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
Jack Steiner2a919592011-05-11 12:50:28 -0500534 bcp->conseccompletes = 0;
535 return FLUSH_RETRY_PLUGGED;
536 }
Jack Steiner2a919592011-05-11 12:50:28 -0500537 bcp->conseccompletes = 0;
538 return FLUSH_RETRY_TIMEOUT;
539 } else {
540 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500541 * descriptor_stat is still BUSY
Jack Steiner2a919592011-05-11 12:50:28 -0500542 */
543 cpu_relax();
544 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500545 descriptor_stat = uv2_read_status(mmr_offset, right_shift, cpu);
Jack Steiner2a919592011-05-11 12:50:28 -0500546 }
547 bcp->conseccompletes++;
548 return FLUSH_COMPLETE;
549}
550
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500551/*
552 * There are 2 status registers; each and array[32] of 2 bits. Set up for
553 * which register to read and position in that register based on cpu in
554 * current hub.
555 */
556static int wait_completion(struct bau_desc *bau_desc,
557 struct bau_control *bcp, long try)
Jack Steiner2a919592011-05-11 12:50:28 -0500558{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500559 int right_shift;
560 unsigned long mmr_offset;
561 int cpu = bcp->uvhub_cpu;
562
563 if (cpu < UV_CPUS_PER_AS) {
564 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
565 right_shift = cpu * UV_ACT_STATUS_SIZE;
566 } else {
567 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
568 right_shift = ((cpu - UV_CPUS_PER_AS) * UV_ACT_STATUS_SIZE);
569 }
570
Jack Steiner2a919592011-05-11 12:50:28 -0500571 if (is_uv1_hub())
572 return uv1_wait_completion(bau_desc, mmr_offset, right_shift,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500573 bcp, try);
Jack Steiner2a919592011-05-11 12:50:28 -0500574 else
575 return uv2_wait_completion(bau_desc, mmr_offset, right_shift,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500576 bcp, try);
Jack Steiner2a919592011-05-11 12:50:28 -0500577}
578
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500579static inline cycles_t sec_2_cycles(unsigned long sec)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500580{
581 unsigned long ns;
582 cycles_t cyc;
583
584 ns = sec * 1000000000;
585 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
586 return cyc;
587}
588
589/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500590 * Our retries are blocked by all destination sw ack resources being
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500591 * in use, and a timeout is pending. In that case hardware immediately
592 * returns the ERROR that looks like a destination timeout.
593 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500594static void destination_plugged(struct bau_desc *bau_desc,
595 struct bau_control *bcp,
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500596 struct bau_control *hmaster, struct ptc_stats *stat)
597{
598 udelay(bcp->plugged_delay);
599 bcp->plugged_tries++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500600
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500601 if (bcp->plugged_tries >= bcp->plugsb4reset) {
602 bcp->plugged_tries = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500603
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500604 quiesce_local_uvhub(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500605
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500606 spin_lock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500607 reset_with_ipi(&bau_desc->distribution, bcp->cpu);
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500608 spin_unlock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500609
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500610 end_uvhub_quiesce(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500611
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500612 bcp->ipi_attempts++;
613 stat->s_resets_plug++;
614 }
615}
616
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500617static void destination_timeout(struct bau_desc *bau_desc,
618 struct bau_control *bcp, struct bau_control *hmaster,
619 struct ptc_stats *stat)
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500620{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500621 hmaster->max_concurr = 1;
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500622 bcp->timeout_tries++;
623 if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
624 bcp->timeout_tries = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500625
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500626 quiesce_local_uvhub(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500627
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500628 spin_lock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500629 reset_with_ipi(&bau_desc->distribution, bcp->cpu);
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500630 spin_unlock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500631
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500632 end_uvhub_quiesce(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500633
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500634 bcp->ipi_attempts++;
635 stat->s_resets_timeout++;
636 }
637}
638
639/*
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500640 * Completions are taking a very long time due to a congested numalink
641 * network.
642 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500643static void disable_for_congestion(struct bau_control *bcp,
644 struct ptc_stats *stat)
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500645{
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500646 /* let only one cpu do this disabling */
647 spin_lock(&disable_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500648
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500649 if (!baudisabled && bcp->period_requests &&
650 ((bcp->period_time / bcp->period_requests) > congested_cycles)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500651 int tcpu;
652 struct bau_control *tbcp;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500653 /* it becomes this cpu's job to turn on the use of the
654 BAU again */
655 baudisabled = 1;
656 bcp->set_bau_off = 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500657 bcp->set_bau_on_time = get_cycles();
658 bcp->set_bau_on_time += sec_2_cycles(bcp->cong_period);
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500659 stat->s_bau_disabled++;
660 for_each_present_cpu(tcpu) {
661 tbcp = &per_cpu(bau_control, tcpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500662 tbcp->baudisabled = 1;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500663 }
664 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500665
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500666 spin_unlock(&disable_lock);
667}
668
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500669static void count_max_concurr(int stat, struct bau_control *bcp,
670 struct bau_control *hmaster)
671{
672 bcp->plugged_tries = 0;
673 bcp->timeout_tries = 0;
674 if (stat != FLUSH_COMPLETE)
675 return;
676 if (bcp->conseccompletes <= bcp->complete_threshold)
677 return;
678 if (hmaster->max_concurr >= hmaster->max_concurr_const)
679 return;
680 hmaster->max_concurr++;
681}
682
683static void record_send_stats(cycles_t time1, cycles_t time2,
684 struct bau_control *bcp, struct ptc_stats *stat,
685 int completion_status, int try)
686{
687 cycles_t elapsed;
688
689 if (time2 > time1) {
690 elapsed = time2 - time1;
691 stat->s_time += elapsed;
692
693 if ((completion_status == FLUSH_COMPLETE) && (try == 1)) {
694 bcp->period_requests++;
695 bcp->period_time += elapsed;
696 if ((elapsed > congested_cycles) &&
697 (bcp->period_requests > bcp->cong_reps))
698 disable_for_congestion(bcp, stat);
699 }
700 } else
701 stat->s_requestor--;
702
703 if (completion_status == FLUSH_COMPLETE && try > 1)
704 stat->s_retriesok++;
705 else if (completion_status == FLUSH_GIVEUP)
706 stat->s_giveup++;
707}
708
709/*
710 * Because of a uv1 hardware bug only a limited number of concurrent
711 * requests can be made.
712 */
713static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
714{
715 spinlock_t *lock = &hmaster->uvhub_lock;
716 atomic_t *v;
717
718 v = &hmaster->active_descriptor_count;
719 if (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr)) {
720 stat->s_throttles++;
721 do {
722 cpu_relax();
723 } while (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr));
724 }
725}
726
727/*
728 * Handle the completion status of a message send.
729 */
730static void handle_cmplt(int completion_status, struct bau_desc *bau_desc,
731 struct bau_control *bcp, struct bau_control *hmaster,
732 struct ptc_stats *stat)
733{
734 if (completion_status == FLUSH_RETRY_PLUGGED)
735 destination_plugged(bau_desc, bcp, hmaster, stat);
736 else if (completion_status == FLUSH_RETRY_TIMEOUT)
737 destination_timeout(bau_desc, bcp, hmaster, stat);
738}
739
740/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500741 * Send a broadcast and wait for it to complete.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500742 *
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500743 * The flush_mask contains the cpus the broadcast is to be sent to including
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500744 * cpus that are on the local uvhub.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500745 *
Cliff Wickman450a0072010-06-02 16:22:02 -0500746 * Returns 0 if all flushing represented in the mask was done.
747 * Returns 1 if it gives up entirely and the original cpu mask is to be
748 * returned to the kernel.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500749 */
Cliff Wickman450a0072010-06-02 16:22:02 -0500750int uv_flush_send_and_wait(struct bau_desc *bau_desc,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500751 struct cpumask *flush_mask, struct bau_control *bcp)
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500752{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500753 int seq_number = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500754 int completion_stat = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500755 long try = 0;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200756 unsigned long index;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500757 cycles_t time1;
758 cycles_t time2;
Cliff Wickman712157a2010-06-02 16:22:02 -0500759 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500760 struct bau_control *hmaster = bcp->uvhub_master;
761
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500762 if (is_uv1_hub())
763 uv1_throttle(hmaster, stat);
764
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500765 while (hmaster->uvhub_quiesce)
766 cpu_relax();
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500767
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500768 time1 = get_cycles();
769 do {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500770 if (try == 0) {
Cliff Wickman7fba1bc2010-06-02 16:22:02 -0500771 bau_desc->header.msg_type = MSG_REGULAR;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500772 seq_number = bcp->message_number++;
773 } else {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500774 bau_desc->header.msg_type = MSG_RETRY;
775 stat->s_retry_messages++;
776 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500777
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500778 bau_desc->header.sequence = seq_number;
779 index = (1UL << AS_PUSH_SHIFT) | bcp->uvhub_cpu;
780 bcp->send_message = get_cycles();
781
782 write_mmr_activation(index);
783
784 try++;
785 completion_stat = wait_completion(bau_desc, bcp, try);
786
787 handle_cmplt(completion_stat, bau_desc, bcp, hmaster, stat);
788
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500789 if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500790 bcp->ipi_attempts = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500791 completion_stat = FLUSH_GIVEUP;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500792 break;
793 }
794 cpu_relax();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500795 } while ((completion_stat == FLUSH_RETRY_PLUGGED) ||
796 (completion_stat == FLUSH_RETRY_TIMEOUT));
797
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500798 time2 = get_cycles();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500799
800 count_max_concurr(completion_stat, bcp, hmaster);
801
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500802 while (hmaster->uvhub_quiesce)
803 cpu_relax();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500804
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500805 atomic_dec(&hmaster->active_descriptor_count);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500806
807 record_send_stats(time1, time2, bcp, stat, completion_stat, try);
808
809 if (completion_stat == FLUSH_GIVEUP)
Cliff Wickman450a0072010-06-02 16:22:02 -0500810 return 1;
Cliff Wickman450a0072010-06-02 16:22:02 -0500811 return 0;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500812}
813
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500814/*
815 * The BAU is disabled. When the disabled time period has expired, the cpu
816 * that disabled it must re-enable it.
817 * Return 0 if it is re-enabled for all cpus.
818 */
819static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
820{
821 int tcpu;
822 struct bau_control *tbcp;
823
824 if (bcp->set_bau_off) {
825 if (get_cycles() >= bcp->set_bau_on_time) {
826 stat->s_bau_reenabled++;
827 baudisabled = 0;
828 for_each_present_cpu(tcpu) {
829 tbcp = &per_cpu(bau_control, tcpu);
830 tbcp->baudisabled = 0;
831 tbcp->period_requests = 0;
832 tbcp->period_time = 0;
833 }
834 return 0;
835 }
836 }
837 return -1;
838}
839
840static void record_send_statistics(struct ptc_stats *stat, int locals, int hubs,
841 int remotes, struct bau_desc *bau_desc)
842{
843 stat->s_requestor++;
844 stat->s_ntargcpu += remotes + locals;
845 stat->s_ntargremotes += remotes;
846 stat->s_ntarglocals += locals;
847
848 /* uvhub statistics */
849 hubs = bau_uvhub_weight(&bau_desc->distribution);
850 if (locals) {
851 stat->s_ntarglocaluvhub++;
852 stat->s_ntargremoteuvhub += (hubs - 1);
853 } else
854 stat->s_ntargremoteuvhub += hubs;
855
856 stat->s_ntarguvhub += hubs;
857
858 if (hubs >= 16)
859 stat->s_ntarguvhub16++;
860 else if (hubs >= 8)
861 stat->s_ntarguvhub8++;
862 else if (hubs >= 4)
863 stat->s_ntarguvhub4++;
864 else if (hubs >= 2)
865 stat->s_ntarguvhub2++;
866 else
867 stat->s_ntarguvhub1++;
868}
869
870/*
871 * Translate a cpu mask to the uvhub distribution mask in the BAU
872 * activation descriptor.
873 */
874static int set_distrib_bits(struct cpumask *flush_mask, struct bau_control *bcp,
875 struct bau_desc *bau_desc, int *localsp, int *remotesp)
876{
877 int cpu;
878 int pnode;
879 int cnt = 0;
880 struct hub_and_pnode *hpp;
881
882 for_each_cpu(cpu, flush_mask) {
883 /*
884 * The distribution vector is a bit map of pnodes, relative
885 * to the partition base pnode (and the partition base nasid
886 * in the header).
887 * Translate cpu to pnode and hub using a local memory array.
888 */
889 hpp = &bcp->socket_master->thp[cpu];
890 pnode = hpp->pnode - bcp->partition_base_pnode;
891 bau_uvhub_set(pnode, &bau_desc->distribution);
892 cnt++;
893 if (hpp->uvhub == bcp->uvhub)
894 (*localsp)++;
895 else
896 (*remotesp)++;
897 }
898 if (!cnt)
899 return 1;
900 return 0;
901}
902
903/*
904 * globally purge translation cache of a virtual address or all TLB's
Tejun Heobdbcdd42009-01-21 17:26:06 +0900905 * @cpumask: mask of all cpu's in which the address is to be removed
Cliff Wickman18129242008-06-02 08:56:14 -0500906 * @mm: mm_struct containing virtual address range
907 * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
Tejun Heobdbcdd42009-01-21 17:26:06 +0900908 * @cpu: the current cpu
Cliff Wickman18129242008-06-02 08:56:14 -0500909 *
910 * This is the entry point for initiating any UV global TLB shootdown.
911 *
912 * Purges the translation caches of all specified processors of the given
913 * virtual address, or purges all TLB's on specified processors.
914 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900915 * The caller has derived the cpumask from the mm_struct. This function
916 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
Cliff Wickman18129242008-06-02 08:56:14 -0500917 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500918 * The cpumask is converted into a uvhubmask of the uvhubs containing
919 * those cpus.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500920 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900921 * Note that this function should be called with preemption disabled.
922 *
923 * Returns NULL if all remote flushing was done.
924 * Returns pointer to cpumask if some remote flushing remains to be
925 * done. The returned pointer is valid till preemption is re-enabled.
Cliff Wickman18129242008-06-02 08:56:14 -0500926 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900927const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500928 struct mm_struct *mm, unsigned long va,
929 unsigned int cpu)
Cliff Wickman18129242008-06-02 08:56:14 -0500930{
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500931 int locals = 0;
Cliff Wickman450a0072010-06-02 16:22:02 -0500932 int remotes = 0;
933 int hubs = 0;
Ingo Molnardc163a42008-06-18 14:15:43 +0200934 struct bau_desc *bau_desc;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500935 struct cpumask *flush_mask;
936 struct ptc_stats *stat;
937 struct bau_control *bcp;
Cliff Wickman18129242008-06-02 08:56:14 -0500938
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500939 /* kernel was booted 'nobau' */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500940 if (nobau)
941 return cpumask;
942
943 bcp = &per_cpu(bau_control, cpu);
Cliff Wickman712157a2010-06-02 16:22:02 -0500944 stat = bcp->statp;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500945
946 /* bau was disabled due to slow response */
947 if (bcp->baudisabled) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500948 if (check_enable(bcp, stat))
949 return cpumask;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500950 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500951
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500952 /*
953 * Each sending cpu has a per-cpu mask which it fills from the caller's
Cliff Wickman450a0072010-06-02 16:22:02 -0500954 * cpu mask. All cpus are converted to uvhubs and copied to the
955 * activation descriptor.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500956 */
957 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
Cliff Wickman450a0072010-06-02 16:22:02 -0500958 /* don't actually do a shootdown of the local cpu */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900959 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500960
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500961 if (cpu_isset(cpu, *cpumask))
Cliff Wickman450a0072010-06-02 16:22:02 -0500962 stat->s_ntargself++;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900963
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500964 bau_desc = bcp->descriptor_base;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500965 bau_desc += ITEMS_PER_DESC * bcp->uvhub_cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500966 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500967 if (set_distrib_bits(flush_mask, bcp, bau_desc, &locals, &remotes))
Cliff Wickman450a0072010-06-02 16:22:02 -0500968 return NULL;
Cliff Wickman450a0072010-06-02 16:22:02 -0500969
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500970 record_send_statistics(stat, locals, hubs, remotes, bau_desc);
Cliff Wickman18129242008-06-02 08:56:14 -0500971
972 bau_desc->payload.address = va;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900973 bau_desc->payload.sending_cpu = cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500974 /*
Cliff Wickman450a0072010-06-02 16:22:02 -0500975 * uv_flush_send_and_wait returns 0 if all cpu's were messaged,
976 * or 1 if it gave up and the original cpumask should be returned.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500977 */
Cliff Wickman450a0072010-06-02 16:22:02 -0500978 if (!uv_flush_send_and_wait(bau_desc, flush_mask, bcp))
979 return NULL;
980 else
981 return cpumask;
Cliff Wickman18129242008-06-02 08:56:14 -0500982}
983
984/*
985 * The BAU message interrupt comes here. (registered by set_intr_gate)
986 * See entry_64.S
987 *
988 * We received a broadcast assist message.
989 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500990 * Interrupts are disabled; this interrupt could represent
Cliff Wickman18129242008-06-02 08:56:14 -0500991 * the receipt of several messages.
992 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500993 * All cores/threads on this hub get this interrupt.
994 * The last one to see it does the software ack.
Cliff Wickman18129242008-06-02 08:56:14 -0500995 * (the resource will not be freed until noninterruptable cpus see this
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500996 * interrupt; hardware may timeout the s/w ack and reply ERROR)
Cliff Wickman18129242008-06-02 08:56:14 -0500997 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500998void uv_bau_message_interrupt(struct pt_regs *regs)
Cliff Wickman18129242008-06-02 08:56:14 -0500999{
Cliff Wickman18129242008-06-02 08:56:14 -05001000 int count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001001 cycles_t time_start;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001002 struct bau_pq_entry *msg;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001003 struct bau_control *bcp;
1004 struct ptc_stats *stat;
1005 struct msg_desc msgdesc;
Cliff Wickman18129242008-06-02 08:56:14 -05001006
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001007 time_start = get_cycles();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001008
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001009 bcp = &per_cpu(bau_control, smp_processor_id());
Cliff Wickman712157a2010-06-02 16:22:02 -05001010 stat = bcp->statp;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001011
1012 msgdesc.queue_first = bcp->queue_first;
1013 msgdesc.queue_last = bcp->queue_last;
1014
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001015 msg = bcp->bau_msg_head;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001016 while (msg->swack_vec) {
Cliff Wickman18129242008-06-02 08:56:14 -05001017 count++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001018
1019 msgdesc.msg_slot = msg - msgdesc.queue_first;
1020 msgdesc.swack_slot = ffs(msg->swack_vec) - 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001021 msgdesc.msg = msg;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001022 bau_process_message(&msgdesc, bcp);
1023
Cliff Wickman18129242008-06-02 08:56:14 -05001024 msg++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001025 if (msg > msgdesc.queue_last)
1026 msg = msgdesc.queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001027 bcp->bau_msg_head = msg;
Cliff Wickman18129242008-06-02 08:56:14 -05001028 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001029 stat->d_time += (get_cycles() - time_start);
Cliff Wickman18129242008-06-02 08:56:14 -05001030 if (!count)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001031 stat->d_nomsg++;
Cliff Wickman18129242008-06-02 08:56:14 -05001032 else if (count > 1)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001033 stat->d_multmsg++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001034
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001035 ack_APIC_irq();
Cliff Wickman18129242008-06-02 08:56:14 -05001036}
1037
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001038/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001039 * Each target uvhub (i.e. a uvhub that has cpu's) needs to have
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001040 * shootdown message timeouts enabled. The timeout does not cause
1041 * an interrupt, but causes an error message to be returned to
1042 * the sender.
1043 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001044static void __init enable_timeouts(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001045{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001046 int uvhub;
1047 int nuvhubs;
Cliff Wickman18129242008-06-02 08:56:14 -05001048 int pnode;
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001049 unsigned long mmr_image;
Cliff Wickman18129242008-06-02 08:56:14 -05001050
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001051 nuvhubs = uv_num_possible_blades();
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001052
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001053 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
1054 if (!uv_blade_nr_possible_cpus(uvhub))
Cliff Wickman18129242008-06-02 08:56:14 -05001055 continue;
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001056
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001057 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001058 mmr_image = read_mmr_misc_control(pnode);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001059 /*
1060 * Set the timeout period and then lock it in, in three
1061 * steps; captures and locks in the period.
1062 *
1063 * To program the period, the SOFT_ACK_MODE must be off.
1064 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001065 mmr_image &= ~(1L << SOFTACK_MSHIFT);
1066 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001067 /*
1068 * Set the 4-bit period.
1069 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001070 mmr_image &= ~((unsigned long)0xf << SOFTACK_PSHIFT);
1071 mmr_image |= (SOFTACK_TIMEOUT_PERIOD << SOFTACK_PSHIFT);
1072 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001073 /*
Jack Steiner2a919592011-05-11 12:50:28 -05001074 * UV1:
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001075 * Subsequent reversals of the timebase bit (3) cause an
1076 * immediate timeout of one or all INTD resources as
1077 * indicated in bits 2:0 (7 causes all of them to timeout).
1078 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001079 mmr_image |= (1L << SOFTACK_MSHIFT);
Jack Steiner2a919592011-05-11 12:50:28 -05001080 if (is_uv2_hub()) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001081 mmr_image |= (1L << UV2_LEG_SHFT);
1082 mmr_image |= (1L << UV2_EXT_SHFT);
Jack Steiner2a919592011-05-11 12:50:28 -05001083 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001084 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickman18129242008-06-02 08:56:14 -05001085 }
Cliff Wickman18129242008-06-02 08:56:14 -05001086}
1087
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001088static void *ptc_seq_start(struct seq_file *file, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -05001089{
1090 if (*offset < num_possible_cpus())
1091 return offset;
1092 return NULL;
1093}
1094
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001095static void *ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -05001096{
1097 (*offset)++;
1098 if (*offset < num_possible_cpus())
1099 return offset;
1100 return NULL;
1101}
1102
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001103static void ptc_seq_stop(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001104{
1105}
1106
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001107static inline unsigned long long usec_2_cycles(unsigned long microsec)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001108{
1109 unsigned long ns;
1110 unsigned long long cyc;
1111
Cliff Wickman12a66112010-06-02 16:22:01 -05001112 ns = microsec * 1000;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001113 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
1114 return cyc;
1115}
1116
Cliff Wickman18129242008-06-02 08:56:14 -05001117/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001118 * Display the statistics thru /proc/sgi_uv/ptc_statistics
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001119 * 'data' points to the cpu number
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001120 * Note: see the descriptions in stat_description[].
Cliff Wickman18129242008-06-02 08:56:14 -05001121 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001122static int ptc_seq_show(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001123{
1124 struct ptc_stats *stat;
1125 int cpu;
1126
1127 cpu = *(loff_t *)data;
Cliff Wickman18129242008-06-02 08:56:14 -05001128 if (!cpu) {
1129 seq_printf(file,
Cliff Wickman450a0072010-06-02 16:22:02 -05001130 "# cpu sent stime self locals remotes ncpus localhub ");
Cliff Wickman18129242008-06-02 08:56:14 -05001131 seq_printf(file,
Cliff Wickman450a0072010-06-02 16:22:02 -05001132 "remotehub numuvhubs numuvhubs16 numuvhubs8 ");
1133 seq_printf(file,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001134 "numuvhubs4 numuvhubs2 numuvhubs1 dto retries rok ");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001135 seq_printf(file,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001136 "resetp resett giveup sto bz throt swack recv rtime ");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001137 seq_printf(file,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001138 "all one mult none retry canc nocan reset rcan ");
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001139 seq_printf(file,
1140 "disable enable\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001141 }
1142 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
1143 stat = &per_cpu(ptcstats, cpu);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001144 /* source side statistics */
1145 seq_printf(file,
1146 "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
1147 cpu, stat->s_requestor, cycles_2_us(stat->s_time),
Cliff Wickman450a0072010-06-02 16:22:02 -05001148 stat->s_ntargself, stat->s_ntarglocals,
1149 stat->s_ntargremotes, stat->s_ntargcpu,
1150 stat->s_ntarglocaluvhub, stat->s_ntargremoteuvhub,
1151 stat->s_ntarguvhub, stat->s_ntarguvhub16);
1152 seq_printf(file, "%ld %ld %ld %ld %ld ",
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001153 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
1154 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
Cliff Wickman450a0072010-06-02 16:22:02 -05001155 stat->s_dtimeout);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001156 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
1157 stat->s_retry_messages, stat->s_retriesok,
1158 stat->s_resets_plug, stat->s_resets_timeout,
1159 stat->s_giveup, stat->s_stimeout,
1160 stat->s_busy, stat->s_throttles);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001161
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001162 /* destination side statistics */
1163 seq_printf(file,
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001164 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001165 read_gmmr_sw_ack(uv_cpu_to_pnode(cpu)),
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001166 stat->d_requestee, cycles_2_us(stat->d_time),
1167 stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
1168 stat->d_nomsg, stat->d_retries, stat->d_canceled,
1169 stat->d_nocanceled, stat->d_resets,
1170 stat->d_rcanceled);
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001171 seq_printf(file, "%ld %ld\n",
1172 stat->s_bau_disabled, stat->s_bau_reenabled);
Cliff Wickman18129242008-06-02 08:56:14 -05001173 }
Cliff Wickman18129242008-06-02 08:56:14 -05001174 return 0;
1175}
1176
1177/*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001178 * Display the tunables thru debugfs
1179 */
1180static ssize_t tunables_read(struct file *file, char __user *userbuf,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001181 size_t count, loff_t *ppos)
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001182{
Dan Carpenterb365a852010-09-29 10:41:05 +02001183 char *buf;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001184 int ret;
1185
Dan Carpenterb365a852010-09-29 10:41:05 +02001186 buf = kasprintf(GFP_KERNEL, "%s %s %s\n%d %d %d %d %d %d %d %d %d\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001187 "max_concur plugged_delay plugsb4reset",
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001188 "timeoutsb4reset ipi_reset_limit complete_threshold",
1189 "congested_response_us congested_reps congested_period",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001190 max_concurr, plugged_delay, plugsb4reset,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001191 timeoutsb4reset, ipi_reset_limit, complete_threshold,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001192 congested_respns_us, congested_reps, congested_period);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001193
Dan Carpenterb365a852010-09-29 10:41:05 +02001194 if (!buf)
1195 return -ENOMEM;
1196
1197 ret = simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
1198 kfree(buf);
1199 return ret;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001200}
1201
1202/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001203 * handle a write to /proc/sgi_uv/ptc_statistics
1204 * -1: reset the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001205 * 0: display meaning of the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001206 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001207static ssize_t ptc_proc_write(struct file *file, const char __user *user,
1208 size_t count, loff_t *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001209{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001210 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001211 int i;
1212 int elements;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001213 long input_arg;
Cliff Wickman18129242008-06-02 08:56:14 -05001214 char optstr[64];
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001215 struct ptc_stats *stat;
Cliff Wickman18129242008-06-02 08:56:14 -05001216
Cliff Wickmane7eb8722008-06-23 08:32:25 -05001217 if (count == 0 || count > sizeof(optstr))
Cliff Wickmancef53272008-06-19 11:16:24 -05001218 return -EINVAL;
Cliff Wickman18129242008-06-02 08:56:14 -05001219 if (copy_from_user(optstr, user, count))
1220 return -EFAULT;
1221 optstr[count - 1] = '\0';
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001222
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001223 if (strict_strtol(optstr, 10, &input_arg) < 0) {
Cliff Wickman18129242008-06-02 08:56:14 -05001224 printk(KERN_DEBUG "%s is invalid\n", optstr);
1225 return -EINVAL;
1226 }
1227
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001228 if (input_arg == 0) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001229 elements = sizeof(stat_description)/sizeof(*stat_description);
Cliff Wickman18129242008-06-02 08:56:14 -05001230 printk(KERN_DEBUG "# cpu: cpu number\n");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001231 printk(KERN_DEBUG "Sender statistics:\n");
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001232 for (i = 0; i < elements; i++)
1233 printk(KERN_DEBUG "%s\n", stat_description[i]);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001234 } else if (input_arg == -1) {
1235 for_each_present_cpu(cpu) {
1236 stat = &per_cpu(ptcstats, cpu);
1237 memset(stat, 0, sizeof(struct ptc_stats));
1238 }
Cliff Wickman18129242008-06-02 08:56:14 -05001239 }
1240
1241 return count;
1242}
1243
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001244static int local_atoi(const char *name)
1245{
1246 int val = 0;
1247
1248 for (;; name++) {
1249 switch (*name) {
1250 case '0' ... '9':
1251 val = 10*val+(*name-'0');
1252 break;
1253 default:
1254 return val;
1255 }
1256 }
1257}
1258
1259/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001260 * Parse the values written to /sys/kernel/debug/sgi_uv/bau_tunables.
1261 * Zero values reset them to defaults.
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001262 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001263static int parse_tunables_write(struct bau_control *bcp, char *instr,
1264 int count)
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001265{
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001266 char *p;
1267 char *q;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001268 int cnt = 0;
1269 int val;
1270 int e = sizeof(tunables) / sizeof(*tunables);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001271
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001272 p = instr + strspn(instr, WHITESPACE);
1273 q = p;
1274 for (; *p; p = q + strspn(q, WHITESPACE)) {
1275 q = p + strcspn(p, WHITESPACE);
1276 cnt++;
1277 if (q == p)
1278 break;
1279 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001280 if (cnt != e) {
1281 printk(KERN_INFO "bau tunable error: should be %d values\n", e);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001282 return -EINVAL;
1283 }
1284
1285 p = instr + strspn(instr, WHITESPACE);
1286 q = p;
1287 for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
1288 q = p + strcspn(p, WHITESPACE);
1289 val = local_atoi(p);
1290 switch (cnt) {
1291 case 0:
1292 if (val == 0) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001293 max_concurr = MAX_BAU_CONCURRENT;
1294 max_concurr_const = MAX_BAU_CONCURRENT;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001295 continue;
1296 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001297 if (val < 1 || val > bcp->cpus_in_uvhub) {
1298 printk(KERN_DEBUG
1299 "Error: BAU max concurrent %d is invalid\n",
1300 val);
1301 return -EINVAL;
1302 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001303 max_concurr = val;
1304 max_concurr_const = val;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001305 continue;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001306 default:
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001307 if (val == 0)
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001308 *tunables[cnt].tunp = tunables[cnt].deflt;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001309 else
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001310 *tunables[cnt].tunp = val;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001311 continue;
1312 }
1313 if (q == p)
1314 break;
1315 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001316 return 0;
1317}
1318
1319/*
1320 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
1321 */
1322static ssize_t tunables_write(struct file *file, const char __user *user,
1323 size_t count, loff_t *data)
1324{
1325 int cpu;
1326 int ret;
1327 char instr[100];
1328 struct bau_control *bcp;
1329
1330 if (count == 0 || count > sizeof(instr)-1)
1331 return -EINVAL;
1332 if (copy_from_user(instr, user, count))
1333 return -EFAULT;
1334
1335 instr[count] = '\0';
1336
cpw@sgi.com00b30cf2011-06-21 07:21:26 -05001337 cpu = get_cpu();
1338 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001339 ret = parse_tunables_write(bcp, instr, count);
cpw@sgi.com00b30cf2011-06-21 07:21:26 -05001340 put_cpu();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001341 if (ret)
1342 return ret;
1343
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001344 for_each_present_cpu(cpu) {
1345 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001346 bcp->max_concurr = max_concurr;
1347 bcp->max_concurr_const = max_concurr;
1348 bcp->plugged_delay = plugged_delay;
1349 bcp->plugsb4reset = plugsb4reset;
1350 bcp->timeoutsb4reset = timeoutsb4reset;
1351 bcp->ipi_reset_limit = ipi_reset_limit;
1352 bcp->complete_threshold = complete_threshold;
1353 bcp->cong_response_us = congested_respns_us;
1354 bcp->cong_reps = congested_reps;
1355 bcp->cong_period = congested_period;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001356 }
1357 return count;
1358}
1359
Cliff Wickman18129242008-06-02 08:56:14 -05001360static const struct seq_operations uv_ptc_seq_ops = {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001361 .start = ptc_seq_start,
1362 .next = ptc_seq_next,
1363 .stop = ptc_seq_stop,
1364 .show = ptc_seq_show
Cliff Wickman18129242008-06-02 08:56:14 -05001365};
1366
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001367static int ptc_proc_open(struct inode *inode, struct file *file)
Cliff Wickman18129242008-06-02 08:56:14 -05001368{
1369 return seq_open(file, &uv_ptc_seq_ops);
1370}
1371
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001372static int tunables_open(struct inode *inode, struct file *file)
1373{
1374 return 0;
1375}
1376
Cliff Wickman18129242008-06-02 08:56:14 -05001377static const struct file_operations proc_uv_ptc_operations = {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001378 .open = ptc_proc_open,
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001379 .read = seq_read,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001380 .write = ptc_proc_write,
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001381 .llseek = seq_lseek,
1382 .release = seq_release,
Cliff Wickman18129242008-06-02 08:56:14 -05001383};
1384
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001385static const struct file_operations tunables_fops = {
1386 .open = tunables_open,
1387 .read = tunables_read,
1388 .write = tunables_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001389 .llseek = default_llseek,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001390};
1391
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001392static int __init uv_ptc_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001393{
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001394 struct proc_dir_entry *proc_uv_ptc;
Cliff Wickman18129242008-06-02 08:56:14 -05001395
1396 if (!is_uv_system())
1397 return 0;
1398
Alexey Dobriyan10f02d112009-08-23 23:17:27 +04001399 proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
1400 &proc_uv_ptc_operations);
Cliff Wickman18129242008-06-02 08:56:14 -05001401 if (!proc_uv_ptc) {
1402 printk(KERN_ERR "unable to create %s proc entry\n",
1403 UV_PTC_BASENAME);
1404 return -EINVAL;
1405 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001406
1407 tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
1408 if (!tunables_dir) {
1409 printk(KERN_ERR "unable to create debugfs directory %s\n",
1410 UV_BAU_TUNABLES_DIR);
1411 return -EINVAL;
1412 }
1413 tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001414 tunables_dir, NULL, &tunables_fops);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001415 if (!tunables_file) {
1416 printk(KERN_ERR "unable to create debugfs file %s\n",
1417 UV_BAU_TUNABLES_FILE);
1418 return -EINVAL;
1419 }
Cliff Wickman18129242008-06-02 08:56:14 -05001420 return 0;
1421}
1422
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001423/*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001424 * Initialize the sending side's sending buffers.
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001425 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001426static void activation_descriptor_init(int node, int pnode, int base_pnode)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001427{
1428 int i;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001429 int cpu;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001430 unsigned long pa;
1431 unsigned long m;
1432 unsigned long n;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001433 size_t dsize;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001434 struct bau_desc *bau_desc;
1435 struct bau_desc *bd2;
1436 struct bau_control *bcp;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001437
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001438 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001439 * each bau_desc is 64 bytes; there are 8 (ITEMS_PER_DESC)
1440 * per cpu; and one per cpu on the uvhub (ADP_SZ)
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001441 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001442 dsize = sizeof(struct bau_desc) * ADP_SZ * ITEMS_PER_DESC;
1443 bau_desc = kmalloc_node(dsize, GFP_KERNEL, node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001444 BUG_ON(!bau_desc);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001445
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001446 pa = uv_gpa(bau_desc); /* need the real nasid*/
1447 n = pa >> uv_nshift;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001448 m = pa & uv_mmask;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001449
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001450 /* the 14-bit pnode */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001451 write_mmr_descriptor_base(pnode, (n << UV_DESC_PSHIFT | m));
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001452 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001453 * Initializing all 8 (ITEMS_PER_DESC) descriptors for each
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001454 * cpu even though we only use the first one; one descriptor can
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001455 * describe a broadcast to 256 uv hubs.
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001456 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001457 for (i = 0, bd2 = bau_desc; i < (ADP_SZ * ITEMS_PER_DESC); i++, bd2++) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001458 memset(bd2, 0, sizeof(struct bau_desc));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001459 bd2->header.swack_flag = 1;
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001460 /*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001461 * The base_dest_nasid set in the message header is the nasid
1462 * of the first uvhub in the partition. The bit map will
1463 * indicate destination pnode numbers relative to that base.
1464 * They may not be consecutive if nasid striding is being used.
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001465 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001466 bd2->header.base_dest_nasid = UV_PNODE_TO_NASID(base_pnode);
1467 bd2->header.dest_subnodeid = UV_LB_SUBNODEID;
1468 bd2->header.command = UV_NET_ENDPOINT_INTD;
1469 bd2->header.int_both = 1;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001470 /*
1471 * all others need to be set to zero:
1472 * fairness chaining multilevel count replied_to
1473 */
1474 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001475 for_each_present_cpu(cpu) {
1476 if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
1477 continue;
1478 bcp = &per_cpu(bau_control, cpu);
1479 bcp->descriptor_base = bau_desc;
1480 }
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001481}
1482
1483/*
1484 * initialize the destination side's receiving buffers
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001485 * entered for each uvhub in the partition
1486 * - node is first node (kernel memory notion) on the uvhub
1487 * - pnode is the uvhub's physical identifier
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001488 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001489static void pq_init(int node, int pnode)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001490{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001491 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001492 size_t plsize;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001493 char *cp;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001494 void *vp;
1495 unsigned long pn;
1496 unsigned long first;
1497 unsigned long pn_first;
1498 unsigned long last;
1499 struct bau_pq_entry *pqp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001500 struct bau_control *bcp;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001501
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001502 plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
1503 vp = kmalloc_node(plsize, GFP_KERNEL, node);
1504 pqp = (struct bau_pq_entry *)vp;
Ingo Molnardc163a42008-06-18 14:15:43 +02001505 BUG_ON(!pqp);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001506
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001507 cp = (char *)pqp + 31;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001508 pqp = (struct bau_pq_entry *)(((unsigned long)cp >> 5) << 5);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001509
1510 for_each_present_cpu(cpu) {
1511 if (pnode != uv_cpu_to_pnode(cpu))
1512 continue;
1513 /* for every cpu on this pnode: */
1514 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001515 bcp->queue_first = pqp;
1516 bcp->bau_msg_head = pqp;
1517 bcp->queue_last = pqp + (DEST_Q_SIZE - 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001518 }
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001519 /*
1520 * need the pnode of where the memory was really allocated
1521 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001522 pn = uv_gpa(pqp) >> uv_nshift;
1523 first = uv_physnodeaddr(pqp);
1524 pn_first = ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) | first;
1525 last = uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1));
1526 write_mmr_payload_first(pnode, pn_first);
1527 write_mmr_payload_tail(pnode, first);
1528 write_mmr_payload_last(pnode, last);
1529
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001530 /* in effect, all msg_type's are set to MSG_NOOP */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001531 memset(pqp, 0, sizeof(struct bau_pq_entry) * DEST_Q_SIZE);
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001532}
1533
1534/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001535 * Initialization of each UV hub's structures
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001536 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001537static void __init init_uvhub(int uvhub, int vector, int base_pnode)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001538{
Cliff Wickman9674f352009-04-03 08:34:05 -05001539 int node;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001540 int pnode;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001541 unsigned long apicid;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001542
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001543 node = uvhub_to_first_node(uvhub);
1544 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001545
1546 activation_descriptor_init(node, pnode, base_pnode);
1547
1548 pq_init(node, pnode);
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001549 /*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001550 * The below initialization can't be in firmware because the
1551 * messaging IRQ will be determined by the OS.
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001552 */
Dimitri Sivanich8191c9f2010-11-16 16:23:52 -06001553 apicid = uvhub_to_first_apicid(uvhub) | uv_apicid_hibits;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001554 write_mmr_data_config(pnode, ((apicid << 32) | vector));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001555}
1556
1557/*
Cliff Wickman12a66112010-06-02 16:22:01 -05001558 * We will set BAU_MISC_CONTROL with a timeout period.
1559 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001560 * So the destination timeout period has to be calculated from them.
Cliff Wickman12a66112010-06-02 16:22:01 -05001561 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001562static int calculate_destination_timeout(void)
Cliff Wickman12a66112010-06-02 16:22:01 -05001563{
1564 unsigned long mmr_image;
1565 int mult1;
1566 int mult2;
1567 int index;
1568 int base;
1569 int ret;
1570 unsigned long ts_ns;
1571
Jack Steiner2a919592011-05-11 12:50:28 -05001572 if (is_uv1_hub()) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001573 mult1 = SOFTACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
Jack Steiner2a919592011-05-11 12:50:28 -05001574 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1575 index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
1576 mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
1577 mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
1578 base = timeout_base_ns[index];
1579 ts_ns = base * mult1 * mult2;
1580 ret = ts_ns / 1000;
1581 } else {
1582 /* 4 bits 0/1 for 10/80us, 3 bits of multiplier */
1583 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1584 mmr_image = (mmr_image & UV_SA_MASK) >> UV_SA_SHFT;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001585 if (mmr_image & (1L << UV2_ACK_UNITS_SHFT))
Jack Steiner2a919592011-05-11 12:50:28 -05001586 mult1 = 80;
1587 else
1588 mult1 = 10;
1589 base = mmr_image & UV2_ACK_MASK;
1590 ret = mult1 * base;
1591 }
Cliff Wickman12a66112010-06-02 16:22:01 -05001592 return ret;
1593}
1594
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001595static void __init init_per_cpu_tunables(void)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001596{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001597 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001598 struct bau_control *bcp;
1599
1600 for_each_present_cpu(cpu) {
1601 bcp = &per_cpu(bau_control, cpu);
1602 bcp->baudisabled = 0;
1603 bcp->statp = &per_cpu(ptcstats, cpu);
1604 /* time interval to catch a hardware stay-busy bug */
1605 bcp->timeout_interval = usec_2_cycles(2*timeout_us);
1606 bcp->max_concurr = max_concurr;
1607 bcp->max_concurr_const = max_concurr;
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->cong_response_us = congested_respns_us;
1614 bcp->cong_reps = congested_reps;
1615 bcp->cong_period = congested_period;
1616 }
1617}
1618
1619/*
1620 * Scan all cpus to collect blade and socket summaries.
1621 */
1622static int __init get_cpu_topology(int base_pnode,
1623 struct uvhub_desc *uvhub_descs,
1624 unsigned char *uvhub_mask)
1625{
1626 int cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001627 int pnode;
1628 int uvhub;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001629 int socket;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001630 struct bau_control *bcp;
1631 struct uvhub_desc *bdp;
1632 struct socket_desc *sdp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001633
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001634 for_each_present_cpu(cpu) {
1635 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001636
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001637 memset(bcp, 0, sizeof(struct bau_control));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001638
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001639 pnode = uv_cpu_hub_info(cpu)->pnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001640 if ((pnode - base_pnode) >= UV_DISTRIBUTION_SIZE) {
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001641 printk(KERN_EMERG
1642 "cpu %d pnode %d-%d beyond %d; BAU disabled\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001643 cpu, pnode, base_pnode, UV_DISTRIBUTION_SIZE);
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001644 return 1;
1645 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001646
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001647 bcp->osnode = cpu_to_node(cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001648 bcp->partition_base_pnode = base_pnode;
1649
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001650 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001651 *(uvhub_mask + (uvhub/8)) |= (1 << (uvhub%8));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001652 bdp = &uvhub_descs[uvhub];
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001653
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001654 bdp->num_cpus++;
1655 bdp->uvhub = uvhub;
1656 bdp->pnode = pnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001657
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001658 /* kludge: 'assuming' one node per socket, and assuming that
1659 disabling a socket just leaves a gap in node numbers */
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001660 socket = bcp->osnode & 1;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001661 bdp->socket_mask |= (1 << socket);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001662 sdp = &bdp->socket[socket];
1663 sdp->cpu_number[sdp->num_cpus] = cpu;
1664 sdp->num_cpus++;
Cliff Wickmancfa60912011-01-03 12:03:53 -06001665 if (sdp->num_cpus > MAX_CPUS_PER_SOCKET) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001666 printk(KERN_EMERG "%d cpus per socket invalid\n",
1667 sdp->num_cpus);
Cliff Wickmancfa60912011-01-03 12:03:53 -06001668 return 1;
1669 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001670 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001671 return 0;
1672}
1673
1674/*
1675 * Each socket is to get a local array of pnodes/hubs.
1676 */
1677static void make_per_cpu_thp(struct bau_control *smaster)
1678{
1679 int cpu;
1680 size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
1681
1682 smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
1683 memset(smaster->thp, 0, hpsz);
1684 for_each_present_cpu(cpu) {
1685 smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
1686 smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
1687 }
1688}
1689
1690/*
1691 * Initialize all the per_cpu information for the cpu's on a given socket,
1692 * given what has been gathered into the socket_desc struct.
1693 * And reports the chosen hub and socket masters back to the caller.
1694 */
1695static int scan_sock(struct socket_desc *sdp, struct uvhub_desc *bdp,
1696 struct bau_control **smasterp,
1697 struct bau_control **hmasterp)
1698{
1699 int i;
1700 int cpu;
1701 struct bau_control *bcp;
1702
1703 for (i = 0; i < sdp->num_cpus; i++) {
1704 cpu = sdp->cpu_number[i];
1705 bcp = &per_cpu(bau_control, cpu);
1706 bcp->cpu = cpu;
1707 if (i == 0) {
1708 *smasterp = bcp;
1709 if (!(*hmasterp))
1710 *hmasterp = bcp;
1711 }
1712 bcp->cpus_in_uvhub = bdp->num_cpus;
1713 bcp->cpus_in_socket = sdp->num_cpus;
1714 bcp->socket_master = *smasterp;
1715 bcp->uvhub = bdp->uvhub;
1716 bcp->uvhub_master = *hmasterp;
1717 bcp->uvhub_cpu = uv_cpu_hub_info(cpu)->blade_processor_id;
1718 if (bcp->uvhub_cpu >= MAX_CPUS_PER_UVHUB) {
1719 printk(KERN_EMERG "%d cpus per uvhub invalid\n",
1720 bcp->uvhub_cpu);
1721 return 1;
1722 }
1723 }
1724 return 0;
1725}
1726
1727/*
1728 * Summarize the blade and socket topology into the per_cpu structures.
1729 */
1730static int __init summarize_uvhub_sockets(int nuvhubs,
1731 struct uvhub_desc *uvhub_descs,
1732 unsigned char *uvhub_mask)
1733{
1734 int socket;
1735 int uvhub;
1736 unsigned short socket_mask;
1737
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001738 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001739 struct uvhub_desc *bdp;
1740 struct bau_control *smaster = NULL;
1741 struct bau_control *hmaster = NULL;
1742
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001743 if (!(*(uvhub_mask + (uvhub/8)) & (1 << (uvhub%8))))
1744 continue;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001745
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001746 bdp = &uvhub_descs[uvhub];
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001747 socket_mask = bdp->socket_mask;
1748 socket = 0;
1749 while (socket_mask) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001750 struct socket_desc *sdp;
1751 if ((socket_mask & 1)) {
1752 sdp = &bdp->socket[socket];
1753 if (scan_sock(sdp, bdp, &smaster, &hmaster))
Cliff Wickmancfa60912011-01-03 12:03:53 -06001754 return 1;
cpw@sgi.com9c9153d2011-06-21 07:21:28 -05001755 make_per_cpu_thp(smaster);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001756 }
1757 socket++;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001758 socket_mask = (socket_mask >> 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001759 }
1760 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001761 return 0;
1762}
1763
1764/*
1765 * initialize the bau_control structure for each cpu
1766 */
1767static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
1768{
1769 unsigned char *uvhub_mask;
1770 void *vp;
1771 struct uvhub_desc *uvhub_descs;
1772
1773 timeout_us = calculate_destination_timeout();
1774
1775 vp = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1776 uvhub_descs = (struct uvhub_desc *)vp;
1777 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
1778 uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
1779
1780 if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask))
1781 return 1;
1782
1783 if (summarize_uvhub_sockets(nuvhubs, uvhub_descs, uvhub_mask))
1784 return 1;
1785
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001786 kfree(uvhub_descs);
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001787 kfree(uvhub_mask);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001788 init_per_cpu_tunables();
Cliff Wickmancfa60912011-01-03 12:03:53 -06001789 return 0;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001790}
Cliff Wickman18129242008-06-02 08:56:14 -05001791
1792/*
1793 * Initialization of BAU-related structures
1794 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001795static int __init uv_bau_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001796{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001797 int uvhub;
1798 int pnode;
1799 int nuvhubs;
Rusty Russell2c74d662009-03-18 08:22:30 +10301800 int cur_cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001801 int cpus;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001802 int vector;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001803 cpumask_var_t *mask;
Cliff Wickman18129242008-06-02 08:56:14 -05001804
1805 if (!is_uv_system())
1806 return 0;
1807
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001808 if (nobau)
1809 return 0;
1810
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001811 for_each_possible_cpu(cur_cpu) {
1812 mask = &per_cpu(uv_flush_tlb_mask, cur_cpu);
1813 zalloc_cpumask_var_node(mask, GFP_KERNEL, cpu_to_node(cur_cpu));
1814 }
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301815
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001816 uv_nshift = uv_hub_info->m_val;
Robin Holt036ed8b2009-10-15 17:40:00 -05001817 uv_mmask = (1UL << uv_hub_info->m_val) - 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001818 nuvhubs = uv_num_possible_blades();
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001819 spin_lock_init(&disable_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001820 congested_cycles = usec_2_cycles(congested_respns_us);
Cliff Wickman9674f352009-04-03 08:34:05 -05001821
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001822 uv_base_pnode = 0x7fffffff;
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001823 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001824 cpus = uv_blade_nr_possible_cpus(uvhub);
1825 if (cpus && (uv_blade_to_pnode(uvhub) < uv_base_pnode))
1826 uv_base_pnode = uv_blade_to_pnode(uvhub);
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001827 }
1828
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001829 if (init_per_cpu(nuvhubs, uv_base_pnode)) {
Cliff Wickmancfa60912011-01-03 12:03:53 -06001830 nobau = 1;
1831 return 0;
1832 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001833
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001834 vector = UV_BAU_MESSAGE;
1835 for_each_possible_blade(uvhub)
1836 if (uv_blade_nr_possible_cpus(uvhub))
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001837 init_uvhub(uvhub, vector, uv_base_pnode);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001838
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001839 enable_timeouts();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001840 alloc_intr_gate(vector, uv_bau_message_intr1);
1841
1842 for_each_possible_blade(uvhub) {
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001843 if (uv_blade_nr_possible_cpus(uvhub)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001844 unsigned long val;
1845 unsigned long mmr;
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001846 pnode = uv_blade_to_pnode(uvhub);
1847 /* INIT the bau */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001848 val = 1L << 63;
1849 write_gmmr_activation(pnode, val);
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001850 mmr = 1; /* should be 1 to broadcast to both sockets */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001851 write_mmr_data_broadcast(pnode, mmr);
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001852 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001853 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001854
Cliff Wickman18129242008-06-02 08:56:14 -05001855 return 0;
1856}
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001857core_initcall(uv_bau_init);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001858fs_initcall(uv_ptc_init);