]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/qlnx/qlnxe/ecore_ll2_api.h
MFC r316485
[FreeBSD/stable/10.git] / sys / dev / qlnx / qlnxe / ecore_ll2_api.h
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 struct ecore_ll2_cbs {
147         ecore_ll2_complete_rx_packet_cb rx_comp_cb;
148         ecore_ll2_release_rx_packet_cb rx_release_cb;
149         ecore_ll2_complete_tx_packet_cb tx_comp_cb;
150         ecore_ll2_release_tx_packet_cb tx_release_cb;
151         void *cookie;
152 };
153
154 struct ecore_ll2_acquire_data {
155         enum ecore_ll2_conn_type conn_type;
156         u16 mtu; /* Maximum bytes that can be placed on a BD*/
157         u16 rx_num_desc;
158
159         /* Relevant only for OOO connection if 0 OOO rx buffers=2*rx_num_desc */
160         u16 rx_num_ooo_buffers;
161         u8 rx_drop_ttl0_flg;
162
163         /* if set, 802.1q tags will be removed and copied to CQE */
164         u8 rx_vlan_removal_en;
165         u16 tx_num_desc;
166         u8 tx_max_bds_per_packet;
167         u8 tx_tc;
168         enum ecore_ll2_tx_dest tx_dest;
169         enum ecore_ll2_error_handle ai_err_packet_too_big;
170         enum ecore_ll2_error_handle ai_err_no_buf;
171         u8 secondary_queue;
172         u8 gsi_enable;
173
174         /* Output container for LL2 connection's handle */
175         u8 *p_connection_handle;
176         const struct ecore_ll2_cbs *cbs;
177 };
178
179 /**
180  * @brief ecore_ll2_acquire_connection - allocate resources,
181  *        starts rx & tx (if relevant) queues pair. Provides
182  *        connecion handler as output parameter.
183  *
184  *
185  * @param p_hwfn
186  * @param data - describes connection parameters
187  * @return enum _ecore_status_t
188  */
189 enum _ecore_status_t
190 ecore_ll2_acquire_connection(void *cxt,
191                              struct ecore_ll2_acquire_data *data);
192
193 /**
194  * @brief ecore_ll2_establish_connection - start previously
195  *        allocated LL2 queues pair
196  *
197  * @param p_hwfn
198  * @param p_ptt
199  * @param connection_handle    LL2 connection's handle
200  *                              obtained from
201  *                              ecore_ll2_require_connection
202  *
203  * @return enum _ecore_status_t
204  */
205 enum _ecore_status_t ecore_ll2_establish_connection(void *cxt,
206                                                     u8 connection_handle);
207
208 /**
209  * @brief ecore_ll2_post_rx_buffers - submit buffers to LL2 RxQ.
210  *
211  * @param p_hwfn
212  * @param connection_handle    LL2 connection's handle
213  *                              obtained from
214  *                              ecore_ll2_require_connection
215  * @param addr                  rx (physical address) buffers to
216  *                              submit
217  * @param cookie
218  * @param notify_fw             produce corresponding Rx BD
219  *                              immediately
220  *
221  * @return enum _ecore_status_t
222  */
223 enum _ecore_status_t ecore_ll2_post_rx_buffer(void *cxt,
224                                               u8 connection_handle,
225                                               dma_addr_t addr,
226                                               u16 buf_len,
227                                               void *cookie,
228                                               u8 notify_fw);
229
230 struct ecore_ll2_tx_pkt_info {
231         u8 num_of_bds;
232         u16 vlan;
233         u8 bd_flags;
234         u16 l4_hdr_offset_w; /* from start of packet */
235         enum ecore_ll2_tx_dest tx_dest;
236         enum ecore_ll2_roce_flavor_type ecore_roce_flavor;
237         dma_addr_t first_frag;
238         u16 first_frag_len;
239         bool enable_ip_cksum;
240         bool enable_l4_cksum;
241         bool calc_ip_len;
242         void *cookie;
243 };
244
245 /**
246  * @brief ecore_ll2_prepare_tx_packet - request for start Tx BD
247  *        to prepare Tx packet submission to FW.
248  *
249  *
250  * @param p_hwfn
251  * @param pkt - info regarding the tx packet
252  * @param notify_fw - issue doorbell to fw for this packet
253  *
254  * @return enum _ecore_status_t
255  */
256 enum _ecore_status_t ecore_ll2_prepare_tx_packet(
257                 void *cxt,
258                 u8 connection_handle,
259                 struct ecore_ll2_tx_pkt_info *pkt,
260                 bool notify_fw);
261
262 /**
263  * @brief ecore_ll2_release_connection - releases resources
264  *        allocated for LL2 connection
265  *
266  * @param p_hwfn
267  * @param connection_handle    LL2 connection's handle
268  *                              obtained from
269  *                              ecore_ll2_require_connection
270  */
271 void ecore_ll2_release_connection(void *cxt,
272                                   u8 connection_handle);
273
274 /**
275  * @brief ecore_ll2_set_fragment_of_tx_packet - provides
276  *        fragments to fill Tx BD of BDs requested by
277  *        ecore_ll2_prepare_tx_packet..
278  *
279  *
280  * @param p_hwfn
281  * @param connection_handle    LL2 connection's handle
282  *                              obtained from
283  *                              ecore_ll2_require_connection
284  * @param addr
285  * @param nbytes
286  *
287  * @return enum _ecore_status_t
288  */
289 enum _ecore_status_t
290 ecore_ll2_set_fragment_of_tx_packet(void *cxt,
291                                     u8 connection_handle,
292                                     dma_addr_t addr,
293                                     u16 nbytes);
294
295 /**
296  * @brief ecore_ll2_terminate_connection - stops Tx/Rx queues
297  *
298  *
299  * @param p_hwfn
300  * @param connection_handle    LL2 connection's handle
301  *                              obtained from
302  *                              ecore_ll2_require_connection
303  *
304  * @return enum _ecore_status_t
305  */
306 enum _ecore_status_t ecore_ll2_terminate_connection(void *cxt,
307                                                     u8 connection_handle);
308
309 /**
310  * @brief ecore_ll2_get_stats - get LL2 queue's statistics
311  *
312  *
313  * @param p_hwfn
314  * @param connection_handle    LL2 connection's handle
315  *                              obtained from
316  *                              ecore_ll2_require_connection
317  * @param p_stats
318  *
319  * @return enum _ecore_status_t
320  */
321 enum _ecore_status_t ecore_ll2_get_stats(void *cxt,
322                                          u8 connection_handle,
323                                          struct ecore_ll2_stats *p_stats);
324
325 #endif