xref: /openbmc/linux/drivers/infiniband/hw/irdma/verbs.h (revision 884194ef264e140a6d22f7a5de2b76765d17734a)
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
7b48c24c2SMustafa Ismail 
8b48c24c2SMustafa Ismail #define IRDMA_PKEY_TBL_SZ		1
9b48c24c2SMustafa Ismail #define IRDMA_DEFAULT_PKEY		0xFFFF
10b48c24c2SMustafa Ismail 
11b48c24c2SMustafa Ismail struct irdma_ucontext {
12b48c24c2SMustafa Ismail 	struct ib_ucontext ibucontext;
13b48c24c2SMustafa Ismail 	struct irdma_device *iwdev;
14b48c24c2SMustafa Ismail 	struct rdma_user_mmap_entry *db_mmap_entry;
15b48c24c2SMustafa Ismail 	struct list_head cq_reg_mem_list;
16b48c24c2SMustafa Ismail 	spinlock_t cq_reg_mem_list_lock; /* protect CQ memory list */
17b48c24c2SMustafa Ismail 	struct list_head qp_reg_mem_list;
18b48c24c2SMustafa Ismail 	spinlock_t qp_reg_mem_list_lock; /* protect QP memory list */
19b48c24c2SMustafa Ismail 	int abi_ver;
20b48c24c2SMustafa Ismail 	bool legacy_mode;
21b48c24c2SMustafa Ismail };
22b48c24c2SMustafa Ismail 
23b48c24c2SMustafa Ismail struct irdma_pd {
24b48c24c2SMustafa Ismail 	struct ib_pd ibpd;
25b48c24c2SMustafa Ismail 	struct irdma_sc_pd sc_pd;
26b48c24c2SMustafa Ismail };
27b48c24c2SMustafa Ismail 
28*884194efSZhu Yanjun union irdma_sockaddr {
29*884194efSZhu Yanjun 	struct sockaddr_in saddr_in;
30*884194efSZhu Yanjun 	struct sockaddr_in6 saddr_in6;
31*884194efSZhu Yanjun };
32*884194efSZhu Yanjun 
33b48c24c2SMustafa Ismail struct irdma_av {
34b48c24c2SMustafa Ismail 	u8 macaddr[16];
35b48c24c2SMustafa Ismail 	struct rdma_ah_attr attrs;
36*884194efSZhu Yanjun 	union irdma_sockaddr sgid_addr;
37*884194efSZhu Yanjun 	union irdma_sockaddr dgid_addr;
38b48c24c2SMustafa Ismail 	u8 net_type;
39b48c24c2SMustafa Ismail };
40b48c24c2SMustafa Ismail 
41b48c24c2SMustafa Ismail struct irdma_ah {
42b48c24c2SMustafa Ismail 	struct ib_ah ibah;
43b48c24c2SMustafa Ismail 	struct irdma_sc_ah sc_ah;
44b48c24c2SMustafa Ismail 	struct irdma_pd *pd;
45b48c24c2SMustafa Ismail 	struct irdma_av av;
46b48c24c2SMustafa Ismail 	u8 sgid_index;
47b48c24c2SMustafa Ismail 	union ib_gid dgid;
48b48c24c2SMustafa Ismail };
49b48c24c2SMustafa Ismail 
50b48c24c2SMustafa Ismail struct irdma_hmc_pble {
51b48c24c2SMustafa Ismail 	union {
52b48c24c2SMustafa Ismail 		u32 idx;
53b48c24c2SMustafa Ismail 		dma_addr_t addr;
54b48c24c2SMustafa Ismail 	};
55b48c24c2SMustafa Ismail };
56b48c24c2SMustafa Ismail 
57b48c24c2SMustafa Ismail struct irdma_cq_mr {
58b48c24c2SMustafa Ismail 	struct irdma_hmc_pble cq_pbl;
59b48c24c2SMustafa Ismail 	dma_addr_t shadow;
60b48c24c2SMustafa Ismail 	bool split;
61b48c24c2SMustafa Ismail };
62b48c24c2SMustafa Ismail 
63b48c24c2SMustafa Ismail struct irdma_qp_mr {
64b48c24c2SMustafa Ismail 	struct irdma_hmc_pble sq_pbl;
65b48c24c2SMustafa Ismail 	struct irdma_hmc_pble rq_pbl;
66b48c24c2SMustafa Ismail 	dma_addr_t shadow;
67b48c24c2SMustafa Ismail 	struct page *sq_page;
68b48c24c2SMustafa Ismail };
69b48c24c2SMustafa Ismail 
70b48c24c2SMustafa Ismail struct irdma_cq_buf {
71b48c24c2SMustafa Ismail 	struct irdma_dma_mem kmem_buf;
72b48c24c2SMustafa Ismail 	struct irdma_cq_uk cq_uk;
73b48c24c2SMustafa Ismail 	struct irdma_hw *hw;
74b48c24c2SMustafa Ismail 	struct list_head list;
75b48c24c2SMustafa Ismail 	struct work_struct work;
76b48c24c2SMustafa Ismail };
77b48c24c2SMustafa Ismail 
78b48c24c2SMustafa Ismail struct irdma_pbl {
79b48c24c2SMustafa Ismail 	struct list_head list;
80b48c24c2SMustafa Ismail 	union {
81b48c24c2SMustafa Ismail 		struct irdma_qp_mr qp_mr;
82b48c24c2SMustafa Ismail 		struct irdma_cq_mr cq_mr;
83b48c24c2SMustafa Ismail 	};
84b48c24c2SMustafa Ismail 
85b48c24c2SMustafa Ismail 	bool pbl_allocated:1;
86b48c24c2SMustafa Ismail 	bool on_list:1;
87b48c24c2SMustafa Ismail 	u64 user_base;
88b48c24c2SMustafa Ismail 	struct irdma_pble_alloc pble_alloc;
89b48c24c2SMustafa Ismail 	struct irdma_mr *iwmr;
90b48c24c2SMustafa Ismail };
91b48c24c2SMustafa Ismail 
92b48c24c2SMustafa Ismail struct irdma_mr {
93b48c24c2SMustafa Ismail 	union {
94b48c24c2SMustafa Ismail 		struct ib_mr ibmr;
95b48c24c2SMustafa Ismail 		struct ib_mw ibmw;
96b48c24c2SMustafa Ismail 	};
97b48c24c2SMustafa Ismail 	struct ib_umem *region;
98b48c24c2SMustafa Ismail 	u16 type;
99b48c24c2SMustafa Ismail 	u32 page_cnt;
100b48c24c2SMustafa Ismail 	u64 page_size;
101b48c24c2SMustafa Ismail 	u32 npages;
102b48c24c2SMustafa Ismail 	u32 stag;
103b48c24c2SMustafa Ismail 	u64 len;
104b48c24c2SMustafa Ismail 	u64 pgaddrmem[IRDMA_MAX_SAVED_PHY_PGADDR];
105b48c24c2SMustafa Ismail 	struct irdma_pbl iwpbl;
106b48c24c2SMustafa Ismail };
107b48c24c2SMustafa Ismail 
108b48c24c2SMustafa Ismail struct irdma_cq {
109b48c24c2SMustafa Ismail 	struct ib_cq ibcq;
110b48c24c2SMustafa Ismail 	struct irdma_sc_cq sc_cq;
111b48c24c2SMustafa Ismail 	u16 cq_head;
112b48c24c2SMustafa Ismail 	u16 cq_size;
113b48c24c2SMustafa Ismail 	u16 cq_num;
114b48c24c2SMustafa Ismail 	bool user_mode;
11510467ce0STatyana Nikolova 	bool armed;
11610467ce0STatyana Nikolova 	enum irdma_cmpl_notify last_notify;
117b48c24c2SMustafa Ismail 	u32 polled_cmpls;
118b48c24c2SMustafa Ismail 	u32 cq_mem_size;
119b48c24c2SMustafa Ismail 	struct irdma_dma_mem kmem;
120b48c24c2SMustafa Ismail 	struct irdma_dma_mem kmem_shadow;
121b48c24c2SMustafa Ismail 	spinlock_t lock; /* for poll cq */
122b48c24c2SMustafa Ismail 	struct irdma_pbl *iwpbl;
123b48c24c2SMustafa Ismail 	struct irdma_pbl *iwpbl_shadow;
124b48c24c2SMustafa Ismail 	struct list_head resize_list;
125b48c24c2SMustafa Ismail 	struct irdma_cq_poll_info cur_cqe;
126b48c24c2SMustafa Ismail };
127b48c24c2SMustafa Ismail 
128b48c24c2SMustafa Ismail struct disconn_work {
129b48c24c2SMustafa Ismail 	struct work_struct work;
130b48c24c2SMustafa Ismail 	struct irdma_qp *iwqp;
131b48c24c2SMustafa Ismail };
132b48c24c2SMustafa Ismail 
133b48c24c2SMustafa Ismail struct iw_cm_id;
134b48c24c2SMustafa Ismail 
135b48c24c2SMustafa Ismail struct irdma_qp_kmode {
136b48c24c2SMustafa Ismail 	struct irdma_dma_mem dma_mem;
137b48c24c2SMustafa Ismail 	struct irdma_sq_uk_wr_trk_info *sq_wrid_mem;
138b48c24c2SMustafa Ismail 	u64 *rq_wrid_mem;
139b48c24c2SMustafa Ismail };
140b48c24c2SMustafa Ismail 
141b48c24c2SMustafa Ismail struct irdma_qp {
142b48c24c2SMustafa Ismail 	struct ib_qp ibqp;
143b48c24c2SMustafa Ismail 	struct irdma_sc_qp sc_qp;
144b48c24c2SMustafa Ismail 	struct irdma_device *iwdev;
145b48c24c2SMustafa Ismail 	struct irdma_cq *iwscq;
146b48c24c2SMustafa Ismail 	struct irdma_cq *iwrcq;
147b48c24c2SMustafa Ismail 	struct irdma_pd *iwpd;
148b48c24c2SMustafa Ismail 	struct rdma_user_mmap_entry *push_wqe_mmap_entry;
149b48c24c2SMustafa Ismail 	struct rdma_user_mmap_entry *push_db_mmap_entry;
150b48c24c2SMustafa Ismail 	struct irdma_qp_host_ctx_info ctx_info;
151b48c24c2SMustafa Ismail 	union {
152b48c24c2SMustafa Ismail 		struct irdma_iwarp_offload_info iwarp_info;
153b48c24c2SMustafa Ismail 		struct irdma_roce_offload_info roce_info;
154b48c24c2SMustafa Ismail 	};
155b48c24c2SMustafa Ismail 
156b48c24c2SMustafa Ismail 	union {
157b48c24c2SMustafa Ismail 		struct irdma_tcp_offload_info tcp_info;
158b48c24c2SMustafa Ismail 		struct irdma_udp_offload_info udp_info;
159b48c24c2SMustafa Ismail 	};
160b48c24c2SMustafa Ismail 
161b48c24c2SMustafa Ismail 	struct irdma_ah roce_ah;
162b48c24c2SMustafa Ismail 	struct list_head teardown_entry;
163b48c24c2SMustafa Ismail 	refcount_t refcnt;
164b48c24c2SMustafa Ismail 	struct iw_cm_id *cm_id;
165b48c24c2SMustafa Ismail 	struct irdma_cm_node *cm_node;
166b48c24c2SMustafa Ismail 	struct ib_mr *lsmm_mr;
167b48c24c2SMustafa Ismail 	atomic_t hw_mod_qp_pend;
168b48c24c2SMustafa Ismail 	enum ib_qp_state ibqp_state;
169b48c24c2SMustafa Ismail 	u32 qp_mem_size;
170b48c24c2SMustafa Ismail 	u32 last_aeq;
171b48c24c2SMustafa Ismail 	int max_send_wr;
172b48c24c2SMustafa Ismail 	int max_recv_wr;
173b48c24c2SMustafa Ismail 	atomic_t close_timer_started;
174b48c24c2SMustafa Ismail 	spinlock_t lock; /* serialize posting WRs to SQ/RQ */
175b48c24c2SMustafa Ismail 	struct irdma_qp_context *iwqp_context;
176b48c24c2SMustafa Ismail 	void *pbl_vbase;
177b48c24c2SMustafa Ismail 	dma_addr_t pbl_pbase;
178b48c24c2SMustafa Ismail 	struct page *page;
179b48c24c2SMustafa Ismail 	u8 active_conn : 1;
180b48c24c2SMustafa Ismail 	u8 user_mode : 1;
181b48c24c2SMustafa Ismail 	u8 hte_added : 1;
182b48c24c2SMustafa Ismail 	u8 flush_issued : 1;
183b48c24c2SMustafa Ismail 	u8 sig_all : 1;
184b48c24c2SMustafa Ismail 	u8 pau_mode : 1;
185b48c24c2SMustafa Ismail 	u8 rsvd : 1;
186b48c24c2SMustafa Ismail 	u8 iwarp_state;
187b48c24c2SMustafa Ismail 	u16 term_sq_flush_code;
188b48c24c2SMustafa Ismail 	u16 term_rq_flush_code;
189b48c24c2SMustafa Ismail 	u8 hw_iwarp_state;
190b48c24c2SMustafa Ismail 	u8 hw_tcp_state;
191b48c24c2SMustafa Ismail 	struct irdma_qp_kmode kqp;
192b48c24c2SMustafa Ismail 	struct irdma_dma_mem host_ctx;
193b48c24c2SMustafa Ismail 	struct timer_list terminate_timer;
194b48c24c2SMustafa Ismail 	struct irdma_pbl *iwpbl;
195b48c24c2SMustafa Ismail 	struct irdma_dma_mem q2_ctx_mem;
196b48c24c2SMustafa Ismail 	struct irdma_dma_mem ietf_mem;
197b48c24c2SMustafa Ismail 	struct completion free_qp;
198b48c24c2SMustafa Ismail 	wait_queue_head_t waitq;
199b48c24c2SMustafa Ismail 	wait_queue_head_t mod_qp_waitq;
200b48c24c2SMustafa Ismail 	u8 rts_ae_rcvd;
201b48c24c2SMustafa Ismail };
202b48c24c2SMustafa Ismail 
203b48c24c2SMustafa Ismail enum irdma_mmap_flag {
204b48c24c2SMustafa Ismail 	IRDMA_MMAP_IO_NC,
205b48c24c2SMustafa Ismail 	IRDMA_MMAP_IO_WC,
206b48c24c2SMustafa Ismail };
207b48c24c2SMustafa Ismail 
208b48c24c2SMustafa Ismail struct irdma_user_mmap_entry {
209b48c24c2SMustafa Ismail 	struct rdma_user_mmap_entry rdma_entry;
210b48c24c2SMustafa Ismail 	u64 bar_offset;
211b48c24c2SMustafa Ismail 	u8 mmap_flag;
212b48c24c2SMustafa Ismail };
213b48c24c2SMustafa Ismail 
214b48c24c2SMustafa Ismail static inline u16 irdma_fw_major_ver(struct irdma_sc_dev *dev)
215b48c24c2SMustafa Ismail {
216b48c24c2SMustafa Ismail 	return (u16)FIELD_GET(IRDMA_FW_VER_MAJOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]);
217b48c24c2SMustafa Ismail }
218b48c24c2SMustafa Ismail 
219b48c24c2SMustafa Ismail static inline u16 irdma_fw_minor_ver(struct irdma_sc_dev *dev)
220b48c24c2SMustafa Ismail {
221b48c24c2SMustafa Ismail 	return (u16)FIELD_GET(IRDMA_FW_VER_MINOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]);
222b48c24c2SMustafa Ismail }
223b48c24c2SMustafa Ismail 
224b48c24c2SMustafa Ismail void irdma_mcast_mac(u32 *ip_addr, u8 *mac, bool ipv4);
225b48c24c2SMustafa Ismail int irdma_ib_register_device(struct irdma_device *iwdev);
226b48c24c2SMustafa Ismail void irdma_ib_unregister_device(struct irdma_device *iwdev);
227b48c24c2SMustafa Ismail void irdma_ib_dealloc_device(struct ib_device *ibdev);
228b48c24c2SMustafa Ismail void irdma_ib_qp_event(struct irdma_qp *iwqp, enum irdma_qp_event_type event);
229b48c24c2SMustafa Ismail #endif /* IRDMA_VERBS_H */
230