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