5e8e669f69c0ebc34f2c30cbc9e52e5c96be5835
[cascardo/linux.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/ptp_clock_kernel.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/rhashtable.h>
47 #include <net/switchdev.h>
48 #include "wq.h"
49 #include "mlx5_core.h"
50 #include "en_stats.h"
51
52 #define MLX5_SET_CFG(p, f, v) MLX5_SET(create_flow_group_in, p, f, v)
53
54 #define MLX5E_MAX_NUM_TC        8
55
56 #define MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE                0x6
57 #define MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE                0xa
58 #define MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE                0xd
59
60 #define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE                0x1
61 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE                0xa
62 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE                0xd
63
64 #define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW            0x1
65 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE_MPW            0x3
66 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW            0x6
67
68 #define MLX5_RX_HEADROOM NET_SKB_PAD
69
70 #define MLX5_MPWRQ_LOG_STRIDE_SIZE              6  /* >= 6, HW restriction */
71 #define MLX5_MPWRQ_LOG_STRIDE_SIZE_CQE_COMPRESS 8  /* >= 6, HW restriction */
72 #define MLX5_MPWRQ_LOG_WQE_SZ                   18
73 #define MLX5_MPWRQ_WQE_PAGE_ORDER  (MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT > 0 ? \
74                                     MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT : 0)
75 #define MLX5_MPWRQ_PAGES_PER_WQE                BIT(MLX5_MPWRQ_WQE_PAGE_ORDER)
76 #define MLX5_MPWRQ_STRIDES_PER_PAGE             (MLX5_MPWRQ_NUM_STRIDES >> \
77                                                  MLX5_MPWRQ_WQE_PAGE_ORDER)
78
79 #define MLX5_MTT_OCTW(npages) (ALIGN(npages, 8) / 2)
80 #define MLX5E_REQUIRED_MTTS(rqs, wqes)\
81         (rqs * wqes * ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8))
82 #define MLX5E_VALID_NUM_MTTS(num_mtts) (MLX5_MTT_OCTW(num_mtts) <= U16_MAX)
83
84 #define MLX5_UMR_ALIGN                          (2048)
85 #define MLX5_MPWRQ_SMALL_PACKET_THRESHOLD       (128)
86
87 #define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ                 (64 * 1024)
88 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC      0x10
89 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE 0x3
90 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS      0x20
91 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC      0x10
92 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS      0x20
93 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES                0x80
94 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW            0x2
95
96 #define MLX5E_LOG_INDIR_RQT_SIZE       0x7
97 #define MLX5E_INDIR_RQT_SIZE           BIT(MLX5E_LOG_INDIR_RQT_SIZE)
98 #define MLX5E_MAX_NUM_CHANNELS         (MLX5E_INDIR_RQT_SIZE >> 1)
99 #define MLX5E_MAX_NUM_SQS              (MLX5E_MAX_NUM_CHANNELS * MLX5E_MAX_NUM_TC)
100 #define MLX5E_TX_CQ_POLL_BUDGET        128
101 #define MLX5E_UPDATE_STATS_INTERVAL    200 /* msecs */
102 #define MLX5E_SQ_BF_BUDGET             16
103
104 #define MLX5E_NUM_MAIN_GROUPS 9
105
106 static inline u16 mlx5_min_rx_wqes(int wq_type, u32 wq_size)
107 {
108         switch (wq_type) {
109         case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
110                 return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW,
111                              wq_size / 2);
112         default:
113                 return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES,
114                              wq_size / 2);
115         }
116 }
117
118 static inline int mlx5_min_log_rq_size(int wq_type)
119 {
120         switch (wq_type) {
121         case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
122                 return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW;
123         default:
124                 return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE;
125         }
126 }
127
128 static inline int mlx5_max_log_rq_size(int wq_type)
129 {
130         switch (wq_type) {
131         case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
132                 return MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW;
133         default:
134                 return MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE;
135         }
136 }
137
138 enum {
139         MLX5E_INLINE_MODE_L2,
140         MLX5E_INLINE_MODE_VPORT_CONTEXT,
141         MLX5_INLINE_MODE_NOT_REQUIRED,
142 };
143
144 struct mlx5e_tx_wqe {
145         struct mlx5_wqe_ctrl_seg ctrl;
146         struct mlx5_wqe_eth_seg  eth;
147 };
148
149 struct mlx5e_rx_wqe {
150         struct mlx5_wqe_srq_next_seg  next;
151         struct mlx5_wqe_data_seg      data;
152 };
153
154 struct mlx5e_umr_wqe {
155         struct mlx5_wqe_ctrl_seg       ctrl;
156         struct mlx5_wqe_umr_ctrl_seg   uctrl;
157         struct mlx5_mkey_seg           mkc;
158         struct mlx5_wqe_data_seg       data;
159 };
160
161 static const char mlx5e_priv_flags[][ETH_GSTRING_LEN] = {
162         "rx_cqe_moder",
163 };
164
165 enum mlx5e_priv_flag {
166         MLX5E_PFLAG_RX_CQE_BASED_MODER = (1 << 0),
167 };
168
169 #define MLX5E_SET_PRIV_FLAG(priv, pflag, enable)    \
170         do {                                        \
171                 if (enable)                         \
172                         priv->pflags |= pflag;      \
173                 else                                \
174                         priv->pflags &= ~pflag;     \
175         } while (0)
176
177 #ifdef CONFIG_MLX5_CORE_EN_DCB
178 #define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */
179 #endif
180
181 struct mlx5e_cq_moder {
182         u16 usec;
183         u16 pkts;
184 };
185
186 struct mlx5e_params {
187         u8  log_sq_size;
188         u8  rq_wq_type;
189         u8  mpwqe_log_stride_sz;
190         u8  mpwqe_log_num_strides;
191         u8  log_rq_size;
192         u16 num_channels;
193         u8  num_tc;
194         u8  rx_cq_period_mode;
195         bool rx_cqe_compress_admin;
196         bool rx_cqe_compress;
197         struct mlx5e_cq_moder rx_cq_moderation;
198         struct mlx5e_cq_moder tx_cq_moderation;
199         u16 min_rx_wqes;
200         bool lro_en;
201         u32 lro_wqe_sz;
202         u16 tx_max_inline;
203         u8  tx_min_inline_mode;
204         u8  rss_hfunc;
205         u8  toeplitz_hash_key[40];
206         u32 indirection_rqt[MLX5E_INDIR_RQT_SIZE];
207         bool vlan_strip_disable;
208 #ifdef CONFIG_MLX5_CORE_EN_DCB
209         struct ieee_ets ets;
210 #endif
211         bool rx_am_enabled;
212 };
213
214 struct mlx5e_tstamp {
215         rwlock_t                   lock;
216         struct cyclecounter        cycles;
217         struct timecounter         clock;
218         struct hwtstamp_config     hwtstamp_config;
219         u32                        nominal_c_mult;
220         unsigned long              overflow_period;
221         struct delayed_work        overflow_work;
222         struct mlx5_core_dev      *mdev;
223         struct ptp_clock          *ptp;
224         struct ptp_clock_info      ptp_info;
225 };
226
227 enum {
228         MLX5E_RQ_STATE_FLUSH,
229         MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS,
230         MLX5E_RQ_STATE_AM,
231 };
232
233 struct mlx5e_cq {
234         /* data path - accessed per cqe */
235         struct mlx5_cqwq           wq;
236
237         /* data path - accessed per napi poll */
238         u16                        event_ctr;
239         struct napi_struct        *napi;
240         struct mlx5_core_cq        mcq;
241         struct mlx5e_channel      *channel;
242         struct mlx5e_priv         *priv;
243
244         /* cqe decompression */
245         struct mlx5_cqe64          title;
246         struct mlx5_mini_cqe8      mini_arr[MLX5_MINI_CQE_ARRAY_SIZE];
247         u8                         mini_arr_idx;
248         u16                        decmprs_left;
249         u16                        decmprs_wqe_counter;
250
251         /* control */
252         struct mlx5_wq_ctrl        wq_ctrl;
253 } ____cacheline_aligned_in_smp;
254
255 struct mlx5e_rq;
256 typedef void (*mlx5e_fp_handle_rx_cqe)(struct mlx5e_rq *rq,
257                                        struct mlx5_cqe64 *cqe);
258 typedef int (*mlx5e_fp_alloc_wqe)(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe,
259                                   u16 ix);
260
261 typedef void (*mlx5e_fp_dealloc_wqe)(struct mlx5e_rq *rq, u16 ix);
262
263 struct mlx5e_dma_info {
264         struct page     *page;
265         dma_addr_t      addr;
266 };
267
268 struct mlx5e_rx_am_stats {
269         int ppms; /* packets per msec */
270         int epms; /* events per msec */
271 };
272
273 struct mlx5e_rx_am_sample {
274         ktime_t         time;
275         unsigned int    pkt_ctr;
276         u16             event_ctr;
277 };
278
279 struct mlx5e_rx_am { /* Adaptive Moderation */
280         u8                                      state;
281         struct mlx5e_rx_am_stats                prev_stats;
282         struct mlx5e_rx_am_sample               start_sample;
283         struct work_struct                      work;
284         u8                                      profile_ix;
285         u8                                      mode;
286         u8                                      tune_state;
287         u8                                      steps_right;
288         u8                                      steps_left;
289         u8                                      tired;
290 };
291
292 /* a single cache unit is capable to serve one napi call (for non-striding rq)
293  * or a MPWQE (for striding rq).
294  */
295 #define MLX5E_CACHE_UNIT        (MLX5_MPWRQ_PAGES_PER_WQE > NAPI_POLL_WEIGHT ? \
296                                  MLX5_MPWRQ_PAGES_PER_WQE : NAPI_POLL_WEIGHT)
297 #define MLX5E_CACHE_SIZE        (2 * roundup_pow_of_two(MLX5E_CACHE_UNIT))
298 struct mlx5e_page_cache {
299         u32 head;
300         u32 tail;
301         struct mlx5e_dma_info page_cache[MLX5E_CACHE_SIZE];
302 };
303
304 struct mlx5e_rq {
305         /* data path */
306         struct mlx5_wq_ll      wq;
307
308         union {
309                 struct mlx5e_dma_info *dma_info;
310                 struct {
311                         struct mlx5e_mpw_info *info;
312                         void                  *mtt_no_align;
313                         u32                    mtt_offset;
314                 } mpwqe;
315         };
316         struct {
317                 u8             page_order;
318                 u32            wqe_sz;    /* wqe data buffer size */
319         } buff;
320         __be32                 mkey_be;
321
322         struct device         *pdev;
323         struct net_device     *netdev;
324         struct mlx5e_tstamp   *tstamp;
325         struct mlx5e_rq_stats  stats;
326         struct mlx5e_cq        cq;
327         struct mlx5e_page_cache page_cache;
328
329         mlx5e_fp_handle_rx_cqe handle_rx_cqe;
330         mlx5e_fp_alloc_wqe     alloc_wqe;
331         mlx5e_fp_dealloc_wqe   dealloc_wqe;
332
333         unsigned long          state;
334         int                    ix;
335
336         struct mlx5e_rx_am     am; /* Adaptive Moderation */
337         struct bpf_prog       *xdp_prog;
338
339         /* control */
340         struct mlx5_wq_ctrl    wq_ctrl;
341         u8                     wq_type;
342         u32                    mpwqe_stride_sz;
343         u32                    mpwqe_num_strides;
344         u32                    rqn;
345         struct mlx5e_channel  *channel;
346         struct mlx5e_priv     *priv;
347 } ____cacheline_aligned_in_smp;
348
349 struct mlx5e_umr_dma_info {
350         __be64                *mtt;
351         dma_addr_t             mtt_addr;
352         struct mlx5e_dma_info  dma_info[MLX5_MPWRQ_PAGES_PER_WQE];
353         struct mlx5e_umr_wqe   wqe;
354 };
355
356 struct mlx5e_mpw_info {
357         struct mlx5e_umr_dma_info umr;
358         u16 consumed_strides;
359         u16 skbs_frags[MLX5_MPWRQ_PAGES_PER_WQE];
360 };
361
362 struct mlx5e_tx_wqe_info {
363         u32 num_bytes;
364         u8  num_wqebbs;
365         u8  num_dma;
366 };
367
368 enum mlx5e_dma_map_type {
369         MLX5E_DMA_MAP_SINGLE,
370         MLX5E_DMA_MAP_PAGE
371 };
372
373 struct mlx5e_sq_dma {
374         dma_addr_t              addr;
375         u32                     size;
376         enum mlx5e_dma_map_type type;
377 };
378
379 enum {
380         MLX5E_SQ_STATE_FLUSH,
381         MLX5E_SQ_STATE_BF_ENABLE,
382 };
383
384 struct mlx5e_ico_wqe_info {
385         u8  opcode;
386         u8  num_wqebbs;
387 };
388
389 struct mlx5e_sq {
390         /* data path */
391
392         /* dirtied @completion */
393         u16                        cc;
394         u32                        dma_fifo_cc;
395
396         /* dirtied @xmit */
397         u16                        pc ____cacheline_aligned_in_smp;
398         u32                        dma_fifo_pc;
399         u16                        bf_offset;
400         u16                        prev_cc;
401         u8                         bf_budget;
402         struct mlx5e_sq_stats      stats;
403
404         struct mlx5e_cq            cq;
405
406         /* pointers to per packet info: write@xmit, read@completion */
407         struct sk_buff           **skb;
408         struct mlx5e_sq_dma       *dma_fifo;
409         struct mlx5e_tx_wqe_info  *wqe_info;
410
411         /* read only */
412         struct mlx5_wq_cyc         wq;
413         u32                        dma_fifo_mask;
414         void __iomem              *uar_map;
415         struct netdev_queue       *txq;
416         u32                        sqn;
417         u16                        bf_buf_size;
418         u16                        max_inline;
419         u8                         min_inline_mode;
420         u16                        edge;
421         struct device             *pdev;
422         struct mlx5e_tstamp       *tstamp;
423         __be32                     mkey_be;
424         unsigned long              state;
425
426         /* control path */
427         struct mlx5_wq_ctrl        wq_ctrl;
428         struct mlx5_uar            uar;
429         struct mlx5e_channel      *channel;
430         int                        tc;
431         struct mlx5e_ico_wqe_info *ico_wqe_info;
432         u32                        rate_limit;
433 } ____cacheline_aligned_in_smp;
434
435 static inline bool mlx5e_sq_has_room_for(struct mlx5e_sq *sq, u16 n)
436 {
437         return (((sq->wq.sz_m1 & (sq->cc - sq->pc)) >= n) ||
438                 (sq->cc  == sq->pc));
439 }
440
441 enum channel_flags {
442         MLX5E_CHANNEL_NAPI_SCHED = 1,
443 };
444
445 struct mlx5e_channel {
446         /* data path */
447         struct mlx5e_rq            rq;
448         struct mlx5e_sq            sq[MLX5E_MAX_NUM_TC];
449         struct mlx5e_sq            icosq;   /* internal control operations */
450         struct napi_struct         napi;
451         struct device             *pdev;
452         struct net_device         *netdev;
453         __be32                     mkey_be;
454         u8                         num_tc;
455         unsigned long              flags;
456
457         /* control */
458         struct mlx5e_priv         *priv;
459         int                        ix;
460         int                        cpu;
461 };
462
463 enum mlx5e_traffic_types {
464         MLX5E_TT_IPV4_TCP,
465         MLX5E_TT_IPV6_TCP,
466         MLX5E_TT_IPV4_UDP,
467         MLX5E_TT_IPV6_UDP,
468         MLX5E_TT_IPV4_IPSEC_AH,
469         MLX5E_TT_IPV6_IPSEC_AH,
470         MLX5E_TT_IPV4_IPSEC_ESP,
471         MLX5E_TT_IPV6_IPSEC_ESP,
472         MLX5E_TT_IPV4,
473         MLX5E_TT_IPV6,
474         MLX5E_TT_ANY,
475         MLX5E_NUM_TT,
476         MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
477 };
478
479 enum {
480         MLX5E_STATE_ASYNC_EVENTS_ENABLED,
481         MLX5E_STATE_OPENED,
482         MLX5E_STATE_DESTROYING,
483 };
484
485 struct mlx5e_vxlan_db {
486         spinlock_t                      lock; /* protect vxlan table */
487         struct radix_tree_root          tree;
488 };
489
490 struct mlx5e_l2_rule {
491         u8  addr[ETH_ALEN + 2];
492         struct mlx5_flow_rule *rule;
493 };
494
495 struct mlx5e_flow_table {
496         int num_groups;
497         struct mlx5_flow_table *t;
498         struct mlx5_flow_group **g;
499 };
500
501 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
502
503 struct mlx5e_tc_table {
504         struct mlx5_flow_table          *t;
505
506         struct rhashtable_params        ht_params;
507         struct rhashtable               ht;
508 };
509
510 struct mlx5e_vlan_table {
511         struct mlx5e_flow_table         ft;
512         unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
513         struct mlx5_flow_rule   *active_vlans_rule[VLAN_N_VID];
514         struct mlx5_flow_rule   *untagged_rule;
515         struct mlx5_flow_rule   *any_vlan_rule;
516         bool          filter_disabled;
517 };
518
519 struct mlx5e_l2_table {
520         struct mlx5e_flow_table    ft;
521         struct hlist_head          netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
522         struct hlist_head          netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
523         struct mlx5e_l2_rule       broadcast;
524         struct mlx5e_l2_rule       allmulti;
525         struct mlx5e_l2_rule       promisc;
526         bool                       broadcast_enabled;
527         bool                       allmulti_enabled;
528         bool                       promisc_enabled;
529 };
530
531 /* L3/L4 traffic type classifier */
532 struct mlx5e_ttc_table {
533         struct mlx5e_flow_table  ft;
534         struct mlx5_flow_rule    *rules[MLX5E_NUM_TT];
535 };
536
537 #define ARFS_HASH_SHIFT BITS_PER_BYTE
538 #define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
539 struct arfs_table {
540         struct mlx5e_flow_table  ft;
541         struct mlx5_flow_rule    *default_rule;
542         struct hlist_head        rules_hash[ARFS_HASH_SIZE];
543 };
544
545 enum  arfs_type {
546         ARFS_IPV4_TCP,
547         ARFS_IPV6_TCP,
548         ARFS_IPV4_UDP,
549         ARFS_IPV6_UDP,
550         ARFS_NUM_TYPES,
551 };
552
553 struct mlx5e_arfs_tables {
554         struct arfs_table arfs_tables[ARFS_NUM_TYPES];
555         /* Protect aRFS rules list */
556         spinlock_t                     arfs_lock;
557         struct list_head               rules;
558         int                            last_filter_id;
559         struct workqueue_struct        *wq;
560 };
561
562 /* NIC prio FTS */
563 enum {
564         MLX5E_VLAN_FT_LEVEL = 0,
565         MLX5E_L2_FT_LEVEL,
566         MLX5E_TTC_FT_LEVEL,
567         MLX5E_ARFS_FT_LEVEL
568 };
569
570 struct mlx5e_ethtool_table {
571         struct mlx5_flow_table *ft;
572         int                    num_rules;
573 };
574
575 #define ETHTOOL_NUM_L3_L4_FTS 7
576 #define ETHTOOL_NUM_L2_FTS 4
577
578 struct mlx5e_ethtool_steering {
579         struct mlx5e_ethtool_table      l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
580         struct mlx5e_ethtool_table      l2_ft[ETHTOOL_NUM_L2_FTS];
581         struct list_head                rules;
582         int                             tot_num_rules;
583 };
584
585 struct mlx5e_flow_steering {
586         struct mlx5_flow_namespace      *ns;
587         struct mlx5e_ethtool_steering   ethtool;
588         struct mlx5e_tc_table           tc;
589         struct mlx5e_vlan_table         vlan;
590         struct mlx5e_l2_table           l2;
591         struct mlx5e_ttc_table          ttc;
592         struct mlx5e_arfs_tables        arfs;
593 };
594
595 struct mlx5e_rqt {
596         u32              rqtn;
597         bool             enabled;
598 };
599
600 struct mlx5e_tir {
601         u32               tirn;
602         struct mlx5e_rqt  rqt;
603         struct list_head  list;
604 };
605
606 enum {
607         MLX5E_TC_PRIO = 0,
608         MLX5E_NIC_PRIO
609 };
610
611 struct mlx5e_profile {
612         void    (*init)(struct mlx5_core_dev *mdev,
613                         struct net_device *netdev,
614                         const struct mlx5e_profile *profile, void *ppriv);
615         void    (*cleanup)(struct mlx5e_priv *priv);
616         int     (*init_rx)(struct mlx5e_priv *priv);
617         void    (*cleanup_rx)(struct mlx5e_priv *priv);
618         int     (*init_tx)(struct mlx5e_priv *priv);
619         void    (*cleanup_tx)(struct mlx5e_priv *priv);
620         void    (*enable)(struct mlx5e_priv *priv);
621         void    (*disable)(struct mlx5e_priv *priv);
622         void    (*update_stats)(struct mlx5e_priv *priv);
623         int     (*max_nch)(struct mlx5_core_dev *mdev);
624         int     max_tc;
625 };
626
627 struct mlx5e_priv {
628         /* priv data path fields - start */
629         struct mlx5e_sq            **txq_to_sq_map;
630         int channeltc_to_txq_map[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
631         struct bpf_prog *xdp_prog;
632         /* priv data path fields - end */
633
634         unsigned long              state;
635         struct mutex               state_lock; /* Protects Interface state */
636         struct mlx5_core_mkey      umr_mkey;
637         struct mlx5e_rq            drop_rq;
638
639         struct mlx5e_channel     **channel;
640         u32                        tisn[MLX5E_MAX_NUM_TC];
641         struct mlx5e_rqt           indir_rqt;
642         struct mlx5e_tir           indir_tir[MLX5E_NUM_INDIR_TIRS];
643         struct mlx5e_tir           direct_tir[MLX5E_MAX_NUM_CHANNELS];
644         u32                        tx_rates[MLX5E_MAX_NUM_SQS];
645
646         struct mlx5e_flow_steering fs;
647         struct mlx5e_vxlan_db      vxlan;
648
649         struct mlx5e_params        params;
650         struct workqueue_struct    *wq;
651         struct work_struct         update_carrier_work;
652         struct work_struct         set_rx_mode_work;
653         struct work_struct         tx_timeout_work;
654         struct delayed_work        update_stats_work;
655
656         u32                        pflags;
657         struct mlx5_core_dev      *mdev;
658         struct net_device         *netdev;
659         struct mlx5e_stats         stats;
660         struct mlx5e_tstamp        tstamp;
661         u16 q_counter;
662         const struct mlx5e_profile *profile;
663         void                      *ppriv;
664 };
665
666 void mlx5e_build_ptys2ethtool_map(void);
667
668 void mlx5e_send_nop(struct mlx5e_sq *sq, bool notify_hw);
669 u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
670                        void *accel_priv, select_queue_fallback_t fallback);
671 netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
672
673 void mlx5e_completion_event(struct mlx5_core_cq *mcq);
674 void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
675 int mlx5e_napi_poll(struct napi_struct *napi, int budget);
676 bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget);
677 int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
678 void mlx5e_free_tx_descs(struct mlx5e_sq *sq);
679
680 void mlx5e_page_release(struct mlx5e_rq *rq, struct mlx5e_dma_info *dma_info,
681                         bool recycle);
682 void mlx5e_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
683 void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
684 bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
685 int mlx5e_alloc_rx_wqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe, u16 ix);
686 int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe, u16 ix);
687 void mlx5e_dealloc_rx_wqe(struct mlx5e_rq *rq, u16 ix);
688 void mlx5e_dealloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix);
689 void mlx5e_post_rx_mpwqe(struct mlx5e_rq *rq);
690 void mlx5e_free_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi);
691 struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);
692
693 void mlx5e_rx_am(struct mlx5e_rq *rq);
694 void mlx5e_rx_am_work(struct work_struct *work);
695 struct mlx5e_cq_moder mlx5e_am_get_def_profile(u8 rx_cq_period_mode);
696
697 void mlx5e_update_stats(struct mlx5e_priv *priv);
698
699 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
700 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
701 void mlx5e_init_l2_addr(struct mlx5e_priv *priv);
702 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
703 int mlx5e_ethtool_get_flow(struct mlx5e_priv *priv, struct ethtool_rxnfc *info,
704                            int location);
705 int mlx5e_ethtool_get_all_flows(struct mlx5e_priv *priv,
706                                 struct ethtool_rxnfc *info, u32 *rule_locs);
707 int mlx5e_ethtool_flow_replace(struct mlx5e_priv *priv,
708                                struct ethtool_rx_flow_spec *fs);
709 int mlx5e_ethtool_flow_remove(struct mlx5e_priv *priv,
710                               int location);
711 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
712 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
713 void mlx5e_set_rx_mode_work(struct work_struct *work);
714
715 void mlx5e_fill_hwstamp(struct mlx5e_tstamp *clock, u64 timestamp,
716                         struct skb_shared_hwtstamps *hwts);
717 void mlx5e_timestamp_init(struct mlx5e_priv *priv);
718 void mlx5e_timestamp_cleanup(struct mlx5e_priv *priv);
719 int mlx5e_hwstamp_set(struct net_device *dev, struct ifreq *ifr);
720 int mlx5e_hwstamp_get(struct net_device *dev, struct ifreq *ifr);
721 void mlx5e_modify_rx_cqe_compression(struct mlx5e_priv *priv, bool val);
722
723 int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
724                           u16 vid);
725 int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
726                            u16 vid);
727 void mlx5e_enable_vlan_filter(struct mlx5e_priv *priv);
728 void mlx5e_disable_vlan_filter(struct mlx5e_priv *priv);
729
730 int mlx5e_modify_rqs_vsd(struct mlx5e_priv *priv, bool vsd);
731
732 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, u32 rqtn, int sz, int ix);
733 void mlx5e_build_tir_ctx_hash(void *tirc, struct mlx5e_priv *priv);
734
735 int mlx5e_open_locked(struct net_device *netdev);
736 int mlx5e_close_locked(struct net_device *netdev);
737 void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
738                                    u32 *indirection_rqt, int len,
739                                    int num_channels);
740 int mlx5e_get_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
741
742 void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params,
743                                  u8 cq_period_mode);
744
745 static inline void mlx5e_tx_notify_hw(struct mlx5e_sq *sq,
746                                       struct mlx5_wqe_ctrl_seg *ctrl, int bf_sz)
747 {
748         u16 ofst = MLX5_BF_OFFSET + sq->bf_offset;
749
750         /* ensure wqe is visible to device before updating doorbell record */
751         dma_wmb();
752
753         *sq->wq.db = cpu_to_be32(sq->pc);
754
755         /* ensure doorbell record is visible to device before ringing the
756          * doorbell
757          */
758         wmb();
759         if (bf_sz)
760                 __iowrite64_copy(sq->uar_map + ofst, ctrl, bf_sz);
761         else
762                 mlx5_write64((__be32 *)ctrl, sq->uar_map + ofst, NULL);
763         /* flush the write-combining mapped buffer */
764         wmb();
765
766         sq->bf_offset ^= sq->bf_buf_size;
767 }
768
769 static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
770 {
771         struct mlx5_core_cq *mcq;
772
773         mcq = &cq->mcq;
774         mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, NULL, cq->wq.cc);
775 }
776
777 static inline u32 mlx5e_get_wqe_mtt_offset(struct mlx5e_rq *rq, u16 wqe_ix)
778 {
779         return rq->mpwqe.mtt_offset +
780                 wqe_ix * ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8);
781 }
782
783 static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
784 {
785         return min_t(int, mdev->priv.eq_table.num_comp_vectors,
786                      MLX5E_MAX_NUM_CHANNELS);
787 }
788
789 extern const struct ethtool_ops mlx5e_ethtool_ops;
790 #ifdef CONFIG_MLX5_CORE_EN_DCB
791 extern const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops;
792 int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets);
793 #endif
794
795 #ifndef CONFIG_RFS_ACCEL
796 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv)
797 {
798         return 0;
799 }
800
801 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
802
803 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv)
804 {
805         return -ENOTSUPP;
806 }
807
808 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv)
809 {
810         return -ENOTSUPP;
811 }
812 #else
813 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
814 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
815 int mlx5e_arfs_enable(struct mlx5e_priv *priv);
816 int mlx5e_arfs_disable(struct mlx5e_priv *priv);
817 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
818                         u16 rxq_index, u32 flow_id);
819 #endif
820
821 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
822 int mlx5e_create_tir(struct mlx5_core_dev *mdev,
823                      struct mlx5e_tir *tir, u32 *in, int inlen);
824 void mlx5e_destroy_tir(struct mlx5_core_dev *mdev,
825                        struct mlx5e_tir *tir);
826 int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev);
827 void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev);
828 int mlx5e_refresh_tirs_self_loopback_enable(struct mlx5_core_dev *mdev);
829
830 struct mlx5_eswitch_rep;
831 int mlx5e_vport_rep_load(struct mlx5_eswitch *esw,
832                          struct mlx5_eswitch_rep *rep);
833 void mlx5e_vport_rep_unload(struct mlx5_eswitch *esw,
834                             struct mlx5_eswitch_rep *rep);
835 int mlx5e_nic_rep_load(struct mlx5_eswitch *esw, struct mlx5_eswitch_rep *rep);
836 void mlx5e_nic_rep_unload(struct mlx5_eswitch *esw,
837                           struct mlx5_eswitch_rep *rep);
838 int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv);
839 void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv);
840 int mlx5e_attr_get(struct net_device *dev, struct switchdev_attr *attr);
841
842 int mlx5e_create_direct_rqts(struct mlx5e_priv *priv);
843 void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt);
844 int mlx5e_create_direct_tirs(struct mlx5e_priv *priv);
845 void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv);
846 int mlx5e_create_tises(struct mlx5e_priv *priv);
847 void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv);
848 int mlx5e_close(struct net_device *netdev);
849 int mlx5e_open(struct net_device *netdev);
850 void mlx5e_update_stats_work(struct work_struct *work);
851 struct net_device *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
852                                        const struct mlx5e_profile *profile,
853                                        void *ppriv);
854 void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv);
855 int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev);
856 void mlx5e_detach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev);
857 struct rtnl_link_stats64 *
858 mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats);
859
860 #endif /* __MLX5_EN_H__ */