Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1 | /* |
| 2 | * SGI UltraViolet TLB flush routines. |
| 3 | * |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 4 | * (c) 2008-2011 Cliff Wickman <cpw@sgi.com>, SGI. |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 5 | * |
| 6 | * This code is released under the GNU General Public License version 2 or |
| 7 | * later. |
| 8 | */ |
Jeremy Fitzhardinge | aef8f5b | 2008-10-14 21:43:43 -0700 | [diff] [blame] | 9 | #include <linux/seq_file.h> |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 10 | #include <linux/proc_fs.h> |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 11 | #include <linux/debugfs.h> |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 12 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Jean Delvare | ca444564 | 2011-03-25 15:20:14 +0100 | [diff] [blame] | 14 | #include <linux/delay.h> |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 15 | |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 16 | #include <asm/mmu_context.h> |
Tejun Heo | bdbcdd4 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 17 | #include <asm/uv/uv.h> |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 18 | #include <asm/uv/uv_mmrs.h> |
Ingo Molnar | b4c286e | 2008-06-18 14:28:19 +0200 | [diff] [blame] | 19 | #include <asm/uv/uv_hub.h> |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 20 | #include <asm/uv/uv_bau.h> |
Ingo Molnar | 7b6aa33 | 2009-02-17 13:58:15 +0100 | [diff] [blame] | 21 | #include <asm/apic.h> |
Ingo Molnar | b4c286e | 2008-06-18 14:28:19 +0200 | [diff] [blame] | 22 | #include <asm/idle.h> |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 23 | #include <asm/tsc.h> |
Cliff Wickman | 99dd871 | 2008-08-19 12:51:59 -0500 | [diff] [blame] | 24 | #include <asm/irq_vectors.h> |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 25 | #include <asm/timer.h> |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 26 | |
Cliff Wickman | 12a6611 | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 27 | /* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */ |
| 28 | static int timeout_base_ns[] = { |
| 29 | 20, |
| 30 | 160, |
| 31 | 1280, |
| 32 | 10240, |
| 33 | 81920, |
| 34 | 655360, |
| 35 | 5242880, |
| 36 | 167772160 |
| 37 | }; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 38 | |
Cliff Wickman | 12a6611 | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 39 | static int timeout_us; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 40 | static int nobau; |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 41 | static int baudisabled; |
| 42 | static spinlock_t disable_lock; |
| 43 | static cycles_t congested_cycles; |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 44 | |
| 45 | /* tunables: */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 46 | static int max_concurr = MAX_BAU_CONCURRENT; |
| 47 | static int max_concurr_const = MAX_BAU_CONCURRENT; |
| 48 | static int plugged_delay = PLUGGED_DELAY; |
| 49 | static int plugsb4reset = PLUGSB4RESET; |
| 50 | static int timeoutsb4reset = TIMEOUTSB4RESET; |
| 51 | static int ipi_reset_limit = IPI_RESET_LIMIT; |
| 52 | static int complete_threshold = COMPLETE_THRESHOLD; |
| 53 | static int congested_respns_us = CONGESTED_RESPONSE_US; |
| 54 | static int congested_reps = CONGESTED_REPS; |
| 55 | static int congested_period = CONGESTED_PERIOD; |
| 56 | |
| 57 | static 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 Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 69 | static struct dentry *tunables_dir; |
| 70 | static struct dentry *tunables_file; |
| 71 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 72 | /* these correspond to the statistics printed by ptc_seq_show() */ |
| 73 | static 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 | |
| 108 | static int __init |
| 109 | setup_nobau(char *arg) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 110 | { |
| 111 | nobau = 1; |
| 112 | return 0; |
| 113 | } |
| 114 | early_param("nobau", setup_nobau); |
Ingo Molnar | b4c286e | 2008-06-18 14:28:19 +0200 | [diff] [blame] | 115 | |
Cliff Wickman | 94ca8e4 | 2009-04-14 10:56:48 -0500 | [diff] [blame] | 116 | /* base pnode in this partition */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 117 | static int uv_base_pnode __read_mostly; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 118 | |
Ingo Molnar | dc163a4 | 2008-06-18 14:15:43 +0200 | [diff] [blame] | 119 | static DEFINE_PER_CPU(struct ptc_stats, ptcstats); |
| 120 | static DEFINE_PER_CPU(struct bau_control, bau_control); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 121 | static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask); |
| 122 | |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 123 | /* |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 124 | * Determine the first node on a uvhub. 'Nodes' are used for kernel |
| 125 | * memory allocation. |
Cliff Wickman | 9674f35 | 2009-04-03 08:34:05 -0500 | [diff] [blame] | 126 | */ |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 127 | static int __init uvhub_to_first_node(int uvhub) |
Cliff Wickman | 9674f35 | 2009-04-03 08:34:05 -0500 | [diff] [blame] | 128 | { |
| 129 | int node, b; |
| 130 | |
| 131 | for_each_online_node(node) { |
| 132 | b = uv_node_to_blade_id(node); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 133 | if (uvhub == b) |
Cliff Wickman | 9674f35 | 2009-04-03 08:34:05 -0500 | [diff] [blame] | 134 | return node; |
| 135 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 136 | return -1; |
Cliff Wickman | 9674f35 | 2009-04-03 08:34:05 -0500 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 140 | * Determine the apicid of the first cpu on a uvhub. |
Cliff Wickman | 9674f35 | 2009-04-03 08:34:05 -0500 | [diff] [blame] | 141 | */ |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 142 | static int __init uvhub_to_first_apicid(int uvhub) |
Cliff Wickman | 9674f35 | 2009-04-03 08:34:05 -0500 | [diff] [blame] | 143 | { |
| 144 | int cpu; |
| 145 | |
| 146 | for_each_present_cpu(cpu) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 147 | if (uvhub == uv_cpu_to_blade_id(cpu)) |
Cliff Wickman | 9674f35 | 2009-04-03 08:34:05 -0500 | [diff] [blame] | 148 | return per_cpu(x86_cpu_to_apicid, cpu); |
| 149 | return -1; |
| 150 | } |
| 151 | |
| 152 | /* |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 153 | * 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 160 | static void reply_to_message(struct msg_desc *mdp, struct bau_control *bcp) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 161 | { |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 162 | unsigned long dw; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 163 | struct bau_pq_entry *msg; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 164 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 165 | msg = mdp->msg; |
| 166 | if (!msg->canceled) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 167 | dw = (msg->swack_vec << UV_SW_ACK_NPENDING) | msg->swack_vec; |
| 168 | write_mmr_sw_ack(dw); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 169 | } |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 170 | msg->replied_to = 1; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 171 | msg->swack_vec = 0; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /* |
| 175 | * Process the receipt of a RETRY message |
| 176 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 177 | static void bau_process_retry_msg(struct msg_desc *mdp, |
| 178 | struct bau_control *bcp) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 179 | { |
| 180 | int i; |
| 181 | int cancel_count = 0; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 182 | unsigned long msg_res; |
| 183 | unsigned long mmr = 0; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 184 | struct bau_pq_entry *msg = mdp->msg; |
| 185 | struct bau_pq_entry *msg2; |
| 186 | struct ptc_stats *stat = bcp->statp; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 187 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 188 | 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 193 | if (msg2 > mdp->queue_last) |
| 194 | msg2 = mdp->queue_first; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 195 | if (msg2 == msg) |
| 196 | break; |
| 197 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 198 | /* same conditions for cancellation as do_reset */ |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 199 | if ((msg2->replied_to == 0) && (msg2->canceled == 0) && |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 200 | (msg2->swack_vec) && ((msg2->swack_vec & |
| 201 | msg->swack_vec) == 0) && |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 202 | (msg2->sending_cpu == msg->sending_cpu) && |
| 203 | (msg2->msg_type != MSG_NOOP)) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 204 | mmr = read_mmr_sw_ack(); |
| 205 | msg_res = msg2->swack_vec; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 206 | /* |
| 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 Wickman | 39847e7 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 212 | if (mmr & (msg_res << UV_SW_ACK_NPENDING)) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 213 | unsigned long mr; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 214 | /* |
| 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 221 | mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res; |
| 222 | write_mmr_sw_ack(mr); |
Cliff Wickman | 39847e7 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 223 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | if (!cancel_count) |
| 227 | stat->d_nocanceled++; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 228 | } |
| 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 234 | static void bau_process_message(struct msg_desc *mdp, |
| 235 | struct bau_control *bcp) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 236 | { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 237 | short socket_ack_count = 0; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 238 | short *sp; |
| 239 | struct atomic_short *asp; |
| 240 | struct ptc_stats *stat = bcp->statp; |
| 241 | struct bau_pq_entry *msg = mdp->msg; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 242 | struct bau_control *smaster = bcp->socket_master; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 243 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 244 | /* |
| 245 | * This must be a normal message, or retry of a normal message |
| 246 | */ |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 247 | if (msg->address == TLB_FLUSH_ALL) { |
| 248 | local_flush_tlb(); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 249 | stat->d_alltlb++; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 250 | } else { |
| 251 | __flush_tlb_one(msg->address); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 252 | stat->d_onetlb++; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 253 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 254 | stat->d_requestee++; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 255 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 256 | /* |
| 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 263 | bau_process_retry_msg(mdp, bcp); |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 264 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 265 | /* |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 266 | * This is a swack message, so we have to reply to it. |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 267 | * 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 271 | sp = &smaster->socket_acknowledge_count[mdp->msg_slot]; |
| 272 | asp = (struct atomic_short *)sp; |
| 273 | socket_ack_count = atom_asr(1, asp); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 274 | if (socket_ack_count == bcp->cpus_in_socket) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 275 | int msg_ack_count; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 276 | /* |
| 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 281 | asp = (struct atomic_short *)&msg->acknowledge_count; |
| 282 | msg_ack_count = atom_asr(socket_ack_count, asp); |
Ingo Molnar | dc163a4 | 2008-06-18 14:15:43 +0200 | [diff] [blame] | 283 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 284 | if (msg_ack_count == bcp->cpus_in_uvhub) { |
| 285 | /* |
| 286 | * All cpus in uvhub saw it; reply |
| 287 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 288 | reply_to_message(mdp, bcp); |
Ingo Molnar | dc163a4 | 2008-06-18 14:15:43 +0200 | [diff] [blame] | 289 | } |
| 290 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 291 | |
| 292 | return; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 296 | * Determine the first cpu on a pnode. |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 297 | */ |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 298 | static int pnode_to_first_cpu(int pnode, struct bau_control *smaster) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 299 | { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 300 | int cpu; |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 301 | struct hub_and_pnode *hpp; |
| 302 | |
| 303 | for_each_present_cpu(cpu) { |
| 304 | hpp = &smaster->thp[cpu]; |
| 305 | if (pnode == hpp->pnode) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 306 | return cpu; |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 307 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 308 | return -1; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 309 | } |
| 310 | |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 311 | /* |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 312 | * 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 315 | * can be identified by their nonzero swack_vec field. |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 316 | * |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 317 | * This is entered for a single cpu on the uvhub. |
| 318 | * The sender want's this uvhub to free a specific message's |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 319 | * swack resources. |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 320 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 321 | static void do_reset(void *ptr) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 322 | { |
| 323 | int i; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 324 | 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 Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 328 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 329 | stat->d_resets++; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 330 | /* |
| 331 | * We're looking for the given sender, and |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 332 | * will free its swack resource. |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 333 | * If all cpu's finally responded after the timeout, its |
| 334 | * message 'replied_to' was set. |
| 335 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 336 | 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 Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 340 | if ((msg->replied_to == 0) && |
| 341 | (msg->canceled == 0) && |
| 342 | (msg->sending_cpu == rap->sender) && |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 343 | (msg->swack_vec) && |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 344 | (msg->msg_type != MSG_NOOP)) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 345 | unsigned long mmr; |
| 346 | unsigned long mr; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 347 | /* |
| 348 | * make everyone else ignore this message |
| 349 | */ |
| 350 | msg->canceled = 1; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 351 | /* |
| 352 | * only reset the resource if it is still pending |
| 353 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 354 | mmr = read_mmr_sw_ack(); |
| 355 | msg_res = msg->swack_vec; |
| 356 | mr = (msg_res << UV_SW_ACK_NPENDING) | msg_res; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 357 | if (mmr & msg_res) { |
| 358 | stat->d_rcanceled++; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 359 | write_mmr_sw_ack(mr); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 360 | } |
| 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.com | a456eaa | 2011-06-21 07:21:30 -0500 | [diff] [blame] | 370 | static void reset_with_ipi(struct pnmask *distribution, struct bau_control *bcp) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 371 | { |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 372 | int pnode; |
| 373 | int apnode; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 374 | int maskbits; |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 375 | int sender = bcp->cpu; |
cpw@sgi.com | 442d392 | 2011-06-21 07:21:31 -0500 | [diff] [blame] | 376 | cpumask_t *mask = bcp->uvhub_master->cpumask; |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 377 | struct bau_control *smaster = bcp->socket_master; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 378 | struct reset_args reset_args; |
| 379 | |
| 380 | reset_args.sender = sender; |
cpw@sgi.com | 442d392 | 2011-06-21 07:21:31 -0500 | [diff] [blame] | 381 | cpus_clear(*mask); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 382 | /* find a single cpu for each uvhub in this distribution mask */ |
cpw@sgi.com | a456eaa | 2011-06-21 07:21:30 -0500 | [diff] [blame] | 383 | maskbits = sizeof(struct pnmask) * BITSPERBYTE; |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 384 | /* each bit is a pnode relative to the partition base pnode */ |
| 385 | for (pnode = 0; pnode < maskbits; pnode++) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 386 | int cpu; |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 387 | if (!bau_uvhub_isset(pnode, distribution)) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 388 | continue; |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 389 | apnode = pnode + bcp->partition_base_pnode; |
| 390 | cpu = pnode_to_first_cpu(apnode, smaster); |
cpw@sgi.com | 442d392 | 2011-06-21 07:21:31 -0500 | [diff] [blame] | 391 | cpu_set(cpu, *mask); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 392 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 393 | |
| 394 | /* IPI all cpus; preemption is already disabled */ |
cpw@sgi.com | 442d392 | 2011-06-21 07:21:31 -0500 | [diff] [blame] | 395 | smp_call_function_many(mask, do_reset, (void *)&reset_args, 1); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 396 | return; |
| 397 | } |
| 398 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 399 | static inline unsigned long cycles_2_us(unsigned long long cyc) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 400 | { |
| 401 | unsigned long long ns; |
| 402 | unsigned long us; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 403 | int cpu = smp_processor_id(); |
| 404 | |
| 405 | ns = (cyc * per_cpu(cyc2ns, cpu)) >> CYC2NS_SCALE_FACTOR; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 406 | 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 415 | static inline void quiesce_local_uvhub(struct bau_control *hmaster) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 416 | { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 417 | atom_asr(1, (struct atomic_short *)&hmaster->uvhub_quiesce); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | /* |
| 421 | * mark this quiet-requestor as done |
| 422 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 423 | static inline void end_uvhub_quiesce(struct bau_control *hmaster) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 424 | { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 425 | atom_asr(-1, (struct atomic_short *)&hmaster->uvhub_quiesce); |
| 426 | } |
| 427 | |
| 428 | static 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 Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /* |
| 439 | * Wait for completion of a broadcast software ack message |
| 440 | * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 441 | */ |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 442 | static int uv1_wait_completion(struct bau_desc *bau_desc, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 443 | unsigned long mmr_offset, int right_shift, |
| 444 | struct bau_control *bcp, long try) |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 445 | { |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 446 | unsigned long descriptor_status; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 447 | cycles_t ttm; |
Cliff Wickman | 712157a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 448 | struct ptc_stats *stat = bcp->statp; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 449 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 450 | descriptor_status = uv1_read_status(mmr_offset, right_shift); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 451 | /* spin on the status MMR, waiting for it to go idle */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 452 | while ((descriptor_status != DS_IDLE)) { |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 453 | /* |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 454 | * 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 Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 458 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 459 | if (descriptor_status == DS_SOURCE_TIMEOUT) { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 460 | stat->s_stimeout++; |
| 461 | return FLUSH_GIVEUP; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 462 | } else if (descriptor_status == DS_DESTINATION_TIMEOUT) { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 463 | stat->s_dtimeout++; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 464 | ttm = get_cycles(); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 465 | |
| 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 472 | if (cycles_2_us(ttm - bcp->send_message) < timeout_us) { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 473 | 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 Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 484 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 485 | descriptor_status = uv1_read_status(mmr_offset, right_shift); |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 486 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 487 | bcp->conseccompletes++; |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 488 | return FLUSH_COMPLETE; |
| 489 | } |
| 490 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 491 | /* |
| 492 | * UV2 has an extra bit of status in the ACTIVATION_STATUS_2 register. |
| 493 | */ |
| 494 | static unsigned long uv2_read_status(unsigned long offset, int rshft, int cpu) |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 495 | { |
| 496 | unsigned long descriptor_status; |
| 497 | unsigned long descriptor_status2; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 498 | |
| 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 | |
| 505 | static 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 Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 512 | struct ptc_stats *stat = bcp->statp; |
| 513 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 514 | descriptor_stat = uv2_read_status(mmr_offset, right_shift, cpu); |
| 515 | |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 516 | /* spin on the status MMR, waiting for it to go idle */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 517 | while (descriptor_stat != UV2H_DESC_IDLE) { |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 518 | /* |
| 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 524 | if ((descriptor_stat == UV2H_DESC_SOURCE_TIMEOUT) || |
| 525 | (descriptor_stat == UV2H_DESC_DEST_STRONG_NACK) || |
| 526 | (descriptor_stat == UV2H_DESC_DEST_PUT_ERR)) { |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 527 | stat->s_stimeout++; |
| 528 | return FLUSH_GIVEUP; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 529 | } else if (descriptor_stat == UV2H_DESC_DEST_TIMEOUT) { |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 530 | stat->s_dtimeout++; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 531 | ttm = get_cycles(); |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 532 | /* |
| 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 538 | if (cycles_2_us(ttm - bcp->send_message) < timeout_us) { |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 539 | bcp->conseccompletes = 0; |
| 540 | return FLUSH_RETRY_PLUGGED; |
| 541 | } |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 542 | bcp->conseccompletes = 0; |
| 543 | return FLUSH_RETRY_TIMEOUT; |
| 544 | } else { |
| 545 | /* |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 546 | * descriptor_stat is still BUSY |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 547 | */ |
| 548 | cpu_relax(); |
| 549 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 550 | descriptor_stat = uv2_read_status(mmr_offset, right_shift, cpu); |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 551 | } |
| 552 | bcp->conseccompletes++; |
| 553 | return FLUSH_COMPLETE; |
| 554 | } |
| 555 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 556 | /* |
| 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 | */ |
| 561 | static int wait_completion(struct bau_desc *bau_desc, |
| 562 | struct bau_control *bcp, long try) |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 563 | { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 564 | 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 | |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 576 | if (bcp->uvhub_version == 1) |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 577 | return uv1_wait_completion(bau_desc, mmr_offset, right_shift, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 578 | bcp, try); |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 579 | else |
| 580 | return uv2_wait_completion(bau_desc, mmr_offset, right_shift, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 581 | bcp, try); |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 582 | } |
| 583 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 584 | static inline cycles_t sec_2_cycles(unsigned long sec) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 585 | { |
| 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 595 | * Our retries are blocked by all destination sw ack resources being |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 596 | * in use, and a timeout is pending. In that case hardware immediately |
| 597 | * returns the ERROR that looks like a destination timeout. |
| 598 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 599 | static void destination_plugged(struct bau_desc *bau_desc, |
| 600 | struct bau_control *bcp, |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 601 | struct bau_control *hmaster, struct ptc_stats *stat) |
| 602 | { |
| 603 | udelay(bcp->plugged_delay); |
| 604 | bcp->plugged_tries++; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 605 | |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 606 | if (bcp->plugged_tries >= bcp->plugsb4reset) { |
| 607 | bcp->plugged_tries = 0; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 608 | |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 609 | quiesce_local_uvhub(hmaster); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 610 | |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 611 | spin_lock(&hmaster->queue_lock); |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 612 | reset_with_ipi(&bau_desc->distribution, bcp); |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 613 | spin_unlock(&hmaster->queue_lock); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 614 | |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 615 | end_uvhub_quiesce(hmaster); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 616 | |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 617 | bcp->ipi_attempts++; |
| 618 | stat->s_resets_plug++; |
| 619 | } |
| 620 | } |
| 621 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 622 | static void destination_timeout(struct bau_desc *bau_desc, |
| 623 | struct bau_control *bcp, struct bau_control *hmaster, |
| 624 | struct ptc_stats *stat) |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 625 | { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 626 | hmaster->max_concurr = 1; |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 627 | bcp->timeout_tries++; |
| 628 | if (bcp->timeout_tries >= bcp->timeoutsb4reset) { |
| 629 | bcp->timeout_tries = 0; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 630 | |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 631 | quiesce_local_uvhub(hmaster); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 632 | |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 633 | spin_lock(&hmaster->queue_lock); |
cpw@sgi.com | 485f07d | 2011-06-21 07:21:29 -0500 | [diff] [blame] | 634 | reset_with_ipi(&bau_desc->distribution, bcp); |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 635 | spin_unlock(&hmaster->queue_lock); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 636 | |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 637 | end_uvhub_quiesce(hmaster); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 638 | |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 639 | bcp->ipi_attempts++; |
| 640 | stat->s_resets_timeout++; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | /* |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 645 | * Completions are taking a very long time due to a congested numalink |
| 646 | * network. |
| 647 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 648 | static void disable_for_congestion(struct bau_control *bcp, |
| 649 | struct ptc_stats *stat) |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 650 | { |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 651 | /* let only one cpu do this disabling */ |
| 652 | spin_lock(&disable_lock); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 653 | |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 654 | if (!baudisabled && bcp->period_requests && |
| 655 | ((bcp->period_time / bcp->period_requests) > congested_cycles)) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 656 | int tcpu; |
| 657 | struct bau_control *tbcp; |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 658 | /* 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 Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 662 | bcp->set_bau_on_time = get_cycles(); |
| 663 | bcp->set_bau_on_time += sec_2_cycles(bcp->cong_period); |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 664 | stat->s_bau_disabled++; |
| 665 | for_each_present_cpu(tcpu) { |
| 666 | tbcp = &per_cpu(bau_control, tcpu); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 667 | tbcp->baudisabled = 1; |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 668 | } |
| 669 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 670 | |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 671 | spin_unlock(&disable_lock); |
| 672 | } |
| 673 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 674 | static 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 | |
| 688 | static 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 | */ |
| 718 | static 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 | */ |
| 735 | static 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 Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 746 | * Send a broadcast and wait for it to complete. |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 747 | * |
Cliff Wickman | f6d8a56 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 748 | * The flush_mask contains the cpus the broadcast is to be sent to including |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 749 | * cpus that are on the local uvhub. |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 750 | * |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 751 | * 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 Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 754 | */ |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 755 | int uv_flush_send_and_wait(struct bau_desc *bau_desc, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 756 | struct cpumask *flush_mask, struct bau_control *bcp) |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 757 | { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 758 | int seq_number = 0; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 759 | int completion_stat = 0; |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 760 | int uv1 = 0; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 761 | long try = 0; |
Ingo Molnar | b4c286e | 2008-06-18 14:28:19 +0200 | [diff] [blame] | 762 | unsigned long index; |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 763 | cycles_t time1; |
| 764 | cycles_t time2; |
Cliff Wickman | 712157a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 765 | struct ptc_stats *stat = bcp->statp; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 766 | struct bau_control *hmaster = bcp->uvhub_master; |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 767 | struct uv1_bau_msg_header *uv1_hdr = NULL; |
| 768 | struct uv2_bau_msg_header *uv2_hdr = NULL; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 769 | |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 770 | if (bcp->uvhub_version == 1) { |
| 771 | uv1 = 1; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 772 | uv1_throttle(hmaster, stat); |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 773 | uv1_hdr = &bau_desc->header.uv1_hdr; |
| 774 | } else |
| 775 | uv2_hdr = &bau_desc->header.uv2_hdr; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 776 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 777 | while (hmaster->uvhub_quiesce) |
| 778 | cpu_relax(); |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 779 | |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 780 | time1 = get_cycles(); |
| 781 | do { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 782 | if (try == 0) { |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 783 | if (uv1) |
| 784 | uv1_hdr->msg_type = MSG_REGULAR; |
| 785 | else |
| 786 | uv2_hdr->msg_type = MSG_REGULAR; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 787 | seq_number = bcp->message_number++; |
| 788 | } else { |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 789 | if (uv1) |
| 790 | uv1_hdr->msg_type = MSG_RETRY; |
| 791 | else |
| 792 | uv2_hdr->msg_type = MSG_RETRY; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 793 | stat->s_retry_messages++; |
| 794 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 795 | |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 796 | if (uv1) |
| 797 | uv1_hdr->sequence = seq_number; |
| 798 | else |
| 799 | uv2_hdr->sequence = seq_number; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 800 | index = (1UL << AS_PUSH_SHIFT) | bcp->uvhub_cpu; |
| 801 | bcp->send_message = get_cycles(); |
| 802 | |
| 803 | write_mmr_activation(index); |
| 804 | |
| 805 | try++; |
| 806 | completion_stat = wait_completion(bau_desc, bcp, try); |
| 807 | |
| 808 | handle_cmplt(completion_stat, bau_desc, bcp, hmaster, stat); |
| 809 | |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 810 | if (bcp->ipi_attempts >= bcp->ipi_reset_limit) { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 811 | bcp->ipi_attempts = 0; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 812 | completion_stat = FLUSH_GIVEUP; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 813 | break; |
| 814 | } |
| 815 | cpu_relax(); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 816 | } while ((completion_stat == FLUSH_RETRY_PLUGGED) || |
| 817 | (completion_stat == FLUSH_RETRY_TIMEOUT)); |
| 818 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 819 | time2 = get_cycles(); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 820 | |
| 821 | count_max_concurr(completion_stat, bcp, hmaster); |
| 822 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 823 | while (hmaster->uvhub_quiesce) |
| 824 | cpu_relax(); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 825 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 826 | atomic_dec(&hmaster->active_descriptor_count); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 827 | |
| 828 | record_send_stats(time1, time2, bcp, stat, completion_stat, try); |
| 829 | |
| 830 | if (completion_stat == FLUSH_GIVEUP) |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 831 | return 1; |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 832 | return 0; |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 833 | } |
| 834 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 835 | /* |
| 836 | * The BAU is disabled. When the disabled time period has expired, the cpu |
| 837 | * that disabled it must re-enable it. |
| 838 | * Return 0 if it is re-enabled for all cpus. |
| 839 | */ |
| 840 | static int check_enable(struct bau_control *bcp, struct ptc_stats *stat) |
| 841 | { |
| 842 | int tcpu; |
| 843 | struct bau_control *tbcp; |
| 844 | |
| 845 | if (bcp->set_bau_off) { |
| 846 | if (get_cycles() >= bcp->set_bau_on_time) { |
| 847 | stat->s_bau_reenabled++; |
| 848 | baudisabled = 0; |
| 849 | for_each_present_cpu(tcpu) { |
| 850 | tbcp = &per_cpu(bau_control, tcpu); |
| 851 | tbcp->baudisabled = 0; |
| 852 | tbcp->period_requests = 0; |
| 853 | tbcp->period_time = 0; |
| 854 | } |
| 855 | return 0; |
| 856 | } |
| 857 | } |
| 858 | return -1; |
| 859 | } |
| 860 | |
| 861 | static void record_send_statistics(struct ptc_stats *stat, int locals, int hubs, |
| 862 | int remotes, struct bau_desc *bau_desc) |
| 863 | { |
| 864 | stat->s_requestor++; |
| 865 | stat->s_ntargcpu += remotes + locals; |
| 866 | stat->s_ntargremotes += remotes; |
| 867 | stat->s_ntarglocals += locals; |
| 868 | |
| 869 | /* uvhub statistics */ |
| 870 | hubs = bau_uvhub_weight(&bau_desc->distribution); |
| 871 | if (locals) { |
| 872 | stat->s_ntarglocaluvhub++; |
| 873 | stat->s_ntargremoteuvhub += (hubs - 1); |
| 874 | } else |
| 875 | stat->s_ntargremoteuvhub += hubs; |
| 876 | |
| 877 | stat->s_ntarguvhub += hubs; |
| 878 | |
| 879 | if (hubs >= 16) |
| 880 | stat->s_ntarguvhub16++; |
| 881 | else if (hubs >= 8) |
| 882 | stat->s_ntarguvhub8++; |
| 883 | else if (hubs >= 4) |
| 884 | stat->s_ntarguvhub4++; |
| 885 | else if (hubs >= 2) |
| 886 | stat->s_ntarguvhub2++; |
| 887 | else |
| 888 | stat->s_ntarguvhub1++; |
| 889 | } |
| 890 | |
| 891 | /* |
| 892 | * Translate a cpu mask to the uvhub distribution mask in the BAU |
| 893 | * activation descriptor. |
| 894 | */ |
| 895 | static int set_distrib_bits(struct cpumask *flush_mask, struct bau_control *bcp, |
| 896 | struct bau_desc *bau_desc, int *localsp, int *remotesp) |
| 897 | { |
| 898 | int cpu; |
| 899 | int pnode; |
| 900 | int cnt = 0; |
| 901 | struct hub_and_pnode *hpp; |
| 902 | |
| 903 | for_each_cpu(cpu, flush_mask) { |
| 904 | /* |
| 905 | * The distribution vector is a bit map of pnodes, relative |
| 906 | * to the partition base pnode (and the partition base nasid |
| 907 | * in the header). |
| 908 | * Translate cpu to pnode and hub using a local memory array. |
| 909 | */ |
| 910 | hpp = &bcp->socket_master->thp[cpu]; |
| 911 | pnode = hpp->pnode - bcp->partition_base_pnode; |
| 912 | bau_uvhub_set(pnode, &bau_desc->distribution); |
| 913 | cnt++; |
| 914 | if (hpp->uvhub == bcp->uvhub) |
| 915 | (*localsp)++; |
| 916 | else |
| 917 | (*remotesp)++; |
| 918 | } |
| 919 | if (!cnt) |
| 920 | return 1; |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | /* |
| 925 | * globally purge translation cache of a virtual address or all TLB's |
Tejun Heo | bdbcdd4 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 926 | * @cpumask: mask of all cpu's in which the address is to be removed |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 927 | * @mm: mm_struct containing virtual address range |
| 928 | * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu) |
Tejun Heo | bdbcdd4 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 929 | * @cpu: the current cpu |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 930 | * |
| 931 | * This is the entry point for initiating any UV global TLB shootdown. |
| 932 | * |
| 933 | * Purges the translation caches of all specified processors of the given |
| 934 | * virtual address, or purges all TLB's on specified processors. |
| 935 | * |
Tejun Heo | bdbcdd4 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 936 | * The caller has derived the cpumask from the mm_struct. This function |
| 937 | * is called only if there are bits set in the mask. (e.g. flush_tlb_page()) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 938 | * |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 939 | * The cpumask is converted into a uvhubmask of the uvhubs containing |
| 940 | * those cpus. |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 941 | * |
Tejun Heo | bdbcdd4 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 942 | * Note that this function should be called with preemption disabled. |
| 943 | * |
| 944 | * Returns NULL if all remote flushing was done. |
| 945 | * Returns pointer to cpumask if some remote flushing remains to be |
| 946 | * done. The returned pointer is valid till preemption is re-enabled. |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 947 | */ |
Tejun Heo | bdbcdd4 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 948 | const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 949 | struct mm_struct *mm, unsigned long va, |
| 950 | unsigned int cpu) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 951 | { |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 952 | int locals = 0; |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 953 | int remotes = 0; |
| 954 | int hubs = 0; |
Ingo Molnar | dc163a4 | 2008-06-18 14:15:43 +0200 | [diff] [blame] | 955 | struct bau_desc *bau_desc; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 956 | struct cpumask *flush_mask; |
| 957 | struct ptc_stats *stat; |
| 958 | struct bau_control *bcp; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 959 | |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 960 | /* kernel was booted 'nobau' */ |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 961 | if (nobau) |
| 962 | return cpumask; |
| 963 | |
| 964 | bcp = &per_cpu(bau_control, cpu); |
Cliff Wickman | 712157a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 965 | stat = bcp->statp; |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 966 | |
| 967 | /* bau was disabled due to slow response */ |
| 968 | if (bcp->baudisabled) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 969 | if (check_enable(bcp, stat)) |
| 970 | return cpumask; |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 971 | } |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 972 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 973 | /* |
| 974 | * Each sending cpu has a per-cpu mask which it fills from the caller's |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 975 | * cpu mask. All cpus are converted to uvhubs and copied to the |
| 976 | * activation descriptor. |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 977 | */ |
| 978 | flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu); |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 979 | /* don't actually do a shootdown of the local cpu */ |
Tejun Heo | bdbcdd4 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 980 | cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu)); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 981 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 982 | if (cpu_isset(cpu, *cpumask)) |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 983 | stat->s_ntargself++; |
Tejun Heo | bdbcdd4 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 984 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 985 | bau_desc = bcp->descriptor_base; |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 986 | bau_desc += (ITEMS_PER_DESC * bcp->uvhub_cpu); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 987 | bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 988 | if (set_distrib_bits(flush_mask, bcp, bau_desc, &locals, &remotes)) |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 989 | return NULL; |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 990 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 991 | record_send_statistics(stat, locals, hubs, remotes, bau_desc); |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 992 | |
| 993 | bau_desc->payload.address = va; |
Tejun Heo | bdbcdd4 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 994 | bau_desc->payload.sending_cpu = cpu; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 995 | /* |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 996 | * uv_flush_send_and_wait returns 0 if all cpu's were messaged, |
| 997 | * or 1 if it gave up and the original cpumask should be returned. |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 998 | */ |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 999 | if (!uv_flush_send_and_wait(bau_desc, flush_mask, bcp)) |
| 1000 | return NULL; |
| 1001 | else |
| 1002 | return cpumask; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /* |
| 1006 | * The BAU message interrupt comes here. (registered by set_intr_gate) |
| 1007 | * See entry_64.S |
| 1008 | * |
| 1009 | * We received a broadcast assist message. |
| 1010 | * |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1011 | * Interrupts are disabled; this interrupt could represent |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1012 | * the receipt of several messages. |
| 1013 | * |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1014 | * All cores/threads on this hub get this interrupt. |
| 1015 | * The last one to see it does the software ack. |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1016 | * (the resource will not be freed until noninterruptable cpus see this |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1017 | * interrupt; hardware may timeout the s/w ack and reply ERROR) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1018 | */ |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1019 | void uv_bau_message_interrupt(struct pt_regs *regs) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1020 | { |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1021 | int count = 0; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1022 | cycles_t time_start; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1023 | struct bau_pq_entry *msg; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1024 | struct bau_control *bcp; |
| 1025 | struct ptc_stats *stat; |
| 1026 | struct msg_desc msgdesc; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1027 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1028 | time_start = get_cycles(); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1029 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1030 | bcp = &per_cpu(bau_control, smp_processor_id()); |
Cliff Wickman | 712157a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1031 | stat = bcp->statp; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1032 | |
| 1033 | msgdesc.queue_first = bcp->queue_first; |
| 1034 | msgdesc.queue_last = bcp->queue_last; |
| 1035 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1036 | msg = bcp->bau_msg_head; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1037 | while (msg->swack_vec) { |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1038 | count++; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1039 | |
| 1040 | msgdesc.msg_slot = msg - msgdesc.queue_first; |
| 1041 | msgdesc.swack_slot = ffs(msg->swack_vec) - 1; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1042 | msgdesc.msg = msg; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1043 | bau_process_message(&msgdesc, bcp); |
| 1044 | |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1045 | msg++; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1046 | if (msg > msgdesc.queue_last) |
| 1047 | msg = msgdesc.queue_first; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1048 | bcp->bau_msg_head = msg; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1049 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1050 | stat->d_time += (get_cycles() - time_start); |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1051 | if (!count) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1052 | stat->d_nomsg++; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1053 | else if (count > 1) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1054 | stat->d_multmsg++; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1055 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1056 | ack_APIC_irq(); |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1057 | } |
| 1058 | |
Cliff Wickman | c4c4688 | 2009-04-03 08:34:32 -0500 | [diff] [blame] | 1059 | /* |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1060 | * Each target uvhub (i.e. a uvhub that has cpu's) needs to have |
Cliff Wickman | c4c4688 | 2009-04-03 08:34:32 -0500 | [diff] [blame] | 1061 | * shootdown message timeouts enabled. The timeout does not cause |
| 1062 | * an interrupt, but causes an error message to be returned to |
| 1063 | * the sender. |
| 1064 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1065 | static void __init enable_timeouts(void) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1066 | { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1067 | int uvhub; |
| 1068 | int nuvhubs; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1069 | int pnode; |
Cliff Wickman | c4c4688 | 2009-04-03 08:34:32 -0500 | [diff] [blame] | 1070 | unsigned long mmr_image; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1071 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1072 | nuvhubs = uv_num_possible_blades(); |
Cliff Wickman | c4c4688 | 2009-04-03 08:34:32 -0500 | [diff] [blame] | 1073 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1074 | for (uvhub = 0; uvhub < nuvhubs; uvhub++) { |
| 1075 | if (!uv_blade_nr_possible_cpus(uvhub)) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1076 | continue; |
Cliff Wickman | c4c4688 | 2009-04-03 08:34:32 -0500 | [diff] [blame] | 1077 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1078 | pnode = uv_blade_to_pnode(uvhub); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1079 | mmr_image = read_mmr_misc_control(pnode); |
Cliff Wickman | c4c4688 | 2009-04-03 08:34:32 -0500 | [diff] [blame] | 1080 | /* |
| 1081 | * Set the timeout period and then lock it in, in three |
| 1082 | * steps; captures and locks in the period. |
| 1083 | * |
| 1084 | * To program the period, the SOFT_ACK_MODE must be off. |
| 1085 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1086 | mmr_image &= ~(1L << SOFTACK_MSHIFT); |
| 1087 | write_mmr_misc_control(pnode, mmr_image); |
Cliff Wickman | c4c4688 | 2009-04-03 08:34:32 -0500 | [diff] [blame] | 1088 | /* |
| 1089 | * Set the 4-bit period. |
| 1090 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1091 | mmr_image &= ~((unsigned long)0xf << SOFTACK_PSHIFT); |
| 1092 | mmr_image |= (SOFTACK_TIMEOUT_PERIOD << SOFTACK_PSHIFT); |
| 1093 | write_mmr_misc_control(pnode, mmr_image); |
Cliff Wickman | c4c4688 | 2009-04-03 08:34:32 -0500 | [diff] [blame] | 1094 | /* |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 1095 | * UV1: |
Cliff Wickman | c4c4688 | 2009-04-03 08:34:32 -0500 | [diff] [blame] | 1096 | * Subsequent reversals of the timebase bit (3) cause an |
| 1097 | * immediate timeout of one or all INTD resources as |
| 1098 | * indicated in bits 2:0 (7 causes all of them to timeout). |
| 1099 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1100 | mmr_image |= (1L << SOFTACK_MSHIFT); |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 1101 | if (is_uv2_hub()) { |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 1102 | mmr_image &= ~(1L << UV2_LEG_SHFT); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1103 | mmr_image |= (1L << UV2_EXT_SHFT); |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 1104 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1105 | write_mmr_misc_control(pnode, mmr_image); |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1106 | } |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1107 | } |
| 1108 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1109 | static void *ptc_seq_start(struct seq_file *file, loff_t *offset) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1110 | { |
| 1111 | if (*offset < num_possible_cpus()) |
| 1112 | return offset; |
| 1113 | return NULL; |
| 1114 | } |
| 1115 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1116 | static void *ptc_seq_next(struct seq_file *file, void *data, loff_t *offset) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1117 | { |
| 1118 | (*offset)++; |
| 1119 | if (*offset < num_possible_cpus()) |
| 1120 | return offset; |
| 1121 | return NULL; |
| 1122 | } |
| 1123 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1124 | static void ptc_seq_stop(struct seq_file *file, void *data) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1125 | { |
| 1126 | } |
| 1127 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1128 | static inline unsigned long long usec_2_cycles(unsigned long microsec) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1129 | { |
| 1130 | unsigned long ns; |
| 1131 | unsigned long long cyc; |
| 1132 | |
Cliff Wickman | 12a6611 | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1133 | ns = microsec * 1000; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1134 | cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id())); |
| 1135 | return cyc; |
| 1136 | } |
| 1137 | |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1138 | /* |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1139 | * Display the statistics thru /proc/sgi_uv/ptc_statistics |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1140 | * 'data' points to the cpu number |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1141 | * Note: see the descriptions in stat_description[]. |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1142 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1143 | static int ptc_seq_show(struct seq_file *file, void *data) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1144 | { |
| 1145 | struct ptc_stats *stat; |
| 1146 | int cpu; |
| 1147 | |
| 1148 | cpu = *(loff_t *)data; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1149 | if (!cpu) { |
| 1150 | seq_printf(file, |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1151 | "# cpu sent stime self locals remotes ncpus localhub "); |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1152 | seq_printf(file, |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1153 | "remotehub numuvhubs numuvhubs16 numuvhubs8 "); |
| 1154 | seq_printf(file, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1155 | "numuvhubs4 numuvhubs2 numuvhubs1 dto retries rok "); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1156 | seq_printf(file, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1157 | "resetp resett giveup sto bz throt swack recv rtime "); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1158 | seq_printf(file, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1159 | "all one mult none retry canc nocan reset rcan "); |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1160 | seq_printf(file, |
| 1161 | "disable enable\n"); |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1162 | } |
| 1163 | if (cpu < num_possible_cpus() && cpu_online(cpu)) { |
| 1164 | stat = &per_cpu(ptcstats, cpu); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1165 | /* source side statistics */ |
| 1166 | seq_printf(file, |
| 1167 | "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ", |
| 1168 | cpu, stat->s_requestor, cycles_2_us(stat->s_time), |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1169 | stat->s_ntargself, stat->s_ntarglocals, |
| 1170 | stat->s_ntargremotes, stat->s_ntargcpu, |
| 1171 | stat->s_ntarglocaluvhub, stat->s_ntargremoteuvhub, |
| 1172 | stat->s_ntarguvhub, stat->s_ntarguvhub16); |
| 1173 | seq_printf(file, "%ld %ld %ld %ld %ld ", |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1174 | stat->s_ntarguvhub8, stat->s_ntarguvhub4, |
| 1175 | stat->s_ntarguvhub2, stat->s_ntarguvhub1, |
Cliff Wickman | 450a007 | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1176 | stat->s_dtimeout); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1177 | seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ", |
| 1178 | stat->s_retry_messages, stat->s_retriesok, |
| 1179 | stat->s_resets_plug, stat->s_resets_timeout, |
| 1180 | stat->s_giveup, stat->s_stimeout, |
| 1181 | stat->s_busy, stat->s_throttles); |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1182 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1183 | /* destination side statistics */ |
| 1184 | seq_printf(file, |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1185 | "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ", |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1186 | read_gmmr_sw_ack(uv_cpu_to_pnode(cpu)), |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1187 | stat->d_requestee, cycles_2_us(stat->d_time), |
| 1188 | stat->d_alltlb, stat->d_onetlb, stat->d_multmsg, |
| 1189 | stat->d_nomsg, stat->d_retries, stat->d_canceled, |
| 1190 | stat->d_nocanceled, stat->d_resets, |
| 1191 | stat->d_rcanceled); |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1192 | seq_printf(file, "%ld %ld\n", |
| 1193 | stat->s_bau_disabled, stat->s_bau_reenabled); |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1194 | } |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1195 | return 0; |
| 1196 | } |
| 1197 | |
| 1198 | /* |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1199 | * Display the tunables thru debugfs |
| 1200 | */ |
| 1201 | static ssize_t tunables_read(struct file *file, char __user *userbuf, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1202 | size_t count, loff_t *ppos) |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1203 | { |
Dan Carpenter | b365a85 | 2010-09-29 10:41:05 +0200 | [diff] [blame] | 1204 | char *buf; |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1205 | int ret; |
| 1206 | |
Dan Carpenter | b365a85 | 2010-09-29 10:41:05 +0200 | [diff] [blame] | 1207 | buf = kasprintf(GFP_KERNEL, "%s %s %s\n%d %d %d %d %d %d %d %d %d\n", |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1208 | "max_concur plugged_delay plugsb4reset", |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1209 | "timeoutsb4reset ipi_reset_limit complete_threshold", |
| 1210 | "congested_response_us congested_reps congested_period", |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1211 | max_concurr, plugged_delay, plugsb4reset, |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1212 | timeoutsb4reset, ipi_reset_limit, complete_threshold, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1213 | congested_respns_us, congested_reps, congested_period); |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1214 | |
Dan Carpenter | b365a85 | 2010-09-29 10:41:05 +0200 | [diff] [blame] | 1215 | if (!buf) |
| 1216 | return -ENOMEM; |
| 1217 | |
| 1218 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf)); |
| 1219 | kfree(buf); |
| 1220 | return ret; |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | /* |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1224 | * handle a write to /proc/sgi_uv/ptc_statistics |
| 1225 | * -1: reset the statistics |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1226 | * 0: display meaning of the statistics |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1227 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1228 | static ssize_t ptc_proc_write(struct file *file, const char __user *user, |
| 1229 | size_t count, loff_t *data) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1230 | { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1231 | int cpu; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1232 | int i; |
| 1233 | int elements; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1234 | long input_arg; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1235 | char optstr[64]; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1236 | struct ptc_stats *stat; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1237 | |
Cliff Wickman | e7eb872 | 2008-06-23 08:32:25 -0500 | [diff] [blame] | 1238 | if (count == 0 || count > sizeof(optstr)) |
Cliff Wickman | cef5327 | 2008-06-19 11:16:24 -0500 | [diff] [blame] | 1239 | return -EINVAL; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1240 | if (copy_from_user(optstr, user, count)) |
| 1241 | return -EFAULT; |
| 1242 | optstr[count - 1] = '\0'; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1243 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1244 | if (strict_strtol(optstr, 10, &input_arg) < 0) { |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1245 | printk(KERN_DEBUG "%s is invalid\n", optstr); |
| 1246 | return -EINVAL; |
| 1247 | } |
| 1248 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1249 | if (input_arg == 0) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1250 | elements = sizeof(stat_description)/sizeof(*stat_description); |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1251 | printk(KERN_DEBUG "# cpu: cpu number\n"); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1252 | printk(KERN_DEBUG "Sender statistics:\n"); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1253 | for (i = 0; i < elements; i++) |
| 1254 | printk(KERN_DEBUG "%s\n", stat_description[i]); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1255 | } else if (input_arg == -1) { |
| 1256 | for_each_present_cpu(cpu) { |
| 1257 | stat = &per_cpu(ptcstats, cpu); |
| 1258 | memset(stat, 0, sizeof(struct ptc_stats)); |
| 1259 | } |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | return count; |
| 1263 | } |
| 1264 | |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1265 | static int local_atoi(const char *name) |
| 1266 | { |
| 1267 | int val = 0; |
| 1268 | |
| 1269 | for (;; name++) { |
| 1270 | switch (*name) { |
| 1271 | case '0' ... '9': |
| 1272 | val = 10*val+(*name-'0'); |
| 1273 | break; |
| 1274 | default: |
| 1275 | return val; |
| 1276 | } |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | /* |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1281 | * Parse the values written to /sys/kernel/debug/sgi_uv/bau_tunables. |
| 1282 | * Zero values reset them to defaults. |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1283 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1284 | static int parse_tunables_write(struct bau_control *bcp, char *instr, |
| 1285 | int count) |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1286 | { |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1287 | char *p; |
| 1288 | char *q; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1289 | int cnt = 0; |
| 1290 | int val; |
| 1291 | int e = sizeof(tunables) / sizeof(*tunables); |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1292 | |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1293 | p = instr + strspn(instr, WHITESPACE); |
| 1294 | q = p; |
| 1295 | for (; *p; p = q + strspn(q, WHITESPACE)) { |
| 1296 | q = p + strcspn(p, WHITESPACE); |
| 1297 | cnt++; |
| 1298 | if (q == p) |
| 1299 | break; |
| 1300 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1301 | if (cnt != e) { |
| 1302 | printk(KERN_INFO "bau tunable error: should be %d values\n", e); |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1303 | return -EINVAL; |
| 1304 | } |
| 1305 | |
| 1306 | p = instr + strspn(instr, WHITESPACE); |
| 1307 | q = p; |
| 1308 | for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) { |
| 1309 | q = p + strcspn(p, WHITESPACE); |
| 1310 | val = local_atoi(p); |
| 1311 | switch (cnt) { |
| 1312 | case 0: |
| 1313 | if (val == 0) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1314 | max_concurr = MAX_BAU_CONCURRENT; |
| 1315 | max_concurr_const = MAX_BAU_CONCURRENT; |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1316 | continue; |
| 1317 | } |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1318 | if (val < 1 || val > bcp->cpus_in_uvhub) { |
| 1319 | printk(KERN_DEBUG |
| 1320 | "Error: BAU max concurrent %d is invalid\n", |
| 1321 | val); |
| 1322 | return -EINVAL; |
| 1323 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1324 | max_concurr = val; |
| 1325 | max_concurr_const = val; |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1326 | continue; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1327 | default: |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1328 | if (val == 0) |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1329 | *tunables[cnt].tunp = tunables[cnt].deflt; |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1330 | else |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1331 | *tunables[cnt].tunp = val; |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1332 | continue; |
| 1333 | } |
| 1334 | if (q == p) |
| 1335 | break; |
| 1336 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1337 | return 0; |
| 1338 | } |
| 1339 | |
| 1340 | /* |
| 1341 | * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables) |
| 1342 | */ |
| 1343 | static ssize_t tunables_write(struct file *file, const char __user *user, |
| 1344 | size_t count, loff_t *data) |
| 1345 | { |
| 1346 | int cpu; |
| 1347 | int ret; |
| 1348 | char instr[100]; |
| 1349 | struct bau_control *bcp; |
| 1350 | |
| 1351 | if (count == 0 || count > sizeof(instr)-1) |
| 1352 | return -EINVAL; |
| 1353 | if (copy_from_user(instr, user, count)) |
| 1354 | return -EFAULT; |
| 1355 | |
| 1356 | instr[count] = '\0'; |
| 1357 | |
cpw@sgi.com | 00b30cf | 2011-06-21 07:21:26 -0500 | [diff] [blame] | 1358 | cpu = get_cpu(); |
| 1359 | bcp = &per_cpu(bau_control, cpu); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1360 | ret = parse_tunables_write(bcp, instr, count); |
cpw@sgi.com | 00b30cf | 2011-06-21 07:21:26 -0500 | [diff] [blame] | 1361 | put_cpu(); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1362 | if (ret) |
| 1363 | return ret; |
| 1364 | |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1365 | for_each_present_cpu(cpu) { |
| 1366 | bcp = &per_cpu(bau_control, cpu); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1367 | bcp->max_concurr = max_concurr; |
| 1368 | bcp->max_concurr_const = max_concurr; |
| 1369 | bcp->plugged_delay = plugged_delay; |
| 1370 | bcp->plugsb4reset = plugsb4reset; |
| 1371 | bcp->timeoutsb4reset = timeoutsb4reset; |
| 1372 | bcp->ipi_reset_limit = ipi_reset_limit; |
| 1373 | bcp->complete_threshold = complete_threshold; |
| 1374 | bcp->cong_response_us = congested_respns_us; |
| 1375 | bcp->cong_reps = congested_reps; |
| 1376 | bcp->cong_period = congested_period; |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1377 | } |
| 1378 | return count; |
| 1379 | } |
| 1380 | |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1381 | static const struct seq_operations uv_ptc_seq_ops = { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1382 | .start = ptc_seq_start, |
| 1383 | .next = ptc_seq_next, |
| 1384 | .stop = ptc_seq_stop, |
| 1385 | .show = ptc_seq_show |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1386 | }; |
| 1387 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1388 | static int ptc_proc_open(struct inode *inode, struct file *file) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1389 | { |
| 1390 | return seq_open(file, &uv_ptc_seq_ops); |
| 1391 | } |
| 1392 | |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1393 | static int tunables_open(struct inode *inode, struct file *file) |
| 1394 | { |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1398 | static const struct file_operations proc_uv_ptc_operations = { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1399 | .open = ptc_proc_open, |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1400 | .read = seq_read, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1401 | .write = ptc_proc_write, |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1402 | .llseek = seq_lseek, |
| 1403 | .release = seq_release, |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1404 | }; |
| 1405 | |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1406 | static const struct file_operations tunables_fops = { |
| 1407 | .open = tunables_open, |
| 1408 | .read = tunables_read, |
| 1409 | .write = tunables_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1410 | .llseek = default_llseek, |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1411 | }; |
| 1412 | |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1413 | static int __init uv_ptc_init(void) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1414 | { |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1415 | struct proc_dir_entry *proc_uv_ptc; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1416 | |
| 1417 | if (!is_uv_system()) |
| 1418 | return 0; |
| 1419 | |
Alexey Dobriyan | 10f02d11 | 2009-08-23 23:17:27 +0400 | [diff] [blame] | 1420 | proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL, |
| 1421 | &proc_uv_ptc_operations); |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1422 | if (!proc_uv_ptc) { |
| 1423 | printk(KERN_ERR "unable to create %s proc entry\n", |
| 1424 | UV_PTC_BASENAME); |
| 1425 | return -EINVAL; |
| 1426 | } |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1427 | |
| 1428 | tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL); |
| 1429 | if (!tunables_dir) { |
| 1430 | printk(KERN_ERR "unable to create debugfs directory %s\n", |
| 1431 | UV_BAU_TUNABLES_DIR); |
| 1432 | return -EINVAL; |
| 1433 | } |
| 1434 | tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600, |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1435 | tunables_dir, NULL, &tunables_fops); |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1436 | if (!tunables_file) { |
| 1437 | printk(KERN_ERR "unable to create debugfs file %s\n", |
| 1438 | UV_BAU_TUNABLES_FILE); |
| 1439 | return -EINVAL; |
| 1440 | } |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1441 | return 0; |
| 1442 | } |
| 1443 | |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1444 | /* |
Cliff Wickman | 77ed23f | 2011-05-10 08:26:43 -0500 | [diff] [blame] | 1445 | * Initialize the sending side's sending buffers. |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1446 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1447 | static void activation_descriptor_init(int node, int pnode, int base_pnode) |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1448 | { |
| 1449 | int i; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1450 | int cpu; |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 1451 | int uv1 = 0; |
Jack Steiner | 6a469e4 | 2011-09-20 13:55:04 -0700 | [diff] [blame] | 1452 | unsigned long gpa; |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1453 | unsigned long m; |
| 1454 | unsigned long n; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1455 | size_t dsize; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1456 | struct bau_desc *bau_desc; |
| 1457 | struct bau_desc *bd2; |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 1458 | struct uv1_bau_msg_header *uv1_hdr; |
| 1459 | struct uv2_bau_msg_header *uv2_hdr; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1460 | struct bau_control *bcp; |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1461 | |
Cliff Wickman | 0e2595c | 2009-05-20 08:10:57 -0500 | [diff] [blame] | 1462 | /* |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1463 | * each bau_desc is 64 bytes; there are 8 (ITEMS_PER_DESC) |
| 1464 | * per cpu; and one per cpu on the uvhub (ADP_SZ) |
Cliff Wickman | 0e2595c | 2009-05-20 08:10:57 -0500 | [diff] [blame] | 1465 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1466 | dsize = sizeof(struct bau_desc) * ADP_SZ * ITEMS_PER_DESC; |
| 1467 | bau_desc = kmalloc_node(dsize, GFP_KERNEL, node); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1468 | BUG_ON(!bau_desc); |
Ingo Molnar | b4c286e | 2008-06-18 14:28:19 +0200 | [diff] [blame] | 1469 | |
Jack Steiner | 6a469e4 | 2011-09-20 13:55:04 -0700 | [diff] [blame] | 1470 | gpa = uv_gpa(bau_desc); |
| 1471 | n = uv_gpa_to_gnode(gpa); |
| 1472 | m = uv_gpa_to_offset(gpa); |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 1473 | if (is_uv1_hub()) |
| 1474 | uv1 = 1; |
Ingo Molnar | b4c286e | 2008-06-18 14:28:19 +0200 | [diff] [blame] | 1475 | |
Cliff Wickman | 77ed23f | 2011-05-10 08:26:43 -0500 | [diff] [blame] | 1476 | /* the 14-bit pnode */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1477 | write_mmr_descriptor_base(pnode, (n << UV_DESC_PSHIFT | m)); |
Cliff Wickman | 0e2595c | 2009-05-20 08:10:57 -0500 | [diff] [blame] | 1478 | /* |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1479 | * Initializing all 8 (ITEMS_PER_DESC) descriptors for each |
Cliff Wickman | 0e2595c | 2009-05-20 08:10:57 -0500 | [diff] [blame] | 1480 | * cpu even though we only use the first one; one descriptor can |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1481 | * describe a broadcast to 256 uv hubs. |
Cliff Wickman | 0e2595c | 2009-05-20 08:10:57 -0500 | [diff] [blame] | 1482 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1483 | for (i = 0, bd2 = bau_desc; i < (ADP_SZ * ITEMS_PER_DESC); i++, bd2++) { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1484 | memset(bd2, 0, sizeof(struct bau_desc)); |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 1485 | if (uv1) { |
| 1486 | uv1_hdr = &bd2->header.uv1_hdr; |
| 1487 | uv1_hdr->swack_flag = 1; |
| 1488 | /* |
| 1489 | * The base_dest_nasid set in the message header |
| 1490 | * is the nasid of the first uvhub in the partition. |
| 1491 | * The bit map will indicate destination pnode numbers |
| 1492 | * relative to that base. They may not be consecutive |
| 1493 | * if nasid striding is being used. |
| 1494 | */ |
| 1495 | uv1_hdr->base_dest_nasid = |
| 1496 | UV_PNODE_TO_NASID(base_pnode); |
| 1497 | uv1_hdr->dest_subnodeid = UV_LB_SUBNODEID; |
| 1498 | uv1_hdr->command = UV_NET_ENDPOINT_INTD; |
| 1499 | uv1_hdr->int_both = 1; |
| 1500 | /* |
| 1501 | * all others need to be set to zero: |
| 1502 | * fairness chaining multilevel count replied_to |
| 1503 | */ |
| 1504 | } else { |
| 1505 | uv2_hdr = &bd2->header.uv2_hdr; |
| 1506 | uv2_hdr->swack_flag = 1; |
| 1507 | uv2_hdr->base_dest_nasid = |
| 1508 | UV_PNODE_TO_NASID(base_pnode); |
| 1509 | uv2_hdr->dest_subnodeid = UV_LB_SUBNODEID; |
| 1510 | uv2_hdr->command = UV_NET_ENDPOINT_INTD; |
| 1511 | } |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1512 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1513 | for_each_present_cpu(cpu) { |
| 1514 | if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu))) |
| 1515 | continue; |
| 1516 | bcp = &per_cpu(bau_control, cpu); |
| 1517 | bcp->descriptor_base = bau_desc; |
| 1518 | } |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /* |
| 1522 | * initialize the destination side's receiving buffers |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1523 | * entered for each uvhub in the partition |
| 1524 | * - node is first node (kernel memory notion) on the uvhub |
| 1525 | * - pnode is the uvhub's physical identifier |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1526 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1527 | static void pq_init(int node, int pnode) |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1528 | { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1529 | int cpu; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1530 | size_t plsize; |
Ingo Molnar | b4c286e | 2008-06-18 14:28:19 +0200 | [diff] [blame] | 1531 | char *cp; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1532 | void *vp; |
| 1533 | unsigned long pn; |
| 1534 | unsigned long first; |
| 1535 | unsigned long pn_first; |
| 1536 | unsigned long last; |
| 1537 | struct bau_pq_entry *pqp; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1538 | struct bau_control *bcp; |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1539 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1540 | plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry); |
| 1541 | vp = kmalloc_node(plsize, GFP_KERNEL, node); |
| 1542 | pqp = (struct bau_pq_entry *)vp; |
Ingo Molnar | dc163a4 | 2008-06-18 14:15:43 +0200 | [diff] [blame] | 1543 | BUG_ON(!pqp); |
Ingo Molnar | b4c286e | 2008-06-18 14:28:19 +0200 | [diff] [blame] | 1544 | |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1545 | cp = (char *)pqp + 31; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1546 | pqp = (struct bau_pq_entry *)(((unsigned long)cp >> 5) << 5); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1547 | |
| 1548 | for_each_present_cpu(cpu) { |
| 1549 | if (pnode != uv_cpu_to_pnode(cpu)) |
| 1550 | continue; |
| 1551 | /* for every cpu on this pnode: */ |
| 1552 | bcp = &per_cpu(bau_control, cpu); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1553 | bcp->queue_first = pqp; |
| 1554 | bcp->bau_msg_head = pqp; |
| 1555 | bcp->queue_last = pqp + (DEST_Q_SIZE - 1); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1556 | } |
Cliff Wickman | 4ea3c51 | 2009-04-16 07:53:09 -0500 | [diff] [blame] | 1557 | /* |
Jack Steiner | 6a469e4 | 2011-09-20 13:55:04 -0700 | [diff] [blame] | 1558 | * need the gnode of where the memory was really allocated |
Cliff Wickman | 4ea3c51 | 2009-04-16 07:53:09 -0500 | [diff] [blame] | 1559 | */ |
Jack Steiner | 6a469e4 | 2011-09-20 13:55:04 -0700 | [diff] [blame] | 1560 | pn = uv_gpa_to_gnode(uv_gpa(pqp)); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1561 | first = uv_physnodeaddr(pqp); |
| 1562 | pn_first = ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) | first; |
| 1563 | last = uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1)); |
| 1564 | write_mmr_payload_first(pnode, pn_first); |
| 1565 | write_mmr_payload_tail(pnode, first); |
| 1566 | write_mmr_payload_last(pnode, last); |
| 1567 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1568 | /* in effect, all msg_type's are set to MSG_NOOP */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1569 | memset(pqp, 0, sizeof(struct bau_pq_entry) * DEST_Q_SIZE); |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | /* |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1573 | * Initialization of each UV hub's structures |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1574 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1575 | static void __init init_uvhub(int uvhub, int vector, int base_pnode) |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1576 | { |
Cliff Wickman | 9674f35 | 2009-04-03 08:34:05 -0500 | [diff] [blame] | 1577 | int node; |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1578 | int pnode; |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1579 | unsigned long apicid; |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1580 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1581 | node = uvhub_to_first_node(uvhub); |
| 1582 | pnode = uv_blade_to_pnode(uvhub); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1583 | |
| 1584 | activation_descriptor_init(node, pnode, base_pnode); |
| 1585 | |
| 1586 | pq_init(node, pnode); |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1587 | /* |
Cliff Wickman | 77ed23f | 2011-05-10 08:26:43 -0500 | [diff] [blame] | 1588 | * The below initialization can't be in firmware because the |
| 1589 | * messaging IRQ will be determined by the OS. |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1590 | */ |
Dimitri Sivanich | 8191c9f | 2010-11-16 16:23:52 -0600 | [diff] [blame] | 1591 | apicid = uvhub_to_first_apicid(uvhub) | uv_apicid_hibits; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1592 | write_mmr_data_config(pnode, ((apicid << 32) | vector)); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | /* |
Cliff Wickman | 12a6611 | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1596 | * We will set BAU_MISC_CONTROL with a timeout period. |
| 1597 | * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT. |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1598 | * So the destination timeout period has to be calculated from them. |
Cliff Wickman | 12a6611 | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1599 | */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1600 | static int calculate_destination_timeout(void) |
Cliff Wickman | 12a6611 | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1601 | { |
| 1602 | unsigned long mmr_image; |
| 1603 | int mult1; |
| 1604 | int mult2; |
| 1605 | int index; |
| 1606 | int base; |
| 1607 | int ret; |
| 1608 | unsigned long ts_ns; |
| 1609 | |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 1610 | if (is_uv1_hub()) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1611 | mult1 = SOFTACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK; |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 1612 | mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL); |
| 1613 | index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK; |
| 1614 | mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT); |
| 1615 | mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK; |
| 1616 | base = timeout_base_ns[index]; |
| 1617 | ts_ns = base * mult1 * mult2; |
| 1618 | ret = ts_ns / 1000; |
| 1619 | } else { |
| 1620 | /* 4 bits 0/1 for 10/80us, 3 bits of multiplier */ |
| 1621 | mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL); |
| 1622 | mmr_image = (mmr_image & UV_SA_MASK) >> UV_SA_SHFT; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1623 | if (mmr_image & (1L << UV2_ACK_UNITS_SHFT)) |
Jack Steiner | 2a91959 | 2011-05-11 12:50:28 -0500 | [diff] [blame] | 1624 | mult1 = 80; |
| 1625 | else |
| 1626 | mult1 = 10; |
| 1627 | base = mmr_image & UV2_ACK_MASK; |
| 1628 | ret = mult1 * base; |
| 1629 | } |
Cliff Wickman | 12a6611 | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1630 | return ret; |
| 1631 | } |
| 1632 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1633 | static void __init init_per_cpu_tunables(void) |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1634 | { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1635 | int cpu; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1636 | struct bau_control *bcp; |
| 1637 | |
| 1638 | for_each_present_cpu(cpu) { |
| 1639 | bcp = &per_cpu(bau_control, cpu); |
| 1640 | bcp->baudisabled = 0; |
| 1641 | bcp->statp = &per_cpu(ptcstats, cpu); |
| 1642 | /* time interval to catch a hardware stay-busy bug */ |
| 1643 | bcp->timeout_interval = usec_2_cycles(2*timeout_us); |
| 1644 | bcp->max_concurr = max_concurr; |
| 1645 | bcp->max_concurr_const = max_concurr; |
| 1646 | bcp->plugged_delay = plugged_delay; |
| 1647 | bcp->plugsb4reset = plugsb4reset; |
| 1648 | bcp->timeoutsb4reset = timeoutsb4reset; |
| 1649 | bcp->ipi_reset_limit = ipi_reset_limit; |
| 1650 | bcp->complete_threshold = complete_threshold; |
| 1651 | bcp->cong_response_us = congested_respns_us; |
| 1652 | bcp->cong_reps = congested_reps; |
| 1653 | bcp->cong_period = congested_period; |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | /* |
| 1658 | * Scan all cpus to collect blade and socket summaries. |
| 1659 | */ |
| 1660 | static int __init get_cpu_topology(int base_pnode, |
| 1661 | struct uvhub_desc *uvhub_descs, |
| 1662 | unsigned char *uvhub_mask) |
| 1663 | { |
| 1664 | int cpu; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1665 | int pnode; |
| 1666 | int uvhub; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1667 | int socket; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1668 | struct bau_control *bcp; |
| 1669 | struct uvhub_desc *bdp; |
| 1670 | struct socket_desc *sdp; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1671 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1672 | for_each_present_cpu(cpu) { |
| 1673 | bcp = &per_cpu(bau_control, cpu); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1674 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1675 | memset(bcp, 0, sizeof(struct bau_control)); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1676 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1677 | pnode = uv_cpu_hub_info(cpu)->pnode; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1678 | if ((pnode - base_pnode) >= UV_DISTRIBUTION_SIZE) { |
Cliff Wickman | 77ed23f | 2011-05-10 08:26:43 -0500 | [diff] [blame] | 1679 | printk(KERN_EMERG |
| 1680 | "cpu %d pnode %d-%d beyond %d; BAU disabled\n", |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1681 | cpu, pnode, base_pnode, UV_DISTRIBUTION_SIZE); |
Cliff Wickman | 77ed23f | 2011-05-10 08:26:43 -0500 | [diff] [blame] | 1682 | return 1; |
| 1683 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1684 | |
Cliff Wickman | 77ed23f | 2011-05-10 08:26:43 -0500 | [diff] [blame] | 1685 | bcp->osnode = cpu_to_node(cpu); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1686 | bcp->partition_base_pnode = base_pnode; |
| 1687 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1688 | uvhub = uv_cpu_hub_info(cpu)->numa_blade_id; |
Cliff Wickman | c4026cf | 2010-07-30 14:10:55 -0500 | [diff] [blame] | 1689 | *(uvhub_mask + (uvhub/8)) |= (1 << (uvhub%8)); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1690 | bdp = &uvhub_descs[uvhub]; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1691 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1692 | bdp->num_cpus++; |
| 1693 | bdp->uvhub = uvhub; |
| 1694 | bdp->pnode = pnode; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1695 | |
Cliff Wickman | a8328ee | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1696 | /* kludge: 'assuming' one node per socket, and assuming that |
| 1697 | disabling a socket just leaves a gap in node numbers */ |
Cliff Wickman | 77ed23f | 2011-05-10 08:26:43 -0500 | [diff] [blame] | 1698 | socket = bcp->osnode & 1; |
Cliff Wickman | a8328ee | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1699 | bdp->socket_mask |= (1 << socket); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1700 | sdp = &bdp->socket[socket]; |
| 1701 | sdp->cpu_number[sdp->num_cpus] = cpu; |
| 1702 | sdp->num_cpus++; |
Cliff Wickman | cfa6091 | 2011-01-03 12:03:53 -0600 | [diff] [blame] | 1703 | if (sdp->num_cpus > MAX_CPUS_PER_SOCKET) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1704 | printk(KERN_EMERG "%d cpus per socket invalid\n", |
| 1705 | sdp->num_cpus); |
Cliff Wickman | cfa6091 | 2011-01-03 12:03:53 -0600 | [diff] [blame] | 1706 | return 1; |
| 1707 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1708 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1709 | return 0; |
| 1710 | } |
| 1711 | |
| 1712 | /* |
| 1713 | * Each socket is to get a local array of pnodes/hubs. |
| 1714 | */ |
| 1715 | static void make_per_cpu_thp(struct bau_control *smaster) |
| 1716 | { |
| 1717 | int cpu; |
| 1718 | size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus(); |
| 1719 | |
| 1720 | smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode); |
| 1721 | memset(smaster->thp, 0, hpsz); |
| 1722 | for_each_present_cpu(cpu) { |
| 1723 | smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode; |
| 1724 | smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id; |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | /* |
cpw@sgi.com | 442d392 | 2011-06-21 07:21:31 -0500 | [diff] [blame] | 1729 | * Each uvhub is to get a local cpumask. |
| 1730 | */ |
| 1731 | static void make_per_hub_cpumask(struct bau_control *hmaster) |
| 1732 | { |
| 1733 | int sz = sizeof(cpumask_t); |
| 1734 | |
| 1735 | hmaster->cpumask = kzalloc_node(sz, GFP_KERNEL, hmaster->osnode); |
| 1736 | } |
| 1737 | |
| 1738 | /* |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1739 | * Initialize all the per_cpu information for the cpu's on a given socket, |
| 1740 | * given what has been gathered into the socket_desc struct. |
| 1741 | * And reports the chosen hub and socket masters back to the caller. |
| 1742 | */ |
| 1743 | static int scan_sock(struct socket_desc *sdp, struct uvhub_desc *bdp, |
| 1744 | struct bau_control **smasterp, |
| 1745 | struct bau_control **hmasterp) |
| 1746 | { |
| 1747 | int i; |
| 1748 | int cpu; |
| 1749 | struct bau_control *bcp; |
| 1750 | |
| 1751 | for (i = 0; i < sdp->num_cpus; i++) { |
| 1752 | cpu = sdp->cpu_number[i]; |
| 1753 | bcp = &per_cpu(bau_control, cpu); |
| 1754 | bcp->cpu = cpu; |
| 1755 | if (i == 0) { |
| 1756 | *smasterp = bcp; |
| 1757 | if (!(*hmasterp)) |
| 1758 | *hmasterp = bcp; |
| 1759 | } |
| 1760 | bcp->cpus_in_uvhub = bdp->num_cpus; |
| 1761 | bcp->cpus_in_socket = sdp->num_cpus; |
| 1762 | bcp->socket_master = *smasterp; |
| 1763 | bcp->uvhub = bdp->uvhub; |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 1764 | if (is_uv1_hub()) |
| 1765 | bcp->uvhub_version = 1; |
| 1766 | else if (is_uv2_hub()) |
| 1767 | bcp->uvhub_version = 2; |
| 1768 | else { |
| 1769 | printk(KERN_EMERG "uvhub version not 1 or 2\n"); |
| 1770 | return 1; |
| 1771 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1772 | bcp->uvhub_master = *hmasterp; |
| 1773 | bcp->uvhub_cpu = uv_cpu_hub_info(cpu)->blade_processor_id; |
| 1774 | if (bcp->uvhub_cpu >= MAX_CPUS_PER_UVHUB) { |
| 1775 | printk(KERN_EMERG "%d cpus per uvhub invalid\n", |
| 1776 | bcp->uvhub_cpu); |
| 1777 | return 1; |
| 1778 | } |
| 1779 | } |
| 1780 | return 0; |
| 1781 | } |
| 1782 | |
| 1783 | /* |
| 1784 | * Summarize the blade and socket topology into the per_cpu structures. |
| 1785 | */ |
| 1786 | static int __init summarize_uvhub_sockets(int nuvhubs, |
| 1787 | struct uvhub_desc *uvhub_descs, |
| 1788 | unsigned char *uvhub_mask) |
| 1789 | { |
| 1790 | int socket; |
| 1791 | int uvhub; |
| 1792 | unsigned short socket_mask; |
| 1793 | |
Cliff Wickman | c4026cf | 2010-07-30 14:10:55 -0500 | [diff] [blame] | 1794 | for (uvhub = 0; uvhub < nuvhubs; uvhub++) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1795 | struct uvhub_desc *bdp; |
| 1796 | struct bau_control *smaster = NULL; |
| 1797 | struct bau_control *hmaster = NULL; |
| 1798 | |
Cliff Wickman | c4026cf | 2010-07-30 14:10:55 -0500 | [diff] [blame] | 1799 | if (!(*(uvhub_mask + (uvhub/8)) & (1 << (uvhub%8)))) |
| 1800 | continue; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1801 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1802 | bdp = &uvhub_descs[uvhub]; |
Cliff Wickman | a8328ee | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1803 | socket_mask = bdp->socket_mask; |
| 1804 | socket = 0; |
| 1805 | while (socket_mask) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1806 | struct socket_desc *sdp; |
| 1807 | if ((socket_mask & 1)) { |
| 1808 | sdp = &bdp->socket[socket]; |
| 1809 | if (scan_sock(sdp, bdp, &smaster, &hmaster)) |
Cliff Wickman | cfa6091 | 2011-01-03 12:03:53 -0600 | [diff] [blame] | 1810 | return 1; |
cpw@sgi.com | 9c9153d | 2011-06-21 07:21:28 -0500 | [diff] [blame] | 1811 | make_per_cpu_thp(smaster); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1812 | } |
| 1813 | socket++; |
Cliff Wickman | a8328ee | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1814 | socket_mask = (socket_mask >> 1); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1815 | } |
cpw@sgi.com | 442d392 | 2011-06-21 07:21:31 -0500 | [diff] [blame] | 1816 | make_per_hub_cpumask(hmaster); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1817 | } |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1818 | return 0; |
| 1819 | } |
| 1820 | |
| 1821 | /* |
| 1822 | * initialize the bau_control structure for each cpu |
| 1823 | */ |
| 1824 | static int __init init_per_cpu(int nuvhubs, int base_part_pnode) |
| 1825 | { |
| 1826 | unsigned char *uvhub_mask; |
| 1827 | void *vp; |
| 1828 | struct uvhub_desc *uvhub_descs; |
| 1829 | |
| 1830 | timeout_us = calculate_destination_timeout(); |
| 1831 | |
| 1832 | vp = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL); |
| 1833 | uvhub_descs = (struct uvhub_desc *)vp; |
| 1834 | memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc)); |
| 1835 | uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL); |
| 1836 | |
| 1837 | if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask)) |
cpw@sgi.com | bbd270e | 2011-06-21 07:21:32 -0500 | [diff] [blame] | 1838 | goto fail; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1839 | |
| 1840 | if (summarize_uvhub_sockets(nuvhubs, uvhub_descs, uvhub_mask)) |
cpw@sgi.com | bbd270e | 2011-06-21 07:21:32 -0500 | [diff] [blame] | 1841 | goto fail; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1842 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1843 | kfree(uvhub_descs); |
Cliff Wickman | c4026cf | 2010-07-30 14:10:55 -0500 | [diff] [blame] | 1844 | kfree(uvhub_mask); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1845 | init_per_cpu_tunables(); |
Cliff Wickman | cfa6091 | 2011-01-03 12:03:53 -0600 | [diff] [blame] | 1846 | return 0; |
cpw@sgi.com | bbd270e | 2011-06-21 07:21:32 -0500 | [diff] [blame] | 1847 | |
| 1848 | fail: |
| 1849 | kfree(uvhub_descs); |
| 1850 | kfree(uvhub_mask); |
| 1851 | return 1; |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1852 | } |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1853 | |
| 1854 | /* |
| 1855 | * Initialization of BAU-related structures |
| 1856 | */ |
Cliff Wickman | b194b120 | 2008-06-12 08:23:48 -0500 | [diff] [blame] | 1857 | static int __init uv_bau_init(void) |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1858 | { |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1859 | int uvhub; |
| 1860 | int pnode; |
| 1861 | int nuvhubs; |
Rusty Russell | 2c74d66 | 2009-03-18 08:22:30 +1030 | [diff] [blame] | 1862 | int cur_cpu; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1863 | int cpus; |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1864 | int vector; |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1865 | cpumask_var_t *mask; |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1866 | |
| 1867 | if (!is_uv_system()) |
| 1868 | return 0; |
| 1869 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1870 | if (nobau) |
| 1871 | return 0; |
| 1872 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1873 | for_each_possible_cpu(cur_cpu) { |
| 1874 | mask = &per_cpu(uv_flush_tlb_mask, cur_cpu); |
| 1875 | zalloc_cpumask_var_node(mask, GFP_KERNEL, cpu_to_node(cur_cpu)); |
| 1876 | } |
Rusty Russell | 76ba0ec | 2009-03-13 14:49:57 +1030 | [diff] [blame] | 1877 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1878 | nuvhubs = uv_num_possible_blades(); |
Cliff Wickman | 50fb55a | 2010-06-02 16:22:02 -0500 | [diff] [blame] | 1879 | spin_lock_init(&disable_lock); |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1880 | congested_cycles = usec_2_cycles(congested_respns_us); |
Cliff Wickman | 9674f35 | 2009-04-03 08:34:05 -0500 | [diff] [blame] | 1881 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1882 | uv_base_pnode = 0x7fffffff; |
Cliff Wickman | 77ed23f | 2011-05-10 08:26:43 -0500 | [diff] [blame] | 1883 | for (uvhub = 0; uvhub < nuvhubs; uvhub++) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1884 | cpus = uv_blade_nr_possible_cpus(uvhub); |
| 1885 | if (cpus && (uv_blade_to_pnode(uvhub) < uv_base_pnode)) |
| 1886 | uv_base_pnode = uv_blade_to_pnode(uvhub); |
Cliff Wickman | 77ed23f | 2011-05-10 08:26:43 -0500 | [diff] [blame] | 1887 | } |
| 1888 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1889 | if (init_per_cpu(nuvhubs, uv_base_pnode)) { |
Cliff Wickman | cfa6091 | 2011-01-03 12:03:53 -0600 | [diff] [blame] | 1890 | nobau = 1; |
| 1891 | return 0; |
| 1892 | } |
Ingo Molnar | b4c286e | 2008-06-18 14:28:19 +0200 | [diff] [blame] | 1893 | |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1894 | vector = UV_BAU_MESSAGE; |
| 1895 | for_each_possible_blade(uvhub) |
| 1896 | if (uv_blade_nr_possible_cpus(uvhub)) |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1897 | init_uvhub(uvhub, vector, uv_base_pnode); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1898 | |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1899 | enable_timeouts(); |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1900 | alloc_intr_gate(vector, uv_bau_message_intr1); |
| 1901 | |
| 1902 | for_each_possible_blade(uvhub) { |
Cliff Wickman | 93a7ca0 | 2010-07-16 10:11:21 -0500 | [diff] [blame] | 1903 | if (uv_blade_nr_possible_cpus(uvhub)) { |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1904 | unsigned long val; |
| 1905 | unsigned long mmr; |
Cliff Wickman | 93a7ca0 | 2010-07-16 10:11:21 -0500 | [diff] [blame] | 1906 | pnode = uv_blade_to_pnode(uvhub); |
| 1907 | /* INIT the bau */ |
Cliff Wickman | f073cc8 | 2011-05-24 13:07:36 -0500 | [diff] [blame] | 1908 | val = 1L << 63; |
| 1909 | write_gmmr_activation(pnode, val); |
Cliff Wickman | 93a7ca0 | 2010-07-16 10:11:21 -0500 | [diff] [blame] | 1910 | mmr = 1; /* should be 1 to broadcast to both sockets */ |
Cliff Wickman | da87c93 | 2012-01-16 15:17:50 -0600 | [diff] [blame^] | 1911 | if (!is_uv1_hub()) |
| 1912 | write_mmr_data_broadcast(pnode, mmr); |
Cliff Wickman | 93a7ca0 | 2010-07-16 10:11:21 -0500 | [diff] [blame] | 1913 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1914 | } |
Ingo Molnar | b4c286e | 2008-06-18 14:28:19 +0200 | [diff] [blame] | 1915 | |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 1916 | return 0; |
| 1917 | } |
Cliff Wickman | b8f7fb1 | 2010-04-14 11:35:46 -0500 | [diff] [blame] | 1918 | core_initcall(uv_bau_init); |
Cliff Wickman | e8e5e8a | 2010-06-02 16:22:01 -0500 | [diff] [blame] | 1919 | fs_initcall(uv_ptc_init); |