2 * Copyright(c) 2015, 2016 Intel Corporation.
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 #include <linux/net.h>
49 #define OPA_NUM_PKEY_BLOCKS_PER_SMP (OPA_SMP_DR_DATA_SIZE \
50 / (OPA_PARTITION_TABLE_BLK_SIZE * sizeof(u16)))
57 /* the reset value from the FM is supposed to be 0xffff, handle both */
58 #define OPA_LINK_WIDTH_RESET_OLD 0x0fff
59 #define OPA_LINK_WIDTH_RESET 0xffff
61 static int reply(struct ib_mad_hdr
*smp
)
64 * The verbs framework will handle the directed/LID route
67 smp
->method
= IB_MGMT_METHOD_GET_RESP
;
68 if (smp
->mgmt_class
== IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
)
69 smp
->status
|= IB_SMP_DIRECTION
;
70 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_REPLY
;
73 static inline void clear_opa_smp_data(struct opa_smp
*smp
)
75 void *data
= opa_get_smp_data(smp
);
76 size_t size
= opa_get_smp_data_size(smp
);
78 memset(data
, 0, size
);
81 void hfi1_event_pkey_change(struct hfi1_devdata
*dd
, u8 port
)
83 struct ib_event event
;
85 event
.event
= IB_EVENT_PKEY_CHANGE
;
86 event
.device
= &dd
->verbs_dev
.rdi
.ibdev
;
87 event
.element
.port_num
= port
;
88 ib_dispatch_event(&event
);
91 static void send_trap(struct hfi1_ibport
*ibp
, void *data
, unsigned len
)
93 struct ib_mad_send_buf
*send_buf
;
94 struct ib_mad_agent
*agent
;
98 unsigned long timeout
;
100 u32 qpn
= ppd_from_ibp(ibp
)->sm_trap_qp
;
102 agent
= ibp
->rvp
.send_agent
;
107 if (ppd_from_ibp(ibp
)->lstate
!= IB_PORT_ACTIVE
)
111 if (ibp
->rvp
.trap_timeout
&& time_before(jiffies
,
112 ibp
->rvp
.trap_timeout
))
115 pkey_idx
= hfi1_lookup_pkey_idx(ibp
, LIM_MGMT_P_KEY
);
117 pr_warn("%s: failed to find limited mgmt pkey, defaulting 0x%x\n",
118 __func__
, hfi1_get_pkey(ibp
, 1));
122 send_buf
= ib_create_send_mad(agent
, qpn
, pkey_idx
, 0,
123 IB_MGMT_MAD_HDR
, IB_MGMT_MAD_DATA
,
124 GFP_ATOMIC
, IB_MGMT_BASE_VERSION
);
125 if (IS_ERR(send_buf
))
129 smp
->base_version
= OPA_MGMT_BASE_VERSION
;
130 smp
->mgmt_class
= IB_MGMT_CLASS_SUBN_LID_ROUTED
;
131 smp
->class_version
= OPA_SMI_CLASS_VERSION
;
132 smp
->method
= IB_MGMT_METHOD_TRAP
;
134 smp
->tid
= cpu_to_be64(ibp
->rvp
.tid
);
135 smp
->attr_id
= IB_SMP_ATTR_NOTICE
;
136 /* o14-1: smp->mkey = 0; */
137 memcpy(smp
->route
.lid
.data
, data
, len
);
139 spin_lock_irqsave(&ibp
->rvp
.lock
, flags
);
140 if (!ibp
->rvp
.sm_ah
) {
141 if (ibp
->rvp
.sm_lid
!= be16_to_cpu(IB_LID_PERMISSIVE
)) {
144 ah
= hfi1_create_qp0_ah(ibp
, ibp
->rvp
.sm_lid
);
149 ibp
->rvp
.sm_ah
= ibah_to_rvtah(ah
);
156 send_buf
->ah
= &ibp
->rvp
.sm_ah
->ibah
;
159 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
162 ret
= ib_post_send_mad(send_buf
, NULL
);
165 timeout
= (4096 * (1UL << ibp
->rvp
.subnet_timeout
)) / 1000;
166 ibp
->rvp
.trap_timeout
= jiffies
+ usecs_to_jiffies(timeout
);
168 ib_free_send_mad(send_buf
);
169 ibp
->rvp
.trap_timeout
= 0;
174 * Send a bad [PQ]_Key trap (ch. 14.3.8).
176 void hfi1_bad_pqkey(struct hfi1_ibport
*ibp
, __be16 trap_num
, u32 key
, u32 sl
,
177 u32 qp1
, u32 qp2
, u16 lid1
, u16 lid2
)
179 struct opa_mad_notice_attr data
;
180 u32 lid
= ppd_from_ibp(ibp
)->lid
;
184 memset(&data
, 0, sizeof(data
));
186 if (trap_num
== OPA_TRAP_BAD_P_KEY
)
187 ibp
->rvp
.pkey_violations
++;
189 ibp
->rvp
.qkey_violations
++;
190 ibp
->rvp
.n_pkt_drops
++;
192 /* Send violation trap */
193 data
.generic_type
= IB_NOTICE_TYPE_SECURITY
;
194 data
.prod_type_lsb
= IB_NOTICE_PROD_CA
;
195 data
.trap_num
= trap_num
;
196 data
.issuer_lid
= cpu_to_be32(lid
);
197 data
.ntc_257_258
.lid1
= cpu_to_be32(_lid1
);
198 data
.ntc_257_258
.lid2
= cpu_to_be32(_lid2
);
199 data
.ntc_257_258
.key
= cpu_to_be32(key
);
200 data
.ntc_257_258
.sl
= sl
<< 3;
201 data
.ntc_257_258
.qp1
= cpu_to_be32(qp1
);
202 data
.ntc_257_258
.qp2
= cpu_to_be32(qp2
);
204 send_trap(ibp
, &data
, sizeof(data
));
208 * Send a bad M_Key trap (ch. 14.3.9).
210 static void bad_mkey(struct hfi1_ibport
*ibp
, struct ib_mad_hdr
*mad
,
211 __be64 mkey
, __be32 dr_slid
, u8 return_path
[], u8 hop_cnt
)
213 struct opa_mad_notice_attr data
;
214 u32 lid
= ppd_from_ibp(ibp
)->lid
;
216 memset(&data
, 0, sizeof(data
));
217 /* Send violation trap */
218 data
.generic_type
= IB_NOTICE_TYPE_SECURITY
;
219 data
.prod_type_lsb
= IB_NOTICE_PROD_CA
;
220 data
.trap_num
= OPA_TRAP_BAD_M_KEY
;
221 data
.issuer_lid
= cpu_to_be32(lid
);
222 data
.ntc_256
.lid
= data
.issuer_lid
;
223 data
.ntc_256
.method
= mad
->method
;
224 data
.ntc_256
.attr_id
= mad
->attr_id
;
225 data
.ntc_256
.attr_mod
= mad
->attr_mod
;
226 data
.ntc_256
.mkey
= mkey
;
227 if (mad
->mgmt_class
== IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
) {
228 data
.ntc_256
.dr_slid
= dr_slid
;
229 data
.ntc_256
.dr_trunc_hop
= IB_NOTICE_TRAP_DR_NOTICE
;
230 if (hop_cnt
> ARRAY_SIZE(data
.ntc_256
.dr_rtn_path
)) {
231 data
.ntc_256
.dr_trunc_hop
|=
232 IB_NOTICE_TRAP_DR_TRUNC
;
233 hop_cnt
= ARRAY_SIZE(data
.ntc_256
.dr_rtn_path
);
235 data
.ntc_256
.dr_trunc_hop
|= hop_cnt
;
236 memcpy(data
.ntc_256
.dr_rtn_path
, return_path
,
240 send_trap(ibp
, &data
, sizeof(data
));
244 * Send a Port Capability Mask Changed trap (ch. 14.3.11).
246 void hfi1_cap_mask_chg(struct rvt_dev_info
*rdi
, u8 port_num
)
248 struct opa_mad_notice_attr data
;
249 struct hfi1_ibdev
*verbs_dev
= dev_from_rdi(rdi
);
250 struct hfi1_devdata
*dd
= dd_from_dev(verbs_dev
);
251 struct hfi1_ibport
*ibp
= &dd
->pport
[port_num
- 1].ibport_data
;
252 u32 lid
= ppd_from_ibp(ibp
)->lid
;
254 memset(&data
, 0, sizeof(data
));
256 data
.generic_type
= IB_NOTICE_TYPE_INFO
;
257 data
.prod_type_lsb
= IB_NOTICE_PROD_CA
;
258 data
.trap_num
= OPA_TRAP_CHANGE_CAPABILITY
;
259 data
.issuer_lid
= cpu_to_be32(lid
);
260 data
.ntc_144
.lid
= data
.issuer_lid
;
261 data
.ntc_144
.new_cap_mask
= cpu_to_be32(ibp
->rvp
.port_cap_flags
);
263 send_trap(ibp
, &data
, sizeof(data
));
267 * Send a System Image GUID Changed trap (ch. 14.3.12).
269 void hfi1_sys_guid_chg(struct hfi1_ibport
*ibp
)
271 struct opa_mad_notice_attr data
;
272 u32 lid
= ppd_from_ibp(ibp
)->lid
;
274 memset(&data
, 0, sizeof(data
));
276 data
.generic_type
= IB_NOTICE_TYPE_INFO
;
277 data
.prod_type_lsb
= IB_NOTICE_PROD_CA
;
278 data
.trap_num
= OPA_TRAP_CHANGE_SYSGUID
;
279 data
.issuer_lid
= cpu_to_be32(lid
);
280 data
.ntc_145
.new_sys_guid
= ib_hfi1_sys_image_guid
;
281 data
.ntc_145
.lid
= data
.issuer_lid
;
283 send_trap(ibp
, &data
, sizeof(data
));
287 * Send a Node Description Changed trap (ch. 14.3.13).
289 void hfi1_node_desc_chg(struct hfi1_ibport
*ibp
)
291 struct opa_mad_notice_attr data
;
292 u32 lid
= ppd_from_ibp(ibp
)->lid
;
294 memset(&data
, 0, sizeof(data
));
296 data
.generic_type
= IB_NOTICE_TYPE_INFO
;
297 data
.prod_type_lsb
= IB_NOTICE_PROD_CA
;
298 data
.trap_num
= OPA_TRAP_CHANGE_CAPABILITY
;
299 data
.issuer_lid
= cpu_to_be32(lid
);
300 data
.ntc_144
.lid
= data
.issuer_lid
;
301 data
.ntc_144
.change_flags
=
302 cpu_to_be16(OPA_NOTICE_TRAP_NODE_DESC_CHG
);
304 send_trap(ibp
, &data
, sizeof(data
));
307 static int __subn_get_opa_nodedesc(struct opa_smp
*smp
, u32 am
,
308 u8
*data
, struct ib_device
*ibdev
,
309 u8 port
, u32
*resp_len
)
311 struct opa_node_description
*nd
;
314 smp
->status
|= IB_SMP_INVALID_FIELD
;
315 return reply((struct ib_mad_hdr
*)smp
);
318 nd
= (struct opa_node_description
*)data
;
320 memcpy(nd
->data
, ibdev
->node_desc
, sizeof(nd
->data
));
323 *resp_len
+= sizeof(*nd
);
325 return reply((struct ib_mad_hdr
*)smp
);
328 static int __subn_get_opa_nodeinfo(struct opa_smp
*smp
, u32 am
, u8
*data
,
329 struct ib_device
*ibdev
, u8 port
,
332 struct opa_node_info
*ni
;
333 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
334 unsigned pidx
= port
- 1; /* IB number port from 1, hw from 0 */
336 ni
= (struct opa_node_info
*)data
;
338 /* GUID 0 is illegal */
339 if (am
|| pidx
>= dd
->num_pports
|| dd
->pport
[pidx
].guid
== 0) {
340 smp
->status
|= IB_SMP_INVALID_FIELD
;
341 return reply((struct ib_mad_hdr
*)smp
);
344 ni
->port_guid
= cpu_to_be64(dd
->pport
[pidx
].guid
);
345 ni
->base_version
= OPA_MGMT_BASE_VERSION
;
346 ni
->class_version
= OPA_SMI_CLASS_VERSION
;
347 ni
->node_type
= 1; /* channel adapter */
348 ni
->num_ports
= ibdev
->phys_port_cnt
;
349 /* This is already in network order */
350 ni
->system_image_guid
= ib_hfi1_sys_image_guid
;
351 /* Use first-port GUID as node */
352 ni
->node_guid
= cpu_to_be64(dd
->pport
->guid
);
353 ni
->partition_cap
= cpu_to_be16(hfi1_get_npkeys(dd
));
354 ni
->device_id
= cpu_to_be16(dd
->pcidev
->device
);
355 ni
->revision
= cpu_to_be32(dd
->minrev
);
356 ni
->local_port_num
= port
;
357 ni
->vendor_id
[0] = dd
->oui1
;
358 ni
->vendor_id
[1] = dd
->oui2
;
359 ni
->vendor_id
[2] = dd
->oui3
;
362 *resp_len
+= sizeof(*ni
);
364 return reply((struct ib_mad_hdr
*)smp
);
367 static int subn_get_nodeinfo(struct ib_smp
*smp
, struct ib_device
*ibdev
,
370 struct ib_node_info
*nip
= (struct ib_node_info
*)&smp
->data
;
371 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
372 unsigned pidx
= port
- 1; /* IB number port from 1, hw from 0 */
374 /* GUID 0 is illegal */
375 if (smp
->attr_mod
|| pidx
>= dd
->num_pports
||
376 dd
->pport
[pidx
].guid
== 0)
377 smp
->status
|= IB_SMP_INVALID_FIELD
;
379 nip
->port_guid
= cpu_to_be64(dd
->pport
[pidx
].guid
);
381 nip
->base_version
= OPA_MGMT_BASE_VERSION
;
382 nip
->class_version
= OPA_SMI_CLASS_VERSION
;
383 nip
->node_type
= 1; /* channel adapter */
384 nip
->num_ports
= ibdev
->phys_port_cnt
;
385 /* This is already in network order */
386 nip
->sys_guid
= ib_hfi1_sys_image_guid
;
387 /* Use first-port GUID as node */
388 nip
->node_guid
= cpu_to_be64(dd
->pport
->guid
);
389 nip
->partition_cap
= cpu_to_be16(hfi1_get_npkeys(dd
));
390 nip
->device_id
= cpu_to_be16(dd
->pcidev
->device
);
391 nip
->revision
= cpu_to_be32(dd
->minrev
);
392 nip
->local_port_num
= port
;
393 nip
->vendor_id
[0] = dd
->oui1
;
394 nip
->vendor_id
[1] = dd
->oui2
;
395 nip
->vendor_id
[2] = dd
->oui3
;
397 return reply((struct ib_mad_hdr
*)smp
);
400 static void set_link_width_enabled(struct hfi1_pportdata
*ppd
, u32 w
)
402 (void)hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_LWID_ENB
, w
);
405 static void set_link_width_downgrade_enabled(struct hfi1_pportdata
*ppd
, u32 w
)
407 (void)hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_LWID_DG_ENB
, w
);
410 static void set_link_speed_enabled(struct hfi1_pportdata
*ppd
, u32 s
)
412 (void)hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_SPD_ENB
, s
);
415 static int check_mkey(struct hfi1_ibport
*ibp
, struct ib_mad_hdr
*mad
,
416 int mad_flags
, __be64 mkey
, __be32 dr_slid
,
417 u8 return_path
[], u8 hop_cnt
)
422 /* Is the mkey in the process of expiring? */
423 if (ibp
->rvp
.mkey_lease_timeout
&&
424 time_after_eq(jiffies
, ibp
->rvp
.mkey_lease_timeout
)) {
425 /* Clear timeout and mkey protection field. */
426 ibp
->rvp
.mkey_lease_timeout
= 0;
427 ibp
->rvp
.mkeyprot
= 0;
430 if ((mad_flags
& IB_MAD_IGNORE_MKEY
) || ibp
->rvp
.mkey
== 0 ||
431 ibp
->rvp
.mkey
== mkey
)
434 /* Unset lease timeout on any valid Get/Set/TrapRepress */
435 if (valid_mkey
&& ibp
->rvp
.mkey_lease_timeout
&&
436 (mad
->method
== IB_MGMT_METHOD_GET
||
437 mad
->method
== IB_MGMT_METHOD_SET
||
438 mad
->method
== IB_MGMT_METHOD_TRAP_REPRESS
))
439 ibp
->rvp
.mkey_lease_timeout
= 0;
442 switch (mad
->method
) {
443 case IB_MGMT_METHOD_GET
:
444 /* Bad mkey not a violation below level 2 */
445 if (ibp
->rvp
.mkeyprot
< 2)
447 case IB_MGMT_METHOD_SET
:
448 case IB_MGMT_METHOD_TRAP_REPRESS
:
449 if (ibp
->rvp
.mkey_violations
!= 0xFFFF)
450 ++ibp
->rvp
.mkey_violations
;
451 if (!ibp
->rvp
.mkey_lease_timeout
&&
452 ibp
->rvp
.mkey_lease_period
)
453 ibp
->rvp
.mkey_lease_timeout
= jiffies
+
454 ibp
->rvp
.mkey_lease_period
* HZ
;
455 /* Generate a trap notice. */
456 bad_mkey(ibp
, mad
, mkey
, dr_slid
, return_path
,
466 * The SMA caches reads from LCB registers in case the LCB is unavailable.
467 * (The LCB is unavailable in certain link states, for example.)
474 static struct lcb_datum lcb_cache
[] = {
475 { DC_LCB_STS_ROUND_TRIP_LTP_CNT
, 0 },
478 static int write_lcb_cache(u32 off
, u64 val
)
482 for (i
= 0; i
< ARRAY_SIZE(lcb_cache
); i
++) {
483 if (lcb_cache
[i
].off
== off
) {
484 lcb_cache
[i
].val
= val
;
489 pr_warn("%s bad offset 0x%x\n", __func__
, off
);
493 static int read_lcb_cache(u32 off
, u64
*val
)
497 for (i
= 0; i
< ARRAY_SIZE(lcb_cache
); i
++) {
498 if (lcb_cache
[i
].off
== off
) {
499 *val
= lcb_cache
[i
].val
;
504 pr_warn("%s bad offset 0x%x\n", __func__
, off
);
508 void read_ltp_rtt(struct hfi1_devdata
*dd
)
512 if (read_lcb_csr(dd
, DC_LCB_STS_ROUND_TRIP_LTP_CNT
, ®
))
513 dd_dev_err(dd
, "%s: unable to read LTP RTT\n", __func__
);
515 write_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT
, reg
);
518 static int __subn_get_opa_portinfo(struct opa_smp
*smp
, u32 am
, u8
*data
,
519 struct ib_device
*ibdev
, u8 port
,
523 struct hfi1_devdata
*dd
;
524 struct hfi1_pportdata
*ppd
;
525 struct hfi1_ibport
*ibp
;
526 struct opa_port_info
*pi
= (struct opa_port_info
*)data
;
529 u8 is_beaconing_active
;
531 u32 num_ports
= OPA_AM_NPORT(am
);
532 u32 start_of_sm_config
= OPA_AM_START_SM_CFG(am
);
536 if (num_ports
!= 1) {
537 smp
->status
|= IB_SMP_INVALID_FIELD
;
538 return reply((struct ib_mad_hdr
*)smp
);
541 dd
= dd_from_ibdev(ibdev
);
542 /* IB numbers ports from 1, hw from 0 */
543 ppd
= dd
->pport
+ (port
- 1);
544 ibp
= &ppd
->ibport_data
;
546 if (ppd
->vls_supported
/ 2 > ARRAY_SIZE(pi
->neigh_mtu
.pvlx_to_mtu
) ||
547 ppd
->vls_supported
> ARRAY_SIZE(dd
->vld
)) {
548 smp
->status
|= IB_SMP_INVALID_FIELD
;
549 return reply((struct ib_mad_hdr
*)smp
);
552 pi
->lid
= cpu_to_be32(ppd
->lid
);
554 /* Only return the mkey if the protection field allows it. */
555 if (!(smp
->method
== IB_MGMT_METHOD_GET
&&
556 ibp
->rvp
.mkey
!= smp
->mkey
&&
557 ibp
->rvp
.mkeyprot
== 1))
558 pi
->mkey
= ibp
->rvp
.mkey
;
560 pi
->subnet_prefix
= ibp
->rvp
.gid_prefix
;
561 pi
->sm_lid
= cpu_to_be32(ibp
->rvp
.sm_lid
);
562 pi
->ib_cap_mask
= cpu_to_be32(ibp
->rvp
.port_cap_flags
);
563 pi
->mkey_lease_period
= cpu_to_be16(ibp
->rvp
.mkey_lease_period
);
564 pi
->sm_trap_qp
= cpu_to_be32(ppd
->sm_trap_qp
);
565 pi
->sa_qp
= cpu_to_be32(ppd
->sa_qp
);
567 pi
->link_width
.enabled
= cpu_to_be16(ppd
->link_width_enabled
);
568 pi
->link_width
.supported
= cpu_to_be16(ppd
->link_width_supported
);
569 pi
->link_width
.active
= cpu_to_be16(ppd
->link_width_active
);
571 pi
->link_width_downgrade
.supported
=
572 cpu_to_be16(ppd
->link_width_downgrade_supported
);
573 pi
->link_width_downgrade
.enabled
=
574 cpu_to_be16(ppd
->link_width_downgrade_enabled
);
575 pi
->link_width_downgrade
.tx_active
=
576 cpu_to_be16(ppd
->link_width_downgrade_tx_active
);
577 pi
->link_width_downgrade
.rx_active
=
578 cpu_to_be16(ppd
->link_width_downgrade_rx_active
);
580 pi
->link_speed
.supported
= cpu_to_be16(ppd
->link_speed_supported
);
581 pi
->link_speed
.active
= cpu_to_be16(ppd
->link_speed_active
);
582 pi
->link_speed
.enabled
= cpu_to_be16(ppd
->link_speed_enabled
);
584 state
= driver_lstate(ppd
);
586 if (start_of_sm_config
&& (state
== IB_PORT_INIT
))
587 ppd
->is_sm_config_started
= 1;
589 pi
->port_phys_conf
= (ppd
->port_type
& 0xf);
591 pi
->port_states
.ledenable_offlinereason
= ppd
->neighbor_normal
<< 4;
592 pi
->port_states
.ledenable_offlinereason
|=
593 ppd
->is_sm_config_started
<< 5;
595 * This pairs with the memory barrier in hfi1_start_led_override to
596 * ensure that we read the correct state of LED beaconing represented
597 * by led_override_timer_active
600 is_beaconing_active
= !!atomic_read(&ppd
->led_override_timer_active
);
601 pi
->port_states
.ledenable_offlinereason
|= is_beaconing_active
<< 6;
602 pi
->port_states
.ledenable_offlinereason
|=
603 ppd
->offline_disabled_reason
;
605 pi
->port_states
.portphysstate_portstate
=
606 (hfi1_ibphys_portstate(ppd
) << 4) | state
;
608 pi
->mkeyprotect_lmc
= (ibp
->rvp
.mkeyprot
<< 6) | ppd
->lmc
;
610 memset(pi
->neigh_mtu
.pvlx_to_mtu
, 0, sizeof(pi
->neigh_mtu
.pvlx_to_mtu
));
611 for (i
= 0; i
< ppd
->vls_supported
; i
++) {
612 mtu
= mtu_to_enum(dd
->vld
[i
].mtu
, HFI1_DEFAULT_ACTIVE_MTU
);
614 pi
->neigh_mtu
.pvlx_to_mtu
[i
/ 2] |= (mtu
<< 4);
616 pi
->neigh_mtu
.pvlx_to_mtu
[i
/ 2] |= mtu
;
618 /* don't forget VL 15 */
619 mtu
= mtu_to_enum(dd
->vld
[15].mtu
, 2048);
620 pi
->neigh_mtu
.pvlx_to_mtu
[15 / 2] |= mtu
;
621 pi
->smsl
= ibp
->rvp
.sm_sl
& OPA_PI_MASK_SMSL
;
622 pi
->operational_vls
= hfi1_get_ib_cfg(ppd
, HFI1_IB_CFG_OP_VLS
);
623 pi
->partenforce_filterraw
|=
624 (ppd
->linkinit_reason
& OPA_PI_MASK_LINKINIT_REASON
);
625 if (ppd
->part_enforce
& HFI1_PART_ENFORCE_IN
)
626 pi
->partenforce_filterraw
|= OPA_PI_MASK_PARTITION_ENFORCE_IN
;
627 if (ppd
->part_enforce
& HFI1_PART_ENFORCE_OUT
)
628 pi
->partenforce_filterraw
|= OPA_PI_MASK_PARTITION_ENFORCE_OUT
;
629 pi
->mkey_violations
= cpu_to_be16(ibp
->rvp
.mkey_violations
);
630 /* P_KeyViolations are counted by hardware. */
631 pi
->pkey_violations
= cpu_to_be16(ibp
->rvp
.pkey_violations
);
632 pi
->qkey_violations
= cpu_to_be16(ibp
->rvp
.qkey_violations
);
634 pi
->vl
.cap
= ppd
->vls_supported
;
635 pi
->vl
.high_limit
= cpu_to_be16(ibp
->rvp
.vl_high_limit
);
636 pi
->vl
.arb_high_cap
= (u8
)hfi1_get_ib_cfg(ppd
, HFI1_IB_CFG_VL_HIGH_CAP
);
637 pi
->vl
.arb_low_cap
= (u8
)hfi1_get_ib_cfg(ppd
, HFI1_IB_CFG_VL_LOW_CAP
);
639 pi
->clientrereg_subnettimeout
= ibp
->rvp
.subnet_timeout
;
641 pi
->port_link_mode
= cpu_to_be16(OPA_PORT_LINK_MODE_OPA
<< 10 |
642 OPA_PORT_LINK_MODE_OPA
<< 5 |
643 OPA_PORT_LINK_MODE_OPA
);
645 pi
->port_ltp_crc_mode
= cpu_to_be16(ppd
->port_ltp_crc_mode
);
647 pi
->port_mode
= cpu_to_be16(
648 ppd
->is_active_optimize_enabled
?
649 OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE
: 0);
651 pi
->port_packet_format
.supported
=
652 cpu_to_be16(OPA_PORT_PACKET_FORMAT_9B
);
653 pi
->port_packet_format
.enabled
=
654 cpu_to_be16(OPA_PORT_PACKET_FORMAT_9B
);
656 /* flit_control.interleave is (OPA V1, version .76):
660 * 2 DistanceSupported
662 * 5 MaxNextLevelTxEnabled
663 * 5 MaxNestLevelRxSupported
665 * HFI supports only "distance mode 1" (see OPA V1, version .76,
666 * section 9.6.2), so set DistanceSupported, DistanceEnabled
669 pi
->flit_control
.interleave
= cpu_to_be16(0x1400);
671 pi
->link_down_reason
= ppd
->local_link_down_reason
.sma
;
672 pi
->neigh_link_down_reason
= ppd
->neigh_link_down_reason
.sma
;
673 pi
->port_error_action
= cpu_to_be32(ppd
->port_error_action
);
674 pi
->mtucap
= mtu_to_enum(hfi1_max_mtu
, IB_MTU_4096
);
676 /* 32.768 usec. response time (guessing) */
677 pi
->resptimevalue
= 3;
679 pi
->local_port_num
= port
;
681 /* buffer info for FM */
682 pi
->overall_buffer_space
= cpu_to_be16(dd
->link_credits
);
684 pi
->neigh_node_guid
= cpu_to_be64(ppd
->neighbor_guid
);
685 pi
->neigh_port_num
= ppd
->neighbor_port_number
;
686 pi
->port_neigh_mode
=
687 (ppd
->neighbor_type
& OPA_PI_MASK_NEIGH_NODE_TYPE
) |
688 (ppd
->mgmt_allowed
? OPA_PI_MASK_NEIGH_MGMT_ALLOWED
: 0) |
689 (ppd
->neighbor_fm_security
?
690 OPA_PI_MASK_NEIGH_FW_AUTH_BYPASS
: 0);
692 /* HFIs shall always return VL15 credits to their
693 * neighbor in a timely manner, without any credit return pacing.
696 buffer_units
= (dd
->vau
) & OPA_PI_MASK_BUF_UNIT_BUF_ALLOC
;
697 buffer_units
|= (dd
->vcu
<< 3) & OPA_PI_MASK_BUF_UNIT_CREDIT_ACK
;
698 buffer_units
|= (credit_rate
<< 6) &
699 OPA_PI_MASK_BUF_UNIT_VL15_CREDIT_RATE
;
700 buffer_units
|= (dd
->vl15_init
<< 11) & OPA_PI_MASK_BUF_UNIT_VL15_INIT
;
701 pi
->buffer_units
= cpu_to_be32(buffer_units
);
703 pi
->opa_cap_mask
= cpu_to_be16(OPA_CAP_MASK3_IsSharedSpaceSupported
);
705 /* HFI supports a replay buffer 128 LTPs in size */
706 pi
->replay_depth
.buffer
= 0x80;
707 /* read the cached value of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
708 read_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT
, &tmp
);
711 * this counter is 16 bits wide, but the replay_depth.wire
712 * variable is only 8 bits
716 pi
->replay_depth
.wire
= tmp
;
719 *resp_len
+= sizeof(struct opa_port_info
);
721 return reply((struct ib_mad_hdr
*)smp
);
725 * get_pkeys - return the PKEY table
726 * @dd: the hfi1_ib device
727 * @port: the IB port number
728 * @pkeys: the pkey table is placed here
730 static int get_pkeys(struct hfi1_devdata
*dd
, u8 port
, u16
*pkeys
)
732 struct hfi1_pportdata
*ppd
= dd
->pport
+ port
- 1;
734 memcpy(pkeys
, ppd
->pkeys
, sizeof(ppd
->pkeys
));
739 static int __subn_get_opa_pkeytable(struct opa_smp
*smp
, u32 am
, u8
*data
,
740 struct ib_device
*ibdev
, u8 port
,
743 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
744 u32 n_blocks_req
= OPA_AM_NBLK(am
);
745 u32 start_block
= am
& 0x7ff;
750 unsigned npkeys
= hfi1_get_npkeys(dd
);
753 if (n_blocks_req
== 0) {
754 pr_warn("OPA Get PKey AM Invalid : P = %d; B = 0x%x; N = 0x%x\n",
755 port
, start_block
, n_blocks_req
);
756 smp
->status
|= IB_SMP_INVALID_FIELD
;
757 return reply((struct ib_mad_hdr
*)smp
);
760 n_blocks_avail
= (u16
)(npkeys
/ OPA_PARTITION_TABLE_BLK_SIZE
) + 1;
762 size
= (n_blocks_req
* OPA_PARTITION_TABLE_BLK_SIZE
) * sizeof(u16
);
764 if (start_block
+ n_blocks_req
> n_blocks_avail
||
765 n_blocks_req
> OPA_NUM_PKEY_BLOCKS_PER_SMP
) {
766 pr_warn("OPA Get PKey AM Invalid : s 0x%x; req 0x%x; "
767 "avail 0x%x; blk/smp 0x%lx\n",
768 start_block
, n_blocks_req
, n_blocks_avail
,
769 OPA_NUM_PKEY_BLOCKS_PER_SMP
);
770 smp
->status
|= IB_SMP_INVALID_FIELD
;
771 return reply((struct ib_mad_hdr
*)smp
);
776 /* get the real pkeys if we are requesting the first block */
777 if (start_block
== 0) {
778 get_pkeys(dd
, port
, q
);
779 for (i
= 0; i
< npkeys
; i
++)
780 p
[i
] = cpu_to_be16(q
[i
]);
784 smp
->status
|= IB_SMP_INVALID_FIELD
;
786 return reply((struct ib_mad_hdr
*)smp
);
790 HFI_TRANSITION_DISALLOWED
,
791 HFI_TRANSITION_IGNORED
,
792 HFI_TRANSITION_ALLOWED
,
793 HFI_TRANSITION_UNDEFINED
,
797 * Use shortened names to improve readability of
798 * {logical,physical}_state_transitions
801 __D
= HFI_TRANSITION_DISALLOWED
,
802 __I
= HFI_TRANSITION_IGNORED
,
803 __A
= HFI_TRANSITION_ALLOWED
,
804 __U
= HFI_TRANSITION_UNDEFINED
,
808 * IB_PORTPHYSSTATE_POLLING (2) through OPA_PORTPHYSSTATE_MAX (11) are
809 * represented in physical_state_transitions.
811 #define __N_PHYSTATES (OPA_PORTPHYSSTATE_MAX - IB_PORTPHYSSTATE_POLLING + 1)
814 * Within physical_state_transitions, rows represent "old" states,
815 * columns "new" states, and physical_state_transitions.allowed[old][new]
816 * indicates if the transition from old state to new state is legal (see
817 * OPAg1v1, Table 6-4).
819 static const struct {
820 u8 allowed
[__N_PHYSTATES
][__N_PHYSTATES
];
821 } physical_state_transitions
= {
823 /* 2 3 4 5 6 7 8 9 10 11 */
824 /* 2 */ { __A
, __A
, __D
, __D
, __D
, __D
, __D
, __D
, __D
, __D
},
825 /* 3 */ { __A
, __I
, __D
, __D
, __D
, __D
, __D
, __D
, __D
, __A
},
826 /* 4 */ { __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
},
827 /* 5 */ { __A
, __A
, __D
, __I
, __D
, __D
, __D
, __D
, __D
, __D
},
828 /* 6 */ { __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
},
829 /* 7 */ { __D
, __A
, __D
, __D
, __D
, __I
, __D
, __D
, __D
, __D
},
830 /* 8 */ { __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
},
831 /* 9 */ { __I
, __A
, __D
, __D
, __D
, __D
, __D
, __I
, __D
, __D
},
832 /*10 */ { __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
},
833 /*11 */ { __D
, __A
, __D
, __D
, __D
, __D
, __D
, __D
, __D
, __I
},
838 * IB_PORT_DOWN (1) through IB_PORT_ACTIVE_DEFER (5) are represented
839 * logical_state_transitions
842 #define __N_LOGICAL_STATES (IB_PORT_ACTIVE_DEFER - IB_PORT_DOWN + 1)
845 * Within logical_state_transitions rows represent "old" states,
846 * columns "new" states, and logical_state_transitions.allowed[old][new]
847 * indicates if the transition from old state to new state is legal (see
848 * OPAg1v1, Table 9-12).
850 static const struct {
851 u8 allowed
[__N_LOGICAL_STATES
][__N_LOGICAL_STATES
];
852 } logical_state_transitions
= {
855 /* 1 */ { __I
, __D
, __D
, __D
, __U
},
856 /* 2 */ { __D
, __I
, __A
, __D
, __U
},
857 /* 3 */ { __D
, __D
, __I
, __A
, __U
},
858 /* 4 */ { __D
, __D
, __I
, __I
, __U
},
859 /* 5 */ { __U
, __U
, __U
, __U
, __U
},
863 static int logical_transition_allowed(int old
, int new)
865 if (old
< IB_PORT_NOP
|| old
> IB_PORT_ACTIVE_DEFER
||
866 new < IB_PORT_NOP
|| new > IB_PORT_ACTIVE_DEFER
) {
867 pr_warn("invalid logical state(s) (old %d new %d)\n",
869 return HFI_TRANSITION_UNDEFINED
;
872 if (new == IB_PORT_NOP
)
873 return HFI_TRANSITION_ALLOWED
; /* always allowed */
875 /* adjust states for indexing into logical_state_transitions */
879 if (old
< 0 || new < 0)
880 return HFI_TRANSITION_UNDEFINED
;
881 return logical_state_transitions
.allowed
[old
][new];
884 static int physical_transition_allowed(int old
, int new)
886 if (old
< IB_PORTPHYSSTATE_NOP
|| old
> OPA_PORTPHYSSTATE_MAX
||
887 new < IB_PORTPHYSSTATE_NOP
|| new > OPA_PORTPHYSSTATE_MAX
) {
888 pr_warn("invalid physical state(s) (old %d new %d)\n",
890 return HFI_TRANSITION_UNDEFINED
;
893 if (new == IB_PORTPHYSSTATE_NOP
)
894 return HFI_TRANSITION_ALLOWED
; /* always allowed */
896 /* adjust states for indexing into physical_state_transitions */
897 old
-= IB_PORTPHYSSTATE_POLLING
;
898 new -= IB_PORTPHYSSTATE_POLLING
;
900 if (old
< 0 || new < 0)
901 return HFI_TRANSITION_UNDEFINED
;
902 return physical_state_transitions
.allowed
[old
][new];
905 static int port_states_transition_allowed(struct hfi1_pportdata
*ppd
,
906 u32 logical_new
, u32 physical_new
)
908 u32 physical_old
= driver_physical_state(ppd
);
909 u32 logical_old
= driver_logical_state(ppd
);
910 int ret
, logical_allowed
, physical_allowed
;
912 ret
= logical_transition_allowed(logical_old
, logical_new
);
913 logical_allowed
= ret
;
915 if (ret
== HFI_TRANSITION_DISALLOWED
||
916 ret
== HFI_TRANSITION_UNDEFINED
) {
917 pr_warn("invalid logical state transition %s -> %s\n",
918 opa_lstate_name(logical_old
),
919 opa_lstate_name(logical_new
));
923 ret
= physical_transition_allowed(physical_old
, physical_new
);
924 physical_allowed
= ret
;
926 if (ret
== HFI_TRANSITION_DISALLOWED
||
927 ret
== HFI_TRANSITION_UNDEFINED
) {
928 pr_warn("invalid physical state transition %s -> %s\n",
929 opa_pstate_name(physical_old
),
930 opa_pstate_name(physical_new
));
934 if (logical_allowed
== HFI_TRANSITION_IGNORED
&&
935 physical_allowed
== HFI_TRANSITION_IGNORED
)
936 return HFI_TRANSITION_IGNORED
;
939 * A change request of Physical Port State from
940 * 'Offline' to 'Polling' should be ignored.
942 if ((physical_old
== OPA_PORTPHYSSTATE_OFFLINE
) &&
943 (physical_new
== IB_PORTPHYSSTATE_POLLING
))
944 return HFI_TRANSITION_IGNORED
;
947 * Either physical_allowed or logical_allowed is
948 * HFI_TRANSITION_ALLOWED.
950 return HFI_TRANSITION_ALLOWED
;
953 static int set_port_states(struct hfi1_pportdata
*ppd
, struct opa_smp
*smp
,
954 u32 logical_state
, u32 phys_state
,
955 int suppress_idle_sma
)
957 struct hfi1_devdata
*dd
= ppd
->dd
;
961 ret
= port_states_transition_allowed(ppd
, logical_state
, phys_state
);
962 if (ret
== HFI_TRANSITION_DISALLOWED
||
963 ret
== HFI_TRANSITION_UNDEFINED
) {
964 /* error message emitted above */
965 smp
->status
|= IB_SMP_INVALID_FIELD
;
969 if (ret
== HFI_TRANSITION_IGNORED
)
972 if ((phys_state
!= IB_PORTPHYSSTATE_NOP
) &&
973 !(logical_state
== IB_PORT_DOWN
||
974 logical_state
== IB_PORT_NOP
)){
975 pr_warn("SubnSet(OPA_PortInfo) port state invalid: logical_state 0x%x physical_state 0x%x\n",
976 logical_state
, phys_state
);
977 smp
->status
|= IB_SMP_INVALID_FIELD
;
981 * Logical state changes are summarized in OPAv1g1 spec.,
982 * Table 9-12; physical state changes are summarized in
983 * OPAv1g1 spec., Table 6.4.
985 switch (logical_state
) {
987 if (phys_state
== IB_PORTPHYSSTATE_NOP
)
991 if (phys_state
== IB_PORTPHYSSTATE_NOP
) {
992 link_state
= HLS_DN_DOWNDEF
;
993 } else if (phys_state
== IB_PORTPHYSSTATE_POLLING
) {
994 link_state
= HLS_DN_POLL
;
995 set_link_down_reason(ppd
, OPA_LINKDOWN_REASON_FM_BOUNCE
,
996 0, OPA_LINKDOWN_REASON_FM_BOUNCE
);
997 } else if (phys_state
== IB_PORTPHYSSTATE_DISABLED
) {
998 link_state
= HLS_DN_DISABLE
;
1000 pr_warn("SubnSet(OPA_PortInfo) invalid physical state 0x%x\n",
1002 smp
->status
|= IB_SMP_INVALID_FIELD
;
1006 if ((link_state
== HLS_DN_POLL
||
1007 link_state
== HLS_DN_DOWNDEF
)) {
1009 * Going to poll. No matter what the current state,
1010 * always move offline first, then tune and start the
1011 * link. This correctly handles a FM link bounce and
1012 * a link enable. Going offline is a no-op if already
1015 set_link_state(ppd
, HLS_DN_OFFLINE
);
1019 set_link_state(ppd
, link_state
);
1021 if (link_state
== HLS_DN_DISABLE
&&
1022 (ppd
->offline_disabled_reason
>
1023 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED
) ||
1024 ppd
->offline_disabled_reason
==
1025 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE
)))
1026 ppd
->offline_disabled_reason
=
1027 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED
);
1029 * Don't send a reply if the response would be sent
1030 * through the disabled port.
1032 if (link_state
== HLS_DN_DISABLE
&& smp
->hop_cnt
)
1033 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_CONSUMED
;
1036 ret
= set_link_state(ppd
, HLS_UP_ARMED
);
1037 if ((ret
== 0) && (suppress_idle_sma
== 0))
1038 send_idle_sma(dd
, SMA_IDLE_ARM
);
1040 case IB_PORT_ACTIVE
:
1041 if (ppd
->neighbor_normal
) {
1042 ret
= set_link_state(ppd
, HLS_UP_ACTIVE
);
1044 send_idle_sma(dd
, SMA_IDLE_ACTIVE
);
1046 pr_warn("SubnSet(OPA_PortInfo) Cannot move to Active with NeighborNormal 0\n");
1047 smp
->status
|= IB_SMP_INVALID_FIELD
;
1051 pr_warn("SubnSet(OPA_PortInfo) invalid logical state 0x%x\n",
1053 smp
->status
|= IB_SMP_INVALID_FIELD
;
1060 * subn_set_opa_portinfo - set port information
1061 * @smp: the incoming SM packet
1062 * @ibdev: the infiniband device
1063 * @port: the port on the device
1066 static int __subn_set_opa_portinfo(struct opa_smp
*smp
, u32 am
, u8
*data
,
1067 struct ib_device
*ibdev
, u8 port
,
1070 struct opa_port_info
*pi
= (struct opa_port_info
*)data
;
1071 struct ib_event event
;
1072 struct hfi1_devdata
*dd
;
1073 struct hfi1_pportdata
*ppd
;
1074 struct hfi1_ibport
*ibp
;
1076 unsigned long flags
;
1077 u32 smlid
, opa_lid
; /* tmp vars to hold LID values */
1079 u8 ls_old
, ls_new
, ps_new
;
1084 u32 num_ports
= OPA_AM_NPORT(am
);
1085 u32 start_of_sm_config
= OPA_AM_START_SM_CFG(am
);
1086 int ret
, i
, invalid
= 0, call_set_mtu
= 0;
1087 int call_link_downgrade_policy
= 0;
1089 if (num_ports
!= 1) {
1090 smp
->status
|= IB_SMP_INVALID_FIELD
;
1091 return reply((struct ib_mad_hdr
*)smp
);
1094 opa_lid
= be32_to_cpu(pi
->lid
);
1095 if (opa_lid
& 0xFFFF0000) {
1096 pr_warn("OPA_PortInfo lid out of range: %X\n", opa_lid
);
1097 smp
->status
|= IB_SMP_INVALID_FIELD
;
1101 lid
= (u16
)(opa_lid
& 0x0000FFFF);
1103 smlid
= be32_to_cpu(pi
->sm_lid
);
1104 if (smlid
& 0xFFFF0000) {
1105 pr_warn("OPA_PortInfo SM lid out of range: %X\n", smlid
);
1106 smp
->status
|= IB_SMP_INVALID_FIELD
;
1109 smlid
&= 0x0000FFFF;
1111 clientrereg
= (pi
->clientrereg_subnettimeout
&
1112 OPA_PI_MASK_CLIENT_REREGISTER
);
1114 dd
= dd_from_ibdev(ibdev
);
1115 /* IB numbers ports from 1, hw from 0 */
1116 ppd
= dd
->pport
+ (port
- 1);
1117 ibp
= &ppd
->ibport_data
;
1118 event
.device
= ibdev
;
1119 event
.element
.port_num
= port
;
1121 ls_old
= driver_lstate(ppd
);
1123 ibp
->rvp
.mkey
= pi
->mkey
;
1124 ibp
->rvp
.gid_prefix
= pi
->subnet_prefix
;
1125 ibp
->rvp
.mkey_lease_period
= be16_to_cpu(pi
->mkey_lease_period
);
1127 /* Must be a valid unicast LID address. */
1128 if ((lid
== 0 && ls_old
> IB_PORT_INIT
) ||
1129 lid
>= be16_to_cpu(IB_MULTICAST_LID_BASE
)) {
1130 smp
->status
|= IB_SMP_INVALID_FIELD
;
1131 pr_warn("SubnSet(OPA_PortInfo) lid invalid 0x%x\n",
1133 } else if (ppd
->lid
!= lid
||
1134 ppd
->lmc
!= (pi
->mkeyprotect_lmc
& OPA_PI_MASK_LMC
)) {
1135 if (ppd
->lid
!= lid
)
1136 hfi1_set_uevent_bits(ppd
, _HFI1_EVENT_LID_CHANGE_BIT
);
1137 if (ppd
->lmc
!= (pi
->mkeyprotect_lmc
& OPA_PI_MASK_LMC
))
1138 hfi1_set_uevent_bits(ppd
, _HFI1_EVENT_LMC_CHANGE_BIT
);
1139 hfi1_set_lid(ppd
, lid
, pi
->mkeyprotect_lmc
& OPA_PI_MASK_LMC
);
1140 event
.event
= IB_EVENT_LID_CHANGE
;
1141 ib_dispatch_event(&event
);
1144 msl
= pi
->smsl
& OPA_PI_MASK_SMSL
;
1145 if (pi
->partenforce_filterraw
& OPA_PI_MASK_LINKINIT_REASON
)
1146 ppd
->linkinit_reason
=
1147 (pi
->partenforce_filterraw
&
1148 OPA_PI_MASK_LINKINIT_REASON
);
1149 /* enable/disable SW pkey checking as per FM control */
1150 if (pi
->partenforce_filterraw
& OPA_PI_MASK_PARTITION_ENFORCE_IN
)
1151 ppd
->part_enforce
|= HFI1_PART_ENFORCE_IN
;
1153 ppd
->part_enforce
&= ~HFI1_PART_ENFORCE_IN
;
1155 if (pi
->partenforce_filterraw
& OPA_PI_MASK_PARTITION_ENFORCE_OUT
)
1156 ppd
->part_enforce
|= HFI1_PART_ENFORCE_OUT
;
1158 ppd
->part_enforce
&= ~HFI1_PART_ENFORCE_OUT
;
1160 /* Must be a valid unicast LID address. */
1161 if ((smlid
== 0 && ls_old
> IB_PORT_INIT
) ||
1162 smlid
>= be16_to_cpu(IB_MULTICAST_LID_BASE
)) {
1163 smp
->status
|= IB_SMP_INVALID_FIELD
;
1164 pr_warn("SubnSet(OPA_PortInfo) smlid invalid 0x%x\n", smlid
);
1165 } else if (smlid
!= ibp
->rvp
.sm_lid
|| msl
!= ibp
->rvp
.sm_sl
) {
1166 pr_warn("SubnSet(OPA_PortInfo) smlid 0x%x\n", smlid
);
1167 spin_lock_irqsave(&ibp
->rvp
.lock
, flags
);
1168 if (ibp
->rvp
.sm_ah
) {
1169 if (smlid
!= ibp
->rvp
.sm_lid
)
1170 ibp
->rvp
.sm_ah
->attr
.dlid
= smlid
;
1171 if (msl
!= ibp
->rvp
.sm_sl
)
1172 ibp
->rvp
.sm_ah
->attr
.sl
= msl
;
1174 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
1175 if (smlid
!= ibp
->rvp
.sm_lid
)
1176 ibp
->rvp
.sm_lid
= smlid
;
1177 if (msl
!= ibp
->rvp
.sm_sl
)
1178 ibp
->rvp
.sm_sl
= msl
;
1179 event
.event
= IB_EVENT_SM_CHANGE
;
1180 ib_dispatch_event(&event
);
1183 if (pi
->link_down_reason
== 0) {
1184 ppd
->local_link_down_reason
.sma
= 0;
1185 ppd
->local_link_down_reason
.latest
= 0;
1188 if (pi
->neigh_link_down_reason
== 0) {
1189 ppd
->neigh_link_down_reason
.sma
= 0;
1190 ppd
->neigh_link_down_reason
.latest
= 0;
1193 ppd
->sm_trap_qp
= be32_to_cpu(pi
->sm_trap_qp
);
1194 ppd
->sa_qp
= be32_to_cpu(pi
->sa_qp
);
1196 ppd
->port_error_action
= be32_to_cpu(pi
->port_error_action
);
1197 lwe
= be16_to_cpu(pi
->link_width
.enabled
);
1199 if (lwe
== OPA_LINK_WIDTH_RESET
||
1200 lwe
== OPA_LINK_WIDTH_RESET_OLD
)
1201 set_link_width_enabled(ppd
, ppd
->link_width_supported
);
1202 else if ((lwe
& ~ppd
->link_width_supported
) == 0)
1203 set_link_width_enabled(ppd
, lwe
);
1205 smp
->status
|= IB_SMP_INVALID_FIELD
;
1207 lwe
= be16_to_cpu(pi
->link_width_downgrade
.enabled
);
1208 /* LWD.E is always applied - 0 means "disabled" */
1209 if (lwe
== OPA_LINK_WIDTH_RESET
||
1210 lwe
== OPA_LINK_WIDTH_RESET_OLD
) {
1211 set_link_width_downgrade_enabled(ppd
,
1213 link_width_downgrade_supported
1215 } else if ((lwe
& ~ppd
->link_width_downgrade_supported
) == 0) {
1216 /* only set and apply if something changed */
1217 if (lwe
!= ppd
->link_width_downgrade_enabled
) {
1218 set_link_width_downgrade_enabled(ppd
, lwe
);
1219 call_link_downgrade_policy
= 1;
1222 smp
->status
|= IB_SMP_INVALID_FIELD
;
1224 lse
= be16_to_cpu(pi
->link_speed
.enabled
);
1226 if (lse
& be16_to_cpu(pi
->link_speed
.supported
))
1227 set_link_speed_enabled(ppd
, lse
);
1229 smp
->status
|= IB_SMP_INVALID_FIELD
;
1233 (pi
->mkeyprotect_lmc
& OPA_PI_MASK_MKEY_PROT_BIT
) >> 6;
1234 ibp
->rvp
.vl_high_limit
= be16_to_cpu(pi
->vl
.high_limit
) & 0xFF;
1235 (void)hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_VL_HIGH_LIMIT
,
1236 ibp
->rvp
.vl_high_limit
);
1238 if (ppd
->vls_supported
/ 2 > ARRAY_SIZE(pi
->neigh_mtu
.pvlx_to_mtu
) ||
1239 ppd
->vls_supported
> ARRAY_SIZE(dd
->vld
)) {
1240 smp
->status
|= IB_SMP_INVALID_FIELD
;
1241 return reply((struct ib_mad_hdr
*)smp
);
1243 for (i
= 0; i
< ppd
->vls_supported
; i
++) {
1245 mtu
= enum_to_mtu((pi
->neigh_mtu
.pvlx_to_mtu
[i
/ 2] >>
1248 mtu
= enum_to_mtu(pi
->neigh_mtu
.pvlx_to_mtu
[i
/ 2] &
1250 if (mtu
== 0xffff) {
1251 pr_warn("SubnSet(OPA_PortInfo) mtu invalid %d (0x%x)\n",
1253 (pi
->neigh_mtu
.pvlx_to_mtu
[0] >> 4) & 0xF);
1254 smp
->status
|= IB_SMP_INVALID_FIELD
;
1255 mtu
= hfi1_max_mtu
; /* use a valid MTU */
1257 if (dd
->vld
[i
].mtu
!= mtu
) {
1259 "MTU change on vl %d from %d to %d\n",
1260 i
, dd
->vld
[i
].mtu
, mtu
);
1261 dd
->vld
[i
].mtu
= mtu
;
1265 /* As per OPAV1 spec: VL15 must support and be configured
1266 * for operation with a 2048 or larger MTU.
1268 mtu
= enum_to_mtu(pi
->neigh_mtu
.pvlx_to_mtu
[15 / 2] & 0xF);
1269 if (mtu
< 2048 || mtu
== 0xffff)
1271 if (dd
->vld
[15].mtu
!= mtu
) {
1273 "MTU change on vl 15 from %d to %d\n",
1274 dd
->vld
[15].mtu
, mtu
);
1275 dd
->vld
[15].mtu
= mtu
;
1281 /* Set operational VLs */
1282 vls
= pi
->operational_vls
& OPA_PI_MASK_OPERATIONAL_VL
;
1284 if (vls
> ppd
->vls_supported
) {
1285 pr_warn("SubnSet(OPA_PortInfo) VL's supported invalid %d\n",
1286 pi
->operational_vls
);
1287 smp
->status
|= IB_SMP_INVALID_FIELD
;
1289 if (hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_OP_VLS
,
1291 smp
->status
|= IB_SMP_INVALID_FIELD
;
1295 if (pi
->mkey_violations
== 0)
1296 ibp
->rvp
.mkey_violations
= 0;
1298 if (pi
->pkey_violations
== 0)
1299 ibp
->rvp
.pkey_violations
= 0;
1301 if (pi
->qkey_violations
== 0)
1302 ibp
->rvp
.qkey_violations
= 0;
1304 ibp
->rvp
.subnet_timeout
=
1305 pi
->clientrereg_subnettimeout
& OPA_PI_MASK_SUBNET_TIMEOUT
;
1307 crc_enabled
= be16_to_cpu(pi
->port_ltp_crc_mode
);
1311 if (crc_enabled
!= 0)
1312 ppd
->port_crc_mode_enabled
= port_ltp_to_cap(crc_enabled
);
1314 ppd
->is_active_optimize_enabled
=
1315 !!(be16_to_cpu(pi
->port_mode
)
1316 & OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE
);
1318 ls_new
= pi
->port_states
.portphysstate_portstate
&
1319 OPA_PI_MASK_PORT_STATE
;
1320 ps_new
= (pi
->port_states
.portphysstate_portstate
&
1321 OPA_PI_MASK_PORT_PHYSICAL_STATE
) >> 4;
1323 if (ls_old
== IB_PORT_INIT
) {
1324 if (start_of_sm_config
) {
1325 if (ls_new
== ls_old
|| (ls_new
== IB_PORT_ARMED
))
1326 ppd
->is_sm_config_started
= 1;
1327 } else if (ls_new
== IB_PORT_ARMED
) {
1328 if (ppd
->is_sm_config_started
== 0)
1333 /* Handle CLIENT_REREGISTER event b/c SM asked us for it */
1335 event
.event
= IB_EVENT_CLIENT_REREGISTER
;
1336 ib_dispatch_event(&event
);
1340 * Do the port state change now that the other link parameters
1342 * Changing the port physical state only makes sense if the link
1343 * is down or is being set to down.
1346 ret
= set_port_states(ppd
, smp
, ls_new
, ps_new
, invalid
);
1350 ret
= __subn_get_opa_portinfo(smp
, am
, data
, ibdev
, port
, resp_len
);
1352 /* restore re-reg bit per o14-12.2.1 */
1353 pi
->clientrereg_subnettimeout
|= clientrereg
;
1356 * Apply the new link downgrade policy. This may result in a link
1357 * bounce. Do this after everything else so things are settled.
1358 * Possible problem: if setting the port state above fails, then
1359 * the policy change is not applied.
1361 if (call_link_downgrade_policy
)
1362 apply_link_downgrade_policy(ppd
, 0);
1367 return __subn_get_opa_portinfo(smp
, am
, data
, ibdev
, port
, resp_len
);
1371 * set_pkeys - set the PKEY table for ctxt 0
1372 * @dd: the hfi1_ib device
1373 * @port: the IB port number
1374 * @pkeys: the PKEY table
1376 static int set_pkeys(struct hfi1_devdata
*dd
, u8 port
, u16
*pkeys
)
1378 struct hfi1_pportdata
*ppd
;
1381 int update_includes_mgmt_partition
= 0;
1384 * IB port one/two always maps to context zero/one,
1385 * always a kernel context, no locking needed
1386 * If we get here with ppd setup, no need to check
1387 * that rcd is valid.
1389 ppd
= dd
->pport
+ (port
- 1);
1391 * If the update does not include the management pkey, don't do it.
1393 for (i
= 0; i
< ARRAY_SIZE(ppd
->pkeys
); i
++) {
1394 if (pkeys
[i
] == LIM_MGMT_P_KEY
) {
1395 update_includes_mgmt_partition
= 1;
1400 if (!update_includes_mgmt_partition
)
1403 for (i
= 0; i
< ARRAY_SIZE(ppd
->pkeys
); i
++) {
1405 u16 okey
= ppd
->pkeys
[i
];
1410 * Don't update pkeys[2], if an HFI port without MgmtAllowed
1411 * by neighbor is a switch.
1413 if (i
== 2 && !ppd
->mgmt_allowed
&& ppd
->neighbor_type
== 1)
1416 * The SM gives us the complete PKey table. We have
1417 * to ensure that we put the PKeys in the matching
1420 ppd
->pkeys
[i
] = key
;
1425 (void)hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_PKEYS
, 0);
1426 hfi1_event_pkey_change(dd
, port
);
1432 static int __subn_set_opa_pkeytable(struct opa_smp
*smp
, u32 am
, u8
*data
,
1433 struct ib_device
*ibdev
, u8 port
,
1436 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1437 u32 n_blocks_sent
= OPA_AM_NBLK(am
);
1438 u32 start_block
= am
& 0x7ff;
1439 u16
*p
= (u16
*)data
;
1440 __be16
*q
= (__be16
*)data
;
1443 unsigned npkeys
= hfi1_get_npkeys(dd
);
1445 if (n_blocks_sent
== 0) {
1446 pr_warn("OPA Get PKey AM Invalid : P = %d; B = 0x%x; N = 0x%x\n",
1447 port
, start_block
, n_blocks_sent
);
1448 smp
->status
|= IB_SMP_INVALID_FIELD
;
1449 return reply((struct ib_mad_hdr
*)smp
);
1452 n_blocks_avail
= (u16
)(npkeys
/ OPA_PARTITION_TABLE_BLK_SIZE
) + 1;
1454 if (start_block
+ n_blocks_sent
> n_blocks_avail
||
1455 n_blocks_sent
> OPA_NUM_PKEY_BLOCKS_PER_SMP
) {
1456 pr_warn("OPA Set PKey AM Invalid : s 0x%x; req 0x%x; avail 0x%x; blk/smp 0x%lx\n",
1457 start_block
, n_blocks_sent
, n_blocks_avail
,
1458 OPA_NUM_PKEY_BLOCKS_PER_SMP
);
1459 smp
->status
|= IB_SMP_INVALID_FIELD
;
1460 return reply((struct ib_mad_hdr
*)smp
);
1463 for (i
= 0; i
< n_blocks_sent
* OPA_PARTITION_TABLE_BLK_SIZE
; i
++)
1464 p
[i
] = be16_to_cpu(q
[i
]);
1466 if (start_block
== 0 && set_pkeys(dd
, port
, p
) != 0) {
1467 smp
->status
|= IB_SMP_INVALID_FIELD
;
1468 return reply((struct ib_mad_hdr
*)smp
);
1471 return __subn_get_opa_pkeytable(smp
, am
, data
, ibdev
, port
, resp_len
);
1474 static int get_sc2vlt_tables(struct hfi1_devdata
*dd
, void *data
)
1478 *val
++ = read_csr(dd
, SEND_SC2VLT0
);
1479 *val
++ = read_csr(dd
, SEND_SC2VLT1
);
1480 *val
++ = read_csr(dd
, SEND_SC2VLT2
);
1481 *val
++ = read_csr(dd
, SEND_SC2VLT3
);
1485 #define ILLEGAL_VL 12
1487 * filter_sc2vlt changes mappings to VL15 to ILLEGAL_VL (except
1488 * for SC15, which must map to VL15). If we don't remap things this
1489 * way it is possible for VL15 counters to increment when we try to
1490 * send on a SC which is mapped to an invalid VL.
1492 static void filter_sc2vlt(void *data
)
1497 for (i
= 0; i
< OPA_MAX_SCS
; i
++) {
1500 if ((pd
[i
] & 0x1f) == 0xf)
1505 static int set_sc2vlt_tables(struct hfi1_devdata
*dd
, void *data
)
1509 filter_sc2vlt(data
);
1511 write_csr(dd
, SEND_SC2VLT0
, *val
++);
1512 write_csr(dd
, SEND_SC2VLT1
, *val
++);
1513 write_csr(dd
, SEND_SC2VLT2
, *val
++);
1514 write_csr(dd
, SEND_SC2VLT3
, *val
++);
1515 write_seqlock_irq(&dd
->sc2vl_lock
);
1516 memcpy(dd
->sc2vl
, data
, sizeof(dd
->sc2vl
));
1517 write_sequnlock_irq(&dd
->sc2vl_lock
);
1521 static int __subn_get_opa_sl_to_sc(struct opa_smp
*smp
, u32 am
, u8
*data
,
1522 struct ib_device
*ibdev
, u8 port
,
1525 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
1527 size_t size
= ARRAY_SIZE(ibp
->sl_to_sc
); /* == 32 */
1531 smp
->status
|= IB_SMP_INVALID_FIELD
;
1532 return reply((struct ib_mad_hdr
*)smp
);
1535 for (i
= 0; i
< ARRAY_SIZE(ibp
->sl_to_sc
); i
++)
1536 *p
++ = ibp
->sl_to_sc
[i
];
1541 return reply((struct ib_mad_hdr
*)smp
);
1544 static int __subn_set_opa_sl_to_sc(struct opa_smp
*smp
, u32 am
, u8
*data
,
1545 struct ib_device
*ibdev
, u8 port
,
1548 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
1554 smp
->status
|= IB_SMP_INVALID_FIELD
;
1555 return reply((struct ib_mad_hdr
*)smp
);
1558 for (i
= 0; i
< ARRAY_SIZE(ibp
->sl_to_sc
); i
++) {
1560 if (ibp
->sl_to_sc
[i
] != sc
) {
1561 ibp
->sl_to_sc
[i
] = sc
;
1563 /* Put all stale qps into error state */
1564 hfi1_error_port_qps(ibp
, i
);
1568 return __subn_get_opa_sl_to_sc(smp
, am
, data
, ibdev
, port
, resp_len
);
1571 static int __subn_get_opa_sc_to_sl(struct opa_smp
*smp
, u32 am
, u8
*data
,
1572 struct ib_device
*ibdev
, u8 port
,
1575 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
1577 size_t size
= ARRAY_SIZE(ibp
->sc_to_sl
); /* == 32 */
1581 smp
->status
|= IB_SMP_INVALID_FIELD
;
1582 return reply((struct ib_mad_hdr
*)smp
);
1585 for (i
= 0; i
< ARRAY_SIZE(ibp
->sc_to_sl
); i
++)
1586 *p
++ = ibp
->sc_to_sl
[i
];
1591 return reply((struct ib_mad_hdr
*)smp
);
1594 static int __subn_set_opa_sc_to_sl(struct opa_smp
*smp
, u32 am
, u8
*data
,
1595 struct ib_device
*ibdev
, u8 port
,
1598 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
1603 smp
->status
|= IB_SMP_INVALID_FIELD
;
1604 return reply((struct ib_mad_hdr
*)smp
);
1607 for (i
= 0; i
< ARRAY_SIZE(ibp
->sc_to_sl
); i
++)
1608 ibp
->sc_to_sl
[i
] = *p
++;
1610 return __subn_get_opa_sc_to_sl(smp
, am
, data
, ibdev
, port
, resp_len
);
1613 static int __subn_get_opa_sc_to_vlt(struct opa_smp
*smp
, u32 am
, u8
*data
,
1614 struct ib_device
*ibdev
, u8 port
,
1617 u32 n_blocks
= OPA_AM_NBLK(am
);
1618 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1619 void *vp
= (void *)data
;
1620 size_t size
= 4 * sizeof(u64
);
1622 if (n_blocks
!= 1) {
1623 smp
->status
|= IB_SMP_INVALID_FIELD
;
1624 return reply((struct ib_mad_hdr
*)smp
);
1627 get_sc2vlt_tables(dd
, vp
);
1632 return reply((struct ib_mad_hdr
*)smp
);
1635 static int __subn_set_opa_sc_to_vlt(struct opa_smp
*smp
, u32 am
, u8
*data
,
1636 struct ib_device
*ibdev
, u8 port
,
1639 u32 n_blocks
= OPA_AM_NBLK(am
);
1640 int async_update
= OPA_AM_ASYNC(am
);
1641 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1642 void *vp
= (void *)data
;
1643 struct hfi1_pportdata
*ppd
;
1646 if (n_blocks
!= 1 || async_update
) {
1647 smp
->status
|= IB_SMP_INVALID_FIELD
;
1648 return reply((struct ib_mad_hdr
*)smp
);
1651 /* IB numbers ports from 1, hw from 0 */
1652 ppd
= dd
->pport
+ (port
- 1);
1653 lstate
= driver_lstate(ppd
);
1655 * it's known that async_update is 0 by this point, but include
1656 * the explicit check for clarity
1658 if (!async_update
&&
1659 (lstate
== IB_PORT_ARMED
|| lstate
== IB_PORT_ACTIVE
)) {
1660 smp
->status
|= IB_SMP_INVALID_FIELD
;
1661 return reply((struct ib_mad_hdr
*)smp
);
1664 set_sc2vlt_tables(dd
, vp
);
1666 return __subn_get_opa_sc_to_vlt(smp
, am
, data
, ibdev
, port
, resp_len
);
1669 static int __subn_get_opa_sc_to_vlnt(struct opa_smp
*smp
, u32 am
, u8
*data
,
1670 struct ib_device
*ibdev
, u8 port
,
1673 u32 n_blocks
= OPA_AM_NPORT(am
);
1674 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1675 struct hfi1_pportdata
*ppd
;
1676 void *vp
= (void *)data
;
1679 if (n_blocks
!= 1) {
1680 smp
->status
|= IB_SMP_INVALID_FIELD
;
1681 return reply((struct ib_mad_hdr
*)smp
);
1684 ppd
= dd
->pport
+ (port
- 1);
1686 size
= fm_get_table(ppd
, FM_TBL_SC2VLNT
, vp
);
1691 return reply((struct ib_mad_hdr
*)smp
);
1694 static int __subn_set_opa_sc_to_vlnt(struct opa_smp
*smp
, u32 am
, u8
*data
,
1695 struct ib_device
*ibdev
, u8 port
,
1698 u32 n_blocks
= OPA_AM_NPORT(am
);
1699 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1700 struct hfi1_pportdata
*ppd
;
1701 void *vp
= (void *)data
;
1704 if (n_blocks
!= 1) {
1705 smp
->status
|= IB_SMP_INVALID_FIELD
;
1706 return reply((struct ib_mad_hdr
*)smp
);
1709 /* IB numbers ports from 1, hw from 0 */
1710 ppd
= dd
->pport
+ (port
- 1);
1711 lstate
= driver_lstate(ppd
);
1712 if (lstate
== IB_PORT_ARMED
|| lstate
== IB_PORT_ACTIVE
) {
1713 smp
->status
|= IB_SMP_INVALID_FIELD
;
1714 return reply((struct ib_mad_hdr
*)smp
);
1717 ppd
= dd
->pport
+ (port
- 1);
1719 fm_set_table(ppd
, FM_TBL_SC2VLNT
, vp
);
1721 return __subn_get_opa_sc_to_vlnt(smp
, am
, data
, ibdev
, port
,
1725 static int __subn_get_opa_psi(struct opa_smp
*smp
, u32 am
, u8
*data
,
1726 struct ib_device
*ibdev
, u8 port
,
1729 u32 nports
= OPA_AM_NPORT(am
);
1730 u32 start_of_sm_config
= OPA_AM_START_SM_CFG(am
);
1732 struct hfi1_ibport
*ibp
;
1733 struct hfi1_pportdata
*ppd
;
1734 struct opa_port_state_info
*psi
= (struct opa_port_state_info
*)data
;
1737 smp
->status
|= IB_SMP_INVALID_FIELD
;
1738 return reply((struct ib_mad_hdr
*)smp
);
1741 ibp
= to_iport(ibdev
, port
);
1742 ppd
= ppd_from_ibp(ibp
);
1744 lstate
= driver_lstate(ppd
);
1746 if (start_of_sm_config
&& (lstate
== IB_PORT_INIT
))
1747 ppd
->is_sm_config_started
= 1;
1749 psi
->port_states
.ledenable_offlinereason
= ppd
->neighbor_normal
<< 4;
1750 psi
->port_states
.ledenable_offlinereason
|=
1751 ppd
->is_sm_config_started
<< 5;
1752 psi
->port_states
.ledenable_offlinereason
|=
1753 ppd
->offline_disabled_reason
;
1755 psi
->port_states
.portphysstate_portstate
=
1756 (hfi1_ibphys_portstate(ppd
) << 4) | (lstate
& 0xf);
1757 psi
->link_width_downgrade_tx_active
=
1758 cpu_to_be16(ppd
->link_width_downgrade_tx_active
);
1759 psi
->link_width_downgrade_rx_active
=
1760 cpu_to_be16(ppd
->link_width_downgrade_rx_active
);
1762 *resp_len
+= sizeof(struct opa_port_state_info
);
1764 return reply((struct ib_mad_hdr
*)smp
);
1767 static int __subn_set_opa_psi(struct opa_smp
*smp
, u32 am
, u8
*data
,
1768 struct ib_device
*ibdev
, u8 port
,
1771 u32 nports
= OPA_AM_NPORT(am
);
1772 u32 start_of_sm_config
= OPA_AM_START_SM_CFG(am
);
1775 struct hfi1_ibport
*ibp
;
1776 struct hfi1_pportdata
*ppd
;
1777 struct opa_port_state_info
*psi
= (struct opa_port_state_info
*)data
;
1778 int ret
, invalid
= 0;
1781 smp
->status
|= IB_SMP_INVALID_FIELD
;
1782 return reply((struct ib_mad_hdr
*)smp
);
1785 ibp
= to_iport(ibdev
, port
);
1786 ppd
= ppd_from_ibp(ibp
);
1788 ls_old
= driver_lstate(ppd
);
1790 ls_new
= port_states_to_logical_state(&psi
->port_states
);
1791 ps_new
= port_states_to_phys_state(&psi
->port_states
);
1793 if (ls_old
== IB_PORT_INIT
) {
1794 if (start_of_sm_config
) {
1795 if (ls_new
== ls_old
|| (ls_new
== IB_PORT_ARMED
))
1796 ppd
->is_sm_config_started
= 1;
1797 } else if (ls_new
== IB_PORT_ARMED
) {
1798 if (ppd
->is_sm_config_started
== 0)
1803 ret
= set_port_states(ppd
, smp
, ls_new
, ps_new
, invalid
);
1808 smp
->status
|= IB_SMP_INVALID_FIELD
;
1810 return __subn_get_opa_psi(smp
, am
, data
, ibdev
, port
, resp_len
);
1813 static int __subn_get_opa_cable_info(struct opa_smp
*smp
, u32 am
, u8
*data
,
1814 struct ib_device
*ibdev
, u8 port
,
1817 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1818 u32 addr
= OPA_AM_CI_ADDR(am
);
1819 u32 len
= OPA_AM_CI_LEN(am
) + 1;
1822 if (dd
->pport
->port_type
!= PORT_TYPE_QSFP
) {
1823 smp
->status
|= IB_SMP_INVALID_FIELD
;
1824 return reply((struct ib_mad_hdr
*)smp
);
1827 #define __CI_PAGE_SIZE BIT(7) /* 128 bytes */
1828 #define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1)
1829 #define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK)
1832 * check that addr is within spec, and
1833 * addr and (addr + len - 1) are on the same "page"
1836 (__CI_PAGE_NUM(addr
) != __CI_PAGE_NUM(addr
+ len
- 1))) {
1837 smp
->status
|= IB_SMP_INVALID_FIELD
;
1838 return reply((struct ib_mad_hdr
*)smp
);
1841 ret
= get_cable_info(dd
, port
, addr
, len
, data
);
1843 if (ret
== -ENODEV
) {
1844 smp
->status
|= IB_SMP_UNSUP_METH_ATTR
;
1845 return reply((struct ib_mad_hdr
*)smp
);
1848 /* The address range for the CableInfo SMA query is wider than the
1849 * memory available on the QSFP cable. We want to return a valid
1850 * response, albeit zeroed out, for address ranges beyond available
1851 * memory but that are within the CableInfo query spec
1853 if (ret
< 0 && ret
!= -ERANGE
) {
1854 smp
->status
|= IB_SMP_INVALID_FIELD
;
1855 return reply((struct ib_mad_hdr
*)smp
);
1861 return reply((struct ib_mad_hdr
*)smp
);
1864 static int __subn_get_opa_bct(struct opa_smp
*smp
, u32 am
, u8
*data
,
1865 struct ib_device
*ibdev
, u8 port
, u32
*resp_len
)
1867 u32 num_ports
= OPA_AM_NPORT(am
);
1868 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1869 struct hfi1_pportdata
*ppd
;
1870 struct buffer_control
*p
= (struct buffer_control
*)data
;
1873 if (num_ports
!= 1) {
1874 smp
->status
|= IB_SMP_INVALID_FIELD
;
1875 return reply((struct ib_mad_hdr
*)smp
);
1878 ppd
= dd
->pport
+ (port
- 1);
1879 size
= fm_get_table(ppd
, FM_TBL_BUFFER_CONTROL
, p
);
1880 trace_bct_get(dd
, p
);
1884 return reply((struct ib_mad_hdr
*)smp
);
1887 static int __subn_set_opa_bct(struct opa_smp
*smp
, u32 am
, u8
*data
,
1888 struct ib_device
*ibdev
, u8 port
, u32
*resp_len
)
1890 u32 num_ports
= OPA_AM_NPORT(am
);
1891 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1892 struct hfi1_pportdata
*ppd
;
1893 struct buffer_control
*p
= (struct buffer_control
*)data
;
1895 if (num_ports
!= 1) {
1896 smp
->status
|= IB_SMP_INVALID_FIELD
;
1897 return reply((struct ib_mad_hdr
*)smp
);
1899 ppd
= dd
->pport
+ (port
- 1);
1900 trace_bct_set(dd
, p
);
1901 if (fm_set_table(ppd
, FM_TBL_BUFFER_CONTROL
, p
) < 0) {
1902 smp
->status
|= IB_SMP_INVALID_FIELD
;
1903 return reply((struct ib_mad_hdr
*)smp
);
1906 return __subn_get_opa_bct(smp
, am
, data
, ibdev
, port
, resp_len
);
1909 static int __subn_get_opa_vl_arb(struct opa_smp
*smp
, u32 am
, u8
*data
,
1910 struct ib_device
*ibdev
, u8 port
,
1913 struct hfi1_pportdata
*ppd
= ppd_from_ibp(to_iport(ibdev
, port
));
1914 u32 num_ports
= OPA_AM_NPORT(am
);
1915 u8 section
= (am
& 0x00ff0000) >> 16;
1919 if (num_ports
!= 1) {
1920 smp
->status
|= IB_SMP_INVALID_FIELD
;
1921 return reply((struct ib_mad_hdr
*)smp
);
1925 case OPA_VLARB_LOW_ELEMENTS
:
1926 size
= fm_get_table(ppd
, FM_TBL_VL_LOW_ARB
, p
);
1928 case OPA_VLARB_HIGH_ELEMENTS
:
1929 size
= fm_get_table(ppd
, FM_TBL_VL_HIGH_ARB
, p
);
1931 case OPA_VLARB_PREEMPT_ELEMENTS
:
1932 size
= fm_get_table(ppd
, FM_TBL_VL_PREEMPT_ELEMS
, p
);
1934 case OPA_VLARB_PREEMPT_MATRIX
:
1935 size
= fm_get_table(ppd
, FM_TBL_VL_PREEMPT_MATRIX
, p
);
1938 pr_warn("OPA SubnGet(VL Arb) AM Invalid : 0x%x\n",
1939 be32_to_cpu(smp
->attr_mod
));
1940 smp
->status
|= IB_SMP_INVALID_FIELD
;
1944 if (size
> 0 && resp_len
)
1947 return reply((struct ib_mad_hdr
*)smp
);
1950 static int __subn_set_opa_vl_arb(struct opa_smp
*smp
, u32 am
, u8
*data
,
1951 struct ib_device
*ibdev
, u8 port
,
1954 struct hfi1_pportdata
*ppd
= ppd_from_ibp(to_iport(ibdev
, port
));
1955 u32 num_ports
= OPA_AM_NPORT(am
);
1956 u8 section
= (am
& 0x00ff0000) >> 16;
1959 if (num_ports
!= 1) {
1960 smp
->status
|= IB_SMP_INVALID_FIELD
;
1961 return reply((struct ib_mad_hdr
*)smp
);
1965 case OPA_VLARB_LOW_ELEMENTS
:
1966 (void)fm_set_table(ppd
, FM_TBL_VL_LOW_ARB
, p
);
1968 case OPA_VLARB_HIGH_ELEMENTS
:
1969 (void)fm_set_table(ppd
, FM_TBL_VL_HIGH_ARB
, p
);
1972 * neither OPA_VLARB_PREEMPT_ELEMENTS, or OPA_VLARB_PREEMPT_MATRIX
1973 * can be changed from the default values
1975 case OPA_VLARB_PREEMPT_ELEMENTS
:
1977 case OPA_VLARB_PREEMPT_MATRIX
:
1978 smp
->status
|= IB_SMP_UNSUP_METH_ATTR
;
1981 pr_warn("OPA SubnSet(VL Arb) AM Invalid : 0x%x\n",
1982 be32_to_cpu(smp
->attr_mod
));
1983 smp
->status
|= IB_SMP_INVALID_FIELD
;
1987 return __subn_get_opa_vl_arb(smp
, am
, data
, ibdev
, port
, resp_len
);
1990 struct opa_pma_mad
{
1991 struct ib_mad_hdr mad_hdr
;
1995 struct opa_class_port_info
{
1999 __be32 cap_mask2_resp_time
;
2001 u8 redirect_gid
[16];
2002 __be32 redirect_tc_fl
;
2003 __be32 redirect_lid
;
2004 __be32 redirect_sl_qp
;
2005 __be32 redirect_qkey
;
2014 __be16 redirect_pkey
;
2020 struct opa_port_status_req
{
2023 __be32 vl_select_mask
;
2026 #define VL_MASK_ALL 0x000080ff
2028 struct opa_port_status_rsp
{
2031 __be32 vl_select_mask
;
2034 __be64 port_xmit_data
;
2035 __be64 port_rcv_data
;
2036 __be64 port_xmit_pkts
;
2037 __be64 port_rcv_pkts
;
2038 __be64 port_multicast_xmit_pkts
;
2039 __be64 port_multicast_rcv_pkts
;
2040 __be64 port_xmit_wait
;
2041 __be64 sw_port_congestion
;
2042 __be64 port_rcv_fecn
;
2043 __be64 port_rcv_becn
;
2044 __be64 port_xmit_time_cong
;
2045 __be64 port_xmit_wasted_bw
;
2046 __be64 port_xmit_wait_data
;
2047 __be64 port_rcv_bubble
;
2048 __be64 port_mark_fecn
;
2049 /* Error counters */
2050 __be64 port_rcv_constraint_errors
;
2051 __be64 port_rcv_switch_relay_errors
;
2052 __be64 port_xmit_discards
;
2053 __be64 port_xmit_constraint_errors
;
2054 __be64 port_rcv_remote_physical_errors
;
2055 __be64 local_link_integrity_errors
;
2056 __be64 port_rcv_errors
;
2057 __be64 excessive_buffer_overruns
;
2058 __be64 fm_config_errors
;
2059 __be32 link_error_recovery
;
2061 u8 uncorrectable_errors
;
2063 u8 link_quality_indicator
; /* 5res, 3bit */
2066 /* per-VL Data counters */
2067 __be64 port_vl_xmit_data
;
2068 __be64 port_vl_rcv_data
;
2069 __be64 port_vl_xmit_pkts
;
2070 __be64 port_vl_rcv_pkts
;
2071 __be64 port_vl_xmit_wait
;
2072 __be64 sw_port_vl_congestion
;
2073 __be64 port_vl_rcv_fecn
;
2074 __be64 port_vl_rcv_becn
;
2075 __be64 port_xmit_time_cong
;
2076 __be64 port_vl_xmit_wasted_bw
;
2077 __be64 port_vl_xmit_wait_data
;
2078 __be64 port_vl_rcv_bubble
;
2079 __be64 port_vl_mark_fecn
;
2080 __be64 port_vl_xmit_discards
;
2081 } vls
[0]; /* real array size defined by # bits set in vl_select_mask */
2084 enum counter_selects
{
2085 CS_PORT_XMIT_DATA
= (1 << 31),
2086 CS_PORT_RCV_DATA
= (1 << 30),
2087 CS_PORT_XMIT_PKTS
= (1 << 29),
2088 CS_PORT_RCV_PKTS
= (1 << 28),
2089 CS_PORT_MCAST_XMIT_PKTS
= (1 << 27),
2090 CS_PORT_MCAST_RCV_PKTS
= (1 << 26),
2091 CS_PORT_XMIT_WAIT
= (1 << 25),
2092 CS_SW_PORT_CONGESTION
= (1 << 24),
2093 CS_PORT_RCV_FECN
= (1 << 23),
2094 CS_PORT_RCV_BECN
= (1 << 22),
2095 CS_PORT_XMIT_TIME_CONG
= (1 << 21),
2096 CS_PORT_XMIT_WASTED_BW
= (1 << 20),
2097 CS_PORT_XMIT_WAIT_DATA
= (1 << 19),
2098 CS_PORT_RCV_BUBBLE
= (1 << 18),
2099 CS_PORT_MARK_FECN
= (1 << 17),
2100 CS_PORT_RCV_CONSTRAINT_ERRORS
= (1 << 16),
2101 CS_PORT_RCV_SWITCH_RELAY_ERRORS
= (1 << 15),
2102 CS_PORT_XMIT_DISCARDS
= (1 << 14),
2103 CS_PORT_XMIT_CONSTRAINT_ERRORS
= (1 << 13),
2104 CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS
= (1 << 12),
2105 CS_LOCAL_LINK_INTEGRITY_ERRORS
= (1 << 11),
2106 CS_PORT_RCV_ERRORS
= (1 << 10),
2107 CS_EXCESSIVE_BUFFER_OVERRUNS
= (1 << 9),
2108 CS_FM_CONFIG_ERRORS
= (1 << 8),
2109 CS_LINK_ERROR_RECOVERY
= (1 << 7),
2110 CS_LINK_DOWNED
= (1 << 6),
2111 CS_UNCORRECTABLE_ERRORS
= (1 << 5),
2114 struct opa_clear_port_status
{
2115 __be64 port_select_mask
[4];
2116 __be32 counter_select_mask
;
2119 struct opa_aggregate
{
2121 __be16 err_reqlength
; /* 1 bit, 8 res, 7 bit */
2126 #define MSK_LLI 0x000000f0
2127 #define MSK_LLI_SFT 4
2128 #define MSK_LER 0x0000000f
2129 #define MSK_LER_SFT 0
2133 /* Request contains first three fields, response contains those plus the rest */
2134 struct opa_port_data_counters_msg
{
2135 __be64 port_select_mask
[4];
2136 __be32 vl_select_mask
;
2139 /* Response fields follow */
2140 struct _port_dctrs
{
2143 __be32 link_quality_indicator
; /* 29res, 3bit */
2146 __be64 port_xmit_data
;
2147 __be64 port_rcv_data
;
2148 __be64 port_xmit_pkts
;
2149 __be64 port_rcv_pkts
;
2150 __be64 port_multicast_xmit_pkts
;
2151 __be64 port_multicast_rcv_pkts
;
2152 __be64 port_xmit_wait
;
2153 __be64 sw_port_congestion
;
2154 __be64 port_rcv_fecn
;
2155 __be64 port_rcv_becn
;
2156 __be64 port_xmit_time_cong
;
2157 __be64 port_xmit_wasted_bw
;
2158 __be64 port_xmit_wait_data
;
2159 __be64 port_rcv_bubble
;
2160 __be64 port_mark_fecn
;
2162 __be64 port_error_counter_summary
;
2163 /* Sum of error counts/port */
2166 /* per-VL Data counters */
2167 __be64 port_vl_xmit_data
;
2168 __be64 port_vl_rcv_data
;
2169 __be64 port_vl_xmit_pkts
;
2170 __be64 port_vl_rcv_pkts
;
2171 __be64 port_vl_xmit_wait
;
2172 __be64 sw_port_vl_congestion
;
2173 __be64 port_vl_rcv_fecn
;
2174 __be64 port_vl_rcv_becn
;
2175 __be64 port_xmit_time_cong
;
2176 __be64 port_vl_xmit_wasted_bw
;
2177 __be64 port_vl_xmit_wait_data
;
2178 __be64 port_vl_rcv_bubble
;
2179 __be64 port_vl_mark_fecn
;
2181 /* array size defined by #bits set in vl_select_mask*/
2182 } port
[1]; /* array size defined by #ports in attribute modifier */
2185 struct opa_port_error_counters64_msg
{
2187 * Request contains first two fields, response contains the
2190 __be64 port_select_mask
[4];
2191 __be32 vl_select_mask
;
2193 /* Response-only fields follow */
2195 struct _port_ectrs
{
2198 __be64 port_rcv_constraint_errors
;
2199 __be64 port_rcv_switch_relay_errors
;
2200 __be64 port_xmit_discards
;
2201 __be64 port_xmit_constraint_errors
;
2202 __be64 port_rcv_remote_physical_errors
;
2203 __be64 local_link_integrity_errors
;
2204 __be64 port_rcv_errors
;
2205 __be64 excessive_buffer_overruns
;
2206 __be64 fm_config_errors
;
2207 __be32 link_error_recovery
;
2209 u8 uncorrectable_errors
;
2212 __be64 port_vl_xmit_discards
;
2214 /* array size defined by #bits set in vl_select_mask */
2215 } port
[1]; /* array size defined by #ports in attribute modifier */
2218 struct opa_port_error_info_msg
{
2219 __be64 port_select_mask
[4];
2220 __be32 error_info_select_mask
;
2226 /* PortRcvErrorInfo */
2232 /* EI1to12 format */
2235 u8 remaining_flit_bits12
;
2239 u8 remaining_flit_bits
;
2243 } __packed port_rcv_ei
;
2245 /* ExcessiveBufferOverrunInfo */
2249 } __packed excessive_buffer_overrun_ei
;
2251 /* PortXmitConstraintErrorInfo */
2257 } __packed port_xmit_constraint_ei
;
2259 /* PortRcvConstraintErrorInfo */
2265 } __packed port_rcv_constraint_ei
;
2267 /* PortRcvSwitchRelayErrorInfo */
2272 } __packed port_rcv_switch_relay_ei
;
2274 /* UncorrectableErrorInfo */
2278 } __packed uncorrectable_ei
;
2280 /* FMConfigErrorInfo */
2284 } __packed fm_config_ei
;
2286 } port
[1]; /* actual array size defined by #ports in attr modifier */
2289 /* opa_port_error_info_msg error_info_select_mask bit definitions */
2290 enum error_info_selects
{
2291 ES_PORT_RCV_ERROR_INFO
= (1 << 31),
2292 ES_EXCESSIVE_BUFFER_OVERRUN_INFO
= (1 << 30),
2293 ES_PORT_XMIT_CONSTRAINT_ERROR_INFO
= (1 << 29),
2294 ES_PORT_RCV_CONSTRAINT_ERROR_INFO
= (1 << 28),
2295 ES_PORT_RCV_SWITCH_RELAY_ERROR_INFO
= (1 << 27),
2296 ES_UNCORRECTABLE_ERROR_INFO
= (1 << 26),
2297 ES_FM_CONFIG_ERROR_INFO
= (1 << 25)
2300 static int pma_get_opa_classportinfo(struct opa_pma_mad
*pmp
,
2301 struct ib_device
*ibdev
, u32
*resp_len
)
2303 struct opa_class_port_info
*p
=
2304 (struct opa_class_port_info
*)pmp
->data
;
2306 memset(pmp
->data
, 0, sizeof(pmp
->data
));
2308 if (pmp
->mad_hdr
.attr_mod
!= 0)
2309 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2311 p
->base_version
= OPA_MGMT_BASE_VERSION
;
2312 p
->class_version
= OPA_SMI_CLASS_VERSION
;
2314 * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec.
2316 p
->cap_mask2_resp_time
= cpu_to_be32(18);
2319 *resp_len
+= sizeof(*p
);
2321 return reply((struct ib_mad_hdr
*)pmp
);
2324 static void a0_portstatus(struct hfi1_pportdata
*ppd
,
2325 struct opa_port_status_rsp
*rsp
, u32 vl_select_mask
)
2327 if (!is_bx(ppd
->dd
)) {
2329 u64 sum_vl_xmit_wait
= 0;
2330 u32 vl_all_mask
= VL_MASK_ALL
;
2332 for_each_set_bit(vl
, (unsigned long *)&(vl_all_mask
),
2333 8 * sizeof(vl_all_mask
)) {
2334 u64 tmp
= sum_vl_xmit_wait
+
2335 read_port_cntr(ppd
, C_TX_WAIT_VL
,
2337 if (tmp
< sum_vl_xmit_wait
) {
2339 sum_vl_xmit_wait
= (u64
)~0;
2342 sum_vl_xmit_wait
= tmp
;
2344 if (be64_to_cpu(rsp
->port_xmit_wait
) > sum_vl_xmit_wait
)
2345 rsp
->port_xmit_wait
= cpu_to_be64(sum_vl_xmit_wait
);
2349 static int pma_get_opa_portstatus(struct opa_pma_mad
*pmp
,
2350 struct ib_device
*ibdev
,
2351 u8 port
, u32
*resp_len
)
2353 struct opa_port_status_req
*req
=
2354 (struct opa_port_status_req
*)pmp
->data
;
2355 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2356 struct opa_port_status_rsp
*rsp
;
2357 u32 vl_select_mask
= be32_to_cpu(req
->vl_select_mask
);
2359 size_t response_data_size
;
2360 u32 nports
= be32_to_cpu(pmp
->mad_hdr
.attr_mod
) >> 24;
2361 u8 port_num
= req
->port_num
;
2362 u8 num_vls
= hweight32(vl_select_mask
);
2363 struct _vls_pctrs
*vlinfo
;
2364 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
2365 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
2369 response_data_size
= sizeof(struct opa_port_status_rsp
) +
2370 num_vls
* sizeof(struct _vls_pctrs
);
2371 if (response_data_size
> sizeof(pmp
->data
)) {
2372 pmp
->mad_hdr
.status
|= OPA_PM_STATUS_REQUEST_TOO_LARGE
;
2373 return reply((struct ib_mad_hdr
*)pmp
);
2376 if (nports
!= 1 || (port_num
&& port_num
!= port
) ||
2377 num_vls
> OPA_MAX_VLS
|| (vl_select_mask
& ~VL_MASK_ALL
)) {
2378 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2379 return reply((struct ib_mad_hdr
*)pmp
);
2382 memset(pmp
->data
, 0, sizeof(pmp
->data
));
2384 rsp
= (struct opa_port_status_rsp
*)pmp
->data
;
2386 rsp
->port_num
= port_num
;
2388 rsp
->port_num
= port
;
2390 rsp
->port_rcv_constraint_errors
=
2391 cpu_to_be64(read_port_cntr(ppd
, C_SW_RCV_CSTR_ERR
,
2394 hfi1_read_link_quality(dd
, &rsp
->link_quality_indicator
);
2396 rsp
->vl_select_mask
= cpu_to_be32(vl_select_mask
);
2397 rsp
->port_xmit_data
= cpu_to_be64(read_dev_cntr(dd
, C_DC_XMIT_FLITS
,
2399 rsp
->port_rcv_data
= cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FLITS
,
2401 rsp
->port_xmit_pkts
= cpu_to_be64(read_dev_cntr(dd
, C_DC_XMIT_PKTS
,
2403 rsp
->port_rcv_pkts
= cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_PKTS
,
2405 rsp
->port_multicast_xmit_pkts
=
2406 cpu_to_be64(read_dev_cntr(dd
, C_DC_MC_XMIT_PKTS
,
2408 rsp
->port_multicast_rcv_pkts
=
2409 cpu_to_be64(read_dev_cntr(dd
, C_DC_MC_RCV_PKTS
,
2411 rsp
->port_xmit_wait
=
2412 cpu_to_be64(read_port_cntr(ppd
, C_TX_WAIT
, CNTR_INVALID_VL
));
2413 rsp
->port_rcv_fecn
=
2414 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FCN
, CNTR_INVALID_VL
));
2415 rsp
->port_rcv_becn
=
2416 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_BCN
, CNTR_INVALID_VL
));
2417 rsp
->port_xmit_discards
=
2418 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_DSCD
,
2420 rsp
->port_xmit_constraint_errors
=
2421 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_CSTR_ERR
,
2423 rsp
->port_rcv_remote_physical_errors
=
2424 cpu_to_be64(read_dev_cntr(dd
, C_DC_RMT_PHY_ERR
,
2426 rsp
->local_link_integrity_errors
=
2427 cpu_to_be64(read_dev_cntr(dd
, C_DC_RX_REPLAY
,
2429 tmp
= read_dev_cntr(dd
, C_DC_SEQ_CRC_CNT
, CNTR_INVALID_VL
);
2430 tmp2
= tmp
+ read_dev_cntr(dd
, C_DC_REINIT_FROM_PEER_CNT
,
2432 if (tmp2
> (u32
)UINT_MAX
|| tmp2
< tmp
) {
2433 /* overflow/wrapped */
2434 rsp
->link_error_recovery
= cpu_to_be32(~0);
2436 rsp
->link_error_recovery
= cpu_to_be32(tmp2
);
2438 rsp
->port_rcv_errors
=
2439 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_ERR
, CNTR_INVALID_VL
));
2440 rsp
->excessive_buffer_overruns
=
2441 cpu_to_be64(read_dev_cntr(dd
, C_RCV_OVF
, CNTR_INVALID_VL
));
2442 rsp
->fm_config_errors
=
2443 cpu_to_be64(read_dev_cntr(dd
, C_DC_FM_CFG_ERR
,
2445 rsp
->link_downed
= cpu_to_be32(read_port_cntr(ppd
, C_SW_LINK_DOWN
,
2448 /* rsp->uncorrectable_errors is 8 bits wide, and it pegs at 0xff */
2449 tmp
= read_dev_cntr(dd
, C_DC_UNC_ERR
, CNTR_INVALID_VL
);
2450 rsp
->uncorrectable_errors
= tmp
< 0x100 ? (tmp
& 0xff) : 0xff;
2452 vlinfo
= &rsp
->vls
[0];
2454 /* The vl_select_mask has been checked above, and we know
2455 * that it contains only entries which represent valid VLs.
2456 * So in the for_each_set_bit() loop below, we don't need
2457 * any additional checks for vl.
2459 for_each_set_bit(vl
, (unsigned long *)&(vl_select_mask
),
2460 8 * sizeof(vl_select_mask
)) {
2461 memset(vlinfo
, 0, sizeof(*vlinfo
));
2463 tmp
= read_dev_cntr(dd
, C_DC_RX_FLIT_VL
, idx_from_vl(vl
));
2464 rsp
->vls
[vfi
].port_vl_rcv_data
= cpu_to_be64(tmp
);
2466 rsp
->vls
[vfi
].port_vl_rcv_pkts
=
2467 cpu_to_be64(read_dev_cntr(dd
, C_DC_RX_PKT_VL
,
2470 rsp
->vls
[vfi
].port_vl_xmit_data
=
2471 cpu_to_be64(read_port_cntr(ppd
, C_TX_FLIT_VL
,
2474 rsp
->vls
[vfi
].port_vl_xmit_pkts
=
2475 cpu_to_be64(read_port_cntr(ppd
, C_TX_PKT_VL
,
2478 rsp
->vls
[vfi
].port_vl_xmit_wait
=
2479 cpu_to_be64(read_port_cntr(ppd
, C_TX_WAIT_VL
,
2482 rsp
->vls
[vfi
].port_vl_rcv_fecn
=
2483 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FCN_VL
,
2486 rsp
->vls
[vfi
].port_vl_rcv_becn
=
2487 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_BCN_VL
,
2490 rsp
->vls
[vfi
].port_vl_xmit_discards
=
2491 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_DSCD_VL
,
2497 a0_portstatus(ppd
, rsp
, vl_select_mask
);
2500 *resp_len
+= response_data_size
;
2502 return reply((struct ib_mad_hdr
*)pmp
);
2505 static u64
get_error_counter_summary(struct ib_device
*ibdev
, u8 port
,
2506 u8 res_lli
, u8 res_ler
)
2508 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2509 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
2510 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
2511 u64 error_counter_summary
= 0, tmp
;
2513 error_counter_summary
+= read_port_cntr(ppd
, C_SW_RCV_CSTR_ERR
,
2515 /* port_rcv_switch_relay_errors is 0 for HFIs */
2516 error_counter_summary
+= read_port_cntr(ppd
, C_SW_XMIT_DSCD
,
2518 error_counter_summary
+= read_port_cntr(ppd
, C_SW_XMIT_CSTR_ERR
,
2520 error_counter_summary
+= read_dev_cntr(dd
, C_DC_RMT_PHY_ERR
,
2522 /* local link integrity must be right-shifted by the lli resolution */
2523 error_counter_summary
+= (read_dev_cntr(dd
, C_DC_RX_REPLAY
,
2524 CNTR_INVALID_VL
) >> res_lli
);
2525 /* link error recovery must b right-shifted by the ler resolution */
2526 tmp
= read_dev_cntr(dd
, C_DC_SEQ_CRC_CNT
, CNTR_INVALID_VL
);
2527 tmp
+= read_dev_cntr(dd
, C_DC_REINIT_FROM_PEER_CNT
, CNTR_INVALID_VL
);
2528 error_counter_summary
+= (tmp
>> res_ler
);
2529 error_counter_summary
+= read_dev_cntr(dd
, C_DC_RCV_ERR
,
2531 error_counter_summary
+= read_dev_cntr(dd
, C_RCV_OVF
, CNTR_INVALID_VL
);
2532 error_counter_summary
+= read_dev_cntr(dd
, C_DC_FM_CFG_ERR
,
2534 /* ppd->link_downed is a 32-bit value */
2535 error_counter_summary
+= read_port_cntr(ppd
, C_SW_LINK_DOWN
,
2537 tmp
= read_dev_cntr(dd
, C_DC_UNC_ERR
, CNTR_INVALID_VL
);
2538 /* this is an 8-bit quantity */
2539 error_counter_summary
+= tmp
< 0x100 ? (tmp
& 0xff) : 0xff;
2541 return error_counter_summary
;
2544 static void a0_datacounters(struct hfi1_pportdata
*ppd
, struct _port_dctrs
*rsp
,
2547 if (!is_bx(ppd
->dd
)) {
2549 u64 sum_vl_xmit_wait
= 0;
2550 u32 vl_all_mask
= VL_MASK_ALL
;
2552 for_each_set_bit(vl
, (unsigned long *)&(vl_all_mask
),
2553 8 * sizeof(vl_all_mask
)) {
2554 u64 tmp
= sum_vl_xmit_wait
+
2555 read_port_cntr(ppd
, C_TX_WAIT_VL
,
2557 if (tmp
< sum_vl_xmit_wait
) {
2559 sum_vl_xmit_wait
= (u64
)~0;
2562 sum_vl_xmit_wait
= tmp
;
2564 if (be64_to_cpu(rsp
->port_xmit_wait
) > sum_vl_xmit_wait
)
2565 rsp
->port_xmit_wait
= cpu_to_be64(sum_vl_xmit_wait
);
2569 static void pma_get_opa_port_dctrs(struct ib_device
*ibdev
,
2570 struct _port_dctrs
*rsp
)
2572 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2574 rsp
->port_xmit_data
= cpu_to_be64(read_dev_cntr(dd
, C_DC_XMIT_FLITS
,
2576 rsp
->port_rcv_data
= cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FLITS
,
2578 rsp
->port_xmit_pkts
= cpu_to_be64(read_dev_cntr(dd
, C_DC_XMIT_PKTS
,
2580 rsp
->port_rcv_pkts
= cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_PKTS
,
2582 rsp
->port_multicast_xmit_pkts
=
2583 cpu_to_be64(read_dev_cntr(dd
, C_DC_MC_XMIT_PKTS
,
2585 rsp
->port_multicast_rcv_pkts
=
2586 cpu_to_be64(read_dev_cntr(dd
, C_DC_MC_RCV_PKTS
,
2590 static int pma_get_opa_datacounters(struct opa_pma_mad
*pmp
,
2591 struct ib_device
*ibdev
,
2592 u8 port
, u32
*resp_len
)
2594 struct opa_port_data_counters_msg
*req
=
2595 (struct opa_port_data_counters_msg
*)pmp
->data
;
2596 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2597 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
2598 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
2599 struct _port_dctrs
*rsp
;
2600 struct _vls_dctrs
*vlinfo
;
2601 size_t response_data_size
;
2605 u8 res_lli
, res_ler
;
2612 num_ports
= be32_to_cpu(pmp
->mad_hdr
.attr_mod
) >> 24;
2613 num_pslm
= hweight64(be64_to_cpu(req
->port_select_mask
[3]));
2614 num_vls
= hweight32(be32_to_cpu(req
->vl_select_mask
));
2615 vl_select_mask
= be32_to_cpu(req
->vl_select_mask
);
2616 res_lli
= (u8
)(be32_to_cpu(req
->resolution
) & MSK_LLI
) >> MSK_LLI_SFT
;
2617 res_lli
= res_lli
? res_lli
+ ADD_LLI
: 0;
2618 res_ler
= (u8
)(be32_to_cpu(req
->resolution
) & MSK_LER
) >> MSK_LER_SFT
;
2619 res_ler
= res_ler
? res_ler
+ ADD_LER
: 0;
2621 if (num_ports
!= 1 || (vl_select_mask
& ~VL_MASK_ALL
)) {
2622 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2623 return reply((struct ib_mad_hdr
*)pmp
);
2627 response_data_size
= sizeof(struct opa_port_data_counters_msg
) +
2628 num_vls
* sizeof(struct _vls_dctrs
);
2630 if (response_data_size
> sizeof(pmp
->data
)) {
2631 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2632 return reply((struct ib_mad_hdr
*)pmp
);
2636 * The bit set in the mask needs to be consistent with the
2637 * port the request came in on.
2639 port_mask
= be64_to_cpu(req
->port_select_mask
[3]);
2640 port_num
= find_first_bit((unsigned long *)&port_mask
,
2643 if (port_num
!= port
) {
2644 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2645 return reply((struct ib_mad_hdr
*)pmp
);
2648 rsp
= &req
->port
[0];
2649 memset(rsp
, 0, sizeof(*rsp
));
2651 rsp
->port_number
= port
;
2653 * Note that link_quality_indicator is a 32 bit quantity in
2654 * 'datacounters' queries (as opposed to 'portinfo' queries,
2655 * where it's a byte).
2657 hfi1_read_link_quality(dd
, &lq
);
2658 rsp
->link_quality_indicator
= cpu_to_be32((u32
)lq
);
2659 pma_get_opa_port_dctrs(ibdev
, rsp
);
2661 rsp
->port_xmit_wait
=
2662 cpu_to_be64(read_port_cntr(ppd
, C_TX_WAIT
, CNTR_INVALID_VL
));
2663 rsp
->port_rcv_fecn
=
2664 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FCN
, CNTR_INVALID_VL
));
2665 rsp
->port_rcv_becn
=
2666 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_BCN
, CNTR_INVALID_VL
));
2667 rsp
->port_error_counter_summary
=
2668 cpu_to_be64(get_error_counter_summary(ibdev
, port
,
2671 vlinfo
= &rsp
->vls
[0];
2673 /* The vl_select_mask has been checked above, and we know
2674 * that it contains only entries which represent valid VLs.
2675 * So in the for_each_set_bit() loop below, we don't need
2676 * any additional checks for vl.
2678 for_each_set_bit(vl
, (unsigned long *)&(vl_select_mask
),
2679 8 * sizeof(req
->vl_select_mask
)) {
2680 memset(vlinfo
, 0, sizeof(*vlinfo
));
2682 rsp
->vls
[vfi
].port_vl_xmit_data
=
2683 cpu_to_be64(read_port_cntr(ppd
, C_TX_FLIT_VL
,
2686 rsp
->vls
[vfi
].port_vl_rcv_data
=
2687 cpu_to_be64(read_dev_cntr(dd
, C_DC_RX_FLIT_VL
,
2690 rsp
->vls
[vfi
].port_vl_xmit_pkts
=
2691 cpu_to_be64(read_port_cntr(ppd
, C_TX_PKT_VL
,
2694 rsp
->vls
[vfi
].port_vl_rcv_pkts
=
2695 cpu_to_be64(read_dev_cntr(dd
, C_DC_RX_PKT_VL
,
2698 rsp
->vls
[vfi
].port_vl_xmit_wait
=
2699 cpu_to_be64(read_port_cntr(ppd
, C_TX_WAIT_VL
,
2702 rsp
->vls
[vfi
].port_vl_rcv_fecn
=
2703 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FCN_VL
,
2705 rsp
->vls
[vfi
].port_vl_rcv_becn
=
2706 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_BCN_VL
,
2709 /* rsp->port_vl_xmit_time_cong is 0 for HFIs */
2710 /* rsp->port_vl_xmit_wasted_bw ??? */
2711 /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ???
2712 * does this differ from rsp->vls[vfi].port_vl_xmit_wait
2714 /*rsp->vls[vfi].port_vl_mark_fecn =
2715 * cpu_to_be64(read_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT
2722 a0_datacounters(ppd
, rsp
, vl_select_mask
);
2725 *resp_len
+= response_data_size
;
2727 return reply((struct ib_mad_hdr
*)pmp
);
2730 static int pma_get_ib_portcounters_ext(struct ib_pma_mad
*pmp
,
2731 struct ib_device
*ibdev
, u8 port
)
2733 struct ib_pma_portcounters_ext
*p
= (struct ib_pma_portcounters_ext
*)
2735 struct _port_dctrs rsp
;
2737 if (pmp
->mad_hdr
.attr_mod
!= 0 || p
->port_select
!= port
) {
2738 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2742 memset(&rsp
, 0, sizeof(rsp
));
2743 pma_get_opa_port_dctrs(ibdev
, &rsp
);
2745 p
->port_xmit_data
= rsp
.port_xmit_data
;
2746 p
->port_rcv_data
= rsp
.port_rcv_data
;
2747 p
->port_xmit_packets
= rsp
.port_xmit_pkts
;
2748 p
->port_rcv_packets
= rsp
.port_rcv_pkts
;
2749 p
->port_unicast_xmit_packets
= 0;
2750 p
->port_unicast_rcv_packets
= 0;
2751 p
->port_multicast_xmit_packets
= rsp
.port_multicast_xmit_pkts
;
2752 p
->port_multicast_rcv_packets
= rsp
.port_multicast_rcv_pkts
;
2755 return reply((struct ib_mad_hdr
*)pmp
);
2758 static void pma_get_opa_port_ectrs(struct ib_device
*ibdev
,
2759 struct _port_ectrs
*rsp
, u8 port
)
2762 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2763 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
2764 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
2766 tmp
= read_dev_cntr(dd
, C_DC_SEQ_CRC_CNT
, CNTR_INVALID_VL
);
2767 tmp2
= tmp
+ read_dev_cntr(dd
, C_DC_REINIT_FROM_PEER_CNT
,
2769 if (tmp2
> (u32
)UINT_MAX
|| tmp2
< tmp
) {
2770 /* overflow/wrapped */
2771 rsp
->link_error_recovery
= cpu_to_be32(~0);
2773 rsp
->link_error_recovery
= cpu_to_be32(tmp2
);
2776 rsp
->link_downed
= cpu_to_be32(read_port_cntr(ppd
, C_SW_LINK_DOWN
,
2778 rsp
->port_rcv_errors
=
2779 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_ERR
, CNTR_INVALID_VL
));
2780 rsp
->port_rcv_remote_physical_errors
=
2781 cpu_to_be64(read_dev_cntr(dd
, C_DC_RMT_PHY_ERR
,
2783 rsp
->port_rcv_switch_relay_errors
= 0;
2784 rsp
->port_xmit_discards
=
2785 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_DSCD
,
2787 rsp
->port_xmit_constraint_errors
=
2788 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_CSTR_ERR
,
2790 rsp
->port_rcv_constraint_errors
=
2791 cpu_to_be64(read_port_cntr(ppd
, C_SW_RCV_CSTR_ERR
,
2793 rsp
->local_link_integrity_errors
=
2794 cpu_to_be64(read_dev_cntr(dd
, C_DC_RX_REPLAY
,
2796 rsp
->excessive_buffer_overruns
=
2797 cpu_to_be64(read_dev_cntr(dd
, C_RCV_OVF
, CNTR_INVALID_VL
));
2800 static int pma_get_opa_porterrors(struct opa_pma_mad
*pmp
,
2801 struct ib_device
*ibdev
,
2802 u8 port
, u32
*resp_len
)
2804 size_t response_data_size
;
2805 struct _port_ectrs
*rsp
;
2807 struct opa_port_error_counters64_msg
*req
;
2808 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2812 struct hfi1_ibport
*ibp
;
2813 struct hfi1_pportdata
*ppd
;
2814 struct _vls_ectrs
*vlinfo
;
2820 req
= (struct opa_port_error_counters64_msg
*)pmp
->data
;
2822 num_ports
= be32_to_cpu(pmp
->mad_hdr
.attr_mod
) >> 24;
2824 num_pslm
= hweight64(be64_to_cpu(req
->port_select_mask
[3]));
2825 num_vls
= hweight32(be32_to_cpu(req
->vl_select_mask
));
2827 if (num_ports
!= 1 || num_ports
!= num_pslm
) {
2828 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2829 return reply((struct ib_mad_hdr
*)pmp
);
2832 response_data_size
= sizeof(struct opa_port_error_counters64_msg
) +
2833 num_vls
* sizeof(struct _vls_ectrs
);
2835 if (response_data_size
> sizeof(pmp
->data
)) {
2836 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2837 return reply((struct ib_mad_hdr
*)pmp
);
2840 * The bit set in the mask needs to be consistent with the
2841 * port the request came in on.
2843 port_mask
= be64_to_cpu(req
->port_select_mask
[3]);
2844 port_num
= find_first_bit((unsigned long *)&port_mask
,
2847 if (port_num
!= port
) {
2848 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2849 return reply((struct ib_mad_hdr
*)pmp
);
2852 rsp
= &req
->port
[0];
2854 ibp
= to_iport(ibdev
, port_num
);
2855 ppd
= ppd_from_ibp(ibp
);
2857 memset(rsp
, 0, sizeof(*rsp
));
2858 rsp
->port_number
= port_num
;
2860 pma_get_opa_port_ectrs(ibdev
, rsp
, port_num
);
2862 rsp
->port_rcv_remote_physical_errors
=
2863 cpu_to_be64(read_dev_cntr(dd
, C_DC_RMT_PHY_ERR
,
2865 rsp
->fm_config_errors
=
2866 cpu_to_be64(read_dev_cntr(dd
, C_DC_FM_CFG_ERR
,
2868 tmp
= read_dev_cntr(dd
, C_DC_UNC_ERR
, CNTR_INVALID_VL
);
2870 rsp
->uncorrectable_errors
= tmp
< 0x100 ? (tmp
& 0xff) : 0xff;
2871 rsp
->port_rcv_errors
=
2872 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_ERR
, CNTR_INVALID_VL
));
2873 vlinfo
= &rsp
->vls
[0];
2875 vl_select_mask
= be32_to_cpu(req
->vl_select_mask
);
2876 for_each_set_bit(vl
, (unsigned long *)&(vl_select_mask
),
2877 8 * sizeof(req
->vl_select_mask
)) {
2878 memset(vlinfo
, 0, sizeof(*vlinfo
));
2879 rsp
->vls
[vfi
].port_vl_xmit_discards
=
2880 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_DSCD_VL
,
2887 *resp_len
+= response_data_size
;
2889 return reply((struct ib_mad_hdr
*)pmp
);
2892 static int pma_get_ib_portcounters(struct ib_pma_mad
*pmp
,
2893 struct ib_device
*ibdev
, u8 port
)
2895 struct ib_pma_portcounters
*p
= (struct ib_pma_portcounters
*)
2897 struct _port_ectrs rsp
;
2898 u64 temp_link_overrun_errors
;
2902 memset(&rsp
, 0, sizeof(rsp
));
2903 pma_get_opa_port_ectrs(ibdev
, &rsp
, port
);
2905 if (pmp
->mad_hdr
.attr_mod
!= 0 || p
->port_select
!= port
) {
2906 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2910 p
->symbol_error_counter
= 0; /* N/A for OPA */
2912 temp_32
= be32_to_cpu(rsp
.link_error_recovery
);
2913 if (temp_32
> 0xFFUL
)
2914 p
->link_error_recovery_counter
= 0xFF;
2916 p
->link_error_recovery_counter
= (u8
)temp_32
;
2918 temp_32
= be32_to_cpu(rsp
.link_downed
);
2919 if (temp_32
> 0xFFUL
)
2920 p
->link_downed_counter
= 0xFF;
2922 p
->link_downed_counter
= (u8
)temp_32
;
2924 temp_64
= be64_to_cpu(rsp
.port_rcv_errors
);
2925 if (temp_64
> 0xFFFFUL
)
2926 p
->port_rcv_errors
= cpu_to_be16(0xFFFF);
2928 p
->port_rcv_errors
= cpu_to_be16((u16
)temp_64
);
2930 temp_64
= be64_to_cpu(rsp
.port_rcv_remote_physical_errors
);
2931 if (temp_64
> 0xFFFFUL
)
2932 p
->port_rcv_remphys_errors
= cpu_to_be16(0xFFFF);
2934 p
->port_rcv_remphys_errors
= cpu_to_be16((u16
)temp_64
);
2936 temp_64
= be64_to_cpu(rsp
.port_rcv_switch_relay_errors
);
2937 p
->port_rcv_switch_relay_errors
= cpu_to_be16((u16
)temp_64
);
2939 temp_64
= be64_to_cpu(rsp
.port_xmit_discards
);
2940 if (temp_64
> 0xFFFFUL
)
2941 p
->port_xmit_discards
= cpu_to_be16(0xFFFF);
2943 p
->port_xmit_discards
= cpu_to_be16((u16
)temp_64
);
2945 temp_64
= be64_to_cpu(rsp
.port_xmit_constraint_errors
);
2946 if (temp_64
> 0xFFUL
)
2947 p
->port_xmit_constraint_errors
= 0xFF;
2949 p
->port_xmit_constraint_errors
= (u8
)temp_64
;
2951 temp_64
= be64_to_cpu(rsp
.port_rcv_constraint_errors
);
2952 if (temp_64
> 0xFFUL
)
2953 p
->port_rcv_constraint_errors
= 0xFFUL
;
2955 p
->port_rcv_constraint_errors
= (u8
)temp_64
;
2957 /* LocalLink: 7:4, BufferOverrun: 3:0 */
2958 temp_64
= be64_to_cpu(rsp
.local_link_integrity_errors
);
2959 if (temp_64
> 0xFUL
)
2962 temp_link_overrun_errors
= temp_64
<< 4;
2964 temp_64
= be64_to_cpu(rsp
.excessive_buffer_overruns
);
2965 if (temp_64
> 0xFUL
)
2967 temp_link_overrun_errors
|= temp_64
;
2969 p
->link_overrun_errors
= (u8
)temp_link_overrun_errors
;
2971 p
->vl15_dropped
= 0; /* N/A for OPA */
2974 return reply((struct ib_mad_hdr
*)pmp
);
2977 static int pma_get_opa_errorinfo(struct opa_pma_mad
*pmp
,
2978 struct ib_device
*ibdev
,
2979 u8 port
, u32
*resp_len
)
2981 size_t response_data_size
;
2982 struct _port_ei
*rsp
;
2983 struct opa_port_error_info_msg
*req
;
2984 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2991 req
= (struct opa_port_error_info_msg
*)pmp
->data
;
2992 rsp
= &req
->port
[0];
2994 num_ports
= OPA_AM_NPORT(be32_to_cpu(pmp
->mad_hdr
.attr_mod
));
2995 num_pslm
= hweight64(be64_to_cpu(req
->port_select_mask
[3]));
2997 memset(rsp
, 0, sizeof(*rsp
));
2999 if (num_ports
!= 1 || num_ports
!= num_pslm
) {
3000 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3001 return reply((struct ib_mad_hdr
*)pmp
);
3005 response_data_size
= sizeof(struct opa_port_error_info_msg
);
3007 if (response_data_size
> sizeof(pmp
->data
)) {
3008 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3009 return reply((struct ib_mad_hdr
*)pmp
);
3013 * The bit set in the mask needs to be consistent with the port
3014 * the request came in on.
3016 port_mask
= be64_to_cpu(req
->port_select_mask
[3]);
3017 port_num
= find_first_bit((unsigned long *)&port_mask
,
3020 if (port_num
!= port
) {
3021 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3022 return reply((struct ib_mad_hdr
*)pmp
);
3025 /* PortRcvErrorInfo */
3026 rsp
->port_rcv_ei
.status_and_code
=
3027 dd
->err_info_rcvport
.status_and_code
;
3028 memcpy(&rsp
->port_rcv_ei
.ei
.ei1to12
.packet_flit1
,
3029 &dd
->err_info_rcvport
.packet_flit1
, sizeof(u64
));
3030 memcpy(&rsp
->port_rcv_ei
.ei
.ei1to12
.packet_flit2
,
3031 &dd
->err_info_rcvport
.packet_flit2
, sizeof(u64
));
3033 /* ExcessiverBufferOverrunInfo */
3034 reg
= read_csr(dd
, RCV_ERR_INFO
);
3035 if (reg
& RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK
) {
3037 * if the RcvExcessBufferOverrun bit is set, save SC of
3038 * first pkt that encountered an excess buffer overrun
3042 tmp
&= RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SC_SMASK
;
3044 rsp
->excessive_buffer_overrun_ei
.status_and_sc
= tmp
;
3045 /* set the status bit */
3046 rsp
->excessive_buffer_overrun_ei
.status_and_sc
|= 0x80;
3049 rsp
->port_xmit_constraint_ei
.status
=
3050 dd
->err_info_xmit_constraint
.status
;
3051 rsp
->port_xmit_constraint_ei
.pkey
=
3052 cpu_to_be16(dd
->err_info_xmit_constraint
.pkey
);
3053 rsp
->port_xmit_constraint_ei
.slid
=
3054 cpu_to_be32(dd
->err_info_xmit_constraint
.slid
);
3056 rsp
->port_rcv_constraint_ei
.status
=
3057 dd
->err_info_rcv_constraint
.status
;
3058 rsp
->port_rcv_constraint_ei
.pkey
=
3059 cpu_to_be16(dd
->err_info_rcv_constraint
.pkey
);
3060 rsp
->port_rcv_constraint_ei
.slid
=
3061 cpu_to_be32(dd
->err_info_rcv_constraint
.slid
);
3063 /* UncorrectableErrorInfo */
3064 rsp
->uncorrectable_ei
.status_and_code
= dd
->err_info_uncorrectable
;
3066 /* FMConfigErrorInfo */
3067 rsp
->fm_config_ei
.status_and_code
= dd
->err_info_fmconfig
;
3070 *resp_len
+= response_data_size
;
3072 return reply((struct ib_mad_hdr
*)pmp
);
3075 static int pma_set_opa_portstatus(struct opa_pma_mad
*pmp
,
3076 struct ib_device
*ibdev
,
3077 u8 port
, u32
*resp_len
)
3079 struct opa_clear_port_status
*req
=
3080 (struct opa_clear_port_status
*)pmp
->data
;
3081 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
3082 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3083 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3084 u32 nports
= be32_to_cpu(pmp
->mad_hdr
.attr_mod
) >> 24;
3085 u64 portn
= be64_to_cpu(req
->port_select_mask
[3]);
3086 u32 counter_select
= be32_to_cpu(req
->counter_select_mask
);
3087 u32 vl_select_mask
= VL_MASK_ALL
; /* clear all per-vl cnts */
3090 if ((nports
!= 1) || (portn
!= 1 << port
)) {
3091 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3092 return reply((struct ib_mad_hdr
*)pmp
);
3095 * only counters returned by pma_get_opa_portstatus() are
3096 * handled, so when pma_get_opa_portstatus() gets a fix,
3097 * the corresponding change should be made here as well.
3100 if (counter_select
& CS_PORT_XMIT_DATA
)
3101 write_dev_cntr(dd
, C_DC_XMIT_FLITS
, CNTR_INVALID_VL
, 0);
3103 if (counter_select
& CS_PORT_RCV_DATA
)
3104 write_dev_cntr(dd
, C_DC_RCV_FLITS
, CNTR_INVALID_VL
, 0);
3106 if (counter_select
& CS_PORT_XMIT_PKTS
)
3107 write_dev_cntr(dd
, C_DC_XMIT_PKTS
, CNTR_INVALID_VL
, 0);
3109 if (counter_select
& CS_PORT_RCV_PKTS
)
3110 write_dev_cntr(dd
, C_DC_RCV_PKTS
, CNTR_INVALID_VL
, 0);
3112 if (counter_select
& CS_PORT_MCAST_XMIT_PKTS
)
3113 write_dev_cntr(dd
, C_DC_MC_XMIT_PKTS
, CNTR_INVALID_VL
, 0);
3115 if (counter_select
& CS_PORT_MCAST_RCV_PKTS
)
3116 write_dev_cntr(dd
, C_DC_MC_RCV_PKTS
, CNTR_INVALID_VL
, 0);
3118 if (counter_select
& CS_PORT_XMIT_WAIT
)
3119 write_port_cntr(ppd
, C_TX_WAIT
, CNTR_INVALID_VL
, 0);
3121 /* ignore cs_sw_portCongestion for HFIs */
3123 if (counter_select
& CS_PORT_RCV_FECN
)
3124 write_dev_cntr(dd
, C_DC_RCV_FCN
, CNTR_INVALID_VL
, 0);
3126 if (counter_select
& CS_PORT_RCV_BECN
)
3127 write_dev_cntr(dd
, C_DC_RCV_BCN
, CNTR_INVALID_VL
, 0);
3129 /* ignore cs_port_xmit_time_cong for HFIs */
3130 /* ignore cs_port_xmit_wasted_bw for now */
3131 /* ignore cs_port_xmit_wait_data for now */
3132 if (counter_select
& CS_PORT_RCV_BUBBLE
)
3133 write_dev_cntr(dd
, C_DC_RCV_BBL
, CNTR_INVALID_VL
, 0);
3135 /* Only applicable for switch */
3136 /* if (counter_select & CS_PORT_MARK_FECN)
3137 * write_csr(dd, DCC_PRF_PORT_MARK_FECN_CNT, 0);
3140 if (counter_select
& CS_PORT_RCV_CONSTRAINT_ERRORS
)
3141 write_port_cntr(ppd
, C_SW_RCV_CSTR_ERR
, CNTR_INVALID_VL
, 0);
3143 /* ignore cs_port_rcv_switch_relay_errors for HFIs */
3144 if (counter_select
& CS_PORT_XMIT_DISCARDS
)
3145 write_port_cntr(ppd
, C_SW_XMIT_DSCD
, CNTR_INVALID_VL
, 0);
3147 if (counter_select
& CS_PORT_XMIT_CONSTRAINT_ERRORS
)
3148 write_port_cntr(ppd
, C_SW_XMIT_CSTR_ERR
, CNTR_INVALID_VL
, 0);
3150 if (counter_select
& CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS
)
3151 write_dev_cntr(dd
, C_DC_RMT_PHY_ERR
, CNTR_INVALID_VL
, 0);
3153 if (counter_select
& CS_LOCAL_LINK_INTEGRITY_ERRORS
)
3154 write_dev_cntr(dd
, C_DC_RX_REPLAY
, CNTR_INVALID_VL
, 0);
3156 if (counter_select
& CS_LINK_ERROR_RECOVERY
) {
3157 write_dev_cntr(dd
, C_DC_SEQ_CRC_CNT
, CNTR_INVALID_VL
, 0);
3158 write_dev_cntr(dd
, C_DC_REINIT_FROM_PEER_CNT
,
3159 CNTR_INVALID_VL
, 0);
3162 if (counter_select
& CS_PORT_RCV_ERRORS
)
3163 write_dev_cntr(dd
, C_DC_RCV_ERR
, CNTR_INVALID_VL
, 0);
3165 if (counter_select
& CS_EXCESSIVE_BUFFER_OVERRUNS
) {
3166 write_dev_cntr(dd
, C_RCV_OVF
, CNTR_INVALID_VL
, 0);
3167 dd
->rcv_ovfl_cnt
= 0;
3170 if (counter_select
& CS_FM_CONFIG_ERRORS
)
3171 write_dev_cntr(dd
, C_DC_FM_CFG_ERR
, CNTR_INVALID_VL
, 0);
3173 if (counter_select
& CS_LINK_DOWNED
)
3174 write_port_cntr(ppd
, C_SW_LINK_DOWN
, CNTR_INVALID_VL
, 0);
3176 if (counter_select
& CS_UNCORRECTABLE_ERRORS
)
3177 write_dev_cntr(dd
, C_DC_UNC_ERR
, CNTR_INVALID_VL
, 0);
3179 for_each_set_bit(vl
, (unsigned long *)&(vl_select_mask
),
3180 8 * sizeof(vl_select_mask
)) {
3181 if (counter_select
& CS_PORT_XMIT_DATA
)
3182 write_port_cntr(ppd
, C_TX_FLIT_VL
, idx_from_vl(vl
), 0);
3184 if (counter_select
& CS_PORT_RCV_DATA
)
3185 write_dev_cntr(dd
, C_DC_RX_FLIT_VL
, idx_from_vl(vl
), 0);
3187 if (counter_select
& CS_PORT_XMIT_PKTS
)
3188 write_port_cntr(ppd
, C_TX_PKT_VL
, idx_from_vl(vl
), 0);
3190 if (counter_select
& CS_PORT_RCV_PKTS
)
3191 write_dev_cntr(dd
, C_DC_RX_PKT_VL
, idx_from_vl(vl
), 0);
3193 if (counter_select
& CS_PORT_XMIT_WAIT
)
3194 write_port_cntr(ppd
, C_TX_WAIT_VL
, idx_from_vl(vl
), 0);
3196 /* sw_port_vl_congestion is 0 for HFIs */
3197 if (counter_select
& CS_PORT_RCV_FECN
)
3198 write_dev_cntr(dd
, C_DC_RCV_FCN_VL
, idx_from_vl(vl
), 0);
3200 if (counter_select
& CS_PORT_RCV_BECN
)
3201 write_dev_cntr(dd
, C_DC_RCV_BCN_VL
, idx_from_vl(vl
), 0);
3203 /* port_vl_xmit_time_cong is 0 for HFIs */
3204 /* port_vl_xmit_wasted_bw ??? */
3205 /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ??? */
3206 if (counter_select
& CS_PORT_RCV_BUBBLE
)
3207 write_dev_cntr(dd
, C_DC_RCV_BBL_VL
, idx_from_vl(vl
), 0);
3209 /* if (counter_select & CS_PORT_MARK_FECN)
3210 * write_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT + offset, 0);
3212 if (counter_select
& C_SW_XMIT_DSCD_VL
)
3213 write_port_cntr(ppd
, C_SW_XMIT_DSCD_VL
,
3214 idx_from_vl(vl
), 0);
3218 *resp_len
+= sizeof(*req
);
3220 return reply((struct ib_mad_hdr
*)pmp
);
3223 static int pma_set_opa_errorinfo(struct opa_pma_mad
*pmp
,
3224 struct ib_device
*ibdev
,
3225 u8 port
, u32
*resp_len
)
3227 struct _port_ei
*rsp
;
3228 struct opa_port_error_info_msg
*req
;
3229 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
3234 u32 error_info_select
;
3236 req
= (struct opa_port_error_info_msg
*)pmp
->data
;
3237 rsp
= &req
->port
[0];
3239 num_ports
= OPA_AM_NPORT(be32_to_cpu(pmp
->mad_hdr
.attr_mod
));
3240 num_pslm
= hweight64(be64_to_cpu(req
->port_select_mask
[3]));
3242 memset(rsp
, 0, sizeof(*rsp
));
3244 if (num_ports
!= 1 || num_ports
!= num_pslm
) {
3245 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3246 return reply((struct ib_mad_hdr
*)pmp
);
3250 * The bit set in the mask needs to be consistent with the port
3251 * the request came in on.
3253 port_mask
= be64_to_cpu(req
->port_select_mask
[3]);
3254 port_num
= find_first_bit((unsigned long *)&port_mask
,
3257 if (port_num
!= port
) {
3258 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3259 return reply((struct ib_mad_hdr
*)pmp
);
3262 error_info_select
= be32_to_cpu(req
->error_info_select_mask
);
3264 /* PortRcvErrorInfo */
3265 if (error_info_select
& ES_PORT_RCV_ERROR_INFO
)
3266 /* turn off status bit */
3267 dd
->err_info_rcvport
.status_and_code
&= ~OPA_EI_STATUS_SMASK
;
3269 /* ExcessiverBufferOverrunInfo */
3270 if (error_info_select
& ES_EXCESSIVE_BUFFER_OVERRUN_INFO
)
3272 * status bit is essentially kept in the h/w - bit 5 of
3275 write_csr(dd
, RCV_ERR_INFO
,
3276 RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK
);
3278 if (error_info_select
& ES_PORT_XMIT_CONSTRAINT_ERROR_INFO
)
3279 dd
->err_info_xmit_constraint
.status
&= ~OPA_EI_STATUS_SMASK
;
3281 if (error_info_select
& ES_PORT_RCV_CONSTRAINT_ERROR_INFO
)
3282 dd
->err_info_rcv_constraint
.status
&= ~OPA_EI_STATUS_SMASK
;
3284 /* UncorrectableErrorInfo */
3285 if (error_info_select
& ES_UNCORRECTABLE_ERROR_INFO
)
3286 /* turn off status bit */
3287 dd
->err_info_uncorrectable
&= ~OPA_EI_STATUS_SMASK
;
3289 /* FMConfigErrorInfo */
3290 if (error_info_select
& ES_FM_CONFIG_ERROR_INFO
)
3291 /* turn off status bit */
3292 dd
->err_info_fmconfig
&= ~OPA_EI_STATUS_SMASK
;
3295 *resp_len
+= sizeof(*req
);
3297 return reply((struct ib_mad_hdr
*)pmp
);
3300 struct opa_congestion_info_attr
{
3301 __be16 congestion_info
;
3302 u8 control_table_cap
; /* Multiple of 64 entry unit CCTs */
3303 u8 congestion_log_length
;
3306 static int __subn_get_opa_cong_info(struct opa_smp
*smp
, u32 am
, u8
*data
,
3307 struct ib_device
*ibdev
, u8 port
,
3310 struct opa_congestion_info_attr
*p
=
3311 (struct opa_congestion_info_attr
*)data
;
3312 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3313 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3315 p
->congestion_info
= 0;
3316 p
->control_table_cap
= ppd
->cc_max_table_entries
;
3317 p
->congestion_log_length
= OPA_CONG_LOG_ELEMS
;
3320 *resp_len
+= sizeof(*p
);
3322 return reply((struct ib_mad_hdr
*)smp
);
3325 static int __subn_get_opa_cong_setting(struct opa_smp
*smp
, u32 am
,
3326 u8
*data
, struct ib_device
*ibdev
,
3327 u8 port
, u32
*resp_len
)
3330 struct opa_congestion_setting_attr
*p
=
3331 (struct opa_congestion_setting_attr
*)data
;
3332 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3333 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3334 struct opa_congestion_setting_entry_shadow
*entries
;
3335 struct cc_state
*cc_state
;
3339 cc_state
= get_cc_state(ppd
);
3343 return reply((struct ib_mad_hdr
*)smp
);
3346 entries
= cc_state
->cong_setting
.entries
;
3347 p
->port_control
= cpu_to_be16(cc_state
->cong_setting
.port_control
);
3348 p
->control_map
= cpu_to_be32(cc_state
->cong_setting
.control_map
);
3349 for (i
= 0; i
< OPA_MAX_SLS
; i
++) {
3350 p
->entries
[i
].ccti_increase
= entries
[i
].ccti_increase
;
3351 p
->entries
[i
].ccti_timer
= cpu_to_be16(entries
[i
].ccti_timer
);
3352 p
->entries
[i
].trigger_threshold
=
3353 entries
[i
].trigger_threshold
;
3354 p
->entries
[i
].ccti_min
= entries
[i
].ccti_min
;
3360 *resp_len
+= sizeof(*p
);
3362 return reply((struct ib_mad_hdr
*)smp
);
3366 * Apply congestion control information stored in the ppd to the
3369 static void apply_cc_state(struct hfi1_pportdata
*ppd
)
3371 struct cc_state
*old_cc_state
, *new_cc_state
;
3373 new_cc_state
= kzalloc(sizeof(*new_cc_state
), GFP_KERNEL
);
3378 * Hold the lock for updating *and* to prevent ppd information
3379 * from changing during the update.
3381 spin_lock(&ppd
->cc_state_lock
);
3383 old_cc_state
= get_cc_state_protected(ppd
);
3384 if (!old_cc_state
) {
3385 /* never active, or shutting down */
3386 spin_unlock(&ppd
->cc_state_lock
);
3387 kfree(new_cc_state
);
3391 *new_cc_state
= *old_cc_state
;
3393 new_cc_state
->cct
.ccti_limit
= ppd
->total_cct_entry
- 1;
3394 memcpy(new_cc_state
->cct
.entries
, ppd
->ccti_entries
,
3395 ppd
->total_cct_entry
* sizeof(struct ib_cc_table_entry
));
3397 new_cc_state
->cong_setting
.port_control
= IB_CC_CCS_PC_SL_BASED
;
3398 new_cc_state
->cong_setting
.control_map
= ppd
->cc_sl_control_map
;
3399 memcpy(new_cc_state
->cong_setting
.entries
, ppd
->congestion_entries
,
3400 OPA_MAX_SLS
* sizeof(struct opa_congestion_setting_entry
));
3402 rcu_assign_pointer(ppd
->cc_state
, new_cc_state
);
3404 spin_unlock(&ppd
->cc_state_lock
);
3406 kfree_rcu(old_cc_state
, rcu
);
3409 static int __subn_set_opa_cong_setting(struct opa_smp
*smp
, u32 am
, u8
*data
,
3410 struct ib_device
*ibdev
, u8 port
,
3413 struct opa_congestion_setting_attr
*p
=
3414 (struct opa_congestion_setting_attr
*)data
;
3415 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3416 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3417 struct opa_congestion_setting_entry_shadow
*entries
;
3421 * Save details from packet into the ppd. Hold the cc_state_lock so
3422 * our information is consistent with anyone trying to apply the state.
3424 spin_lock(&ppd
->cc_state_lock
);
3425 ppd
->cc_sl_control_map
= be32_to_cpu(p
->control_map
);
3427 entries
= ppd
->congestion_entries
;
3428 for (i
= 0; i
< OPA_MAX_SLS
; i
++) {
3429 entries
[i
].ccti_increase
= p
->entries
[i
].ccti_increase
;
3430 entries
[i
].ccti_timer
= be16_to_cpu(p
->entries
[i
].ccti_timer
);
3431 entries
[i
].trigger_threshold
=
3432 p
->entries
[i
].trigger_threshold
;
3433 entries
[i
].ccti_min
= p
->entries
[i
].ccti_min
;
3435 spin_unlock(&ppd
->cc_state_lock
);
3437 /* now apply the information */
3438 apply_cc_state(ppd
);
3440 return __subn_get_opa_cong_setting(smp
, am
, data
, ibdev
, port
,
3444 static int __subn_get_opa_hfi1_cong_log(struct opa_smp
*smp
, u32 am
,
3445 u8
*data
, struct ib_device
*ibdev
,
3446 u8 port
, u32
*resp_len
)
3448 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3449 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3450 struct opa_hfi1_cong_log
*cong_log
= (struct opa_hfi1_cong_log
*)data
;
3455 smp
->status
|= IB_SMP_INVALID_FIELD
;
3456 return reply((struct ib_mad_hdr
*)smp
);
3459 spin_lock_irq(&ppd
->cc_log_lock
);
3461 cong_log
->log_type
= OPA_CC_LOG_TYPE_HFI
;
3462 cong_log
->congestion_flags
= 0;
3463 cong_log
->threshold_event_counter
=
3464 cpu_to_be16(ppd
->threshold_event_counter
);
3465 memcpy(cong_log
->threshold_cong_event_map
,
3466 ppd
->threshold_cong_event_map
,
3467 sizeof(cong_log
->threshold_cong_event_map
));
3468 /* keep timestamp in units of 1.024 usec */
3469 ts
= ktime_to_ns(ktime_get()) / 1024;
3470 cong_log
->current_time_stamp
= cpu_to_be32(ts
);
3471 for (i
= 0; i
< OPA_CONG_LOG_ELEMS
; i
++) {
3472 struct opa_hfi1_cong_log_event_internal
*cce
=
3473 &ppd
->cc_events
[ppd
->cc_mad_idx
++];
3474 if (ppd
->cc_mad_idx
== OPA_CONG_LOG_ELEMS
)
3475 ppd
->cc_mad_idx
= 0;
3477 * Entries which are older than twice the time
3478 * required to wrap the counter are supposed to
3479 * be zeroed (CA10-49 IBTA, release 1.2.1, V1).
3481 if ((u64
)(ts
- cce
->timestamp
) > (2 * UINT_MAX
))
3483 memcpy(cong_log
->events
[i
].local_qp_cn_entry
, &cce
->lqpn
, 3);
3484 memcpy(cong_log
->events
[i
].remote_qp_number_cn_entry
,
3486 cong_log
->events
[i
].sl_svc_type_cn_entry
=
3487 ((cce
->sl
& 0x1f) << 3) | (cce
->svc_type
& 0x7);
3488 cong_log
->events
[i
].remote_lid_cn_entry
=
3489 cpu_to_be32(cce
->rlid
);
3490 cong_log
->events
[i
].timestamp_cn_entry
=
3491 cpu_to_be32(cce
->timestamp
);
3495 * Reset threshold_cong_event_map, and threshold_event_counter
3496 * to 0 when log is read.
3498 memset(ppd
->threshold_cong_event_map
, 0x0,
3499 sizeof(ppd
->threshold_cong_event_map
));
3500 ppd
->threshold_event_counter
= 0;
3502 spin_unlock_irq(&ppd
->cc_log_lock
);
3505 *resp_len
+= sizeof(struct opa_hfi1_cong_log
);
3507 return reply((struct ib_mad_hdr
*)smp
);
3510 static int __subn_get_opa_cc_table(struct opa_smp
*smp
, u32 am
, u8
*data
,
3511 struct ib_device
*ibdev
, u8 port
,
3514 struct ib_cc_table_attr
*cc_table_attr
=
3515 (struct ib_cc_table_attr
*)data
;
3516 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3517 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3518 u32 start_block
= OPA_AM_START_BLK(am
);
3519 u32 n_blocks
= OPA_AM_NBLK(am
);
3520 struct ib_cc_table_entry_shadow
*entries
;
3523 struct cc_state
*cc_state
;
3525 /* sanity check n_blocks, start_block */
3526 if (n_blocks
== 0 ||
3527 start_block
+ n_blocks
> ppd
->cc_max_table_entries
) {
3528 smp
->status
|= IB_SMP_INVALID_FIELD
;
3529 return reply((struct ib_mad_hdr
*)smp
);
3534 cc_state
= get_cc_state(ppd
);
3538 return reply((struct ib_mad_hdr
*)smp
);
3541 sentry
= start_block
* IB_CCT_ENTRIES
;
3542 eentry
= sentry
+ (IB_CCT_ENTRIES
* n_blocks
);
3544 cc_table_attr
->ccti_limit
= cpu_to_be16(cc_state
->cct
.ccti_limit
);
3546 entries
= cc_state
->cct
.entries
;
3548 /* return n_blocks, though the last block may not be full */
3549 for (j
= 0, i
= sentry
; i
< eentry
; j
++, i
++)
3550 cc_table_attr
->ccti_entries
[j
].entry
=
3551 cpu_to_be16(entries
[i
].entry
);
3556 *resp_len
+= sizeof(u16
) * (IB_CCT_ENTRIES
* n_blocks
+ 1);
3558 return reply((struct ib_mad_hdr
*)smp
);
3561 static int __subn_set_opa_cc_table(struct opa_smp
*smp
, u32 am
, u8
*data
,
3562 struct ib_device
*ibdev
, u8 port
,
3565 struct ib_cc_table_attr
*p
= (struct ib_cc_table_attr
*)data
;
3566 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3567 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3568 u32 start_block
= OPA_AM_START_BLK(am
);
3569 u32 n_blocks
= OPA_AM_NBLK(am
);
3570 struct ib_cc_table_entry_shadow
*entries
;
3575 /* sanity check n_blocks, start_block */
3576 if (n_blocks
== 0 ||
3577 start_block
+ n_blocks
> ppd
->cc_max_table_entries
) {
3578 smp
->status
|= IB_SMP_INVALID_FIELD
;
3579 return reply((struct ib_mad_hdr
*)smp
);
3582 sentry
= start_block
* IB_CCT_ENTRIES
;
3583 eentry
= sentry
+ ((n_blocks
- 1) * IB_CCT_ENTRIES
) +
3584 (be16_to_cpu(p
->ccti_limit
)) % IB_CCT_ENTRIES
+ 1;
3586 /* sanity check ccti_limit */
3587 ccti_limit
= be16_to_cpu(p
->ccti_limit
);
3588 if (ccti_limit
+ 1 > eentry
) {
3589 smp
->status
|= IB_SMP_INVALID_FIELD
;
3590 return reply((struct ib_mad_hdr
*)smp
);
3594 * Save details from packet into the ppd. Hold the cc_state_lock so
3595 * our information is consistent with anyone trying to apply the state.
3597 spin_lock(&ppd
->cc_state_lock
);
3598 ppd
->total_cct_entry
= ccti_limit
+ 1;
3599 entries
= ppd
->ccti_entries
;
3600 for (j
= 0, i
= sentry
; i
< eentry
; j
++, i
++)
3601 entries
[i
].entry
= be16_to_cpu(p
->ccti_entries
[j
].entry
);
3602 spin_unlock(&ppd
->cc_state_lock
);
3604 /* now apply the information */
3605 apply_cc_state(ppd
);
3607 return __subn_get_opa_cc_table(smp
, am
, data
, ibdev
, port
, resp_len
);
3610 struct opa_led_info
{
3611 __be32 rsvd_led_mask
;
3615 #define OPA_LED_SHIFT 31
3616 #define OPA_LED_MASK BIT(OPA_LED_SHIFT)
3618 static int __subn_get_opa_led_info(struct opa_smp
*smp
, u32 am
, u8
*data
,
3619 struct ib_device
*ibdev
, u8 port
,
3622 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
3623 struct hfi1_pportdata
*ppd
= dd
->pport
;
3624 struct opa_led_info
*p
= (struct opa_led_info
*)data
;
3625 u32 nport
= OPA_AM_NPORT(am
);
3626 u32 is_beaconing_active
;
3629 smp
->status
|= IB_SMP_INVALID_FIELD
;
3630 return reply((struct ib_mad_hdr
*)smp
);
3634 * This pairs with the memory barrier in hfi1_start_led_override to
3635 * ensure that we read the correct state of LED beaconing represented
3636 * by led_override_timer_active
3639 is_beaconing_active
= !!atomic_read(&ppd
->led_override_timer_active
);
3640 p
->rsvd_led_mask
= cpu_to_be32(is_beaconing_active
<< OPA_LED_SHIFT
);
3643 *resp_len
+= sizeof(struct opa_led_info
);
3645 return reply((struct ib_mad_hdr
*)smp
);
3648 static int __subn_set_opa_led_info(struct opa_smp
*smp
, u32 am
, u8
*data
,
3649 struct ib_device
*ibdev
, u8 port
,
3652 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
3653 struct opa_led_info
*p
= (struct opa_led_info
*)data
;
3654 u32 nport
= OPA_AM_NPORT(am
);
3655 int on
= !!(be32_to_cpu(p
->rsvd_led_mask
) & OPA_LED_MASK
);
3658 smp
->status
|= IB_SMP_INVALID_FIELD
;
3659 return reply((struct ib_mad_hdr
*)smp
);
3663 hfi1_start_led_override(dd
->pport
, 2000, 1500);
3665 shutdown_led_override(dd
->pport
);
3667 return __subn_get_opa_led_info(smp
, am
, data
, ibdev
, port
, resp_len
);
3670 static int subn_get_opa_sma(__be16 attr_id
, struct opa_smp
*smp
, u32 am
,
3671 u8
*data
, struct ib_device
*ibdev
, u8 port
,
3675 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3678 case IB_SMP_ATTR_NODE_DESC
:
3679 ret
= __subn_get_opa_nodedesc(smp
, am
, data
, ibdev
, port
,
3682 case IB_SMP_ATTR_NODE_INFO
:
3683 ret
= __subn_get_opa_nodeinfo(smp
, am
, data
, ibdev
, port
,
3686 case IB_SMP_ATTR_PORT_INFO
:
3687 ret
= __subn_get_opa_portinfo(smp
, am
, data
, ibdev
, port
,
3690 case IB_SMP_ATTR_PKEY_TABLE
:
3691 ret
= __subn_get_opa_pkeytable(smp
, am
, data
, ibdev
, port
,
3694 case OPA_ATTRIB_ID_SL_TO_SC_MAP
:
3695 ret
= __subn_get_opa_sl_to_sc(smp
, am
, data
, ibdev
, port
,
3698 case OPA_ATTRIB_ID_SC_TO_SL_MAP
:
3699 ret
= __subn_get_opa_sc_to_sl(smp
, am
, data
, ibdev
, port
,
3702 case OPA_ATTRIB_ID_SC_TO_VLT_MAP
:
3703 ret
= __subn_get_opa_sc_to_vlt(smp
, am
, data
, ibdev
, port
,
3706 case OPA_ATTRIB_ID_SC_TO_VLNT_MAP
:
3707 ret
= __subn_get_opa_sc_to_vlnt(smp
, am
, data
, ibdev
, port
,
3710 case OPA_ATTRIB_ID_PORT_STATE_INFO
:
3711 ret
= __subn_get_opa_psi(smp
, am
, data
, ibdev
, port
,
3714 case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE
:
3715 ret
= __subn_get_opa_bct(smp
, am
, data
, ibdev
, port
,
3718 case OPA_ATTRIB_ID_CABLE_INFO
:
3719 ret
= __subn_get_opa_cable_info(smp
, am
, data
, ibdev
, port
,
3722 case IB_SMP_ATTR_VL_ARB_TABLE
:
3723 ret
= __subn_get_opa_vl_arb(smp
, am
, data
, ibdev
, port
,
3726 case OPA_ATTRIB_ID_CONGESTION_INFO
:
3727 ret
= __subn_get_opa_cong_info(smp
, am
, data
, ibdev
, port
,
3730 case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING
:
3731 ret
= __subn_get_opa_cong_setting(smp
, am
, data
, ibdev
,
3734 case OPA_ATTRIB_ID_HFI_CONGESTION_LOG
:
3735 ret
= __subn_get_opa_hfi1_cong_log(smp
, am
, data
, ibdev
,
3738 case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE
:
3739 ret
= __subn_get_opa_cc_table(smp
, am
, data
, ibdev
, port
,
3742 case IB_SMP_ATTR_LED_INFO
:
3743 ret
= __subn_get_opa_led_info(smp
, am
, data
, ibdev
, port
,
3746 case IB_SMP_ATTR_SM_INFO
:
3747 if (ibp
->rvp
.port_cap_flags
& IB_PORT_SM_DISABLED
)
3748 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_CONSUMED
;
3749 if (ibp
->rvp
.port_cap_flags
& IB_PORT_SM
)
3750 return IB_MAD_RESULT_SUCCESS
;
3753 smp
->status
|= IB_SMP_UNSUP_METH_ATTR
;
3754 ret
= reply((struct ib_mad_hdr
*)smp
);
3760 static int subn_set_opa_sma(__be16 attr_id
, struct opa_smp
*smp
, u32 am
,
3761 u8
*data
, struct ib_device
*ibdev
, u8 port
,
3765 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3768 case IB_SMP_ATTR_PORT_INFO
:
3769 ret
= __subn_set_opa_portinfo(smp
, am
, data
, ibdev
, port
,
3772 case IB_SMP_ATTR_PKEY_TABLE
:
3773 ret
= __subn_set_opa_pkeytable(smp
, am
, data
, ibdev
, port
,
3776 case OPA_ATTRIB_ID_SL_TO_SC_MAP
:
3777 ret
= __subn_set_opa_sl_to_sc(smp
, am
, data
, ibdev
, port
,
3780 case OPA_ATTRIB_ID_SC_TO_SL_MAP
:
3781 ret
= __subn_set_opa_sc_to_sl(smp
, am
, data
, ibdev
, port
,
3784 case OPA_ATTRIB_ID_SC_TO_VLT_MAP
:
3785 ret
= __subn_set_opa_sc_to_vlt(smp
, am
, data
, ibdev
, port
,
3788 case OPA_ATTRIB_ID_SC_TO_VLNT_MAP
:
3789 ret
= __subn_set_opa_sc_to_vlnt(smp
, am
, data
, ibdev
, port
,
3792 case OPA_ATTRIB_ID_PORT_STATE_INFO
:
3793 ret
= __subn_set_opa_psi(smp
, am
, data
, ibdev
, port
,
3796 case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE
:
3797 ret
= __subn_set_opa_bct(smp
, am
, data
, ibdev
, port
,
3800 case IB_SMP_ATTR_VL_ARB_TABLE
:
3801 ret
= __subn_set_opa_vl_arb(smp
, am
, data
, ibdev
, port
,
3804 case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING
:
3805 ret
= __subn_set_opa_cong_setting(smp
, am
, data
, ibdev
,
3808 case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE
:
3809 ret
= __subn_set_opa_cc_table(smp
, am
, data
, ibdev
, port
,
3812 case IB_SMP_ATTR_LED_INFO
:
3813 ret
= __subn_set_opa_led_info(smp
, am
, data
, ibdev
, port
,
3816 case IB_SMP_ATTR_SM_INFO
:
3817 if (ibp
->rvp
.port_cap_flags
& IB_PORT_SM_DISABLED
)
3818 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_CONSUMED
;
3819 if (ibp
->rvp
.port_cap_flags
& IB_PORT_SM
)
3820 return IB_MAD_RESULT_SUCCESS
;
3823 smp
->status
|= IB_SMP_UNSUP_METH_ATTR
;
3824 ret
= reply((struct ib_mad_hdr
*)smp
);
3830 static inline void set_aggr_error(struct opa_aggregate
*ag
)
3832 ag
->err_reqlength
|= cpu_to_be16(0x8000);
3835 static int subn_get_opa_aggregate(struct opa_smp
*smp
,
3836 struct ib_device
*ibdev
, u8 port
,
3840 u32 num_attr
= be32_to_cpu(smp
->attr_mod
) & 0x000000ff;
3841 u8
*next_smp
= opa_get_smp_data(smp
);
3843 if (num_attr
< 1 || num_attr
> 117) {
3844 smp
->status
|= IB_SMP_INVALID_FIELD
;
3845 return reply((struct ib_mad_hdr
*)smp
);
3848 for (i
= 0; i
< num_attr
; i
++) {
3849 struct opa_aggregate
*agg
;
3850 size_t agg_data_len
;
3854 agg
= (struct opa_aggregate
*)next_smp
;
3855 agg_data_len
= (be16_to_cpu(agg
->err_reqlength
) & 0x007f) * 8;
3856 agg_size
= sizeof(*agg
) + agg_data_len
;
3857 am
= be32_to_cpu(agg
->attr_mod
);
3859 *resp_len
+= agg_size
;
3861 if (next_smp
+ agg_size
> ((u8
*)smp
) + sizeof(*smp
)) {
3862 smp
->status
|= IB_SMP_INVALID_FIELD
;
3863 return reply((struct ib_mad_hdr
*)smp
);
3866 /* zero the payload for this segment */
3867 memset(next_smp
+ sizeof(*agg
), 0, agg_data_len
);
3869 (void)subn_get_opa_sma(agg
->attr_id
, smp
, am
, agg
->data
,
3871 if (smp
->status
& ~IB_SMP_DIRECTION
) {
3872 set_aggr_error(agg
);
3873 return reply((struct ib_mad_hdr
*)smp
);
3875 next_smp
+= agg_size
;
3878 return reply((struct ib_mad_hdr
*)smp
);
3881 static int subn_set_opa_aggregate(struct opa_smp
*smp
,
3882 struct ib_device
*ibdev
, u8 port
,
3886 u32 num_attr
= be32_to_cpu(smp
->attr_mod
) & 0x000000ff;
3887 u8
*next_smp
= opa_get_smp_data(smp
);
3889 if (num_attr
< 1 || num_attr
> 117) {
3890 smp
->status
|= IB_SMP_INVALID_FIELD
;
3891 return reply((struct ib_mad_hdr
*)smp
);
3894 for (i
= 0; i
< num_attr
; i
++) {
3895 struct opa_aggregate
*agg
;
3896 size_t agg_data_len
;
3900 agg
= (struct opa_aggregate
*)next_smp
;
3901 agg_data_len
= (be16_to_cpu(agg
->err_reqlength
) & 0x007f) * 8;
3902 agg_size
= sizeof(*agg
) + agg_data_len
;
3903 am
= be32_to_cpu(agg
->attr_mod
);
3905 *resp_len
+= agg_size
;
3907 if (next_smp
+ agg_size
> ((u8
*)smp
) + sizeof(*smp
)) {
3908 smp
->status
|= IB_SMP_INVALID_FIELD
;
3909 return reply((struct ib_mad_hdr
*)smp
);
3912 (void)subn_set_opa_sma(agg
->attr_id
, smp
, am
, agg
->data
,
3914 if (smp
->status
& ~IB_SMP_DIRECTION
) {
3915 set_aggr_error(agg
);
3916 return reply((struct ib_mad_hdr
*)smp
);
3918 next_smp
+= agg_size
;
3921 return reply((struct ib_mad_hdr
*)smp
);
3925 * OPAv1 specifies that, on the transition to link up, these counters
3929 * LocalLinkIntegrityErrors
3930 * ExcessiveBufferOverruns [*]
3932 * [*] Error info associated with these counters is retained, but the
3933 * error info status is reset to 0.
3935 void clear_linkup_counters(struct hfi1_devdata
*dd
)
3938 write_dev_cntr(dd
, C_DC_RCV_ERR
, CNTR_INVALID_VL
, 0);
3939 dd
->err_info_rcvport
.status_and_code
&= ~OPA_EI_STATUS_SMASK
;
3940 /* LinkErrorRecovery */
3941 write_dev_cntr(dd
, C_DC_SEQ_CRC_CNT
, CNTR_INVALID_VL
, 0);
3942 write_dev_cntr(dd
, C_DC_REINIT_FROM_PEER_CNT
, CNTR_INVALID_VL
, 0);
3943 /* LocalLinkIntegrityErrors */
3944 write_dev_cntr(dd
, C_DC_RX_REPLAY
, CNTR_INVALID_VL
, 0);
3945 /* ExcessiveBufferOverruns */
3946 write_dev_cntr(dd
, C_RCV_OVF
, CNTR_INVALID_VL
, 0);
3947 dd
->rcv_ovfl_cnt
= 0;
3948 dd
->err_info_xmit_constraint
.status
&= ~OPA_EI_STATUS_SMASK
;
3952 * is_local_mad() returns 1 if 'mad' is sent from, and destined to the
3953 * local node, 0 otherwise.
3955 static int is_local_mad(struct hfi1_ibport
*ibp
, const struct opa_mad
*mad
,
3956 const struct ib_wc
*in_wc
)
3958 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3959 const struct opa_smp
*smp
= (const struct opa_smp
*)mad
;
3961 if (smp
->mgmt_class
== IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
) {
3962 return (smp
->hop_cnt
== 0 &&
3963 smp
->route
.dr
.dr_slid
== OPA_LID_PERMISSIVE
&&
3964 smp
->route
.dr
.dr_dlid
== OPA_LID_PERMISSIVE
);
3967 return (in_wc
->slid
== ppd
->lid
);
3971 * opa_local_smp_check() should only be called on MADs for which
3972 * is_local_mad() returns true. It applies the SMP checks that are
3973 * specific to SMPs which are sent from, and destined to this node.
3974 * opa_local_smp_check() returns 0 if the SMP passes its checks, 1
3977 * SMPs which arrive from other nodes are instead checked by
3980 static int opa_local_smp_check(struct hfi1_ibport
*ibp
,
3981 const struct ib_wc
*in_wc
)
3983 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3984 u16 slid
= in_wc
->slid
;
3987 if (in_wc
->pkey_index
>= ARRAY_SIZE(ppd
->pkeys
))
3990 pkey
= ppd
->pkeys
[in_wc
->pkey_index
];
3992 * We need to do the "node-local" checks specified in OPAv1,
3993 * rev 0.90, section 9.10.26, which are:
3994 * - pkey is 0x7fff, or 0xffff
3995 * - Source QPN == 0 || Destination QPN == 0
3996 * - the MAD header's management class is either
3997 * IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE or
3998 * IB_MGMT_CLASS_SUBN_LID_ROUTED
4001 * However, we know (and so don't need to check again) that,
4002 * for local SMPs, the MAD stack passes MADs with:
4004 * - MAD mgmt_class is IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
4005 * - SLID is either: OPA_LID_PERMISSIVE (0xFFFFFFFF), or
4006 * our own port's lid
4009 if (pkey
== LIM_MGMT_P_KEY
|| pkey
== FULL_MGMT_P_KEY
)
4011 ingress_pkey_table_fail(ppd
, pkey
, slid
);
4015 static int process_subn_opa(struct ib_device
*ibdev
, int mad_flags
,
4016 u8 port
, const struct opa_mad
*in_mad
,
4017 struct opa_mad
*out_mad
,
4020 struct opa_smp
*smp
= (struct opa_smp
*)out_mad
;
4021 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
4028 data
= opa_get_smp_data(smp
);
4030 am
= be32_to_cpu(smp
->attr_mod
);
4031 attr_id
= smp
->attr_id
;
4032 if (smp
->class_version
!= OPA_SMI_CLASS_VERSION
) {
4033 smp
->status
|= IB_SMP_UNSUP_VERSION
;
4034 ret
= reply((struct ib_mad_hdr
*)smp
);
4037 ret
= check_mkey(ibp
, (struct ib_mad_hdr
*)smp
, mad_flags
, smp
->mkey
,
4038 smp
->route
.dr
.dr_slid
, smp
->route
.dr
.return_path
,
4041 u32 port_num
= be32_to_cpu(smp
->attr_mod
);
4044 * If this is a get/set portinfo, we already check the
4045 * M_Key if the MAD is for another port and the M_Key
4046 * is OK on the receiving port. This check is needed
4047 * to increment the error counters when the M_Key
4048 * fails to match on *both* ports.
4050 if (attr_id
== IB_SMP_ATTR_PORT_INFO
&&
4051 (smp
->method
== IB_MGMT_METHOD_GET
||
4052 smp
->method
== IB_MGMT_METHOD_SET
) &&
4053 port_num
&& port_num
<= ibdev
->phys_port_cnt
&&
4055 (void)check_mkey(to_iport(ibdev
, port_num
),
4056 (struct ib_mad_hdr
*)smp
, 0,
4057 smp
->mkey
, smp
->route
.dr
.dr_slid
,
4058 smp
->route
.dr
.return_path
,
4060 ret
= IB_MAD_RESULT_FAILURE
;
4064 *resp_len
= opa_get_smp_header_size(smp
);
4066 switch (smp
->method
) {
4067 case IB_MGMT_METHOD_GET
:
4070 clear_opa_smp_data(smp
);
4071 ret
= subn_get_opa_sma(attr_id
, smp
, am
, data
,
4072 ibdev
, port
, resp_len
);
4074 case OPA_ATTRIB_ID_AGGREGATE
:
4075 ret
= subn_get_opa_aggregate(smp
, ibdev
, port
,
4080 case IB_MGMT_METHOD_SET
:
4083 ret
= subn_set_opa_sma(attr_id
, smp
, am
, data
,
4084 ibdev
, port
, resp_len
);
4086 case OPA_ATTRIB_ID_AGGREGATE
:
4087 ret
= subn_set_opa_aggregate(smp
, ibdev
, port
,
4092 case IB_MGMT_METHOD_TRAP
:
4093 case IB_MGMT_METHOD_REPORT
:
4094 case IB_MGMT_METHOD_REPORT_RESP
:
4095 case IB_MGMT_METHOD_GET_RESP
:
4097 * The ib_mad module will call us to process responses
4098 * before checking for other consumers.
4099 * Just tell the caller to process it normally.
4101 ret
= IB_MAD_RESULT_SUCCESS
;
4104 smp
->status
|= IB_SMP_UNSUP_METHOD
;
4105 ret
= reply((struct ib_mad_hdr
*)smp
);
4112 static int process_subn(struct ib_device
*ibdev
, int mad_flags
,
4113 u8 port
, const struct ib_mad
*in_mad
,
4114 struct ib_mad
*out_mad
)
4116 struct ib_smp
*smp
= (struct ib_smp
*)out_mad
;
4117 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
4121 if (smp
->class_version
!= 1) {
4122 smp
->status
|= IB_SMP_UNSUP_VERSION
;
4123 ret
= reply((struct ib_mad_hdr
*)smp
);
4127 ret
= check_mkey(ibp
, (struct ib_mad_hdr
*)smp
, mad_flags
,
4128 smp
->mkey
, (__force __be32
)smp
->dr_slid
,
4129 smp
->return_path
, smp
->hop_cnt
);
4131 u32 port_num
= be32_to_cpu(smp
->attr_mod
);
4134 * If this is a get/set portinfo, we already check the
4135 * M_Key if the MAD is for another port and the M_Key
4136 * is OK on the receiving port. This check is needed
4137 * to increment the error counters when the M_Key
4138 * fails to match on *both* ports.
4140 if (in_mad
->mad_hdr
.attr_id
== IB_SMP_ATTR_PORT_INFO
&&
4141 (smp
->method
== IB_MGMT_METHOD_GET
||
4142 smp
->method
== IB_MGMT_METHOD_SET
) &&
4143 port_num
&& port_num
<= ibdev
->phys_port_cnt
&&
4145 (void)check_mkey(to_iport(ibdev
, port_num
),
4146 (struct ib_mad_hdr
*)smp
, 0,
4148 (__force __be32
)smp
->dr_slid
,
4149 smp
->return_path
, smp
->hop_cnt
);
4150 ret
= IB_MAD_RESULT_FAILURE
;
4154 switch (smp
->method
) {
4155 case IB_MGMT_METHOD_GET
:
4156 switch (smp
->attr_id
) {
4157 case IB_SMP_ATTR_NODE_INFO
:
4158 ret
= subn_get_nodeinfo(smp
, ibdev
, port
);
4161 smp
->status
|= IB_SMP_UNSUP_METH_ATTR
;
4162 ret
= reply((struct ib_mad_hdr
*)smp
);
4171 static int process_perf(struct ib_device
*ibdev
, u8 port
,
4172 const struct ib_mad
*in_mad
,
4173 struct ib_mad
*out_mad
)
4175 struct ib_pma_mad
*pmp
= (struct ib_pma_mad
*)out_mad
;
4176 struct ib_class_port_info
*cpi
= (struct ib_class_port_info
*)
4178 int ret
= IB_MAD_RESULT_FAILURE
;
4181 if (pmp
->mad_hdr
.class_version
!= 1) {
4182 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_VERSION
;
4183 ret
= reply((struct ib_mad_hdr
*)pmp
);
4187 switch (pmp
->mad_hdr
.method
) {
4188 case IB_MGMT_METHOD_GET
:
4189 switch (pmp
->mad_hdr
.attr_id
) {
4190 case IB_PMA_PORT_COUNTERS
:
4191 ret
= pma_get_ib_portcounters(pmp
, ibdev
, port
);
4193 case IB_PMA_PORT_COUNTERS_EXT
:
4194 ret
= pma_get_ib_portcounters_ext(pmp
, ibdev
, port
);
4196 case IB_PMA_CLASS_PORT_INFO
:
4197 cpi
->capability_mask
= IB_PMA_CLASS_CAP_EXT_WIDTH
;
4198 ret
= reply((struct ib_mad_hdr
*)pmp
);
4201 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METH_ATTR
;
4202 ret
= reply((struct ib_mad_hdr
*)pmp
);
4207 case IB_MGMT_METHOD_SET
:
4208 if (pmp
->mad_hdr
.attr_id
) {
4209 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METH_ATTR
;
4210 ret
= reply((struct ib_mad_hdr
*)pmp
);
4214 case IB_MGMT_METHOD_TRAP
:
4215 case IB_MGMT_METHOD_GET_RESP
:
4217 * The ib_mad module will call us to process responses
4218 * before checking for other consumers.
4219 * Just tell the caller to process it normally.
4221 ret
= IB_MAD_RESULT_SUCCESS
;
4225 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METHOD
;
4226 ret
= reply((struct ib_mad_hdr
*)pmp
);
4233 static int process_perf_opa(struct ib_device
*ibdev
, u8 port
,
4234 const struct opa_mad
*in_mad
,
4235 struct opa_mad
*out_mad
, u32
*resp_len
)
4237 struct opa_pma_mad
*pmp
= (struct opa_pma_mad
*)out_mad
;
4242 if (pmp
->mad_hdr
.class_version
!= OPA_SMI_CLASS_VERSION
) {
4243 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_VERSION
;
4244 return reply((struct ib_mad_hdr
*)pmp
);
4247 *resp_len
= sizeof(pmp
->mad_hdr
);
4249 switch (pmp
->mad_hdr
.method
) {
4250 case IB_MGMT_METHOD_GET
:
4251 switch (pmp
->mad_hdr
.attr_id
) {
4252 case IB_PMA_CLASS_PORT_INFO
:
4253 ret
= pma_get_opa_classportinfo(pmp
, ibdev
, resp_len
);
4255 case OPA_PM_ATTRIB_ID_PORT_STATUS
:
4256 ret
= pma_get_opa_portstatus(pmp
, ibdev
, port
,
4259 case OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERS
:
4260 ret
= pma_get_opa_datacounters(pmp
, ibdev
, port
,
4263 case OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS
:
4264 ret
= pma_get_opa_porterrors(pmp
, ibdev
, port
,
4267 case OPA_PM_ATTRIB_ID_ERROR_INFO
:
4268 ret
= pma_get_opa_errorinfo(pmp
, ibdev
, port
,
4272 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METH_ATTR
;
4273 ret
= reply((struct ib_mad_hdr
*)pmp
);
4278 case IB_MGMT_METHOD_SET
:
4279 switch (pmp
->mad_hdr
.attr_id
) {
4280 case OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS
:
4281 ret
= pma_set_opa_portstatus(pmp
, ibdev
, port
,
4284 case OPA_PM_ATTRIB_ID_ERROR_INFO
:
4285 ret
= pma_set_opa_errorinfo(pmp
, ibdev
, port
,
4289 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METH_ATTR
;
4290 ret
= reply((struct ib_mad_hdr
*)pmp
);
4295 case IB_MGMT_METHOD_TRAP
:
4296 case IB_MGMT_METHOD_GET_RESP
:
4298 * The ib_mad module will call us to process responses
4299 * before checking for other consumers.
4300 * Just tell the caller to process it normally.
4302 ret
= IB_MAD_RESULT_SUCCESS
;
4306 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METHOD
;
4307 ret
= reply((struct ib_mad_hdr
*)pmp
);
4314 static int hfi1_process_opa_mad(struct ib_device
*ibdev
, int mad_flags
,
4315 u8 port
, const struct ib_wc
*in_wc
,
4316 const struct ib_grh
*in_grh
,
4317 const struct opa_mad
*in_mad
,
4318 struct opa_mad
*out_mad
, size_t *out_mad_size
,
4319 u16
*out_mad_pkey_index
)
4324 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
4326 pkey_idx
= hfi1_lookup_pkey_idx(ibp
, LIM_MGMT_P_KEY
);
4328 pr_warn("failed to find limited mgmt pkey, defaulting 0x%x\n",
4329 hfi1_get_pkey(ibp
, 1));
4332 *out_mad_pkey_index
= (u16
)pkey_idx
;
4334 switch (in_mad
->mad_hdr
.mgmt_class
) {
4335 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
:
4336 case IB_MGMT_CLASS_SUBN_LID_ROUTED
:
4337 if (is_local_mad(ibp
, in_mad
, in_wc
)) {
4338 ret
= opa_local_smp_check(ibp
, in_wc
);
4340 return IB_MAD_RESULT_FAILURE
;
4342 ret
= process_subn_opa(ibdev
, mad_flags
, port
, in_mad
,
4343 out_mad
, &resp_len
);
4345 case IB_MGMT_CLASS_PERF_MGMT
:
4346 ret
= process_perf_opa(ibdev
, port
, in_mad
, out_mad
,
4351 ret
= IB_MAD_RESULT_SUCCESS
;
4355 if (ret
& IB_MAD_RESULT_REPLY
)
4356 *out_mad_size
= round_up(resp_len
, 8);
4357 else if (ret
& IB_MAD_RESULT_SUCCESS
)
4358 *out_mad_size
= in_wc
->byte_len
- sizeof(struct ib_grh
);
4363 static int hfi1_process_ib_mad(struct ib_device
*ibdev
, int mad_flags
, u8 port
,
4364 const struct ib_wc
*in_wc
,
4365 const struct ib_grh
*in_grh
,
4366 const struct ib_mad
*in_mad
,
4367 struct ib_mad
*out_mad
)
4371 switch (in_mad
->mad_hdr
.mgmt_class
) {
4372 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
:
4373 case IB_MGMT_CLASS_SUBN_LID_ROUTED
:
4374 ret
= process_subn(ibdev
, mad_flags
, port
, in_mad
, out_mad
);
4376 case IB_MGMT_CLASS_PERF_MGMT
:
4377 ret
= process_perf(ibdev
, port
, in_mad
, out_mad
);
4380 ret
= IB_MAD_RESULT_SUCCESS
;
4388 * hfi1_process_mad - process an incoming MAD packet
4389 * @ibdev: the infiniband device this packet came in on
4390 * @mad_flags: MAD flags
4391 * @port: the port number this packet came in on
4392 * @in_wc: the work completion entry for this packet
4393 * @in_grh: the global route header for this packet
4394 * @in_mad: the incoming MAD
4395 * @out_mad: any outgoing MAD reply
4397 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
4398 * interested in processing.
4400 * Note that the verbs framework has already done the MAD sanity checks,
4401 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
4404 * This is called by the ib_mad module.
4406 int hfi1_process_mad(struct ib_device
*ibdev
, int mad_flags
, u8 port
,
4407 const struct ib_wc
*in_wc
, const struct ib_grh
*in_grh
,
4408 const struct ib_mad_hdr
*in_mad
, size_t in_mad_size
,
4409 struct ib_mad_hdr
*out_mad
, size_t *out_mad_size
,
4410 u16
*out_mad_pkey_index
)
4412 switch (in_mad
->base_version
) {
4413 case OPA_MGMT_BASE_VERSION
:
4414 if (unlikely(in_mad_size
!= sizeof(struct opa_mad
))) {
4415 dev_err(ibdev
->dma_device
, "invalid in_mad_size\n");
4416 return IB_MAD_RESULT_FAILURE
;
4418 return hfi1_process_opa_mad(ibdev
, mad_flags
, port
,
4420 (struct opa_mad
*)in_mad
,
4421 (struct opa_mad
*)out_mad
,
4423 out_mad_pkey_index
);
4424 case IB_MGMT_BASE_VERSION
:
4425 return hfi1_process_ib_mad(ibdev
, mad_flags
, port
,
4427 (const struct ib_mad
*)in_mad
,
4428 (struct ib_mad
*)out_mad
);
4433 return IB_MAD_RESULT_FAILURE
;