net/mlx5e: Build RX SKB on demand
[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         struct mlx5e_dma_info *dma_info;
309         struct mlx5e_mpw_info *wqe_info;
310         void                  *mtt_no_align;
311         struct {
312                 u8             page_order;
313                 u32            wqe_sz;    /* wqe data buffer size */
314         } buff;
315         __be32                 mkey_be;
316
317         struct device         *pdev;
318         struct net_device     *netdev;
319         struct mlx5e_tstamp   *tstamp;
320         struct mlx5e_rq_stats  stats;
321         struct mlx5e_cq        cq;
322         struct mlx5e_page_cache page_cache;
323
324         mlx5e_fp_handle_rx_cqe handle_rx_cqe;
325         mlx5e_fp_alloc_wqe     alloc_wqe;
326         mlx5e_fp_dealloc_wqe   dealloc_wqe;
327
328         unsigned long          state;
329         int                    ix;
330         u32                    mpwqe_mtt_offset;
331
332         struct mlx5e_rx_am     am; /* Adaptive Moderation */
333
334         /* control */
335         struct mlx5_wq_ctrl    wq_ctrl;
336         u8                     wq_type;
337         u32                    mpwqe_stride_sz;
338         u32                    mpwqe_num_strides;
339         u32                    rqn;
340         struct mlx5e_channel  *channel;
341         struct mlx5e_priv     *priv;
342 } ____cacheline_aligned_in_smp;
343
344 struct mlx5e_umr_dma_info {
345         __be64                *mtt;
346         dma_addr_t             mtt_addr;
347         struct mlx5e_dma_info  dma_info[MLX5_MPWRQ_PAGES_PER_WQE];
348         struct mlx5e_umr_wqe   wqe;
349 };
350
351 struct mlx5e_mpw_info {
352         struct mlx5e_umr_dma_info umr;
353         u16 consumed_strides;
354         u16 skbs_frags[MLX5_MPWRQ_PAGES_PER_WQE];
355 };
356
357 struct mlx5e_tx_wqe_info {
358         u32 num_bytes;
359         u8  num_wqebbs;
360         u8  num_dma;
361 };
362
363 enum mlx5e_dma_map_type {
364         MLX5E_DMA_MAP_SINGLE,
365         MLX5E_DMA_MAP_PAGE
366 };
367
368 struct mlx5e_sq_dma {
369         dma_addr_t              addr;
370         u32                     size;
371         enum mlx5e_dma_map_type type;
372 };
373
374 enum {
375         MLX5E_SQ_STATE_FLUSH,
376         MLX5E_SQ_STATE_BF_ENABLE,
377 };
378
379 struct mlx5e_ico_wqe_info {
380         u8  opcode;
381         u8  num_wqebbs;
382 };
383
384 struct mlx5e_sq {
385         /* data path */
386
387         /* dirtied @completion */
388         u16                        cc;
389         u32                        dma_fifo_cc;
390
391         /* dirtied @xmit */
392         u16                        pc ____cacheline_aligned_in_smp;
393         u32                        dma_fifo_pc;
394         u16                        bf_offset;
395         u16                        prev_cc;
396         u8                         bf_budget;
397         struct mlx5e_sq_stats      stats;
398
399         struct mlx5e_cq            cq;
400
401         /* pointers to per packet info: write@xmit, read@completion */
402         struct sk_buff           **skb;
403         struct mlx5e_sq_dma       *dma_fifo;
404         struct mlx5e_tx_wqe_info  *wqe_info;
405
406         /* read only */
407         struct mlx5_wq_cyc         wq;
408         u32                        dma_fifo_mask;
409         void __iomem              *uar_map;
410         struct netdev_queue       *txq;
411         u32                        sqn;
412         u16                        bf_buf_size;
413         u16                        max_inline;
414         u8                         min_inline_mode;
415         u16                        edge;
416         struct device             *pdev;
417         struct mlx5e_tstamp       *tstamp;
418         __be32                     mkey_be;
419         unsigned long              state;
420
421         /* control path */
422         struct mlx5_wq_ctrl        wq_ctrl;
423         struct mlx5_uar            uar;
424         struct mlx5e_channel      *channel;
425         int                        tc;
426         struct mlx5e_ico_wqe_info *ico_wqe_info;
427         u32                        rate_limit;
428 } ____cacheline_aligned_in_smp;
429
430 static inline bool mlx5e_sq_has_room_for(struct mlx5e_sq *sq, u16 n)
431 {
432         return (((sq->wq.sz_m1 & (sq->cc - sq->pc)) >= n) ||
433                 (sq->cc  == sq->pc));
434 }
435
436 enum channel_flags {
437         MLX5E_CHANNEL_NAPI_SCHED = 1,
438 };
439
440 struct mlx5e_channel {
441         /* data path */
442         struct mlx5e_rq            rq;
443         struct mlx5e_sq            sq[MLX5E_MAX_NUM_TC];
444         struct mlx5e_sq            icosq;   /* internal control operations */
445         struct napi_struct         napi;
446         struct device             *pdev;
447         struct net_device         *netdev;
448         __be32                     mkey_be;
449         u8                         num_tc;
450         unsigned long              flags;
451
452         /* control */
453         struct mlx5e_priv         *priv;
454         int                        ix;
455         int                        cpu;
456 };
457
458 enum mlx5e_traffic_types {
459         MLX5E_TT_IPV4_TCP,
460         MLX5E_TT_IPV6_TCP,
461         MLX5E_TT_IPV4_UDP,
462         MLX5E_TT_IPV6_UDP,
463         MLX5E_TT_IPV4_IPSEC_AH,
464         MLX5E_TT_IPV6_IPSEC_AH,
465         MLX5E_TT_IPV4_IPSEC_ESP,
466         MLX5E_TT_IPV6_IPSEC_ESP,
467         MLX5E_TT_IPV4,
468         MLX5E_TT_IPV6,
469         MLX5E_TT_ANY,
470         MLX5E_NUM_TT,
471         MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
472 };
473
474 enum {
475         MLX5E_STATE_ASYNC_EVENTS_ENABLED,
476         MLX5E_STATE_OPENED,
477         MLX5E_STATE_DESTROYING,
478 };
479
480 struct mlx5e_vxlan_db {
481         spinlock_t                      lock; /* protect vxlan table */
482         struct radix_tree_root          tree;
483 };
484
485 struct mlx5e_l2_rule {
486         u8  addr[ETH_ALEN + 2];
487         struct mlx5_flow_rule *rule;
488 };
489
490 struct mlx5e_flow_table {
491         int num_groups;
492         struct mlx5_flow_table *t;
493         struct mlx5_flow_group **g;
494 };
495
496 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
497
498 struct mlx5e_tc_table {
499         struct mlx5_flow_table          *t;
500
501         struct rhashtable_params        ht_params;
502         struct rhashtable               ht;
503 };
504
505 struct mlx5e_vlan_table {
506         struct mlx5e_flow_table         ft;
507         unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
508         struct mlx5_flow_rule   *active_vlans_rule[VLAN_N_VID];
509         struct mlx5_flow_rule   *untagged_rule;
510         struct mlx5_flow_rule   *any_vlan_rule;
511         bool          filter_disabled;
512 };
513
514 struct mlx5e_l2_table {
515         struct mlx5e_flow_table    ft;
516         struct hlist_head          netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
517         struct hlist_head          netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
518         struct mlx5e_l2_rule       broadcast;
519         struct mlx5e_l2_rule       allmulti;
520         struct mlx5e_l2_rule       promisc;
521         bool                       broadcast_enabled;
522         bool                       allmulti_enabled;
523         bool                       promisc_enabled;
524 };
525
526 /* L3/L4 traffic type classifier */
527 struct mlx5e_ttc_table {
528         struct mlx5e_flow_table  ft;
529         struct mlx5_flow_rule    *rules[MLX5E_NUM_TT];
530 };
531
532 #define ARFS_HASH_SHIFT BITS_PER_BYTE
533 #define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
534 struct arfs_table {
535         struct mlx5e_flow_table  ft;
536         struct mlx5_flow_rule    *default_rule;
537         struct hlist_head        rules_hash[ARFS_HASH_SIZE];
538 };
539
540 enum  arfs_type {
541         ARFS_IPV4_TCP,
542         ARFS_IPV6_TCP,
543         ARFS_IPV4_UDP,
544         ARFS_IPV6_UDP,
545         ARFS_NUM_TYPES,
546 };
547
548 struct mlx5e_arfs_tables {
549         struct arfs_table arfs_tables[ARFS_NUM_TYPES];
550         /* Protect aRFS rules list */
551         spinlock_t                     arfs_lock;
552         struct list_head               rules;
553         int                            last_filter_id;
554         struct workqueue_struct        *wq;
555 };
556
557 /* NIC prio FTS */
558 enum {
559         MLX5E_VLAN_FT_LEVEL = 0,
560         MLX5E_L2_FT_LEVEL,
561         MLX5E_TTC_FT_LEVEL,
562         MLX5E_ARFS_FT_LEVEL
563 };
564
565 struct mlx5e_ethtool_table {
566         struct mlx5_flow_table *ft;
567         int                    num_rules;
568 };
569
570 #define ETHTOOL_NUM_L3_L4_FTS 7
571 #define ETHTOOL_NUM_L2_FTS 4
572
573 struct mlx5e_ethtool_steering {
574         struct mlx5e_ethtool_table      l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
575         struct mlx5e_ethtool_table      l2_ft[ETHTOOL_NUM_L2_FTS];
576         struct list_head                rules;
577         int                             tot_num_rules;
578 };
579
580 struct mlx5e_flow_steering {
581         struct mlx5_flow_namespace      *ns;
582         struct mlx5e_ethtool_steering   ethtool;
583         struct mlx5e_tc_table           tc;
584         struct mlx5e_vlan_table         vlan;
585         struct mlx5e_l2_table           l2;
586         struct mlx5e_ttc_table          ttc;
587         struct mlx5e_arfs_tables        arfs;
588 };
589
590 struct mlx5e_rqt {
591         u32              rqtn;
592         bool             enabled;
593 };
594
595 struct mlx5e_tir {
596         u32               tirn;
597         struct mlx5e_rqt  rqt;
598         struct list_head  list;
599 };
600
601 enum {
602         MLX5E_TC_PRIO = 0,
603         MLX5E_NIC_PRIO
604 };
605
606 struct mlx5e_profile {
607         void    (*init)(struct mlx5_core_dev *mdev,
608                         struct net_device *netdev,
609                         const struct mlx5e_profile *profile, void *ppriv);
610         void    (*cleanup)(struct mlx5e_priv *priv);
611         int     (*init_rx)(struct mlx5e_priv *priv);
612         void    (*cleanup_rx)(struct mlx5e_priv *priv);
613         int     (*init_tx)(struct mlx5e_priv *priv);
614         void    (*cleanup_tx)(struct mlx5e_priv *priv);
615         void    (*enable)(struct mlx5e_priv *priv);
616         void    (*disable)(struct mlx5e_priv *priv);
617         void    (*update_stats)(struct mlx5e_priv *priv);
618         int     (*max_nch)(struct mlx5_core_dev *mdev);
619         int     max_tc;
620 };
621
622 struct mlx5e_priv {
623         /* priv data path fields - start */
624         struct mlx5e_sq            **txq_to_sq_map;
625         int channeltc_to_txq_map[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
626         /* priv data path fields - end */
627
628         unsigned long              state;
629         struct mutex               state_lock; /* Protects Interface state */
630         struct mlx5_core_mkey      umr_mkey;
631         struct mlx5e_rq            drop_rq;
632
633         struct mlx5e_channel     **channel;
634         u32                        tisn[MLX5E_MAX_NUM_TC];
635         struct mlx5e_rqt           indir_rqt;
636         struct mlx5e_tir           indir_tir[MLX5E_NUM_INDIR_TIRS];
637         struct mlx5e_tir           direct_tir[MLX5E_MAX_NUM_CHANNELS];
638         u32                        tx_rates[MLX5E_MAX_NUM_SQS];
639
640         struct mlx5e_flow_steering fs;
641         struct mlx5e_vxlan_db      vxlan;
642
643         struct mlx5e_params        params;
644         struct workqueue_struct    *wq;
645         struct work_struct         update_carrier_work;
646         struct work_struct         set_rx_mode_work;
647         struct work_struct         tx_timeout_work;
648         struct delayed_work        update_stats_work;
649
650         u32                        pflags;
651         struct mlx5_core_dev      *mdev;
652         struct net_device         *netdev;
653         struct mlx5e_stats         stats;
654         struct mlx5e_tstamp        tstamp;
655         u16 q_counter;
656         const struct mlx5e_profile *profile;
657         void                      *ppriv;
658 };
659
660 void mlx5e_build_ptys2ethtool_map(void);
661
662 void mlx5e_send_nop(struct mlx5e_sq *sq, bool notify_hw);
663 u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
664                        void *accel_priv, select_queue_fallback_t fallback);
665 netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
666
667 void mlx5e_completion_event(struct mlx5_core_cq *mcq);
668 void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
669 int mlx5e_napi_poll(struct napi_struct *napi, int budget);
670 bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget);
671 int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
672 void mlx5e_free_tx_descs(struct mlx5e_sq *sq);
673
674 void mlx5e_page_release(struct mlx5e_rq *rq, struct mlx5e_dma_info *dma_info,
675                         bool recycle);
676 void mlx5e_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
677 void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
678 bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
679 int mlx5e_alloc_rx_wqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe, u16 ix);
680 int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe, u16 ix);
681 void mlx5e_dealloc_rx_wqe(struct mlx5e_rq *rq, u16 ix);
682 void mlx5e_dealloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix);
683 void mlx5e_post_rx_mpwqe(struct mlx5e_rq *rq);
684 void mlx5e_free_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi);
685 struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);
686
687 void mlx5e_rx_am(struct mlx5e_rq *rq);
688 void mlx5e_rx_am_work(struct work_struct *work);
689 struct mlx5e_cq_moder mlx5e_am_get_def_profile(u8 rx_cq_period_mode);
690
691 void mlx5e_update_stats(struct mlx5e_priv *priv);
692
693 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
694 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
695 void mlx5e_init_l2_addr(struct mlx5e_priv *priv);
696 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
697 int mlx5e_ethtool_get_flow(struct mlx5e_priv *priv, struct ethtool_rxnfc *info,
698                            int location);
699 int mlx5e_ethtool_get_all_flows(struct mlx5e_priv *priv,
700                                 struct ethtool_rxnfc *info, u32 *rule_locs);
701 int mlx5e_ethtool_flow_replace(struct mlx5e_priv *priv,
702                                struct ethtool_rx_flow_spec *fs);
703 int mlx5e_ethtool_flow_remove(struct mlx5e_priv *priv,
704                               int location);
705 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
706 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
707 void mlx5e_set_rx_mode_work(struct work_struct *work);
708
709 void mlx5e_fill_hwstamp(struct mlx5e_tstamp *clock, u64 timestamp,
710                         struct skb_shared_hwtstamps *hwts);
711 void mlx5e_timestamp_init(struct mlx5e_priv *priv);
712 void mlx5e_timestamp_cleanup(struct mlx5e_priv *priv);
713 int mlx5e_hwstamp_set(struct net_device *dev, struct ifreq *ifr);
714 int mlx5e_hwstamp_get(struct net_device *dev, struct ifreq *ifr);
715 void mlx5e_modify_rx_cqe_compression(struct mlx5e_priv *priv, bool val);
716
717 int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
718                           u16 vid);
719 int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
720                            u16 vid);
721 void mlx5e_enable_vlan_filter(struct mlx5e_priv *priv);
722 void mlx5e_disable_vlan_filter(struct mlx5e_priv *priv);
723
724 int mlx5e_modify_rqs_vsd(struct mlx5e_priv *priv, bool vsd);
725
726 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, u32 rqtn, int sz, int ix);
727 void mlx5e_build_tir_ctx_hash(void *tirc, struct mlx5e_priv *priv);
728
729 int mlx5e_open_locked(struct net_device *netdev);
730 int mlx5e_close_locked(struct net_device *netdev);
731 void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
732                                    u32 *indirection_rqt, int len,
733                                    int num_channels);
734 int mlx5e_get_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
735
736 void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params,
737                                  u8 cq_period_mode);
738
739 static inline void mlx5e_tx_notify_hw(struct mlx5e_sq *sq,
740                                       struct mlx5_wqe_ctrl_seg *ctrl, int bf_sz)
741 {
742         u16 ofst = MLX5_BF_OFFSET + sq->bf_offset;
743
744         /* ensure wqe is visible to device before updating doorbell record */
745         dma_wmb();
746
747         *sq->wq.db = cpu_to_be32(sq->pc);
748
749         /* ensure doorbell record is visible to device before ringing the
750          * doorbell
751          */
752         wmb();
753         if (bf_sz)
754                 __iowrite64_copy(sq->uar_map + ofst, ctrl, bf_sz);
755         else
756                 mlx5_write64((__be32 *)ctrl, sq->uar_map + ofst, NULL);
757         /* flush the write-combining mapped buffer */
758         wmb();
759
760         sq->bf_offset ^= sq->bf_buf_size;
761 }
762
763 static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
764 {
765         struct mlx5_core_cq *mcq;
766
767         mcq = &cq->mcq;
768         mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, NULL, cq->wq.cc);
769 }
770
771 static inline u32 mlx5e_get_wqe_mtt_offset(struct mlx5e_rq *rq, u16 wqe_ix)
772 {
773         return rq->mpwqe_mtt_offset +
774                 wqe_ix * ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8);
775 }
776
777 static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
778 {
779         return min_t(int, mdev->priv.eq_table.num_comp_vectors,
780                      MLX5E_MAX_NUM_CHANNELS);
781 }
782
783 extern const struct ethtool_ops mlx5e_ethtool_ops;
784 #ifdef CONFIG_MLX5_CORE_EN_DCB
785 extern const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops;
786 int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets);
787 #endif
788
789 #ifndef CONFIG_RFS_ACCEL
790 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv)
791 {
792         return 0;
793 }
794
795 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
796
797 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv)
798 {
799         return -ENOTSUPP;
800 }
801
802 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv)
803 {
804         return -ENOTSUPP;
805 }
806 #else
807 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
808 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
809 int mlx5e_arfs_enable(struct mlx5e_priv *priv);
810 int mlx5e_arfs_disable(struct mlx5e_priv *priv);
811 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
812                         u16 rxq_index, u32 flow_id);
813 #endif
814
815 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
816 int mlx5e_create_tir(struct mlx5_core_dev *mdev,
817                      struct mlx5e_tir *tir, u32 *in, int inlen);
818 void mlx5e_destroy_tir(struct mlx5_core_dev *mdev,
819                        struct mlx5e_tir *tir);
820 int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev);
821 void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev);
822 int mlx5e_refresh_tirs_self_loopback_enable(struct mlx5_core_dev *mdev);
823
824 struct mlx5_eswitch_rep;
825 int mlx5e_vport_rep_load(struct mlx5_eswitch *esw,
826                          struct mlx5_eswitch_rep *rep);
827 void mlx5e_vport_rep_unload(struct mlx5_eswitch *esw,
828                             struct mlx5_eswitch_rep *rep);
829 int mlx5e_nic_rep_load(struct mlx5_eswitch *esw, struct mlx5_eswitch_rep *rep);
830 void mlx5e_nic_rep_unload(struct mlx5_eswitch *esw,
831                           struct mlx5_eswitch_rep *rep);
832 int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv);
833 void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv);
834 int mlx5e_attr_get(struct net_device *dev, struct switchdev_attr *attr);
835
836 int mlx5e_create_direct_rqts(struct mlx5e_priv *priv);
837 void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt);
838 int mlx5e_create_direct_tirs(struct mlx5e_priv *priv);
839 void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv);
840 int mlx5e_create_tises(struct mlx5e_priv *priv);
841 void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv);
842 int mlx5e_close(struct net_device *netdev);
843 int mlx5e_open(struct net_device *netdev);
844 void mlx5e_update_stats_work(struct work_struct *work);
845 struct net_device *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
846                                        const struct mlx5e_profile *profile,
847                                        void *ppriv);
848 void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv);
849 int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev);
850 void mlx5e_detach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev);
851 struct rtnl_link_stats64 *
852 mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats);
853
854 #endif /* __MLX5_EN_H__ */