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