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