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/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>
47 #include "mlx5_core.h"
49 #define MLX5E_MAX_NUM_TC 8
51 #define MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE 0x6
52 #define MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE 0xa
53 #define MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE 0xd
55 #define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE 0x1
56 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE 0xa
57 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE 0xd
59 #define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ (64 * 1024)
60 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC 0x10
61 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS 0x20
62 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC 0x10
63 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS 0x20
64 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES 0x80
66 #define MLX5E_LOG_INDIR_RQT_SIZE 0x7
67 #define MLX5E_INDIR_RQT_SIZE BIT(MLX5E_LOG_INDIR_RQT_SIZE)
68 #define MLX5E_MAX_NUM_CHANNELS (MLX5E_INDIR_RQT_SIZE >> 1)
69 #define MLX5E_TX_CQ_POLL_BUDGET 128
70 #define MLX5E_UPDATE_STATS_INTERVAL 200 /* msecs */
71 #define MLX5E_SQ_BF_BUDGET 16
73 #define MLX5E_NUM_MAIN_GROUPS 9
75 #ifdef CONFIG_MLX5_CORE_EN_DCB
76 #define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */
77 #define MLX5E_MIN_BW_ALLOC 1 /* Min percentage of BW allocation */
80 static const char vport_strings[][ETH_GSTRING_LEN] = {
81 /* vport statistics */
94 "rx_multicast_packets",
96 "tx_multicast_packets",
98 "rx_broadcast_packets",
100 "tx_broadcast_packets",
101 "tx_broadcast_bytes",
121 struct mlx5e_vport_stats {
127 u64 rx_error_packets;
129 u64 tx_error_packets;
131 u64 rx_unicast_packets;
132 u64 rx_unicast_bytes;
133 u64 tx_unicast_packets;
134 u64 tx_unicast_bytes;
135 u64 rx_multicast_packets;
136 u64 rx_multicast_bytes;
137 u64 tx_multicast_packets;
138 u64 tx_multicast_bytes;
139 u64 rx_broadcast_packets;
140 u64 rx_broadcast_bytes;
141 u64 tx_broadcast_packets;
142 u64 tx_broadcast_bytes;
147 u64 tso_inner_packets;
156 u64 tx_queue_stopped;
158 u64 tx_queue_dropped;
161 #define NUM_VPORT_COUNTERS 35
164 static const char pport_strings[][ETH_GSTRING_LEN] = {
165 /* IEEE802.3 counters */
176 "in_range_len_errors",
186 /* RFC2863 counters */
198 "out_multicast_pkts",
199 "out_broadcast_pkts",
201 /* RFC2819 counters */
222 "p8192to10239octets",
225 #define NUM_IEEE_802_3_COUNTERS 19
226 #define NUM_RFC_2863_COUNTERS 13
227 #define NUM_RFC_2819_COUNTERS 21
228 #define NUM_PPORT_COUNTERS (NUM_IEEE_802_3_COUNTERS + \
229 NUM_RFC_2863_COUNTERS + \
230 NUM_RFC_2819_COUNTERS)
232 struct mlx5e_pport_stats {
233 __be64 IEEE_802_3_counters[NUM_IEEE_802_3_COUNTERS];
234 __be64 RFC_2863_counters[NUM_RFC_2863_COUNTERS];
235 __be64 RFC_2819_counters[NUM_RFC_2819_COUNTERS];
238 static const char rq_stats_strings[][ETH_GSTRING_LEN] = {
247 struct mlx5e_rq_stats {
254 #define NUM_RQ_STATS 6
257 static const char sq_stats_strings[][ETH_GSTRING_LEN] = {
264 "csum_offload_inner",
271 struct mlx5e_sq_stats {
275 u64 tso_inner_packets;
277 u64 csum_offload_none;
278 u64 csum_offload_inner;
283 #define NUM_SQ_STATS 11
287 struct mlx5e_vport_stats vport;
288 struct mlx5e_pport_stats pport;
291 struct mlx5e_params {
296 u16 rx_cq_moderation_usec;
297 u16 rx_cq_moderation_pkts;
298 u16 tx_cq_moderation_usec;
299 u16 tx_cq_moderation_pkts;
305 u8 toeplitz_hash_key[40];
306 u32 indirection_rqt[MLX5E_INDIR_RQT_SIZE];
307 #ifdef CONFIG_MLX5_CORE_EN_DCB
312 struct mlx5e_tstamp {
314 struct cyclecounter cycles;
315 struct timecounter clock;
316 struct hwtstamp_config hwtstamp_config;
318 unsigned long overflow_period;
319 struct delayed_work overflow_work;
320 struct mlx5_core_dev *mdev;
321 struct ptp_clock *ptp;
322 struct ptp_clock_info ptp_info;
326 MLX5E_RQ_STATE_POST_WQES_ENABLE,
330 MLX5E_CQ_HAS_CQES = 1,
334 /* data path - accessed per cqe */
338 /* data path - accessed per napi poll */
339 struct napi_struct *napi;
340 struct mlx5_core_cq mcq;
341 struct mlx5e_channel *channel;
342 struct mlx5e_priv *priv;
345 struct mlx5_wq_ctrl wq_ctrl;
346 } ____cacheline_aligned_in_smp;
350 struct mlx5_wq_ll wq;
352 struct sk_buff **skb;
355 struct net_device *netdev;
356 struct mlx5e_tstamp *tstamp;
357 struct mlx5e_rq_stats stats;
364 struct mlx5_wq_ctrl wq_ctrl;
366 struct mlx5e_channel *channel;
367 struct mlx5e_priv *priv;
368 } ____cacheline_aligned_in_smp;
370 struct mlx5e_tx_wqe_info {
376 enum mlx5e_dma_map_type {
377 MLX5E_DMA_MAP_SINGLE,
381 struct mlx5e_sq_dma {
384 enum mlx5e_dma_map_type type;
388 MLX5E_SQ_STATE_WAKE_TXQ_ENABLE,
394 /* dirtied @completion */
399 u16 pc ____cacheline_aligned_in_smp;
404 struct mlx5e_sq_stats stats;
408 /* pointers to per packet info: write@xmit, read@completion */
409 struct sk_buff **skb;
410 struct mlx5e_sq_dma *dma_fifo;
411 struct mlx5e_tx_wqe_info *wqe_info;
414 struct mlx5_wq_cyc wq;
416 void __iomem *uar_map;
417 void __iomem *uar_bf_map;
418 struct netdev_queue *txq;
424 struct mlx5e_tstamp *tstamp;
429 struct mlx5_wq_ctrl wq_ctrl;
431 struct mlx5e_channel *channel;
433 } ____cacheline_aligned_in_smp;
435 static inline bool mlx5e_sq_has_room_for(struct mlx5e_sq *sq, u16 n)
437 return (((sq->wq.sz_m1 & (sq->cc - sq->pc)) >= n) ||
442 MLX5E_CHANNEL_NAPI_SCHED = 1,
445 struct mlx5e_channel {
448 struct mlx5e_sq sq[MLX5E_MAX_NUM_TC];
449 struct napi_struct napi;
451 struct net_device *netdev;
457 struct mlx5e_priv *priv;
462 enum mlx5e_traffic_types {
467 MLX5E_TT_IPV4_IPSEC_AH,
468 MLX5E_TT_IPV6_IPSEC_AH,
469 MLX5E_TT_IPV4_IPSEC_ESP,
470 MLX5E_TT_IPV6_IPSEC_ESP,
478 MLX5E_INDIRECTION_RQT,
483 struct mlx5e_eth_addr_info {
484 u8 addr[ETH_ALEN + 2];
486 struct mlx5_flow_rule *ft_rule[MLX5E_NUM_TT];
489 #define MLX5E_ETH_ADDR_HASH_SIZE (1 << BITS_PER_BYTE)
491 struct mlx5e_eth_addr_db {
492 struct hlist_head netdev_uc[MLX5E_ETH_ADDR_HASH_SIZE];
493 struct hlist_head netdev_mc[MLX5E_ETH_ADDR_HASH_SIZE];
494 struct mlx5e_eth_addr_info broadcast;
495 struct mlx5e_eth_addr_info allmulti;
496 struct mlx5e_eth_addr_info promisc;
497 bool broadcast_enabled;
498 bool allmulti_enabled;
499 bool promisc_enabled;
503 MLX5E_STATE_ASYNC_EVENTS_ENABLE,
505 MLX5E_STATE_DESTROYING,
508 struct mlx5e_vlan_db {
509 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
510 struct mlx5_flow_rule *active_vlans_rule[VLAN_N_VID];
511 struct mlx5_flow_rule *untagged_rule;
512 struct mlx5_flow_rule *any_vlan_rule;
513 bool filter_disabled;
516 struct mlx5e_vxlan_db {
517 spinlock_t lock; /* protect vxlan table */
518 struct radix_tree_root tree;
521 struct mlx5e_flow_table {
523 struct mlx5_flow_table *t;
524 struct mlx5_flow_group **g;
527 struct mlx5e_flow_tables {
528 struct mlx5_flow_namespace *ns;
529 struct mlx5e_flow_table vlan;
530 struct mlx5e_flow_table main;
534 /* priv data path fields - start */
535 struct mlx5e_sq **txq_to_sq_map;
536 int channeltc_to_txq_map[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
537 /* priv data path fields - end */
540 struct mutex state_lock; /* Protects Interface state */
541 struct mlx5_uar cq_uar;
544 struct mlx5_core_mr mr;
545 struct mlx5e_rq drop_rq;
547 struct mlx5e_channel **channel;
548 u32 tisn[MLX5E_MAX_NUM_TC];
549 u32 rqtn[MLX5E_NUM_RQT];
550 u32 tirn[MLX5E_NUM_TT];
552 struct mlx5e_flow_tables fts;
553 struct mlx5e_eth_addr_db eth_addr;
554 struct mlx5e_vlan_db vlan;
555 struct mlx5e_vxlan_db vxlan;
557 struct mlx5e_params params;
558 struct work_struct update_carrier_work;
559 struct work_struct set_rx_mode_work;
560 struct delayed_work update_stats_work;
562 struct mlx5_core_dev *mdev;
563 struct net_device *netdev;
564 struct mlx5e_stats stats;
565 struct mlx5e_tstamp tstamp;
568 #define MLX5E_NET_IP_ALIGN 2
570 struct mlx5e_tx_wqe {
571 struct mlx5_wqe_ctrl_seg ctrl;
572 struct mlx5_wqe_eth_seg eth;
575 struct mlx5e_rx_wqe {
576 struct mlx5_wqe_srq_next_seg next;
577 struct mlx5_wqe_data_seg data;
580 enum mlx5e_link_mode {
581 MLX5E_1000BASE_CX_SGMII = 0,
582 MLX5E_1000BASE_KX = 1,
583 MLX5E_10GBASE_CX4 = 2,
584 MLX5E_10GBASE_KX4 = 3,
585 MLX5E_10GBASE_KR = 4,
586 MLX5E_20GBASE_KR2 = 5,
587 MLX5E_40GBASE_CR4 = 6,
588 MLX5E_40GBASE_KR4 = 7,
589 MLX5E_56GBASE_R4 = 8,
590 MLX5E_10GBASE_CR = 12,
591 MLX5E_10GBASE_SR = 13,
592 MLX5E_10GBASE_ER = 14,
593 MLX5E_40GBASE_SR4 = 15,
594 MLX5E_40GBASE_LR4 = 16,
595 MLX5E_100GBASE_CR4 = 20,
596 MLX5E_100GBASE_SR4 = 21,
597 MLX5E_100GBASE_KR4 = 22,
598 MLX5E_100GBASE_LR4 = 23,
599 MLX5E_100BASE_TX = 24,
600 MLX5E_100BASE_T = 25,
601 MLX5E_10GBASE_T = 26,
602 MLX5E_25GBASE_CR = 27,
603 MLX5E_25GBASE_KR = 28,
604 MLX5E_25GBASE_SR = 29,
605 MLX5E_50GBASE_CR2 = 30,
606 MLX5E_50GBASE_KR2 = 31,
607 MLX5E_LINK_MODES_NUMBER,
610 #define MLX5E_PROT_MASK(link_mode) (1 << link_mode)
612 void mlx5e_send_nop(struct mlx5e_sq *sq, bool notify_hw);
613 u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
614 void *accel_priv, select_queue_fallback_t fallback);
615 netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
617 void mlx5e_completion_event(struct mlx5_core_cq *mcq);
618 void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
619 int mlx5e_napi_poll(struct napi_struct *napi, int budget);
620 bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq);
621 int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
622 bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
623 struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);
625 void mlx5e_update_stats(struct mlx5e_priv *priv);
627 int mlx5e_create_flow_tables(struct mlx5e_priv *priv);
628 void mlx5e_destroy_flow_tables(struct mlx5e_priv *priv);
629 void mlx5e_init_eth_addr(struct mlx5e_priv *priv);
630 void mlx5e_set_rx_mode_work(struct work_struct *work);
632 void mlx5e_fill_hwstamp(struct mlx5e_tstamp *clock, u64 timestamp,
633 struct skb_shared_hwtstamps *hwts);
634 void mlx5e_timestamp_init(struct mlx5e_priv *priv);
635 void mlx5e_timestamp_cleanup(struct mlx5e_priv *priv);
636 int mlx5e_hwstamp_set(struct net_device *dev, struct ifreq *ifr);
637 int mlx5e_hwstamp_get(struct net_device *dev, struct ifreq *ifr);
639 int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
641 int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
643 void mlx5e_enable_vlan_filter(struct mlx5e_priv *priv);
644 void mlx5e_disable_vlan_filter(struct mlx5e_priv *priv);
646 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, enum mlx5e_rqt_ix rqt_ix);
648 int mlx5e_open_locked(struct net_device *netdev);
649 int mlx5e_close_locked(struct net_device *netdev);
651 static inline void mlx5e_tx_notify_hw(struct mlx5e_sq *sq,
652 struct mlx5e_tx_wqe *wqe, int bf_sz)
654 u16 ofst = MLX5_BF_OFFSET + sq->bf_offset;
656 /* ensure wqe is visible to device before updating doorbell record */
659 *sq->wq.db = cpu_to_be32(sq->pc);
661 /* ensure doorbell record is visible to device before ringing the
667 __iowrite64_copy(sq->uar_bf_map + ofst, &wqe->ctrl, bf_sz);
669 /* flush the write-combining mapped buffer */
673 mlx5_write64((__be32 *)&wqe->ctrl, sq->uar_map + ofst, NULL);
676 sq->bf_offset ^= sq->bf_buf_size;
679 static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
681 struct mlx5_core_cq *mcq;
684 mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, NULL, cq->wq.cc);
687 static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
689 return min_t(int, mdev->priv.eq_table.num_comp_vectors,
690 MLX5E_MAX_NUM_CHANNELS);
693 extern const struct ethtool_ops mlx5e_ethtool_ops;
694 #ifdef CONFIG_MLX5_CORE_EN_DCB
695 extern const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops;
696 int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets);
699 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
701 #endif /* __MLX5_EN_H__ */