2 * Copyright(c) 2015-2017 Intel Corporation.
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 #include <linux/spinlock.h>
49 #include <linux/pci.h>
51 #include <linux/delay.h>
52 #include <linux/netdevice.h>
53 #include <linux/vmalloc.h>
54 #include <linux/module.h>
55 #include <linux/prefetch.h>
56 #include <rdma/ib_verbs.h>
66 #define pr_fmt(fmt) DRIVER_NAME ": " fmt
69 * The size has to be longer than this string, so we can append
70 * board/chip information to it in the initialization code.
72 const char ib_hfi1_version
[] = HFI1_DRIVER_VERSION
"\n";
74 DEFINE_SPINLOCK(hfi1_devs_lock
);
75 LIST_HEAD(hfi1_dev_list
);
76 DEFINE_MUTEX(hfi1_mutex
); /* general driver use */
78 unsigned int hfi1_max_mtu
= HFI1_DEFAULT_MAX_MTU
;
79 module_param_named(max_mtu
, hfi1_max_mtu
, uint
, S_IRUGO
);
80 MODULE_PARM_DESC(max_mtu
, "Set max MTU bytes, default is " __stringify(
81 HFI1_DEFAULT_MAX_MTU
));
83 unsigned int hfi1_cu
= 1;
84 module_param_named(cu
, hfi1_cu
, uint
, S_IRUGO
);
85 MODULE_PARM_DESC(cu
, "Credit return units");
87 unsigned long hfi1_cap_mask
= HFI1_CAP_MASK_DEFAULT
;
88 static int hfi1_caps_set(const char *val
, const struct kernel_param
*kp
);
89 static int hfi1_caps_get(char *buffer
, const struct kernel_param
*kp
);
90 static const struct kernel_param_ops cap_ops
= {
94 module_param_cb(cap_mask
, &cap_ops
, &hfi1_cap_mask
, S_IWUSR
| S_IRUGO
);
95 MODULE_PARM_DESC(cap_mask
, "Bit mask of enabled/disabled HW features");
97 MODULE_LICENSE("Dual BSD/GPL");
98 MODULE_DESCRIPTION("Intel Omni-Path Architecture driver");
101 * MAX_PKT_RCV is the max # if packets processed per receive interrupt.
103 #define MAX_PKT_RECV 64
105 * MAX_PKT_THREAD_RCV is the max # of packets processed before
106 * the qp_wait_list queue is flushed.
108 #define MAX_PKT_RECV_THREAD (MAX_PKT_RECV * 4)
109 #define EGR_HEAD_UPDATE_THRESHOLD 16
111 struct hfi1_ib_stats hfi1_stats
;
113 static int hfi1_caps_set(const char *val
, const struct kernel_param
*kp
)
116 unsigned long *cap_mask_ptr
= (unsigned long *)kp
->arg
,
117 cap_mask
= *cap_mask_ptr
, value
, diff
,
118 write_mask
= ((HFI1_CAP_WRITABLE_MASK
<< HFI1_CAP_USER_SHIFT
) |
119 HFI1_CAP_WRITABLE_MASK
);
121 ret
= kstrtoul(val
, 0, &value
);
123 pr_warn("Invalid module parameter value for 'cap_mask'\n");
126 /* Get the changed bits (except the locked bit) */
127 diff
= value
^ (cap_mask
& ~HFI1_CAP_LOCKED_SMASK
);
129 /* Remove any bits that are not allowed to change after driver load */
130 if (HFI1_CAP_LOCKED() && (diff
& ~write_mask
)) {
131 pr_warn("Ignoring non-writable capability bits %#lx\n",
136 /* Mask off any reserved bits */
137 diff
&= ~HFI1_CAP_RESERVED_MASK
;
138 /* Clear any previously set and changing bits */
140 /* Update the bits with the new capability */
141 cap_mask
|= (value
& diff
);
142 /* Check for any kernel/user restrictions */
143 diff
= (cap_mask
& (HFI1_CAP_MUST_HAVE_KERN
<< HFI1_CAP_USER_SHIFT
)) ^
144 ((cap_mask
& HFI1_CAP_MUST_HAVE_KERN
) << HFI1_CAP_USER_SHIFT
);
146 /* Set the bitmask to the final set */
147 *cap_mask_ptr
= cap_mask
;
152 static int hfi1_caps_get(char *buffer
, const struct kernel_param
*kp
)
154 unsigned long cap_mask
= *(unsigned long *)kp
->arg
;
156 cap_mask
&= ~HFI1_CAP_LOCKED_SMASK
;
157 cap_mask
|= ((cap_mask
& HFI1_CAP_K2U
) << HFI1_CAP_USER_SHIFT
);
159 return scnprintf(buffer
, PAGE_SIZE
, "0x%lx", cap_mask
);
162 struct pci_dev
*get_pci_dev(struct rvt_dev_info
*rdi
)
164 struct hfi1_ibdev
*ibdev
= container_of(rdi
, struct hfi1_ibdev
, rdi
);
165 struct hfi1_devdata
*dd
= container_of(ibdev
,
166 struct hfi1_devdata
, verbs_dev
);
171 * Return count of units with at least one port ACTIVE.
173 int hfi1_count_active_units(void)
175 struct hfi1_devdata
*dd
;
176 struct hfi1_pportdata
*ppd
;
178 int pidx
, nunits_active
= 0;
180 spin_lock_irqsave(&hfi1_devs_lock
, flags
);
181 list_for_each_entry(dd
, &hfi1_dev_list
, list
) {
182 if (!(dd
->flags
& HFI1_PRESENT
) || !dd
->kregbase1
)
184 for (pidx
= 0; pidx
< dd
->num_pports
; ++pidx
) {
185 ppd
= dd
->pport
+ pidx
;
186 if (ppd
->lid
&& ppd
->linkup
) {
192 spin_unlock_irqrestore(&hfi1_devs_lock
, flags
);
193 return nunits_active
;
197 * Get address of eager buffer from it's index (allocated in chunks, not
200 static inline void *get_egrbuf(const struct hfi1_ctxtdata
*rcd
, u64 rhf
,
203 u32 idx
= rhf_egr_index(rhf
), offset
= rhf_egr_buf_offset(rhf
);
205 *update
|= !(idx
& (rcd
->egrbufs
.threshold
- 1)) && !offset
;
206 return (void *)(((u64
)(rcd
->egrbufs
.rcvtids
[idx
].addr
)) +
207 (offset
* RCV_BUF_BLOCK_SIZE
));
210 static inline void *hfi1_get_header(struct hfi1_devdata
*dd
,
213 u32 offset
= rhf_hdrq_offset(rhf_to_cpu(rhf_addr
));
215 return (void *)(rhf_addr
- dd
->rhf_offset
+ offset
);
218 static inline struct ib_header
*hfi1_get_msgheader(struct hfi1_devdata
*dd
,
221 return (struct ib_header
*)hfi1_get_header(dd
, rhf_addr
);
224 static inline struct hfi1_16b_header
225 *hfi1_get_16B_header(struct hfi1_devdata
*dd
,
228 return (struct hfi1_16b_header
*)hfi1_get_header(dd
, rhf_addr
);
232 * Validate and encode the a given RcvArray Buffer size.
233 * The function will check whether the given size falls within
234 * allowed size ranges for the respective type and, optionally,
235 * return the proper encoding.
237 int hfi1_rcvbuf_validate(u32 size
, u8 type
, u16
*encoded
)
239 if (unlikely(!PAGE_ALIGNED(size
)))
241 if (unlikely(size
< MIN_EAGER_BUFFER
))
244 (type
== PT_EAGER
? MAX_EAGER_BUFFER
: MAX_EXPECTED_BUFFER
))
247 *encoded
= ilog2(size
/ PAGE_SIZE
) + 1;
251 static void rcv_hdrerr(struct hfi1_ctxtdata
*rcd
, struct hfi1_pportdata
*ppd
,
252 struct hfi1_packet
*packet
)
254 struct ib_header
*rhdr
= packet
->hdr
;
255 u32 rte
= rhf_rcv_type_err(packet
->rhf
);
257 struct hfi1_ibport
*ibp
= rcd_to_iport(rcd
);
258 struct hfi1_devdata
*dd
= ppd
->dd
;
259 struct hfi1_ibdev
*verbs_dev
= &dd
->verbs_dev
;
260 struct rvt_dev_info
*rdi
= &verbs_dev
->rdi
;
262 if ((packet
->rhf
& RHF_DC_ERR
) &&
263 hfi1_dbg_fault_suppress_err(verbs_dev
))
266 if (packet
->rhf
& (RHF_VCRC_ERR
| RHF_ICRC_ERR
))
269 if (packet
->etype
== RHF_RCV_TYPE_BYPASS
) {
272 u8 lnh
= ib_get_lnh(rhdr
);
274 mlid_base
= be16_to_cpu(IB_MULTICAST_LID_BASE
);
275 if (lnh
== HFI1_LRH_BTH
) {
276 packet
->ohdr
= &rhdr
->u
.oth
;
277 } else if (lnh
== HFI1_LRH_GRH
) {
278 packet
->ohdr
= &rhdr
->u
.l
.oth
;
279 packet
->grh
= &rhdr
->u
.l
.grh
;
285 if (packet
->rhf
& RHF_TID_ERR
) {
286 /* For TIDERR and RC QPs preemptively schedule a NAK */
287 u32 tlen
= rhf_pkt_len(packet
->rhf
); /* in bytes */
288 u32 dlid
= ib_get_dlid(rhdr
);
291 /* Sanity check packet */
298 struct ib_grh
*grh
= packet
->grh
;
300 if (grh
->next_hdr
!= IB_GRH_NEXT_HDR
)
302 vtf
= be32_to_cpu(grh
->version_tclass_flow
);
303 if ((vtf
>> IB_GRH_VERSION_SHIFT
) != IB_GRH_VERSION
)
307 /* Get the destination QP number. */
308 qp_num
= ib_bth_get_qpn(packet
->ohdr
);
309 if (dlid
< mlid_base
) {
314 qp
= rvt_lookup_qpn(rdi
, &ibp
->rvp
, qp_num
);
321 * Handle only RC QPs - for other QP types drop error
324 spin_lock_irqsave(&qp
->r_lock
, flags
);
326 /* Check for valid receive state. */
327 if (!(ib_rvt_state_ops
[qp
->state
] &
328 RVT_PROCESS_RECV_OK
)) {
329 ibp
->rvp
.n_pkt_drops
++;
332 switch (qp
->ibqp
.qp_type
) {
334 hfi1_rc_hdrerr(rcd
, packet
, qp
);
337 /* For now don't handle any other QP types */
341 spin_unlock_irqrestore(&qp
->r_lock
, flags
);
344 } /* Valid packet with TIDErr */
346 /* handle "RcvTypeErr" flags */
348 case RHF_RTE_ERROR_OP_CODE_ERR
:
353 if (rhf_use_egr_bfr(packet
->rhf
))
357 goto drop
; /* this should never happen */
359 opcode
= ib_bth_get_opcode(packet
->ohdr
);
360 if (opcode
== IB_OPCODE_CNP
) {
362 * Only in pre-B0 h/w is the CNP_OPCODE handled
363 * via this code path.
365 struct rvt_qp
*qp
= NULL
;
368 u8 svc_type
, sl
, sc5
;
370 sc5
= hfi1_9B_get_sc5(rhdr
, packet
->rhf
);
371 sl
= ibp
->sc_to_sl
[sc5
];
373 lqpn
= ib_bth_get_qpn(packet
->ohdr
);
375 qp
= rvt_lookup_qpn(rdi
, &ibp
->rvp
, lqpn
);
381 switch (qp
->ibqp
.qp_type
) {
385 svc_type
= IB_CC_SVCTYPE_UD
;
388 rlid
= ib_get_slid(rhdr
);
389 rqpn
= qp
->remote_qpn
;
390 svc_type
= IB_CC_SVCTYPE_UC
;
396 process_becn(ppd
, sl
, rlid
, lqpn
, rqpn
, svc_type
);
400 packet
->rhf
&= ~RHF_RCV_TYPE_ERR_SMASK
;
411 static inline void init_packet(struct hfi1_ctxtdata
*rcd
,
412 struct hfi1_packet
*packet
)
414 packet
->rsize
= rcd
->rcvhdrqentsize
; /* words */
415 packet
->maxcnt
= rcd
->rcvhdrq_cnt
* packet
->rsize
; /* words */
419 packet
->rhf_addr
= get_rhf_addr(rcd
);
420 packet
->rhf
= rhf_to_cpu(packet
->rhf_addr
);
421 packet
->rhqoff
= rcd
->head
;
425 /* We support only two types - 9B and 16B for now */
426 static const hfi1_handle_cnp hfi1_handle_cnp_tbl
[2] = {
427 [HFI1_PKT_TYPE_9B
] = &return_cnp
,
428 [HFI1_PKT_TYPE_16B
] = &return_cnp_16B
431 void hfi1_process_ecn_slowpath(struct rvt_qp
*qp
, struct hfi1_packet
*pkt
,
434 struct hfi1_ibport
*ibp
= to_iport(qp
->ibqp
.device
, qp
->port_num
);
435 struct ib_other_headers
*ohdr
= pkt
->ohdr
;
436 struct ib_grh
*grh
= pkt
->grh
;
438 u16 pkey
, rlid
, dlid
= ib_get_dlid(pkt
->hdr
);
439 u8 hdr_type
, sc
, svc_type
;
440 bool is_mcast
= false;
442 if (pkt
->etype
== RHF_RCV_TYPE_BYPASS
) {
443 is_mcast
= hfi1_is_16B_mcast(dlid
);
444 pkey
= hfi1_16B_get_pkey(pkt
->hdr
);
445 sc
= hfi1_16B_get_sc(pkt
->hdr
);
446 hdr_type
= HFI1_PKT_TYPE_16B
;
448 is_mcast
= (dlid
> be16_to_cpu(IB_MULTICAST_LID_BASE
)) &&
449 (dlid
!= be16_to_cpu(IB_LID_PERMISSIVE
));
450 pkey
= ib_bth_get_pkey(ohdr
);
451 sc
= hfi1_9B_get_sc5(pkt
->hdr
, pkt
->rhf
);
452 hdr_type
= HFI1_PKT_TYPE_9B
;
455 switch (qp
->ibqp
.qp_type
) {
459 rlid
= ib_get_slid(pkt
->hdr
);
460 rqpn
= ib_get_sqpn(pkt
->ohdr
);
461 svc_type
= IB_CC_SVCTYPE_UD
;
464 rlid
= rdma_ah_get_dlid(&qp
->remote_ah_attr
);
465 rqpn
= qp
->remote_qpn
;
466 svc_type
= IB_CC_SVCTYPE_UC
;
469 rlid
= rdma_ah_get_dlid(&qp
->remote_ah_attr
);
470 rqpn
= qp
->remote_qpn
;
471 svc_type
= IB_CC_SVCTYPE_RC
;
477 bth1
= be32_to_cpu(ohdr
->bth
[1]);
478 /* Call appropriate CNP handler */
479 if (do_cnp
&& (bth1
& IB_FECN_SMASK
))
480 hfi1_handle_cnp_tbl
[hdr_type
](ibp
, qp
, rqpn
, pkey
,
481 dlid
, rlid
, sc
, grh
);
483 if (!is_mcast
&& (bth1
& IB_BECN_SMASK
)) {
484 struct hfi1_pportdata
*ppd
= ppd_from_ibp(ibp
);
485 u32 lqpn
= bth1
& RVT_QPN_MASK
;
486 u8 sl
= ibp
->sc_to_sl
[sc
];
488 process_becn(ppd
, sl
, rlid
, lqpn
, rqpn
, svc_type
);
494 struct hfi1_ctxtdata
*rcd
;
502 static inline void init_ps_mdata(struct ps_mdata
*mdata
,
503 struct hfi1_packet
*packet
)
505 struct hfi1_ctxtdata
*rcd
= packet
->rcd
;
508 mdata
->rsize
= packet
->rsize
;
509 mdata
->maxcnt
= packet
->maxcnt
;
510 mdata
->ps_head
= packet
->rhqoff
;
512 if (HFI1_CAP_KGET_MASK(rcd
->flags
, DMA_RTAIL
)) {
513 mdata
->ps_tail
= get_rcvhdrtail(rcd
);
514 if (rcd
->ctxt
== HFI1_CTRL_CTXT
)
515 mdata
->ps_seq
= rcd
->seq_cnt
;
517 mdata
->ps_seq
= 0; /* not used with DMA_RTAIL */
519 mdata
->ps_tail
= 0; /* used only with DMA_RTAIL*/
520 mdata
->ps_seq
= rcd
->seq_cnt
;
524 static inline int ps_done(struct ps_mdata
*mdata
, u64 rhf
,
525 struct hfi1_ctxtdata
*rcd
)
527 if (HFI1_CAP_KGET_MASK(rcd
->flags
, DMA_RTAIL
))
528 return mdata
->ps_head
== mdata
->ps_tail
;
529 return mdata
->ps_seq
!= rhf_rcv_seq(rhf
);
532 static inline int ps_skip(struct ps_mdata
*mdata
, u64 rhf
,
533 struct hfi1_ctxtdata
*rcd
)
536 * Control context can potentially receive an invalid rhf.
539 if ((rcd
->ctxt
== HFI1_CTRL_CTXT
) && (mdata
->ps_head
!= mdata
->ps_tail
))
540 return mdata
->ps_seq
!= rhf_rcv_seq(rhf
);
545 static inline void update_ps_mdata(struct ps_mdata
*mdata
,
546 struct hfi1_ctxtdata
*rcd
)
548 mdata
->ps_head
+= mdata
->rsize
;
549 if (mdata
->ps_head
>= mdata
->maxcnt
)
552 /* Control context must do seq counting */
553 if (!HFI1_CAP_KGET_MASK(rcd
->flags
, DMA_RTAIL
) ||
554 (rcd
->ctxt
== HFI1_CTRL_CTXT
)) {
555 if (++mdata
->ps_seq
> 13)
561 * prescan_rxq - search through the receive queue looking for packets
562 * containing Excplicit Congestion Notifications (FECNs, or BECNs).
563 * When an ECN is found, process the Congestion Notification, and toggle
565 * This is declared as a macro to allow quick checking of the port to avoid
566 * the overhead of a function call if not enabled.
568 #define prescan_rxq(rcd, packet) \
570 if (rcd->ppd->cc_prescan) \
571 __prescan_rxq(packet); \
573 static void __prescan_rxq(struct hfi1_packet
*packet
)
575 struct hfi1_ctxtdata
*rcd
= packet
->rcd
;
576 struct ps_mdata mdata
;
578 init_ps_mdata(&mdata
, packet
);
581 struct hfi1_devdata
*dd
= rcd
->dd
;
582 struct hfi1_ibport
*ibp
= rcd_to_iport(rcd
);
583 __le32
*rhf_addr
= (__le32
*)rcd
->rcvhdrq
+ mdata
.ps_head
+
586 struct ib_header
*hdr
;
587 struct rvt_dev_info
*rdi
= &dd
->verbs_dev
.rdi
;
588 u64 rhf
= rhf_to_cpu(rhf_addr
);
589 u32 etype
= rhf_rcv_type(rhf
), qpn
, bth1
;
593 if (ps_done(&mdata
, rhf
, rcd
))
596 if (ps_skip(&mdata
, rhf
, rcd
))
599 if (etype
!= RHF_RCV_TYPE_IB
)
602 packet
->hdr
= hfi1_get_msgheader(dd
, rhf_addr
);
604 lnh
= ib_get_lnh(hdr
);
606 if (lnh
== HFI1_LRH_BTH
) {
607 packet
->ohdr
= &hdr
->u
.oth
;
609 } else if (lnh
== HFI1_LRH_GRH
) {
610 packet
->ohdr
= &hdr
->u
.l
.oth
;
611 packet
->grh
= &hdr
->u
.l
.grh
;
613 goto next
; /* just in case */
616 bth1
= be32_to_cpu(packet
->ohdr
->bth
[1]);
617 is_ecn
= !!(bth1
& (IB_FECN_SMASK
| IB_BECN_SMASK
));
622 qpn
= bth1
& RVT_QPN_MASK
;
624 qp
= rvt_lookup_qpn(rdi
, &ibp
->rvp
, qpn
);
631 process_ecn(qp
, packet
, true);
634 /* turn off BECN, FECN */
635 bth1
&= ~(IB_FECN_SMASK
| IB_BECN_SMASK
);
636 packet
->ohdr
->bth
[1] = cpu_to_be32(bth1
);
638 update_ps_mdata(&mdata
, rcd
);
642 static void process_rcv_qp_work(struct hfi1_packet
*packet
)
644 struct rvt_qp
*qp
, *nqp
;
645 struct hfi1_ctxtdata
*rcd
= packet
->rcd
;
648 * Iterate over all QPs waiting to respond.
649 * The list won't change since the IRQ is only run on one CPU.
651 list_for_each_entry_safe(qp
, nqp
, &rcd
->qp_wait_list
, rspwait
) {
652 list_del_init(&qp
->rspwait
);
653 if (qp
->r_flags
& RVT_R_RSP_NAK
) {
654 qp
->r_flags
&= ~RVT_R_RSP_NAK
;
656 hfi1_send_rc_ack(packet
, 0);
658 if (qp
->r_flags
& RVT_R_RSP_SEND
) {
661 qp
->r_flags
&= ~RVT_R_RSP_SEND
;
662 spin_lock_irqsave(&qp
->s_lock
, flags
);
663 if (ib_rvt_state_ops
[qp
->state
] &
664 RVT_PROCESS_OR_FLUSH_SEND
)
665 hfi1_schedule_send(qp
);
666 spin_unlock_irqrestore(&qp
->s_lock
, flags
);
672 static noinline
int max_packet_exceeded(struct hfi1_packet
*packet
, int thread
)
675 if ((packet
->numpkt
& (MAX_PKT_RECV_THREAD
- 1)) == 0)
676 /* allow defered processing */
677 process_rcv_qp_work(packet
);
681 this_cpu_inc(*packet
->rcd
->dd
->rcv_limit
);
682 return RCV_PKT_LIMIT
;
686 static inline int check_max_packet(struct hfi1_packet
*packet
, int thread
)
688 int ret
= RCV_PKT_OK
;
690 if (unlikely((packet
->numpkt
& (MAX_PKT_RECV
- 1)) == 0))
691 ret
= max_packet_exceeded(packet
, thread
);
695 static noinline
int skip_rcv_packet(struct hfi1_packet
*packet
, int thread
)
699 /* Set up for the next packet */
700 packet
->rhqoff
+= packet
->rsize
;
701 if (packet
->rhqoff
>= packet
->maxcnt
)
705 ret
= check_max_packet(packet
, thread
);
707 packet
->rhf_addr
= (__le32
*)packet
->rcd
->rcvhdrq
+ packet
->rhqoff
+
708 packet
->rcd
->dd
->rhf_offset
;
709 packet
->rhf
= rhf_to_cpu(packet
->rhf_addr
);
714 static inline int process_rcv_packet(struct hfi1_packet
*packet
, int thread
)
718 packet
->etype
= rhf_rcv_type(packet
->rhf
);
721 packet
->tlen
= rhf_pkt_len(packet
->rhf
); /* in bytes */
722 /* retrieve eager buffer details */
724 if (rhf_use_egr_bfr(packet
->rhf
)) {
725 packet
->etail
= rhf_egr_index(packet
->rhf
);
726 packet
->ebuf
= get_egrbuf(packet
->rcd
, packet
->rhf
,
729 * Prefetch the contents of the eager buffer. It is
730 * OK to send a negative length to prefetch_range().
731 * The +2 is the size of the RHF.
733 prefetch_range(packet
->ebuf
,
734 packet
->tlen
- ((packet
->rcd
->rcvhdrqentsize
-
735 (rhf_hdrq_offset(packet
->rhf
)
740 * Call a type specific handler for the packet. We
741 * should be able to trust that etype won't be beyond
742 * the range of valid indexes. If so something is really
743 * wrong and we can probably just let things come
744 * crashing down. There is no need to eat another
745 * comparison in this performance critical code.
747 packet
->rcd
->dd
->rhf_rcv_function_map
[packet
->etype
](packet
);
750 /* Set up for the next packet */
751 packet
->rhqoff
+= packet
->rsize
;
752 if (packet
->rhqoff
>= packet
->maxcnt
)
755 ret
= check_max_packet(packet
, thread
);
757 packet
->rhf_addr
= (__le32
*)packet
->rcd
->rcvhdrq
+ packet
->rhqoff
+
758 packet
->rcd
->dd
->rhf_offset
;
759 packet
->rhf
= rhf_to_cpu(packet
->rhf_addr
);
764 static inline void process_rcv_update(int last
, struct hfi1_packet
*packet
)
767 * Update head regs etc., every 16 packets, if not last pkt,
768 * to help prevent rcvhdrq overflows, when many packets
769 * are processed and queue is nearly full.
770 * Don't request an interrupt for intermediate updates.
772 if (!last
&& !(packet
->numpkt
& 0xf)) {
773 update_usrhead(packet
->rcd
, packet
->rhqoff
, packet
->updegr
,
774 packet
->etail
, 0, 0);
780 static inline void finish_packet(struct hfi1_packet
*packet
)
783 * Nothing we need to free for the packet.
785 * The only thing we need to do is a final update and call for an
788 update_usrhead(packet
->rcd
, packet
->rcd
->head
, packet
->updegr
,
789 packet
->etail
, rcv_intr_dynamic
, packet
->numpkt
);
793 * Handle receive interrupts when using the no dma rtail option.
795 int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata
*rcd
, int thread
)
798 int last
= RCV_PKT_OK
;
799 struct hfi1_packet packet
;
801 init_packet(rcd
, &packet
);
802 seq
= rhf_rcv_seq(packet
.rhf
);
803 if (seq
!= rcd
->seq_cnt
) {
808 prescan_rxq(rcd
, &packet
);
810 while (last
== RCV_PKT_OK
) {
811 last
= process_rcv_packet(&packet
, thread
);
812 seq
= rhf_rcv_seq(packet
.rhf
);
813 if (++rcd
->seq_cnt
> 13)
815 if (seq
!= rcd
->seq_cnt
)
817 process_rcv_update(last
, &packet
);
819 process_rcv_qp_work(&packet
);
820 rcd
->head
= packet
.rhqoff
;
822 finish_packet(&packet
);
826 int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata
*rcd
, int thread
)
829 int last
= RCV_PKT_OK
;
830 struct hfi1_packet packet
;
832 init_packet(rcd
, &packet
);
833 hdrqtail
= get_rcvhdrtail(rcd
);
834 if (packet
.rhqoff
== hdrqtail
) {
838 smp_rmb(); /* prevent speculative reads of dma'ed hdrq */
840 prescan_rxq(rcd
, &packet
);
842 while (last
== RCV_PKT_OK
) {
843 last
= process_rcv_packet(&packet
, thread
);
844 if (packet
.rhqoff
== hdrqtail
)
846 process_rcv_update(last
, &packet
);
848 process_rcv_qp_work(&packet
);
849 rcd
->head
= packet
.rhqoff
;
851 finish_packet(&packet
);
855 static inline void set_nodma_rtail(struct hfi1_devdata
*dd
, u16 ctxt
)
857 struct hfi1_ctxtdata
*rcd
;
861 * For dynamically allocated kernel contexts (like vnic) switch
862 * interrupt handler only for that context. Otherwise, switch
863 * interrupt handler for all statically allocated kernel contexts.
865 if (ctxt
>= dd
->first_dyn_alloc_ctxt
) {
866 rcd
= hfi1_rcd_get_by_index_safe(dd
, ctxt
);
869 &handle_receive_interrupt_nodma_rtail
;
875 for (i
= HFI1_CTRL_CTXT
+ 1; i
< dd
->first_dyn_alloc_ctxt
; i
++) {
876 rcd
= hfi1_rcd_get_by_index(dd
, i
);
879 &handle_receive_interrupt_nodma_rtail
;
884 static inline void set_dma_rtail(struct hfi1_devdata
*dd
, u16 ctxt
)
886 struct hfi1_ctxtdata
*rcd
;
890 * For dynamically allocated kernel contexts (like vnic) switch
891 * interrupt handler only for that context. Otherwise, switch
892 * interrupt handler for all statically allocated kernel contexts.
894 if (ctxt
>= dd
->first_dyn_alloc_ctxt
) {
895 rcd
= hfi1_rcd_get_by_index_safe(dd
, ctxt
);
898 &handle_receive_interrupt_dma_rtail
;
904 for (i
= HFI1_CTRL_CTXT
+ 1; i
< dd
->first_dyn_alloc_ctxt
; i
++) {
905 rcd
= hfi1_rcd_get_by_index(dd
, i
);
908 &handle_receive_interrupt_dma_rtail
;
913 void set_all_slowpath(struct hfi1_devdata
*dd
)
915 struct hfi1_ctxtdata
*rcd
;
918 /* HFI1_CTRL_CTXT must always use the slow path interrupt handler */
919 for (i
= HFI1_CTRL_CTXT
+ 1; i
< dd
->num_rcv_contexts
; i
++) {
920 rcd
= hfi1_rcd_get_by_index(dd
, i
);
923 if (i
< dd
->first_dyn_alloc_ctxt
|| rcd
->is_vnic
)
924 rcd
->do_interrupt
= &handle_receive_interrupt
;
930 static inline int set_armed_to_active(struct hfi1_ctxtdata
*rcd
,
931 struct hfi1_packet
*packet
,
932 struct hfi1_devdata
*dd
)
934 struct work_struct
*lsaw
= &rcd
->ppd
->linkstate_active_work
;
935 u8 etype
= rhf_rcv_type(packet
->rhf
);
938 if (etype
== RHF_RCV_TYPE_IB
) {
939 struct ib_header
*hdr
= hfi1_get_msgheader(packet
->rcd
->dd
,
941 sc
= hfi1_9B_get_sc5(hdr
, packet
->rhf
);
942 } else if (etype
== RHF_RCV_TYPE_BYPASS
) {
943 struct hfi1_16b_header
*hdr
= hfi1_get_16B_header(
946 sc
= hfi1_16B_get_sc(hdr
);
948 if (sc
!= SC15_PACKET
) {
949 int hwstate
= driver_lstate(rcd
->ppd
);
951 if (hwstate
!= IB_PORT_ACTIVE
) {
953 "Unexpected link state %s\n",
954 opa_lstate_name(hwstate
));
958 queue_work(rcd
->ppd
->link_wq
, lsaw
);
965 * handle_receive_interrupt - receive a packet
968 * Called from interrupt handler for errors or receive interrupt.
969 * This is the slow path interrupt handler.
971 int handle_receive_interrupt(struct hfi1_ctxtdata
*rcd
, int thread
)
973 struct hfi1_devdata
*dd
= rcd
->dd
;
975 int needset
, last
= RCV_PKT_OK
;
976 struct hfi1_packet packet
;
979 /* Control context will always use the slow path interrupt handler */
980 needset
= (rcd
->ctxt
== HFI1_CTRL_CTXT
) ? 0 : 1;
982 init_packet(rcd
, &packet
);
984 if (!HFI1_CAP_KGET_MASK(rcd
->flags
, DMA_RTAIL
)) {
985 u32 seq
= rhf_rcv_seq(packet
.rhf
);
987 if (seq
!= rcd
->seq_cnt
) {
993 hdrqtail
= get_rcvhdrtail(rcd
);
994 if (packet
.rhqoff
== hdrqtail
) {
998 smp_rmb(); /* prevent speculative reads of dma'ed hdrq */
1001 * Control context can potentially receive an invalid
1002 * rhf. Drop such packets.
1004 if (rcd
->ctxt
== HFI1_CTRL_CTXT
) {
1005 u32 seq
= rhf_rcv_seq(packet
.rhf
);
1007 if (seq
!= rcd
->seq_cnt
)
1012 prescan_rxq(rcd
, &packet
);
1014 while (last
== RCV_PKT_OK
) {
1015 if (unlikely(dd
->do_drop
&&
1016 atomic_xchg(&dd
->drop_packet
, DROP_PACKET_OFF
) ==
1020 /* On to the next packet */
1021 packet
.rhqoff
+= packet
.rsize
;
1022 packet
.rhf_addr
= (__le32
*)rcd
->rcvhdrq
+
1025 packet
.rhf
= rhf_to_cpu(packet
.rhf_addr
);
1027 } else if (skip_pkt
) {
1028 last
= skip_rcv_packet(&packet
, thread
);
1031 /* Auto activate link on non-SC15 packet receive */
1032 if (unlikely(rcd
->ppd
->host_link_state
==
1034 set_armed_to_active(rcd
, &packet
, dd
))
1036 last
= process_rcv_packet(&packet
, thread
);
1039 if (!HFI1_CAP_KGET_MASK(rcd
->flags
, DMA_RTAIL
)) {
1040 u32 seq
= rhf_rcv_seq(packet
.rhf
);
1042 if (++rcd
->seq_cnt
> 13)
1044 if (seq
!= rcd
->seq_cnt
)
1045 last
= RCV_PKT_DONE
;
1047 dd_dev_info(dd
, "Switching to NO_DMA_RTAIL\n");
1048 set_nodma_rtail(dd
, rcd
->ctxt
);
1052 if (packet
.rhqoff
== hdrqtail
)
1053 last
= RCV_PKT_DONE
;
1055 * Control context can potentially receive an invalid
1056 * rhf. Drop such packets.
1058 if (rcd
->ctxt
== HFI1_CTRL_CTXT
) {
1059 u32 seq
= rhf_rcv_seq(packet
.rhf
);
1061 if (++rcd
->seq_cnt
> 13)
1063 if (!last
&& (seq
!= rcd
->seq_cnt
))
1069 "Switching to DMA_RTAIL\n");
1070 set_dma_rtail(dd
, rcd
->ctxt
);
1075 process_rcv_update(last
, &packet
);
1078 process_rcv_qp_work(&packet
);
1079 rcd
->head
= packet
.rhqoff
;
1083 * Always write head at end, and setup rcv interrupt, even
1084 * if no packets were processed.
1086 finish_packet(&packet
);
1091 * We may discover in the interrupt that the hardware link state has
1092 * changed from ARMED to ACTIVE (due to the arrival of a non-SC15 packet),
1093 * and we need to update the driver's notion of the link state. We cannot
1094 * run set_link_state from interrupt context, so we queue this function on
1097 * We delay the regular interrupt processing until after the state changes
1098 * so that the link will be in the correct state by the time any application
1099 * we wake up attempts to send a reply to any message it received.
1100 * (Subsequent receive interrupts may possibly force the wakeup before we
1101 * update the link state.)
1103 * The rcd is freed in hfi1_free_ctxtdata after hfi1_postinit_cleanup invokes
1104 * dd->f_cleanup(dd) to disable the interrupt handler and flush workqueues,
1105 * so we're safe from use-after-free of the rcd.
1107 void receive_interrupt_work(struct work_struct
*work
)
1109 struct hfi1_pportdata
*ppd
= container_of(work
, struct hfi1_pportdata
,
1110 linkstate_active_work
);
1111 struct hfi1_devdata
*dd
= ppd
->dd
;
1112 struct hfi1_ctxtdata
*rcd
;
1115 /* Received non-SC15 packet implies neighbor_normal */
1116 ppd
->neighbor_normal
= 1;
1117 set_link_state(ppd
, HLS_UP_ACTIVE
);
1120 * Interrupt all statically allocated kernel contexts that could
1121 * have had an interrupt during auto activation.
1123 for (i
= HFI1_CTRL_CTXT
; i
< dd
->first_dyn_alloc_ctxt
; i
++) {
1124 rcd
= hfi1_rcd_get_by_index(dd
, i
);
1126 force_recv_intr(rcd
);
1132 * Convert a given MTU size to the on-wire MAD packet enumeration.
1133 * Return -1 if the size is invalid.
1135 int mtu_to_enum(u32 mtu
, int default_if_bad
)
1138 case 0: return OPA_MTU_0
;
1139 case 256: return OPA_MTU_256
;
1140 case 512: return OPA_MTU_512
;
1141 case 1024: return OPA_MTU_1024
;
1142 case 2048: return OPA_MTU_2048
;
1143 case 4096: return OPA_MTU_4096
;
1144 case 8192: return OPA_MTU_8192
;
1145 case 10240: return OPA_MTU_10240
;
1147 return default_if_bad
;
1150 u16
enum_to_mtu(int mtu
)
1153 case OPA_MTU_0
: return 0;
1154 case OPA_MTU_256
: return 256;
1155 case OPA_MTU_512
: return 512;
1156 case OPA_MTU_1024
: return 1024;
1157 case OPA_MTU_2048
: return 2048;
1158 case OPA_MTU_4096
: return 4096;
1159 case OPA_MTU_8192
: return 8192;
1160 case OPA_MTU_10240
: return 10240;
1161 default: return 0xffff;
1166 * set_mtu - set the MTU
1167 * @ppd: the per port data
1169 * We can handle "any" incoming size, the issue here is whether we
1170 * need to restrict our outgoing size. We do not deal with what happens
1171 * to programs that are already running when the size changes.
1173 int set_mtu(struct hfi1_pportdata
*ppd
)
1175 struct hfi1_devdata
*dd
= ppd
->dd
;
1176 int i
, drain
, ret
= 0, is_up
= 0;
1179 for (i
= 0; i
< ppd
->vls_supported
; i
++)
1180 if (ppd
->ibmtu
< dd
->vld
[i
].mtu
)
1181 ppd
->ibmtu
= dd
->vld
[i
].mtu
;
1182 ppd
->ibmaxlen
= ppd
->ibmtu
+ lrh_max_header_bytes(ppd
->dd
);
1184 mutex_lock(&ppd
->hls_lock
);
1185 if (ppd
->host_link_state
== HLS_UP_INIT
||
1186 ppd
->host_link_state
== HLS_UP_ARMED
||
1187 ppd
->host_link_state
== HLS_UP_ACTIVE
)
1190 drain
= !is_ax(dd
) && is_up
;
1194 * MTU is specified per-VL. To ensure that no packet gets
1195 * stuck (due, e.g., to the MTU for the packet's VL being
1196 * reduced), empty the per-VL FIFOs before adjusting MTU.
1198 ret
= stop_drain_data_vls(dd
);
1201 dd_dev_err(dd
, "%s: cannot stop/drain VLs - refusing to change per-VL MTUs\n",
1206 hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_MTU
, 0);
1209 open_fill_data_vls(dd
); /* reopen all VLs */
1212 mutex_unlock(&ppd
->hls_lock
);
1217 int hfi1_set_lid(struct hfi1_pportdata
*ppd
, u32 lid
, u8 lmc
)
1219 struct hfi1_devdata
*dd
= ppd
->dd
;
1223 hfi1_set_ib_cfg(ppd
, HFI1_IB_CFG_LIDLMC
, 0);
1225 dd_dev_info(dd
, "port %u: got a lid: 0x%x\n", ppd
->port
, lid
);
1230 void shutdown_led_override(struct hfi1_pportdata
*ppd
)
1232 struct hfi1_devdata
*dd
= ppd
->dd
;
1235 * This pairs with the memory barrier in hfi1_start_led_override to
1236 * ensure that we read the correct state of LED beaconing represented
1237 * by led_override_timer_active
1240 if (atomic_read(&ppd
->led_override_timer_active
)) {
1241 del_timer_sync(&ppd
->led_override_timer
);
1242 atomic_set(&ppd
->led_override_timer_active
, 0);
1243 /* Ensure the atomic_set is visible to all CPUs */
1247 /* Hand control of the LED to the DC for normal operation */
1248 write_csr(dd
, DCC_CFG_LED_CNTRL
, 0);
1251 static void run_led_override(struct timer_list
*t
)
1253 struct hfi1_pportdata
*ppd
= from_timer(ppd
, t
, led_override_timer
);
1254 struct hfi1_devdata
*dd
= ppd
->dd
;
1255 unsigned long timeout
;
1258 if (!(dd
->flags
& HFI1_INITTED
))
1261 phase_idx
= ppd
->led_override_phase
& 1;
1263 setextled(dd
, phase_idx
);
1265 timeout
= ppd
->led_override_vals
[phase_idx
];
1267 /* Set up for next phase */
1268 ppd
->led_override_phase
= !ppd
->led_override_phase
;
1270 mod_timer(&ppd
->led_override_timer
, jiffies
+ timeout
);
1274 * To have the LED blink in a particular pattern, provide timeon and timeoff
1276 * To turn off custom blinking and return to normal operation, use
1277 * shutdown_led_override()
1279 void hfi1_start_led_override(struct hfi1_pportdata
*ppd
, unsigned int timeon
,
1280 unsigned int timeoff
)
1282 if (!(ppd
->dd
->flags
& HFI1_INITTED
))
1285 /* Convert to jiffies for direct use in timer */
1286 ppd
->led_override_vals
[0] = msecs_to_jiffies(timeoff
);
1287 ppd
->led_override_vals
[1] = msecs_to_jiffies(timeon
);
1289 /* Arbitrarily start from LED on phase */
1290 ppd
->led_override_phase
= 1;
1293 * If the timer has not already been started, do so. Use a "quick"
1294 * timeout so the handler will be called soon to look at our request.
1296 if (!timer_pending(&ppd
->led_override_timer
)) {
1297 timer_setup(&ppd
->led_override_timer
, run_led_override
, 0);
1298 ppd
->led_override_timer
.expires
= jiffies
+ 1;
1299 add_timer(&ppd
->led_override_timer
);
1300 atomic_set(&ppd
->led_override_timer_active
, 1);
1301 /* Ensure the atomic_set is visible to all CPUs */
1307 * hfi1_reset_device - reset the chip if possible
1308 * @unit: the device to reset
1310 * Whether or not reset is successful, we attempt to re-initialize the chip
1311 * (that is, much like a driver unload/reload). We clear the INITTED flag
1312 * so that the various entry points will fail until we reinitialize. For
1313 * now, we only allow this if no user contexts are open that use chip resources
1315 int hfi1_reset_device(int unit
)
1318 struct hfi1_devdata
*dd
= hfi1_lookup(unit
);
1319 struct hfi1_pportdata
*ppd
;
1327 dd_dev_info(dd
, "Reset on unit %u requested\n", unit
);
1329 if (!dd
->kregbase1
|| !(dd
->flags
& HFI1_PRESENT
)) {
1331 "Invalid unit number %u or not initialized or not present\n",
1337 /* If there are any user/vnic contexts, we cannot reset */
1338 mutex_lock(&hfi1_mutex
);
1340 if (hfi1_stats
.sps_ctxts
) {
1341 mutex_unlock(&hfi1_mutex
);
1345 mutex_unlock(&hfi1_mutex
);
1347 for (pidx
= 0; pidx
< dd
->num_pports
; ++pidx
) {
1348 ppd
= dd
->pport
+ pidx
;
1350 shutdown_led_override(ppd
);
1352 if (dd
->flags
& HFI1_HAS_SEND_DMA
)
1355 hfi1_reset_cpu_counters(dd
);
1357 ret
= hfi1_init(dd
, 1);
1361 "Reinitialize unit %u after reset failed with %d\n",
1364 dd_dev_info(dd
, "Reinitialized unit %u after resetting\n",
1371 static inline void hfi1_setup_ib_header(struct hfi1_packet
*packet
)
1373 packet
->hdr
= (struct hfi1_ib_message_header
*)
1374 hfi1_get_msgheader(packet
->rcd
->dd
,
1376 packet
->hlen
= (u8
*)packet
->rhf_addr
- (u8
*)packet
->hdr
;
1379 static int hfi1_bypass_ingress_pkt_check(struct hfi1_packet
*packet
)
1381 struct hfi1_pportdata
*ppd
= packet
->rcd
->ppd
;
1383 /* slid and dlid cannot be 0 */
1384 if ((!packet
->slid
) || (!packet
->dlid
))
1387 /* Compare port lid with incoming packet dlid */
1388 if ((!(hfi1_is_16B_mcast(packet
->dlid
))) &&
1390 opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE
), 16B
))) {
1391 if (packet
->dlid
!= ppd
->lid
)
1395 /* No multicast packets with SC15 */
1396 if ((hfi1_is_16B_mcast(packet
->dlid
)) && (packet
->sc
== 0xF))
1399 /* Packets with permissive DLID always on SC15 */
1400 if ((packet
->dlid
== opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE
),
1402 (packet
->sc
!= 0xF))
1408 static int hfi1_setup_9B_packet(struct hfi1_packet
*packet
)
1410 struct hfi1_ibport
*ibp
= rcd_to_iport(packet
->rcd
);
1411 struct ib_header
*hdr
;
1414 hfi1_setup_ib_header(packet
);
1417 lnh
= ib_get_lnh(hdr
);
1418 if (lnh
== HFI1_LRH_BTH
) {
1419 packet
->ohdr
= &hdr
->u
.oth
;
1421 } else if (lnh
== HFI1_LRH_GRH
) {
1424 packet
->ohdr
= &hdr
->u
.l
.oth
;
1425 packet
->grh
= &hdr
->u
.l
.grh
;
1426 if (packet
->grh
->next_hdr
!= IB_GRH_NEXT_HDR
)
1428 vtf
= be32_to_cpu(packet
->grh
->version_tclass_flow
);
1429 if ((vtf
>> IB_GRH_VERSION_SHIFT
) != IB_GRH_VERSION
)
1435 /* Query commonly used fields from packet header */
1436 packet
->payload
= packet
->ebuf
;
1437 packet
->opcode
= ib_bth_get_opcode(packet
->ohdr
);
1438 packet
->slid
= ib_get_slid(hdr
);
1439 packet
->dlid
= ib_get_dlid(hdr
);
1440 if (unlikely((packet
->dlid
>= be16_to_cpu(IB_MULTICAST_LID_BASE
)) &&
1441 (packet
->dlid
!= be16_to_cpu(IB_LID_PERMISSIVE
))))
1442 packet
->dlid
+= opa_get_mcast_base(OPA_MCAST_NR
) -
1443 be16_to_cpu(IB_MULTICAST_LID_BASE
);
1444 packet
->sl
= ib_get_sl(hdr
);
1445 packet
->sc
= hfi1_9B_get_sc5(hdr
, packet
->rhf
);
1446 packet
->pad
= ib_bth_get_pad(packet
->ohdr
);
1447 packet
->extra_byte
= 0;
1448 packet
->pkey
= ib_bth_get_pkey(packet
->ohdr
);
1449 packet
->migrated
= ib_bth_is_migration(packet
->ohdr
);
1453 ibp
->rvp
.n_pkt_drops
++;
1457 static int hfi1_setup_bypass_packet(struct hfi1_packet
*packet
)
1460 * Bypass packets have a different header/payload split
1461 * compared to an IB packet.
1462 * Current split is set such that 16 bytes of the actual
1463 * header is in the header buffer and the remining is in
1464 * the eager buffer. We chose 16 since hfi1 driver only
1465 * supports 16B bypass packets and we will be able to
1466 * receive the entire LRH with such a split.
1469 struct hfi1_ctxtdata
*rcd
= packet
->rcd
;
1470 struct hfi1_pportdata
*ppd
= rcd
->ppd
;
1471 struct hfi1_ibport
*ibp
= &ppd
->ibport_data
;
1475 packet
->hdr
= (struct hfi1_16b_header
*)
1476 hfi1_get_16B_header(packet
->rcd
->dd
,
1478 packet
->hlen
= (u8
*)packet
->rhf_addr
- (u8
*)packet
->hdr
;
1480 l4
= hfi1_16B_get_l4(packet
->hdr
);
1481 if (l4
== OPA_16B_L4_IB_LOCAL
) {
1483 packet
->ohdr
= packet
->ebuf
;
1485 } else if (l4
== OPA_16B_L4_IB_GLOBAL
) {
1488 grh_len
= sizeof(struct ib_grh
);
1489 packet
->ohdr
= packet
->ebuf
+ grh_len
;
1490 packet
->grh
= packet
->ebuf
;
1491 if (packet
->grh
->next_hdr
!= IB_GRH_NEXT_HDR
)
1493 vtf
= be32_to_cpu(packet
->grh
->version_tclass_flow
);
1494 if ((vtf
>> IB_GRH_VERSION_SHIFT
) != IB_GRH_VERSION
)
1500 /* Query commonly used fields from packet header */
1501 packet
->opcode
= ib_bth_get_opcode(packet
->ohdr
);
1502 /* hdr_len_by_opcode already has an IB LRH factored in */
1503 packet
->hlen
= hdr_len_by_opcode
[packet
->opcode
] +
1504 (LRH_16B_BYTES
- LRH_9B_BYTES
) + grh_len
;
1505 packet
->payload
= packet
->ebuf
+ packet
->hlen
- LRH_16B_BYTES
;
1506 packet
->slid
= hfi1_16B_get_slid(packet
->hdr
);
1507 packet
->dlid
= hfi1_16B_get_dlid(packet
->hdr
);
1508 if (unlikely(hfi1_is_16B_mcast(packet
->dlid
)))
1509 packet
->dlid
+= opa_get_mcast_base(OPA_MCAST_NR
) -
1510 opa_get_lid(opa_get_mcast_base(OPA_MCAST_NR
),
1512 packet
->sc
= hfi1_16B_get_sc(packet
->hdr
);
1513 packet
->sl
= ibp
->sc_to_sl
[packet
->sc
];
1514 packet
->pad
= hfi1_16B_bth_get_pad(packet
->ohdr
);
1515 packet
->extra_byte
= SIZE_OF_LT
;
1516 packet
->pkey
= hfi1_16B_get_pkey(packet
->hdr
);
1517 packet
->migrated
= opa_bth_is_migration(packet
->ohdr
);
1519 if (hfi1_bypass_ingress_pkt_check(packet
))
1524 hfi1_cdbg(PKT
, "%s: packet dropped\n", __func__
);
1525 ibp
->rvp
.n_pkt_drops
++;
1529 void handle_eflags(struct hfi1_packet
*packet
)
1531 struct hfi1_ctxtdata
*rcd
= packet
->rcd
;
1532 u32 rte
= rhf_rcv_type_err(packet
->rhf
);
1534 rcv_hdrerr(rcd
, rcd
->ppd
, packet
);
1535 if (rhf_err_flags(packet
->rhf
))
1537 "receive context %d: rhf 0x%016llx, errs [ %s%s%s%s%s%s%s%s] rte 0x%x\n",
1538 rcd
->ctxt
, packet
->rhf
,
1539 packet
->rhf
& RHF_K_HDR_LEN_ERR
? "k_hdr_len " : "",
1540 packet
->rhf
& RHF_DC_UNC_ERR
? "dc_unc " : "",
1541 packet
->rhf
& RHF_DC_ERR
? "dc " : "",
1542 packet
->rhf
& RHF_TID_ERR
? "tid " : "",
1543 packet
->rhf
& RHF_LEN_ERR
? "len " : "",
1544 packet
->rhf
& RHF_ECC_ERR
? "ecc " : "",
1545 packet
->rhf
& RHF_VCRC_ERR
? "vcrc " : "",
1546 packet
->rhf
& RHF_ICRC_ERR
? "icrc " : "",
1551 * The following functions are called by the interrupt handler. They are type
1552 * specific handlers for each packet type.
1554 int process_receive_ib(struct hfi1_packet
*packet
)
1556 if (unlikely(hfi1_dbg_fault_packet(packet
)))
1557 return RHF_RCV_CONTINUE
;
1559 if (hfi1_setup_9B_packet(packet
))
1560 return RHF_RCV_CONTINUE
;
1562 trace_hfi1_rcvhdr(packet
);
1564 if (unlikely(rhf_err_flags(packet
->rhf
))) {
1565 handle_eflags(packet
);
1566 return RHF_RCV_CONTINUE
;
1569 hfi1_ib_rcv(packet
);
1570 return RHF_RCV_CONTINUE
;
1573 static inline bool hfi1_is_vnic_packet(struct hfi1_packet
*packet
)
1575 /* Packet received in VNIC context via RSM */
1576 if (packet
->rcd
->is_vnic
)
1579 if ((hfi1_16B_get_l2(packet
->ebuf
) == OPA_16B_L2_TYPE
) &&
1580 (hfi1_16B_get_l4(packet
->ebuf
) == OPA_16B_L4_ETHR
))
1586 int process_receive_bypass(struct hfi1_packet
*packet
)
1588 struct hfi1_devdata
*dd
= packet
->rcd
->dd
;
1590 if (hfi1_is_vnic_packet(packet
)) {
1591 hfi1_vnic_bypass_rcv(packet
);
1592 return RHF_RCV_CONTINUE
;
1595 if (hfi1_setup_bypass_packet(packet
))
1596 return RHF_RCV_CONTINUE
;
1598 trace_hfi1_rcvhdr(packet
);
1600 if (unlikely(rhf_err_flags(packet
->rhf
))) {
1601 handle_eflags(packet
);
1602 return RHF_RCV_CONTINUE
;
1605 if (hfi1_16B_get_l2(packet
->hdr
) == 0x2) {
1606 hfi1_16B_rcv(packet
);
1609 "Bypass packets other than 16B are not supported in normal operation. Dropping\n");
1610 incr_cntr64(&dd
->sw_rcv_bypass_packet_errors
);
1611 if (!(dd
->err_info_rcvport
.status_and_code
&
1612 OPA_EI_STATUS_SMASK
)) {
1613 u64
*flits
= packet
->ebuf
;
1615 if (flits
&& !(packet
->rhf
& RHF_LEN_ERR
)) {
1616 dd
->err_info_rcvport
.packet_flit1
= flits
[0];
1617 dd
->err_info_rcvport
.packet_flit2
=
1618 packet
->tlen
> sizeof(flits
[0]) ?
1621 dd
->err_info_rcvport
.status_and_code
|=
1622 (OPA_EI_STATUS_SMASK
| BAD_L2_ERR
);
1625 return RHF_RCV_CONTINUE
;
1628 int process_receive_error(struct hfi1_packet
*packet
)
1630 /* KHdrHCRCErr -- KDETH packet with a bad HCRC */
1632 hfi1_dbg_fault_suppress_err(&packet
->rcd
->dd
->verbs_dev
) &&
1633 rhf_rcv_type_err(packet
->rhf
) == 3))
1634 return RHF_RCV_CONTINUE
;
1636 hfi1_setup_ib_header(packet
);
1637 handle_eflags(packet
);
1639 if (unlikely(rhf_err_flags(packet
->rhf
)))
1640 dd_dev_err(packet
->rcd
->dd
,
1641 "Unhandled error packet received. Dropping.\n");
1643 return RHF_RCV_CONTINUE
;
1646 int kdeth_process_expected(struct hfi1_packet
*packet
)
1648 if (unlikely(hfi1_dbg_fault_packet(packet
)))
1649 return RHF_RCV_CONTINUE
;
1651 hfi1_setup_ib_header(packet
);
1652 if (unlikely(rhf_err_flags(packet
->rhf
)))
1653 handle_eflags(packet
);
1655 dd_dev_err(packet
->rcd
->dd
,
1656 "Unhandled expected packet received. Dropping.\n");
1657 return RHF_RCV_CONTINUE
;
1660 int kdeth_process_eager(struct hfi1_packet
*packet
)
1662 hfi1_setup_ib_header(packet
);
1663 if (unlikely(rhf_err_flags(packet
->rhf
)))
1664 handle_eflags(packet
);
1665 if (unlikely(hfi1_dbg_fault_packet(packet
)))
1666 return RHF_RCV_CONTINUE
;
1668 dd_dev_err(packet
->rcd
->dd
,
1669 "Unhandled eager packet received. Dropping.\n");
1670 return RHF_RCV_CONTINUE
;
1673 int process_receive_invalid(struct hfi1_packet
*packet
)
1675 dd_dev_err(packet
->rcd
->dd
, "Invalid packet type %d. Dropping\n",
1676 rhf_rcv_type(packet
->rhf
));
1677 return RHF_RCV_CONTINUE
;
1680 void seqfile_dump_rcd(struct seq_file
*s
, struct hfi1_ctxtdata
*rcd
)
1682 struct hfi1_packet packet
;
1683 struct ps_mdata mdata
;
1685 seq_printf(s
, "Rcd %u: RcvHdr cnt %u entsize %u %s head %llu tail %llu\n",
1686 rcd
->ctxt
, rcd
->rcvhdrq_cnt
, rcd
->rcvhdrqentsize
,
1687 HFI1_CAP_KGET_MASK(rcd
->flags
, DMA_RTAIL
) ?
1688 "dma_rtail" : "nodma_rtail",
1689 read_uctxt_csr(rcd
->dd
, rcd
->ctxt
, RCV_HDR_HEAD
) &
1690 RCV_HDR_HEAD_HEAD_MASK
,
1691 read_uctxt_csr(rcd
->dd
, rcd
->ctxt
, RCV_HDR_TAIL
));
1693 init_packet(rcd
, &packet
);
1694 init_ps_mdata(&mdata
, &packet
);
1697 struct hfi1_devdata
*dd
= rcd
->dd
;
1698 __le32
*rhf_addr
= (__le32
*)rcd
->rcvhdrq
+ mdata
.ps_head
+
1700 struct ib_header
*hdr
;
1701 u64 rhf
= rhf_to_cpu(rhf_addr
);
1702 u32 etype
= rhf_rcv_type(rhf
), qpn
;
1707 if (ps_done(&mdata
, rhf
, rcd
))
1710 if (ps_skip(&mdata
, rhf
, rcd
))
1713 if (etype
> RHF_RCV_TYPE_IB
)
1716 packet
.hdr
= hfi1_get_msgheader(dd
, rhf_addr
);
1719 lnh
= be16_to_cpu(hdr
->lrh
[0]) & 3;
1721 if (lnh
== HFI1_LRH_BTH
)
1722 packet
.ohdr
= &hdr
->u
.oth
;
1723 else if (lnh
== HFI1_LRH_GRH
)
1724 packet
.ohdr
= &hdr
->u
.l
.oth
;
1726 goto next
; /* just in case */
1728 opcode
= (be32_to_cpu(packet
.ohdr
->bth
[0]) >> 24);
1729 qpn
= be32_to_cpu(packet
.ohdr
->bth
[1]) & RVT_QPN_MASK
;
1730 psn
= mask_psn(be32_to_cpu(packet
.ohdr
->bth
[2]));
1732 seq_printf(s
, "\tEnt %u: opcode 0x%x, qpn 0x%x, psn 0x%x\n",
1733 mdata
.ps_head
, opcode
, qpn
, psn
);
1735 update_ps_mdata(&mdata
, rcd
);