Merge tag 'ipvs-for-v4.7' of https://git.kernel.org/pub/scm/linux/kernel/git/horms...
[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 "wq.h"
48 #include "mlx5_core.h"
49
50 #define MLX5E_MAX_NUM_TC        8
51
52 #define MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE                0x6
53 #define MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE                0xa
54 #define MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE                0xd
55
56 #define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE                0x1
57 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE                0xa
58 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE                0xd
59
60 #define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW            0x1
61 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE_MPW            0x4
62 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW            0x6
63
64 #define MLX5_MPWRQ_LOG_NUM_STRIDES              11 /* >= 9, HW restriction */
65 #define MLX5_MPWRQ_LOG_STRIDE_SIZE              6  /* >= 6, HW restriction */
66 #define MLX5_MPWRQ_NUM_STRIDES                  BIT(MLX5_MPWRQ_LOG_NUM_STRIDES)
67 #define MLX5_MPWRQ_STRIDE_SIZE                  BIT(MLX5_MPWRQ_LOG_STRIDE_SIZE)
68 #define MLX5_MPWRQ_LOG_WQE_SZ                   (MLX5_MPWRQ_LOG_NUM_STRIDES +\
69                                                  MLX5_MPWRQ_LOG_STRIDE_SIZE)
70 #define MLX5_MPWRQ_WQE_PAGE_ORDER  (MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT > 0 ? \
71                                     MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT : 0)
72 #define MLX5_MPWRQ_PAGES_PER_WQE                BIT(MLX5_MPWRQ_WQE_PAGE_ORDER)
73 #define MLX5_MPWRQ_STRIDES_PER_PAGE             (MLX5_MPWRQ_NUM_STRIDES >> \
74                                                  MLX5_MPWRQ_WQE_PAGE_ORDER)
75 #define MLX5_CHANNEL_MAX_NUM_MTTS (ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8) * \
76                                    BIT(MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW))
77 #define MLX5_UMR_ALIGN                          (2048)
78 #define MLX5_MPWRQ_SMALL_PACKET_THRESHOLD       (128)
79
80 #define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ                 (64 * 1024)
81 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC      0x10
82 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS      0x20
83 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC      0x10
84 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS      0x20
85 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES                0x80
86 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW            0x2
87
88 #define MLX5E_LOG_INDIR_RQT_SIZE       0x7
89 #define MLX5E_INDIR_RQT_SIZE           BIT(MLX5E_LOG_INDIR_RQT_SIZE)
90 #define MLX5E_MAX_NUM_CHANNELS         (MLX5E_INDIR_RQT_SIZE >> 1)
91 #define MLX5E_TX_CQ_POLL_BUDGET        128
92 #define MLX5E_UPDATE_STATS_INTERVAL    200 /* msecs */
93 #define MLX5E_SQ_BF_BUDGET             16
94
95 #define MLX5E_NUM_MAIN_GROUPS 9
96
97 static inline u16 mlx5_min_rx_wqes(int wq_type, u32 wq_size)
98 {
99         switch (wq_type) {
100         case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
101                 return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW,
102                              wq_size / 2);
103         default:
104                 return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES,
105                              wq_size / 2);
106         }
107 }
108
109 static inline int mlx5_min_log_rq_size(int wq_type)
110 {
111         switch (wq_type) {
112         case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
113                 return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW;
114         default:
115                 return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE;
116         }
117 }
118
119 static inline int mlx5_max_log_rq_size(int wq_type)
120 {
121         switch (wq_type) {
122         case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
123                 return MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW;
124         default:
125                 return MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE;
126         }
127 }
128
129 struct mlx5e_tx_wqe {
130         struct mlx5_wqe_ctrl_seg ctrl;
131         struct mlx5_wqe_eth_seg  eth;
132 };
133
134 struct mlx5e_rx_wqe {
135         struct mlx5_wqe_srq_next_seg  next;
136         struct mlx5_wqe_data_seg      data;
137 };
138
139 struct mlx5e_umr_wqe {
140         struct mlx5_wqe_ctrl_seg       ctrl;
141         struct mlx5_wqe_umr_ctrl_seg   uctrl;
142         struct mlx5_mkey_seg           mkc;
143         struct mlx5_wqe_data_seg       data;
144 };
145
146 #ifdef CONFIG_MLX5_CORE_EN_DCB
147 #define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */
148 #define MLX5E_MIN_BW_ALLOC 1   /* Min percentage of BW allocation */
149 #endif
150
151 static const char vport_strings[][ETH_GSTRING_LEN] = {
152         /* vport statistics */
153         "rx_packets",
154         "rx_bytes",
155         "tx_packets",
156         "tx_bytes",
157         "rx_error_packets",
158         "rx_error_bytes",
159         "tx_error_packets",
160         "tx_error_bytes",
161         "rx_unicast_packets",
162         "rx_unicast_bytes",
163         "tx_unicast_packets",
164         "tx_unicast_bytes",
165         "rx_multicast_packets",
166         "rx_multicast_bytes",
167         "tx_multicast_packets",
168         "tx_multicast_bytes",
169         "rx_broadcast_packets",
170         "rx_broadcast_bytes",
171         "tx_broadcast_packets",
172         "tx_broadcast_bytes",
173
174         /* SW counters */
175         "tso_packets",
176         "tso_bytes",
177         "tso_inner_packets",
178         "tso_inner_bytes",
179         "lro_packets",
180         "lro_bytes",
181         "rx_csum_good",
182         "rx_csum_none",
183         "rx_csum_sw",
184         "tx_csum_offload",
185         "tx_csum_inner",
186         "tx_queue_stopped",
187         "tx_queue_wake",
188         "tx_queue_dropped",
189         "rx_wqe_err",
190         "rx_mpwqe_filler",
191         "rx_mpwqe_frag",
192         "rx_buff_alloc_err",
193 };
194
195 struct mlx5e_vport_stats {
196         /* HW counters */
197         u64 rx_packets;
198         u64 rx_bytes;
199         u64 tx_packets;
200         u64 tx_bytes;
201         u64 rx_error_packets;
202         u64 rx_error_bytes;
203         u64 tx_error_packets;
204         u64 tx_error_bytes;
205         u64 rx_unicast_packets;
206         u64 rx_unicast_bytes;
207         u64 tx_unicast_packets;
208         u64 tx_unicast_bytes;
209         u64 rx_multicast_packets;
210         u64 rx_multicast_bytes;
211         u64 tx_multicast_packets;
212         u64 tx_multicast_bytes;
213         u64 rx_broadcast_packets;
214         u64 rx_broadcast_bytes;
215         u64 tx_broadcast_packets;
216         u64 tx_broadcast_bytes;
217
218         /* SW counters */
219         u64 tso_packets;
220         u64 tso_bytes;
221         u64 tso_inner_packets;
222         u64 tso_inner_bytes;
223         u64 lro_packets;
224         u64 lro_bytes;
225         u64 rx_csum_good;
226         u64 rx_csum_none;
227         u64 rx_csum_sw;
228         u64 tx_csum_offload;
229         u64 tx_csum_inner;
230         u64 tx_queue_stopped;
231         u64 tx_queue_wake;
232         u64 tx_queue_dropped;
233         u64 rx_wqe_err;
234         u64 rx_mpwqe_filler;
235         u64 rx_mpwqe_frag;
236         u64 rx_buff_alloc_err;
237
238 #define NUM_VPORT_COUNTERS     38
239 };
240
241 static const char pport_strings[][ETH_GSTRING_LEN] = {
242         /* IEEE802.3 counters */
243         "frames_tx",
244         "frames_rx",
245         "check_seq_err",
246         "alignment_err",
247         "octets_tx",
248         "octets_received",
249         "multicast_xmitted",
250         "broadcast_xmitted",
251         "multicast_rx",
252         "broadcast_rx",
253         "in_range_len_errors",
254         "out_of_range_len",
255         "too_long_errors",
256         "symbol_err",
257         "mac_control_tx",
258         "mac_control_rx",
259         "unsupported_op_rx",
260         "pause_ctrl_rx",
261         "pause_ctrl_tx",
262
263         /* RFC2863 counters */
264         "in_octets",
265         "in_ucast_pkts",
266         "in_discards",
267         "in_errors",
268         "in_unknown_protos",
269         "out_octets",
270         "out_ucast_pkts",
271         "out_discards",
272         "out_errors",
273         "in_multicast_pkts",
274         "in_broadcast_pkts",
275         "out_multicast_pkts",
276         "out_broadcast_pkts",
277
278         /* RFC2819 counters */
279         "drop_events",
280         "octets",
281         "pkts",
282         "broadcast_pkts",
283         "multicast_pkts",
284         "crc_align_errors",
285         "undersize_pkts",
286         "oversize_pkts",
287         "fragments",
288         "jabbers",
289         "collisions",
290         "p64octets",
291         "p65to127octets",
292         "p128to255octets",
293         "p256to511octets",
294         "p512to1023octets",
295         "p1024to1518octets",
296         "p1519to2047octets",
297         "p2048to4095octets",
298         "p4096to8191octets",
299         "p8192to10239octets",
300 };
301
302 #define NUM_IEEE_802_3_COUNTERS         19
303 #define NUM_RFC_2863_COUNTERS           13
304 #define NUM_RFC_2819_COUNTERS           21
305 #define NUM_PPORT_COUNTERS              (NUM_IEEE_802_3_COUNTERS + \
306                                          NUM_RFC_2863_COUNTERS + \
307                                          NUM_RFC_2819_COUNTERS)
308
309 struct mlx5e_pport_stats {
310         __be64 IEEE_802_3_counters[NUM_IEEE_802_3_COUNTERS];
311         __be64 RFC_2863_counters[NUM_RFC_2863_COUNTERS];
312         __be64 RFC_2819_counters[NUM_RFC_2819_COUNTERS];
313 };
314
315 static const char qcounter_stats_strings[][ETH_GSTRING_LEN] = {
316         "rx_out_of_buffer",
317 };
318
319 struct mlx5e_qcounter_stats {
320         u32 rx_out_of_buffer;
321 #define NUM_Q_COUNTERS 1
322 };
323
324 static const char rq_stats_strings[][ETH_GSTRING_LEN] = {
325         "packets",
326         "bytes",
327         "csum_none",
328         "csum_sw",
329         "lro_packets",
330         "lro_bytes",
331         "wqe_err",
332         "mpwqe_filler",
333         "mpwqe_frag",
334         "buff_alloc_err",
335 };
336
337 struct mlx5e_rq_stats {
338         u64 packets;
339         u64 bytes;
340         u64 csum_none;
341         u64 csum_sw;
342         u64 lro_packets;
343         u64 lro_bytes;
344         u64 wqe_err;
345         u64 mpwqe_filler;
346         u64 mpwqe_frag;
347         u64 buff_alloc_err;
348 #define NUM_RQ_STATS 10
349 };
350
351 static const char sq_stats_strings[][ETH_GSTRING_LEN] = {
352         "packets",
353         "bytes",
354         "tso_packets",
355         "tso_bytes",
356         "tso_inner_packets",
357         "tso_inner_bytes",
358         "csum_offload_inner",
359         "nop",
360         "csum_offload_none",
361         "stopped",
362         "wake",
363         "dropped",
364 };
365
366 struct mlx5e_sq_stats {
367         /* commonly accessed in data path */
368         u64 packets;
369         u64 bytes;
370         u64 tso_packets;
371         u64 tso_bytes;
372         u64 tso_inner_packets;
373         u64 tso_inner_bytes;
374         u64 csum_offload_inner;
375         u64 nop;
376         /* less likely accessed in data path */
377         u64 csum_offload_none;
378         u64 stopped;
379         u64 wake;
380         u64 dropped;
381 #define NUM_SQ_STATS 12
382 };
383
384 struct mlx5e_stats {
385         struct mlx5e_vport_stats   vport;
386         struct mlx5e_pport_stats   pport;
387         struct mlx5e_qcounter_stats qcnt;
388 };
389
390 struct mlx5e_params {
391         u8  log_sq_size;
392         u8  rq_wq_type;
393         u8  log_rq_size;
394         u16 num_channels;
395         u8  num_tc;
396         u16 rx_cq_moderation_usec;
397         u16 rx_cq_moderation_pkts;
398         u16 tx_cq_moderation_usec;
399         u16 tx_cq_moderation_pkts;
400         u16 min_rx_wqes;
401         bool lro_en;
402         u32 lro_wqe_sz;
403         u16 tx_max_inline;
404         u8  rss_hfunc;
405         u8  toeplitz_hash_key[40];
406         u32 indirection_rqt[MLX5E_INDIR_RQT_SIZE];
407 #ifdef CONFIG_MLX5_CORE_EN_DCB
408         struct ieee_ets ets;
409 #endif
410 };
411
412 struct mlx5e_tstamp {
413         rwlock_t                   lock;
414         struct cyclecounter        cycles;
415         struct timecounter         clock;
416         struct hwtstamp_config     hwtstamp_config;
417         u32                        nominal_c_mult;
418         unsigned long              overflow_period;
419         struct delayed_work        overflow_work;
420         struct mlx5_core_dev      *mdev;
421         struct ptp_clock          *ptp;
422         struct ptp_clock_info      ptp_info;
423 };
424
425 enum {
426         MLX5E_RQ_STATE_POST_WQES_ENABLE,
427         MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS,
428 };
429
430 struct mlx5e_cq {
431         /* data path - accessed per cqe */
432         struct mlx5_cqwq           wq;
433
434         /* data path - accessed per napi poll */
435         struct napi_struct        *napi;
436         struct mlx5_core_cq        mcq;
437         struct mlx5e_channel      *channel;
438         struct mlx5e_priv         *priv;
439
440         /* control */
441         struct mlx5_wq_ctrl        wq_ctrl;
442 } ____cacheline_aligned_in_smp;
443
444 struct mlx5e_rq;
445 typedef void (*mlx5e_fp_handle_rx_cqe)(struct mlx5e_rq *rq,
446                                        struct mlx5_cqe64 *cqe);
447 typedef int (*mlx5e_fp_alloc_wqe)(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe,
448                                   u16 ix);
449
450 struct mlx5e_dma_info {
451         struct page     *page;
452         dma_addr_t      addr;
453 };
454
455 struct mlx5e_rq {
456         /* data path */
457         struct mlx5_wq_ll      wq;
458         u32                    wqe_sz;
459         struct sk_buff       **skb;
460         struct mlx5e_mpw_info *wqe_info;
461         __be32                 mkey_be;
462         __be32                 umr_mkey_be;
463
464         struct device         *pdev;
465         struct net_device     *netdev;
466         struct mlx5e_tstamp   *tstamp;
467         struct mlx5e_rq_stats  stats;
468         struct mlx5e_cq        cq;
469         mlx5e_fp_handle_rx_cqe handle_rx_cqe;
470         mlx5e_fp_alloc_wqe     alloc_wqe;
471
472         unsigned long          state;
473         int                    ix;
474
475         /* control */
476         struct mlx5_wq_ctrl    wq_ctrl;
477         u8                     wq_type;
478         u32                    rqn;
479         struct mlx5e_channel  *channel;
480         struct mlx5e_priv     *priv;
481 } ____cacheline_aligned_in_smp;
482
483 struct mlx5e_umr_dma_info {
484         __be64                *mtt;
485         __be64                *mtt_no_align;
486         dma_addr_t             mtt_addr;
487         struct mlx5e_dma_info *dma_info;
488 };
489
490 struct mlx5e_mpw_info {
491         union {
492                 struct mlx5e_dma_info     dma_info;
493                 struct mlx5e_umr_dma_info umr;
494         };
495         u16 consumed_strides;
496         u16 skbs_frags[MLX5_MPWRQ_PAGES_PER_WQE];
497
498         void (*dma_pre_sync)(struct device *pdev,
499                              struct mlx5e_mpw_info *wi,
500                              u32 wqe_offset, u32 len);
501         void (*add_skb_frag)(struct device *pdev,
502                              struct sk_buff *skb,
503                              struct mlx5e_mpw_info *wi,
504                              u32 page_idx, u32 frag_offset, u32 len);
505         void (*copy_skb_header)(struct device *pdev,
506                                 struct sk_buff *skb,
507                                 struct mlx5e_mpw_info *wi,
508                                 u32 page_idx, u32 offset,
509                                 u32 headlen);
510         void (*free_wqe)(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi);
511 };
512
513 struct mlx5e_tx_wqe_info {
514         u32 num_bytes;
515         u8  num_wqebbs;
516         u8  num_dma;
517 };
518
519 enum mlx5e_dma_map_type {
520         MLX5E_DMA_MAP_SINGLE,
521         MLX5E_DMA_MAP_PAGE
522 };
523
524 struct mlx5e_sq_dma {
525         dma_addr_t              addr;
526         u32                     size;
527         enum mlx5e_dma_map_type type;
528 };
529
530 enum {
531         MLX5E_SQ_STATE_WAKE_TXQ_ENABLE,
532         MLX5E_SQ_STATE_BF_ENABLE,
533 };
534
535 struct mlx5e_ico_wqe_info {
536         u8  opcode;
537         u8  num_wqebbs;
538 };
539
540 struct mlx5e_sq {
541         /* data path */
542
543         /* dirtied @completion */
544         u16                        cc;
545         u32                        dma_fifo_cc;
546
547         /* dirtied @xmit */
548         u16                        pc ____cacheline_aligned_in_smp;
549         u32                        dma_fifo_pc;
550         u16                        bf_offset;
551         u16                        prev_cc;
552         u8                         bf_budget;
553         struct mlx5e_sq_stats      stats;
554
555         struct mlx5e_cq            cq;
556
557         /* pointers to per packet info: write@xmit, read@completion */
558         struct sk_buff           **skb;
559         struct mlx5e_sq_dma       *dma_fifo;
560         struct mlx5e_tx_wqe_info  *wqe_info;
561
562         /* read only */
563         struct mlx5_wq_cyc         wq;
564         u32                        dma_fifo_mask;
565         void __iomem              *uar_map;
566         struct netdev_queue       *txq;
567         u32                        sqn;
568         u16                        bf_buf_size;
569         u16                        max_inline;
570         u16                        edge;
571         struct device             *pdev;
572         struct mlx5e_tstamp       *tstamp;
573         __be32                     mkey_be;
574         unsigned long              state;
575
576         /* control path */
577         struct mlx5_wq_ctrl        wq_ctrl;
578         struct mlx5_uar            uar;
579         struct mlx5e_channel      *channel;
580         int                        tc;
581         struct mlx5e_ico_wqe_info *ico_wqe_info;
582 } ____cacheline_aligned_in_smp;
583
584 static inline bool mlx5e_sq_has_room_for(struct mlx5e_sq *sq, u16 n)
585 {
586         return (((sq->wq.sz_m1 & (sq->cc - sq->pc)) >= n) ||
587                 (sq->cc  == sq->pc));
588 }
589
590 enum channel_flags {
591         MLX5E_CHANNEL_NAPI_SCHED = 1,
592 };
593
594 struct mlx5e_channel {
595         /* data path */
596         struct mlx5e_rq            rq;
597         struct mlx5e_sq            sq[MLX5E_MAX_NUM_TC];
598         struct mlx5e_sq            icosq;   /* internal control operations */
599         struct napi_struct         napi;
600         struct device             *pdev;
601         struct net_device         *netdev;
602         __be32                     mkey_be;
603         u8                         num_tc;
604         unsigned long              flags;
605
606         /* control */
607         struct mlx5e_priv         *priv;
608         int                        ix;
609         int                        cpu;
610 };
611
612 enum mlx5e_traffic_types {
613         MLX5E_TT_IPV4_TCP,
614         MLX5E_TT_IPV6_TCP,
615         MLX5E_TT_IPV4_UDP,
616         MLX5E_TT_IPV6_UDP,
617         MLX5E_TT_IPV4_IPSEC_AH,
618         MLX5E_TT_IPV6_IPSEC_AH,
619         MLX5E_TT_IPV4_IPSEC_ESP,
620         MLX5E_TT_IPV6_IPSEC_ESP,
621         MLX5E_TT_IPV4,
622         MLX5E_TT_IPV6,
623         MLX5E_TT_ANY,
624         MLX5E_NUM_TT,
625 };
626
627 #define IS_HASHING_TT(tt) (tt != MLX5E_TT_ANY)
628
629 enum mlx5e_rqt_ix {
630         MLX5E_INDIRECTION_RQT,
631         MLX5E_SINGLE_RQ_RQT,
632         MLX5E_NUM_RQT,
633 };
634
635 struct mlx5e_eth_addr_info {
636         u8  addr[ETH_ALEN + 2];
637         u32 tt_vec;
638         struct mlx5_flow_rule *ft_rule[MLX5E_NUM_TT];
639 };
640
641 #define MLX5E_ETH_ADDR_HASH_SIZE (1 << BITS_PER_BYTE)
642
643 struct mlx5e_eth_addr_db {
644         struct hlist_head          netdev_uc[MLX5E_ETH_ADDR_HASH_SIZE];
645         struct hlist_head          netdev_mc[MLX5E_ETH_ADDR_HASH_SIZE];
646         struct mlx5e_eth_addr_info broadcast;
647         struct mlx5e_eth_addr_info allmulti;
648         struct mlx5e_eth_addr_info promisc;
649         bool                       broadcast_enabled;
650         bool                       allmulti_enabled;
651         bool                       promisc_enabled;
652 };
653
654 enum {
655         MLX5E_STATE_ASYNC_EVENTS_ENABLE,
656         MLX5E_STATE_OPENED,
657         MLX5E_STATE_DESTROYING,
658 };
659
660 struct mlx5e_vlan_db {
661         unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
662         struct mlx5_flow_rule   *active_vlans_rule[VLAN_N_VID];
663         struct mlx5_flow_rule   *untagged_rule;
664         struct mlx5_flow_rule   *any_vlan_rule;
665         bool          filter_disabled;
666 };
667
668 struct mlx5e_vxlan_db {
669         spinlock_t                      lock; /* protect vxlan table */
670         struct radix_tree_root          tree;
671 };
672
673 struct mlx5e_flow_table {
674         int num_groups;
675         struct mlx5_flow_table          *t;
676         struct mlx5_flow_group          **g;
677 };
678
679 struct mlx5e_tc_flow_table {
680         struct mlx5_flow_table          *t;
681
682         struct rhashtable_params        ht_params;
683         struct rhashtable               ht;
684 };
685
686 struct mlx5e_flow_tables {
687         struct mlx5_flow_namespace      *ns;
688         struct mlx5e_tc_flow_table      tc;
689         struct mlx5e_flow_table         vlan;
690         struct mlx5e_flow_table         main;
691 };
692
693 struct mlx5e_priv {
694         /* priv data path fields - start */
695         struct mlx5e_sq            **txq_to_sq_map;
696         int channeltc_to_txq_map[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
697         /* priv data path fields - end */
698
699         unsigned long              state;
700         struct mutex               state_lock; /* Protects Interface state */
701         struct mlx5_uar            cq_uar;
702         u32                        pdn;
703         u32                        tdn;
704         struct mlx5_core_mkey      mkey;
705         struct mlx5_core_mkey      umr_mkey;
706         struct mlx5e_rq            drop_rq;
707
708         struct mlx5e_channel     **channel;
709         u32                        tisn[MLX5E_MAX_NUM_TC];
710         u32                        rqtn[MLX5E_NUM_RQT];
711         u32                        tirn[MLX5E_NUM_TT];
712
713         struct mlx5e_flow_tables   fts;
714         struct mlx5e_eth_addr_db   eth_addr;
715         struct mlx5e_vlan_db       vlan;
716         struct mlx5e_vxlan_db      vxlan;
717
718         struct mlx5e_params        params;
719         struct work_struct         update_carrier_work;
720         struct work_struct         set_rx_mode_work;
721         struct delayed_work        update_stats_work;
722
723         struct mlx5_core_dev      *mdev;
724         struct net_device         *netdev;
725         struct mlx5e_stats         stats;
726         struct mlx5e_tstamp        tstamp;
727         u16 q_counter;
728 };
729
730 enum mlx5e_link_mode {
731         MLX5E_1000BASE_CX_SGMII  = 0,
732         MLX5E_1000BASE_KX        = 1,
733         MLX5E_10GBASE_CX4        = 2,
734         MLX5E_10GBASE_KX4        = 3,
735         MLX5E_10GBASE_KR         = 4,
736         MLX5E_20GBASE_KR2        = 5,
737         MLX5E_40GBASE_CR4        = 6,
738         MLX5E_40GBASE_KR4        = 7,
739         MLX5E_56GBASE_R4         = 8,
740         MLX5E_10GBASE_CR         = 12,
741         MLX5E_10GBASE_SR         = 13,
742         MLX5E_10GBASE_ER         = 14,
743         MLX5E_40GBASE_SR4        = 15,
744         MLX5E_40GBASE_LR4        = 16,
745         MLX5E_100GBASE_CR4       = 20,
746         MLX5E_100GBASE_SR4       = 21,
747         MLX5E_100GBASE_KR4       = 22,
748         MLX5E_100GBASE_LR4       = 23,
749         MLX5E_100BASE_TX         = 24,
750         MLX5E_100BASE_T          = 25,
751         MLX5E_10GBASE_T          = 26,
752         MLX5E_25GBASE_CR         = 27,
753         MLX5E_25GBASE_KR         = 28,
754         MLX5E_25GBASE_SR         = 29,
755         MLX5E_50GBASE_CR2        = 30,
756         MLX5E_50GBASE_KR2        = 31,
757         MLX5E_LINK_MODES_NUMBER,
758 };
759
760 #define MLX5E_PROT_MASK(link_mode) (1 << link_mode)
761
762 void mlx5e_send_nop(struct mlx5e_sq *sq, bool notify_hw);
763 u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
764                        void *accel_priv, select_queue_fallback_t fallback);
765 netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
766
767 void mlx5e_completion_event(struct mlx5_core_cq *mcq);
768 void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
769 int mlx5e_napi_poll(struct napi_struct *napi, int budget);
770 bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget);
771 int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
772
773 void mlx5e_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
774 void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
775 bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
776 int mlx5e_alloc_rx_wqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe, u16 ix);
777 int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe, u16 ix);
778 void mlx5e_post_rx_fragmented_mpwqe(struct mlx5e_rq *rq);
779 void mlx5e_complete_rx_linear_mpwqe(struct mlx5e_rq *rq,
780                                     struct mlx5_cqe64 *cqe,
781                                     u16 byte_cnt,
782                                     struct mlx5e_mpw_info *wi,
783                                     struct sk_buff *skb);
784 void mlx5e_complete_rx_fragmented_mpwqe(struct mlx5e_rq *rq,
785                                         struct mlx5_cqe64 *cqe,
786                                         u16 byte_cnt,
787                                         struct mlx5e_mpw_info *wi,
788                                         struct sk_buff *skb);
789 void mlx5e_free_rx_linear_mpwqe(struct mlx5e_rq *rq,
790                                 struct mlx5e_mpw_info *wi);
791 void mlx5e_free_rx_fragmented_mpwqe(struct mlx5e_rq *rq,
792                                     struct mlx5e_mpw_info *wi);
793 struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);
794
795 void mlx5e_update_stats(struct mlx5e_priv *priv);
796
797 int mlx5e_create_flow_tables(struct mlx5e_priv *priv);
798 void mlx5e_destroy_flow_tables(struct mlx5e_priv *priv);
799 void mlx5e_init_eth_addr(struct mlx5e_priv *priv);
800 void mlx5e_set_rx_mode_work(struct work_struct *work);
801
802 void mlx5e_fill_hwstamp(struct mlx5e_tstamp *clock, u64 timestamp,
803                         struct skb_shared_hwtstamps *hwts);
804 void mlx5e_timestamp_init(struct mlx5e_priv *priv);
805 void mlx5e_timestamp_cleanup(struct mlx5e_priv *priv);
806 int mlx5e_hwstamp_set(struct net_device *dev, struct ifreq *ifr);
807 int mlx5e_hwstamp_get(struct net_device *dev, struct ifreq *ifr);
808
809 int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
810                           u16 vid);
811 int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
812                            u16 vid);
813 void mlx5e_enable_vlan_filter(struct mlx5e_priv *priv);
814 void mlx5e_disable_vlan_filter(struct mlx5e_priv *priv);
815
816 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, enum mlx5e_rqt_ix rqt_ix);
817 void mlx5e_build_tir_ctx_hash(void *tirc, struct mlx5e_priv *priv);
818
819 int mlx5e_open_locked(struct net_device *netdev);
820 int mlx5e_close_locked(struct net_device *netdev);
821 void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
822                                    u32 *indirection_rqt, int len,
823                                    int num_channels);
824
825 static inline void mlx5e_tx_notify_hw(struct mlx5e_sq *sq,
826                                       struct mlx5_wqe_ctrl_seg *ctrl, int bf_sz)
827 {
828         u16 ofst = MLX5_BF_OFFSET + sq->bf_offset;
829
830         /* ensure wqe is visible to device before updating doorbell record */
831         dma_wmb();
832
833         *sq->wq.db = cpu_to_be32(sq->pc);
834
835         /* ensure doorbell record is visible to device before ringing the
836          * doorbell
837          */
838         wmb();
839         if (bf_sz)
840                 __iowrite64_copy(sq->uar_map + ofst, ctrl, bf_sz);
841         else
842                 mlx5_write64((__be32 *)ctrl, sq->uar_map + ofst, NULL);
843         /* flush the write-combining mapped buffer */
844         wmb();
845
846         sq->bf_offset ^= sq->bf_buf_size;
847 }
848
849 static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
850 {
851         struct mlx5_core_cq *mcq;
852
853         mcq = &cq->mcq;
854         mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, NULL, cq->wq.cc);
855 }
856
857 static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
858 {
859         return min_t(int, mdev->priv.eq_table.num_comp_vectors,
860                      MLX5E_MAX_NUM_CHANNELS);
861 }
862
863 static inline int mlx5e_get_mtt_octw(int npages)
864 {
865         return ALIGN(npages, 8) / 2;
866 }
867
868 extern const struct ethtool_ops mlx5e_ethtool_ops;
869 #ifdef CONFIG_MLX5_CORE_EN_DCB
870 extern const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops;
871 int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets);
872 #endif
873
874 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
875
876 #endif /* __MLX5_EN_H__ */