net/mlx5e: Add support for PCI relaxed ordering
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / en.h
1 /*
2  * Copyright (c) 2015-2016, Mellanox Technologies. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32 #ifndef __MLX5_EN_H__
33 #define __MLX5_EN_H__
34
35 #include <linux/if_vlan.h>
36 #include <linux/etherdevice.h>
37 #include <linux/timecounter.h>
38 #include <linux/net_tstamp.h>
39 #include <linux/crash_dump.h>
40 #include <linux/mlx5/driver.h>
41 #include <linux/mlx5/qp.h>
42 #include <linux/mlx5/cq.h>
43 #include <linux/mlx5/port.h>
44 #include <linux/mlx5/vport.h>
45 #include <linux/mlx5/transobj.h>
46 #include <linux/mlx5/fs.h>
47 #include <linux/rhashtable.h>
48 #include <net/switchdev.h>
49 #include <net/xdp.h>
50 #include <linux/dim.h>
51 #include <linux/bits.h>
52 #include "wq.h"
53 #include "mlx5_core.h"
54 #include "en_stats.h"
55 #include "en/dcbnl.h"
56 #include "en/fs.h"
57 #include "lib/hv_vhca.h"
58
59 extern const struct net_device_ops mlx5e_netdev_ops;
60 struct page_pool;
61
62 #define MLX5E_METADATA_ETHER_TYPE (0x8CE4)
63 #define MLX5E_METADATA_ETHER_LEN 8
64
65 #define MLX5_SET_CFG(p, f, v) MLX5_SET(create_flow_group_in, p, f, v)
66
67 #define MLX5E_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
68
69 #define MLX5E_HW2SW_MTU(params, hwmtu) ((hwmtu) - ((params)->hard_mtu))
70 #define MLX5E_SW2HW_MTU(params, swmtu) ((swmtu) + ((params)->hard_mtu))
71
72 #define MLX5E_MAX_NUM_TC        8
73
74 #define MLX5_RX_HEADROOM NET_SKB_PAD
75 #define MLX5_SKB_FRAG_SZ(len)   (SKB_DATA_ALIGN(len) +  \
76                                  SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
77
78 #define MLX5E_RX_MAX_HEAD (256)
79
80 #define MLX5_MPWRQ_MIN_LOG_STRIDE_SZ(mdev) \
81         (6 + MLX5_CAP_GEN(mdev, cache_line_128byte)) /* HW restriction */
82 #define MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, req) \
83         max_t(u32, MLX5_MPWRQ_MIN_LOG_STRIDE_SZ(mdev), req)
84 #define MLX5_MPWRQ_DEF_LOG_STRIDE_SZ(mdev) \
85         MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, order_base_2(MLX5E_RX_MAX_HEAD))
86
87 #define MLX5_MPWRQ_LOG_WQE_SZ                   18
88 #define MLX5_MPWRQ_WQE_PAGE_ORDER  (MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT > 0 ? \
89                                     MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT : 0)
90 #define MLX5_MPWRQ_PAGES_PER_WQE                BIT(MLX5_MPWRQ_WQE_PAGE_ORDER)
91
92 #define MLX5_MTT_OCTW(npages) (ALIGN(npages, 8) / 2)
93 #define MLX5E_REQUIRED_WQE_MTTS         (ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8))
94 #define MLX5E_LOG_ALIGNED_MPWQE_PPW     (ilog2(MLX5E_REQUIRED_WQE_MTTS))
95 #define MLX5E_REQUIRED_MTTS(wqes)       (wqes * MLX5E_REQUIRED_WQE_MTTS)
96 #define MLX5E_MAX_RQ_NUM_MTTS   \
97         ((1 << 16) * 2) /* So that MLX5_MTT_OCTW(num_mtts) fits into u16 */
98 #define MLX5E_ORDER2_MAX_PACKET_MTU (order_base_2(10 * 1024))
99 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW    \
100                 (ilog2(MLX5E_MAX_RQ_NUM_MTTS / MLX5E_REQUIRED_WQE_MTTS))
101 #define MLX5E_LOG_MAX_RQ_NUM_PACKETS_MPW \
102         (MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW + \
103          (MLX5_MPWRQ_LOG_WQE_SZ - MLX5E_ORDER2_MAX_PACKET_MTU))
104
105 #define MLX5E_MIN_SKB_FRAG_SZ           (MLX5_SKB_FRAG_SZ(MLX5_RX_HEADROOM))
106 #define MLX5E_LOG_MAX_RX_WQE_BULK       \
107         (ilog2(PAGE_SIZE / roundup_pow_of_two(MLX5E_MIN_SKB_FRAG_SZ)))
108
109 #define MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE                0x6
110 #define MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE                0xa
111 #define MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE                0xd
112
113 #define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE (1 + MLX5E_LOG_MAX_RX_WQE_BULK)
114 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE                0xa
115 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE min_t(u8, 0xd, \
116                                                MLX5E_LOG_MAX_RQ_NUM_PACKETS_MPW)
117
118 #define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW            0x2
119
120 #define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ                 (64 * 1024)
121 #define MLX5E_DEFAULT_LRO_TIMEOUT                       32
122 #define MLX5E_LRO_TIMEOUT_ARR_SIZE                      4
123
124 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC      0x10
125 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE 0x3
126 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS      0x20
127 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC      0x10
128 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC_FROM_CQE 0x10
129 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS      0x20
130 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES                0x80
131 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW            0x2
132
133 #define MLX5E_LOG_INDIR_RQT_SIZE       0x7
134 #define MLX5E_INDIR_RQT_SIZE           BIT(MLX5E_LOG_INDIR_RQT_SIZE)
135 #define MLX5E_MIN_NUM_CHANNELS         0x1
136 #define MLX5E_MAX_NUM_CHANNELS         MLX5E_INDIR_RQT_SIZE
137 #define MLX5E_MAX_NUM_SQS              (MLX5E_MAX_NUM_CHANNELS * MLX5E_MAX_NUM_TC)
138 #define MLX5E_TX_CQ_POLL_BUDGET        128
139 #define MLX5E_TX_XSK_POLL_BUDGET       64
140 #define MLX5E_SQ_RECOVER_MIN_INTERVAL  500 /* msecs */
141
142 #define MLX5E_UMR_WQE_INLINE_SZ \
143         (sizeof(struct mlx5e_umr_wqe) + \
144          ALIGN(MLX5_MPWRQ_PAGES_PER_WQE * sizeof(struct mlx5_mtt), \
145                MLX5_UMR_MTT_ALIGNMENT))
146 #define MLX5E_UMR_WQEBBS \
147         (DIV_ROUND_UP(MLX5E_UMR_WQE_INLINE_SZ, MLX5_SEND_WQE_BB))
148
149 #define MLX5E_MSG_LEVEL                 NETIF_MSG_LINK
150
151 #define mlx5e_dbg(mlevel, priv, format, ...)                    \
152 do {                                                            \
153         if (NETIF_MSG_##mlevel & (priv)->msglevel)              \
154                 netdev_warn(priv->netdev, format,               \
155                             ##__VA_ARGS__);                     \
156 } while (0)
157
158 enum mlx5e_rq_group {
159         MLX5E_RQ_GROUP_REGULAR,
160         MLX5E_RQ_GROUP_XSK,
161 #define MLX5E_NUM_RQ_GROUPS(g) (1 + MLX5E_RQ_GROUP_##g)
162 };
163
164 static inline u8 mlx5e_get_num_lag_ports(struct mlx5_core_dev *mdev)
165 {
166         if (mlx5_lag_is_lacp_owner(mdev))
167                 return 1;
168
169         return clamp_t(u8, MLX5_CAP_GEN(mdev, num_lag_ports), 1, MLX5_MAX_PORTS);
170 }
171
172 static inline u16 mlx5_min_rx_wqes(int wq_type, u32 wq_size)
173 {
174         switch (wq_type) {
175         case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
176                 return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW,
177                              wq_size / 2);
178         default:
179                 return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES,
180                              wq_size / 2);
181         }
182 }
183
184 /* Use this function to get max num channels (rxqs/txqs) only to create netdev */
185 static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
186 {
187         return is_kdump_kernel() ?
188                 MLX5E_MIN_NUM_CHANNELS :
189                 min_t(int, mlx5_comp_vectors_count(mdev), MLX5E_MAX_NUM_CHANNELS);
190 }
191
192 struct mlx5e_tx_wqe {
193         struct mlx5_wqe_ctrl_seg ctrl;
194         struct mlx5_wqe_eth_seg  eth;
195         struct mlx5_wqe_data_seg data[0];
196 };
197
198 struct mlx5e_rx_wqe_ll {
199         struct mlx5_wqe_srq_next_seg  next;
200         struct mlx5_wqe_data_seg      data[];
201 };
202
203 struct mlx5e_rx_wqe_cyc {
204         struct mlx5_wqe_data_seg      data[0];
205 };
206
207 struct mlx5e_umr_wqe {
208         struct mlx5_wqe_ctrl_seg       ctrl;
209         struct mlx5_wqe_umr_ctrl_seg   uctrl;
210         struct mlx5_mkey_seg           mkc;
211         struct mlx5_mtt                inline_mtts[0];
212 };
213
214 extern const char mlx5e_self_tests[][ETH_GSTRING_LEN];
215
216 enum mlx5e_priv_flag {
217         MLX5E_PFLAG_RX_CQE_BASED_MODER,
218         MLX5E_PFLAG_TX_CQE_BASED_MODER,
219         MLX5E_PFLAG_RX_CQE_COMPRESS,
220         MLX5E_PFLAG_RX_STRIDING_RQ,
221         MLX5E_PFLAG_RX_NO_CSUM_COMPLETE,
222         MLX5E_PFLAG_XDP_TX_MPWQE,
223         MLX5E_NUM_PFLAGS, /* Keep last */
224 };
225
226 #define MLX5E_SET_PFLAG(params, pflag, enable)                  \
227         do {                                                    \
228                 if (enable)                                     \
229                         (params)->pflags |= BIT(pflag);         \
230                 else                                            \
231                         (params)->pflags &= ~(BIT(pflag));      \
232         } while (0)
233
234 #define MLX5E_GET_PFLAG(params, pflag) (!!((params)->pflags & (BIT(pflag))))
235
236 struct mlx5e_params {
237         u8  log_sq_size;
238         u8  rq_wq_type;
239         u8  log_rq_mtu_frames;
240         u16 num_channels;
241         u8  num_tc;
242         bool rx_cqe_compress_def;
243         bool tunneled_offload_en;
244         struct dim_cq_moder rx_cq_moderation;
245         struct dim_cq_moder tx_cq_moderation;
246         bool lro_en;
247         u8  tx_min_inline_mode;
248         bool vlan_strip_disable;
249         bool scatter_fcs_en;
250         bool rx_dim_enabled;
251         bool tx_dim_enabled;
252         u32 lro_timeout;
253         u32 pflags;
254         struct bpf_prog *xdp_prog;
255         struct mlx5e_xsk *xsk;
256         unsigned int sw_mtu;
257         int hard_mtu;
258 };
259
260 enum {
261         MLX5E_RQ_STATE_ENABLED,
262         MLX5E_RQ_STATE_RECOVERING,
263         MLX5E_RQ_STATE_AM,
264         MLX5E_RQ_STATE_NO_CSUM_COMPLETE,
265         MLX5E_RQ_STATE_CSUM_FULL, /* cqe_csum_full hw bit is set */
266         MLX5E_RQ_STATE_FPGA_TLS, /* FPGA TLS enabled */
267 };
268
269 struct mlx5e_cq {
270         /* data path - accessed per cqe */
271         struct mlx5_cqwq           wq;
272
273         /* data path - accessed per napi poll */
274         u16                        event_ctr;
275         struct napi_struct        *napi;
276         struct mlx5_core_cq        mcq;
277         struct mlx5e_channel      *channel;
278
279         /* control */
280         struct mlx5_core_dev      *mdev;
281         struct mlx5_wq_ctrl        wq_ctrl;
282 } ____cacheline_aligned_in_smp;
283
284 struct mlx5e_cq_decomp {
285         /* cqe decompression */
286         struct mlx5_cqe64          title;
287         struct mlx5_mini_cqe8      mini_arr[MLX5_MINI_CQE_ARRAY_SIZE];
288         u8                         mini_arr_idx;
289         u16                        left;
290         u16                        wqe_counter;
291 } ____cacheline_aligned_in_smp;
292
293 enum mlx5e_dma_map_type {
294         MLX5E_DMA_MAP_SINGLE,
295         MLX5E_DMA_MAP_PAGE
296 };
297
298 struct mlx5e_sq_dma {
299         dma_addr_t              addr;
300         u32                     size;
301         enum mlx5e_dma_map_type type;
302 };
303
304 enum {
305         MLX5E_SQ_STATE_ENABLED,
306         MLX5E_SQ_STATE_RECOVERING,
307         MLX5E_SQ_STATE_IPSEC,
308         MLX5E_SQ_STATE_AM,
309         MLX5E_SQ_STATE_TLS,
310         MLX5E_SQ_STATE_VLAN_NEED_L2_INLINE,
311         MLX5E_SQ_STATE_PENDING_XSK_TX,
312 };
313
314 struct mlx5e_txqsq {
315         /* data path */
316
317         /* dirtied @completion */
318         u16                        cc;
319         u32                        dma_fifo_cc;
320         struct dim                 dim; /* Adaptive Moderation */
321
322         /* dirtied @xmit */
323         u16                        pc ____cacheline_aligned_in_smp;
324         u32                        dma_fifo_pc;
325
326         struct mlx5e_cq            cq;
327
328         /* read only */
329         struct mlx5_wq_cyc         wq;
330         u32                        dma_fifo_mask;
331         struct mlx5e_sq_stats     *stats;
332         struct {
333                 struct mlx5e_sq_dma       *dma_fifo;
334                 struct mlx5e_tx_wqe_info  *wqe_info;
335         } db;
336         void __iomem              *uar_map;
337         struct netdev_queue       *txq;
338         u32                        sqn;
339         u16                        stop_room;
340         u8                         min_inline_mode;
341         struct device             *pdev;
342         __be32                     mkey_be;
343         unsigned long              state;
344         unsigned int               hw_mtu;
345         struct hwtstamp_config    *tstamp;
346         struct mlx5_clock         *clock;
347
348         /* control path */
349         struct mlx5_wq_ctrl        wq_ctrl;
350         struct mlx5e_channel      *channel;
351         int                        ch_ix;
352         int                        txq_ix;
353         u32                        rate_limit;
354         struct work_struct         recover_work;
355 } ____cacheline_aligned_in_smp;
356
357 struct mlx5e_dma_info {
358         dma_addr_t addr;
359         union {
360                 struct page *page;
361                 struct xdp_buff *xsk;
362         };
363 };
364
365 /* XDP packets can be transmitted in different ways. On completion, we need to
366  * distinguish between them to clean up things in a proper way.
367  */
368 enum mlx5e_xdp_xmit_mode {
369         /* An xdp_frame was transmitted due to either XDP_REDIRECT from another
370          * device or XDP_TX from an XSK RQ. The frame has to be unmapped and
371          * returned.
372          */
373         MLX5E_XDP_XMIT_MODE_FRAME,
374
375         /* The xdp_frame was created in place as a result of XDP_TX from a
376          * regular RQ. No DMA remapping happened, and the page belongs to us.
377          */
378         MLX5E_XDP_XMIT_MODE_PAGE,
379
380         /* No xdp_frame was created at all, the transmit happened from a UMEM
381          * page. The UMEM Completion Ring producer pointer has to be increased.
382          */
383         MLX5E_XDP_XMIT_MODE_XSK,
384 };
385
386 struct mlx5e_xdp_info {
387         enum mlx5e_xdp_xmit_mode mode;
388         union {
389                 struct {
390                         struct xdp_frame *xdpf;
391                         dma_addr_t dma_addr;
392                 } frame;
393                 struct {
394                         struct mlx5e_rq *rq;
395                         struct mlx5e_dma_info di;
396                 } page;
397         };
398 };
399
400 struct mlx5e_xdp_xmit_data {
401         dma_addr_t  dma_addr;
402         void       *data;
403         u32         len;
404 };
405
406 struct mlx5e_xdp_info_fifo {
407         struct mlx5e_xdp_info *xi;
408         u32 *cc;
409         u32 *pc;
410         u32 mask;
411 };
412
413 struct mlx5e_xdp_mpwqe {
414         /* Current MPWQE session */
415         struct mlx5e_tx_wqe *wqe;
416         u8                   ds_count;
417         u8                   pkt_count;
418         u8                   inline_on;
419 };
420
421 struct mlx5e_xdpsq;
422 typedef int (*mlx5e_fp_xmit_xdp_frame_check)(struct mlx5e_xdpsq *);
423 typedef bool (*mlx5e_fp_xmit_xdp_frame)(struct mlx5e_xdpsq *,
424                                         struct mlx5e_xdp_xmit_data *,
425                                         struct mlx5e_xdp_info *,
426                                         int);
427
428 struct mlx5e_xdpsq {
429         /* data path */
430
431         /* dirtied @completion */
432         u32                        xdpi_fifo_cc;
433         u16                        cc;
434
435         /* dirtied @xmit */
436         u32                        xdpi_fifo_pc ____cacheline_aligned_in_smp;
437         u16                        pc;
438         struct mlx5_wqe_ctrl_seg   *doorbell_cseg;
439         struct mlx5e_xdp_mpwqe     mpwqe;
440
441         struct mlx5e_cq            cq;
442
443         /* read only */
444         struct xdp_umem           *umem;
445         struct mlx5_wq_cyc         wq;
446         struct mlx5e_xdpsq_stats  *stats;
447         mlx5e_fp_xmit_xdp_frame_check xmit_xdp_frame_check;
448         mlx5e_fp_xmit_xdp_frame    xmit_xdp_frame;
449         struct {
450                 struct mlx5e_xdp_wqe_info *wqe_info;
451                 struct mlx5e_xdp_info_fifo xdpi_fifo;
452         } db;
453         void __iomem              *uar_map;
454         u32                        sqn;
455         struct device             *pdev;
456         __be32                     mkey_be;
457         u8                         min_inline_mode;
458         unsigned long              state;
459         unsigned int               hw_mtu;
460
461         /* control path */
462         struct mlx5_wq_ctrl        wq_ctrl;
463         struct mlx5e_channel      *channel;
464 } ____cacheline_aligned_in_smp;
465
466 struct mlx5e_icosq {
467         /* data path */
468         u16                        cc;
469         u16                        pc;
470
471         struct mlx5_wqe_ctrl_seg  *doorbell_cseg;
472         struct mlx5e_cq            cq;
473
474         /* write@xmit, read@completion */
475         struct {
476                 struct mlx5e_icosq_wqe_info *wqe_info;
477         } db;
478
479         /* read only */
480         struct mlx5_wq_cyc         wq;
481         void __iomem              *uar_map;
482         u32                        sqn;
483         unsigned long              state;
484
485         /* control path */
486         struct mlx5_wq_ctrl        wq_ctrl;
487         struct mlx5e_channel      *channel;
488
489         struct work_struct         recover_work;
490 } ____cacheline_aligned_in_smp;
491
492 struct mlx5e_wqe_frag_info {
493         struct mlx5e_dma_info *di;
494         u32 offset;
495         bool last_in_page;
496 };
497
498 struct mlx5e_umr_dma_info {
499         struct mlx5e_dma_info  dma_info[MLX5_MPWRQ_PAGES_PER_WQE];
500 };
501
502 struct mlx5e_mpw_info {
503         struct mlx5e_umr_dma_info umr;
504         u16 consumed_strides;
505         DECLARE_BITMAP(xdp_xmit_bitmap, MLX5_MPWRQ_PAGES_PER_WQE);
506 };
507
508 #define MLX5E_MAX_RX_FRAGS 4
509
510 /* a single cache unit is capable to serve one napi call (for non-striding rq)
511  * or a MPWQE (for striding rq).
512  */
513 #define MLX5E_CACHE_UNIT        (MLX5_MPWRQ_PAGES_PER_WQE > NAPI_POLL_WEIGHT ? \
514                                  MLX5_MPWRQ_PAGES_PER_WQE : NAPI_POLL_WEIGHT)
515 #define MLX5E_CACHE_SIZE        (4 * roundup_pow_of_two(MLX5E_CACHE_UNIT))
516 struct mlx5e_page_cache {
517         u32 head;
518         u32 tail;
519         struct mlx5e_dma_info page_cache[MLX5E_CACHE_SIZE];
520 };
521
522 struct mlx5e_rq;
523 typedef void (*mlx5e_fp_handle_rx_cqe)(struct mlx5e_rq*, struct mlx5_cqe64*);
524 typedef struct sk_buff *
525 (*mlx5e_fp_skb_from_cqe_mpwrq)(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi,
526                                u16 cqe_bcnt, u32 head_offset, u32 page_idx);
527 typedef struct sk_buff *
528 (*mlx5e_fp_skb_from_cqe)(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe,
529                          struct mlx5e_wqe_frag_info *wi, u32 cqe_bcnt);
530 typedef bool (*mlx5e_fp_post_rx_wqes)(struct mlx5e_rq *rq);
531 typedef void (*mlx5e_fp_dealloc_wqe)(struct mlx5e_rq*, u16);
532
533 int mlx5e_rq_set_handlers(struct mlx5e_rq *rq, struct mlx5e_params *params, bool xsk);
534
535 enum mlx5e_rq_flag {
536         MLX5E_RQ_FLAG_XDP_XMIT,
537         MLX5E_RQ_FLAG_XDP_REDIRECT,
538 };
539
540 struct mlx5e_rq_frag_info {
541         int frag_size;
542         int frag_stride;
543 };
544
545 struct mlx5e_rq_frags_info {
546         struct mlx5e_rq_frag_info arr[MLX5E_MAX_RX_FRAGS];
547         u8 num_frags;
548         u8 log_num_frags;
549         u8 wqe_bulk;
550 };
551
552 struct mlx5e_rq {
553         /* data path */
554         union {
555                 struct {
556                         struct mlx5_wq_cyc          wq;
557                         struct mlx5e_wqe_frag_info *frags;
558                         struct mlx5e_dma_info      *di;
559                         struct mlx5e_rq_frags_info  info;
560                         mlx5e_fp_skb_from_cqe       skb_from_cqe;
561                 } wqe;
562                 struct {
563                         struct mlx5_wq_ll      wq;
564                         struct mlx5e_umr_wqe   umr_wqe;
565                         struct mlx5e_mpw_info *info;
566                         mlx5e_fp_skb_from_cqe_mpwrq skb_from_cqe_mpwrq;
567                         u16                    num_strides;
568                         u16                    actual_wq_head;
569                         u8                     log_stride_sz;
570                         u8                     umr_in_progress;
571                         u8                     umr_last_bulk;
572                         u8                     umr_completed;
573                 } mpwqe;
574         };
575         struct {
576                 u16            headroom;
577                 u32            frame0_sz;
578                 u8             map_dir;   /* dma map direction */
579         } buff;
580
581         struct mlx5e_channel  *channel;
582         struct device         *pdev;
583         struct net_device     *netdev;
584         struct mlx5e_rq_stats *stats;
585         struct mlx5e_cq        cq;
586         struct mlx5e_cq_decomp cqd;
587         struct mlx5e_page_cache page_cache;
588         struct hwtstamp_config *tstamp;
589         struct mlx5_clock      *clock;
590
591         mlx5e_fp_handle_rx_cqe handle_rx_cqe;
592         mlx5e_fp_post_rx_wqes  post_wqes;
593         mlx5e_fp_dealloc_wqe   dealloc_wqe;
594
595         unsigned long          state;
596         int                    ix;
597         unsigned int           hw_mtu;
598
599         struct dim         dim; /* Dynamic Interrupt Moderation */
600
601         /* XDP */
602         struct bpf_prog       *xdp_prog;
603         struct mlx5e_xdpsq    *xdpsq;
604         DECLARE_BITMAP(flags, 8);
605         struct page_pool      *page_pool;
606
607         /* AF_XDP zero-copy */
608         struct xdp_umem       *umem;
609
610         struct work_struct     recover_work;
611
612         /* control */
613         struct mlx5_wq_ctrl    wq_ctrl;
614         __be32                 mkey_be;
615         u8                     wq_type;
616         u32                    rqn;
617         struct mlx5_core_dev  *mdev;
618         struct mlx5_core_mkey  umr_mkey;
619
620         /* XDP read-mostly */
621         struct xdp_rxq_info    xdp_rxq;
622 } ____cacheline_aligned_in_smp;
623
624 enum mlx5e_channel_state {
625         MLX5E_CHANNEL_STATE_XSK,
626         MLX5E_CHANNEL_NUM_STATES
627 };
628
629 struct mlx5e_channel {
630         /* data path */
631         struct mlx5e_rq            rq;
632         struct mlx5e_xdpsq         rq_xdpsq;
633         struct mlx5e_txqsq         sq[MLX5E_MAX_NUM_TC];
634         struct mlx5e_icosq         icosq;   /* internal control operations */
635         bool                       xdp;
636         struct napi_struct         napi;
637         struct device             *pdev;
638         struct net_device         *netdev;
639         __be32                     mkey_be;
640         u8                         num_tc;
641         u8                         lag_port;
642
643         /* XDP_REDIRECT */
644         struct mlx5e_xdpsq         xdpsq;
645
646         /* AF_XDP zero-copy */
647         struct mlx5e_rq            xskrq;
648         struct mlx5e_xdpsq         xsksq;
649
650         /* Async ICOSQ */
651         struct mlx5e_icosq         async_icosq;
652         /* async_icosq can be accessed from any CPU - the spinlock protects it. */
653         spinlock_t                 async_icosq_lock;
654
655         /* data path - accessed per napi poll */
656         struct irq_desc *irq_desc;
657         struct mlx5e_ch_stats     *stats;
658
659         /* control */
660         struct mlx5e_priv         *priv;
661         struct mlx5_core_dev      *mdev;
662         struct hwtstamp_config    *tstamp;
663         DECLARE_BITMAP(state, MLX5E_CHANNEL_NUM_STATES);
664         int                        ix;
665         int                        cpu;
666 };
667
668 struct mlx5e_channels {
669         struct mlx5e_channel **c;
670         unsigned int           num;
671         struct mlx5e_params    params;
672 };
673
674 struct mlx5e_channel_stats {
675         struct mlx5e_ch_stats ch;
676         struct mlx5e_sq_stats sq[MLX5E_MAX_NUM_TC];
677         struct mlx5e_rq_stats rq;
678         struct mlx5e_rq_stats xskrq;
679         struct mlx5e_xdpsq_stats rq_xdpsq;
680         struct mlx5e_xdpsq_stats xdpsq;
681         struct mlx5e_xdpsq_stats xsksq;
682 } ____cacheline_aligned_in_smp;
683
684 enum {
685         MLX5E_STATE_OPENED,
686         MLX5E_STATE_DESTROYING,
687         MLX5E_STATE_XDP_TX_ENABLED,
688         MLX5E_STATE_XDP_ACTIVE,
689 };
690
691 struct mlx5e_rqt {
692         u32              rqtn;
693         bool             enabled;
694 };
695
696 struct mlx5e_tir {
697         u32               tirn;
698         struct mlx5e_rqt  rqt;
699         struct list_head  list;
700 };
701
702 enum {
703         MLX5E_TC_PRIO = 0,
704         MLX5E_NIC_PRIO
705 };
706
707 struct mlx5e_rss_params {
708         u32     indirection_rqt[MLX5E_INDIR_RQT_SIZE];
709         u32     rx_hash_fields[MLX5E_NUM_INDIR_TIRS];
710         u8      toeplitz_hash_key[40];
711         u8      hfunc;
712 };
713
714 struct mlx5e_modify_sq_param {
715         int curr_state;
716         int next_state;
717         int rl_update;
718         int rl_index;
719 };
720
721 #if IS_ENABLED(CONFIG_PCI_HYPERV_INTERFACE)
722 struct mlx5e_hv_vhca_stats_agent {
723         struct mlx5_hv_vhca_agent *agent;
724         struct delayed_work        work;
725         u16                        delay;
726         void                      *buf;
727 };
728 #endif
729
730 struct mlx5e_xsk {
731         /* UMEMs are stored separately from channels, because we don't want to
732          * lose them when channels are recreated. The kernel also stores UMEMs,
733          * but it doesn't distinguish between zero-copy and non-zero-copy UMEMs,
734          * so rely on our mechanism.
735          */
736         struct xdp_umem **umems;
737         u16 refcnt;
738         bool ever_used;
739 };
740
741 /* Temporary storage for variables that are allocated when struct mlx5e_priv is
742  * initialized, and used where we can't allocate them because that functions
743  * must not fail. Use with care and make sure the same variable is not used
744  * simultaneously by multiple users.
745  */
746 struct mlx5e_scratchpad {
747         cpumask_var_t cpumask;
748 };
749
750 struct mlx5e_priv {
751         /* priv data path fields - start */
752         struct mlx5e_txqsq *txq2sq[MLX5E_MAX_NUM_CHANNELS * MLX5E_MAX_NUM_TC];
753         int channel_tc2realtxq[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
754 #ifdef CONFIG_MLX5_CORE_EN_DCB
755         struct mlx5e_dcbx_dp       dcbx_dp;
756 #endif
757         /* priv data path fields - end */
758
759         u32                        msglevel;
760         unsigned long              state;
761         struct mutex               state_lock; /* Protects Interface state */
762         struct mlx5e_rq            drop_rq;
763
764         struct mlx5e_channels      channels;
765         u32                        tisn[MLX5_MAX_PORTS][MLX5E_MAX_NUM_TC];
766         struct mlx5e_rqt           indir_rqt;
767         struct mlx5e_tir           indir_tir[MLX5E_NUM_INDIR_TIRS];
768         struct mlx5e_tir           inner_indir_tir[MLX5E_NUM_INDIR_TIRS];
769         struct mlx5e_tir           direct_tir[MLX5E_MAX_NUM_CHANNELS];
770         struct mlx5e_tir           xsk_tir[MLX5E_MAX_NUM_CHANNELS];
771         struct mlx5e_rss_params    rss_params;
772         u32                        tx_rates[MLX5E_MAX_NUM_SQS];
773
774         struct mlx5e_flow_steering fs;
775
776         struct workqueue_struct    *wq;
777         struct work_struct         update_carrier_work;
778         struct work_struct         set_rx_mode_work;
779         struct work_struct         tx_timeout_work;
780         struct work_struct         update_stats_work;
781         struct work_struct         monitor_counters_work;
782         struct mlx5_nb             monitor_counters_nb;
783
784         struct mlx5_core_dev      *mdev;
785         struct net_device         *netdev;
786         struct mlx5e_stats         stats;
787         struct mlx5e_channel_stats channel_stats[MLX5E_MAX_NUM_CHANNELS];
788         u16                        max_nch;
789         u8                         max_opened_tc;
790         struct hwtstamp_config     tstamp;
791         u16                        q_counter;
792         u16                        drop_rq_q_counter;
793         struct notifier_block      events_nb;
794
795 #ifdef CONFIG_MLX5_CORE_EN_DCB
796         struct mlx5e_dcbx          dcbx;
797 #endif
798
799         const struct mlx5e_profile *profile;
800         void                      *ppriv;
801 #ifdef CONFIG_MLX5_EN_IPSEC
802         struct mlx5e_ipsec        *ipsec;
803 #endif
804 #ifdef CONFIG_MLX5_EN_TLS
805         struct mlx5e_tls          *tls;
806 #endif
807         struct devlink_health_reporter *tx_reporter;
808         struct devlink_health_reporter *rx_reporter;
809         struct devlink_port            dl_port;
810         struct mlx5e_xsk           xsk;
811 #if IS_ENABLED(CONFIG_PCI_HYPERV_INTERFACE)
812         struct mlx5e_hv_vhca_stats_agent stats_agent;
813 #endif
814         struct mlx5e_scratchpad    scratchpad;
815 };
816
817 struct mlx5e_rx_handlers {
818         mlx5e_fp_handle_rx_cqe handle_rx_cqe;
819         mlx5e_fp_handle_rx_cqe handle_rx_cqe_mpwqe;
820 };
821
822 extern const struct mlx5e_rx_handlers mlx5e_rx_handlers_nic;
823
824 struct mlx5e_profile {
825         int     (*init)(struct mlx5_core_dev *mdev,
826                         struct net_device *netdev,
827                         const struct mlx5e_profile *profile, void *ppriv);
828         void    (*cleanup)(struct mlx5e_priv *priv);
829         int     (*init_rx)(struct mlx5e_priv *priv);
830         void    (*cleanup_rx)(struct mlx5e_priv *priv);
831         int     (*init_tx)(struct mlx5e_priv *priv);
832         void    (*cleanup_tx)(struct mlx5e_priv *priv);
833         void    (*enable)(struct mlx5e_priv *priv);
834         void    (*disable)(struct mlx5e_priv *priv);
835         int     (*update_rx)(struct mlx5e_priv *priv);
836         void    (*update_stats)(struct mlx5e_priv *priv);
837         void    (*update_carrier)(struct mlx5e_priv *priv);
838         unsigned int (*stats_grps_num)(struct mlx5e_priv *priv);
839         mlx5e_stats_grp_t *stats_grps;
840         const struct mlx5e_rx_handlers *rx_handlers;
841         int     max_tc;
842         u8      rq_groups;
843 };
844
845 void mlx5e_build_ptys2ethtool_map(void);
846
847 bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev);
848 bool mlx5e_striding_rq_possible(struct mlx5_core_dev *mdev,
849                                 struct mlx5e_params *params);
850
851 void mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats);
852 void mlx5e_fold_sw_stats64(struct mlx5e_priv *priv, struct rtnl_link_stats64 *s);
853
854 void mlx5e_init_l2_addr(struct mlx5e_priv *priv);
855 int mlx5e_self_test_num(struct mlx5e_priv *priv);
856 void mlx5e_self_test(struct net_device *ndev, struct ethtool_test *etest,
857                      u64 *buf);
858 void mlx5e_set_rx_mode_work(struct work_struct *work);
859
860 int mlx5e_hwstamp_set(struct mlx5e_priv *priv, struct ifreq *ifr);
861 int mlx5e_hwstamp_get(struct mlx5e_priv *priv, struct ifreq *ifr);
862 int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool val);
863
864 int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
865                           u16 vid);
866 int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
867                            u16 vid);
868 void mlx5e_timestamp_init(struct mlx5e_priv *priv);
869
870 struct mlx5e_redirect_rqt_param {
871         bool is_rss;
872         union {
873                 u32 rqn; /* Direct RQN (Non-RSS) */
874                 struct {
875                         u8 hfunc;
876                         struct mlx5e_channels *channels;
877                 } rss; /* RSS data */
878         };
879 };
880
881 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, u32 rqtn, int sz,
882                        struct mlx5e_redirect_rqt_param rrp);
883 void mlx5e_build_indir_tir_ctx_hash(struct mlx5e_rss_params *rss_params,
884                                     const struct mlx5e_tirc_config *ttconfig,
885                                     void *tirc, bool inner);
886 void mlx5e_modify_tirs_hash(struct mlx5e_priv *priv, void *in);
887 struct mlx5e_tirc_config mlx5e_tirc_get_default_config(enum mlx5e_traffic_types tt);
888
889 struct mlx5e_xsk_param;
890
891 struct mlx5e_rq_param;
892 int mlx5e_open_rq(struct mlx5e_channel *c, struct mlx5e_params *params,
893                   struct mlx5e_rq_param *param, struct mlx5e_xsk_param *xsk,
894                   struct xdp_umem *umem, struct mlx5e_rq *rq);
895 int mlx5e_wait_for_min_rx_wqes(struct mlx5e_rq *rq, int wait_time);
896 void mlx5e_deactivate_rq(struct mlx5e_rq *rq);
897 void mlx5e_close_rq(struct mlx5e_rq *rq);
898
899 struct mlx5e_sq_param;
900 int mlx5e_open_icosq(struct mlx5e_channel *c, struct mlx5e_params *params,
901                      struct mlx5e_sq_param *param, struct mlx5e_icosq *sq);
902 void mlx5e_close_icosq(struct mlx5e_icosq *sq);
903 int mlx5e_open_xdpsq(struct mlx5e_channel *c, struct mlx5e_params *params,
904                      struct mlx5e_sq_param *param, struct xdp_umem *umem,
905                      struct mlx5e_xdpsq *sq, bool is_redirect);
906 void mlx5e_close_xdpsq(struct mlx5e_xdpsq *sq);
907
908 struct mlx5e_cq_param;
909 int mlx5e_open_cq(struct mlx5e_channel *c, struct dim_cq_moder moder,
910                   struct mlx5e_cq_param *param, struct mlx5e_cq *cq);
911 void mlx5e_close_cq(struct mlx5e_cq *cq);
912
913 int mlx5e_open_locked(struct net_device *netdev);
914 int mlx5e_close_locked(struct net_device *netdev);
915
916 int mlx5e_open_channels(struct mlx5e_priv *priv,
917                         struct mlx5e_channels *chs);
918 void mlx5e_close_channels(struct mlx5e_channels *chs);
919
920 /* Function pointer to be used to modify HW or kernel settings while
921  * switching channels
922  */
923 typedef int (*mlx5e_fp_preactivate)(struct mlx5e_priv *priv, void *context);
924 #define MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX(fn) \
925 int fn##_ctx(struct mlx5e_priv *priv, void *context) \
926 { \
927         return fn(priv); \
928 }
929 int mlx5e_safe_reopen_channels(struct mlx5e_priv *priv);
930 int mlx5e_safe_switch_channels(struct mlx5e_priv *priv,
931                                struct mlx5e_channels *new_chs,
932                                mlx5e_fp_preactivate preactivate,
933                                void *context);
934 int mlx5e_num_channels_changed(struct mlx5e_priv *priv);
935 int mlx5e_num_channels_changed_ctx(struct mlx5e_priv *priv, void *context);
936 void mlx5e_activate_priv_channels(struct mlx5e_priv *priv);
937 void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv);
938
939 void mlx5e_build_default_indir_rqt(u32 *indirection_rqt, int len,
940                                    int num_channels);
941
942 void mlx5e_reset_tx_moderation(struct mlx5e_params *params, u8 cq_period_mode);
943 void mlx5e_reset_rx_moderation(struct mlx5e_params *params, u8 cq_period_mode);
944 void mlx5e_set_tx_cq_mode_params(struct mlx5e_params *params, u8 cq_period_mode);
945 void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params, u8 cq_period_mode);
946
947 void mlx5e_set_rq_type(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
948 void mlx5e_init_rq_type_params(struct mlx5_core_dev *mdev,
949                                struct mlx5e_params *params);
950 int mlx5e_modify_rq_state(struct mlx5e_rq *rq, int curr_state, int next_state);
951 void mlx5e_activate_rq(struct mlx5e_rq *rq);
952 void mlx5e_deactivate_rq(struct mlx5e_rq *rq);
953 void mlx5e_activate_icosq(struct mlx5e_icosq *icosq);
954 void mlx5e_deactivate_icosq(struct mlx5e_icosq *icosq);
955
956 int mlx5e_modify_sq(struct mlx5_core_dev *mdev, u32 sqn,
957                     struct mlx5e_modify_sq_param *p);
958 void mlx5e_activate_txqsq(struct mlx5e_txqsq *sq);
959 void mlx5e_tx_disable_queue(struct netdev_queue *txq);
960
961 static inline bool mlx5_tx_swp_supported(struct mlx5_core_dev *mdev)
962 {
963         return MLX5_CAP_ETH(mdev, swp) &&
964                 MLX5_CAP_ETH(mdev, swp_csum) && MLX5_CAP_ETH(mdev, swp_lso);
965 }
966
967 extern const struct ethtool_ops mlx5e_ethtool_ops;
968
969 int mlx5e_create_tir(struct mlx5_core_dev *mdev, struct mlx5e_tir *tir,
970                      u32 *in);
971 void mlx5e_destroy_tir(struct mlx5_core_dev *mdev,
972                        struct mlx5e_tir *tir);
973 int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev);
974 void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev);
975 int mlx5e_refresh_tirs(struct mlx5e_priv *priv, bool enable_uc_lb,
976                        bool enable_mc_lb);
977 void mlx5e_mkey_set_relaxed_ordering(struct mlx5_core_dev *mdev, void *mkc);
978
979 /* common netdev helpers */
980 void mlx5e_create_q_counters(struct mlx5e_priv *priv);
981 void mlx5e_destroy_q_counters(struct mlx5e_priv *priv);
982 int mlx5e_open_drop_rq(struct mlx5e_priv *priv,
983                        struct mlx5e_rq *drop_rq);
984 void mlx5e_close_drop_rq(struct mlx5e_rq *drop_rq);
985
986 int mlx5e_create_indirect_rqt(struct mlx5e_priv *priv);
987
988 int mlx5e_create_indirect_tirs(struct mlx5e_priv *priv, bool inner_ttc);
989 void mlx5e_destroy_indirect_tirs(struct mlx5e_priv *priv);
990
991 int mlx5e_create_direct_rqts(struct mlx5e_priv *priv, struct mlx5e_tir *tirs);
992 void mlx5e_destroy_direct_rqts(struct mlx5e_priv *priv, struct mlx5e_tir *tirs);
993 int mlx5e_create_direct_tirs(struct mlx5e_priv *priv, struct mlx5e_tir *tirs);
994 void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv, struct mlx5e_tir *tirs);
995 void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt);
996
997 int mlx5e_create_tis(struct mlx5_core_dev *mdev, void *in, u32 *tisn);
998 void mlx5e_destroy_tis(struct mlx5_core_dev *mdev, u32 tisn);
999
1000 int mlx5e_create_tises(struct mlx5e_priv *priv);
1001 void mlx5e_destroy_tises(struct mlx5e_priv *priv);
1002 int mlx5e_update_nic_rx(struct mlx5e_priv *priv);
1003 void mlx5e_update_carrier(struct mlx5e_priv *priv);
1004 int mlx5e_close(struct net_device *netdev);
1005 int mlx5e_open(struct net_device *netdev);
1006 void mlx5e_update_ndo_stats(struct mlx5e_priv *priv);
1007
1008 void mlx5e_queue_update_stats(struct mlx5e_priv *priv);
1009 int mlx5e_bits_invert(unsigned long a, int size);
1010
1011 int mlx5e_set_dev_port_mtu(struct mlx5e_priv *priv);
1012 int mlx5e_set_dev_port_mtu_ctx(struct mlx5e_priv *priv, void *context);
1013 int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,
1014                      mlx5e_fp_preactivate preactivate);
1015
1016 /* ethtool helpers */
1017 void mlx5e_ethtool_get_drvinfo(struct mlx5e_priv *priv,
1018                                struct ethtool_drvinfo *drvinfo);
1019 void mlx5e_ethtool_get_strings(struct mlx5e_priv *priv,
1020                                uint32_t stringset, uint8_t *data);
1021 int mlx5e_ethtool_get_sset_count(struct mlx5e_priv *priv, int sset);
1022 void mlx5e_ethtool_get_ethtool_stats(struct mlx5e_priv *priv,
1023                                      struct ethtool_stats *stats, u64 *data);
1024 void mlx5e_ethtool_get_ringparam(struct mlx5e_priv *priv,
1025                                  struct ethtool_ringparam *param);
1026 int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
1027                                 struct ethtool_ringparam *param);
1028 void mlx5e_ethtool_get_channels(struct mlx5e_priv *priv,
1029                                 struct ethtool_channels *ch);
1030 int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,
1031                                struct ethtool_channels *ch);
1032 int mlx5e_ethtool_get_coalesce(struct mlx5e_priv *priv,
1033                                struct ethtool_coalesce *coal);
1034 int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
1035                                struct ethtool_coalesce *coal);
1036 int mlx5e_ethtool_get_link_ksettings(struct mlx5e_priv *priv,
1037                                      struct ethtool_link_ksettings *link_ksettings);
1038 int mlx5e_ethtool_set_link_ksettings(struct mlx5e_priv *priv,
1039                                      const struct ethtool_link_ksettings *link_ksettings);
1040 int mlx5e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc);
1041 int mlx5e_set_rxfh(struct net_device *dev, const u32 *indir, const u8 *key,
1042                    const u8 hfunc);
1043 int mlx5e_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1044                     u32 *rule_locs);
1045 int mlx5e_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
1046 u32 mlx5e_ethtool_get_rxfh_key_size(struct mlx5e_priv *priv);
1047 u32 mlx5e_ethtool_get_rxfh_indir_size(struct mlx5e_priv *priv);
1048 int mlx5e_ethtool_get_ts_info(struct mlx5e_priv *priv,
1049                               struct ethtool_ts_info *info);
1050 int mlx5e_ethtool_flash_device(struct mlx5e_priv *priv,
1051                                struct ethtool_flash *flash);
1052 void mlx5e_ethtool_get_pauseparam(struct mlx5e_priv *priv,
1053                                   struct ethtool_pauseparam *pauseparam);
1054 int mlx5e_ethtool_set_pauseparam(struct mlx5e_priv *priv,
1055                                  struct ethtool_pauseparam *pauseparam);
1056
1057 /* mlx5e generic netdev management API */
1058 int mlx5e_netdev_init(struct net_device *netdev,
1059                       struct mlx5e_priv *priv,
1060                       struct mlx5_core_dev *mdev,
1061                       const struct mlx5e_profile *profile,
1062                       void *ppriv);
1063 void mlx5e_netdev_cleanup(struct net_device *netdev, struct mlx5e_priv *priv);
1064 struct net_device*
1065 mlx5e_create_netdev(struct mlx5_core_dev *mdev, const struct mlx5e_profile *profile,
1066                     int nch, void *ppriv);
1067 int mlx5e_attach_netdev(struct mlx5e_priv *priv);
1068 void mlx5e_detach_netdev(struct mlx5e_priv *priv);
1069 void mlx5e_destroy_netdev(struct mlx5e_priv *priv);
1070 void mlx5e_set_netdev_mtu_boundaries(struct mlx5e_priv *priv);
1071 void mlx5e_build_nic_params(struct mlx5e_priv *priv,
1072                             struct mlx5e_xsk *xsk,
1073                             struct mlx5e_rss_params *rss_params,
1074                             struct mlx5e_params *params,
1075                             u16 mtu);
1076 void mlx5e_build_rq_params(struct mlx5_core_dev *mdev,
1077                            struct mlx5e_params *params);
1078 void mlx5e_build_rss_params(struct mlx5e_rss_params *rss_params,
1079                             u16 num_channels);
1080 void mlx5e_rx_dim_work(struct work_struct *work);
1081 void mlx5e_tx_dim_work(struct work_struct *work);
1082
1083 void mlx5e_add_vxlan_port(struct net_device *netdev, struct udp_tunnel_info *ti);
1084 void mlx5e_del_vxlan_port(struct net_device *netdev, struct udp_tunnel_info *ti);
1085 netdev_features_t mlx5e_features_check(struct sk_buff *skb,
1086                                        struct net_device *netdev,
1087                                        netdev_features_t features);
1088 int mlx5e_set_features(struct net_device *netdev, netdev_features_t features);
1089 #ifdef CONFIG_MLX5_ESWITCH
1090 int mlx5e_set_vf_mac(struct net_device *dev, int vf, u8 *mac);
1091 int mlx5e_set_vf_rate(struct net_device *dev, int vf, int min_tx_rate, int max_tx_rate);
1092 int mlx5e_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_info *ivi);
1093 int mlx5e_get_vf_stats(struct net_device *dev, int vf, struct ifla_vf_stats *vf_stats);
1094 #endif
1095 #endif /* __MLX5_EN_H__ */