blob: a33a43358e4ecc4a2f810c2dbba22dfd207c1c2d [file] [log] [blame]
Cliff Wickman18129242008-06-02 08:56:14 -05001/*
2 * SGI UltraViolet TLB flush routines.
3 *
Cliff Wickmana26fd712014-05-14 16:15:47 -05004 * (c) 2008-2014 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 Wickmanb194b122008-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
Andrew Banman5e4f96f2016-09-21 11:09:16 -050027static struct bau_operations ops;
28
29static struct bau_operations uv123_bau_ops = {
30 .bau_gpa_to_offset = uv_gpa_to_offset,
31 .read_l_sw_ack = read_mmr_sw_ack,
32 .read_g_sw_ack = read_gmmr_sw_ack,
33 .write_l_sw_ack = write_mmr_sw_ack,
34 .write_g_sw_ack = write_gmmr_sw_ack,
35 .write_payload_first = write_mmr_payload_first,
36 .write_payload_last = write_mmr_payload_last,
37};
38
Cliff Wickman12a66112010-06-02 16:22:01 -050039/* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
40static int timeout_base_ns[] = {
41 20,
42 160,
43 1280,
44 10240,
45 81920,
46 655360,
47 5242880,
48 167772160
49};
Cliff Wickmanf073cc82011-05-24 13:07:36 -050050
Cliff Wickman12a66112010-06-02 16:22:01 -050051static int timeout_us;
Alex Thorlton1c532e02016-03-31 14:18:29 -050052static bool nobau = true;
Cliff Wickman26ef8572012-06-22 08:13:30 -050053static int nobau_perm;
Cliff Wickman50fb55a2010-06-02 16:22:02 -050054static cycles_t congested_cycles;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050055
56/* tunables: */
Cliff Wickmanf073cc82011-05-24 13:07:36 -050057static int max_concurr = MAX_BAU_CONCURRENT;
58static int max_concurr_const = MAX_BAU_CONCURRENT;
59static int plugged_delay = PLUGGED_DELAY;
60static int plugsb4reset = PLUGSB4RESET;
Cliff Wickman8b6e5112012-06-22 08:14:59 -050061static int giveup_limit = GIVEUP_LIMIT;
Cliff Wickmanf073cc82011-05-24 13:07:36 -050062static int timeoutsb4reset = TIMEOUTSB4RESET;
63static int ipi_reset_limit = IPI_RESET_LIMIT;
64static int complete_threshold = COMPLETE_THRESHOLD;
65static int congested_respns_us = CONGESTED_RESPONSE_US;
66static int congested_reps = CONGESTED_REPS;
Cliff Wickman8b6e5112012-06-22 08:14:59 -050067static int disabled_period = DISABLED_PERIOD;
Cliff Wickmanf073cc82011-05-24 13:07:36 -050068
69static struct tunables tunables[] = {
Andrew Banman67492c82016-09-21 11:09:12 -050070 {&max_concurr, MAX_BAU_CONCURRENT}, /* must be [0] */
71 {&plugged_delay, PLUGGED_DELAY},
72 {&plugsb4reset, PLUGSB4RESET},
73 {&timeoutsb4reset, TIMEOUTSB4RESET},
74 {&ipi_reset_limit, IPI_RESET_LIMIT},
75 {&complete_threshold, COMPLETE_THRESHOLD},
76 {&congested_respns_us, CONGESTED_RESPONSE_US},
77 {&congested_reps, CONGESTED_REPS},
78 {&disabled_period, DISABLED_PERIOD},
79 {&giveup_limit, GIVEUP_LIMIT}
Cliff Wickmanf073cc82011-05-24 13:07:36 -050080};
81
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050082static struct dentry *tunables_dir;
83static struct dentry *tunables_file;
84
Cliff Wickmanf073cc82011-05-24 13:07:36 -050085/* these correspond to the statistics printed by ptc_seq_show() */
86static char *stat_description[] = {
87 "sent: number of shootdown messages sent",
88 "stime: time spent sending messages",
89 "numuvhubs: number of hubs targeted with shootdown",
90 "numuvhubs16: number times 16 or more hubs targeted",
91 "numuvhubs8: number times 8 or more hubs targeted",
92 "numuvhubs4: number times 4 or more hubs targeted",
93 "numuvhubs2: number times 2 or more hubs targeted",
94 "numuvhubs1: number times 1 hub targeted",
95 "numcpus: number of cpus targeted with shootdown",
96 "dto: number of destination timeouts",
97 "retries: destination timeout retries sent",
98 "rok: : destination timeouts successfully retried",
99 "resetp: ipi-style resource resets for plugs",
100 "resett: ipi-style resource resets for timeouts",
101 "giveup: fall-backs to ipi-style shootdowns",
102 "sto: number of source timeouts",
103 "bz: number of stay-busy's",
104 "throt: number times spun in throttle",
105 "swack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE",
106 "recv: shootdown messages received",
107 "rtime: time spent processing messages",
108 "all: shootdown all-tlb messages",
109 "one: shootdown one-tlb messages",
110 "mult: interrupts that found multiple messages",
111 "none: interrupts that found no messages",
112 "retry: number of retry messages processed",
113 "canc: number messages canceled by retries",
114 "nocan: number retries that found nothing to cancel",
115 "reset: number of ipi-style reset requests processed",
116 "rcan: number messages canceled by reset requests",
117 "disable: number times use of the BAU was disabled",
118 "enable: number times use of the BAU was re-enabled"
119};
120
Alex Thorlton1c532e02016-03-31 14:18:29 -0500121static int __init setup_bau(char *arg)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500122{
Alex Thorlton1c532e02016-03-31 14:18:29 -0500123 int result;
124
125 if (!arg)
126 return -EINVAL;
127
128 result = strtobool(arg, &nobau);
129 if (result)
130 return result;
131
132 /* we need to flip the logic here, so that bau=y sets nobau to false */
133 nobau = !nobau;
134
135 if (!nobau)
136 pr_info("UV BAU Enabled\n");
137 else
138 pr_info("UV BAU Disabled\n");
139
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500140 return 0;
141}
Alex Thorlton1c532e02016-03-31 14:18:29 -0500142early_param("bau", setup_bau);
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200143
Cliff Wickman94ca8e42009-04-14 10:56:48 -0500144/* base pnode in this partition */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500145static int uv_base_pnode __read_mostly;
Cliff Wickman18129242008-06-02 08:56:14 -0500146
Ingo Molnardc163a42008-06-18 14:15:43 +0200147static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
148static DEFINE_PER_CPU(struct bau_control, bau_control);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500149static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
150
Cliff Wickman26ef8572012-06-22 08:13:30 -0500151static void
152set_bau_on(void)
153{
154 int cpu;
155 struct bau_control *bcp;
156
157 if (nobau_perm) {
158 pr_info("BAU not initialized; cannot be turned on\n");
159 return;
160 }
Alex Thorlton1c532e02016-03-31 14:18:29 -0500161 nobau = false;
Cliff Wickman26ef8572012-06-22 08:13:30 -0500162 for_each_present_cpu(cpu) {
163 bcp = &per_cpu(bau_control, cpu);
Alex Thorlton1c532e02016-03-31 14:18:29 -0500164 bcp->nobau = false;
Cliff Wickman26ef8572012-06-22 08:13:30 -0500165 }
166 pr_info("BAU turned on\n");
167 return;
168}
169
170static void
171set_bau_off(void)
172{
173 int cpu;
174 struct bau_control *bcp;
175
Alex Thorlton1c532e02016-03-31 14:18:29 -0500176 nobau = true;
Cliff Wickman26ef8572012-06-22 08:13:30 -0500177 for_each_present_cpu(cpu) {
178 bcp = &per_cpu(bau_control, cpu);
Alex Thorlton1c532e02016-03-31 14:18:29 -0500179 bcp->nobau = true;
Cliff Wickman26ef8572012-06-22 08:13:30 -0500180 }
181 pr_info("BAU turned off\n");
182 return;
183}
184
Cliff Wickman18129242008-06-02 08:56:14 -0500185/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500186 * Determine the first node on a uvhub. 'Nodes' are used for kernel
187 * memory allocation.
Cliff Wickman9674f352009-04-03 08:34:05 -0500188 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500189static int __init uvhub_to_first_node(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -0500190{
191 int node, b;
192
193 for_each_online_node(node) {
194 b = uv_node_to_blade_id(node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500195 if (uvhub == b)
Cliff Wickman9674f352009-04-03 08:34:05 -0500196 return node;
197 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500198 return -1;
Cliff Wickman9674f352009-04-03 08:34:05 -0500199}
200
201/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500202 * Determine the apicid of the first cpu on a uvhub.
Cliff Wickman9674f352009-04-03 08:34:05 -0500203 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500204static int __init uvhub_to_first_apicid(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -0500205{
206 int cpu;
207
208 for_each_present_cpu(cpu)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500209 if (uvhub == uv_cpu_to_blade_id(cpu))
Cliff Wickman9674f352009-04-03 08:34:05 -0500210 return per_cpu(x86_cpu_to_apicid, cpu);
211 return -1;
212}
213
214/*
Cliff Wickman18129242008-06-02 08:56:14 -0500215 * Free a software acknowledge hardware resource by clearing its Pending
216 * bit. This will return a reply to the sender.
217 * If the message has timed out, a reply has already been sent by the
218 * hardware but the resource has not been released. In that case our
219 * clear of the Timeout bit (as well) will free the resource. No reply will
220 * be sent (the hardware will only do one reply per message).
221 */
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600222static void reply_to_message(struct msg_desc *mdp, struct bau_control *bcp,
223 int do_acknowledge)
Cliff Wickman18129242008-06-02 08:56:14 -0500224{
Cliff Wickmanb194b122008-06-12 08:23:48 -0500225 unsigned long dw;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500226 struct bau_pq_entry *msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500227
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500228 msg = mdp->msg;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600229 if (!msg->canceled && do_acknowledge) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500230 dw = (msg->swack_vec << UV_SW_ACK_NPENDING) | msg->swack_vec;
231 write_mmr_sw_ack(dw);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500232 }
Cliff Wickman18129242008-06-02 08:56:14 -0500233 msg->replied_to = 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500234 msg->swack_vec = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500235}
236
237/*
238 * Process the receipt of a RETRY message
239 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500240static void bau_process_retry_msg(struct msg_desc *mdp,
241 struct bau_control *bcp)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500242{
243 int i;
244 int cancel_count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500245 unsigned long msg_res;
246 unsigned long mmr = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500247 struct bau_pq_entry *msg = mdp->msg;
248 struct bau_pq_entry *msg2;
249 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500250
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500251 stat->d_retries++;
252 /*
253 * cancel any message from msg+1 to the retry itself
254 */
255 for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500256 if (msg2 > mdp->queue_last)
257 msg2 = mdp->queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500258 if (msg2 == msg)
259 break;
260
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500261 /* same conditions for cancellation as do_reset */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500262 if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500263 (msg2->swack_vec) && ((msg2->swack_vec &
264 msg->swack_vec) == 0) &&
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500265 (msg2->sending_cpu == msg->sending_cpu) &&
266 (msg2->msg_type != MSG_NOOP)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500267 mmr = read_mmr_sw_ack();
268 msg_res = msg2->swack_vec;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500269 /*
270 * This is a message retry; clear the resources held
271 * by the previous message only if they timed out.
272 * If it has not timed out we have an unexpected
273 * situation to report.
274 */
Cliff Wickman39847e72010-06-02 16:22:02 -0500275 if (mmr & (msg_res << UV_SW_ACK_NPENDING)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500276 unsigned long mr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500277 /*
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600278 * Is the resource timed out?
279 * Make everyone ignore the cancelled message.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500280 */
281 msg2->canceled = 1;
282 stat->d_canceled++;
283 cancel_count++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500284 mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
285 write_mmr_sw_ack(mr);
Cliff Wickman39847e72010-06-02 16:22:02 -0500286 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500287 }
288 }
289 if (!cancel_count)
290 stat->d_nocanceled++;
Cliff Wickman18129242008-06-02 08:56:14 -0500291}
292
293/*
294 * Do all the things a cpu should do for a TLB shootdown message.
295 * Other cpu's may come here at the same time for this message.
296 */
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600297static void bau_process_message(struct msg_desc *mdp, struct bau_control *bcp,
298 int do_acknowledge)
Cliff Wickman18129242008-06-02 08:56:14 -0500299{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500300 short socket_ack_count = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500301 short *sp;
302 struct atomic_short *asp;
303 struct ptc_stats *stat = bcp->statp;
304 struct bau_pq_entry *msg = mdp->msg;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500305 struct bau_control *smaster = bcp->socket_master;
Cliff Wickman18129242008-06-02 08:56:14 -0500306
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500307 /*
308 * This must be a normal message, or retry of a normal message
309 */
Cliff Wickman18129242008-06-02 08:56:14 -0500310 if (msg->address == TLB_FLUSH_ALL) {
311 local_flush_tlb();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500312 stat->d_alltlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500313 } else {
314 __flush_tlb_one(msg->address);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500315 stat->d_onetlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500316 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500317 stat->d_requestee++;
Cliff Wickman18129242008-06-02 08:56:14 -0500318
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500319 /*
320 * One cpu on each uvhub has the additional job on a RETRY
321 * of releasing the resource held by the message that is
322 * being retried. That message is identified by sending
323 * cpu number.
324 */
325 if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500326 bau_process_retry_msg(mdp, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500327
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500328 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500329 * This is a swack message, so we have to reply to it.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500330 * Count each responding cpu on the socket. This avoids
331 * pinging the count's cache line back and forth between
332 * the sockets.
333 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500334 sp = &smaster->socket_acknowledge_count[mdp->msg_slot];
335 asp = (struct atomic_short *)sp;
336 socket_ack_count = atom_asr(1, asp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500337 if (socket_ack_count == bcp->cpus_in_socket) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500338 int msg_ack_count;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500339 /*
340 * Both sockets dump their completed count total into
341 * the message's count.
342 */
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500343 *sp = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500344 asp = (struct atomic_short *)&msg->acknowledge_count;
345 msg_ack_count = atom_asr(socket_ack_count, asp);
Ingo Molnardc163a42008-06-18 14:15:43 +0200346
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500347 if (msg_ack_count == bcp->cpus_in_uvhub) {
348 /*
349 * All cpus in uvhub saw it; reply
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600350 * (unless we are in the UV2 workaround)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500351 */
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600352 reply_to_message(mdp, bcp, do_acknowledge);
Ingo Molnardc163a42008-06-18 14:15:43 +0200353 }
354 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500355
356 return;
Cliff Wickman18129242008-06-02 08:56:14 -0500357}
358
359/*
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500360 * Determine the first cpu on a pnode.
Cliff Wickman18129242008-06-02 08:56:14 -0500361 */
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500362static int pnode_to_first_cpu(int pnode, struct bau_control *smaster)
Cliff Wickman18129242008-06-02 08:56:14 -0500363{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500364 int cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500365 struct hub_and_pnode *hpp;
366
367 for_each_present_cpu(cpu) {
368 hpp = &smaster->thp[cpu];
369 if (pnode == hpp->pnode)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500370 return cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500371 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500372 return -1;
Cliff Wickman18129242008-06-02 08:56:14 -0500373}
374
Cliff Wickmanb194b122008-06-12 08:23:48 -0500375/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500376 * Last resort when we get a large number of destination timeouts is
377 * to clear resources held by a given cpu.
378 * Do this with IPI so that all messages in the BAU message queue
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500379 * can be identified by their nonzero swack_vec field.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500380 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500381 * This is entered for a single cpu on the uvhub.
382 * The sender want's this uvhub to free a specific message's
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500383 * swack resources.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500384 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500385static void do_reset(void *ptr)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500386{
387 int i;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500388 struct bau_control *bcp = &per_cpu(bau_control, smp_processor_id());
389 struct reset_args *rap = (struct reset_args *)ptr;
390 struct bau_pq_entry *msg;
391 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500392
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500393 stat->d_resets++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500394 /*
395 * We're looking for the given sender, and
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500396 * will free its swack resource.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500397 * If all cpu's finally responded after the timeout, its
398 * message 'replied_to' was set.
399 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500400 for (msg = bcp->queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
401 unsigned long msg_res;
402 /* do_reset: same conditions for cancellation as
403 bau_process_retry_msg() */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500404 if ((msg->replied_to == 0) &&
405 (msg->canceled == 0) &&
406 (msg->sending_cpu == rap->sender) &&
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500407 (msg->swack_vec) &&
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500408 (msg->msg_type != MSG_NOOP)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500409 unsigned long mmr;
410 unsigned long mr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500411 /*
412 * make everyone else ignore this message
413 */
414 msg->canceled = 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500415 /*
416 * only reset the resource if it is still pending
417 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500418 mmr = read_mmr_sw_ack();
419 msg_res = msg->swack_vec;
420 mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500421 if (mmr & msg_res) {
422 stat->d_rcanceled++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500423 write_mmr_sw_ack(mr);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500424 }
425 }
426 }
427 return;
428}
429
430/*
431 * Use IPI to get all target uvhubs to release resources held by
432 * a given sending cpu number.
433 */
cpw@sgi.coma456eaa2011-06-21 07:21:30 -0500434static void reset_with_ipi(struct pnmask *distribution, struct bau_control *bcp)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500435{
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500436 int pnode;
437 int apnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500438 int maskbits;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500439 int sender = bcp->cpu;
cpw@sgi.com442d3922011-06-21 07:21:31 -0500440 cpumask_t *mask = bcp->uvhub_master->cpumask;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500441 struct bau_control *smaster = bcp->socket_master;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500442 struct reset_args reset_args;
443
444 reset_args.sender = sender;
Rusty Russell020b37a2015-03-02 22:05:49 +1030445 cpumask_clear(mask);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500446 /* find a single cpu for each uvhub in this distribution mask */
cpw@sgi.coma456eaa2011-06-21 07:21:30 -0500447 maskbits = sizeof(struct pnmask) * BITSPERBYTE;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500448 /* each bit is a pnode relative to the partition base pnode */
449 for (pnode = 0; pnode < maskbits; pnode++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500450 int cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500451 if (!bau_uvhub_isset(pnode, distribution))
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500452 continue;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500453 apnode = pnode + bcp->partition_base_pnode;
454 cpu = pnode_to_first_cpu(apnode, smaster);
Rusty Russell020b37a2015-03-02 22:05:49 +1030455 cpumask_set_cpu(cpu, mask);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500456 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500457
458 /* IPI all cpus; preemption is already disabled */
cpw@sgi.com442d3922011-06-21 07:21:31 -0500459 smp_call_function_many(mask, do_reset, (void *)&reset_args, 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500460 return;
461}
462
Peter Zijlstra20d1c862013-11-29 15:40:29 +0100463/*
464 * Not to be confused with cycles_2_ns() from tsc.c; this gives a relative
465 * number, not an absolute. It converts a duration in cycles to a duration in
466 * ns.
467 */
468static inline unsigned long long cycles_2_ns(unsigned long long cyc)
469{
470 struct cyc2ns_data *data = cyc2ns_read_begin();
471 unsigned long long ns;
472
473 ns = mul_u64_u32_shr(cyc, data->cyc2ns_mul, data->cyc2ns_shift);
474
475 cyc2ns_read_end(data);
476 return ns;
477}
478
479/*
480 * The reverse of the above; converts a duration in ns to a duration in cycles.
Cliff Wickmana26fd712014-05-14 16:15:47 -0500481 */
Peter Zijlstra20d1c862013-11-29 15:40:29 +0100482static inline unsigned long long ns_2_cycles(unsigned long long ns)
483{
484 struct cyc2ns_data *data = cyc2ns_read_begin();
485 unsigned long long cyc;
486
487 cyc = (ns << data->cyc2ns_shift) / data->cyc2ns_mul;
488
489 cyc2ns_read_end(data);
490 return cyc;
491}
492
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500493static inline unsigned long cycles_2_us(unsigned long long cyc)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500494{
Peter Zijlstra20d1c862013-11-29 15:40:29 +0100495 return cycles_2_ns(cyc) / NSEC_PER_USEC;
496}
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500497
Peter Zijlstra20d1c862013-11-29 15:40:29 +0100498static inline cycles_t sec_2_cycles(unsigned long sec)
499{
500 return ns_2_cycles(sec * NSEC_PER_SEC);
501}
502
503static inline unsigned long long usec_2_cycles(unsigned long usec)
504{
505 return ns_2_cycles(usec * NSEC_PER_USEC);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500506}
507
508/*
509 * wait for all cpus on this hub to finish their sends and go quiet
510 * leaves uvhub_quiesce set so that no new broadcasts are started by
511 * bau_flush_send_and_wait()
512 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500513static inline void quiesce_local_uvhub(struct bau_control *hmaster)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500514{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500515 atom_asr(1, (struct atomic_short *)&hmaster->uvhub_quiesce);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500516}
517
518/*
519 * mark this quiet-requestor as done
520 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500521static inline void end_uvhub_quiesce(struct bau_control *hmaster)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500522{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500523 atom_asr(-1, (struct atomic_short *)&hmaster->uvhub_quiesce);
524}
525
526static unsigned long uv1_read_status(unsigned long mmr_offset, int right_shift)
527{
528 unsigned long descriptor_status;
529
530 descriptor_status = uv_read_local_mmr(mmr_offset);
531 descriptor_status >>= right_shift;
532 descriptor_status &= UV_ACT_STATUS_MASK;
533 return descriptor_status;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500534}
535
536/*
537 * Wait for completion of a broadcast software ack message
538 * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
Cliff Wickmanb194b122008-06-12 08:23:48 -0500539 */
Jack Steiner2a919592011-05-11 12:50:28 -0500540static int uv1_wait_completion(struct bau_desc *bau_desc,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500541 unsigned long mmr_offset, int right_shift,
542 struct bau_control *bcp, long try)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500543{
Cliff Wickmanb194b122008-06-12 08:23:48 -0500544 unsigned long descriptor_status;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500545 cycles_t ttm;
Cliff Wickman712157a2010-06-02 16:22:02 -0500546 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500547
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500548 descriptor_status = uv1_read_status(mmr_offset, right_shift);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500549 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500550 while ((descriptor_status != DS_IDLE)) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500551 /*
Jack Steiner2a919592011-05-11 12:50:28 -0500552 * Our software ack messages may be blocked because
553 * there are no swack resources available. As long
554 * as none of them has timed out hardware will NACK
555 * our message and its state will stay IDLE.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500556 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500557 if (descriptor_status == DS_SOURCE_TIMEOUT) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500558 stat->s_stimeout++;
559 return FLUSH_GIVEUP;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500560 } else if (descriptor_status == DS_DESTINATION_TIMEOUT) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500561 stat->s_dtimeout++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500562 ttm = get_cycles();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500563
564 /*
565 * Our retries may be blocked by all destination
566 * swack resources being consumed, and a timeout
567 * pending. In that case hardware returns the
568 * ERROR that looks like a destination timeout.
569 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500570 if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500571 bcp->conseccompletes = 0;
572 return FLUSH_RETRY_PLUGGED;
573 }
574
575 bcp->conseccompletes = 0;
576 return FLUSH_RETRY_TIMEOUT;
577 } else {
578 /*
579 * descriptor_status is still BUSY
580 */
581 cpu_relax();
Cliff Wickmanb194b122008-06-12 08:23:48 -0500582 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500583 descriptor_status = uv1_read_status(mmr_offset, right_shift);
Cliff Wickmanb194b122008-06-12 08:23:48 -0500584 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500585 bcp->conseccompletes++;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500586 return FLUSH_COMPLETE;
587}
588
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500589/*
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500590 * UV2 could have an extra bit of status in the ACTIVATION_STATUS_2 register.
591 * But not currently used.
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500592 */
Cliff Wickmana26fd712014-05-14 16:15:47 -0500593static unsigned long uv2_3_read_status(unsigned long offset, int rshft, int desc)
Jack Steiner2a919592011-05-11 12:50:28 -0500594{
595 unsigned long descriptor_status;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500596
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500597 descriptor_status =
598 ((read_lmmr(offset) >> rshft) & UV_ACT_STATUS_MASK) << 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500599 return descriptor_status;
600}
601
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600602/*
603 * Return whether the status of the descriptor that is normally used for this
604 * cpu (the one indexed by its hub-relative cpu number) is busy.
605 * The status of the original 32 descriptors is always reflected in the 64
606 * bits of UVH_LB_BAU_SB_ACTIVATION_STATUS_0.
607 * The bit provided by the activation_status_2 register is irrelevant to
608 * the status if it is only being tested for busy or not busy.
609 */
610int normal_busy(struct bau_control *bcp)
611{
612 int cpu = bcp->uvhub_cpu;
613 int mmr_offset;
614 int right_shift;
615
616 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
617 right_shift = cpu * UV_ACT_STATUS_SIZE;
618 return (((((read_lmmr(mmr_offset) >> right_shift) &
619 UV_ACT_STATUS_MASK)) << 1) == UV2H_DESC_BUSY);
620}
621
622/*
623 * Entered when a bau descriptor has gone into a permanent busy wait because
624 * of a hardware bug.
625 * Workaround the bug.
626 */
627int handle_uv2_busy(struct bau_control *bcp)
628{
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600629 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600630
631 stat->s_uv2_wars++;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500632 bcp->busy = 1;
633 return FLUSH_GIVEUP;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600634}
635
Cliff Wickmana26fd712014-05-14 16:15:47 -0500636static int uv2_3_wait_completion(struct bau_desc *bau_desc,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500637 unsigned long mmr_offset, int right_shift,
638 struct bau_control *bcp, long try)
639{
640 unsigned long descriptor_stat;
641 cycles_t ttm;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500642 int desc = bcp->uvhub_cpu;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600643 long busy_reps = 0;
Jack Steiner2a919592011-05-11 12:50:28 -0500644 struct ptc_stats *stat = bcp->statp;
645
Cliff Wickmana26fd712014-05-14 16:15:47 -0500646 descriptor_stat = uv2_3_read_status(mmr_offset, right_shift, desc);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500647
Jack Steiner2a919592011-05-11 12:50:28 -0500648 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500649 while (descriptor_stat != UV2H_DESC_IDLE) {
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500650 if ((descriptor_stat == UV2H_DESC_SOURCE_TIMEOUT)) {
651 /*
652 * A h/w bug on the destination side may
653 * have prevented the message being marked
654 * pending, thus it doesn't get replied to
655 * and gets continually nacked until it times
656 * out with a SOURCE_TIMEOUT.
657 */
Jack Steiner2a919592011-05-11 12:50:28 -0500658 stat->s_stimeout++;
659 return FLUSH_GIVEUP;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500660 } else if (descriptor_stat == UV2H_DESC_DEST_TIMEOUT) {
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500661 ttm = get_cycles();
662
663 /*
664 * Our retries may be blocked by all destination
665 * swack resources being consumed, and a timeout
666 * pending. In that case hardware returns the
667 * ERROR that looks like a destination timeout.
668 * Without using the extended status we have to
669 * deduce from the short time that this was a
670 * strong nack.
671 */
672 if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
673 bcp->conseccompletes = 0;
674 stat->s_plugged++;
675 /* FLUSH_RETRY_PLUGGED causes hang on boot */
676 return FLUSH_GIVEUP;
677 }
Jack Steiner2a919592011-05-11 12:50:28 -0500678 stat->s_dtimeout++;
Jack Steiner2a919592011-05-11 12:50:28 -0500679 bcp->conseccompletes = 0;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500680 /* FLUSH_RETRY_TIMEOUT causes hang on boot */
681 return FLUSH_GIVEUP;
Jack Steiner2a919592011-05-11 12:50:28 -0500682 } else {
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600683 busy_reps++;
684 if (busy_reps > 1000000) {
685 /* not to hammer on the clock */
686 busy_reps = 0;
687 ttm = get_cycles();
Cliff Wickmana26fd712014-05-14 16:15:47 -0500688 if ((ttm - bcp->send_message) > bcp->timeout_interval)
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600689 return handle_uv2_busy(bcp);
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600690 }
Jack Steiner2a919592011-05-11 12:50:28 -0500691 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500692 * descriptor_stat is still BUSY
Jack Steiner2a919592011-05-11 12:50:28 -0500693 */
694 cpu_relax();
695 }
Cliff Wickmana26fd712014-05-14 16:15:47 -0500696 descriptor_stat = uv2_3_read_status(mmr_offset, right_shift, desc);
Jack Steiner2a919592011-05-11 12:50:28 -0500697 }
698 bcp->conseccompletes++;
699 return FLUSH_COMPLETE;
700}
701
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500702/*
703 * There are 2 status registers; each and array[32] of 2 bits. Set up for
704 * which register to read and position in that register based on cpu in
705 * current hub.
706 */
Cliff Wickmana26fd712014-05-14 16:15:47 -0500707static int wait_completion(struct bau_desc *bau_desc, struct bau_control *bcp, long try)
Jack Steiner2a919592011-05-11 12:50:28 -0500708{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500709 int right_shift;
710 unsigned long mmr_offset;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500711 int desc = bcp->uvhub_cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500712
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600713 if (desc < UV_CPUS_PER_AS) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500714 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600715 right_shift = desc * UV_ACT_STATUS_SIZE;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500716 } else {
717 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600718 right_shift = ((desc - UV_CPUS_PER_AS) * UV_ACT_STATUS_SIZE);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500719 }
720
Cliff Wickmanda87c932012-01-16 15:17:50 -0600721 if (bcp->uvhub_version == 1)
Cliff Wickmana26fd712014-05-14 16:15:47 -0500722 return uv1_wait_completion(bau_desc, mmr_offset, right_shift, bcp, try);
Jack Steiner2a919592011-05-11 12:50:28 -0500723 else
Cliff Wickmana26fd712014-05-14 16:15:47 -0500724 return uv2_3_wait_completion(bau_desc, mmr_offset, right_shift, bcp, try);
Jack Steiner2a919592011-05-11 12:50:28 -0500725}
726
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500727/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500728 * Our retries are blocked by all destination sw ack resources being
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500729 * in use, and a timeout is pending. In that case hardware immediately
730 * returns the ERROR that looks like a destination timeout.
731 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500732static void destination_plugged(struct bau_desc *bau_desc,
733 struct bau_control *bcp,
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500734 struct bau_control *hmaster, struct ptc_stats *stat)
735{
736 udelay(bcp->plugged_delay);
737 bcp->plugged_tries++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500738
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500739 if (bcp->plugged_tries >= bcp->plugsb4reset) {
740 bcp->plugged_tries = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500741
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500742 quiesce_local_uvhub(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500743
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500744 spin_lock(&hmaster->queue_lock);
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500745 reset_with_ipi(&bau_desc->distribution, bcp);
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500746 spin_unlock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500747
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500748 end_uvhub_quiesce(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500749
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500750 bcp->ipi_attempts++;
751 stat->s_resets_plug++;
752 }
753}
754
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500755static void destination_timeout(struct bau_desc *bau_desc,
756 struct bau_control *bcp, struct bau_control *hmaster,
757 struct ptc_stats *stat)
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500758{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500759 hmaster->max_concurr = 1;
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500760 bcp->timeout_tries++;
761 if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
762 bcp->timeout_tries = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500763
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500764 quiesce_local_uvhub(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500765
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500766 spin_lock(&hmaster->queue_lock);
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500767 reset_with_ipi(&bau_desc->distribution, bcp);
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500768 spin_unlock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500769
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500770 end_uvhub_quiesce(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500771
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500772 bcp->ipi_attempts++;
773 stat->s_resets_timeout++;
774 }
775}
776
777/*
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500778 * Stop all cpus on a uvhub from using the BAU for a period of time.
779 * This is reversed by check_enable.
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500780 */
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500781static void disable_for_period(struct bau_control *bcp, struct ptc_stats *stat)
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500782{
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500783 int tcpu;
784 struct bau_control *tbcp;
785 struct bau_control *hmaster;
786 cycles_t tm1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500787
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500788 hmaster = bcp->uvhub_master;
789 spin_lock(&hmaster->disable_lock);
790 if (!bcp->baudisabled) {
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500791 stat->s_bau_disabled++;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500792 tm1 = get_cycles();
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500793 for_each_present_cpu(tcpu) {
794 tbcp = &per_cpu(bau_control, tcpu);
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500795 if (tbcp->uvhub_master == hmaster) {
796 tbcp->baudisabled = 1;
797 tbcp->set_bau_on_time =
798 tm1 + bcp->disabled_period;
799 }
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500800 }
801 }
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500802 spin_unlock(&hmaster->disable_lock);
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500803}
804
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500805static void count_max_concurr(int stat, struct bau_control *bcp,
806 struct bau_control *hmaster)
807{
808 bcp->plugged_tries = 0;
809 bcp->timeout_tries = 0;
810 if (stat != FLUSH_COMPLETE)
811 return;
812 if (bcp->conseccompletes <= bcp->complete_threshold)
813 return;
814 if (hmaster->max_concurr >= hmaster->max_concurr_const)
815 return;
816 hmaster->max_concurr++;
817}
818
819static void record_send_stats(cycles_t time1, cycles_t time2,
820 struct bau_control *bcp, struct ptc_stats *stat,
821 int completion_status, int try)
822{
823 cycles_t elapsed;
824
825 if (time2 > time1) {
826 elapsed = time2 - time1;
827 stat->s_time += elapsed;
828
829 if ((completion_status == FLUSH_COMPLETE) && (try == 1)) {
830 bcp->period_requests++;
831 bcp->period_time += elapsed;
832 if ((elapsed > congested_cycles) &&
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500833 (bcp->period_requests > bcp->cong_reps) &&
834 ((bcp->period_time / bcp->period_requests) >
835 congested_cycles)) {
836 stat->s_congested++;
837 disable_for_period(bcp, stat);
838 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500839 }
840 } else
841 stat->s_requestor--;
842
843 if (completion_status == FLUSH_COMPLETE && try > 1)
844 stat->s_retriesok++;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500845 else if (completion_status == FLUSH_GIVEUP) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500846 stat->s_giveup++;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500847 if (get_cycles() > bcp->period_end)
848 bcp->period_giveups = 0;
849 bcp->period_giveups++;
850 if (bcp->period_giveups == 1)
851 bcp->period_end = get_cycles() + bcp->disabled_period;
852 if (bcp->period_giveups > bcp->giveup_limit) {
853 disable_for_period(bcp, stat);
854 stat->s_giveuplimit++;
855 }
856 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500857}
858
859/*
860 * Because of a uv1 hardware bug only a limited number of concurrent
861 * requests can be made.
862 */
863static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
864{
865 spinlock_t *lock = &hmaster->uvhub_lock;
866 atomic_t *v;
867
868 v = &hmaster->active_descriptor_count;
869 if (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr)) {
870 stat->s_throttles++;
871 do {
872 cpu_relax();
873 } while (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr));
874 }
875}
876
877/*
878 * Handle the completion status of a message send.
879 */
880static void handle_cmplt(int completion_status, struct bau_desc *bau_desc,
881 struct bau_control *bcp, struct bau_control *hmaster,
882 struct ptc_stats *stat)
883{
884 if (completion_status == FLUSH_RETRY_PLUGGED)
885 destination_plugged(bau_desc, bcp, hmaster, stat);
886 else if (completion_status == FLUSH_RETRY_TIMEOUT)
887 destination_timeout(bau_desc, bcp, hmaster, stat);
888}
889
890/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500891 * Send a broadcast and wait for it to complete.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500892 *
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500893 * The flush_mask contains the cpus the broadcast is to be sent to including
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500894 * cpus that are on the local uvhub.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500895 *
Cliff Wickman450a0072010-06-02 16:22:02 -0500896 * Returns 0 if all flushing represented in the mask was done.
897 * Returns 1 if it gives up entirely and the original cpu mask is to be
898 * returned to the kernel.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500899 */
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500900int uv_flush_send_and_wait(struct cpumask *flush_mask, struct bau_control *bcp,
901 struct bau_desc *bau_desc)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500902{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500903 int seq_number = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500904 int completion_stat = 0;
Cliff Wickmanda87c932012-01-16 15:17:50 -0600905 int uv1 = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500906 long try = 0;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200907 unsigned long index;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500908 cycles_t time1;
909 cycles_t time2;
Cliff Wickman712157a2010-06-02 16:22:02 -0500910 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500911 struct bau_control *hmaster = bcp->uvhub_master;
Cliff Wickmanda87c932012-01-16 15:17:50 -0600912 struct uv1_bau_msg_header *uv1_hdr = NULL;
Cliff Wickmana26fd712014-05-14 16:15:47 -0500913 struct uv2_3_bau_msg_header *uv2_3_hdr = NULL;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500914
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500915 if (bcp->uvhub_version == 1) {
916 uv1 = 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500917 uv1_throttle(hmaster, stat);
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500918 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500919
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500920 while (hmaster->uvhub_quiesce)
921 cpu_relax();
Cliff Wickmanb194b122008-06-12 08:23:48 -0500922
Cliff Wickmanb194b122008-06-12 08:23:48 -0500923 time1 = get_cycles();
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500924 if (uv1)
925 uv1_hdr = &bau_desc->header.uv1_hdr;
926 else
Cliff Wickmana26fd712014-05-14 16:15:47 -0500927 /* uv2 and uv3 */
928 uv2_3_hdr = &bau_desc->header.uv2_3_hdr;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500929
Cliff Wickmanb194b122008-06-12 08:23:48 -0500930 do {
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500931 if (try == 0) {
Cliff Wickmanda87c932012-01-16 15:17:50 -0600932 if (uv1)
933 uv1_hdr->msg_type = MSG_REGULAR;
934 else
Cliff Wickmana26fd712014-05-14 16:15:47 -0500935 uv2_3_hdr->msg_type = MSG_REGULAR;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500936 seq_number = bcp->message_number++;
937 } else {
Cliff Wickmanda87c932012-01-16 15:17:50 -0600938 if (uv1)
939 uv1_hdr->msg_type = MSG_RETRY;
940 else
Cliff Wickmana26fd712014-05-14 16:15:47 -0500941 uv2_3_hdr->msg_type = MSG_RETRY;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500942 stat->s_retry_messages++;
943 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500944
Cliff Wickmanda87c932012-01-16 15:17:50 -0600945 if (uv1)
946 uv1_hdr->sequence = seq_number;
947 else
Cliff Wickmana26fd712014-05-14 16:15:47 -0500948 uv2_3_hdr->sequence = seq_number;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500949 index = (1UL << AS_PUSH_SHIFT) | bcp->uvhub_cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500950 bcp->send_message = get_cycles();
951
952 write_mmr_activation(index);
953
954 try++;
955 completion_stat = wait_completion(bau_desc, bcp, try);
956
957 handle_cmplt(completion_stat, bau_desc, bcp, hmaster, stat);
958
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500959 if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500960 bcp->ipi_attempts = 0;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500961 stat->s_overipilimit++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500962 completion_stat = FLUSH_GIVEUP;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500963 break;
964 }
965 cpu_relax();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500966 } while ((completion_stat == FLUSH_RETRY_PLUGGED) ||
967 (completion_stat == FLUSH_RETRY_TIMEOUT));
968
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500969 time2 = get_cycles();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500970
971 count_max_concurr(completion_stat, bcp, hmaster);
972
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500973 while (hmaster->uvhub_quiesce)
974 cpu_relax();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500975
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500976 atomic_dec(&hmaster->active_descriptor_count);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500977
978 record_send_stats(time1, time2, bcp, stat, completion_stat, try);
979
980 if (completion_stat == FLUSH_GIVEUP)
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600981 /* FLUSH_GIVEUP will fall back to using IPI's for tlb flush */
Cliff Wickman450a0072010-06-02 16:22:02 -0500982 return 1;
Cliff Wickman450a0072010-06-02 16:22:02 -0500983 return 0;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500984}
985
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500986/*
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500987 * The BAU is disabled for this uvhub. When the disabled time period has
988 * expired re-enable it.
989 * Return 0 if it is re-enabled for all cpus on this uvhub.
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500990 */
991static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
992{
993 int tcpu;
994 struct bau_control *tbcp;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500995 struct bau_control *hmaster;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500996
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500997 hmaster = bcp->uvhub_master;
998 spin_lock(&hmaster->disable_lock);
999 if (bcp->baudisabled && (get_cycles() >= bcp->set_bau_on_time)) {
1000 stat->s_bau_reenabled++;
1001 for_each_present_cpu(tcpu) {
1002 tbcp = &per_cpu(bau_control, tcpu);
1003 if (tbcp->uvhub_master == hmaster) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001004 tbcp->baudisabled = 0;
1005 tbcp->period_requests = 0;
1006 tbcp->period_time = 0;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001007 tbcp->period_giveups = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001008 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001009 }
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001010 spin_unlock(&hmaster->disable_lock);
1011 return 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001012 }
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001013 spin_unlock(&hmaster->disable_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001014 return -1;
1015}
1016
1017static void record_send_statistics(struct ptc_stats *stat, int locals, int hubs,
1018 int remotes, struct bau_desc *bau_desc)
1019{
1020 stat->s_requestor++;
1021 stat->s_ntargcpu += remotes + locals;
1022 stat->s_ntargremotes += remotes;
1023 stat->s_ntarglocals += locals;
1024
1025 /* uvhub statistics */
1026 hubs = bau_uvhub_weight(&bau_desc->distribution);
1027 if (locals) {
1028 stat->s_ntarglocaluvhub++;
1029 stat->s_ntargremoteuvhub += (hubs - 1);
1030 } else
1031 stat->s_ntargremoteuvhub += hubs;
1032
1033 stat->s_ntarguvhub += hubs;
1034
1035 if (hubs >= 16)
1036 stat->s_ntarguvhub16++;
1037 else if (hubs >= 8)
1038 stat->s_ntarguvhub8++;
1039 else if (hubs >= 4)
1040 stat->s_ntarguvhub4++;
1041 else if (hubs >= 2)
1042 stat->s_ntarguvhub2++;
1043 else
1044 stat->s_ntarguvhub1++;
1045}
1046
1047/*
1048 * Translate a cpu mask to the uvhub distribution mask in the BAU
1049 * activation descriptor.
1050 */
1051static int set_distrib_bits(struct cpumask *flush_mask, struct bau_control *bcp,
1052 struct bau_desc *bau_desc, int *localsp, int *remotesp)
1053{
1054 int cpu;
1055 int pnode;
1056 int cnt = 0;
1057 struct hub_and_pnode *hpp;
1058
1059 for_each_cpu(cpu, flush_mask) {
1060 /*
1061 * The distribution vector is a bit map of pnodes, relative
1062 * to the partition base pnode (and the partition base nasid
1063 * in the header).
1064 * Translate cpu to pnode and hub using a local memory array.
1065 */
1066 hpp = &bcp->socket_master->thp[cpu];
1067 pnode = hpp->pnode - bcp->partition_base_pnode;
1068 bau_uvhub_set(pnode, &bau_desc->distribution);
1069 cnt++;
1070 if (hpp->uvhub == bcp->uvhub)
1071 (*localsp)++;
1072 else
1073 (*remotesp)++;
1074 }
1075 if (!cnt)
1076 return 1;
1077 return 0;
1078}
1079
1080/*
1081 * globally purge translation cache of a virtual address or all TLB's
Tejun Heobdbcdd42009-01-21 17:26:06 +09001082 * @cpumask: mask of all cpu's in which the address is to be removed
Cliff Wickman18129242008-06-02 08:56:14 -05001083 * @mm: mm_struct containing virtual address range
Alex Shi57c4f432012-12-18 12:22:14 -08001084 * @start: start virtual address to be removed from TLB
1085 * @end: end virtual address to be remove from TLB
Tejun Heobdbcdd42009-01-21 17:26:06 +09001086 * @cpu: the current cpu
Cliff Wickman18129242008-06-02 08:56:14 -05001087 *
1088 * This is the entry point for initiating any UV global TLB shootdown.
1089 *
1090 * Purges the translation caches of all specified processors of the given
1091 * virtual address, or purges all TLB's on specified processors.
1092 *
Tejun Heobdbcdd42009-01-21 17:26:06 +09001093 * The caller has derived the cpumask from the mm_struct. This function
1094 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
Cliff Wickman18129242008-06-02 08:56:14 -05001095 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001096 * The cpumask is converted into a uvhubmask of the uvhubs containing
1097 * those cpus.
Cliff Wickmanb194b122008-06-12 08:23:48 -05001098 *
Tejun Heobdbcdd42009-01-21 17:26:06 +09001099 * Note that this function should be called with preemption disabled.
1100 *
1101 * Returns NULL if all remote flushing was done.
1102 * Returns pointer to cpumask if some remote flushing remains to be
1103 * done. The returned pointer is valid till preemption is re-enabled.
Cliff Wickman18129242008-06-02 08:56:14 -05001104 */
Tejun Heobdbcdd42009-01-21 17:26:06 +09001105const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
Cliff Wickmana26fd712014-05-14 16:15:47 -05001106 struct mm_struct *mm,
1107 unsigned long start,
1108 unsigned long end,
1109 unsigned int cpu)
Cliff Wickman18129242008-06-02 08:56:14 -05001110{
Cliff Wickmanb194b122008-06-12 08:23:48 -05001111 int locals = 0;
Cliff Wickman450a0072010-06-02 16:22:02 -05001112 int remotes = 0;
1113 int hubs = 0;
Ingo Molnardc163a42008-06-18 14:15:43 +02001114 struct bau_desc *bau_desc;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001115 struct cpumask *flush_mask;
1116 struct ptc_stats *stat;
1117 struct bau_control *bcp;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001118 unsigned long descriptor_status;
1119 unsigned long status;
Cliff Wickman18129242008-06-02 08:56:14 -05001120
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001121 bcp = &per_cpu(bau_control, cpu);
Cliff Wickman26ef8572012-06-22 08:13:30 -05001122
1123 if (bcp->nobau)
1124 return cpumask;
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001125
cpw3eae49c2013-12-03 17:15:30 -06001126 stat = bcp->statp;
1127 stat->s_enters++;
1128
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001129 if (bcp->busy) {
1130 descriptor_status =
1131 read_lmmr(UVH_LB_BAU_SB_ACTIVATION_STATUS_0);
1132 status = ((descriptor_status >> (bcp->uvhub_cpu *
1133 UV_ACT_STATUS_SIZE)) & UV_ACT_STATUS_MASK) << 1;
1134 if (status == UV2H_DESC_BUSY)
1135 return cpumask;
1136 bcp->busy = 0;
1137 }
1138
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001139 /* bau was disabled due to slow response */
1140 if (bcp->baudisabled) {
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001141 if (check_enable(bcp, stat)) {
1142 stat->s_ipifordisabled++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001143 return cpumask;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001144 }
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001145 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001146
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001147 /*
1148 * Each sending cpu has a per-cpu mask which it fills from the caller's
Cliff Wickman450a0072010-06-02 16:22:02 -05001149 * cpu mask. All cpus are converted to uvhubs and copied to the
1150 * activation descriptor.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001151 */
1152 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
Cliff Wickman450a0072010-06-02 16:22:02 -05001153 /* don't actually do a shootdown of the local cpu */
Tejun Heobdbcdd42009-01-21 17:26:06 +09001154 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001155
Rusty Russell020b37a2015-03-02 22:05:49 +10301156 if (cpumask_test_cpu(cpu, cpumask))
Cliff Wickman450a0072010-06-02 16:22:02 -05001157 stat->s_ntargself++;
Tejun Heobdbcdd42009-01-21 17:26:06 +09001158
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001159 bau_desc = bcp->descriptor_base;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001160 bau_desc += (ITEMS_PER_DESC * bcp->uvhub_cpu);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001161 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001162 if (set_distrib_bits(flush_mask, bcp, bau_desc, &locals, &remotes))
Cliff Wickman450a0072010-06-02 16:22:02 -05001163 return NULL;
Cliff Wickman450a0072010-06-02 16:22:02 -05001164
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001165 record_send_statistics(stat, locals, hubs, remotes, bau_desc);
Cliff Wickman18129242008-06-02 08:56:14 -05001166
Alex Shi57c4f432012-12-18 12:22:14 -08001167 if (!end || (end - start) <= PAGE_SIZE)
1168 bau_desc->payload.address = start;
1169 else
1170 bau_desc->payload.address = TLB_FLUSH_ALL;
Tejun Heobdbcdd42009-01-21 17:26:06 +09001171 bau_desc->payload.sending_cpu = cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001172 /*
Cliff Wickman450a0072010-06-02 16:22:02 -05001173 * uv_flush_send_and_wait returns 0 if all cpu's were messaged,
1174 * or 1 if it gave up and the original cpumask should be returned.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001175 */
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001176 if (!uv_flush_send_and_wait(flush_mask, bcp, bau_desc))
Cliff Wickman450a0072010-06-02 16:22:02 -05001177 return NULL;
1178 else
1179 return cpumask;
Cliff Wickman18129242008-06-02 08:56:14 -05001180}
1181
1182/*
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001183 * Search the message queue for any 'other' unprocessed message with the
1184 * same software acknowledge resource bit vector as the 'msg' message.
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001185 */
1186struct bau_pq_entry *find_another_by_swack(struct bau_pq_entry *msg,
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001187 struct bau_control *bcp)
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001188{
1189 struct bau_pq_entry *msg_next = msg + 1;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001190 unsigned char swack_vec = msg->swack_vec;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001191
1192 if (msg_next > bcp->queue_last)
1193 msg_next = bcp->queue_first;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001194 while (msg_next != msg) {
1195 if ((msg_next->canceled == 0) && (msg_next->replied_to == 0) &&
1196 (msg_next->swack_vec == swack_vec))
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001197 return msg_next;
1198 msg_next++;
1199 if (msg_next > bcp->queue_last)
1200 msg_next = bcp->queue_first;
1201 }
1202 return NULL;
1203}
1204
1205/*
1206 * UV2 needs to work around a bug in which an arriving message has not
1207 * set a bit in the UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE register.
1208 * Such a message must be ignored.
1209 */
1210void process_uv2_message(struct msg_desc *mdp, struct bau_control *bcp)
1211{
1212 unsigned long mmr_image;
1213 unsigned char swack_vec;
1214 struct bau_pq_entry *msg = mdp->msg;
1215 struct bau_pq_entry *other_msg;
1216
1217 mmr_image = read_mmr_sw_ack();
1218 swack_vec = msg->swack_vec;
1219
1220 if ((swack_vec & mmr_image) == 0) {
1221 /*
1222 * This message was assigned a swack resource, but no
1223 * reserved acknowlegment is pending.
1224 * The bug has prevented this message from setting the MMR.
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001225 */
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001226 /*
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001227 * Some message has set the MMR 'pending' bit; it might have
1228 * been another message. Look for that message.
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001229 */
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001230 other_msg = find_another_by_swack(msg, bcp);
1231 if (other_msg) {
1232 /*
1233 * There is another. Process this one but do not
1234 * ack it.
1235 */
1236 bau_process_message(mdp, bcp, 0);
1237 /*
1238 * Let the natural processing of that other message
1239 * acknowledge it. Don't get the processing of sw_ack's
1240 * out of order.
1241 */
1242 return;
1243 }
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001244 }
1245
1246 /*
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001247 * Either the MMR shows this one pending a reply or there is no
1248 * other message using this sw_ack, so it is safe to acknowledge it.
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001249 */
1250 bau_process_message(mdp, bcp, 1);
1251
1252 return;
1253}
1254
1255/*
Cliff Wickman18129242008-06-02 08:56:14 -05001256 * The BAU message interrupt comes here. (registered by set_intr_gate)
1257 * See entry_64.S
1258 *
1259 * We received a broadcast assist message.
1260 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001261 * Interrupts are disabled; this interrupt could represent
Cliff Wickman18129242008-06-02 08:56:14 -05001262 * the receipt of several messages.
1263 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001264 * All cores/threads on this hub get this interrupt.
1265 * The last one to see it does the software ack.
Cliff Wickman18129242008-06-02 08:56:14 -05001266 * (the resource will not be freed until noninterruptable cpus see this
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001267 * interrupt; hardware may timeout the s/w ack and reply ERROR)
Cliff Wickman18129242008-06-02 08:56:14 -05001268 */
Cliff Wickmanb194b122008-06-12 08:23:48 -05001269void uv_bau_message_interrupt(struct pt_regs *regs)
Cliff Wickman18129242008-06-02 08:56:14 -05001270{
Cliff Wickman18129242008-06-02 08:56:14 -05001271 int count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001272 cycles_t time_start;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001273 struct bau_pq_entry *msg;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001274 struct bau_control *bcp;
1275 struct ptc_stats *stat;
1276 struct msg_desc msgdesc;
Cliff Wickman18129242008-06-02 08:56:14 -05001277
Cliff Wickman88ed9dd2012-01-16 15:21:46 -06001278 ack_APIC_irq();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001279 time_start = get_cycles();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001280
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001281 bcp = &per_cpu(bau_control, smp_processor_id());
Cliff Wickman712157a2010-06-02 16:22:02 -05001282 stat = bcp->statp;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001283
1284 msgdesc.queue_first = bcp->queue_first;
1285 msgdesc.queue_last = bcp->queue_last;
1286
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001287 msg = bcp->bau_msg_head;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001288 while (msg->swack_vec) {
Cliff Wickman18129242008-06-02 08:56:14 -05001289 count++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001290
1291 msgdesc.msg_slot = msg - msgdesc.queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001292 msgdesc.msg = msg;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001293 if (bcp->uvhub_version == 2)
1294 process_uv2_message(&msgdesc, bcp);
1295 else
Cliff Wickmana26fd712014-05-14 16:15:47 -05001296 /* no error workaround for uv1 or uv3 */
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001297 bau_process_message(&msgdesc, bcp, 1);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001298
Cliff Wickman18129242008-06-02 08:56:14 -05001299 msg++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001300 if (msg > msgdesc.queue_last)
1301 msg = msgdesc.queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001302 bcp->bau_msg_head = msg;
Cliff Wickman18129242008-06-02 08:56:14 -05001303 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001304 stat->d_time += (get_cycles() - time_start);
Cliff Wickman18129242008-06-02 08:56:14 -05001305 if (!count)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001306 stat->d_nomsg++;
Cliff Wickman18129242008-06-02 08:56:14 -05001307 else if (count > 1)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001308 stat->d_multmsg++;
Cliff Wickman18129242008-06-02 08:56:14 -05001309}
1310
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001311/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001312 * Each target uvhub (i.e. a uvhub that has cpu's) needs to have
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001313 * shootdown message timeouts enabled. The timeout does not cause
1314 * an interrupt, but causes an error message to be returned to
1315 * the sender.
1316 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001317static void __init enable_timeouts(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001318{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001319 int uvhub;
1320 int nuvhubs;
Cliff Wickman18129242008-06-02 08:56:14 -05001321 int pnode;
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001322 unsigned long mmr_image;
Cliff Wickman18129242008-06-02 08:56:14 -05001323
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001324 nuvhubs = uv_num_possible_blades();
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001325
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001326 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
1327 if (!uv_blade_nr_possible_cpus(uvhub))
Cliff Wickman18129242008-06-02 08:56:14 -05001328 continue;
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001329
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001330 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001331 mmr_image = read_mmr_misc_control(pnode);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001332 /*
1333 * Set the timeout period and then lock it in, in three
1334 * steps; captures and locks in the period.
1335 *
1336 * To program the period, the SOFT_ACK_MODE must be off.
1337 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001338 mmr_image &= ~(1L << SOFTACK_MSHIFT);
1339 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001340 /*
1341 * Set the 4-bit period.
1342 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001343 mmr_image &= ~((unsigned long)0xf << SOFTACK_PSHIFT);
1344 mmr_image |= (SOFTACK_TIMEOUT_PERIOD << SOFTACK_PSHIFT);
1345 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001346 /*
Jack Steiner2a919592011-05-11 12:50:28 -05001347 * UV1:
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001348 * Subsequent reversals of the timebase bit (3) cause an
1349 * immediate timeout of one or all INTD resources as
1350 * indicated in bits 2:0 (7 causes all of them to timeout).
1351 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001352 mmr_image |= (1L << SOFTACK_MSHIFT);
Jack Steiner2a919592011-05-11 12:50:28 -05001353 if (is_uv2_hub()) {
Cliff Wickmana26fd712014-05-14 16:15:47 -05001354 /* do not touch the legacy mode bit */
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001355 /* hw bug workaround; do not use extended status */
1356 mmr_image &= ~(1L << UV2_EXT_SHFT);
Cliff Wickmana26fd712014-05-14 16:15:47 -05001357 } else if (is_uv3_hub()) {
1358 mmr_image &= ~(1L << PREFETCH_HINT_SHFT);
1359 mmr_image |= (1L << SB_STATUS_SHFT);
Jack Steiner2a919592011-05-11 12:50:28 -05001360 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001361 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickman18129242008-06-02 08:56:14 -05001362 }
Cliff Wickman18129242008-06-02 08:56:14 -05001363}
1364
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001365static void *ptc_seq_start(struct seq_file *file, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -05001366{
1367 if (*offset < num_possible_cpus())
1368 return offset;
1369 return NULL;
1370}
1371
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001372static void *ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -05001373{
1374 (*offset)++;
1375 if (*offset < num_possible_cpus())
1376 return offset;
1377 return NULL;
1378}
1379
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001380static void ptc_seq_stop(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001381{
1382}
1383
1384/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001385 * Display the statistics thru /proc/sgi_uv/ptc_statistics
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001386 * 'data' points to the cpu number
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001387 * Note: see the descriptions in stat_description[].
Cliff Wickman18129242008-06-02 08:56:14 -05001388 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001389static int ptc_seq_show(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001390{
1391 struct ptc_stats *stat;
Cliff Wickman26ef8572012-06-22 08:13:30 -05001392 struct bau_control *bcp;
Cliff Wickman18129242008-06-02 08:56:14 -05001393 int cpu;
1394
1395 cpu = *(loff_t *)data;
Cliff Wickman18129242008-06-02 08:56:14 -05001396 if (!cpu) {
Rasmus Villemoes37367082014-11-28 22:03:41 +01001397 seq_puts(file,
1398 "# cpu bauoff sent stime self locals remotes ncpus localhub ");
1399 seq_puts(file, "remotehub numuvhubs numuvhubs16 numuvhubs8 ");
1400 seq_puts(file,
1401 "numuvhubs4 numuvhubs2 numuvhubs1 dto snacks retries ");
1402 seq_puts(file,
1403 "rok resetp resett giveup sto bz throt disable ");
1404 seq_puts(file,
1405 "enable wars warshw warwaits enters ipidis plugged ");
1406 seq_puts(file,
1407 "ipiover glim cong swack recv rtime all one mult ");
1408 seq_puts(file, "none retry canc nocan reset rcan\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001409 }
1410 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
Cliff Wickman26ef8572012-06-22 08:13:30 -05001411 bcp = &per_cpu(bau_control, cpu);
James Custerfa2a79ce2014-11-02 12:16:39 -06001412 if (bcp->nobau) {
1413 seq_printf(file, "cpu %d bau disabled\n", cpu);
1414 return 0;
1415 }
Cliff Wickman26ef8572012-06-22 08:13:30 -05001416 stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001417 /* source side statistics */
1418 seq_printf(file,
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001419 "cpu %d %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
Cliff Wickman26ef8572012-06-22 08:13:30 -05001420 cpu, bcp->nobau, stat->s_requestor,
1421 cycles_2_us(stat->s_time),
Cliff Wickman450a0072010-06-02 16:22:02 -05001422 stat->s_ntargself, stat->s_ntarglocals,
1423 stat->s_ntargremotes, stat->s_ntargcpu,
1424 stat->s_ntarglocaluvhub, stat->s_ntargremoteuvhub,
1425 stat->s_ntarguvhub, stat->s_ntarguvhub16);
Cliff Wickmanb54bd9b2012-01-16 15:22:38 -06001426 seq_printf(file, "%ld %ld %ld %ld %ld %ld ",
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001427 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
1428 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
Cliff Wickmanb54bd9b2012-01-16 15:22:38 -06001429 stat->s_dtimeout, stat->s_strongnacks);
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001430 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001431 stat->s_retry_messages, stat->s_retriesok,
1432 stat->s_resets_plug, stat->s_resets_timeout,
1433 stat->s_giveup, stat->s_stimeout,
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001434 stat->s_busy, stat->s_throttles);
1435 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
1436 stat->s_bau_disabled, stat->s_bau_reenabled,
1437 stat->s_uv2_wars, stat->s_uv2_wars_hw,
1438 stat->s_uv2_war_waits, stat->s_enters,
1439 stat->s_ipifordisabled, stat->s_plugged,
1440 stat->s_overipilimit, stat->s_giveuplimit,
1441 stat->s_congested);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001442
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001443 /* destination side statistics */
1444 seq_printf(file,
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001445 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001446 read_gmmr_sw_ack(uv_cpu_to_pnode(cpu)),
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001447 stat->d_requestee, cycles_2_us(stat->d_time),
1448 stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
1449 stat->d_nomsg, stat->d_retries, stat->d_canceled,
1450 stat->d_nocanceled, stat->d_resets,
1451 stat->d_rcanceled);
Cliff Wickman18129242008-06-02 08:56:14 -05001452 }
Cliff Wickman18129242008-06-02 08:56:14 -05001453 return 0;
1454}
1455
1456/*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001457 * Display the tunables thru debugfs
1458 */
1459static ssize_t tunables_read(struct file *file, char __user *userbuf,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001460 size_t count, loff_t *ppos)
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001461{
Dan Carpenterb365a852010-09-29 10:41:05 +02001462 char *buf;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001463 int ret;
1464
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001465 buf = kasprintf(GFP_KERNEL, "%s %s %s\n%d %d %d %d %d %d %d %d %d %d\n",
1466 "max_concur plugged_delay plugsb4reset timeoutsb4reset",
1467 "ipi_reset_limit complete_threshold congested_response_us",
1468 "congested_reps disabled_period giveup_limit",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001469 max_concurr, plugged_delay, plugsb4reset,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001470 timeoutsb4reset, ipi_reset_limit, complete_threshold,
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001471 congested_respns_us, congested_reps, disabled_period,
1472 giveup_limit);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001473
Dan Carpenterb365a852010-09-29 10:41:05 +02001474 if (!buf)
1475 return -ENOMEM;
1476
1477 ret = simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
1478 kfree(buf);
1479 return ret;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001480}
1481
1482/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001483 * handle a write to /proc/sgi_uv/ptc_statistics
1484 * -1: reset the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001485 * 0: display meaning of the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001486 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001487static ssize_t ptc_proc_write(struct file *file, const char __user *user,
1488 size_t count, loff_t *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001489{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001490 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001491 int i;
1492 int elements;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001493 long input_arg;
Cliff Wickman18129242008-06-02 08:56:14 -05001494 char optstr[64];
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001495 struct ptc_stats *stat;
Cliff Wickman18129242008-06-02 08:56:14 -05001496
Cliff Wickmane7eb8722008-06-23 08:32:25 -05001497 if (count == 0 || count > sizeof(optstr))
Cliff Wickmancef53272008-06-19 11:16:24 -05001498 return -EINVAL;
Cliff Wickman18129242008-06-02 08:56:14 -05001499 if (copy_from_user(optstr, user, count))
1500 return -EFAULT;
1501 optstr[count - 1] = '\0';
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001502
Cliff Wickman26ef8572012-06-22 08:13:30 -05001503 if (!strcmp(optstr, "on")) {
1504 set_bau_on();
1505 return count;
1506 } else if (!strcmp(optstr, "off")) {
1507 set_bau_off();
1508 return count;
1509 }
1510
Daniel Walter164109e2014-08-08 14:24:03 -07001511 if (kstrtol(optstr, 10, &input_arg) < 0) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001512 pr_debug("%s is invalid\n", optstr);
Cliff Wickman18129242008-06-02 08:56:14 -05001513 return -EINVAL;
1514 }
1515
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001516 if (input_arg == 0) {
Sasha Levin64441742012-12-20 14:11:34 -05001517 elements = ARRAY_SIZE(stat_description);
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001518 pr_debug("# cpu: cpu number\n");
1519 pr_debug("Sender statistics:\n");
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001520 for (i = 0; i < elements; i++)
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001521 pr_debug("%s\n", stat_description[i]);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001522 } else if (input_arg == -1) {
1523 for_each_present_cpu(cpu) {
1524 stat = &per_cpu(ptcstats, cpu);
1525 memset(stat, 0, sizeof(struct ptc_stats));
1526 }
Cliff Wickman18129242008-06-02 08:56:14 -05001527 }
1528
1529 return count;
1530}
1531
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001532static int local_atoi(const char *name)
1533{
1534 int val = 0;
1535
1536 for (;; name++) {
1537 switch (*name) {
1538 case '0' ... '9':
1539 val = 10*val+(*name-'0');
1540 break;
1541 default:
1542 return val;
1543 }
1544 }
1545}
1546
1547/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001548 * Parse the values written to /sys/kernel/debug/sgi_uv/bau_tunables.
1549 * Zero values reset them to defaults.
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001550 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001551static int parse_tunables_write(struct bau_control *bcp, char *instr,
1552 int count)
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001553{
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001554 char *p;
1555 char *q;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001556 int cnt = 0;
1557 int val;
Sasha Levin64441742012-12-20 14:11:34 -05001558 int e = ARRAY_SIZE(tunables);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001559
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001560 p = instr + strspn(instr, WHITESPACE);
1561 q = p;
1562 for (; *p; p = q + strspn(q, WHITESPACE)) {
1563 q = p + strcspn(p, WHITESPACE);
1564 cnt++;
1565 if (q == p)
1566 break;
1567 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001568 if (cnt != e) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001569 pr_info("bau tunable error: should be %d values\n", e);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001570 return -EINVAL;
1571 }
1572
1573 p = instr + strspn(instr, WHITESPACE);
1574 q = p;
1575 for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
1576 q = p + strcspn(p, WHITESPACE);
1577 val = local_atoi(p);
1578 switch (cnt) {
1579 case 0:
1580 if (val == 0) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001581 max_concurr = MAX_BAU_CONCURRENT;
1582 max_concurr_const = MAX_BAU_CONCURRENT;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001583 continue;
1584 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001585 if (val < 1 || val > bcp->cpus_in_uvhub) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001586 pr_debug(
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001587 "Error: BAU max concurrent %d is invalid\n",
1588 val);
1589 return -EINVAL;
1590 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001591 max_concurr = val;
1592 max_concurr_const = val;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001593 continue;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001594 default:
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001595 if (val == 0)
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001596 *tunables[cnt].tunp = tunables[cnt].deflt;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001597 else
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001598 *tunables[cnt].tunp = val;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001599 continue;
1600 }
1601 if (q == p)
1602 break;
1603 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001604 return 0;
1605}
1606
1607/*
1608 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
1609 */
1610static ssize_t tunables_write(struct file *file, const char __user *user,
1611 size_t count, loff_t *data)
1612{
1613 int cpu;
1614 int ret;
1615 char instr[100];
1616 struct bau_control *bcp;
1617
1618 if (count == 0 || count > sizeof(instr)-1)
1619 return -EINVAL;
1620 if (copy_from_user(instr, user, count))
1621 return -EFAULT;
1622
1623 instr[count] = '\0';
1624
cpw@sgi.com00b30cf2011-06-21 07:21:26 -05001625 cpu = get_cpu();
1626 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001627 ret = parse_tunables_write(bcp, instr, count);
cpw@sgi.com00b30cf2011-06-21 07:21:26 -05001628 put_cpu();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001629 if (ret)
1630 return ret;
1631
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001632 for_each_present_cpu(cpu) {
1633 bcp = &per_cpu(bau_control, cpu);
Andrew Banman67492c82016-09-21 11:09:12 -05001634 bcp->max_concurr = max_concurr;
1635 bcp->max_concurr_const = max_concurr;
1636 bcp->plugged_delay = plugged_delay;
1637 bcp->plugsb4reset = plugsb4reset;
1638 bcp->timeoutsb4reset = timeoutsb4reset;
1639 bcp->ipi_reset_limit = ipi_reset_limit;
1640 bcp->complete_threshold = complete_threshold;
1641 bcp->cong_response_us = congested_respns_us;
1642 bcp->cong_reps = congested_reps;
1643 bcp->disabled_period = sec_2_cycles(disabled_period);
1644 bcp->giveup_limit = giveup_limit;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001645 }
1646 return count;
1647}
1648
Cliff Wickman18129242008-06-02 08:56:14 -05001649static const struct seq_operations uv_ptc_seq_ops = {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001650 .start = ptc_seq_start,
1651 .next = ptc_seq_next,
1652 .stop = ptc_seq_stop,
1653 .show = ptc_seq_show
Cliff Wickman18129242008-06-02 08:56:14 -05001654};
1655
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001656static int ptc_proc_open(struct inode *inode, struct file *file)
Cliff Wickman18129242008-06-02 08:56:14 -05001657{
1658 return seq_open(file, &uv_ptc_seq_ops);
1659}
1660
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001661static int tunables_open(struct inode *inode, struct file *file)
1662{
1663 return 0;
1664}
1665
Cliff Wickman18129242008-06-02 08:56:14 -05001666static const struct file_operations proc_uv_ptc_operations = {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001667 .open = ptc_proc_open,
Cliff Wickmanb194b122008-06-12 08:23:48 -05001668 .read = seq_read,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001669 .write = ptc_proc_write,
Cliff Wickmanb194b122008-06-12 08:23:48 -05001670 .llseek = seq_lseek,
1671 .release = seq_release,
Cliff Wickman18129242008-06-02 08:56:14 -05001672};
1673
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001674static const struct file_operations tunables_fops = {
1675 .open = tunables_open,
1676 .read = tunables_read,
1677 .write = tunables_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001678 .llseek = default_llseek,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001679};
1680
Cliff Wickmanb194b122008-06-12 08:23:48 -05001681static int __init uv_ptc_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001682{
Cliff Wickmanb194b122008-06-12 08:23:48 -05001683 struct proc_dir_entry *proc_uv_ptc;
Cliff Wickman18129242008-06-02 08:56:14 -05001684
1685 if (!is_uv_system())
1686 return 0;
1687
Alexey Dobriyan10f02d112009-08-23 23:17:27 +04001688 proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
1689 &proc_uv_ptc_operations);
Cliff Wickman18129242008-06-02 08:56:14 -05001690 if (!proc_uv_ptc) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001691 pr_err("unable to create %s proc entry\n",
Cliff Wickman18129242008-06-02 08:56:14 -05001692 UV_PTC_BASENAME);
1693 return -EINVAL;
1694 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001695
1696 tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
1697 if (!tunables_dir) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001698 pr_err("unable to create debugfs directory %s\n",
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001699 UV_BAU_TUNABLES_DIR);
1700 return -EINVAL;
1701 }
1702 tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001703 tunables_dir, NULL, &tunables_fops);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001704 if (!tunables_file) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001705 pr_err("unable to create debugfs file %s\n",
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001706 UV_BAU_TUNABLES_FILE);
1707 return -EINVAL;
1708 }
Cliff Wickman18129242008-06-02 08:56:14 -05001709 return 0;
1710}
1711
Cliff Wickmanb194b122008-06-12 08:23:48 -05001712/*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001713 * Initialize the sending side's sending buffers.
Cliff Wickmanb194b122008-06-12 08:23:48 -05001714 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001715static void activation_descriptor_init(int node, int pnode, int base_pnode)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001716{
1717 int i;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001718 int cpu;
Cliff Wickmanda87c932012-01-16 15:17:50 -06001719 int uv1 = 0;
Jack Steiner6a469e42011-09-20 13:55:04 -07001720 unsigned long gpa;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001721 unsigned long m;
1722 unsigned long n;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001723 size_t dsize;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001724 struct bau_desc *bau_desc;
1725 struct bau_desc *bd2;
Cliff Wickmanda87c932012-01-16 15:17:50 -06001726 struct uv1_bau_msg_header *uv1_hdr;
Cliff Wickmana26fd712014-05-14 16:15:47 -05001727 struct uv2_3_bau_msg_header *uv2_3_hdr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001728 struct bau_control *bcp;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001729
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001730 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001731 * each bau_desc is 64 bytes; there are 8 (ITEMS_PER_DESC)
1732 * per cpu; and one per cpu on the uvhub (ADP_SZ)
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001733 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001734 dsize = sizeof(struct bau_desc) * ADP_SZ * ITEMS_PER_DESC;
1735 bau_desc = kmalloc_node(dsize, GFP_KERNEL, node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001736 BUG_ON(!bau_desc);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001737
Jack Steiner6a469e42011-09-20 13:55:04 -07001738 gpa = uv_gpa(bau_desc);
1739 n = uv_gpa_to_gnode(gpa);
1740 m = uv_gpa_to_offset(gpa);
Cliff Wickmanda87c932012-01-16 15:17:50 -06001741 if (is_uv1_hub())
1742 uv1 = 1;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001743
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001744 /* the 14-bit pnode */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001745 write_mmr_descriptor_base(pnode, (n << UV_DESC_PSHIFT | m));
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001746 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001747 * Initializing all 8 (ITEMS_PER_DESC) descriptors for each
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001748 * cpu even though we only use the first one; one descriptor can
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001749 * describe a broadcast to 256 uv hubs.
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001750 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001751 for (i = 0, bd2 = bau_desc; i < (ADP_SZ * ITEMS_PER_DESC); i++, bd2++) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001752 memset(bd2, 0, sizeof(struct bau_desc));
Cliff Wickmanda87c932012-01-16 15:17:50 -06001753 if (uv1) {
1754 uv1_hdr = &bd2->header.uv1_hdr;
Andrew Banman67492c82016-09-21 11:09:12 -05001755 uv1_hdr->swack_flag = 1;
Cliff Wickmanda87c932012-01-16 15:17:50 -06001756 /*
1757 * The base_dest_nasid set in the message header
1758 * is the nasid of the first uvhub in the partition.
1759 * The bit map will indicate destination pnode numbers
1760 * relative to that base. They may not be consecutive
1761 * if nasid striding is being used.
1762 */
1763 uv1_hdr->base_dest_nasid =
Andrew Banman67492c82016-09-21 11:09:12 -05001764 UV_PNODE_TO_NASID(base_pnode);
1765 uv1_hdr->dest_subnodeid = UV_LB_SUBNODEID;
1766 uv1_hdr->command = UV_NET_ENDPOINT_INTD;
1767 uv1_hdr->int_both = 1;
Cliff Wickmanda87c932012-01-16 15:17:50 -06001768 /*
1769 * all others need to be set to zero:
1770 * fairness chaining multilevel count replied_to
1771 */
1772 } else {
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001773 /*
Cliff Wickmana26fd712014-05-14 16:15:47 -05001774 * BIOS uses legacy mode, but uv2 and uv3 hardware always
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001775 * uses native mode for selective broadcasts.
1776 */
Cliff Wickmana26fd712014-05-14 16:15:47 -05001777 uv2_3_hdr = &bd2->header.uv2_3_hdr;
Andrew Banman67492c82016-09-21 11:09:12 -05001778 uv2_3_hdr->swack_flag = 1;
Cliff Wickmana26fd712014-05-14 16:15:47 -05001779 uv2_3_hdr->base_dest_nasid =
Andrew Banman67492c82016-09-21 11:09:12 -05001780 UV_PNODE_TO_NASID(base_pnode);
1781 uv2_3_hdr->dest_subnodeid = UV_LB_SUBNODEID;
1782 uv2_3_hdr->command = UV_NET_ENDPOINT_INTD;
Cliff Wickmanda87c932012-01-16 15:17:50 -06001783 }
Cliff Wickmanb194b122008-06-12 08:23:48 -05001784 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001785 for_each_present_cpu(cpu) {
1786 if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
1787 continue;
1788 bcp = &per_cpu(bau_control, cpu);
1789 bcp->descriptor_base = bau_desc;
1790 }
Cliff Wickmanb194b122008-06-12 08:23:48 -05001791}
1792
1793/*
1794 * initialize the destination side's receiving buffers
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001795 * entered for each uvhub in the partition
1796 * - node is first node (kernel memory notion) on the uvhub
1797 * - pnode is the uvhub's physical identifier
Cliff Wickmanb194b122008-06-12 08:23:48 -05001798 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001799static void pq_init(int node, int pnode)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001800{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001801 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001802 size_t plsize;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001803 char *cp;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001804 void *vp;
Andrew Banmand2a57afa2016-09-21 11:09:14 -05001805 unsigned long gnode, first, last, tail;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001806 struct bau_pq_entry *pqp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001807 struct bau_control *bcp;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001808
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001809 plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
1810 vp = kmalloc_node(plsize, GFP_KERNEL, node);
1811 pqp = (struct bau_pq_entry *)vp;
Ingo Molnardc163a42008-06-18 14:15:43 +02001812 BUG_ON(!pqp);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001813
Cliff Wickmanb194b122008-06-12 08:23:48 -05001814 cp = (char *)pqp + 31;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001815 pqp = (struct bau_pq_entry *)(((unsigned long)cp >> 5) << 5);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001816
1817 for_each_present_cpu(cpu) {
1818 if (pnode != uv_cpu_to_pnode(cpu))
1819 continue;
1820 /* for every cpu on this pnode: */
1821 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001822 bcp->queue_first = pqp;
1823 bcp->bau_msg_head = pqp;
1824 bcp->queue_last = pqp + (DEST_Q_SIZE - 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001825 }
Andrew Banmand2a57afa2016-09-21 11:09:14 -05001826
Andrew Banman60e1c842016-09-21 11:09:15 -05001827 first = uv_gpa_to_offset(uv_gpa(pqp));
1828 last = uv_gpa_to_offset(uv_gpa(pqp + (DEST_Q_SIZE - 1)));
Andrew Banmand2a57afa2016-09-21 11:09:14 -05001829 tail = first;
1830 gnode = uv_gpa_to_gnode(uv_gpa(pqp));
1831 first = (gnode << UV_PAYLOADQ_GNODE_SHIFT) | tail;
1832
1833 write_mmr_payload_first(pnode, first);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001834 write_mmr_payload_last(pnode, last);
Andrew Banmand2a57afa2016-09-21 11:09:14 -05001835 write_mmr_payload_tail(pnode, tail);
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001836 write_gmmr_sw_ack(pnode, 0xffffUL);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001837
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001838 /* in effect, all msg_type's are set to MSG_NOOP */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001839 memset(pqp, 0, sizeof(struct bau_pq_entry) * DEST_Q_SIZE);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001840}
1841
1842/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001843 * Initialization of each UV hub's structures
Cliff Wickmanb194b122008-06-12 08:23:48 -05001844 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001845static void __init init_uvhub(int uvhub, int vector, int base_pnode)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001846{
Cliff Wickman9674f352009-04-03 08:34:05 -05001847 int node;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001848 int pnode;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001849 unsigned long apicid;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001850
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001851 node = uvhub_to_first_node(uvhub);
1852 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001853
1854 activation_descriptor_init(node, pnode, base_pnode);
1855
1856 pq_init(node, pnode);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001857 /*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001858 * The below initialization can't be in firmware because the
1859 * messaging IRQ will be determined by the OS.
Cliff Wickmanb194b122008-06-12 08:23:48 -05001860 */
Dimitri Sivanich8191c9f2010-11-16 16:23:52 -06001861 apicid = uvhub_to_first_apicid(uvhub) | uv_apicid_hibits;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001862 write_mmr_data_config(pnode, ((apicid << 32) | vector));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001863}
1864
1865/*
Cliff Wickman12a66112010-06-02 16:22:01 -05001866 * We will set BAU_MISC_CONTROL with a timeout period.
1867 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001868 * So the destination timeout period has to be calculated from them.
Cliff Wickman12a66112010-06-02 16:22:01 -05001869 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001870static int calculate_destination_timeout(void)
Cliff Wickman12a66112010-06-02 16:22:01 -05001871{
1872 unsigned long mmr_image;
1873 int mult1;
1874 int mult2;
1875 int index;
1876 int base;
1877 int ret;
1878 unsigned long ts_ns;
1879
Jack Steiner2a919592011-05-11 12:50:28 -05001880 if (is_uv1_hub()) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001881 mult1 = SOFTACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
Jack Steiner2a919592011-05-11 12:50:28 -05001882 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1883 index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
1884 mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
1885 mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
Cliff Wickman11cab712012-06-22 08:12:12 -05001886 ts_ns = timeout_base_ns[index];
1887 ts_ns *= (mult1 * mult2);
Jack Steiner2a919592011-05-11 12:50:28 -05001888 ret = ts_ns / 1000;
1889 } else {
Cliff Wickmana26fd712014-05-14 16:15:47 -05001890 /* same destination timeout for uv2 and uv3 */
Cliff Wickmand059f9f2012-01-16 15:18:48 -06001891 /* 4 bits 0/1 for 10/80us base, 3 bits of multiplier */
1892 mmr_image = uv_read_local_mmr(UVH_LB_BAU_MISC_CONTROL);
Jack Steiner2a919592011-05-11 12:50:28 -05001893 mmr_image = (mmr_image & UV_SA_MASK) >> UV_SA_SHFT;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001894 if (mmr_image & (1L << UV2_ACK_UNITS_SHFT))
Cliff Wickmand059f9f2012-01-16 15:18:48 -06001895 base = 80;
Jack Steiner2a919592011-05-11 12:50:28 -05001896 else
Cliff Wickmand059f9f2012-01-16 15:18:48 -06001897 base = 10;
1898 mult1 = mmr_image & UV2_ACK_MASK;
Jack Steiner2a919592011-05-11 12:50:28 -05001899 ret = mult1 * base;
1900 }
Cliff Wickman12a66112010-06-02 16:22:01 -05001901 return ret;
1902}
1903
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001904static void __init init_per_cpu_tunables(void)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001905{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001906 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001907 struct bau_control *bcp;
1908
1909 for_each_present_cpu(cpu) {
1910 bcp = &per_cpu(bau_control, cpu);
1911 bcp->baudisabled = 0;
Cliff Wickman26ef8572012-06-22 08:13:30 -05001912 if (nobau)
Alex Thorlton1c532e02016-03-31 14:18:29 -05001913 bcp->nobau = true;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001914 bcp->statp = &per_cpu(ptcstats, cpu);
1915 /* time interval to catch a hardware stay-busy bug */
1916 bcp->timeout_interval = usec_2_cycles(2*timeout_us);
1917 bcp->max_concurr = max_concurr;
1918 bcp->max_concurr_const = max_concurr;
1919 bcp->plugged_delay = plugged_delay;
1920 bcp->plugsb4reset = plugsb4reset;
1921 bcp->timeoutsb4reset = timeoutsb4reset;
1922 bcp->ipi_reset_limit = ipi_reset_limit;
1923 bcp->complete_threshold = complete_threshold;
1924 bcp->cong_response_us = congested_respns_us;
1925 bcp->cong_reps = congested_reps;
Andrew Banman67492c82016-09-21 11:09:12 -05001926 bcp->disabled_period = sec_2_cycles(disabled_period);
1927 bcp->giveup_limit = giveup_limit;
Cliff Wickmand2ebc712012-01-18 09:40:47 -06001928 spin_lock_init(&bcp->queue_lock);
1929 spin_lock_init(&bcp->uvhub_lock);
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001930 spin_lock_init(&bcp->disable_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001931 }
1932}
1933
1934/*
1935 * Scan all cpus to collect blade and socket summaries.
1936 */
1937static int __init get_cpu_topology(int base_pnode,
1938 struct uvhub_desc *uvhub_descs,
1939 unsigned char *uvhub_mask)
1940{
1941 int cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001942 int pnode;
1943 int uvhub;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001944 int socket;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001945 struct bau_control *bcp;
1946 struct uvhub_desc *bdp;
1947 struct socket_desc *sdp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001948
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001949 for_each_present_cpu(cpu) {
1950 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001951
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001952 memset(bcp, 0, sizeof(struct bau_control));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001953
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001954 pnode = uv_cpu_hub_info(cpu)->pnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001955 if ((pnode - base_pnode) >= UV_DISTRIBUTION_SIZE) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001956 pr_emerg(
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001957 "cpu %d pnode %d-%d beyond %d; BAU disabled\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001958 cpu, pnode, base_pnode, UV_DISTRIBUTION_SIZE);
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001959 return 1;
1960 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001961
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001962 bcp->osnode = cpu_to_node(cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001963 bcp->partition_base_pnode = base_pnode;
1964
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001965 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001966 *(uvhub_mask + (uvhub/8)) |= (1 << (uvhub%8));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001967 bdp = &uvhub_descs[uvhub];
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001968
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001969 bdp->num_cpus++;
1970 bdp->uvhub = uvhub;
1971 bdp->pnode = pnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001972
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001973 /* kludge: 'assuming' one node per socket, and assuming that
1974 disabling a socket just leaves a gap in node numbers */
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001975 socket = bcp->osnode & 1;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001976 bdp->socket_mask |= (1 << socket);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001977 sdp = &bdp->socket[socket];
1978 sdp->cpu_number[sdp->num_cpus] = cpu;
1979 sdp->num_cpus++;
Cliff Wickmancfa60912011-01-03 12:03:53 -06001980 if (sdp->num_cpus > MAX_CPUS_PER_SOCKET) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001981 pr_emerg("%d cpus per socket invalid\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001982 sdp->num_cpus);
Cliff Wickmancfa60912011-01-03 12:03:53 -06001983 return 1;
1984 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001985 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001986 return 0;
1987}
1988
1989/*
1990 * Each socket is to get a local array of pnodes/hubs.
1991 */
1992static void make_per_cpu_thp(struct bau_control *smaster)
1993{
1994 int cpu;
1995 size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
1996
1997 smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
1998 memset(smaster->thp, 0, hpsz);
1999 for_each_present_cpu(cpu) {
2000 smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
2001 smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
2002 }
2003}
2004
2005/*
cpw@sgi.com442d3922011-06-21 07:21:31 -05002006 * Each uvhub is to get a local cpumask.
2007 */
2008static void make_per_hub_cpumask(struct bau_control *hmaster)
2009{
2010 int sz = sizeof(cpumask_t);
2011
2012 hmaster->cpumask = kzalloc_node(sz, GFP_KERNEL, hmaster->osnode);
2013}
2014
2015/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002016 * Initialize all the per_cpu information for the cpu's on a given socket,
2017 * given what has been gathered into the socket_desc struct.
2018 * And reports the chosen hub and socket masters back to the caller.
2019 */
2020static int scan_sock(struct socket_desc *sdp, struct uvhub_desc *bdp,
2021 struct bau_control **smasterp,
2022 struct bau_control **hmasterp)
2023{
2024 int i;
2025 int cpu;
2026 struct bau_control *bcp;
2027
2028 for (i = 0; i < sdp->num_cpus; i++) {
2029 cpu = sdp->cpu_number[i];
2030 bcp = &per_cpu(bau_control, cpu);
2031 bcp->cpu = cpu;
2032 if (i == 0) {
2033 *smasterp = bcp;
2034 if (!(*hmasterp))
2035 *hmasterp = bcp;
2036 }
2037 bcp->cpus_in_uvhub = bdp->num_cpus;
2038 bcp->cpus_in_socket = sdp->num_cpus;
2039 bcp->socket_master = *smasterp;
2040 bcp->uvhub = bdp->uvhub;
Cliff Wickmanda87c932012-01-16 15:17:50 -06002041 if (is_uv1_hub())
2042 bcp->uvhub_version = 1;
2043 else if (is_uv2_hub())
2044 bcp->uvhub_version = 2;
Cliff Wickmana26fd712014-05-14 16:15:47 -05002045 else if (is_uv3_hub())
2046 bcp->uvhub_version = 3;
Cliff Wickmanda87c932012-01-16 15:17:50 -06002047 else {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05002048 pr_emerg("uvhub version not 1, 2, or 3\n");
Cliff Wickmanda87c932012-01-16 15:17:50 -06002049 return 1;
2050 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002051 bcp->uvhub_master = *hmasterp;
Mike Travis5627a8252016-04-29 16:54:14 -05002052 bcp->uvhub_cpu = uv_cpu_blade_processor_id(cpu);
2053
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002054 if (bcp->uvhub_cpu >= MAX_CPUS_PER_UVHUB) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05002055 pr_emerg("%d cpus per uvhub invalid\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002056 bcp->uvhub_cpu);
2057 return 1;
2058 }
2059 }
2060 return 0;
2061}
2062
2063/*
2064 * Summarize the blade and socket topology into the per_cpu structures.
2065 */
2066static int __init summarize_uvhub_sockets(int nuvhubs,
2067 struct uvhub_desc *uvhub_descs,
2068 unsigned char *uvhub_mask)
2069{
2070 int socket;
2071 int uvhub;
2072 unsigned short socket_mask;
2073
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05002074 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002075 struct uvhub_desc *bdp;
2076 struct bau_control *smaster = NULL;
2077 struct bau_control *hmaster = NULL;
2078
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05002079 if (!(*(uvhub_mask + (uvhub/8)) & (1 << (uvhub%8))))
2080 continue;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002081
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002082 bdp = &uvhub_descs[uvhub];
Cliff Wickmana8328ee2010-06-02 16:22:02 -05002083 socket_mask = bdp->socket_mask;
2084 socket = 0;
2085 while (socket_mask) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002086 struct socket_desc *sdp;
2087 if ((socket_mask & 1)) {
2088 sdp = &bdp->socket[socket];
2089 if (scan_sock(sdp, bdp, &smaster, &hmaster))
Cliff Wickmancfa60912011-01-03 12:03:53 -06002090 return 1;
cpw@sgi.com9c9153d2011-06-21 07:21:28 -05002091 make_per_cpu_thp(smaster);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002092 }
2093 socket++;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05002094 socket_mask = (socket_mask >> 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002095 }
cpw@sgi.com442d3922011-06-21 07:21:31 -05002096 make_per_hub_cpumask(hmaster);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002097 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002098 return 0;
2099}
2100
2101/*
2102 * initialize the bau_control structure for each cpu
2103 */
2104static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
2105{
2106 unsigned char *uvhub_mask;
2107 void *vp;
2108 struct uvhub_desc *uvhub_descs;
2109
2110 timeout_us = calculate_destination_timeout();
2111
2112 vp = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
2113 uvhub_descs = (struct uvhub_desc *)vp;
2114 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
2115 uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
2116
2117 if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask))
cpw@sgi.combbd270e2011-06-21 07:21:32 -05002118 goto fail;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002119
2120 if (summarize_uvhub_sockets(nuvhubs, uvhub_descs, uvhub_mask))
cpw@sgi.combbd270e2011-06-21 07:21:32 -05002121 goto fail;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002122
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002123 kfree(uvhub_descs);
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05002124 kfree(uvhub_mask);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002125 init_per_cpu_tunables();
Cliff Wickmancfa60912011-01-03 12:03:53 -06002126 return 0;
cpw@sgi.combbd270e2011-06-21 07:21:32 -05002127
2128fail:
2129 kfree(uvhub_descs);
2130 kfree(uvhub_mask);
2131 return 1;
Cliff Wickmanb194b122008-06-12 08:23:48 -05002132}
Cliff Wickman18129242008-06-02 08:56:14 -05002133
2134/*
2135 * Initialization of BAU-related structures
2136 */
Cliff Wickmanb194b122008-06-12 08:23:48 -05002137static int __init uv_bau_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05002138{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002139 int uvhub;
2140 int pnode;
2141 int nuvhubs;
Rusty Russell2c74d662009-03-18 08:22:30 +10302142 int cur_cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002143 int cpus;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002144 int vector;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002145 cpumask_var_t *mask;
Cliff Wickman18129242008-06-02 08:56:14 -05002146
2147 if (!is_uv_system())
2148 return 0;
2149
Andrew Banman5e4f96f2016-09-21 11:09:16 -05002150 if (is_uv3_hub())
2151 ops = uv123_bau_ops;
2152 else if (is_uv2_hub())
2153 ops = uv123_bau_ops;
2154 else if (is_uv1_hub())
2155 ops = uv123_bau_ops;
2156
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002157 for_each_possible_cpu(cur_cpu) {
2158 mask = &per_cpu(uv_flush_tlb_mask, cur_cpu);
2159 zalloc_cpumask_var_node(mask, GFP_KERNEL, cpu_to_node(cur_cpu));
2160 }
Rusty Russell76ba0ec2009-03-13 14:49:57 +10302161
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002162 nuvhubs = uv_num_possible_blades();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002163 congested_cycles = usec_2_cycles(congested_respns_us);
Cliff Wickman9674f352009-04-03 08:34:05 -05002164
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002165 uv_base_pnode = 0x7fffffff;
Cliff Wickman77ed23f2011-05-10 08:26:43 -05002166 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002167 cpus = uv_blade_nr_possible_cpus(uvhub);
2168 if (cpus && (uv_blade_to_pnode(uvhub) < uv_base_pnode))
2169 uv_base_pnode = uv_blade_to_pnode(uvhub);
Cliff Wickman77ed23f2011-05-10 08:26:43 -05002170 }
2171
Cliff Wickmand059f9f2012-01-16 15:18:48 -06002172 enable_timeouts();
2173
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002174 if (init_per_cpu(nuvhubs, uv_base_pnode)) {
Cliff Wickman26ef8572012-06-22 08:13:30 -05002175 set_bau_off();
2176 nobau_perm = 1;
Cliff Wickmancfa60912011-01-03 12:03:53 -06002177 return 0;
2178 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02002179
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002180 vector = UV_BAU_MESSAGE;
Cliff Wickmana26fd712014-05-14 16:15:47 -05002181 for_each_possible_blade(uvhub) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002182 if (uv_blade_nr_possible_cpus(uvhub))
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002183 init_uvhub(uvhub, vector, uv_base_pnode);
Cliff Wickmana26fd712014-05-14 16:15:47 -05002184 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002185
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002186 alloc_intr_gate(vector, uv_bau_message_intr1);
2187
2188 for_each_possible_blade(uvhub) {
Cliff Wickman93a7ca02010-07-16 10:11:21 -05002189 if (uv_blade_nr_possible_cpus(uvhub)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002190 unsigned long val;
2191 unsigned long mmr;
Cliff Wickman93a7ca02010-07-16 10:11:21 -05002192 pnode = uv_blade_to_pnode(uvhub);
2193 /* INIT the bau */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002194 val = 1L << 63;
2195 write_gmmr_activation(pnode, val);
Cliff Wickman93a7ca02010-07-16 10:11:21 -05002196 mmr = 1; /* should be 1 to broadcast to both sockets */
Cliff Wickmanda87c932012-01-16 15:17:50 -06002197 if (!is_uv1_hub())
2198 write_mmr_data_broadcast(pnode, mmr);
Cliff Wickman93a7ca02010-07-16 10:11:21 -05002199 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002200 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02002201
Cliff Wickman18129242008-06-02 08:56:14 -05002202 return 0;
2203}
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002204core_initcall(uv_bau_init);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05002205fs_initcall(uv_ptc_init);