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