Commit | Line | Data |
---|---|---|
77241056 | 1 | /* |
3ca4fbc8 | 2 | * Copyright(c) 2015-2017 Intel Corporation. |
77241056 MM |
3 | * |
4 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
5 | * redistributing this file, you may do so under either license. | |
6 | * | |
7 | * GPL LICENSE SUMMARY | |
8 | * | |
77241056 MM |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of version 2 of the GNU General Public License as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * BSD LICENSE | |
19 | * | |
77241056 MM |
20 | * Redistribution and use in source and binary forms, with or without |
21 | * modification, are permitted provided that the following conditions | |
22 | * are met: | |
23 | * | |
24 | * - Redistributions of source code must retain the above copyright | |
25 | * notice, this list of conditions and the following disclaimer. | |
26 | * - Redistributions in binary form must reproduce the above copyright | |
27 | * notice, this list of conditions and the following disclaimer in | |
28 | * the documentation and/or other materials provided with the | |
29 | * distribution. | |
30 | * - Neither the name of Intel Corporation nor the names of its | |
31 | * contributors may be used to endorse or promote products derived | |
32 | * from this software without specific prior written permission. | |
33 | * | |
34 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
35 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
37 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
38 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
39 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
40 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
41 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
42 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
43 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
45 | * | |
46 | */ | |
47 | ||
48 | #include <linux/net.h> | |
13c19222 | 49 | #include <rdma/opa_addr.h> |
77241056 MM |
50 | #define OPA_NUM_PKEY_BLOCKS_PER_SMP (OPA_SMP_DR_DATA_SIZE \ |
51 | / (OPA_PARTITION_TABLE_BLK_SIZE * sizeof(u16))) | |
52 | ||
53 | #include "hfi.h" | |
54 | #include "mad.h" | |
55 | #include "trace.h" | |
0ec79e87 | 56 | #include "qp.h" |
2280740f | 57 | #include "vnic.h" |
77241056 MM |
58 | |
59 | /* the reset value from the FM is supposed to be 0xffff, handle both */ | |
60 | #define OPA_LINK_WIDTH_RESET_OLD 0x0fff | |
61 | #define OPA_LINK_WIDTH_RESET 0xffff | |
62 | ||
bf90aadd MR |
63 | struct trap_node { |
64 | struct list_head list; | |
65 | struct opa_mad_notice_attr data; | |
66 | __be64 tid; | |
67 | int len; | |
68 | u32 retry; | |
69 | u8 in_use; | |
70 | u8 repress; | |
71 | }; | |
72 | ||
f1685179 ND |
73 | static int smp_length_check(u32 data_size, u32 request_len) |
74 | { | |
75 | if (unlikely(request_len < data_size)) | |
76 | return -EINVAL; | |
77 | ||
78 | return 0; | |
79 | } | |
80 | ||
77241056 MM |
81 | static int reply(struct ib_mad_hdr *smp) |
82 | { | |
83 | /* | |
84 | * The verbs framework will handle the directed/LID route | |
85 | * packet changes. | |
86 | */ | |
87 | smp->method = IB_MGMT_METHOD_GET_RESP; | |
88 | if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) | |
89 | smp->status |= IB_SMP_DIRECTION; | |
90 | return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY; | |
91 | } | |
92 | ||
93 | static inline void clear_opa_smp_data(struct opa_smp *smp) | |
94 | { | |
95 | void *data = opa_get_smp_data(smp); | |
96 | size_t size = opa_get_smp_data_size(smp); | |
97 | ||
98 | memset(data, 0, size); | |
99 | } | |
100 | ||
406310c6 SS |
101 | static u16 hfi1_lookup_pkey_value(struct hfi1_ibport *ibp, int pkey_idx) |
102 | { | |
103 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
104 | ||
105 | if (pkey_idx < ARRAY_SIZE(ppd->pkeys)) | |
106 | return ppd->pkeys[pkey_idx]; | |
107 | ||
108 | return 0; | |
109 | } | |
110 | ||
34d351f8 SS |
111 | void hfi1_event_pkey_change(struct hfi1_devdata *dd, u8 port) |
112 | { | |
113 | struct ib_event event; | |
114 | ||
115 | event.event = IB_EVENT_PKEY_CHANGE; | |
116 | event.device = &dd->verbs_dev.rdi.ibdev; | |
117 | event.element.port_num = port; | |
118 | ib_dispatch_event(&event); | |
119 | } | |
120 | ||
bf90aadd MR |
121 | /* |
122 | * If the port is down, clean up all pending traps. We need to be careful | |
123 | * with the given trap, because it may be queued. | |
124 | */ | |
125 | static void cleanup_traps(struct hfi1_ibport *ibp, struct trap_node *trap) | |
126 | { | |
127 | struct trap_node *node, *q; | |
128 | unsigned long flags; | |
129 | struct list_head trap_list; | |
130 | int i; | |
131 | ||
132 | for (i = 0; i < RVT_MAX_TRAP_LISTS; i++) { | |
133 | spin_lock_irqsave(&ibp->rvp.lock, flags); | |
134 | list_replace_init(&ibp->rvp.trap_lists[i].list, &trap_list); | |
135 | ibp->rvp.trap_lists[i].list_len = 0; | |
136 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); | |
137 | ||
138 | /* | |
139 | * Remove all items from the list, freeing all the non-given | |
140 | * traps. | |
141 | */ | |
142 | list_for_each_entry_safe(node, q, &trap_list, list) { | |
143 | list_del(&node->list); | |
144 | if (node != trap) | |
145 | kfree(node); | |
146 | } | |
147 | } | |
148 | ||
149 | /* | |
150 | * If this wasn't on one of the lists it would not be freed. If it | |
151 | * was on the list, it is now safe to free. | |
152 | */ | |
153 | kfree(trap); | |
154 | } | |
155 | ||
156 | static struct trap_node *check_and_add_trap(struct hfi1_ibport *ibp, | |
157 | struct trap_node *trap) | |
158 | { | |
159 | struct trap_node *node; | |
160 | struct trap_list *trap_list; | |
161 | unsigned long flags; | |
162 | unsigned long timeout; | |
163 | int found = 0; | |
ec0d8b8a KA |
164 | unsigned int queue_id; |
165 | static int trap_count; | |
166 | ||
167 | queue_id = trap->data.generic_type & 0x0F; | |
168 | if (queue_id >= RVT_MAX_TRAP_LISTS) { | |
169 | trap_count++; | |
170 | pr_err_ratelimited("hfi1: Invalid trap 0x%0x dropped. Total dropped: %d\n", | |
d68e68e5 | 171 | trap->data.generic_type, trap_count); |
ec0d8b8a KA |
172 | kfree(trap); |
173 | return NULL; | |
174 | } | |
bf90aadd MR |
175 | |
176 | /* | |
177 | * Since the retry (handle timeout) does not remove a trap request | |
178 | * from the list, all we have to do is compare the node. | |
179 | */ | |
180 | spin_lock_irqsave(&ibp->rvp.lock, flags); | |
ec0d8b8a | 181 | trap_list = &ibp->rvp.trap_lists[queue_id]; |
bf90aadd MR |
182 | |
183 | list_for_each_entry(node, &trap_list->list, list) { | |
184 | if (node == trap) { | |
185 | node->retry++; | |
186 | found = 1; | |
187 | break; | |
188 | } | |
189 | } | |
190 | ||
191 | /* If it is not on the list, add it, limited to RVT-MAX_TRAP_LEN. */ | |
192 | if (!found) { | |
193 | if (trap_list->list_len < RVT_MAX_TRAP_LEN) { | |
194 | trap_list->list_len++; | |
195 | list_add_tail(&trap->list, &trap_list->list); | |
196 | } else { | |
028e0a67 | 197 | pr_warn_ratelimited("hfi1: Maximum trap limit reached for 0x%0x traps\n", |
bf90aadd MR |
198 | trap->data.generic_type); |
199 | kfree(trap); | |
200 | } | |
201 | } | |
202 | ||
203 | /* | |
204 | * Next check to see if there is a timer pending. If not, set it up | |
205 | * and get the first trap from the list. | |
206 | */ | |
207 | node = NULL; | |
208 | if (!timer_pending(&ibp->rvp.trap_timer)) { | |
209 | /* | |
210 | * o14-2 | |
211 | * If the time out is set we have to wait until it expires | |
212 | * before the trap can be sent. | |
213 | * This should be > RVT_TRAP_TIMEOUT | |
214 | */ | |
215 | timeout = (RVT_TRAP_TIMEOUT * | |
216 | (1UL << ibp->rvp.subnet_timeout)) / 1000; | |
217 | mod_timer(&ibp->rvp.trap_timer, | |
218 | jiffies + usecs_to_jiffies(timeout)); | |
219 | node = list_first_entry(&trap_list->list, struct trap_node, | |
220 | list); | |
221 | node->in_use = 1; | |
222 | } | |
223 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); | |
224 | ||
225 | return node; | |
226 | } | |
227 | ||
228 | static void subn_handle_opa_trap_repress(struct hfi1_ibport *ibp, | |
229 | struct opa_smp *smp) | |
230 | { | |
231 | struct trap_list *trap_list; | |
232 | struct trap_node *trap; | |
233 | unsigned long flags; | |
234 | int i; | |
235 | ||
236 | if (smp->attr_id != IB_SMP_ATTR_NOTICE) | |
237 | return; | |
238 | ||
239 | spin_lock_irqsave(&ibp->rvp.lock, flags); | |
240 | for (i = 0; i < RVT_MAX_TRAP_LISTS; i++) { | |
241 | trap_list = &ibp->rvp.trap_lists[i]; | |
242 | trap = list_first_entry_or_null(&trap_list->list, | |
243 | struct trap_node, list); | |
244 | if (trap && trap->tid == smp->tid) { | |
245 | if (trap->in_use) { | |
246 | trap->repress = 1; | |
247 | } else { | |
248 | trap_list->list_len--; | |
249 | list_del(&trap->list); | |
250 | kfree(trap); | |
251 | } | |
252 | break; | |
253 | } | |
254 | } | |
255 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); | |
256 | } | |
257 | ||
51e658f5 DC |
258 | static void hfi1_update_sm_ah_attr(struct hfi1_ibport *ibp, |
259 | struct rdma_ah_attr *attr, u32 dlid) | |
260 | { | |
261 | rdma_ah_set_dlid(attr, dlid); | |
262 | rdma_ah_set_port_num(attr, ppd_from_ibp(ibp)->port); | |
263 | if (dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) { | |
264 | struct ib_global_route *grh = rdma_ah_retrieve_grh(attr); | |
265 | ||
266 | rdma_ah_set_ah_flags(attr, IB_AH_GRH); | |
267 | grh->sgid_index = 0; | |
268 | grh->hop_limit = 1; | |
269 | grh->dgid.global.subnet_prefix = | |
270 | ibp->rvp.gid_prefix; | |
271 | grh->dgid.global.interface_id = OPA_MAKE_ID(dlid); | |
272 | } | |
273 | } | |
274 | ||
275 | static int hfi1_modify_qp0_ah(struct hfi1_ibport *ibp, | |
276 | struct rvt_ah *ah, u32 dlid) | |
277 | { | |
278 | struct rdma_ah_attr attr; | |
279 | struct rvt_qp *qp0; | |
280 | int ret = -EINVAL; | |
281 | ||
282 | memset(&attr, 0, sizeof(attr)); | |
283 | attr.type = ah->ibah.type; | |
284 | hfi1_update_sm_ah_attr(ibp, &attr, dlid); | |
285 | rcu_read_lock(); | |
286 | qp0 = rcu_dereference(ibp->rvp.qp[0]); | |
287 | if (qp0) | |
288 | ret = rdma_modify_ah(&ah->ibah, &attr); | |
289 | rcu_read_unlock(); | |
290 | return ret; | |
291 | } | |
292 | ||
293 | static struct ib_ah *hfi1_create_qp0_ah(struct hfi1_ibport *ibp, u32 dlid) | |
294 | { | |
295 | struct rdma_ah_attr attr; | |
296 | struct ib_ah *ah = ERR_PTR(-EINVAL); | |
297 | struct rvt_qp *qp0; | |
298 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
299 | struct hfi1_devdata *dd = dd_from_ppd(ppd); | |
300 | u8 port_num = ppd->port; | |
301 | ||
302 | memset(&attr, 0, sizeof(attr)); | |
303 | attr.type = rdma_ah_find_type(&dd->verbs_dev.rdi.ibdev, port_num); | |
304 | hfi1_update_sm_ah_attr(ibp, &attr, dlid); | |
305 | rcu_read_lock(); | |
306 | qp0 = rcu_dereference(ibp->rvp.qp[0]); | |
307 | if (qp0) | |
308 | ah = rdma_create_ah(qp0->ibqp.pd, &attr); | |
309 | rcu_read_unlock(); | |
310 | return ah; | |
311 | } | |
312 | ||
bf90aadd | 313 | static void send_trap(struct hfi1_ibport *ibp, struct trap_node *trap) |
77241056 MM |
314 | { |
315 | struct ib_mad_send_buf *send_buf; | |
316 | struct ib_mad_agent *agent; | |
5cd24119 | 317 | struct opa_smp *smp; |
77241056 | 318 | unsigned long flags; |
77241056 MM |
319 | int pkey_idx; |
320 | u32 qpn = ppd_from_ibp(ibp)->sm_trap_qp; | |
321 | ||
4eb06882 | 322 | agent = ibp->rvp.send_agent; |
bf90aadd MR |
323 | if (!agent) { |
324 | cleanup_traps(ibp, trap); | |
77241056 | 325 | return; |
bf90aadd | 326 | } |
77241056 MM |
327 | |
328 | /* o14-3.2.1 */ | |
bf90aadd MR |
329 | if (driver_lstate(ppd_from_ibp(ibp)) != IB_PORT_ACTIVE) { |
330 | cleanup_traps(ibp, trap); | |
77241056 | 331 | return; |
bf90aadd | 332 | } |
77241056 | 333 | |
bf90aadd MR |
334 | /* Add the trap to the list if necessary and see if we can send it */ |
335 | trap = check_and_add_trap(ibp, trap); | |
336 | if (!trap) | |
77241056 MM |
337 | return; |
338 | ||
339 | pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY); | |
340 | if (pkey_idx < 0) { | |
341 | pr_warn("%s: failed to find limited mgmt pkey, defaulting 0x%x\n", | |
342 | __func__, hfi1_get_pkey(ibp, 1)); | |
343 | pkey_idx = 1; | |
344 | } | |
345 | ||
346 | send_buf = ib_create_send_mad(agent, qpn, pkey_idx, 0, | |
347 | IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA, | |
348 | GFP_ATOMIC, IB_MGMT_BASE_VERSION); | |
349 | if (IS_ERR(send_buf)) | |
350 | return; | |
351 | ||
352 | smp = send_buf->mad; | |
5cd24119 | 353 | smp->base_version = OPA_MGMT_BASE_VERSION; |
77241056 | 354 | smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; |
9fa240bb | 355 | smp->class_version = OPA_SM_CLASS_VERSION; |
77241056 | 356 | smp->method = IB_MGMT_METHOD_TRAP; |
bf90aadd MR |
357 | |
358 | /* Only update the transaction ID for new traps (o13-5). */ | |
359 | if (trap->tid == 0) { | |
360 | ibp->rvp.tid++; | |
361 | /* make sure that tid != 0 */ | |
362 | if (ibp->rvp.tid == 0) | |
363 | ibp->rvp.tid++; | |
364 | trap->tid = cpu_to_be64(ibp->rvp.tid); | |
365 | } | |
366 | smp->tid = trap->tid; | |
367 | ||
77241056 MM |
368 | smp->attr_id = IB_SMP_ATTR_NOTICE; |
369 | /* o14-1: smp->mkey = 0; */ | |
bf90aadd MR |
370 | |
371 | memcpy(smp->route.lid.data, &trap->data, trap->len); | |
77241056 | 372 | |
4eb06882 | 373 | spin_lock_irqsave(&ibp->rvp.lock, flags); |
9c4a311e | 374 | if (!ibp->rvp.sm_ah) { |
4eb06882 | 375 | if (ibp->rvp.sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) { |
77241056 MM |
376 | struct ib_ah *ah; |
377 | ||
4eb06882 | 378 | ah = hfi1_create_qp0_ah(ibp, ibp->rvp.sm_lid); |
e490974e | 379 | if (IS_ERR(ah)) { |
bf90aadd MR |
380 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); |
381 | return; | |
77241056 | 382 | } |
bf90aadd MR |
383 | send_buf->ah = ah; |
384 | ibp->rvp.sm_ah = ibah_to_rvtah(ah); | |
e490974e | 385 | } else { |
bf90aadd MR |
386 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); |
387 | return; | |
e490974e | 388 | } |
77241056 | 389 | } else { |
9c4a311e | 390 | send_buf->ah = &ibp->rvp.sm_ah->ibah; |
77241056 | 391 | } |
bf90aadd MR |
392 | |
393 | /* | |
394 | * If the trap was repressed while things were getting set up, don't | |
395 | * bother sending it. This could happen for a retry. | |
396 | */ | |
397 | if (trap->repress) { | |
398 | list_del(&trap->list); | |
399 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); | |
400 | kfree(trap); | |
401 | ib_free_send_mad(send_buf); | |
402 | return; | |
403 | } | |
404 | ||
405 | trap->in_use = 0; | |
4eb06882 | 406 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); |
77241056 | 407 | |
bf90aadd | 408 | if (ib_post_send_mad(send_buf, NULL)) |
77241056 | 409 | ib_free_send_mad(send_buf); |
bf90aadd MR |
410 | } |
411 | ||
8064135e | 412 | void hfi1_handle_trap_timer(struct timer_list *t) |
bf90aadd | 413 | { |
8064135e | 414 | struct hfi1_ibport *ibp = from_timer(ibp, t, rvp.trap_timer); |
bf90aadd MR |
415 | struct trap_node *trap = NULL; |
416 | unsigned long flags; | |
417 | int i; | |
418 | ||
419 | /* Find the trap with the highest priority */ | |
420 | spin_lock_irqsave(&ibp->rvp.lock, flags); | |
421 | for (i = 0; !trap && i < RVT_MAX_TRAP_LISTS; i++) { | |
422 | trap = list_first_entry_or_null(&ibp->rvp.trap_lists[i].list, | |
423 | struct trap_node, list); | |
77241056 | 424 | } |
bf90aadd MR |
425 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); |
426 | ||
427 | if (trap) | |
428 | send_trap(ibp, trap); | |
429 | } | |
430 | ||
431 | static struct trap_node *create_trap_node(u8 type, __be16 trap_num, u32 lid) | |
432 | { | |
433 | struct trap_node *trap; | |
434 | ||
435 | trap = kzalloc(sizeof(*trap), GFP_ATOMIC); | |
436 | if (!trap) | |
437 | return NULL; | |
438 | ||
439 | INIT_LIST_HEAD(&trap->list); | |
440 | trap->data.generic_type = type; | |
441 | trap->data.prod_type_lsb = IB_NOTICE_PROD_CA; | |
442 | trap->data.trap_num = trap_num; | |
443 | trap->data.issuer_lid = cpu_to_be32(lid); | |
444 | ||
445 | return trap; | |
77241056 MM |
446 | } |
447 | ||
448 | /* | |
13d84914 | 449 | * Send a bad P_Key trap (ch. 14.3.8). |
77241056 | 450 | */ |
13d84914 | 451 | void hfi1_bad_pkey(struct hfi1_ibport *ibp, u32 key, u32 sl, |
88733e3b | 452 | u32 qp1, u32 qp2, u32 lid1, u32 lid2) |
77241056 | 453 | { |
bf90aadd | 454 | struct trap_node *trap; |
5cd24119 | 455 | u32 lid = ppd_from_ibp(ibp)->lid; |
77241056 | 456 | |
4eb06882 | 457 | ibp->rvp.n_pkt_drops++; |
13d84914 | 458 | ibp->rvp.pkey_violations++; |
77241056 | 459 | |
bf90aadd MR |
460 | trap = create_trap_node(IB_NOTICE_TYPE_SECURITY, OPA_TRAP_BAD_P_KEY, |
461 | lid); | |
462 | if (!trap) | |
463 | return; | |
464 | ||
77241056 | 465 | /* Send violation trap */ |
88733e3b DH |
466 | trap->data.ntc_257_258.lid1 = cpu_to_be32(lid1); |
467 | trap->data.ntc_257_258.lid2 = cpu_to_be32(lid2); | |
bf90aadd MR |
468 | trap->data.ntc_257_258.key = cpu_to_be32(key); |
469 | trap->data.ntc_257_258.sl = sl << 3; | |
470 | trap->data.ntc_257_258.qp1 = cpu_to_be32(qp1); | |
471 | trap->data.ntc_257_258.qp2 = cpu_to_be32(qp2); | |
472 | ||
473 | trap->len = sizeof(trap->data); | |
474 | send_trap(ibp, trap); | |
77241056 MM |
475 | } |
476 | ||
477 | /* | |
478 | * Send a bad M_Key trap (ch. 14.3.9). | |
479 | */ | |
480 | static void bad_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad, | |
481 | __be64 mkey, __be32 dr_slid, u8 return_path[], u8 hop_cnt) | |
482 | { | |
bf90aadd | 483 | struct trap_node *trap; |
5cd24119 | 484 | u32 lid = ppd_from_ibp(ibp)->lid; |
77241056 | 485 | |
bf90aadd MR |
486 | trap = create_trap_node(IB_NOTICE_TYPE_SECURITY, OPA_TRAP_BAD_M_KEY, |
487 | lid); | |
488 | if (!trap) | |
489 | return; | |
490 | ||
77241056 | 491 | /* Send violation trap */ |
bf90aadd MR |
492 | trap->data.ntc_256.lid = trap->data.issuer_lid; |
493 | trap->data.ntc_256.method = mad->method; | |
494 | trap->data.ntc_256.attr_id = mad->attr_id; | |
495 | trap->data.ntc_256.attr_mod = mad->attr_mod; | |
496 | trap->data.ntc_256.mkey = mkey; | |
77241056 | 497 | if (mad->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) { |
bf90aadd MR |
498 | trap->data.ntc_256.dr_slid = dr_slid; |
499 | trap->data.ntc_256.dr_trunc_hop = IB_NOTICE_TRAP_DR_NOTICE; | |
500 | if (hop_cnt > ARRAY_SIZE(trap->data.ntc_256.dr_rtn_path)) { | |
501 | trap->data.ntc_256.dr_trunc_hop |= | |
77241056 | 502 | IB_NOTICE_TRAP_DR_TRUNC; |
bf90aadd | 503 | hop_cnt = ARRAY_SIZE(trap->data.ntc_256.dr_rtn_path); |
77241056 | 504 | } |
bf90aadd MR |
505 | trap->data.ntc_256.dr_trunc_hop |= hop_cnt; |
506 | memcpy(trap->data.ntc_256.dr_rtn_path, return_path, | |
77241056 MM |
507 | hop_cnt); |
508 | } | |
509 | ||
bf90aadd MR |
510 | trap->len = sizeof(trap->data); |
511 | ||
512 | send_trap(ibp, trap); | |
77241056 MM |
513 | } |
514 | ||
515 | /* | |
516 | * Send a Port Capability Mask Changed trap (ch. 14.3.11). | |
517 | */ | |
45b59eef | 518 | void hfi1_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num) |
77241056 | 519 | { |
bf90aadd | 520 | struct trap_node *trap; |
45b59eef HC |
521 | struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi); |
522 | struct hfi1_devdata *dd = dd_from_dev(verbs_dev); | |
523 | struct hfi1_ibport *ibp = &dd->pport[port_num - 1].ibport_data; | |
5cd24119 EK |
524 | u32 lid = ppd_from_ibp(ibp)->lid; |
525 | ||
bf90aadd MR |
526 | trap = create_trap_node(IB_NOTICE_TYPE_INFO, |
527 | OPA_TRAP_CHANGE_CAPABILITY, | |
528 | lid); | |
529 | if (!trap) | |
530 | return; | |
77241056 | 531 | |
bf90aadd MR |
532 | trap->data.ntc_144.lid = trap->data.issuer_lid; |
533 | trap->data.ntc_144.new_cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags); | |
534 | trap->data.ntc_144.cap_mask3 = cpu_to_be16(ibp->rvp.port_cap3_flags); | |
77241056 | 535 | |
bf90aadd MR |
536 | trap->len = sizeof(trap->data); |
537 | send_trap(ibp, trap); | |
77241056 MM |
538 | } |
539 | ||
540 | /* | |
541 | * Send a System Image GUID Changed trap (ch. 14.3.12). | |
542 | */ | |
543 | void hfi1_sys_guid_chg(struct hfi1_ibport *ibp) | |
544 | { | |
bf90aadd | 545 | struct trap_node *trap; |
5cd24119 EK |
546 | u32 lid = ppd_from_ibp(ibp)->lid; |
547 | ||
bf90aadd MR |
548 | trap = create_trap_node(IB_NOTICE_TYPE_INFO, OPA_TRAP_CHANGE_SYSGUID, |
549 | lid); | |
550 | if (!trap) | |
551 | return; | |
77241056 | 552 | |
bf90aadd MR |
553 | trap->data.ntc_145.new_sys_guid = ib_hfi1_sys_image_guid; |
554 | trap->data.ntc_145.lid = trap->data.issuer_lid; | |
77241056 | 555 | |
bf90aadd MR |
556 | trap->len = sizeof(trap->data); |
557 | send_trap(ibp, trap); | |
77241056 MM |
558 | } |
559 | ||
560 | /* | |
561 | * Send a Node Description Changed trap (ch. 14.3.13). | |
562 | */ | |
563 | void hfi1_node_desc_chg(struct hfi1_ibport *ibp) | |
564 | { | |
bf90aadd | 565 | struct trap_node *trap; |
5cd24119 EK |
566 | u32 lid = ppd_from_ibp(ibp)->lid; |
567 | ||
bf90aadd MR |
568 | trap = create_trap_node(IB_NOTICE_TYPE_INFO, |
569 | OPA_TRAP_CHANGE_CAPABILITY, | |
570 | lid); | |
571 | if (!trap) | |
572 | return; | |
77241056 | 573 | |
bf90aadd MR |
574 | trap->data.ntc_144.lid = trap->data.issuer_lid; |
575 | trap->data.ntc_144.change_flags = | |
5cd24119 | 576 | cpu_to_be16(OPA_NOTICE_TRAP_NODE_DESC_CHG); |
77241056 | 577 | |
bf90aadd MR |
578 | trap->len = sizeof(trap->data); |
579 | send_trap(ibp, trap); | |
77241056 MM |
580 | } |
581 | ||
582 | static int __subn_get_opa_nodedesc(struct opa_smp *smp, u32 am, | |
583 | u8 *data, struct ib_device *ibdev, | |
f1685179 | 584 | u8 port, u32 *resp_len, u32 max_len) |
77241056 MM |
585 | { |
586 | struct opa_node_description *nd; | |
587 | ||
f1685179 | 588 | if (am || smp_length_check(sizeof(*nd), max_len)) { |
77241056 MM |
589 | smp->status |= IB_SMP_INVALID_FIELD; |
590 | return reply((struct ib_mad_hdr *)smp); | |
591 | } | |
592 | ||
593 | nd = (struct opa_node_description *)data; | |
594 | ||
595 | memcpy(nd->data, ibdev->node_desc, sizeof(nd->data)); | |
596 | ||
597 | if (resp_len) | |
598 | *resp_len += sizeof(*nd); | |
599 | ||
600 | return reply((struct ib_mad_hdr *)smp); | |
601 | } | |
602 | ||
603 | static int __subn_get_opa_nodeinfo(struct opa_smp *smp, u32 am, u8 *data, | |
604 | struct ib_device *ibdev, u8 port, | |
f1685179 | 605 | u32 *resp_len, u32 max_len) |
77241056 MM |
606 | { |
607 | struct opa_node_info *ni; | |
608 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
609 | unsigned pidx = port - 1; /* IB number port from 1, hw from 0 */ | |
610 | ||
611 | ni = (struct opa_node_info *)data; | |
612 | ||
613 | /* GUID 0 is illegal */ | |
a6cd5f08 | 614 | if (am || pidx >= dd->num_pports || ibdev->node_guid == 0 || |
f1685179 | 615 | smp_length_check(sizeof(*ni), max_len) || |
a6cd5f08 | 616 | get_sguid(to_iport(ibdev, port), HFI1_PORT_GUID_INDEX) == 0) { |
77241056 MM |
617 | smp->status |= IB_SMP_INVALID_FIELD; |
618 | return reply((struct ib_mad_hdr *)smp); | |
619 | } | |
620 | ||
a6cd5f08 | 621 | ni->port_guid = get_sguid(to_iport(ibdev, port), HFI1_PORT_GUID_INDEX); |
77241056 | 622 | ni->base_version = OPA_MGMT_BASE_VERSION; |
9fa240bb | 623 | ni->class_version = OPA_SM_CLASS_VERSION; |
77241056 MM |
624 | ni->node_type = 1; /* channel adapter */ |
625 | ni->num_ports = ibdev->phys_port_cnt; | |
626 | /* This is already in network order */ | |
627 | ni->system_image_guid = ib_hfi1_sys_image_guid; | |
a6cd5f08 | 628 | ni->node_guid = ibdev->node_guid; |
77241056 MM |
629 | ni->partition_cap = cpu_to_be16(hfi1_get_npkeys(dd)); |
630 | ni->device_id = cpu_to_be16(dd->pcidev->device); | |
631 | ni->revision = cpu_to_be32(dd->minrev); | |
632 | ni->local_port_num = port; | |
633 | ni->vendor_id[0] = dd->oui1; | |
634 | ni->vendor_id[1] = dd->oui2; | |
635 | ni->vendor_id[2] = dd->oui3; | |
636 | ||
637 | if (resp_len) | |
638 | *resp_len += sizeof(*ni); | |
639 | ||
640 | return reply((struct ib_mad_hdr *)smp); | |
641 | } | |
642 | ||
643 | static int subn_get_nodeinfo(struct ib_smp *smp, struct ib_device *ibdev, | |
644 | u8 port) | |
645 | { | |
646 | struct ib_node_info *nip = (struct ib_node_info *)&smp->data; | |
647 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
648 | unsigned pidx = port - 1; /* IB number port from 1, hw from 0 */ | |
649 | ||
650 | /* GUID 0 is illegal */ | |
651 | if (smp->attr_mod || pidx >= dd->num_pports || | |
a6cd5f08 JP |
652 | ibdev->node_guid == 0 || |
653 | get_sguid(to_iport(ibdev, port), HFI1_PORT_GUID_INDEX) == 0) { | |
77241056 | 654 | smp->status |= IB_SMP_INVALID_FIELD; |
a6cd5f08 JP |
655 | return reply((struct ib_mad_hdr *)smp); |
656 | } | |
77241056 | 657 | |
a6cd5f08 | 658 | nip->port_guid = get_sguid(to_iport(ibdev, port), HFI1_PORT_GUID_INDEX); |
77241056 | 659 | nip->base_version = OPA_MGMT_BASE_VERSION; |
9fa240bb | 660 | nip->class_version = OPA_SM_CLASS_VERSION; |
77241056 MM |
661 | nip->node_type = 1; /* channel adapter */ |
662 | nip->num_ports = ibdev->phys_port_cnt; | |
663 | /* This is already in network order */ | |
664 | nip->sys_guid = ib_hfi1_sys_image_guid; | |
a6cd5f08 | 665 | nip->node_guid = ibdev->node_guid; |
77241056 MM |
666 | nip->partition_cap = cpu_to_be16(hfi1_get_npkeys(dd)); |
667 | nip->device_id = cpu_to_be16(dd->pcidev->device); | |
668 | nip->revision = cpu_to_be32(dd->minrev); | |
669 | nip->local_port_num = port; | |
670 | nip->vendor_id[0] = dd->oui1; | |
671 | nip->vendor_id[1] = dd->oui2; | |
672 | nip->vendor_id[2] = dd->oui3; | |
673 | ||
674 | return reply((struct ib_mad_hdr *)smp); | |
675 | } | |
676 | ||
677 | static void set_link_width_enabled(struct hfi1_pportdata *ppd, u32 w) | |
678 | { | |
679 | (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_LWID_ENB, w); | |
680 | } | |
681 | ||
682 | static void set_link_width_downgrade_enabled(struct hfi1_pportdata *ppd, u32 w) | |
683 | { | |
684 | (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_LWID_DG_ENB, w); | |
685 | } | |
686 | ||
687 | static void set_link_speed_enabled(struct hfi1_pportdata *ppd, u32 s) | |
688 | { | |
689 | (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_SPD_ENB, s); | |
690 | } | |
691 | ||
692 | static int check_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad, | |
693 | int mad_flags, __be64 mkey, __be32 dr_slid, | |
694 | u8 return_path[], u8 hop_cnt) | |
695 | { | |
696 | int valid_mkey = 0; | |
697 | int ret = 0; | |
698 | ||
699 | /* Is the mkey in the process of expiring? */ | |
4eb06882 DD |
700 | if (ibp->rvp.mkey_lease_timeout && |
701 | time_after_eq(jiffies, ibp->rvp.mkey_lease_timeout)) { | |
77241056 | 702 | /* Clear timeout and mkey protection field. */ |
4eb06882 DD |
703 | ibp->rvp.mkey_lease_timeout = 0; |
704 | ibp->rvp.mkeyprot = 0; | |
77241056 MM |
705 | } |
706 | ||
4eb06882 DD |
707 | if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->rvp.mkey == 0 || |
708 | ibp->rvp.mkey == mkey) | |
77241056 MM |
709 | valid_mkey = 1; |
710 | ||
711 | /* Unset lease timeout on any valid Get/Set/TrapRepress */ | |
4eb06882 | 712 | if (valid_mkey && ibp->rvp.mkey_lease_timeout && |
77241056 MM |
713 | (mad->method == IB_MGMT_METHOD_GET || |
714 | mad->method == IB_MGMT_METHOD_SET || | |
715 | mad->method == IB_MGMT_METHOD_TRAP_REPRESS)) | |
4eb06882 | 716 | ibp->rvp.mkey_lease_timeout = 0; |
77241056 MM |
717 | |
718 | if (!valid_mkey) { | |
719 | switch (mad->method) { | |
720 | case IB_MGMT_METHOD_GET: | |
721 | /* Bad mkey not a violation below level 2 */ | |
4eb06882 | 722 | if (ibp->rvp.mkeyprot < 2) |
77241056 | 723 | break; |
6ffeb21f | 724 | /* fall through */ |
77241056 MM |
725 | case IB_MGMT_METHOD_SET: |
726 | case IB_MGMT_METHOD_TRAP_REPRESS: | |
4eb06882 DD |
727 | if (ibp->rvp.mkey_violations != 0xFFFF) |
728 | ++ibp->rvp.mkey_violations; | |
729 | if (!ibp->rvp.mkey_lease_timeout && | |
730 | ibp->rvp.mkey_lease_period) | |
731 | ibp->rvp.mkey_lease_timeout = jiffies + | |
732 | ibp->rvp.mkey_lease_period * HZ; | |
77241056 MM |
733 | /* Generate a trap notice. */ |
734 | bad_mkey(ibp, mad, mkey, dr_slid, return_path, | |
735 | hop_cnt); | |
736 | ret = 1; | |
737 | } | |
738 | } | |
739 | ||
740 | return ret; | |
741 | } | |
742 | ||
743 | /* | |
744 | * The SMA caches reads from LCB registers in case the LCB is unavailable. | |
745 | * (The LCB is unavailable in certain link states, for example.) | |
746 | */ | |
747 | struct lcb_datum { | |
748 | u32 off; | |
749 | u64 val; | |
750 | }; | |
751 | ||
752 | static struct lcb_datum lcb_cache[] = { | |
753 | { DC_LCB_STS_ROUND_TRIP_LTP_CNT, 0 }, | |
754 | }; | |
755 | ||
756 | static int write_lcb_cache(u32 off, u64 val) | |
757 | { | |
758 | int i; | |
759 | ||
760 | for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) { | |
761 | if (lcb_cache[i].off == off) { | |
762 | lcb_cache[i].val = val; | |
763 | return 0; | |
764 | } | |
765 | } | |
766 | ||
767 | pr_warn("%s bad offset 0x%x\n", __func__, off); | |
768 | return -1; | |
769 | } | |
770 | ||
771 | static int read_lcb_cache(u32 off, u64 *val) | |
772 | { | |
773 | int i; | |
774 | ||
775 | for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) { | |
776 | if (lcb_cache[i].off == off) { | |
777 | *val = lcb_cache[i].val; | |
778 | return 0; | |
779 | } | |
780 | } | |
781 | ||
782 | pr_warn("%s bad offset 0x%x\n", __func__, off); | |
783 | return -1; | |
784 | } | |
785 | ||
786 | void read_ltp_rtt(struct hfi1_devdata *dd) | |
787 | { | |
788 | u64 reg; | |
789 | ||
790 | if (read_lcb_csr(dd, DC_LCB_STS_ROUND_TRIP_LTP_CNT, ®)) | |
791 | dd_dev_err(dd, "%s: unable to read LTP RTT\n", __func__); | |
792 | else | |
793 | write_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, reg); | |
794 | } | |
795 | ||
77241056 MM |
796 | static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data, |
797 | struct ib_device *ibdev, u8 port, | |
f1685179 | 798 | u32 *resp_len, u32 max_len) |
77241056 MM |
799 | { |
800 | int i; | |
801 | struct hfi1_devdata *dd; | |
802 | struct hfi1_pportdata *ppd; | |
803 | struct hfi1_ibport *ibp; | |
804 | struct opa_port_info *pi = (struct opa_port_info *)data; | |
805 | u8 mtu; | |
806 | u8 credit_rate; | |
409b1462 | 807 | u8 is_beaconing_active; |
77241056 MM |
808 | u32 state; |
809 | u32 num_ports = OPA_AM_NPORT(am); | |
810 | u32 start_of_sm_config = OPA_AM_START_SM_CFG(am); | |
811 | u32 buffer_units; | |
812 | u64 tmp = 0; | |
813 | ||
f1685179 | 814 | if (num_ports != 1 || smp_length_check(sizeof(*pi), max_len)) { |
77241056 MM |
815 | smp->status |= IB_SMP_INVALID_FIELD; |
816 | return reply((struct ib_mad_hdr *)smp); | |
817 | } | |
818 | ||
819 | dd = dd_from_ibdev(ibdev); | |
820 | /* IB numbers ports from 1, hw from 0 */ | |
821 | ppd = dd->pport + (port - 1); | |
822 | ibp = &ppd->ibport_data; | |
823 | ||
8638b77f | 824 | if (ppd->vls_supported / 2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) || |
17fb4f29 | 825 | ppd->vls_supported > ARRAY_SIZE(dd->vld)) { |
77241056 MM |
826 | smp->status |= IB_SMP_INVALID_FIELD; |
827 | return reply((struct ib_mad_hdr *)smp); | |
828 | } | |
829 | ||
830 | pi->lid = cpu_to_be32(ppd->lid); | |
831 | ||
832 | /* Only return the mkey if the protection field allows it. */ | |
833 | if (!(smp->method == IB_MGMT_METHOD_GET && | |
4eb06882 DD |
834 | ibp->rvp.mkey != smp->mkey && |
835 | ibp->rvp.mkeyprot == 1)) | |
836 | pi->mkey = ibp->rvp.mkey; | |
837 | ||
838 | pi->subnet_prefix = ibp->rvp.gid_prefix; | |
839 | pi->sm_lid = cpu_to_be32(ibp->rvp.sm_lid); | |
840 | pi->ib_cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags); | |
841 | pi->mkey_lease_period = cpu_to_be16(ibp->rvp.mkey_lease_period); | |
77241056 MM |
842 | pi->sm_trap_qp = cpu_to_be32(ppd->sm_trap_qp); |
843 | pi->sa_qp = cpu_to_be32(ppd->sa_qp); | |
844 | ||
845 | pi->link_width.enabled = cpu_to_be16(ppd->link_width_enabled); | |
846 | pi->link_width.supported = cpu_to_be16(ppd->link_width_supported); | |
847 | pi->link_width.active = cpu_to_be16(ppd->link_width_active); | |
848 | ||
849 | pi->link_width_downgrade.supported = | |
850 | cpu_to_be16(ppd->link_width_downgrade_supported); | |
851 | pi->link_width_downgrade.enabled = | |
852 | cpu_to_be16(ppd->link_width_downgrade_enabled); | |
853 | pi->link_width_downgrade.tx_active = | |
854 | cpu_to_be16(ppd->link_width_downgrade_tx_active); | |
855 | pi->link_width_downgrade.rx_active = | |
856 | cpu_to_be16(ppd->link_width_downgrade_rx_active); | |
857 | ||
858 | pi->link_speed.supported = cpu_to_be16(ppd->link_speed_supported); | |
859 | pi->link_speed.active = cpu_to_be16(ppd->link_speed_active); | |
860 | pi->link_speed.enabled = cpu_to_be16(ppd->link_speed_enabled); | |
861 | ||
862 | state = driver_lstate(ppd); | |
863 | ||
864 | if (start_of_sm_config && (state == IB_PORT_INIT)) | |
865 | ppd->is_sm_config_started = 1; | |
866 | ||
1d01cf33 | 867 | pi->port_phys_conf = (ppd->port_type & 0xf); |
77241056 | 868 | |
77241056 MM |
869 | pi->port_states.ledenable_offlinereason = ppd->neighbor_normal << 4; |
870 | pi->port_states.ledenable_offlinereason |= | |
871 | ppd->is_sm_config_started << 5; | |
409b1462 | 872 | /* |
2243472e EH |
873 | * This pairs with the memory barrier in hfi1_start_led_override to |
874 | * ensure that we read the correct state of LED beaconing represented | |
875 | * by led_override_timer_active | |
409b1462 | 876 | */ |
2243472e | 877 | smp_rmb(); |
409b1462 EH |
878 | is_beaconing_active = !!atomic_read(&ppd->led_override_timer_active); |
879 | pi->port_states.ledenable_offlinereason |= is_beaconing_active << 6; | |
77241056 | 880 | pi->port_states.ledenable_offlinereason |= |
a9c05e35 | 881 | ppd->offline_disabled_reason; |
77241056 MM |
882 | |
883 | pi->port_states.portphysstate_portstate = | |
bec7c79c | 884 | (driver_pstate(ppd) << 4) | state; |
77241056 | 885 | |
4eb06882 | 886 | pi->mkeyprotect_lmc = (ibp->rvp.mkeyprot << 6) | ppd->lmc; |
77241056 MM |
887 | |
888 | memset(pi->neigh_mtu.pvlx_to_mtu, 0, sizeof(pi->neigh_mtu.pvlx_to_mtu)); | |
889 | for (i = 0; i < ppd->vls_supported; i++) { | |
890 | mtu = mtu_to_enum(dd->vld[i].mtu, HFI1_DEFAULT_ACTIVE_MTU); | |
891 | if ((i % 2) == 0) | |
8638b77f | 892 | pi->neigh_mtu.pvlx_to_mtu[i / 2] |= (mtu << 4); |
77241056 | 893 | else |
8638b77f | 894 | pi->neigh_mtu.pvlx_to_mtu[i / 2] |= mtu; |
77241056 MM |
895 | } |
896 | /* don't forget VL 15 */ | |
897 | mtu = mtu_to_enum(dd->vld[15].mtu, 2048); | |
8638b77f | 898 | pi->neigh_mtu.pvlx_to_mtu[15 / 2] |= mtu; |
4eb06882 | 899 | pi->smsl = ibp->rvp.sm_sl & OPA_PI_MASK_SMSL; |
77241056 MM |
900 | pi->operational_vls = hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS); |
901 | pi->partenforce_filterraw |= | |
902 | (ppd->linkinit_reason & OPA_PI_MASK_LINKINIT_REASON); | |
903 | if (ppd->part_enforce & HFI1_PART_ENFORCE_IN) | |
904 | pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_IN; | |
905 | if (ppd->part_enforce & HFI1_PART_ENFORCE_OUT) | |
906 | pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_OUT; | |
4eb06882 | 907 | pi->mkey_violations = cpu_to_be16(ibp->rvp.mkey_violations); |
77241056 | 908 | /* P_KeyViolations are counted by hardware. */ |
4eb06882 DD |
909 | pi->pkey_violations = cpu_to_be16(ibp->rvp.pkey_violations); |
910 | pi->qkey_violations = cpu_to_be16(ibp->rvp.qkey_violations); | |
77241056 MM |
911 | |
912 | pi->vl.cap = ppd->vls_supported; | |
4eb06882 | 913 | pi->vl.high_limit = cpu_to_be16(ibp->rvp.vl_high_limit); |
77241056 MM |
914 | pi->vl.arb_high_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_CAP); |
915 | pi->vl.arb_low_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_LOW_CAP); | |
916 | ||
4eb06882 | 917 | pi->clientrereg_subnettimeout = ibp->rvp.subnet_timeout; |
77241056 MM |
918 | |
919 | pi->port_link_mode = cpu_to_be16(OPA_PORT_LINK_MODE_OPA << 10 | | |
920 | OPA_PORT_LINK_MODE_OPA << 5 | | |
921 | OPA_PORT_LINK_MODE_OPA); | |
922 | ||
923 | pi->port_ltp_crc_mode = cpu_to_be16(ppd->port_ltp_crc_mode); | |
924 | ||
925 | pi->port_mode = cpu_to_be16( | |
926 | ppd->is_active_optimize_enabled ? | |
927 | OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE : 0); | |
928 | ||
929 | pi->port_packet_format.supported = | |
2280740f VN |
930 | cpu_to_be16(OPA_PORT_PACKET_FORMAT_9B | |
931 | OPA_PORT_PACKET_FORMAT_16B); | |
77241056 | 932 | pi->port_packet_format.enabled = |
2280740f VN |
933 | cpu_to_be16(OPA_PORT_PACKET_FORMAT_9B | |
934 | OPA_PORT_PACKET_FORMAT_16B); | |
77241056 MM |
935 | |
936 | /* flit_control.interleave is (OPA V1, version .76): | |
937 | * bits use | |
938 | * ---- --- | |
939 | * 2 res | |
940 | * 2 DistanceSupported | |
941 | * 2 DistanceEnabled | |
942 | * 5 MaxNextLevelTxEnabled | |
943 | * 5 MaxNestLevelRxSupported | |
944 | * | |
945 | * HFI supports only "distance mode 1" (see OPA V1, version .76, | |
946 | * section 9.6.2), so set DistanceSupported, DistanceEnabled | |
947 | * to 0x1. | |
948 | */ | |
949 | pi->flit_control.interleave = cpu_to_be16(0x1400); | |
950 | ||
951 | pi->link_down_reason = ppd->local_link_down_reason.sma; | |
952 | pi->neigh_link_down_reason = ppd->neigh_link_down_reason.sma; | |
953 | pi->port_error_action = cpu_to_be32(ppd->port_error_action); | |
954 | pi->mtucap = mtu_to_enum(hfi1_max_mtu, IB_MTU_4096); | |
955 | ||
956 | /* 32.768 usec. response time (guessing) */ | |
957 | pi->resptimevalue = 3; | |
958 | ||
959 | pi->local_port_num = port; | |
960 | ||
961 | /* buffer info for FM */ | |
962 | pi->overall_buffer_space = cpu_to_be16(dd->link_credits); | |
963 | ||
964 | pi->neigh_node_guid = cpu_to_be64(ppd->neighbor_guid); | |
965 | pi->neigh_port_num = ppd->neighbor_port_number; | |
966 | pi->port_neigh_mode = | |
967 | (ppd->neighbor_type & OPA_PI_MASK_NEIGH_NODE_TYPE) | | |
968 | (ppd->mgmt_allowed ? OPA_PI_MASK_NEIGH_MGMT_ALLOWED : 0) | | |
969 | (ppd->neighbor_fm_security ? | |
970 | OPA_PI_MASK_NEIGH_FW_AUTH_BYPASS : 0); | |
971 | ||
972 | /* HFIs shall always return VL15 credits to their | |
973 | * neighbor in a timely manner, without any credit return pacing. | |
974 | */ | |
975 | credit_rate = 0; | |
976 | buffer_units = (dd->vau) & OPA_PI_MASK_BUF_UNIT_BUF_ALLOC; | |
977 | buffer_units |= (dd->vcu << 3) & OPA_PI_MASK_BUF_UNIT_CREDIT_ACK; | |
978 | buffer_units |= (credit_rate << 6) & | |
979 | OPA_PI_MASK_BUF_UNIT_VL15_CREDIT_RATE; | |
980 | buffer_units |= (dd->vl15_init << 11) & OPA_PI_MASK_BUF_UNIT_VL15_INIT; | |
981 | pi->buffer_units = cpu_to_be32(buffer_units); | |
982 | ||
cb49366f | 983 | pi->opa_cap_mask = cpu_to_be16(ibp->rvp.port_cap3_flags); |
13c19222 DH |
984 | pi->collectivemask_multicastmask = ((OPA_COLLECTIVE_NR & 0x7) |
985 | << 3 | (OPA_MCAST_NR & 0x7)); | |
77241056 MM |
986 | |
987 | /* HFI supports a replay buffer 128 LTPs in size */ | |
988 | pi->replay_depth.buffer = 0x80; | |
989 | /* read the cached value of DC_LCB_STS_ROUND_TRIP_LTP_CNT */ | |
990 | read_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, &tmp); | |
991 | ||
4d114fdd JJ |
992 | /* |
993 | * this counter is 16 bits wide, but the replay_depth.wire | |
994 | * variable is only 8 bits | |
995 | */ | |
77241056 MM |
996 | if (tmp > 0xff) |
997 | tmp = 0xff; | |
998 | pi->replay_depth.wire = tmp; | |
999 | ||
1000 | if (resp_len) | |
1001 | *resp_len += sizeof(struct opa_port_info); | |
1002 | ||
1003 | return reply((struct ib_mad_hdr *)smp); | |
1004 | } | |
1005 | ||
1006 | /** | |
1007 | * get_pkeys - return the PKEY table | |
1008 | * @dd: the hfi1_ib device | |
1009 | * @port: the IB port number | |
1010 | * @pkeys: the pkey table is placed here | |
1011 | */ | |
1012 | static int get_pkeys(struct hfi1_devdata *dd, u8 port, u16 *pkeys) | |
1013 | { | |
1014 | struct hfi1_pportdata *ppd = dd->pport + port - 1; | |
1015 | ||
1016 | memcpy(pkeys, ppd->pkeys, sizeof(ppd->pkeys)); | |
1017 | ||
1018 | return 0; | |
1019 | } | |
1020 | ||
1021 | static int __subn_get_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data, | |
1022 | struct ib_device *ibdev, u8 port, | |
f1685179 | 1023 | u32 *resp_len, u32 max_len) |
77241056 MM |
1024 | { |
1025 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1026 | u32 n_blocks_req = OPA_AM_NBLK(am); | |
1027 | u32 start_block = am & 0x7ff; | |
1028 | __be16 *p; | |
1029 | u16 *q; | |
1030 | int i; | |
1031 | u16 n_blocks_avail; | |
1032 | unsigned npkeys = hfi1_get_npkeys(dd); | |
1033 | size_t size; | |
1034 | ||
1035 | if (n_blocks_req == 0) { | |
1036 | pr_warn("OPA Get PKey AM Invalid : P = %d; B = 0x%x; N = 0x%x\n", | |
1037 | port, start_block, n_blocks_req); | |
1038 | smp->status |= IB_SMP_INVALID_FIELD; | |
1039 | return reply((struct ib_mad_hdr *)smp); | |
1040 | } | |
1041 | ||
50e5dcbe | 1042 | n_blocks_avail = (u16)(npkeys / OPA_PARTITION_TABLE_BLK_SIZE) + 1; |
77241056 MM |
1043 | |
1044 | size = (n_blocks_req * OPA_PARTITION_TABLE_BLK_SIZE) * sizeof(u16); | |
1045 | ||
f1685179 ND |
1046 | if (smp_length_check(size, max_len)) { |
1047 | smp->status |= IB_SMP_INVALID_FIELD; | |
1048 | return reply((struct ib_mad_hdr *)smp); | |
1049 | } | |
1050 | ||
77241056 MM |
1051 | if (start_block + n_blocks_req > n_blocks_avail || |
1052 | n_blocks_req > OPA_NUM_PKEY_BLOCKS_PER_SMP) { | |
1053 | pr_warn("OPA Get PKey AM Invalid : s 0x%x; req 0x%x; " | |
1054 | "avail 0x%x; blk/smp 0x%lx\n", | |
1055 | start_block, n_blocks_req, n_blocks_avail, | |
1056 | OPA_NUM_PKEY_BLOCKS_PER_SMP); | |
1057 | smp->status |= IB_SMP_INVALID_FIELD; | |
1058 | return reply((struct ib_mad_hdr *)smp); | |
1059 | } | |
1060 | ||
50e5dcbe | 1061 | p = (__be16 *)data; |
77241056 MM |
1062 | q = (u16 *)data; |
1063 | /* get the real pkeys if we are requesting the first block */ | |
1064 | if (start_block == 0) { | |
1065 | get_pkeys(dd, port, q); | |
1066 | for (i = 0; i < npkeys; i++) | |
1067 | p[i] = cpu_to_be16(q[i]); | |
1068 | if (resp_len) | |
1069 | *resp_len += size; | |
e490974e | 1070 | } else { |
77241056 | 1071 | smp->status |= IB_SMP_INVALID_FIELD; |
e490974e | 1072 | } |
77241056 MM |
1073 | return reply((struct ib_mad_hdr *)smp); |
1074 | } | |
1075 | ||
1076 | enum { | |
1077 | HFI_TRANSITION_DISALLOWED, | |
1078 | HFI_TRANSITION_IGNORED, | |
1079 | HFI_TRANSITION_ALLOWED, | |
1080 | HFI_TRANSITION_UNDEFINED, | |
1081 | }; | |
1082 | ||
1083 | /* | |
1084 | * Use shortened names to improve readability of | |
1085 | * {logical,physical}_state_transitions | |
1086 | */ | |
1087 | enum { | |
1088 | __D = HFI_TRANSITION_DISALLOWED, | |
1089 | __I = HFI_TRANSITION_IGNORED, | |
1090 | __A = HFI_TRANSITION_ALLOWED, | |
1091 | __U = HFI_TRANSITION_UNDEFINED, | |
1092 | }; | |
1093 | ||
1094 | /* | |
1095 | * IB_PORTPHYSSTATE_POLLING (2) through OPA_PORTPHYSSTATE_MAX (11) are | |
1096 | * represented in physical_state_transitions. | |
1097 | */ | |
1098 | #define __N_PHYSTATES (OPA_PORTPHYSSTATE_MAX - IB_PORTPHYSSTATE_POLLING + 1) | |
1099 | ||
1100 | /* | |
1101 | * Within physical_state_transitions, rows represent "old" states, | |
1102 | * columns "new" states, and physical_state_transitions.allowed[old][new] | |
1103 | * indicates if the transition from old state to new state is legal (see | |
1104 | * OPAg1v1, Table 6-4). | |
1105 | */ | |
1106 | static const struct { | |
1107 | u8 allowed[__N_PHYSTATES][__N_PHYSTATES]; | |
1108 | } physical_state_transitions = { | |
1109 | { | |
1110 | /* 2 3 4 5 6 7 8 9 10 11 */ | |
1111 | /* 2 */ { __A, __A, __D, __D, __D, __D, __D, __D, __D, __D }, | |
1112 | /* 3 */ { __A, __I, __D, __D, __D, __D, __D, __D, __D, __A }, | |
1113 | /* 4 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U }, | |
1114 | /* 5 */ { __A, __A, __D, __I, __D, __D, __D, __D, __D, __D }, | |
1115 | /* 6 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U }, | |
1116 | /* 7 */ { __D, __A, __D, __D, __D, __I, __D, __D, __D, __D }, | |
1117 | /* 8 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U }, | |
1118 | /* 9 */ { __I, __A, __D, __D, __D, __D, __D, __I, __D, __D }, | |
1119 | /*10 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U }, | |
1120 | /*11 */ { __D, __A, __D, __D, __D, __D, __D, __D, __D, __I }, | |
1121 | } | |
1122 | }; | |
1123 | ||
1124 | /* | |
1125 | * IB_PORT_DOWN (1) through IB_PORT_ACTIVE_DEFER (5) are represented | |
1126 | * logical_state_transitions | |
1127 | */ | |
1128 | ||
1129 | #define __N_LOGICAL_STATES (IB_PORT_ACTIVE_DEFER - IB_PORT_DOWN + 1) | |
1130 | ||
1131 | /* | |
1132 | * Within logical_state_transitions rows represent "old" states, | |
1133 | * columns "new" states, and logical_state_transitions.allowed[old][new] | |
1134 | * indicates if the transition from old state to new state is legal (see | |
1135 | * OPAg1v1, Table 9-12). | |
1136 | */ | |
1137 | static const struct { | |
1138 | u8 allowed[__N_LOGICAL_STATES][__N_LOGICAL_STATES]; | |
1139 | } logical_state_transitions = { | |
1140 | { | |
1141 | /* 1 2 3 4 5 */ | |
1142 | /* 1 */ { __I, __D, __D, __D, __U}, | |
1143 | /* 2 */ { __D, __I, __A, __D, __U}, | |
1144 | /* 3 */ { __D, __D, __I, __A, __U}, | |
1145 | /* 4 */ { __D, __D, __I, __I, __U}, | |
1146 | /* 5 */ { __U, __U, __U, __U, __U}, | |
1147 | } | |
1148 | }; | |
1149 | ||
1150 | static int logical_transition_allowed(int old, int new) | |
1151 | { | |
1152 | if (old < IB_PORT_NOP || old > IB_PORT_ACTIVE_DEFER || | |
1153 | new < IB_PORT_NOP || new > IB_PORT_ACTIVE_DEFER) { | |
1154 | pr_warn("invalid logical state(s) (old %d new %d)\n", | |
1155 | old, new); | |
1156 | return HFI_TRANSITION_UNDEFINED; | |
1157 | } | |
1158 | ||
1159 | if (new == IB_PORT_NOP) | |
1160 | return HFI_TRANSITION_ALLOWED; /* always allowed */ | |
1161 | ||
1162 | /* adjust states for indexing into logical_state_transitions */ | |
1163 | old -= IB_PORT_DOWN; | |
1164 | new -= IB_PORT_DOWN; | |
1165 | ||
1166 | if (old < 0 || new < 0) | |
1167 | return HFI_TRANSITION_UNDEFINED; | |
1168 | return logical_state_transitions.allowed[old][new]; | |
1169 | } | |
1170 | ||
1171 | static int physical_transition_allowed(int old, int new) | |
1172 | { | |
1173 | if (old < IB_PORTPHYSSTATE_NOP || old > OPA_PORTPHYSSTATE_MAX || | |
1174 | new < IB_PORTPHYSSTATE_NOP || new > OPA_PORTPHYSSTATE_MAX) { | |
1175 | pr_warn("invalid physical state(s) (old %d new %d)\n", | |
1176 | old, new); | |
1177 | return HFI_TRANSITION_UNDEFINED; | |
1178 | } | |
1179 | ||
1180 | if (new == IB_PORTPHYSSTATE_NOP) | |
1181 | return HFI_TRANSITION_ALLOWED; /* always allowed */ | |
1182 | ||
1183 | /* adjust states for indexing into physical_state_transitions */ | |
1184 | old -= IB_PORTPHYSSTATE_POLLING; | |
1185 | new -= IB_PORTPHYSSTATE_POLLING; | |
1186 | ||
1187 | if (old < 0 || new < 0) | |
1188 | return HFI_TRANSITION_UNDEFINED; | |
1189 | return physical_state_transitions.allowed[old][new]; | |
1190 | } | |
1191 | ||
1192 | static int port_states_transition_allowed(struct hfi1_pportdata *ppd, | |
1193 | u32 logical_new, u32 physical_new) | |
1194 | { | |
d392a673 | 1195 | u32 physical_old = driver_pstate(ppd); |
02a222c7 | 1196 | u32 logical_old = driver_lstate(ppd); |
77241056 MM |
1197 | int ret, logical_allowed, physical_allowed; |
1198 | ||
f3ff8189 JJ |
1199 | ret = logical_transition_allowed(logical_old, logical_new); |
1200 | logical_allowed = ret; | |
77241056 MM |
1201 | |
1202 | if (ret == HFI_TRANSITION_DISALLOWED || | |
1203 | ret == HFI_TRANSITION_UNDEFINED) { | |
1204 | pr_warn("invalid logical state transition %s -> %s\n", | |
1205 | opa_lstate_name(logical_old), | |
1206 | opa_lstate_name(logical_new)); | |
1207 | return ret; | |
1208 | } | |
1209 | ||
f3ff8189 JJ |
1210 | ret = physical_transition_allowed(physical_old, physical_new); |
1211 | physical_allowed = ret; | |
77241056 MM |
1212 | |
1213 | if (ret == HFI_TRANSITION_DISALLOWED || | |
1214 | ret == HFI_TRANSITION_UNDEFINED) { | |
1215 | pr_warn("invalid physical state transition %s -> %s\n", | |
1216 | opa_pstate_name(physical_old), | |
1217 | opa_pstate_name(physical_new)); | |
1218 | return ret; | |
1219 | } | |
1220 | ||
1221 | if (logical_allowed == HFI_TRANSITION_IGNORED && | |
1222 | physical_allowed == HFI_TRANSITION_IGNORED) | |
1223 | return HFI_TRANSITION_IGNORED; | |
1224 | ||
a9c05e35 BM |
1225 | /* |
1226 | * A change request of Physical Port State from | |
1227 | * 'Offline' to 'Polling' should be ignored. | |
1228 | */ | |
1229 | if ((physical_old == OPA_PORTPHYSSTATE_OFFLINE) && | |
1230 | (physical_new == IB_PORTPHYSSTATE_POLLING)) | |
1231 | return HFI_TRANSITION_IGNORED; | |
1232 | ||
77241056 MM |
1233 | /* |
1234 | * Either physical_allowed or logical_allowed is | |
1235 | * HFI_TRANSITION_ALLOWED. | |
1236 | */ | |
1237 | return HFI_TRANSITION_ALLOWED; | |
1238 | } | |
1239 | ||
1240 | static int set_port_states(struct hfi1_pportdata *ppd, struct opa_smp *smp, | |
1241 | u32 logical_state, u32 phys_state, | |
1242 | int suppress_idle_sma) | |
1243 | { | |
1244 | struct hfi1_devdata *dd = ppd->dd; | |
1245 | u32 link_state; | |
1246 | int ret; | |
1247 | ||
1248 | ret = port_states_transition_allowed(ppd, logical_state, phys_state); | |
1249 | if (ret == HFI_TRANSITION_DISALLOWED || | |
1250 | ret == HFI_TRANSITION_UNDEFINED) { | |
1251 | /* error message emitted above */ | |
1252 | smp->status |= IB_SMP_INVALID_FIELD; | |
1253 | return 0; | |
1254 | } | |
1255 | ||
1256 | if (ret == HFI_TRANSITION_IGNORED) | |
1257 | return 0; | |
1258 | ||
1259 | if ((phys_state != IB_PORTPHYSSTATE_NOP) && | |
1260 | !(logical_state == IB_PORT_DOWN || | |
1261 | logical_state == IB_PORT_NOP)){ | |
1262 | pr_warn("SubnSet(OPA_PortInfo) port state invalid: logical_state 0x%x physical_state 0x%x\n", | |
1263 | logical_state, phys_state); | |
1264 | smp->status |= IB_SMP_INVALID_FIELD; | |
1265 | } | |
1266 | ||
1267 | /* | |
1268 | * Logical state changes are summarized in OPAv1g1 spec., | |
1269 | * Table 9-12; physical state changes are summarized in | |
1270 | * OPAv1g1 spec., Table 6.4. | |
1271 | */ | |
1272 | switch (logical_state) { | |
1273 | case IB_PORT_NOP: | |
1274 | if (phys_state == IB_PORTPHYSSTATE_NOP) | |
1275 | break; | |
1276 | /* FALLTHROUGH */ | |
1277 | case IB_PORT_DOWN: | |
e490974e | 1278 | if (phys_state == IB_PORTPHYSSTATE_NOP) { |
77241056 | 1279 | link_state = HLS_DN_DOWNDEF; |
e490974e | 1280 | } else if (phys_state == IB_PORTPHYSSTATE_POLLING) { |
77241056 | 1281 | link_state = HLS_DN_POLL; |
17fb4f29 JJ |
1282 | set_link_down_reason(ppd, OPA_LINKDOWN_REASON_FM_BOUNCE, |
1283 | 0, OPA_LINKDOWN_REASON_FM_BOUNCE); | |
e490974e | 1284 | } else if (phys_state == IB_PORTPHYSSTATE_DISABLED) { |
77241056 | 1285 | link_state = HLS_DN_DISABLE; |
e490974e | 1286 | } else { |
77241056 MM |
1287 | pr_warn("SubnSet(OPA_PortInfo) invalid physical state 0x%x\n", |
1288 | phys_state); | |
1289 | smp->status |= IB_SMP_INVALID_FIELD; | |
1290 | break; | |
1291 | } | |
1292 | ||
1cbaa670 DL |
1293 | if ((link_state == HLS_DN_POLL || |
1294 | link_state == HLS_DN_DOWNDEF)) { | |
1295 | /* | |
1296 | * Going to poll. No matter what the current state, | |
1297 | * always move offline first, then tune and start the | |
1298 | * link. This correctly handles a FM link bounce and | |
1299 | * a link enable. Going offline is a no-op if already | |
1300 | * offline. | |
1301 | */ | |
1302 | set_link_state(ppd, HLS_DN_OFFLINE); | |
1cbaa670 DL |
1303 | start_link(ppd); |
1304 | } else { | |
1305 | set_link_state(ppd, link_state); | |
1306 | } | |
77241056 MM |
1307 | if (link_state == HLS_DN_DISABLE && |
1308 | (ppd->offline_disabled_reason > | |
a9c05e35 | 1309 | HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED) || |
77241056 | 1310 | ppd->offline_disabled_reason == |
a9c05e35 | 1311 | HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))) |
77241056 | 1312 | ppd->offline_disabled_reason = |
a9c05e35 | 1313 | HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED); |
77241056 MM |
1314 | /* |
1315 | * Don't send a reply if the response would be sent | |
1316 | * through the disabled port. | |
1317 | */ | |
1318 | if (link_state == HLS_DN_DISABLE && smp->hop_cnt) | |
1319 | return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; | |
1320 | break; | |
1321 | case IB_PORT_ARMED: | |
1322 | ret = set_link_state(ppd, HLS_UP_ARMED); | |
1323 | if ((ret == 0) && (suppress_idle_sma == 0)) | |
1324 | send_idle_sma(dd, SMA_IDLE_ARM); | |
1325 | break; | |
1326 | case IB_PORT_ACTIVE: | |
1327 | if (ppd->neighbor_normal) { | |
1328 | ret = set_link_state(ppd, HLS_UP_ACTIVE); | |
1329 | if (ret == 0) | |
1330 | send_idle_sma(dd, SMA_IDLE_ACTIVE); | |
1331 | } else { | |
1332 | pr_warn("SubnSet(OPA_PortInfo) Cannot move to Active with NeighborNormal 0\n"); | |
1333 | smp->status |= IB_SMP_INVALID_FIELD; | |
1334 | } | |
1335 | break; | |
1336 | default: | |
1337 | pr_warn("SubnSet(OPA_PortInfo) invalid logical state 0x%x\n", | |
1338 | logical_state); | |
1339 | smp->status |= IB_SMP_INVALID_FIELD; | |
1340 | } | |
1341 | ||
1342 | return 0; | |
1343 | } | |
1344 | ||
1345 | /** | |
1346 | * subn_set_opa_portinfo - set port information | |
1347 | * @smp: the incoming SM packet | |
1348 | * @ibdev: the infiniband device | |
1349 | * @port: the port on the device | |
1350 | * | |
1351 | */ | |
1352 | static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data, | |
1353 | struct ib_device *ibdev, u8 port, | |
f1685179 | 1354 | u32 *resp_len, u32 max_len) |
77241056 MM |
1355 | { |
1356 | struct opa_port_info *pi = (struct opa_port_info *)data; | |
1357 | struct ib_event event; | |
1358 | struct hfi1_devdata *dd; | |
1359 | struct hfi1_pportdata *ppd; | |
1360 | struct hfi1_ibport *ibp; | |
1361 | u8 clientrereg; | |
1362 | unsigned long flags; | |
51e658f5 DC |
1363 | u32 smlid; |
1364 | u32 lid; | |
77241056 MM |
1365 | u8 ls_old, ls_new, ps_new; |
1366 | u8 vls; | |
1367 | u8 msl; | |
1368 | u8 crc_enabled; | |
1369 | u16 lse, lwe, mtu; | |
1370 | u32 num_ports = OPA_AM_NPORT(am); | |
1371 | u32 start_of_sm_config = OPA_AM_START_SM_CFG(am); | |
1372 | int ret, i, invalid = 0, call_set_mtu = 0; | |
1373 | int call_link_downgrade_policy = 0; | |
1374 | ||
f1685179 ND |
1375 | if (num_ports != 1 || |
1376 | smp_length_check(sizeof(*pi), max_len)) { | |
77241056 MM |
1377 | smp->status |= IB_SMP_INVALID_FIELD; |
1378 | return reply((struct ib_mad_hdr *)smp); | |
1379 | } | |
1380 | ||
51e658f5 DC |
1381 | lid = be32_to_cpu(pi->lid); |
1382 | if (lid & 0xFF000000) { | |
1383 | pr_warn("OPA_PortInfo lid out of range: %X\n", lid); | |
77241056 MM |
1384 | smp->status |= IB_SMP_INVALID_FIELD; |
1385 | goto get_only; | |
1386 | } | |
1387 | ||
77241056 MM |
1388 | |
1389 | smlid = be32_to_cpu(pi->sm_lid); | |
51e658f5 | 1390 | if (smlid & 0xFF000000) { |
77241056 MM |
1391 | pr_warn("OPA_PortInfo SM lid out of range: %X\n", smlid); |
1392 | smp->status |= IB_SMP_INVALID_FIELD; | |
1393 | goto get_only; | |
1394 | } | |
77241056 MM |
1395 | |
1396 | clientrereg = (pi->clientrereg_subnettimeout & | |
1397 | OPA_PI_MASK_CLIENT_REREGISTER); | |
1398 | ||
1399 | dd = dd_from_ibdev(ibdev); | |
1400 | /* IB numbers ports from 1, hw from 0 */ | |
1401 | ppd = dd->pport + (port - 1); | |
1402 | ibp = &ppd->ibport_data; | |
1403 | event.device = ibdev; | |
1404 | event.element.port_num = port; | |
1405 | ||
1406 | ls_old = driver_lstate(ppd); | |
1407 | ||
4eb06882 | 1408 | ibp->rvp.mkey = pi->mkey; |
51e658f5 DC |
1409 | if (ibp->rvp.gid_prefix != pi->subnet_prefix) { |
1410 | ibp->rvp.gid_prefix = pi->subnet_prefix; | |
1411 | event.event = IB_EVENT_GID_CHANGE; | |
1412 | ib_dispatch_event(&event); | |
1413 | } | |
4eb06882 | 1414 | ibp->rvp.mkey_lease_period = be16_to_cpu(pi->mkey_lease_period); |
77241056 MM |
1415 | |
1416 | /* Must be a valid unicast LID address. */ | |
1417 | if ((lid == 0 && ls_old > IB_PORT_INIT) || | |
51e658f5 | 1418 | (hfi1_is_16B_mcast(lid))) { |
77241056 MM |
1419 | smp->status |= IB_SMP_INVALID_FIELD; |
1420 | pr_warn("SubnSet(OPA_PortInfo) lid invalid 0x%x\n", | |
1421 | lid); | |
1422 | } else if (ppd->lid != lid || | |
1423 | ppd->lmc != (pi->mkeyprotect_lmc & OPA_PI_MASK_LMC)) { | |
1424 | if (ppd->lid != lid) | |
1425 | hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LID_CHANGE_BIT); | |
1426 | if (ppd->lmc != (pi->mkeyprotect_lmc & OPA_PI_MASK_LMC)) | |
1427 | hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LMC_CHANGE_BIT); | |
1428 | hfi1_set_lid(ppd, lid, pi->mkeyprotect_lmc & OPA_PI_MASK_LMC); | |
1429 | event.event = IB_EVENT_LID_CHANGE; | |
1430 | ib_dispatch_event(&event); | |
51e658f5 DC |
1431 | |
1432 | if (HFI1_PORT_GUID_INDEX + 1 < HFI1_GUIDS_PER_PORT) { | |
1433 | /* Manufacture GID from LID to support extended | |
1434 | * addresses | |
1435 | */ | |
1436 | ppd->guids[HFI1_PORT_GUID_INDEX + 1] = | |
1437 | be64_to_cpu(OPA_MAKE_ID(lid)); | |
1438 | event.event = IB_EVENT_GID_CHANGE; | |
1439 | ib_dispatch_event(&event); | |
1440 | } | |
77241056 MM |
1441 | } |
1442 | ||
1443 | msl = pi->smsl & OPA_PI_MASK_SMSL; | |
1444 | if (pi->partenforce_filterraw & OPA_PI_MASK_LINKINIT_REASON) | |
1445 | ppd->linkinit_reason = | |
1446 | (pi->partenforce_filterraw & | |
1447 | OPA_PI_MASK_LINKINIT_REASON); | |
77241056 MM |
1448 | |
1449 | /* Must be a valid unicast LID address. */ | |
1450 | if ((smlid == 0 && ls_old > IB_PORT_INIT) || | |
51e658f5 | 1451 | (hfi1_is_16B_mcast(smlid))) { |
77241056 MM |
1452 | smp->status |= IB_SMP_INVALID_FIELD; |
1453 | pr_warn("SubnSet(OPA_PortInfo) smlid invalid 0x%x\n", smlid); | |
4eb06882 | 1454 | } else if (smlid != ibp->rvp.sm_lid || msl != ibp->rvp.sm_sl) { |
77241056 | 1455 | pr_warn("SubnSet(OPA_PortInfo) smlid 0x%x\n", smlid); |
4eb06882 | 1456 | spin_lock_irqsave(&ibp->rvp.lock, flags); |
9c4a311e | 1457 | if (ibp->rvp.sm_ah) { |
4eb06882 | 1458 | if (smlid != ibp->rvp.sm_lid) |
51e658f5 | 1459 | hfi1_modify_qp0_ah(ibp, ibp->rvp.sm_ah, smlid); |
4eb06882 | 1460 | if (msl != ibp->rvp.sm_sl) |
d8966fcd | 1461 | rdma_ah_set_sl(&ibp->rvp.sm_ah->attr, msl); |
77241056 | 1462 | } |
4eb06882 DD |
1463 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); |
1464 | if (smlid != ibp->rvp.sm_lid) | |
1465 | ibp->rvp.sm_lid = smlid; | |
1466 | if (msl != ibp->rvp.sm_sl) | |
1467 | ibp->rvp.sm_sl = msl; | |
77241056 MM |
1468 | event.event = IB_EVENT_SM_CHANGE; |
1469 | ib_dispatch_event(&event); | |
1470 | } | |
1471 | ||
1472 | if (pi->link_down_reason == 0) { | |
1473 | ppd->local_link_down_reason.sma = 0; | |
1474 | ppd->local_link_down_reason.latest = 0; | |
1475 | } | |
1476 | ||
1477 | if (pi->neigh_link_down_reason == 0) { | |
1478 | ppd->neigh_link_down_reason.sma = 0; | |
1479 | ppd->neigh_link_down_reason.latest = 0; | |
1480 | } | |
1481 | ||
1482 | ppd->sm_trap_qp = be32_to_cpu(pi->sm_trap_qp); | |
1483 | ppd->sa_qp = be32_to_cpu(pi->sa_qp); | |
1484 | ||
1485 | ppd->port_error_action = be32_to_cpu(pi->port_error_action); | |
1486 | lwe = be16_to_cpu(pi->link_width.enabled); | |
1487 | if (lwe) { | |
d0d236ea JJ |
1488 | if (lwe == OPA_LINK_WIDTH_RESET || |
1489 | lwe == OPA_LINK_WIDTH_RESET_OLD) | |
77241056 MM |
1490 | set_link_width_enabled(ppd, ppd->link_width_supported); |
1491 | else if ((lwe & ~ppd->link_width_supported) == 0) | |
1492 | set_link_width_enabled(ppd, lwe); | |
1493 | else | |
1494 | smp->status |= IB_SMP_INVALID_FIELD; | |
1495 | } | |
1496 | lwe = be16_to_cpu(pi->link_width_downgrade.enabled); | |
1497 | /* LWD.E is always applied - 0 means "disabled" */ | |
d0d236ea JJ |
1498 | if (lwe == OPA_LINK_WIDTH_RESET || |
1499 | lwe == OPA_LINK_WIDTH_RESET_OLD) { | |
77241056 | 1500 | set_link_width_downgrade_enabled(ppd, |
17fb4f29 JJ |
1501 | ppd-> |
1502 | link_width_downgrade_supported | |
1503 | ); | |
77241056 MM |
1504 | } else if ((lwe & ~ppd->link_width_downgrade_supported) == 0) { |
1505 | /* only set and apply if something changed */ | |
1506 | if (lwe != ppd->link_width_downgrade_enabled) { | |
1507 | set_link_width_downgrade_enabled(ppd, lwe); | |
1508 | call_link_downgrade_policy = 1; | |
1509 | } | |
e490974e | 1510 | } else { |
77241056 | 1511 | smp->status |= IB_SMP_INVALID_FIELD; |
e490974e | 1512 | } |
77241056 MM |
1513 | lse = be16_to_cpu(pi->link_speed.enabled); |
1514 | if (lse) { | |
1515 | if (lse & be16_to_cpu(pi->link_speed.supported)) | |
1516 | set_link_speed_enabled(ppd, lse); | |
1517 | else | |
1518 | smp->status |= IB_SMP_INVALID_FIELD; | |
1519 | } | |
1520 | ||
4eb06882 DD |
1521 | ibp->rvp.mkeyprot = |
1522 | (pi->mkeyprotect_lmc & OPA_PI_MASK_MKEY_PROT_BIT) >> 6; | |
1523 | ibp->rvp.vl_high_limit = be16_to_cpu(pi->vl.high_limit) & 0xFF; | |
77241056 | 1524 | (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_LIMIT, |
4eb06882 | 1525 | ibp->rvp.vl_high_limit); |
77241056 | 1526 | |
8638b77f | 1527 | if (ppd->vls_supported / 2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) || |
17fb4f29 | 1528 | ppd->vls_supported > ARRAY_SIZE(dd->vld)) { |
77241056 MM |
1529 | smp->status |= IB_SMP_INVALID_FIELD; |
1530 | return reply((struct ib_mad_hdr *)smp); | |
1531 | } | |
1532 | for (i = 0; i < ppd->vls_supported; i++) { | |
1533 | if ((i % 2) == 0) | |
17fb4f29 JJ |
1534 | mtu = enum_to_mtu((pi->neigh_mtu.pvlx_to_mtu[i / 2] >> |
1535 | 4) & 0xF); | |
77241056 | 1536 | else |
17fb4f29 JJ |
1537 | mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[i / 2] & |
1538 | 0xF); | |
77241056 MM |
1539 | if (mtu == 0xffff) { |
1540 | pr_warn("SubnSet(OPA_PortInfo) mtu invalid %d (0x%x)\n", | |
1541 | mtu, | |
1542 | (pi->neigh_mtu.pvlx_to_mtu[0] >> 4) & 0xF); | |
1543 | smp->status |= IB_SMP_INVALID_FIELD; | |
1544 | mtu = hfi1_max_mtu; /* use a valid MTU */ | |
1545 | } | |
1546 | if (dd->vld[i].mtu != mtu) { | |
1547 | dd_dev_info(dd, | |
17fb4f29 JJ |
1548 | "MTU change on vl %d from %d to %d\n", |
1549 | i, dd->vld[i].mtu, mtu); | |
77241056 MM |
1550 | dd->vld[i].mtu = mtu; |
1551 | call_set_mtu++; | |
1552 | } | |
1553 | } | |
1554 | /* As per OPAV1 spec: VL15 must support and be configured | |
1555 | * for operation with a 2048 or larger MTU. | |
1556 | */ | |
8638b77f | 1557 | mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[15 / 2] & 0xF); |
77241056 MM |
1558 | if (mtu < 2048 || mtu == 0xffff) |
1559 | mtu = 2048; | |
1560 | if (dd->vld[15].mtu != mtu) { | |
1561 | dd_dev_info(dd, | |
17fb4f29 JJ |
1562 | "MTU change on vl 15 from %d to %d\n", |
1563 | dd->vld[15].mtu, mtu); | |
77241056 MM |
1564 | dd->vld[15].mtu = mtu; |
1565 | call_set_mtu++; | |
1566 | } | |
1567 | if (call_set_mtu) | |
1568 | set_mtu(ppd); | |
1569 | ||
1570 | /* Set operational VLs */ | |
1571 | vls = pi->operational_vls & OPA_PI_MASK_OPERATIONAL_VL; | |
1572 | if (vls) { | |
1573 | if (vls > ppd->vls_supported) { | |
1574 | pr_warn("SubnSet(OPA_PortInfo) VL's supported invalid %d\n", | |
1575 | pi->operational_vls); | |
1576 | smp->status |= IB_SMP_INVALID_FIELD; | |
1577 | } else { | |
1578 | if (hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS, | |
17fb4f29 | 1579 | vls) == -EINVAL) |
77241056 MM |
1580 | smp->status |= IB_SMP_INVALID_FIELD; |
1581 | } | |
1582 | } | |
1583 | ||
1584 | if (pi->mkey_violations == 0) | |
4eb06882 | 1585 | ibp->rvp.mkey_violations = 0; |
77241056 MM |
1586 | |
1587 | if (pi->pkey_violations == 0) | |
4eb06882 | 1588 | ibp->rvp.pkey_violations = 0; |
77241056 MM |
1589 | |
1590 | if (pi->qkey_violations == 0) | |
4eb06882 | 1591 | ibp->rvp.qkey_violations = 0; |
77241056 | 1592 | |
4eb06882 | 1593 | ibp->rvp.subnet_timeout = |
77241056 MM |
1594 | pi->clientrereg_subnettimeout & OPA_PI_MASK_SUBNET_TIMEOUT; |
1595 | ||
1596 | crc_enabled = be16_to_cpu(pi->port_ltp_crc_mode); | |
1597 | crc_enabled >>= 4; | |
1598 | crc_enabled &= 0xf; | |
1599 | ||
1600 | if (crc_enabled != 0) | |
1601 | ppd->port_crc_mode_enabled = port_ltp_to_cap(crc_enabled); | |
1602 | ||
1603 | ppd->is_active_optimize_enabled = | |
1604 | !!(be16_to_cpu(pi->port_mode) | |
1605 | & OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE); | |
1606 | ||
1607 | ls_new = pi->port_states.portphysstate_portstate & | |
1608 | OPA_PI_MASK_PORT_STATE; | |
1609 | ps_new = (pi->port_states.portphysstate_portstate & | |
1610 | OPA_PI_MASK_PORT_PHYSICAL_STATE) >> 4; | |
1611 | ||
1612 | if (ls_old == IB_PORT_INIT) { | |
1613 | if (start_of_sm_config) { | |
1614 | if (ls_new == ls_old || (ls_new == IB_PORT_ARMED)) | |
1615 | ppd->is_sm_config_started = 1; | |
1616 | } else if (ls_new == IB_PORT_ARMED) { | |
1617 | if (ppd->is_sm_config_started == 0) | |
1618 | invalid = 1; | |
1619 | } | |
1620 | } | |
1621 | ||
1622 | /* Handle CLIENT_REREGISTER event b/c SM asked us for it */ | |
1623 | if (clientrereg) { | |
1624 | event.event = IB_EVENT_CLIENT_REREGISTER; | |
1625 | ib_dispatch_event(&event); | |
1626 | } | |
1627 | ||
1628 | /* | |
1629 | * Do the port state change now that the other link parameters | |
1630 | * have been set. | |
1631 | * Changing the port physical state only makes sense if the link | |
1632 | * is down or is being set to down. | |
1633 | */ | |
1634 | ||
1635 | ret = set_port_states(ppd, smp, ls_new, ps_new, invalid); | |
1636 | if (ret) | |
1637 | return ret; | |
1638 | ||
f1685179 ND |
1639 | ret = __subn_get_opa_portinfo(smp, am, data, ibdev, port, resp_len, |
1640 | max_len); | |
77241056 MM |
1641 | |
1642 | /* restore re-reg bit per o14-12.2.1 */ | |
1643 | pi->clientrereg_subnettimeout |= clientrereg; | |
1644 | ||
1645 | /* | |
1646 | * Apply the new link downgrade policy. This may result in a link | |
1647 | * bounce. Do this after everything else so things are settled. | |
1648 | * Possible problem: if setting the port state above fails, then | |
1649 | * the policy change is not applied. | |
1650 | */ | |
1651 | if (call_link_downgrade_policy) | |
1652 | apply_link_downgrade_policy(ppd, 0); | |
1653 | ||
1654 | return ret; | |
1655 | ||
1656 | get_only: | |
f1685179 ND |
1657 | return __subn_get_opa_portinfo(smp, am, data, ibdev, port, resp_len, |
1658 | max_len); | |
77241056 MM |
1659 | } |
1660 | ||
1661 | /** | |
1662 | * set_pkeys - set the PKEY table for ctxt 0 | |
1663 | * @dd: the hfi1_ib device | |
1664 | * @port: the IB port number | |
1665 | * @pkeys: the PKEY table | |
1666 | */ | |
1667 | static int set_pkeys(struct hfi1_devdata *dd, u8 port, u16 *pkeys) | |
1668 | { | |
1669 | struct hfi1_pportdata *ppd; | |
1670 | int i; | |
1671 | int changed = 0; | |
1672 | int update_includes_mgmt_partition = 0; | |
1673 | ||
1674 | /* | |
1675 | * IB port one/two always maps to context zero/one, | |
1676 | * always a kernel context, no locking needed | |
1677 | * If we get here with ppd setup, no need to check | |
1678 | * that rcd is valid. | |
1679 | */ | |
1680 | ppd = dd->pport + (port - 1); | |
1681 | /* | |
1682 | * If the update does not include the management pkey, don't do it. | |
1683 | */ | |
1684 | for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) { | |
1685 | if (pkeys[i] == LIM_MGMT_P_KEY) { | |
1686 | update_includes_mgmt_partition = 1; | |
1687 | break; | |
1688 | } | |
1689 | } | |
1690 | ||
1691 | if (!update_includes_mgmt_partition) | |
1692 | return 1; | |
1693 | ||
1694 | for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) { | |
1695 | u16 key = pkeys[i]; | |
1696 | u16 okey = ppd->pkeys[i]; | |
1697 | ||
1698 | if (key == okey) | |
1699 | continue; | |
1700 | /* | |
1701 | * The SM gives us the complete PKey table. We have | |
1702 | * to ensure that we put the PKeys in the matching | |
1703 | * slots. | |
1704 | */ | |
1705 | ppd->pkeys[i] = key; | |
1706 | changed = 1; | |
1707 | } | |
1708 | ||
1709 | if (changed) { | |
77241056 | 1710 | (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0); |
34d351f8 | 1711 | hfi1_event_pkey_change(dd, port); |
77241056 | 1712 | } |
34d351f8 | 1713 | |
77241056 MM |
1714 | return 0; |
1715 | } | |
1716 | ||
1717 | static int __subn_set_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data, | |
1718 | struct ib_device *ibdev, u8 port, | |
f1685179 | 1719 | u32 *resp_len, u32 max_len) |
77241056 MM |
1720 | { |
1721 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1722 | u32 n_blocks_sent = OPA_AM_NBLK(am); | |
1723 | u32 start_block = am & 0x7ff; | |
50e5dcbe | 1724 | u16 *p = (u16 *)data; |
77241056 MM |
1725 | __be16 *q = (__be16 *)data; |
1726 | int i; | |
1727 | u16 n_blocks_avail; | |
1728 | unsigned npkeys = hfi1_get_npkeys(dd); | |
f1685179 | 1729 | u32 size = 0; |
77241056 MM |
1730 | |
1731 | if (n_blocks_sent == 0) { | |
1732 | pr_warn("OPA Get PKey AM Invalid : P = %d; B = 0x%x; N = 0x%x\n", | |
1733 | port, start_block, n_blocks_sent); | |
1734 | smp->status |= IB_SMP_INVALID_FIELD; | |
1735 | return reply((struct ib_mad_hdr *)smp); | |
1736 | } | |
1737 | ||
8638b77f | 1738 | n_blocks_avail = (u16)(npkeys / OPA_PARTITION_TABLE_BLK_SIZE) + 1; |
77241056 | 1739 | |
f1685179 ND |
1740 | size = sizeof(u16) * (n_blocks_sent * OPA_PARTITION_TABLE_BLK_SIZE); |
1741 | ||
1742 | if (smp_length_check(size, max_len)) { | |
1743 | smp->status |= IB_SMP_INVALID_FIELD; | |
1744 | return reply((struct ib_mad_hdr *)smp); | |
1745 | } | |
1746 | ||
77241056 MM |
1747 | if (start_block + n_blocks_sent > n_blocks_avail || |
1748 | n_blocks_sent > OPA_NUM_PKEY_BLOCKS_PER_SMP) { | |
1749 | pr_warn("OPA Set PKey AM Invalid : s 0x%x; req 0x%x; avail 0x%x; blk/smp 0x%lx\n", | |
1750 | start_block, n_blocks_sent, n_blocks_avail, | |
1751 | OPA_NUM_PKEY_BLOCKS_PER_SMP); | |
1752 | smp->status |= IB_SMP_INVALID_FIELD; | |
1753 | return reply((struct ib_mad_hdr *)smp); | |
1754 | } | |
1755 | ||
1756 | for (i = 0; i < n_blocks_sent * OPA_PARTITION_TABLE_BLK_SIZE; i++) | |
1757 | p[i] = be16_to_cpu(q[i]); | |
1758 | ||
1759 | if (start_block == 0 && set_pkeys(dd, port, p) != 0) { | |
1760 | smp->status |= IB_SMP_INVALID_FIELD; | |
1761 | return reply((struct ib_mad_hdr *)smp); | |
1762 | } | |
1763 | ||
f1685179 ND |
1764 | return __subn_get_opa_pkeytable(smp, am, data, ibdev, port, resp_len, |
1765 | max_len); | |
77241056 MM |
1766 | } |
1767 | ||
77241056 MM |
1768 | #define ILLEGAL_VL 12 |
1769 | /* | |
1770 | * filter_sc2vlt changes mappings to VL15 to ILLEGAL_VL (except | |
1771 | * for SC15, which must map to VL15). If we don't remap things this | |
1772 | * way it is possible for VL15 counters to increment when we try to | |
1773 | * send on a SC which is mapped to an invalid VL. | |
3ca4fbc8 | 1774 | * When getting the table convert ILLEGAL_VL back to VL15. |
77241056 | 1775 | */ |
3ca4fbc8 | 1776 | static void filter_sc2vlt(void *data, bool set) |
77241056 MM |
1777 | { |
1778 | int i; | |
a787bde8 | 1779 | u8 *pd = data; |
77241056 MM |
1780 | |
1781 | for (i = 0; i < OPA_MAX_SCS; i++) { | |
1782 | if (i == 15) | |
1783 | continue; | |
3ca4fbc8 SS |
1784 | |
1785 | if (set) { | |
1786 | if ((pd[i] & 0x1f) == 0xf) | |
1787 | pd[i] = ILLEGAL_VL; | |
1788 | } else { | |
1789 | if ((pd[i] & 0x1f) == ILLEGAL_VL) | |
1790 | pd[i] = 0xf; | |
1791 | } | |
77241056 MM |
1792 | } |
1793 | } | |
1794 | ||
1795 | static int set_sc2vlt_tables(struct hfi1_devdata *dd, void *data) | |
1796 | { | |
a787bde8 | 1797 | u64 *val = data; |
77241056 | 1798 | |
3ca4fbc8 | 1799 | filter_sc2vlt(data, true); |
77241056 MM |
1800 | |
1801 | write_csr(dd, SEND_SC2VLT0, *val++); | |
1802 | write_csr(dd, SEND_SC2VLT1, *val++); | |
1803 | write_csr(dd, SEND_SC2VLT2, *val++); | |
1804 | write_csr(dd, SEND_SC2VLT3, *val++); | |
1805 | write_seqlock_irq(&dd->sc2vl_lock); | |
a787bde8 | 1806 | memcpy(dd->sc2vl, data, sizeof(dd->sc2vl)); |
77241056 MM |
1807 | write_sequnlock_irq(&dd->sc2vl_lock); |
1808 | return 0; | |
1809 | } | |
1810 | ||
3ca4fbc8 SS |
1811 | static int get_sc2vlt_tables(struct hfi1_devdata *dd, void *data) |
1812 | { | |
1813 | u64 *val = (u64 *)data; | |
1814 | ||
1815 | *val++ = read_csr(dd, SEND_SC2VLT0); | |
1816 | *val++ = read_csr(dd, SEND_SC2VLT1); | |
1817 | *val++ = read_csr(dd, SEND_SC2VLT2); | |
1818 | *val++ = read_csr(dd, SEND_SC2VLT3); | |
1819 | ||
1820 | filter_sc2vlt((u64 *)data, false); | |
1821 | return 0; | |
1822 | } | |
1823 | ||
77241056 MM |
1824 | static int __subn_get_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data, |
1825 | struct ib_device *ibdev, u8 port, | |
f1685179 | 1826 | u32 *resp_len, u32 max_len) |
77241056 MM |
1827 | { |
1828 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
6618c051 | 1829 | u8 *p = data; |
77241056 MM |
1830 | size_t size = ARRAY_SIZE(ibp->sl_to_sc); /* == 32 */ |
1831 | unsigned i; | |
1832 | ||
f1685179 | 1833 | if (am || smp_length_check(size, max_len)) { |
77241056 MM |
1834 | smp->status |= IB_SMP_INVALID_FIELD; |
1835 | return reply((struct ib_mad_hdr *)smp); | |
1836 | } | |
1837 | ||
1838 | for (i = 0; i < ARRAY_SIZE(ibp->sl_to_sc); i++) | |
1839 | *p++ = ibp->sl_to_sc[i]; | |
1840 | ||
1841 | if (resp_len) | |
1842 | *resp_len += size; | |
1843 | ||
1844 | return reply((struct ib_mad_hdr *)smp); | |
1845 | } | |
1846 | ||
1847 | static int __subn_set_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data, | |
1848 | struct ib_device *ibdev, u8 port, | |
f1685179 | 1849 | u32 *resp_len, u32 max_len) |
77241056 MM |
1850 | { |
1851 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
6618c051 | 1852 | u8 *p = data; |
f1685179 | 1853 | size_t size = ARRAY_SIZE(ibp->sl_to_sc); |
77241056 | 1854 | int i; |
0ec79e87 | 1855 | u8 sc; |
77241056 | 1856 | |
f1685179 | 1857 | if (am || smp_length_check(size, max_len)) { |
77241056 MM |
1858 | smp->status |= IB_SMP_INVALID_FIELD; |
1859 | return reply((struct ib_mad_hdr *)smp); | |
1860 | } | |
1861 | ||
0ec79e87 KW |
1862 | for (i = 0; i < ARRAY_SIZE(ibp->sl_to_sc); i++) { |
1863 | sc = *p++; | |
1864 | if (ibp->sl_to_sc[i] != sc) { | |
1865 | ibp->sl_to_sc[i] = sc; | |
1866 | ||
1867 | /* Put all stale qps into error state */ | |
1868 | hfi1_error_port_qps(ibp, i); | |
1869 | } | |
1870 | } | |
77241056 | 1871 | |
f1685179 ND |
1872 | return __subn_get_opa_sl_to_sc(smp, am, data, ibdev, port, resp_len, |
1873 | max_len); | |
77241056 MM |
1874 | } |
1875 | ||
1876 | static int __subn_get_opa_sc_to_sl(struct opa_smp *smp, u32 am, u8 *data, | |
1877 | struct ib_device *ibdev, u8 port, | |
f1685179 | 1878 | u32 *resp_len, u32 max_len) |
77241056 MM |
1879 | { |
1880 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
6618c051 | 1881 | u8 *p = data; |
77241056 MM |
1882 | size_t size = ARRAY_SIZE(ibp->sc_to_sl); /* == 32 */ |
1883 | unsigned i; | |
1884 | ||
f1685179 | 1885 | if (am || smp_length_check(size, max_len)) { |
77241056 MM |
1886 | smp->status |= IB_SMP_INVALID_FIELD; |
1887 | return reply((struct ib_mad_hdr *)smp); | |
1888 | } | |
1889 | ||
1890 | for (i = 0; i < ARRAY_SIZE(ibp->sc_to_sl); i++) | |
1891 | *p++ = ibp->sc_to_sl[i]; | |
1892 | ||
1893 | if (resp_len) | |
1894 | *resp_len += size; | |
1895 | ||
1896 | return reply((struct ib_mad_hdr *)smp); | |
1897 | } | |
1898 | ||
1899 | static int __subn_set_opa_sc_to_sl(struct opa_smp *smp, u32 am, u8 *data, | |
1900 | struct ib_device *ibdev, u8 port, | |
f1685179 | 1901 | u32 *resp_len, u32 max_len) |
77241056 MM |
1902 | { |
1903 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
f1685179 | 1904 | size_t size = ARRAY_SIZE(ibp->sc_to_sl); |
6618c051 | 1905 | u8 *p = data; |
77241056 MM |
1906 | int i; |
1907 | ||
f1685179 | 1908 | if (am || smp_length_check(size, max_len)) { |
77241056 MM |
1909 | smp->status |= IB_SMP_INVALID_FIELD; |
1910 | return reply((struct ib_mad_hdr *)smp); | |
1911 | } | |
1912 | ||
1913 | for (i = 0; i < ARRAY_SIZE(ibp->sc_to_sl); i++) | |
1914 | ibp->sc_to_sl[i] = *p++; | |
1915 | ||
f1685179 ND |
1916 | return __subn_get_opa_sc_to_sl(smp, am, data, ibdev, port, resp_len, |
1917 | max_len); | |
77241056 MM |
1918 | } |
1919 | ||
1920 | static int __subn_get_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data, | |
1921 | struct ib_device *ibdev, u8 port, | |
f1685179 | 1922 | u32 *resp_len, u32 max_len) |
77241056 MM |
1923 | { |
1924 | u32 n_blocks = OPA_AM_NBLK(am); | |
1925 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
50e5dcbe | 1926 | void *vp = (void *)data; |
77241056 MM |
1927 | size_t size = 4 * sizeof(u64); |
1928 | ||
f1685179 | 1929 | if (n_blocks != 1 || smp_length_check(size, max_len)) { |
77241056 MM |
1930 | smp->status |= IB_SMP_INVALID_FIELD; |
1931 | return reply((struct ib_mad_hdr *)smp); | |
1932 | } | |
1933 | ||
1934 | get_sc2vlt_tables(dd, vp); | |
1935 | ||
1936 | if (resp_len) | |
1937 | *resp_len += size; | |
1938 | ||
1939 | return reply((struct ib_mad_hdr *)smp); | |
1940 | } | |
1941 | ||
1942 | static int __subn_set_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data, | |
1943 | struct ib_device *ibdev, u8 port, | |
f1685179 | 1944 | u32 *resp_len, u32 max_len) |
77241056 MM |
1945 | { |
1946 | u32 n_blocks = OPA_AM_NBLK(am); | |
1947 | int async_update = OPA_AM_ASYNC(am); | |
1948 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
50e5dcbe | 1949 | void *vp = (void *)data; |
77241056 MM |
1950 | struct hfi1_pportdata *ppd; |
1951 | int lstate; | |
f1685179 ND |
1952 | /* |
1953 | * set_sc2vlt_tables writes the information contained in *data | |
1954 | * to four 64-bit registers SendSC2VLt[0-3]. We need to make | |
1955 | * sure *max_len is not greater than the total size of the four | |
1956 | * SendSC2VLt[0-3] registers. | |
1957 | */ | |
1958 | size_t size = 4 * sizeof(u64); | |
77241056 | 1959 | |
f1685179 | 1960 | if (n_blocks != 1 || async_update || smp_length_check(size, max_len)) { |
77241056 MM |
1961 | smp->status |= IB_SMP_INVALID_FIELD; |
1962 | return reply((struct ib_mad_hdr *)smp); | |
1963 | } | |
1964 | ||
1965 | /* IB numbers ports from 1, hw from 0 */ | |
1966 | ppd = dd->pport + (port - 1); | |
1967 | lstate = driver_lstate(ppd); | |
4d114fdd JJ |
1968 | /* |
1969 | * it's known that async_update is 0 by this point, but include | |
1970 | * the explicit check for clarity | |
1971 | */ | |
77241056 MM |
1972 | if (!async_update && |
1973 | (lstate == IB_PORT_ARMED || lstate == IB_PORT_ACTIVE)) { | |
1974 | smp->status |= IB_SMP_INVALID_FIELD; | |
1975 | return reply((struct ib_mad_hdr *)smp); | |
1976 | } | |
1977 | ||
1978 | set_sc2vlt_tables(dd, vp); | |
1979 | ||
f1685179 ND |
1980 | return __subn_get_opa_sc_to_vlt(smp, am, data, ibdev, port, resp_len, |
1981 | max_len); | |
77241056 MM |
1982 | } |
1983 | ||
1984 | static int __subn_get_opa_sc_to_vlnt(struct opa_smp *smp, u32 am, u8 *data, | |
1985 | struct ib_device *ibdev, u8 port, | |
f1685179 | 1986 | u32 *resp_len, u32 max_len) |
77241056 MM |
1987 | { |
1988 | u32 n_blocks = OPA_AM_NPORT(am); | |
1989 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1990 | struct hfi1_pportdata *ppd; | |
50e5dcbe | 1991 | void *vp = (void *)data; |
f1685179 | 1992 | int size = sizeof(struct sc2vlnt); |
77241056 | 1993 | |
f1685179 | 1994 | if (n_blocks != 1 || smp_length_check(size, max_len)) { |
77241056 MM |
1995 | smp->status |= IB_SMP_INVALID_FIELD; |
1996 | return reply((struct ib_mad_hdr *)smp); | |
1997 | } | |
1998 | ||
1999 | ppd = dd->pport + (port - 1); | |
2000 | ||
f1685179 | 2001 | fm_get_table(ppd, FM_TBL_SC2VLNT, vp); |
77241056 MM |
2002 | |
2003 | if (resp_len) | |
2004 | *resp_len += size; | |
2005 | ||
2006 | return reply((struct ib_mad_hdr *)smp); | |
2007 | } | |
2008 | ||
2009 | static int __subn_set_opa_sc_to_vlnt(struct opa_smp *smp, u32 am, u8 *data, | |
2010 | struct ib_device *ibdev, u8 port, | |
f1685179 | 2011 | u32 *resp_len, u32 max_len) |
77241056 MM |
2012 | { |
2013 | u32 n_blocks = OPA_AM_NPORT(am); | |
2014 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2015 | struct hfi1_pportdata *ppd; | |
50e5dcbe | 2016 | void *vp = (void *)data; |
77241056 | 2017 | int lstate; |
f1685179 | 2018 | int size = sizeof(struct sc2vlnt); |
77241056 | 2019 | |
f1685179 | 2020 | if (n_blocks != 1 || smp_length_check(size, max_len)) { |
77241056 MM |
2021 | smp->status |= IB_SMP_INVALID_FIELD; |
2022 | return reply((struct ib_mad_hdr *)smp); | |
2023 | } | |
2024 | ||
2025 | /* IB numbers ports from 1, hw from 0 */ | |
2026 | ppd = dd->pport + (port - 1); | |
2027 | lstate = driver_lstate(ppd); | |
2028 | if (lstate == IB_PORT_ARMED || lstate == IB_PORT_ACTIVE) { | |
2029 | smp->status |= IB_SMP_INVALID_FIELD; | |
2030 | return reply((struct ib_mad_hdr *)smp); | |
2031 | } | |
2032 | ||
2033 | ppd = dd->pport + (port - 1); | |
2034 | ||
2035 | fm_set_table(ppd, FM_TBL_SC2VLNT, vp); | |
2036 | ||
2037 | return __subn_get_opa_sc_to_vlnt(smp, am, data, ibdev, port, | |
f1685179 | 2038 | resp_len, max_len); |
77241056 MM |
2039 | } |
2040 | ||
2041 | static int __subn_get_opa_psi(struct opa_smp *smp, u32 am, u8 *data, | |
2042 | struct ib_device *ibdev, u8 port, | |
f1685179 | 2043 | u32 *resp_len, u32 max_len) |
77241056 MM |
2044 | { |
2045 | u32 nports = OPA_AM_NPORT(am); | |
2046 | u32 start_of_sm_config = OPA_AM_START_SM_CFG(am); | |
2047 | u32 lstate; | |
2048 | struct hfi1_ibport *ibp; | |
2049 | struct hfi1_pportdata *ppd; | |
50e5dcbe | 2050 | struct opa_port_state_info *psi = (struct opa_port_state_info *)data; |
77241056 | 2051 | |
f1685179 | 2052 | if (nports != 1 || smp_length_check(sizeof(*psi), max_len)) { |
77241056 MM |
2053 | smp->status |= IB_SMP_INVALID_FIELD; |
2054 | return reply((struct ib_mad_hdr *)smp); | |
2055 | } | |
2056 | ||
2057 | ibp = to_iport(ibdev, port); | |
2058 | ppd = ppd_from_ibp(ibp); | |
2059 | ||
2060 | lstate = driver_lstate(ppd); | |
2061 | ||
2062 | if (start_of_sm_config && (lstate == IB_PORT_INIT)) | |
2063 | ppd->is_sm_config_started = 1; | |
2064 | ||
77241056 MM |
2065 | psi->port_states.ledenable_offlinereason = ppd->neighbor_normal << 4; |
2066 | psi->port_states.ledenable_offlinereason |= | |
2067 | ppd->is_sm_config_started << 5; | |
2068 | psi->port_states.ledenable_offlinereason |= | |
a9c05e35 | 2069 | ppd->offline_disabled_reason; |
77241056 MM |
2070 | |
2071 | psi->port_states.portphysstate_portstate = | |
bec7c79c | 2072 | (driver_pstate(ppd) << 4) | (lstate & 0xf); |
77241056 | 2073 | psi->link_width_downgrade_tx_active = |
aadfc3b2 | 2074 | cpu_to_be16(ppd->link_width_downgrade_tx_active); |
77241056 | 2075 | psi->link_width_downgrade_rx_active = |
aadfc3b2 | 2076 | cpu_to_be16(ppd->link_width_downgrade_rx_active); |
77241056 MM |
2077 | if (resp_len) |
2078 | *resp_len += sizeof(struct opa_port_state_info); | |
2079 | ||
2080 | return reply((struct ib_mad_hdr *)smp); | |
2081 | } | |
2082 | ||
2083 | static int __subn_set_opa_psi(struct opa_smp *smp, u32 am, u8 *data, | |
2084 | struct ib_device *ibdev, u8 port, | |
f1685179 | 2085 | u32 *resp_len, u32 max_len) |
77241056 MM |
2086 | { |
2087 | u32 nports = OPA_AM_NPORT(am); | |
2088 | u32 start_of_sm_config = OPA_AM_START_SM_CFG(am); | |
2089 | u32 ls_old; | |
2090 | u8 ls_new, ps_new; | |
2091 | struct hfi1_ibport *ibp; | |
2092 | struct hfi1_pportdata *ppd; | |
50e5dcbe | 2093 | struct opa_port_state_info *psi = (struct opa_port_state_info *)data; |
77241056 MM |
2094 | int ret, invalid = 0; |
2095 | ||
f1685179 | 2096 | if (nports != 1 || smp_length_check(sizeof(*psi), max_len)) { |
77241056 MM |
2097 | smp->status |= IB_SMP_INVALID_FIELD; |
2098 | return reply((struct ib_mad_hdr *)smp); | |
2099 | } | |
2100 | ||
2101 | ibp = to_iport(ibdev, port); | |
2102 | ppd = ppd_from_ibp(ibp); | |
2103 | ||
2104 | ls_old = driver_lstate(ppd); | |
2105 | ||
2106 | ls_new = port_states_to_logical_state(&psi->port_states); | |
2107 | ps_new = port_states_to_phys_state(&psi->port_states); | |
2108 | ||
2109 | if (ls_old == IB_PORT_INIT) { | |
2110 | if (start_of_sm_config) { | |
2111 | if (ls_new == ls_old || (ls_new == IB_PORT_ARMED)) | |
2112 | ppd->is_sm_config_started = 1; | |
2113 | } else if (ls_new == IB_PORT_ARMED) { | |
2114 | if (ppd->is_sm_config_started == 0) | |
2115 | invalid = 1; | |
2116 | } | |
2117 | } | |
2118 | ||
2119 | ret = set_port_states(ppd, smp, ls_new, ps_new, invalid); | |
2120 | if (ret) | |
2121 | return ret; | |
2122 | ||
2123 | if (invalid) | |
2124 | smp->status |= IB_SMP_INVALID_FIELD; | |
2125 | ||
f1685179 ND |
2126 | return __subn_get_opa_psi(smp, am, data, ibdev, port, resp_len, |
2127 | max_len); | |
77241056 MM |
2128 | } |
2129 | ||
2130 | static int __subn_get_opa_cable_info(struct opa_smp *smp, u32 am, u8 *data, | |
2131 | struct ib_device *ibdev, u8 port, | |
f1685179 | 2132 | u32 *resp_len, u32 max_len) |
77241056 MM |
2133 | { |
2134 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2135 | u32 addr = OPA_AM_CI_ADDR(am); | |
2136 | u32 len = OPA_AM_CI_LEN(am) + 1; | |
2137 | int ret; | |
2138 | ||
f1685179 ND |
2139 | if (dd->pport->port_type != PORT_TYPE_QSFP || |
2140 | smp_length_check(len, max_len)) { | |
f29a08dc EH |
2141 | smp->status |= IB_SMP_INVALID_FIELD; |
2142 | return reply((struct ib_mad_hdr *)smp); | |
2143 | } | |
2144 | ||
349ac71f | 2145 | #define __CI_PAGE_SIZE BIT(7) /* 128 bytes */ |
77241056 MM |
2146 | #define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1) |
2147 | #define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK) | |
2148 | ||
4d114fdd JJ |
2149 | /* |
2150 | * check that addr is within spec, and | |
2151 | * addr and (addr + len - 1) are on the same "page" | |
2152 | */ | |
77241056 | 2153 | if (addr >= 4096 || |
17fb4f29 | 2154 | (__CI_PAGE_NUM(addr) != __CI_PAGE_NUM(addr + len - 1))) { |
77241056 MM |
2155 | smp->status |= IB_SMP_INVALID_FIELD; |
2156 | return reply((struct ib_mad_hdr *)smp); | |
2157 | } | |
2158 | ||
2159 | ret = get_cable_info(dd, port, addr, len, data); | |
2160 | ||
2161 | if (ret == -ENODEV) { | |
2162 | smp->status |= IB_SMP_UNSUP_METH_ATTR; | |
2163 | return reply((struct ib_mad_hdr *)smp); | |
2164 | } | |
2165 | ||
2166 | /* The address range for the CableInfo SMA query is wider than the | |
2167 | * memory available on the QSFP cable. We want to return a valid | |
2168 | * response, albeit zeroed out, for address ranges beyond available | |
2169 | * memory but that are within the CableInfo query spec | |
2170 | */ | |
2171 | if (ret < 0 && ret != -ERANGE) { | |
2172 | smp->status |= IB_SMP_INVALID_FIELD; | |
2173 | return reply((struct ib_mad_hdr *)smp); | |
2174 | } | |
2175 | ||
2176 | if (resp_len) | |
2177 | *resp_len += len; | |
2178 | ||
2179 | return reply((struct ib_mad_hdr *)smp); | |
2180 | } | |
2181 | ||
2182 | static int __subn_get_opa_bct(struct opa_smp *smp, u32 am, u8 *data, | |
f1685179 ND |
2183 | struct ib_device *ibdev, u8 port, u32 *resp_len, |
2184 | u32 max_len) | |
77241056 MM |
2185 | { |
2186 | u32 num_ports = OPA_AM_NPORT(am); | |
2187 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2188 | struct hfi1_pportdata *ppd; | |
50e5dcbe | 2189 | struct buffer_control *p = (struct buffer_control *)data; |
f1685179 | 2190 | int size = sizeof(struct buffer_control); |
77241056 | 2191 | |
f1685179 | 2192 | if (num_ports != 1 || smp_length_check(size, max_len)) { |
77241056 MM |
2193 | smp->status |= IB_SMP_INVALID_FIELD; |
2194 | return reply((struct ib_mad_hdr *)smp); | |
2195 | } | |
2196 | ||
2197 | ppd = dd->pport + (port - 1); | |
f1685179 | 2198 | fm_get_table(ppd, FM_TBL_BUFFER_CONTROL, p); |
77241056 MM |
2199 | trace_bct_get(dd, p); |
2200 | if (resp_len) | |
2201 | *resp_len += size; | |
2202 | ||
2203 | return reply((struct ib_mad_hdr *)smp); | |
2204 | } | |
2205 | ||
2206 | static int __subn_set_opa_bct(struct opa_smp *smp, u32 am, u8 *data, | |
f1685179 ND |
2207 | struct ib_device *ibdev, u8 port, u32 *resp_len, |
2208 | u32 max_len) | |
77241056 MM |
2209 | { |
2210 | u32 num_ports = OPA_AM_NPORT(am); | |
2211 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2212 | struct hfi1_pportdata *ppd; | |
50e5dcbe | 2213 | struct buffer_control *p = (struct buffer_control *)data; |
77241056 | 2214 | |
f1685179 | 2215 | if (num_ports != 1 || smp_length_check(sizeof(*p), max_len)) { |
77241056 MM |
2216 | smp->status |= IB_SMP_INVALID_FIELD; |
2217 | return reply((struct ib_mad_hdr *)smp); | |
2218 | } | |
2219 | ppd = dd->pport + (port - 1); | |
2220 | trace_bct_set(dd, p); | |
2221 | if (fm_set_table(ppd, FM_TBL_BUFFER_CONTROL, p) < 0) { | |
2222 | smp->status |= IB_SMP_INVALID_FIELD; | |
2223 | return reply((struct ib_mad_hdr *)smp); | |
2224 | } | |
2225 | ||
f1685179 ND |
2226 | return __subn_get_opa_bct(smp, am, data, ibdev, port, resp_len, |
2227 | max_len); | |
77241056 MM |
2228 | } |
2229 | ||
2230 | static int __subn_get_opa_vl_arb(struct opa_smp *smp, u32 am, u8 *data, | |
2231 | struct ib_device *ibdev, u8 port, | |
f1685179 | 2232 | u32 *resp_len, u32 max_len) |
77241056 MM |
2233 | { |
2234 | struct hfi1_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port)); | |
2235 | u32 num_ports = OPA_AM_NPORT(am); | |
2236 | u8 section = (am & 0x00ff0000) >> 16; | |
2237 | u8 *p = data; | |
f1685179 | 2238 | int size = 256; |
77241056 | 2239 | |
f1685179 | 2240 | if (num_ports != 1 || smp_length_check(size, max_len)) { |
77241056 MM |
2241 | smp->status |= IB_SMP_INVALID_FIELD; |
2242 | return reply((struct ib_mad_hdr *)smp); | |
2243 | } | |
2244 | ||
2245 | switch (section) { | |
2246 | case OPA_VLARB_LOW_ELEMENTS: | |
f1685179 | 2247 | fm_get_table(ppd, FM_TBL_VL_LOW_ARB, p); |
77241056 MM |
2248 | break; |
2249 | case OPA_VLARB_HIGH_ELEMENTS: | |
f1685179 | 2250 | fm_get_table(ppd, FM_TBL_VL_HIGH_ARB, p); |
77241056 MM |
2251 | break; |
2252 | case OPA_VLARB_PREEMPT_ELEMENTS: | |
f1685179 | 2253 | fm_get_table(ppd, FM_TBL_VL_PREEMPT_ELEMS, p); |
77241056 MM |
2254 | break; |
2255 | case OPA_VLARB_PREEMPT_MATRIX: | |
f1685179 | 2256 | fm_get_table(ppd, FM_TBL_VL_PREEMPT_MATRIX, p); |
77241056 MM |
2257 | break; |
2258 | default: | |
2259 | pr_warn("OPA SubnGet(VL Arb) AM Invalid : 0x%x\n", | |
2260 | be32_to_cpu(smp->attr_mod)); | |
2261 | smp->status |= IB_SMP_INVALID_FIELD; | |
f1685179 | 2262 | size = 0; |
77241056 MM |
2263 | break; |
2264 | } | |
2265 | ||
2266 | if (size > 0 && resp_len) | |
2267 | *resp_len += size; | |
2268 | ||
2269 | return reply((struct ib_mad_hdr *)smp); | |
2270 | } | |
2271 | ||
2272 | static int __subn_set_opa_vl_arb(struct opa_smp *smp, u32 am, u8 *data, | |
2273 | struct ib_device *ibdev, u8 port, | |
f1685179 | 2274 | u32 *resp_len, u32 max_len) |
77241056 MM |
2275 | { |
2276 | struct hfi1_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port)); | |
2277 | u32 num_ports = OPA_AM_NPORT(am); | |
2278 | u8 section = (am & 0x00ff0000) >> 16; | |
2279 | u8 *p = data; | |
f1685179 | 2280 | int size = 256; |
77241056 | 2281 | |
f1685179 | 2282 | if (num_ports != 1 || smp_length_check(size, max_len)) { |
77241056 MM |
2283 | smp->status |= IB_SMP_INVALID_FIELD; |
2284 | return reply((struct ib_mad_hdr *)smp); | |
2285 | } | |
2286 | ||
2287 | switch (section) { | |
2288 | case OPA_VLARB_LOW_ELEMENTS: | |
50e5dcbe | 2289 | (void)fm_set_table(ppd, FM_TBL_VL_LOW_ARB, p); |
77241056 MM |
2290 | break; |
2291 | case OPA_VLARB_HIGH_ELEMENTS: | |
50e5dcbe | 2292 | (void)fm_set_table(ppd, FM_TBL_VL_HIGH_ARB, p); |
77241056 | 2293 | break; |
4d114fdd JJ |
2294 | /* |
2295 | * neither OPA_VLARB_PREEMPT_ELEMENTS, or OPA_VLARB_PREEMPT_MATRIX | |
2296 | * can be changed from the default values | |
2297 | */ | |
77241056 MM |
2298 | case OPA_VLARB_PREEMPT_ELEMENTS: |
2299 | /* FALLTHROUGH */ | |
2300 | case OPA_VLARB_PREEMPT_MATRIX: | |
2301 | smp->status |= IB_SMP_UNSUP_METH_ATTR; | |
2302 | break; | |
2303 | default: | |
2304 | pr_warn("OPA SubnSet(VL Arb) AM Invalid : 0x%x\n", | |
2305 | be32_to_cpu(smp->attr_mod)); | |
2306 | smp->status |= IB_SMP_INVALID_FIELD; | |
2307 | break; | |
2308 | } | |
2309 | ||
f1685179 ND |
2310 | return __subn_get_opa_vl_arb(smp, am, data, ibdev, port, resp_len, |
2311 | max_len); | |
77241056 MM |
2312 | } |
2313 | ||
2314 | struct opa_pma_mad { | |
2315 | struct ib_mad_hdr mad_hdr; | |
2316 | u8 data[2024]; | |
2317 | } __packed; | |
2318 | ||
77241056 MM |
2319 | struct opa_port_status_req { |
2320 | __u8 port_num; | |
2321 | __u8 reserved[3]; | |
2322 | __be32 vl_select_mask; | |
2323 | }; | |
2324 | ||
2325 | #define VL_MASK_ALL 0x000080ff | |
2326 | ||
2327 | struct opa_port_status_rsp { | |
2328 | __u8 port_num; | |
2329 | __u8 reserved[3]; | |
2330 | __be32 vl_select_mask; | |
2331 | ||
2332 | /* Data counters */ | |
2333 | __be64 port_xmit_data; | |
2334 | __be64 port_rcv_data; | |
2335 | __be64 port_xmit_pkts; | |
2336 | __be64 port_rcv_pkts; | |
2337 | __be64 port_multicast_xmit_pkts; | |
2338 | __be64 port_multicast_rcv_pkts; | |
2339 | __be64 port_xmit_wait; | |
2340 | __be64 sw_port_congestion; | |
2341 | __be64 port_rcv_fecn; | |
2342 | __be64 port_rcv_becn; | |
2343 | __be64 port_xmit_time_cong; | |
2344 | __be64 port_xmit_wasted_bw; | |
2345 | __be64 port_xmit_wait_data; | |
2346 | __be64 port_rcv_bubble; | |
2347 | __be64 port_mark_fecn; | |
2348 | /* Error counters */ | |
2349 | __be64 port_rcv_constraint_errors; | |
2350 | __be64 port_rcv_switch_relay_errors; | |
2351 | __be64 port_xmit_discards; | |
2352 | __be64 port_xmit_constraint_errors; | |
2353 | __be64 port_rcv_remote_physical_errors; | |
2354 | __be64 local_link_integrity_errors; | |
2355 | __be64 port_rcv_errors; | |
2356 | __be64 excessive_buffer_overruns; | |
2357 | __be64 fm_config_errors; | |
2358 | __be32 link_error_recovery; | |
2359 | __be32 link_downed; | |
2360 | u8 uncorrectable_errors; | |
2361 | ||
2362 | u8 link_quality_indicator; /* 5res, 3bit */ | |
2363 | u8 res2[6]; | |
2364 | struct _vls_pctrs { | |
2365 | /* per-VL Data counters */ | |
2366 | __be64 port_vl_xmit_data; | |
2367 | __be64 port_vl_rcv_data; | |
2368 | __be64 port_vl_xmit_pkts; | |
2369 | __be64 port_vl_rcv_pkts; | |
2370 | __be64 port_vl_xmit_wait; | |
2371 | __be64 sw_port_vl_congestion; | |
2372 | __be64 port_vl_rcv_fecn; | |
2373 | __be64 port_vl_rcv_becn; | |
2374 | __be64 port_xmit_time_cong; | |
2375 | __be64 port_vl_xmit_wasted_bw; | |
2376 | __be64 port_vl_xmit_wait_data; | |
2377 | __be64 port_vl_rcv_bubble; | |
2378 | __be64 port_vl_mark_fecn; | |
2379 | __be64 port_vl_xmit_discards; | |
2380 | } vls[0]; /* real array size defined by # bits set in vl_select_mask */ | |
2381 | }; | |
2382 | ||
2383 | enum counter_selects { | |
2384 | CS_PORT_XMIT_DATA = (1 << 31), | |
2385 | CS_PORT_RCV_DATA = (1 << 30), | |
2386 | CS_PORT_XMIT_PKTS = (1 << 29), | |
2387 | CS_PORT_RCV_PKTS = (1 << 28), | |
2388 | CS_PORT_MCAST_XMIT_PKTS = (1 << 27), | |
2389 | CS_PORT_MCAST_RCV_PKTS = (1 << 26), | |
2390 | CS_PORT_XMIT_WAIT = (1 << 25), | |
2391 | CS_SW_PORT_CONGESTION = (1 << 24), | |
2392 | CS_PORT_RCV_FECN = (1 << 23), | |
2393 | CS_PORT_RCV_BECN = (1 << 22), | |
2394 | CS_PORT_XMIT_TIME_CONG = (1 << 21), | |
2395 | CS_PORT_XMIT_WASTED_BW = (1 << 20), | |
2396 | CS_PORT_XMIT_WAIT_DATA = (1 << 19), | |
2397 | CS_PORT_RCV_BUBBLE = (1 << 18), | |
2398 | CS_PORT_MARK_FECN = (1 << 17), | |
2399 | CS_PORT_RCV_CONSTRAINT_ERRORS = (1 << 16), | |
2400 | CS_PORT_RCV_SWITCH_RELAY_ERRORS = (1 << 15), | |
2401 | CS_PORT_XMIT_DISCARDS = (1 << 14), | |
2402 | CS_PORT_XMIT_CONSTRAINT_ERRORS = (1 << 13), | |
2403 | CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS = (1 << 12), | |
2404 | CS_LOCAL_LINK_INTEGRITY_ERRORS = (1 << 11), | |
2405 | CS_PORT_RCV_ERRORS = (1 << 10), | |
2406 | CS_EXCESSIVE_BUFFER_OVERRUNS = (1 << 9), | |
2407 | CS_FM_CONFIG_ERRORS = (1 << 8), | |
2408 | CS_LINK_ERROR_RECOVERY = (1 << 7), | |
2409 | CS_LINK_DOWNED = (1 << 6), | |
2410 | CS_UNCORRECTABLE_ERRORS = (1 << 5), | |
2411 | }; | |
2412 | ||
2413 | struct opa_clear_port_status { | |
2414 | __be64 port_select_mask[4]; | |
2415 | __be32 counter_select_mask; | |
2416 | }; | |
2417 | ||
2418 | struct opa_aggregate { | |
2419 | __be16 attr_id; | |
2420 | __be16 err_reqlength; /* 1 bit, 8 res, 7 bit */ | |
2421 | __be32 attr_mod; | |
2422 | u8 data[0]; | |
2423 | }; | |
2424 | ||
f0852922 AL |
2425 | #define MSK_LLI 0x000000f0 |
2426 | #define MSK_LLI_SFT 4 | |
2427 | #define MSK_LER 0x0000000f | |
2428 | #define MSK_LER_SFT 0 | |
2429 | #define ADD_LLI 8 | |
2430 | #define ADD_LER 2 | |
2431 | ||
2432 | /* Request contains first three fields, response contains those plus the rest */ | |
77241056 MM |
2433 | struct opa_port_data_counters_msg { |
2434 | __be64 port_select_mask[4]; | |
2435 | __be32 vl_select_mask; | |
f0852922 | 2436 | __be32 resolution; |
77241056 MM |
2437 | |
2438 | /* Response fields follow */ | |
77241056 MM |
2439 | struct _port_dctrs { |
2440 | u8 port_number; | |
2441 | u8 reserved2[3]; | |
2442 | __be32 link_quality_indicator; /* 29res, 3bit */ | |
2443 | ||
2444 | /* Data counters */ | |
2445 | __be64 port_xmit_data; | |
2446 | __be64 port_rcv_data; | |
2447 | __be64 port_xmit_pkts; | |
2448 | __be64 port_rcv_pkts; | |
2449 | __be64 port_multicast_xmit_pkts; | |
2450 | __be64 port_multicast_rcv_pkts; | |
2451 | __be64 port_xmit_wait; | |
2452 | __be64 sw_port_congestion; | |
2453 | __be64 port_rcv_fecn; | |
2454 | __be64 port_rcv_becn; | |
2455 | __be64 port_xmit_time_cong; | |
2456 | __be64 port_xmit_wasted_bw; | |
2457 | __be64 port_xmit_wait_data; | |
2458 | __be64 port_rcv_bubble; | |
2459 | __be64 port_mark_fecn; | |
2460 | ||
2461 | __be64 port_error_counter_summary; | |
2462 | /* Sum of error counts/port */ | |
2463 | ||
2464 | struct _vls_dctrs { | |
2465 | /* per-VL Data counters */ | |
2466 | __be64 port_vl_xmit_data; | |
2467 | __be64 port_vl_rcv_data; | |
2468 | __be64 port_vl_xmit_pkts; | |
2469 | __be64 port_vl_rcv_pkts; | |
2470 | __be64 port_vl_xmit_wait; | |
2471 | __be64 sw_port_vl_congestion; | |
2472 | __be64 port_vl_rcv_fecn; | |
2473 | __be64 port_vl_rcv_becn; | |
2474 | __be64 port_xmit_time_cong; | |
2475 | __be64 port_vl_xmit_wasted_bw; | |
2476 | __be64 port_vl_xmit_wait_data; | |
2477 | __be64 port_vl_rcv_bubble; | |
2478 | __be64 port_vl_mark_fecn; | |
2479 | } vls[0]; | |
2480 | /* array size defined by #bits set in vl_select_mask*/ | |
2481 | } port[1]; /* array size defined by #ports in attribute modifier */ | |
2482 | }; | |
2483 | ||
2484 | struct opa_port_error_counters64_msg { | |
4d114fdd JJ |
2485 | /* |
2486 | * Request contains first two fields, response contains the | |
2487 | * whole magilla | |
2488 | */ | |
77241056 MM |
2489 | __be64 port_select_mask[4]; |
2490 | __be32 vl_select_mask; | |
2491 | ||
2492 | /* Response-only fields follow */ | |
2493 | __be32 reserved1; | |
2494 | struct _port_ectrs { | |
2495 | u8 port_number; | |
2496 | u8 reserved2[7]; | |
2497 | __be64 port_rcv_constraint_errors; | |
2498 | __be64 port_rcv_switch_relay_errors; | |
2499 | __be64 port_xmit_discards; | |
2500 | __be64 port_xmit_constraint_errors; | |
2501 | __be64 port_rcv_remote_physical_errors; | |
2502 | __be64 local_link_integrity_errors; | |
2503 | __be64 port_rcv_errors; | |
2504 | __be64 excessive_buffer_overruns; | |
2505 | __be64 fm_config_errors; | |
2506 | __be32 link_error_recovery; | |
2507 | __be32 link_downed; | |
2508 | u8 uncorrectable_errors; | |
2509 | u8 reserved3[7]; | |
2510 | struct _vls_ectrs { | |
2511 | __be64 port_vl_xmit_discards; | |
2512 | } vls[0]; | |
2513 | /* array size defined by #bits set in vl_select_mask */ | |
2514 | } port[1]; /* array size defined by #ports in attribute modifier */ | |
2515 | }; | |
2516 | ||
2517 | struct opa_port_error_info_msg { | |
2518 | __be64 port_select_mask[4]; | |
2519 | __be32 error_info_select_mask; | |
2520 | __be32 reserved1; | |
2521 | struct _port_ei { | |
77241056 MM |
2522 | u8 port_number; |
2523 | u8 reserved2[7]; | |
2524 | ||
2525 | /* PortRcvErrorInfo */ | |
2526 | struct { | |
2527 | u8 status_and_code; | |
2528 | union { | |
2529 | u8 raw[17]; | |
2530 | struct { | |
2531 | /* EI1to12 format */ | |
2532 | u8 packet_flit1[8]; | |
2533 | u8 packet_flit2[8]; | |
2534 | u8 remaining_flit_bits12; | |
2535 | } ei1to12; | |
2536 | struct { | |
2537 | u8 packet_bytes[8]; | |
2538 | u8 remaining_flit_bits; | |
2539 | } ei13; | |
2540 | } ei; | |
2541 | u8 reserved3[6]; | |
2542 | } __packed port_rcv_ei; | |
2543 | ||
2544 | /* ExcessiveBufferOverrunInfo */ | |
2545 | struct { | |
2546 | u8 status_and_sc; | |
2547 | u8 reserved4[7]; | |
2548 | } __packed excessive_buffer_overrun_ei; | |
2549 | ||
2550 | /* PortXmitConstraintErrorInfo */ | |
2551 | struct { | |
2552 | u8 status; | |
2553 | u8 reserved5; | |
2554 | __be16 pkey; | |
2555 | __be32 slid; | |
2556 | } __packed port_xmit_constraint_ei; | |
2557 | ||
2558 | /* PortRcvConstraintErrorInfo */ | |
2559 | struct { | |
2560 | u8 status; | |
2561 | u8 reserved6; | |
2562 | __be16 pkey; | |
2563 | __be32 slid; | |
2564 | } __packed port_rcv_constraint_ei; | |
2565 | ||
2566 | /* PortRcvSwitchRelayErrorInfo */ | |
2567 | struct { | |
2568 | u8 status_and_code; | |
2569 | u8 reserved7[3]; | |
2570 | __u32 error_info; | |
2571 | } __packed port_rcv_switch_relay_ei; | |
2572 | ||
2573 | /* UncorrectableErrorInfo */ | |
2574 | struct { | |
2575 | u8 status_and_code; | |
2576 | u8 reserved8; | |
2577 | } __packed uncorrectable_ei; | |
2578 | ||
2579 | /* FMConfigErrorInfo */ | |
2580 | struct { | |
2581 | u8 status_and_code; | |
2582 | u8 error_info; | |
2583 | } __packed fm_config_ei; | |
2584 | __u32 reserved9; | |
2585 | } port[1]; /* actual array size defined by #ports in attr modifier */ | |
2586 | }; | |
2587 | ||
2588 | /* opa_port_error_info_msg error_info_select_mask bit definitions */ | |
2589 | enum error_info_selects { | |
2590 | ES_PORT_RCV_ERROR_INFO = (1 << 31), | |
2591 | ES_EXCESSIVE_BUFFER_OVERRUN_INFO = (1 << 30), | |
2592 | ES_PORT_XMIT_CONSTRAINT_ERROR_INFO = (1 << 29), | |
2593 | ES_PORT_RCV_CONSTRAINT_ERROR_INFO = (1 << 28), | |
2594 | ES_PORT_RCV_SWITCH_RELAY_ERROR_INFO = (1 << 27), | |
2595 | ES_UNCORRECTABLE_ERROR_INFO = (1 << 26), | |
2596 | ES_FM_CONFIG_ERROR_INFO = (1 << 25) | |
2597 | }; | |
2598 | ||
2599 | static int pma_get_opa_classportinfo(struct opa_pma_mad *pmp, | |
17fb4f29 | 2600 | struct ib_device *ibdev, u32 *resp_len) |
77241056 MM |
2601 | { |
2602 | struct opa_class_port_info *p = | |
2603 | (struct opa_class_port_info *)pmp->data; | |
2604 | ||
2605 | memset(pmp->data, 0, sizeof(pmp->data)); | |
2606 | ||
2607 | if (pmp->mad_hdr.attr_mod != 0) | |
2608 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2609 | ||
2610 | p->base_version = OPA_MGMT_BASE_VERSION; | |
9fa240bb | 2611 | p->class_version = OPA_SM_CLASS_VERSION; |
77241056 MM |
2612 | /* |
2613 | * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec. | |
2614 | */ | |
2615 | p->cap_mask2_resp_time = cpu_to_be32(18); | |
2616 | ||
2617 | if (resp_len) | |
2618 | *resp_len += sizeof(*p); | |
2619 | ||
2620 | return reply((struct ib_mad_hdr *)pmp); | |
2621 | } | |
2622 | ||
2623 | static void a0_portstatus(struct hfi1_pportdata *ppd, | |
2624 | struct opa_port_status_rsp *rsp, u32 vl_select_mask) | |
2625 | { | |
2626 | if (!is_bx(ppd->dd)) { | |
2627 | unsigned long vl; | |
d9d3e025 | 2628 | u64 sum_vl_xmit_wait = 0; |
77241056 | 2629 | u32 vl_all_mask = VL_MASK_ALL; |
77241056 MM |
2630 | |
2631 | for_each_set_bit(vl, (unsigned long *)&(vl_all_mask), | |
2632 | 8 * sizeof(vl_all_mask)) { | |
d9d3e025 IW |
2633 | u64 tmp = sum_vl_xmit_wait + |
2634 | read_port_cntr(ppd, C_TX_WAIT_VL, | |
2635 | idx_from_vl(vl)); | |
2636 | if (tmp < sum_vl_xmit_wait) { | |
2637 | /* we wrapped */ | |
2638 | sum_vl_xmit_wait = (u64)~0; | |
2639 | break; | |
2640 | } | |
2641 | sum_vl_xmit_wait = tmp; | |
77241056 | 2642 | } |
d9d3e025 IW |
2643 | if (be64_to_cpu(rsp->port_xmit_wait) > sum_vl_xmit_wait) |
2644 | rsp->port_xmit_wait = cpu_to_be64(sum_vl_xmit_wait); | |
77241056 MM |
2645 | } |
2646 | } | |
2647 | ||
77241056 | 2648 | static int pma_get_opa_portstatus(struct opa_pma_mad *pmp, |
17fb4f29 JJ |
2649 | struct ib_device *ibdev, |
2650 | u8 port, u32 *resp_len) | |
77241056 MM |
2651 | { |
2652 | struct opa_port_status_req *req = | |
2653 | (struct opa_port_status_req *)pmp->data; | |
2654 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2655 | struct opa_port_status_rsp *rsp; | |
2656 | u32 vl_select_mask = be32_to_cpu(req->vl_select_mask); | |
2657 | unsigned long vl; | |
2658 | size_t response_data_size; | |
2659 | u32 nports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24; | |
2660 | u8 port_num = req->port_num; | |
2661 | u8 num_vls = hweight32(vl_select_mask); | |
2662 | struct _vls_pctrs *vlinfo; | |
2663 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
2664 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
2665 | int vfi; | |
2666 | u64 tmp, tmp2; | |
2667 | ||
2668 | response_data_size = sizeof(struct opa_port_status_rsp) + | |
2669 | num_vls * sizeof(struct _vls_pctrs); | |
2670 | if (response_data_size > sizeof(pmp->data)) { | |
2671 | pmp->mad_hdr.status |= OPA_PM_STATUS_REQUEST_TOO_LARGE; | |
2672 | return reply((struct ib_mad_hdr *)pmp); | |
2673 | } | |
2674 | ||
d0d236ea JJ |
2675 | if (nports != 1 || (port_num && port_num != port) || |
2676 | num_vls > OPA_MAX_VLS || (vl_select_mask & ~VL_MASK_ALL)) { | |
77241056 MM |
2677 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
2678 | return reply((struct ib_mad_hdr *)pmp); | |
2679 | } | |
2680 | ||
2681 | memset(pmp->data, 0, sizeof(pmp->data)); | |
2682 | ||
2683 | rsp = (struct opa_port_status_rsp *)pmp->data; | |
2684 | if (port_num) | |
2685 | rsp->port_num = port_num; | |
2686 | else | |
2687 | rsp->port_num = port; | |
2688 | ||
2689 | rsp->port_rcv_constraint_errors = | |
2690 | cpu_to_be64(read_port_cntr(ppd, C_SW_RCV_CSTR_ERR, | |
2691 | CNTR_INVALID_VL)); | |
2692 | ||
2693 | hfi1_read_link_quality(dd, &rsp->link_quality_indicator); | |
2694 | ||
2695 | rsp->vl_select_mask = cpu_to_be32(vl_select_mask); | |
2696 | rsp->port_xmit_data = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_FLITS, | |
2697 | CNTR_INVALID_VL)); | |
2698 | rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS, | |
2699 | CNTR_INVALID_VL)); | |
77241056 MM |
2700 | rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS, |
2701 | CNTR_INVALID_VL)); | |
2702 | rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS, | |
2703 | CNTR_INVALID_VL)); | |
2704 | rsp->port_multicast_xmit_pkts = | |
2705 | cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS, | |
17fb4f29 | 2706 | CNTR_INVALID_VL)); |
77241056 MM |
2707 | rsp->port_multicast_rcv_pkts = |
2708 | cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS, | |
2709 | CNTR_INVALID_VL)); | |
2710 | rsp->port_xmit_wait = | |
2711 | cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL)); | |
2712 | rsp->port_rcv_fecn = | |
2713 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL)); | |
2714 | rsp->port_rcv_becn = | |
2715 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL)); | |
2716 | rsp->port_xmit_discards = | |
2717 | cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD, | |
2718 | CNTR_INVALID_VL)); | |
2719 | rsp->port_xmit_constraint_errors = | |
2720 | cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, | |
2721 | CNTR_INVALID_VL)); | |
2722 | rsp->port_rcv_remote_physical_errors = | |
2723 | cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR, | |
2724 | CNTR_INVALID_VL)); | |
3210314a JP |
2725 | rsp->local_link_integrity_errors = |
2726 | cpu_to_be64(read_dev_cntr(dd, C_DC_RX_REPLAY, | |
2727 | CNTR_INVALID_VL)); | |
77241056 MM |
2728 | tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL); |
2729 | tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, | |
17fb4f29 | 2730 | CNTR_INVALID_VL); |
77241056 MM |
2731 | if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) { |
2732 | /* overflow/wrapped */ | |
2733 | rsp->link_error_recovery = cpu_to_be32(~0); | |
2734 | } else { | |
2735 | rsp->link_error_recovery = cpu_to_be32(tmp2); | |
2736 | } | |
2737 | rsp->port_rcv_errors = | |
2738 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL)); | |
2739 | rsp->excessive_buffer_overruns = | |
2740 | cpu_to_be64(read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL)); | |
2741 | rsp->fm_config_errors = | |
2742 | cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR, | |
2743 | CNTR_INVALID_VL)); | |
2744 | rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN, | |
17fb4f29 | 2745 | CNTR_INVALID_VL)); |
77241056 MM |
2746 | |
2747 | /* rsp->uncorrectable_errors is 8 bits wide, and it pegs at 0xff */ | |
2748 | tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL); | |
2749 | rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff; | |
2750 | ||
58721b8f | 2751 | vlinfo = &rsp->vls[0]; |
77241056 MM |
2752 | vfi = 0; |
2753 | /* The vl_select_mask has been checked above, and we know | |
2754 | * that it contains only entries which represent valid VLs. | |
2755 | * So in the for_each_set_bit() loop below, we don't need | |
2756 | * any additional checks for vl. | |
2757 | */ | |
2758 | for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), | |
2759 | 8 * sizeof(vl_select_mask)) { | |
2760 | memset(vlinfo, 0, sizeof(*vlinfo)); | |
2761 | ||
2762 | tmp = read_dev_cntr(dd, C_DC_RX_FLIT_VL, idx_from_vl(vl)); | |
2763 | rsp->vls[vfi].port_vl_rcv_data = cpu_to_be64(tmp); | |
77241056 MM |
2764 | |
2765 | rsp->vls[vfi].port_vl_rcv_pkts = | |
2766 | cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL, | |
17fb4f29 | 2767 | idx_from_vl(vl))); |
77241056 MM |
2768 | |
2769 | rsp->vls[vfi].port_vl_xmit_data = | |
2770 | cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL, | |
17fb4f29 | 2771 | idx_from_vl(vl))); |
77241056 MM |
2772 | |
2773 | rsp->vls[vfi].port_vl_xmit_pkts = | |
2774 | cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL, | |
17fb4f29 | 2775 | idx_from_vl(vl))); |
77241056 MM |
2776 | |
2777 | rsp->vls[vfi].port_vl_xmit_wait = | |
2778 | cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL, | |
17fb4f29 | 2779 | idx_from_vl(vl))); |
77241056 MM |
2780 | |
2781 | rsp->vls[vfi].port_vl_rcv_fecn = | |
2782 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL, | |
17fb4f29 | 2783 | idx_from_vl(vl))); |
77241056 MM |
2784 | |
2785 | rsp->vls[vfi].port_vl_rcv_becn = | |
2786 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL, | |
17fb4f29 | 2787 | idx_from_vl(vl))); |
77241056 | 2788 | |
583eb8b8 JP |
2789 | rsp->vls[vfi].port_vl_xmit_discards = |
2790 | cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD_VL, | |
2791 | idx_from_vl(vl))); | |
77241056 MM |
2792 | vlinfo++; |
2793 | vfi++; | |
2794 | } | |
2795 | ||
2796 | a0_portstatus(ppd, rsp, vl_select_mask); | |
2797 | ||
2798 | if (resp_len) | |
2799 | *resp_len += response_data_size; | |
2800 | ||
2801 | return reply((struct ib_mad_hdr *)pmp); | |
2802 | } | |
2803 | ||
f0852922 AL |
2804 | static u64 get_error_counter_summary(struct ib_device *ibdev, u8 port, |
2805 | u8 res_lli, u8 res_ler) | |
77241056 MM |
2806 | { |
2807 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2808 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
2809 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
2810 | u64 error_counter_summary = 0, tmp; | |
2811 | ||
2812 | error_counter_summary += read_port_cntr(ppd, C_SW_RCV_CSTR_ERR, | |
2813 | CNTR_INVALID_VL); | |
2814 | /* port_rcv_switch_relay_errors is 0 for HFIs */ | |
2815 | error_counter_summary += read_port_cntr(ppd, C_SW_XMIT_DSCD, | |
2816 | CNTR_INVALID_VL); | |
2817 | error_counter_summary += read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, | |
2818 | CNTR_INVALID_VL); | |
2819 | error_counter_summary += read_dev_cntr(dd, C_DC_RMT_PHY_ERR, | |
17fb4f29 | 2820 | CNTR_INVALID_VL); |
f0852922 | 2821 | /* local link integrity must be right-shifted by the lli resolution */ |
3210314a JP |
2822 | error_counter_summary += (read_dev_cntr(dd, C_DC_RX_REPLAY, |
2823 | CNTR_INVALID_VL) >> res_lli); | |
f0852922 AL |
2824 | /* link error recovery must b right-shifted by the ler resolution */ |
2825 | tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL); | |
2826 | tmp += read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL); | |
2827 | error_counter_summary += (tmp >> res_ler); | |
77241056 | 2828 | error_counter_summary += read_dev_cntr(dd, C_DC_RCV_ERR, |
17fb4f29 | 2829 | CNTR_INVALID_VL); |
77241056 MM |
2830 | error_counter_summary += read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL); |
2831 | error_counter_summary += read_dev_cntr(dd, C_DC_FM_CFG_ERR, | |
17fb4f29 | 2832 | CNTR_INVALID_VL); |
77241056 MM |
2833 | /* ppd->link_downed is a 32-bit value */ |
2834 | error_counter_summary += read_port_cntr(ppd, C_SW_LINK_DOWN, | |
2835 | CNTR_INVALID_VL); | |
2836 | tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL); | |
2837 | /* this is an 8-bit quantity */ | |
2838 | error_counter_summary += tmp < 0x100 ? (tmp & 0xff) : 0xff; | |
2839 | ||
2840 | return error_counter_summary; | |
2841 | } | |
2842 | ||
d9d3e025 | 2843 | static void a0_datacounters(struct hfi1_pportdata *ppd, struct _port_dctrs *rsp, |
77241056 MM |
2844 | u32 vl_select_mask) |
2845 | { | |
d9d3e025 | 2846 | if (!is_bx(ppd->dd)) { |
77241056 | 2847 | unsigned long vl; |
db00a055 | 2848 | u64 sum_vl_xmit_wait = 0; |
d9d3e025 | 2849 | u32 vl_all_mask = VL_MASK_ALL; |
db00a055 | 2850 | |
d9d3e025 IW |
2851 | for_each_set_bit(vl, (unsigned long *)&(vl_all_mask), |
2852 | 8 * sizeof(vl_all_mask)) { | |
77241056 | 2853 | u64 tmp = sum_vl_xmit_wait + |
d9d3e025 IW |
2854 | read_port_cntr(ppd, C_TX_WAIT_VL, |
2855 | idx_from_vl(vl)); | |
77241056 MM |
2856 | if (tmp < sum_vl_xmit_wait) { |
2857 | /* we wrapped */ | |
50e5dcbe | 2858 | sum_vl_xmit_wait = (u64)~0; |
77241056 MM |
2859 | break; |
2860 | } | |
2861 | sum_vl_xmit_wait = tmp; | |
2862 | } | |
2863 | if (be64_to_cpu(rsp->port_xmit_wait) > sum_vl_xmit_wait) | |
2864 | rsp->port_xmit_wait = cpu_to_be64(sum_vl_xmit_wait); | |
2865 | } | |
2866 | } | |
2867 | ||
b8d114eb SS |
2868 | static void pma_get_opa_port_dctrs(struct ib_device *ibdev, |
2869 | struct _port_dctrs *rsp) | |
2870 | { | |
2871 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2872 | ||
2873 | rsp->port_xmit_data = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_FLITS, | |
2874 | CNTR_INVALID_VL)); | |
2875 | rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS, | |
2876 | CNTR_INVALID_VL)); | |
2877 | rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS, | |
2878 | CNTR_INVALID_VL)); | |
2879 | rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS, | |
2880 | CNTR_INVALID_VL)); | |
2881 | rsp->port_multicast_xmit_pkts = | |
2882 | cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS, | |
2883 | CNTR_INVALID_VL)); | |
2884 | rsp->port_multicast_rcv_pkts = | |
2885 | cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS, | |
2886 | CNTR_INVALID_VL)); | |
2887 | } | |
2888 | ||
77241056 | 2889 | static int pma_get_opa_datacounters(struct opa_pma_mad *pmp, |
17fb4f29 JJ |
2890 | struct ib_device *ibdev, |
2891 | u8 port, u32 *resp_len) | |
77241056 MM |
2892 | { |
2893 | struct opa_port_data_counters_msg *req = | |
2894 | (struct opa_port_data_counters_msg *)pmp->data; | |
2895 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2896 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
2897 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
2898 | struct _port_dctrs *rsp; | |
2899 | struct _vls_dctrs *vlinfo; | |
2900 | size_t response_data_size; | |
2901 | u32 num_ports; | |
77241056 | 2902 | u8 lq, num_vls; |
f0852922 | 2903 | u8 res_lli, res_ler; |
77241056 | 2904 | u64 port_mask; |
61a28d2b | 2905 | u8 port_num; |
77241056 MM |
2906 | unsigned long vl; |
2907 | u32 vl_select_mask; | |
2908 | int vfi; | |
2909 | ||
2910 | num_ports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24; | |
77241056 MM |
2911 | num_vls = hweight32(be32_to_cpu(req->vl_select_mask)); |
2912 | vl_select_mask = be32_to_cpu(req->vl_select_mask); | |
f0852922 AL |
2913 | res_lli = (u8)(be32_to_cpu(req->resolution) & MSK_LLI) >> MSK_LLI_SFT; |
2914 | res_lli = res_lli ? res_lli + ADD_LLI : 0; | |
2915 | res_ler = (u8)(be32_to_cpu(req->resolution) & MSK_LER) >> MSK_LER_SFT; | |
2916 | res_ler = res_ler ? res_ler + ADD_LER : 0; | |
77241056 MM |
2917 | |
2918 | if (num_ports != 1 || (vl_select_mask & ~VL_MASK_ALL)) { | |
2919 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2920 | return reply((struct ib_mad_hdr *)pmp); | |
2921 | } | |
2922 | ||
2923 | /* Sanity check */ | |
2924 | response_data_size = sizeof(struct opa_port_data_counters_msg) + | |
2925 | num_vls * sizeof(struct _vls_dctrs); | |
2926 | ||
2927 | if (response_data_size > sizeof(pmp->data)) { | |
2928 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2929 | return reply((struct ib_mad_hdr *)pmp); | |
2930 | } | |
2931 | ||
2932 | /* | |
2933 | * The bit set in the mask needs to be consistent with the | |
2934 | * port the request came in on. | |
2935 | */ | |
2936 | port_mask = be64_to_cpu(req->port_select_mask[3]); | |
2937 | port_num = find_first_bit((unsigned long *)&port_mask, | |
6aaa382f | 2938 | sizeof(port_mask) * 8); |
77241056 | 2939 | |
61a28d2b | 2940 | if (port_num != port) { |
77241056 MM |
2941 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
2942 | return reply((struct ib_mad_hdr *)pmp); | |
2943 | } | |
2944 | ||
acc17d67 | 2945 | rsp = &req->port[0]; |
77241056 MM |
2946 | memset(rsp, 0, sizeof(*rsp)); |
2947 | ||
2948 | rsp->port_number = port; | |
2949 | /* | |
2950 | * Note that link_quality_indicator is a 32 bit quantity in | |
2951 | * 'datacounters' queries (as opposed to 'portinfo' queries, | |
2952 | * where it's a byte). | |
2953 | */ | |
2954 | hfi1_read_link_quality(dd, &lq); | |
2955 | rsp->link_quality_indicator = cpu_to_be32((u32)lq); | |
b8d114eb | 2956 | pma_get_opa_port_dctrs(ibdev, rsp); |
77241056 | 2957 | |
77241056 MM |
2958 | rsp->port_xmit_wait = |
2959 | cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL)); | |
2960 | rsp->port_rcv_fecn = | |
2961 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL)); | |
2962 | rsp->port_rcv_becn = | |
2963 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL)); | |
77241056 | 2964 | rsp->port_error_counter_summary = |
f0852922 AL |
2965 | cpu_to_be64(get_error_counter_summary(ibdev, port, |
2966 | res_lli, res_ler)); | |
77241056 | 2967 | |
58721b8f | 2968 | vlinfo = &rsp->vls[0]; |
77241056 MM |
2969 | vfi = 0; |
2970 | /* The vl_select_mask has been checked above, and we know | |
2971 | * that it contains only entries which represent valid VLs. | |
2972 | * So in the for_each_set_bit() loop below, we don't need | |
2973 | * any additional checks for vl. | |
2974 | */ | |
2975 | for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), | |
17fb4f29 | 2976 | 8 * sizeof(req->vl_select_mask)) { |
77241056 MM |
2977 | memset(vlinfo, 0, sizeof(*vlinfo)); |
2978 | ||
2979 | rsp->vls[vfi].port_vl_xmit_data = | |
2980 | cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL, | |
17fb4f29 | 2981 | idx_from_vl(vl))); |
77241056 MM |
2982 | |
2983 | rsp->vls[vfi].port_vl_rcv_data = | |
2984 | cpu_to_be64(read_dev_cntr(dd, C_DC_RX_FLIT_VL, | |
17fb4f29 | 2985 | idx_from_vl(vl))); |
77241056 MM |
2986 | |
2987 | rsp->vls[vfi].port_vl_xmit_pkts = | |
2988 | cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL, | |
17fb4f29 | 2989 | idx_from_vl(vl))); |
77241056 MM |
2990 | |
2991 | rsp->vls[vfi].port_vl_rcv_pkts = | |
2992 | cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL, | |
17fb4f29 | 2993 | idx_from_vl(vl))); |
77241056 MM |
2994 | |
2995 | rsp->vls[vfi].port_vl_xmit_wait = | |
2996 | cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL, | |
17fb4f29 | 2997 | idx_from_vl(vl))); |
77241056 MM |
2998 | |
2999 | rsp->vls[vfi].port_vl_rcv_fecn = | |
3000 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL, | |
17fb4f29 | 3001 | idx_from_vl(vl))); |
77241056 MM |
3002 | rsp->vls[vfi].port_vl_rcv_becn = |
3003 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL, | |
17fb4f29 | 3004 | idx_from_vl(vl))); |
77241056 MM |
3005 | |
3006 | /* rsp->port_vl_xmit_time_cong is 0 for HFIs */ | |
3007 | /* rsp->port_vl_xmit_wasted_bw ??? */ | |
3008 | /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ??? | |
4d114fdd JJ |
3009 | * does this differ from rsp->vls[vfi].port_vl_xmit_wait |
3010 | */ | |
77241056 | 3011 | /*rsp->vls[vfi].port_vl_mark_fecn = |
4d114fdd JJ |
3012 | * cpu_to_be64(read_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT |
3013 | * + offset)); | |
3014 | */ | |
77241056 MM |
3015 | vlinfo++; |
3016 | vfi++; | |
3017 | } | |
3018 | ||
d9d3e025 | 3019 | a0_datacounters(ppd, rsp, vl_select_mask); |
77241056 MM |
3020 | |
3021 | if (resp_len) | |
3022 | *resp_len += response_data_size; | |
3023 | ||
3024 | return reply((struct ib_mad_hdr *)pmp); | |
3025 | } | |
3026 | ||
b8d114eb SS |
3027 | static int pma_get_ib_portcounters_ext(struct ib_pma_mad *pmp, |
3028 | struct ib_device *ibdev, u8 port) | |
3029 | { | |
3030 | struct ib_pma_portcounters_ext *p = (struct ib_pma_portcounters_ext *) | |
3031 | pmp->data; | |
3032 | struct _port_dctrs rsp; | |
3033 | ||
3034 | if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) { | |
3035 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
3036 | goto bail; | |
3037 | } | |
3038 | ||
3039 | memset(&rsp, 0, sizeof(rsp)); | |
3040 | pma_get_opa_port_dctrs(ibdev, &rsp); | |
3041 | ||
3042 | p->port_xmit_data = rsp.port_xmit_data; | |
3043 | p->port_rcv_data = rsp.port_rcv_data; | |
3044 | p->port_xmit_packets = rsp.port_xmit_pkts; | |
3045 | p->port_rcv_packets = rsp.port_rcv_pkts; | |
3046 | p->port_unicast_xmit_packets = 0; | |
3047 | p->port_unicast_rcv_packets = 0; | |
3048 | p->port_multicast_xmit_packets = rsp.port_multicast_xmit_pkts; | |
3049 | p->port_multicast_rcv_packets = rsp.port_multicast_rcv_pkts; | |
3050 | ||
3051 | bail: | |
3052 | return reply((struct ib_mad_hdr *)pmp); | |
3053 | } | |
3054 | ||
3055 | static void pma_get_opa_port_ectrs(struct ib_device *ibdev, | |
3056 | struct _port_ectrs *rsp, u8 port) | |
3057 | { | |
3058 | u64 tmp, tmp2; | |
3059 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
3060 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3061 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3062 | ||
3063 | tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL); | |
3064 | tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, | |
3065 | CNTR_INVALID_VL); | |
3066 | if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) { | |
3067 | /* overflow/wrapped */ | |
3068 | rsp->link_error_recovery = cpu_to_be32(~0); | |
3069 | } else { | |
3070 | rsp->link_error_recovery = cpu_to_be32(tmp2); | |
3071 | } | |
3072 | ||
3073 | rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN, | |
3074 | CNTR_INVALID_VL)); | |
3075 | rsp->port_rcv_errors = | |
3076 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL)); | |
3077 | rsp->port_rcv_remote_physical_errors = | |
3078 | cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR, | |
3079 | CNTR_INVALID_VL)); | |
3080 | rsp->port_rcv_switch_relay_errors = 0; | |
3081 | rsp->port_xmit_discards = | |
3082 | cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD, | |
3083 | CNTR_INVALID_VL)); | |
3084 | rsp->port_xmit_constraint_errors = | |
3085 | cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, | |
3086 | CNTR_INVALID_VL)); | |
3087 | rsp->port_rcv_constraint_errors = | |
3088 | cpu_to_be64(read_port_cntr(ppd, C_SW_RCV_CSTR_ERR, | |
3089 | CNTR_INVALID_VL)); | |
3210314a JP |
3090 | rsp->local_link_integrity_errors = |
3091 | cpu_to_be64(read_dev_cntr(dd, C_DC_RX_REPLAY, | |
3092 | CNTR_INVALID_VL)); | |
b8d114eb SS |
3093 | rsp->excessive_buffer_overruns = |
3094 | cpu_to_be64(read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL)); | |
3095 | } | |
3096 | ||
77241056 | 3097 | static int pma_get_opa_porterrors(struct opa_pma_mad *pmp, |
17fb4f29 JJ |
3098 | struct ib_device *ibdev, |
3099 | u8 port, u32 *resp_len) | |
77241056 MM |
3100 | { |
3101 | size_t response_data_size; | |
3102 | struct _port_ectrs *rsp; | |
eb2e557c | 3103 | u8 port_num; |
77241056 MM |
3104 | struct opa_port_error_counters64_msg *req; |
3105 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
3106 | u32 num_ports; | |
3107 | u8 num_pslm; | |
3108 | u8 num_vls; | |
3109 | struct hfi1_ibport *ibp; | |
3110 | struct hfi1_pportdata *ppd; | |
3111 | struct _vls_ectrs *vlinfo; | |
3112 | unsigned long vl; | |
b8d114eb | 3113 | u64 port_mask, tmp; |
77241056 MM |
3114 | u32 vl_select_mask; |
3115 | int vfi; | |
3116 | ||
3117 | req = (struct opa_port_error_counters64_msg *)pmp->data; | |
3118 | ||
3119 | num_ports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24; | |
3120 | ||
3121 | num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3])); | |
3122 | num_vls = hweight32(be32_to_cpu(req->vl_select_mask)); | |
3123 | ||
3124 | if (num_ports != 1 || num_ports != num_pslm) { | |
3125 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
3126 | return reply((struct ib_mad_hdr *)pmp); | |
3127 | } | |
3128 | ||
3129 | response_data_size = sizeof(struct opa_port_error_counters64_msg) + | |
3130 | num_vls * sizeof(struct _vls_ectrs); | |
3131 | ||
3132 | if (response_data_size > sizeof(pmp->data)) { | |
3133 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
3134 | return reply((struct ib_mad_hdr *)pmp); | |
3135 | } | |
3136 | /* | |
3137 | * The bit set in the mask needs to be consistent with the | |
3138 | * port the request came in on. | |
3139 | */ | |
3140 | port_mask = be64_to_cpu(req->port_select_mask[3]); | |
3141 | port_num = find_first_bit((unsigned long *)&port_mask, | |
6aaa382f | 3142 | sizeof(port_mask) * 8); |
77241056 | 3143 | |
eb2e557c | 3144 | if (port_num != port) { |
77241056 MM |
3145 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
3146 | return reply((struct ib_mad_hdr *)pmp); | |
3147 | } | |
3148 | ||
acc17d67 | 3149 | rsp = &req->port[0]; |
77241056 MM |
3150 | |
3151 | ibp = to_iport(ibdev, port_num); | |
3152 | ppd = ppd_from_ibp(ibp); | |
3153 | ||
3154 | memset(rsp, 0, sizeof(*rsp)); | |
eb2e557c | 3155 | rsp->port_number = port_num; |
77241056 | 3156 | |
b8d114eb | 3157 | pma_get_opa_port_ectrs(ibdev, rsp, port_num); |
77241056 | 3158 | |
77241056 MM |
3159 | rsp->port_rcv_remote_physical_errors = |
3160 | cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR, | |
b8d114eb | 3161 | CNTR_INVALID_VL)); |
77241056 MM |
3162 | rsp->fm_config_errors = |
3163 | cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR, | |
17fb4f29 | 3164 | CNTR_INVALID_VL)); |
77241056 | 3165 | tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL); |
b8d114eb | 3166 | |
77241056 | 3167 | rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff; |
2b719046 JP |
3168 | rsp->port_rcv_errors = |
3169 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL)); | |
acc17d67 | 3170 | vlinfo = &rsp->vls[0]; |
77241056 MM |
3171 | vfi = 0; |
3172 | vl_select_mask = be32_to_cpu(req->vl_select_mask); | |
3173 | for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), | |
3174 | 8 * sizeof(req->vl_select_mask)) { | |
3175 | memset(vlinfo, 0, sizeof(*vlinfo)); | |
583eb8b8 JP |
3176 | rsp->vls[vfi].port_vl_xmit_discards = |
3177 | cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD_VL, | |
3178 | idx_from_vl(vl))); | |
77241056 MM |
3179 | vlinfo += 1; |
3180 | vfi++; | |
3181 | } | |
3182 | ||
3183 | if (resp_len) | |
3184 | *resp_len += response_data_size; | |
3185 | ||
3186 | return reply((struct ib_mad_hdr *)pmp); | |
3187 | } | |
3188 | ||
b8d114eb SS |
3189 | static int pma_get_ib_portcounters(struct ib_pma_mad *pmp, |
3190 | struct ib_device *ibdev, u8 port) | |
3191 | { | |
3192 | struct ib_pma_portcounters *p = (struct ib_pma_portcounters *) | |
3193 | pmp->data; | |
3194 | struct _port_ectrs rsp; | |
3195 | u64 temp_link_overrun_errors; | |
3196 | u64 temp_64; | |
3197 | u32 temp_32; | |
3198 | ||
3199 | memset(&rsp, 0, sizeof(rsp)); | |
3200 | pma_get_opa_port_ectrs(ibdev, &rsp, port); | |
3201 | ||
3202 | if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) { | |
3203 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
3204 | goto bail; | |
3205 | } | |
3206 | ||
3207 | p->symbol_error_counter = 0; /* N/A for OPA */ | |
3208 | ||
3209 | temp_32 = be32_to_cpu(rsp.link_error_recovery); | |
3210 | if (temp_32 > 0xFFUL) | |
3211 | p->link_error_recovery_counter = 0xFF; | |
3212 | else | |
3213 | p->link_error_recovery_counter = (u8)temp_32; | |
3214 | ||
3215 | temp_32 = be32_to_cpu(rsp.link_downed); | |
3216 | if (temp_32 > 0xFFUL) | |
3217 | p->link_downed_counter = 0xFF; | |
3218 | else | |
3219 | p->link_downed_counter = (u8)temp_32; | |
3220 | ||
3221 | temp_64 = be64_to_cpu(rsp.port_rcv_errors); | |
3222 | if (temp_64 > 0xFFFFUL) | |
3223 | p->port_rcv_errors = cpu_to_be16(0xFFFF); | |
3224 | else | |
3225 | p->port_rcv_errors = cpu_to_be16((u16)temp_64); | |
3226 | ||
3227 | temp_64 = be64_to_cpu(rsp.port_rcv_remote_physical_errors); | |
3228 | if (temp_64 > 0xFFFFUL) | |
3229 | p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF); | |
3230 | else | |
3231 | p->port_rcv_remphys_errors = cpu_to_be16((u16)temp_64); | |
3232 | ||
3233 | temp_64 = be64_to_cpu(rsp.port_rcv_switch_relay_errors); | |
3234 | p->port_rcv_switch_relay_errors = cpu_to_be16((u16)temp_64); | |
3235 | ||
3236 | temp_64 = be64_to_cpu(rsp.port_xmit_discards); | |
3237 | if (temp_64 > 0xFFFFUL) | |
3238 | p->port_xmit_discards = cpu_to_be16(0xFFFF); | |
3239 | else | |
3240 | p->port_xmit_discards = cpu_to_be16((u16)temp_64); | |
3241 | ||
3242 | temp_64 = be64_to_cpu(rsp.port_xmit_constraint_errors); | |
3243 | if (temp_64 > 0xFFUL) | |
3244 | p->port_xmit_constraint_errors = 0xFF; | |
3245 | else | |
3246 | p->port_xmit_constraint_errors = (u8)temp_64; | |
3247 | ||
3248 | temp_64 = be64_to_cpu(rsp.port_rcv_constraint_errors); | |
3249 | if (temp_64 > 0xFFUL) | |
3250 | p->port_rcv_constraint_errors = 0xFFUL; | |
3251 | else | |
3252 | p->port_rcv_constraint_errors = (u8)temp_64; | |
3253 | ||
3254 | /* LocalLink: 7:4, BufferOverrun: 3:0 */ | |
3255 | temp_64 = be64_to_cpu(rsp.local_link_integrity_errors); | |
3256 | if (temp_64 > 0xFUL) | |
3257 | temp_64 = 0xFUL; | |
3258 | ||
3259 | temp_link_overrun_errors = temp_64 << 4; | |
3260 | ||
3261 | temp_64 = be64_to_cpu(rsp.excessive_buffer_overruns); | |
3262 | if (temp_64 > 0xFUL) | |
3263 | temp_64 = 0xFUL; | |
3264 | temp_link_overrun_errors |= temp_64; | |
3265 | ||
3266 | p->link_overrun_errors = (u8)temp_link_overrun_errors; | |
3267 | ||
3268 | p->vl15_dropped = 0; /* N/A for OPA */ | |
3269 | ||
3270 | bail: | |
3271 | return reply((struct ib_mad_hdr *)pmp); | |
3272 | } | |
3273 | ||
77241056 | 3274 | static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp, |
17fb4f29 JJ |
3275 | struct ib_device *ibdev, |
3276 | u8 port, u32 *resp_len) | |
77241056 MM |
3277 | { |
3278 | size_t response_data_size; | |
3279 | struct _port_ei *rsp; | |
3280 | struct opa_port_error_info_msg *req; | |
3281 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
3282 | u64 port_mask; | |
3283 | u32 num_ports; | |
eb2e557c | 3284 | u8 port_num; |
77241056 MM |
3285 | u8 num_pslm; |
3286 | u64 reg; | |
3287 | ||
3288 | req = (struct opa_port_error_info_msg *)pmp->data; | |
acc17d67 | 3289 | rsp = &req->port[0]; |
77241056 MM |
3290 | |
3291 | num_ports = OPA_AM_NPORT(be32_to_cpu(pmp->mad_hdr.attr_mod)); | |
3292 | num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3])); | |
3293 | ||
3294 | memset(rsp, 0, sizeof(*rsp)); | |
3295 | ||
3296 | if (num_ports != 1 || num_ports != num_pslm) { | |
3297 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
3298 | return reply((struct ib_mad_hdr *)pmp); | |
3299 | } | |
3300 | ||
3301 | /* Sanity check */ | |
3302 | response_data_size = sizeof(struct opa_port_error_info_msg); | |
3303 | ||
3304 | if (response_data_size > sizeof(pmp->data)) { | |
3305 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
3306 | return reply((struct ib_mad_hdr *)pmp); | |
3307 | } | |
3308 | ||
3309 | /* | |
3310 | * The bit set in the mask needs to be consistent with the port | |
3311 | * the request came in on. | |
3312 | */ | |
3313 | port_mask = be64_to_cpu(req->port_select_mask[3]); | |
3314 | port_num = find_first_bit((unsigned long *)&port_mask, | |
6aaa382f | 3315 | sizeof(port_mask) * 8); |
77241056 | 3316 | |
eb2e557c | 3317 | if (port_num != port) { |
77241056 MM |
3318 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
3319 | return reply((struct ib_mad_hdr *)pmp); | |
3320 | } | |
3321 | ||
3322 | /* PortRcvErrorInfo */ | |
3323 | rsp->port_rcv_ei.status_and_code = | |
3324 | dd->err_info_rcvport.status_and_code; | |
3325 | memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit1, | |
17fb4f29 | 3326 | &dd->err_info_rcvport.packet_flit1, sizeof(u64)); |
77241056 | 3327 | memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit2, |
17fb4f29 | 3328 | &dd->err_info_rcvport.packet_flit2, sizeof(u64)); |
77241056 MM |
3329 | |
3330 | /* ExcessiverBufferOverrunInfo */ | |
3331 | reg = read_csr(dd, RCV_ERR_INFO); | |
3332 | if (reg & RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK) { | |
4d114fdd JJ |
3333 | /* |
3334 | * if the RcvExcessBufferOverrun bit is set, save SC of | |
3335 | * first pkt that encountered an excess buffer overrun | |
3336 | */ | |
77241056 MM |
3337 | u8 tmp = (u8)reg; |
3338 | ||
3339 | tmp &= RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SC_SMASK; | |
3340 | tmp <<= 2; | |
3341 | rsp->excessive_buffer_overrun_ei.status_and_sc = tmp; | |
3342 | /* set the status bit */ | |
3343 | rsp->excessive_buffer_overrun_ei.status_and_sc |= 0x80; | |
3344 | } | |
3345 | ||
3346 | rsp->port_xmit_constraint_ei.status = | |
3347 | dd->err_info_xmit_constraint.status; | |
3348 | rsp->port_xmit_constraint_ei.pkey = | |
3349 | cpu_to_be16(dd->err_info_xmit_constraint.pkey); | |
3350 | rsp->port_xmit_constraint_ei.slid = | |
3351 | cpu_to_be32(dd->err_info_xmit_constraint.slid); | |
3352 | ||
3353 | rsp->port_rcv_constraint_ei.status = | |
3354 | dd->err_info_rcv_constraint.status; | |
3355 | rsp->port_rcv_constraint_ei.pkey = | |
3356 | cpu_to_be16(dd->err_info_rcv_constraint.pkey); | |
3357 | rsp->port_rcv_constraint_ei.slid = | |
3358 | cpu_to_be32(dd->err_info_rcv_constraint.slid); | |
3359 | ||
3360 | /* UncorrectableErrorInfo */ | |
3361 | rsp->uncorrectable_ei.status_and_code = dd->err_info_uncorrectable; | |
3362 | ||
3363 | /* FMConfigErrorInfo */ | |
3364 | rsp->fm_config_ei.status_and_code = dd->err_info_fmconfig; | |
3365 | ||
3366 | if (resp_len) | |
3367 | *resp_len += response_data_size; | |
3368 | ||
3369 | return reply((struct ib_mad_hdr *)pmp); | |
3370 | } | |
3371 | ||
3372 | static int pma_set_opa_portstatus(struct opa_pma_mad *pmp, | |
17fb4f29 JJ |
3373 | struct ib_device *ibdev, |
3374 | u8 port, u32 *resp_len) | |
77241056 MM |
3375 | { |
3376 | struct opa_clear_port_status *req = | |
3377 | (struct opa_clear_port_status *)pmp->data; | |
3378 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
3379 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3380 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3381 | u32 nports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24; | |
3382 | u64 portn = be64_to_cpu(req->port_select_mask[3]); | |
3383 | u32 counter_select = be32_to_cpu(req->counter_select_mask); | |
3384 | u32 vl_select_mask = VL_MASK_ALL; /* clear all per-vl cnts */ | |
3385 | unsigned long vl; | |
3386 | ||
3387 | if ((nports != 1) || (portn != 1 << port)) { | |
3388 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
3389 | return reply((struct ib_mad_hdr *)pmp); | |
3390 | } | |
3391 | /* | |
3392 | * only counters returned by pma_get_opa_portstatus() are | |
3393 | * handled, so when pma_get_opa_portstatus() gets a fix, | |
3394 | * the corresponding change should be made here as well. | |
3395 | */ | |
3396 | ||
3397 | if (counter_select & CS_PORT_XMIT_DATA) | |
3398 | write_dev_cntr(dd, C_DC_XMIT_FLITS, CNTR_INVALID_VL, 0); | |
3399 | ||
3400 | if (counter_select & CS_PORT_RCV_DATA) | |
3401 | write_dev_cntr(dd, C_DC_RCV_FLITS, CNTR_INVALID_VL, 0); | |
3402 | ||
3403 | if (counter_select & CS_PORT_XMIT_PKTS) | |
3404 | write_dev_cntr(dd, C_DC_XMIT_PKTS, CNTR_INVALID_VL, 0); | |
3405 | ||
3406 | if (counter_select & CS_PORT_RCV_PKTS) | |
3407 | write_dev_cntr(dd, C_DC_RCV_PKTS, CNTR_INVALID_VL, 0); | |
3408 | ||
3409 | if (counter_select & CS_PORT_MCAST_XMIT_PKTS) | |
3410 | write_dev_cntr(dd, C_DC_MC_XMIT_PKTS, CNTR_INVALID_VL, 0); | |
3411 | ||
3412 | if (counter_select & CS_PORT_MCAST_RCV_PKTS) | |
3413 | write_dev_cntr(dd, C_DC_MC_RCV_PKTS, CNTR_INVALID_VL, 0); | |
3414 | ||
3415 | if (counter_select & CS_PORT_XMIT_WAIT) | |
3416 | write_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL, 0); | |
3417 | ||
3418 | /* ignore cs_sw_portCongestion for HFIs */ | |
3419 | ||
3420 | if (counter_select & CS_PORT_RCV_FECN) | |
3421 | write_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL, 0); | |
3422 | ||
3423 | if (counter_select & CS_PORT_RCV_BECN) | |
3424 | write_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL, 0); | |
3425 | ||
3426 | /* ignore cs_port_xmit_time_cong for HFIs */ | |
3427 | /* ignore cs_port_xmit_wasted_bw for now */ | |
3428 | /* ignore cs_port_xmit_wait_data for now */ | |
3429 | if (counter_select & CS_PORT_RCV_BUBBLE) | |
3430 | write_dev_cntr(dd, C_DC_RCV_BBL, CNTR_INVALID_VL, 0); | |
3431 | ||
3432 | /* Only applicable for switch */ | |
4d114fdd JJ |
3433 | /* if (counter_select & CS_PORT_MARK_FECN) |
3434 | * write_csr(dd, DCC_PRF_PORT_MARK_FECN_CNT, 0); | |
3435 | */ | |
77241056 MM |
3436 | |
3437 | if (counter_select & CS_PORT_RCV_CONSTRAINT_ERRORS) | |
3438 | write_port_cntr(ppd, C_SW_RCV_CSTR_ERR, CNTR_INVALID_VL, 0); | |
3439 | ||
3440 | /* ignore cs_port_rcv_switch_relay_errors for HFIs */ | |
3441 | if (counter_select & CS_PORT_XMIT_DISCARDS) | |
3442 | write_port_cntr(ppd, C_SW_XMIT_DSCD, CNTR_INVALID_VL, 0); | |
3443 | ||
3444 | if (counter_select & CS_PORT_XMIT_CONSTRAINT_ERRORS) | |
3445 | write_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, CNTR_INVALID_VL, 0); | |
3446 | ||
3447 | if (counter_select & CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS) | |
3448 | write_dev_cntr(dd, C_DC_RMT_PHY_ERR, CNTR_INVALID_VL, 0); | |
3449 | ||
3210314a | 3450 | if (counter_select & CS_LOCAL_LINK_INTEGRITY_ERRORS) |
77241056 | 3451 | write_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL, 0); |
77241056 MM |
3452 | |
3453 | if (counter_select & CS_LINK_ERROR_RECOVERY) { | |
3454 | write_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL, 0); | |
3455 | write_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, | |
17fb4f29 | 3456 | CNTR_INVALID_VL, 0); |
77241056 MM |
3457 | } |
3458 | ||
3459 | if (counter_select & CS_PORT_RCV_ERRORS) | |
3460 | write_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL, 0); | |
3461 | ||
3462 | if (counter_select & CS_EXCESSIVE_BUFFER_OVERRUNS) { | |
3463 | write_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL, 0); | |
3464 | dd->rcv_ovfl_cnt = 0; | |
3465 | } | |
3466 | ||
3467 | if (counter_select & CS_FM_CONFIG_ERRORS) | |
3468 | write_dev_cntr(dd, C_DC_FM_CFG_ERR, CNTR_INVALID_VL, 0); | |
3469 | ||
3470 | if (counter_select & CS_LINK_DOWNED) | |
3471 | write_port_cntr(ppd, C_SW_LINK_DOWN, CNTR_INVALID_VL, 0); | |
3472 | ||
3473 | if (counter_select & CS_UNCORRECTABLE_ERRORS) | |
3474 | write_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL, 0); | |
3475 | ||
3476 | for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), | |
3477 | 8 * sizeof(vl_select_mask)) { | |
77241056 MM |
3478 | if (counter_select & CS_PORT_XMIT_DATA) |
3479 | write_port_cntr(ppd, C_TX_FLIT_VL, idx_from_vl(vl), 0); | |
3480 | ||
3481 | if (counter_select & CS_PORT_RCV_DATA) | |
3482 | write_dev_cntr(dd, C_DC_RX_FLIT_VL, idx_from_vl(vl), 0); | |
3483 | ||
3484 | if (counter_select & CS_PORT_XMIT_PKTS) | |
3485 | write_port_cntr(ppd, C_TX_PKT_VL, idx_from_vl(vl), 0); | |
3486 | ||
3487 | if (counter_select & CS_PORT_RCV_PKTS) | |
3488 | write_dev_cntr(dd, C_DC_RX_PKT_VL, idx_from_vl(vl), 0); | |
3489 | ||
3490 | if (counter_select & CS_PORT_XMIT_WAIT) | |
3491 | write_port_cntr(ppd, C_TX_WAIT_VL, idx_from_vl(vl), 0); | |
3492 | ||
3493 | /* sw_port_vl_congestion is 0 for HFIs */ | |
3494 | if (counter_select & CS_PORT_RCV_FECN) | |
3495 | write_dev_cntr(dd, C_DC_RCV_FCN_VL, idx_from_vl(vl), 0); | |
3496 | ||
3497 | if (counter_select & CS_PORT_RCV_BECN) | |
3498 | write_dev_cntr(dd, C_DC_RCV_BCN_VL, idx_from_vl(vl), 0); | |
3499 | ||
3500 | /* port_vl_xmit_time_cong is 0 for HFIs */ | |
3501 | /* port_vl_xmit_wasted_bw ??? */ | |
3502 | /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ??? */ | |
3503 | if (counter_select & CS_PORT_RCV_BUBBLE) | |
3504 | write_dev_cntr(dd, C_DC_RCV_BBL_VL, idx_from_vl(vl), 0); | |
3505 | ||
4d114fdd JJ |
3506 | /* if (counter_select & CS_PORT_MARK_FECN) |
3507 | * write_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT + offset, 0); | |
3508 | */ | |
583eb8b8 JP |
3509 | if (counter_select & C_SW_XMIT_DSCD_VL) |
3510 | write_port_cntr(ppd, C_SW_XMIT_DSCD_VL, | |
3511 | idx_from_vl(vl), 0); | |
77241056 MM |
3512 | } |
3513 | ||
3514 | if (resp_len) | |
3515 | *resp_len += sizeof(*req); | |
3516 | ||
3517 | return reply((struct ib_mad_hdr *)pmp); | |
3518 | } | |
3519 | ||
3520 | static int pma_set_opa_errorinfo(struct opa_pma_mad *pmp, | |
17fb4f29 JJ |
3521 | struct ib_device *ibdev, |
3522 | u8 port, u32 *resp_len) | |
77241056 MM |
3523 | { |
3524 | struct _port_ei *rsp; | |
3525 | struct opa_port_error_info_msg *req; | |
3526 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
3527 | u64 port_mask; | |
3528 | u32 num_ports; | |
eb2e557c | 3529 | u8 port_num; |
77241056 MM |
3530 | u8 num_pslm; |
3531 | u32 error_info_select; | |
3532 | ||
3533 | req = (struct opa_port_error_info_msg *)pmp->data; | |
acc17d67 | 3534 | rsp = &req->port[0]; |
77241056 MM |
3535 | |
3536 | num_ports = OPA_AM_NPORT(be32_to_cpu(pmp->mad_hdr.attr_mod)); | |
3537 | num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3])); | |
3538 | ||
3539 | memset(rsp, 0, sizeof(*rsp)); | |
3540 | ||
3541 | if (num_ports != 1 || num_ports != num_pslm) { | |
3542 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
3543 | return reply((struct ib_mad_hdr *)pmp); | |
3544 | } | |
3545 | ||
3546 | /* | |
3547 | * The bit set in the mask needs to be consistent with the port | |
3548 | * the request came in on. | |
3549 | */ | |
3550 | port_mask = be64_to_cpu(req->port_select_mask[3]); | |
3551 | port_num = find_first_bit((unsigned long *)&port_mask, | |
6aaa382f | 3552 | sizeof(port_mask) * 8); |
77241056 | 3553 | |
eb2e557c | 3554 | if (port_num != port) { |
77241056 MM |
3555 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
3556 | return reply((struct ib_mad_hdr *)pmp); | |
3557 | } | |
3558 | ||
3559 | error_info_select = be32_to_cpu(req->error_info_select_mask); | |
3560 | ||
3561 | /* PortRcvErrorInfo */ | |
3562 | if (error_info_select & ES_PORT_RCV_ERROR_INFO) | |
3563 | /* turn off status bit */ | |
3564 | dd->err_info_rcvport.status_and_code &= ~OPA_EI_STATUS_SMASK; | |
3565 | ||
3566 | /* ExcessiverBufferOverrunInfo */ | |
3567 | if (error_info_select & ES_EXCESSIVE_BUFFER_OVERRUN_INFO) | |
4d114fdd JJ |
3568 | /* |
3569 | * status bit is essentially kept in the h/w - bit 5 of | |
3570 | * RCV_ERR_INFO | |
3571 | */ | |
77241056 MM |
3572 | write_csr(dd, RCV_ERR_INFO, |
3573 | RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK); | |
3574 | ||
3575 | if (error_info_select & ES_PORT_XMIT_CONSTRAINT_ERROR_INFO) | |
3576 | dd->err_info_xmit_constraint.status &= ~OPA_EI_STATUS_SMASK; | |
3577 | ||
3578 | if (error_info_select & ES_PORT_RCV_CONSTRAINT_ERROR_INFO) | |
3579 | dd->err_info_rcv_constraint.status &= ~OPA_EI_STATUS_SMASK; | |
3580 | ||
3581 | /* UncorrectableErrorInfo */ | |
3582 | if (error_info_select & ES_UNCORRECTABLE_ERROR_INFO) | |
3583 | /* turn off status bit */ | |
3584 | dd->err_info_uncorrectable &= ~OPA_EI_STATUS_SMASK; | |
3585 | ||
3586 | /* FMConfigErrorInfo */ | |
3587 | if (error_info_select & ES_FM_CONFIG_ERROR_INFO) | |
3588 | /* turn off status bit */ | |
3589 | dd->err_info_fmconfig &= ~OPA_EI_STATUS_SMASK; | |
3590 | ||
3591 | if (resp_len) | |
3592 | *resp_len += sizeof(*req); | |
3593 | ||
3594 | return reply((struct ib_mad_hdr *)pmp); | |
3595 | } | |
3596 | ||
3597 | struct opa_congestion_info_attr { | |
3598 | __be16 congestion_info; | |
3599 | u8 control_table_cap; /* Multiple of 64 entry unit CCTs */ | |
3600 | u8 congestion_log_length; | |
3601 | } __packed; | |
3602 | ||
3603 | static int __subn_get_opa_cong_info(struct opa_smp *smp, u32 am, u8 *data, | |
3604 | struct ib_device *ibdev, u8 port, | |
f1685179 | 3605 | u32 *resp_len, u32 max_len) |
77241056 MM |
3606 | { |
3607 | struct opa_congestion_info_attr *p = | |
3608 | (struct opa_congestion_info_attr *)data; | |
3609 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3610 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3611 | ||
f1685179 ND |
3612 | if (smp_length_check(sizeof(*p), max_len)) { |
3613 | smp->status |= IB_SMP_INVALID_FIELD; | |
3614 | return reply((struct ib_mad_hdr *)smp); | |
3615 | } | |
3616 | ||
77241056 MM |
3617 | p->congestion_info = 0; |
3618 | p->control_table_cap = ppd->cc_max_table_entries; | |
3619 | p->congestion_log_length = OPA_CONG_LOG_ELEMS; | |
3620 | ||
3621 | if (resp_len) | |
3622 | *resp_len += sizeof(*p); | |
3623 | ||
3624 | return reply((struct ib_mad_hdr *)smp); | |
3625 | } | |
3626 | ||
3627 | static int __subn_get_opa_cong_setting(struct opa_smp *smp, u32 am, | |
17fb4f29 | 3628 | u8 *data, struct ib_device *ibdev, |
f1685179 | 3629 | u8 port, u32 *resp_len, u32 max_len) |
77241056 MM |
3630 | { |
3631 | int i; | |
3632 | struct opa_congestion_setting_attr *p = | |
50e5dcbe | 3633 | (struct opa_congestion_setting_attr *)data; |
77241056 MM |
3634 | struct hfi1_ibport *ibp = to_iport(ibdev, port); |
3635 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3636 | struct opa_congestion_setting_entry_shadow *entries; | |
3637 | struct cc_state *cc_state; | |
3638 | ||
f1685179 ND |
3639 | if (smp_length_check(sizeof(*p), max_len)) { |
3640 | smp->status |= IB_SMP_INVALID_FIELD; | |
3641 | return reply((struct ib_mad_hdr *)smp); | |
3642 | } | |
3643 | ||
77241056 MM |
3644 | rcu_read_lock(); |
3645 | ||
3646 | cc_state = get_cc_state(ppd); | |
3647 | ||
d125a6c6 | 3648 | if (!cc_state) { |
77241056 MM |
3649 | rcu_read_unlock(); |
3650 | return reply((struct ib_mad_hdr *)smp); | |
3651 | } | |
3652 | ||
3653 | entries = cc_state->cong_setting.entries; | |
3654 | p->port_control = cpu_to_be16(cc_state->cong_setting.port_control); | |
3655 | p->control_map = cpu_to_be32(cc_state->cong_setting.control_map); | |
3656 | for (i = 0; i < OPA_MAX_SLS; i++) { | |
3657 | p->entries[i].ccti_increase = entries[i].ccti_increase; | |
3658 | p->entries[i].ccti_timer = cpu_to_be16(entries[i].ccti_timer); | |
3659 | p->entries[i].trigger_threshold = | |
3660 | entries[i].trigger_threshold; | |
3661 | p->entries[i].ccti_min = entries[i].ccti_min; | |
3662 | } | |
3663 | ||
3664 | rcu_read_unlock(); | |
3665 | ||
3666 | if (resp_len) | |
3667 | *resp_len += sizeof(*p); | |
3668 | ||
3669 | return reply((struct ib_mad_hdr *)smp); | |
3670 | } | |
3671 | ||
f036780b DL |
3672 | /* |
3673 | * Apply congestion control information stored in the ppd to the | |
3674 | * active structure. | |
3675 | */ | |
3676 | static void apply_cc_state(struct hfi1_pportdata *ppd) | |
3677 | { | |
3678 | struct cc_state *old_cc_state, *new_cc_state; | |
3679 | ||
3680 | new_cc_state = kzalloc(sizeof(*new_cc_state), GFP_KERNEL); | |
3681 | if (!new_cc_state) | |
3682 | return; | |
3683 | ||
3684 | /* | |
3685 | * Hold the lock for updating *and* to prevent ppd information | |
3686 | * from changing during the update. | |
3687 | */ | |
3688 | spin_lock(&ppd->cc_state_lock); | |
3689 | ||
8adf71fa | 3690 | old_cc_state = get_cc_state_protected(ppd); |
f036780b DL |
3691 | if (!old_cc_state) { |
3692 | /* never active, or shutting down */ | |
3693 | spin_unlock(&ppd->cc_state_lock); | |
3694 | kfree(new_cc_state); | |
3695 | return; | |
3696 | } | |
3697 | ||
3698 | *new_cc_state = *old_cc_state; | |
3699 | ||
3700 | new_cc_state->cct.ccti_limit = ppd->total_cct_entry - 1; | |
3701 | memcpy(new_cc_state->cct.entries, ppd->ccti_entries, | |
3702 | ppd->total_cct_entry * sizeof(struct ib_cc_table_entry)); | |
3703 | ||
3704 | new_cc_state->cong_setting.port_control = IB_CC_CCS_PC_SL_BASED; | |
3705 | new_cc_state->cong_setting.control_map = ppd->cc_sl_control_map; | |
3706 | memcpy(new_cc_state->cong_setting.entries, ppd->congestion_entries, | |
3707 | OPA_MAX_SLS * sizeof(struct opa_congestion_setting_entry)); | |
3708 | ||
3709 | rcu_assign_pointer(ppd->cc_state, new_cc_state); | |
3710 | ||
3711 | spin_unlock(&ppd->cc_state_lock); | |
3712 | ||
476d95bd | 3713 | kfree_rcu(old_cc_state, rcu); |
f036780b DL |
3714 | } |
3715 | ||
77241056 MM |
3716 | static int __subn_set_opa_cong_setting(struct opa_smp *smp, u32 am, u8 *data, |
3717 | struct ib_device *ibdev, u8 port, | |
f1685179 | 3718 | u32 *resp_len, u32 max_len) |
77241056 MM |
3719 | { |
3720 | struct opa_congestion_setting_attr *p = | |
50e5dcbe | 3721 | (struct opa_congestion_setting_attr *)data; |
77241056 MM |
3722 | struct hfi1_ibport *ibp = to_iport(ibdev, port); |
3723 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3724 | struct opa_congestion_setting_entry_shadow *entries; | |
3725 | int i; | |
3726 | ||
f1685179 ND |
3727 | if (smp_length_check(sizeof(*p), max_len)) { |
3728 | smp->status |= IB_SMP_INVALID_FIELD; | |
3729 | return reply((struct ib_mad_hdr *)smp); | |
3730 | } | |
3731 | ||
f036780b DL |
3732 | /* |
3733 | * Save details from packet into the ppd. Hold the cc_state_lock so | |
3734 | * our information is consistent with anyone trying to apply the state. | |
3735 | */ | |
3736 | spin_lock(&ppd->cc_state_lock); | |
77241056 MM |
3737 | ppd->cc_sl_control_map = be32_to_cpu(p->control_map); |
3738 | ||
3739 | entries = ppd->congestion_entries; | |
3740 | for (i = 0; i < OPA_MAX_SLS; i++) { | |
3741 | entries[i].ccti_increase = p->entries[i].ccti_increase; | |
3742 | entries[i].ccti_timer = be16_to_cpu(p->entries[i].ccti_timer); | |
3743 | entries[i].trigger_threshold = | |
3744 | p->entries[i].trigger_threshold; | |
3745 | entries[i].ccti_min = p->entries[i].ccti_min; | |
3746 | } | |
f036780b DL |
3747 | spin_unlock(&ppd->cc_state_lock); |
3748 | ||
3749 | /* now apply the information */ | |
3750 | apply_cc_state(ppd); | |
77241056 MM |
3751 | |
3752 | return __subn_get_opa_cong_setting(smp, am, data, ibdev, port, | |
f1685179 | 3753 | resp_len, max_len); |
77241056 MM |
3754 | } |
3755 | ||
3756 | static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am, | |
3757 | u8 *data, struct ib_device *ibdev, | |
f1685179 | 3758 | u8 port, u32 *resp_len, u32 max_len) |
77241056 MM |
3759 | { |
3760 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3761 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3762 | struct opa_hfi1_cong_log *cong_log = (struct opa_hfi1_cong_log *)data; | |
d61ea075 | 3763 | u64 ts; |
77241056 MM |
3764 | int i; |
3765 | ||
f1685179 | 3766 | if (am || smp_length_check(sizeof(*cong_log), max_len)) { |
77241056 MM |
3767 | smp->status |= IB_SMP_INVALID_FIELD; |
3768 | return reply((struct ib_mad_hdr *)smp); | |
3769 | } | |
3770 | ||
b77d713a | 3771 | spin_lock_irq(&ppd->cc_log_lock); |
77241056 MM |
3772 | |
3773 | cong_log->log_type = OPA_CC_LOG_TYPE_HFI; | |
3774 | cong_log->congestion_flags = 0; | |
3775 | cong_log->threshold_event_counter = | |
3776 | cpu_to_be16(ppd->threshold_event_counter); | |
3777 | memcpy(cong_log->threshold_cong_event_map, | |
3778 | ppd->threshold_cong_event_map, | |
3779 | sizeof(cong_log->threshold_cong_event_map)); | |
3780 | /* keep timestamp in units of 1.024 usec */ | |
d61ea075 | 3781 | ts = ktime_get_ns() / 1024; |
77241056 MM |
3782 | cong_log->current_time_stamp = cpu_to_be32(ts); |
3783 | for (i = 0; i < OPA_CONG_LOG_ELEMS; i++) { | |
3784 | struct opa_hfi1_cong_log_event_internal *cce = | |
3785 | &ppd->cc_events[ppd->cc_mad_idx++]; | |
3786 | if (ppd->cc_mad_idx == OPA_CONG_LOG_ELEMS) | |
3787 | ppd->cc_mad_idx = 0; | |
3788 | /* | |
3789 | * Entries which are older than twice the time | |
3790 | * required to wrap the counter are supposed to | |
3791 | * be zeroed (CA10-49 IBTA, release 1.2.1, V1). | |
3792 | */ | |
d61ea075 | 3793 | if ((ts - cce->timestamp) / 2 > U32_MAX) |
77241056 MM |
3794 | continue; |
3795 | memcpy(cong_log->events[i].local_qp_cn_entry, &cce->lqpn, 3); | |
3796 | memcpy(cong_log->events[i].remote_qp_number_cn_entry, | |
17fb4f29 | 3797 | &cce->rqpn, 3); |
77241056 MM |
3798 | cong_log->events[i].sl_svc_type_cn_entry = |
3799 | ((cce->sl & 0x1f) << 3) | (cce->svc_type & 0x7); | |
3800 | cong_log->events[i].remote_lid_cn_entry = | |
3801 | cpu_to_be32(cce->rlid); | |
3802 | cong_log->events[i].timestamp_cn_entry = | |
3803 | cpu_to_be32(cce->timestamp); | |
3804 | } | |
3805 | ||
3806 | /* | |
3807 | * Reset threshold_cong_event_map, and threshold_event_counter | |
3808 | * to 0 when log is read. | |
3809 | */ | |
3810 | memset(ppd->threshold_cong_event_map, 0x0, | |
3811 | sizeof(ppd->threshold_cong_event_map)); | |
3812 | ppd->threshold_event_counter = 0; | |
3813 | ||
b77d713a | 3814 | spin_unlock_irq(&ppd->cc_log_lock); |
77241056 MM |
3815 | |
3816 | if (resp_len) | |
3817 | *resp_len += sizeof(struct opa_hfi1_cong_log); | |
3818 | ||
3819 | return reply((struct ib_mad_hdr *)smp); | |
3820 | } | |
3821 | ||
3822 | static int __subn_get_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data, | |
3823 | struct ib_device *ibdev, u8 port, | |
f1685179 | 3824 | u32 *resp_len, u32 max_len) |
77241056 MM |
3825 | { |
3826 | struct ib_cc_table_attr *cc_table_attr = | |
50e5dcbe | 3827 | (struct ib_cc_table_attr *)data; |
77241056 MM |
3828 | struct hfi1_ibport *ibp = to_iport(ibdev, port); |
3829 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3830 | u32 start_block = OPA_AM_START_BLK(am); | |
3831 | u32 n_blocks = OPA_AM_NBLK(am); | |
3832 | struct ib_cc_table_entry_shadow *entries; | |
3833 | int i, j; | |
3834 | u32 sentry, eentry; | |
3835 | struct cc_state *cc_state; | |
f1685179 | 3836 | u32 size = sizeof(u16) * (IB_CCT_ENTRIES * n_blocks + 1); |
77241056 MM |
3837 | |
3838 | /* sanity check n_blocks, start_block */ | |
f1685179 | 3839 | if (n_blocks == 0 || smp_length_check(size, max_len) || |
77241056 MM |
3840 | start_block + n_blocks > ppd->cc_max_table_entries) { |
3841 | smp->status |= IB_SMP_INVALID_FIELD; | |
3842 | return reply((struct ib_mad_hdr *)smp); | |
3843 | } | |
3844 | ||
3845 | rcu_read_lock(); | |
3846 | ||
3847 | cc_state = get_cc_state(ppd); | |
3848 | ||
d125a6c6 | 3849 | if (!cc_state) { |
77241056 MM |
3850 | rcu_read_unlock(); |
3851 | return reply((struct ib_mad_hdr *)smp); | |
3852 | } | |
3853 | ||
3854 | sentry = start_block * IB_CCT_ENTRIES; | |
3855 | eentry = sentry + (IB_CCT_ENTRIES * n_blocks); | |
3856 | ||
3857 | cc_table_attr->ccti_limit = cpu_to_be16(cc_state->cct.ccti_limit); | |
3858 | ||
3859 | entries = cc_state->cct.entries; | |
3860 | ||
3861 | /* return n_blocks, though the last block may not be full */ | |
3862 | for (j = 0, i = sentry; i < eentry; j++, i++) | |
3863 | cc_table_attr->ccti_entries[j].entry = | |
3864 | cpu_to_be16(entries[i].entry); | |
3865 | ||
3866 | rcu_read_unlock(); | |
3867 | ||
3868 | if (resp_len) | |
f1685179 | 3869 | *resp_len += size; |
77241056 MM |
3870 | |
3871 | return reply((struct ib_mad_hdr *)smp); | |
3872 | } | |
3873 | ||
77241056 MM |
3874 | static int __subn_set_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data, |
3875 | struct ib_device *ibdev, u8 port, | |
f1685179 | 3876 | u32 *resp_len, u32 max_len) |
77241056 | 3877 | { |
50e5dcbe | 3878 | struct ib_cc_table_attr *p = (struct ib_cc_table_attr *)data; |
77241056 MM |
3879 | struct hfi1_ibport *ibp = to_iport(ibdev, port); |
3880 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3881 | u32 start_block = OPA_AM_START_BLK(am); | |
3882 | u32 n_blocks = OPA_AM_NBLK(am); | |
3883 | struct ib_cc_table_entry_shadow *entries; | |
3884 | int i, j; | |
3885 | u32 sentry, eentry; | |
3886 | u16 ccti_limit; | |
f1685179 | 3887 | u32 size = sizeof(u16) * (IB_CCT_ENTRIES * n_blocks + 1); |
77241056 MM |
3888 | |
3889 | /* sanity check n_blocks, start_block */ | |
f1685179 | 3890 | if (n_blocks == 0 || smp_length_check(size, max_len) || |
77241056 MM |
3891 | start_block + n_blocks > ppd->cc_max_table_entries) { |
3892 | smp->status |= IB_SMP_INVALID_FIELD; | |
3893 | return reply((struct ib_mad_hdr *)smp); | |
3894 | } | |
3895 | ||
3896 | sentry = start_block * IB_CCT_ENTRIES; | |
3897 | eentry = sentry + ((n_blocks - 1) * IB_CCT_ENTRIES) + | |
3898 | (be16_to_cpu(p->ccti_limit)) % IB_CCT_ENTRIES + 1; | |
3899 | ||
3900 | /* sanity check ccti_limit */ | |
3901 | ccti_limit = be16_to_cpu(p->ccti_limit); | |
3902 | if (ccti_limit + 1 > eentry) { | |
3903 | smp->status |= IB_SMP_INVALID_FIELD; | |
3904 | return reply((struct ib_mad_hdr *)smp); | |
3905 | } | |
3906 | ||
f036780b DL |
3907 | /* |
3908 | * Save details from packet into the ppd. Hold the cc_state_lock so | |
3909 | * our information is consistent with anyone trying to apply the state. | |
3910 | */ | |
77241056 | 3911 | spin_lock(&ppd->cc_state_lock); |
77241056 | 3912 | ppd->total_cct_entry = ccti_limit + 1; |
f036780b | 3913 | entries = ppd->ccti_entries; |
77241056 MM |
3914 | for (j = 0, i = sentry; i < eentry; j++, i++) |
3915 | entries[i].entry = be16_to_cpu(p->ccti_entries[j].entry); | |
77241056 MM |
3916 | spin_unlock(&ppd->cc_state_lock); |
3917 | ||
f036780b DL |
3918 | /* now apply the information */ |
3919 | apply_cc_state(ppd); | |
77241056 | 3920 | |
f1685179 ND |
3921 | return __subn_get_opa_cc_table(smp, am, data, ibdev, port, resp_len, |
3922 | max_len); | |
77241056 MM |
3923 | } |
3924 | ||
3925 | struct opa_led_info { | |
3926 | __be32 rsvd_led_mask; | |
3927 | __be32 rsvd; | |
3928 | }; | |
3929 | ||
3930 | #define OPA_LED_SHIFT 31 | |
349ac71f | 3931 | #define OPA_LED_MASK BIT(OPA_LED_SHIFT) |
77241056 MM |
3932 | |
3933 | static int __subn_get_opa_led_info(struct opa_smp *smp, u32 am, u8 *data, | |
3934 | struct ib_device *ibdev, u8 port, | |
f1685179 | 3935 | u32 *resp_len, u32 max_len) |
77241056 MM |
3936 | { |
3937 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
409b1462 | 3938 | struct hfi1_pportdata *ppd = dd->pport; |
50e5dcbe | 3939 | struct opa_led_info *p = (struct opa_led_info *)data; |
77241056 | 3940 | u32 nport = OPA_AM_NPORT(am); |
409b1462 | 3941 | u32 is_beaconing_active; |
77241056 | 3942 | |
f1685179 | 3943 | if (nport != 1 || smp_length_check(sizeof(*p), max_len)) { |
77241056 MM |
3944 | smp->status |= IB_SMP_INVALID_FIELD; |
3945 | return reply((struct ib_mad_hdr *)smp); | |
3946 | } | |
3947 | ||
409b1462 | 3948 | /* |
2243472e EH |
3949 | * This pairs with the memory barrier in hfi1_start_led_override to |
3950 | * ensure that we read the correct state of LED beaconing represented | |
3951 | * by led_override_timer_active | |
409b1462 | 3952 | */ |
2243472e | 3953 | smp_rmb(); |
409b1462 EH |
3954 | is_beaconing_active = !!atomic_read(&ppd->led_override_timer_active); |
3955 | p->rsvd_led_mask = cpu_to_be32(is_beaconing_active << OPA_LED_SHIFT); | |
77241056 MM |
3956 | |
3957 | if (resp_len) | |
3958 | *resp_len += sizeof(struct opa_led_info); | |
3959 | ||
3960 | return reply((struct ib_mad_hdr *)smp); | |
3961 | } | |
3962 | ||
3963 | static int __subn_set_opa_led_info(struct opa_smp *smp, u32 am, u8 *data, | |
3964 | struct ib_device *ibdev, u8 port, | |
f1685179 | 3965 | u32 *resp_len, u32 max_len) |
77241056 MM |
3966 | { |
3967 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
50e5dcbe | 3968 | struct opa_led_info *p = (struct opa_led_info *)data; |
77241056 MM |
3969 | u32 nport = OPA_AM_NPORT(am); |
3970 | int on = !!(be32_to_cpu(p->rsvd_led_mask) & OPA_LED_MASK); | |
3971 | ||
f1685179 | 3972 | if (nport != 1 || smp_length_check(sizeof(*p), max_len)) { |
77241056 MM |
3973 | smp->status |= IB_SMP_INVALID_FIELD; |
3974 | return reply((struct ib_mad_hdr *)smp); | |
3975 | } | |
3976 | ||
91ab4ed3 | 3977 | if (on) |
2243472e | 3978 | hfi1_start_led_override(dd->pport, 2000, 1500); |
91ab4ed3 | 3979 | else |
2243472e | 3980 | shutdown_led_override(dd->pport); |
77241056 | 3981 | |
f1685179 ND |
3982 | return __subn_get_opa_led_info(smp, am, data, ibdev, port, resp_len, |
3983 | max_len); | |
77241056 MM |
3984 | } |
3985 | ||
3986 | static int subn_get_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am, | |
3987 | u8 *data, struct ib_device *ibdev, u8 port, | |
f1685179 | 3988 | u32 *resp_len, u32 max_len) |
77241056 MM |
3989 | { |
3990 | int ret; | |
3991 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3992 | ||
3993 | switch (attr_id) { | |
3994 | case IB_SMP_ATTR_NODE_DESC: | |
3995 | ret = __subn_get_opa_nodedesc(smp, am, data, ibdev, port, | |
f1685179 | 3996 | resp_len, max_len); |
77241056 MM |
3997 | break; |
3998 | case IB_SMP_ATTR_NODE_INFO: | |
3999 | ret = __subn_get_opa_nodeinfo(smp, am, data, ibdev, port, | |
f1685179 | 4000 | resp_len, max_len); |
77241056 MM |
4001 | break; |
4002 | case IB_SMP_ATTR_PORT_INFO: | |
4003 | ret = __subn_get_opa_portinfo(smp, am, data, ibdev, port, | |
f1685179 | 4004 | resp_len, max_len); |
77241056 MM |
4005 | break; |
4006 | case IB_SMP_ATTR_PKEY_TABLE: | |
4007 | ret = __subn_get_opa_pkeytable(smp, am, data, ibdev, port, | |
f1685179 | 4008 | resp_len, max_len); |
77241056 MM |
4009 | break; |
4010 | case OPA_ATTRIB_ID_SL_TO_SC_MAP: | |
4011 | ret = __subn_get_opa_sl_to_sc(smp, am, data, ibdev, port, | |
f1685179 | 4012 | resp_len, max_len); |
77241056 MM |
4013 | break; |
4014 | case OPA_ATTRIB_ID_SC_TO_SL_MAP: | |
4015 | ret = __subn_get_opa_sc_to_sl(smp, am, data, ibdev, port, | |
f1685179 | 4016 | resp_len, max_len); |
77241056 MM |
4017 | break; |
4018 | case OPA_ATTRIB_ID_SC_TO_VLT_MAP: | |
4019 | ret = __subn_get_opa_sc_to_vlt(smp, am, data, ibdev, port, | |
f1685179 | 4020 | resp_len, max_len); |
77241056 MM |
4021 | break; |
4022 | case OPA_ATTRIB_ID_SC_TO_VLNT_MAP: | |
4023 | ret = __subn_get_opa_sc_to_vlnt(smp, am, data, ibdev, port, | |
f1685179 | 4024 | resp_len, max_len); |
77241056 MM |
4025 | break; |
4026 | case OPA_ATTRIB_ID_PORT_STATE_INFO: | |
4027 | ret = __subn_get_opa_psi(smp, am, data, ibdev, port, | |
f1685179 | 4028 | resp_len, max_len); |
77241056 MM |
4029 | break; |
4030 | case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE: | |
4031 | ret = __subn_get_opa_bct(smp, am, data, ibdev, port, | |
f1685179 | 4032 | resp_len, max_len); |
77241056 MM |
4033 | break; |
4034 | case OPA_ATTRIB_ID_CABLE_INFO: | |
4035 | ret = __subn_get_opa_cable_info(smp, am, data, ibdev, port, | |
f1685179 | 4036 | resp_len, max_len); |
77241056 MM |
4037 | break; |
4038 | case IB_SMP_ATTR_VL_ARB_TABLE: | |
4039 | ret = __subn_get_opa_vl_arb(smp, am, data, ibdev, port, | |
f1685179 | 4040 | resp_len, max_len); |
77241056 MM |
4041 | break; |
4042 | case OPA_ATTRIB_ID_CONGESTION_INFO: | |
4043 | ret = __subn_get_opa_cong_info(smp, am, data, ibdev, port, | |
f1685179 | 4044 | resp_len, max_len); |
77241056 MM |
4045 | break; |
4046 | case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING: | |
4047 | ret = __subn_get_opa_cong_setting(smp, am, data, ibdev, | |
f1685179 | 4048 | port, resp_len, max_len); |
77241056 MM |
4049 | break; |
4050 | case OPA_ATTRIB_ID_HFI_CONGESTION_LOG: | |
4051 | ret = __subn_get_opa_hfi1_cong_log(smp, am, data, ibdev, | |
f1685179 | 4052 | port, resp_len, max_len); |
77241056 MM |
4053 | break; |
4054 | case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE: | |
4055 | ret = __subn_get_opa_cc_table(smp, am, data, ibdev, port, | |
f1685179 | 4056 | resp_len, max_len); |
77241056 MM |
4057 | break; |
4058 | case IB_SMP_ATTR_LED_INFO: | |
4059 | ret = __subn_get_opa_led_info(smp, am, data, ibdev, port, | |
f1685179 | 4060 | resp_len, max_len); |
77241056 MM |
4061 | break; |
4062 | case IB_SMP_ATTR_SM_INFO: | |
4eb06882 | 4063 | if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED) |
77241056 | 4064 | return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; |
4eb06882 | 4065 | if (ibp->rvp.port_cap_flags & IB_PORT_SM) |
77241056 MM |
4066 | return IB_MAD_RESULT_SUCCESS; |
4067 | /* FALLTHROUGH */ | |
4068 | default: | |
4069 | smp->status |= IB_SMP_UNSUP_METH_ATTR; | |
4070 | ret = reply((struct ib_mad_hdr *)smp); | |
4071 | break; | |
4072 | } | |
4073 | return ret; | |
4074 | } | |
4075 | ||
4076 | static int subn_set_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am, | |
4077 | u8 *data, struct ib_device *ibdev, u8 port, | |
f1685179 | 4078 | u32 *resp_len, u32 max_len) |
77241056 MM |
4079 | { |
4080 | int ret; | |
4081 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
4082 | ||
4083 | switch (attr_id) { | |
4084 | case IB_SMP_ATTR_PORT_INFO: | |
4085 | ret = __subn_set_opa_portinfo(smp, am, data, ibdev, port, | |
f1685179 | 4086 | resp_len, max_len); |
77241056 MM |
4087 | break; |
4088 | case IB_SMP_ATTR_PKEY_TABLE: | |
4089 | ret = __subn_set_opa_pkeytable(smp, am, data, ibdev, port, | |
f1685179 | 4090 | resp_len, max_len); |
77241056 MM |
4091 | break; |
4092 | case OPA_ATTRIB_ID_SL_TO_SC_MAP: | |
4093 | ret = __subn_set_opa_sl_to_sc(smp, am, data, ibdev, port, | |
f1685179 | 4094 | resp_len, max_len); |
77241056 MM |
4095 | break; |
4096 | case OPA_ATTRIB_ID_SC_TO_SL_MAP: | |
4097 | ret = __subn_set_opa_sc_to_sl(smp, am, data, ibdev, port, | |
f1685179 | 4098 | resp_len, max_len); |
77241056 MM |
4099 | break; |
4100 | case OPA_ATTRIB_ID_SC_TO_VLT_MAP: | |
4101 | ret = __subn_set_opa_sc_to_vlt(smp, am, data, ibdev, port, | |
f1685179 | 4102 | resp_len, max_len); |
77241056 MM |
4103 | break; |
4104 | case OPA_ATTRIB_ID_SC_TO_VLNT_MAP: | |
4105 | ret = __subn_set_opa_sc_to_vlnt(smp, am, data, ibdev, port, | |
f1685179 | 4106 | resp_len, max_len); |
77241056 MM |
4107 | break; |
4108 | case OPA_ATTRIB_ID_PORT_STATE_INFO: | |
4109 | ret = __subn_set_opa_psi(smp, am, data, ibdev, port, | |
f1685179 | 4110 | resp_len, max_len); |
77241056 MM |
4111 | break; |
4112 | case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE: | |
4113 | ret = __subn_set_opa_bct(smp, am, data, ibdev, port, | |
f1685179 | 4114 | resp_len, max_len); |
77241056 MM |
4115 | break; |
4116 | case IB_SMP_ATTR_VL_ARB_TABLE: | |
4117 | ret = __subn_set_opa_vl_arb(smp, am, data, ibdev, port, | |
f1685179 | 4118 | resp_len, max_len); |
77241056 MM |
4119 | break; |
4120 | case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING: | |
4121 | ret = __subn_set_opa_cong_setting(smp, am, data, ibdev, | |
f1685179 | 4122 | port, resp_len, max_len); |
77241056 MM |
4123 | break; |
4124 | case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE: | |
4125 | ret = __subn_set_opa_cc_table(smp, am, data, ibdev, port, | |
f1685179 | 4126 | resp_len, max_len); |
77241056 MM |
4127 | break; |
4128 | case IB_SMP_ATTR_LED_INFO: | |
4129 | ret = __subn_set_opa_led_info(smp, am, data, ibdev, port, | |
f1685179 | 4130 | resp_len, max_len); |
77241056 MM |
4131 | break; |
4132 | case IB_SMP_ATTR_SM_INFO: | |
4eb06882 | 4133 | if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED) |
77241056 | 4134 | return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; |
4eb06882 | 4135 | if (ibp->rvp.port_cap_flags & IB_PORT_SM) |
77241056 MM |
4136 | return IB_MAD_RESULT_SUCCESS; |
4137 | /* FALLTHROUGH */ | |
4138 | default: | |
4139 | smp->status |= IB_SMP_UNSUP_METH_ATTR; | |
4140 | ret = reply((struct ib_mad_hdr *)smp); | |
4141 | break; | |
4142 | } | |
4143 | return ret; | |
4144 | } | |
4145 | ||
4146 | static inline void set_aggr_error(struct opa_aggregate *ag) | |
4147 | { | |
4148 | ag->err_reqlength |= cpu_to_be16(0x8000); | |
4149 | } | |
4150 | ||
4151 | static int subn_get_opa_aggregate(struct opa_smp *smp, | |
4152 | struct ib_device *ibdev, u8 port, | |
4153 | u32 *resp_len) | |
4154 | { | |
4155 | int i; | |
4156 | u32 num_attr = be32_to_cpu(smp->attr_mod) & 0x000000ff; | |
4157 | u8 *next_smp = opa_get_smp_data(smp); | |
4158 | ||
4159 | if (num_attr < 1 || num_attr > 117) { | |
4160 | smp->status |= IB_SMP_INVALID_FIELD; | |
4161 | return reply((struct ib_mad_hdr *)smp); | |
4162 | } | |
4163 | ||
4164 | for (i = 0; i < num_attr; i++) { | |
4165 | struct opa_aggregate *agg; | |
4166 | size_t agg_data_len; | |
4167 | size_t agg_size; | |
4168 | u32 am; | |
4169 | ||
4170 | agg = (struct opa_aggregate *)next_smp; | |
4171 | agg_data_len = (be16_to_cpu(agg->err_reqlength) & 0x007f) * 8; | |
4172 | agg_size = sizeof(*agg) + agg_data_len; | |
4173 | am = be32_to_cpu(agg->attr_mod); | |
4174 | ||
4175 | *resp_len += agg_size; | |
4176 | ||
4177 | if (next_smp + agg_size > ((u8 *)smp) + sizeof(*smp)) { | |
4178 | smp->status |= IB_SMP_INVALID_FIELD; | |
4179 | return reply((struct ib_mad_hdr *)smp); | |
4180 | } | |
4181 | ||
4182 | /* zero the payload for this segment */ | |
4183 | memset(next_smp + sizeof(*agg), 0, agg_data_len); | |
4184 | ||
50e5dcbe | 4185 | (void)subn_get_opa_sma(agg->attr_id, smp, am, agg->data, |
f1685179 ND |
4186 | ibdev, port, NULL, (u32)agg_data_len); |
4187 | ||
4188 | if (smp->status & IB_SMP_INVALID_FIELD) | |
4189 | break; | |
77241056 MM |
4190 | if (smp->status & ~IB_SMP_DIRECTION) { |
4191 | set_aggr_error(agg); | |
4192 | return reply((struct ib_mad_hdr *)smp); | |
4193 | } | |
4194 | next_smp += agg_size; | |
77241056 MM |
4195 | } |
4196 | ||
4197 | return reply((struct ib_mad_hdr *)smp); | |
4198 | } | |
4199 | ||
4200 | static int subn_set_opa_aggregate(struct opa_smp *smp, | |
4201 | struct ib_device *ibdev, u8 port, | |
4202 | u32 *resp_len) | |
4203 | { | |
4204 | int i; | |
4205 | u32 num_attr = be32_to_cpu(smp->attr_mod) & 0x000000ff; | |
4206 | u8 *next_smp = opa_get_smp_data(smp); | |
4207 | ||
4208 | if (num_attr < 1 || num_attr > 117) { | |
4209 | smp->status |= IB_SMP_INVALID_FIELD; | |
4210 | return reply((struct ib_mad_hdr *)smp); | |
4211 | } | |
4212 | ||
4213 | for (i = 0; i < num_attr; i++) { | |
4214 | struct opa_aggregate *agg; | |
4215 | size_t agg_data_len; | |
4216 | size_t agg_size; | |
4217 | u32 am; | |
4218 | ||
4219 | agg = (struct opa_aggregate *)next_smp; | |
4220 | agg_data_len = (be16_to_cpu(agg->err_reqlength) & 0x007f) * 8; | |
4221 | agg_size = sizeof(*agg) + agg_data_len; | |
4222 | am = be32_to_cpu(agg->attr_mod); | |
4223 | ||
4224 | *resp_len += agg_size; | |
4225 | ||
4226 | if (next_smp + agg_size > ((u8 *)smp) + sizeof(*smp)) { | |
4227 | smp->status |= IB_SMP_INVALID_FIELD; | |
4228 | return reply((struct ib_mad_hdr *)smp); | |
4229 | } | |
4230 | ||
50e5dcbe | 4231 | (void)subn_set_opa_sma(agg->attr_id, smp, am, agg->data, |
f1685179 ND |
4232 | ibdev, port, NULL, (u32)agg_data_len); |
4233 | if (smp->status & IB_SMP_INVALID_FIELD) | |
4234 | break; | |
77241056 MM |
4235 | if (smp->status & ~IB_SMP_DIRECTION) { |
4236 | set_aggr_error(agg); | |
4237 | return reply((struct ib_mad_hdr *)smp); | |
4238 | } | |
4239 | next_smp += agg_size; | |
77241056 MM |
4240 | } |
4241 | ||
4242 | return reply((struct ib_mad_hdr *)smp); | |
4243 | } | |
4244 | ||
4245 | /* | |
4246 | * OPAv1 specifies that, on the transition to link up, these counters | |
4247 | * are cleared: | |
4248 | * PortRcvErrors [*] | |
4249 | * LinkErrorRecovery | |
4250 | * LocalLinkIntegrityErrors | |
4251 | * ExcessiveBufferOverruns [*] | |
4252 | * | |
4253 | * [*] Error info associated with these counters is retained, but the | |
4254 | * error info status is reset to 0. | |
4255 | */ | |
4256 | void clear_linkup_counters(struct hfi1_devdata *dd) | |
4257 | { | |
4258 | /* PortRcvErrors */ | |
4259 | write_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL, 0); | |
4260 | dd->err_info_rcvport.status_and_code &= ~OPA_EI_STATUS_SMASK; | |
4261 | /* LinkErrorRecovery */ | |
4262 | write_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL, 0); | |
4263 | write_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL, 0); | |
4264 | /* LocalLinkIntegrityErrors */ | |
77241056 MM |
4265 | write_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL, 0); |
4266 | /* ExcessiveBufferOverruns */ | |
4267 | write_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL, 0); | |
4268 | dd->rcv_ovfl_cnt = 0; | |
4269 | dd->err_info_xmit_constraint.status &= ~OPA_EI_STATUS_SMASK; | |
4270 | } | |
4271 | ||
406310c6 SS |
4272 | static int is_full_mgmt_pkey_in_table(struct hfi1_ibport *ibp) |
4273 | { | |
4274 | unsigned int i; | |
4275 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
4276 | ||
4277 | for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i) | |
4278 | if (ppd->pkeys[i] == FULL_MGMT_P_KEY) | |
4279 | return 1; | |
4280 | ||
4281 | return 0; | |
4282 | } | |
4283 | ||
77241056 MM |
4284 | /* |
4285 | * is_local_mad() returns 1 if 'mad' is sent from, and destined to the | |
4286 | * local node, 0 otherwise. | |
4287 | */ | |
4288 | static int is_local_mad(struct hfi1_ibport *ibp, const struct opa_mad *mad, | |
4289 | const struct ib_wc *in_wc) | |
4290 | { | |
4291 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
4292 | const struct opa_smp *smp = (const struct opa_smp *)mad; | |
4293 | ||
4294 | if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) { | |
4295 | return (smp->hop_cnt == 0 && | |
4296 | smp->route.dr.dr_slid == OPA_LID_PERMISSIVE && | |
4297 | smp->route.dr.dr_dlid == OPA_LID_PERMISSIVE); | |
4298 | } | |
4299 | ||
4300 | return (in_wc->slid == ppd->lid); | |
4301 | } | |
4302 | ||
4303 | /* | |
4304 | * opa_local_smp_check() should only be called on MADs for which | |
4305 | * is_local_mad() returns true. It applies the SMP checks that are | |
4306 | * specific to SMPs which are sent from, and destined to this node. | |
4307 | * opa_local_smp_check() returns 0 if the SMP passes its checks, 1 | |
4308 | * otherwise. | |
4309 | * | |
4310 | * SMPs which arrive from other nodes are instead checked by | |
4311 | * opa_smp_check(). | |
4312 | */ | |
4313 | static int opa_local_smp_check(struct hfi1_ibport *ibp, | |
4314 | const struct ib_wc *in_wc) | |
4315 | { | |
4316 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
77241056 MM |
4317 | u16 pkey; |
4318 | ||
4319 | if (in_wc->pkey_index >= ARRAY_SIZE(ppd->pkeys)) | |
4320 | return 1; | |
4321 | ||
4322 | pkey = ppd->pkeys[in_wc->pkey_index]; | |
4323 | /* | |
4324 | * We need to do the "node-local" checks specified in OPAv1, | |
4325 | * rev 0.90, section 9.10.26, which are: | |
4326 | * - pkey is 0x7fff, or 0xffff | |
4327 | * - Source QPN == 0 || Destination QPN == 0 | |
4328 | * - the MAD header's management class is either | |
4329 | * IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE or | |
4330 | * IB_MGMT_CLASS_SUBN_LID_ROUTED | |
4331 | * - SLID != 0 | |
4332 | * | |
4333 | * However, we know (and so don't need to check again) that, | |
4334 | * for local SMPs, the MAD stack passes MADs with: | |
4335 | * - Source QPN of 0 | |
4336 | * - MAD mgmt_class is IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE | |
4337 | * - SLID is either: OPA_LID_PERMISSIVE (0xFFFFFFFF), or | |
4338 | * our own port's lid | |
4339 | * | |
4340 | */ | |
4341 | if (pkey == LIM_MGMT_P_KEY || pkey == FULL_MGMT_P_KEY) | |
4342 | return 0; | |
4988be58 DH |
4343 | /* |
4344 | * On OPA devices it is okay to lose the upper 16 bits of LID as this | |
4345 | * information is obtained elsewhere. Mask off the upper 16 bits. | |
4346 | */ | |
4347 | ingress_pkey_table_fail(ppd, pkey, ib_lid_cpu16(0xFFFF & in_wc->slid)); | |
77241056 MM |
4348 | return 1; |
4349 | } | |
4350 | ||
406310c6 SS |
4351 | /** |
4352 | * hfi1_pkey_validation_pma - It validates PKEYs for incoming PMA MAD packets. | |
4353 | * @ibp: IB port data | |
4354 | * @in_mad: MAD packet with header and data | |
4355 | * @in_wc: Work completion data such as source LID, port number, etc. | |
4356 | * | |
4357 | * These are all the possible logic rules for validating a pkey: | |
4358 | * | |
4359 | * a) If pkey neither FULL_MGMT_P_KEY nor LIM_MGMT_P_KEY, | |
4360 | * and NOT self-originated packet: | |
4361 | * Drop MAD packet as it should always be part of the | |
4362 | * management partition unless it's a self-originated packet. | |
4363 | * | |
4364 | * b) If pkey_index -> FULL_MGMT_P_KEY, and LIM_MGMT_P_KEY in pkey table: | |
4365 | * The packet is coming from a management node and the receiving node | |
4366 | * is also a management node, so it is safe for the packet to go through. | |
4367 | * | |
4368 | * c) If pkey_index -> FULL_MGMT_P_KEY, and LIM_MGMT_P_KEY is NOT in pkey table: | |
4369 | * Drop the packet as LIM_MGMT_P_KEY should always be in the pkey table. | |
4370 | * It could be an FM misconfiguration. | |
4371 | * | |
4372 | * d) If pkey_index -> LIM_MGMT_P_KEY and FULL_MGMT_P_KEY is NOT in pkey table: | |
4373 | * It is safe for the packet to go through since a non-management node is | |
4374 | * talking to another non-management node. | |
4375 | * | |
4376 | * e) If pkey_index -> LIM_MGMT_P_KEY and FULL_MGMT_P_KEY in pkey table: | |
4377 | * Drop the packet because a non-management node is talking to a | |
4378 | * management node, and it could be an attack. | |
4379 | * | |
4380 | * For the implementation, these rules can be simplied to only checking | |
4381 | * for (a) and (e). There's no need to check for rule (b) as | |
4382 | * the packet doesn't need to be dropped. Rule (c) is not possible in | |
4383 | * the driver as LIM_MGMT_P_KEY is always in the pkey table. | |
4384 | * | |
4385 | * Return: | |
4386 | * 0 - pkey is okay, -EINVAL it's a bad pkey | |
4387 | */ | |
4388 | static int hfi1_pkey_validation_pma(struct hfi1_ibport *ibp, | |
4389 | const struct opa_mad *in_mad, | |
4390 | const struct ib_wc *in_wc) | |
4391 | { | |
4392 | u16 pkey_value = hfi1_lookup_pkey_value(ibp, in_wc->pkey_index); | |
4393 | ||
4394 | /* Rule (a) from above */ | |
4395 | if (!is_local_mad(ibp, in_mad, in_wc) && | |
4396 | pkey_value != LIM_MGMT_P_KEY && | |
4397 | pkey_value != FULL_MGMT_P_KEY) | |
4398 | return -EINVAL; | |
4399 | ||
4400 | /* Rule (e) from above */ | |
4401 | if (pkey_value == LIM_MGMT_P_KEY && | |
4402 | is_full_mgmt_pkey_in_table(ibp)) | |
4403 | return -EINVAL; | |
4404 | ||
4405 | return 0; | |
4406 | } | |
4407 | ||
77241056 MM |
4408 | static int process_subn_opa(struct ib_device *ibdev, int mad_flags, |
4409 | u8 port, const struct opa_mad *in_mad, | |
4410 | struct opa_mad *out_mad, | |
4411 | u32 *resp_len) | |
4412 | { | |
4413 | struct opa_smp *smp = (struct opa_smp *)out_mad; | |
4414 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
4415 | u8 *data; | |
f1685179 | 4416 | u32 am, data_size; |
77241056 MM |
4417 | __be16 attr_id; |
4418 | int ret; | |
4419 | ||
4420 | *out_mad = *in_mad; | |
4421 | data = opa_get_smp_data(smp); | |
f1685179 | 4422 | data_size = (u32)opa_get_smp_data_size(smp); |
77241056 MM |
4423 | |
4424 | am = be32_to_cpu(smp->attr_mod); | |
4425 | attr_id = smp->attr_id; | |
9fa240bb | 4426 | if (smp->class_version != OPA_SM_CLASS_VERSION) { |
77241056 MM |
4427 | smp->status |= IB_SMP_UNSUP_VERSION; |
4428 | ret = reply((struct ib_mad_hdr *)smp); | |
5950e9b1 | 4429 | return ret; |
77241056 MM |
4430 | } |
4431 | ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags, smp->mkey, | |
4432 | smp->route.dr.dr_slid, smp->route.dr.return_path, | |
4433 | smp->hop_cnt); | |
4434 | if (ret) { | |
4435 | u32 port_num = be32_to_cpu(smp->attr_mod); | |
4436 | ||
4437 | /* | |
4438 | * If this is a get/set portinfo, we already check the | |
4439 | * M_Key if the MAD is for another port and the M_Key | |
4440 | * is OK on the receiving port. This check is needed | |
4441 | * to increment the error counters when the M_Key | |
4442 | * fails to match on *both* ports. | |
4443 | */ | |
4444 | if (attr_id == IB_SMP_ATTR_PORT_INFO && | |
4445 | (smp->method == IB_MGMT_METHOD_GET || | |
4446 | smp->method == IB_MGMT_METHOD_SET) && | |
4447 | port_num && port_num <= ibdev->phys_port_cnt && | |
4448 | port != port_num) | |
50e5dcbe | 4449 | (void)check_mkey(to_iport(ibdev, port_num), |
77241056 MM |
4450 | (struct ib_mad_hdr *)smp, 0, |
4451 | smp->mkey, smp->route.dr.dr_slid, | |
4452 | smp->route.dr.return_path, | |
4453 | smp->hop_cnt); | |
4454 | ret = IB_MAD_RESULT_FAILURE; | |
5950e9b1 | 4455 | return ret; |
77241056 MM |
4456 | } |
4457 | ||
4458 | *resp_len = opa_get_smp_header_size(smp); | |
4459 | ||
4460 | switch (smp->method) { | |
4461 | case IB_MGMT_METHOD_GET: | |
4462 | switch (attr_id) { | |
4463 | default: | |
4464 | clear_opa_smp_data(smp); | |
4465 | ret = subn_get_opa_sma(attr_id, smp, am, data, | |
f1685179 ND |
4466 | ibdev, port, resp_len, |
4467 | data_size); | |
5950e9b1 | 4468 | break; |
77241056 MM |
4469 | case OPA_ATTRIB_ID_AGGREGATE: |
4470 | ret = subn_get_opa_aggregate(smp, ibdev, port, | |
4471 | resp_len); | |
5950e9b1 | 4472 | break; |
77241056 | 4473 | } |
5950e9b1 | 4474 | break; |
77241056 MM |
4475 | case IB_MGMT_METHOD_SET: |
4476 | switch (attr_id) { | |
4477 | default: | |
4478 | ret = subn_set_opa_sma(attr_id, smp, am, data, | |
f1685179 ND |
4479 | ibdev, port, resp_len, |
4480 | data_size); | |
5950e9b1 | 4481 | break; |
77241056 MM |
4482 | case OPA_ATTRIB_ID_AGGREGATE: |
4483 | ret = subn_set_opa_aggregate(smp, ibdev, port, | |
4484 | resp_len); | |
5950e9b1 | 4485 | break; |
77241056 | 4486 | } |
5950e9b1 | 4487 | break; |
77241056 MM |
4488 | case IB_MGMT_METHOD_TRAP: |
4489 | case IB_MGMT_METHOD_REPORT: | |
4490 | case IB_MGMT_METHOD_REPORT_RESP: | |
4491 | case IB_MGMT_METHOD_GET_RESP: | |
4492 | /* | |
4493 | * The ib_mad module will call us to process responses | |
4494 | * before checking for other consumers. | |
4495 | * Just tell the caller to process it normally. | |
4496 | */ | |
4497 | ret = IB_MAD_RESULT_SUCCESS; | |
5950e9b1 | 4498 | break; |
bf90aadd MR |
4499 | case IB_MGMT_METHOD_TRAP_REPRESS: |
4500 | subn_handle_opa_trap_repress(ibp, smp); | |
4501 | /* Always successful */ | |
4502 | ret = IB_MAD_RESULT_SUCCESS; | |
4503 | break; | |
77241056 MM |
4504 | default: |
4505 | smp->status |= IB_SMP_UNSUP_METHOD; | |
4506 | ret = reply((struct ib_mad_hdr *)smp); | |
5950e9b1 | 4507 | break; |
77241056 MM |
4508 | } |
4509 | ||
77241056 MM |
4510 | return ret; |
4511 | } | |
4512 | ||
4513 | static int process_subn(struct ib_device *ibdev, int mad_flags, | |
4514 | u8 port, const struct ib_mad *in_mad, | |
4515 | struct ib_mad *out_mad) | |
4516 | { | |
4517 | struct ib_smp *smp = (struct ib_smp *)out_mad; | |
4518 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
4519 | int ret; | |
4520 | ||
4521 | *out_mad = *in_mad; | |
4522 | if (smp->class_version != 1) { | |
4523 | smp->status |= IB_SMP_UNSUP_VERSION; | |
4524 | ret = reply((struct ib_mad_hdr *)smp); | |
5950e9b1 | 4525 | return ret; |
77241056 MM |
4526 | } |
4527 | ||
4528 | ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags, | |
4529 | smp->mkey, (__force __be32)smp->dr_slid, | |
4530 | smp->return_path, smp->hop_cnt); | |
4531 | if (ret) { | |
4532 | u32 port_num = be32_to_cpu(smp->attr_mod); | |
4533 | ||
4534 | /* | |
4535 | * If this is a get/set portinfo, we already check the | |
4536 | * M_Key if the MAD is for another port and the M_Key | |
4537 | * is OK on the receiving port. This check is needed | |
4538 | * to increment the error counters when the M_Key | |
4539 | * fails to match on *both* ports. | |
4540 | */ | |
4541 | if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO && | |
4542 | (smp->method == IB_MGMT_METHOD_GET || | |
4543 | smp->method == IB_MGMT_METHOD_SET) && | |
4544 | port_num && port_num <= ibdev->phys_port_cnt && | |
4545 | port != port_num) | |
50e5dcbe | 4546 | (void)check_mkey(to_iport(ibdev, port_num), |
17fb4f29 JJ |
4547 | (struct ib_mad_hdr *)smp, 0, |
4548 | smp->mkey, | |
4549 | (__force __be32)smp->dr_slid, | |
4550 | smp->return_path, smp->hop_cnt); | |
77241056 | 4551 | ret = IB_MAD_RESULT_FAILURE; |
5950e9b1 | 4552 | return ret; |
77241056 MM |
4553 | } |
4554 | ||
4555 | switch (smp->method) { | |
4556 | case IB_MGMT_METHOD_GET: | |
4557 | switch (smp->attr_id) { | |
4558 | case IB_SMP_ATTR_NODE_INFO: | |
4559 | ret = subn_get_nodeinfo(smp, ibdev, port); | |
5950e9b1 | 4560 | break; |
77241056 MM |
4561 | default: |
4562 | smp->status |= IB_SMP_UNSUP_METH_ATTR; | |
4563 | ret = reply((struct ib_mad_hdr *)smp); | |
5950e9b1 | 4564 | break; |
77241056 | 4565 | } |
5950e9b1 | 4566 | break; |
77241056 MM |
4567 | } |
4568 | ||
77241056 MM |
4569 | return ret; |
4570 | } | |
4571 | ||
b8d114eb SS |
4572 | static int process_perf(struct ib_device *ibdev, u8 port, |
4573 | const struct ib_mad *in_mad, | |
4574 | struct ib_mad *out_mad) | |
4575 | { | |
4576 | struct ib_pma_mad *pmp = (struct ib_pma_mad *)out_mad; | |
4577 | struct ib_class_port_info *cpi = (struct ib_class_port_info *) | |
4578 | &pmp->data; | |
4579 | int ret = IB_MAD_RESULT_FAILURE; | |
4580 | ||
4581 | *out_mad = *in_mad; | |
4582 | if (pmp->mad_hdr.class_version != 1) { | |
4583 | pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION; | |
4584 | ret = reply((struct ib_mad_hdr *)pmp); | |
4585 | return ret; | |
4586 | } | |
4587 | ||
4588 | switch (pmp->mad_hdr.method) { | |
4589 | case IB_MGMT_METHOD_GET: | |
4590 | switch (pmp->mad_hdr.attr_id) { | |
4591 | case IB_PMA_PORT_COUNTERS: | |
4592 | ret = pma_get_ib_portcounters(pmp, ibdev, port); | |
4593 | break; | |
4594 | case IB_PMA_PORT_COUNTERS_EXT: | |
4595 | ret = pma_get_ib_portcounters_ext(pmp, ibdev, port); | |
4596 | break; | |
4597 | case IB_PMA_CLASS_PORT_INFO: | |
4598 | cpi->capability_mask = IB_PMA_CLASS_CAP_EXT_WIDTH; | |
4599 | ret = reply((struct ib_mad_hdr *)pmp); | |
4600 | break; | |
4601 | default: | |
4602 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; | |
4603 | ret = reply((struct ib_mad_hdr *)pmp); | |
4604 | break; | |
4605 | } | |
4606 | break; | |
4607 | ||
4608 | case IB_MGMT_METHOD_SET: | |
4609 | if (pmp->mad_hdr.attr_id) { | |
4610 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; | |
4611 | ret = reply((struct ib_mad_hdr *)pmp); | |
4612 | } | |
4613 | break; | |
4614 | ||
4615 | case IB_MGMT_METHOD_TRAP: | |
4616 | case IB_MGMT_METHOD_GET_RESP: | |
4617 | /* | |
4618 | * The ib_mad module will call us to process responses | |
4619 | * before checking for other consumers. | |
4620 | * Just tell the caller to process it normally. | |
4621 | */ | |
4622 | ret = IB_MAD_RESULT_SUCCESS; | |
4623 | break; | |
4624 | ||
4625 | default: | |
4626 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD; | |
4627 | ret = reply((struct ib_mad_hdr *)pmp); | |
4628 | break; | |
77241056 MM |
4629 | } |
4630 | ||
77241056 MM |
4631 | return ret; |
4632 | } | |
4633 | ||
4634 | static int process_perf_opa(struct ib_device *ibdev, u8 port, | |
4635 | const struct opa_mad *in_mad, | |
4636 | struct opa_mad *out_mad, u32 *resp_len) | |
4637 | { | |
4638 | struct opa_pma_mad *pmp = (struct opa_pma_mad *)out_mad; | |
4639 | int ret; | |
4640 | ||
4641 | *out_mad = *in_mad; | |
4642 | ||
9fa240bb | 4643 | if (pmp->mad_hdr.class_version != OPA_SM_CLASS_VERSION) { |
77241056 MM |
4644 | pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION; |
4645 | return reply((struct ib_mad_hdr *)pmp); | |
4646 | } | |
4647 | ||
4648 | *resp_len = sizeof(pmp->mad_hdr); | |
4649 | ||
4650 | switch (pmp->mad_hdr.method) { | |
4651 | case IB_MGMT_METHOD_GET: | |
4652 | switch (pmp->mad_hdr.attr_id) { | |
4653 | case IB_PMA_CLASS_PORT_INFO: | |
4654 | ret = pma_get_opa_classportinfo(pmp, ibdev, resp_len); | |
5950e9b1 | 4655 | break; |
77241056 MM |
4656 | case OPA_PM_ATTRIB_ID_PORT_STATUS: |
4657 | ret = pma_get_opa_portstatus(pmp, ibdev, port, | |
17fb4f29 | 4658 | resp_len); |
5950e9b1 | 4659 | break; |
77241056 MM |
4660 | case OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERS: |
4661 | ret = pma_get_opa_datacounters(pmp, ibdev, port, | |
17fb4f29 | 4662 | resp_len); |
5950e9b1 | 4663 | break; |
77241056 MM |
4664 | case OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS: |
4665 | ret = pma_get_opa_porterrors(pmp, ibdev, port, | |
17fb4f29 | 4666 | resp_len); |
5950e9b1 | 4667 | break; |
77241056 MM |
4668 | case OPA_PM_ATTRIB_ID_ERROR_INFO: |
4669 | ret = pma_get_opa_errorinfo(pmp, ibdev, port, | |
17fb4f29 | 4670 | resp_len); |
5950e9b1 | 4671 | break; |
77241056 MM |
4672 | default: |
4673 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; | |
4674 | ret = reply((struct ib_mad_hdr *)pmp); | |
5950e9b1 | 4675 | break; |
77241056 | 4676 | } |
5950e9b1 | 4677 | break; |
77241056 MM |
4678 | |
4679 | case IB_MGMT_METHOD_SET: | |
4680 | switch (pmp->mad_hdr.attr_id) { | |
4681 | case OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS: | |
4682 | ret = pma_set_opa_portstatus(pmp, ibdev, port, | |
17fb4f29 | 4683 | resp_len); |
5950e9b1 | 4684 | break; |
77241056 MM |
4685 | case OPA_PM_ATTRIB_ID_ERROR_INFO: |
4686 | ret = pma_set_opa_errorinfo(pmp, ibdev, port, | |
17fb4f29 | 4687 | resp_len); |
5950e9b1 | 4688 | break; |
77241056 MM |
4689 | default: |
4690 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; | |
4691 | ret = reply((struct ib_mad_hdr *)pmp); | |
5950e9b1 | 4692 | break; |
77241056 | 4693 | } |
5950e9b1 | 4694 | break; |
77241056 MM |
4695 | |
4696 | case IB_MGMT_METHOD_TRAP: | |
4697 | case IB_MGMT_METHOD_GET_RESP: | |
4698 | /* | |
4699 | * The ib_mad module will call us to process responses | |
4700 | * before checking for other consumers. | |
4701 | * Just tell the caller to process it normally. | |
4702 | */ | |
4703 | ret = IB_MAD_RESULT_SUCCESS; | |
5950e9b1 | 4704 | break; |
77241056 MM |
4705 | |
4706 | default: | |
4707 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD; | |
4708 | ret = reply((struct ib_mad_hdr *)pmp); | |
5950e9b1 | 4709 | break; |
77241056 MM |
4710 | } |
4711 | ||
77241056 MM |
4712 | return ret; |
4713 | } | |
4714 | ||
4715 | static int hfi1_process_opa_mad(struct ib_device *ibdev, int mad_flags, | |
a724648e JB |
4716 | u8 port, const struct ib_wc *in_wc, |
4717 | const struct ib_grh *in_grh, | |
4718 | const struct opa_mad *in_mad, | |
4719 | struct opa_mad *out_mad, size_t *out_mad_size, | |
4720 | u16 *out_mad_pkey_index) | |
77241056 MM |
4721 | { |
4722 | int ret; | |
4723 | int pkey_idx; | |
4724 | u32 resp_len = 0; | |
4725 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
4726 | ||
4727 | pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY); | |
4728 | if (pkey_idx < 0) { | |
4729 | pr_warn("failed to find limited mgmt pkey, defaulting 0x%x\n", | |
4730 | hfi1_get_pkey(ibp, 1)); | |
4731 | pkey_idx = 1; | |
4732 | } | |
4733 | *out_mad_pkey_index = (u16)pkey_idx; | |
4734 | ||
4735 | switch (in_mad->mad_hdr.mgmt_class) { | |
4736 | case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE: | |
4737 | case IB_MGMT_CLASS_SUBN_LID_ROUTED: | |
4738 | if (is_local_mad(ibp, in_mad, in_wc)) { | |
4739 | ret = opa_local_smp_check(ibp, in_wc); | |
4740 | if (ret) | |
4741 | return IB_MAD_RESULT_FAILURE; | |
4742 | } | |
4743 | ret = process_subn_opa(ibdev, mad_flags, port, in_mad, | |
4744 | out_mad, &resp_len); | |
4745 | goto bail; | |
4746 | case IB_MGMT_CLASS_PERF_MGMT: | |
406310c6 SS |
4747 | ret = hfi1_pkey_validation_pma(ibp, in_mad, in_wc); |
4748 | if (ret) | |
4749 | return IB_MAD_RESULT_FAILURE; | |
4750 | ||
4751 | ret = process_perf_opa(ibdev, port, in_mad, out_mad, &resp_len); | |
77241056 MM |
4752 | goto bail; |
4753 | ||
4754 | default: | |
4755 | ret = IB_MAD_RESULT_SUCCESS; | |
4756 | } | |
4757 | ||
4758 | bail: | |
4759 | if (ret & IB_MAD_RESULT_REPLY) | |
4760 | *out_mad_size = round_up(resp_len, 8); | |
4761 | else if (ret & IB_MAD_RESULT_SUCCESS) | |
4762 | *out_mad_size = in_wc->byte_len - sizeof(struct ib_grh); | |
4763 | ||
4764 | return ret; | |
4765 | } | |
4766 | ||
4767 | static int hfi1_process_ib_mad(struct ib_device *ibdev, int mad_flags, u8 port, | |
4768 | const struct ib_wc *in_wc, | |
4769 | const struct ib_grh *in_grh, | |
4770 | const struct ib_mad *in_mad, | |
4771 | struct ib_mad *out_mad) | |
4772 | { | |
4773 | int ret; | |
4774 | ||
4775 | switch (in_mad->mad_hdr.mgmt_class) { | |
4776 | case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE: | |
4777 | case IB_MGMT_CLASS_SUBN_LID_ROUTED: | |
4778 | ret = process_subn(ibdev, mad_flags, port, in_mad, out_mad); | |
5950e9b1 | 4779 | break; |
b8d114eb SS |
4780 | case IB_MGMT_CLASS_PERF_MGMT: |
4781 | ret = process_perf(ibdev, port, in_mad, out_mad); | |
4782 | break; | |
77241056 MM |
4783 | default: |
4784 | ret = IB_MAD_RESULT_SUCCESS; | |
5950e9b1 | 4785 | break; |
77241056 MM |
4786 | } |
4787 | ||
77241056 MM |
4788 | return ret; |
4789 | } | |
4790 | ||
4791 | /** | |
4792 | * hfi1_process_mad - process an incoming MAD packet | |
4793 | * @ibdev: the infiniband device this packet came in on | |
4794 | * @mad_flags: MAD flags | |
4795 | * @port: the port number this packet came in on | |
4796 | * @in_wc: the work completion entry for this packet | |
4797 | * @in_grh: the global route header for this packet | |
4798 | * @in_mad: the incoming MAD | |
4799 | * @out_mad: any outgoing MAD reply | |
4800 | * | |
4801 | * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not | |
4802 | * interested in processing. | |
4803 | * | |
4804 | * Note that the verbs framework has already done the MAD sanity checks, | |
4805 | * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE | |
4806 | * MADs. | |
4807 | * | |
4808 | * This is called by the ib_mad module. | |
4809 | */ | |
4810 | int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port, | |
4811 | const struct ib_wc *in_wc, const struct ib_grh *in_grh, | |
4812 | const struct ib_mad_hdr *in_mad, size_t in_mad_size, | |
4813 | struct ib_mad_hdr *out_mad, size_t *out_mad_size, | |
4814 | u16 *out_mad_pkey_index) | |
4815 | { | |
4816 | switch (in_mad->base_version) { | |
4817 | case OPA_MGMT_BASE_VERSION: | |
4818 | if (unlikely(in_mad_size != sizeof(struct opa_mad))) { | |
3067771c | 4819 | dev_err(ibdev->dev.parent, "invalid in_mad_size\n"); |
77241056 MM |
4820 | return IB_MAD_RESULT_FAILURE; |
4821 | } | |
4822 | return hfi1_process_opa_mad(ibdev, mad_flags, port, | |
4823 | in_wc, in_grh, | |
4824 | (struct opa_mad *)in_mad, | |
4825 | (struct opa_mad *)out_mad, | |
4826 | out_mad_size, | |
4827 | out_mad_pkey_index); | |
4828 | case IB_MGMT_BASE_VERSION: | |
4829 | return hfi1_process_ib_mad(ibdev, mad_flags, port, | |
4830 | in_wc, in_grh, | |
4831 | (const struct ib_mad *)in_mad, | |
4832 | (struct ib_mad *)out_mad); | |
4833 | default: | |
4834 | break; | |
4835 | } | |
4836 | ||
4837 | return IB_MAD_RESULT_FAILURE; | |
4838 | } |