1b48c24c2SMustafa Ismail /* 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;
103b48c24c2SMustafa Ismail u16 type;
104b48c24c2SMustafa Ismail u32 page_cnt;
105b48c24c2SMustafa Ismail u64 page_size;
106b48c24c2SMustafa Ismail u32 npages;
107b48c24c2SMustafa Ismail u32 stag;
108b48c24c2SMustafa Ismail u64 len;
109b48c24c2SMustafa Ismail u64 pgaddrmem[IRDMA_MAX_SAVED_PHY_PGADDR];
110b48c24c2SMustafa Ismail struct irdma_pbl iwpbl;
111b48c24c2SMustafa Ismail };
112b48c24c2SMustafa Ismail
113b48c24c2SMustafa Ismail struct irdma_cq {
114b48c24c2SMustafa Ismail struct ib_cq ibcq;
115b48c24c2SMustafa Ismail struct irdma_sc_cq sc_cq;
116b48c24c2SMustafa Ismail u16 cq_head;
117b48c24c2SMustafa Ismail u16 cq_size;
118b48c24c2SMustafa Ismail u16 cq_num;
119b48c24c2SMustafa Ismail bool user_mode;
12081091d76SMustafa Ismail atomic_t armed;
12110467ce0STatyana Nikolova enum irdma_cmpl_notify last_notify;
122b48c24c2SMustafa Ismail u32 polled_cmpls;
123b48c24c2SMustafa Ismail u32 cq_mem_size;
124b48c24c2SMustafa Ismail struct irdma_dma_mem kmem;
125b48c24c2SMustafa Ismail struct irdma_dma_mem kmem_shadow;
126e49bad78SKrzysztof Czurylo struct completion free_cq;
127e49bad78SKrzysztof Czurylo refcount_t refcnt;
128b48c24c2SMustafa Ismail spinlock_t lock; /* for poll cq */
129b48c24c2SMustafa Ismail struct irdma_pbl *iwpbl;
130b48c24c2SMustafa Ismail struct irdma_pbl *iwpbl_shadow;
131b48c24c2SMustafa Ismail struct list_head resize_list;
132b48c24c2SMustafa Ismail struct irdma_cq_poll_info cur_cqe;
13381091d76SMustafa Ismail struct list_head cmpl_generated;
13481091d76SMustafa Ismail };
13581091d76SMustafa Ismail
13681091d76SMustafa Ismail struct irdma_cmpl_gen {
13781091d76SMustafa Ismail struct list_head list;
13881091d76SMustafa Ismail struct irdma_cq_poll_info cpi;
139b48c24c2SMustafa Ismail };
140b48c24c2SMustafa Ismail
141b48c24c2SMustafa Ismail struct disconn_work {
142b48c24c2SMustafa Ismail struct work_struct work;
143b48c24c2SMustafa Ismail struct irdma_qp *iwqp;
144b48c24c2SMustafa Ismail };
145b48c24c2SMustafa Ismail
146b48c24c2SMustafa Ismail struct iw_cm_id;
147b48c24c2SMustafa Ismail
148b48c24c2SMustafa Ismail struct irdma_qp_kmode {
149b48c24c2SMustafa Ismail struct irdma_dma_mem dma_mem;
150b48c24c2SMustafa Ismail struct irdma_sq_uk_wr_trk_info *sq_wrid_mem;
151b48c24c2SMustafa Ismail u64 *rq_wrid_mem;
152b48c24c2SMustafa Ismail };
153b48c24c2SMustafa Ismail
154b48c24c2SMustafa Ismail struct irdma_qp {
155b48c24c2SMustafa Ismail struct ib_qp ibqp;
156b48c24c2SMustafa Ismail struct irdma_sc_qp sc_qp;
157b48c24c2SMustafa Ismail struct irdma_device *iwdev;
158b48c24c2SMustafa Ismail struct irdma_cq *iwscq;
159b48c24c2SMustafa Ismail struct irdma_cq *iwrcq;
160b48c24c2SMustafa Ismail struct irdma_pd *iwpd;
161b48c24c2SMustafa Ismail struct rdma_user_mmap_entry *push_wqe_mmap_entry;
162b48c24c2SMustafa Ismail struct rdma_user_mmap_entry *push_db_mmap_entry;
163b48c24c2SMustafa Ismail struct irdma_qp_host_ctx_info ctx_info;
164b48c24c2SMustafa Ismail union {
165b48c24c2SMustafa Ismail struct irdma_iwarp_offload_info iwarp_info;
166b48c24c2SMustafa Ismail struct irdma_roce_offload_info roce_info;
167b48c24c2SMustafa Ismail };
168b48c24c2SMustafa Ismail
169b48c24c2SMustafa Ismail union {
170b48c24c2SMustafa Ismail struct irdma_tcp_offload_info tcp_info;
171b48c24c2SMustafa Ismail struct irdma_udp_offload_info udp_info;
172b48c24c2SMustafa Ismail };
173b48c24c2SMustafa Ismail
174b48c24c2SMustafa Ismail struct irdma_ah roce_ah;
175b48c24c2SMustafa Ismail struct list_head teardown_entry;
176b48c24c2SMustafa Ismail refcount_t refcnt;
177b48c24c2SMustafa Ismail struct iw_cm_id *cm_id;
178b48c24c2SMustafa Ismail struct irdma_cm_node *cm_node;
17981091d76SMustafa Ismail struct delayed_work dwork_flush;
180b48c24c2SMustafa Ismail struct ib_mr *lsmm_mr;
181b48c24c2SMustafa Ismail atomic_t hw_mod_qp_pend;
182b48c24c2SMustafa Ismail enum ib_qp_state ibqp_state;
183b48c24c2SMustafa Ismail u32 qp_mem_size;
184b48c24c2SMustafa Ismail u32 last_aeq;
185b48c24c2SMustafa Ismail int max_send_wr;
186b48c24c2SMustafa Ismail int max_recv_wr;
187b48c24c2SMustafa Ismail atomic_t close_timer_started;
188b48c24c2SMustafa Ismail spinlock_t lock; /* serialize posting WRs to SQ/RQ */
189b48c24c2SMustafa Ismail struct irdma_qp_context *iwqp_context;
190b48c24c2SMustafa Ismail void *pbl_vbase;
191b48c24c2SMustafa Ismail dma_addr_t pbl_pbase;
192b48c24c2SMustafa Ismail struct page *page;
193b48c24c2SMustafa Ismail u8 active_conn : 1;
194b48c24c2SMustafa Ismail u8 user_mode : 1;
195b48c24c2SMustafa Ismail u8 hte_added : 1;
196b48c24c2SMustafa Ismail u8 flush_issued : 1;
197b48c24c2SMustafa Ismail u8 sig_all : 1;
198b48c24c2SMustafa Ismail u8 pau_mode : 1;
199*9b1b8ab2SMustafa Ismail u8 suspend_pending : 1;
200b48c24c2SMustafa Ismail u8 rsvd : 1;
201b48c24c2SMustafa Ismail u8 iwarp_state;
202b48c24c2SMustafa Ismail u16 term_sq_flush_code;
203b48c24c2SMustafa Ismail u16 term_rq_flush_code;
204b48c24c2SMustafa Ismail u8 hw_iwarp_state;
205b48c24c2SMustafa Ismail u8 hw_tcp_state;
206b48c24c2SMustafa Ismail struct irdma_qp_kmode kqp;
207b48c24c2SMustafa Ismail struct irdma_dma_mem host_ctx;
208b48c24c2SMustafa Ismail struct timer_list terminate_timer;
209b48c24c2SMustafa Ismail struct irdma_pbl *iwpbl;
210b48c24c2SMustafa Ismail struct irdma_dma_mem q2_ctx_mem;
211b48c24c2SMustafa Ismail struct irdma_dma_mem ietf_mem;
212b48c24c2SMustafa Ismail struct completion free_qp;
213b48c24c2SMustafa Ismail wait_queue_head_t waitq;
214b48c24c2SMustafa Ismail wait_queue_head_t mod_qp_waitq;
215b48c24c2SMustafa Ismail u8 rts_ae_rcvd;
216b48c24c2SMustafa Ismail };
217b48c24c2SMustafa Ismail
218b48c24c2SMustafa Ismail enum irdma_mmap_flag {
219b48c24c2SMustafa Ismail IRDMA_MMAP_IO_NC,
220b48c24c2SMustafa Ismail IRDMA_MMAP_IO_WC,
221b48c24c2SMustafa Ismail };
222b48c24c2SMustafa Ismail
223b48c24c2SMustafa Ismail struct irdma_user_mmap_entry {
224b48c24c2SMustafa Ismail struct rdma_user_mmap_entry rdma_entry;
225b48c24c2SMustafa Ismail u64 bar_offset;
226b48c24c2SMustafa Ismail u8 mmap_flag;
227b48c24c2SMustafa Ismail };
228b48c24c2SMustafa Ismail
irdma_fw_major_ver(struct irdma_sc_dev * dev)229b48c24c2SMustafa Ismail static inline u16 irdma_fw_major_ver(struct irdma_sc_dev *dev)
230b48c24c2SMustafa Ismail {
231b48c24c2SMustafa Ismail return (u16)FIELD_GET(IRDMA_FW_VER_MAJOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]);
232b48c24c2SMustafa Ismail }
233b48c24c2SMustafa Ismail
irdma_fw_minor_ver(struct irdma_sc_dev * dev)234b48c24c2SMustafa Ismail static inline u16 irdma_fw_minor_ver(struct irdma_sc_dev *dev)
235b48c24c2SMustafa Ismail {
236b48c24c2SMustafa Ismail return (u16)FIELD_GET(IRDMA_FW_VER_MINOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]);
237b48c24c2SMustafa Ismail }
238b48c24c2SMustafa Ismail
set_ib_wc_op_sq(struct irdma_cq_poll_info * cq_poll_info,struct ib_wc * entry)23924419777SMustafa Ismail static inline void set_ib_wc_op_sq(struct irdma_cq_poll_info *cq_poll_info,
24024419777SMustafa Ismail struct ib_wc *entry)
24124419777SMustafa Ismail {
24224419777SMustafa Ismail switch (cq_poll_info->op_type) {
24324419777SMustafa Ismail case IRDMA_OP_TYPE_RDMA_WRITE:
24424419777SMustafa Ismail case IRDMA_OP_TYPE_RDMA_WRITE_SOL:
24524419777SMustafa Ismail entry->opcode = IB_WC_RDMA_WRITE;
24624419777SMustafa Ismail break;
24724419777SMustafa Ismail case IRDMA_OP_TYPE_RDMA_READ_INV_STAG:
24824419777SMustafa Ismail case IRDMA_OP_TYPE_RDMA_READ:
24924419777SMustafa Ismail entry->opcode = IB_WC_RDMA_READ;
25024419777SMustafa Ismail break;
25124419777SMustafa Ismail case IRDMA_OP_TYPE_SEND_SOL:
25224419777SMustafa Ismail case IRDMA_OP_TYPE_SEND_SOL_INV:
25324419777SMustafa Ismail case IRDMA_OP_TYPE_SEND_INV:
25424419777SMustafa Ismail case IRDMA_OP_TYPE_SEND:
25524419777SMustafa Ismail entry->opcode = IB_WC_SEND;
25624419777SMustafa Ismail break;
25724419777SMustafa Ismail case IRDMA_OP_TYPE_FAST_REG_NSMR:
25824419777SMustafa Ismail entry->opcode = IB_WC_REG_MR;
25924419777SMustafa Ismail break;
26024419777SMustafa Ismail case IRDMA_OP_TYPE_INV_STAG:
26124419777SMustafa Ismail entry->opcode = IB_WC_LOCAL_INV;
26224419777SMustafa Ismail break;
26324419777SMustafa Ismail default:
26424419777SMustafa Ismail entry->status = IB_WC_GENERAL_ERR;
26524419777SMustafa Ismail }
26624419777SMustafa Ismail }
26724419777SMustafa Ismail
set_ib_wc_op_rq(struct irdma_cq_poll_info * cq_poll_info,struct ib_wc * entry,bool send_imm_support)26824419777SMustafa Ismail static inline void set_ib_wc_op_rq(struct irdma_cq_poll_info *cq_poll_info,
26924419777SMustafa Ismail struct ib_wc *entry, bool send_imm_support)
27024419777SMustafa Ismail {
27124419777SMustafa Ismail /**
27224419777SMustafa Ismail * iWARP does not support sendImm, so the presence of Imm data
27324419777SMustafa Ismail * must be WriteImm.
27424419777SMustafa Ismail */
27524419777SMustafa Ismail if (!send_imm_support) {
27624419777SMustafa Ismail entry->opcode = cq_poll_info->imm_valid ?
27724419777SMustafa Ismail IB_WC_RECV_RDMA_WITH_IMM :
27824419777SMustafa Ismail IB_WC_RECV;
27924419777SMustafa Ismail return;
28024419777SMustafa Ismail }
28124419777SMustafa Ismail
28224419777SMustafa Ismail switch (cq_poll_info->op_type) {
28324419777SMustafa Ismail case IB_OPCODE_RDMA_WRITE_ONLY_WITH_IMMEDIATE:
28424419777SMustafa Ismail case IB_OPCODE_RDMA_WRITE_LAST_WITH_IMMEDIATE:
28524419777SMustafa Ismail entry->opcode = IB_WC_RECV_RDMA_WITH_IMM;
28624419777SMustafa Ismail break;
28724419777SMustafa Ismail default:
28824419777SMustafa Ismail entry->opcode = IB_WC_RECV;
28924419777SMustafa Ismail }
29024419777SMustafa Ismail }
29124419777SMustafa Ismail
292b48c24c2SMustafa Ismail void irdma_mcast_mac(u32 *ip_addr, u8 *mac, bool ipv4);
293b48c24c2SMustafa Ismail int irdma_ib_register_device(struct irdma_device *iwdev);
294b48c24c2SMustafa Ismail void irdma_ib_unregister_device(struct irdma_device *iwdev);
295b48c24c2SMustafa Ismail void irdma_ib_dealloc_device(struct ib_device *ibdev);
296b48c24c2SMustafa Ismail void irdma_ib_qp_event(struct irdma_qp *iwqp, enum irdma_qp_event_type event);
29781091d76SMustafa Ismail void irdma_generate_flush_completions(struct irdma_qp *iwqp);
29881091d76SMustafa Ismail void irdma_remove_cmpls_list(struct irdma_cq *iwcq);
29981091d76SMustafa Ismail int irdma_generated_cmpls(struct irdma_cq *iwcq, struct irdma_cq_poll_info *cq_poll_info);
300b48c24c2SMustafa Ismail #endif /* IRDMA_VERBS_H */
301