2 * Copyright (c) 2015, 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
33 #include <linux/if_vlan.h>
34 #include <linux/etherdevice.h>
35 #include <linux/mlx5/driver.h>
36 #include <linux/mlx5/qp.h>
37 #include <linux/mlx5/cq.h>
38 #include <linux/mlx5/vport.h>
41 #include "mlx5_core.h"
43 #define MLX5E_MAX_NUM_TC 8
45 #define MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE 0x6
46 #define MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE 0xa
47 #define MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE 0xd
49 #define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE 0x1
50 #define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE 0xa
51 #define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE 0xd
53 #define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ (64 * 1024)
54 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC 0x10
55 #define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS 0x20
56 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC 0x10
57 #define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS 0x20
58 #define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES 0x80
60 #define MLX5E_LOG_INDIR_RQT_SIZE 0x7
61 #define MLX5E_INDIR_RQT_SIZE BIT(MLX5E_LOG_INDIR_RQT_SIZE)
62 #define MLX5E_MAX_NUM_CHANNELS (MLX5E_INDIR_RQT_SIZE >> 1)
63 #define MLX5E_TX_CQ_POLL_BUDGET 128
64 #define MLX5E_UPDATE_STATS_INTERVAL 200 /* msecs */
65 #define MLX5E_SQ_BF_BUDGET 16
67 #define MLX5E_NUM_MAIN_GROUPS 9
69 static const char vport_strings[][ETH_GSTRING_LEN] = {
70 /* vport statistics */
83 "rx_multicast_packets",
85 "tx_multicast_packets",
87 "rx_broadcast_packets",
89 "tx_broadcast_packets",
107 struct mlx5e_vport_stats {
113 u64 rx_error_packets;
115 u64 tx_error_packets;
117 u64 rx_unicast_packets;
118 u64 rx_unicast_bytes;
119 u64 tx_unicast_packets;
120 u64 tx_unicast_bytes;
121 u64 rx_multicast_packets;
122 u64 rx_multicast_bytes;
123 u64 tx_multicast_packets;
124 u64 tx_multicast_bytes;
125 u64 rx_broadcast_packets;
126 u64 rx_broadcast_bytes;
127 u64 tx_broadcast_packets;
128 u64 tx_broadcast_bytes;
139 u64 tx_queue_stopped;
141 u64 tx_queue_dropped;
144 #define NUM_VPORT_COUNTERS 32
147 static const char pport_strings[][ETH_GSTRING_LEN] = {
148 /* IEEE802.3 counters */
159 "in_range_len_errors",
169 /* RFC2863 counters */
181 "out_multicast_pkts",
182 "out_broadcast_pkts",
184 /* RFC2819 counters */
205 "p8192to10239octets",
208 #define NUM_IEEE_802_3_COUNTERS 19
209 #define NUM_RFC_2863_COUNTERS 13
210 #define NUM_RFC_2819_COUNTERS 21
211 #define NUM_PPORT_COUNTERS (NUM_IEEE_802_3_COUNTERS + \
212 NUM_RFC_2863_COUNTERS + \
213 NUM_RFC_2819_COUNTERS)
215 struct mlx5e_pport_stats {
216 __be64 IEEE_802_3_counters[NUM_IEEE_802_3_COUNTERS];
217 __be64 RFC_2863_counters[NUM_RFC_2863_COUNTERS];
218 __be64 RFC_2819_counters[NUM_RFC_2819_COUNTERS];
221 static const char rq_stats_strings[][ETH_GSTRING_LEN] = {
230 struct mlx5e_rq_stats {
237 #define NUM_RQ_STATS 6
240 static const char sq_stats_strings[][ETH_GSTRING_LEN] = {
251 struct mlx5e_sq_stats {
255 u64 csum_offload_none;
260 #define NUM_SQ_STATS 8
264 struct mlx5e_vport_stats vport;
265 struct mlx5e_pport_stats pport;
268 struct mlx5e_params {
272 u8 default_vlan_prio;
274 u16 rx_cq_moderation_usec;
275 u16 rx_cq_moderation_pkts;
276 u16 tx_cq_moderation_usec;
277 u16 tx_cq_moderation_pkts;
283 u8 toeplitz_hash_key[40];
284 u32 indirection_rqt[MLX5E_INDIR_RQT_SIZE];
288 MLX5E_RQ_STATE_POST_WQES_ENABLE,
292 MLX5E_CQ_HAS_CQES = 1,
296 /* data path - accessed per cqe */
300 /* data path - accessed per napi poll */
301 struct napi_struct *napi;
302 struct mlx5_core_cq mcq;
303 struct mlx5e_channel *channel;
304 struct mlx5e_priv *priv;
307 struct mlx5_wq_ctrl wq_ctrl;
308 } ____cacheline_aligned_in_smp;
312 struct mlx5_wq_ll wq;
314 struct sk_buff **skb;
317 struct net_device *netdev;
318 struct mlx5e_rq_stats stats;
325 struct mlx5_wq_ctrl wq_ctrl;
327 struct mlx5e_channel *channel;
328 struct mlx5e_priv *priv;
329 } ____cacheline_aligned_in_smp;
331 struct mlx5e_tx_skb_cb {
337 #define MLX5E_TX_SKB_CB(__skb) ((struct mlx5e_tx_skb_cb *)__skb->cb)
339 enum mlx5e_dma_map_type {
340 MLX5E_DMA_MAP_SINGLE,
344 struct mlx5e_sq_dma {
347 enum mlx5e_dma_map_type type;
351 MLX5E_SQ_STATE_WAKE_TXQ_ENABLE,
357 /* dirtied @completion */
362 u16 pc ____cacheline_aligned_in_smp;
367 struct mlx5e_sq_stats stats;
371 /* pointers to per packet info: write@xmit, read@completion */
372 struct sk_buff **skb;
373 struct mlx5e_sq_dma *dma_fifo;
376 struct mlx5_wq_cyc wq;
378 void __iomem *uar_map;
379 void __iomem *uar_bf_map;
380 struct netdev_queue *txq;
390 struct mlx5_wq_ctrl wq_ctrl;
392 struct mlx5e_channel *channel;
394 } ____cacheline_aligned_in_smp;
396 static inline bool mlx5e_sq_has_room_for(struct mlx5e_sq *sq, u16 n)
398 return (((sq->wq.sz_m1 & (sq->cc - sq->pc)) >= n) ||
403 MLX5E_CHANNEL_NAPI_SCHED = 1,
406 struct mlx5e_channel {
409 struct mlx5e_sq sq[MLX5E_MAX_NUM_TC];
410 struct napi_struct napi;
412 struct net_device *netdev;
418 struct mlx5e_priv *priv;
423 enum mlx5e_traffic_types {
428 MLX5E_TT_IPV4_IPSEC_AH,
429 MLX5E_TT_IPV6_IPSEC_AH,
430 MLX5E_TT_IPV4_IPSEC_ESP,
431 MLX5E_TT_IPV6_IPSEC_ESP,
439 MLX5E_INDIRECTION_RQT,
444 struct mlx5e_eth_addr_info {
445 u8 addr[ETH_ALEN + 2];
447 struct mlx5_flow_rule *ft_rule[MLX5E_NUM_TT];
450 #define MLX5E_ETH_ADDR_HASH_SIZE (1 << BITS_PER_BYTE)
452 struct mlx5e_eth_addr_db {
453 struct hlist_head netdev_uc[MLX5E_ETH_ADDR_HASH_SIZE];
454 struct hlist_head netdev_mc[MLX5E_ETH_ADDR_HASH_SIZE];
455 struct mlx5e_eth_addr_info broadcast;
456 struct mlx5e_eth_addr_info allmulti;
457 struct mlx5e_eth_addr_info promisc;
458 bool broadcast_enabled;
459 bool allmulti_enabled;
460 bool promisc_enabled;
464 MLX5E_STATE_ASYNC_EVENTS_ENABLE,
466 MLX5E_STATE_DESTROYING,
469 struct mlx5e_vlan_db {
470 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
471 struct mlx5_flow_rule *active_vlans_rule[VLAN_N_VID];
472 struct mlx5_flow_rule *untagged_rule;
473 struct mlx5_flow_rule *any_vlan_rule;
474 bool filter_disabled;
477 struct mlx5e_flow_table {
479 struct mlx5_flow_table *t;
480 struct mlx5_flow_group **g;
483 struct mlx5e_flow_tables {
484 struct mlx5_flow_namespace *ns;
485 struct mlx5e_flow_table vlan;
486 struct mlx5e_flow_table main;
490 /* priv data path fields - start */
491 int default_vlan_prio;
492 struct mlx5e_sq **txq_to_sq_map;
493 int channeltc_to_txq_map[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
494 /* priv data path fields - end */
497 struct mutex state_lock; /* Protects Interface state */
498 struct mlx5_uar cq_uar;
501 struct mlx5_core_mr mr;
502 struct mlx5e_rq drop_rq;
504 struct mlx5e_channel **channel;
505 u32 tisn[MLX5E_MAX_NUM_TC];
506 u32 rqtn[MLX5E_NUM_RQT];
507 u32 tirn[MLX5E_NUM_TT];
509 struct mlx5e_flow_tables fts;
510 struct mlx5e_eth_addr_db eth_addr;
511 struct mlx5e_vlan_db vlan;
513 struct mlx5e_params params;
514 spinlock_t async_events_spinlock; /* sync hw events */
515 struct work_struct update_carrier_work;
516 struct work_struct set_rx_mode_work;
517 struct delayed_work update_stats_work;
519 struct mlx5_core_dev *mdev;
520 struct net_device *netdev;
521 struct mlx5e_stats stats;
524 #define MLX5E_NET_IP_ALIGN 2
526 struct mlx5e_tx_wqe {
527 struct mlx5_wqe_ctrl_seg ctrl;
528 struct mlx5_wqe_eth_seg eth;
531 struct mlx5e_rx_wqe {
532 struct mlx5_wqe_srq_next_seg next;
533 struct mlx5_wqe_data_seg data;
536 enum mlx5e_link_mode {
537 MLX5E_1000BASE_CX_SGMII = 0,
538 MLX5E_1000BASE_KX = 1,
539 MLX5E_10GBASE_CX4 = 2,
540 MLX5E_10GBASE_KX4 = 3,
541 MLX5E_10GBASE_KR = 4,
542 MLX5E_20GBASE_KR2 = 5,
543 MLX5E_40GBASE_CR4 = 6,
544 MLX5E_40GBASE_KR4 = 7,
545 MLX5E_56GBASE_R4 = 8,
546 MLX5E_10GBASE_CR = 12,
547 MLX5E_10GBASE_SR = 13,
548 MLX5E_10GBASE_ER = 14,
549 MLX5E_40GBASE_SR4 = 15,
550 MLX5E_40GBASE_LR4 = 16,
551 MLX5E_100GBASE_CR4 = 20,
552 MLX5E_100GBASE_SR4 = 21,
553 MLX5E_100GBASE_KR4 = 22,
554 MLX5E_100GBASE_LR4 = 23,
555 MLX5E_100BASE_TX = 24,
556 MLX5E_100BASE_T = 25,
557 MLX5E_10GBASE_T = 26,
558 MLX5E_25GBASE_CR = 27,
559 MLX5E_25GBASE_KR = 28,
560 MLX5E_25GBASE_SR = 29,
561 MLX5E_50GBASE_CR2 = 30,
562 MLX5E_50GBASE_KR2 = 31,
563 MLX5E_LINK_MODES_NUMBER,
566 #define MLX5E_PROT_MASK(link_mode) (1 << link_mode)
568 void mlx5e_send_nop(struct mlx5e_sq *sq, bool notify_hw);
569 u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
570 void *accel_priv, select_queue_fallback_t fallback);
571 netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
573 void mlx5e_completion_event(struct mlx5_core_cq *mcq);
574 void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
575 int mlx5e_napi_poll(struct napi_struct *napi, int budget);
576 bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq);
577 int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
578 bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
579 struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);
581 void mlx5e_update_stats(struct mlx5e_priv *priv);
583 int mlx5e_create_flow_tables(struct mlx5e_priv *priv);
584 void mlx5e_destroy_flow_tables(struct mlx5e_priv *priv);
585 void mlx5e_init_eth_addr(struct mlx5e_priv *priv);
586 void mlx5e_set_rx_mode_work(struct work_struct *work);
588 int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
590 int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
592 void mlx5e_enable_vlan_filter(struct mlx5e_priv *priv);
593 void mlx5e_disable_vlan_filter(struct mlx5e_priv *priv);
595 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, enum mlx5e_rqt_ix rqt_ix);
597 int mlx5e_open_locked(struct net_device *netdev);
598 int mlx5e_close_locked(struct net_device *netdev);
600 static inline void mlx5e_tx_notify_hw(struct mlx5e_sq *sq,
601 struct mlx5e_tx_wqe *wqe, int bf_sz)
603 u16 ofst = MLX5_BF_OFFSET + sq->bf_offset;
605 /* ensure wqe is visible to device before updating doorbell record */
608 *sq->wq.db = cpu_to_be32(sq->pc);
610 /* ensure doorbell record is visible to device before ringing the
616 __iowrite64_copy(sq->uar_bf_map + ofst, &wqe->ctrl, bf_sz);
618 /* flush the write-combining mapped buffer */
622 mlx5_write64((__be32 *)&wqe->ctrl, sq->uar_map + ofst, NULL);
625 sq->bf_offset ^= sq->bf_buf_size;
628 static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
630 struct mlx5_core_cq *mcq;
633 mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, NULL, cq->wq.cc);
636 static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
638 return min_t(int, mdev->priv.eq_table.num_comp_vectors,
639 MLX5E_MAX_NUM_CHANNELS);
642 extern const struct ethtool_ops mlx5e_ethtool_ops;
643 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);