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