blob: 16d4967d59ea21cfa901ecccf2384e3d106392f9 [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
Andrew Banman4f059d52016-09-21 11:09:21 -050039static struct bau_operations uv4_bau_ops = {
40 .bau_gpa_to_offset = uv_gpa_to_soc_phys_ram,
41 .read_l_sw_ack = read_mmr_proc_sw_ack,
42 .read_g_sw_ack = read_gmmr_proc_sw_ack,
43 .write_l_sw_ack = write_mmr_proc_sw_ack,
44 .write_g_sw_ack = write_gmmr_proc_sw_ack,
45 .write_payload_first = write_mmr_proc_payload_first,
46 .write_payload_last = write_mmr_proc_payload_last,
47};
48
49
Cliff Wickman12a66112010-06-02 16:22:01 -050050/* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
51static int timeout_base_ns[] = {
52 20,
53 160,
54 1280,
55 10240,
56 81920,
57 655360,
58 5242880,
59 167772160
60};
Cliff Wickmanf073cc82011-05-24 13:07:36 -050061
Cliff Wickman12a66112010-06-02 16:22:01 -050062static int timeout_us;
Alex Thorlton1c532e02016-03-31 14:18:29 -050063static bool nobau = true;
Cliff Wickman26ef8572012-06-22 08:13:30 -050064static int nobau_perm;
Cliff Wickman50fb55a2010-06-02 16:22:02 -050065static cycles_t congested_cycles;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050066
67/* tunables: */
Cliff Wickmanf073cc82011-05-24 13:07:36 -050068static int max_concurr = MAX_BAU_CONCURRENT;
69static int max_concurr_const = MAX_BAU_CONCURRENT;
70static int plugged_delay = PLUGGED_DELAY;
71static int plugsb4reset = PLUGSB4RESET;
Cliff Wickman8b6e5112012-06-22 08:14:59 -050072static int giveup_limit = GIVEUP_LIMIT;
Cliff Wickmanf073cc82011-05-24 13:07:36 -050073static int timeoutsb4reset = TIMEOUTSB4RESET;
74static int ipi_reset_limit = IPI_RESET_LIMIT;
75static int complete_threshold = COMPLETE_THRESHOLD;
76static int congested_respns_us = CONGESTED_RESPONSE_US;
77static int congested_reps = CONGESTED_REPS;
Cliff Wickman8b6e5112012-06-22 08:14:59 -050078static int disabled_period = DISABLED_PERIOD;
Cliff Wickmanf073cc82011-05-24 13:07:36 -050079
80static struct tunables tunables[] = {
Andrew Banman67492c82016-09-21 11:09:12 -050081 {&max_concurr, MAX_BAU_CONCURRENT}, /* must be [0] */
82 {&plugged_delay, PLUGGED_DELAY},
83 {&plugsb4reset, PLUGSB4RESET},
84 {&timeoutsb4reset, TIMEOUTSB4RESET},
85 {&ipi_reset_limit, IPI_RESET_LIMIT},
86 {&complete_threshold, COMPLETE_THRESHOLD},
87 {&congested_respns_us, CONGESTED_RESPONSE_US},
88 {&congested_reps, CONGESTED_REPS},
89 {&disabled_period, DISABLED_PERIOD},
90 {&giveup_limit, GIVEUP_LIMIT}
Cliff Wickmanf073cc82011-05-24 13:07:36 -050091};
92
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050093static struct dentry *tunables_dir;
94static struct dentry *tunables_file;
95
Cliff Wickmanf073cc82011-05-24 13:07:36 -050096/* these correspond to the statistics printed by ptc_seq_show() */
97static char *stat_description[] = {
98 "sent: number of shootdown messages sent",
99 "stime: time spent sending messages",
100 "numuvhubs: number of hubs targeted with shootdown",
101 "numuvhubs16: number times 16 or more hubs targeted",
102 "numuvhubs8: number times 8 or more hubs targeted",
103 "numuvhubs4: number times 4 or more hubs targeted",
104 "numuvhubs2: number times 2 or more hubs targeted",
105 "numuvhubs1: number times 1 hub targeted",
106 "numcpus: number of cpus targeted with shootdown",
107 "dto: number of destination timeouts",
108 "retries: destination timeout retries sent",
109 "rok: : destination timeouts successfully retried",
110 "resetp: ipi-style resource resets for plugs",
111 "resett: ipi-style resource resets for timeouts",
112 "giveup: fall-backs to ipi-style shootdowns",
113 "sto: number of source timeouts",
114 "bz: number of stay-busy's",
115 "throt: number times spun in throttle",
116 "swack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE",
117 "recv: shootdown messages received",
118 "rtime: time spent processing messages",
119 "all: shootdown all-tlb messages",
120 "one: shootdown one-tlb messages",
121 "mult: interrupts that found multiple messages",
122 "none: interrupts that found no messages",
123 "retry: number of retry messages processed",
124 "canc: number messages canceled by retries",
125 "nocan: number retries that found nothing to cancel",
126 "reset: number of ipi-style reset requests processed",
127 "rcan: number messages canceled by reset requests",
128 "disable: number times use of the BAU was disabled",
129 "enable: number times use of the BAU was re-enabled"
130};
131
Alex Thorlton1c532e02016-03-31 14:18:29 -0500132static int __init setup_bau(char *arg)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500133{
Alex Thorlton1c532e02016-03-31 14:18:29 -0500134 int result;
135
136 if (!arg)
137 return -EINVAL;
138
139 result = strtobool(arg, &nobau);
140 if (result)
141 return result;
142
143 /* we need to flip the logic here, so that bau=y sets nobau to false */
144 nobau = !nobau;
145
146 if (!nobau)
147 pr_info("UV BAU Enabled\n");
148 else
149 pr_info("UV BAU Disabled\n");
150
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500151 return 0;
152}
Alex Thorlton1c532e02016-03-31 14:18:29 -0500153early_param("bau", setup_bau);
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200154
Cliff Wickman94ca8e42009-04-14 10:56:48 -0500155/* base pnode in this partition */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500156static int uv_base_pnode __read_mostly;
Cliff Wickman18129242008-06-02 08:56:14 -0500157
Ingo Molnardc163a42008-06-18 14:15:43 +0200158static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
159static DEFINE_PER_CPU(struct bau_control, bau_control);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500160static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
161
Cliff Wickman26ef8572012-06-22 08:13:30 -0500162static void
163set_bau_on(void)
164{
165 int cpu;
166 struct bau_control *bcp;
167
168 if (nobau_perm) {
169 pr_info("BAU not initialized; cannot be turned on\n");
170 return;
171 }
Alex Thorlton1c532e02016-03-31 14:18:29 -0500172 nobau = false;
Cliff Wickman26ef8572012-06-22 08:13:30 -0500173 for_each_present_cpu(cpu) {
174 bcp = &per_cpu(bau_control, cpu);
Alex Thorlton1c532e02016-03-31 14:18:29 -0500175 bcp->nobau = false;
Cliff Wickman26ef8572012-06-22 08:13:30 -0500176 }
177 pr_info("BAU turned on\n");
178 return;
179}
180
181static void
182set_bau_off(void)
183{
184 int cpu;
185 struct bau_control *bcp;
186
Alex Thorlton1c532e02016-03-31 14:18:29 -0500187 nobau = true;
Cliff Wickman26ef8572012-06-22 08:13:30 -0500188 for_each_present_cpu(cpu) {
189 bcp = &per_cpu(bau_control, cpu);
Alex Thorlton1c532e02016-03-31 14:18:29 -0500190 bcp->nobau = true;
Cliff Wickman26ef8572012-06-22 08:13:30 -0500191 }
192 pr_info("BAU turned off\n");
193 return;
194}
195
Cliff Wickman18129242008-06-02 08:56:14 -0500196/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500197 * Determine the first node on a uvhub. 'Nodes' are used for kernel
198 * memory allocation.
Cliff Wickman9674f352009-04-03 08:34:05 -0500199 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500200static int __init uvhub_to_first_node(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -0500201{
202 int node, b;
203
204 for_each_online_node(node) {
205 b = uv_node_to_blade_id(node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500206 if (uvhub == b)
Cliff Wickman9674f352009-04-03 08:34:05 -0500207 return node;
208 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500209 return -1;
Cliff Wickman9674f352009-04-03 08:34:05 -0500210}
211
212/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500213 * Determine the apicid of the first cpu on a uvhub.
Cliff Wickman9674f352009-04-03 08:34:05 -0500214 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500215static int __init uvhub_to_first_apicid(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -0500216{
217 int cpu;
218
219 for_each_present_cpu(cpu)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500220 if (uvhub == uv_cpu_to_blade_id(cpu))
Cliff Wickman9674f352009-04-03 08:34:05 -0500221 return per_cpu(x86_cpu_to_apicid, cpu);
222 return -1;
223}
224
225/*
Cliff Wickman18129242008-06-02 08:56:14 -0500226 * Free a software acknowledge hardware resource by clearing its Pending
227 * bit. This will return a reply to the sender.
228 * If the message has timed out, a reply has already been sent by the
229 * hardware but the resource has not been released. In that case our
230 * clear of the Timeout bit (as well) will free the resource. No reply will
231 * be sent (the hardware will only do one reply per message).
232 */
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600233static void reply_to_message(struct msg_desc *mdp, struct bau_control *bcp,
234 int do_acknowledge)
Cliff Wickman18129242008-06-02 08:56:14 -0500235{
Cliff Wickmanb194b122008-06-12 08:23:48 -0500236 unsigned long dw;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500237 struct bau_pq_entry *msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500238
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500239 msg = mdp->msg;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600240 if (!msg->canceled && do_acknowledge) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500241 dw = (msg->swack_vec << UV_SW_ACK_NPENDING) | msg->swack_vec;
Andrew Banman21e3f122016-09-21 11:09:17 -0500242 ops.write_l_sw_ack(dw);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500243 }
Cliff Wickman18129242008-06-02 08:56:14 -0500244 msg->replied_to = 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500245 msg->swack_vec = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500246}
247
248/*
249 * Process the receipt of a RETRY message
250 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500251static void bau_process_retry_msg(struct msg_desc *mdp,
252 struct bau_control *bcp)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500253{
254 int i;
255 int cancel_count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500256 unsigned long msg_res;
257 unsigned long mmr = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500258 struct bau_pq_entry *msg = mdp->msg;
259 struct bau_pq_entry *msg2;
260 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500261
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500262 stat->d_retries++;
263 /*
264 * cancel any message from msg+1 to the retry itself
265 */
266 for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500267 if (msg2 > mdp->queue_last)
268 msg2 = mdp->queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500269 if (msg2 == msg)
270 break;
271
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500272 /* same conditions for cancellation as do_reset */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500273 if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500274 (msg2->swack_vec) && ((msg2->swack_vec &
275 msg->swack_vec) == 0) &&
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500276 (msg2->sending_cpu == msg->sending_cpu) &&
277 (msg2->msg_type != MSG_NOOP)) {
Andrew Banman21e3f122016-09-21 11:09:17 -0500278 mmr = ops.read_l_sw_ack();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500279 msg_res = msg2->swack_vec;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500280 /*
281 * This is a message retry; clear the resources held
282 * by the previous message only if they timed out.
283 * If it has not timed out we have an unexpected
284 * situation to report.
285 */
Cliff Wickman39847e72010-06-02 16:22:02 -0500286 if (mmr & (msg_res << UV_SW_ACK_NPENDING)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500287 unsigned long mr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500288 /*
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600289 * Is the resource timed out?
290 * Make everyone ignore the cancelled message.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500291 */
292 msg2->canceled = 1;
293 stat->d_canceled++;
294 cancel_count++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500295 mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
Andrew Banman21e3f122016-09-21 11:09:17 -0500296 ops.write_l_sw_ack(mr);
Cliff Wickman39847e72010-06-02 16:22:02 -0500297 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500298 }
299 }
300 if (!cancel_count)
301 stat->d_nocanceled++;
Cliff Wickman18129242008-06-02 08:56:14 -0500302}
303
304/*
305 * Do all the things a cpu should do for a TLB shootdown message.
306 * Other cpu's may come here at the same time for this message.
307 */
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600308static void bau_process_message(struct msg_desc *mdp, struct bau_control *bcp,
309 int do_acknowledge)
Cliff Wickman18129242008-06-02 08:56:14 -0500310{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500311 short socket_ack_count = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500312 short *sp;
313 struct atomic_short *asp;
314 struct ptc_stats *stat = bcp->statp;
315 struct bau_pq_entry *msg = mdp->msg;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500316 struct bau_control *smaster = bcp->socket_master;
Cliff Wickman18129242008-06-02 08:56:14 -0500317
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500318 /*
319 * This must be a normal message, or retry of a normal message
320 */
Cliff Wickman18129242008-06-02 08:56:14 -0500321 if (msg->address == TLB_FLUSH_ALL) {
322 local_flush_tlb();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500323 stat->d_alltlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500324 } else {
325 __flush_tlb_one(msg->address);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500326 stat->d_onetlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500327 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500328 stat->d_requestee++;
Cliff Wickman18129242008-06-02 08:56:14 -0500329
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500330 /*
331 * One cpu on each uvhub has the additional job on a RETRY
332 * of releasing the resource held by the message that is
333 * being retried. That message is identified by sending
334 * cpu number.
335 */
336 if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500337 bau_process_retry_msg(mdp, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500338
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500339 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500340 * This is a swack message, so we have to reply to it.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500341 * Count each responding cpu on the socket. This avoids
342 * pinging the count's cache line back and forth between
343 * the sockets.
344 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500345 sp = &smaster->socket_acknowledge_count[mdp->msg_slot];
346 asp = (struct atomic_short *)sp;
347 socket_ack_count = atom_asr(1, asp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500348 if (socket_ack_count == bcp->cpus_in_socket) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500349 int msg_ack_count;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500350 /*
351 * Both sockets dump their completed count total into
352 * the message's count.
353 */
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500354 *sp = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500355 asp = (struct atomic_short *)&msg->acknowledge_count;
356 msg_ack_count = atom_asr(socket_ack_count, asp);
Ingo Molnardc163a42008-06-18 14:15:43 +0200357
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500358 if (msg_ack_count == bcp->cpus_in_uvhub) {
359 /*
360 * All cpus in uvhub saw it; reply
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600361 * (unless we are in the UV2 workaround)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500362 */
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600363 reply_to_message(mdp, bcp, do_acknowledge);
Ingo Molnardc163a42008-06-18 14:15:43 +0200364 }
365 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500366
367 return;
Cliff Wickman18129242008-06-02 08:56:14 -0500368}
369
370/*
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500371 * Determine the first cpu on a pnode.
Cliff Wickman18129242008-06-02 08:56:14 -0500372 */
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500373static int pnode_to_first_cpu(int pnode, struct bau_control *smaster)
Cliff Wickman18129242008-06-02 08:56:14 -0500374{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500375 int cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500376 struct hub_and_pnode *hpp;
377
378 for_each_present_cpu(cpu) {
379 hpp = &smaster->thp[cpu];
380 if (pnode == hpp->pnode)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500381 return cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500382 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500383 return -1;
Cliff Wickman18129242008-06-02 08:56:14 -0500384}
385
Cliff Wickmanb194b122008-06-12 08:23:48 -0500386/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500387 * Last resort when we get a large number of destination timeouts is
388 * to clear resources held by a given cpu.
389 * Do this with IPI so that all messages in the BAU message queue
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500390 * can be identified by their nonzero swack_vec field.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500391 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500392 * This is entered for a single cpu on the uvhub.
393 * The sender want's this uvhub to free a specific message's
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500394 * swack resources.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500395 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500396static void do_reset(void *ptr)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500397{
398 int i;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500399 struct bau_control *bcp = &per_cpu(bau_control, smp_processor_id());
400 struct reset_args *rap = (struct reset_args *)ptr;
401 struct bau_pq_entry *msg;
402 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500403
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500404 stat->d_resets++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500405 /*
406 * We're looking for the given sender, and
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500407 * will free its swack resource.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500408 * If all cpu's finally responded after the timeout, its
409 * message 'replied_to' was set.
410 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500411 for (msg = bcp->queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
412 unsigned long msg_res;
413 /* do_reset: same conditions for cancellation as
414 bau_process_retry_msg() */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500415 if ((msg->replied_to == 0) &&
416 (msg->canceled == 0) &&
417 (msg->sending_cpu == rap->sender) &&
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500418 (msg->swack_vec) &&
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500419 (msg->msg_type != MSG_NOOP)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500420 unsigned long mmr;
421 unsigned long mr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500422 /*
423 * make everyone else ignore this message
424 */
425 msg->canceled = 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500426 /*
427 * only reset the resource if it is still pending
428 */
Andrew Banman21e3f122016-09-21 11:09:17 -0500429 mmr = ops.read_l_sw_ack();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500430 msg_res = msg->swack_vec;
431 mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500432 if (mmr & msg_res) {
433 stat->d_rcanceled++;
Andrew Banman21e3f122016-09-21 11:09:17 -0500434 ops.write_l_sw_ack(mr);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500435 }
436 }
437 }
438 return;
439}
440
441/*
442 * Use IPI to get all target uvhubs to release resources held by
443 * a given sending cpu number.
444 */
cpw@sgi.coma456eaa2011-06-21 07:21:30 -0500445static void reset_with_ipi(struct pnmask *distribution, struct bau_control *bcp)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500446{
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500447 int pnode;
448 int apnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500449 int maskbits;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500450 int sender = bcp->cpu;
cpw@sgi.com442d3922011-06-21 07:21:31 -0500451 cpumask_t *mask = bcp->uvhub_master->cpumask;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500452 struct bau_control *smaster = bcp->socket_master;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500453 struct reset_args reset_args;
454
455 reset_args.sender = sender;
Rusty Russell020b37a2015-03-02 22:05:49 +1030456 cpumask_clear(mask);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500457 /* find a single cpu for each uvhub in this distribution mask */
cpw@sgi.coma456eaa2011-06-21 07:21:30 -0500458 maskbits = sizeof(struct pnmask) * BITSPERBYTE;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500459 /* each bit is a pnode relative to the partition base pnode */
460 for (pnode = 0; pnode < maskbits; pnode++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500461 int cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500462 if (!bau_uvhub_isset(pnode, distribution))
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500463 continue;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500464 apnode = pnode + bcp->partition_base_pnode;
465 cpu = pnode_to_first_cpu(apnode, smaster);
Rusty Russell020b37a2015-03-02 22:05:49 +1030466 cpumask_set_cpu(cpu, mask);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500467 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500468
469 /* IPI all cpus; preemption is already disabled */
cpw@sgi.com442d3922011-06-21 07:21:31 -0500470 smp_call_function_many(mask, do_reset, (void *)&reset_args, 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500471 return;
472}
473
Peter Zijlstra20d1c862013-11-29 15:40:29 +0100474/*
475 * Not to be confused with cycles_2_ns() from tsc.c; this gives a relative
476 * number, not an absolute. It converts a duration in cycles to a duration in
477 * ns.
478 */
479static inline unsigned long long cycles_2_ns(unsigned long long cyc)
480{
481 struct cyc2ns_data *data = cyc2ns_read_begin();
482 unsigned long long ns;
483
484 ns = mul_u64_u32_shr(cyc, data->cyc2ns_mul, data->cyc2ns_shift);
485
486 cyc2ns_read_end(data);
487 return ns;
488}
489
490/*
491 * The reverse of the above; converts a duration in ns to a duration in cycles.
Cliff Wickmana26fd712014-05-14 16:15:47 -0500492 */
Peter Zijlstra20d1c862013-11-29 15:40:29 +0100493static inline unsigned long long ns_2_cycles(unsigned long long ns)
494{
495 struct cyc2ns_data *data = cyc2ns_read_begin();
496 unsigned long long cyc;
497
498 cyc = (ns << data->cyc2ns_shift) / data->cyc2ns_mul;
499
500 cyc2ns_read_end(data);
501 return cyc;
502}
503
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500504static inline unsigned long cycles_2_us(unsigned long long cyc)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500505{
Peter Zijlstra20d1c862013-11-29 15:40:29 +0100506 return cycles_2_ns(cyc) / NSEC_PER_USEC;
507}
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500508
Peter Zijlstra20d1c862013-11-29 15:40:29 +0100509static inline cycles_t sec_2_cycles(unsigned long sec)
510{
511 return ns_2_cycles(sec * NSEC_PER_SEC);
512}
513
514static inline unsigned long long usec_2_cycles(unsigned long usec)
515{
516 return ns_2_cycles(usec * NSEC_PER_USEC);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500517}
518
519/*
520 * wait for all cpus on this hub to finish their sends and go quiet
521 * leaves uvhub_quiesce set so that no new broadcasts are started by
522 * bau_flush_send_and_wait()
523 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500524static inline void quiesce_local_uvhub(struct bau_control *hmaster)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500525{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500526 atom_asr(1, (struct atomic_short *)&hmaster->uvhub_quiesce);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500527}
528
529/*
530 * mark this quiet-requestor as done
531 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500532static inline void end_uvhub_quiesce(struct bau_control *hmaster)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500533{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500534 atom_asr(-1, (struct atomic_short *)&hmaster->uvhub_quiesce);
535}
536
537static unsigned long uv1_read_status(unsigned long mmr_offset, int right_shift)
538{
539 unsigned long descriptor_status;
540
541 descriptor_status = uv_read_local_mmr(mmr_offset);
542 descriptor_status >>= right_shift;
543 descriptor_status &= UV_ACT_STATUS_MASK;
544 return descriptor_status;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500545}
546
547/*
548 * Wait for completion of a broadcast software ack message
549 * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
Cliff Wickmanb194b122008-06-12 08:23:48 -0500550 */
Jack Steiner2a919592011-05-11 12:50:28 -0500551static int uv1_wait_completion(struct bau_desc *bau_desc,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500552 unsigned long mmr_offset, int right_shift,
553 struct bau_control *bcp, long try)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500554{
Cliff Wickmanb194b122008-06-12 08:23:48 -0500555 unsigned long descriptor_status;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500556 cycles_t ttm;
Cliff Wickman712157a2010-06-02 16:22:02 -0500557 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500558
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500559 descriptor_status = uv1_read_status(mmr_offset, right_shift);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500560 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500561 while ((descriptor_status != DS_IDLE)) {
Cliff Wickmanb194b122008-06-12 08:23:48 -0500562 /*
Jack Steiner2a919592011-05-11 12:50:28 -0500563 * Our software ack messages may be blocked because
564 * there are no swack resources available. As long
565 * as none of them has timed out hardware will NACK
566 * our message and its state will stay IDLE.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500567 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500568 if (descriptor_status == DS_SOURCE_TIMEOUT) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500569 stat->s_stimeout++;
570 return FLUSH_GIVEUP;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500571 } else if (descriptor_status == DS_DESTINATION_TIMEOUT) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500572 stat->s_dtimeout++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500573 ttm = get_cycles();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500574
575 /*
576 * Our retries may be blocked by all destination
577 * swack resources being consumed, and a timeout
578 * pending. In that case hardware returns the
579 * ERROR that looks like a destination timeout.
580 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500581 if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500582 bcp->conseccompletes = 0;
583 return FLUSH_RETRY_PLUGGED;
584 }
585
586 bcp->conseccompletes = 0;
587 return FLUSH_RETRY_TIMEOUT;
588 } else {
589 /*
590 * descriptor_status is still BUSY
591 */
592 cpu_relax();
Cliff Wickmanb194b122008-06-12 08:23:48 -0500593 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500594 descriptor_status = uv1_read_status(mmr_offset, right_shift);
Cliff Wickmanb194b122008-06-12 08:23:48 -0500595 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500596 bcp->conseccompletes++;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500597 return FLUSH_COMPLETE;
598}
599
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500600/*
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500601 * UV2 could have an extra bit of status in the ACTIVATION_STATUS_2 register.
602 * But not currently used.
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500603 */
Cliff Wickmana26fd712014-05-14 16:15:47 -0500604static unsigned long uv2_3_read_status(unsigned long offset, int rshft, int desc)
Jack Steiner2a919592011-05-11 12:50:28 -0500605{
Masahiro Yamadaf148b412016-09-11 14:58:21 +0900606 return ((read_lmmr(offset) >> rshft) & UV_ACT_STATUS_MASK) << 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500607}
608
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600609/*
610 * Return whether the status of the descriptor that is normally used for this
611 * cpu (the one indexed by its hub-relative cpu number) is busy.
612 * The status of the original 32 descriptors is always reflected in the 64
613 * bits of UVH_LB_BAU_SB_ACTIVATION_STATUS_0.
614 * The bit provided by the activation_status_2 register is irrelevant to
615 * the status if it is only being tested for busy or not busy.
616 */
617int normal_busy(struct bau_control *bcp)
618{
619 int cpu = bcp->uvhub_cpu;
620 int mmr_offset;
621 int right_shift;
622
623 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
624 right_shift = cpu * UV_ACT_STATUS_SIZE;
625 return (((((read_lmmr(mmr_offset) >> right_shift) &
626 UV_ACT_STATUS_MASK)) << 1) == UV2H_DESC_BUSY);
627}
628
629/*
630 * Entered when a bau descriptor has gone into a permanent busy wait because
631 * of a hardware bug.
632 * Workaround the bug.
633 */
634int handle_uv2_busy(struct bau_control *bcp)
635{
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600636 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600637
638 stat->s_uv2_wars++;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500639 bcp->busy = 1;
640 return FLUSH_GIVEUP;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600641}
642
Cliff Wickmana26fd712014-05-14 16:15:47 -0500643static int uv2_3_wait_completion(struct bau_desc *bau_desc,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500644 unsigned long mmr_offset, int right_shift,
645 struct bau_control *bcp, long try)
646{
647 unsigned long descriptor_stat;
648 cycles_t ttm;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500649 int desc = bcp->uvhub_cpu;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600650 long busy_reps = 0;
Jack Steiner2a919592011-05-11 12:50:28 -0500651 struct ptc_stats *stat = bcp->statp;
652
Cliff Wickmana26fd712014-05-14 16:15:47 -0500653 descriptor_stat = uv2_3_read_status(mmr_offset, right_shift, desc);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500654
Jack Steiner2a919592011-05-11 12:50:28 -0500655 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500656 while (descriptor_stat != UV2H_DESC_IDLE) {
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500657 if ((descriptor_stat == UV2H_DESC_SOURCE_TIMEOUT)) {
658 /*
659 * A h/w bug on the destination side may
660 * have prevented the message being marked
661 * pending, thus it doesn't get replied to
662 * and gets continually nacked until it times
663 * out with a SOURCE_TIMEOUT.
664 */
Jack Steiner2a919592011-05-11 12:50:28 -0500665 stat->s_stimeout++;
666 return FLUSH_GIVEUP;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500667 } else if (descriptor_stat == UV2H_DESC_DEST_TIMEOUT) {
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500668 ttm = get_cycles();
669
670 /*
671 * Our retries may be blocked by all destination
672 * swack resources being consumed, and a timeout
673 * pending. In that case hardware returns the
674 * ERROR that looks like a destination timeout.
675 * Without using the extended status we have to
676 * deduce from the short time that this was a
677 * strong nack.
678 */
679 if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
680 bcp->conseccompletes = 0;
681 stat->s_plugged++;
682 /* FLUSH_RETRY_PLUGGED causes hang on boot */
683 return FLUSH_GIVEUP;
684 }
Jack Steiner2a919592011-05-11 12:50:28 -0500685 stat->s_dtimeout++;
Jack Steiner2a919592011-05-11 12:50:28 -0500686 bcp->conseccompletes = 0;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500687 /* FLUSH_RETRY_TIMEOUT causes hang on boot */
688 return FLUSH_GIVEUP;
Jack Steiner2a919592011-05-11 12:50:28 -0500689 } else {
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600690 busy_reps++;
691 if (busy_reps > 1000000) {
692 /* not to hammer on the clock */
693 busy_reps = 0;
694 ttm = get_cycles();
Cliff Wickmana26fd712014-05-14 16:15:47 -0500695 if ((ttm - bcp->send_message) > bcp->timeout_interval)
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600696 return handle_uv2_busy(bcp);
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600697 }
Jack Steiner2a919592011-05-11 12:50:28 -0500698 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500699 * descriptor_stat is still BUSY
Jack Steiner2a919592011-05-11 12:50:28 -0500700 */
701 cpu_relax();
702 }
Cliff Wickmana26fd712014-05-14 16:15:47 -0500703 descriptor_stat = uv2_3_read_status(mmr_offset, right_shift, desc);
Jack Steiner2a919592011-05-11 12:50:28 -0500704 }
705 bcp->conseccompletes++;
706 return FLUSH_COMPLETE;
707}
708
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500709/*
710 * There are 2 status registers; each and array[32] of 2 bits. Set up for
711 * which register to read and position in that register based on cpu in
712 * current hub.
713 */
Cliff Wickmana26fd712014-05-14 16:15:47 -0500714static int wait_completion(struct bau_desc *bau_desc, struct bau_control *bcp, long try)
Jack Steiner2a919592011-05-11 12:50:28 -0500715{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500716 int right_shift;
717 unsigned long mmr_offset;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500718 int desc = bcp->uvhub_cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500719
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600720 if (desc < UV_CPUS_PER_AS) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500721 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600722 right_shift = desc * UV_ACT_STATUS_SIZE;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500723 } else {
724 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600725 right_shift = ((desc - UV_CPUS_PER_AS) * UV_ACT_STATUS_SIZE);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500726 }
727
Cliff Wickmanda87c932012-01-16 15:17:50 -0600728 if (bcp->uvhub_version == 1)
Cliff Wickmana26fd712014-05-14 16:15:47 -0500729 return uv1_wait_completion(bau_desc, mmr_offset, right_shift, bcp, try);
Jack Steiner2a919592011-05-11 12:50:28 -0500730 else
Cliff Wickmana26fd712014-05-14 16:15:47 -0500731 return uv2_3_wait_completion(bau_desc, mmr_offset, right_shift, bcp, try);
Jack Steiner2a919592011-05-11 12:50:28 -0500732}
733
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500734/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500735 * Our retries are blocked by all destination sw ack resources being
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500736 * in use, and a timeout is pending. In that case hardware immediately
737 * returns the ERROR that looks like a destination timeout.
738 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500739static void destination_plugged(struct bau_desc *bau_desc,
740 struct bau_control *bcp,
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500741 struct bau_control *hmaster, struct ptc_stats *stat)
742{
743 udelay(bcp->plugged_delay);
744 bcp->plugged_tries++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500745
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500746 if (bcp->plugged_tries >= bcp->plugsb4reset) {
747 bcp->plugged_tries = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500748
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500749 quiesce_local_uvhub(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500750
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500751 spin_lock(&hmaster->queue_lock);
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500752 reset_with_ipi(&bau_desc->distribution, bcp);
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500753 spin_unlock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500754
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500755 end_uvhub_quiesce(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500756
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500757 bcp->ipi_attempts++;
758 stat->s_resets_plug++;
759 }
760}
761
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500762static void destination_timeout(struct bau_desc *bau_desc,
763 struct bau_control *bcp, struct bau_control *hmaster,
764 struct ptc_stats *stat)
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500765{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500766 hmaster->max_concurr = 1;
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500767 bcp->timeout_tries++;
768 if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
769 bcp->timeout_tries = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500770
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500771 quiesce_local_uvhub(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500772
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500773 spin_lock(&hmaster->queue_lock);
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500774 reset_with_ipi(&bau_desc->distribution, bcp);
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500775 spin_unlock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500776
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500777 end_uvhub_quiesce(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500778
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500779 bcp->ipi_attempts++;
780 stat->s_resets_timeout++;
781 }
782}
783
784/*
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500785 * Stop all cpus on a uvhub from using the BAU for a period of time.
786 * This is reversed by check_enable.
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500787 */
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500788static void disable_for_period(struct bau_control *bcp, struct ptc_stats *stat)
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500789{
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500790 int tcpu;
791 struct bau_control *tbcp;
792 struct bau_control *hmaster;
793 cycles_t tm1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500794
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500795 hmaster = bcp->uvhub_master;
796 spin_lock(&hmaster->disable_lock);
797 if (!bcp->baudisabled) {
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500798 stat->s_bau_disabled++;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500799 tm1 = get_cycles();
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500800 for_each_present_cpu(tcpu) {
801 tbcp = &per_cpu(bau_control, tcpu);
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500802 if (tbcp->uvhub_master == hmaster) {
803 tbcp->baudisabled = 1;
804 tbcp->set_bau_on_time =
805 tm1 + bcp->disabled_period;
806 }
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500807 }
808 }
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500809 spin_unlock(&hmaster->disable_lock);
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500810}
811
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500812static void count_max_concurr(int stat, struct bau_control *bcp,
813 struct bau_control *hmaster)
814{
815 bcp->plugged_tries = 0;
816 bcp->timeout_tries = 0;
817 if (stat != FLUSH_COMPLETE)
818 return;
819 if (bcp->conseccompletes <= bcp->complete_threshold)
820 return;
821 if (hmaster->max_concurr >= hmaster->max_concurr_const)
822 return;
823 hmaster->max_concurr++;
824}
825
826static void record_send_stats(cycles_t time1, cycles_t time2,
827 struct bau_control *bcp, struct ptc_stats *stat,
828 int completion_status, int try)
829{
830 cycles_t elapsed;
831
832 if (time2 > time1) {
833 elapsed = time2 - time1;
834 stat->s_time += elapsed;
835
836 if ((completion_status == FLUSH_COMPLETE) && (try == 1)) {
837 bcp->period_requests++;
838 bcp->period_time += elapsed;
839 if ((elapsed > congested_cycles) &&
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500840 (bcp->period_requests > bcp->cong_reps) &&
841 ((bcp->period_time / bcp->period_requests) >
842 congested_cycles)) {
843 stat->s_congested++;
844 disable_for_period(bcp, stat);
845 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500846 }
847 } else
848 stat->s_requestor--;
849
850 if (completion_status == FLUSH_COMPLETE && try > 1)
851 stat->s_retriesok++;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500852 else if (completion_status == FLUSH_GIVEUP) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500853 stat->s_giveup++;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500854 if (get_cycles() > bcp->period_end)
855 bcp->period_giveups = 0;
856 bcp->period_giveups++;
857 if (bcp->period_giveups == 1)
858 bcp->period_end = get_cycles() + bcp->disabled_period;
859 if (bcp->period_giveups > bcp->giveup_limit) {
860 disable_for_period(bcp, stat);
861 stat->s_giveuplimit++;
862 }
863 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500864}
865
866/*
867 * Because of a uv1 hardware bug only a limited number of concurrent
868 * requests can be made.
869 */
870static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
871{
872 spinlock_t *lock = &hmaster->uvhub_lock;
873 atomic_t *v;
874
875 v = &hmaster->active_descriptor_count;
876 if (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr)) {
877 stat->s_throttles++;
878 do {
879 cpu_relax();
880 } while (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr));
881 }
882}
883
884/*
885 * Handle the completion status of a message send.
886 */
887static void handle_cmplt(int completion_status, struct bau_desc *bau_desc,
888 struct bau_control *bcp, struct bau_control *hmaster,
889 struct ptc_stats *stat)
890{
891 if (completion_status == FLUSH_RETRY_PLUGGED)
892 destination_plugged(bau_desc, bcp, hmaster, stat);
893 else if (completion_status == FLUSH_RETRY_TIMEOUT)
894 destination_timeout(bau_desc, bcp, hmaster, stat);
895}
896
897/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500898 * Send a broadcast and wait for it to complete.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500899 *
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500900 * The flush_mask contains the cpus the broadcast is to be sent to including
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500901 * cpus that are on the local uvhub.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500902 *
Cliff Wickman450a0072010-06-02 16:22:02 -0500903 * Returns 0 if all flushing represented in the mask was done.
904 * Returns 1 if it gives up entirely and the original cpu mask is to be
905 * returned to the kernel.
Cliff Wickmanb194b122008-06-12 08:23:48 -0500906 */
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500907int uv_flush_send_and_wait(struct cpumask *flush_mask, struct bau_control *bcp,
908 struct bau_desc *bau_desc)
Cliff Wickmanb194b122008-06-12 08:23:48 -0500909{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500910 int seq_number = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500911 int completion_stat = 0;
Cliff Wickmanda87c932012-01-16 15:17:50 -0600912 int uv1 = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500913 long try = 0;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200914 unsigned long index;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500915 cycles_t time1;
916 cycles_t time2;
Cliff Wickman712157a2010-06-02 16:22:02 -0500917 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500918 struct bau_control *hmaster = bcp->uvhub_master;
Cliff Wickmanda87c932012-01-16 15:17:50 -0600919 struct uv1_bau_msg_header *uv1_hdr = NULL;
Cliff Wickmana26fd712014-05-14 16:15:47 -0500920 struct uv2_3_bau_msg_header *uv2_3_hdr = NULL;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500921
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500922 if (bcp->uvhub_version == 1) {
923 uv1 = 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500924 uv1_throttle(hmaster, stat);
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500925 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500926
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500927 while (hmaster->uvhub_quiesce)
928 cpu_relax();
Cliff Wickmanb194b122008-06-12 08:23:48 -0500929
Cliff Wickmanb194b122008-06-12 08:23:48 -0500930 time1 = get_cycles();
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500931 if (uv1)
932 uv1_hdr = &bau_desc->header.uv1_hdr;
933 else
Cliff Wickmana26fd712014-05-14 16:15:47 -0500934 /* uv2 and uv3 */
935 uv2_3_hdr = &bau_desc->header.uv2_3_hdr;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500936
Cliff Wickmanb194b122008-06-12 08:23:48 -0500937 do {
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500938 if (try == 0) {
Cliff Wickmanda87c932012-01-16 15:17:50 -0600939 if (uv1)
940 uv1_hdr->msg_type = MSG_REGULAR;
941 else
Cliff Wickmana26fd712014-05-14 16:15:47 -0500942 uv2_3_hdr->msg_type = MSG_REGULAR;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500943 seq_number = bcp->message_number++;
944 } else {
Cliff Wickmanda87c932012-01-16 15:17:50 -0600945 if (uv1)
946 uv1_hdr->msg_type = MSG_RETRY;
947 else
Cliff Wickmana26fd712014-05-14 16:15:47 -0500948 uv2_3_hdr->msg_type = MSG_RETRY;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500949 stat->s_retry_messages++;
950 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500951
Cliff Wickmanda87c932012-01-16 15:17:50 -0600952 if (uv1)
953 uv1_hdr->sequence = seq_number;
954 else
Cliff Wickmana26fd712014-05-14 16:15:47 -0500955 uv2_3_hdr->sequence = seq_number;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500956 index = (1UL << AS_PUSH_SHIFT) | bcp->uvhub_cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500957 bcp->send_message = get_cycles();
958
959 write_mmr_activation(index);
960
961 try++;
962 completion_stat = wait_completion(bau_desc, bcp, try);
963
964 handle_cmplt(completion_stat, bau_desc, bcp, hmaster, stat);
965
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500966 if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500967 bcp->ipi_attempts = 0;
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500968 stat->s_overipilimit++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500969 completion_stat = FLUSH_GIVEUP;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500970 break;
971 }
972 cpu_relax();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500973 } while ((completion_stat == FLUSH_RETRY_PLUGGED) ||
974 (completion_stat == FLUSH_RETRY_TIMEOUT));
975
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500976 time2 = get_cycles();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500977
978 count_max_concurr(completion_stat, bcp, hmaster);
979
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500980 while (hmaster->uvhub_quiesce)
981 cpu_relax();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500982
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500983 atomic_dec(&hmaster->active_descriptor_count);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500984
985 record_send_stats(time1, time2, bcp, stat, completion_stat, try);
986
987 if (completion_stat == FLUSH_GIVEUP)
Cliff Wickmanc5d35d32012-01-16 15:19:47 -0600988 /* FLUSH_GIVEUP will fall back to using IPI's for tlb flush */
Cliff Wickman450a0072010-06-02 16:22:02 -0500989 return 1;
Cliff Wickman450a0072010-06-02 16:22:02 -0500990 return 0;
Cliff Wickmanb194b122008-06-12 08:23:48 -0500991}
992
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500993/*
Cliff Wickman8b6e5112012-06-22 08:14:59 -0500994 * The BAU is disabled for this uvhub. When the disabled time period has
995 * expired re-enable it.
996 * Return 0 if it is re-enabled for all cpus on this uvhub.
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500997 */
998static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
999{
1000 int tcpu;
1001 struct bau_control *tbcp;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001002 struct bau_control *hmaster;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001003
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001004 hmaster = bcp->uvhub_master;
1005 spin_lock(&hmaster->disable_lock);
1006 if (bcp->baudisabled && (get_cycles() >= bcp->set_bau_on_time)) {
1007 stat->s_bau_reenabled++;
1008 for_each_present_cpu(tcpu) {
1009 tbcp = &per_cpu(bau_control, tcpu);
1010 if (tbcp->uvhub_master == hmaster) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001011 tbcp->baudisabled = 0;
1012 tbcp->period_requests = 0;
1013 tbcp->period_time = 0;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001014 tbcp->period_giveups = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001015 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001016 }
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001017 spin_unlock(&hmaster->disable_lock);
1018 return 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001019 }
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001020 spin_unlock(&hmaster->disable_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001021 return -1;
1022}
1023
1024static void record_send_statistics(struct ptc_stats *stat, int locals, int hubs,
1025 int remotes, struct bau_desc *bau_desc)
1026{
1027 stat->s_requestor++;
1028 stat->s_ntargcpu += remotes + locals;
1029 stat->s_ntargremotes += remotes;
1030 stat->s_ntarglocals += locals;
1031
1032 /* uvhub statistics */
1033 hubs = bau_uvhub_weight(&bau_desc->distribution);
1034 if (locals) {
1035 stat->s_ntarglocaluvhub++;
1036 stat->s_ntargremoteuvhub += (hubs - 1);
1037 } else
1038 stat->s_ntargremoteuvhub += hubs;
1039
1040 stat->s_ntarguvhub += hubs;
1041
1042 if (hubs >= 16)
1043 stat->s_ntarguvhub16++;
1044 else if (hubs >= 8)
1045 stat->s_ntarguvhub8++;
1046 else if (hubs >= 4)
1047 stat->s_ntarguvhub4++;
1048 else if (hubs >= 2)
1049 stat->s_ntarguvhub2++;
1050 else
1051 stat->s_ntarguvhub1++;
1052}
1053
1054/*
1055 * Translate a cpu mask to the uvhub distribution mask in the BAU
1056 * activation descriptor.
1057 */
1058static int set_distrib_bits(struct cpumask *flush_mask, struct bau_control *bcp,
1059 struct bau_desc *bau_desc, int *localsp, int *remotesp)
1060{
1061 int cpu;
1062 int pnode;
1063 int cnt = 0;
1064 struct hub_and_pnode *hpp;
1065
1066 for_each_cpu(cpu, flush_mask) {
1067 /*
1068 * The distribution vector is a bit map of pnodes, relative
1069 * to the partition base pnode (and the partition base nasid
1070 * in the header).
1071 * Translate cpu to pnode and hub using a local memory array.
1072 */
1073 hpp = &bcp->socket_master->thp[cpu];
1074 pnode = hpp->pnode - bcp->partition_base_pnode;
1075 bau_uvhub_set(pnode, &bau_desc->distribution);
1076 cnt++;
1077 if (hpp->uvhub == bcp->uvhub)
1078 (*localsp)++;
1079 else
1080 (*remotesp)++;
1081 }
1082 if (!cnt)
1083 return 1;
1084 return 0;
1085}
1086
1087/*
1088 * globally purge translation cache of a virtual address or all TLB's
Tejun Heobdbcdd42009-01-21 17:26:06 +09001089 * @cpumask: mask of all cpu's in which the address is to be removed
Cliff Wickman18129242008-06-02 08:56:14 -05001090 * @mm: mm_struct containing virtual address range
Alex Shi57c4f432012-12-18 12:22:14 -08001091 * @start: start virtual address to be removed from TLB
1092 * @end: end virtual address to be remove from TLB
Tejun Heobdbcdd42009-01-21 17:26:06 +09001093 * @cpu: the current cpu
Cliff Wickman18129242008-06-02 08:56:14 -05001094 *
1095 * This is the entry point for initiating any UV global TLB shootdown.
1096 *
1097 * Purges the translation caches of all specified processors of the given
1098 * virtual address, or purges all TLB's on specified processors.
1099 *
Tejun Heobdbcdd42009-01-21 17:26:06 +09001100 * The caller has derived the cpumask from the mm_struct. This function
1101 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
Cliff Wickman18129242008-06-02 08:56:14 -05001102 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001103 * The cpumask is converted into a uvhubmask of the uvhubs containing
1104 * those cpus.
Cliff Wickmanb194b122008-06-12 08:23:48 -05001105 *
Tejun Heobdbcdd42009-01-21 17:26:06 +09001106 * Note that this function should be called with preemption disabled.
1107 *
1108 * Returns NULL if all remote flushing was done.
1109 * Returns pointer to cpumask if some remote flushing remains to be
1110 * done. The returned pointer is valid till preemption is re-enabled.
Cliff Wickman18129242008-06-02 08:56:14 -05001111 */
Tejun Heobdbcdd42009-01-21 17:26:06 +09001112const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
Cliff Wickmana26fd712014-05-14 16:15:47 -05001113 struct mm_struct *mm,
1114 unsigned long start,
1115 unsigned long end,
1116 unsigned int cpu)
Cliff Wickman18129242008-06-02 08:56:14 -05001117{
Cliff Wickmanb194b122008-06-12 08:23:48 -05001118 int locals = 0;
Cliff Wickman450a0072010-06-02 16:22:02 -05001119 int remotes = 0;
1120 int hubs = 0;
Ingo Molnardc163a42008-06-18 14:15:43 +02001121 struct bau_desc *bau_desc;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001122 struct cpumask *flush_mask;
1123 struct ptc_stats *stat;
1124 struct bau_control *bcp;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001125 unsigned long descriptor_status;
1126 unsigned long status;
Cliff Wickman18129242008-06-02 08:56:14 -05001127
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001128 bcp = &per_cpu(bau_control, cpu);
Cliff Wickman26ef8572012-06-22 08:13:30 -05001129
1130 if (bcp->nobau)
1131 return cpumask;
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001132
cpw3eae49c2013-12-03 17:15:30 -06001133 stat = bcp->statp;
1134 stat->s_enters++;
1135
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001136 if (bcp->busy) {
1137 descriptor_status =
1138 read_lmmr(UVH_LB_BAU_SB_ACTIVATION_STATUS_0);
1139 status = ((descriptor_status >> (bcp->uvhub_cpu *
1140 UV_ACT_STATUS_SIZE)) & UV_ACT_STATUS_MASK) << 1;
1141 if (status == UV2H_DESC_BUSY)
1142 return cpumask;
1143 bcp->busy = 0;
1144 }
1145
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001146 /* bau was disabled due to slow response */
1147 if (bcp->baudisabled) {
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001148 if (check_enable(bcp, stat)) {
1149 stat->s_ipifordisabled++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001150 return cpumask;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001151 }
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001152 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001153
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001154 /*
1155 * Each sending cpu has a per-cpu mask which it fills from the caller's
Cliff Wickman450a0072010-06-02 16:22:02 -05001156 * cpu mask. All cpus are converted to uvhubs and copied to the
1157 * activation descriptor.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001158 */
1159 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
Cliff Wickman450a0072010-06-02 16:22:02 -05001160 /* don't actually do a shootdown of the local cpu */
Tejun Heobdbcdd42009-01-21 17:26:06 +09001161 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001162
Rusty Russell020b37a2015-03-02 22:05:49 +10301163 if (cpumask_test_cpu(cpu, cpumask))
Cliff Wickman450a0072010-06-02 16:22:02 -05001164 stat->s_ntargself++;
Tejun Heobdbcdd42009-01-21 17:26:06 +09001165
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001166 bau_desc = bcp->descriptor_base;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001167 bau_desc += (ITEMS_PER_DESC * bcp->uvhub_cpu);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001168 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001169 if (set_distrib_bits(flush_mask, bcp, bau_desc, &locals, &remotes))
Cliff Wickman450a0072010-06-02 16:22:02 -05001170 return NULL;
Cliff Wickman450a0072010-06-02 16:22:02 -05001171
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001172 record_send_statistics(stat, locals, hubs, remotes, bau_desc);
Cliff Wickman18129242008-06-02 08:56:14 -05001173
Alex Shi57c4f432012-12-18 12:22:14 -08001174 if (!end || (end - start) <= PAGE_SIZE)
1175 bau_desc->payload.address = start;
1176 else
1177 bau_desc->payload.address = TLB_FLUSH_ALL;
Tejun Heobdbcdd42009-01-21 17:26:06 +09001178 bau_desc->payload.sending_cpu = cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001179 /*
Cliff Wickman450a0072010-06-02 16:22:02 -05001180 * uv_flush_send_and_wait returns 0 if all cpu's were messaged,
1181 * or 1 if it gave up and the original cpumask should be returned.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001182 */
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001183 if (!uv_flush_send_and_wait(flush_mask, bcp, bau_desc))
Cliff Wickman450a0072010-06-02 16:22:02 -05001184 return NULL;
1185 else
1186 return cpumask;
Cliff Wickman18129242008-06-02 08:56:14 -05001187}
1188
1189/*
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001190 * Search the message queue for any 'other' unprocessed message with the
1191 * same software acknowledge resource bit vector as the 'msg' message.
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001192 */
1193struct bau_pq_entry *find_another_by_swack(struct bau_pq_entry *msg,
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001194 struct bau_control *bcp)
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001195{
1196 struct bau_pq_entry *msg_next = msg + 1;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001197 unsigned char swack_vec = msg->swack_vec;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001198
1199 if (msg_next > bcp->queue_last)
1200 msg_next = bcp->queue_first;
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001201 while (msg_next != msg) {
1202 if ((msg_next->canceled == 0) && (msg_next->replied_to == 0) &&
1203 (msg_next->swack_vec == swack_vec))
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001204 return msg_next;
1205 msg_next++;
1206 if (msg_next > bcp->queue_last)
1207 msg_next = bcp->queue_first;
1208 }
1209 return NULL;
1210}
1211
1212/*
1213 * UV2 needs to work around a bug in which an arriving message has not
1214 * set a bit in the UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE register.
1215 * Such a message must be ignored.
1216 */
1217void process_uv2_message(struct msg_desc *mdp, struct bau_control *bcp)
1218{
1219 unsigned long mmr_image;
1220 unsigned char swack_vec;
1221 struct bau_pq_entry *msg = mdp->msg;
1222 struct bau_pq_entry *other_msg;
1223
Andrew Banman21e3f122016-09-21 11:09:17 -05001224 mmr_image = ops.read_l_sw_ack();
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001225 swack_vec = msg->swack_vec;
1226
1227 if ((swack_vec & mmr_image) == 0) {
1228 /*
1229 * This message was assigned a swack resource, but no
1230 * reserved acknowlegment is pending.
1231 * The bug has prevented this message from setting the MMR.
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001232 */
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001233 /*
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001234 * Some message has set the MMR 'pending' bit; it might have
1235 * been another message. Look for that message.
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001236 */
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001237 other_msg = find_another_by_swack(msg, bcp);
1238 if (other_msg) {
1239 /*
1240 * There is another. Process this one but do not
1241 * ack it.
1242 */
1243 bau_process_message(mdp, bcp, 0);
1244 /*
1245 * Let the natural processing of that other message
1246 * acknowledge it. Don't get the processing of sw_ack's
1247 * out of order.
1248 */
1249 return;
1250 }
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001251 }
1252
1253 /*
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001254 * Either the MMR shows this one pending a reply or there is no
1255 * other message using this sw_ack, so it is safe to acknowledge it.
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001256 */
1257 bau_process_message(mdp, bcp, 1);
1258
1259 return;
1260}
1261
1262/*
Cliff Wickman18129242008-06-02 08:56:14 -05001263 * The BAU message interrupt comes here. (registered by set_intr_gate)
1264 * See entry_64.S
1265 *
1266 * We received a broadcast assist message.
1267 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001268 * Interrupts are disabled; this interrupt could represent
Cliff Wickman18129242008-06-02 08:56:14 -05001269 * the receipt of several messages.
1270 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001271 * All cores/threads on this hub get this interrupt.
1272 * The last one to see it does the software ack.
Cliff Wickman18129242008-06-02 08:56:14 -05001273 * (the resource will not be freed until noninterruptable cpus see this
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001274 * interrupt; hardware may timeout the s/w ack and reply ERROR)
Cliff Wickman18129242008-06-02 08:56:14 -05001275 */
Cliff Wickmanb194b122008-06-12 08:23:48 -05001276void uv_bau_message_interrupt(struct pt_regs *regs)
Cliff Wickman18129242008-06-02 08:56:14 -05001277{
Cliff Wickman18129242008-06-02 08:56:14 -05001278 int count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001279 cycles_t time_start;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001280 struct bau_pq_entry *msg;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001281 struct bau_control *bcp;
1282 struct ptc_stats *stat;
1283 struct msg_desc msgdesc;
Cliff Wickman18129242008-06-02 08:56:14 -05001284
Cliff Wickman88ed9dd2012-01-16 15:21:46 -06001285 ack_APIC_irq();
Nicolai Stange2c5a3a02018-07-29 13:06:04 +02001286 kvm_set_cpu_l1tf_flush_l1d();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001287 time_start = get_cycles();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001288
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001289 bcp = &per_cpu(bau_control, smp_processor_id());
Cliff Wickman712157a2010-06-02 16:22:02 -05001290 stat = bcp->statp;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001291
1292 msgdesc.queue_first = bcp->queue_first;
1293 msgdesc.queue_last = bcp->queue_last;
1294
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001295 msg = bcp->bau_msg_head;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001296 while (msg->swack_vec) {
Cliff Wickman18129242008-06-02 08:56:14 -05001297 count++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001298
1299 msgdesc.msg_slot = msg - msgdesc.queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001300 msgdesc.msg = msg;
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001301 if (bcp->uvhub_version == 2)
1302 process_uv2_message(&msgdesc, bcp);
1303 else
Cliff Wickmana26fd712014-05-14 16:15:47 -05001304 /* no error workaround for uv1 or uv3 */
Cliff Wickmanc5d35d32012-01-16 15:19:47 -06001305 bau_process_message(&msgdesc, bcp, 1);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001306
Cliff Wickman18129242008-06-02 08:56:14 -05001307 msg++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001308 if (msg > msgdesc.queue_last)
1309 msg = msgdesc.queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001310 bcp->bau_msg_head = msg;
Cliff Wickman18129242008-06-02 08:56:14 -05001311 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001312 stat->d_time += (get_cycles() - time_start);
Cliff Wickman18129242008-06-02 08:56:14 -05001313 if (!count)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001314 stat->d_nomsg++;
Cliff Wickman18129242008-06-02 08:56:14 -05001315 else if (count > 1)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001316 stat->d_multmsg++;
Cliff Wickman18129242008-06-02 08:56:14 -05001317}
1318
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001319/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001320 * Each target uvhub (i.e. a uvhub that has cpu's) needs to have
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001321 * shootdown message timeouts enabled. The timeout does not cause
1322 * an interrupt, but causes an error message to be returned to
1323 * the sender.
1324 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001325static void __init enable_timeouts(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001326{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001327 int uvhub;
1328 int nuvhubs;
Cliff Wickman18129242008-06-02 08:56:14 -05001329 int pnode;
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001330 unsigned long mmr_image;
Cliff Wickman18129242008-06-02 08:56:14 -05001331
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001332 nuvhubs = uv_num_possible_blades();
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001333
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001334 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
1335 if (!uv_blade_nr_possible_cpus(uvhub))
Cliff Wickman18129242008-06-02 08:56:14 -05001336 continue;
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001337
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001338 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001339 mmr_image = read_mmr_misc_control(pnode);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001340 /*
1341 * Set the timeout period and then lock it in, in three
1342 * steps; captures and locks in the period.
1343 *
1344 * To program the period, the SOFT_ACK_MODE must be off.
1345 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001346 mmr_image &= ~(1L << SOFTACK_MSHIFT);
1347 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001348 /*
1349 * Set the 4-bit period.
1350 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001351 mmr_image &= ~((unsigned long)0xf << SOFTACK_PSHIFT);
1352 mmr_image |= (SOFTACK_TIMEOUT_PERIOD << SOFTACK_PSHIFT);
1353 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001354 /*
Jack Steiner2a919592011-05-11 12:50:28 -05001355 * UV1:
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001356 * Subsequent reversals of the timebase bit (3) cause an
1357 * immediate timeout of one or all INTD resources as
1358 * indicated in bits 2:0 (7 causes all of them to timeout).
1359 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001360 mmr_image |= (1L << SOFTACK_MSHIFT);
Jack Steiner2a919592011-05-11 12:50:28 -05001361 if (is_uv2_hub()) {
Cliff Wickmana26fd712014-05-14 16:15:47 -05001362 /* do not touch the legacy mode bit */
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001363 /* hw bug workaround; do not use extended status */
1364 mmr_image &= ~(1L << UV2_EXT_SHFT);
Cliff Wickmana26fd712014-05-14 16:15:47 -05001365 } else if (is_uv3_hub()) {
1366 mmr_image &= ~(1L << PREFETCH_HINT_SHFT);
1367 mmr_image |= (1L << SB_STATUS_SHFT);
Jack Steiner2a919592011-05-11 12:50:28 -05001368 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001369 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickman18129242008-06-02 08:56:14 -05001370 }
Cliff Wickman18129242008-06-02 08:56:14 -05001371}
1372
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001373static void *ptc_seq_start(struct seq_file *file, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -05001374{
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_next(struct seq_file *file, void *data, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -05001381{
1382 (*offset)++;
1383 if (*offset < num_possible_cpus())
1384 return offset;
1385 return NULL;
1386}
1387
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001388static void ptc_seq_stop(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001389{
1390}
1391
1392/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001393 * Display the statistics thru /proc/sgi_uv/ptc_statistics
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001394 * 'data' points to the cpu number
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001395 * Note: see the descriptions in stat_description[].
Cliff Wickman18129242008-06-02 08:56:14 -05001396 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001397static int ptc_seq_show(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001398{
1399 struct ptc_stats *stat;
Cliff Wickman26ef8572012-06-22 08:13:30 -05001400 struct bau_control *bcp;
Cliff Wickman18129242008-06-02 08:56:14 -05001401 int cpu;
1402
1403 cpu = *(loff_t *)data;
Cliff Wickman18129242008-06-02 08:56:14 -05001404 if (!cpu) {
Rasmus Villemoes37367082014-11-28 22:03:41 +01001405 seq_puts(file,
1406 "# cpu bauoff sent stime self locals remotes ncpus localhub ");
1407 seq_puts(file, "remotehub numuvhubs numuvhubs16 numuvhubs8 ");
1408 seq_puts(file,
1409 "numuvhubs4 numuvhubs2 numuvhubs1 dto snacks retries ");
1410 seq_puts(file,
1411 "rok resetp resett giveup sto bz throt disable ");
1412 seq_puts(file,
1413 "enable wars warshw warwaits enters ipidis plugged ");
1414 seq_puts(file,
1415 "ipiover glim cong swack recv rtime all one mult ");
1416 seq_puts(file, "none retry canc nocan reset rcan\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001417 }
1418 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
Cliff Wickman26ef8572012-06-22 08:13:30 -05001419 bcp = &per_cpu(bau_control, cpu);
James Custerfa2a79ce2014-11-02 12:16:39 -06001420 if (bcp->nobau) {
1421 seq_printf(file, "cpu %d bau disabled\n", cpu);
1422 return 0;
1423 }
Cliff Wickman26ef8572012-06-22 08:13:30 -05001424 stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001425 /* source side statistics */
1426 seq_printf(file,
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001427 "cpu %d %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
Cliff Wickman26ef8572012-06-22 08:13:30 -05001428 cpu, bcp->nobau, stat->s_requestor,
1429 cycles_2_us(stat->s_time),
Cliff Wickman450a0072010-06-02 16:22:02 -05001430 stat->s_ntargself, stat->s_ntarglocals,
1431 stat->s_ntargremotes, stat->s_ntargcpu,
1432 stat->s_ntarglocaluvhub, stat->s_ntargremoteuvhub,
1433 stat->s_ntarguvhub, stat->s_ntarguvhub16);
Cliff Wickmanb54bd9b2012-01-16 15:22:38 -06001434 seq_printf(file, "%ld %ld %ld %ld %ld %ld ",
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001435 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
1436 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
Cliff Wickmanb54bd9b2012-01-16 15:22:38 -06001437 stat->s_dtimeout, stat->s_strongnacks);
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001438 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001439 stat->s_retry_messages, stat->s_retriesok,
1440 stat->s_resets_plug, stat->s_resets_timeout,
1441 stat->s_giveup, stat->s_stimeout,
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001442 stat->s_busy, stat->s_throttles);
1443 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
1444 stat->s_bau_disabled, stat->s_bau_reenabled,
1445 stat->s_uv2_wars, stat->s_uv2_wars_hw,
1446 stat->s_uv2_war_waits, stat->s_enters,
1447 stat->s_ipifordisabled, stat->s_plugged,
1448 stat->s_overipilimit, stat->s_giveuplimit,
1449 stat->s_congested);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001450
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001451 /* destination side statistics */
1452 seq_printf(file,
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001453 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
Andrew Banman21e3f122016-09-21 11:09:17 -05001454 ops.read_g_sw_ack(uv_cpu_to_pnode(cpu)),
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001455 stat->d_requestee, cycles_2_us(stat->d_time),
1456 stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
1457 stat->d_nomsg, stat->d_retries, stat->d_canceled,
1458 stat->d_nocanceled, stat->d_resets,
1459 stat->d_rcanceled);
Cliff Wickman18129242008-06-02 08:56:14 -05001460 }
Cliff Wickman18129242008-06-02 08:56:14 -05001461 return 0;
1462}
1463
1464/*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001465 * Display the tunables thru debugfs
1466 */
1467static ssize_t tunables_read(struct file *file, char __user *userbuf,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001468 size_t count, loff_t *ppos)
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001469{
Dan Carpenterb365a852010-09-29 10:41:05 +02001470 char *buf;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001471 int ret;
1472
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001473 buf = kasprintf(GFP_KERNEL, "%s %s %s\n%d %d %d %d %d %d %d %d %d %d\n",
1474 "max_concur plugged_delay plugsb4reset timeoutsb4reset",
1475 "ipi_reset_limit complete_threshold congested_response_us",
1476 "congested_reps disabled_period giveup_limit",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001477 max_concurr, plugged_delay, plugsb4reset,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001478 timeoutsb4reset, ipi_reset_limit, complete_threshold,
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001479 congested_respns_us, congested_reps, disabled_period,
1480 giveup_limit);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001481
Dan Carpenterb365a852010-09-29 10:41:05 +02001482 if (!buf)
1483 return -ENOMEM;
1484
1485 ret = simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
1486 kfree(buf);
1487 return ret;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001488}
1489
1490/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001491 * handle a write to /proc/sgi_uv/ptc_statistics
1492 * -1: reset the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001493 * 0: display meaning of the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001494 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001495static ssize_t ptc_proc_write(struct file *file, const char __user *user,
1496 size_t count, loff_t *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001497{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001498 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001499 int i;
1500 int elements;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001501 long input_arg;
Cliff Wickman18129242008-06-02 08:56:14 -05001502 char optstr[64];
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001503 struct ptc_stats *stat;
Cliff Wickman18129242008-06-02 08:56:14 -05001504
Cliff Wickmane7eb8722008-06-23 08:32:25 -05001505 if (count == 0 || count > sizeof(optstr))
Cliff Wickmancef53272008-06-19 11:16:24 -05001506 return -EINVAL;
Cliff Wickman18129242008-06-02 08:56:14 -05001507 if (copy_from_user(optstr, user, count))
1508 return -EFAULT;
1509 optstr[count - 1] = '\0';
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001510
Cliff Wickman26ef8572012-06-22 08:13:30 -05001511 if (!strcmp(optstr, "on")) {
1512 set_bau_on();
1513 return count;
1514 } else if (!strcmp(optstr, "off")) {
1515 set_bau_off();
1516 return count;
1517 }
1518
Daniel Walter164109e2014-08-08 14:24:03 -07001519 if (kstrtol(optstr, 10, &input_arg) < 0) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001520 pr_debug("%s is invalid\n", optstr);
Cliff Wickman18129242008-06-02 08:56:14 -05001521 return -EINVAL;
1522 }
1523
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001524 if (input_arg == 0) {
Sasha Levin64441742012-12-20 14:11:34 -05001525 elements = ARRAY_SIZE(stat_description);
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001526 pr_debug("# cpu: cpu number\n");
1527 pr_debug("Sender statistics:\n");
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001528 for (i = 0; i < elements; i++)
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001529 pr_debug("%s\n", stat_description[i]);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001530 } else if (input_arg == -1) {
1531 for_each_present_cpu(cpu) {
1532 stat = &per_cpu(ptcstats, cpu);
1533 memset(stat, 0, sizeof(struct ptc_stats));
1534 }
Cliff Wickman18129242008-06-02 08:56:14 -05001535 }
1536
1537 return count;
1538}
1539
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001540static int local_atoi(const char *name)
1541{
1542 int val = 0;
1543
1544 for (;; name++) {
1545 switch (*name) {
1546 case '0' ... '9':
1547 val = 10*val+(*name-'0');
1548 break;
1549 default:
1550 return val;
1551 }
1552 }
1553}
1554
1555/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001556 * Parse the values written to /sys/kernel/debug/sgi_uv/bau_tunables.
1557 * Zero values reset them to defaults.
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001558 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001559static int parse_tunables_write(struct bau_control *bcp, char *instr,
1560 int count)
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001561{
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001562 char *p;
1563 char *q;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001564 int cnt = 0;
1565 int val;
Sasha Levin64441742012-12-20 14:11:34 -05001566 int e = ARRAY_SIZE(tunables);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001567
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001568 p = instr + strspn(instr, WHITESPACE);
1569 q = p;
1570 for (; *p; p = q + strspn(q, WHITESPACE)) {
1571 q = p + strcspn(p, WHITESPACE);
1572 cnt++;
1573 if (q == p)
1574 break;
1575 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001576 if (cnt != e) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001577 pr_info("bau tunable error: should be %d values\n", e);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001578 return -EINVAL;
1579 }
1580
1581 p = instr + strspn(instr, WHITESPACE);
1582 q = p;
1583 for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
1584 q = p + strcspn(p, WHITESPACE);
1585 val = local_atoi(p);
1586 switch (cnt) {
1587 case 0:
1588 if (val == 0) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001589 max_concurr = MAX_BAU_CONCURRENT;
1590 max_concurr_const = MAX_BAU_CONCURRENT;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001591 continue;
1592 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001593 if (val < 1 || val > bcp->cpus_in_uvhub) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001594 pr_debug(
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001595 "Error: BAU max concurrent %d is invalid\n",
1596 val);
1597 return -EINVAL;
1598 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001599 max_concurr = val;
1600 max_concurr_const = val;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001601 continue;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001602 default:
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001603 if (val == 0)
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001604 *tunables[cnt].tunp = tunables[cnt].deflt;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001605 else
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001606 *tunables[cnt].tunp = val;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001607 continue;
1608 }
1609 if (q == p)
1610 break;
1611 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001612 return 0;
1613}
1614
1615/*
1616 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
1617 */
1618static ssize_t tunables_write(struct file *file, const char __user *user,
1619 size_t count, loff_t *data)
1620{
1621 int cpu;
1622 int ret;
1623 char instr[100];
1624 struct bau_control *bcp;
1625
1626 if (count == 0 || count > sizeof(instr)-1)
1627 return -EINVAL;
1628 if (copy_from_user(instr, user, count))
1629 return -EFAULT;
1630
1631 instr[count] = '\0';
1632
cpw@sgi.com00b30cf2011-06-21 07:21:26 -05001633 cpu = get_cpu();
1634 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001635 ret = parse_tunables_write(bcp, instr, count);
cpw@sgi.com00b30cf2011-06-21 07:21:26 -05001636 put_cpu();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001637 if (ret)
1638 return ret;
1639
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001640 for_each_present_cpu(cpu) {
1641 bcp = &per_cpu(bau_control, cpu);
Andrew Banman67492c82016-09-21 11:09:12 -05001642 bcp->max_concurr = max_concurr;
1643 bcp->max_concurr_const = max_concurr;
1644 bcp->plugged_delay = plugged_delay;
1645 bcp->plugsb4reset = plugsb4reset;
1646 bcp->timeoutsb4reset = timeoutsb4reset;
1647 bcp->ipi_reset_limit = ipi_reset_limit;
1648 bcp->complete_threshold = complete_threshold;
1649 bcp->cong_response_us = congested_respns_us;
1650 bcp->cong_reps = congested_reps;
1651 bcp->disabled_period = sec_2_cycles(disabled_period);
1652 bcp->giveup_limit = giveup_limit;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001653 }
1654 return count;
1655}
1656
Cliff Wickman18129242008-06-02 08:56:14 -05001657static const struct seq_operations uv_ptc_seq_ops = {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001658 .start = ptc_seq_start,
1659 .next = ptc_seq_next,
1660 .stop = ptc_seq_stop,
1661 .show = ptc_seq_show
Cliff Wickman18129242008-06-02 08:56:14 -05001662};
1663
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001664static int ptc_proc_open(struct inode *inode, struct file *file)
Cliff Wickman18129242008-06-02 08:56:14 -05001665{
1666 return seq_open(file, &uv_ptc_seq_ops);
1667}
1668
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001669static int tunables_open(struct inode *inode, struct file *file)
1670{
1671 return 0;
1672}
1673
Cliff Wickman18129242008-06-02 08:56:14 -05001674static const struct file_operations proc_uv_ptc_operations = {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001675 .open = ptc_proc_open,
Cliff Wickmanb194b122008-06-12 08:23:48 -05001676 .read = seq_read,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001677 .write = ptc_proc_write,
Cliff Wickmanb194b122008-06-12 08:23:48 -05001678 .llseek = seq_lseek,
1679 .release = seq_release,
Cliff Wickman18129242008-06-02 08:56:14 -05001680};
1681
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001682static const struct file_operations tunables_fops = {
1683 .open = tunables_open,
1684 .read = tunables_read,
1685 .write = tunables_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001686 .llseek = default_llseek,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001687};
1688
Cliff Wickmanb194b122008-06-12 08:23:48 -05001689static int __init uv_ptc_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001690{
Cliff Wickmanb194b122008-06-12 08:23:48 -05001691 struct proc_dir_entry *proc_uv_ptc;
Cliff Wickman18129242008-06-02 08:56:14 -05001692
1693 if (!is_uv_system())
1694 return 0;
1695
Alexey Dobriyan10f02d112009-08-23 23:17:27 +04001696 proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
1697 &proc_uv_ptc_operations);
Cliff Wickman18129242008-06-02 08:56:14 -05001698 if (!proc_uv_ptc) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001699 pr_err("unable to create %s proc entry\n",
Cliff Wickman18129242008-06-02 08:56:14 -05001700 UV_PTC_BASENAME);
1701 return -EINVAL;
1702 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001703
1704 tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
1705 if (!tunables_dir) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001706 pr_err("unable to create debugfs directory %s\n",
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001707 UV_BAU_TUNABLES_DIR);
1708 return -EINVAL;
1709 }
1710 tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001711 tunables_dir, NULL, &tunables_fops);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001712 if (!tunables_file) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001713 pr_err("unable to create debugfs file %s\n",
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001714 UV_BAU_TUNABLES_FILE);
1715 return -EINVAL;
1716 }
Cliff Wickman18129242008-06-02 08:56:14 -05001717 return 0;
1718}
1719
Cliff Wickmanb194b122008-06-12 08:23:48 -05001720/*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001721 * Initialize the sending side's sending buffers.
Cliff Wickmanb194b122008-06-12 08:23:48 -05001722 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001723static void activation_descriptor_init(int node, int pnode, int base_pnode)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001724{
1725 int i;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001726 int cpu;
Cliff Wickmanda87c932012-01-16 15:17:50 -06001727 int uv1 = 0;
Jack Steiner6a469e42011-09-20 13:55:04 -07001728 unsigned long gpa;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001729 unsigned long m;
1730 unsigned long n;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001731 size_t dsize;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001732 struct bau_desc *bau_desc;
1733 struct bau_desc *bd2;
Cliff Wickmanda87c932012-01-16 15:17:50 -06001734 struct uv1_bau_msg_header *uv1_hdr;
Cliff Wickmana26fd712014-05-14 16:15:47 -05001735 struct uv2_3_bau_msg_header *uv2_3_hdr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001736 struct bau_control *bcp;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001737
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001738 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001739 * each bau_desc is 64 bytes; there are 8 (ITEMS_PER_DESC)
1740 * per cpu; and one per cpu on the uvhub (ADP_SZ)
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001741 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001742 dsize = sizeof(struct bau_desc) * ADP_SZ * ITEMS_PER_DESC;
1743 bau_desc = kmalloc_node(dsize, GFP_KERNEL, node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001744 BUG_ON(!bau_desc);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001745
Jack Steiner6a469e42011-09-20 13:55:04 -07001746 gpa = uv_gpa(bau_desc);
1747 n = uv_gpa_to_gnode(gpa);
Andrew Banman21e3f122016-09-21 11:09:17 -05001748 m = ops.bau_gpa_to_offset(gpa);
Cliff Wickmanda87c932012-01-16 15:17:50 -06001749 if (is_uv1_hub())
1750 uv1 = 1;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001751
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001752 /* the 14-bit pnode */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001753 write_mmr_descriptor_base(pnode, (n << UV_DESC_PSHIFT | m));
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001754 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001755 * Initializing all 8 (ITEMS_PER_DESC) descriptors for each
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001756 * cpu even though we only use the first one; one descriptor can
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001757 * describe a broadcast to 256 uv hubs.
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001758 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001759 for (i = 0, bd2 = bau_desc; i < (ADP_SZ * ITEMS_PER_DESC); i++, bd2++) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001760 memset(bd2, 0, sizeof(struct bau_desc));
Cliff Wickmanda87c932012-01-16 15:17:50 -06001761 if (uv1) {
1762 uv1_hdr = &bd2->header.uv1_hdr;
Andrew Banman67492c82016-09-21 11:09:12 -05001763 uv1_hdr->swack_flag = 1;
Cliff Wickmanda87c932012-01-16 15:17:50 -06001764 /*
1765 * The base_dest_nasid set in the message header
1766 * is the nasid of the first uvhub in the partition.
1767 * The bit map will indicate destination pnode numbers
1768 * relative to that base. They may not be consecutive
1769 * if nasid striding is being used.
1770 */
1771 uv1_hdr->base_dest_nasid =
Andrew Banman67492c82016-09-21 11:09:12 -05001772 UV_PNODE_TO_NASID(base_pnode);
1773 uv1_hdr->dest_subnodeid = UV_LB_SUBNODEID;
1774 uv1_hdr->command = UV_NET_ENDPOINT_INTD;
1775 uv1_hdr->int_both = 1;
Cliff Wickmanda87c932012-01-16 15:17:50 -06001776 /*
1777 * all others need to be set to zero:
1778 * fairness chaining multilevel count replied_to
1779 */
1780 } else {
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001781 /*
Cliff Wickmana26fd712014-05-14 16:15:47 -05001782 * BIOS uses legacy mode, but uv2 and uv3 hardware always
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001783 * uses native mode for selective broadcasts.
1784 */
Cliff Wickmana26fd712014-05-14 16:15:47 -05001785 uv2_3_hdr = &bd2->header.uv2_3_hdr;
Andrew Banman67492c82016-09-21 11:09:12 -05001786 uv2_3_hdr->swack_flag = 1;
Cliff Wickmana26fd712014-05-14 16:15:47 -05001787 uv2_3_hdr->base_dest_nasid =
Andrew Banman67492c82016-09-21 11:09:12 -05001788 UV_PNODE_TO_NASID(base_pnode);
1789 uv2_3_hdr->dest_subnodeid = UV_LB_SUBNODEID;
1790 uv2_3_hdr->command = UV_NET_ENDPOINT_INTD;
Cliff Wickmanda87c932012-01-16 15:17:50 -06001791 }
Cliff Wickmanb194b122008-06-12 08:23:48 -05001792 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001793 for_each_present_cpu(cpu) {
1794 if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
1795 continue;
1796 bcp = &per_cpu(bau_control, cpu);
1797 bcp->descriptor_base = bau_desc;
1798 }
Cliff Wickmanb194b122008-06-12 08:23:48 -05001799}
1800
1801/*
1802 * initialize the destination side's receiving buffers
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001803 * entered for each uvhub in the partition
1804 * - node is first node (kernel memory notion) on the uvhub
1805 * - pnode is the uvhub's physical identifier
Cliff Wickmanb194b122008-06-12 08:23:48 -05001806 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001807static void pq_init(int node, int pnode)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001808{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001809 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001810 size_t plsize;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001811 char *cp;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001812 void *vp;
Andrew Banmand2a57afa2016-09-21 11:09:14 -05001813 unsigned long gnode, first, last, tail;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001814 struct bau_pq_entry *pqp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001815 struct bau_control *bcp;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001816
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001817 plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
1818 vp = kmalloc_node(plsize, GFP_KERNEL, node);
1819 pqp = (struct bau_pq_entry *)vp;
Ingo Molnardc163a42008-06-18 14:15:43 +02001820 BUG_ON(!pqp);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001821
Cliff Wickmanb194b122008-06-12 08:23:48 -05001822 cp = (char *)pqp + 31;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001823 pqp = (struct bau_pq_entry *)(((unsigned long)cp >> 5) << 5);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001824
1825 for_each_present_cpu(cpu) {
1826 if (pnode != uv_cpu_to_pnode(cpu))
1827 continue;
1828 /* for every cpu on this pnode: */
1829 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001830 bcp->queue_first = pqp;
1831 bcp->bau_msg_head = pqp;
1832 bcp->queue_last = pqp + (DEST_Q_SIZE - 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001833 }
Andrew Banmand2a57afa2016-09-21 11:09:14 -05001834
Andrew Banman21e3f122016-09-21 11:09:17 -05001835 first = ops.bau_gpa_to_offset(uv_gpa(pqp));
1836 last = ops.bau_gpa_to_offset(uv_gpa(pqp + (DEST_Q_SIZE - 1)));
Andrew Banmand2a57afa2016-09-21 11:09:14 -05001837
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001838 /*
Andrew Banman6d780592016-09-21 11:09:20 -05001839 * Pre UV4, the gnode is required to locate the payload queue
1840 * and the payload queue tail must be maintained by the kernel.
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001841 */
Andrew Banman6d780592016-09-21 11:09:20 -05001842 bcp = &per_cpu(bau_control, smp_processor_id());
1843 if (bcp->uvhub_version <= 3) {
1844 tail = first;
1845 gnode = uv_gpa_to_gnode(uv_gpa(pqp));
1846 first = (gnode << UV_PAYLOADQ_GNODE_SHIFT) | tail;
1847 write_mmr_payload_tail(pnode, tail);
1848 }
1849
Andrew Banman21e3f122016-09-21 11:09:17 -05001850 ops.write_payload_first(pnode, first);
1851 ops.write_payload_last(pnode, last);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001852
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001853 /* in effect, all msg_type's are set to MSG_NOOP */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001854 memset(pqp, 0, sizeof(struct bau_pq_entry) * DEST_Q_SIZE);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001855}
1856
1857/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001858 * Initialization of each UV hub's structures
Cliff Wickmanb194b122008-06-12 08:23:48 -05001859 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001860static void __init init_uvhub(int uvhub, int vector, int base_pnode)
Cliff Wickmanb194b122008-06-12 08:23:48 -05001861{
Cliff Wickman9674f352009-04-03 08:34:05 -05001862 int node;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001863 int pnode;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001864 unsigned long apicid;
Cliff Wickmanb194b122008-06-12 08:23:48 -05001865
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001866 node = uvhub_to_first_node(uvhub);
1867 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001868
1869 activation_descriptor_init(node, pnode, base_pnode);
1870
1871 pq_init(node, pnode);
Cliff Wickmanb194b122008-06-12 08:23:48 -05001872 /*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001873 * The below initialization can't be in firmware because the
1874 * messaging IRQ will be determined by the OS.
Cliff Wickmanb194b122008-06-12 08:23:48 -05001875 */
Dimitri Sivanich8191c9f2010-11-16 16:23:52 -06001876 apicid = uvhub_to_first_apicid(uvhub) | uv_apicid_hibits;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001877 write_mmr_data_config(pnode, ((apicid << 32) | vector));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001878}
1879
1880/*
Cliff Wickman12a66112010-06-02 16:22:01 -05001881 * We will set BAU_MISC_CONTROL with a timeout period.
1882 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001883 * So the destination timeout period has to be calculated from them.
Cliff Wickman12a66112010-06-02 16:22:01 -05001884 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001885static int calculate_destination_timeout(void)
Cliff Wickman12a66112010-06-02 16:22:01 -05001886{
1887 unsigned long mmr_image;
1888 int mult1;
1889 int mult2;
1890 int index;
1891 int base;
1892 int ret;
1893 unsigned long ts_ns;
1894
Jack Steiner2a919592011-05-11 12:50:28 -05001895 if (is_uv1_hub()) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001896 mult1 = SOFTACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
Jack Steiner2a919592011-05-11 12:50:28 -05001897 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1898 index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
1899 mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
1900 mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
Cliff Wickman11cab712012-06-22 08:12:12 -05001901 ts_ns = timeout_base_ns[index];
1902 ts_ns *= (mult1 * mult2);
Jack Steiner2a919592011-05-11 12:50:28 -05001903 ret = ts_ns / 1000;
1904 } else {
Cliff Wickmana26fd712014-05-14 16:15:47 -05001905 /* same destination timeout for uv2 and uv3 */
Cliff Wickmand059f9f2012-01-16 15:18:48 -06001906 /* 4 bits 0/1 for 10/80us base, 3 bits of multiplier */
1907 mmr_image = uv_read_local_mmr(UVH_LB_BAU_MISC_CONTROL);
Jack Steiner2a919592011-05-11 12:50:28 -05001908 mmr_image = (mmr_image & UV_SA_MASK) >> UV_SA_SHFT;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001909 if (mmr_image & (1L << UV2_ACK_UNITS_SHFT))
Cliff Wickmand059f9f2012-01-16 15:18:48 -06001910 base = 80;
Jack Steiner2a919592011-05-11 12:50:28 -05001911 else
Cliff Wickmand059f9f2012-01-16 15:18:48 -06001912 base = 10;
1913 mult1 = mmr_image & UV2_ACK_MASK;
Jack Steiner2a919592011-05-11 12:50:28 -05001914 ret = mult1 * base;
1915 }
Cliff Wickman12a66112010-06-02 16:22:01 -05001916 return ret;
1917}
1918
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001919static void __init init_per_cpu_tunables(void)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001920{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001921 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001922 struct bau_control *bcp;
1923
1924 for_each_present_cpu(cpu) {
1925 bcp = &per_cpu(bau_control, cpu);
1926 bcp->baudisabled = 0;
Cliff Wickman26ef8572012-06-22 08:13:30 -05001927 if (nobau)
Alex Thorlton1c532e02016-03-31 14:18:29 -05001928 bcp->nobau = true;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001929 bcp->statp = &per_cpu(ptcstats, cpu);
1930 /* time interval to catch a hardware stay-busy bug */
1931 bcp->timeout_interval = usec_2_cycles(2*timeout_us);
1932 bcp->max_concurr = max_concurr;
1933 bcp->max_concurr_const = max_concurr;
1934 bcp->plugged_delay = plugged_delay;
1935 bcp->plugsb4reset = plugsb4reset;
1936 bcp->timeoutsb4reset = timeoutsb4reset;
1937 bcp->ipi_reset_limit = ipi_reset_limit;
1938 bcp->complete_threshold = complete_threshold;
1939 bcp->cong_response_us = congested_respns_us;
1940 bcp->cong_reps = congested_reps;
Andrew Banman67492c82016-09-21 11:09:12 -05001941 bcp->disabled_period = sec_2_cycles(disabled_period);
1942 bcp->giveup_limit = giveup_limit;
Cliff Wickmand2ebc712012-01-18 09:40:47 -06001943 spin_lock_init(&bcp->queue_lock);
1944 spin_lock_init(&bcp->uvhub_lock);
Cliff Wickman8b6e5112012-06-22 08:14:59 -05001945 spin_lock_init(&bcp->disable_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001946 }
1947}
1948
1949/*
1950 * Scan all cpus to collect blade and socket summaries.
1951 */
1952static int __init get_cpu_topology(int base_pnode,
1953 struct uvhub_desc *uvhub_descs,
1954 unsigned char *uvhub_mask)
1955{
1956 int cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001957 int pnode;
1958 int uvhub;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001959 int socket;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001960 struct bau_control *bcp;
1961 struct uvhub_desc *bdp;
1962 struct socket_desc *sdp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001963
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001964 for_each_present_cpu(cpu) {
1965 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001966
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001967 memset(bcp, 0, sizeof(struct bau_control));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001968
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001969 pnode = uv_cpu_hub_info(cpu)->pnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001970 if ((pnode - base_pnode) >= UV_DISTRIBUTION_SIZE) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001971 pr_emerg(
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001972 "cpu %d pnode %d-%d beyond %d; BAU disabled\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001973 cpu, pnode, base_pnode, UV_DISTRIBUTION_SIZE);
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001974 return 1;
1975 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001976
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001977 bcp->osnode = cpu_to_node(cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001978 bcp->partition_base_pnode = base_pnode;
1979
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001980 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001981 *(uvhub_mask + (uvhub/8)) |= (1 << (uvhub%8));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001982 bdp = &uvhub_descs[uvhub];
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001983
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001984 bdp->num_cpus++;
1985 bdp->uvhub = uvhub;
1986 bdp->pnode = pnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001987
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001988 /* kludge: 'assuming' one node per socket, and assuming that
1989 disabling a socket just leaves a gap in node numbers */
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001990 socket = bcp->osnode & 1;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001991 bdp->socket_mask |= (1 << socket);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001992 sdp = &bdp->socket[socket];
1993 sdp->cpu_number[sdp->num_cpus] = cpu;
1994 sdp->num_cpus++;
Cliff Wickmancfa60912011-01-03 12:03:53 -06001995 if (sdp->num_cpus > MAX_CPUS_PER_SOCKET) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05001996 pr_emerg("%d cpus per socket invalid\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001997 sdp->num_cpus);
Cliff Wickmancfa60912011-01-03 12:03:53 -06001998 return 1;
1999 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002000 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002001 return 0;
2002}
2003
2004/*
2005 * Each socket is to get a local array of pnodes/hubs.
2006 */
2007static void make_per_cpu_thp(struct bau_control *smaster)
2008{
2009 int cpu;
2010 size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
2011
2012 smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
2013 memset(smaster->thp, 0, hpsz);
2014 for_each_present_cpu(cpu) {
2015 smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
2016 smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
2017 }
2018}
2019
2020/*
cpw@sgi.com442d3922011-06-21 07:21:31 -05002021 * Each uvhub is to get a local cpumask.
2022 */
2023static void make_per_hub_cpumask(struct bau_control *hmaster)
2024{
2025 int sz = sizeof(cpumask_t);
2026
2027 hmaster->cpumask = kzalloc_node(sz, GFP_KERNEL, hmaster->osnode);
2028}
2029
2030/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002031 * Initialize all the per_cpu information for the cpu's on a given socket,
2032 * given what has been gathered into the socket_desc struct.
2033 * And reports the chosen hub and socket masters back to the caller.
2034 */
2035static int scan_sock(struct socket_desc *sdp, struct uvhub_desc *bdp,
2036 struct bau_control **smasterp,
2037 struct bau_control **hmasterp)
2038{
2039 int i;
2040 int cpu;
2041 struct bau_control *bcp;
2042
2043 for (i = 0; i < sdp->num_cpus; i++) {
2044 cpu = sdp->cpu_number[i];
2045 bcp = &per_cpu(bau_control, cpu);
2046 bcp->cpu = cpu;
2047 if (i == 0) {
2048 *smasterp = bcp;
2049 if (!(*hmasterp))
2050 *hmasterp = bcp;
2051 }
2052 bcp->cpus_in_uvhub = bdp->num_cpus;
2053 bcp->cpus_in_socket = sdp->num_cpus;
2054 bcp->socket_master = *smasterp;
2055 bcp->uvhub = bdp->uvhub;
Cliff Wickmanda87c932012-01-16 15:17:50 -06002056 if (is_uv1_hub())
2057 bcp->uvhub_version = 1;
2058 else if (is_uv2_hub())
2059 bcp->uvhub_version = 2;
Cliff Wickmana26fd712014-05-14 16:15:47 -05002060 else if (is_uv3_hub())
2061 bcp->uvhub_version = 3;
Andrew Banman58d4ab42016-09-21 11:09:18 -05002062 else if (is_uv4_hub())
2063 bcp->uvhub_version = 4;
Cliff Wickmanda87c932012-01-16 15:17:50 -06002064 else {
Andrew Banman58d4ab42016-09-21 11:09:18 -05002065 pr_emerg("uvhub version not 1, 2, 3, or 4\n");
Cliff Wickmanda87c932012-01-16 15:17:50 -06002066 return 1;
2067 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002068 bcp->uvhub_master = *hmasterp;
Mike Travis5627a8252016-04-29 16:54:14 -05002069 bcp->uvhub_cpu = uv_cpu_blade_processor_id(cpu);
2070
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002071 if (bcp->uvhub_cpu >= MAX_CPUS_PER_UVHUB) {
Andrew Banmanefa59ab2016-09-21 11:09:13 -05002072 pr_emerg("%d cpus per uvhub invalid\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002073 bcp->uvhub_cpu);
2074 return 1;
2075 }
2076 }
2077 return 0;
2078}
2079
2080/*
2081 * Summarize the blade and socket topology into the per_cpu structures.
2082 */
2083static int __init summarize_uvhub_sockets(int nuvhubs,
2084 struct uvhub_desc *uvhub_descs,
2085 unsigned char *uvhub_mask)
2086{
2087 int socket;
2088 int uvhub;
2089 unsigned short socket_mask;
2090
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05002091 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002092 struct uvhub_desc *bdp;
2093 struct bau_control *smaster = NULL;
2094 struct bau_control *hmaster = NULL;
2095
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05002096 if (!(*(uvhub_mask + (uvhub/8)) & (1 << (uvhub%8))))
2097 continue;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002098
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002099 bdp = &uvhub_descs[uvhub];
Cliff Wickmana8328ee2010-06-02 16:22:02 -05002100 socket_mask = bdp->socket_mask;
2101 socket = 0;
2102 while (socket_mask) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002103 struct socket_desc *sdp;
2104 if ((socket_mask & 1)) {
2105 sdp = &bdp->socket[socket];
2106 if (scan_sock(sdp, bdp, &smaster, &hmaster))
Cliff Wickmancfa60912011-01-03 12:03:53 -06002107 return 1;
cpw@sgi.com9c9153d2011-06-21 07:21:28 -05002108 make_per_cpu_thp(smaster);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002109 }
2110 socket++;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05002111 socket_mask = (socket_mask >> 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002112 }
cpw@sgi.com442d3922011-06-21 07:21:31 -05002113 make_per_hub_cpumask(hmaster);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002114 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002115 return 0;
2116}
2117
2118/*
2119 * initialize the bau_control structure for each cpu
2120 */
2121static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
2122{
2123 unsigned char *uvhub_mask;
2124 void *vp;
2125 struct uvhub_desc *uvhub_descs;
2126
Andrew Banmane879c112016-09-21 11:09:19 -05002127 if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub())
2128 timeout_us = calculate_destination_timeout();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002129
2130 vp = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
2131 uvhub_descs = (struct uvhub_desc *)vp;
2132 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
2133 uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
2134
2135 if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask))
cpw@sgi.combbd270e2011-06-21 07:21:32 -05002136 goto fail;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002137
2138 if (summarize_uvhub_sockets(nuvhubs, uvhub_descs, uvhub_mask))
cpw@sgi.combbd270e2011-06-21 07:21:32 -05002139 goto fail;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002140
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002141 kfree(uvhub_descs);
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05002142 kfree(uvhub_mask);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002143 init_per_cpu_tunables();
Cliff Wickmancfa60912011-01-03 12:03:53 -06002144 return 0;
cpw@sgi.combbd270e2011-06-21 07:21:32 -05002145
2146fail:
2147 kfree(uvhub_descs);
2148 kfree(uvhub_mask);
2149 return 1;
Cliff Wickmanb194b122008-06-12 08:23:48 -05002150}
Cliff Wickman18129242008-06-02 08:56:14 -05002151
2152/*
2153 * Initialization of BAU-related structures
2154 */
Cliff Wickmanb194b122008-06-12 08:23:48 -05002155static int __init uv_bau_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05002156{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002157 int uvhub;
2158 int pnode;
2159 int nuvhubs;
Rusty Russell2c74d662009-03-18 08:22:30 +10302160 int cur_cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002161 int cpus;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002162 int vector;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002163 cpumask_var_t *mask;
Cliff Wickman18129242008-06-02 08:56:14 -05002164
2165 if (!is_uv_system())
2166 return 0;
2167
Andrew Banman4f059d52016-09-21 11:09:21 -05002168 if (is_uv4_hub())
2169 ops = uv4_bau_ops;
2170 else if (is_uv3_hub())
Andrew Banman5e4f96f2016-09-21 11:09:16 -05002171 ops = uv123_bau_ops;
2172 else if (is_uv2_hub())
2173 ops = uv123_bau_ops;
2174 else if (is_uv1_hub())
2175 ops = uv123_bau_ops;
2176
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002177 for_each_possible_cpu(cur_cpu) {
2178 mask = &per_cpu(uv_flush_tlb_mask, cur_cpu);
2179 zalloc_cpumask_var_node(mask, GFP_KERNEL, cpu_to_node(cur_cpu));
2180 }
Rusty Russell76ba0ec2009-03-13 14:49:57 +10302181
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002182 nuvhubs = uv_num_possible_blades();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002183 congested_cycles = usec_2_cycles(congested_respns_us);
Cliff Wickman9674f352009-04-03 08:34:05 -05002184
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002185 uv_base_pnode = 0x7fffffff;
Cliff Wickman77ed23f2011-05-10 08:26:43 -05002186 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002187 cpus = uv_blade_nr_possible_cpus(uvhub);
2188 if (cpus && (uv_blade_to_pnode(uvhub) < uv_base_pnode))
2189 uv_base_pnode = uv_blade_to_pnode(uvhub);
Cliff Wickman77ed23f2011-05-10 08:26:43 -05002190 }
2191
Andrew Banmane879c112016-09-21 11:09:19 -05002192 /* software timeouts are not supported on UV4 */
2193 if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub())
2194 enable_timeouts();
Cliff Wickmand059f9f2012-01-16 15:18:48 -06002195
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002196 if (init_per_cpu(nuvhubs, uv_base_pnode)) {
Cliff Wickman26ef8572012-06-22 08:13:30 -05002197 set_bau_off();
2198 nobau_perm = 1;
Cliff Wickmancfa60912011-01-03 12:03:53 -06002199 return 0;
2200 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02002201
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002202 vector = UV_BAU_MESSAGE;
Cliff Wickmana26fd712014-05-14 16:15:47 -05002203 for_each_possible_blade(uvhub) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002204 if (uv_blade_nr_possible_cpus(uvhub))
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002205 init_uvhub(uvhub, vector, uv_base_pnode);
Cliff Wickmana26fd712014-05-14 16:15:47 -05002206 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002207
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002208 alloc_intr_gate(vector, uv_bau_message_intr1);
2209
2210 for_each_possible_blade(uvhub) {
Cliff Wickman93a7ca02010-07-16 10:11:21 -05002211 if (uv_blade_nr_possible_cpus(uvhub)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002212 unsigned long val;
2213 unsigned long mmr;
Cliff Wickman93a7ca02010-07-16 10:11:21 -05002214 pnode = uv_blade_to_pnode(uvhub);
2215 /* INIT the bau */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05002216 val = 1L << 63;
2217 write_gmmr_activation(pnode, val);
Cliff Wickman93a7ca02010-07-16 10:11:21 -05002218 mmr = 1; /* should be 1 to broadcast to both sockets */
Cliff Wickmanda87c932012-01-16 15:17:50 -06002219 if (!is_uv1_hub())
2220 write_mmr_data_broadcast(pnode, mmr);
Cliff Wickman93a7ca02010-07-16 10:11:21 -05002221 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002222 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02002223
Cliff Wickman18129242008-06-02 08:56:14 -05002224 return 0;
2225}
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05002226core_initcall(uv_bau_init);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05002227fs_initcall(uv_ptc_init);