Cai Huoqing | 145eba1 | 2021-08-23 12:26:22 +0800 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */ |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2 | /* |
Mitko Haralanov | a74d530 | 2018-05-02 06:43:24 -0700 | [diff] [blame] | 3 | * Copyright(c) 2015 - 2018 Intel Corporation. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef HFI1_VERBS_H |
| 7 | #define HFI1_VERBS_H |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/seqlock.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/kref.h> |
| 14 | #include <linux/workqueue.h> |
| 15 | #include <linux/kthread.h> |
| 16 | #include <linux/completion.h> |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 17 | #include <linux/slab.h> |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 18 | #include <rdma/ib_pack.h> |
| 19 | #include <rdma/ib_user_verbs.h> |
| 20 | #include <rdma/ib_mad.h> |
Mike Marciniszyn | 261a435 | 2016-09-06 04:35:05 -0700 | [diff] [blame] | 21 | #include <rdma/ib_hdrs.h> |
Dennis Dalessandro | ec3f2c1 | 2016-01-19 14:41:33 -0800 | [diff] [blame] | 22 | #include <rdma/rdma_vt.h> |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 23 | #include <rdma/rdmavt_qp.h> |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 24 | #include <rdma/rdmavt_cq.h> |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 25 | |
| 26 | struct hfi1_ctxtdata; |
| 27 | struct hfi1_pportdata; |
| 28 | struct hfi1_devdata; |
| 29 | struct hfi1_packet; |
| 30 | |
| 31 | #include "iowait.h" |
Mike Marciniszyn | 5190f05 | 2018-11-28 10:22:31 -0800 | [diff] [blame] | 32 | #include "tid_rdma.h" |
Mitko Haralanov | 44e43d9 | 2019-01-24 06:09:46 -0800 | [diff] [blame] | 33 | #include "opfn.h" |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 34 | |
| 35 | #define HFI1_MAX_RDMA_ATOMIC 16 |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * Increment this value if any changes that break userspace ABI |
| 39 | * compatibility are made. |
| 40 | */ |
| 41 | #define HFI1_UVERBS_ABI_VERSION 2 |
| 42 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 43 | /* IB Performance Manager status values */ |
| 44 | #define IB_PMA_SAMPLE_STATUS_DONE 0x00 |
| 45 | #define IB_PMA_SAMPLE_STATUS_STARTED 0x01 |
| 46 | #define IB_PMA_SAMPLE_STATUS_RUNNING 0x02 |
| 47 | |
| 48 | /* Mandatory IB performance counter select values. */ |
| 49 | #define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001) |
| 50 | #define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002) |
| 51 | #define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003) |
| 52 | #define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004) |
| 53 | #define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005) |
| 54 | |
| 55 | #define HFI1_VENDOR_IPG cpu_to_be16(0xFFA0) |
| 56 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 57 | #define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL) |
Don Hiatt | 5786adf3 | 2017-08-04 13:54:10 -0700 | [diff] [blame] | 58 | #define OPA_BTH_MIG_REQ BIT(31) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 59 | |
Mike Marciniszyn | b374e06 | 2016-09-25 07:40:58 -0700 | [diff] [blame] | 60 | #define RC_OP(x) IB_OPCODE_RC_##x |
| 61 | #define UC_OP(x) IB_OPCODE_UC_##x |
| 62 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 63 | /* flags passed by hfi1_ib_rcv() */ |
| 64 | enum { |
| 65 | HFI1_HAS_GRH = (1 << 0), |
| 66 | }; |
| 67 | |
Pankaj Bharadiya | c593642 | 2019-12-09 10:31:43 -0800 | [diff] [blame] | 68 | #define LRH_16B_BYTES (sizeof_field(struct hfi1_16b_header, lrh)) |
Mike Marciniszyn | 78d3633 | 2018-02-01 10:52:35 -0800 | [diff] [blame] | 69 | #define LRH_16B_DWORDS (LRH_16B_BYTES / sizeof(u32)) |
Pankaj Bharadiya | c593642 | 2019-12-09 10:31:43 -0800 | [diff] [blame] | 70 | #define LRH_9B_BYTES (sizeof_field(struct ib_header, lrh)) |
Mike Marciniszyn | 78d3633 | 2018-02-01 10:52:35 -0800 | [diff] [blame] | 71 | #define LRH_9B_DWORDS (LRH_9B_BYTES / sizeof(u32)) |
| 72 | |
Don Hiatt | 4171a69 | 2018-05-15 18:28:07 -0700 | [diff] [blame] | 73 | /* 24Bits for qpn, upper 8Bits reserved */ |
| 74 | struct opa_16b_mgmt { |
| 75 | __be32 dest_qpn; |
| 76 | __be32 src_qpn; |
| 77 | }; |
| 78 | |
Don Hiatt | 72c07e2 | 2017-08-04 13:53:58 -0700 | [diff] [blame] | 79 | struct hfi1_16b_header { |
| 80 | u32 lrh[4]; |
| 81 | union { |
| 82 | struct { |
| 83 | struct ib_grh grh; |
| 84 | struct ib_other_headers oth; |
| 85 | } l; |
| 86 | struct ib_other_headers oth; |
Don Hiatt | 4171a69 | 2018-05-15 18:28:07 -0700 | [diff] [blame] | 87 | struct opa_16b_mgmt mgmt; |
Don Hiatt | 72c07e2 | 2017-08-04 13:53:58 -0700 | [diff] [blame] | 88 | } u; |
| 89 | } __packed; |
| 90 | |
Don Hiatt | 30e0741 | 2017-08-04 13:54:04 -0700 | [diff] [blame] | 91 | struct hfi1_opa_header { |
| 92 | union { |
| 93 | struct ib_header ibh; /* 9B header */ |
| 94 | struct hfi1_16b_header opah; /* 16B header */ |
| 95 | }; |
| 96 | u8 hdr_type; /* 9B or 16B */ |
| 97 | } __packed; |
| 98 | |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 99 | struct hfi1_ahg_info { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 100 | u32 ahgdesc[2]; |
| 101 | u16 tx_flags; |
| 102 | u8 ahgcount; |
| 103 | u8 ahgidx; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 104 | }; |
| 105 | |
Don Hiatt | d4d602e | 2016-07-25 13:40:22 -0700 | [diff] [blame] | 106 | struct hfi1_sdma_header { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 107 | __le64 pbc; |
Don Hiatt | 30e0741 | 2017-08-04 13:54:04 -0700 | [diff] [blame] | 108 | struct hfi1_opa_header hdr; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 109 | } __packed; |
| 110 | |
| 111 | /* |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 112 | * hfi1 specific data structures that will be hidden from rvt after the queue |
| 113 | * pair is made common |
| 114 | */ |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 115 | struct hfi1_qp_priv { |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 116 | struct hfi1_ahg_info *s_ahg; /* ahg info for next header */ |
Jubin John | 721d042 | 2016-02-14 12:45:00 -0800 | [diff] [blame] | 117 | struct sdma_engine *s_sde; /* current sde */ |
| 118 | struct send_context *s_sendcontext; /* current sendcontext */ |
Mike Marciniszyn | 5190f05 | 2018-11-28 10:22:31 -0800 | [diff] [blame] | 119 | struct hfi1_ctxtdata *rcd; /* QP's receive context */ |
Kaike Wan | 838b6fd | 2019-01-23 19:30:07 -0800 | [diff] [blame] | 120 | struct page **pages; /* for TID page scan */ |
Kaike Wan | 37356e7 | 2019-02-05 14:13:13 -0800 | [diff] [blame] | 121 | u32 tid_enqueue; /* saved when tid waited */ |
Jubin John | 721d042 | 2016-02-14 12:45:00 -0800 | [diff] [blame] | 122 | u8 s_sc; /* SC[0..4] for next packet */ |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 123 | struct iowait s_iowait; |
Kaike Wan | 3c759e0 | 2019-01-23 21:49:19 -0800 | [diff] [blame] | 124 | struct timer_list s_tid_timer; /* for timing tid wait */ |
Kaike Wan | 829eaee | 2019-01-23 21:50:24 -0800 | [diff] [blame] | 125 | struct timer_list s_tid_retry_timer; /* for timing tid ack */ |
Kaike Wan | 37356e7 | 2019-02-05 14:13:13 -0800 | [diff] [blame] | 126 | struct list_head tid_wait; /* for queueing tid space */ |
Kaike Wan | d22a207 | 2019-01-23 19:20:42 -0800 | [diff] [blame] | 127 | struct hfi1_opfn_data opfn; |
Kaike Wan | 37356e7 | 2019-02-05 14:13:13 -0800 | [diff] [blame] | 128 | struct tid_flow_state flow_state; |
Kaike Wan | d22a207 | 2019-01-23 19:20:42 -0800 | [diff] [blame] | 129 | struct tid_rdma_qp_params tid_rdma; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 130 | struct rvt_qp *owner; |
Mike Marciniszyn | 270a983 | 2019-02-26 08:46:16 -0800 | [diff] [blame] | 131 | u16 s_running_pkt_size; |
Don Hiatt | d98bb7f | 2017-08-04 13:54:16 -0700 | [diff] [blame] | 132 | u8 hdr_type; /* 9B or 16B */ |
Kaike Wan | 6e38fca | 2019-01-23 21:50:56 -0800 | [diff] [blame] | 133 | struct rvt_sge_state tid_ss; /* SGE state pointer for 2nd leg */ |
Kaike Wan | 70dcb2e | 2019-01-23 21:51:07 -0800 | [diff] [blame] | 134 | atomic_t n_requests; /* # of TID RDMA requests in the */ |
| 135 | /* queue */ |
Kaike Wan | 9e93e96 | 2019-01-23 21:50:14 -0800 | [diff] [blame] | 136 | atomic_t n_tid_requests; /* # of sent TID RDMA requests */ |
Kaike Wan | d22a207 | 2019-01-23 19:20:42 -0800 | [diff] [blame] | 137 | unsigned long tid_timer_timeout_jiffies; |
Kaike Wan | 829eaee | 2019-01-23 21:50:24 -0800 | [diff] [blame] | 138 | unsigned long tid_retry_timeout_jiffies; |
Kaike Wan | 742a382 | 2019-01-23 19:30:40 -0800 | [diff] [blame] | 139 | |
Kaike Wan | a0b34f7 | 2019-01-24 06:36:48 -0800 | [diff] [blame] | 140 | /* variables for the TID RDMA SE state machine */ |
Kaike Wan | 9e93e96 | 2019-01-23 21:50:14 -0800 | [diff] [blame] | 141 | u8 s_state; |
| 142 | u8 s_retry; |
Kaike Wan | 07b92370 | 2019-01-23 21:48:59 -0800 | [diff] [blame] | 143 | u8 rnr_nak_state; /* RNR NAK state */ |
Kaike Wan | d72fe7d | 2019-01-23 21:49:51 -0800 | [diff] [blame] | 144 | u8 s_nak_state; |
| 145 | u32 s_nak_psn; |
Kaike Wan | a0b34f7 | 2019-01-24 06:36:48 -0800 | [diff] [blame] | 146 | u32 s_flags; |
Kaike Wan | 72a0ea9 | 2019-01-23 21:49:31 -0800 | [diff] [blame] | 147 | u32 s_tid_cur; |
| 148 | u32 s_tid_head; |
| 149 | u32 s_tid_tail; |
Kaike Wan | 07b92370 | 2019-01-23 21:48:59 -0800 | [diff] [blame] | 150 | u32 r_tid_head; /* Most recently added TID RDMA request */ |
| 151 | u32 r_tid_tail; /* the last completed TID RDMA request */ |
| 152 | u32 r_tid_ack; /* the TID RDMA request to be ACK'ed */ |
| 153 | u32 r_tid_alloc; /* Request for which we are allocating resources */ |
| 154 | u32 pending_tid_w_segs; /* Num of pending tid write segments */ |
Kaike Wan | 3c6cb20 | 2019-01-23 21:51:39 -0800 | [diff] [blame] | 155 | u32 pending_tid_w_resp; /* Num of pending tid write responses */ |
Kaike Wan | 07b92370 | 2019-01-23 21:48:59 -0800 | [diff] [blame] | 156 | u32 alloc_w_segs; /* Number of segments for which write */ |
| 157 | /* resources have been allocated for this QP */ |
Kaike Wan | a0b34f7 | 2019-01-24 06:36:48 -0800 | [diff] [blame] | 158 | |
Kaike Wan | 742a382 | 2019-01-23 19:30:40 -0800 | [diff] [blame] | 159 | /* For TID RDMA READ */ |
Kaike Wan | 9905bf0 | 2019-02-05 14:13:30 -0800 | [diff] [blame] | 160 | u32 tid_r_reqs; /* Num of tid reads requested */ |
| 161 | u32 tid_r_comp; /* Num of tid reads completed */ |
Kaike Wan | 742a382 | 2019-01-23 19:30:40 -0800 | [diff] [blame] | 162 | u32 pending_tid_r_segs; /* Num of pending tid read segments */ |
Kaike Wan | d22a207 | 2019-01-23 19:20:42 -0800 | [diff] [blame] | 163 | u16 pkts_ps; /* packets per segment */ |
| 164 | u8 timeout_shift; /* account for number of packets per segment */ |
Kaike Wan | 07b92370 | 2019-01-23 21:48:59 -0800 | [diff] [blame] | 165 | |
Kaike Wan | d72fe7d | 2019-01-23 21:49:51 -0800 | [diff] [blame] | 166 | u32 r_next_psn_kdeth; |
Kaike Wan | 0f75e32 | 2019-01-23 21:50:03 -0800 | [diff] [blame] | 167 | u32 r_next_psn_kdeth_save; |
Kaike Wan | 9e93e96 | 2019-01-23 21:50:14 -0800 | [diff] [blame] | 168 | u32 s_resync_psn; |
Kaike Wan | 07b92370 | 2019-01-23 21:48:59 -0800 | [diff] [blame] | 169 | u8 sync_pt; /* Set when QP reaches sync point */ |
Kaike Wan | 0f75e32 | 2019-01-23 21:50:03 -0800 | [diff] [blame] | 170 | u8 resync; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 171 | }; |
| 172 | |
Kaike Wan | 07b92370 | 2019-01-23 21:48:59 -0800 | [diff] [blame] | 173 | #define HFI1_QP_WQE_INVALID ((u32)-1) |
| 174 | |
Kaike Wan | 838b6fd | 2019-01-23 19:30:07 -0800 | [diff] [blame] | 175 | struct hfi1_swqe_priv { |
| 176 | struct tid_rdma_request tid_req; |
Kaike Wan | 742a382 | 2019-01-23 19:30:40 -0800 | [diff] [blame] | 177 | struct rvt_sge_state ss; /* Used for TID RDMA READ Request */ |
Kaike Wan | 838b6fd | 2019-01-23 19:30:07 -0800 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | struct hfi1_ack_priv { |
Kaike Wan | 38d46d3 | 2019-01-23 21:49:09 -0800 | [diff] [blame] | 181 | struct rvt_sge_state ss; /* used for TID WRITE RESP */ |
Kaike Wan | 838b6fd | 2019-01-23 19:30:07 -0800 | [diff] [blame] | 182 | struct tid_rdma_request tid_req; |
| 183 | }; |
| 184 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 185 | /* |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 186 | * This structure is used to hold commonly lookedup and computed values during |
| 187 | * the send engine progress. |
| 188 | */ |
Dennis Dalessandro | 5da0fc9 | 2018-09-28 07:17:09 -0700 | [diff] [blame] | 189 | struct iowait_work; |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 190 | struct hfi1_pkt_state { |
| 191 | struct hfi1_ibdev *dev; |
| 192 | struct hfi1_ibport *ibp; |
| 193 | struct hfi1_pportdata *ppd; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 194 | struct verbs_txreq *s_txreq; |
Dennis Dalessandro | 5da0fc9 | 2018-09-28 07:17:09 -0700 | [diff] [blame] | 195 | struct iowait_work *wait; |
Mike Marciniszyn | 747f4d7 | 2016-04-12 10:46:10 -0700 | [diff] [blame] | 196 | unsigned long flags; |
Mike Marciniszyn | dd1ed10 | 2017-05-04 05:14:10 -0700 | [diff] [blame] | 197 | unsigned long timeout; |
| 198 | unsigned long timeout_int; |
| 199 | int cpu; |
Don Hiatt | 566d53a | 2017-08-04 13:54:47 -0700 | [diff] [blame] | 200 | u8 opcode; |
Mike Marciniszyn | dd1ed10 | 2017-05-04 05:14:10 -0700 | [diff] [blame] | 201 | bool in_thread; |
Kaike Wan | bcad291 | 2017-07-24 07:45:37 -0700 | [diff] [blame] | 202 | bool pkts_sent; |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 203 | }; |
| 204 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 205 | #define HFI1_PSN_CREDIT 16 |
| 206 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 207 | struct hfi1_opcode_stats { |
| 208 | u64 n_packets; /* number of packets */ |
| 209 | u64 n_bytes; /* total number of bytes */ |
| 210 | }; |
| 211 | |
| 212 | struct hfi1_opcode_stats_perctx { |
| 213 | struct hfi1_opcode_stats stats[256]; |
| 214 | }; |
| 215 | |
| 216 | static inline void inc_opstats( |
| 217 | u32 tlen, |
| 218 | struct hfi1_opcode_stats *stats) |
| 219 | { |
| 220 | #ifdef CONFIG_DEBUG_FS |
| 221 | stats->n_bytes += tlen; |
| 222 | stats->n_packets++; |
| 223 | #endif |
| 224 | } |
| 225 | |
| 226 | struct hfi1_ibport { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 227 | struct rvt_qp __rcu *qp[2]; |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 228 | struct rvt_ibport rvp; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 229 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 230 | /* the first 16 entries are sl_to_vl for !OPA */ |
| 231 | u8 sl_to_sc[32]; |
| 232 | u8 sc_to_sl[32]; |
| 233 | }; |
| 234 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 235 | struct hfi1_ibdev { |
Dennis Dalessandro | ec3f2c1 | 2016-01-19 14:41:33 -0800 | [diff] [blame] | 236 | struct rvt_dev_info rdi; /* Must be first */ |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 237 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 238 | /* QP numbers are shared by all IB ports */ |
Mike Marciniszyn | 4e04557 | 2016-10-10 06:14:28 -0700 | [diff] [blame] | 239 | /* protect txwait list */ |
| 240 | seqlock_t txwait_lock ____cacheline_aligned_in_smp; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 241 | struct list_head txwait; /* list for wait verbs_txreq */ |
| 242 | struct list_head memwait; /* list for wait kernel memory */ |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 243 | struct kmem_cache *verbs_txreq_cache; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 244 | u64 n_txwait; |
| 245 | u64 n_kmem_wait; |
Kaike Wan | 2f16a69 | 2019-01-23 19:30:18 -0800 | [diff] [blame] | 246 | u64 n_tidwait; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 247 | |
Mike Marciniszyn | 4e04557 | 2016-10-10 06:14:28 -0700 | [diff] [blame] | 248 | /* protect iowait lists */ |
| 249 | seqlock_t iowait_lock ____cacheline_aligned_in_smp; |
| 250 | u64 n_piowait; |
| 251 | u64 n_piodrain; |
| 252 | struct timer_list mem_timer; |
| 253 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 254 | #ifdef CONFIG_DEBUG_FS |
| 255 | /* per HFI debugfs */ |
| 256 | struct dentry *hfi1_ibdev_dbg; |
| 257 | /* per HFI symlinks to above */ |
| 258 | struct dentry *hfi1_ibdev_link; |
Don Hiatt | 0181ce3 | 2017-03-20 17:26:14 -0700 | [diff] [blame] | 259 | #ifdef CONFIG_FAULT_INJECTION |
Mitko Haralanov | a74d530 | 2018-05-02 06:43:24 -0700 | [diff] [blame] | 260 | struct fault *fault; |
Don Hiatt | 0181ce3 | 2017-03-20 17:26:14 -0700 | [diff] [blame] | 261 | #endif |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 262 | #endif |
| 263 | }; |
| 264 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 265 | static inline struct hfi1_ibdev *to_idev(struct ib_device *ibdev) |
| 266 | { |
Dennis Dalessandro | ec3f2c1 | 2016-01-19 14:41:33 -0800 | [diff] [blame] | 267 | struct rvt_dev_info *rdi; |
| 268 | |
| 269 | rdi = container_of(ibdev, struct rvt_dev_info, ibdev); |
| 270 | return container_of(rdi, struct hfi1_ibdev, rdi); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Dennis Dalessandro | 5da0fc9 | 2018-09-28 07:17:09 -0700 | [diff] [blame] | 273 | static inline struct rvt_qp *iowait_to_qp(struct iowait *s_iowait) |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 274 | { |
| 275 | struct hfi1_qp_priv *priv; |
| 276 | |
| 277 | priv = container_of(s_iowait, struct hfi1_qp_priv, s_iowait); |
| 278 | return priv->owner; |
| 279 | } |
| 280 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 281 | /* |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 282 | * This must be called with s_lock held. |
| 283 | */ |
Dennis Dalessandro | 13d8491 | 2017-05-29 17:22:01 -0700 | [diff] [blame] | 284 | void hfi1_bad_pkey(struct hfi1_ibport *ibp, u32 key, u32 sl, |
Don Hiatt | 88733e3 | 2017-08-04 13:54:23 -0700 | [diff] [blame] | 285 | u32 qp1, u32 qp2, u32 lid1, u32 lid2); |
Mark Bloch | 1fb7f89 | 2021-03-01 09:04:20 +0200 | [diff] [blame] | 286 | void hfi1_cap_mask_chg(struct rvt_dev_info *rdi, u32 port_num); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 287 | void hfi1_sys_guid_chg(struct hfi1_ibport *ibp); |
| 288 | void hfi1_node_desc_chg(struct hfi1_ibport *ibp); |
Mark Bloch | 1fb7f89 | 2021-03-01 09:04:20 +0200 | [diff] [blame] | 289 | int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u32 port, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 290 | const struct ib_wc *in_wc, const struct ib_grh *in_grh, |
Leon Romanovsky | e26e7b8 | 2019-10-29 08:27:45 +0200 | [diff] [blame] | 291 | const struct ib_mad *in_mad, struct ib_mad *out_mad, |
| 292 | size_t *out_mad_size, u16 *out_mad_pkey_index); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | * The PSN_MASK and PSN_SHIFT allow for |
| 296 | * 1) comparing two PSNs |
| 297 | * 2) returning the PSN with any upper bits masked |
| 298 | * 3) returning the difference between to PSNs |
| 299 | * |
| 300 | * The number of significant bits in the PSN must |
| 301 | * necessarily be at least one bit less than |
| 302 | * the container holding the PSN. |
| 303 | */ |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 304 | #define PSN_MASK 0x7FFFFFFF |
| 305 | #define PSN_SHIFT 1 |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 306 | #define PSN_MODIFY_MASK 0xFFFFFF |
| 307 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 308 | /* |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 309 | * Compare two PSNs |
| 310 | * Returns an integer <, ==, or > than zero. |
| 311 | */ |
| 312 | static inline int cmp_psn(u32 a, u32 b) |
| 313 | { |
Jubin John | 50e5dcb | 2016-02-14 20:19:41 -0800 | [diff] [blame] | 314 | return (((int)a) - ((int)b)) << PSN_SHIFT; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /* |
| 318 | * Return masked PSN |
| 319 | */ |
| 320 | static inline u32 mask_psn(u32 a) |
| 321 | { |
| 322 | return a & PSN_MASK; |
| 323 | } |
| 324 | |
| 325 | /* |
| 326 | * Return delta between two PSNs |
| 327 | */ |
| 328 | static inline u32 delta_psn(u32 a, u32 b) |
| 329 | { |
| 330 | return (((int)a - (int)b) << PSN_SHIFT) >> PSN_SHIFT; |
| 331 | } |
| 332 | |
Kaike Wan | 742a382 | 2019-01-23 19:30:40 -0800 | [diff] [blame] | 333 | static inline struct tid_rdma_request *wqe_to_tid_req(struct rvt_swqe *wqe) |
| 334 | { |
| 335 | return &((struct hfi1_swqe_priv *)wqe->priv)->tid_req; |
| 336 | } |
| 337 | |
Kaike Wan | d0d564a | 2019-01-23 19:31:02 -0800 | [diff] [blame] | 338 | static inline struct tid_rdma_request *ack_to_tid_req(struct rvt_ack_entry *e) |
| 339 | { |
| 340 | return &((struct hfi1_ack_priv *)e->priv)->tid_req; |
| 341 | } |
| 342 | |
Kaike Wan | 838b6fd | 2019-01-23 19:30:07 -0800 | [diff] [blame] | 343 | /* |
| 344 | * Look through all the active flows for a TID RDMA request and find |
| 345 | * the one (if it exists) that contains the specified PSN. |
| 346 | */ |
| 347 | static inline u32 __full_flow_psn(struct flow_state *state, u32 psn) |
| 348 | { |
| 349 | return mask_psn((state->generation << HFI1_KDETH_BTH_SEQ_SHIFT) | |
| 350 | (psn & HFI1_KDETH_BTH_SEQ_MASK)); |
| 351 | } |
| 352 | |
| 353 | static inline u32 full_flow_psn(struct tid_rdma_flow *flow, u32 psn) |
| 354 | { |
| 355 | return __full_flow_psn(&flow->flow_state, psn); |
| 356 | } |
| 357 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 358 | struct verbs_txreq; |
| 359 | void hfi1_put_txreq(struct verbs_txreq *tx); |
| 360 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 361 | int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 362 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 363 | void hfi1_cnp_rcv(struct hfi1_packet *packet); |
| 364 | |
| 365 | void hfi1_uc_rcv(struct hfi1_packet *packet); |
| 366 | |
| 367 | void hfi1_rc_rcv(struct hfi1_packet *packet); |
| 368 | |
| 369 | void hfi1_rc_hdrerr( |
| 370 | struct hfi1_ctxtdata *rcd, |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 371 | struct hfi1_packet *packet, |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 372 | struct rvt_qp *qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 373 | |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 374 | u8 ah_to_sc(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 375 | |
Mike Marciniszyn | 4bb02e9 | 2019-06-14 12:32:44 -0400 | [diff] [blame] | 376 | void hfi1_rc_verbs_aborted(struct rvt_qp *qp, struct hfi1_opa_header *opah); |
Don Hiatt | 30e0741 | 2017-08-04 13:54:04 -0700 | [diff] [blame] | 377 | void hfi1_rc_send_complete(struct rvt_qp *qp, struct hfi1_opa_header *opah); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 378 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 379 | void hfi1_ud_rcv(struct hfi1_packet *packet); |
| 380 | |
| 381 | int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey); |
| 382 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 383 | void hfi1_migrate_qp(struct rvt_qp *qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 384 | |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 385 | int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr, |
| 386 | int attr_mask, struct ib_udata *udata); |
| 387 | |
| 388 | void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr, |
| 389 | int attr_mask, struct ib_udata *udata); |
Venkata Sandeep Dhanalakota | 56acbbf | 2017-02-08 05:27:19 -0800 | [diff] [blame] | 390 | void hfi1_restart_rc(struct rvt_qp *qp, u32 psn, int wait); |
Kaike Wan | d205a06a | 2018-09-26 10:26:44 -0700 | [diff] [blame] | 391 | int hfi1_setup_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe, |
| 392 | bool *call_send); |
Ira Weiny | 31e7af1 | 2016-02-03 14:33:14 -0800 | [diff] [blame] | 393 | |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 394 | extern const u32 rc_only_opcode; |
| 395 | extern const u32 uc_only_opcode; |
| 396 | |
Don Hiatt | 9039746 | 2017-05-12 09:20:20 -0700 | [diff] [blame] | 397 | int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_packet *packet); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 398 | |
| 399 | u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr, |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 400 | const struct ib_global_route *grh, u32 hwords, u32 nwords); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 401 | |
Mike Marciniszyn | 261a435 | 2016-09-06 04:35:05 -0700 | [diff] [blame] | 402 | void hfi1_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr, |
Mitko Haralanov | 44e43d9 | 2019-01-24 06:09:46 -0800 | [diff] [blame] | 403 | u32 bth0, u32 bth1, u32 bth2, int middle, |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 404 | struct hfi1_pkt_state *ps); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 405 | |
Kaike Wan | 572f0c3 | 2019-01-23 21:51:27 -0800 | [diff] [blame] | 406 | bool hfi1_schedule_send_yield(struct rvt_qp *qp, struct hfi1_pkt_state *ps, |
| 407 | bool tid); |
| 408 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 409 | void _hfi1_do_send(struct work_struct *work); |
| 410 | |
Mike Marciniszyn | b6eac93 | 2017-04-09 10:16:35 -0700 | [diff] [blame] | 411 | void hfi1_do_send_from_rvt(struct rvt_qp *qp); |
| 412 | |
| 413 | void hfi1_do_send(struct rvt_qp *qp, bool in_thread); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 414 | |
Sebastian Sanchez | bdaf96f | 2018-02-01 10:46:31 -0800 | [diff] [blame] | 415 | void hfi1_send_rc_ack(struct hfi1_packet *packet, bool is_fecn); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 416 | |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 417 | int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 418 | |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 419 | int hfi1_make_uc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 420 | |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 421 | int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 422 | |
| 423 | int hfi1_register_ib_device(struct hfi1_devdata *); |
| 424 | |
| 425 | void hfi1_unregister_ib_device(struct hfi1_devdata *); |
| 426 | |
Kaike Wan | 22d136d | 2019-01-24 06:36:34 -0800 | [diff] [blame] | 427 | void hfi1_kdeth_eager_rcv(struct hfi1_packet *packet); |
| 428 | |
| 429 | void hfi1_kdeth_expected_rcv(struct hfi1_packet *packet); |
| 430 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 431 | void hfi1_ib_rcv(struct hfi1_packet *packet); |
| 432 | |
Don Hiatt | 72c07e2 | 2017-08-04 13:53:58 -0700 | [diff] [blame] | 433 | void hfi1_16B_rcv(struct hfi1_packet *packet); |
| 434 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 435 | unsigned hfi1_get_npkeys(struct hfi1_devdata *); |
| 436 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 437 | int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps, |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 438 | u64 pbc); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 439 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 440 | int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps, |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 441 | u64 pbc); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 442 | |
Sebastian Sanchez | 6d6b884 | 2018-02-01 10:46:23 -0800 | [diff] [blame] | 443 | static inline bool opa_bth_is_migration(struct ib_other_headers *ohdr) |
| 444 | { |
| 445 | return ohdr->bth[1] & cpu_to_be32(OPA_BTH_MIG_REQ); |
| 446 | } |
| 447 | |
Kaike Wan | 838b6fd | 2019-01-23 19:30:07 -0800 | [diff] [blame] | 448 | void hfi1_wait_kmem(struct rvt_qp *qp); |
| 449 | |
| 450 | static inline void hfi1_trdma_send_complete(struct rvt_qp *qp, |
| 451 | struct rvt_swqe *wqe, |
| 452 | enum ib_wc_status status) |
| 453 | { |
| 454 | trdma_clean_swqe(qp, wqe); |
| 455 | rvt_send_complete(qp, wqe, status); |
| 456 | } |
| 457 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 458 | extern const enum ib_wc_opcode ib_hfi1_wc_opcode[]; |
| 459 | |
| 460 | extern const u8 hdr_len_by_opcode[]; |
| 461 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 462 | extern const int ib_rvt_state_ops[]; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 463 | |
| 464 | extern __be64 ib_hfi1_sys_image_guid; /* in network order */ |
| 465 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 466 | extern unsigned int hfi1_max_cqes; |
| 467 | |
| 468 | extern unsigned int hfi1_max_cqs; |
| 469 | |
| 470 | extern unsigned int hfi1_max_qp_wrs; |
| 471 | |
| 472 | extern unsigned int hfi1_max_qps; |
| 473 | |
| 474 | extern unsigned int hfi1_max_sges; |
| 475 | |
| 476 | extern unsigned int hfi1_max_mcast_grps; |
| 477 | |
| 478 | extern unsigned int hfi1_max_mcast_qp_attached; |
| 479 | |
| 480 | extern unsigned int hfi1_max_srqs; |
| 481 | |
| 482 | extern unsigned int hfi1_max_srq_sges; |
| 483 | |
| 484 | extern unsigned int hfi1_max_srq_wrs; |
| 485 | |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 486 | extern unsigned short piothreshold; |
| 487 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 488 | extern const u32 ib_hfi1_rnr_table[]; |
| 489 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 490 | #endif /* HFI1_VERBS_H */ |