xref: /openbmc/linux/drivers/infiniband/hw/bnxt_re/ib_verbs.h (revision aad29a73199b7fbccfbabea3f1ee627ad1924f52)
11ac5a404SSelvin Xavier /*
21ac5a404SSelvin Xavier  * Broadcom NetXtreme-E RoCE driver.
31ac5a404SSelvin Xavier  *
41ac5a404SSelvin Xavier  * Copyright (c) 2016 - 2017, Broadcom. All rights reserved.  The term
51ac5a404SSelvin Xavier  * Broadcom refers to Broadcom Limited and/or its subsidiaries.
61ac5a404SSelvin Xavier  *
71ac5a404SSelvin Xavier  * This software is available to you under a choice of one of two
81ac5a404SSelvin Xavier  * licenses.  You may choose to be licensed under the terms of the GNU
91ac5a404SSelvin Xavier  * General Public License (GPL) Version 2, available from the file
101ac5a404SSelvin Xavier  * COPYING in the main directory of this source tree, or the
111ac5a404SSelvin Xavier  * BSD license below:
121ac5a404SSelvin Xavier  *
131ac5a404SSelvin Xavier  * Redistribution and use in source and binary forms, with or without
141ac5a404SSelvin Xavier  * modification, are permitted provided that the following conditions
151ac5a404SSelvin Xavier  * are met:
161ac5a404SSelvin Xavier  *
171ac5a404SSelvin Xavier  * 1. Redistributions of source code must retain the above copyright
181ac5a404SSelvin Xavier  *    notice, this list of conditions and the following disclaimer.
191ac5a404SSelvin Xavier  * 2. Redistributions in binary form must reproduce the above copyright
201ac5a404SSelvin Xavier  *    notice, this list of conditions and the following disclaimer in
211ac5a404SSelvin Xavier  *    the documentation and/or other materials provided with the
221ac5a404SSelvin Xavier  *    distribution.
231ac5a404SSelvin Xavier  *
241ac5a404SSelvin Xavier  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
251ac5a404SSelvin Xavier  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
261ac5a404SSelvin Xavier  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
271ac5a404SSelvin Xavier  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
281ac5a404SSelvin Xavier  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
291ac5a404SSelvin Xavier  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
301ac5a404SSelvin Xavier  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
311ac5a404SSelvin Xavier  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
321ac5a404SSelvin Xavier  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
331ac5a404SSelvin Xavier  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
341ac5a404SSelvin Xavier  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
351ac5a404SSelvin Xavier  *
361ac5a404SSelvin Xavier  * Description: IB Verbs interpreter (header)
371ac5a404SSelvin Xavier  */
381ac5a404SSelvin Xavier 
391ac5a404SSelvin Xavier #ifndef __BNXT_RE_IB_VERBS_H__
401ac5a404SSelvin Xavier #define __BNXT_RE_IB_VERBS_H__
411ac5a404SSelvin Xavier 
421ac5a404SSelvin Xavier struct bnxt_re_gid_ctx {
431ac5a404SSelvin Xavier 	u32			idx;
441ac5a404SSelvin Xavier 	u32			refcnt;
451ac5a404SSelvin Xavier };
461ac5a404SSelvin Xavier 
479152e0b7SEddie Wai #define BNXT_RE_FENCE_BYTES	64
489152e0b7SEddie Wai struct bnxt_re_fence_data {
499152e0b7SEddie Wai 	u32 size;
509152e0b7SEddie Wai 	u8 va[BNXT_RE_FENCE_BYTES];
519152e0b7SEddie Wai 	dma_addr_t dma_addr;
529152e0b7SEddie Wai 	struct bnxt_re_mr *mr;
539152e0b7SEddie Wai 	struct ib_mw *mw;
549152e0b7SEddie Wai 	struct bnxt_qplib_swqe bind_wqe;
559152e0b7SEddie Wai 	u32 bind_rkey;
569152e0b7SEddie Wai };
579152e0b7SEddie Wai 
581ac5a404SSelvin Xavier struct bnxt_re_pd {
591ac5a404SSelvin Xavier 	struct ib_pd            ib_pd;
6021a428a0SLeon Romanovsky 	struct bnxt_re_dev	*rdev;
611ac5a404SSelvin Xavier 	struct bnxt_qplib_pd	qplib_pd;
629152e0b7SEddie Wai 	struct bnxt_re_fence_data fence;
6324ce9478SSelvin Xavier 	struct rdma_user_mmap_entry *pd_db_mmap;
64360da60dSSelvin Xavier 	struct rdma_user_mmap_entry *pd_wcdb_mmap;
651ac5a404SSelvin Xavier };
661ac5a404SSelvin Xavier 
671ac5a404SSelvin Xavier struct bnxt_re_ah {
681ac5a404SSelvin Xavier 	struct ib_ah		ib_ah;
69d3456914SLeon Romanovsky 	struct bnxt_re_dev	*rdev;
701ac5a404SSelvin Xavier 	struct bnxt_qplib_ah	qplib_ah;
711ac5a404SSelvin Xavier };
721ac5a404SSelvin Xavier 
7337cb11acSDevesh Sharma struct bnxt_re_srq {
7468e326deSLeon Romanovsky 	struct ib_srq		ib_srq;
7537cb11acSDevesh Sharma 	struct bnxt_re_dev	*rdev;
7637cb11acSDevesh Sharma 	u32			srq_limit;
7737cb11acSDevesh Sharma 	struct bnxt_qplib_srq	qplib_srq;
7837cb11acSDevesh Sharma 	struct ib_umem		*umem;
7937cb11acSDevesh Sharma 	spinlock_t		lock;		/* protect srq */
8037cb11acSDevesh Sharma };
8137cb11acSDevesh Sharma 
821ac5a404SSelvin Xavier struct bnxt_re_qp {
83514aee66SLeon Romanovsky 	struct ib_qp		ib_qp;
841ac5a404SSelvin Xavier 	struct list_head	list;
851ac5a404SSelvin Xavier 	struct bnxt_re_dev	*rdev;
861ac5a404SSelvin Xavier 	spinlock_t		sq_lock;	/* protect sq */
87018cf599SDevesh Sharma 	spinlock_t		rq_lock;	/* protect rq */
881ac5a404SSelvin Xavier 	struct bnxt_qplib_qp	qplib_qp;
891ac5a404SSelvin Xavier 	struct ib_umem		*sumem;
901ac5a404SSelvin Xavier 	struct ib_umem		*rumem;
911ac5a404SSelvin Xavier 	/* QP1 */
921ac5a404SSelvin Xavier 	u32			send_psn;
931ac5a404SSelvin Xavier 	struct ib_ud_header	qp1_hdr;
943b921e3bSSelvin Xavier 	struct bnxt_re_cq	*scq;
953b921e3bSSelvin Xavier 	struct bnxt_re_cq	*rcq;
961ac5a404SSelvin Xavier };
971ac5a404SSelvin Xavier 
981ac5a404SSelvin Xavier struct bnxt_re_cq {
99e39afe3dSLeon Romanovsky 	struct ib_cq		ib_cq;
1001ac5a404SSelvin Xavier 	struct bnxt_re_dev	*rdev;
1011ac5a404SSelvin Xavier 	spinlock_t              cq_lock;	/* protect cq */
1021ac5a404SSelvin Xavier 	u16			cq_count;
1031ac5a404SSelvin Xavier 	u16			cq_period;
1041ac5a404SSelvin Xavier 	struct bnxt_qplib_cq	qplib_cq;
1051ac5a404SSelvin Xavier 	struct bnxt_qplib_cqe	*cql;
1061ac5a404SSelvin Xavier #define MAX_CQL_PER_POLL	1024
1071ac5a404SSelvin Xavier 	u32			max_cql;
1081ac5a404SSelvin Xavier 	struct ib_umem		*umem;
109d54bd5abSSelvin Xavier 	struct ib_umem		*resize_umem;
110d54bd5abSSelvin Xavier 	int			resize_cqe;
1111ac5a404SSelvin Xavier };
1121ac5a404SSelvin Xavier 
1131ac5a404SSelvin Xavier struct bnxt_re_mr {
1141ac5a404SSelvin Xavier 	struct bnxt_re_dev	*rdev;
1151ac5a404SSelvin Xavier 	struct ib_mr		ib_mr;
1161ac5a404SSelvin Xavier 	struct ib_umem		*ib_umem;
1171ac5a404SSelvin Xavier 	struct bnxt_qplib_mrw	qplib_mr;
1181ac5a404SSelvin Xavier 	u32			npages;
1191ac5a404SSelvin Xavier 	u64			*pages;
1201ac5a404SSelvin Xavier 	struct bnxt_qplib_frpl	qplib_frpl;
1211ac5a404SSelvin Xavier };
1221ac5a404SSelvin Xavier 
1231ac5a404SSelvin Xavier struct bnxt_re_frpl {
1241ac5a404SSelvin Xavier 	struct bnxt_re_dev		*rdev;
1251ac5a404SSelvin Xavier 	struct bnxt_qplib_frpl		qplib_frpl;
1261ac5a404SSelvin Xavier 	u64				*page_list;
1271ac5a404SSelvin Xavier };
1281ac5a404SSelvin Xavier 
1291ac5a404SSelvin Xavier struct bnxt_re_mw {
1301ac5a404SSelvin Xavier 	struct bnxt_re_dev	*rdev;
1311ac5a404SSelvin Xavier 	struct ib_mw		ib_mw;
1321ac5a404SSelvin Xavier 	struct bnxt_qplib_mrw	qplib_mw;
1331ac5a404SSelvin Xavier };
1341ac5a404SSelvin Xavier 
1351ac5a404SSelvin Xavier struct bnxt_re_ucontext {
1361ac5a404SSelvin Xavier 	struct ib_ucontext      ib_uctx;
137a2a074efSLeon Romanovsky 	struct bnxt_re_dev	*rdev;
138b3b2c7c5SDevesh Sharma 	struct bnxt_qplib_dpi	dpi;
139360da60dSSelvin Xavier 	struct bnxt_qplib_dpi   wcdpi;
1401ac5a404SSelvin Xavier 	void			*shpg;
1411ac5a404SSelvin Xavier 	spinlock_t		sh_lock;	/* protect shpg */
14224ce9478SSelvin Xavier 	struct rdma_user_mmap_entry *shpage_mmap;
143e300b1b9SChandramohan Akula 	u64 cmask;
14424ce9478SSelvin Xavier };
14524ce9478SSelvin Xavier 
14624ce9478SSelvin Xavier enum bnxt_re_mmap_flag {
14724ce9478SSelvin Xavier 	BNXT_RE_MMAP_SH_PAGE,
14824ce9478SSelvin Xavier 	BNXT_RE_MMAP_UC_DB,
149360da60dSSelvin Xavier 	BNXT_RE_MMAP_WC_DB,
150ea222485SChandramohan Akula 	BNXT_RE_MMAP_DBR_PAGE,
151ea222485SChandramohan Akula 	BNXT_RE_MMAP_DBR_BAR,
15224ce9478SSelvin Xavier };
15324ce9478SSelvin Xavier 
15424ce9478SSelvin Xavier struct bnxt_re_user_mmap_entry {
15524ce9478SSelvin Xavier 	struct rdma_user_mmap_entry rdma_entry;
156360da60dSSelvin Xavier 	struct bnxt_re_ucontext *uctx;
15724ce9478SSelvin Xavier 	u64 mem_offset;
15824ce9478SSelvin Xavier 	u8 mmap_flag;
1591ac5a404SSelvin Xavier };
1601ac5a404SSelvin Xavier 
bnxt_re_get_swqe_size(int nsge)1612bb3c32cSDevesh Sharma static inline u16 bnxt_re_get_swqe_size(int nsge)
162fddcbbb0SDevesh Sharma {
1632bb3c32cSDevesh Sharma 	return sizeof(struct sq_send_hdr) + nsge * sizeof(struct sq_sge);
164fddcbbb0SDevesh Sharma }
165fddcbbb0SDevesh Sharma 
bnxt_re_get_rwqe_size(int nsge)1662bb3c32cSDevesh Sharma static inline u16 bnxt_re_get_rwqe_size(int nsge)
167fddcbbb0SDevesh Sharma {
1682bb3c32cSDevesh Sharma 	return sizeof(struct rq_wqe_hdr) + (nsge * sizeof(struct sq_sge));
169fddcbbb0SDevesh Sharma }
170fddcbbb0SDevesh Sharma 
bnxt_re_init_depth(u32 ent,struct bnxt_re_ucontext * uctx)171e300b1b9SChandramohan Akula static inline u32 bnxt_re_init_depth(u32 ent, struct bnxt_re_ucontext *uctx)
172e300b1b9SChandramohan Akula {
173e300b1b9SChandramohan Akula 	return uctx ? (uctx->cmask & BNXT_RE_UCNTX_CMASK_POW2_DISABLED) ?
174e300b1b9SChandramohan Akula 		ent : roundup_pow_of_two(ent) : ent;
175e300b1b9SChandramohan Akula }
176e300b1b9SChandramohan Akula 
1771ac5a404SSelvin Xavier int bnxt_re_query_device(struct ib_device *ibdev,
1781ac5a404SSelvin Xavier 			 struct ib_device_attr *ib_attr,
1791ac5a404SSelvin Xavier 			 struct ib_udata *udata);
1801fb7f897SMark Bloch int bnxt_re_query_port(struct ib_device *ibdev, u32 port_num,
1811ac5a404SSelvin Xavier 		       struct ib_port_attr *port_attr);
1821fb7f897SMark Bloch int bnxt_re_get_port_immutable(struct ib_device *ibdev, u32 port_num,
1831ac5a404SSelvin Xavier 			       struct ib_port_immutable *immutable);
1842fc68543SSelvin Xavier void bnxt_re_query_fw_str(struct ib_device *ibdev, char *str);
1851fb7f897SMark Bloch int bnxt_re_query_pkey(struct ib_device *ibdev, u32 port_num,
1861ac5a404SSelvin Xavier 		       u16 index, u16 *pkey);
187414448d2SParav Pandit int bnxt_re_del_gid(const struct ib_gid_attr *attr, void **context);
188f4df9a7cSParav Pandit int bnxt_re_add_gid(const struct ib_gid_attr *attr, void **context);
1891fb7f897SMark Bloch int bnxt_re_query_gid(struct ib_device *ibdev, u32 port_num,
1901ac5a404SSelvin Xavier 		      int index, union ib_gid *gid);
1911ac5a404SSelvin Xavier enum rdma_link_layer bnxt_re_get_link_layer(struct ib_device *ibdev,
1921fb7f897SMark Bloch 					    u32 port_num);
193ff23dfa1SShamir Rabinovitch int bnxt_re_alloc_pd(struct ib_pd *pd, struct ib_udata *udata);
19491a7c58fSLeon Romanovsky int bnxt_re_dealloc_pd(struct ib_pd *pd, struct ib_udata *udata);
195fa5d010cSMaor Gottlieb int bnxt_re_create_ah(struct ib_ah *ah, struct rdma_ah_init_attr *init_attr,
1961ac5a404SSelvin Xavier 		      struct ib_udata *udata);
19790898850SDasaratharaman Chandramouli int bnxt_re_query_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
1989a9ebf8cSLeon Romanovsky int bnxt_re_destroy_ah(struct ib_ah *ah, u32 flags);
19968e326deSLeon Romanovsky int bnxt_re_create_srq(struct ib_srq *srq,
20037cb11acSDevesh Sharma 		       struct ib_srq_init_attr *srq_init_attr,
20137cb11acSDevesh Sharma 		       struct ib_udata *udata);
20237cb11acSDevesh Sharma int bnxt_re_modify_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr,
20337cb11acSDevesh Sharma 		       enum ib_srq_attr_mask srq_attr_mask,
20437cb11acSDevesh Sharma 		       struct ib_udata *udata);
20537cb11acSDevesh Sharma int bnxt_re_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
206119181d1SLeon Romanovsky int bnxt_re_destroy_srq(struct ib_srq *srq, struct ib_udata *udata);
207d34ac5cdSBart Van Assche int bnxt_re_post_srq_recv(struct ib_srq *srq, const struct ib_recv_wr *recv_wr,
208d34ac5cdSBart Van Assche 			  const struct ib_recv_wr **bad_recv_wr);
209514aee66SLeon Romanovsky int bnxt_re_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *qp_init_attr,
2101ac5a404SSelvin Xavier 		      struct ib_udata *udata);
2111ac5a404SSelvin Xavier int bnxt_re_modify_qp(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
2121ac5a404SSelvin Xavier 		      int qp_attr_mask, struct ib_udata *udata);
2131ac5a404SSelvin Xavier int bnxt_re_query_qp(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
2141ac5a404SSelvin Xavier 		     int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr);
215c4367a26SShamir Rabinovitch int bnxt_re_destroy_qp(struct ib_qp *qp, struct ib_udata *udata);
216d34ac5cdSBart Van Assche int bnxt_re_post_send(struct ib_qp *qp, const struct ib_send_wr *send_wr,
217d34ac5cdSBart Van Assche 		      const struct ib_send_wr **bad_send_wr);
218d34ac5cdSBart Van Assche int bnxt_re_post_recv(struct ib_qp *qp, const struct ib_recv_wr *recv_wr,
219d34ac5cdSBart Van Assche 		      const struct ib_recv_wr **bad_recv_wr);
220e39afe3dSLeon Romanovsky int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
2211ac5a404SSelvin Xavier 		      struct ib_udata *udata);
222d54bd5abSSelvin Xavier int bnxt_re_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata);
22343d781b9SLeon Romanovsky int bnxt_re_destroy_cq(struct ib_cq *cq, struct ib_udata *udata);
2241ac5a404SSelvin Xavier int bnxt_re_poll_cq(struct ib_cq *cq, int num_entries, struct ib_wc *wc);
2251ac5a404SSelvin Xavier int bnxt_re_req_notify_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);
2261ac5a404SSelvin Xavier struct ib_mr *bnxt_re_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
2271ac5a404SSelvin Xavier 
2281ac5a404SSelvin Xavier int bnxt_re_map_mr_sg(struct ib_mr *ib_mr, struct scatterlist *sg, int sg_nents,
2291ac5a404SSelvin Xavier 		      unsigned int *sg_offset);
2301ac5a404SSelvin Xavier struct ib_mr *bnxt_re_alloc_mr(struct ib_pd *ib_pd, enum ib_mr_type mr_type,
23142a3b153SGal Pressman 			       u32 max_num_sg);
232c4367a26SShamir Rabinovitch int bnxt_re_dereg_mr(struct ib_mr *mr, struct ib_udata *udata);
2339152e0b7SEddie Wai struct ib_mw *bnxt_re_alloc_mw(struct ib_pd *ib_pd, enum ib_mw_type type,
2349152e0b7SEddie Wai 			       struct ib_udata *udata);
2359152e0b7SEddie Wai int bnxt_re_dealloc_mw(struct ib_mw *mw);
2361ac5a404SSelvin Xavier struct ib_mr *bnxt_re_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
2371ac5a404SSelvin Xavier 				  u64 virt_addr, int mr_access_flags,
2381ac5a404SSelvin Xavier 				  struct ib_udata *udata);
2390a30e59fSSaravanan Vajravel struct ib_mr *bnxt_re_reg_user_mr_dmabuf(struct ib_pd *ib_pd, u64 start,
2400a30e59fSSaravanan Vajravel 					 u64 length, u64 virt_addr,
2410a30e59fSSaravanan Vajravel 					 int fd, int mr_access_flags,
2420a30e59fSSaravanan Vajravel 					 struct ib_udata *udata);
243a2a074efSLeon Romanovsky int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata);
244a2a074efSLeon Romanovsky void bnxt_re_dealloc_ucontext(struct ib_ucontext *context);
2451ac5a404SSelvin Xavier int bnxt_re_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
24624ce9478SSelvin Xavier void bnxt_re_mmap_free(struct rdma_user_mmap_entry *rdma_entry);
24724ce9478SSelvin Xavier 
__to_ib_port_num(u16 port_id)248*8c9c1a2bSHongguang Gao static inline u32 __to_ib_port_num(u16 port_id)
249*8c9c1a2bSHongguang Gao {
250*8c9c1a2bSHongguang Gao 	return (u32)port_id + 1;
251*8c9c1a2bSHongguang Gao }
252942c9b6cSSelvin Xavier 
253942c9b6cSSelvin Xavier unsigned long bnxt_re_lock_cqs(struct bnxt_re_qp *qp);
254942c9b6cSSelvin Xavier void bnxt_re_unlock_cqs(struct bnxt_re_qp *qp, unsigned long flags);
2551ac5a404SSelvin Xavier #endif /* __BNXT_RE_IB_VERBS_H__ */
256