85034e6b6974f14c55edc84482d7d88dc5886858
[dpdk.git] / drivers / net / qede / base / ecore_l2_api.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2016 - 2018 Cavium Inc.
3  * All rights reserved.
4  * www.cavium.com
5  */
6
7 #ifndef __ECORE_L2_API_H__
8 #define __ECORE_L2_API_H__
9
10 #include "ecore_status.h"
11 #include "ecore_sp_api.h"
12 #include "ecore_int_api.h"
13
14 #ifndef __EXTRACT__LINUX__
15 enum ecore_rss_caps {
16         ECORE_RSS_IPV4          = 0x1,
17         ECORE_RSS_IPV6          = 0x2,
18         ECORE_RSS_IPV4_TCP      = 0x4,
19         ECORE_RSS_IPV6_TCP      = 0x8,
20         ECORE_RSS_IPV4_UDP      = 0x10,
21         ECORE_RSS_IPV6_UDP      = 0x20,
22 };
23
24 /* Should be the same as ETH_RSS_IND_TABLE_ENTRIES_NUM */
25 #define ECORE_RSS_IND_TABLE_SIZE 128
26 #define ECORE_RSS_KEY_SIZE 10 /* size in 32b chunks */
27 #endif
28
29 struct ecore_queue_start_common_params {
30         /* Should always be relative to entity sending this. */
31         u8 vport_id;
32         u16 queue_id;
33
34         /* Relative, but relevant only for PFs */
35         u8 stats_id;
36
37         struct ecore_sb_info *p_sb;
38         u8 sb_idx;
39 };
40
41 struct ecore_rxq_start_ret_params {
42         void OSAL_IOMEM *p_prod;
43         void *p_handle;
44 };
45
46 struct ecore_txq_start_ret_params {
47         void OSAL_IOMEM *p_doorbell;
48         void *p_handle;
49 };
50
51 struct ecore_rss_params {
52         u8 update_rss_config;
53         u8 rss_enable;
54         u8 rss_eng_id;
55         u8 update_rss_capabilities;
56         u8 update_rss_ind_table;
57         u8 update_rss_key;
58         u8 rss_caps;
59         u8 rss_table_size_log; /* The table size is 2 ^ rss_table_size_log */
60
61         /* Indirection table consist of rx queue handles */
62         void *rss_ind_table[ECORE_RSS_IND_TABLE_SIZE];
63         u32 rss_key[ECORE_RSS_KEY_SIZE];
64 };
65
66 struct ecore_sge_tpa_params {
67         u8 max_buffers_per_cqe;
68
69         u8 update_tpa_en_flg;
70         u8 tpa_ipv4_en_flg;
71         u8 tpa_ipv6_en_flg;
72         u8 tpa_ipv4_tunn_en_flg;
73         u8 tpa_ipv6_tunn_en_flg;
74
75         u8 update_tpa_param_flg;
76         u8 tpa_pkt_split_flg;
77         u8 tpa_hdr_data_split_flg;
78         u8 tpa_gro_consistent_flg;
79         u8 tpa_max_aggs_num;
80         u16 tpa_max_size;
81         u16 tpa_min_size_to_start;
82         u16 tpa_min_size_to_cont;
83 };
84
85 enum ecore_filter_opcode {
86         ECORE_FILTER_ADD,
87         ECORE_FILTER_REMOVE,
88         ECORE_FILTER_MOVE,
89         ECORE_FILTER_REPLACE, /* Delete all MACs and add new one instead */
90         ECORE_FILTER_FLUSH, /* Removes all filters */
91 };
92
93 enum ecore_filter_ucast_type {
94         ECORE_FILTER_MAC,
95         ECORE_FILTER_VLAN,
96         ECORE_FILTER_MAC_VLAN,
97         ECORE_FILTER_INNER_MAC,
98         ECORE_FILTER_INNER_VLAN,
99         ECORE_FILTER_INNER_PAIR,
100         ECORE_FILTER_INNER_MAC_VNI_PAIR,
101         ECORE_FILTER_MAC_VNI_PAIR,
102         ECORE_FILTER_VNI,
103         ECORE_FILTER_UNUSED, /* @DPDK */
104 };
105
106 struct ecore_filter_ucast {
107         enum ecore_filter_opcode opcode;
108         enum ecore_filter_ucast_type type;
109         u8 is_rx_filter;
110         u8 is_tx_filter;
111         u8 vport_to_add_to;
112         u8 vport_to_remove_from;
113         unsigned char mac[ETH_ALEN];
114         u8 assert_on_error;
115         u16 vlan;
116         u32 vni;
117 };
118
119 struct ecore_filter_mcast {
120         /* MOVE is not supported for multicast */
121         enum ecore_filter_opcode opcode;
122         u8 vport_to_add_to;
123         u8 vport_to_remove_from;
124         u8      num_mc_addrs;
125 #define ECORE_MAX_MC_ADDRS      64
126         unsigned char mac[ECORE_MAX_MC_ADDRS][ETH_ALEN];
127 };
128
129 struct ecore_filter_accept_flags {
130         u8 update_rx_mode_config;
131         u8 update_tx_mode_config;
132         u8 rx_accept_filter;
133         u8 tx_accept_filter;
134 #define ECORE_ACCEPT_NONE               0x01
135 #define ECORE_ACCEPT_UCAST_MATCHED      0x02
136 #define ECORE_ACCEPT_UCAST_UNMATCHED    0x04
137 #define ECORE_ACCEPT_MCAST_MATCHED      0x08
138 #define ECORE_ACCEPT_MCAST_UNMATCHED    0x10
139 #define ECORE_ACCEPT_BCAST              0x20
140 };
141
142 enum ecore_filter_config_mode {
143         ECORE_FILTER_CONFIG_MODE_DISABLE,
144         ECORE_FILTER_CONFIG_MODE_5_TUPLE,
145         ECORE_FILTER_CONFIG_MODE_L4_PORT,
146         ECORE_FILTER_CONFIG_MODE_IP_DEST,
147         ECORE_FILTER_CONFIG_MODE_TUNN_TYPE,
148         ECORE_FILTER_CONFIG_MODE_IP_SRC,
149 };
150
151 struct ecore_arfs_config_params {
152         bool tcp;
153         bool udp;
154         bool ipv4;
155         bool ipv6;
156         enum ecore_filter_config_mode mode;
157 };
158
159 /* Add / remove / move / remove-all unicast MAC-VLAN filters.
160  * FW will assert in the following cases, so driver should take care...:
161  * 1. Adding a filter to a full table.
162  * 2. Adding a filter which already exists on that vport.
163  * 3. Removing a filter which doesn't exist.
164  */
165
166 enum _ecore_status_t
167 ecore_filter_ucast_cmd(struct ecore_dev *p_dev,
168                        struct ecore_filter_ucast *p_filter_cmd,
169                        enum spq_mode comp_mode,
170                        struct ecore_spq_comp_cb *p_comp_data);
171
172 /* Add / remove / move multicast MAC filters. */
173 enum _ecore_status_t
174 ecore_filter_mcast_cmd(struct ecore_dev *p_dev,
175                        struct ecore_filter_mcast *p_filter_cmd,
176                        enum spq_mode comp_mode,
177                        struct ecore_spq_comp_cb *p_comp_data);
178
179 /* Set "accept" filters */
180 enum _ecore_status_t
181 ecore_filter_accept_cmd(
182         struct ecore_dev                 *p_dev,
183         u8                               vport,
184         struct ecore_filter_accept_flags accept_flags,
185         u8                               update_accept_any_vlan,
186         u8                               accept_any_vlan,
187         enum spq_mode                    comp_mode,
188         struct ecore_spq_comp_cb         *p_comp_data);
189
190 /**
191  * @brief ecore_eth_rx_queue_start - RX Queue Start Ramrod
192  *
193  * This ramrod initializes an RX Queue for a VPort. An Assert is generated if
194  * the VPort ID is not currently initialized.
195  *
196  * @param p_hwfn
197  * @param opaque_fid
198  * @p_params                    Inputs; Relative for PF [SB being an exception]
199  * @param bd_max_bytes          Maximum bytes that can be placed on a BD
200  * @param bd_chain_phys_addr    Physical address of BDs for receive.
201  * @param cqe_pbl_addr          Physical address of the CQE PBL Table.
202  * @param cqe_pbl_size          Size of the CQE PBL Table
203  * @param p_ret_params          Pointed struct to be filled with outputs.
204  *
205  * @return enum _ecore_status_t
206  */
207 enum _ecore_status_t
208 ecore_eth_rx_queue_start(struct ecore_hwfn *p_hwfn,
209                          u16 opaque_fid,
210                          struct ecore_queue_start_common_params *p_params,
211                          u16 bd_max_bytes,
212                          dma_addr_t bd_chain_phys_addr,
213                          dma_addr_t cqe_pbl_addr,
214                          u16 cqe_pbl_size,
215                          struct ecore_rxq_start_ret_params *p_ret_params);
216
217 /**
218  * @brief ecore_eth_rx_queue_stop - This ramrod closes an Rx queue
219  *
220  * @param p_hwfn
221  * @param p_rxq                 Handler of queue to close
222  * @param eq_completion_only    If True completion will be on
223  *                              EQe, if False completion will be
224  *                              on EQe if p_hwfn opaque
225  *                              different from the RXQ opaque
226  *                              otherwise on CQe.
227  * @param cqe_completion        If True completion will be
228  *                              receive on CQe.
229  * @return enum _ecore_status_t
230  */
231 enum _ecore_status_t
232 ecore_eth_rx_queue_stop(struct ecore_hwfn *p_hwfn,
233                         void *p_rxq,
234                         bool eq_completion_only,
235                         bool cqe_completion);
236
237 /**
238  * @brief - TX Queue Start Ramrod
239  *
240  * This ramrod initializes a TX Queue for a VPort. An Assert is generated if
241  * the VPort is not currently initialized.
242  *
243  * @param p_hwfn
244  * @param opaque_fid
245  * @p_params
246  * @param tc                    traffic class to use with this L2 txq
247  * @param pbl_addr              address of the pbl array
248  * @param pbl_size              number of entries in pbl
249  * @param p_ret_params          Pointer to fill the return parameters in.
250  *
251  * @return enum _ecore_status_t
252  */
253 enum _ecore_status_t
254 ecore_eth_tx_queue_start(struct ecore_hwfn *p_hwfn,
255                          u16 opaque_fid,
256                          struct ecore_queue_start_common_params *p_params,
257                          u8 tc,
258                          dma_addr_t pbl_addr,
259                          u16 pbl_size,
260                          struct ecore_txq_start_ret_params *p_ret_params);
261
262 /**
263  * @brief ecore_eth_tx_queue_stop - closes a Tx queue
264  *
265  * @param p_hwfn
266  * @param p_txq - handle to Tx queue needed to be closed
267  *
268  * @return enum _ecore_status_t
269  */
270 enum _ecore_status_t ecore_eth_tx_queue_stop(struct ecore_hwfn *p_hwfn,
271                                              void *p_txq);
272
273 enum ecore_tpa_mode     {
274         ECORE_TPA_MODE_NONE,
275         ECORE_TPA_MODE_RSC,
276         ECORE_TPA_MODE_GRO,
277         ECORE_TPA_MODE_MAX
278 };
279
280 struct ecore_sp_vport_start_params {
281         enum ecore_tpa_mode tpa_mode;
282         bool remove_inner_vlan; /* Inner VLAN removal is enabled */
283         bool tx_switching;      /* Vport supports tx-switching */
284         bool handle_ptp_pkts;   /* Handle PTP packets */
285         bool only_untagged;     /* Untagged pkt control */
286         bool drop_ttl0;         /* Drop packets with TTL = 0 */
287         u8 max_buffers_per_cqe;
288         u32 concrete_fid;
289         u16 opaque_fid;
290         u8 vport_id;            /* VPORT ID */
291         u16 mtu;                /* VPORT MTU */
292         bool zero_placement_offset;
293         bool check_mac;
294         bool check_ethtype;
295
296         /* Strict behavior on transmission errors */
297         bool b_err_illegal_vlan_mode;
298         bool b_err_illegal_inband_mode;
299         bool b_err_vlan_insert_with_inband;
300         bool b_err_small_pkt;
301         bool b_err_big_pkt;
302         bool b_err_anti_spoof;
303         bool b_err_ctrl_frame;
304 };
305
306 /**
307  * @brief ecore_sp_vport_start -
308  *
309  * This ramrod initializes a VPort. An Assert if generated if the Function ID
310  * of the VPort is not enabled.
311  *
312  * @param p_hwfn
313  * @param p_params              VPORT start params
314  *
315  * @return enum _ecore_status_t
316  */
317 enum _ecore_status_t
318 ecore_sp_vport_start(struct ecore_hwfn *p_hwfn,
319                      struct ecore_sp_vport_start_params *p_params);
320
321 struct ecore_sp_vport_update_params {
322         u16                     opaque_fid;
323         u8                      vport_id;
324         u8                      update_vport_active_rx_flg;
325         u8                      vport_active_rx_flg;
326         u8                      update_vport_active_tx_flg;
327         u8                      vport_active_tx_flg;
328         u8                      update_inner_vlan_removal_flg;
329         u8                      inner_vlan_removal_flg;
330         u8                      silent_vlan_removal_flg;
331         u8                      update_default_vlan_enable_flg;
332         u8                      default_vlan_enable_flg;
333         u8                      update_default_vlan_flg;
334         u16                     default_vlan;
335         u8                      update_tx_switching_flg;
336         u8                      tx_switching_flg;
337         u8                      update_approx_mcast_flg;
338         u8                      update_anti_spoofing_en_flg;
339         u8                      anti_spoofing_en;
340         u8                      update_accept_any_vlan_flg;
341         u8                      accept_any_vlan;
342         u32                     bins[8];
343         struct ecore_rss_params *rss_params;
344         struct ecore_filter_accept_flags accept_flags;
345         struct ecore_sge_tpa_params *sge_tpa_params;
346         /* MTU change - notice this requires the vport to be disabled.
347          * If non-zero, value would be used.
348          */
349         u16 mtu;
350 };
351
352 /**
353  * @brief ecore_sp_vport_update -
354  *
355  * This ramrod updates the parameters of the VPort. Every field can be updated
356  * independently, according to flags.
357  *
358  * This ramrod is also used to set the VPort state to active after creation.
359  * An Assert is generated if the VPort does not contain an RX queue.
360  *
361  * @param p_hwfn
362  * @param p_params
363  *
364  * @return enum _ecore_status_t
365  */
366 enum _ecore_status_t
367 ecore_sp_vport_update(struct ecore_hwfn *p_hwfn,
368                       struct ecore_sp_vport_update_params *p_params,
369                       enum spq_mode comp_mode,
370                       struct ecore_spq_comp_cb *p_comp_data);
371 /**
372  * @brief ecore_sp_vport_stop -
373  *
374  * This ramrod closes a VPort after all its RX and TX queues are terminated.
375  * An Assert is generated if any queues are left open.
376  *
377  * @param p_hwfn
378  * @param opaque_fid
379  * @param vport_id VPort ID
380  *
381  * @return enum _ecore_status_t
382  */
383 enum _ecore_status_t ecore_sp_vport_stop(struct ecore_hwfn *p_hwfn,
384                                          u16 opaque_fid,
385                                          u8 vport_id);
386
387 enum _ecore_status_t
388 ecore_sp_eth_filter_ucast(struct ecore_hwfn *p_hwfn,
389                           u16 opaque_fid,
390                           struct ecore_filter_ucast *p_filter_cmd,
391                           enum spq_mode comp_mode,
392                           struct ecore_spq_comp_cb *p_comp_data);
393
394 /**
395  * @brief ecore_sp_rx_eth_queues_update -
396  *
397  * This ramrod updates an RX queue. It is used for setting the active state
398  * of the queue and updating the TPA and SGE parameters.
399  *
400  * @note Final phase API.
401  *
402  * @param p_hwfn
403  * @param pp_rxq_handlers       An array of queue handlers to be updated.
404  * @param num_rxqs              number of queues to update.
405  * @param complete_cqe_flg      Post completion to the CQE Ring if set
406  * @param complete_event_flg    Post completion to the Event Ring if set
407  * @param comp_mode
408  * @param p_comp_data
409  *
410  * @return enum _ecore_status_t
411  */
412
413 enum _ecore_status_t
414 ecore_sp_eth_rx_queues_update(struct ecore_hwfn *p_hwfn,
415                               void **pp_rxq_handlers,
416                               u8 num_rxqs,
417                               u8 complete_cqe_flg,
418                               u8 complete_event_flg,
419                               enum spq_mode comp_mode,
420                               struct ecore_spq_comp_cb *p_comp_data);
421
422 void __ecore_get_vport_stats(struct ecore_hwfn *p_hwfn,
423                              struct ecore_ptt *p_ptt,
424                              struct ecore_eth_stats *stats,
425                              u16 statistics_bin, bool b_get_port_stats);
426
427 void ecore_get_vport_stats(struct ecore_dev *p_dev,
428                            struct ecore_eth_stats *stats);
429
430 void ecore_reset_vport_stats(struct ecore_dev *p_dev);
431
432 /**
433  *@brief ecore_arfs_mode_configure -
434  *
435  *Enable or disable rfs mode. It must accept atleast one of tcp or udp true
436  *and atleast one of ipv4 or ipv6 true to enable rfs mode.
437  *
438  *@param p_hwfn
439  *@param p_ptt
440  *@param p_cfg_params           arfs mode configuration parameters.
441  *
442  */
443 void ecore_arfs_mode_configure(struct ecore_hwfn *p_hwfn,
444                                struct ecore_ptt *p_ptt,
445                                struct ecore_arfs_config_params *p_cfg_params);
446
447 /**
448  * @brief - ecore_configure_rfs_ntuple_filter
449  *
450  * This ramrod should be used to add or remove arfs hw filter
451  *
452  * @params p_hwfn
453  * @params p_cb         Used for ECORE_SPQ_MODE_CB,where client would initialize
454  *                      it with cookie and callback function address, if not
455  *                      using this mode then client must pass NULL.
456  * @params p_addr       p_addr is an actual packet header that needs to be
457  *                      filter. It has to mapped with IO to read prior to
458  *                      calling this, [contains 4 tuples- src ip, dest ip,
459  *                      src port, dest port].
460  * @params length       length of p_addr header up to past the transport header.
461  * @params qid          receive packet will be directed to this queue.
462  * @params vport_id
463  * @params b_is_add     flag to add or remove filter.
464  *
465  */
466 enum _ecore_status_t
467 ecore_configure_rfs_ntuple_filter(struct ecore_hwfn *p_hwfn,
468                                   struct ecore_spq_comp_cb *p_cb,
469                                   dma_addr_t p_addr, u16 length,
470                                   u16 qid, u8 vport_id,
471                                   bool b_is_add);
472 #endif