blob: db8b915f54bc50ca23baad161d249d0382c649ab [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/*
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500299 * Determine the first cpu on a pnode.
Cliff Wickman18129242008-06-02 08:56:14 -0500300 */
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500301static int pnode_to_first_cpu(int pnode, struct bau_control *smaster)
Cliff Wickman18129242008-06-02 08:56:14 -0500302{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500303 int cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500304 struct hub_and_pnode *hpp;
305
306 for_each_present_cpu(cpu) {
307 hpp = &smaster->thp[cpu];
308 if (pnode == hpp->pnode)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500309 return cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500310 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500311 return -1;
Cliff Wickman18129242008-06-02 08:56:14 -0500312}
313
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500314/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500315 * Last resort when we get a large number of destination timeouts is
316 * to clear resources held by a given cpu.
317 * Do this with IPI so that all messages in the BAU message queue
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500318 * can be identified by their nonzero swack_vec field.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500319 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500320 * This is entered for a single cpu on the uvhub.
321 * The sender want's this uvhub to free a specific message's
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500322 * swack resources.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500323 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500324static void do_reset(void *ptr)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500325{
326 int i;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500327 struct bau_control *bcp = &per_cpu(bau_control, smp_processor_id());
328 struct reset_args *rap = (struct reset_args *)ptr;
329 struct bau_pq_entry *msg;
330 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500331
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500332 stat->d_resets++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500333 /*
334 * We're looking for the given sender, and
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500335 * will free its swack resource.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500336 * If all cpu's finally responded after the timeout, its
337 * message 'replied_to' was set.
338 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500339 for (msg = bcp->queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
340 unsigned long msg_res;
341 /* do_reset: same conditions for cancellation as
342 bau_process_retry_msg() */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500343 if ((msg->replied_to == 0) &&
344 (msg->canceled == 0) &&
345 (msg->sending_cpu == rap->sender) &&
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500346 (msg->swack_vec) &&
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500347 (msg->msg_type != MSG_NOOP)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500348 unsigned long mmr;
349 unsigned long mr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500350 /*
351 * make everyone else ignore this message
352 */
353 msg->canceled = 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500354 /*
355 * only reset the resource if it is still pending
356 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500357 mmr = read_mmr_sw_ack();
358 msg_res = msg->swack_vec;
359 mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500360 if (mmr & msg_res) {
361 stat->d_rcanceled++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500362 write_mmr_sw_ack(mr);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500363 }
364 }
365 }
366 return;
367}
368
369/*
370 * Use IPI to get all target uvhubs to release resources held by
371 * a given sending cpu number.
372 */
cpw@sgi.coma456eaa2011-06-21 07:21:30 -0500373static void reset_with_ipi(struct pnmask *distribution, struct bau_control *bcp)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500374{
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500375 int pnode;
376 int apnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500377 int maskbits;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500378 int sender = bcp->cpu;
cpw@sgi.com442d3922011-06-21 07:21:31 -0500379 cpumask_t *mask = bcp->uvhub_master->cpumask;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500380 struct bau_control *smaster = bcp->socket_master;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500381 struct reset_args reset_args;
382
383 reset_args.sender = sender;
cpw@sgi.com442d3922011-06-21 07:21:31 -0500384 cpus_clear(*mask);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500385 /* find a single cpu for each uvhub in this distribution mask */
cpw@sgi.coma456eaa2011-06-21 07:21:30 -0500386 maskbits = sizeof(struct pnmask) * BITSPERBYTE;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500387 /* each bit is a pnode relative to the partition base pnode */
388 for (pnode = 0; pnode < maskbits; pnode++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500389 int cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500390 if (!bau_uvhub_isset(pnode, distribution))
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500391 continue;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500392 apnode = pnode + bcp->partition_base_pnode;
393 cpu = pnode_to_first_cpu(apnode, smaster);
cpw@sgi.com442d3922011-06-21 07:21:31 -0500394 cpu_set(cpu, *mask);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500395 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500396
397 /* IPI all cpus; preemption is already disabled */
cpw@sgi.com442d3922011-06-21 07:21:31 -0500398 smp_call_function_many(mask, do_reset, (void *)&reset_args, 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500399 return;
400}
401
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500402static inline unsigned long cycles_2_us(unsigned long long cyc)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500403{
404 unsigned long long ns;
405 unsigned long us;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500406 int cpu = smp_processor_id();
407
408 ns = (cyc * per_cpu(cyc2ns, cpu)) >> CYC2NS_SCALE_FACTOR;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500409 us = ns / 1000;
410 return us;
411}
412
413/*
414 * wait for all cpus on this hub to finish their sends and go quiet
415 * leaves uvhub_quiesce set so that no new broadcasts are started by
416 * bau_flush_send_and_wait()
417 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500418static inline void quiesce_local_uvhub(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);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500421}
422
423/*
424 * mark this quiet-requestor as done
425 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500426static inline void end_uvhub_quiesce(struct bau_control *hmaster)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500427{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500428 atom_asr(-1, (struct atomic_short *)&hmaster->uvhub_quiesce);
429}
430
431static unsigned long uv1_read_status(unsigned long mmr_offset, int right_shift)
432{
433 unsigned long descriptor_status;
434
435 descriptor_status = uv_read_local_mmr(mmr_offset);
436 descriptor_status >>= right_shift;
437 descriptor_status &= UV_ACT_STATUS_MASK;
438 return descriptor_status;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500439}
440
441/*
442 * Wait for completion of a broadcast software ack message
443 * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500444 */
Jack Steiner2a919592011-05-11 12:50:28 -0500445static int uv1_wait_completion(struct bau_desc *bau_desc,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500446 unsigned long mmr_offset, int right_shift,
447 struct bau_control *bcp, long try)
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500448{
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500449 unsigned long descriptor_status;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500450 cycles_t ttm;
Cliff Wickman712157a2010-06-02 16:22:02 -0500451 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500452
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500453 descriptor_status = uv1_read_status(mmr_offset, right_shift);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500454 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500455 while ((descriptor_status != DS_IDLE)) {
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500456 /*
Jack Steiner2a919592011-05-11 12:50:28 -0500457 * Our software ack messages may be blocked because
458 * there are no swack resources available. As long
459 * as none of them has timed out hardware will NACK
460 * our message and its state will stay IDLE.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500461 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500462 if (descriptor_status == DS_SOURCE_TIMEOUT) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500463 stat->s_stimeout++;
464 return FLUSH_GIVEUP;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500465 } else if (descriptor_status == DS_DESTINATION_TIMEOUT) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500466 stat->s_dtimeout++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500467 ttm = get_cycles();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500468
469 /*
470 * Our retries may be blocked by all destination
471 * swack resources being consumed, and a timeout
472 * pending. In that case hardware returns the
473 * ERROR that looks like a destination timeout.
474 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500475 if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500476 bcp->conseccompletes = 0;
477 return FLUSH_RETRY_PLUGGED;
478 }
479
480 bcp->conseccompletes = 0;
481 return FLUSH_RETRY_TIMEOUT;
482 } else {
483 /*
484 * descriptor_status is still BUSY
485 */
486 cpu_relax();
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500487 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500488 descriptor_status = uv1_read_status(mmr_offset, right_shift);
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500489 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500490 bcp->conseccompletes++;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500491 return FLUSH_COMPLETE;
492}
493
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500494/*
495 * UV2 has an extra bit of status in the ACTIVATION_STATUS_2 register.
496 */
497static unsigned long uv2_read_status(unsigned long offset, int rshft, int cpu)
Jack Steiner2a919592011-05-11 12:50:28 -0500498{
499 unsigned long descriptor_status;
500 unsigned long descriptor_status2;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500501
502 descriptor_status = ((read_lmmr(offset) >> rshft) & UV_ACT_STATUS_MASK);
503 descriptor_status2 = (read_mmr_uv2_status() >> cpu) & 0x1UL;
504 descriptor_status = (descriptor_status << 1) | descriptor_status2;
505 return descriptor_status;
506}
507
508static int uv2_wait_completion(struct bau_desc *bau_desc,
509 unsigned long mmr_offset, int right_shift,
510 struct bau_control *bcp, long try)
511{
512 unsigned long descriptor_stat;
513 cycles_t ttm;
514 int cpu = bcp->uvhub_cpu;
Jack Steiner2a919592011-05-11 12:50:28 -0500515 struct ptc_stats *stat = bcp->statp;
516
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500517 descriptor_stat = uv2_read_status(mmr_offset, right_shift, cpu);
518
Jack Steiner2a919592011-05-11 12:50:28 -0500519 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500520 while (descriptor_stat != UV2H_DESC_IDLE) {
Jack Steiner2a919592011-05-11 12:50:28 -0500521 /*
522 * Our software ack messages may be blocked because
523 * there are no swack resources available. As long
524 * as none of them has timed out hardware will NACK
525 * our message and its state will stay IDLE.
526 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500527 if ((descriptor_stat == UV2H_DESC_SOURCE_TIMEOUT) ||
528 (descriptor_stat == UV2H_DESC_DEST_STRONG_NACK) ||
529 (descriptor_stat == UV2H_DESC_DEST_PUT_ERR)) {
Jack Steiner2a919592011-05-11 12:50:28 -0500530 stat->s_stimeout++;
531 return FLUSH_GIVEUP;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500532 } else if (descriptor_stat == UV2H_DESC_DEST_TIMEOUT) {
Jack Steiner2a919592011-05-11 12:50:28 -0500533 stat->s_dtimeout++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500534 ttm = get_cycles();
Jack Steiner2a919592011-05-11 12:50:28 -0500535 /*
536 * Our retries may be blocked by all destination
537 * swack resources being consumed, and a timeout
538 * pending. In that case hardware returns the
539 * ERROR that looks like a destination timeout.
540 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500541 if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
Jack Steiner2a919592011-05-11 12:50:28 -0500542 bcp->conseccompletes = 0;
543 return FLUSH_RETRY_PLUGGED;
544 }
Jack Steiner2a919592011-05-11 12:50:28 -0500545 bcp->conseccompletes = 0;
546 return FLUSH_RETRY_TIMEOUT;
547 } else {
548 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500549 * descriptor_stat is still BUSY
Jack Steiner2a919592011-05-11 12:50:28 -0500550 */
551 cpu_relax();
552 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500553 descriptor_stat = uv2_read_status(mmr_offset, right_shift, cpu);
Jack Steiner2a919592011-05-11 12:50:28 -0500554 }
555 bcp->conseccompletes++;
556 return FLUSH_COMPLETE;
557}
558
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500559/*
560 * There are 2 status registers; each and array[32] of 2 bits. Set up for
561 * which register to read and position in that register based on cpu in
562 * current hub.
563 */
564static int wait_completion(struct bau_desc *bau_desc,
565 struct bau_control *bcp, long try)
Jack Steiner2a919592011-05-11 12:50:28 -0500566{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500567 int right_shift;
568 unsigned long mmr_offset;
569 int cpu = bcp->uvhub_cpu;
570
571 if (cpu < UV_CPUS_PER_AS) {
572 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
573 right_shift = cpu * UV_ACT_STATUS_SIZE;
574 } else {
575 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
576 right_shift = ((cpu - UV_CPUS_PER_AS) * UV_ACT_STATUS_SIZE);
577 }
578
Jack Steiner2a919592011-05-11 12:50:28 -0500579 if (is_uv1_hub())
580 return uv1_wait_completion(bau_desc, mmr_offset, right_shift,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500581 bcp, try);
Jack Steiner2a919592011-05-11 12:50:28 -0500582 else
583 return uv2_wait_completion(bau_desc, mmr_offset, right_shift,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500584 bcp, try);
Jack Steiner2a919592011-05-11 12:50:28 -0500585}
586
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500587static inline cycles_t sec_2_cycles(unsigned long sec)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500588{
589 unsigned long ns;
590 cycles_t cyc;
591
592 ns = sec * 1000000000;
593 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
594 return cyc;
595}
596
597/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500598 * Our retries are blocked by all destination sw ack resources being
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500599 * in use, and a timeout is pending. In that case hardware immediately
600 * returns the ERROR that looks like a destination timeout.
601 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500602static void destination_plugged(struct bau_desc *bau_desc,
603 struct bau_control *bcp,
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500604 struct bau_control *hmaster, struct ptc_stats *stat)
605{
606 udelay(bcp->plugged_delay);
607 bcp->plugged_tries++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500608
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500609 if (bcp->plugged_tries >= bcp->plugsb4reset) {
610 bcp->plugged_tries = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500611
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500612 quiesce_local_uvhub(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500613
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500614 spin_lock(&hmaster->queue_lock);
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500615 reset_with_ipi(&bau_desc->distribution, bcp);
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500616 spin_unlock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500617
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500618 end_uvhub_quiesce(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500619
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500620 bcp->ipi_attempts++;
621 stat->s_resets_plug++;
622 }
623}
624
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500625static void destination_timeout(struct bau_desc *bau_desc,
626 struct bau_control *bcp, struct bau_control *hmaster,
627 struct ptc_stats *stat)
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500628{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500629 hmaster->max_concurr = 1;
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500630 bcp->timeout_tries++;
631 if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
632 bcp->timeout_tries = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500633
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500634 quiesce_local_uvhub(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500635
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500636 spin_lock(&hmaster->queue_lock);
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500637 reset_with_ipi(&bau_desc->distribution, bcp);
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500638 spin_unlock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500639
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500640 end_uvhub_quiesce(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500641
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500642 bcp->ipi_attempts++;
643 stat->s_resets_timeout++;
644 }
645}
646
647/*
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500648 * Completions are taking a very long time due to a congested numalink
649 * network.
650 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500651static void disable_for_congestion(struct bau_control *bcp,
652 struct ptc_stats *stat)
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500653{
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500654 /* let only one cpu do this disabling */
655 spin_lock(&disable_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500656
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500657 if (!baudisabled && bcp->period_requests &&
658 ((bcp->period_time / bcp->period_requests) > congested_cycles)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500659 int tcpu;
660 struct bau_control *tbcp;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500661 /* it becomes this cpu's job to turn on the use of the
662 BAU again */
663 baudisabled = 1;
664 bcp->set_bau_off = 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500665 bcp->set_bau_on_time = get_cycles();
666 bcp->set_bau_on_time += sec_2_cycles(bcp->cong_period);
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500667 stat->s_bau_disabled++;
668 for_each_present_cpu(tcpu) {
669 tbcp = &per_cpu(bau_control, tcpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500670 tbcp->baudisabled = 1;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500671 }
672 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500673
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500674 spin_unlock(&disable_lock);
675}
676
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500677static void count_max_concurr(int stat, struct bau_control *bcp,
678 struct bau_control *hmaster)
679{
680 bcp->plugged_tries = 0;
681 bcp->timeout_tries = 0;
682 if (stat != FLUSH_COMPLETE)
683 return;
684 if (bcp->conseccompletes <= bcp->complete_threshold)
685 return;
686 if (hmaster->max_concurr >= hmaster->max_concurr_const)
687 return;
688 hmaster->max_concurr++;
689}
690
691static void record_send_stats(cycles_t time1, cycles_t time2,
692 struct bau_control *bcp, struct ptc_stats *stat,
693 int completion_status, int try)
694{
695 cycles_t elapsed;
696
697 if (time2 > time1) {
698 elapsed = time2 - time1;
699 stat->s_time += elapsed;
700
701 if ((completion_status == FLUSH_COMPLETE) && (try == 1)) {
702 bcp->period_requests++;
703 bcp->period_time += elapsed;
704 if ((elapsed > congested_cycles) &&
705 (bcp->period_requests > bcp->cong_reps))
706 disable_for_congestion(bcp, stat);
707 }
708 } else
709 stat->s_requestor--;
710
711 if (completion_status == FLUSH_COMPLETE && try > 1)
712 stat->s_retriesok++;
713 else if (completion_status == FLUSH_GIVEUP)
714 stat->s_giveup++;
715}
716
717/*
718 * Because of a uv1 hardware bug only a limited number of concurrent
719 * requests can be made.
720 */
721static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
722{
723 spinlock_t *lock = &hmaster->uvhub_lock;
724 atomic_t *v;
725
726 v = &hmaster->active_descriptor_count;
727 if (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr)) {
728 stat->s_throttles++;
729 do {
730 cpu_relax();
731 } while (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr));
732 }
733}
734
735/*
736 * Handle the completion status of a message send.
737 */
738static void handle_cmplt(int completion_status, struct bau_desc *bau_desc,
739 struct bau_control *bcp, struct bau_control *hmaster,
740 struct ptc_stats *stat)
741{
742 if (completion_status == FLUSH_RETRY_PLUGGED)
743 destination_plugged(bau_desc, bcp, hmaster, stat);
744 else if (completion_status == FLUSH_RETRY_TIMEOUT)
745 destination_timeout(bau_desc, bcp, hmaster, stat);
746}
747
748/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500749 * Send a broadcast and wait for it to complete.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500750 *
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500751 * The flush_mask contains the cpus the broadcast is to be sent to including
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500752 * cpus that are on the local uvhub.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500753 *
Cliff Wickman450a0072010-06-02 16:22:02 -0500754 * Returns 0 if all flushing represented in the mask was done.
755 * Returns 1 if it gives up entirely and the original cpu mask is to be
756 * returned to the kernel.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500757 */
Cliff Wickman450a0072010-06-02 16:22:02 -0500758int uv_flush_send_and_wait(struct bau_desc *bau_desc,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500759 struct cpumask *flush_mask, struct bau_control *bcp)
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500760{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500761 int seq_number = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500762 int completion_stat = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500763 long try = 0;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200764 unsigned long index;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500765 cycles_t time1;
766 cycles_t time2;
Cliff Wickman712157a2010-06-02 16:22:02 -0500767 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500768 struct bau_control *hmaster = bcp->uvhub_master;
769
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500770 if (is_uv1_hub())
771 uv1_throttle(hmaster, stat);
772
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500773 while (hmaster->uvhub_quiesce)
774 cpu_relax();
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500775
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500776 time1 = get_cycles();
777 do {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500778 if (try == 0) {
Cliff Wickman7fba1bc2010-06-02 16:22:02 -0500779 bau_desc->header.msg_type = MSG_REGULAR;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500780 seq_number = bcp->message_number++;
781 } else {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500782 bau_desc->header.msg_type = MSG_RETRY;
783 stat->s_retry_messages++;
784 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500785
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500786 bau_desc->header.sequence = seq_number;
787 index = (1UL << AS_PUSH_SHIFT) | bcp->uvhub_cpu;
788 bcp->send_message = get_cycles();
789
790 write_mmr_activation(index);
791
792 try++;
793 completion_stat = wait_completion(bau_desc, bcp, try);
794
795 handle_cmplt(completion_stat, bau_desc, bcp, hmaster, stat);
796
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500797 if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500798 bcp->ipi_attempts = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500799 completion_stat = FLUSH_GIVEUP;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500800 break;
801 }
802 cpu_relax();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500803 } while ((completion_stat == FLUSH_RETRY_PLUGGED) ||
804 (completion_stat == FLUSH_RETRY_TIMEOUT));
805
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500806 time2 = get_cycles();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500807
808 count_max_concurr(completion_stat, bcp, hmaster);
809
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500810 while (hmaster->uvhub_quiesce)
811 cpu_relax();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500812
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500813 atomic_dec(&hmaster->active_descriptor_count);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500814
815 record_send_stats(time1, time2, bcp, stat, completion_stat, try);
816
817 if (completion_stat == FLUSH_GIVEUP)
Cliff Wickman450a0072010-06-02 16:22:02 -0500818 return 1;
Cliff Wickman450a0072010-06-02 16:22:02 -0500819 return 0;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500820}
821
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500822/*
823 * The BAU is disabled. When the disabled time period has expired, the cpu
824 * that disabled it must re-enable it.
825 * Return 0 if it is re-enabled for all cpus.
826 */
827static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
828{
829 int tcpu;
830 struct bau_control *tbcp;
831
832 if (bcp->set_bau_off) {
833 if (get_cycles() >= bcp->set_bau_on_time) {
834 stat->s_bau_reenabled++;
835 baudisabled = 0;
836 for_each_present_cpu(tcpu) {
837 tbcp = &per_cpu(bau_control, tcpu);
838 tbcp->baudisabled = 0;
839 tbcp->period_requests = 0;
840 tbcp->period_time = 0;
841 }
842 return 0;
843 }
844 }
845 return -1;
846}
847
848static void record_send_statistics(struct ptc_stats *stat, int locals, int hubs,
849 int remotes, struct bau_desc *bau_desc)
850{
851 stat->s_requestor++;
852 stat->s_ntargcpu += remotes + locals;
853 stat->s_ntargremotes += remotes;
854 stat->s_ntarglocals += locals;
855
856 /* uvhub statistics */
857 hubs = bau_uvhub_weight(&bau_desc->distribution);
858 if (locals) {
859 stat->s_ntarglocaluvhub++;
860 stat->s_ntargremoteuvhub += (hubs - 1);
861 } else
862 stat->s_ntargremoteuvhub += hubs;
863
864 stat->s_ntarguvhub += hubs;
865
866 if (hubs >= 16)
867 stat->s_ntarguvhub16++;
868 else if (hubs >= 8)
869 stat->s_ntarguvhub8++;
870 else if (hubs >= 4)
871 stat->s_ntarguvhub4++;
872 else if (hubs >= 2)
873 stat->s_ntarguvhub2++;
874 else
875 stat->s_ntarguvhub1++;
876}
877
878/*
879 * Translate a cpu mask to the uvhub distribution mask in the BAU
880 * activation descriptor.
881 */
882static int set_distrib_bits(struct cpumask *flush_mask, struct bau_control *bcp,
883 struct bau_desc *bau_desc, int *localsp, int *remotesp)
884{
885 int cpu;
886 int pnode;
887 int cnt = 0;
888 struct hub_and_pnode *hpp;
889
890 for_each_cpu(cpu, flush_mask) {
891 /*
892 * The distribution vector is a bit map of pnodes, relative
893 * to the partition base pnode (and the partition base nasid
894 * in the header).
895 * Translate cpu to pnode and hub using a local memory array.
896 */
897 hpp = &bcp->socket_master->thp[cpu];
898 pnode = hpp->pnode - bcp->partition_base_pnode;
899 bau_uvhub_set(pnode, &bau_desc->distribution);
900 cnt++;
901 if (hpp->uvhub == bcp->uvhub)
902 (*localsp)++;
903 else
904 (*remotesp)++;
905 }
906 if (!cnt)
907 return 1;
908 return 0;
909}
910
911/*
912 * globally purge translation cache of a virtual address or all TLB's
Tejun Heobdbcdd42009-01-21 17:26:06 +0900913 * @cpumask: mask of all cpu's in which the address is to be removed
Cliff Wickman18129242008-06-02 08:56:14 -0500914 * @mm: mm_struct containing virtual address range
915 * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
Tejun Heobdbcdd42009-01-21 17:26:06 +0900916 * @cpu: the current cpu
Cliff Wickman18129242008-06-02 08:56:14 -0500917 *
918 * This is the entry point for initiating any UV global TLB shootdown.
919 *
920 * Purges the translation caches of all specified processors of the given
921 * virtual address, or purges all TLB's on specified processors.
922 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900923 * The caller has derived the cpumask from the mm_struct. This function
924 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
Cliff Wickman18129242008-06-02 08:56:14 -0500925 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500926 * The cpumask is converted into a uvhubmask of the uvhubs containing
927 * those cpus.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500928 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900929 * Note that this function should be called with preemption disabled.
930 *
931 * Returns NULL if all remote flushing was done.
932 * Returns pointer to cpumask if some remote flushing remains to be
933 * done. The returned pointer is valid till preemption is re-enabled.
Cliff Wickman18129242008-06-02 08:56:14 -0500934 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900935const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500936 struct mm_struct *mm, unsigned long va,
937 unsigned int cpu)
Cliff Wickman18129242008-06-02 08:56:14 -0500938{
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500939 int locals = 0;
Cliff Wickman450a0072010-06-02 16:22:02 -0500940 int remotes = 0;
941 int hubs = 0;
Ingo Molnardc163a42008-06-18 14:15:43 +0200942 struct bau_desc *bau_desc;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500943 struct cpumask *flush_mask;
944 struct ptc_stats *stat;
945 struct bau_control *bcp;
Cliff Wickman18129242008-06-02 08:56:14 -0500946
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500947 /* kernel was booted 'nobau' */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500948 if (nobau)
949 return cpumask;
950
951 bcp = &per_cpu(bau_control, cpu);
Cliff Wickman712157a2010-06-02 16:22:02 -0500952 stat = bcp->statp;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500953
954 /* bau was disabled due to slow response */
955 if (bcp->baudisabled) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500956 if (check_enable(bcp, stat))
957 return cpumask;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500958 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500959
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500960 /*
961 * Each sending cpu has a per-cpu mask which it fills from the caller's
Cliff Wickman450a0072010-06-02 16:22:02 -0500962 * cpu mask. All cpus are converted to uvhubs and copied to the
963 * activation descriptor.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500964 */
965 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
Cliff Wickman450a0072010-06-02 16:22:02 -0500966 /* don't actually do a shootdown of the local cpu */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900967 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500968
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500969 if (cpu_isset(cpu, *cpumask))
Cliff Wickman450a0072010-06-02 16:22:02 -0500970 stat->s_ntargself++;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900971
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500972 bau_desc = bcp->descriptor_base;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500973 bau_desc += ITEMS_PER_DESC * bcp->uvhub_cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500974 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500975 if (set_distrib_bits(flush_mask, bcp, bau_desc, &locals, &remotes))
Cliff Wickman450a0072010-06-02 16:22:02 -0500976 return NULL;
Cliff Wickman450a0072010-06-02 16:22:02 -0500977
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500978 record_send_statistics(stat, locals, hubs, remotes, bau_desc);
Cliff Wickman18129242008-06-02 08:56:14 -0500979
980 bau_desc->payload.address = va;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900981 bau_desc->payload.sending_cpu = cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500982 /*
Cliff Wickman450a0072010-06-02 16:22:02 -0500983 * uv_flush_send_and_wait returns 0 if all cpu's were messaged,
984 * or 1 if it gave up and the original cpumask should be returned.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500985 */
Cliff Wickman450a0072010-06-02 16:22:02 -0500986 if (!uv_flush_send_and_wait(bau_desc, flush_mask, bcp))
987 return NULL;
988 else
989 return cpumask;
Cliff Wickman18129242008-06-02 08:56:14 -0500990}
991
992/*
993 * The BAU message interrupt comes here. (registered by set_intr_gate)
994 * See entry_64.S
995 *
996 * We received a broadcast assist message.
997 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500998 * Interrupts are disabled; this interrupt could represent
Cliff Wickman18129242008-06-02 08:56:14 -0500999 * the receipt of several messages.
1000 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001001 * All cores/threads on this hub get this interrupt.
1002 * The last one to see it does the software ack.
Cliff Wickman18129242008-06-02 08:56:14 -05001003 * (the resource will not be freed until noninterruptable cpus see this
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001004 * interrupt; hardware may timeout the s/w ack and reply ERROR)
Cliff Wickman18129242008-06-02 08:56:14 -05001005 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001006void uv_bau_message_interrupt(struct pt_regs *regs)
Cliff Wickman18129242008-06-02 08:56:14 -05001007{
Cliff Wickman18129242008-06-02 08:56:14 -05001008 int count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001009 cycles_t time_start;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001010 struct bau_pq_entry *msg;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001011 struct bau_control *bcp;
1012 struct ptc_stats *stat;
1013 struct msg_desc msgdesc;
Cliff Wickman18129242008-06-02 08:56:14 -05001014
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001015 time_start = get_cycles();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001016
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001017 bcp = &per_cpu(bau_control, smp_processor_id());
Cliff Wickman712157a2010-06-02 16:22:02 -05001018 stat = bcp->statp;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001019
1020 msgdesc.queue_first = bcp->queue_first;
1021 msgdesc.queue_last = bcp->queue_last;
1022
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001023 msg = bcp->bau_msg_head;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001024 while (msg->swack_vec) {
Cliff Wickman18129242008-06-02 08:56:14 -05001025 count++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001026
1027 msgdesc.msg_slot = msg - msgdesc.queue_first;
1028 msgdesc.swack_slot = ffs(msg->swack_vec) - 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001029 msgdesc.msg = msg;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001030 bau_process_message(&msgdesc, bcp);
1031
Cliff Wickman18129242008-06-02 08:56:14 -05001032 msg++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001033 if (msg > msgdesc.queue_last)
1034 msg = msgdesc.queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001035 bcp->bau_msg_head = msg;
Cliff Wickman18129242008-06-02 08:56:14 -05001036 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001037 stat->d_time += (get_cycles() - time_start);
Cliff Wickman18129242008-06-02 08:56:14 -05001038 if (!count)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001039 stat->d_nomsg++;
Cliff Wickman18129242008-06-02 08:56:14 -05001040 else if (count > 1)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001041 stat->d_multmsg++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001042
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001043 ack_APIC_irq();
Cliff Wickman18129242008-06-02 08:56:14 -05001044}
1045
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001046/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001047 * Each target uvhub (i.e. a uvhub that has cpu's) needs to have
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001048 * shootdown message timeouts enabled. The timeout does not cause
1049 * an interrupt, but causes an error message to be returned to
1050 * the sender.
1051 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001052static void __init enable_timeouts(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001053{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001054 int uvhub;
1055 int nuvhubs;
Cliff Wickman18129242008-06-02 08:56:14 -05001056 int pnode;
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001057 unsigned long mmr_image;
Cliff Wickman18129242008-06-02 08:56:14 -05001058
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001059 nuvhubs = uv_num_possible_blades();
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001060
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001061 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
1062 if (!uv_blade_nr_possible_cpus(uvhub))
Cliff Wickman18129242008-06-02 08:56:14 -05001063 continue;
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001064
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001065 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001066 mmr_image = read_mmr_misc_control(pnode);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001067 /*
1068 * Set the timeout period and then lock it in, in three
1069 * steps; captures and locks in the period.
1070 *
1071 * To program the period, the SOFT_ACK_MODE must be off.
1072 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001073 mmr_image &= ~(1L << SOFTACK_MSHIFT);
1074 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001075 /*
1076 * Set the 4-bit period.
1077 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001078 mmr_image &= ~((unsigned long)0xf << SOFTACK_PSHIFT);
1079 mmr_image |= (SOFTACK_TIMEOUT_PERIOD << SOFTACK_PSHIFT);
1080 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001081 /*
Jack Steiner2a919592011-05-11 12:50:28 -05001082 * UV1:
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001083 * Subsequent reversals of the timebase bit (3) cause an
1084 * immediate timeout of one or all INTD resources as
1085 * indicated in bits 2:0 (7 causes all of them to timeout).
1086 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001087 mmr_image |= (1L << SOFTACK_MSHIFT);
Jack Steiner2a919592011-05-11 12:50:28 -05001088 if (is_uv2_hub()) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001089 mmr_image |= (1L << UV2_LEG_SHFT);
1090 mmr_image |= (1L << UV2_EXT_SHFT);
Jack Steiner2a919592011-05-11 12:50:28 -05001091 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001092 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickman18129242008-06-02 08:56:14 -05001093 }
Cliff Wickman18129242008-06-02 08:56:14 -05001094}
1095
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001096static void *ptc_seq_start(struct seq_file *file, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -05001097{
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_next(struct seq_file *file, void *data, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -05001104{
1105 (*offset)++;
1106 if (*offset < num_possible_cpus())
1107 return offset;
1108 return NULL;
1109}
1110
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001111static void ptc_seq_stop(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001112{
1113}
1114
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001115static inline unsigned long long usec_2_cycles(unsigned long microsec)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001116{
1117 unsigned long ns;
1118 unsigned long long cyc;
1119
Cliff Wickman12a66112010-06-02 16:22:01 -05001120 ns = microsec * 1000;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001121 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
1122 return cyc;
1123}
1124
Cliff Wickman18129242008-06-02 08:56:14 -05001125/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001126 * Display the statistics thru /proc/sgi_uv/ptc_statistics
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001127 * 'data' points to the cpu number
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001128 * Note: see the descriptions in stat_description[].
Cliff Wickman18129242008-06-02 08:56:14 -05001129 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001130static int ptc_seq_show(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001131{
1132 struct ptc_stats *stat;
1133 int cpu;
1134
1135 cpu = *(loff_t *)data;
Cliff Wickman18129242008-06-02 08:56:14 -05001136 if (!cpu) {
1137 seq_printf(file,
Cliff Wickman450a0072010-06-02 16:22:02 -05001138 "# cpu sent stime self locals remotes ncpus localhub ");
Cliff Wickman18129242008-06-02 08:56:14 -05001139 seq_printf(file,
Cliff Wickman450a0072010-06-02 16:22:02 -05001140 "remotehub numuvhubs numuvhubs16 numuvhubs8 ");
1141 seq_printf(file,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001142 "numuvhubs4 numuvhubs2 numuvhubs1 dto retries rok ");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001143 seq_printf(file,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001144 "resetp resett giveup sto bz throt swack recv rtime ");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001145 seq_printf(file,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001146 "all one mult none retry canc nocan reset rcan ");
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001147 seq_printf(file,
1148 "disable enable\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001149 }
1150 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
1151 stat = &per_cpu(ptcstats, cpu);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001152 /* source side statistics */
1153 seq_printf(file,
1154 "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
1155 cpu, stat->s_requestor, cycles_2_us(stat->s_time),
Cliff Wickman450a0072010-06-02 16:22:02 -05001156 stat->s_ntargself, stat->s_ntarglocals,
1157 stat->s_ntargremotes, stat->s_ntargcpu,
1158 stat->s_ntarglocaluvhub, stat->s_ntargremoteuvhub,
1159 stat->s_ntarguvhub, stat->s_ntarguvhub16);
1160 seq_printf(file, "%ld %ld %ld %ld %ld ",
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001161 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
1162 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
Cliff Wickman450a0072010-06-02 16:22:02 -05001163 stat->s_dtimeout);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001164 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
1165 stat->s_retry_messages, stat->s_retriesok,
1166 stat->s_resets_plug, stat->s_resets_timeout,
1167 stat->s_giveup, stat->s_stimeout,
1168 stat->s_busy, stat->s_throttles);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001169
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001170 /* destination side statistics */
1171 seq_printf(file,
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001172 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001173 read_gmmr_sw_ack(uv_cpu_to_pnode(cpu)),
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001174 stat->d_requestee, cycles_2_us(stat->d_time),
1175 stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
1176 stat->d_nomsg, stat->d_retries, stat->d_canceled,
1177 stat->d_nocanceled, stat->d_resets,
1178 stat->d_rcanceled);
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001179 seq_printf(file, "%ld %ld\n",
1180 stat->s_bau_disabled, stat->s_bau_reenabled);
Cliff Wickman18129242008-06-02 08:56:14 -05001181 }
Cliff Wickman18129242008-06-02 08:56:14 -05001182 return 0;
1183}
1184
1185/*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001186 * Display the tunables thru debugfs
1187 */
1188static ssize_t tunables_read(struct file *file, char __user *userbuf,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001189 size_t count, loff_t *ppos)
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001190{
Dan Carpenterb365a852010-09-29 10:41:05 +02001191 char *buf;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001192 int ret;
1193
Dan Carpenterb365a852010-09-29 10:41:05 +02001194 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 -05001195 "max_concur plugged_delay plugsb4reset",
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001196 "timeoutsb4reset ipi_reset_limit complete_threshold",
1197 "congested_response_us congested_reps congested_period",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001198 max_concurr, plugged_delay, plugsb4reset,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001199 timeoutsb4reset, ipi_reset_limit, complete_threshold,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001200 congested_respns_us, congested_reps, congested_period);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001201
Dan Carpenterb365a852010-09-29 10:41:05 +02001202 if (!buf)
1203 return -ENOMEM;
1204
1205 ret = simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
1206 kfree(buf);
1207 return ret;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001208}
1209
1210/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001211 * handle a write to /proc/sgi_uv/ptc_statistics
1212 * -1: reset the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001213 * 0: display meaning of the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001214 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001215static ssize_t ptc_proc_write(struct file *file, const char __user *user,
1216 size_t count, loff_t *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001217{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001218 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001219 int i;
1220 int elements;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001221 long input_arg;
Cliff Wickman18129242008-06-02 08:56:14 -05001222 char optstr[64];
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001223 struct ptc_stats *stat;
Cliff Wickman18129242008-06-02 08:56:14 -05001224
Cliff Wickmane7eb8722008-06-23 08:32:25 -05001225 if (count == 0 || count > sizeof(optstr))
Cliff Wickmancef53272008-06-19 11:16:24 -05001226 return -EINVAL;
Cliff Wickman18129242008-06-02 08:56:14 -05001227 if (copy_from_user(optstr, user, count))
1228 return -EFAULT;
1229 optstr[count - 1] = '\0';
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001230
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001231 if (strict_strtol(optstr, 10, &input_arg) < 0) {
Cliff Wickman18129242008-06-02 08:56:14 -05001232 printk(KERN_DEBUG "%s is invalid\n", optstr);
1233 return -EINVAL;
1234 }
1235
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001236 if (input_arg == 0) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001237 elements = sizeof(stat_description)/sizeof(*stat_description);
Cliff Wickman18129242008-06-02 08:56:14 -05001238 printk(KERN_DEBUG "# cpu: cpu number\n");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001239 printk(KERN_DEBUG "Sender statistics:\n");
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001240 for (i = 0; i < elements; i++)
1241 printk(KERN_DEBUG "%s\n", stat_description[i]);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001242 } else if (input_arg == -1) {
1243 for_each_present_cpu(cpu) {
1244 stat = &per_cpu(ptcstats, cpu);
1245 memset(stat, 0, sizeof(struct ptc_stats));
1246 }
Cliff Wickman18129242008-06-02 08:56:14 -05001247 }
1248
1249 return count;
1250}
1251
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001252static int local_atoi(const char *name)
1253{
1254 int val = 0;
1255
1256 for (;; name++) {
1257 switch (*name) {
1258 case '0' ... '9':
1259 val = 10*val+(*name-'0');
1260 break;
1261 default:
1262 return val;
1263 }
1264 }
1265}
1266
1267/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001268 * Parse the values written to /sys/kernel/debug/sgi_uv/bau_tunables.
1269 * Zero values reset them to defaults.
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001270 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001271static int parse_tunables_write(struct bau_control *bcp, char *instr,
1272 int count)
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001273{
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001274 char *p;
1275 char *q;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001276 int cnt = 0;
1277 int val;
1278 int e = sizeof(tunables) / sizeof(*tunables);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001279
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001280 p = instr + strspn(instr, WHITESPACE);
1281 q = p;
1282 for (; *p; p = q + strspn(q, WHITESPACE)) {
1283 q = p + strcspn(p, WHITESPACE);
1284 cnt++;
1285 if (q == p)
1286 break;
1287 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001288 if (cnt != e) {
1289 printk(KERN_INFO "bau tunable error: should be %d values\n", e);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001290 return -EINVAL;
1291 }
1292
1293 p = instr + strspn(instr, WHITESPACE);
1294 q = p;
1295 for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
1296 q = p + strcspn(p, WHITESPACE);
1297 val = local_atoi(p);
1298 switch (cnt) {
1299 case 0:
1300 if (val == 0) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001301 max_concurr = MAX_BAU_CONCURRENT;
1302 max_concurr_const = MAX_BAU_CONCURRENT;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001303 continue;
1304 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001305 if (val < 1 || val > bcp->cpus_in_uvhub) {
1306 printk(KERN_DEBUG
1307 "Error: BAU max concurrent %d is invalid\n",
1308 val);
1309 return -EINVAL;
1310 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001311 max_concurr = val;
1312 max_concurr_const = val;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001313 continue;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001314 default:
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001315 if (val == 0)
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001316 *tunables[cnt].tunp = tunables[cnt].deflt;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001317 else
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001318 *tunables[cnt].tunp = val;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001319 continue;
1320 }
1321 if (q == p)
1322 break;
1323 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001324 return 0;
1325}
1326
1327/*
1328 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
1329 */
1330static ssize_t tunables_write(struct file *file, const char __user *user,
1331 size_t count, loff_t *data)
1332{
1333 int cpu;
1334 int ret;
1335 char instr[100];
1336 struct bau_control *bcp;
1337
1338 if (count == 0 || count > sizeof(instr)-1)
1339 return -EINVAL;
1340 if (copy_from_user(instr, user, count))
1341 return -EFAULT;
1342
1343 instr[count] = '\0';
1344
cpw@sgi.com00b30cf2011-06-21 07:21:26 -05001345 cpu = get_cpu();
1346 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001347 ret = parse_tunables_write(bcp, instr, count);
cpw@sgi.com00b30cf2011-06-21 07:21:26 -05001348 put_cpu();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001349 if (ret)
1350 return ret;
1351
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001352 for_each_present_cpu(cpu) {
1353 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001354 bcp->max_concurr = max_concurr;
1355 bcp->max_concurr_const = max_concurr;
1356 bcp->plugged_delay = plugged_delay;
1357 bcp->plugsb4reset = plugsb4reset;
1358 bcp->timeoutsb4reset = timeoutsb4reset;
1359 bcp->ipi_reset_limit = ipi_reset_limit;
1360 bcp->complete_threshold = complete_threshold;
1361 bcp->cong_response_us = congested_respns_us;
1362 bcp->cong_reps = congested_reps;
1363 bcp->cong_period = congested_period;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001364 }
1365 return count;
1366}
1367
Cliff Wickman18129242008-06-02 08:56:14 -05001368static const struct seq_operations uv_ptc_seq_ops = {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001369 .start = ptc_seq_start,
1370 .next = ptc_seq_next,
1371 .stop = ptc_seq_stop,
1372 .show = ptc_seq_show
Cliff Wickman18129242008-06-02 08:56:14 -05001373};
1374
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001375static int ptc_proc_open(struct inode *inode, struct file *file)
Cliff Wickman18129242008-06-02 08:56:14 -05001376{
1377 return seq_open(file, &uv_ptc_seq_ops);
1378}
1379
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001380static int tunables_open(struct inode *inode, struct file *file)
1381{
1382 return 0;
1383}
1384
Cliff Wickman18129242008-06-02 08:56:14 -05001385static const struct file_operations proc_uv_ptc_operations = {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001386 .open = ptc_proc_open,
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001387 .read = seq_read,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001388 .write = ptc_proc_write,
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001389 .llseek = seq_lseek,
1390 .release = seq_release,
Cliff Wickman18129242008-06-02 08:56:14 -05001391};
1392
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001393static const struct file_operations tunables_fops = {
1394 .open = tunables_open,
1395 .read = tunables_read,
1396 .write = tunables_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001397 .llseek = default_llseek,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001398};
1399
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001400static int __init uv_ptc_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001401{
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001402 struct proc_dir_entry *proc_uv_ptc;
Cliff Wickman18129242008-06-02 08:56:14 -05001403
1404 if (!is_uv_system())
1405 return 0;
1406
Alexey Dobriyan10f02d112009-08-23 23:17:27 +04001407 proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
1408 &proc_uv_ptc_operations);
Cliff Wickman18129242008-06-02 08:56:14 -05001409 if (!proc_uv_ptc) {
1410 printk(KERN_ERR "unable to create %s proc entry\n",
1411 UV_PTC_BASENAME);
1412 return -EINVAL;
1413 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001414
1415 tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
1416 if (!tunables_dir) {
1417 printk(KERN_ERR "unable to create debugfs directory %s\n",
1418 UV_BAU_TUNABLES_DIR);
1419 return -EINVAL;
1420 }
1421 tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001422 tunables_dir, NULL, &tunables_fops);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001423 if (!tunables_file) {
1424 printk(KERN_ERR "unable to create debugfs file %s\n",
1425 UV_BAU_TUNABLES_FILE);
1426 return -EINVAL;
1427 }
Cliff Wickman18129242008-06-02 08:56:14 -05001428 return 0;
1429}
1430
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001431/*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001432 * Initialize the sending side's sending buffers.
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001433 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001434static void activation_descriptor_init(int node, int pnode, int base_pnode)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001435{
1436 int i;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001437 int cpu;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001438 unsigned long pa;
1439 unsigned long m;
1440 unsigned long n;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001441 size_t dsize;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001442 struct bau_desc *bau_desc;
1443 struct bau_desc *bd2;
1444 struct bau_control *bcp;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001445
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001446 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001447 * each bau_desc is 64 bytes; there are 8 (ITEMS_PER_DESC)
1448 * per cpu; and one per cpu on the uvhub (ADP_SZ)
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001449 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001450 dsize = sizeof(struct bau_desc) * ADP_SZ * ITEMS_PER_DESC;
1451 bau_desc = kmalloc_node(dsize, GFP_KERNEL, node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001452 BUG_ON(!bau_desc);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001453
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001454 pa = uv_gpa(bau_desc); /* need the real nasid*/
1455 n = pa >> uv_nshift;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001456 m = pa & uv_mmask;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001457
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001458 /* the 14-bit pnode */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001459 write_mmr_descriptor_base(pnode, (n << UV_DESC_PSHIFT | m));
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001460 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001461 * Initializing all 8 (ITEMS_PER_DESC) descriptors for each
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001462 * cpu even though we only use the first one; one descriptor can
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001463 * describe a broadcast to 256 uv hubs.
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001464 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001465 for (i = 0, bd2 = bau_desc; i < (ADP_SZ * ITEMS_PER_DESC); i++, bd2++) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001466 memset(bd2, 0, sizeof(struct bau_desc));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001467 bd2->header.swack_flag = 1;
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001468 /*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001469 * The base_dest_nasid set in the message header is the nasid
1470 * of the first uvhub in the partition. The bit map will
1471 * indicate destination pnode numbers relative to that base.
1472 * They may not be consecutive if nasid striding is being used.
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001473 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001474 bd2->header.base_dest_nasid = UV_PNODE_TO_NASID(base_pnode);
1475 bd2->header.dest_subnodeid = UV_LB_SUBNODEID;
1476 bd2->header.command = UV_NET_ENDPOINT_INTD;
1477 bd2->header.int_both = 1;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001478 /*
1479 * all others need to be set to zero:
1480 * fairness chaining multilevel count replied_to
1481 */
1482 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001483 for_each_present_cpu(cpu) {
1484 if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
1485 continue;
1486 bcp = &per_cpu(bau_control, cpu);
1487 bcp->descriptor_base = bau_desc;
1488 }
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001489}
1490
1491/*
1492 * initialize the destination side's receiving buffers
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001493 * entered for each uvhub in the partition
1494 * - node is first node (kernel memory notion) on the uvhub
1495 * - pnode is the uvhub's physical identifier
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001496 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001497static void pq_init(int node, int pnode)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001498{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001499 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001500 size_t plsize;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001501 char *cp;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001502 void *vp;
1503 unsigned long pn;
1504 unsigned long first;
1505 unsigned long pn_first;
1506 unsigned long last;
1507 struct bau_pq_entry *pqp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001508 struct bau_control *bcp;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001509
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001510 plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
1511 vp = kmalloc_node(plsize, GFP_KERNEL, node);
1512 pqp = (struct bau_pq_entry *)vp;
Ingo Molnardc163a42008-06-18 14:15:43 +02001513 BUG_ON(!pqp);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001514
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001515 cp = (char *)pqp + 31;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001516 pqp = (struct bau_pq_entry *)(((unsigned long)cp >> 5) << 5);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001517
1518 for_each_present_cpu(cpu) {
1519 if (pnode != uv_cpu_to_pnode(cpu))
1520 continue;
1521 /* for every cpu on this pnode: */
1522 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001523 bcp->queue_first = pqp;
1524 bcp->bau_msg_head = pqp;
1525 bcp->queue_last = pqp + (DEST_Q_SIZE - 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001526 }
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001527 /*
1528 * need the pnode of where the memory was really allocated
1529 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001530 pn = uv_gpa(pqp) >> uv_nshift;
1531 first = uv_physnodeaddr(pqp);
1532 pn_first = ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) | first;
1533 last = uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1));
1534 write_mmr_payload_first(pnode, pn_first);
1535 write_mmr_payload_tail(pnode, first);
1536 write_mmr_payload_last(pnode, last);
1537
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001538 /* in effect, all msg_type's are set to MSG_NOOP */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001539 memset(pqp, 0, sizeof(struct bau_pq_entry) * DEST_Q_SIZE);
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001540}
1541
1542/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001543 * Initialization of each UV hub's structures
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001544 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001545static void __init init_uvhub(int uvhub, int vector, int base_pnode)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001546{
Cliff Wickman9674f352009-04-03 08:34:05 -05001547 int node;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001548 int pnode;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001549 unsigned long apicid;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001550
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001551 node = uvhub_to_first_node(uvhub);
1552 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001553
1554 activation_descriptor_init(node, pnode, base_pnode);
1555
1556 pq_init(node, pnode);
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001557 /*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001558 * The below initialization can't be in firmware because the
1559 * messaging IRQ will be determined by the OS.
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001560 */
Dimitri Sivanich8191c9f2010-11-16 16:23:52 -06001561 apicid = uvhub_to_first_apicid(uvhub) | uv_apicid_hibits;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001562 write_mmr_data_config(pnode, ((apicid << 32) | vector));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001563}
1564
1565/*
Cliff Wickman12a66112010-06-02 16:22:01 -05001566 * We will set BAU_MISC_CONTROL with a timeout period.
1567 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001568 * So the destination timeout period has to be calculated from them.
Cliff Wickman12a66112010-06-02 16:22:01 -05001569 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001570static int calculate_destination_timeout(void)
Cliff Wickman12a66112010-06-02 16:22:01 -05001571{
1572 unsigned long mmr_image;
1573 int mult1;
1574 int mult2;
1575 int index;
1576 int base;
1577 int ret;
1578 unsigned long ts_ns;
1579
Jack Steiner2a919592011-05-11 12:50:28 -05001580 if (is_uv1_hub()) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001581 mult1 = SOFTACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
Jack Steiner2a919592011-05-11 12:50:28 -05001582 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1583 index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
1584 mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
1585 mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
1586 base = timeout_base_ns[index];
1587 ts_ns = base * mult1 * mult2;
1588 ret = ts_ns / 1000;
1589 } else {
1590 /* 4 bits 0/1 for 10/80us, 3 bits of multiplier */
1591 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1592 mmr_image = (mmr_image & UV_SA_MASK) >> UV_SA_SHFT;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001593 if (mmr_image & (1L << UV2_ACK_UNITS_SHFT))
Jack Steiner2a919592011-05-11 12:50:28 -05001594 mult1 = 80;
1595 else
1596 mult1 = 10;
1597 base = mmr_image & UV2_ACK_MASK;
1598 ret = mult1 * base;
1599 }
Cliff Wickman12a66112010-06-02 16:22:01 -05001600 return ret;
1601}
1602
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001603static void __init init_per_cpu_tunables(void)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001604{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001605 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001606 struct bau_control *bcp;
1607
1608 for_each_present_cpu(cpu) {
1609 bcp = &per_cpu(bau_control, cpu);
1610 bcp->baudisabled = 0;
1611 bcp->statp = &per_cpu(ptcstats, cpu);
1612 /* time interval to catch a hardware stay-busy bug */
1613 bcp->timeout_interval = usec_2_cycles(2*timeout_us);
1614 bcp->max_concurr = max_concurr;
1615 bcp->max_concurr_const = max_concurr;
1616 bcp->plugged_delay = plugged_delay;
1617 bcp->plugsb4reset = plugsb4reset;
1618 bcp->timeoutsb4reset = timeoutsb4reset;
1619 bcp->ipi_reset_limit = ipi_reset_limit;
1620 bcp->complete_threshold = complete_threshold;
1621 bcp->cong_response_us = congested_respns_us;
1622 bcp->cong_reps = congested_reps;
1623 bcp->cong_period = congested_period;
1624 }
1625}
1626
1627/*
1628 * Scan all cpus to collect blade and socket summaries.
1629 */
1630static int __init get_cpu_topology(int base_pnode,
1631 struct uvhub_desc *uvhub_descs,
1632 unsigned char *uvhub_mask)
1633{
1634 int cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001635 int pnode;
1636 int uvhub;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001637 int socket;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001638 struct bau_control *bcp;
1639 struct uvhub_desc *bdp;
1640 struct socket_desc *sdp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001641
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001642 for_each_present_cpu(cpu) {
1643 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001644
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001645 memset(bcp, 0, sizeof(struct bau_control));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001646
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001647 pnode = uv_cpu_hub_info(cpu)->pnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001648 if ((pnode - base_pnode) >= UV_DISTRIBUTION_SIZE) {
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001649 printk(KERN_EMERG
1650 "cpu %d pnode %d-%d beyond %d; BAU disabled\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001651 cpu, pnode, base_pnode, UV_DISTRIBUTION_SIZE);
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001652 return 1;
1653 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001654
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001655 bcp->osnode = cpu_to_node(cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001656 bcp->partition_base_pnode = base_pnode;
1657
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001658 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001659 *(uvhub_mask + (uvhub/8)) |= (1 << (uvhub%8));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001660 bdp = &uvhub_descs[uvhub];
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001661
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001662 bdp->num_cpus++;
1663 bdp->uvhub = uvhub;
1664 bdp->pnode = pnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001665
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001666 /* kludge: 'assuming' one node per socket, and assuming that
1667 disabling a socket just leaves a gap in node numbers */
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001668 socket = bcp->osnode & 1;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001669 bdp->socket_mask |= (1 << socket);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001670 sdp = &bdp->socket[socket];
1671 sdp->cpu_number[sdp->num_cpus] = cpu;
1672 sdp->num_cpus++;
Cliff Wickmancfa60912011-01-03 12:03:53 -06001673 if (sdp->num_cpus > MAX_CPUS_PER_SOCKET) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001674 printk(KERN_EMERG "%d cpus per socket invalid\n",
1675 sdp->num_cpus);
Cliff Wickmancfa60912011-01-03 12:03:53 -06001676 return 1;
1677 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001678 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001679 return 0;
1680}
1681
1682/*
1683 * Each socket is to get a local array of pnodes/hubs.
1684 */
1685static void make_per_cpu_thp(struct bau_control *smaster)
1686{
1687 int cpu;
1688 size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
1689
1690 smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
1691 memset(smaster->thp, 0, hpsz);
1692 for_each_present_cpu(cpu) {
1693 smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
1694 smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
1695 }
1696}
1697
1698/*
cpw@sgi.com442d3922011-06-21 07:21:31 -05001699 * Each uvhub is to get a local cpumask.
1700 */
1701static void make_per_hub_cpumask(struct bau_control *hmaster)
1702{
1703 int sz = sizeof(cpumask_t);
1704
1705 hmaster->cpumask = kzalloc_node(sz, GFP_KERNEL, hmaster->osnode);
1706}
1707
1708/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001709 * Initialize all the per_cpu information for the cpu's on a given socket,
1710 * given what has been gathered into the socket_desc struct.
1711 * And reports the chosen hub and socket masters back to the caller.
1712 */
1713static int scan_sock(struct socket_desc *sdp, struct uvhub_desc *bdp,
1714 struct bau_control **smasterp,
1715 struct bau_control **hmasterp)
1716{
1717 int i;
1718 int cpu;
1719 struct bau_control *bcp;
1720
1721 for (i = 0; i < sdp->num_cpus; i++) {
1722 cpu = sdp->cpu_number[i];
1723 bcp = &per_cpu(bau_control, cpu);
1724 bcp->cpu = cpu;
1725 if (i == 0) {
1726 *smasterp = bcp;
1727 if (!(*hmasterp))
1728 *hmasterp = bcp;
1729 }
1730 bcp->cpus_in_uvhub = bdp->num_cpus;
1731 bcp->cpus_in_socket = sdp->num_cpus;
1732 bcp->socket_master = *smasterp;
1733 bcp->uvhub = bdp->uvhub;
1734 bcp->uvhub_master = *hmasterp;
1735 bcp->uvhub_cpu = uv_cpu_hub_info(cpu)->blade_processor_id;
1736 if (bcp->uvhub_cpu >= MAX_CPUS_PER_UVHUB) {
1737 printk(KERN_EMERG "%d cpus per uvhub invalid\n",
1738 bcp->uvhub_cpu);
1739 return 1;
1740 }
1741 }
1742 return 0;
1743}
1744
1745/*
1746 * Summarize the blade and socket topology into the per_cpu structures.
1747 */
1748static int __init summarize_uvhub_sockets(int nuvhubs,
1749 struct uvhub_desc *uvhub_descs,
1750 unsigned char *uvhub_mask)
1751{
1752 int socket;
1753 int uvhub;
1754 unsigned short socket_mask;
1755
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001756 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001757 struct uvhub_desc *bdp;
1758 struct bau_control *smaster = NULL;
1759 struct bau_control *hmaster = NULL;
1760
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001761 if (!(*(uvhub_mask + (uvhub/8)) & (1 << (uvhub%8))))
1762 continue;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001763
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001764 bdp = &uvhub_descs[uvhub];
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001765 socket_mask = bdp->socket_mask;
1766 socket = 0;
1767 while (socket_mask) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001768 struct socket_desc *sdp;
1769 if ((socket_mask & 1)) {
1770 sdp = &bdp->socket[socket];
1771 if (scan_sock(sdp, bdp, &smaster, &hmaster))
Cliff Wickmancfa60912011-01-03 12:03:53 -06001772 return 1;
cpw@sgi.com9c9153d2011-06-21 07:21:28 -05001773 make_per_cpu_thp(smaster);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001774 }
1775 socket++;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001776 socket_mask = (socket_mask >> 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001777 }
cpw@sgi.com442d3922011-06-21 07:21:31 -05001778 make_per_hub_cpumask(hmaster);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001779 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001780 return 0;
1781}
1782
1783/*
1784 * initialize the bau_control structure for each cpu
1785 */
1786static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
1787{
1788 unsigned char *uvhub_mask;
1789 void *vp;
1790 struct uvhub_desc *uvhub_descs;
1791
1792 timeout_us = calculate_destination_timeout();
1793
1794 vp = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1795 uvhub_descs = (struct uvhub_desc *)vp;
1796 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
1797 uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
1798
1799 if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask))
cpw@sgi.combbd270e2011-06-21 07:21:32 -05001800 goto fail;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001801
1802 if (summarize_uvhub_sockets(nuvhubs, uvhub_descs, uvhub_mask))
cpw@sgi.combbd270e2011-06-21 07:21:32 -05001803 goto fail;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001804
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001805 kfree(uvhub_descs);
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001806 kfree(uvhub_mask);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001807 init_per_cpu_tunables();
Cliff Wickmancfa60912011-01-03 12:03:53 -06001808 return 0;
cpw@sgi.combbd270e2011-06-21 07:21:32 -05001809
1810fail:
1811 kfree(uvhub_descs);
1812 kfree(uvhub_mask);
1813 return 1;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001814}
Cliff Wickman18129242008-06-02 08:56:14 -05001815
1816/*
1817 * Initialization of BAU-related structures
1818 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001819static int __init uv_bau_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001820{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001821 int uvhub;
1822 int pnode;
1823 int nuvhubs;
Rusty Russell2c74d662009-03-18 08:22:30 +10301824 int cur_cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001825 int cpus;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001826 int vector;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001827 cpumask_var_t *mask;
Cliff Wickman18129242008-06-02 08:56:14 -05001828
1829 if (!is_uv_system())
1830 return 0;
1831
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001832 if (nobau)
1833 return 0;
1834
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001835 for_each_possible_cpu(cur_cpu) {
1836 mask = &per_cpu(uv_flush_tlb_mask, cur_cpu);
1837 zalloc_cpumask_var_node(mask, GFP_KERNEL, cpu_to_node(cur_cpu));
1838 }
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301839
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001840 uv_nshift = uv_hub_info->m_val;
Robin Holt036ed8b2009-10-15 17:40:00 -05001841 uv_mmask = (1UL << uv_hub_info->m_val) - 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001842 nuvhubs = uv_num_possible_blades();
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001843 spin_lock_init(&disable_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001844 congested_cycles = usec_2_cycles(congested_respns_us);
Cliff Wickman9674f352009-04-03 08:34:05 -05001845
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001846 uv_base_pnode = 0x7fffffff;
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001847 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001848 cpus = uv_blade_nr_possible_cpus(uvhub);
1849 if (cpus && (uv_blade_to_pnode(uvhub) < uv_base_pnode))
1850 uv_base_pnode = uv_blade_to_pnode(uvhub);
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001851 }
1852
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001853 if (init_per_cpu(nuvhubs, uv_base_pnode)) {
Cliff Wickmancfa60912011-01-03 12:03:53 -06001854 nobau = 1;
1855 return 0;
1856 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001857
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001858 vector = UV_BAU_MESSAGE;
1859 for_each_possible_blade(uvhub)
1860 if (uv_blade_nr_possible_cpus(uvhub))
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001861 init_uvhub(uvhub, vector, uv_base_pnode);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001862
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001863 enable_timeouts();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001864 alloc_intr_gate(vector, uv_bau_message_intr1);
1865
1866 for_each_possible_blade(uvhub) {
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001867 if (uv_blade_nr_possible_cpus(uvhub)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001868 unsigned long val;
1869 unsigned long mmr;
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001870 pnode = uv_blade_to_pnode(uvhub);
1871 /* INIT the bau */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001872 val = 1L << 63;
1873 write_gmmr_activation(pnode, val);
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001874 mmr = 1; /* should be 1 to broadcast to both sockets */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001875 write_mmr_data_broadcast(pnode, mmr);
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001876 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001877 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001878
Cliff Wickman18129242008-06-02 08:56:14 -05001879 return 0;
1880}
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001881core_initcall(uv_bau_init);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001882fs_initcall(uv_ptc_init);