xref: /freebsd/sys/dev/qlnx/qlnxr/qlnxr_cm.h (revision 2f513db7)
1 /*
2  * Copyright (c) 2018-2019 Cavium, Inc.
3  * All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 
31 
32 #ifndef __QLNXR_CM_H__
33 #define __QLNXR_CM_H__
34 
35 
36 /* ECORE LL2 has a limit to the number of buffers it can handle.
37  * FYI, OFED used 512 and 128 for recv and send.
38  */
39 #define QLNXR_GSI_MAX_RECV_WR	(4096)
40 #define QLNXR_GSI_MAX_SEND_WR	(4096)
41 
42 #define QLNXR_GSI_MAX_RECV_SGE	(1)	/* LL2 FW limitation */
43 
44 /* future OFED/kernel will have these */
45 #define ETH_P_ROCE		(0x8915)
46 #define QLNXR_ROCE_V2_UDP_SPORT	(0000)
47 
48 #if __FreeBSD_version >= 1102000
49 
50 #define rdma_wr(_wr) rdma_wr(_wr)
51 #define ud_wr(_wr) ud_wr(_wr)
52 #define atomic_wr(_wr) atomic_wr(_wr)
53 
54 #else
55 
56 #define rdma_wr(_wr) (&(_wr->wr.rdma))
57 #define ud_wr(_wr) (&(_wr->wr.ud))
58 #define atomic_wr(_wr) (&(_wr->wr.atomic))
59 
60 #endif /* #if __FreeBSD_version >= 1102000 */
61 
62 static inline u32 qlnxr_get_ipv4_from_gid(u8 *gid)
63 {
64 	return *(u32 *)(void *)&gid[12];
65 }
66 
67 struct ecore_roce_ll2_header {
68         void *vaddr;
69         dma_addr_t baddr;
70         size_t len;
71 };
72 
73 struct ecore_roce_ll2_buffer {
74         dma_addr_t baddr;
75         size_t len;
76 };
77 
78 struct ecore_roce_ll2_packet {
79         struct ecore_roce_ll2_header header;
80         int n_seg;
81         struct ecore_roce_ll2_buffer payload[RDMA_MAX_SGE_PER_SQ_WQE];
82         int roce_mode;
83         enum ecore_roce_ll2_tx_dest tx_dest;
84 };
85 
86 /* RDMA CM */
87 
88 extern int qlnxr_gsi_poll_cq(struct ib_cq *ibcq,
89 			int num_entries,
90 			struct ib_wc *wc);
91 
92 extern int qlnxr_gsi_post_recv(struct ib_qp *ibqp,
93 			struct ib_recv_wr *wr,
94 			struct ib_recv_wr **bad_wr);
95 
96 extern int qlnxr_gsi_post_send(struct ib_qp *ibqp,
97 			struct ib_send_wr *wr,
98 			struct ib_send_wr **bad_wr);
99 
100 extern struct ib_qp* qlnxr_create_gsi_qp(struct qlnxr_dev *dev,
101 			struct ib_qp_init_attr *attrs,
102 			struct qlnxr_qp *qp);
103 
104 extern void qlnxr_store_gsi_qp_cq(struct qlnxr_dev *dev,
105 			struct qlnxr_qp *qp,
106 			struct ib_qp_init_attr *attrs);
107 
108 extern void qlnxr_inc_sw_gsi_cons(struct qlnxr_qp_hwq_info *info);
109 
110 extern int qlnxr_destroy_gsi_qp(struct qlnxr_dev *dev);
111 
112 #endif /* #ifndef __QLNXR_CM_H__ */
113