1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, v.1,  (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 
22 /*
23 * Copyright 2014-2017 Cavium, Inc.
24 * The contents of this file are subject to the terms of the Common Development
25 * and Distribution License, v.1,  (the "License").
26 
27 * You may not use this file except in compliance with the License.
28 
29 * You can obtain a copy of the License at available
30 * at http://opensource.org/licenses/CDDL-1.0
31 
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
34 */
35 
36 #ifndef __ECORE_LL2_API_H__
37 #define __ECORE_LL2_API_H__
38 
39 /* ECORE LL2 API: called by ECORE's upper level client  */
40 /* must be the asme as core_rx_conn_type */
41 #ifndef __EXTRACT__LINUX__
42 
43 enum ecore_ll2_conn_type {
44 	ECORE_LL2_TYPE_FCOE /* FCoE L2 connection */,
45 	ECORE_LL2_TYPE_ISCSI /* Iscsi L2 connection */,
46 	ECORE_LL2_TYPE_TEST /* Eth TB test connection */,
47 	ECORE_LL2_TYPE_OOO /* Iscsi OOO L2 connection */,
48 	ECORE_LL2_TYPE_TOE /* toe L2 connection */,
49 	ECORE_LL2_TYPE_ROCE /* RoCE L2 connection */,
50 	ECORE_LL2_TYPE_IWARP,
51 	MAX_ECORE_LL2_RX_CONN_TYPE
52 };
53 
54 enum ecore_ll2_roce_flavor_type {
55 	ECORE_LL2_ROCE,		/* use this as default or d/c */
56 	ECORE_LL2_RROCE,
57 	MAX_ECORE_LL2_ROCE_FLAVOR_TYPE
58 };
59 
60 enum ecore_ll2_tx_dest
61 {
62 	ECORE_LL2_TX_DEST_NW /* Light L2 TX Destination to the Network */,
63 	ECORE_LL2_TX_DEST_LB /* Light L2 TX Destination to the Loopback */,
64 	ECORE_LL2_TX_DEST_DROP /* Light L2 Drop the TX packet */,
65 	ECORE_LL2_TX_DEST_MAX
66 };
67 
68 enum ecore_ll2_error_handle
69 {
70 	ECORE_LL2_DROP_PACKET /* If error occurs drop packet */,
71 	ECORE_LL2_DO_NOTHING /* If error occurs do nothing */,
72 	ECORE_LL2_ASSERT /* If error occurs assert */,
73 };
74 
75 struct ecore_ll2_stats {
76 	u64 gsi_invalid_hdr;
77 	u64 gsi_invalid_pkt_length;
78 	u64 gsi_unsupported_pkt_typ;
79 	u64 gsi_crcchksm_error;
80 
81 	u64 packet_too_big_discard;
82 	u64 no_buff_discard;
83 
84 	u64 rcv_ucast_bytes;
85 	u64 rcv_mcast_bytes;
86 	u64 rcv_bcast_bytes;
87 	u64 rcv_ucast_pkts;
88 	u64 rcv_mcast_pkts;
89 	u64 rcv_bcast_pkts;
90 
91 	u64 sent_ucast_bytes;
92 	u64 sent_mcast_bytes;
93 	u64 sent_bcast_bytes;
94 	u64 sent_ucast_pkts;
95 	u64 sent_mcast_pkts;
96 	u64 sent_bcast_pkts;
97 };
98 
99 struct ecore_ll2_comp_rx_data {
100 	u8 connection_handle;
101 	void *cookie;
102 	dma_addr_t rx_buf_addr;
103 	u16 parse_flags;
104 	u16 err_flags;
105 	u16 vlan;
106 	bool b_last_packet;
107 
108 	union {
109 		u8 placement_offset;
110 		u8 data_length_error;
111 	} u;
112 	union {
113 		u16 packet_length;
114 		u16 data_length;
115 	} length;
116 
117 	u32 opaque_data_0; /* src_mac_addr_hi */
118 	u32 opaque_data_1; /* src_mac_addr_lo */
119 
120 	/* GSI only */
121 	u32 gid_dst[4];
122 	u16 qp_id;
123 };
124 
125 typedef
126 void (*ecore_ll2_complete_rx_packet_cb)(void *cxt,
127 					struct ecore_ll2_comp_rx_data *data);
128 
129 typedef
130 void (*ecore_ll2_release_rx_packet_cb)(void *cxt,
131 				       u8 connection_handle,
132 				       void *cookie,
133 				       dma_addr_t rx_buf_addr,
134 				       bool b_last_packet);
135 
136 typedef
137 void (*ecore_ll2_complete_tx_packet_cb)(void *cxt,
138 					u8 connection_handle,
139 					void *cookie,
140 					dma_addr_t first_frag_addr,
141 					bool b_last_fragment,
142 					bool b_last_packet);
143 
144 typedef
145 void (*ecore_ll2_release_tx_packet_cb)(void *cxt,
146 				       u8 connection_handle,
147 				       void *cookie,
148 				       dma_addr_t first_frag_addr,
149 				       bool b_last_fragment,
150 				       bool b_last_packet);
151 
152 typedef
153 void (*ecore_ll2_slowpath_cb)(void *cxt,
154 			      u8 connection_handle,
155 			      u32 opaque_data_0,
156 			      u32 opaque_data_1);
157 
158 struct ecore_ll2_cbs {
159 	ecore_ll2_complete_rx_packet_cb rx_comp_cb;
160 	ecore_ll2_release_rx_packet_cb rx_release_cb;
161 	ecore_ll2_complete_tx_packet_cb tx_comp_cb;
162 	ecore_ll2_release_tx_packet_cb tx_release_cb;
163 	ecore_ll2_slowpath_cb slowpath_cb;
164 	void *cookie;
165 };
166 
167 struct ecore_ll2_acquire_data {
168 	enum ecore_ll2_conn_type conn_type;
169 	u16 mtu; /* Maximum bytes that can be placed on a BD*/
170 	u16 rx_num_desc;
171 
172 	/* Relevant only for OOO connection if 0 OOO rx buffers=2*rx_num_desc */
173 	u16 rx_num_ooo_buffers;
174 	u8 rx_drop_ttl0_flg;
175 
176 	/* if set, 802.1q tags will be removed and copied to CQE */
177 	u8 rx_vlan_removal_en;
178 	u16 tx_num_desc;
179 	u8 tx_max_bds_per_packet;
180 	u8 tx_tc;
181 	enum ecore_ll2_tx_dest tx_dest;
182 	enum ecore_ll2_error_handle ai_err_packet_too_big;
183 	enum ecore_ll2_error_handle ai_err_no_buf;
184 	u8 secondary_queue;
185 	u8 gsi_enable;
186 
187 	/* Output container for LL2 connection's handle */
188 	u8 *p_connection_handle;
189 	const struct ecore_ll2_cbs *cbs;
190 };
191 #endif
192 
193 /**
194  * @brief ecore_ll2_acquire_connection - allocate resources,
195  *        starts rx & tx (if relevant) queues pair. Provides
196  *        connecion handler as output parameter.
197  *
198  *
199  * @param p_hwfn
200  * @param data - describes connection parameters
201  * @return enum _ecore_status_t
202  */
203 enum _ecore_status_t
204 ecore_ll2_acquire_connection(void *cxt,
205 			     struct ecore_ll2_acquire_data *data);
206 
207 /**
208  * @brief ecore_ll2_establish_connection - start previously
209  *        allocated LL2 queues pair
210  *
211  * @param p_hwfn
212  * @param p_ptt
213  * @param connection_handle    LL2 connection's handle
214  *                              obtained from
215  *                              ecore_ll2_require_connection
216  *
217  * @return enum _ecore_status_t
218  */
219 enum _ecore_status_t ecore_ll2_establish_connection(void *cxt,
220 						    u8 connection_handle);
221 
222 /**
223  * @brief ecore_ll2_post_rx_buffers - submit buffers to LL2 RxQ.
224  *
225  * @param p_hwfn
226  * @param connection_handle    LL2 connection's handle
227  *                              obtained from
228  *                              ecore_ll2_require_connection
229  * @param addr                  rx (physical address) buffers to
230  *                              submit
231  * @param cookie
232  * @param notify_fw             produce corresponding Rx BD
233  *                              immediately
234  *
235  * @return enum _ecore_status_t
236  */
237 enum _ecore_status_t ecore_ll2_post_rx_buffer(void *cxt,
238 					      u8 connection_handle,
239 					      dma_addr_t addr,
240 					      u16 buf_len,
241 					      void *cookie,
242 					      u8 notify_fw);
243 
244 #ifndef __EXTRACT__LINUX__
245 struct ecore_ll2_tx_pkt_info {
246 	u8 num_of_bds;
247 	u16 vlan;
248 	u8 bd_flags;
249 	u16 l4_hdr_offset_w; /* from start of packet */
250 	enum ecore_ll2_tx_dest tx_dest;
251 	enum ecore_ll2_roce_flavor_type ecore_roce_flavor;
252 	dma_addr_t first_frag;
253 	u16 first_frag_len;
254 	bool enable_ip_cksum;
255 	bool enable_l4_cksum;
256 	bool calc_ip_len;
257 	void *cookie;
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  */
272 enum _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  */
287 void 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  */
305 enum _ecore_status_t
306 ecore_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  */
322 enum _ecore_status_t ecore_ll2_terminate_connection(void *cxt,
323 						    u8 connection_handle);
324 
325 /**
326  * @brief ecore_ll2_get_stats - get LL2 queue's statistics
327  *
328  *
329  * @param p_hwfn
330  * @param connection_handle    LL2 connection's handle
331  *                              obtained from
332  *                              ecore_ll2_require_connection
333  * @param p_stats
334  *
335  * @return enum _ecore_status_t
336  */
337 enum _ecore_status_t ecore_ll2_get_stats(void *cxt,
338 					 u8 connection_handle,
339 					 struct ecore_ll2_stats	*p_stats);
340 
341 #endif
342