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