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