1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright(c) 2015-2018 Intel Corporation.
7 #include <rdma/opa_addr.h>
8 #define OPA_NUM_PKEY_BLOCKS_PER_SMP (OPA_SMP_DR_DATA_SIZE \
9 / (OPA_PARTITION_TABLE_BLK_SIZE * sizeof(u16)))
17 /* the reset value from the FM is supposed to be 0xffff, handle both */
18 #define OPA_LINK_WIDTH_RESET_OLD 0x0fff
19 #define OPA_LINK_WIDTH_RESET 0xffff
22 struct list_head list
;
23 struct opa_mad_notice_attr data
;
31 static int smp_length_check(u32 data_size
, u32 request_len
)
33 if (unlikely(request_len
< data_size
))
39 static int reply(struct ib_mad_hdr
*smp
)
42 * The verbs framework will handle the directed/LID route
45 smp
->method
= IB_MGMT_METHOD_GET_RESP
;
46 if (smp
->mgmt_class
== IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
)
47 smp
->status
|= IB_SMP_DIRECTION
;
48 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_REPLY
;
51 static inline void clear_opa_smp_data(struct opa_smp
*smp
)
53 void *data
= opa_get_smp_data(smp
);
54 size_t size
= opa_get_smp_data_size(smp
);
56 memset(data
, 0, size
);
59 static u16
hfi1_lookup_pkey_value(struct hfi1_ibport
*ibp
, int pkey_idx
)
61 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
63 if (pkey_idx
< ARRAY_SIZE(ppd
->pkeys
))
64 return ppd
->pkeys
[pkey_idx
];
69 void hfi1_event_pkey_change(struct hfi1_devdata
*dd
, u32 port
)
71 struct ib_event event
;
73 event
.event
= IB_EVENT_PKEY_CHANGE
;
74 event
.device
= &dd
->verbs_dev
.rdi
.ibdev
;
75 event
.element
.port_num
= port
;
76 ib_dispatch_event(&event
);
80 * If the port is down, clean up all pending traps. We need to be careful
81 * with the given trap, because it may be queued.
83 static void cleanup_traps(struct hfi1_ibport
*ibp
, struct trap_node
*trap
)
85 struct trap_node
*node
, *q
;
87 struct list_head trap_list
;
90 for (i
= 0; i
< RVT_MAX_TRAP_LISTS
; i
++) {
91 spin_lock_irqsave(&ibp
->rvp
.lock
, flags
);
92 list_replace_init(&ibp
->rvp
.trap_lists
[i
].list
, &trap_list
);
93 ibp
->rvp
.trap_lists
[i
].list_len
= 0;
94 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
97 * Remove all items from the list, freeing all the non-given
100 list_for_each_entry_safe(node
, q
, &trap_list
, list
) {
101 list_del(&node
->list
);
108 * If this wasn't on one of the lists it would not be freed. If it
109 * was on the list, it is now safe to free.
114 static struct trap_node
*check_and_add_trap(struct hfi1_ibport
*ibp
,
115 struct trap_node
*trap
)
117 struct trap_node
*node
;
118 struct trap_list
*trap_list
;
120 unsigned long timeout
;
122 unsigned int queue_id
;
123 static int trap_count
;
125 queue_id
= trap
->data
.generic_type
& 0x0F;
126 if (queue_id
>= RVT_MAX_TRAP_LISTS
) {
128 pr_err_ratelimited("hfi1: Invalid trap 0x%0x dropped. Total dropped: %d\n",
129 trap
->data
.generic_type
, trap_count
);
135 * Since the retry (handle timeout) does not remove a trap request
136 * from the list, all we have to do is compare the node.
138 spin_lock_irqsave(&ibp
->rvp
.lock
, flags
);
139 trap_list
= &ibp
->rvp
.trap_lists
[queue_id
];
141 list_for_each_entry(node
, &trap_list
->list
, list
) {
149 /* If it is not on the list, add it, limited to RVT-MAX_TRAP_LEN. */
151 if (trap_list
->list_len
< RVT_MAX_TRAP_LEN
) {
152 trap_list
->list_len
++;
153 list_add_tail(&trap
->list
, &trap_list
->list
);
155 pr_warn_ratelimited("hfi1: Maximum trap limit reached for 0x%0x traps\n",
156 trap
->data
.generic_type
);
162 * Next check to see if there is a timer pending. If not, set it up
163 * and get the first trap from the list.
166 if (!timer_pending(&ibp
->rvp
.trap_timer
)) {
169 * If the time out is set we have to wait until it expires
170 * before the trap can be sent.
171 * This should be > RVT_TRAP_TIMEOUT
173 timeout
= (RVT_TRAP_TIMEOUT
*
174 (1UL << ibp
->rvp
.subnet_timeout
)) / 1000;
175 mod_timer(&ibp
->rvp
.trap_timer
,
176 jiffies
+ usecs_to_jiffies(timeout
));
177 node
= list_first_entry(&trap_list
->list
, struct trap_node
,
181 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
186 static void subn_handle_opa_trap_repress(struct hfi1_ibport
*ibp
,
189 struct trap_list
*trap_list
;
190 struct trap_node
*trap
;
194 if (smp
->attr_id
!= IB_SMP_ATTR_NOTICE
)
197 spin_lock_irqsave(&ibp
->rvp
.lock
, flags
);
198 for (i
= 0; i
< RVT_MAX_TRAP_LISTS
; i
++) {
199 trap_list
= &ibp
->rvp
.trap_lists
[i
];
200 trap
= list_first_entry_or_null(&trap_list
->list
,
201 struct trap_node
, list
);
202 if (trap
&& trap
->tid
== smp
->tid
) {
206 trap_list
->list_len
--;
207 list_del(&trap
->list
);
213 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
216 static void hfi1_update_sm_ah_attr(struct hfi1_ibport
*ibp
,
217 struct rdma_ah_attr
*attr
, u32 dlid
)
219 rdma_ah_set_dlid(attr
, dlid
);
220 rdma_ah_set_port_num(attr
, ppd_from_ibp(ibp
)->port
);
221 if (dlid
>= be16_to_cpu(IB_MULTICAST_LID_BASE
)) {
222 struct ib_global_route
*grh
= rdma_ah_retrieve_grh(attr
);
224 rdma_ah_set_ah_flags(attr
, IB_AH_GRH
);
227 grh
->dgid
.global
.subnet_prefix
=
229 grh
->dgid
.global
.interface_id
= OPA_MAKE_ID(dlid
);
233 static int hfi1_modify_qp0_ah(struct hfi1_ibport
*ibp
,
234 struct rvt_ah
*ah
, u32 dlid
)
236 struct rdma_ah_attr attr
;
240 memset(&attr
, 0, sizeof(attr
));
241 attr
.type
= ah
->ibah
.type
;
242 hfi1_update_sm_ah_attr(ibp
, &attr
, dlid
);
244 qp0
= rcu_dereference(ibp
->rvp
.qp
[0]);
246 ret
= rdma_modify_ah(&ah
->ibah
, &attr
);
251 static struct ib_ah
*hfi1_create_qp0_ah(struct hfi1_ibport
*ibp
, u32 dlid
)
253 struct rdma_ah_attr attr
;
254 struct ib_ah
*ah
= ERR_PTR(-EINVAL
);
256 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
257 struct hfi1_devdata
*dd
= dd_from_ppd(ppd
);
258 u32 port_num
= ppd
->port
;
260 memset(&attr
, 0, sizeof(attr
));
261 attr
.type
= rdma_ah_find_type(&dd
->verbs_dev
.rdi
.ibdev
, port_num
);
262 hfi1_update_sm_ah_attr(ibp
, &attr
, dlid
);
264 qp0
= rcu_dereference(ibp
->rvp
.qp
[0]);
266 ah
= rdma_create_ah(qp0
->ibqp
.pd
, &attr
, 0);
271 static void send_trap(struct hfi1_ibport
*ibp
, struct trap_node
*trap
)
273 struct ib_mad_send_buf
*send_buf
;
274 struct ib_mad_agent
*agent
;
278 u32 qpn
= ppd_from_ibp(ibp
)->sm_trap_qp
;
280 agent
= ibp
->rvp
.send_agent
;
282 cleanup_traps(ibp
, trap
);
287 if (driver_lstate(ppd_from_ibp(ibp
)) != IB_PORT_ACTIVE
) {
288 cleanup_traps(ibp
, trap
);
292 /* Add the trap to the list if necessary and see if we can send it */
293 trap
= check_and_add_trap(ibp
, trap
);
297 pkey_idx
= hfi1_lookup_pkey_idx(ibp
, LIM_MGMT_P_KEY
);
299 pr_warn("%s: failed to find limited mgmt pkey, defaulting 0x%x\n",
300 __func__
, hfi1_get_pkey(ibp
, 1));
304 send_buf
= ib_create_send_mad(agent
, qpn
, pkey_idx
, 0,
305 IB_MGMT_MAD_HDR
, IB_MGMT_MAD_DATA
,
306 GFP_ATOMIC
, IB_MGMT_BASE_VERSION
);
307 if (IS_ERR(send_buf
))
311 smp
->base_version
= OPA_MGMT_BASE_VERSION
;
312 smp
->mgmt_class
= IB_MGMT_CLASS_SUBN_LID_ROUTED
;
313 smp
->class_version
= OPA_SM_CLASS_VERSION
;
314 smp
->method
= IB_MGMT_METHOD_TRAP
;
316 /* Only update the transaction ID for new traps (o13-5). */
317 if (trap
->tid
== 0) {
319 /* make sure that tid != 0 */
320 if (ibp
->rvp
.tid
== 0)
322 trap
->tid
= cpu_to_be64(ibp
->rvp
.tid
);
324 smp
->tid
= trap
->tid
;
326 smp
->attr_id
= IB_SMP_ATTR_NOTICE
;
327 /* o14-1: smp->mkey = 0; */
329 memcpy(smp
->route
.lid
.data
, &trap
->data
, trap
->len
);
331 spin_lock_irqsave(&ibp
->rvp
.lock
, flags
);
332 if (!ibp
->rvp
.sm_ah
) {
333 if (ibp
->rvp
.sm_lid
!= be16_to_cpu(IB_LID_PERMISSIVE
)) {
336 ah
= hfi1_create_qp0_ah(ibp
, ibp
->rvp
.sm_lid
);
338 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
342 ibp
->rvp
.sm_ah
= ibah_to_rvtah(ah
);
344 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
348 send_buf
->ah
= &ibp
->rvp
.sm_ah
->ibah
;
352 * If the trap was repressed while things were getting set up, don't
353 * bother sending it. This could happen for a retry.
356 list_del(&trap
->list
);
357 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
359 ib_free_send_mad(send_buf
);
364 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
366 if (ib_post_send_mad(send_buf
, NULL
))
367 ib_free_send_mad(send_buf
);
370 void hfi1_handle_trap_timer(struct timer_list
*t
)
372 struct hfi1_ibport
*ibp
= from_timer(ibp
, t
, rvp
.trap_timer
);
373 struct trap_node
*trap
= NULL
;
377 /* Find the trap with the highest priority */
378 spin_lock_irqsave(&ibp
->rvp
.lock
, flags
);
379 for (i
= 0; !trap
&& i
< RVT_MAX_TRAP_LISTS
; i
++) {
380 trap
= list_first_entry_or_null(&ibp
->rvp
.trap_lists
[i
].list
,
381 struct trap_node
, list
);
383 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
386 send_trap(ibp
, trap
);
389 static struct trap_node
*create_trap_node(u8 type
, __be16 trap_num
, u32 lid
)
391 struct trap_node
*trap
;
393 trap
= kzalloc(sizeof(*trap
), GFP_ATOMIC
);
397 INIT_LIST_HEAD(&trap
->list
);
398 trap
->data
.generic_type
= type
;
399 trap
->data
.prod_type_lsb
= IB_NOTICE_PROD_CA
;
400 trap
->data
.trap_num
= trap_num
;
401 trap
->data
.issuer_lid
= cpu_to_be32(lid
);
407 * Send a bad P_Key trap (ch. 14.3.8).
409 void hfi1_bad_pkey(struct hfi1_ibport
*ibp
, u32 key
, u32 sl
,
410 u32 qp1
, u32 qp2
, u32 lid1
, u32 lid2
)
412 struct trap_node
*trap
;
413 u32 lid
= ppd_from_ibp(ibp
)->lid
;
415 ibp
->rvp
.n_pkt_drops
++;
416 ibp
->rvp
.pkey_violations
++;
418 trap
= create_trap_node(IB_NOTICE_TYPE_SECURITY
, OPA_TRAP_BAD_P_KEY
,
423 /* Send violation trap */
424 trap
->data
.ntc_257_258
.lid1
= cpu_to_be32(lid1
);
425 trap
->data
.ntc_257_258
.lid2
= cpu_to_be32(lid2
);
426 trap
->data
.ntc_257_258
.key
= cpu_to_be32(key
);
427 trap
->data
.ntc_257_258
.sl
= sl
<< 3;
428 trap
->data
.ntc_257_258
.qp1
= cpu_to_be32(qp1
);
429 trap
->data
.ntc_257_258
.qp2
= cpu_to_be32(qp2
);
431 trap
->len
= sizeof(trap
->data
);
432 send_trap(ibp
, trap
);
436 * Send a bad M_Key trap (ch. 14.3.9).
438 static void bad_mkey(struct hfi1_ibport
*ibp
, struct ib_mad_hdr
*mad
,
439 __be64 mkey
, __be32 dr_slid
, u8 return_path
[], u8 hop_cnt
)
441 struct trap_node
*trap
;
442 u32 lid
= ppd_from_ibp(ibp
)->lid
;
444 trap
= create_trap_node(IB_NOTICE_TYPE_SECURITY
, OPA_TRAP_BAD_M_KEY
,
449 /* Send violation trap */
450 trap
->data
.ntc_256
.lid
= trap
->data
.issuer_lid
;
451 trap
->data
.ntc_256
.method
= mad
->method
;
452 trap
->data
.ntc_256
.attr_id
= mad
->attr_id
;
453 trap
->data
.ntc_256
.attr_mod
= mad
->attr_mod
;
454 trap
->data
.ntc_256
.mkey
= mkey
;
455 if (mad
->mgmt_class
== IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
) {
456 trap
->data
.ntc_256
.dr_slid
= dr_slid
;
457 trap
->data
.ntc_256
.dr_trunc_hop
= IB_NOTICE_TRAP_DR_NOTICE
;
458 if (hop_cnt
> ARRAY_SIZE(trap
->data
.ntc_256
.dr_rtn_path
)) {
459 trap
->data
.ntc_256
.dr_trunc_hop
|=
460 IB_NOTICE_TRAP_DR_TRUNC
;
461 hop_cnt
= ARRAY_SIZE(trap
->data
.ntc_256
.dr_rtn_path
);
463 trap
->data
.ntc_256
.dr_trunc_hop
|= hop_cnt
;
464 memcpy(trap
->data
.ntc_256
.dr_rtn_path
, return_path
,
468 trap
->len
= sizeof(trap
->data
);
470 send_trap(ibp
, trap
);
474 * Send a Port Capability Mask Changed trap (ch. 14.3.11).
476 void hfi1_cap_mask_chg(struct rvt_dev_info
*rdi
, u32 port_num
)
478 struct trap_node
*trap
;
479 struct hfi1_ibdev
*verbs_dev
= dev_from_rdi(rdi
);
480 struct hfi1_devdata
*dd
= dd_from_dev(verbs_dev
);
481 struct hfi1_ibport
*ibp
= &dd
->pport
[port_num
- 1].ibport_data
;
482 u32 lid
= ppd_from_ibp(ibp
)->lid
;
484 trap
= create_trap_node(IB_NOTICE_TYPE_INFO
,
485 OPA_TRAP_CHANGE_CAPABILITY
,
490 trap
->data
.ntc_144
.lid
= trap
->data
.issuer_lid
;
491 trap
->data
.ntc_144
.new_cap_mask
= cpu_to_be32(ibp
->rvp
.port_cap_flags
);
492 trap
->data
.ntc_144
.cap_mask3
= cpu_to_be16(ibp
->rvp
.port_cap3_flags
);
494 trap
->len
= sizeof(trap
->data
);
495 send_trap(ibp
, trap
);
499 * Send a System Image GUID Changed trap (ch. 14.3.12).
501 void hfi1_sys_guid_chg(struct hfi1_ibport
*ibp
)
503 struct trap_node
*trap
;
504 u32 lid
= ppd_from_ibp(ibp
)->lid
;
506 trap
= create_trap_node(IB_NOTICE_TYPE_INFO
, OPA_TRAP_CHANGE_SYSGUID
,
511 trap
->data
.ntc_145
.new_sys_guid
= ib_hfi1_sys_image_guid
;
512 trap
->data
.ntc_145
.lid
= trap
->data
.issuer_lid
;
514 trap
->len
= sizeof(trap
->data
);
515 send_trap(ibp
, trap
);
519 * Send a Node Description Changed trap (ch. 14.3.13).
521 void hfi1_node_desc_chg(struct hfi1_ibport
*ibp
)
523 struct trap_node
*trap
;
524 u32 lid
= ppd_from_ibp(ibp
)->lid
;
526 trap
= create_trap_node(IB_NOTICE_TYPE_INFO
,
527 OPA_TRAP_CHANGE_CAPABILITY
,
532 trap
->data
.ntc_144
.lid
= trap
->data
.issuer_lid
;
533 trap
->data
.ntc_144
.change_flags
=
534 cpu_to_be16(OPA_NOTICE_TRAP_NODE_DESC_CHG
);
536 trap
->len
= sizeof(trap
->data
);
537 send_trap(ibp
, trap
);
540 static int __subn_get_opa_nodedesc(struct opa_smp
*smp
, u32 am
,
541 u8
*data
, struct ib_device
*ibdev
,
542 u32 port
, u32
*resp_len
, u32 max_len
)
544 struct opa_node_description
*nd
;
546 if (am
|| smp_length_check(sizeof(*nd
), max_len
)) {
547 smp
->status
|= IB_SMP_INVALID_FIELD
;
548 return reply((struct ib_mad_hdr
*)smp
);
551 nd
= (struct opa_node_description
*)data
;
553 memcpy(nd
->data
, ibdev
->node_desc
, sizeof(nd
->data
));
556 *resp_len
+= sizeof(*nd
);
558 return reply((struct ib_mad_hdr
*)smp
);
561 static int __subn_get_opa_nodeinfo(struct opa_smp
*smp
, u32 am
, u8
*data
,
562 struct ib_device
*ibdev
, u32 port
,
563 u32
*resp_len
, u32 max_len
)
565 struct opa_node_info
*ni
;
566 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
567 u32 pidx
= port
- 1; /* IB number port from 1, hw from 0 */
569 ni
= (struct opa_node_info
*)data
;
571 /* GUID 0 is illegal */
572 if (am
|| pidx
>= dd
->num_pports
|| ibdev
->node_guid
== 0 ||
573 smp_length_check(sizeof(*ni
), max_len
) ||
574 get_sguid(to_iport(ibdev
, port
), HFI1_PORT_GUID_INDEX
) == 0) {
575 smp
->status
|= IB_SMP_INVALID_FIELD
;
576 return reply((struct ib_mad_hdr
*)smp
);
579 ni
->port_guid
= get_sguid(to_iport(ibdev
, port
), HFI1_PORT_GUID_INDEX
);
580 ni
->base_version
= OPA_MGMT_BASE_VERSION
;
581 ni
->class_version
= OPA_SM_CLASS_VERSION
;
582 ni
->node_type
= 1; /* channel adapter */
583 ni
->num_ports
= ibdev
->phys_port_cnt
;
584 /* This is already in network order */
585 ni
->system_image_guid
= ib_hfi1_sys_image_guid
;
586 ni
->node_guid
= ibdev
->node_guid
;
587 ni
->partition_cap
= cpu_to_be16(hfi1_get_npkeys(dd
));
588 ni
->device_id
= cpu_to_be16(dd
->pcidev
->device
);
589 ni
->revision
= cpu_to_be32(dd
->minrev
);
590 ni
->local_port_num
= port
;
591 ni
->vendor_id
[0] = dd
->oui1
;
592 ni
->vendor_id
[1] = dd
->oui2
;
593 ni
->vendor_id
[2] = dd
->oui3
;
596 *resp_len
+= sizeof(*ni
);
598 return reply((struct ib_mad_hdr
*)smp
);
601 static int subn_get_nodeinfo(struct ib_smp
*smp
, struct ib_device
*ibdev
,
604 struct ib_node_info
*nip
= (struct ib_node_info
*)&smp
->data
;
605 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
606 u32 pidx
= port
- 1; /* IB number port from 1, hw from 0 */
608 /* GUID 0 is illegal */
609 if (smp
->attr_mod
|| pidx
>= dd
->num_pports
||
610 ibdev
->node_guid
== 0 ||
611 get_sguid(to_iport(ibdev
, port
), HFI1_PORT_GUID_INDEX
) == 0) {
612 smp
->status
|= IB_SMP_INVALID_FIELD
;
613 return reply((struct ib_mad_hdr
*)smp
);
616 nip
->port_guid
= get_sguid(to_iport(ibdev
, port
), HFI1_PORT_GUID_INDEX
);
617 nip
->base_version
= OPA_MGMT_BASE_VERSION
;
618 nip
->class_version
= OPA_SM_CLASS_VERSION
;
619 nip
->node_type
= 1; /* channel adapter */
620 nip
->num_ports
= ibdev
->phys_port_cnt
;
621 /* This is already in network order */
622 nip
->sys_guid
= ib_hfi1_sys_image_guid
;
623 nip
->node_guid
= ibdev
->node_guid
;
624 nip
->partition_cap
= cpu_to_be16(hfi1_get_npkeys(dd
));
625 nip
->device_id
= cpu_to_be16(dd
->pcidev
->device
);
626 nip
->revision
= cpu_to_be32(dd
->minrev
);
627 nip
->local_port_num
= port
;
628 nip
->vendor_id
[0] = dd
->oui1
;
629 nip
->vendor_id
[1] = dd
->oui2
;
630 nip
->vendor_id
[2] = dd
->oui3
;
632 return reply((struct ib_mad_hdr
*)smp
);
635 static void set_link_width_enabled(struct hfi1_pportdata
*ppd
, u32 w
)
637 (void)hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_LWID_ENB
, w
);
640 static void set_link_width_downgrade_enabled(struct hfi1_pportdata
*ppd
, u32 w
)
642 (void)hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_LWID_DG_ENB
, w
);
645 static void set_link_speed_enabled(struct hfi1_pportdata
*ppd
, u32 s
)
647 (void)hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_SPD_ENB
, s
);
650 static int check_mkey(struct hfi1_ibport
*ibp
, struct ib_mad_hdr
*mad
,
651 int mad_flags
, __be64 mkey
, __be32 dr_slid
,
652 u8 return_path
[], u8 hop_cnt
)
657 /* Is the mkey in the process of expiring? */
658 if (ibp
->rvp
.mkey_lease_timeout
&&
659 time_after_eq(jiffies
, ibp
->rvp
.mkey_lease_timeout
)) {
660 /* Clear timeout and mkey protection field. */
661 ibp
->rvp
.mkey_lease_timeout
= 0;
662 ibp
->rvp
.mkeyprot
= 0;
665 if ((mad_flags
& IB_MAD_IGNORE_MKEY
) || ibp
->rvp
.mkey
== 0 ||
666 ibp
->rvp
.mkey
== mkey
)
669 /* Unset lease timeout on any valid Get/Set/TrapRepress */
670 if (valid_mkey
&& ibp
->rvp
.mkey_lease_timeout
&&
671 (mad
->method
== IB_MGMT_METHOD_GET
||
672 mad
->method
== IB_MGMT_METHOD_SET
||
673 mad
->method
== IB_MGMT_METHOD_TRAP_REPRESS
))
674 ibp
->rvp
.mkey_lease_timeout
= 0;
677 switch (mad
->method
) {
678 case IB_MGMT_METHOD_GET
:
679 /* Bad mkey not a violation below level 2 */
680 if (ibp
->rvp
.mkeyprot
< 2)
683 case IB_MGMT_METHOD_SET
:
684 case IB_MGMT_METHOD_TRAP_REPRESS
:
685 if (ibp
->rvp
.mkey_violations
!= 0xFFFF)
686 ++ibp
->rvp
.mkey_violations
;
687 if (!ibp
->rvp
.mkey_lease_timeout
&&
688 ibp
->rvp
.mkey_lease_period
)
689 ibp
->rvp
.mkey_lease_timeout
= jiffies
+
690 ibp
->rvp
.mkey_lease_period
* HZ
;
691 /* Generate a trap notice. */
692 bad_mkey(ibp
, mad
, mkey
, dr_slid
, return_path
,
702 * The SMA caches reads from LCB registers in case the LCB is unavailable.
703 * (The LCB is unavailable in certain link states, for example.)
710 static struct lcb_datum lcb_cache
[] = {
711 { DC_LCB_STS_ROUND_TRIP_LTP_CNT
, 0 },
714 static int write_lcb_cache(u32 off
, u64 val
)
718 for (i
= 0; i
< ARRAY_SIZE(lcb_cache
); i
++) {
719 if (lcb_cache
[i
].off
== off
) {
720 lcb_cache
[i
].val
= val
;
725 pr_warn("%s bad offset 0x%x\n", __func__
, off
);
729 static int read_lcb_cache(u32 off
, u64
*val
)
733 for (i
= 0; i
< ARRAY_SIZE(lcb_cache
); i
++) {
734 if (lcb_cache
[i
].off
== off
) {
735 *val
= lcb_cache
[i
].val
;
740 pr_warn("%s bad offset 0x%x\n", __func__
, off
);
744 void read_ltp_rtt(struct hfi1_devdata
*dd
)
748 if (read_lcb_csr(dd
, DC_LCB_STS_ROUND_TRIP_LTP_CNT
, ®
))
749 dd_dev_err(dd
, "%s: unable to read LTP RTT\n", __func__
);
751 write_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT
, reg
);
754 static int __subn_get_opa_portinfo(struct opa_smp
*smp
, u32 am
, u8
*data
,
755 struct ib_device
*ibdev
, u32 port
,
756 u32
*resp_len
, u32 max_len
)
759 struct hfi1_devdata
*dd
;
760 struct hfi1_pportdata
*ppd
;
761 struct hfi1_ibport
*ibp
;
762 struct opa_port_info
*pi
= (struct opa_port_info
*)data
;
765 u8 is_beaconing_active
;
767 u32 num_ports
= OPA_AM_NPORT(am
);
768 u32 start_of_sm_config
= OPA_AM_START_SM_CFG(am
);
772 if (num_ports
!= 1 || smp_length_check(sizeof(*pi
), max_len
)) {
773 smp
->status
|= IB_SMP_INVALID_FIELD
;
774 return reply((struct ib_mad_hdr
*)smp
);
777 dd
= dd_from_ibdev(ibdev
);
778 /* IB numbers ports from 1, hw from 0 */
779 ppd
= dd
->pport
+ (port
- 1);
780 ibp
= &ppd
->ibport_data
;
782 if (ppd
->vls_supported
/ 2 > ARRAY_SIZE(pi
->neigh_mtu
.pvlx_to_mtu
) ||
783 ppd
->vls_supported
> ARRAY_SIZE(dd
->vld
)) {
784 smp
->status
|= IB_SMP_INVALID_FIELD
;
785 return reply((struct ib_mad_hdr
*)smp
);
788 pi
->lid
= cpu_to_be32(ppd
->lid
);
790 /* Only return the mkey if the protection field allows it. */
791 if (!(smp
->method
== IB_MGMT_METHOD_GET
&&
792 ibp
->rvp
.mkey
!= smp
->mkey
&&
793 ibp
->rvp
.mkeyprot
== 1))
794 pi
->mkey
= ibp
->rvp
.mkey
;
796 pi
->subnet_prefix
= ibp
->rvp
.gid_prefix
;
797 pi
->sm_lid
= cpu_to_be32(ibp
->rvp
.sm_lid
);
798 pi
->ib_cap_mask
= cpu_to_be32(ibp
->rvp
.port_cap_flags
);
799 pi
->mkey_lease_period
= cpu_to_be16(ibp
->rvp
.mkey_lease_period
);
800 pi
->sm_trap_qp
= cpu_to_be32(ppd
->sm_trap_qp
);
801 pi
->sa_qp
= cpu_to_be32(ppd
->sa_qp
);
803 pi
->link_width
.enabled
= cpu_to_be16(ppd
->link_width_enabled
);
804 pi
->link_width
.supported
= cpu_to_be16(ppd
->link_width_supported
);
805 pi
->link_width
.active
= cpu_to_be16(ppd
->link_width_active
);
807 pi
->link_width_downgrade
.supported
=
808 cpu_to_be16(ppd
->link_width_downgrade_supported
);
809 pi
->link_width_downgrade
.enabled
=
810 cpu_to_be16(ppd
->link_width_downgrade_enabled
);
811 pi
->link_width_downgrade
.tx_active
=
812 cpu_to_be16(ppd
->link_width_downgrade_tx_active
);
813 pi
->link_width_downgrade
.rx_active
=
814 cpu_to_be16(ppd
->link_width_downgrade_rx_active
);
816 pi
->link_speed
.supported
= cpu_to_be16(ppd
->link_speed_supported
);
817 pi
->link_speed
.active
= cpu_to_be16(ppd
->link_speed_active
);
818 pi
->link_speed
.enabled
= cpu_to_be16(ppd
->link_speed_enabled
);
820 state
= driver_lstate(ppd
);
822 if (start_of_sm_config
&& (state
== IB_PORT_INIT
))
823 ppd
->is_sm_config_started
= 1;
825 pi
->port_phys_conf
= (ppd
->port_type
& 0xf);
827 pi
->port_states
.ledenable_offlinereason
= ppd
->neighbor_normal
<< 4;
828 pi
->port_states
.ledenable_offlinereason
|=
829 ppd
->is_sm_config_started
<< 5;
831 * This pairs with the memory barrier in hfi1_start_led_override to
832 * ensure that we read the correct state of LED beaconing represented
833 * by led_override_timer_active
836 is_beaconing_active
= !!atomic_read(&ppd
->led_override_timer_active
);
837 pi
->port_states
.ledenable_offlinereason
|= is_beaconing_active
<< 6;
838 pi
->port_states
.ledenable_offlinereason
|=
839 ppd
->offline_disabled_reason
;
841 pi
->port_states
.portphysstate_portstate
=
842 (driver_pstate(ppd
) << 4) | state
;
844 pi
->mkeyprotect_lmc
= (ibp
->rvp
.mkeyprot
<< 6) | ppd
->lmc
;
846 memset(pi
->neigh_mtu
.pvlx_to_mtu
, 0, sizeof(pi
->neigh_mtu
.pvlx_to_mtu
));
847 for (i
= 0; i
< ppd
->vls_supported
; i
++) {
848 mtu
= mtu_to_enum(dd
->vld
[i
].mtu
, HFI1_DEFAULT_ACTIVE_MTU
);
850 pi
->neigh_mtu
.pvlx_to_mtu
[i
/ 2] |= (mtu
<< 4);
852 pi
->neigh_mtu
.pvlx_to_mtu
[i
/ 2] |= mtu
;
854 /* don't forget VL 15 */
855 mtu
= mtu_to_enum(dd
->vld
[15].mtu
, 2048);
856 pi
->neigh_mtu
.pvlx_to_mtu
[15 / 2] |= mtu
;
857 pi
->smsl
= ibp
->rvp
.sm_sl
& OPA_PI_MASK_SMSL
;
858 pi
->operational_vls
= hfi1_get_ib_cfg(ppd
, HFI1_IB_CFG_OP_VLS
);
859 pi
->partenforce_filterraw
|=
860 (ppd
->linkinit_reason
& OPA_PI_MASK_LINKINIT_REASON
);
861 if (ppd
->part_enforce
& HFI1_PART_ENFORCE_IN
)
862 pi
->partenforce_filterraw
|= OPA_PI_MASK_PARTITION_ENFORCE_IN
;
863 if (ppd
->part_enforce
& HFI1_PART_ENFORCE_OUT
)
864 pi
->partenforce_filterraw
|= OPA_PI_MASK_PARTITION_ENFORCE_OUT
;
865 pi
->mkey_violations
= cpu_to_be16(ibp
->rvp
.mkey_violations
);
866 /* P_KeyViolations are counted by hardware. */
867 pi
->pkey_violations
= cpu_to_be16(ibp
->rvp
.pkey_violations
);
868 pi
->qkey_violations
= cpu_to_be16(ibp
->rvp
.qkey_violations
);
870 pi
->vl
.cap
= ppd
->vls_supported
;
871 pi
->vl
.high_limit
= cpu_to_be16(ibp
->rvp
.vl_high_limit
);
872 pi
->vl
.arb_high_cap
= (u8
)hfi1_get_ib_cfg(ppd
, HFI1_IB_CFG_VL_HIGH_CAP
);
873 pi
->vl
.arb_low_cap
= (u8
)hfi1_get_ib_cfg(ppd
, HFI1_IB_CFG_VL_LOW_CAP
);
875 pi
->clientrereg_subnettimeout
= ibp
->rvp
.subnet_timeout
;
877 pi
->port_link_mode
= cpu_to_be16(OPA_PORT_LINK_MODE_OPA
<< 10 |
878 OPA_PORT_LINK_MODE_OPA
<< 5 |
879 OPA_PORT_LINK_MODE_OPA
);
881 pi
->port_ltp_crc_mode
= cpu_to_be16(ppd
->port_ltp_crc_mode
);
883 pi
->port_mode
= cpu_to_be16(
884 ppd
->is_active_optimize_enabled
?
885 OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE
: 0);
887 pi
->port_packet_format
.supported
=
888 cpu_to_be16(OPA_PORT_PACKET_FORMAT_9B
|
889 OPA_PORT_PACKET_FORMAT_16B
);
890 pi
->port_packet_format
.enabled
=
891 cpu_to_be16(OPA_PORT_PACKET_FORMAT_9B
|
892 OPA_PORT_PACKET_FORMAT_16B
);
894 /* flit_control.interleave is (OPA V1, version .76):
898 * 2 DistanceSupported
900 * 5 MaxNextLevelTxEnabled
901 * 5 MaxNestLevelRxSupported
903 * HFI supports only "distance mode 1" (see OPA V1, version .76,
904 * section 9.6.2), so set DistanceSupported, DistanceEnabled
907 pi
->flit_control
.interleave
= cpu_to_be16(0x1400);
909 pi
->link_down_reason
= ppd
->local_link_down_reason
.sma
;
910 pi
->neigh_link_down_reason
= ppd
->neigh_link_down_reason
.sma
;
911 pi
->port_error_action
= cpu_to_be32(ppd
->port_error_action
);
912 pi
->mtucap
= mtu_to_enum(hfi1_max_mtu
, IB_MTU_4096
);
914 /* 32.768 usec. response time (guessing) */
915 pi
->resptimevalue
= 3;
917 pi
->local_port_num
= port
;
919 /* buffer info for FM */
920 pi
->overall_buffer_space
= cpu_to_be16(dd
->link_credits
);
922 pi
->neigh_node_guid
= cpu_to_be64(ppd
->neighbor_guid
);
923 pi
->neigh_port_num
= ppd
->neighbor_port_number
;
924 pi
->port_neigh_mode
=
925 (ppd
->neighbor_type
& OPA_PI_MASK_NEIGH_NODE_TYPE
) |
926 (ppd
->mgmt_allowed
? OPA_PI_MASK_NEIGH_MGMT_ALLOWED
: 0) |
927 (ppd
->neighbor_fm_security
?
928 OPA_PI_MASK_NEIGH_FW_AUTH_BYPASS
: 0);
930 /* HFIs shall always return VL15 credits to their
931 * neighbor in a timely manner, without any credit return pacing.
934 buffer_units
= (dd
->vau
) & OPA_PI_MASK_BUF_UNIT_BUF_ALLOC
;
935 buffer_units
|= (dd
->vcu
<< 3) & OPA_PI_MASK_BUF_UNIT_CREDIT_ACK
;
936 buffer_units
|= (credit_rate
<< 6) &
937 OPA_PI_MASK_BUF_UNIT_VL15_CREDIT_RATE
;
938 buffer_units
|= (dd
->vl15_init
<< 11) & OPA_PI_MASK_BUF_UNIT_VL15_INIT
;
939 pi
->buffer_units
= cpu_to_be32(buffer_units
);
941 pi
->opa_cap_mask
= cpu_to_be16(ibp
->rvp
.port_cap3_flags
);
942 pi
->collectivemask_multicastmask
= ((OPA_COLLECTIVE_NR
& 0x7)
943 << 3 | (OPA_MCAST_NR
& 0x7));
945 /* HFI supports a replay buffer 128 LTPs in size */
946 pi
->replay_depth
.buffer
= 0x80;
947 /* read the cached value of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
948 read_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT
, &tmp
);
951 * this counter is 16 bits wide, but the replay_depth.wire
952 * variable is only 8 bits
956 pi
->replay_depth
.wire
= tmp
;
959 *resp_len
+= sizeof(struct opa_port_info
);
961 return reply((struct ib_mad_hdr
*)smp
);
965 * get_pkeys - return the PKEY table
966 * @dd: the hfi1_ib device
967 * @port: the IB port number
968 * @pkeys: the pkey table is placed here
970 static int get_pkeys(struct hfi1_devdata
*dd
, u32 port
, u16
*pkeys
)
972 struct hfi1_pportdata
*ppd
= dd
->pport
+ port
- 1;
974 memcpy(pkeys
, ppd
->pkeys
, sizeof(ppd
->pkeys
));
979 static int __subn_get_opa_pkeytable(struct opa_smp
*smp
, u32 am
, u8
*data
,
980 struct ib_device
*ibdev
, u32 port
,
981 u32
*resp_len
, u32 max_len
)
983 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
984 u32 n_blocks_req
= OPA_AM_NBLK(am
);
985 u32 start_block
= am
& 0x7ff;
990 unsigned npkeys
= hfi1_get_npkeys(dd
);
993 if (n_blocks_req
== 0) {
994 pr_warn("OPA Get PKey AM Invalid : P = %d; B = 0x%x; N = 0x%x\n",
995 port
, start_block
, n_blocks_req
);
996 smp
->status
|= IB_SMP_INVALID_FIELD
;
997 return reply((struct ib_mad_hdr
*)smp
);
1000 n_blocks_avail
= (u16
)(npkeys
/ OPA_PARTITION_TABLE_BLK_SIZE
) + 1;
1002 size
= (n_blocks_req
* OPA_PARTITION_TABLE_BLK_SIZE
) * sizeof(u16
);
1004 if (smp_length_check(size
, max_len
)) {
1005 smp
->status
|= IB_SMP_INVALID_FIELD
;
1006 return reply((struct ib_mad_hdr
*)smp
);
1009 if (start_block
+ n_blocks_req
> n_blocks_avail
||
1010 n_blocks_req
> OPA_NUM_PKEY_BLOCKS_PER_SMP
) {
1011 pr_warn("OPA Get PKey AM Invalid : s 0x%x; req 0x%x; "
1012 "avail 0x%x; blk/smp 0x%lx\n",
1013 start_block
, n_blocks_req
, n_blocks_avail
,
1014 OPA_NUM_PKEY_BLOCKS_PER_SMP
);
1015 smp
->status
|= IB_SMP_INVALID_FIELD
;
1016 return reply((struct ib_mad_hdr
*)smp
);
1021 /* get the real pkeys if we are requesting the first block */
1022 if (start_block
== 0) {
1023 get_pkeys(dd
, port
, q
);
1024 for (i
= 0; i
< npkeys
; i
++)
1025 p
[i
] = cpu_to_be16(q
[i
]);
1029 smp
->status
|= IB_SMP_INVALID_FIELD
;
1031 return reply((struct ib_mad_hdr
*)smp
);
1035 HFI_TRANSITION_DISALLOWED
,
1036 HFI_TRANSITION_IGNORED
,
1037 HFI_TRANSITION_ALLOWED
,
1038 HFI_TRANSITION_UNDEFINED
,
1042 * Use shortened names to improve readability of
1043 * {logical,physical}_state_transitions
1046 __D
= HFI_TRANSITION_DISALLOWED
,
1047 __I
= HFI_TRANSITION_IGNORED
,
1048 __A
= HFI_TRANSITION_ALLOWED
,
1049 __U
= HFI_TRANSITION_UNDEFINED
,
1053 * IB_PORTPHYSSTATE_POLLING (2) through OPA_PORTPHYSSTATE_MAX (11) are
1054 * represented in physical_state_transitions.
1056 #define __N_PHYSTATES (OPA_PORTPHYSSTATE_MAX - IB_PORTPHYSSTATE_POLLING + 1)
1059 * Within physical_state_transitions, rows represent "old" states,
1060 * columns "new" states, and physical_state_transitions.allowed[old][new]
1061 * indicates if the transition from old state to new state is legal (see
1062 * OPAg1v1, Table 6-4).
1064 static const struct {
1065 u8 allowed
[__N_PHYSTATES
][__N_PHYSTATES
];
1066 } physical_state_transitions
= {
1068 /* 2 3 4 5 6 7 8 9 10 11 */
1069 /* 2 */ { __A
, __A
, __D
, __D
, __D
, __D
, __D
, __D
, __D
, __D
},
1070 /* 3 */ { __A
, __I
, __D
, __D
, __D
, __D
, __D
, __D
, __D
, __A
},
1071 /* 4 */ { __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
},
1072 /* 5 */ { __A
, __A
, __D
, __I
, __D
, __D
, __D
, __D
, __D
, __D
},
1073 /* 6 */ { __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
},
1074 /* 7 */ { __D
, __A
, __D
, __D
, __D
, __I
, __D
, __D
, __D
, __D
},
1075 /* 8 */ { __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
},
1076 /* 9 */ { __I
, __A
, __D
, __D
, __D
, __D
, __D
, __I
, __D
, __D
},
1077 /*10 */ { __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
, __U
},
1078 /*11 */ { __D
, __A
, __D
, __D
, __D
, __D
, __D
, __D
, __D
, __I
},
1083 * IB_PORT_DOWN (1) through IB_PORT_ACTIVE_DEFER (5) are represented
1084 * logical_state_transitions
1087 #define __N_LOGICAL_STATES (IB_PORT_ACTIVE_DEFER - IB_PORT_DOWN + 1)
1090 * Within logical_state_transitions rows represent "old" states,
1091 * columns "new" states, and logical_state_transitions.allowed[old][new]
1092 * indicates if the transition from old state to new state is legal (see
1093 * OPAg1v1, Table 9-12).
1095 static const struct {
1096 u8 allowed
[__N_LOGICAL_STATES
][__N_LOGICAL_STATES
];
1097 } logical_state_transitions
= {
1100 /* 1 */ { __I
, __D
, __D
, __D
, __U
},
1101 /* 2 */ { __D
, __I
, __A
, __D
, __U
},
1102 /* 3 */ { __D
, __D
, __I
, __A
, __U
},
1103 /* 4 */ { __D
, __D
, __I
, __I
, __U
},
1104 /* 5 */ { __U
, __U
, __U
, __U
, __U
},
1108 static int logical_transition_allowed(int old
, int new)
1110 if (old
< IB_PORT_NOP
|| old
> IB_PORT_ACTIVE_DEFER
||
1111 new < IB_PORT_NOP
|| new > IB_PORT_ACTIVE_DEFER
) {
1112 pr_warn("invalid logical state(s) (old %d new %d)\n",
1114 return HFI_TRANSITION_UNDEFINED
;
1117 if (new == IB_PORT_NOP
)
1118 return HFI_TRANSITION_ALLOWED
; /* always allowed */
1120 /* adjust states for indexing into logical_state_transitions */
1121 old
-= IB_PORT_DOWN
;
1122 new -= IB_PORT_DOWN
;
1124 if (old
< 0 || new < 0)
1125 return HFI_TRANSITION_UNDEFINED
;
1126 return logical_state_transitions
.allowed
[old
][new];
1129 static int physical_transition_allowed(int old
, int new)
1131 if (old
< IB_PORTPHYSSTATE_NOP
|| old
> OPA_PORTPHYSSTATE_MAX
||
1132 new < IB_PORTPHYSSTATE_NOP
|| new > OPA_PORTPHYSSTATE_MAX
) {
1133 pr_warn("invalid physical state(s) (old %d new %d)\n",
1135 return HFI_TRANSITION_UNDEFINED
;
1138 if (new == IB_PORTPHYSSTATE_NOP
)
1139 return HFI_TRANSITION_ALLOWED
; /* always allowed */
1141 /* adjust states for indexing into physical_state_transitions */
1142 old
-= IB_PORTPHYSSTATE_POLLING
;
1143 new -= IB_PORTPHYSSTATE_POLLING
;
1145 if (old
< 0 || new < 0)
1146 return HFI_TRANSITION_UNDEFINED
;
1147 return physical_state_transitions
.allowed
[old
][new];
1150 static int port_states_transition_allowed(struct hfi1_pportdata
*ppd
,
1151 u32 logical_new
, u32 physical_new
)
1153 u32 physical_old
= driver_pstate(ppd
);
1154 u32 logical_old
= driver_lstate(ppd
);
1155 int ret
, logical_allowed
, physical_allowed
;
1157 ret
= logical_transition_allowed(logical_old
, logical_new
);
1158 logical_allowed
= ret
;
1160 if (ret
== HFI_TRANSITION_DISALLOWED
||
1161 ret
== HFI_TRANSITION_UNDEFINED
) {
1162 pr_warn("invalid logical state transition %s -> %s\n",
1163 opa_lstate_name(logical_old
),
1164 opa_lstate_name(logical_new
));
1168 ret
= physical_transition_allowed(physical_old
, physical_new
);
1169 physical_allowed
= ret
;
1171 if (ret
== HFI_TRANSITION_DISALLOWED
||
1172 ret
== HFI_TRANSITION_UNDEFINED
) {
1173 pr_warn("invalid physical state transition %s -> %s\n",
1174 opa_pstate_name(physical_old
),
1175 opa_pstate_name(physical_new
));
1179 if (logical_allowed
== HFI_TRANSITION_IGNORED
&&
1180 physical_allowed
== HFI_TRANSITION_IGNORED
)
1181 return HFI_TRANSITION_IGNORED
;
1184 * A change request of Physical Port State from
1185 * 'Offline' to 'Polling' should be ignored.
1187 if ((physical_old
== OPA_PORTPHYSSTATE_OFFLINE
) &&
1188 (physical_new
== IB_PORTPHYSSTATE_POLLING
))
1189 return HFI_TRANSITION_IGNORED
;
1192 * Either physical_allowed or logical_allowed is
1193 * HFI_TRANSITION_ALLOWED.
1195 return HFI_TRANSITION_ALLOWED
;
1198 static int set_port_states(struct hfi1_pportdata
*ppd
, struct opa_smp
*smp
,
1199 u32 logical_state
, u32 phys_state
, int local_mad
)
1201 struct hfi1_devdata
*dd
= ppd
->dd
;
1205 ret
= port_states_transition_allowed(ppd
, logical_state
, phys_state
);
1206 if (ret
== HFI_TRANSITION_DISALLOWED
||
1207 ret
== HFI_TRANSITION_UNDEFINED
) {
1208 /* error message emitted above */
1209 smp
->status
|= IB_SMP_INVALID_FIELD
;
1213 if (ret
== HFI_TRANSITION_IGNORED
)
1216 if ((phys_state
!= IB_PORTPHYSSTATE_NOP
) &&
1217 !(logical_state
== IB_PORT_DOWN
||
1218 logical_state
== IB_PORT_NOP
)){
1219 pr_warn("SubnSet(OPA_PortInfo) port state invalid: logical_state 0x%x physical_state 0x%x\n",
1220 logical_state
, phys_state
);
1221 smp
->status
|= IB_SMP_INVALID_FIELD
;
1225 * Logical state changes are summarized in OPAv1g1 spec.,
1226 * Table 9-12; physical state changes are summarized in
1227 * OPAv1g1 spec., Table 6.4.
1229 switch (logical_state
) {
1231 if (phys_state
== IB_PORTPHYSSTATE_NOP
)
1235 if (phys_state
== IB_PORTPHYSSTATE_NOP
) {
1236 link_state
= HLS_DN_DOWNDEF
;
1237 } else if (phys_state
== IB_PORTPHYSSTATE_POLLING
) {
1238 link_state
= HLS_DN_POLL
;
1239 set_link_down_reason(ppd
, OPA_LINKDOWN_REASON_FM_BOUNCE
,
1240 0, OPA_LINKDOWN_REASON_FM_BOUNCE
);
1241 } else if (phys_state
== IB_PORTPHYSSTATE_DISABLED
) {
1242 link_state
= HLS_DN_DISABLE
;
1244 pr_warn("SubnSet(OPA_PortInfo) invalid physical state 0x%x\n",
1246 smp
->status
|= IB_SMP_INVALID_FIELD
;
1250 if ((link_state
== HLS_DN_POLL
||
1251 link_state
== HLS_DN_DOWNDEF
)) {
1253 * Going to poll. No matter what the current state,
1254 * always move offline first, then tune and start the
1255 * link. This correctly handles a FM link bounce and
1256 * a link enable. Going offline is a no-op if already
1259 set_link_state(ppd
, HLS_DN_OFFLINE
);
1262 set_link_state(ppd
, link_state
);
1264 if (link_state
== HLS_DN_DISABLE
&&
1265 (ppd
->offline_disabled_reason
>
1266 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED
) ||
1267 ppd
->offline_disabled_reason
==
1268 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE
)))
1269 ppd
->offline_disabled_reason
=
1270 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED
);
1272 * Don't send a reply if the response would be sent
1273 * through the disabled port.
1275 if (link_state
== HLS_DN_DISABLE
&& !local_mad
)
1276 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_CONSUMED
;
1279 ret
= set_link_state(ppd
, HLS_UP_ARMED
);
1281 send_idle_sma(dd
, SMA_IDLE_ARM
);
1283 case IB_PORT_ACTIVE
:
1284 if (ppd
->neighbor_normal
) {
1285 ret
= set_link_state(ppd
, HLS_UP_ACTIVE
);
1287 send_idle_sma(dd
, SMA_IDLE_ACTIVE
);
1289 pr_warn("SubnSet(OPA_PortInfo) Cannot move to Active with NeighborNormal 0\n");
1290 smp
->status
|= IB_SMP_INVALID_FIELD
;
1294 pr_warn("SubnSet(OPA_PortInfo) invalid logical state 0x%x\n",
1296 smp
->status
|= IB_SMP_INVALID_FIELD
;
1303 * subn_set_opa_portinfo - set port information
1304 * @smp: the incoming SM packet
1305 * @ibdev: the infiniband device
1306 * @port: the port on the device
1309 static int __subn_set_opa_portinfo(struct opa_smp
*smp
, u32 am
, u8
*data
,
1310 struct ib_device
*ibdev
, u32 port
,
1311 u32
*resp_len
, u32 max_len
, int local_mad
)
1313 struct opa_port_info
*pi
= (struct opa_port_info
*)data
;
1314 struct ib_event event
;
1315 struct hfi1_devdata
*dd
;
1316 struct hfi1_pportdata
*ppd
;
1317 struct hfi1_ibport
*ibp
;
1319 unsigned long flags
;
1322 u8 ls_old
, ls_new
, ps_new
;
1327 u32 num_ports
= OPA_AM_NPORT(am
);
1328 u32 start_of_sm_config
= OPA_AM_START_SM_CFG(am
);
1329 int ret
, i
, invalid
= 0, call_set_mtu
= 0;
1330 int call_link_downgrade_policy
= 0;
1332 if (num_ports
!= 1 ||
1333 smp_length_check(sizeof(*pi
), max_len
)) {
1334 smp
->status
|= IB_SMP_INVALID_FIELD
;
1335 return reply((struct ib_mad_hdr
*)smp
);
1338 lid
= be32_to_cpu(pi
->lid
);
1339 if (lid
& 0xFF000000) {
1340 pr_warn("OPA_PortInfo lid out of range: %X\n", lid
);
1341 smp
->status
|= IB_SMP_INVALID_FIELD
;
1346 smlid
= be32_to_cpu(pi
->sm_lid
);
1347 if (smlid
& 0xFF000000) {
1348 pr_warn("OPA_PortInfo SM lid out of range: %X\n", smlid
);
1349 smp
->status
|= IB_SMP_INVALID_FIELD
;
1353 clientrereg
= (pi
->clientrereg_subnettimeout
&
1354 OPA_PI_MASK_CLIENT_REREGISTER
);
1356 dd
= dd_from_ibdev(ibdev
);
1357 /* IB numbers ports from 1, hw from 0 */
1358 ppd
= dd
->pport
+ (port
- 1);
1359 ibp
= &ppd
->ibport_data
;
1360 event
.device
= ibdev
;
1361 event
.element
.port_num
= port
;
1363 ls_old
= driver_lstate(ppd
);
1365 ibp
->rvp
.mkey
= pi
->mkey
;
1366 if (ibp
->rvp
.gid_prefix
!= pi
->subnet_prefix
) {
1367 ibp
->rvp
.gid_prefix
= pi
->subnet_prefix
;
1368 event
.event
= IB_EVENT_GID_CHANGE
;
1369 ib_dispatch_event(&event
);
1371 ibp
->rvp
.mkey_lease_period
= be16_to_cpu(pi
->mkey_lease_period
);
1373 /* Must be a valid unicast LID address. */
1374 if ((lid
== 0 && ls_old
> IB_PORT_INIT
) ||
1375 (hfi1_is_16B_mcast(lid
))) {
1376 smp
->status
|= IB_SMP_INVALID_FIELD
;
1377 pr_warn("SubnSet(OPA_PortInfo) lid invalid 0x%x\n",
1379 } else if (ppd
->lid
!= lid
||
1380 ppd
->lmc
!= (pi
->mkeyprotect_lmc
& OPA_PI_MASK_LMC
)) {
1381 if (ppd
->lid
!= lid
)
1382 hfi1_set_uevent_bits(ppd
, _HFI1_EVENT_LID_CHANGE_BIT
);
1383 if (ppd
->lmc
!= (pi
->mkeyprotect_lmc
& OPA_PI_MASK_LMC
))
1384 hfi1_set_uevent_bits(ppd
, _HFI1_EVENT_LMC_CHANGE_BIT
);
1385 hfi1_set_lid(ppd
, lid
, pi
->mkeyprotect_lmc
& OPA_PI_MASK_LMC
);
1386 event
.event
= IB_EVENT_LID_CHANGE
;
1387 ib_dispatch_event(&event
);
1389 if (HFI1_PORT_GUID_INDEX
+ 1 < HFI1_GUIDS_PER_PORT
) {
1390 /* Manufacture GID from LID to support extended
1393 ppd
->guids
[HFI1_PORT_GUID_INDEX
+ 1] =
1394 be64_to_cpu(OPA_MAKE_ID(lid
));
1395 event
.event
= IB_EVENT_GID_CHANGE
;
1396 ib_dispatch_event(&event
);
1400 msl
= pi
->smsl
& OPA_PI_MASK_SMSL
;
1401 if (pi
->partenforce_filterraw
& OPA_PI_MASK_LINKINIT_REASON
)
1402 ppd
->linkinit_reason
=
1403 (pi
->partenforce_filterraw
&
1404 OPA_PI_MASK_LINKINIT_REASON
);
1406 /* Must be a valid unicast LID address. */
1407 if ((smlid
== 0 && ls_old
> IB_PORT_INIT
) ||
1408 (hfi1_is_16B_mcast(smlid
))) {
1409 smp
->status
|= IB_SMP_INVALID_FIELD
;
1410 pr_warn("SubnSet(OPA_PortInfo) smlid invalid 0x%x\n", smlid
);
1411 } else if (smlid
!= ibp
->rvp
.sm_lid
|| msl
!= ibp
->rvp
.sm_sl
) {
1412 pr_warn("SubnSet(OPA_PortInfo) smlid 0x%x\n", smlid
);
1413 spin_lock_irqsave(&ibp
->rvp
.lock
, flags
);
1414 if (ibp
->rvp
.sm_ah
) {
1415 if (smlid
!= ibp
->rvp
.sm_lid
)
1416 hfi1_modify_qp0_ah(ibp
, ibp
->rvp
.sm_ah
, smlid
);
1417 if (msl
!= ibp
->rvp
.sm_sl
)
1418 rdma_ah_set_sl(&ibp
->rvp
.sm_ah
->attr
, msl
);
1420 spin_unlock_irqrestore(&ibp
->rvp
.lock
, flags
);
1421 if (smlid
!= ibp
->rvp
.sm_lid
)
1422 ibp
->rvp
.sm_lid
= smlid
;
1423 if (msl
!= ibp
->rvp
.sm_sl
)
1424 ibp
->rvp
.sm_sl
= msl
;
1425 event
.event
= IB_EVENT_SM_CHANGE
;
1426 ib_dispatch_event(&event
);
1429 if (pi
->link_down_reason
== 0) {
1430 ppd
->local_link_down_reason
.sma
= 0;
1431 ppd
->local_link_down_reason
.latest
= 0;
1434 if (pi
->neigh_link_down_reason
== 0) {
1435 ppd
->neigh_link_down_reason
.sma
= 0;
1436 ppd
->neigh_link_down_reason
.latest
= 0;
1439 ppd
->sm_trap_qp
= be32_to_cpu(pi
->sm_trap_qp
);
1440 ppd
->sa_qp
= be32_to_cpu(pi
->sa_qp
);
1442 ppd
->port_error_action
= be32_to_cpu(pi
->port_error_action
);
1443 lwe
= be16_to_cpu(pi
->link_width
.enabled
);
1445 if (lwe
== OPA_LINK_WIDTH_RESET
||
1446 lwe
== OPA_LINK_WIDTH_RESET_OLD
)
1447 set_link_width_enabled(ppd
, ppd
->link_width_supported
);
1448 else if ((lwe
& ~ppd
->link_width_supported
) == 0)
1449 set_link_width_enabled(ppd
, lwe
);
1451 smp
->status
|= IB_SMP_INVALID_FIELD
;
1453 lwe
= be16_to_cpu(pi
->link_width_downgrade
.enabled
);
1454 /* LWD.E is always applied - 0 means "disabled" */
1455 if (lwe
== OPA_LINK_WIDTH_RESET
||
1456 lwe
== OPA_LINK_WIDTH_RESET_OLD
) {
1457 set_link_width_downgrade_enabled(ppd
,
1459 link_width_downgrade_supported
1461 } else if ((lwe
& ~ppd
->link_width_downgrade_supported
) == 0) {
1462 /* only set and apply if something changed */
1463 if (lwe
!= ppd
->link_width_downgrade_enabled
) {
1464 set_link_width_downgrade_enabled(ppd
, lwe
);
1465 call_link_downgrade_policy
= 1;
1468 smp
->status
|= IB_SMP_INVALID_FIELD
;
1470 lse
= be16_to_cpu(pi
->link_speed
.enabled
);
1472 if (lse
& be16_to_cpu(pi
->link_speed
.supported
))
1473 set_link_speed_enabled(ppd
, lse
);
1475 smp
->status
|= IB_SMP_INVALID_FIELD
;
1479 (pi
->mkeyprotect_lmc
& OPA_PI_MASK_MKEY_PROT_BIT
) >> 6;
1480 ibp
->rvp
.vl_high_limit
= be16_to_cpu(pi
->vl
.high_limit
) & 0xFF;
1481 (void)hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_VL_HIGH_LIMIT
,
1482 ibp
->rvp
.vl_high_limit
);
1484 if (ppd
->vls_supported
/ 2 > ARRAY_SIZE(pi
->neigh_mtu
.pvlx_to_mtu
) ||
1485 ppd
->vls_supported
> ARRAY_SIZE(dd
->vld
)) {
1486 smp
->status
|= IB_SMP_INVALID_FIELD
;
1487 return reply((struct ib_mad_hdr
*)smp
);
1489 for (i
= 0; i
< ppd
->vls_supported
; i
++) {
1491 mtu
= enum_to_mtu((pi
->neigh_mtu
.pvlx_to_mtu
[i
/ 2] >>
1494 mtu
= enum_to_mtu(pi
->neigh_mtu
.pvlx_to_mtu
[i
/ 2] &
1496 if (mtu
== 0xffff) {
1497 pr_warn("SubnSet(OPA_PortInfo) mtu invalid %d (0x%x)\n",
1499 (pi
->neigh_mtu
.pvlx_to_mtu
[0] >> 4) & 0xF);
1500 smp
->status
|= IB_SMP_INVALID_FIELD
;
1501 mtu
= hfi1_max_mtu
; /* use a valid MTU */
1503 if (dd
->vld
[i
].mtu
!= mtu
) {
1505 "MTU change on vl %d from %d to %d\n",
1506 i
, dd
->vld
[i
].mtu
, mtu
);
1507 dd
->vld
[i
].mtu
= mtu
;
1511 /* As per OPAV1 spec: VL15 must support and be configured
1512 * for operation with a 2048 or larger MTU.
1514 mtu
= enum_to_mtu(pi
->neigh_mtu
.pvlx_to_mtu
[15 / 2] & 0xF);
1515 if (mtu
< 2048 || mtu
== 0xffff)
1517 if (dd
->vld
[15].mtu
!= mtu
) {
1519 "MTU change on vl 15 from %d to %d\n",
1520 dd
->vld
[15].mtu
, mtu
);
1521 dd
->vld
[15].mtu
= mtu
;
1527 /* Set operational VLs */
1528 vls
= pi
->operational_vls
& OPA_PI_MASK_OPERATIONAL_VL
;
1530 if (vls
> ppd
->vls_supported
) {
1531 pr_warn("SubnSet(OPA_PortInfo) VL's supported invalid %d\n",
1532 pi
->operational_vls
);
1533 smp
->status
|= IB_SMP_INVALID_FIELD
;
1535 if (hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_OP_VLS
,
1537 smp
->status
|= IB_SMP_INVALID_FIELD
;
1541 if (pi
->mkey_violations
== 0)
1542 ibp
->rvp
.mkey_violations
= 0;
1544 if (pi
->pkey_violations
== 0)
1545 ibp
->rvp
.pkey_violations
= 0;
1547 if (pi
->qkey_violations
== 0)
1548 ibp
->rvp
.qkey_violations
= 0;
1550 ibp
->rvp
.subnet_timeout
=
1551 pi
->clientrereg_subnettimeout
& OPA_PI_MASK_SUBNET_TIMEOUT
;
1553 crc_enabled
= be16_to_cpu(pi
->port_ltp_crc_mode
);
1557 if (crc_enabled
!= 0)
1558 ppd
->port_crc_mode_enabled
= port_ltp_to_cap(crc_enabled
);
1560 ppd
->is_active_optimize_enabled
=
1561 !!(be16_to_cpu(pi
->port_mode
)
1562 & OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE
);
1564 ls_new
= pi
->port_states
.portphysstate_portstate
&
1565 OPA_PI_MASK_PORT_STATE
;
1566 ps_new
= (pi
->port_states
.portphysstate_portstate
&
1567 OPA_PI_MASK_PORT_PHYSICAL_STATE
) >> 4;
1569 if (ls_old
== IB_PORT_INIT
) {
1570 if (start_of_sm_config
) {
1571 if (ls_new
== ls_old
|| (ls_new
== IB_PORT_ARMED
))
1572 ppd
->is_sm_config_started
= 1;
1573 } else if (ls_new
== IB_PORT_ARMED
) {
1574 if (ppd
->is_sm_config_started
== 0) {
1576 smp
->status
|= IB_SMP_INVALID_FIELD
;
1581 /* Handle CLIENT_REREGISTER event b/c SM asked us for it */
1583 event
.event
= IB_EVENT_CLIENT_REREGISTER
;
1584 ib_dispatch_event(&event
);
1588 * Do the port state change now that the other link parameters
1590 * Changing the port physical state only makes sense if the link
1591 * is down or is being set to down.
1595 ret
= set_port_states(ppd
, smp
, ls_new
, ps_new
, local_mad
);
1600 ret
= __subn_get_opa_portinfo(smp
, am
, data
, ibdev
, port
, resp_len
,
1603 /* restore re-reg bit per o14-12.2.1 */
1604 pi
->clientrereg_subnettimeout
|= clientrereg
;
1607 * Apply the new link downgrade policy. This may result in a link
1608 * bounce. Do this after everything else so things are settled.
1609 * Possible problem: if setting the port state above fails, then
1610 * the policy change is not applied.
1612 if (call_link_downgrade_policy
)
1613 apply_link_downgrade_policy(ppd
, 0);
1618 return __subn_get_opa_portinfo(smp
, am
, data
, ibdev
, port
, resp_len
,
1623 * set_pkeys - set the PKEY table for ctxt 0
1624 * @dd: the hfi1_ib device
1625 * @port: the IB port number
1626 * @pkeys: the PKEY table
1628 static int set_pkeys(struct hfi1_devdata
*dd
, u32 port
, u16
*pkeys
)
1630 struct hfi1_pportdata
*ppd
;
1633 int update_includes_mgmt_partition
= 0;
1636 * IB port one/two always maps to context zero/one,
1637 * always a kernel context, no locking needed
1638 * If we get here with ppd setup, no need to check
1639 * that rcd is valid.
1641 ppd
= dd
->pport
+ (port
- 1);
1643 * If the update does not include the management pkey, don't do it.
1645 for (i
= 0; i
< ARRAY_SIZE(ppd
->pkeys
); i
++) {
1646 if (pkeys
[i
] == LIM_MGMT_P_KEY
) {
1647 update_includes_mgmt_partition
= 1;
1652 if (!update_includes_mgmt_partition
)
1655 for (i
= 0; i
< ARRAY_SIZE(ppd
->pkeys
); i
++) {
1657 u16 okey
= ppd
->pkeys
[i
];
1662 * The SM gives us the complete PKey table. We have
1663 * to ensure that we put the PKeys in the matching
1666 ppd
->pkeys
[i
] = key
;
1671 (void)hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_PKEYS
, 0);
1672 hfi1_event_pkey_change(dd
, port
);
1678 static int __subn_set_opa_pkeytable(struct opa_smp
*smp
, u32 am
, u8
*data
,
1679 struct ib_device
*ibdev
, u32 port
,
1680 u32
*resp_len
, u32 max_len
)
1682 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1683 u32 n_blocks_sent
= OPA_AM_NBLK(am
);
1684 u32 start_block
= am
& 0x7ff;
1685 u16
*p
= (u16
*)data
;
1686 __be16
*q
= (__be16
*)data
;
1689 unsigned npkeys
= hfi1_get_npkeys(dd
);
1692 if (n_blocks_sent
== 0) {
1693 pr_warn("OPA Get PKey AM Invalid : P = %u; B = 0x%x; N = 0x%x\n",
1694 port
, start_block
, n_blocks_sent
);
1695 smp
->status
|= IB_SMP_INVALID_FIELD
;
1696 return reply((struct ib_mad_hdr
*)smp
);
1699 n_blocks_avail
= (u16
)(npkeys
/ OPA_PARTITION_TABLE_BLK_SIZE
) + 1;
1701 size
= sizeof(u16
) * (n_blocks_sent
* OPA_PARTITION_TABLE_BLK_SIZE
);
1703 if (smp_length_check(size
, max_len
)) {
1704 smp
->status
|= IB_SMP_INVALID_FIELD
;
1705 return reply((struct ib_mad_hdr
*)smp
);
1708 if (start_block
+ n_blocks_sent
> n_blocks_avail
||
1709 n_blocks_sent
> OPA_NUM_PKEY_BLOCKS_PER_SMP
) {
1710 pr_warn("OPA Set PKey AM Invalid : s 0x%x; req 0x%x; avail 0x%x; blk/smp 0x%lx\n",
1711 start_block
, n_blocks_sent
, n_blocks_avail
,
1712 OPA_NUM_PKEY_BLOCKS_PER_SMP
);
1713 smp
->status
|= IB_SMP_INVALID_FIELD
;
1714 return reply((struct ib_mad_hdr
*)smp
);
1717 for (i
= 0; i
< n_blocks_sent
* OPA_PARTITION_TABLE_BLK_SIZE
; i
++)
1718 p
[i
] = be16_to_cpu(q
[i
]);
1720 if (start_block
== 0 && set_pkeys(dd
, port
, p
) != 0) {
1721 smp
->status
|= IB_SMP_INVALID_FIELD
;
1722 return reply((struct ib_mad_hdr
*)smp
);
1725 return __subn_get_opa_pkeytable(smp
, am
, data
, ibdev
, port
, resp_len
,
1729 #define ILLEGAL_VL 12
1731 * filter_sc2vlt changes mappings to VL15 to ILLEGAL_VL (except
1732 * for SC15, which must map to VL15). If we don't remap things this
1733 * way it is possible for VL15 counters to increment when we try to
1734 * send on a SC which is mapped to an invalid VL.
1735 * When getting the table convert ILLEGAL_VL back to VL15.
1737 static void filter_sc2vlt(void *data
, bool set
)
1742 for (i
= 0; i
< OPA_MAX_SCS
; i
++) {
1747 if ((pd
[i
] & 0x1f) == 0xf)
1750 if ((pd
[i
] & 0x1f) == ILLEGAL_VL
)
1756 static int set_sc2vlt_tables(struct hfi1_devdata
*dd
, void *data
)
1760 filter_sc2vlt(data
, true);
1762 write_csr(dd
, SEND_SC2VLT0
, *val
++);
1763 write_csr(dd
, SEND_SC2VLT1
, *val
++);
1764 write_csr(dd
, SEND_SC2VLT2
, *val
++);
1765 write_csr(dd
, SEND_SC2VLT3
, *val
++);
1766 write_seqlock_irq(&dd
->sc2vl_lock
);
1767 memcpy(dd
->sc2vl
, data
, sizeof(dd
->sc2vl
));
1768 write_sequnlock_irq(&dd
->sc2vl_lock
);
1772 static int get_sc2vlt_tables(struct hfi1_devdata
*dd
, void *data
)
1774 u64
*val
= (u64
*)data
;
1776 *val
++ = read_csr(dd
, SEND_SC2VLT0
);
1777 *val
++ = read_csr(dd
, SEND_SC2VLT1
);
1778 *val
++ = read_csr(dd
, SEND_SC2VLT2
);
1779 *val
++ = read_csr(dd
, SEND_SC2VLT3
);
1781 filter_sc2vlt((u64
*)data
, false);
1785 static int __subn_get_opa_sl_to_sc(struct opa_smp
*smp
, u32 am
, u8
*data
,
1786 struct ib_device
*ibdev
, u32 port
,
1787 u32
*resp_len
, u32 max_len
)
1789 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
1791 size_t size
= ARRAY_SIZE(ibp
->sl_to_sc
); /* == 32 */
1794 if (am
|| smp_length_check(size
, max_len
)) {
1795 smp
->status
|= IB_SMP_INVALID_FIELD
;
1796 return reply((struct ib_mad_hdr
*)smp
);
1799 for (i
= 0; i
< ARRAY_SIZE(ibp
->sl_to_sc
); i
++)
1800 *p
++ = ibp
->sl_to_sc
[i
];
1805 return reply((struct ib_mad_hdr
*)smp
);
1808 static int __subn_set_opa_sl_to_sc(struct opa_smp
*smp
, u32 am
, u8
*data
,
1809 struct ib_device
*ibdev
, u32 port
,
1810 u32
*resp_len
, u32 max_len
)
1812 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
1814 size_t size
= ARRAY_SIZE(ibp
->sl_to_sc
);
1818 if (am
|| smp_length_check(size
, max_len
)) {
1819 smp
->status
|= IB_SMP_INVALID_FIELD
;
1820 return reply((struct ib_mad_hdr
*)smp
);
1823 for (i
= 0; i
< ARRAY_SIZE(ibp
->sl_to_sc
); i
++) {
1825 if (ibp
->sl_to_sc
[i
] != sc
) {
1826 ibp
->sl_to_sc
[i
] = sc
;
1828 /* Put all stale qps into error state */
1829 hfi1_error_port_qps(ibp
, i
);
1833 return __subn_get_opa_sl_to_sc(smp
, am
, data
, ibdev
, port
, resp_len
,
1837 static int __subn_get_opa_sc_to_sl(struct opa_smp
*smp
, u32 am
, u8
*data
,
1838 struct ib_device
*ibdev
, u32 port
,
1839 u32
*resp_len
, u32 max_len
)
1841 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
1843 size_t size
= ARRAY_SIZE(ibp
->sc_to_sl
); /* == 32 */
1846 if (am
|| smp_length_check(size
, max_len
)) {
1847 smp
->status
|= IB_SMP_INVALID_FIELD
;
1848 return reply((struct ib_mad_hdr
*)smp
);
1851 for (i
= 0; i
< ARRAY_SIZE(ibp
->sc_to_sl
); i
++)
1852 *p
++ = ibp
->sc_to_sl
[i
];
1857 return reply((struct ib_mad_hdr
*)smp
);
1860 static int __subn_set_opa_sc_to_sl(struct opa_smp
*smp
, u32 am
, u8
*data
,
1861 struct ib_device
*ibdev
, u32 port
,
1862 u32
*resp_len
, u32 max_len
)
1864 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
1865 size_t size
= ARRAY_SIZE(ibp
->sc_to_sl
);
1869 if (am
|| smp_length_check(size
, max_len
)) {
1870 smp
->status
|= IB_SMP_INVALID_FIELD
;
1871 return reply((struct ib_mad_hdr
*)smp
);
1874 for (i
= 0; i
< ARRAY_SIZE(ibp
->sc_to_sl
); i
++)
1875 ibp
->sc_to_sl
[i
] = *p
++;
1877 return __subn_get_opa_sc_to_sl(smp
, am
, data
, ibdev
, port
, resp_len
,
1881 static int __subn_get_opa_sc_to_vlt(struct opa_smp
*smp
, u32 am
, u8
*data
,
1882 struct ib_device
*ibdev
, u32 port
,
1883 u32
*resp_len
, u32 max_len
)
1885 u32 n_blocks
= OPA_AM_NBLK(am
);
1886 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1887 void *vp
= (void *)data
;
1888 size_t size
= 4 * sizeof(u64
);
1890 if (n_blocks
!= 1 || smp_length_check(size
, max_len
)) {
1891 smp
->status
|= IB_SMP_INVALID_FIELD
;
1892 return reply((struct ib_mad_hdr
*)smp
);
1895 get_sc2vlt_tables(dd
, vp
);
1900 return reply((struct ib_mad_hdr
*)smp
);
1903 static int __subn_set_opa_sc_to_vlt(struct opa_smp
*smp
, u32 am
, u8
*data
,
1904 struct ib_device
*ibdev
, u32 port
,
1905 u32
*resp_len
, u32 max_len
)
1907 u32 n_blocks
= OPA_AM_NBLK(am
);
1908 int async_update
= OPA_AM_ASYNC(am
);
1909 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1910 void *vp
= (void *)data
;
1911 struct hfi1_pportdata
*ppd
;
1914 * set_sc2vlt_tables writes the information contained in *data
1915 * to four 64-bit registers SendSC2VLt[0-3]. We need to make
1916 * sure *max_len is not greater than the total size of the four
1917 * SendSC2VLt[0-3] registers.
1919 size_t size
= 4 * sizeof(u64
);
1921 if (n_blocks
!= 1 || async_update
|| smp_length_check(size
, max_len
)) {
1922 smp
->status
|= IB_SMP_INVALID_FIELD
;
1923 return reply((struct ib_mad_hdr
*)smp
);
1926 /* IB numbers ports from 1, hw from 0 */
1927 ppd
= dd
->pport
+ (port
- 1);
1928 lstate
= driver_lstate(ppd
);
1930 * it's known that async_update is 0 by this point, but include
1931 * the explicit check for clarity
1933 if (!async_update
&&
1934 (lstate
== IB_PORT_ARMED
|| lstate
== IB_PORT_ACTIVE
)) {
1935 smp
->status
|= IB_SMP_INVALID_FIELD
;
1936 return reply((struct ib_mad_hdr
*)smp
);
1939 set_sc2vlt_tables(dd
, vp
);
1941 return __subn_get_opa_sc_to_vlt(smp
, am
, data
, ibdev
, port
, resp_len
,
1945 static int __subn_get_opa_sc_to_vlnt(struct opa_smp
*smp
, u32 am
, u8
*data
,
1946 struct ib_device
*ibdev
, u32 port
,
1947 u32
*resp_len
, u32 max_len
)
1949 u32 n_blocks
= OPA_AM_NPORT(am
);
1950 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1951 struct hfi1_pportdata
*ppd
;
1952 void *vp
= (void *)data
;
1953 int size
= sizeof(struct sc2vlnt
);
1955 if (n_blocks
!= 1 || smp_length_check(size
, max_len
)) {
1956 smp
->status
|= IB_SMP_INVALID_FIELD
;
1957 return reply((struct ib_mad_hdr
*)smp
);
1960 ppd
= dd
->pport
+ (port
- 1);
1962 fm_get_table(ppd
, FM_TBL_SC2VLNT
, vp
);
1967 return reply((struct ib_mad_hdr
*)smp
);
1970 static int __subn_set_opa_sc_to_vlnt(struct opa_smp
*smp
, u32 am
, u8
*data
,
1971 struct ib_device
*ibdev
, u32 port
,
1972 u32
*resp_len
, u32 max_len
)
1974 u32 n_blocks
= OPA_AM_NPORT(am
);
1975 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
1976 struct hfi1_pportdata
*ppd
;
1977 void *vp
= (void *)data
;
1979 int size
= sizeof(struct sc2vlnt
);
1981 if (n_blocks
!= 1 || smp_length_check(size
, max_len
)) {
1982 smp
->status
|= IB_SMP_INVALID_FIELD
;
1983 return reply((struct ib_mad_hdr
*)smp
);
1986 /* IB numbers ports from 1, hw from 0 */
1987 ppd
= dd
->pport
+ (port
- 1);
1988 lstate
= driver_lstate(ppd
);
1989 if (lstate
== IB_PORT_ARMED
|| lstate
== IB_PORT_ACTIVE
) {
1990 smp
->status
|= IB_SMP_INVALID_FIELD
;
1991 return reply((struct ib_mad_hdr
*)smp
);
1994 ppd
= dd
->pport
+ (port
- 1);
1996 fm_set_table(ppd
, FM_TBL_SC2VLNT
, vp
);
1998 return __subn_get_opa_sc_to_vlnt(smp
, am
, data
, ibdev
, port
,
2002 static int __subn_get_opa_psi(struct opa_smp
*smp
, u32 am
, u8
*data
,
2003 struct ib_device
*ibdev
, u32 port
,
2004 u32
*resp_len
, u32 max_len
)
2006 u32 nports
= OPA_AM_NPORT(am
);
2007 u32 start_of_sm_config
= OPA_AM_START_SM_CFG(am
);
2009 struct hfi1_ibport
*ibp
;
2010 struct hfi1_pportdata
*ppd
;
2011 struct opa_port_state_info
*psi
= (struct opa_port_state_info
*)data
;
2013 if (nports
!= 1 || smp_length_check(sizeof(*psi
), max_len
)) {
2014 smp
->status
|= IB_SMP_INVALID_FIELD
;
2015 return reply((struct ib_mad_hdr
*)smp
);
2018 ibp
= to_iport(ibdev
, port
);
2019 ppd
= ppd_from_ibp(ibp
);
2021 lstate
= driver_lstate(ppd
);
2023 if (start_of_sm_config
&& (lstate
== IB_PORT_INIT
))
2024 ppd
->is_sm_config_started
= 1;
2026 psi
->port_states
.ledenable_offlinereason
= ppd
->neighbor_normal
<< 4;
2027 psi
->port_states
.ledenable_offlinereason
|=
2028 ppd
->is_sm_config_started
<< 5;
2029 psi
->port_states
.ledenable_offlinereason
|=
2030 ppd
->offline_disabled_reason
;
2032 psi
->port_states
.portphysstate_portstate
=
2033 (driver_pstate(ppd
) << 4) | (lstate
& 0xf);
2034 psi
->link_width_downgrade_tx_active
=
2035 cpu_to_be16(ppd
->link_width_downgrade_tx_active
);
2036 psi
->link_width_downgrade_rx_active
=
2037 cpu_to_be16(ppd
->link_width_downgrade_rx_active
);
2039 *resp_len
+= sizeof(struct opa_port_state_info
);
2041 return reply((struct ib_mad_hdr
*)smp
);
2044 static int __subn_set_opa_psi(struct opa_smp
*smp
, u32 am
, u8
*data
,
2045 struct ib_device
*ibdev
, u32 port
,
2046 u32
*resp_len
, u32 max_len
, int local_mad
)
2048 u32 nports
= OPA_AM_NPORT(am
);
2049 u32 start_of_sm_config
= OPA_AM_START_SM_CFG(am
);
2052 struct hfi1_ibport
*ibp
;
2053 struct hfi1_pportdata
*ppd
;
2054 struct opa_port_state_info
*psi
= (struct opa_port_state_info
*)data
;
2055 int ret
, invalid
= 0;
2057 if (nports
!= 1 || smp_length_check(sizeof(*psi
), max_len
)) {
2058 smp
->status
|= IB_SMP_INVALID_FIELD
;
2059 return reply((struct ib_mad_hdr
*)smp
);
2062 ibp
= to_iport(ibdev
, port
);
2063 ppd
= ppd_from_ibp(ibp
);
2065 ls_old
= driver_lstate(ppd
);
2067 ls_new
= port_states_to_logical_state(&psi
->port_states
);
2068 ps_new
= port_states_to_phys_state(&psi
->port_states
);
2070 if (ls_old
== IB_PORT_INIT
) {
2071 if (start_of_sm_config
) {
2072 if (ls_new
== ls_old
|| (ls_new
== IB_PORT_ARMED
))
2073 ppd
->is_sm_config_started
= 1;
2074 } else if (ls_new
== IB_PORT_ARMED
) {
2075 if (ppd
->is_sm_config_started
== 0) {
2077 smp
->status
|= IB_SMP_INVALID_FIELD
;
2083 ret
= set_port_states(ppd
, smp
, ls_new
, ps_new
, local_mad
);
2088 return __subn_get_opa_psi(smp
, am
, data
, ibdev
, port
, resp_len
,
2092 static int __subn_get_opa_cable_info(struct opa_smp
*smp
, u32 am
, u8
*data
,
2093 struct ib_device
*ibdev
, u32 port
,
2094 u32
*resp_len
, u32 max_len
)
2096 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2097 u32 addr
= OPA_AM_CI_ADDR(am
);
2098 u32 len
= OPA_AM_CI_LEN(am
) + 1;
2101 if (dd
->pport
->port_type
!= PORT_TYPE_QSFP
||
2102 smp_length_check(len
, max_len
)) {
2103 smp
->status
|= IB_SMP_INVALID_FIELD
;
2104 return reply((struct ib_mad_hdr
*)smp
);
2107 #define __CI_PAGE_SIZE BIT(7) /* 128 bytes */
2108 #define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1)
2109 #define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK)
2112 * check that addr is within spec, and
2113 * addr and (addr + len - 1) are on the same "page"
2116 (__CI_PAGE_NUM(addr
) != __CI_PAGE_NUM(addr
+ len
- 1))) {
2117 smp
->status
|= IB_SMP_INVALID_FIELD
;
2118 return reply((struct ib_mad_hdr
*)smp
);
2121 ret
= get_cable_info(dd
, port
, addr
, len
, data
);
2123 if (ret
== -ENODEV
) {
2124 smp
->status
|= IB_SMP_UNSUP_METH_ATTR
;
2125 return reply((struct ib_mad_hdr
*)smp
);
2128 /* The address range for the CableInfo SMA query is wider than the
2129 * memory available on the QSFP cable. We want to return a valid
2130 * response, albeit zeroed out, for address ranges beyond available
2131 * memory but that are within the CableInfo query spec
2133 if (ret
< 0 && ret
!= -ERANGE
) {
2134 smp
->status
|= IB_SMP_INVALID_FIELD
;
2135 return reply((struct ib_mad_hdr
*)smp
);
2141 return reply((struct ib_mad_hdr
*)smp
);
2144 static int __subn_get_opa_bct(struct opa_smp
*smp
, u32 am
, u8
*data
,
2145 struct ib_device
*ibdev
, u32 port
, u32
*resp_len
,
2148 u32 num_ports
= OPA_AM_NPORT(am
);
2149 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2150 struct hfi1_pportdata
*ppd
;
2151 struct buffer_control
*p
= (struct buffer_control
*)data
;
2152 int size
= sizeof(struct buffer_control
);
2154 if (num_ports
!= 1 || smp_length_check(size
, max_len
)) {
2155 smp
->status
|= IB_SMP_INVALID_FIELD
;
2156 return reply((struct ib_mad_hdr
*)smp
);
2159 ppd
= dd
->pport
+ (port
- 1);
2160 fm_get_table(ppd
, FM_TBL_BUFFER_CONTROL
, p
);
2161 trace_bct_get(dd
, p
);
2165 return reply((struct ib_mad_hdr
*)smp
);
2168 static int __subn_set_opa_bct(struct opa_smp
*smp
, u32 am
, u8
*data
,
2169 struct ib_device
*ibdev
, u32 port
, u32
*resp_len
,
2172 u32 num_ports
= OPA_AM_NPORT(am
);
2173 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2174 struct hfi1_pportdata
*ppd
;
2175 struct buffer_control
*p
= (struct buffer_control
*)data
;
2177 if (num_ports
!= 1 || smp_length_check(sizeof(*p
), max_len
)) {
2178 smp
->status
|= IB_SMP_INVALID_FIELD
;
2179 return reply((struct ib_mad_hdr
*)smp
);
2181 ppd
= dd
->pport
+ (port
- 1);
2182 trace_bct_set(dd
, p
);
2183 if (fm_set_table(ppd
, FM_TBL_BUFFER_CONTROL
, p
) < 0) {
2184 smp
->status
|= IB_SMP_INVALID_FIELD
;
2185 return reply((struct ib_mad_hdr
*)smp
);
2188 return __subn_get_opa_bct(smp
, am
, data
, ibdev
, port
, resp_len
,
2192 static int __subn_get_opa_vl_arb(struct opa_smp
*smp
, u32 am
, u8
*data
,
2193 struct ib_device
*ibdev
, u32 port
,
2194 u32
*resp_len
, u32 max_len
)
2196 struct hfi1_pportdata
*ppd
= ppd_from_ibp(to_iport(ibdev
, port
));
2197 u32 num_ports
= OPA_AM_NPORT(am
);
2198 u8 section
= (am
& 0x00ff0000) >> 16;
2202 if (num_ports
!= 1 || smp_length_check(size
, max_len
)) {
2203 smp
->status
|= IB_SMP_INVALID_FIELD
;
2204 return reply((struct ib_mad_hdr
*)smp
);
2208 case OPA_VLARB_LOW_ELEMENTS
:
2209 fm_get_table(ppd
, FM_TBL_VL_LOW_ARB
, p
);
2211 case OPA_VLARB_HIGH_ELEMENTS
:
2212 fm_get_table(ppd
, FM_TBL_VL_HIGH_ARB
, p
);
2214 case OPA_VLARB_PREEMPT_ELEMENTS
:
2215 fm_get_table(ppd
, FM_TBL_VL_PREEMPT_ELEMS
, p
);
2217 case OPA_VLARB_PREEMPT_MATRIX
:
2218 fm_get_table(ppd
, FM_TBL_VL_PREEMPT_MATRIX
, p
);
2221 pr_warn("OPA SubnGet(VL Arb) AM Invalid : 0x%x\n",
2222 be32_to_cpu(smp
->attr_mod
));
2223 smp
->status
|= IB_SMP_INVALID_FIELD
;
2228 if (size
> 0 && resp_len
)
2231 return reply((struct ib_mad_hdr
*)smp
);
2234 static int __subn_set_opa_vl_arb(struct opa_smp
*smp
, u32 am
, u8
*data
,
2235 struct ib_device
*ibdev
, u32 port
,
2236 u32
*resp_len
, u32 max_len
)
2238 struct hfi1_pportdata
*ppd
= ppd_from_ibp(to_iport(ibdev
, port
));
2239 u32 num_ports
= OPA_AM_NPORT(am
);
2240 u8 section
= (am
& 0x00ff0000) >> 16;
2244 if (num_ports
!= 1 || smp_length_check(size
, max_len
)) {
2245 smp
->status
|= IB_SMP_INVALID_FIELD
;
2246 return reply((struct ib_mad_hdr
*)smp
);
2250 case OPA_VLARB_LOW_ELEMENTS
:
2251 (void)fm_set_table(ppd
, FM_TBL_VL_LOW_ARB
, p
);
2253 case OPA_VLARB_HIGH_ELEMENTS
:
2254 (void)fm_set_table(ppd
, FM_TBL_VL_HIGH_ARB
, p
);
2257 * neither OPA_VLARB_PREEMPT_ELEMENTS, or OPA_VLARB_PREEMPT_MATRIX
2258 * can be changed from the default values
2260 case OPA_VLARB_PREEMPT_ELEMENTS
:
2261 case OPA_VLARB_PREEMPT_MATRIX
:
2262 smp
->status
|= IB_SMP_UNSUP_METH_ATTR
;
2265 pr_warn("OPA SubnSet(VL Arb) AM Invalid : 0x%x\n",
2266 be32_to_cpu(smp
->attr_mod
));
2267 smp
->status
|= IB_SMP_INVALID_FIELD
;
2271 return __subn_get_opa_vl_arb(smp
, am
, data
, ibdev
, port
, resp_len
,
2275 struct opa_pma_mad
{
2276 struct ib_mad_hdr mad_hdr
;
2280 struct opa_port_status_req
{
2283 __be32 vl_select_mask
;
2286 #define VL_MASK_ALL 0x00000000000080ffUL
2288 struct opa_port_status_rsp
{
2291 __be32 vl_select_mask
;
2294 __be64 port_xmit_data
;
2295 __be64 port_rcv_data
;
2296 __be64 port_xmit_pkts
;
2297 __be64 port_rcv_pkts
;
2298 __be64 port_multicast_xmit_pkts
;
2299 __be64 port_multicast_rcv_pkts
;
2300 __be64 port_xmit_wait
;
2301 __be64 sw_port_congestion
;
2302 __be64 port_rcv_fecn
;
2303 __be64 port_rcv_becn
;
2304 __be64 port_xmit_time_cong
;
2305 __be64 port_xmit_wasted_bw
;
2306 __be64 port_xmit_wait_data
;
2307 __be64 port_rcv_bubble
;
2308 __be64 port_mark_fecn
;
2309 /* Error counters */
2310 __be64 port_rcv_constraint_errors
;
2311 __be64 port_rcv_switch_relay_errors
;
2312 __be64 port_xmit_discards
;
2313 __be64 port_xmit_constraint_errors
;
2314 __be64 port_rcv_remote_physical_errors
;
2315 __be64 local_link_integrity_errors
;
2316 __be64 port_rcv_errors
;
2317 __be64 excessive_buffer_overruns
;
2318 __be64 fm_config_errors
;
2319 __be32 link_error_recovery
;
2321 u8 uncorrectable_errors
;
2323 u8 link_quality_indicator
; /* 5res, 3bit */
2326 /* per-VL Data counters */
2327 __be64 port_vl_xmit_data
;
2328 __be64 port_vl_rcv_data
;
2329 __be64 port_vl_xmit_pkts
;
2330 __be64 port_vl_rcv_pkts
;
2331 __be64 port_vl_xmit_wait
;
2332 __be64 sw_port_vl_congestion
;
2333 __be64 port_vl_rcv_fecn
;
2334 __be64 port_vl_rcv_becn
;
2335 __be64 port_xmit_time_cong
;
2336 __be64 port_vl_xmit_wasted_bw
;
2337 __be64 port_vl_xmit_wait_data
;
2338 __be64 port_vl_rcv_bubble
;
2339 __be64 port_vl_mark_fecn
;
2340 __be64 port_vl_xmit_discards
;
2341 } vls
[]; /* real array size defined by # bits set in vl_select_mask */
2344 enum counter_selects
{
2345 CS_PORT_XMIT_DATA
= (1 << 31),
2346 CS_PORT_RCV_DATA
= (1 << 30),
2347 CS_PORT_XMIT_PKTS
= (1 << 29),
2348 CS_PORT_RCV_PKTS
= (1 << 28),
2349 CS_PORT_MCAST_XMIT_PKTS
= (1 << 27),
2350 CS_PORT_MCAST_RCV_PKTS
= (1 << 26),
2351 CS_PORT_XMIT_WAIT
= (1 << 25),
2352 CS_SW_PORT_CONGESTION
= (1 << 24),
2353 CS_PORT_RCV_FECN
= (1 << 23),
2354 CS_PORT_RCV_BECN
= (1 << 22),
2355 CS_PORT_XMIT_TIME_CONG
= (1 << 21),
2356 CS_PORT_XMIT_WASTED_BW
= (1 << 20),
2357 CS_PORT_XMIT_WAIT_DATA
= (1 << 19),
2358 CS_PORT_RCV_BUBBLE
= (1 << 18),
2359 CS_PORT_MARK_FECN
= (1 << 17),
2360 CS_PORT_RCV_CONSTRAINT_ERRORS
= (1 << 16),
2361 CS_PORT_RCV_SWITCH_RELAY_ERRORS
= (1 << 15),
2362 CS_PORT_XMIT_DISCARDS
= (1 << 14),
2363 CS_PORT_XMIT_CONSTRAINT_ERRORS
= (1 << 13),
2364 CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS
= (1 << 12),
2365 CS_LOCAL_LINK_INTEGRITY_ERRORS
= (1 << 11),
2366 CS_PORT_RCV_ERRORS
= (1 << 10),
2367 CS_EXCESSIVE_BUFFER_OVERRUNS
= (1 << 9),
2368 CS_FM_CONFIG_ERRORS
= (1 << 8),
2369 CS_LINK_ERROR_RECOVERY
= (1 << 7),
2370 CS_LINK_DOWNED
= (1 << 6),
2371 CS_UNCORRECTABLE_ERRORS
= (1 << 5),
2374 struct opa_clear_port_status
{
2375 __be64 port_select_mask
[4];
2376 __be32 counter_select_mask
;
2379 struct opa_aggregate
{
2381 __be16 err_reqlength
; /* 1 bit, 8 res, 7 bit */
2386 #define MSK_LLI 0x000000f0
2387 #define MSK_LLI_SFT 4
2388 #define MSK_LER 0x0000000f
2389 #define MSK_LER_SFT 0
2393 /* Request contains first three fields, response contains those plus the rest */
2394 struct opa_port_data_counters_msg
{
2395 __be64 port_select_mask
[4];
2396 __be32 vl_select_mask
;
2399 /* Response fields follow */
2400 struct _port_dctrs
{
2403 __be32 link_quality_indicator
; /* 29res, 3bit */
2406 __be64 port_xmit_data
;
2407 __be64 port_rcv_data
;
2408 __be64 port_xmit_pkts
;
2409 __be64 port_rcv_pkts
;
2410 __be64 port_multicast_xmit_pkts
;
2411 __be64 port_multicast_rcv_pkts
;
2412 __be64 port_xmit_wait
;
2413 __be64 sw_port_congestion
;
2414 __be64 port_rcv_fecn
;
2415 __be64 port_rcv_becn
;
2416 __be64 port_xmit_time_cong
;
2417 __be64 port_xmit_wasted_bw
;
2418 __be64 port_xmit_wait_data
;
2419 __be64 port_rcv_bubble
;
2420 __be64 port_mark_fecn
;
2422 __be64 port_error_counter_summary
;
2423 /* Sum of error counts/port */
2426 /* per-VL Data counters */
2427 __be64 port_vl_xmit_data
;
2428 __be64 port_vl_rcv_data
;
2429 __be64 port_vl_xmit_pkts
;
2430 __be64 port_vl_rcv_pkts
;
2431 __be64 port_vl_xmit_wait
;
2432 __be64 sw_port_vl_congestion
;
2433 __be64 port_vl_rcv_fecn
;
2434 __be64 port_vl_rcv_becn
;
2435 __be64 port_xmit_time_cong
;
2436 __be64 port_vl_xmit_wasted_bw
;
2437 __be64 port_vl_xmit_wait_data
;
2438 __be64 port_vl_rcv_bubble
;
2439 __be64 port_vl_mark_fecn
;
2441 /* array size defined by #bits set in vl_select_mask*/
2445 struct opa_port_error_counters64_msg
{
2447 * Request contains first two fields, response contains the
2450 __be64 port_select_mask
[4];
2451 __be32 vl_select_mask
;
2453 /* Response-only fields follow */
2455 struct _port_ectrs
{
2458 __be64 port_rcv_constraint_errors
;
2459 __be64 port_rcv_switch_relay_errors
;
2460 __be64 port_xmit_discards
;
2461 __be64 port_xmit_constraint_errors
;
2462 __be64 port_rcv_remote_physical_errors
;
2463 __be64 local_link_integrity_errors
;
2464 __be64 port_rcv_errors
;
2465 __be64 excessive_buffer_overruns
;
2466 __be64 fm_config_errors
;
2467 __be32 link_error_recovery
;
2469 u8 uncorrectable_errors
;
2472 __be64 port_vl_xmit_discards
;
2474 /* array size defined by #bits set in vl_select_mask */
2478 struct opa_port_error_info_msg
{
2479 __be64 port_select_mask
[4];
2480 __be32 error_info_select_mask
;
2486 /* PortRcvErrorInfo */
2492 /* EI1to12 format */
2495 u8 remaining_flit_bits12
;
2499 u8 remaining_flit_bits
;
2503 } __packed port_rcv_ei
;
2505 /* ExcessiveBufferOverrunInfo */
2509 } __packed excessive_buffer_overrun_ei
;
2511 /* PortXmitConstraintErrorInfo */
2517 } __packed port_xmit_constraint_ei
;
2519 /* PortRcvConstraintErrorInfo */
2525 } __packed port_rcv_constraint_ei
;
2527 /* PortRcvSwitchRelayErrorInfo */
2532 } __packed port_rcv_switch_relay_ei
;
2534 /* UncorrectableErrorInfo */
2538 } __packed uncorrectable_ei
;
2540 /* FMConfigErrorInfo */
2544 } __packed fm_config_ei
;
2549 /* opa_port_error_info_msg error_info_select_mask bit definitions */
2550 enum error_info_selects
{
2551 ES_PORT_RCV_ERROR_INFO
= (1 << 31),
2552 ES_EXCESSIVE_BUFFER_OVERRUN_INFO
= (1 << 30),
2553 ES_PORT_XMIT_CONSTRAINT_ERROR_INFO
= (1 << 29),
2554 ES_PORT_RCV_CONSTRAINT_ERROR_INFO
= (1 << 28),
2555 ES_PORT_RCV_SWITCH_RELAY_ERROR_INFO
= (1 << 27),
2556 ES_UNCORRECTABLE_ERROR_INFO
= (1 << 26),
2557 ES_FM_CONFIG_ERROR_INFO
= (1 << 25)
2560 static int pma_get_opa_classportinfo(struct opa_pma_mad
*pmp
,
2561 struct ib_device
*ibdev
, u32
*resp_len
)
2563 struct opa_class_port_info
*p
=
2564 (struct opa_class_port_info
*)pmp
->data
;
2566 memset(pmp
->data
, 0, sizeof(pmp
->data
));
2568 if (pmp
->mad_hdr
.attr_mod
!= 0)
2569 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2571 p
->base_version
= OPA_MGMT_BASE_VERSION
;
2572 p
->class_version
= OPA_SM_CLASS_VERSION
;
2574 * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec.
2576 p
->cap_mask2_resp_time
= cpu_to_be32(18);
2579 *resp_len
+= sizeof(*p
);
2581 return reply((struct ib_mad_hdr
*)pmp
);
2584 static void a0_portstatus(struct hfi1_pportdata
*ppd
,
2585 struct opa_port_status_rsp
*rsp
)
2587 if (!is_bx(ppd
->dd
)) {
2589 u64 sum_vl_xmit_wait
= 0;
2590 unsigned long vl_all_mask
= VL_MASK_ALL
;
2592 for_each_set_bit(vl
, &vl_all_mask
, BITS_PER_LONG
) {
2593 u64 tmp
= sum_vl_xmit_wait
+
2594 read_port_cntr(ppd
, C_TX_WAIT_VL
,
2596 if (tmp
< sum_vl_xmit_wait
) {
2598 sum_vl_xmit_wait
= (u64
)~0;
2601 sum_vl_xmit_wait
= tmp
;
2603 if (be64_to_cpu(rsp
->port_xmit_wait
) > sum_vl_xmit_wait
)
2604 rsp
->port_xmit_wait
= cpu_to_be64(sum_vl_xmit_wait
);
2609 * tx_link_width - convert link width bitmask to integer
2610 * value representing actual link width.
2611 * @link_width: width of active link
2612 * @return: return index of the bit set in link_width var
2614 * The function convert and return the index of bit set
2615 * that indicate the current link width.
2617 u16
tx_link_width(u16 link_width
)
2619 int n
= LINK_WIDTH_DEFAULT
;
2622 while (link_width
&& n
) {
2623 if (link_width
& (1 << (n
- 1))) {
2634 * get_xmit_wait_counters - Convert HFI 's SendWaitCnt/SendWaitVlCnt
2635 * counter in unit of TXE cycle times to flit times.
2636 * @ppd: info of physical Hfi port
2637 * @link_width: width of active link
2638 * @link_speed: speed of active link
2639 * @vl: represent VL0-VL7, VL15 for PortVLXmitWait counters request
2640 * and if vl value is C_VL_COUNT, it represent SendWaitCnt
2642 * @return: return SendWaitCnt/SendWaitVlCnt counter value per vl.
2644 * Convert SendWaitCnt/SendWaitVlCnt counter from TXE cycle times to
2645 * flit times. Call this function to samples these counters. This
2646 * function will calculate for previous state transition and update
2647 * current state at end of function using ppd->prev_link_width and
2648 * ppd->port_vl_xmit_wait_last to port_vl_xmit_wait_curr and link_width.
2650 u64
get_xmit_wait_counters(struct hfi1_pportdata
*ppd
,
2651 u16 link_width
, u16 link_speed
, int vl
)
2653 u64 port_vl_xmit_wait_curr
;
2654 u64 delta_vl_xmit_wait
;
2657 if (vl
> C_VL_COUNT
)
2659 if (vl
< C_VL_COUNT
)
2660 port_vl_xmit_wait_curr
=
2661 read_port_cntr(ppd
, C_TX_WAIT_VL
, vl
);
2663 port_vl_xmit_wait_curr
=
2664 read_port_cntr(ppd
, C_TX_WAIT
, CNTR_INVALID_VL
);
2667 port_vl_xmit_wait_curr
-
2668 ppd
->port_vl_xmit_wait_last
[vl
];
2669 delta_vl_xmit_wait
=
2670 convert_xmit_counter(xmit_wait_val
,
2671 ppd
->prev_link_width
,
2674 ppd
->vl_xmit_flit_cnt
[vl
] += delta_vl_xmit_wait
;
2675 ppd
->port_vl_xmit_wait_last
[vl
] = port_vl_xmit_wait_curr
;
2676 ppd
->prev_link_width
= link_width
;
2678 return ppd
->vl_xmit_flit_cnt
[vl
];
2681 static int pma_get_opa_portstatus(struct opa_pma_mad
*pmp
,
2682 struct ib_device
*ibdev
,
2683 u32 port
, u32
*resp_len
)
2685 struct opa_port_status_req
*req
=
2686 (struct opa_port_status_req
*)pmp
->data
;
2687 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2688 struct opa_port_status_rsp
*rsp
;
2689 unsigned long vl_select_mask
= be32_to_cpu(req
->vl_select_mask
);
2691 size_t response_data_size
;
2692 u32 nports
= be32_to_cpu(pmp
->mad_hdr
.attr_mod
) >> 24;
2693 u32 port_num
= req
->port_num
;
2694 u8 num_vls
= hweight64(vl_select_mask
);
2695 struct _vls_pctrs
*vlinfo
;
2696 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
2697 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
2703 response_data_size
= struct_size(rsp
, vls
, num_vls
);
2704 if (response_data_size
> sizeof(pmp
->data
)) {
2705 pmp
->mad_hdr
.status
|= OPA_PM_STATUS_REQUEST_TOO_LARGE
;
2706 return reply((struct ib_mad_hdr
*)pmp
);
2709 if (nports
!= 1 || (port_num
&& port_num
!= port
) ||
2710 num_vls
> OPA_MAX_VLS
|| (vl_select_mask
& ~VL_MASK_ALL
)) {
2711 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2712 return reply((struct ib_mad_hdr
*)pmp
);
2715 memset(pmp
->data
, 0, sizeof(pmp
->data
));
2717 rsp
= (struct opa_port_status_rsp
*)pmp
->data
;
2719 rsp
->port_num
= port_num
;
2721 rsp
->port_num
= port
;
2723 rsp
->port_rcv_constraint_errors
=
2724 cpu_to_be64(read_port_cntr(ppd
, C_SW_RCV_CSTR_ERR
,
2727 hfi1_read_link_quality(dd
, &rsp
->link_quality_indicator
);
2729 rsp
->vl_select_mask
= cpu_to_be32((u32
)vl_select_mask
);
2730 rsp
->port_xmit_data
= cpu_to_be64(read_dev_cntr(dd
, C_DC_XMIT_FLITS
,
2732 rsp
->port_rcv_data
= cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FLITS
,
2734 rsp
->port_xmit_pkts
= cpu_to_be64(read_dev_cntr(dd
, C_DC_XMIT_PKTS
,
2736 rsp
->port_rcv_pkts
= cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_PKTS
,
2738 rsp
->port_multicast_xmit_pkts
=
2739 cpu_to_be64(read_dev_cntr(dd
, C_DC_MC_XMIT_PKTS
,
2741 rsp
->port_multicast_rcv_pkts
=
2742 cpu_to_be64(read_dev_cntr(dd
, C_DC_MC_RCV_PKTS
,
2745 * Convert PortXmitWait counter from TXE cycle times
2749 tx_link_width(ppd
->link_width_downgrade_tx_active
);
2750 link_speed
= get_link_speed(ppd
->link_speed_active
);
2751 rsp
->port_xmit_wait
=
2752 cpu_to_be64(get_xmit_wait_counters(ppd
, link_width
,
2753 link_speed
, C_VL_COUNT
));
2754 rsp
->port_rcv_fecn
=
2755 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FCN
, CNTR_INVALID_VL
));
2756 rsp
->port_rcv_becn
=
2757 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_BCN
, CNTR_INVALID_VL
));
2758 rsp
->port_xmit_discards
=
2759 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_DSCD
,
2761 rsp
->port_xmit_constraint_errors
=
2762 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_CSTR_ERR
,
2764 rsp
->port_rcv_remote_physical_errors
=
2765 cpu_to_be64(read_dev_cntr(dd
, C_DC_RMT_PHY_ERR
,
2767 rsp
->local_link_integrity_errors
=
2768 cpu_to_be64(read_dev_cntr(dd
, C_DC_RX_REPLAY
,
2770 tmp
= read_dev_cntr(dd
, C_DC_SEQ_CRC_CNT
, CNTR_INVALID_VL
);
2771 tmp2
= tmp
+ read_dev_cntr(dd
, C_DC_REINIT_FROM_PEER_CNT
,
2773 if (tmp2
> (u32
)UINT_MAX
|| tmp2
< tmp
) {
2774 /* overflow/wrapped */
2775 rsp
->link_error_recovery
= cpu_to_be32(~0);
2777 rsp
->link_error_recovery
= cpu_to_be32(tmp2
);
2779 rsp
->port_rcv_errors
=
2780 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_ERR
, CNTR_INVALID_VL
));
2781 rsp
->excessive_buffer_overruns
=
2782 cpu_to_be64(read_dev_cntr(dd
, C_RCV_OVF
, CNTR_INVALID_VL
));
2783 rsp
->fm_config_errors
=
2784 cpu_to_be64(read_dev_cntr(dd
, C_DC_FM_CFG_ERR
,
2786 rsp
->link_downed
= cpu_to_be32(read_port_cntr(ppd
, C_SW_LINK_DOWN
,
2789 /* rsp->uncorrectable_errors is 8 bits wide, and it pegs at 0xff */
2790 tmp
= read_dev_cntr(dd
, C_DC_UNC_ERR
, CNTR_INVALID_VL
);
2791 rsp
->uncorrectable_errors
= tmp
< 0x100 ? (tmp
& 0xff) : 0xff;
2793 vlinfo
= &rsp
->vls
[0];
2795 /* The vl_select_mask has been checked above, and we know
2796 * that it contains only entries which represent valid VLs.
2797 * So in the for_each_set_bit() loop below, we don't need
2798 * any additional checks for vl.
2800 for_each_set_bit(vl
, &vl_select_mask
, BITS_PER_LONG
) {
2801 memset(vlinfo
, 0, sizeof(*vlinfo
));
2803 tmp
= read_dev_cntr(dd
, C_DC_RX_FLIT_VL
, idx_from_vl(vl
));
2804 rsp
->vls
[vfi
].port_vl_rcv_data
= cpu_to_be64(tmp
);
2806 rsp
->vls
[vfi
].port_vl_rcv_pkts
=
2807 cpu_to_be64(read_dev_cntr(dd
, C_DC_RX_PKT_VL
,
2810 rsp
->vls
[vfi
].port_vl_xmit_data
=
2811 cpu_to_be64(read_port_cntr(ppd
, C_TX_FLIT_VL
,
2814 rsp
->vls
[vfi
].port_vl_xmit_pkts
=
2815 cpu_to_be64(read_port_cntr(ppd
, C_TX_PKT_VL
,
2818 * Convert PortVlXmitWait counter from TXE cycle
2819 * times to flit times.
2821 rsp
->vls
[vfi
].port_vl_xmit_wait
=
2822 cpu_to_be64(get_xmit_wait_counters(ppd
, link_width
,
2826 rsp
->vls
[vfi
].port_vl_rcv_fecn
=
2827 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FCN_VL
,
2830 rsp
->vls
[vfi
].port_vl_rcv_becn
=
2831 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_BCN_VL
,
2834 rsp
->vls
[vfi
].port_vl_xmit_discards
=
2835 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_DSCD_VL
,
2841 a0_portstatus(ppd
, rsp
);
2844 *resp_len
+= response_data_size
;
2846 return reply((struct ib_mad_hdr
*)pmp
);
2849 static u64
get_error_counter_summary(struct ib_device
*ibdev
, u32 port
,
2850 u8 res_lli
, u8 res_ler
)
2852 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2853 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
2854 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
2855 u64 error_counter_summary
= 0, tmp
;
2857 error_counter_summary
+= read_port_cntr(ppd
, C_SW_RCV_CSTR_ERR
,
2859 /* port_rcv_switch_relay_errors is 0 for HFIs */
2860 error_counter_summary
+= read_port_cntr(ppd
, C_SW_XMIT_DSCD
,
2862 error_counter_summary
+= read_port_cntr(ppd
, C_SW_XMIT_CSTR_ERR
,
2864 error_counter_summary
+= read_dev_cntr(dd
, C_DC_RMT_PHY_ERR
,
2866 /* local link integrity must be right-shifted by the lli resolution */
2867 error_counter_summary
+= (read_dev_cntr(dd
, C_DC_RX_REPLAY
,
2868 CNTR_INVALID_VL
) >> res_lli
);
2869 /* link error recovery must b right-shifted by the ler resolution */
2870 tmp
= read_dev_cntr(dd
, C_DC_SEQ_CRC_CNT
, CNTR_INVALID_VL
);
2871 tmp
+= read_dev_cntr(dd
, C_DC_REINIT_FROM_PEER_CNT
, CNTR_INVALID_VL
);
2872 error_counter_summary
+= (tmp
>> res_ler
);
2873 error_counter_summary
+= read_dev_cntr(dd
, C_DC_RCV_ERR
,
2875 error_counter_summary
+= read_dev_cntr(dd
, C_RCV_OVF
, CNTR_INVALID_VL
);
2876 error_counter_summary
+= read_dev_cntr(dd
, C_DC_FM_CFG_ERR
,
2878 /* ppd->link_downed is a 32-bit value */
2879 error_counter_summary
+= read_port_cntr(ppd
, C_SW_LINK_DOWN
,
2881 tmp
= read_dev_cntr(dd
, C_DC_UNC_ERR
, CNTR_INVALID_VL
);
2882 /* this is an 8-bit quantity */
2883 error_counter_summary
+= tmp
< 0x100 ? (tmp
& 0xff) : 0xff;
2885 return error_counter_summary
;
2888 static void a0_datacounters(struct hfi1_pportdata
*ppd
, struct _port_dctrs
*rsp
)
2890 if (!is_bx(ppd
->dd
)) {
2892 u64 sum_vl_xmit_wait
= 0;
2893 unsigned long vl_all_mask
= VL_MASK_ALL
;
2895 for_each_set_bit(vl
, &vl_all_mask
, BITS_PER_LONG
) {
2896 u64 tmp
= sum_vl_xmit_wait
+
2897 read_port_cntr(ppd
, C_TX_WAIT_VL
,
2899 if (tmp
< sum_vl_xmit_wait
) {
2901 sum_vl_xmit_wait
= (u64
)~0;
2904 sum_vl_xmit_wait
= tmp
;
2906 if (be64_to_cpu(rsp
->port_xmit_wait
) > sum_vl_xmit_wait
)
2907 rsp
->port_xmit_wait
= cpu_to_be64(sum_vl_xmit_wait
);
2911 static void pma_get_opa_port_dctrs(struct ib_device
*ibdev
,
2912 struct _port_dctrs
*rsp
)
2914 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2916 rsp
->port_xmit_data
= cpu_to_be64(read_dev_cntr(dd
, C_DC_XMIT_FLITS
,
2918 rsp
->port_rcv_data
= cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FLITS
,
2920 rsp
->port_xmit_pkts
= cpu_to_be64(read_dev_cntr(dd
, C_DC_XMIT_PKTS
,
2922 rsp
->port_rcv_pkts
= cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_PKTS
,
2924 rsp
->port_multicast_xmit_pkts
=
2925 cpu_to_be64(read_dev_cntr(dd
, C_DC_MC_XMIT_PKTS
,
2927 rsp
->port_multicast_rcv_pkts
=
2928 cpu_to_be64(read_dev_cntr(dd
, C_DC_MC_RCV_PKTS
,
2932 static int pma_get_opa_datacounters(struct opa_pma_mad
*pmp
,
2933 struct ib_device
*ibdev
,
2934 u32 port
, u32
*resp_len
)
2936 struct opa_port_data_counters_msg
*req
=
2937 (struct opa_port_data_counters_msg
*)pmp
->data
;
2938 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
2939 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
2940 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
2941 struct _port_dctrs
*rsp
;
2942 struct _vls_dctrs
*vlinfo
;
2943 size_t response_data_size
;
2946 u8 res_lli
, res_ler
;
2950 unsigned long vl_select_mask
;
2955 num_ports
= be32_to_cpu(pmp
->mad_hdr
.attr_mod
) >> 24;
2956 num_vls
= hweight32(be32_to_cpu(req
->vl_select_mask
));
2957 vl_select_mask
= be32_to_cpu(req
->vl_select_mask
);
2958 res_lli
= (u8
)(be32_to_cpu(req
->resolution
) & MSK_LLI
) >> MSK_LLI_SFT
;
2959 res_lli
= res_lli
? res_lli
+ ADD_LLI
: 0;
2960 res_ler
= (u8
)(be32_to_cpu(req
->resolution
) & MSK_LER
) >> MSK_LER_SFT
;
2961 res_ler
= res_ler
? res_ler
+ ADD_LER
: 0;
2963 if (num_ports
!= 1 || (vl_select_mask
& ~VL_MASK_ALL
)) {
2964 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2965 return reply((struct ib_mad_hdr
*)pmp
);
2969 response_data_size
= struct_size(req
, port
.vls
, num_vls
);
2971 if (response_data_size
> sizeof(pmp
->data
)) {
2972 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2973 return reply((struct ib_mad_hdr
*)pmp
);
2977 * The bit set in the mask needs to be consistent with the
2978 * port the request came in on.
2980 port_mask
= be64_to_cpu(req
->port_select_mask
[3]);
2981 port_num
= find_first_bit((unsigned long *)&port_mask
,
2982 sizeof(port_mask
) * 8);
2984 if (port_num
!= port
) {
2985 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
2986 return reply((struct ib_mad_hdr
*)pmp
);
2990 memset(rsp
, 0, sizeof(*rsp
));
2992 rsp
->port_number
= port
;
2994 * Note that link_quality_indicator is a 32 bit quantity in
2995 * 'datacounters' queries (as opposed to 'portinfo' queries,
2996 * where it's a byte).
2998 hfi1_read_link_quality(dd
, &lq
);
2999 rsp
->link_quality_indicator
= cpu_to_be32((u32
)lq
);
3000 pma_get_opa_port_dctrs(ibdev
, rsp
);
3003 * Convert PortXmitWait counter from TXE
3004 * cycle times to flit times.
3007 tx_link_width(ppd
->link_width_downgrade_tx_active
);
3008 link_speed
= get_link_speed(ppd
->link_speed_active
);
3009 rsp
->port_xmit_wait
=
3010 cpu_to_be64(get_xmit_wait_counters(ppd
, link_width
,
3011 link_speed
, C_VL_COUNT
));
3012 rsp
->port_rcv_fecn
=
3013 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FCN
, CNTR_INVALID_VL
));
3014 rsp
->port_rcv_becn
=
3015 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_BCN
, CNTR_INVALID_VL
));
3016 rsp
->port_error_counter_summary
=
3017 cpu_to_be64(get_error_counter_summary(ibdev
, port
,
3020 vlinfo
= &rsp
->vls
[0];
3022 /* The vl_select_mask has been checked above, and we know
3023 * that it contains only entries which represent valid VLs.
3024 * So in the for_each_set_bit() loop below, we don't need
3025 * any additional checks for vl.
3027 for_each_set_bit(vl
, &vl_select_mask
, BITS_PER_LONG
) {
3028 memset(vlinfo
, 0, sizeof(*vlinfo
));
3030 rsp
->vls
[vfi
].port_vl_xmit_data
=
3031 cpu_to_be64(read_port_cntr(ppd
, C_TX_FLIT_VL
,
3034 rsp
->vls
[vfi
].port_vl_rcv_data
=
3035 cpu_to_be64(read_dev_cntr(dd
, C_DC_RX_FLIT_VL
,
3038 rsp
->vls
[vfi
].port_vl_xmit_pkts
=
3039 cpu_to_be64(read_port_cntr(ppd
, C_TX_PKT_VL
,
3042 rsp
->vls
[vfi
].port_vl_rcv_pkts
=
3043 cpu_to_be64(read_dev_cntr(dd
, C_DC_RX_PKT_VL
,
3047 * Convert PortVlXmitWait counter from TXE
3048 * cycle times to flit times.
3050 rsp
->vls
[vfi
].port_vl_xmit_wait
=
3051 cpu_to_be64(get_xmit_wait_counters(ppd
, link_width
,
3055 rsp
->vls
[vfi
].port_vl_rcv_fecn
=
3056 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_FCN_VL
,
3058 rsp
->vls
[vfi
].port_vl_rcv_becn
=
3059 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_BCN_VL
,
3062 /* rsp->port_vl_xmit_time_cong is 0 for HFIs */
3063 /* rsp->port_vl_xmit_wasted_bw ??? */
3064 /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ???
3065 * does this differ from rsp->vls[vfi].port_vl_xmit_wait
3067 /*rsp->vls[vfi].port_vl_mark_fecn =
3068 * cpu_to_be64(read_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT
3075 a0_datacounters(ppd
, rsp
);
3078 *resp_len
+= response_data_size
;
3080 return reply((struct ib_mad_hdr
*)pmp
);
3083 static int pma_get_ib_portcounters_ext(struct ib_pma_mad
*pmp
,
3084 struct ib_device
*ibdev
, u32 port
)
3086 struct ib_pma_portcounters_ext
*p
= (struct ib_pma_portcounters_ext
*)
3088 struct _port_dctrs rsp
;
3090 if (pmp
->mad_hdr
.attr_mod
!= 0 || p
->port_select
!= port
) {
3091 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3095 memset(&rsp
, 0, sizeof(rsp
));
3096 pma_get_opa_port_dctrs(ibdev
, &rsp
);
3098 p
->port_xmit_data
= rsp
.port_xmit_data
;
3099 p
->port_rcv_data
= rsp
.port_rcv_data
;
3100 p
->port_xmit_packets
= rsp
.port_xmit_pkts
;
3101 p
->port_rcv_packets
= rsp
.port_rcv_pkts
;
3102 p
->port_unicast_xmit_packets
= 0;
3103 p
->port_unicast_rcv_packets
= 0;
3104 p
->port_multicast_xmit_packets
= rsp
.port_multicast_xmit_pkts
;
3105 p
->port_multicast_rcv_packets
= rsp
.port_multicast_rcv_pkts
;
3108 return reply((struct ib_mad_hdr
*)pmp
);
3111 static void pma_get_opa_port_ectrs(struct ib_device
*ibdev
,
3112 struct _port_ectrs
*rsp
, u32 port
)
3115 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
3116 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3117 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3119 tmp
= read_dev_cntr(dd
, C_DC_SEQ_CRC_CNT
, CNTR_INVALID_VL
);
3120 tmp2
= tmp
+ read_dev_cntr(dd
, C_DC_REINIT_FROM_PEER_CNT
,
3122 if (tmp2
> (u32
)UINT_MAX
|| tmp2
< tmp
) {
3123 /* overflow/wrapped */
3124 rsp
->link_error_recovery
= cpu_to_be32(~0);
3126 rsp
->link_error_recovery
= cpu_to_be32(tmp2
);
3129 rsp
->link_downed
= cpu_to_be32(read_port_cntr(ppd
, C_SW_LINK_DOWN
,
3131 rsp
->port_rcv_errors
=
3132 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_ERR
, CNTR_INVALID_VL
));
3133 rsp
->port_rcv_remote_physical_errors
=
3134 cpu_to_be64(read_dev_cntr(dd
, C_DC_RMT_PHY_ERR
,
3136 rsp
->port_rcv_switch_relay_errors
= 0;
3137 rsp
->port_xmit_discards
=
3138 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_DSCD
,
3140 rsp
->port_xmit_constraint_errors
=
3141 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_CSTR_ERR
,
3143 rsp
->port_rcv_constraint_errors
=
3144 cpu_to_be64(read_port_cntr(ppd
, C_SW_RCV_CSTR_ERR
,
3146 rsp
->local_link_integrity_errors
=
3147 cpu_to_be64(read_dev_cntr(dd
, C_DC_RX_REPLAY
,
3149 rsp
->excessive_buffer_overruns
=
3150 cpu_to_be64(read_dev_cntr(dd
, C_RCV_OVF
, CNTR_INVALID_VL
));
3153 static int pma_get_opa_porterrors(struct opa_pma_mad
*pmp
,
3154 struct ib_device
*ibdev
,
3155 u32 port
, u32
*resp_len
)
3157 size_t response_data_size
;
3158 struct _port_ectrs
*rsp
;
3160 struct opa_port_error_counters64_msg
*req
;
3161 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
3165 struct hfi1_ibport
*ibp
;
3166 struct hfi1_pportdata
*ppd
;
3167 struct _vls_ectrs
*vlinfo
;
3170 unsigned long vl_select_mask
;
3173 req
= (struct opa_port_error_counters64_msg
*)pmp
->data
;
3175 num_ports
= be32_to_cpu(pmp
->mad_hdr
.attr_mod
) >> 24;
3177 num_pslm
= hweight64(be64_to_cpu(req
->port_select_mask
[3]));
3178 num_vls
= hweight32(be32_to_cpu(req
->vl_select_mask
));
3180 if (num_ports
!= 1 || num_ports
!= num_pslm
) {
3181 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3182 return reply((struct ib_mad_hdr
*)pmp
);
3185 response_data_size
= struct_size(req
, port
.vls
, num_vls
);
3187 if (response_data_size
> sizeof(pmp
->data
)) {
3188 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3189 return reply((struct ib_mad_hdr
*)pmp
);
3192 * The bit set in the mask needs to be consistent with the
3193 * port the request came in on.
3195 port_mask
= be64_to_cpu(req
->port_select_mask
[3]);
3196 port_num
= find_first_bit((unsigned long *)&port_mask
,
3197 sizeof(port_mask
) * 8);
3199 if (port_num
!= port
) {
3200 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3201 return reply((struct ib_mad_hdr
*)pmp
);
3206 ibp
= to_iport(ibdev
, port_num
);
3207 ppd
= ppd_from_ibp(ibp
);
3209 memset(rsp
, 0, sizeof(*rsp
));
3210 rsp
->port_number
= port_num
;
3212 pma_get_opa_port_ectrs(ibdev
, rsp
, port_num
);
3214 rsp
->port_rcv_remote_physical_errors
=
3215 cpu_to_be64(read_dev_cntr(dd
, C_DC_RMT_PHY_ERR
,
3217 rsp
->fm_config_errors
=
3218 cpu_to_be64(read_dev_cntr(dd
, C_DC_FM_CFG_ERR
,
3220 tmp
= read_dev_cntr(dd
, C_DC_UNC_ERR
, CNTR_INVALID_VL
);
3222 rsp
->uncorrectable_errors
= tmp
< 0x100 ? (tmp
& 0xff) : 0xff;
3223 rsp
->port_rcv_errors
=
3224 cpu_to_be64(read_dev_cntr(dd
, C_DC_RCV_ERR
, CNTR_INVALID_VL
));
3225 vlinfo
= &rsp
->vls
[0];
3227 vl_select_mask
= be32_to_cpu(req
->vl_select_mask
);
3228 for_each_set_bit(vl
, &vl_select_mask
, BITS_PER_LONG
) {
3229 memset(vlinfo
, 0, sizeof(*vlinfo
));
3230 rsp
->vls
[vfi
].port_vl_xmit_discards
=
3231 cpu_to_be64(read_port_cntr(ppd
, C_SW_XMIT_DSCD_VL
,
3238 *resp_len
+= response_data_size
;
3240 return reply((struct ib_mad_hdr
*)pmp
);
3243 static int pma_get_ib_portcounters(struct ib_pma_mad
*pmp
,
3244 struct ib_device
*ibdev
, u32 port
)
3246 struct ib_pma_portcounters
*p
= (struct ib_pma_portcounters
*)
3248 struct _port_ectrs rsp
;
3249 u64 temp_link_overrun_errors
;
3253 memset(&rsp
, 0, sizeof(rsp
));
3254 pma_get_opa_port_ectrs(ibdev
, &rsp
, port
);
3256 if (pmp
->mad_hdr
.attr_mod
!= 0 || p
->port_select
!= port
) {
3257 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3261 p
->symbol_error_counter
= 0; /* N/A for OPA */
3263 temp_32
= be32_to_cpu(rsp
.link_error_recovery
);
3264 if (temp_32
> 0xFFUL
)
3265 p
->link_error_recovery_counter
= 0xFF;
3267 p
->link_error_recovery_counter
= (u8
)temp_32
;
3269 temp_32
= be32_to_cpu(rsp
.link_downed
);
3270 if (temp_32
> 0xFFUL
)
3271 p
->link_downed_counter
= 0xFF;
3273 p
->link_downed_counter
= (u8
)temp_32
;
3275 temp_64
= be64_to_cpu(rsp
.port_rcv_errors
);
3276 if (temp_64
> 0xFFFFUL
)
3277 p
->port_rcv_errors
= cpu_to_be16(0xFFFF);
3279 p
->port_rcv_errors
= cpu_to_be16((u16
)temp_64
);
3281 temp_64
= be64_to_cpu(rsp
.port_rcv_remote_physical_errors
);
3282 if (temp_64
> 0xFFFFUL
)
3283 p
->port_rcv_remphys_errors
= cpu_to_be16(0xFFFF);
3285 p
->port_rcv_remphys_errors
= cpu_to_be16((u16
)temp_64
);
3287 temp_64
= be64_to_cpu(rsp
.port_rcv_switch_relay_errors
);
3288 p
->port_rcv_switch_relay_errors
= cpu_to_be16((u16
)temp_64
);
3290 temp_64
= be64_to_cpu(rsp
.port_xmit_discards
);
3291 if (temp_64
> 0xFFFFUL
)
3292 p
->port_xmit_discards
= cpu_to_be16(0xFFFF);
3294 p
->port_xmit_discards
= cpu_to_be16((u16
)temp_64
);
3296 temp_64
= be64_to_cpu(rsp
.port_xmit_constraint_errors
);
3297 if (temp_64
> 0xFFUL
)
3298 p
->port_xmit_constraint_errors
= 0xFF;
3300 p
->port_xmit_constraint_errors
= (u8
)temp_64
;
3302 temp_64
= be64_to_cpu(rsp
.port_rcv_constraint_errors
);
3303 if (temp_64
> 0xFFUL
)
3304 p
->port_rcv_constraint_errors
= 0xFFUL
;
3306 p
->port_rcv_constraint_errors
= (u8
)temp_64
;
3308 /* LocalLink: 7:4, BufferOverrun: 3:0 */
3309 temp_64
= be64_to_cpu(rsp
.local_link_integrity_errors
);
3310 if (temp_64
> 0xFUL
)
3313 temp_link_overrun_errors
= temp_64
<< 4;
3315 temp_64
= be64_to_cpu(rsp
.excessive_buffer_overruns
);
3316 if (temp_64
> 0xFUL
)
3318 temp_link_overrun_errors
|= temp_64
;
3320 p
->link_overrun_errors
= (u8
)temp_link_overrun_errors
;
3322 p
->vl15_dropped
= 0; /* N/A for OPA */
3325 return reply((struct ib_mad_hdr
*)pmp
);
3328 static int pma_get_opa_errorinfo(struct opa_pma_mad
*pmp
,
3329 struct ib_device
*ibdev
,
3330 u32 port
, u32
*resp_len
)
3332 size_t response_data_size
;
3333 struct _port_ei
*rsp
;
3334 struct opa_port_error_info_msg
*req
;
3335 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
3342 req
= (struct opa_port_error_info_msg
*)pmp
->data
;
3345 num_ports
= OPA_AM_NPORT(be32_to_cpu(pmp
->mad_hdr
.attr_mod
));
3346 num_pslm
= hweight64(be64_to_cpu(req
->port_select_mask
[3]));
3348 memset(rsp
, 0, sizeof(*rsp
));
3350 if (num_ports
!= 1 || num_ports
!= num_pslm
) {
3351 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3352 return reply((struct ib_mad_hdr
*)pmp
);
3356 response_data_size
= sizeof(struct opa_port_error_info_msg
);
3358 if (response_data_size
> sizeof(pmp
->data
)) {
3359 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3360 return reply((struct ib_mad_hdr
*)pmp
);
3364 * The bit set in the mask needs to be consistent with the port
3365 * the request came in on.
3367 port_mask
= be64_to_cpu(req
->port_select_mask
[3]);
3368 port_num
= find_first_bit((unsigned long *)&port_mask
,
3369 sizeof(port_mask
) * 8);
3371 if (port_num
!= port
) {
3372 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3373 return reply((struct ib_mad_hdr
*)pmp
);
3375 rsp
->port_number
= port
;
3377 /* PortRcvErrorInfo */
3378 rsp
->port_rcv_ei
.status_and_code
=
3379 dd
->err_info_rcvport
.status_and_code
;
3380 memcpy(&rsp
->port_rcv_ei
.ei
.ei1to12
.packet_flit1
,
3381 &dd
->err_info_rcvport
.packet_flit1
, sizeof(u64
));
3382 memcpy(&rsp
->port_rcv_ei
.ei
.ei1to12
.packet_flit2
,
3383 &dd
->err_info_rcvport
.packet_flit2
, sizeof(u64
));
3385 /* ExcessiverBufferOverrunInfo */
3386 reg
= read_csr(dd
, RCV_ERR_INFO
);
3387 if (reg
& RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK
) {
3389 * if the RcvExcessBufferOverrun bit is set, save SC of
3390 * first pkt that encountered an excess buffer overrun
3394 tmp
&= RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SC_SMASK
;
3396 rsp
->excessive_buffer_overrun_ei
.status_and_sc
= tmp
;
3397 /* set the status bit */
3398 rsp
->excessive_buffer_overrun_ei
.status_and_sc
|= 0x80;
3401 rsp
->port_xmit_constraint_ei
.status
=
3402 dd
->err_info_xmit_constraint
.status
;
3403 rsp
->port_xmit_constraint_ei
.pkey
=
3404 cpu_to_be16(dd
->err_info_xmit_constraint
.pkey
);
3405 rsp
->port_xmit_constraint_ei
.slid
=
3406 cpu_to_be32(dd
->err_info_xmit_constraint
.slid
);
3408 rsp
->port_rcv_constraint_ei
.status
=
3409 dd
->err_info_rcv_constraint
.status
;
3410 rsp
->port_rcv_constraint_ei
.pkey
=
3411 cpu_to_be16(dd
->err_info_rcv_constraint
.pkey
);
3412 rsp
->port_rcv_constraint_ei
.slid
=
3413 cpu_to_be32(dd
->err_info_rcv_constraint
.slid
);
3415 /* UncorrectableErrorInfo */
3416 rsp
->uncorrectable_ei
.status_and_code
= dd
->err_info_uncorrectable
;
3418 /* FMConfigErrorInfo */
3419 rsp
->fm_config_ei
.status_and_code
= dd
->err_info_fmconfig
;
3422 *resp_len
+= response_data_size
;
3424 return reply((struct ib_mad_hdr
*)pmp
);
3427 static int pma_set_opa_portstatus(struct opa_pma_mad
*pmp
,
3428 struct ib_device
*ibdev
,
3429 u32 port
, u32
*resp_len
)
3431 struct opa_clear_port_status
*req
=
3432 (struct opa_clear_port_status
*)pmp
->data
;
3433 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
3434 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3435 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3436 u32 nports
= be32_to_cpu(pmp
->mad_hdr
.attr_mod
) >> 24;
3437 u64 portn
= be64_to_cpu(req
->port_select_mask
[3]);
3438 u32 counter_select
= be32_to_cpu(req
->counter_select_mask
);
3439 unsigned long vl_select_mask
= VL_MASK_ALL
; /* clear all per-vl cnts */
3442 if ((nports
!= 1) || (portn
!= 1 << port
)) {
3443 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3444 return reply((struct ib_mad_hdr
*)pmp
);
3447 * only counters returned by pma_get_opa_portstatus() are
3448 * handled, so when pma_get_opa_portstatus() gets a fix,
3449 * the corresponding change should be made here as well.
3452 if (counter_select
& CS_PORT_XMIT_DATA
)
3453 write_dev_cntr(dd
, C_DC_XMIT_FLITS
, CNTR_INVALID_VL
, 0);
3455 if (counter_select
& CS_PORT_RCV_DATA
)
3456 write_dev_cntr(dd
, C_DC_RCV_FLITS
, CNTR_INVALID_VL
, 0);
3458 if (counter_select
& CS_PORT_XMIT_PKTS
)
3459 write_dev_cntr(dd
, C_DC_XMIT_PKTS
, CNTR_INVALID_VL
, 0);
3461 if (counter_select
& CS_PORT_RCV_PKTS
)
3462 write_dev_cntr(dd
, C_DC_RCV_PKTS
, CNTR_INVALID_VL
, 0);
3464 if (counter_select
& CS_PORT_MCAST_XMIT_PKTS
)
3465 write_dev_cntr(dd
, C_DC_MC_XMIT_PKTS
, CNTR_INVALID_VL
, 0);
3467 if (counter_select
& CS_PORT_MCAST_RCV_PKTS
)
3468 write_dev_cntr(dd
, C_DC_MC_RCV_PKTS
, CNTR_INVALID_VL
, 0);
3470 if (counter_select
& CS_PORT_XMIT_WAIT
) {
3471 write_port_cntr(ppd
, C_TX_WAIT
, CNTR_INVALID_VL
, 0);
3472 ppd
->port_vl_xmit_wait_last
[C_VL_COUNT
] = 0;
3473 ppd
->vl_xmit_flit_cnt
[C_VL_COUNT
] = 0;
3475 /* ignore cs_sw_portCongestion for HFIs */
3477 if (counter_select
& CS_PORT_RCV_FECN
)
3478 write_dev_cntr(dd
, C_DC_RCV_FCN
, CNTR_INVALID_VL
, 0);
3480 if (counter_select
& CS_PORT_RCV_BECN
)
3481 write_dev_cntr(dd
, C_DC_RCV_BCN
, CNTR_INVALID_VL
, 0);
3483 /* ignore cs_port_xmit_time_cong for HFIs */
3484 /* ignore cs_port_xmit_wasted_bw for now */
3485 /* ignore cs_port_xmit_wait_data for now */
3486 if (counter_select
& CS_PORT_RCV_BUBBLE
)
3487 write_dev_cntr(dd
, C_DC_RCV_BBL
, CNTR_INVALID_VL
, 0);
3489 /* Only applicable for switch */
3490 /* if (counter_select & CS_PORT_MARK_FECN)
3491 * write_csr(dd, DCC_PRF_PORT_MARK_FECN_CNT, 0);
3494 if (counter_select
& CS_PORT_RCV_CONSTRAINT_ERRORS
)
3495 write_port_cntr(ppd
, C_SW_RCV_CSTR_ERR
, CNTR_INVALID_VL
, 0);
3497 /* ignore cs_port_rcv_switch_relay_errors for HFIs */
3498 if (counter_select
& CS_PORT_XMIT_DISCARDS
)
3499 write_port_cntr(ppd
, C_SW_XMIT_DSCD
, CNTR_INVALID_VL
, 0);
3501 if (counter_select
& CS_PORT_XMIT_CONSTRAINT_ERRORS
)
3502 write_port_cntr(ppd
, C_SW_XMIT_CSTR_ERR
, CNTR_INVALID_VL
, 0);
3504 if (counter_select
& CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS
)
3505 write_dev_cntr(dd
, C_DC_RMT_PHY_ERR
, CNTR_INVALID_VL
, 0);
3507 if (counter_select
& CS_LOCAL_LINK_INTEGRITY_ERRORS
)
3508 write_dev_cntr(dd
, C_DC_RX_REPLAY
, CNTR_INVALID_VL
, 0);
3510 if (counter_select
& CS_LINK_ERROR_RECOVERY
) {
3511 write_dev_cntr(dd
, C_DC_SEQ_CRC_CNT
, CNTR_INVALID_VL
, 0);
3512 write_dev_cntr(dd
, C_DC_REINIT_FROM_PEER_CNT
,
3513 CNTR_INVALID_VL
, 0);
3516 if (counter_select
& CS_PORT_RCV_ERRORS
)
3517 write_dev_cntr(dd
, C_DC_RCV_ERR
, CNTR_INVALID_VL
, 0);
3519 if (counter_select
& CS_EXCESSIVE_BUFFER_OVERRUNS
) {
3520 write_dev_cntr(dd
, C_RCV_OVF
, CNTR_INVALID_VL
, 0);
3521 dd
->rcv_ovfl_cnt
= 0;
3524 if (counter_select
& CS_FM_CONFIG_ERRORS
)
3525 write_dev_cntr(dd
, C_DC_FM_CFG_ERR
, CNTR_INVALID_VL
, 0);
3527 if (counter_select
& CS_LINK_DOWNED
)
3528 write_port_cntr(ppd
, C_SW_LINK_DOWN
, CNTR_INVALID_VL
, 0);
3530 if (counter_select
& CS_UNCORRECTABLE_ERRORS
)
3531 write_dev_cntr(dd
, C_DC_UNC_ERR
, CNTR_INVALID_VL
, 0);
3533 for_each_set_bit(vl
, &vl_select_mask
, BITS_PER_LONG
) {
3534 if (counter_select
& CS_PORT_XMIT_DATA
)
3535 write_port_cntr(ppd
, C_TX_FLIT_VL
, idx_from_vl(vl
), 0);
3537 if (counter_select
& CS_PORT_RCV_DATA
)
3538 write_dev_cntr(dd
, C_DC_RX_FLIT_VL
, idx_from_vl(vl
), 0);
3540 if (counter_select
& CS_PORT_XMIT_PKTS
)
3541 write_port_cntr(ppd
, C_TX_PKT_VL
, idx_from_vl(vl
), 0);
3543 if (counter_select
& CS_PORT_RCV_PKTS
)
3544 write_dev_cntr(dd
, C_DC_RX_PKT_VL
, idx_from_vl(vl
), 0);
3546 if (counter_select
& CS_PORT_XMIT_WAIT
) {
3547 write_port_cntr(ppd
, C_TX_WAIT_VL
, idx_from_vl(vl
), 0);
3548 ppd
->port_vl_xmit_wait_last
[idx_from_vl(vl
)] = 0;
3549 ppd
->vl_xmit_flit_cnt
[idx_from_vl(vl
)] = 0;
3552 /* sw_port_vl_congestion is 0 for HFIs */
3553 if (counter_select
& CS_PORT_RCV_FECN
)
3554 write_dev_cntr(dd
, C_DC_RCV_FCN_VL
, idx_from_vl(vl
), 0);
3556 if (counter_select
& CS_PORT_RCV_BECN
)
3557 write_dev_cntr(dd
, C_DC_RCV_BCN_VL
, idx_from_vl(vl
), 0);
3559 /* port_vl_xmit_time_cong is 0 for HFIs */
3560 /* port_vl_xmit_wasted_bw ??? */
3561 /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ??? */
3562 if (counter_select
& CS_PORT_RCV_BUBBLE
)
3563 write_dev_cntr(dd
, C_DC_RCV_BBL_VL
, idx_from_vl(vl
), 0);
3565 /* if (counter_select & CS_PORT_MARK_FECN)
3566 * write_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT + offset, 0);
3568 if (counter_select
& C_SW_XMIT_DSCD_VL
)
3569 write_port_cntr(ppd
, C_SW_XMIT_DSCD_VL
,
3570 idx_from_vl(vl
), 0);
3574 *resp_len
+= sizeof(*req
);
3576 return reply((struct ib_mad_hdr
*)pmp
);
3579 static int pma_set_opa_errorinfo(struct opa_pma_mad
*pmp
,
3580 struct ib_device
*ibdev
,
3581 u32 port
, u32
*resp_len
)
3583 struct _port_ei
*rsp
;
3584 struct opa_port_error_info_msg
*req
;
3585 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
3590 u32 error_info_select
;
3592 req
= (struct opa_port_error_info_msg
*)pmp
->data
;
3595 num_ports
= OPA_AM_NPORT(be32_to_cpu(pmp
->mad_hdr
.attr_mod
));
3596 num_pslm
= hweight64(be64_to_cpu(req
->port_select_mask
[3]));
3598 memset(rsp
, 0, sizeof(*rsp
));
3600 if (num_ports
!= 1 || num_ports
!= num_pslm
) {
3601 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3602 return reply((struct ib_mad_hdr
*)pmp
);
3606 * The bit set in the mask needs to be consistent with the port
3607 * the request came in on.
3609 port_mask
= be64_to_cpu(req
->port_select_mask
[3]);
3610 port_num
= find_first_bit((unsigned long *)&port_mask
,
3611 sizeof(port_mask
) * 8);
3613 if (port_num
!= port
) {
3614 pmp
->mad_hdr
.status
|= IB_SMP_INVALID_FIELD
;
3615 return reply((struct ib_mad_hdr
*)pmp
);
3618 error_info_select
= be32_to_cpu(req
->error_info_select_mask
);
3620 /* PortRcvErrorInfo */
3621 if (error_info_select
& ES_PORT_RCV_ERROR_INFO
)
3622 /* turn off status bit */
3623 dd
->err_info_rcvport
.status_and_code
&= ~OPA_EI_STATUS_SMASK
;
3625 /* ExcessiverBufferOverrunInfo */
3626 if (error_info_select
& ES_EXCESSIVE_BUFFER_OVERRUN_INFO
)
3628 * status bit is essentially kept in the h/w - bit 5 of
3631 write_csr(dd
, RCV_ERR_INFO
,
3632 RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK
);
3634 if (error_info_select
& ES_PORT_XMIT_CONSTRAINT_ERROR_INFO
)
3635 dd
->err_info_xmit_constraint
.status
&= ~OPA_EI_STATUS_SMASK
;
3637 if (error_info_select
& ES_PORT_RCV_CONSTRAINT_ERROR_INFO
)
3638 dd
->err_info_rcv_constraint
.status
&= ~OPA_EI_STATUS_SMASK
;
3640 /* UncorrectableErrorInfo */
3641 if (error_info_select
& ES_UNCORRECTABLE_ERROR_INFO
)
3642 /* turn off status bit */
3643 dd
->err_info_uncorrectable
&= ~OPA_EI_STATUS_SMASK
;
3645 /* FMConfigErrorInfo */
3646 if (error_info_select
& ES_FM_CONFIG_ERROR_INFO
)
3647 /* turn off status bit */
3648 dd
->err_info_fmconfig
&= ~OPA_EI_STATUS_SMASK
;
3651 *resp_len
+= sizeof(*req
);
3653 return reply((struct ib_mad_hdr
*)pmp
);
3656 struct opa_congestion_info_attr
{
3657 __be16 congestion_info
;
3658 u8 control_table_cap
; /* Multiple of 64 entry unit CCTs */
3659 u8 congestion_log_length
;
3662 static int __subn_get_opa_cong_info(struct opa_smp
*smp
, u32 am
, u8
*data
,
3663 struct ib_device
*ibdev
, u32 port
,
3664 u32
*resp_len
, u32 max_len
)
3666 struct opa_congestion_info_attr
*p
=
3667 (struct opa_congestion_info_attr
*)data
;
3668 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3669 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3671 if (smp_length_check(sizeof(*p
), max_len
)) {
3672 smp
->status
|= IB_SMP_INVALID_FIELD
;
3673 return reply((struct ib_mad_hdr
*)smp
);
3676 p
->congestion_info
= 0;
3677 p
->control_table_cap
= ppd
->cc_max_table_entries
;
3678 p
->congestion_log_length
= OPA_CONG_LOG_ELEMS
;
3681 *resp_len
+= sizeof(*p
);
3683 return reply((struct ib_mad_hdr
*)smp
);
3686 static int __subn_get_opa_cong_setting(struct opa_smp
*smp
, u32 am
,
3687 u8
*data
, struct ib_device
*ibdev
,
3688 u32 port
, u32
*resp_len
, u32 max_len
)
3691 struct opa_congestion_setting_attr
*p
=
3692 (struct opa_congestion_setting_attr
*)data
;
3693 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3694 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3695 struct opa_congestion_setting_entry_shadow
*entries
;
3696 struct cc_state
*cc_state
;
3698 if (smp_length_check(sizeof(*p
), max_len
)) {
3699 smp
->status
|= IB_SMP_INVALID_FIELD
;
3700 return reply((struct ib_mad_hdr
*)smp
);
3705 cc_state
= get_cc_state(ppd
);
3709 return reply((struct ib_mad_hdr
*)smp
);
3712 entries
= cc_state
->cong_setting
.entries
;
3713 p
->port_control
= cpu_to_be16(cc_state
->cong_setting
.port_control
);
3714 p
->control_map
= cpu_to_be32(cc_state
->cong_setting
.control_map
);
3715 for (i
= 0; i
< OPA_MAX_SLS
; i
++) {
3716 p
->entries
[i
].ccti_increase
= entries
[i
].ccti_increase
;
3717 p
->entries
[i
].ccti_timer
= cpu_to_be16(entries
[i
].ccti_timer
);
3718 p
->entries
[i
].trigger_threshold
=
3719 entries
[i
].trigger_threshold
;
3720 p
->entries
[i
].ccti_min
= entries
[i
].ccti_min
;
3726 *resp_len
+= sizeof(*p
);
3728 return reply((struct ib_mad_hdr
*)smp
);
3732 * Apply congestion control information stored in the ppd to the
3735 static void apply_cc_state(struct hfi1_pportdata
*ppd
)
3737 struct cc_state
*old_cc_state
, *new_cc_state
;
3739 new_cc_state
= kzalloc(sizeof(*new_cc_state
), GFP_KERNEL
);
3744 * Hold the lock for updating *and* to prevent ppd information
3745 * from changing during the update.
3747 spin_lock(&ppd
->cc_state_lock
);
3749 old_cc_state
= get_cc_state_protected(ppd
);
3750 if (!old_cc_state
) {
3751 /* never active, or shutting down */
3752 spin_unlock(&ppd
->cc_state_lock
);
3753 kfree(new_cc_state
);
3757 *new_cc_state
= *old_cc_state
;
3759 if (ppd
->total_cct_entry
)
3760 new_cc_state
->cct
.ccti_limit
= ppd
->total_cct_entry
- 1;
3762 new_cc_state
->cct
.ccti_limit
= 0;
3764 memcpy(new_cc_state
->cct
.entries
, ppd
->ccti_entries
,
3765 ppd
->total_cct_entry
* sizeof(struct ib_cc_table_entry
));
3767 new_cc_state
->cong_setting
.port_control
= IB_CC_CCS_PC_SL_BASED
;
3768 new_cc_state
->cong_setting
.control_map
= ppd
->cc_sl_control_map
;
3769 memcpy(new_cc_state
->cong_setting
.entries
, ppd
->congestion_entries
,
3770 OPA_MAX_SLS
* sizeof(struct opa_congestion_setting_entry
));
3772 rcu_assign_pointer(ppd
->cc_state
, new_cc_state
);
3774 spin_unlock(&ppd
->cc_state_lock
);
3776 kfree_rcu(old_cc_state
, rcu
);
3779 static int __subn_set_opa_cong_setting(struct opa_smp
*smp
, u32 am
, u8
*data
,
3780 struct ib_device
*ibdev
, u32 port
,
3781 u32
*resp_len
, u32 max_len
)
3783 struct opa_congestion_setting_attr
*p
=
3784 (struct opa_congestion_setting_attr
*)data
;
3785 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3786 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3787 struct opa_congestion_setting_entry_shadow
*entries
;
3790 if (smp_length_check(sizeof(*p
), max_len
)) {
3791 smp
->status
|= IB_SMP_INVALID_FIELD
;
3792 return reply((struct ib_mad_hdr
*)smp
);
3796 * Save details from packet into the ppd. Hold the cc_state_lock so
3797 * our information is consistent with anyone trying to apply the state.
3799 spin_lock(&ppd
->cc_state_lock
);
3800 ppd
->cc_sl_control_map
= be32_to_cpu(p
->control_map
);
3802 entries
= ppd
->congestion_entries
;
3803 for (i
= 0; i
< OPA_MAX_SLS
; i
++) {
3804 entries
[i
].ccti_increase
= p
->entries
[i
].ccti_increase
;
3805 entries
[i
].ccti_timer
= be16_to_cpu(p
->entries
[i
].ccti_timer
);
3806 entries
[i
].trigger_threshold
=
3807 p
->entries
[i
].trigger_threshold
;
3808 entries
[i
].ccti_min
= p
->entries
[i
].ccti_min
;
3810 spin_unlock(&ppd
->cc_state_lock
);
3812 /* now apply the information */
3813 apply_cc_state(ppd
);
3815 return __subn_get_opa_cong_setting(smp
, am
, data
, ibdev
, port
,
3819 static int __subn_get_opa_hfi1_cong_log(struct opa_smp
*smp
, u32 am
,
3820 u8
*data
, struct ib_device
*ibdev
,
3821 u32 port
, u32
*resp_len
, u32 max_len
)
3823 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3824 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3825 struct opa_hfi1_cong_log
*cong_log
= (struct opa_hfi1_cong_log
*)data
;
3829 if (am
|| smp_length_check(sizeof(*cong_log
), max_len
)) {
3830 smp
->status
|= IB_SMP_INVALID_FIELD
;
3831 return reply((struct ib_mad_hdr
*)smp
);
3834 spin_lock_irq(&ppd
->cc_log_lock
);
3836 cong_log
->log_type
= OPA_CC_LOG_TYPE_HFI
;
3837 cong_log
->congestion_flags
= 0;
3838 cong_log
->threshold_event_counter
=
3839 cpu_to_be16(ppd
->threshold_event_counter
);
3840 memcpy(cong_log
->threshold_cong_event_map
,
3841 ppd
->threshold_cong_event_map
,
3842 sizeof(cong_log
->threshold_cong_event_map
));
3843 /* keep timestamp in units of 1.024 usec */
3844 ts
= ktime_get_ns() / 1024;
3845 cong_log
->current_time_stamp
= cpu_to_be32(ts
);
3846 for (i
= 0; i
< OPA_CONG_LOG_ELEMS
; i
++) {
3847 struct opa_hfi1_cong_log_event_internal
*cce
=
3848 &ppd
->cc_events
[ppd
->cc_mad_idx
++];
3849 if (ppd
->cc_mad_idx
== OPA_CONG_LOG_ELEMS
)
3850 ppd
->cc_mad_idx
= 0;
3852 * Entries which are older than twice the time
3853 * required to wrap the counter are supposed to
3854 * be zeroed (CA10-49 IBTA, release 1.2.1, V1).
3856 if ((ts
- cce
->timestamp
) / 2 > U32_MAX
)
3858 memcpy(cong_log
->events
[i
].local_qp_cn_entry
, &cce
->lqpn
, 3);
3859 memcpy(cong_log
->events
[i
].remote_qp_number_cn_entry
,
3861 cong_log
->events
[i
].sl_svc_type_cn_entry
=
3862 ((cce
->sl
& 0x1f) << 3) | (cce
->svc_type
& 0x7);
3863 cong_log
->events
[i
].remote_lid_cn_entry
=
3864 cpu_to_be32(cce
->rlid
);
3865 cong_log
->events
[i
].timestamp_cn_entry
=
3866 cpu_to_be32(cce
->timestamp
);
3870 * Reset threshold_cong_event_map, and threshold_event_counter
3871 * to 0 when log is read.
3873 memset(ppd
->threshold_cong_event_map
, 0x0,
3874 sizeof(ppd
->threshold_cong_event_map
));
3875 ppd
->threshold_event_counter
= 0;
3877 spin_unlock_irq(&ppd
->cc_log_lock
);
3880 *resp_len
+= sizeof(struct opa_hfi1_cong_log
);
3882 return reply((struct ib_mad_hdr
*)smp
);
3885 static int __subn_get_opa_cc_table(struct opa_smp
*smp
, u32 am
, u8
*data
,
3886 struct ib_device
*ibdev
, u32 port
,
3887 u32
*resp_len
, u32 max_len
)
3889 struct ib_cc_table_attr
*cc_table_attr
=
3890 (struct ib_cc_table_attr
*)data
;
3891 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3892 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3893 u32 start_block
= OPA_AM_START_BLK(am
);
3894 u32 n_blocks
= OPA_AM_NBLK(am
);
3895 struct ib_cc_table_entry_shadow
*entries
;
3898 struct cc_state
*cc_state
;
3899 u32 size
= sizeof(u16
) * (IB_CCT_ENTRIES
* n_blocks
+ 1);
3901 /* sanity check n_blocks, start_block */
3902 if (n_blocks
== 0 || smp_length_check(size
, max_len
) ||
3903 start_block
+ n_blocks
> ppd
->cc_max_table_entries
) {
3904 smp
->status
|= IB_SMP_INVALID_FIELD
;
3905 return reply((struct ib_mad_hdr
*)smp
);
3910 cc_state
= get_cc_state(ppd
);
3914 return reply((struct ib_mad_hdr
*)smp
);
3917 sentry
= start_block
* IB_CCT_ENTRIES
;
3918 eentry
= sentry
+ (IB_CCT_ENTRIES
* n_blocks
);
3920 cc_table_attr
->ccti_limit
= cpu_to_be16(cc_state
->cct
.ccti_limit
);
3922 entries
= cc_state
->cct
.entries
;
3924 /* return n_blocks, though the last block may not be full */
3925 for (j
= 0, i
= sentry
; i
< eentry
; j
++, i
++)
3926 cc_table_attr
->ccti_entries
[j
].entry
=
3927 cpu_to_be16(entries
[i
].entry
);
3934 return reply((struct ib_mad_hdr
*)smp
);
3937 static int __subn_set_opa_cc_table(struct opa_smp
*smp
, u32 am
, u8
*data
,
3938 struct ib_device
*ibdev
, u32 port
,
3939 u32
*resp_len
, u32 max_len
)
3941 struct ib_cc_table_attr
*p
= (struct ib_cc_table_attr
*)data
;
3942 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
3943 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
3944 u32 start_block
= OPA_AM_START_BLK(am
);
3945 u32 n_blocks
= OPA_AM_NBLK(am
);
3946 struct ib_cc_table_entry_shadow
*entries
;
3950 u32 size
= sizeof(u16
) * (IB_CCT_ENTRIES
* n_blocks
+ 1);
3952 /* sanity check n_blocks, start_block */
3953 if (n_blocks
== 0 || smp_length_check(size
, max_len
) ||
3954 start_block
+ n_blocks
> ppd
->cc_max_table_entries
) {
3955 smp
->status
|= IB_SMP_INVALID_FIELD
;
3956 return reply((struct ib_mad_hdr
*)smp
);
3959 sentry
= start_block
* IB_CCT_ENTRIES
;
3960 eentry
= sentry
+ ((n_blocks
- 1) * IB_CCT_ENTRIES
) +
3961 (be16_to_cpu(p
->ccti_limit
)) % IB_CCT_ENTRIES
+ 1;
3963 /* sanity check ccti_limit */
3964 ccti_limit
= be16_to_cpu(p
->ccti_limit
);
3965 if (ccti_limit
+ 1 > eentry
) {
3966 smp
->status
|= IB_SMP_INVALID_FIELD
;
3967 return reply((struct ib_mad_hdr
*)smp
);
3971 * Save details from packet into the ppd. Hold the cc_state_lock so
3972 * our information is consistent with anyone trying to apply the state.
3974 spin_lock(&ppd
->cc_state_lock
);
3975 ppd
->total_cct_entry
= ccti_limit
+ 1;
3976 entries
= ppd
->ccti_entries
;
3977 for (j
= 0, i
= sentry
; i
< eentry
; j
++, i
++)
3978 entries
[i
].entry
= be16_to_cpu(p
->ccti_entries
[j
].entry
);
3979 spin_unlock(&ppd
->cc_state_lock
);
3981 /* now apply the information */
3982 apply_cc_state(ppd
);
3984 return __subn_get_opa_cc_table(smp
, am
, data
, ibdev
, port
, resp_len
,
3988 struct opa_led_info
{
3989 __be32 rsvd_led_mask
;
3993 #define OPA_LED_SHIFT 31
3994 #define OPA_LED_MASK BIT(OPA_LED_SHIFT)
3996 static int __subn_get_opa_led_info(struct opa_smp
*smp
, u32 am
, u8
*data
,
3997 struct ib_device
*ibdev
, u32 port
,
3998 u32
*resp_len
, u32 max_len
)
4000 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
4001 struct hfi1_pportdata
*ppd
= dd
->pport
;
4002 struct opa_led_info
*p
= (struct opa_led_info
*)data
;
4003 u32 nport
= OPA_AM_NPORT(am
);
4004 u32 is_beaconing_active
;
4006 if (nport
!= 1 || smp_length_check(sizeof(*p
), max_len
)) {
4007 smp
->status
|= IB_SMP_INVALID_FIELD
;
4008 return reply((struct ib_mad_hdr
*)smp
);
4012 * This pairs with the memory barrier in hfi1_start_led_override to
4013 * ensure that we read the correct state of LED beaconing represented
4014 * by led_override_timer_active
4017 is_beaconing_active
= !!atomic_read(&ppd
->led_override_timer_active
);
4018 p
->rsvd_led_mask
= cpu_to_be32(is_beaconing_active
<< OPA_LED_SHIFT
);
4021 *resp_len
+= sizeof(struct opa_led_info
);
4023 return reply((struct ib_mad_hdr
*)smp
);
4026 static int __subn_set_opa_led_info(struct opa_smp
*smp
, u32 am
, u8
*data
,
4027 struct ib_device
*ibdev
, u32 port
,
4028 u32
*resp_len
, u32 max_len
)
4030 struct hfi1_devdata
*dd
= dd_from_ibdev(ibdev
);
4031 struct opa_led_info
*p
= (struct opa_led_info
*)data
;
4032 u32 nport
= OPA_AM_NPORT(am
);
4033 int on
= !!(be32_to_cpu(p
->rsvd_led_mask
) & OPA_LED_MASK
);
4035 if (nport
!= 1 || smp_length_check(sizeof(*p
), max_len
)) {
4036 smp
->status
|= IB_SMP_INVALID_FIELD
;
4037 return reply((struct ib_mad_hdr
*)smp
);
4041 hfi1_start_led_override(dd
->pport
, 2000, 1500);
4043 shutdown_led_override(dd
->pport
);
4045 return __subn_get_opa_led_info(smp
, am
, data
, ibdev
, port
, resp_len
,
4049 static int subn_get_opa_sma(__be16 attr_id
, struct opa_smp
*smp
, u32 am
,
4050 u8
*data
, struct ib_device
*ibdev
, u32 port
,
4051 u32
*resp_len
, u32 max_len
)
4054 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
4057 case IB_SMP_ATTR_NODE_DESC
:
4058 ret
= __subn_get_opa_nodedesc(smp
, am
, data
, ibdev
, port
,
4061 case IB_SMP_ATTR_NODE_INFO
:
4062 ret
= __subn_get_opa_nodeinfo(smp
, am
, data
, ibdev
, port
,
4065 case IB_SMP_ATTR_PORT_INFO
:
4066 ret
= __subn_get_opa_portinfo(smp
, am
, data
, ibdev
, port
,
4069 case IB_SMP_ATTR_PKEY_TABLE
:
4070 ret
= __subn_get_opa_pkeytable(smp
, am
, data
, ibdev
, port
,
4073 case OPA_ATTRIB_ID_SL_TO_SC_MAP
:
4074 ret
= __subn_get_opa_sl_to_sc(smp
, am
, data
, ibdev
, port
,
4077 case OPA_ATTRIB_ID_SC_TO_SL_MAP
:
4078 ret
= __subn_get_opa_sc_to_sl(smp
, am
, data
, ibdev
, port
,
4081 case OPA_ATTRIB_ID_SC_TO_VLT_MAP
:
4082 ret
= __subn_get_opa_sc_to_vlt(smp
, am
, data
, ibdev
, port
,
4085 case OPA_ATTRIB_ID_SC_TO_VLNT_MAP
:
4086 ret
= __subn_get_opa_sc_to_vlnt(smp
, am
, data
, ibdev
, port
,
4089 case OPA_ATTRIB_ID_PORT_STATE_INFO
:
4090 ret
= __subn_get_opa_psi(smp
, am
, data
, ibdev
, port
,
4093 case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE
:
4094 ret
= __subn_get_opa_bct(smp
, am
, data
, ibdev
, port
,
4097 case OPA_ATTRIB_ID_CABLE_INFO
:
4098 ret
= __subn_get_opa_cable_info(smp
, am
, data
, ibdev
, port
,
4101 case IB_SMP_ATTR_VL_ARB_TABLE
:
4102 ret
= __subn_get_opa_vl_arb(smp
, am
, data
, ibdev
, port
,
4105 case OPA_ATTRIB_ID_CONGESTION_INFO
:
4106 ret
= __subn_get_opa_cong_info(smp
, am
, data
, ibdev
, port
,
4109 case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING
:
4110 ret
= __subn_get_opa_cong_setting(smp
, am
, data
, ibdev
,
4111 port
, resp_len
, max_len
);
4113 case OPA_ATTRIB_ID_HFI_CONGESTION_LOG
:
4114 ret
= __subn_get_opa_hfi1_cong_log(smp
, am
, data
, ibdev
,
4115 port
, resp_len
, max_len
);
4117 case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE
:
4118 ret
= __subn_get_opa_cc_table(smp
, am
, data
, ibdev
, port
,
4121 case IB_SMP_ATTR_LED_INFO
:
4122 ret
= __subn_get_opa_led_info(smp
, am
, data
, ibdev
, port
,
4125 case IB_SMP_ATTR_SM_INFO
:
4126 if (ibp
->rvp
.port_cap_flags
& IB_PORT_SM_DISABLED
)
4127 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_CONSUMED
;
4128 if (ibp
->rvp
.port_cap_flags
& IB_PORT_SM
)
4129 return IB_MAD_RESULT_SUCCESS
;
4132 smp
->status
|= IB_SMP_UNSUP_METH_ATTR
;
4133 ret
= reply((struct ib_mad_hdr
*)smp
);
4139 static int subn_set_opa_sma(__be16 attr_id
, struct opa_smp
*smp
, u32 am
,
4140 u8
*data
, struct ib_device
*ibdev
, u32 port
,
4141 u32
*resp_len
, u32 max_len
, int local_mad
)
4144 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
4147 case IB_SMP_ATTR_PORT_INFO
:
4148 ret
= __subn_set_opa_portinfo(smp
, am
, data
, ibdev
, port
,
4149 resp_len
, max_len
, local_mad
);
4151 case IB_SMP_ATTR_PKEY_TABLE
:
4152 ret
= __subn_set_opa_pkeytable(smp
, am
, data
, ibdev
, port
,
4155 case OPA_ATTRIB_ID_SL_TO_SC_MAP
:
4156 ret
= __subn_set_opa_sl_to_sc(smp
, am
, data
, ibdev
, port
,
4159 case OPA_ATTRIB_ID_SC_TO_SL_MAP
:
4160 ret
= __subn_set_opa_sc_to_sl(smp
, am
, data
, ibdev
, port
,
4163 case OPA_ATTRIB_ID_SC_TO_VLT_MAP
:
4164 ret
= __subn_set_opa_sc_to_vlt(smp
, am
, data
, ibdev
, port
,
4167 case OPA_ATTRIB_ID_SC_TO_VLNT_MAP
:
4168 ret
= __subn_set_opa_sc_to_vlnt(smp
, am
, data
, ibdev
, port
,
4171 case OPA_ATTRIB_ID_PORT_STATE_INFO
:
4172 ret
= __subn_set_opa_psi(smp
, am
, data
, ibdev
, port
,
4173 resp_len
, max_len
, local_mad
);
4175 case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE
:
4176 ret
= __subn_set_opa_bct(smp
, am
, data
, ibdev
, port
,
4179 case IB_SMP_ATTR_VL_ARB_TABLE
:
4180 ret
= __subn_set_opa_vl_arb(smp
, am
, data
, ibdev
, port
,
4183 case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING
:
4184 ret
= __subn_set_opa_cong_setting(smp
, am
, data
, ibdev
,
4185 port
, resp_len
, max_len
);
4187 case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE
:
4188 ret
= __subn_set_opa_cc_table(smp
, am
, data
, ibdev
, port
,
4191 case IB_SMP_ATTR_LED_INFO
:
4192 ret
= __subn_set_opa_led_info(smp
, am
, data
, ibdev
, port
,
4195 case IB_SMP_ATTR_SM_INFO
:
4196 if (ibp
->rvp
.port_cap_flags
& IB_PORT_SM_DISABLED
)
4197 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_CONSUMED
;
4198 if (ibp
->rvp
.port_cap_flags
& IB_PORT_SM
)
4199 return IB_MAD_RESULT_SUCCESS
;
4202 smp
->status
|= IB_SMP_UNSUP_METH_ATTR
;
4203 ret
= reply((struct ib_mad_hdr
*)smp
);
4209 static inline void set_aggr_error(struct opa_aggregate
*ag
)
4211 ag
->err_reqlength
|= cpu_to_be16(0x8000);
4214 static int subn_get_opa_aggregate(struct opa_smp
*smp
,
4215 struct ib_device
*ibdev
, u32 port
,
4219 u32 num_attr
= be32_to_cpu(smp
->attr_mod
) & 0x000000ff;
4220 u8
*next_smp
= opa_get_smp_data(smp
);
4222 if (num_attr
< 1 || num_attr
> 117) {
4223 smp
->status
|= IB_SMP_INVALID_FIELD
;
4224 return reply((struct ib_mad_hdr
*)smp
);
4227 for (i
= 0; i
< num_attr
; i
++) {
4228 struct opa_aggregate
*agg
;
4229 size_t agg_data_len
;
4233 agg
= (struct opa_aggregate
*)next_smp
;
4234 agg_data_len
= (be16_to_cpu(agg
->err_reqlength
) & 0x007f) * 8;
4235 agg_size
= sizeof(*agg
) + agg_data_len
;
4236 am
= be32_to_cpu(agg
->attr_mod
);
4238 *resp_len
+= agg_size
;
4240 if (next_smp
+ agg_size
> ((u8
*)smp
) + sizeof(*smp
)) {
4241 smp
->status
|= IB_SMP_INVALID_FIELD
;
4242 return reply((struct ib_mad_hdr
*)smp
);
4245 /* zero the payload for this segment */
4246 memset(next_smp
+ sizeof(*agg
), 0, agg_data_len
);
4248 (void)subn_get_opa_sma(agg
->attr_id
, smp
, am
, agg
->data
,
4249 ibdev
, port
, NULL
, (u32
)agg_data_len
);
4251 if (smp
->status
& IB_SMP_INVALID_FIELD
)
4253 if (smp
->status
& ~IB_SMP_DIRECTION
) {
4254 set_aggr_error(agg
);
4255 return reply((struct ib_mad_hdr
*)smp
);
4257 next_smp
+= agg_size
;
4260 return reply((struct ib_mad_hdr
*)smp
);
4263 static int subn_set_opa_aggregate(struct opa_smp
*smp
,
4264 struct ib_device
*ibdev
, u32 port
,
4265 u32
*resp_len
, int local_mad
)
4268 u32 num_attr
= be32_to_cpu(smp
->attr_mod
) & 0x000000ff;
4269 u8
*next_smp
= opa_get_smp_data(smp
);
4271 if (num_attr
< 1 || num_attr
> 117) {
4272 smp
->status
|= IB_SMP_INVALID_FIELD
;
4273 return reply((struct ib_mad_hdr
*)smp
);
4276 for (i
= 0; i
< num_attr
; i
++) {
4277 struct opa_aggregate
*agg
;
4278 size_t agg_data_len
;
4282 agg
= (struct opa_aggregate
*)next_smp
;
4283 agg_data_len
= (be16_to_cpu(agg
->err_reqlength
) & 0x007f) * 8;
4284 agg_size
= sizeof(*agg
) + agg_data_len
;
4285 am
= be32_to_cpu(agg
->attr_mod
);
4287 *resp_len
+= agg_size
;
4289 if (next_smp
+ agg_size
> ((u8
*)smp
) + sizeof(*smp
)) {
4290 smp
->status
|= IB_SMP_INVALID_FIELD
;
4291 return reply((struct ib_mad_hdr
*)smp
);
4294 (void)subn_set_opa_sma(agg
->attr_id
, smp
, am
, agg
->data
,
4295 ibdev
, port
, NULL
, (u32
)agg_data_len
,
4298 if (smp
->status
& IB_SMP_INVALID_FIELD
)
4300 if (smp
->status
& ~IB_SMP_DIRECTION
) {
4301 set_aggr_error(agg
);
4302 return reply((struct ib_mad_hdr
*)smp
);
4304 next_smp
+= agg_size
;
4307 return reply((struct ib_mad_hdr
*)smp
);
4311 * OPAv1 specifies that, on the transition to link up, these counters
4315 * LocalLinkIntegrityErrors
4316 * ExcessiveBufferOverruns [*]
4318 * [*] Error info associated with these counters is retained, but the
4319 * error info status is reset to 0.
4321 void clear_linkup_counters(struct hfi1_devdata
*dd
)
4324 write_dev_cntr(dd
, C_DC_RCV_ERR
, CNTR_INVALID_VL
, 0);
4325 dd
->err_info_rcvport
.status_and_code
&= ~OPA_EI_STATUS_SMASK
;
4326 /* LinkErrorRecovery */
4327 write_dev_cntr(dd
, C_DC_SEQ_CRC_CNT
, CNTR_INVALID_VL
, 0);
4328 write_dev_cntr(dd
, C_DC_REINIT_FROM_PEER_CNT
, CNTR_INVALID_VL
, 0);
4329 /* LocalLinkIntegrityErrors */
4330 write_dev_cntr(dd
, C_DC_RX_REPLAY
, CNTR_INVALID_VL
, 0);
4331 /* ExcessiveBufferOverruns */
4332 write_dev_cntr(dd
, C_RCV_OVF
, CNTR_INVALID_VL
, 0);
4333 dd
->rcv_ovfl_cnt
= 0;
4334 dd
->err_info_xmit_constraint
.status
&= ~OPA_EI_STATUS_SMASK
;
4337 static int is_full_mgmt_pkey_in_table(struct hfi1_ibport
*ibp
)
4340 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
4342 for (i
= 0; i
< ARRAY_SIZE(ppd
->pkeys
); ++i
)
4343 if (ppd
->pkeys
[i
] == FULL_MGMT_P_KEY
)
4350 * is_local_mad() returns 1 if 'mad' is sent from, and destined to the
4351 * local node, 0 otherwise.
4353 static int is_local_mad(struct hfi1_ibport
*ibp
, const struct opa_mad
*mad
,
4354 const struct ib_wc
*in_wc
)
4356 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
4357 const struct opa_smp
*smp
= (const struct opa_smp
*)mad
;
4359 if (smp
->mgmt_class
== IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
) {
4360 return (smp
->hop_cnt
== 0 &&
4361 smp
->route
.dr
.dr_slid
== OPA_LID_PERMISSIVE
&&
4362 smp
->route
.dr
.dr_dlid
== OPA_LID_PERMISSIVE
);
4365 return (in_wc
->slid
== ppd
->lid
);
4369 * opa_local_smp_check() should only be called on MADs for which
4370 * is_local_mad() returns true. It applies the SMP checks that are
4371 * specific to SMPs which are sent from, and destined to this node.
4372 * opa_local_smp_check() returns 0 if the SMP passes its checks, 1
4375 * SMPs which arrive from other nodes are instead checked by
4378 static int opa_local_smp_check(struct hfi1_ibport
*ibp
,
4379 const struct ib_wc
*in_wc
)
4381 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
4384 if (in_wc
->pkey_index
>= ARRAY_SIZE(ppd
->pkeys
))
4387 pkey
= ppd
->pkeys
[in_wc
->pkey_index
];
4389 * We need to do the "node-local" checks specified in OPAv1,
4390 * rev 0.90, section 9.10.26, which are:
4391 * - pkey is 0x7fff, or 0xffff
4392 * - Source QPN == 0 || Destination QPN == 0
4393 * - the MAD header's management class is either
4394 * IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE or
4395 * IB_MGMT_CLASS_SUBN_LID_ROUTED
4398 * However, we know (and so don't need to check again) that,
4399 * for local SMPs, the MAD stack passes MADs with:
4401 * - MAD mgmt_class is IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
4402 * - SLID is either: OPA_LID_PERMISSIVE (0xFFFFFFFF), or
4403 * our own port's lid
4406 if (pkey
== LIM_MGMT_P_KEY
|| pkey
== FULL_MGMT_P_KEY
)
4408 ingress_pkey_table_fail(ppd
, pkey
, in_wc
->slid
);
4413 * hfi1_pkey_validation_pma - It validates PKEYs for incoming PMA MAD packets.
4414 * @ibp: IB port data
4415 * @in_mad: MAD packet with header and data
4416 * @in_wc: Work completion data such as source LID, port number, etc.
4418 * These are all the possible logic rules for validating a pkey:
4420 * a) If pkey neither FULL_MGMT_P_KEY nor LIM_MGMT_P_KEY,
4421 * and NOT self-originated packet:
4422 * Drop MAD packet as it should always be part of the
4423 * management partition unless it's a self-originated packet.
4425 * b) If pkey_index -> FULL_MGMT_P_KEY, and LIM_MGMT_P_KEY in pkey table:
4426 * The packet is coming from a management node and the receiving node
4427 * is also a management node, so it is safe for the packet to go through.
4429 * c) If pkey_index -> FULL_MGMT_P_KEY, and LIM_MGMT_P_KEY is NOT in pkey table:
4430 * Drop the packet as LIM_MGMT_P_KEY should always be in the pkey table.
4431 * It could be an FM misconfiguration.
4433 * d) If pkey_index -> LIM_MGMT_P_KEY and FULL_MGMT_P_KEY is NOT in pkey table:
4434 * It is safe for the packet to go through since a non-management node is
4435 * talking to another non-management node.
4437 * e) If pkey_index -> LIM_MGMT_P_KEY and FULL_MGMT_P_KEY in pkey table:
4438 * Drop the packet because a non-management node is talking to a
4439 * management node, and it could be an attack.
4441 * For the implementation, these rules can be simplied to only checking
4442 * for (a) and (e). There's no need to check for rule (b) as
4443 * the packet doesn't need to be dropped. Rule (c) is not possible in
4444 * the driver as LIM_MGMT_P_KEY is always in the pkey table.
4447 * 0 - pkey is okay, -EINVAL it's a bad pkey
4449 static int hfi1_pkey_validation_pma(struct hfi1_ibport
*ibp
,
4450 const struct opa_mad
*in_mad
,
4451 const struct ib_wc
*in_wc
)
4453 u16 pkey_value
= hfi1_lookup_pkey_value(ibp
, in_wc
->pkey_index
);
4455 /* Rule (a) from above */
4456 if (!is_local_mad(ibp
, in_mad
, in_wc
) &&
4457 pkey_value
!= LIM_MGMT_P_KEY
&&
4458 pkey_value
!= FULL_MGMT_P_KEY
)
4461 /* Rule (e) from above */
4462 if (pkey_value
== LIM_MGMT_P_KEY
&&
4463 is_full_mgmt_pkey_in_table(ibp
))
4469 static int process_subn_opa(struct ib_device
*ibdev
, int mad_flags
,
4470 u32 port
, const struct opa_mad
*in_mad
,
4471 struct opa_mad
*out_mad
,
4472 u32
*resp_len
, int local_mad
)
4474 struct opa_smp
*smp
= (struct opa_smp
*)out_mad
;
4475 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
4482 data
= opa_get_smp_data(smp
);
4483 data_size
= (u32
)opa_get_smp_data_size(smp
);
4485 am
= be32_to_cpu(smp
->attr_mod
);
4486 attr_id
= smp
->attr_id
;
4487 if (smp
->class_version
!= OPA_SM_CLASS_VERSION
) {
4488 smp
->status
|= IB_SMP_UNSUP_VERSION
;
4489 ret
= reply((struct ib_mad_hdr
*)smp
);
4492 ret
= check_mkey(ibp
, (struct ib_mad_hdr
*)smp
, mad_flags
, smp
->mkey
,
4493 smp
->route
.dr
.dr_slid
, smp
->route
.dr
.return_path
,
4496 u32 port_num
= be32_to_cpu(smp
->attr_mod
);
4499 * If this is a get/set portinfo, we already check the
4500 * M_Key if the MAD is for another port and the M_Key
4501 * is OK on the receiving port. This check is needed
4502 * to increment the error counters when the M_Key
4503 * fails to match on *both* ports.
4505 if (attr_id
== IB_SMP_ATTR_PORT_INFO
&&
4506 (smp
->method
== IB_MGMT_METHOD_GET
||
4507 smp
->method
== IB_MGMT_METHOD_SET
) &&
4508 port_num
&& port_num
<= ibdev
->phys_port_cnt
&&
4510 (void)check_mkey(to_iport(ibdev
, port_num
),
4511 (struct ib_mad_hdr
*)smp
, 0,
4512 smp
->mkey
, smp
->route
.dr
.dr_slid
,
4513 smp
->route
.dr
.return_path
,
4515 ret
= IB_MAD_RESULT_FAILURE
;
4519 *resp_len
= opa_get_smp_header_size(smp
);
4521 switch (smp
->method
) {
4522 case IB_MGMT_METHOD_GET
:
4525 clear_opa_smp_data(smp
);
4526 ret
= subn_get_opa_sma(attr_id
, smp
, am
, data
,
4527 ibdev
, port
, resp_len
,
4530 case OPA_ATTRIB_ID_AGGREGATE
:
4531 ret
= subn_get_opa_aggregate(smp
, ibdev
, port
,
4536 case IB_MGMT_METHOD_SET
:
4539 ret
= subn_set_opa_sma(attr_id
, smp
, am
, data
,
4540 ibdev
, port
, resp_len
,
4541 data_size
, local_mad
);
4543 case OPA_ATTRIB_ID_AGGREGATE
:
4544 ret
= subn_set_opa_aggregate(smp
, ibdev
, port
,
4545 resp_len
, local_mad
);
4549 case IB_MGMT_METHOD_TRAP
:
4550 case IB_MGMT_METHOD_REPORT
:
4551 case IB_MGMT_METHOD_REPORT_RESP
:
4552 case IB_MGMT_METHOD_GET_RESP
:
4554 * The ib_mad module will call us to process responses
4555 * before checking for other consumers.
4556 * Just tell the caller to process it normally.
4558 ret
= IB_MAD_RESULT_SUCCESS
;
4560 case IB_MGMT_METHOD_TRAP_REPRESS
:
4561 subn_handle_opa_trap_repress(ibp
, smp
);
4562 /* Always successful */
4563 ret
= IB_MAD_RESULT_SUCCESS
;
4566 smp
->status
|= IB_SMP_UNSUP_METHOD
;
4567 ret
= reply((struct ib_mad_hdr
*)smp
);
4574 static int process_subn(struct ib_device
*ibdev
, int mad_flags
,
4575 u32 port
, const struct ib_mad
*in_mad
,
4576 struct ib_mad
*out_mad
)
4578 struct ib_smp
*smp
= (struct ib_smp
*)out_mad
;
4579 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
4583 if (smp
->class_version
!= 1) {
4584 smp
->status
|= IB_SMP_UNSUP_VERSION
;
4585 ret
= reply((struct ib_mad_hdr
*)smp
);
4589 ret
= check_mkey(ibp
, (struct ib_mad_hdr
*)smp
, mad_flags
,
4590 smp
->mkey
, (__force __be32
)smp
->dr_slid
,
4591 smp
->return_path
, smp
->hop_cnt
);
4593 u32 port_num
= be32_to_cpu(smp
->attr_mod
);
4596 * If this is a get/set portinfo, we already check the
4597 * M_Key if the MAD is for another port and the M_Key
4598 * is OK on the receiving port. This check is needed
4599 * to increment the error counters when the M_Key
4600 * fails to match on *both* ports.
4602 if (in_mad
->mad_hdr
.attr_id
== IB_SMP_ATTR_PORT_INFO
&&
4603 (smp
->method
== IB_MGMT_METHOD_GET
||
4604 smp
->method
== IB_MGMT_METHOD_SET
) &&
4605 port_num
&& port_num
<= ibdev
->phys_port_cnt
&&
4607 (void)check_mkey(to_iport(ibdev
, port_num
),
4608 (struct ib_mad_hdr
*)smp
, 0,
4610 (__force __be32
)smp
->dr_slid
,
4611 smp
->return_path
, smp
->hop_cnt
);
4612 ret
= IB_MAD_RESULT_FAILURE
;
4616 switch (smp
->method
) {
4617 case IB_MGMT_METHOD_GET
:
4618 switch (smp
->attr_id
) {
4619 case IB_SMP_ATTR_NODE_INFO
:
4620 ret
= subn_get_nodeinfo(smp
, ibdev
, port
);
4623 smp
->status
|= IB_SMP_UNSUP_METH_ATTR
;
4624 ret
= reply((struct ib_mad_hdr
*)smp
);
4633 static int process_perf(struct ib_device
*ibdev
, u32 port
,
4634 const struct ib_mad
*in_mad
,
4635 struct ib_mad
*out_mad
)
4637 struct ib_pma_mad
*pmp
= (struct ib_pma_mad
*)out_mad
;
4638 struct ib_class_port_info
*cpi
= (struct ib_class_port_info
*)
4640 int ret
= IB_MAD_RESULT_FAILURE
;
4643 if (pmp
->mad_hdr
.class_version
!= 1) {
4644 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_VERSION
;
4645 ret
= reply((struct ib_mad_hdr
*)pmp
);
4649 switch (pmp
->mad_hdr
.method
) {
4650 case IB_MGMT_METHOD_GET
:
4651 switch (pmp
->mad_hdr
.attr_id
) {
4652 case IB_PMA_PORT_COUNTERS
:
4653 ret
= pma_get_ib_portcounters(pmp
, ibdev
, port
);
4655 case IB_PMA_PORT_COUNTERS_EXT
:
4656 ret
= pma_get_ib_portcounters_ext(pmp
, ibdev
, port
);
4658 case IB_PMA_CLASS_PORT_INFO
:
4659 cpi
->capability_mask
= IB_PMA_CLASS_CAP_EXT_WIDTH
;
4660 ret
= reply((struct ib_mad_hdr
*)pmp
);
4663 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METH_ATTR
;
4664 ret
= reply((struct ib_mad_hdr
*)pmp
);
4669 case IB_MGMT_METHOD_SET
:
4670 if (pmp
->mad_hdr
.attr_id
) {
4671 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METH_ATTR
;
4672 ret
= reply((struct ib_mad_hdr
*)pmp
);
4676 case IB_MGMT_METHOD_TRAP
:
4677 case IB_MGMT_METHOD_GET_RESP
:
4679 * The ib_mad module will call us to process responses
4680 * before checking for other consumers.
4681 * Just tell the caller to process it normally.
4683 ret
= IB_MAD_RESULT_SUCCESS
;
4687 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METHOD
;
4688 ret
= reply((struct ib_mad_hdr
*)pmp
);
4695 static int process_perf_opa(struct ib_device
*ibdev
, u32 port
,
4696 const struct opa_mad
*in_mad
,
4697 struct opa_mad
*out_mad
, u32
*resp_len
)
4699 struct opa_pma_mad
*pmp
= (struct opa_pma_mad
*)out_mad
;
4704 if (pmp
->mad_hdr
.class_version
!= OPA_SM_CLASS_VERSION
) {
4705 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_VERSION
;
4706 return reply((struct ib_mad_hdr
*)pmp
);
4709 *resp_len
= sizeof(pmp
->mad_hdr
);
4711 switch (pmp
->mad_hdr
.method
) {
4712 case IB_MGMT_METHOD_GET
:
4713 switch (pmp
->mad_hdr
.attr_id
) {
4714 case IB_PMA_CLASS_PORT_INFO
:
4715 ret
= pma_get_opa_classportinfo(pmp
, ibdev
, resp_len
);
4717 case OPA_PM_ATTRIB_ID_PORT_STATUS
:
4718 ret
= pma_get_opa_portstatus(pmp
, ibdev
, port
,
4721 case OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERS
:
4722 ret
= pma_get_opa_datacounters(pmp
, ibdev
, port
,
4725 case OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS
:
4726 ret
= pma_get_opa_porterrors(pmp
, ibdev
, port
,
4729 case OPA_PM_ATTRIB_ID_ERROR_INFO
:
4730 ret
= pma_get_opa_errorinfo(pmp
, ibdev
, port
,
4734 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METH_ATTR
;
4735 ret
= reply((struct ib_mad_hdr
*)pmp
);
4740 case IB_MGMT_METHOD_SET
:
4741 switch (pmp
->mad_hdr
.attr_id
) {
4742 case OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS
:
4743 ret
= pma_set_opa_portstatus(pmp
, ibdev
, port
,
4746 case OPA_PM_ATTRIB_ID_ERROR_INFO
:
4747 ret
= pma_set_opa_errorinfo(pmp
, ibdev
, port
,
4751 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METH_ATTR
;
4752 ret
= reply((struct ib_mad_hdr
*)pmp
);
4757 case IB_MGMT_METHOD_TRAP
:
4758 case IB_MGMT_METHOD_GET_RESP
:
4760 * The ib_mad module will call us to process responses
4761 * before checking for other consumers.
4762 * Just tell the caller to process it normally.
4764 ret
= IB_MAD_RESULT_SUCCESS
;
4768 pmp
->mad_hdr
.status
|= IB_SMP_UNSUP_METHOD
;
4769 ret
= reply((struct ib_mad_hdr
*)pmp
);
4776 static int hfi1_process_opa_mad(struct ib_device
*ibdev
, int mad_flags
,
4777 u32 port
, const struct ib_wc
*in_wc
,
4778 const struct ib_grh
*in_grh
,
4779 const struct opa_mad
*in_mad
,
4780 struct opa_mad
*out_mad
, size_t *out_mad_size
,
4781 u16
*out_mad_pkey_index
)
4786 u32 resp_len
= in_wc
->byte_len
- sizeof(*in_grh
);
4787 struct hfi1_ibport
*ibp
= to_iport(ibdev
, port
);
4789 pkey_idx
= hfi1_lookup_pkey_idx(ibp
, LIM_MGMT_P_KEY
);
4791 pr_warn("failed to find limited mgmt pkey, defaulting 0x%x\n",
4792 hfi1_get_pkey(ibp
, 1));
4795 *out_mad_pkey_index
= (u16
)pkey_idx
;
4797 switch (in_mad
->mad_hdr
.mgmt_class
) {
4798 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
:
4799 case IB_MGMT_CLASS_SUBN_LID_ROUTED
:
4800 local_mad
= is_local_mad(ibp
, in_mad
, in_wc
);
4802 ret
= opa_local_smp_check(ibp
, in_wc
);
4804 return IB_MAD_RESULT_FAILURE
;
4806 ret
= process_subn_opa(ibdev
, mad_flags
, port
, in_mad
,
4807 out_mad
, &resp_len
, local_mad
);
4809 case IB_MGMT_CLASS_PERF_MGMT
:
4810 ret
= hfi1_pkey_validation_pma(ibp
, in_mad
, in_wc
);
4812 return IB_MAD_RESULT_FAILURE
;
4814 ret
= process_perf_opa(ibdev
, port
, in_mad
, out_mad
, &resp_len
);
4818 ret
= IB_MAD_RESULT_SUCCESS
;
4822 if (ret
& IB_MAD_RESULT_REPLY
)
4823 *out_mad_size
= round_up(resp_len
, 8);
4824 else if (ret
& IB_MAD_RESULT_SUCCESS
)
4825 *out_mad_size
= in_wc
->byte_len
- sizeof(struct ib_grh
);
4830 static int hfi1_process_ib_mad(struct ib_device
*ibdev
, int mad_flags
, u32 port
,
4831 const struct ib_wc
*in_wc
,
4832 const struct ib_grh
*in_grh
,
4833 const struct ib_mad
*in_mad
,
4834 struct ib_mad
*out_mad
)
4838 switch (in_mad
->mad_hdr
.mgmt_class
) {
4839 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
:
4840 case IB_MGMT_CLASS_SUBN_LID_ROUTED
:
4841 ret
= process_subn(ibdev
, mad_flags
, port
, in_mad
, out_mad
);
4843 case IB_MGMT_CLASS_PERF_MGMT
:
4844 ret
= process_perf(ibdev
, port
, in_mad
, out_mad
);
4847 ret
= IB_MAD_RESULT_SUCCESS
;
4855 * hfi1_process_mad - process an incoming MAD packet
4856 * @ibdev: the infiniband device this packet came in on
4857 * @mad_flags: MAD flags
4858 * @port: the port number this packet came in on
4859 * @in_wc: the work completion entry for this packet
4860 * @in_grh: the global route header for this packet
4861 * @in_mad: the incoming MAD
4862 * @out_mad: any outgoing MAD reply
4863 * @out_mad_size: size of the outgoing MAD reply
4864 * @out_mad_pkey_index: used to apss back the packet key index
4866 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
4867 * interested in processing.
4869 * Note that the verbs framework has already done the MAD sanity checks,
4870 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
4873 * This is called by the ib_mad module.
4875 int hfi1_process_mad(struct ib_device
*ibdev
, int mad_flags
, u32 port
,
4876 const struct ib_wc
*in_wc
, const struct ib_grh
*in_grh
,
4877 const struct ib_mad
*in_mad
, struct ib_mad
*out_mad
,
4878 size_t *out_mad_size
, u16
*out_mad_pkey_index
)
4880 switch (in_mad
->mad_hdr
.base_version
) {
4881 case OPA_MGMT_BASE_VERSION
:
4882 return hfi1_process_opa_mad(ibdev
, mad_flags
, port
,
4884 (struct opa_mad
*)in_mad
,
4885 (struct opa_mad
*)out_mad
,
4887 out_mad_pkey_index
);
4888 case IB_MGMT_BASE_VERSION
:
4889 return hfi1_process_ib_mad(ibdev
, mad_flags
, port
, in_wc
,
4890 in_grh
, in_mad
, out_mad
);
4895 return IB_MAD_RESULT_FAILURE
;