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