2 * Copyright (c) 2015-2016, Mellanox Technologies. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
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/crash_dump.h>
41 #include <linux/mlx5/driver.h>
42 #include <linux/mlx5/qp.h>
43 #include <linux/mlx5/cq.h>
44 #include <linux/mlx5/port.h>
45 #include <linux/mlx5/vport.h>
46 #include <linux/mlx5/transobj.h>
47 #include <linux/rhashtable.h>
48 #include <net/switchdev.h>
50 #include "mlx5_core.h"
53 #define MLX5_SET_CFG(p, f, v) MLX5_SET(create_flow_group_in, p, f, v)
55 #define MLX5E_HW2SW_MTU(hwmtu) ((hwmtu) - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
56 #define MLX5E_SW2HW_MTU(swmtu) ((swmtu) + (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
58 #define MLX5E_MAX_NUM_TC 8
60 #define MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE 0x6
61 #define MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE 0xa
62 #define MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE 0xd
64 #define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE 0x1
65 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE 0xa
66 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE 0xd
68 #define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW 0x1
69 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE_MPW 0x3
70 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW 0x6
72 #define MLX5_RX_HEADROOM NET_SKB_PAD
74 #define MLX5_MPWRQ_MIN_LOG_STRIDE_SZ(mdev) \
75 (6 + MLX5_CAP_GEN(mdev, cache_line_128byte)) /* HW restriction */
76 #define MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, req) \
77 max_t(u32, MLX5_MPWRQ_MIN_LOG_STRIDE_SZ(mdev), req)
78 #define MLX5_MPWRQ_DEF_LOG_STRIDE_SZ(mdev) MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, 6)
79 #define MLX5_MPWRQ_CQE_CMPRS_LOG_STRIDE_SZ(mdev) MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, 8)
81 #define MLX5_MPWRQ_LOG_WQE_SZ 18
82 #define MLX5_MPWRQ_WQE_PAGE_ORDER (MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT > 0 ? \
83 MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT : 0)
84 #define MLX5_MPWRQ_PAGES_PER_WQE BIT(MLX5_MPWRQ_WQE_PAGE_ORDER)
85 #define MLX5_MPWRQ_STRIDES_PER_PAGE (MLX5_MPWRQ_NUM_STRIDES >> \
86 MLX5_MPWRQ_WQE_PAGE_ORDER)
88 #define MLX5_MTT_OCTW(npages) (ALIGN(npages, 8) / 2)
89 #define MLX5E_REQUIRED_MTTS(wqes) \
90 (wqes * ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8))
91 #define MLX5E_VALID_NUM_MTTS(num_mtts) (MLX5_MTT_OCTW(num_mtts) - 1 <= U16_MAX)
93 #define MLX5_UMR_ALIGN (2048)
94 #define MLX5_MPWRQ_SMALL_PACKET_THRESHOLD (256)
96 #define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ (64 * 1024)
97 #define MLX5E_DEFAULT_LRO_TIMEOUT 32
98 #define MLX5E_LRO_TIMEOUT_ARR_SIZE 4
100 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC 0x10
101 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE 0x3
102 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS 0x20
103 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC 0x10
104 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS 0x20
105 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES 0x80
106 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW 0x2
108 #define MLX5E_LOG_INDIR_RQT_SIZE 0x7
109 #define MLX5E_INDIR_RQT_SIZE BIT(MLX5E_LOG_INDIR_RQT_SIZE)
110 #define MLX5E_MIN_NUM_CHANNELS 0x1
111 #define MLX5E_MAX_NUM_CHANNELS (MLX5E_INDIR_RQT_SIZE >> 1)
112 #define MLX5E_MAX_NUM_SQS (MLX5E_MAX_NUM_CHANNELS * MLX5E_MAX_NUM_TC)
113 #define MLX5E_TX_CQ_POLL_BUDGET 128
114 #define MLX5E_UPDATE_STATS_INTERVAL 200 /* msecs */
116 #define MLX5E_ICOSQ_MAX_WQEBBS \
117 (DIV_ROUND_UP(sizeof(struct mlx5e_umr_wqe), MLX5_SEND_WQE_BB))
119 #define MLX5E_XDP_MIN_INLINE (ETH_HLEN + VLAN_HLEN)
120 #define MLX5E_XDP_TX_DS_COUNT \
121 ((sizeof(struct mlx5e_tx_wqe) / MLX5_SEND_WQE_DS) + 1 /* SG DS */)
123 #define MLX5E_NUM_MAIN_GROUPS 9
125 static inline u16 mlx5_min_rx_wqes(int wq_type, u32 wq_size)
128 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
129 return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW,
132 return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES,
137 static inline int mlx5_min_log_rq_size(int wq_type)
140 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
141 return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW;
143 return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE;
147 static inline int mlx5_max_log_rq_size(int wq_type)
150 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
151 return MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW;
153 return MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE;
157 static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
159 return is_kdump_kernel() ?
160 MLX5E_MIN_NUM_CHANNELS :
161 min_t(int, mdev->priv.eq_table.num_comp_vectors,
162 MLX5E_MAX_NUM_CHANNELS);
165 struct mlx5e_tx_wqe {
166 struct mlx5_wqe_ctrl_seg ctrl;
167 struct mlx5_wqe_eth_seg eth;
170 struct mlx5e_rx_wqe {
171 struct mlx5_wqe_srq_next_seg next;
172 struct mlx5_wqe_data_seg data;
175 struct mlx5e_umr_wqe {
176 struct mlx5_wqe_ctrl_seg ctrl;
177 struct mlx5_wqe_umr_ctrl_seg uctrl;
178 struct mlx5_mkey_seg mkc;
179 struct mlx5_wqe_data_seg data;
182 extern const char mlx5e_self_tests[][ETH_GSTRING_LEN];
184 static const char mlx5e_priv_flags[][ETH_GSTRING_LEN] = {
189 enum mlx5e_priv_flag {
190 MLX5E_PFLAG_RX_CQE_BASED_MODER = (1 << 0),
191 MLX5E_PFLAG_RX_CQE_COMPRESS = (1 << 1),
194 #define MLX5E_SET_PFLAG(params, pflag, enable) \
197 (params)->pflags |= (pflag); \
199 (params)->pflags &= ~(pflag); \
202 #define MLX5E_GET_PFLAG(params, pflag) (!!((params)->pflags & (pflag)))
204 #ifdef CONFIG_MLX5_CORE_EN_DCB
205 #define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */
208 struct mlx5e_cq_moder {
213 struct mlx5e_params {
216 u8 mpwqe_log_stride_sz;
217 u8 mpwqe_log_num_strides;
221 u8 rx_cq_period_mode;
222 bool rx_cqe_compress_def;
223 struct mlx5e_cq_moder rx_cq_moderation;
224 struct mlx5e_cq_moder tx_cq_moderation;
228 u8 tx_min_inline_mode;
230 u8 toeplitz_hash_key[40];
231 u32 indirection_rqt[MLX5E_INDIR_RQT_SIZE];
232 bool vlan_strip_disable;
237 struct bpf_prog *xdp_prog;
240 #ifdef CONFIG_MLX5_CORE_EN_DCB
241 struct mlx5e_cee_config {
242 /* bw pct for priority group */
243 u8 pg_bw_pct[CEE_DCBX_MAX_PGS];
244 u8 prio_to_pg_map[CEE_DCBX_MAX_PRIO];
245 bool pfc_setting[CEE_DCBX_MAX_PRIO];
252 MLX5_DCB_CHG_NO_RESET,
256 enum mlx5_dcbx_oper_mode mode;
257 struct mlx5e_cee_config cee_cfg; /* pending configuration */
259 /* The only setting that cannot be read from FW */
260 u8 tc_tsa[IEEE_8021QAZ_MAX_TCS];
264 struct mlx5e_tstamp {
266 struct cyclecounter cycles;
267 struct timecounter clock;
268 struct hwtstamp_config hwtstamp_config;
270 unsigned long overflow_period;
271 struct delayed_work overflow_work;
272 struct mlx5_core_dev *mdev;
273 struct ptp_clock *ptp;
274 struct ptp_clock_info ptp_info;
279 MLX5E_RQ_STATE_ENABLED,
280 MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS,
285 /* data path - accessed per cqe */
288 /* data path - accessed per napi poll */
290 struct napi_struct *napi;
291 struct mlx5_core_cq mcq;
292 struct mlx5e_channel *channel;
294 /* cqe decompression */
295 struct mlx5_cqe64 title;
296 struct mlx5_mini_cqe8 mini_arr[MLX5_MINI_CQE_ARRAY_SIZE];
299 u16 decmprs_wqe_counter;
302 struct mlx5_core_dev *mdev;
303 struct mlx5_frag_wq_ctrl wq_ctrl;
304 } ____cacheline_aligned_in_smp;
306 struct mlx5e_tx_wqe_info {
313 enum mlx5e_dma_map_type {
314 MLX5E_DMA_MAP_SINGLE,
318 struct mlx5e_sq_dma {
321 enum mlx5e_dma_map_type type;
325 MLX5E_SQ_STATE_ENABLED,
328 struct mlx5e_sq_wqe_info {
336 /* dirtied @completion */
341 u16 pc ____cacheline_aligned_in_smp;
343 struct mlx5e_sq_stats stats;
347 /* write@xmit, read@completion */
349 struct mlx5e_sq_dma *dma_fifo;
350 struct mlx5e_tx_wqe_info *wqe_info;
354 struct mlx5_wq_cyc wq;
356 void __iomem *uar_map;
357 struct netdev_queue *txq;
363 struct mlx5e_tstamp *tstamp;
368 struct mlx5_wq_ctrl wq_ctrl;
369 struct mlx5e_channel *channel;
372 } ____cacheline_aligned_in_smp;
377 /* dirtied @rx completion */
383 /* write@xmit, read@completion */
385 struct mlx5e_dma_info *di;
390 struct mlx5_wq_cyc wq;
391 void __iomem *uar_map;
399 struct mlx5_wq_ctrl wq_ctrl;
400 struct mlx5e_channel *channel;
401 } ____cacheline_aligned_in_smp;
406 /* dirtied @completion */
410 u16 pc ____cacheline_aligned_in_smp;
416 /* write@xmit, read@completion */
418 struct mlx5e_sq_wqe_info *ico_wqe;
422 struct mlx5_wq_cyc wq;
423 void __iomem *uar_map;
431 struct mlx5_wq_ctrl wq_ctrl;
432 struct mlx5e_channel *channel;
433 } ____cacheline_aligned_in_smp;
436 mlx5e_wqc_has_room_for(struct mlx5_wq_cyc *wq, u16 cc, u16 pc, u16 n)
438 return (((wq->sz_m1 & (cc - pc)) >= n) || (cc == pc));
441 struct mlx5e_dma_info {
446 struct mlx5e_umr_dma_info {
449 struct mlx5e_dma_info dma_info[MLX5_MPWRQ_PAGES_PER_WQE];
450 struct mlx5e_umr_wqe wqe;
453 struct mlx5e_mpw_info {
454 struct mlx5e_umr_dma_info umr;
455 u16 consumed_strides;
456 u16 skbs_frags[MLX5_MPWRQ_PAGES_PER_WQE];
459 struct mlx5e_rx_am_stats {
460 int ppms; /* packets per msec */
461 int bpms; /* bytes per msec */
462 int epms; /* events per msec */
465 struct mlx5e_rx_am_sample {
472 struct mlx5e_rx_am { /* Adaptive Moderation */
474 struct mlx5e_rx_am_stats prev_stats;
475 struct mlx5e_rx_am_sample start_sample;
476 struct work_struct work;
485 /* a single cache unit is capable to serve one napi call (for non-striding rq)
486 * or a MPWQE (for striding rq).
488 #define MLX5E_CACHE_UNIT (MLX5_MPWRQ_PAGES_PER_WQE > NAPI_POLL_WEIGHT ? \
489 MLX5_MPWRQ_PAGES_PER_WQE : NAPI_POLL_WEIGHT)
490 #define MLX5E_CACHE_SIZE (2 * roundup_pow_of_two(MLX5E_CACHE_UNIT))
491 struct mlx5e_page_cache {
494 struct mlx5e_dma_info page_cache[MLX5E_CACHE_SIZE];
498 typedef void (*mlx5e_fp_handle_rx_cqe)(struct mlx5e_rq*, struct mlx5_cqe64*);
499 typedef int (*mlx5e_fp_alloc_wqe)(struct mlx5e_rq*, struct mlx5e_rx_wqe*, u16);
500 typedef void (*mlx5e_fp_dealloc_wqe)(struct mlx5e_rq*, u16);
504 struct mlx5_wq_ll wq;
507 struct mlx5e_dma_info *dma_info;
509 struct mlx5e_mpw_info *info;
515 u32 wqe_sz; /* wqe data buffer size */
516 u8 map_dir; /* dma map direction */
521 struct net_device *netdev;
522 struct mlx5e_tstamp *tstamp;
523 struct mlx5e_rq_stats stats;
525 struct mlx5e_page_cache page_cache;
527 mlx5e_fp_handle_rx_cqe handle_rx_cqe;
528 mlx5e_fp_alloc_wqe alloc_wqe;
529 mlx5e_fp_dealloc_wqe dealloc_wqe;
535 struct mlx5e_rx_am am; /* Adaptive Moderation */
538 struct bpf_prog *xdp_prog;
539 struct mlx5e_xdpsq xdpsq;
542 struct mlx5_wq_ctrl wq_ctrl;
545 u32 mpwqe_num_strides;
547 struct mlx5e_channel *channel;
548 struct mlx5_core_dev *mdev;
549 struct mlx5_core_mkey umr_mkey;
550 } ____cacheline_aligned_in_smp;
553 MLX5E_CHANNEL_NAPI_SCHED = 1,
556 struct mlx5e_channel {
559 struct mlx5e_txqsq sq[MLX5E_MAX_NUM_TC];
560 struct mlx5e_icosq icosq; /* internal control operations */
562 struct napi_struct napi;
564 struct net_device *netdev;
570 struct mlx5e_priv *priv;
571 struct mlx5_core_dev *mdev;
572 struct mlx5e_tstamp *tstamp;
577 struct mlx5e_channels {
578 struct mlx5e_channel **c;
580 struct mlx5e_params params;
583 enum mlx5e_traffic_types {
588 MLX5E_TT_IPV4_IPSEC_AH,
589 MLX5E_TT_IPV6_IPSEC_AH,
590 MLX5E_TT_IPV4_IPSEC_ESP,
591 MLX5E_TT_IPV6_IPSEC_ESP,
596 MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
600 MLX5E_STATE_ASYNC_EVENTS_ENABLED,
602 MLX5E_STATE_DESTROYING,
605 struct mlx5e_vxlan_db {
606 spinlock_t lock; /* protect vxlan table */
607 struct radix_tree_root tree;
610 struct mlx5e_l2_rule {
611 u8 addr[ETH_ALEN + 2];
612 struct mlx5_flow_handle *rule;
615 struct mlx5e_flow_table {
617 struct mlx5_flow_table *t;
618 struct mlx5_flow_group **g;
621 #define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
623 struct mlx5e_tc_table {
624 struct mlx5_flow_table *t;
626 struct rhashtable_params ht_params;
627 struct rhashtable ht;
630 struct mlx5e_vlan_table {
631 struct mlx5e_flow_table ft;
632 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
633 struct mlx5_flow_handle *active_vlans_rule[VLAN_N_VID];
634 struct mlx5_flow_handle *untagged_rule;
635 struct mlx5_flow_handle *any_cvlan_rule;
636 struct mlx5_flow_handle *any_svlan_rule;
637 bool filter_disabled;
640 struct mlx5e_l2_table {
641 struct mlx5e_flow_table ft;
642 struct hlist_head netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
643 struct hlist_head netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
644 struct mlx5e_l2_rule broadcast;
645 struct mlx5e_l2_rule allmulti;
646 struct mlx5e_l2_rule promisc;
647 bool broadcast_enabled;
648 bool allmulti_enabled;
649 bool promisc_enabled;
652 /* L3/L4 traffic type classifier */
653 struct mlx5e_ttc_table {
654 struct mlx5e_flow_table ft;
655 struct mlx5_flow_handle *rules[MLX5E_NUM_TT];
658 #define ARFS_HASH_SHIFT BITS_PER_BYTE
659 #define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
661 struct mlx5e_flow_table ft;
662 struct mlx5_flow_handle *default_rule;
663 struct hlist_head rules_hash[ARFS_HASH_SIZE];
674 struct mlx5e_arfs_tables {
675 struct arfs_table arfs_tables[ARFS_NUM_TYPES];
676 /* Protect aRFS rules list */
677 spinlock_t arfs_lock;
678 struct list_head rules;
680 struct workqueue_struct *wq;
685 MLX5E_VLAN_FT_LEVEL = 0,
691 struct mlx5e_ethtool_table {
692 struct mlx5_flow_table *ft;
696 #define ETHTOOL_NUM_L3_L4_FTS 7
697 #define ETHTOOL_NUM_L2_FTS 4
699 struct mlx5e_ethtool_steering {
700 struct mlx5e_ethtool_table l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
701 struct mlx5e_ethtool_table l2_ft[ETHTOOL_NUM_L2_FTS];
702 struct list_head rules;
706 struct mlx5e_flow_steering {
707 struct mlx5_flow_namespace *ns;
708 struct mlx5e_ethtool_steering ethtool;
709 struct mlx5e_tc_table tc;
710 struct mlx5e_vlan_table vlan;
711 struct mlx5e_l2_table l2;
712 struct mlx5e_ttc_table ttc;
713 struct mlx5e_arfs_tables arfs;
723 struct mlx5e_rqt rqt;
724 struct list_head list;
733 /* priv data path fields - start */
734 struct mlx5e_txqsq *txq2sq[MLX5E_MAX_NUM_CHANNELS * MLX5E_MAX_NUM_TC];
735 int channel_tc2txq[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
736 /* priv data path fields - end */
739 struct mutex state_lock; /* Protects Interface state */
740 struct mlx5e_rq drop_rq;
742 struct mlx5e_channels channels;
743 u32 tisn[MLX5E_MAX_NUM_TC];
744 struct mlx5e_rqt indir_rqt;
745 struct mlx5e_tir indir_tir[MLX5E_NUM_INDIR_TIRS];
746 struct mlx5e_tir direct_tir[MLX5E_MAX_NUM_CHANNELS];
747 u32 tx_rates[MLX5E_MAX_NUM_SQS];
749 struct mlx5e_flow_steering fs;
750 struct mlx5e_vxlan_db vxlan;
752 struct workqueue_struct *wq;
753 struct work_struct update_carrier_work;
754 struct work_struct set_rx_mode_work;
755 struct work_struct tx_timeout_work;
756 struct delayed_work update_stats_work;
758 struct mlx5_core_dev *mdev;
759 struct net_device *netdev;
760 struct mlx5e_stats stats;
761 struct mlx5e_tstamp tstamp;
763 #ifdef CONFIG_MLX5_CORE_EN_DCB
764 struct mlx5e_dcbx dcbx;
767 const struct mlx5e_profile *profile;
771 struct mlx5e_profile {
772 void (*init)(struct mlx5_core_dev *mdev,
773 struct net_device *netdev,
774 const struct mlx5e_profile *profile, void *ppriv);
775 void (*cleanup)(struct mlx5e_priv *priv);
776 int (*init_rx)(struct mlx5e_priv *priv);
777 void (*cleanup_rx)(struct mlx5e_priv *priv);
778 int (*init_tx)(struct mlx5e_priv *priv);
779 void (*cleanup_tx)(struct mlx5e_priv *priv);
780 void (*enable)(struct mlx5e_priv *priv);
781 void (*disable)(struct mlx5e_priv *priv);
782 void (*update_stats)(struct mlx5e_priv *priv);
783 int (*max_nch)(struct mlx5_core_dev *mdev);
785 mlx5e_fp_handle_rx_cqe handle_rx_cqe;
786 mlx5e_fp_handle_rx_cqe handle_rx_cqe_mpwqe;
791 void mlx5e_build_ptys2ethtool_map(void);
793 u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
794 void *accel_priv, select_queue_fallback_t fallback);
795 netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
797 void mlx5e_completion_event(struct mlx5_core_cq *mcq);
798 void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
799 int mlx5e_napi_poll(struct napi_struct *napi, int budget);
800 bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget);
801 int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
802 bool mlx5e_poll_xdpsq_cq(struct mlx5e_cq *cq);
803 void mlx5e_free_txqsq_descs(struct mlx5e_txqsq *sq);
804 void mlx5e_free_xdpsq_descs(struct mlx5e_xdpsq *sq);
806 void mlx5e_page_release(struct mlx5e_rq *rq, struct mlx5e_dma_info *dma_info,
808 void mlx5e_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
809 void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
810 bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
811 int mlx5e_alloc_rx_wqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe, u16 ix);
812 int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe, u16 ix);
813 void mlx5e_dealloc_rx_wqe(struct mlx5e_rq *rq, u16 ix);
814 void mlx5e_dealloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix);
815 void mlx5e_post_rx_mpwqe(struct mlx5e_rq *rq);
816 void mlx5e_free_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi);
817 struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);
819 void mlx5e_rx_am(struct mlx5e_rq *rq);
820 void mlx5e_rx_am_work(struct work_struct *work);
821 struct mlx5e_cq_moder mlx5e_am_get_def_profile(u8 rx_cq_period_mode);
823 void mlx5e_update_stats(struct mlx5e_priv *priv);
825 int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
826 void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
827 void mlx5e_init_l2_addr(struct mlx5e_priv *priv);
828 void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
829 int mlx5e_self_test_num(struct mlx5e_priv *priv);
830 void mlx5e_self_test(struct net_device *ndev, struct ethtool_test *etest,
832 int mlx5e_ethtool_get_flow(struct mlx5e_priv *priv, struct ethtool_rxnfc *info,
834 int mlx5e_ethtool_get_all_flows(struct mlx5e_priv *priv,
835 struct ethtool_rxnfc *info, u32 *rule_locs);
836 int mlx5e_ethtool_flow_replace(struct mlx5e_priv *priv,
837 struct ethtool_rx_flow_spec *fs);
838 int mlx5e_ethtool_flow_remove(struct mlx5e_priv *priv,
840 void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
841 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
842 void mlx5e_set_rx_mode_work(struct work_struct *work);
844 void mlx5e_fill_hwstamp(struct mlx5e_tstamp *clock, u64 timestamp,
845 struct skb_shared_hwtstamps *hwts);
846 void mlx5e_timestamp_init(struct mlx5e_priv *priv);
847 void mlx5e_timestamp_cleanup(struct mlx5e_priv *priv);
848 void mlx5e_pps_event_handler(struct mlx5e_priv *priv,
849 struct ptp_clock_event *event);
850 int mlx5e_hwstamp_set(struct net_device *dev, struct ifreq *ifr);
851 int mlx5e_hwstamp_get(struct net_device *dev, struct ifreq *ifr);
852 int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool val);
854 int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
856 int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
858 void mlx5e_enable_vlan_filter(struct mlx5e_priv *priv);
859 void mlx5e_disable_vlan_filter(struct mlx5e_priv *priv);
861 struct mlx5e_redirect_rqt_param {
864 u32 rqn; /* Direct RQN (Non-RSS) */
867 struct mlx5e_channels *channels;
868 } rss; /* RSS data */
872 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, u32 rqtn, int sz,
873 struct mlx5e_redirect_rqt_param rrp);
874 void mlx5e_build_indir_tir_ctx_hash(struct mlx5e_params *params,
875 enum mlx5e_traffic_types tt,
878 int mlx5e_open_locked(struct net_device *netdev);
879 int mlx5e_close_locked(struct net_device *netdev);
881 int mlx5e_open_channels(struct mlx5e_priv *priv,
882 struct mlx5e_channels *chs);
883 void mlx5e_close_channels(struct mlx5e_channels *chs);
885 /* Function pointer to be used to modify WH settings while
888 typedef int (*mlx5e_fp_hw_modify)(struct mlx5e_priv *priv);
889 void mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
890 struct mlx5e_channels *new_chs,
891 mlx5e_fp_hw_modify hw_modify);
892 void mlx5e_activate_priv_channels(struct mlx5e_priv *priv);
893 void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv);
895 void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
896 u32 *indirection_rqt, int len,
898 int mlx5e_get_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
900 void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params,
902 void mlx5e_set_rq_type_params(struct mlx5_core_dev *mdev,
903 struct mlx5e_params *params, u8 rq_type);
906 struct mlx5e_tx_wqe *mlx5e_post_nop(struct mlx5_wq_cyc *wq, u32 sqn, u16 *pc)
908 u16 pi = *pc & wq->sz_m1;
909 struct mlx5e_tx_wqe *wqe = mlx5_wq_cyc_get_wqe(wq, pi);
910 struct mlx5_wqe_ctrl_seg *cseg = &wqe->ctrl;
912 memset(cseg, 0, sizeof(*cseg));
914 cseg->opmod_idx_opcode = cpu_to_be32((*pc << 8) | MLX5_OPCODE_NOP);
915 cseg->qpn_ds = cpu_to_be32((sqn << 8) | 0x01);
923 void mlx5e_notify_hw(struct mlx5_wq_cyc *wq, u16 pc,
924 void __iomem *uar_map,
925 struct mlx5_wqe_ctrl_seg *ctrl)
927 ctrl->fm_ce_se = MLX5_WQE_CTRL_CQ_UPDATE;
928 /* ensure wqe is visible to device before updating doorbell record */
931 *wq->db = cpu_to_be32(pc);
933 /* ensure doorbell record is visible to device before ringing the
938 mlx5_write64((__be32 *)ctrl, uar_map, NULL);
941 static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
943 struct mlx5_core_cq *mcq;
946 mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, cq->wq.cc);
949 static inline u32 mlx5e_get_wqe_mtt_offset(struct mlx5e_rq *rq, u16 wqe_ix)
951 return wqe_ix * ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8);
954 extern const struct ethtool_ops mlx5e_ethtool_ops;
955 #ifdef CONFIG_MLX5_CORE_EN_DCB
956 extern const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops;
957 int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets);
958 void mlx5e_dcbnl_initialize(struct mlx5e_priv *priv);
961 #ifndef CONFIG_RFS_ACCEL
962 static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv)
967 static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
969 static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv)
974 static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv)
979 int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
980 void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
981 int mlx5e_arfs_enable(struct mlx5e_priv *priv);
982 int mlx5e_arfs_disable(struct mlx5e_priv *priv);
983 int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
984 u16 rxq_index, u32 flow_id);
987 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
988 int mlx5e_create_tir(struct mlx5_core_dev *mdev,
989 struct mlx5e_tir *tir, u32 *in, int inlen);
990 void mlx5e_destroy_tir(struct mlx5_core_dev *mdev,
991 struct mlx5e_tir *tir);
992 int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev);
993 void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev);
994 int mlx5e_refresh_tirs(struct mlx5e_priv *priv, bool enable_uc_lb);
996 /* common netdev helpers */
997 int mlx5e_create_indirect_rqt(struct mlx5e_priv *priv);
999 int mlx5e_create_indirect_tirs(struct mlx5e_priv *priv);
1000 void mlx5e_destroy_indirect_tirs(struct mlx5e_priv *priv);
1002 int mlx5e_create_direct_rqts(struct mlx5e_priv *priv);
1003 void mlx5e_destroy_direct_rqts(struct mlx5e_priv *priv);
1004 int mlx5e_create_direct_tirs(struct mlx5e_priv *priv);
1005 void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv);
1006 void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt);
1008 int mlx5e_create_ttc_table(struct mlx5e_priv *priv);
1009 void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv);
1011 int mlx5e_create_tis(struct mlx5_core_dev *mdev, int tc,
1012 u32 underlay_qpn, u32 *tisn);
1013 void mlx5e_destroy_tis(struct mlx5_core_dev *mdev, u32 tisn);
1015 int mlx5e_create_tises(struct mlx5e_priv *priv);
1016 void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv);
1017 int mlx5e_close(struct net_device *netdev);
1018 int mlx5e_open(struct net_device *netdev);
1019 void mlx5e_update_stats_work(struct work_struct *work);
1020 u32 mlx5e_choose_lro_timeout(struct mlx5_core_dev *mdev, u32 wanted_timeout);
1022 /* mlx5e generic netdev management API */
1024 mlx5e_create_netdev(struct mlx5_core_dev *mdev, const struct mlx5e_profile *profile,
1026 int mlx5e_attach_netdev(struct mlx5e_priv *priv);
1027 void mlx5e_detach_netdev(struct mlx5e_priv *priv);
1028 void mlx5e_destroy_netdev(struct mlx5e_priv *priv);
1029 void mlx5e_build_nic_params(struct mlx5_core_dev *mdev,
1030 struct mlx5e_params *params,
1033 #endif /* __MLX5_EN_H__ */