blob: 5b552198f774eb1e6c6ab3b9ef42276706d74328 [file] [log] [blame]
Cliff Wickman18129242008-06-02 08:56:14 -05001/*
2 * SGI UltraViolet TLB flush routines.
3 *
Cliff Wickmanf073cc82011-05-24 13:07:36 -05004 * (c) 2008-2011 Cliff Wickman <cpw@sgi.com>, SGI.
Cliff Wickman18129242008-06-02 08:56:14 -05005 *
6 * This code is released under the GNU General Public License version 2 or
7 * later.
8 */
Jeremy Fitzhardingeaef8f5b2008-10-14 21:43:43 -07009#include <linux/seq_file.h>
Cliff Wickman18129242008-06-02 08:56:14 -050010#include <linux/proc_fs.h>
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050011#include <linux/debugfs.h>
Cliff Wickman18129242008-06-02 08:56:14 -050012#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Jean Delvareca4445642011-03-25 15:20:14 +010014#include <linux/delay.h>
Cliff Wickman18129242008-06-02 08:56:14 -050015
Cliff Wickman18129242008-06-02 08:56:14 -050016#include <asm/mmu_context.h>
Tejun Heobdbcdd42009-01-21 17:26:06 +090017#include <asm/uv/uv.h>
Cliff Wickman18129242008-06-02 08:56:14 -050018#include <asm/uv/uv_mmrs.h>
Ingo Molnarb4c286e2008-06-18 14:28:19 +020019#include <asm/uv/uv_hub.h>
Cliff Wickman18129242008-06-02 08:56:14 -050020#include <asm/uv/uv_bau.h>
Ingo Molnar7b6aa332009-02-17 13:58:15 +010021#include <asm/apic.h>
Ingo Molnarb4c286e2008-06-18 14:28:19 +020022#include <asm/idle.h>
Cliff Wickmanb194b1202008-06-12 08:23:48 -050023#include <asm/tsc.h>
Cliff Wickman99dd8712008-08-19 12:51:59 -050024#include <asm/irq_vectors.h>
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050025#include <asm/timer.h>
Cliff Wickman18129242008-06-02 08:56:14 -050026
Cliff Wickman12a66112010-06-02 16:22:01 -050027/* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
28static int timeout_base_ns[] = {
29 20,
30 160,
31 1280,
32 10240,
33 81920,
34 655360,
35 5242880,
36 167772160
37};
Cliff Wickmanf073cc82011-05-24 13:07:36 -050038
Cliff Wickman12a66112010-06-02 16:22:01 -050039static int timeout_us;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -050040static int nobau;
Cliff Wickman50fb55a2010-06-02 16:22:02 -050041static int baudisabled;
42static spinlock_t disable_lock;
43static cycles_t congested_cycles;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050044
45/* tunables: */
Cliff Wickmanf073cc82011-05-24 13:07:36 -050046static int max_concurr = MAX_BAU_CONCURRENT;
47static int max_concurr_const = MAX_BAU_CONCURRENT;
48static int plugged_delay = PLUGGED_DELAY;
49static int plugsb4reset = PLUGSB4RESET;
50static int timeoutsb4reset = TIMEOUTSB4RESET;
51static int ipi_reset_limit = IPI_RESET_LIMIT;
52static int complete_threshold = COMPLETE_THRESHOLD;
53static int congested_respns_us = CONGESTED_RESPONSE_US;
54static int congested_reps = CONGESTED_REPS;
55static int congested_period = CONGESTED_PERIOD;
56
57static struct tunables tunables[] = {
58 {&max_concurr, MAX_BAU_CONCURRENT}, /* must be [0] */
59 {&plugged_delay, PLUGGED_DELAY},
60 {&plugsb4reset, PLUGSB4RESET},
61 {&timeoutsb4reset, TIMEOUTSB4RESET},
62 {&ipi_reset_limit, IPI_RESET_LIMIT},
63 {&complete_threshold, COMPLETE_THRESHOLD},
64 {&congested_respns_us, CONGESTED_RESPONSE_US},
65 {&congested_reps, CONGESTED_REPS},
66 {&congested_period, CONGESTED_PERIOD}
67};
68
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -050069static struct dentry *tunables_dir;
70static struct dentry *tunables_file;
71
Cliff Wickmanf073cc82011-05-24 13:07:36 -050072/* these correspond to the statistics printed by ptc_seq_show() */
73static char *stat_description[] = {
74 "sent: number of shootdown messages sent",
75 "stime: time spent sending messages",
76 "numuvhubs: number of hubs targeted with shootdown",
77 "numuvhubs16: number times 16 or more hubs targeted",
78 "numuvhubs8: number times 8 or more hubs targeted",
79 "numuvhubs4: number times 4 or more hubs targeted",
80 "numuvhubs2: number times 2 or more hubs targeted",
81 "numuvhubs1: number times 1 hub targeted",
82 "numcpus: number of cpus targeted with shootdown",
83 "dto: number of destination timeouts",
84 "retries: destination timeout retries sent",
85 "rok: : destination timeouts successfully retried",
86 "resetp: ipi-style resource resets for plugs",
87 "resett: ipi-style resource resets for timeouts",
88 "giveup: fall-backs to ipi-style shootdowns",
89 "sto: number of source timeouts",
90 "bz: number of stay-busy's",
91 "throt: number times spun in throttle",
92 "swack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE",
93 "recv: shootdown messages received",
94 "rtime: time spent processing messages",
95 "all: shootdown all-tlb messages",
96 "one: shootdown one-tlb messages",
97 "mult: interrupts that found multiple messages",
98 "none: interrupts that found no messages",
99 "retry: number of retry messages processed",
100 "canc: number messages canceled by retries",
101 "nocan: number retries that found nothing to cancel",
102 "reset: number of ipi-style reset requests processed",
103 "rcan: number messages canceled by reset requests",
104 "disable: number times use of the BAU was disabled",
105 "enable: number times use of the BAU was re-enabled"
106};
107
108static int __init
109setup_nobau(char *arg)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500110{
111 nobau = 1;
112 return 0;
113}
114early_param("nobau", setup_nobau);
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200115
Cliff Wickman94ca8e42009-04-14 10:56:48 -0500116/* base pnode in this partition */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500117static int uv_base_pnode __read_mostly;
Cliff Wickman18129242008-06-02 08:56:14 -0500118
Ingo Molnardc163a42008-06-18 14:15:43 +0200119static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
120static DEFINE_PER_CPU(struct bau_control, bau_control);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500121static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
122
Cliff Wickman18129242008-06-02 08:56:14 -0500123/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500124 * Determine the first node on a uvhub. 'Nodes' are used for kernel
125 * memory allocation.
Cliff Wickman9674f352009-04-03 08:34:05 -0500126 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500127static int __init uvhub_to_first_node(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -0500128{
129 int node, b;
130
131 for_each_online_node(node) {
132 b = uv_node_to_blade_id(node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500133 if (uvhub == b)
Cliff Wickman9674f352009-04-03 08:34:05 -0500134 return node;
135 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500136 return -1;
Cliff Wickman9674f352009-04-03 08:34:05 -0500137}
138
139/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500140 * Determine the apicid of the first cpu on a uvhub.
Cliff Wickman9674f352009-04-03 08:34:05 -0500141 */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500142static int __init uvhub_to_first_apicid(int uvhub)
Cliff Wickman9674f352009-04-03 08:34:05 -0500143{
144 int cpu;
145
146 for_each_present_cpu(cpu)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500147 if (uvhub == uv_cpu_to_blade_id(cpu))
Cliff Wickman9674f352009-04-03 08:34:05 -0500148 return per_cpu(x86_cpu_to_apicid, cpu);
149 return -1;
150}
151
152/*
Cliff Wickman18129242008-06-02 08:56:14 -0500153 * Free a software acknowledge hardware resource by clearing its Pending
154 * bit. This will return a reply to the sender.
155 * If the message has timed out, a reply has already been sent by the
156 * hardware but the resource has not been released. In that case our
157 * clear of the Timeout bit (as well) will free the resource. No reply will
158 * be sent (the hardware will only do one reply per message).
159 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500160static void reply_to_message(struct msg_desc *mdp, struct bau_control *bcp)
Cliff Wickman18129242008-06-02 08:56:14 -0500161{
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500162 unsigned long dw;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500163 struct bau_pq_entry *msg;
Cliff Wickman18129242008-06-02 08:56:14 -0500164
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500165 msg = mdp->msg;
166 if (!msg->canceled) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500167 dw = (msg->swack_vec << UV_SW_ACK_NPENDING) | msg->swack_vec;
168 write_mmr_sw_ack(dw);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500169 }
Cliff Wickman18129242008-06-02 08:56:14 -0500170 msg->replied_to = 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500171 msg->swack_vec = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500172}
173
174/*
175 * Process the receipt of a RETRY message
176 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500177static void bau_process_retry_msg(struct msg_desc *mdp,
178 struct bau_control *bcp)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500179{
180 int i;
181 int cancel_count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500182 unsigned long msg_res;
183 unsigned long mmr = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500184 struct bau_pq_entry *msg = mdp->msg;
185 struct bau_pq_entry *msg2;
186 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500187
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500188 stat->d_retries++;
189 /*
190 * cancel any message from msg+1 to the retry itself
191 */
192 for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500193 if (msg2 > mdp->queue_last)
194 msg2 = mdp->queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500195 if (msg2 == msg)
196 break;
197
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500198 /* same conditions for cancellation as do_reset */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500199 if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500200 (msg2->swack_vec) && ((msg2->swack_vec &
201 msg->swack_vec) == 0) &&
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500202 (msg2->sending_cpu == msg->sending_cpu) &&
203 (msg2->msg_type != MSG_NOOP)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500204 mmr = read_mmr_sw_ack();
205 msg_res = msg2->swack_vec;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500206 /*
207 * This is a message retry; clear the resources held
208 * by the previous message only if they timed out.
209 * If it has not timed out we have an unexpected
210 * situation to report.
211 */
Cliff Wickman39847e72010-06-02 16:22:02 -0500212 if (mmr & (msg_res << UV_SW_ACK_NPENDING)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500213 unsigned long mr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500214 /*
215 * is the resource timed out?
216 * make everyone ignore the cancelled message.
217 */
218 msg2->canceled = 1;
219 stat->d_canceled++;
220 cancel_count++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500221 mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
222 write_mmr_sw_ack(mr);
Cliff Wickman39847e72010-06-02 16:22:02 -0500223 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500224 }
225 }
226 if (!cancel_count)
227 stat->d_nocanceled++;
Cliff Wickman18129242008-06-02 08:56:14 -0500228}
229
230/*
231 * Do all the things a cpu should do for a TLB shootdown message.
232 * Other cpu's may come here at the same time for this message.
233 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500234static void bau_process_message(struct msg_desc *mdp,
235 struct bau_control *bcp)
Cliff Wickman18129242008-06-02 08:56:14 -0500236{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500237 short socket_ack_count = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500238 short *sp;
239 struct atomic_short *asp;
240 struct ptc_stats *stat = bcp->statp;
241 struct bau_pq_entry *msg = mdp->msg;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500242 struct bau_control *smaster = bcp->socket_master;
Cliff Wickman18129242008-06-02 08:56:14 -0500243
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500244 /*
245 * This must be a normal message, or retry of a normal message
246 */
Cliff Wickman18129242008-06-02 08:56:14 -0500247 if (msg->address == TLB_FLUSH_ALL) {
248 local_flush_tlb();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500249 stat->d_alltlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500250 } else {
251 __flush_tlb_one(msg->address);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500252 stat->d_onetlb++;
Cliff Wickman18129242008-06-02 08:56:14 -0500253 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500254 stat->d_requestee++;
Cliff Wickman18129242008-06-02 08:56:14 -0500255
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500256 /*
257 * One cpu on each uvhub has the additional job on a RETRY
258 * of releasing the resource held by the message that is
259 * being retried. That message is identified by sending
260 * cpu number.
261 */
262 if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500263 bau_process_retry_msg(mdp, bcp);
Cliff Wickman18129242008-06-02 08:56:14 -0500264
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500265 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500266 * This is a swack message, so we have to reply to it.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500267 * Count each responding cpu on the socket. This avoids
268 * pinging the count's cache line back and forth between
269 * the sockets.
270 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500271 sp = &smaster->socket_acknowledge_count[mdp->msg_slot];
272 asp = (struct atomic_short *)sp;
273 socket_ack_count = atom_asr(1, asp);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500274 if (socket_ack_count == bcp->cpus_in_socket) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500275 int msg_ack_count;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500276 /*
277 * Both sockets dump their completed count total into
278 * the message's count.
279 */
280 smaster->socket_acknowledge_count[mdp->msg_slot] = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500281 asp = (struct atomic_short *)&msg->acknowledge_count;
282 msg_ack_count = atom_asr(socket_ack_count, asp);
Ingo Molnardc163a42008-06-18 14:15:43 +0200283
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500284 if (msg_ack_count == bcp->cpus_in_uvhub) {
285 /*
286 * All cpus in uvhub saw it; reply
287 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500288 reply_to_message(mdp, bcp);
Ingo Molnardc163a42008-06-18 14:15:43 +0200289 }
290 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500291
292 return;
Cliff Wickman18129242008-06-02 08:56:14 -0500293}
294
295/*
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500296 * Determine the first cpu on a pnode.
Cliff Wickman18129242008-06-02 08:56:14 -0500297 */
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500298static int pnode_to_first_cpu(int pnode, struct bau_control *smaster)
Cliff Wickman18129242008-06-02 08:56:14 -0500299{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500300 int cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500301 struct hub_and_pnode *hpp;
302
303 for_each_present_cpu(cpu) {
304 hpp = &smaster->thp[cpu];
305 if (pnode == hpp->pnode)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500306 return cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500307 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500308 return -1;
Cliff Wickman18129242008-06-02 08:56:14 -0500309}
310
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500311/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500312 * Last resort when we get a large number of destination timeouts is
313 * to clear resources held by a given cpu.
314 * Do this with IPI so that all messages in the BAU message queue
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500315 * can be identified by their nonzero swack_vec field.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500316 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500317 * This is entered for a single cpu on the uvhub.
318 * The sender want's this uvhub to free a specific message's
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500319 * swack resources.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500320 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500321static void do_reset(void *ptr)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500322{
323 int i;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500324 struct bau_control *bcp = &per_cpu(bau_control, smp_processor_id());
325 struct reset_args *rap = (struct reset_args *)ptr;
326 struct bau_pq_entry *msg;
327 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500328
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500329 stat->d_resets++;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500330 /*
331 * We're looking for the given sender, and
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500332 * will free its swack resource.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500333 * If all cpu's finally responded after the timeout, its
334 * message 'replied_to' was set.
335 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500336 for (msg = bcp->queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
337 unsigned long msg_res;
338 /* do_reset: same conditions for cancellation as
339 bau_process_retry_msg() */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500340 if ((msg->replied_to == 0) &&
341 (msg->canceled == 0) &&
342 (msg->sending_cpu == rap->sender) &&
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500343 (msg->swack_vec) &&
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500344 (msg->msg_type != MSG_NOOP)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500345 unsigned long mmr;
346 unsigned long mr;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500347 /*
348 * make everyone else ignore this message
349 */
350 msg->canceled = 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500351 /*
352 * only reset the resource if it is still pending
353 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500354 mmr = read_mmr_sw_ack();
355 msg_res = msg->swack_vec;
356 mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500357 if (mmr & msg_res) {
358 stat->d_rcanceled++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500359 write_mmr_sw_ack(mr);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500360 }
361 }
362 }
363 return;
364}
365
366/*
367 * Use IPI to get all target uvhubs to release resources held by
368 * a given sending cpu number.
369 */
cpw@sgi.coma456eaa2011-06-21 07:21:30 -0500370static void reset_with_ipi(struct pnmask *distribution, struct bau_control *bcp)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500371{
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500372 int pnode;
373 int apnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500374 int maskbits;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500375 int sender = bcp->cpu;
cpw@sgi.com442d3922011-06-21 07:21:31 -0500376 cpumask_t *mask = bcp->uvhub_master->cpumask;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500377 struct bau_control *smaster = bcp->socket_master;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500378 struct reset_args reset_args;
379
380 reset_args.sender = sender;
cpw@sgi.com442d3922011-06-21 07:21:31 -0500381 cpus_clear(*mask);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500382 /* find a single cpu for each uvhub in this distribution mask */
cpw@sgi.coma456eaa2011-06-21 07:21:30 -0500383 maskbits = sizeof(struct pnmask) * BITSPERBYTE;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500384 /* each bit is a pnode relative to the partition base pnode */
385 for (pnode = 0; pnode < maskbits; pnode++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500386 int cpu;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500387 if (!bau_uvhub_isset(pnode, distribution))
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500388 continue;
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500389 apnode = pnode + bcp->partition_base_pnode;
390 cpu = pnode_to_first_cpu(apnode, smaster);
cpw@sgi.com442d3922011-06-21 07:21:31 -0500391 cpu_set(cpu, *mask);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500392 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500393
394 /* IPI all cpus; preemption is already disabled */
cpw@sgi.com442d3922011-06-21 07:21:31 -0500395 smp_call_function_many(mask, do_reset, (void *)&reset_args, 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500396 return;
397}
398
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500399static inline unsigned long cycles_2_us(unsigned long long cyc)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500400{
401 unsigned long long ns;
402 unsigned long us;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500403 int cpu = smp_processor_id();
404
405 ns = (cyc * per_cpu(cyc2ns, cpu)) >> CYC2NS_SCALE_FACTOR;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500406 us = ns / 1000;
407 return us;
408}
409
410/*
411 * wait for all cpus on this hub to finish their sends and go quiet
412 * leaves uvhub_quiesce set so that no new broadcasts are started by
413 * bau_flush_send_and_wait()
414 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500415static inline void quiesce_local_uvhub(struct bau_control *hmaster)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500416{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500417 atom_asr(1, (struct atomic_short *)&hmaster->uvhub_quiesce);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500418}
419
420/*
421 * mark this quiet-requestor as done
422 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500423static inline void end_uvhub_quiesce(struct bau_control *hmaster)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500424{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500425 atom_asr(-1, (struct atomic_short *)&hmaster->uvhub_quiesce);
426}
427
428static unsigned long uv1_read_status(unsigned long mmr_offset, int right_shift)
429{
430 unsigned long descriptor_status;
431
432 descriptor_status = uv_read_local_mmr(mmr_offset);
433 descriptor_status >>= right_shift;
434 descriptor_status &= UV_ACT_STATUS_MASK;
435 return descriptor_status;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500436}
437
438/*
439 * Wait for completion of a broadcast software ack message
440 * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500441 */
Jack Steiner2a919592011-05-11 12:50:28 -0500442static int uv1_wait_completion(struct bau_desc *bau_desc,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500443 unsigned long mmr_offset, int right_shift,
444 struct bau_control *bcp, long try)
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500445{
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500446 unsigned long descriptor_status;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500447 cycles_t ttm;
Cliff Wickman712157a2010-06-02 16:22:02 -0500448 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500449
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500450 descriptor_status = uv1_read_status(mmr_offset, right_shift);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500451 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500452 while ((descriptor_status != DS_IDLE)) {
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500453 /*
Jack Steiner2a919592011-05-11 12:50:28 -0500454 * Our software ack messages may be blocked because
455 * there are no swack resources available. As long
456 * as none of them has timed out hardware will NACK
457 * our message and its state will stay IDLE.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500458 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500459 if (descriptor_status == DS_SOURCE_TIMEOUT) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500460 stat->s_stimeout++;
461 return FLUSH_GIVEUP;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500462 } else if (descriptor_status == DS_DESTINATION_TIMEOUT) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500463 stat->s_dtimeout++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500464 ttm = get_cycles();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500465
466 /*
467 * Our retries may be blocked by all destination
468 * swack resources being consumed, and a timeout
469 * pending. In that case hardware returns the
470 * ERROR that looks like a destination timeout.
471 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500472 if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500473 bcp->conseccompletes = 0;
474 return FLUSH_RETRY_PLUGGED;
475 }
476
477 bcp->conseccompletes = 0;
478 return FLUSH_RETRY_TIMEOUT;
479 } else {
480 /*
481 * descriptor_status is still BUSY
482 */
483 cpu_relax();
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500484 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500485 descriptor_status = uv1_read_status(mmr_offset, right_shift);
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500486 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500487 bcp->conseccompletes++;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500488 return FLUSH_COMPLETE;
489}
490
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500491/*
492 * UV2 has an extra bit of status in the ACTIVATION_STATUS_2 register.
493 */
494static unsigned long uv2_read_status(unsigned long offset, int rshft, int cpu)
Jack Steiner2a919592011-05-11 12:50:28 -0500495{
496 unsigned long descriptor_status;
497 unsigned long descriptor_status2;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500498
499 descriptor_status = ((read_lmmr(offset) >> rshft) & UV_ACT_STATUS_MASK);
500 descriptor_status2 = (read_mmr_uv2_status() >> cpu) & 0x1UL;
501 descriptor_status = (descriptor_status << 1) | descriptor_status2;
502 return descriptor_status;
503}
504
505static int uv2_wait_completion(struct bau_desc *bau_desc,
506 unsigned long mmr_offset, int right_shift,
507 struct bau_control *bcp, long try)
508{
509 unsigned long descriptor_stat;
510 cycles_t ttm;
511 int cpu = bcp->uvhub_cpu;
Jack Steiner2a919592011-05-11 12:50:28 -0500512 struct ptc_stats *stat = bcp->statp;
513
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500514 descriptor_stat = uv2_read_status(mmr_offset, right_shift, cpu);
515
Jack Steiner2a919592011-05-11 12:50:28 -0500516 /* spin on the status MMR, waiting for it to go idle */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500517 while (descriptor_stat != UV2H_DESC_IDLE) {
Jack Steiner2a919592011-05-11 12:50:28 -0500518 /*
519 * Our software ack messages may be blocked because
520 * there are no swack resources available. As long
521 * as none of them has timed out hardware will NACK
522 * our message and its state will stay IDLE.
523 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500524 if ((descriptor_stat == UV2H_DESC_SOURCE_TIMEOUT) ||
525 (descriptor_stat == UV2H_DESC_DEST_STRONG_NACK) ||
526 (descriptor_stat == UV2H_DESC_DEST_PUT_ERR)) {
Jack Steiner2a919592011-05-11 12:50:28 -0500527 stat->s_stimeout++;
528 return FLUSH_GIVEUP;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500529 } else if (descriptor_stat == UV2H_DESC_DEST_TIMEOUT) {
Jack Steiner2a919592011-05-11 12:50:28 -0500530 stat->s_dtimeout++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500531 ttm = get_cycles();
Jack Steiner2a919592011-05-11 12:50:28 -0500532 /*
533 * Our retries may be blocked by all destination
534 * swack resources being consumed, and a timeout
535 * pending. In that case hardware returns the
536 * ERROR that looks like a destination timeout.
537 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500538 if (cycles_2_us(ttm - bcp->send_message) < timeout_us) {
Jack Steiner2a919592011-05-11 12:50:28 -0500539 bcp->conseccompletes = 0;
540 return FLUSH_RETRY_PLUGGED;
541 }
Jack Steiner2a919592011-05-11 12:50:28 -0500542 bcp->conseccompletes = 0;
543 return FLUSH_RETRY_TIMEOUT;
544 } else {
545 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500546 * descriptor_stat is still BUSY
Jack Steiner2a919592011-05-11 12:50:28 -0500547 */
548 cpu_relax();
549 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500550 descriptor_stat = uv2_read_status(mmr_offset, right_shift, cpu);
Jack Steiner2a919592011-05-11 12:50:28 -0500551 }
552 bcp->conseccompletes++;
553 return FLUSH_COMPLETE;
554}
555
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500556/*
557 * There are 2 status registers; each and array[32] of 2 bits. Set up for
558 * which register to read and position in that register based on cpu in
559 * current hub.
560 */
561static int wait_completion(struct bau_desc *bau_desc,
562 struct bau_control *bcp, long try)
Jack Steiner2a919592011-05-11 12:50:28 -0500563{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500564 int right_shift;
565 unsigned long mmr_offset;
566 int cpu = bcp->uvhub_cpu;
567
568 if (cpu < UV_CPUS_PER_AS) {
569 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
570 right_shift = cpu * UV_ACT_STATUS_SIZE;
571 } else {
572 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
573 right_shift = ((cpu - UV_CPUS_PER_AS) * UV_ACT_STATUS_SIZE);
574 }
575
Jack Steiner2a919592011-05-11 12:50:28 -0500576 if (is_uv1_hub())
577 return uv1_wait_completion(bau_desc, mmr_offset, right_shift,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500578 bcp, try);
Jack Steiner2a919592011-05-11 12:50:28 -0500579 else
580 return uv2_wait_completion(bau_desc, mmr_offset, right_shift,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500581 bcp, try);
Jack Steiner2a919592011-05-11 12:50:28 -0500582}
583
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500584static inline cycles_t sec_2_cycles(unsigned long sec)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500585{
586 unsigned long ns;
587 cycles_t cyc;
588
589 ns = sec * 1000000000;
590 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
591 return cyc;
592}
593
594/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500595 * Our retries are blocked by all destination sw ack resources being
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500596 * in use, and a timeout is pending. In that case hardware immediately
597 * returns the ERROR that looks like a destination timeout.
598 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500599static void destination_plugged(struct bau_desc *bau_desc,
600 struct bau_control *bcp,
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500601 struct bau_control *hmaster, struct ptc_stats *stat)
602{
603 udelay(bcp->plugged_delay);
604 bcp->plugged_tries++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500605
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500606 if (bcp->plugged_tries >= bcp->plugsb4reset) {
607 bcp->plugged_tries = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500608
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500609 quiesce_local_uvhub(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500610
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500611 spin_lock(&hmaster->queue_lock);
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500612 reset_with_ipi(&bau_desc->distribution, bcp);
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500613 spin_unlock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500614
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500615 end_uvhub_quiesce(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500616
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500617 bcp->ipi_attempts++;
618 stat->s_resets_plug++;
619 }
620}
621
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500622static void destination_timeout(struct bau_desc *bau_desc,
623 struct bau_control *bcp, struct bau_control *hmaster,
624 struct ptc_stats *stat)
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500625{
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500626 hmaster->max_concurr = 1;
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500627 bcp->timeout_tries++;
628 if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
629 bcp->timeout_tries = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500630
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500631 quiesce_local_uvhub(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500632
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500633 spin_lock(&hmaster->queue_lock);
cpw@sgi.com485f07d2011-06-21 07:21:29 -0500634 reset_with_ipi(&bau_desc->distribution, bcp);
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500635 spin_unlock(&hmaster->queue_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500636
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500637 end_uvhub_quiesce(hmaster);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500638
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500639 bcp->ipi_attempts++;
640 stat->s_resets_timeout++;
641 }
642}
643
644/*
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500645 * Completions are taking a very long time due to a congested numalink
646 * network.
647 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500648static void disable_for_congestion(struct bau_control *bcp,
649 struct ptc_stats *stat)
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500650{
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500651 /* let only one cpu do this disabling */
652 spin_lock(&disable_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500653
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500654 if (!baudisabled && bcp->period_requests &&
655 ((bcp->period_time / bcp->period_requests) > congested_cycles)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500656 int tcpu;
657 struct bau_control *tbcp;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500658 /* it becomes this cpu's job to turn on the use of the
659 BAU again */
660 baudisabled = 1;
661 bcp->set_bau_off = 1;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500662 bcp->set_bau_on_time = get_cycles();
663 bcp->set_bau_on_time += sec_2_cycles(bcp->cong_period);
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500664 stat->s_bau_disabled++;
665 for_each_present_cpu(tcpu) {
666 tbcp = &per_cpu(bau_control, tcpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500667 tbcp->baudisabled = 1;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500668 }
669 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500670
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500671 spin_unlock(&disable_lock);
672}
673
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500674static void count_max_concurr(int stat, struct bau_control *bcp,
675 struct bau_control *hmaster)
676{
677 bcp->plugged_tries = 0;
678 bcp->timeout_tries = 0;
679 if (stat != FLUSH_COMPLETE)
680 return;
681 if (bcp->conseccompletes <= bcp->complete_threshold)
682 return;
683 if (hmaster->max_concurr >= hmaster->max_concurr_const)
684 return;
685 hmaster->max_concurr++;
686}
687
688static void record_send_stats(cycles_t time1, cycles_t time2,
689 struct bau_control *bcp, struct ptc_stats *stat,
690 int completion_status, int try)
691{
692 cycles_t elapsed;
693
694 if (time2 > time1) {
695 elapsed = time2 - time1;
696 stat->s_time += elapsed;
697
698 if ((completion_status == FLUSH_COMPLETE) && (try == 1)) {
699 bcp->period_requests++;
700 bcp->period_time += elapsed;
701 if ((elapsed > congested_cycles) &&
702 (bcp->period_requests > bcp->cong_reps))
703 disable_for_congestion(bcp, stat);
704 }
705 } else
706 stat->s_requestor--;
707
708 if (completion_status == FLUSH_COMPLETE && try > 1)
709 stat->s_retriesok++;
710 else if (completion_status == FLUSH_GIVEUP)
711 stat->s_giveup++;
712}
713
714/*
715 * Because of a uv1 hardware bug only a limited number of concurrent
716 * requests can be made.
717 */
718static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
719{
720 spinlock_t *lock = &hmaster->uvhub_lock;
721 atomic_t *v;
722
723 v = &hmaster->active_descriptor_count;
724 if (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr)) {
725 stat->s_throttles++;
726 do {
727 cpu_relax();
728 } while (!atomic_inc_unless_ge(lock, v, hmaster->max_concurr));
729 }
730}
731
732/*
733 * Handle the completion status of a message send.
734 */
735static void handle_cmplt(int completion_status, struct bau_desc *bau_desc,
736 struct bau_control *bcp, struct bau_control *hmaster,
737 struct ptc_stats *stat)
738{
739 if (completion_status == FLUSH_RETRY_PLUGGED)
740 destination_plugged(bau_desc, bcp, hmaster, stat);
741 else if (completion_status == FLUSH_RETRY_TIMEOUT)
742 destination_timeout(bau_desc, bcp, hmaster, stat);
743}
744
745/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500746 * Send a broadcast and wait for it to complete.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500747 *
Cliff Wickmanf6d8a562010-06-02 16:22:02 -0500748 * The flush_mask contains the cpus the broadcast is to be sent to including
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500749 * cpus that are on the local uvhub.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500750 *
Cliff Wickman450a0072010-06-02 16:22:02 -0500751 * Returns 0 if all flushing represented in the mask was done.
752 * Returns 1 if it gives up entirely and the original cpu mask is to be
753 * returned to the kernel.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500754 */
Cliff Wickman450a0072010-06-02 16:22:02 -0500755int uv_flush_send_and_wait(struct bau_desc *bau_desc,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500756 struct cpumask *flush_mask, struct bau_control *bcp)
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500757{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500758 int seq_number = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500759 int completion_stat = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500760 long try = 0;
Ingo Molnarb4c286e2008-06-18 14:28:19 +0200761 unsigned long index;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500762 cycles_t time1;
763 cycles_t time2;
Cliff Wickman712157a2010-06-02 16:22:02 -0500764 struct ptc_stats *stat = bcp->statp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500765 struct bau_control *hmaster = bcp->uvhub_master;
766
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500767 if (is_uv1_hub())
768 uv1_throttle(hmaster, stat);
769
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500770 while (hmaster->uvhub_quiesce)
771 cpu_relax();
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500772
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500773 time1 = get_cycles();
774 do {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500775 if (try == 0) {
Cliff Wickman7fba1bc2010-06-02 16:22:02 -0500776 bau_desc->header.msg_type = MSG_REGULAR;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500777 seq_number = bcp->message_number++;
778 } else {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500779 bau_desc->header.msg_type = MSG_RETRY;
780 stat->s_retry_messages++;
781 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500782
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500783 bau_desc->header.sequence = seq_number;
784 index = (1UL << AS_PUSH_SHIFT) | bcp->uvhub_cpu;
785 bcp->send_message = get_cycles();
786
787 write_mmr_activation(index);
788
789 try++;
790 completion_stat = wait_completion(bau_desc, bcp, try);
791
792 handle_cmplt(completion_stat, bau_desc, bcp, hmaster, stat);
793
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500794 if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500795 bcp->ipi_attempts = 0;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500796 completion_stat = FLUSH_GIVEUP;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500797 break;
798 }
799 cpu_relax();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500800 } while ((completion_stat == FLUSH_RETRY_PLUGGED) ||
801 (completion_stat == FLUSH_RETRY_TIMEOUT));
802
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500803 time2 = get_cycles();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500804
805 count_max_concurr(completion_stat, bcp, hmaster);
806
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500807 while (hmaster->uvhub_quiesce)
808 cpu_relax();
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500809
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500810 atomic_dec(&hmaster->active_descriptor_count);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500811
812 record_send_stats(time1, time2, bcp, stat, completion_stat, try);
813
814 if (completion_stat == FLUSH_GIVEUP)
Cliff Wickman450a0072010-06-02 16:22:02 -0500815 return 1;
Cliff Wickman450a0072010-06-02 16:22:02 -0500816 return 0;
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500817}
818
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500819/*
820 * The BAU is disabled. When the disabled time period has expired, the cpu
821 * that disabled it must re-enable it.
822 * Return 0 if it is re-enabled for all cpus.
823 */
824static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
825{
826 int tcpu;
827 struct bau_control *tbcp;
828
829 if (bcp->set_bau_off) {
830 if (get_cycles() >= bcp->set_bau_on_time) {
831 stat->s_bau_reenabled++;
832 baudisabled = 0;
833 for_each_present_cpu(tcpu) {
834 tbcp = &per_cpu(bau_control, tcpu);
835 tbcp->baudisabled = 0;
836 tbcp->period_requests = 0;
837 tbcp->period_time = 0;
838 }
839 return 0;
840 }
841 }
842 return -1;
843}
844
845static void record_send_statistics(struct ptc_stats *stat, int locals, int hubs,
846 int remotes, struct bau_desc *bau_desc)
847{
848 stat->s_requestor++;
849 stat->s_ntargcpu += remotes + locals;
850 stat->s_ntargremotes += remotes;
851 stat->s_ntarglocals += locals;
852
853 /* uvhub statistics */
854 hubs = bau_uvhub_weight(&bau_desc->distribution);
855 if (locals) {
856 stat->s_ntarglocaluvhub++;
857 stat->s_ntargremoteuvhub += (hubs - 1);
858 } else
859 stat->s_ntargremoteuvhub += hubs;
860
861 stat->s_ntarguvhub += hubs;
862
863 if (hubs >= 16)
864 stat->s_ntarguvhub16++;
865 else if (hubs >= 8)
866 stat->s_ntarguvhub8++;
867 else if (hubs >= 4)
868 stat->s_ntarguvhub4++;
869 else if (hubs >= 2)
870 stat->s_ntarguvhub2++;
871 else
872 stat->s_ntarguvhub1++;
873}
874
875/*
876 * Translate a cpu mask to the uvhub distribution mask in the BAU
877 * activation descriptor.
878 */
879static int set_distrib_bits(struct cpumask *flush_mask, struct bau_control *bcp,
880 struct bau_desc *bau_desc, int *localsp, int *remotesp)
881{
882 int cpu;
883 int pnode;
884 int cnt = 0;
885 struct hub_and_pnode *hpp;
886
887 for_each_cpu(cpu, flush_mask) {
888 /*
889 * The distribution vector is a bit map of pnodes, relative
890 * to the partition base pnode (and the partition base nasid
891 * in the header).
892 * Translate cpu to pnode and hub using a local memory array.
893 */
894 hpp = &bcp->socket_master->thp[cpu];
895 pnode = hpp->pnode - bcp->partition_base_pnode;
896 bau_uvhub_set(pnode, &bau_desc->distribution);
897 cnt++;
898 if (hpp->uvhub == bcp->uvhub)
899 (*localsp)++;
900 else
901 (*remotesp)++;
902 }
903 if (!cnt)
904 return 1;
905 return 0;
906}
907
908/*
909 * globally purge translation cache of a virtual address or all TLB's
Tejun Heobdbcdd42009-01-21 17:26:06 +0900910 * @cpumask: mask of all cpu's in which the address is to be removed
Cliff Wickman18129242008-06-02 08:56:14 -0500911 * @mm: mm_struct containing virtual address range
912 * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
Tejun Heobdbcdd42009-01-21 17:26:06 +0900913 * @cpu: the current cpu
Cliff Wickman18129242008-06-02 08:56:14 -0500914 *
915 * This is the entry point for initiating any UV global TLB shootdown.
916 *
917 * Purges the translation caches of all specified processors of the given
918 * virtual address, or purges all TLB's on specified processors.
919 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900920 * The caller has derived the cpumask from the mm_struct. This function
921 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
Cliff Wickman18129242008-06-02 08:56:14 -0500922 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500923 * The cpumask is converted into a uvhubmask of the uvhubs containing
924 * those cpus.
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500925 *
Tejun Heobdbcdd42009-01-21 17:26:06 +0900926 * Note that this function should be called with preemption disabled.
927 *
928 * Returns NULL if all remote flushing was done.
929 * Returns pointer to cpumask if some remote flushing remains to be
930 * done. The returned pointer is valid till preemption is re-enabled.
Cliff Wickman18129242008-06-02 08:56:14 -0500931 */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900932const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500933 struct mm_struct *mm, unsigned long va,
934 unsigned int cpu)
Cliff Wickman18129242008-06-02 08:56:14 -0500935{
Cliff Wickmanb194b1202008-06-12 08:23:48 -0500936 int locals = 0;
Cliff Wickman450a0072010-06-02 16:22:02 -0500937 int remotes = 0;
938 int hubs = 0;
Ingo Molnardc163a42008-06-18 14:15:43 +0200939 struct bau_desc *bau_desc;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500940 struct cpumask *flush_mask;
941 struct ptc_stats *stat;
942 struct bau_control *bcp;
Cliff Wickman18129242008-06-02 08:56:14 -0500943
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500944 /* kernel was booted 'nobau' */
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500945 if (nobau)
946 return cpumask;
947
948 bcp = &per_cpu(bau_control, cpu);
Cliff Wickman712157a2010-06-02 16:22:02 -0500949 stat = bcp->statp;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500950
951 /* bau was disabled due to slow response */
952 if (bcp->baudisabled) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500953 if (check_enable(bcp, stat))
954 return cpumask;
Cliff Wickman50fb55a2010-06-02 16:22:02 -0500955 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -0500956
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500957 /*
958 * Each sending cpu has a per-cpu mask which it fills from the caller's
Cliff Wickman450a0072010-06-02 16:22:02 -0500959 * cpu mask. All cpus are converted to uvhubs and copied to the
960 * activation descriptor.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500961 */
962 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
Cliff Wickman450a0072010-06-02 16:22:02 -0500963 /* don't actually do a shootdown of the local cpu */
Tejun Heobdbcdd42009-01-21 17:26:06 +0900964 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500965
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500966 if (cpu_isset(cpu, *cpumask))
Cliff Wickman450a0072010-06-02 16:22:02 -0500967 stat->s_ntargself++;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900968
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500969 bau_desc = bcp->descriptor_base;
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500970 bau_desc += ITEMS_PER_DESC * bcp->uvhub_cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500971 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500972 if (set_distrib_bits(flush_mask, bcp, bau_desc, &locals, &remotes))
Cliff Wickman450a0072010-06-02 16:22:02 -0500973 return NULL;
Cliff Wickman450a0072010-06-02 16:22:02 -0500974
Cliff Wickmanf073cc82011-05-24 13:07:36 -0500975 record_send_statistics(stat, locals, hubs, remotes, bau_desc);
Cliff Wickman18129242008-06-02 08:56:14 -0500976
977 bau_desc->payload.address = va;
Tejun Heobdbcdd42009-01-21 17:26:06 +0900978 bau_desc->payload.sending_cpu = cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500979 /*
Cliff Wickman450a0072010-06-02 16:22:02 -0500980 * uv_flush_send_and_wait returns 0 if all cpu's were messaged,
981 * or 1 if it gave up and the original cpumask should be returned.
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500982 */
Cliff Wickman450a0072010-06-02 16:22:02 -0500983 if (!uv_flush_send_and_wait(bau_desc, flush_mask, bcp))
984 return NULL;
985 else
986 return cpumask;
Cliff Wickman18129242008-06-02 08:56:14 -0500987}
988
989/*
990 * The BAU message interrupt comes here. (registered by set_intr_gate)
991 * See entry_64.S
992 *
993 * We received a broadcast assist message.
994 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500995 * Interrupts are disabled; this interrupt could represent
Cliff Wickman18129242008-06-02 08:56:14 -0500996 * the receipt of several messages.
997 *
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -0500998 * All cores/threads on this hub get this interrupt.
999 * The last one to see it does the software ack.
Cliff Wickman18129242008-06-02 08:56:14 -05001000 * (the resource will not be freed until noninterruptable cpus see this
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001001 * interrupt; hardware may timeout the s/w ack and reply ERROR)
Cliff Wickman18129242008-06-02 08:56:14 -05001002 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001003void uv_bau_message_interrupt(struct pt_regs *regs)
Cliff Wickman18129242008-06-02 08:56:14 -05001004{
Cliff Wickman18129242008-06-02 08:56:14 -05001005 int count = 0;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001006 cycles_t time_start;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001007 struct bau_pq_entry *msg;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001008 struct bau_control *bcp;
1009 struct ptc_stats *stat;
1010 struct msg_desc msgdesc;
Cliff Wickman18129242008-06-02 08:56:14 -05001011
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001012 time_start = get_cycles();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001013
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001014 bcp = &per_cpu(bau_control, smp_processor_id());
Cliff Wickman712157a2010-06-02 16:22:02 -05001015 stat = bcp->statp;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001016
1017 msgdesc.queue_first = bcp->queue_first;
1018 msgdesc.queue_last = bcp->queue_last;
1019
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001020 msg = bcp->bau_msg_head;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001021 while (msg->swack_vec) {
Cliff Wickman18129242008-06-02 08:56:14 -05001022 count++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001023
1024 msgdesc.msg_slot = msg - msgdesc.queue_first;
1025 msgdesc.swack_slot = ffs(msg->swack_vec) - 1;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001026 msgdesc.msg = msg;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001027 bau_process_message(&msgdesc, bcp);
1028
Cliff Wickman18129242008-06-02 08:56:14 -05001029 msg++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001030 if (msg > msgdesc.queue_last)
1031 msg = msgdesc.queue_first;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001032 bcp->bau_msg_head = msg;
Cliff Wickman18129242008-06-02 08:56:14 -05001033 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001034 stat->d_time += (get_cycles() - time_start);
Cliff Wickman18129242008-06-02 08:56:14 -05001035 if (!count)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001036 stat->d_nomsg++;
Cliff Wickman18129242008-06-02 08:56:14 -05001037 else if (count > 1)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001038 stat->d_multmsg++;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001039
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001040 ack_APIC_irq();
Cliff Wickman18129242008-06-02 08:56:14 -05001041}
1042
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001043/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001044 * Each target uvhub (i.e. a uvhub that has cpu's) needs to have
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001045 * shootdown message timeouts enabled. The timeout does not cause
1046 * an interrupt, but causes an error message to be returned to
1047 * the sender.
1048 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001049static void __init enable_timeouts(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001050{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001051 int uvhub;
1052 int nuvhubs;
Cliff Wickman18129242008-06-02 08:56:14 -05001053 int pnode;
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001054 unsigned long mmr_image;
Cliff Wickman18129242008-06-02 08:56:14 -05001055
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001056 nuvhubs = uv_num_possible_blades();
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001057
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001058 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
1059 if (!uv_blade_nr_possible_cpus(uvhub))
Cliff Wickman18129242008-06-02 08:56:14 -05001060 continue;
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001061
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001062 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001063 mmr_image = read_mmr_misc_control(pnode);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001064 /*
1065 * Set the timeout period and then lock it in, in three
1066 * steps; captures and locks in the period.
1067 *
1068 * To program the period, the SOFT_ACK_MODE must be off.
1069 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001070 mmr_image &= ~(1L << SOFTACK_MSHIFT);
1071 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001072 /*
1073 * Set the 4-bit period.
1074 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001075 mmr_image &= ~((unsigned long)0xf << SOFTACK_PSHIFT);
1076 mmr_image |= (SOFTACK_TIMEOUT_PERIOD << SOFTACK_PSHIFT);
1077 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001078 /*
Jack Steiner2a919592011-05-11 12:50:28 -05001079 * UV1:
Cliff Wickmanc4c46882009-04-03 08:34:32 -05001080 * Subsequent reversals of the timebase bit (3) cause an
1081 * immediate timeout of one or all INTD resources as
1082 * indicated in bits 2:0 (7 causes all of them to timeout).
1083 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001084 mmr_image |= (1L << SOFTACK_MSHIFT);
Jack Steiner2a919592011-05-11 12:50:28 -05001085 if (is_uv2_hub()) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001086 mmr_image |= (1L << UV2_LEG_SHFT);
1087 mmr_image |= (1L << UV2_EXT_SHFT);
Jack Steiner2a919592011-05-11 12:50:28 -05001088 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001089 write_mmr_misc_control(pnode, mmr_image);
Cliff Wickman18129242008-06-02 08:56:14 -05001090 }
Cliff Wickman18129242008-06-02 08:56:14 -05001091}
1092
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001093static void *ptc_seq_start(struct seq_file *file, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -05001094{
1095 if (*offset < num_possible_cpus())
1096 return offset;
1097 return NULL;
1098}
1099
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001100static void *ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
Cliff Wickman18129242008-06-02 08:56:14 -05001101{
1102 (*offset)++;
1103 if (*offset < num_possible_cpus())
1104 return offset;
1105 return NULL;
1106}
1107
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001108static void ptc_seq_stop(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001109{
1110}
1111
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001112static inline unsigned long long usec_2_cycles(unsigned long microsec)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001113{
1114 unsigned long ns;
1115 unsigned long long cyc;
1116
Cliff Wickman12a66112010-06-02 16:22:01 -05001117 ns = microsec * 1000;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001118 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
1119 return cyc;
1120}
1121
Cliff Wickman18129242008-06-02 08:56:14 -05001122/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001123 * Display the statistics thru /proc/sgi_uv/ptc_statistics
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001124 * 'data' points to the cpu number
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001125 * Note: see the descriptions in stat_description[].
Cliff Wickman18129242008-06-02 08:56:14 -05001126 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001127static int ptc_seq_show(struct seq_file *file, void *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001128{
1129 struct ptc_stats *stat;
1130 int cpu;
1131
1132 cpu = *(loff_t *)data;
Cliff Wickman18129242008-06-02 08:56:14 -05001133 if (!cpu) {
1134 seq_printf(file,
Cliff Wickman450a0072010-06-02 16:22:02 -05001135 "# cpu sent stime self locals remotes ncpus localhub ");
Cliff Wickman18129242008-06-02 08:56:14 -05001136 seq_printf(file,
Cliff Wickman450a0072010-06-02 16:22:02 -05001137 "remotehub numuvhubs numuvhubs16 numuvhubs8 ");
1138 seq_printf(file,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001139 "numuvhubs4 numuvhubs2 numuvhubs1 dto retries rok ");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001140 seq_printf(file,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001141 "resetp resett giveup sto bz throt swack recv rtime ");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001142 seq_printf(file,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001143 "all one mult none retry canc nocan reset rcan ");
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001144 seq_printf(file,
1145 "disable enable\n");
Cliff Wickman18129242008-06-02 08:56:14 -05001146 }
1147 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
1148 stat = &per_cpu(ptcstats, cpu);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001149 /* source side statistics */
1150 seq_printf(file,
1151 "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
1152 cpu, stat->s_requestor, cycles_2_us(stat->s_time),
Cliff Wickman450a0072010-06-02 16:22:02 -05001153 stat->s_ntargself, stat->s_ntarglocals,
1154 stat->s_ntargremotes, stat->s_ntargcpu,
1155 stat->s_ntarglocaluvhub, stat->s_ntargremoteuvhub,
1156 stat->s_ntarguvhub, stat->s_ntarguvhub16);
1157 seq_printf(file, "%ld %ld %ld %ld %ld ",
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001158 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
1159 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
Cliff Wickman450a0072010-06-02 16:22:02 -05001160 stat->s_dtimeout);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001161 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
1162 stat->s_retry_messages, stat->s_retriesok,
1163 stat->s_resets_plug, stat->s_resets_timeout,
1164 stat->s_giveup, stat->s_stimeout,
1165 stat->s_busy, stat->s_throttles);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001166
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001167 /* destination side statistics */
1168 seq_printf(file,
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001169 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001170 read_gmmr_sw_ack(uv_cpu_to_pnode(cpu)),
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001171 stat->d_requestee, cycles_2_us(stat->d_time),
1172 stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
1173 stat->d_nomsg, stat->d_retries, stat->d_canceled,
1174 stat->d_nocanceled, stat->d_resets,
1175 stat->d_rcanceled);
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001176 seq_printf(file, "%ld %ld\n",
1177 stat->s_bau_disabled, stat->s_bau_reenabled);
Cliff Wickman18129242008-06-02 08:56:14 -05001178 }
Cliff Wickman18129242008-06-02 08:56:14 -05001179 return 0;
1180}
1181
1182/*
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001183 * Display the tunables thru debugfs
1184 */
1185static ssize_t tunables_read(struct file *file, char __user *userbuf,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001186 size_t count, loff_t *ppos)
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001187{
Dan Carpenterb365a852010-09-29 10:41:05 +02001188 char *buf;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001189 int ret;
1190
Dan Carpenterb365a852010-09-29 10:41:05 +02001191 buf = kasprintf(GFP_KERNEL, "%s %s %s\n%d %d %d %d %d %d %d %d %d\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001192 "max_concur plugged_delay plugsb4reset",
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001193 "timeoutsb4reset ipi_reset_limit complete_threshold",
1194 "congested_response_us congested_reps congested_period",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001195 max_concurr, plugged_delay, plugsb4reset,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001196 timeoutsb4reset, ipi_reset_limit, complete_threshold,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001197 congested_respns_us, congested_reps, congested_period);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001198
Dan Carpenterb365a852010-09-29 10:41:05 +02001199 if (!buf)
1200 return -ENOMEM;
1201
1202 ret = simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
1203 kfree(buf);
1204 return ret;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001205}
1206
1207/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001208 * handle a write to /proc/sgi_uv/ptc_statistics
1209 * -1: reset the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001210 * 0: display meaning of the statistics
Cliff Wickman18129242008-06-02 08:56:14 -05001211 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001212static ssize_t ptc_proc_write(struct file *file, const char __user *user,
1213 size_t count, loff_t *data)
Cliff Wickman18129242008-06-02 08:56:14 -05001214{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001215 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001216 int i;
1217 int elements;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001218 long input_arg;
Cliff Wickman18129242008-06-02 08:56:14 -05001219 char optstr[64];
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001220 struct ptc_stats *stat;
Cliff Wickman18129242008-06-02 08:56:14 -05001221
Cliff Wickmane7eb8722008-06-23 08:32:25 -05001222 if (count == 0 || count > sizeof(optstr))
Cliff Wickmancef53272008-06-19 11:16:24 -05001223 return -EINVAL;
Cliff Wickman18129242008-06-02 08:56:14 -05001224 if (copy_from_user(optstr, user, count))
1225 return -EFAULT;
1226 optstr[count - 1] = '\0';
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001227
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001228 if (strict_strtol(optstr, 10, &input_arg) < 0) {
Cliff Wickman18129242008-06-02 08:56:14 -05001229 printk(KERN_DEBUG "%s is invalid\n", optstr);
1230 return -EINVAL;
1231 }
1232
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001233 if (input_arg == 0) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001234 elements = sizeof(stat_description)/sizeof(*stat_description);
Cliff Wickman18129242008-06-02 08:56:14 -05001235 printk(KERN_DEBUG "# cpu: cpu number\n");
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001236 printk(KERN_DEBUG "Sender statistics:\n");
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001237 for (i = 0; i < elements; i++)
1238 printk(KERN_DEBUG "%s\n", stat_description[i]);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001239 } else if (input_arg == -1) {
1240 for_each_present_cpu(cpu) {
1241 stat = &per_cpu(ptcstats, cpu);
1242 memset(stat, 0, sizeof(struct ptc_stats));
1243 }
Cliff Wickman18129242008-06-02 08:56:14 -05001244 }
1245
1246 return count;
1247}
1248
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001249static int local_atoi(const char *name)
1250{
1251 int val = 0;
1252
1253 for (;; name++) {
1254 switch (*name) {
1255 case '0' ... '9':
1256 val = 10*val+(*name-'0');
1257 break;
1258 default:
1259 return val;
1260 }
1261 }
1262}
1263
1264/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001265 * Parse the values written to /sys/kernel/debug/sgi_uv/bau_tunables.
1266 * Zero values reset them to defaults.
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001267 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001268static int parse_tunables_write(struct bau_control *bcp, char *instr,
1269 int count)
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001270{
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001271 char *p;
1272 char *q;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001273 int cnt = 0;
1274 int val;
1275 int e = sizeof(tunables) / sizeof(*tunables);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001276
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001277 p = instr + strspn(instr, WHITESPACE);
1278 q = p;
1279 for (; *p; p = q + strspn(q, WHITESPACE)) {
1280 q = p + strcspn(p, WHITESPACE);
1281 cnt++;
1282 if (q == p)
1283 break;
1284 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001285 if (cnt != e) {
1286 printk(KERN_INFO "bau tunable error: should be %d values\n", e);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001287 return -EINVAL;
1288 }
1289
1290 p = instr + strspn(instr, WHITESPACE);
1291 q = p;
1292 for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
1293 q = p + strcspn(p, WHITESPACE);
1294 val = local_atoi(p);
1295 switch (cnt) {
1296 case 0:
1297 if (val == 0) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001298 max_concurr = MAX_BAU_CONCURRENT;
1299 max_concurr_const = MAX_BAU_CONCURRENT;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001300 continue;
1301 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001302 if (val < 1 || val > bcp->cpus_in_uvhub) {
1303 printk(KERN_DEBUG
1304 "Error: BAU max concurrent %d is invalid\n",
1305 val);
1306 return -EINVAL;
1307 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001308 max_concurr = val;
1309 max_concurr_const = val;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001310 continue;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001311 default:
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001312 if (val == 0)
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001313 *tunables[cnt].tunp = tunables[cnt].deflt;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001314 else
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001315 *tunables[cnt].tunp = val;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001316 continue;
1317 }
1318 if (q == p)
1319 break;
1320 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001321 return 0;
1322}
1323
1324/*
1325 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
1326 */
1327static ssize_t tunables_write(struct file *file, const char __user *user,
1328 size_t count, loff_t *data)
1329{
1330 int cpu;
1331 int ret;
1332 char instr[100];
1333 struct bau_control *bcp;
1334
1335 if (count == 0 || count > sizeof(instr)-1)
1336 return -EINVAL;
1337 if (copy_from_user(instr, user, count))
1338 return -EFAULT;
1339
1340 instr[count] = '\0';
1341
cpw@sgi.com00b30cf2011-06-21 07:21:26 -05001342 cpu = get_cpu();
1343 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001344 ret = parse_tunables_write(bcp, instr, count);
cpw@sgi.com00b30cf2011-06-21 07:21:26 -05001345 put_cpu();
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001346 if (ret)
1347 return ret;
1348
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001349 for_each_present_cpu(cpu) {
1350 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001351 bcp->max_concurr = max_concurr;
1352 bcp->max_concurr_const = max_concurr;
1353 bcp->plugged_delay = plugged_delay;
1354 bcp->plugsb4reset = plugsb4reset;
1355 bcp->timeoutsb4reset = timeoutsb4reset;
1356 bcp->ipi_reset_limit = ipi_reset_limit;
1357 bcp->complete_threshold = complete_threshold;
1358 bcp->cong_response_us = congested_respns_us;
1359 bcp->cong_reps = congested_reps;
1360 bcp->cong_period = congested_period;
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001361 }
1362 return count;
1363}
1364
Cliff Wickman18129242008-06-02 08:56:14 -05001365static const struct seq_operations uv_ptc_seq_ops = {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001366 .start = ptc_seq_start,
1367 .next = ptc_seq_next,
1368 .stop = ptc_seq_stop,
1369 .show = ptc_seq_show
Cliff Wickman18129242008-06-02 08:56:14 -05001370};
1371
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001372static int ptc_proc_open(struct inode *inode, struct file *file)
Cliff Wickman18129242008-06-02 08:56:14 -05001373{
1374 return seq_open(file, &uv_ptc_seq_ops);
1375}
1376
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001377static int tunables_open(struct inode *inode, struct file *file)
1378{
1379 return 0;
1380}
1381
Cliff Wickman18129242008-06-02 08:56:14 -05001382static const struct file_operations proc_uv_ptc_operations = {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001383 .open = ptc_proc_open,
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001384 .read = seq_read,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001385 .write = ptc_proc_write,
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001386 .llseek = seq_lseek,
1387 .release = seq_release,
Cliff Wickman18129242008-06-02 08:56:14 -05001388};
1389
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001390static const struct file_operations tunables_fops = {
1391 .open = tunables_open,
1392 .read = tunables_read,
1393 .write = tunables_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001394 .llseek = default_llseek,
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001395};
1396
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001397static int __init uv_ptc_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001398{
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001399 struct proc_dir_entry *proc_uv_ptc;
Cliff Wickman18129242008-06-02 08:56:14 -05001400
1401 if (!is_uv_system())
1402 return 0;
1403
Alexey Dobriyan10f02d112009-08-23 23:17:27 +04001404 proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
1405 &proc_uv_ptc_operations);
Cliff Wickman18129242008-06-02 08:56:14 -05001406 if (!proc_uv_ptc) {
1407 printk(KERN_ERR "unable to create %s proc entry\n",
1408 UV_PTC_BASENAME);
1409 return -EINVAL;
1410 }
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001411
1412 tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
1413 if (!tunables_dir) {
1414 printk(KERN_ERR "unable to create debugfs directory %s\n",
1415 UV_BAU_TUNABLES_DIR);
1416 return -EINVAL;
1417 }
1418 tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001419 tunables_dir, NULL, &tunables_fops);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001420 if (!tunables_file) {
1421 printk(KERN_ERR "unable to create debugfs file %s\n",
1422 UV_BAU_TUNABLES_FILE);
1423 return -EINVAL;
1424 }
Cliff Wickman18129242008-06-02 08:56:14 -05001425 return 0;
1426}
1427
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001428/*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001429 * Initialize the sending side's sending buffers.
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001430 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001431static void activation_descriptor_init(int node, int pnode, int base_pnode)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001432{
1433 int i;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001434 int cpu;
Jack Steiner6a469e42011-09-20 13:55:04 -07001435 unsigned long gpa;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001436 unsigned long m;
1437 unsigned long n;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001438 size_t dsize;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001439 struct bau_desc *bau_desc;
1440 struct bau_desc *bd2;
1441 struct bau_control *bcp;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001442
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001443 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001444 * each bau_desc is 64 bytes; there are 8 (ITEMS_PER_DESC)
1445 * per cpu; and one per cpu on the uvhub (ADP_SZ)
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001446 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001447 dsize = sizeof(struct bau_desc) * ADP_SZ * ITEMS_PER_DESC;
1448 bau_desc = kmalloc_node(dsize, GFP_KERNEL, node);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001449 BUG_ON(!bau_desc);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001450
Jack Steiner6a469e42011-09-20 13:55:04 -07001451 gpa = uv_gpa(bau_desc);
1452 n = uv_gpa_to_gnode(gpa);
1453 m = uv_gpa_to_offset(gpa);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001454
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001455 /* the 14-bit pnode */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001456 write_mmr_descriptor_base(pnode, (n << UV_DESC_PSHIFT | m));
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001457 /*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001458 * Initializing all 8 (ITEMS_PER_DESC) descriptors for each
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001459 * cpu even though we only use the first one; one descriptor can
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001460 * describe a broadcast to 256 uv hubs.
Cliff Wickman0e2595c2009-05-20 08:10:57 -05001461 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001462 for (i = 0, bd2 = bau_desc; i < (ADP_SZ * ITEMS_PER_DESC); i++, bd2++) {
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001463 memset(bd2, 0, sizeof(struct bau_desc));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001464 bd2->header.swack_flag = 1;
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001465 /*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001466 * The base_dest_nasid set in the message header is the nasid
1467 * of the first uvhub in the partition. The bit map will
1468 * indicate destination pnode numbers relative to that base.
1469 * They may not be consecutive if nasid striding is being used.
Cliff Wickman94ca8e42009-04-14 10:56:48 -05001470 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001471 bd2->header.base_dest_nasid = UV_PNODE_TO_NASID(base_pnode);
1472 bd2->header.dest_subnodeid = UV_LB_SUBNODEID;
1473 bd2->header.command = UV_NET_ENDPOINT_INTD;
1474 bd2->header.int_both = 1;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001475 /*
1476 * all others need to be set to zero:
1477 * fairness chaining multilevel count replied_to
1478 */
1479 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001480 for_each_present_cpu(cpu) {
1481 if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
1482 continue;
1483 bcp = &per_cpu(bau_control, cpu);
1484 bcp->descriptor_base = bau_desc;
1485 }
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001486}
1487
1488/*
1489 * initialize the destination side's receiving buffers
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001490 * entered for each uvhub in the partition
1491 * - node is first node (kernel memory notion) on the uvhub
1492 * - pnode is the uvhub's physical identifier
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001493 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001494static void pq_init(int node, int pnode)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001495{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001496 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001497 size_t plsize;
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001498 char *cp;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001499 void *vp;
1500 unsigned long pn;
1501 unsigned long first;
1502 unsigned long pn_first;
1503 unsigned long last;
1504 struct bau_pq_entry *pqp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001505 struct bau_control *bcp;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001506
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001507 plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
1508 vp = kmalloc_node(plsize, GFP_KERNEL, node);
1509 pqp = (struct bau_pq_entry *)vp;
Ingo Molnardc163a42008-06-18 14:15:43 +02001510 BUG_ON(!pqp);
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001511
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001512 cp = (char *)pqp + 31;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001513 pqp = (struct bau_pq_entry *)(((unsigned long)cp >> 5) << 5);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001514
1515 for_each_present_cpu(cpu) {
1516 if (pnode != uv_cpu_to_pnode(cpu))
1517 continue;
1518 /* for every cpu on this pnode: */
1519 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001520 bcp->queue_first = pqp;
1521 bcp->bau_msg_head = pqp;
1522 bcp->queue_last = pqp + (DEST_Q_SIZE - 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001523 }
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001524 /*
Jack Steiner6a469e42011-09-20 13:55:04 -07001525 * need the gnode of where the memory was really allocated
Cliff Wickman4ea3c512009-04-16 07:53:09 -05001526 */
Jack Steiner6a469e42011-09-20 13:55:04 -07001527 pn = uv_gpa_to_gnode(uv_gpa(pqp));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001528 first = uv_physnodeaddr(pqp);
1529 pn_first = ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) | first;
1530 last = uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1));
1531 write_mmr_payload_first(pnode, pn_first);
1532 write_mmr_payload_tail(pnode, first);
1533 write_mmr_payload_last(pnode, last);
1534
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001535 /* in effect, all msg_type's are set to MSG_NOOP */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001536 memset(pqp, 0, sizeof(struct bau_pq_entry) * DEST_Q_SIZE);
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001537}
1538
1539/*
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001540 * Initialization of each UV hub's structures
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001541 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001542static void __init init_uvhub(int uvhub, int vector, int base_pnode)
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001543{
Cliff Wickman9674f352009-04-03 08:34:05 -05001544 int node;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001545 int pnode;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001546 unsigned long apicid;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001547
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001548 node = uvhub_to_first_node(uvhub);
1549 pnode = uv_blade_to_pnode(uvhub);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001550
1551 activation_descriptor_init(node, pnode, base_pnode);
1552
1553 pq_init(node, pnode);
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001554 /*
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001555 * The below initialization can't be in firmware because the
1556 * messaging IRQ will be determined by the OS.
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001557 */
Dimitri Sivanich8191c9f2010-11-16 16:23:52 -06001558 apicid = uvhub_to_first_apicid(uvhub) | uv_apicid_hibits;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001559 write_mmr_data_config(pnode, ((apicid << 32) | vector));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001560}
1561
1562/*
Cliff Wickman12a66112010-06-02 16:22:01 -05001563 * We will set BAU_MISC_CONTROL with a timeout period.
1564 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001565 * So the destination timeout period has to be calculated from them.
Cliff Wickman12a66112010-06-02 16:22:01 -05001566 */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001567static int calculate_destination_timeout(void)
Cliff Wickman12a66112010-06-02 16:22:01 -05001568{
1569 unsigned long mmr_image;
1570 int mult1;
1571 int mult2;
1572 int index;
1573 int base;
1574 int ret;
1575 unsigned long ts_ns;
1576
Jack Steiner2a919592011-05-11 12:50:28 -05001577 if (is_uv1_hub()) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001578 mult1 = SOFTACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
Jack Steiner2a919592011-05-11 12:50:28 -05001579 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1580 index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
1581 mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
1582 mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
1583 base = timeout_base_ns[index];
1584 ts_ns = base * mult1 * mult2;
1585 ret = ts_ns / 1000;
1586 } else {
1587 /* 4 bits 0/1 for 10/80us, 3 bits of multiplier */
1588 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1589 mmr_image = (mmr_image & UV_SA_MASK) >> UV_SA_SHFT;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001590 if (mmr_image & (1L << UV2_ACK_UNITS_SHFT))
Jack Steiner2a919592011-05-11 12:50:28 -05001591 mult1 = 80;
1592 else
1593 mult1 = 10;
1594 base = mmr_image & UV2_ACK_MASK;
1595 ret = mult1 * base;
1596 }
Cliff Wickman12a66112010-06-02 16:22:01 -05001597 return ret;
1598}
1599
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001600static void __init init_per_cpu_tunables(void)
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001601{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001602 int cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001603 struct bau_control *bcp;
1604
1605 for_each_present_cpu(cpu) {
1606 bcp = &per_cpu(bau_control, cpu);
1607 bcp->baudisabled = 0;
1608 bcp->statp = &per_cpu(ptcstats, cpu);
1609 /* time interval to catch a hardware stay-busy bug */
1610 bcp->timeout_interval = usec_2_cycles(2*timeout_us);
1611 bcp->max_concurr = max_concurr;
1612 bcp->max_concurr_const = max_concurr;
1613 bcp->plugged_delay = plugged_delay;
1614 bcp->plugsb4reset = plugsb4reset;
1615 bcp->timeoutsb4reset = timeoutsb4reset;
1616 bcp->ipi_reset_limit = ipi_reset_limit;
1617 bcp->complete_threshold = complete_threshold;
1618 bcp->cong_response_us = congested_respns_us;
1619 bcp->cong_reps = congested_reps;
1620 bcp->cong_period = congested_period;
1621 }
1622}
1623
1624/*
1625 * Scan all cpus to collect blade and socket summaries.
1626 */
1627static int __init get_cpu_topology(int base_pnode,
1628 struct uvhub_desc *uvhub_descs,
1629 unsigned char *uvhub_mask)
1630{
1631 int cpu;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001632 int pnode;
1633 int uvhub;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001634 int socket;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001635 struct bau_control *bcp;
1636 struct uvhub_desc *bdp;
1637 struct socket_desc *sdp;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001638
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001639 for_each_present_cpu(cpu) {
1640 bcp = &per_cpu(bau_control, cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001641
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001642 memset(bcp, 0, sizeof(struct bau_control));
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001643
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001644 pnode = uv_cpu_hub_info(cpu)->pnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001645 if ((pnode - base_pnode) >= UV_DISTRIBUTION_SIZE) {
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001646 printk(KERN_EMERG
1647 "cpu %d pnode %d-%d beyond %d; BAU disabled\n",
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001648 cpu, pnode, base_pnode, UV_DISTRIBUTION_SIZE);
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001649 return 1;
1650 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001651
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001652 bcp->osnode = cpu_to_node(cpu);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001653 bcp->partition_base_pnode = base_pnode;
1654
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001655 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001656 *(uvhub_mask + (uvhub/8)) |= (1 << (uvhub%8));
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001657 bdp = &uvhub_descs[uvhub];
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001658
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001659 bdp->num_cpus++;
1660 bdp->uvhub = uvhub;
1661 bdp->pnode = pnode;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001662
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001663 /* kludge: 'assuming' one node per socket, and assuming that
1664 disabling a socket just leaves a gap in node numbers */
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001665 socket = bcp->osnode & 1;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001666 bdp->socket_mask |= (1 << socket);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001667 sdp = &bdp->socket[socket];
1668 sdp->cpu_number[sdp->num_cpus] = cpu;
1669 sdp->num_cpus++;
Cliff Wickmancfa60912011-01-03 12:03:53 -06001670 if (sdp->num_cpus > MAX_CPUS_PER_SOCKET) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001671 printk(KERN_EMERG "%d cpus per socket invalid\n",
1672 sdp->num_cpus);
Cliff Wickmancfa60912011-01-03 12:03:53 -06001673 return 1;
1674 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001675 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001676 return 0;
1677}
1678
1679/*
1680 * Each socket is to get a local array of pnodes/hubs.
1681 */
1682static void make_per_cpu_thp(struct bau_control *smaster)
1683{
1684 int cpu;
1685 size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
1686
1687 smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
1688 memset(smaster->thp, 0, hpsz);
1689 for_each_present_cpu(cpu) {
1690 smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
1691 smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
1692 }
1693}
1694
1695/*
cpw@sgi.com442d3922011-06-21 07:21:31 -05001696 * Each uvhub is to get a local cpumask.
1697 */
1698static void make_per_hub_cpumask(struct bau_control *hmaster)
1699{
1700 int sz = sizeof(cpumask_t);
1701
1702 hmaster->cpumask = kzalloc_node(sz, GFP_KERNEL, hmaster->osnode);
1703}
1704
1705/*
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001706 * Initialize all the per_cpu information for the cpu's on a given socket,
1707 * given what has been gathered into the socket_desc struct.
1708 * And reports the chosen hub and socket masters back to the caller.
1709 */
1710static int scan_sock(struct socket_desc *sdp, struct uvhub_desc *bdp,
1711 struct bau_control **smasterp,
1712 struct bau_control **hmasterp)
1713{
1714 int i;
1715 int cpu;
1716 struct bau_control *bcp;
1717
1718 for (i = 0; i < sdp->num_cpus; i++) {
1719 cpu = sdp->cpu_number[i];
1720 bcp = &per_cpu(bau_control, cpu);
1721 bcp->cpu = cpu;
1722 if (i == 0) {
1723 *smasterp = bcp;
1724 if (!(*hmasterp))
1725 *hmasterp = bcp;
1726 }
1727 bcp->cpus_in_uvhub = bdp->num_cpus;
1728 bcp->cpus_in_socket = sdp->num_cpus;
1729 bcp->socket_master = *smasterp;
1730 bcp->uvhub = bdp->uvhub;
1731 bcp->uvhub_master = *hmasterp;
1732 bcp->uvhub_cpu = uv_cpu_hub_info(cpu)->blade_processor_id;
1733 if (bcp->uvhub_cpu >= MAX_CPUS_PER_UVHUB) {
1734 printk(KERN_EMERG "%d cpus per uvhub invalid\n",
1735 bcp->uvhub_cpu);
1736 return 1;
1737 }
1738 }
1739 return 0;
1740}
1741
1742/*
1743 * Summarize the blade and socket topology into the per_cpu structures.
1744 */
1745static int __init summarize_uvhub_sockets(int nuvhubs,
1746 struct uvhub_desc *uvhub_descs,
1747 unsigned char *uvhub_mask)
1748{
1749 int socket;
1750 int uvhub;
1751 unsigned short socket_mask;
1752
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001753 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001754 struct uvhub_desc *bdp;
1755 struct bau_control *smaster = NULL;
1756 struct bau_control *hmaster = NULL;
1757
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001758 if (!(*(uvhub_mask + (uvhub/8)) & (1 << (uvhub%8))))
1759 continue;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001760
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001761 bdp = &uvhub_descs[uvhub];
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001762 socket_mask = bdp->socket_mask;
1763 socket = 0;
1764 while (socket_mask) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001765 struct socket_desc *sdp;
1766 if ((socket_mask & 1)) {
1767 sdp = &bdp->socket[socket];
1768 if (scan_sock(sdp, bdp, &smaster, &hmaster))
Cliff Wickmancfa60912011-01-03 12:03:53 -06001769 return 1;
cpw@sgi.com9c9153d2011-06-21 07:21:28 -05001770 make_per_cpu_thp(smaster);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001771 }
1772 socket++;
Cliff Wickmana8328ee2010-06-02 16:22:02 -05001773 socket_mask = (socket_mask >> 1);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001774 }
cpw@sgi.com442d3922011-06-21 07:21:31 -05001775 make_per_hub_cpumask(hmaster);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001776 }
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001777 return 0;
1778}
1779
1780/*
1781 * initialize the bau_control structure for each cpu
1782 */
1783static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
1784{
1785 unsigned char *uvhub_mask;
1786 void *vp;
1787 struct uvhub_desc *uvhub_descs;
1788
1789 timeout_us = calculate_destination_timeout();
1790
1791 vp = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1792 uvhub_descs = (struct uvhub_desc *)vp;
1793 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
1794 uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
1795
1796 if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask))
cpw@sgi.combbd270e2011-06-21 07:21:32 -05001797 goto fail;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001798
1799 if (summarize_uvhub_sockets(nuvhubs, uvhub_descs, uvhub_mask))
cpw@sgi.combbd270e2011-06-21 07:21:32 -05001800 goto fail;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001801
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001802 kfree(uvhub_descs);
Cliff Wickmanc4026cf2010-07-30 14:10:55 -05001803 kfree(uvhub_mask);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001804 init_per_cpu_tunables();
Cliff Wickmancfa60912011-01-03 12:03:53 -06001805 return 0;
cpw@sgi.combbd270e2011-06-21 07:21:32 -05001806
1807fail:
1808 kfree(uvhub_descs);
1809 kfree(uvhub_mask);
1810 return 1;
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001811}
Cliff Wickman18129242008-06-02 08:56:14 -05001812
1813/*
1814 * Initialization of BAU-related structures
1815 */
Cliff Wickmanb194b1202008-06-12 08:23:48 -05001816static int __init uv_bau_init(void)
Cliff Wickman18129242008-06-02 08:56:14 -05001817{
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001818 int uvhub;
1819 int pnode;
1820 int nuvhubs;
Rusty Russell2c74d662009-03-18 08:22:30 +10301821 int cur_cpu;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001822 int cpus;
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001823 int vector;
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001824 cpumask_var_t *mask;
Cliff Wickman18129242008-06-02 08:56:14 -05001825
1826 if (!is_uv_system())
1827 return 0;
1828
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001829 if (nobau)
1830 return 0;
1831
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001832 for_each_possible_cpu(cur_cpu) {
1833 mask = &per_cpu(uv_flush_tlb_mask, cur_cpu);
1834 zalloc_cpumask_var_node(mask, GFP_KERNEL, cpu_to_node(cur_cpu));
1835 }
Rusty Russell76ba0ec2009-03-13 14:49:57 +10301836
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001837 nuvhubs = uv_num_possible_blades();
Cliff Wickman50fb55a2010-06-02 16:22:02 -05001838 spin_lock_init(&disable_lock);
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001839 congested_cycles = usec_2_cycles(congested_respns_us);
Cliff Wickman9674f352009-04-03 08:34:05 -05001840
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001841 uv_base_pnode = 0x7fffffff;
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001842 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001843 cpus = uv_blade_nr_possible_cpus(uvhub);
1844 if (cpus && (uv_blade_to_pnode(uvhub) < uv_base_pnode))
1845 uv_base_pnode = uv_blade_to_pnode(uvhub);
Cliff Wickman77ed23f2011-05-10 08:26:43 -05001846 }
1847
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001848 if (init_per_cpu(nuvhubs, uv_base_pnode)) {
Cliff Wickmancfa60912011-01-03 12:03:53 -06001849 nobau = 1;
1850 return 0;
1851 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001852
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001853 vector = UV_BAU_MESSAGE;
1854 for_each_possible_blade(uvhub)
1855 if (uv_blade_nr_possible_cpus(uvhub))
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001856 init_uvhub(uvhub, vector, uv_base_pnode);
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001857
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001858 enable_timeouts();
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001859 alloc_intr_gate(vector, uv_bau_message_intr1);
1860
1861 for_each_possible_blade(uvhub) {
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001862 if (uv_blade_nr_possible_cpus(uvhub)) {
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001863 unsigned long val;
1864 unsigned long mmr;
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001865 pnode = uv_blade_to_pnode(uvhub);
1866 /* INIT the bau */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001867 val = 1L << 63;
1868 write_gmmr_activation(pnode, val);
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001869 mmr = 1; /* should be 1 to broadcast to both sockets */
Cliff Wickmanf073cc82011-05-24 13:07:36 -05001870 write_mmr_data_broadcast(pnode, mmr);
Cliff Wickman93a7ca02010-07-16 10:11:21 -05001871 }
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001872 }
Ingo Molnarb4c286e2008-06-18 14:28:19 +02001873
Cliff Wickman18129242008-06-02 08:56:14 -05001874 return 0;
1875}
Cliff Wickmanb8f7fb12010-04-14 11:35:46 -05001876core_initcall(uv_bau_init);
Cliff Wickmane8e5e8a2010-06-02 16:22:01 -05001877fs_initcall(uv_ptc_init);