13ec648c6SKrzysztof Kozlowski /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2b48c24c2SMustafa Ismail /* Copyright (c) 2015 - 2021 Intel Corporation */
3b48c24c2SMustafa Ismail #ifndef IRDMA_VERBS_H
4b48c24c2SMustafa Ismail #define IRDMA_VERBS_H
5b48c24c2SMustafa Ismail
6b48c24c2SMustafa Ismail #define IRDMA_MAX_SAVED_PHY_PGADDR 4
781091d76SMustafa Ismail #define IRDMA_FLUSH_DELAY_MS 20
8b48c24c2SMustafa Ismail
9b48c24c2SMustafa Ismail #define IRDMA_PKEY_TBL_SZ 1
10b48c24c2SMustafa Ismail #define IRDMA_DEFAULT_PKEY 0xFFFF
11b48c24c2SMustafa Ismail
12b48c24c2SMustafa Ismail struct irdma_ucontext {
13b48c24c2SMustafa Ismail struct ib_ucontext ibucontext;
14b48c24c2SMustafa Ismail struct irdma_device *iwdev;
15b48c24c2SMustafa Ismail struct rdma_user_mmap_entry *db_mmap_entry;
16b48c24c2SMustafa Ismail struct list_head cq_reg_mem_list;
17b48c24c2SMustafa Ismail spinlock_t cq_reg_mem_list_lock; /* protect CQ memory list */
18b48c24c2SMustafa Ismail struct list_head qp_reg_mem_list;
19b48c24c2SMustafa Ismail spinlock_t qp_reg_mem_list_lock; /* protect QP memory list */
20b48c24c2SMustafa Ismail int abi_ver;
213a849872SSindhu Devale u8 legacy_mode : 1;
223a849872SSindhu Devale u8 use_raw_attrs : 1;
23b48c24c2SMustafa Ismail };
24b48c24c2SMustafa Ismail
25b48c24c2SMustafa Ismail struct irdma_pd {
26b48c24c2SMustafa Ismail struct ib_pd ibpd;
27b48c24c2SMustafa Ismail struct irdma_sc_pd sc_pd;
28b48c24c2SMustafa Ismail };
29b48c24c2SMustafa Ismail
30884194efSZhu Yanjun union irdma_sockaddr {
31884194efSZhu Yanjun struct sockaddr_in saddr_in;
32884194efSZhu Yanjun struct sockaddr_in6 saddr_in6;
33884194efSZhu Yanjun };
34884194efSZhu Yanjun
35b48c24c2SMustafa Ismail struct irdma_av {
36b48c24c2SMustafa Ismail u8 macaddr[16];
37b48c24c2SMustafa Ismail struct rdma_ah_attr attrs;
38884194efSZhu Yanjun union irdma_sockaddr sgid_addr;
39884194efSZhu Yanjun union irdma_sockaddr dgid_addr;
40b48c24c2SMustafa Ismail u8 net_type;
41b48c24c2SMustafa Ismail };
42b48c24c2SMustafa Ismail
43b48c24c2SMustafa Ismail struct irdma_ah {
44b48c24c2SMustafa Ismail struct ib_ah ibah;
45b48c24c2SMustafa Ismail struct irdma_sc_ah sc_ah;
46b48c24c2SMustafa Ismail struct irdma_pd *pd;
47b48c24c2SMustafa Ismail struct irdma_av av;
48b48c24c2SMustafa Ismail u8 sgid_index;
49b48c24c2SMustafa Ismail union ib_gid dgid;
5051cad287SMustafa Ismail struct hlist_node list;
5151cad287SMustafa Ismail refcount_t refcnt;
5251cad287SMustafa Ismail struct irdma_ah *parent_ah; /* AH from cached list */
53b48c24c2SMustafa Ismail };
54b48c24c2SMustafa Ismail
55b48c24c2SMustafa Ismail struct irdma_hmc_pble {
56b48c24c2SMustafa Ismail union {
57b48c24c2SMustafa Ismail u32 idx;
58b48c24c2SMustafa Ismail dma_addr_t addr;
59b48c24c2SMustafa Ismail };
60b48c24c2SMustafa Ismail };
61b48c24c2SMustafa Ismail
62b48c24c2SMustafa Ismail struct irdma_cq_mr {
63b48c24c2SMustafa Ismail struct irdma_hmc_pble cq_pbl;
64b48c24c2SMustafa Ismail dma_addr_t shadow;
65b48c24c2SMustafa Ismail bool split;
66b48c24c2SMustafa Ismail };
67b48c24c2SMustafa Ismail
68b48c24c2SMustafa Ismail struct irdma_qp_mr {
69b48c24c2SMustafa Ismail struct irdma_hmc_pble sq_pbl;
70b48c24c2SMustafa Ismail struct irdma_hmc_pble rq_pbl;
71b48c24c2SMustafa Ismail dma_addr_t shadow;
72b48c24c2SMustafa Ismail struct page *sq_page;
73b48c24c2SMustafa Ismail };
74b48c24c2SMustafa Ismail
75b48c24c2SMustafa Ismail struct irdma_cq_buf {
76b48c24c2SMustafa Ismail struct irdma_dma_mem kmem_buf;
77b48c24c2SMustafa Ismail struct irdma_cq_uk cq_uk;
78b48c24c2SMustafa Ismail struct irdma_hw *hw;
79b48c24c2SMustafa Ismail struct list_head list;
80b48c24c2SMustafa Ismail struct work_struct work;
81b48c24c2SMustafa Ismail };
82b48c24c2SMustafa Ismail
83b48c24c2SMustafa Ismail struct irdma_pbl {
84b48c24c2SMustafa Ismail struct list_head list;
85b48c24c2SMustafa Ismail union {
86b48c24c2SMustafa Ismail struct irdma_qp_mr qp_mr;
87b48c24c2SMustafa Ismail struct irdma_cq_mr cq_mr;
88b48c24c2SMustafa Ismail };
89b48c24c2SMustafa Ismail
90b48c24c2SMustafa Ismail bool pbl_allocated:1;
91b48c24c2SMustafa Ismail bool on_list:1;
92b48c24c2SMustafa Ismail u64 user_base;
93b48c24c2SMustafa Ismail struct irdma_pble_alloc pble_alloc;
94b48c24c2SMustafa Ismail struct irdma_mr *iwmr;
95b48c24c2SMustafa Ismail };
96b48c24c2SMustafa Ismail
97b48c24c2SMustafa Ismail struct irdma_mr {
98b48c24c2SMustafa Ismail union {
99b48c24c2SMustafa Ismail struct ib_mr ibmr;
100b48c24c2SMustafa Ismail struct ib_mw ibmw;
101b48c24c2SMustafa Ismail };
102b48c24c2SMustafa Ismail struct ib_umem *region;
1035ac388dbSSindhu Devale int access;
1045ac388dbSSindhu Devale u8 is_hwreg;
105b48c24c2SMustafa Ismail u16 type;
106b48c24c2SMustafa Ismail u32 page_cnt;
107b48c24c2SMustafa Ismail u64 page_size;
108b48c24c2SMustafa Ismail u32 npages;
109b48c24c2SMustafa Ismail u32 stag;
110b48c24c2SMustafa Ismail u64 len;
111b48c24c2SMustafa Ismail u64 pgaddrmem[IRDMA_MAX_SAVED_PHY_PGADDR];
112b48c24c2SMustafa Ismail struct irdma_pbl iwpbl;
113b48c24c2SMustafa Ismail };
114b48c24c2SMustafa Ismail
115b48c24c2SMustafa Ismail struct irdma_cq {
116b48c24c2SMustafa Ismail struct ib_cq ibcq;
117b48c24c2SMustafa Ismail struct irdma_sc_cq sc_cq;
118b48c24c2SMustafa Ismail u16 cq_head;
119b48c24c2SMustafa Ismail u16 cq_size;
120b48c24c2SMustafa Ismail u16 cq_num;
121b48c24c2SMustafa Ismail bool user_mode;
12281091d76SMustafa Ismail atomic_t armed;
12310467ce0STatyana Nikolova enum irdma_cmpl_notify last_notify;
124b48c24c2SMustafa Ismail u32 polled_cmpls;
125b48c24c2SMustafa Ismail u32 cq_mem_size;
126b48c24c2SMustafa Ismail struct irdma_dma_mem kmem;
127b48c24c2SMustafa Ismail struct irdma_dma_mem kmem_shadow;
128e49bad78SKrzysztof Czurylo struct completion free_cq;
129e49bad78SKrzysztof Czurylo refcount_t refcnt;
130b48c24c2SMustafa Ismail spinlock_t lock; /* for poll cq */
131b48c24c2SMustafa Ismail struct irdma_pbl *iwpbl;
132b48c24c2SMustafa Ismail struct irdma_pbl *iwpbl_shadow;
133b48c24c2SMustafa Ismail struct list_head resize_list;
134b48c24c2SMustafa Ismail struct irdma_cq_poll_info cur_cqe;
13581091d76SMustafa Ismail struct list_head cmpl_generated;
13681091d76SMustafa Ismail };
13781091d76SMustafa Ismail
13881091d76SMustafa Ismail struct irdma_cmpl_gen {
13981091d76SMustafa Ismail struct list_head list;
14081091d76SMustafa Ismail struct irdma_cq_poll_info cpi;
141b48c24c2SMustafa Ismail };
142b48c24c2SMustafa Ismail
143b48c24c2SMustafa Ismail struct disconn_work {
144b48c24c2SMustafa Ismail struct work_struct work;
145b48c24c2SMustafa Ismail struct irdma_qp *iwqp;
146b48c24c2SMustafa Ismail };
147b48c24c2SMustafa Ismail
148b48c24c2SMustafa Ismail struct iw_cm_id;
149b48c24c2SMustafa Ismail
150b48c24c2SMustafa Ismail struct irdma_qp_kmode {
151b48c24c2SMustafa Ismail struct irdma_dma_mem dma_mem;
152b48c24c2SMustafa Ismail struct irdma_sq_uk_wr_trk_info *sq_wrid_mem;
153b48c24c2SMustafa Ismail u64 *rq_wrid_mem;
154b48c24c2SMustafa Ismail };
155b48c24c2SMustafa Ismail
156b48c24c2SMustafa Ismail struct irdma_qp {
157b48c24c2SMustafa Ismail struct ib_qp ibqp;
158b48c24c2SMustafa Ismail struct irdma_sc_qp sc_qp;
159b48c24c2SMustafa Ismail struct irdma_device *iwdev;
160b48c24c2SMustafa Ismail struct irdma_cq *iwscq;
161b48c24c2SMustafa Ismail struct irdma_cq *iwrcq;
162b48c24c2SMustafa Ismail struct irdma_pd *iwpd;
163b48c24c2SMustafa Ismail struct rdma_user_mmap_entry *push_wqe_mmap_entry;
164b48c24c2SMustafa Ismail struct rdma_user_mmap_entry *push_db_mmap_entry;
165b48c24c2SMustafa Ismail struct irdma_qp_host_ctx_info ctx_info;
166b48c24c2SMustafa Ismail union {
167b48c24c2SMustafa Ismail struct irdma_iwarp_offload_info iwarp_info;
168b48c24c2SMustafa Ismail struct irdma_roce_offload_info roce_info;
169b48c24c2SMustafa Ismail };
170b48c24c2SMustafa Ismail
171b48c24c2SMustafa Ismail union {
172b48c24c2SMustafa Ismail struct irdma_tcp_offload_info tcp_info;
173b48c24c2SMustafa Ismail struct irdma_udp_offload_info udp_info;
174b48c24c2SMustafa Ismail };
175b48c24c2SMustafa Ismail
176b48c24c2SMustafa Ismail struct irdma_ah roce_ah;
177b48c24c2SMustafa Ismail struct list_head teardown_entry;
178b48c24c2SMustafa Ismail refcount_t refcnt;
179b48c24c2SMustafa Ismail struct iw_cm_id *cm_id;
180b48c24c2SMustafa Ismail struct irdma_cm_node *cm_node;
18181091d76SMustafa Ismail struct delayed_work dwork_flush;
182b48c24c2SMustafa Ismail struct ib_mr *lsmm_mr;
183b48c24c2SMustafa Ismail atomic_t hw_mod_qp_pend;
184b48c24c2SMustafa Ismail enum ib_qp_state ibqp_state;
185b48c24c2SMustafa Ismail u32 qp_mem_size;
186b48c24c2SMustafa Ismail u32 last_aeq;
187b48c24c2SMustafa Ismail int max_send_wr;
188b48c24c2SMustafa Ismail int max_recv_wr;
189b48c24c2SMustafa Ismail atomic_t close_timer_started;
190b48c24c2SMustafa Ismail spinlock_t lock; /* serialize posting WRs to SQ/RQ */
191b48c24c2SMustafa Ismail struct irdma_qp_context *iwqp_context;
192b48c24c2SMustafa Ismail void *pbl_vbase;
193b48c24c2SMustafa Ismail dma_addr_t pbl_pbase;
194b48c24c2SMustafa Ismail struct page *page;
195b48c24c2SMustafa Ismail u8 active_conn : 1;
196b48c24c2SMustafa Ismail u8 user_mode : 1;
197b48c24c2SMustafa Ismail u8 hte_added : 1;
198b48c24c2SMustafa Ismail u8 flush_issued : 1;
199b48c24c2SMustafa Ismail u8 sig_all : 1;
200b48c24c2SMustafa Ismail u8 pau_mode : 1;
201*bd6da690SMustafa Ismail u8 suspend_pending : 1;
202b48c24c2SMustafa Ismail u8 rsvd : 1;
203b48c24c2SMustafa Ismail u8 iwarp_state;
204b48c24c2SMustafa Ismail u16 term_sq_flush_code;
205b48c24c2SMustafa Ismail u16 term_rq_flush_code;
206b48c24c2SMustafa Ismail u8 hw_iwarp_state;
207b48c24c2SMustafa Ismail u8 hw_tcp_state;
208b48c24c2SMustafa Ismail struct irdma_qp_kmode kqp;
209b48c24c2SMustafa Ismail struct irdma_dma_mem host_ctx;
210b48c24c2SMustafa Ismail struct timer_list terminate_timer;
211b48c24c2SMustafa Ismail struct irdma_pbl *iwpbl;
212b48c24c2SMustafa Ismail struct irdma_dma_mem q2_ctx_mem;
213b48c24c2SMustafa Ismail struct irdma_dma_mem ietf_mem;
214b48c24c2SMustafa Ismail struct completion free_qp;
215b48c24c2SMustafa Ismail wait_queue_head_t waitq;
216b48c24c2SMustafa Ismail wait_queue_head_t mod_qp_waitq;
217b48c24c2SMustafa Ismail u8 rts_ae_rcvd;
218b48c24c2SMustafa Ismail };
219b48c24c2SMustafa Ismail
220b48c24c2SMustafa Ismail enum irdma_mmap_flag {
221b48c24c2SMustafa Ismail IRDMA_MMAP_IO_NC,
222b48c24c2SMustafa Ismail IRDMA_MMAP_IO_WC,
223b48c24c2SMustafa Ismail };
224b48c24c2SMustafa Ismail
225b48c24c2SMustafa Ismail struct irdma_user_mmap_entry {
226b48c24c2SMustafa Ismail struct rdma_user_mmap_entry rdma_entry;
227b48c24c2SMustafa Ismail u64 bar_offset;
228b48c24c2SMustafa Ismail u8 mmap_flag;
229b48c24c2SMustafa Ismail };
230b48c24c2SMustafa Ismail
irdma_fw_major_ver(struct irdma_sc_dev * dev)231b48c24c2SMustafa Ismail static inline u16 irdma_fw_major_ver(struct irdma_sc_dev *dev)
232b48c24c2SMustafa Ismail {
233b48c24c2SMustafa Ismail return (u16)FIELD_GET(IRDMA_FW_VER_MAJOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]);
234b48c24c2SMustafa Ismail }
235b48c24c2SMustafa Ismail
irdma_fw_minor_ver(struct irdma_sc_dev * dev)236b48c24c2SMustafa Ismail static inline u16 irdma_fw_minor_ver(struct irdma_sc_dev *dev)
237b48c24c2SMustafa Ismail {
238b48c24c2SMustafa Ismail return (u16)FIELD_GET(IRDMA_FW_VER_MINOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]);
239b48c24c2SMustafa Ismail }
240b48c24c2SMustafa Ismail
set_ib_wc_op_sq(struct irdma_cq_poll_info * cq_poll_info,struct ib_wc * entry)24124419777SMustafa Ismail static inline void set_ib_wc_op_sq(struct irdma_cq_poll_info *cq_poll_info,
24224419777SMustafa Ismail struct ib_wc *entry)
24324419777SMustafa Ismail {
24424419777SMustafa Ismail switch (cq_poll_info->op_type) {
24524419777SMustafa Ismail case IRDMA_OP_TYPE_RDMA_WRITE:
24624419777SMustafa Ismail case IRDMA_OP_TYPE_RDMA_WRITE_SOL:
24724419777SMustafa Ismail entry->opcode = IB_WC_RDMA_WRITE;
24824419777SMustafa Ismail break;
24924419777SMustafa Ismail case IRDMA_OP_TYPE_RDMA_READ_INV_STAG:
25024419777SMustafa Ismail case IRDMA_OP_TYPE_RDMA_READ:
25124419777SMustafa Ismail entry->opcode = IB_WC_RDMA_READ;
25224419777SMustafa Ismail break;
25324419777SMustafa Ismail case IRDMA_OP_TYPE_SEND_SOL:
25424419777SMustafa Ismail case IRDMA_OP_TYPE_SEND_SOL_INV:
25524419777SMustafa Ismail case IRDMA_OP_TYPE_SEND_INV:
25624419777SMustafa Ismail case IRDMA_OP_TYPE_SEND:
25724419777SMustafa Ismail entry->opcode = IB_WC_SEND;
25824419777SMustafa Ismail break;
25924419777SMustafa Ismail case IRDMA_OP_TYPE_FAST_REG_NSMR:
26024419777SMustafa Ismail entry->opcode = IB_WC_REG_MR;
26124419777SMustafa Ismail break;
26224419777SMustafa Ismail case IRDMA_OP_TYPE_INV_STAG:
26324419777SMustafa Ismail entry->opcode = IB_WC_LOCAL_INV;
26424419777SMustafa Ismail break;
26524419777SMustafa Ismail default:
26624419777SMustafa Ismail entry->status = IB_WC_GENERAL_ERR;
26724419777SMustafa Ismail }
26824419777SMustafa Ismail }
26924419777SMustafa Ismail
set_ib_wc_op_rq(struct irdma_cq_poll_info * cq_poll_info,struct ib_wc * entry,bool send_imm_support)27024419777SMustafa Ismail static inline void set_ib_wc_op_rq(struct irdma_cq_poll_info *cq_poll_info,
27124419777SMustafa Ismail struct ib_wc *entry, bool send_imm_support)
27224419777SMustafa Ismail {
27324419777SMustafa Ismail /**
27424419777SMustafa Ismail * iWARP does not support sendImm, so the presence of Imm data
27524419777SMustafa Ismail * must be WriteImm.
27624419777SMustafa Ismail */
27724419777SMustafa Ismail if (!send_imm_support) {
27824419777SMustafa Ismail entry->opcode = cq_poll_info->imm_valid ?
27924419777SMustafa Ismail IB_WC_RECV_RDMA_WITH_IMM :
28024419777SMustafa Ismail IB_WC_RECV;
28124419777SMustafa Ismail return;
28224419777SMustafa Ismail }
28324419777SMustafa Ismail
28424419777SMustafa Ismail switch (cq_poll_info->op_type) {
28524419777SMustafa Ismail case IB_OPCODE_RDMA_WRITE_ONLY_WITH_IMMEDIATE:
28624419777SMustafa Ismail case IB_OPCODE_RDMA_WRITE_LAST_WITH_IMMEDIATE:
28724419777SMustafa Ismail entry->opcode = IB_WC_RECV_RDMA_WITH_IMM;
28824419777SMustafa Ismail break;
28924419777SMustafa Ismail default:
29024419777SMustafa Ismail entry->opcode = IB_WC_RECV;
29124419777SMustafa Ismail }
29224419777SMustafa Ismail }
29324419777SMustafa Ismail
294b48c24c2SMustafa Ismail void irdma_mcast_mac(u32 *ip_addr, u8 *mac, bool ipv4);
295b48c24c2SMustafa Ismail int irdma_ib_register_device(struct irdma_device *iwdev);
296b48c24c2SMustafa Ismail void irdma_ib_unregister_device(struct irdma_device *iwdev);
297b48c24c2SMustafa Ismail void irdma_ib_dealloc_device(struct ib_device *ibdev);
298b48c24c2SMustafa Ismail void irdma_ib_qp_event(struct irdma_qp *iwqp, enum irdma_qp_event_type event);
29981091d76SMustafa Ismail void irdma_generate_flush_completions(struct irdma_qp *iwqp);
30081091d76SMustafa Ismail void irdma_remove_cmpls_list(struct irdma_cq *iwcq);
30181091d76SMustafa Ismail int irdma_generated_cmpls(struct irdma_cq *iwcq, struct irdma_cq_poll_info *cq_poll_info);
302b48c24c2SMustafa Ismail #endif /* IRDMA_VERBS_H */
303