xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_ll2_api.h (revision 38069501)
1 /*
2  * Copyright (c) 2017-2018 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 #ifndef __ECORE_LL2_API_H__
32 #define __ECORE_LL2_API_H__
33 
34 /* ECORE LL2 API: called by ECORE's upper level client  */
35 /* must be the asme as core_rx_conn_type */
36 
37 enum ecore_ll2_conn_type {
38 	ECORE_LL2_TYPE_FCOE /* FCoE L2 connection */,
39 	ECORE_LL2_TYPE_ISCSI /* Iscsi L2 connection */,
40 	ECORE_LL2_TYPE_TEST /* Eth TB test connection */,
41 	ECORE_LL2_TYPE_OOO /* Iscsi OOO L2 connection */,
42 	ECORE_LL2_TYPE_TOE /* toe L2 connection */,
43 	ECORE_LL2_TYPE_ROCE /* RoCE L2 connection */,
44 	ECORE_LL2_TYPE_IWARP,
45 	MAX_ECORE_LL2_RX_CONN_TYPE
46 };
47 
48 enum ecore_ll2_roce_flavor_type {
49 	ECORE_LL2_ROCE,		/* use this as default or d/c */
50 	ECORE_LL2_RROCE,
51 	MAX_ECORE_LL2_ROCE_FLAVOR_TYPE
52 };
53 
54 enum ecore_ll2_tx_dest
55 {
56 	ECORE_LL2_TX_DEST_NW /* Light L2 TX Destination to the Network */,
57 	ECORE_LL2_TX_DEST_LB /* Light L2 TX Destination to the Loopback */,
58 	ECORE_LL2_TX_DEST_DROP /* Light L2 Drop the TX packet */,
59 	ECORE_LL2_TX_DEST_MAX
60 };
61 
62 enum ecore_ll2_error_handle
63 {
64 	ECORE_LL2_DROP_PACKET /* If error occurs drop packet */,
65 	ECORE_LL2_DO_NOTHING /* If error occurs do nothing */,
66 	ECORE_LL2_ASSERT /* If error occurs assert */,
67 };
68 
69 struct ecore_ll2_stats {
70 	u64 gsi_invalid_hdr;
71 	u64 gsi_invalid_pkt_length;
72 	u64 gsi_unsupported_pkt_typ;
73 	u64 gsi_crcchksm_error;
74 
75 	u64 packet_too_big_discard;
76 	u64 no_buff_discard;
77 
78 	u64 rcv_ucast_bytes;
79 	u64 rcv_mcast_bytes;
80 	u64 rcv_bcast_bytes;
81 	u64 rcv_ucast_pkts;
82 	u64 rcv_mcast_pkts;
83 	u64 rcv_bcast_pkts;
84 
85 	u64 sent_ucast_bytes;
86 	u64 sent_mcast_bytes;
87 	u64 sent_bcast_bytes;
88 	u64 sent_ucast_pkts;
89 	u64 sent_mcast_pkts;
90 	u64 sent_bcast_pkts;
91 };
92 
93 struct ecore_ll2_comp_rx_data {
94 	u8 connection_handle;
95 	void *cookie;
96 	dma_addr_t rx_buf_addr;
97 	u16 parse_flags;
98 	u16 err_flags;
99 	u16 vlan;
100 	bool b_last_packet;
101 
102 	union {
103 		u8 placement_offset;
104 		u8 data_length_error;
105 	} u;
106 	union {
107 		u16 packet_length;
108 		u16 data_length;
109 	} length;
110 
111 	u32 opaque_data_0; /* src_mac_addr_hi */
112 	u32 opaque_data_1; /* src_mac_addr_lo */
113 
114 	/* GSI only */
115 	u32 gid_dst[4];
116 	u16 qp_id;
117 };
118 
119 typedef
120 void (*ecore_ll2_complete_rx_packet_cb)(void *cxt,
121 					struct ecore_ll2_comp_rx_data *data);
122 
123 typedef
124 void (*ecore_ll2_release_rx_packet_cb)(void *cxt,
125 				       u8 connection_handle,
126 				       void *cookie,
127 				       dma_addr_t rx_buf_addr,
128 				       bool b_last_packet);
129 
130 typedef
131 void (*ecore_ll2_complete_tx_packet_cb)(void *cxt,
132 					u8 connection_handle,
133 					void *cookie,
134 					dma_addr_t first_frag_addr,
135 					bool b_last_fragment,
136 					bool b_last_packet);
137 
138 typedef
139 void (*ecore_ll2_release_tx_packet_cb)(void *cxt,
140 				       u8 connection_handle,
141 				       void *cookie,
142 				       dma_addr_t first_frag_addr,
143 				       bool b_last_fragment,
144 				       bool b_last_packet);
145 
146 typedef
147 void (*ecore_ll2_slowpath_cb)(void *cxt,
148 			      u8 connection_handle,
149 			      u32 opaque_data_0,
150 			      u32 opaque_data_1);
151 
152 struct ecore_ll2_cbs {
153 	ecore_ll2_complete_rx_packet_cb rx_comp_cb;
154 	ecore_ll2_release_rx_packet_cb rx_release_cb;
155 	ecore_ll2_complete_tx_packet_cb tx_comp_cb;
156 	ecore_ll2_release_tx_packet_cb tx_release_cb;
157 	ecore_ll2_slowpath_cb slowpath_cb;
158 	void *cookie;
159 };
160 
161 struct ecore_ll2_acquire_data_inputs {
162 	enum ecore_ll2_conn_type conn_type;
163 	u16 mtu; /* Maximum bytes that can be placed on a BD*/
164 	u16 rx_num_desc;
165 
166 	/* Relevant only for OOO connection if 0 OOO rx buffers=2*rx_num_desc */
167 	u16 rx_num_ooo_buffers;
168 	u8 rx_drop_ttl0_flg;
169 
170 	/* if set, 802.1q tags will be removed and copied to CQE */
171 	u8 rx_vlan_removal_en;
172 	u16 tx_num_desc;
173 	u8 tx_max_bds_per_packet;
174 	u8 tx_tc;
175 	enum ecore_ll2_tx_dest tx_dest;
176 	enum ecore_ll2_error_handle ai_err_packet_too_big;
177 	enum ecore_ll2_error_handle ai_err_no_buf;
178 	u8 secondary_queue;
179 	u8 gsi_enable;
180 };
181 
182 struct ecore_ll2_acquire_data {
183 	struct ecore_ll2_acquire_data_inputs input;
184 	const struct ecore_ll2_cbs *cbs;
185 
186 	/* Output container for LL2 connection's handle */
187 	u8 *p_connection_handle;
188 };
189 
190 /**
191  * @brief ecore_ll2_acquire_connection - allocate resources,
192  *        starts rx & tx (if relevant) queues pair. Provides
193  *        connecion handler as output parameter.
194  *
195  *
196  * @param p_hwfn
197  * @param data - describes connection parameters
198  * @return enum _ecore_status_t
199  */
200 enum _ecore_status_t
201 ecore_ll2_acquire_connection(void *cxt,
202 			     struct ecore_ll2_acquire_data *data);
203 
204 /**
205  * @brief ecore_ll2_establish_connection - start previously
206  *        allocated LL2 queues pair
207  *
208  * @param p_hwfn
209  * @param p_ptt
210  * @param connection_handle    LL2 connection's handle
211  *                              obtained from
212  *                              ecore_ll2_require_connection
213  *
214  * @return enum _ecore_status_t
215  */
216 enum _ecore_status_t ecore_ll2_establish_connection(void *cxt,
217 						    u8 connection_handle);
218 
219 /**
220  * @brief ecore_ll2_post_rx_buffers - submit buffers to LL2 RxQ.
221  *
222  * @param p_hwfn
223  * @param connection_handle    LL2 connection's handle
224  *                              obtained from
225  *                              ecore_ll2_require_connection
226  * @param addr                  rx (physical address) buffers to
227  *                              submit
228  * @param cookie
229  * @param notify_fw             produce corresponding Rx BD
230  *                              immediately
231  *
232  * @return enum _ecore_status_t
233  */
234 enum _ecore_status_t ecore_ll2_post_rx_buffer(void *cxt,
235 					      u8 connection_handle,
236 					      dma_addr_t addr,
237 					      u16 buf_len,
238 					      void *cookie,
239 					      u8 notify_fw);
240 
241 struct ecore_ll2_tx_pkt_info {
242 	u8 num_of_bds;
243 	u16 vlan;
244 	u8 bd_flags;
245 	u16 l4_hdr_offset_w; /* from start of packet */
246 	enum ecore_ll2_tx_dest tx_dest;
247 	enum ecore_ll2_roce_flavor_type ecore_roce_flavor;
248 	dma_addr_t first_frag;
249 	u16 first_frag_len;
250 	bool enable_ip_cksum;
251 	bool enable_l4_cksum;
252 	bool calc_ip_len;
253 	void *cookie;
254 };
255 
256 /**
257  * @brief ecore_ll2_prepare_tx_packet - request for start Tx BD
258  *        to prepare Tx packet submission to FW.
259  *
260  *
261  * @param p_hwfn
262  * @param pkt - info regarding the tx packet
263  * @param notify_fw - issue doorbell to fw for this packet
264  *
265  * @return enum _ecore_status_t
266  */
267 enum _ecore_status_t ecore_ll2_prepare_tx_packet(
268 		void *cxt,
269 		u8 connection_handle,
270 		struct ecore_ll2_tx_pkt_info *pkt,
271 		bool notify_fw);
272 
273 /**
274  * @brief ecore_ll2_release_connection - releases resources
275  *        allocated for LL2 connection
276  *
277  * @param p_hwfn
278  * @param connection_handle    LL2 connection's handle
279  *                              obtained from
280  *                              ecore_ll2_require_connection
281  */
282 void ecore_ll2_release_connection(void *cxt,
283 				  u8 connection_handle);
284 
285 /**
286  * @brief ecore_ll2_set_fragment_of_tx_packet - provides
287  *        fragments to fill Tx BD of BDs requested by
288  *        ecore_ll2_prepare_tx_packet..
289  *
290  *
291  * @param p_hwfn
292  * @param connection_handle    LL2 connection's handle
293  *                              obtained from
294  *                              ecore_ll2_require_connection
295  * @param addr
296  * @param nbytes
297  *
298  * @return enum _ecore_status_t
299  */
300 enum _ecore_status_t
301 ecore_ll2_set_fragment_of_tx_packet(void *cxt,
302 				    u8 connection_handle,
303 				    dma_addr_t addr,
304 				    u16 nbytes);
305 
306 /**
307  * @brief ecore_ll2_terminate_connection - stops Tx/Rx queues
308  *
309  *
310  * @param p_hwfn
311  * @param connection_handle    LL2 connection's handle
312  *                              obtained from
313  *                              ecore_ll2_require_connection
314  *
315  * @return enum _ecore_status_t
316  */
317 enum _ecore_status_t ecore_ll2_terminate_connection(void *cxt,
318 						    u8 connection_handle);
319 
320 /**
321  * @brief ecore_ll2_get_stats - get LL2 queue's statistics
322  *
323  *
324  * @param p_hwfn
325  * @param connection_handle    LL2 connection's handle
326  *                              obtained from
327  *                              ecore_ll2_require_connection
328  * @param p_stats
329  *
330  * @return enum _ecore_status_t
331  */
332 enum _ecore_status_t ecore_ll2_get_stats(void *cxt,
333 					 u8 connection_handle,
334 					 struct ecore_ll2_stats	*p_stats);
335 
336 #endif
337