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 static const char vport_strings[][ETH_GSTRING_LEN] = {
68 /* vport statistics */
81 "rx_multicast_packets",
83 "tx_multicast_packets",
85 "rx_broadcast_packets",
87 "tx_broadcast_packets",
105 struct mlx5e_vport_stats {
111 u64 rx_error_packets;
113 u64 tx_error_packets;
115 u64 rx_unicast_packets;
116 u64 rx_unicast_bytes;
117 u64 tx_unicast_packets;
118 u64 tx_unicast_bytes;
119 u64 rx_multicast_packets;
120 u64 rx_multicast_bytes;
121 u64 tx_multicast_packets;
122 u64 tx_multicast_bytes;
123 u64 rx_broadcast_packets;
124 u64 rx_broadcast_bytes;
125 u64 tx_broadcast_packets;
126 u64 tx_broadcast_bytes;
137 u64 tx_queue_stopped;
139 u64 tx_queue_dropped;
142 #define NUM_VPORT_COUNTERS 32
145 static const char pport_strings[][ETH_GSTRING_LEN] = {
146 /* IEEE802.3 counters */
157 "in_range_len_errors",
167 /* RFC2863 counters */
179 "out_multicast_pkts",
180 "out_broadcast_pkts",
182 /* RFC2819 counters */
203 "p8192to10239octets",
206 #define NUM_IEEE_802_3_COUNTERS 19
207 #define NUM_RFC_2863_COUNTERS 13
208 #define NUM_RFC_2819_COUNTERS 21
209 #define NUM_PPORT_COUNTERS (NUM_IEEE_802_3_COUNTERS + \
210 NUM_RFC_2863_COUNTERS + \
211 NUM_RFC_2819_COUNTERS)
213 struct mlx5e_pport_stats {
214 __be64 IEEE_802_3_counters[NUM_IEEE_802_3_COUNTERS];
215 __be64 RFC_2863_counters[NUM_RFC_2863_COUNTERS];
216 __be64 RFC_2819_counters[NUM_RFC_2819_COUNTERS];
219 static const char rq_stats_strings[][ETH_GSTRING_LEN] = {
228 struct mlx5e_rq_stats {
235 #define NUM_RQ_STATS 6
238 static const char sq_stats_strings[][ETH_GSTRING_LEN] = {
249 struct mlx5e_sq_stats {
253 u64 csum_offload_none;
258 #define NUM_SQ_STATS 8
262 struct mlx5e_vport_stats vport;
263 struct mlx5e_pport_stats pport;
266 struct mlx5e_params {
270 u8 default_vlan_prio;
272 u16 rx_cq_moderation_usec;
273 u16 rx_cq_moderation_pkts;
274 u16 tx_cq_moderation_usec;
275 u16 tx_cq_moderation_pkts;
281 u8 toeplitz_hash_key[40];
282 u32 indirection_rqt[MLX5E_INDIR_RQT_SIZE];
286 MLX5E_RQ_STATE_POST_WQES_ENABLE,
290 MLX5E_CQ_HAS_CQES = 1,
294 /* data path - accessed per cqe */
298 /* data path - accessed per napi poll */
299 struct napi_struct *napi;
300 struct mlx5_core_cq mcq;
301 struct mlx5e_channel *channel;
302 struct mlx5e_priv *priv;
305 struct mlx5_wq_ctrl wq_ctrl;
306 } ____cacheline_aligned_in_smp;
310 struct mlx5_wq_ll wq;
312 struct sk_buff **skb;
315 struct net_device *netdev;
316 struct mlx5e_rq_stats stats;
323 struct mlx5_wq_ctrl wq_ctrl;
325 struct mlx5e_channel *channel;
326 struct mlx5e_priv *priv;
327 } ____cacheline_aligned_in_smp;
329 struct mlx5e_tx_skb_cb {
335 #define MLX5E_TX_SKB_CB(__skb) ((struct mlx5e_tx_skb_cb *)__skb->cb)
337 enum mlx5e_dma_map_type {
338 MLX5E_DMA_MAP_SINGLE,
342 struct mlx5e_sq_dma {
345 enum mlx5e_dma_map_type type;
349 MLX5E_SQ_STATE_WAKE_TXQ_ENABLE,
355 /* dirtied @completion */
360 u16 pc ____cacheline_aligned_in_smp;
365 struct mlx5e_sq_stats stats;
369 /* pointers to per packet info: write@xmit, read@completion */
370 struct sk_buff **skb;
371 struct mlx5e_sq_dma *dma_fifo;
374 struct mlx5_wq_cyc wq;
376 void __iomem *uar_map;
377 void __iomem *uar_bf_map;
378 struct netdev_queue *txq;
388 struct mlx5_wq_ctrl wq_ctrl;
390 struct mlx5e_channel *channel;
392 } ____cacheline_aligned_in_smp;
394 static inline bool mlx5e_sq_has_room_for(struct mlx5e_sq *sq, u16 n)
396 return (((sq->wq.sz_m1 & (sq->cc - sq->pc)) >= n) ||
401 MLX5E_CHANNEL_NAPI_SCHED = 1,
404 struct mlx5e_channel {
407 struct mlx5e_sq sq[MLX5E_MAX_NUM_TC];
408 struct napi_struct napi;
410 struct net_device *netdev;
416 struct mlx5e_priv *priv;
421 enum mlx5e_traffic_types {
426 MLX5E_TT_IPV4_IPSEC_AH,
427 MLX5E_TT_IPV6_IPSEC_AH,
428 MLX5E_TT_IPV4_IPSEC_ESP,
429 MLX5E_TT_IPV6_IPSEC_ESP,
437 MLX5E_INDIRECTION_RQT,
442 struct mlx5e_eth_addr_info {
443 u8 addr[ETH_ALEN + 2];
445 u32 ft_ix[MLX5E_NUM_TT]; /* flow table index per traffic type */
448 #define MLX5E_ETH_ADDR_HASH_SIZE (1 << BITS_PER_BYTE)
450 struct mlx5e_eth_addr_db {
451 struct hlist_head netdev_uc[MLX5E_ETH_ADDR_HASH_SIZE];
452 struct hlist_head netdev_mc[MLX5E_ETH_ADDR_HASH_SIZE];
453 struct mlx5e_eth_addr_info broadcast;
454 struct mlx5e_eth_addr_info allmulti;
455 struct mlx5e_eth_addr_info promisc;
456 bool broadcast_enabled;
457 bool allmulti_enabled;
458 bool promisc_enabled;
462 MLX5E_STATE_ASYNC_EVENTS_ENABLE,
464 MLX5E_STATE_DESTROYING,
467 struct mlx5e_vlan_db {
468 u32 active_vlans_ft_ix[VLAN_N_VID];
469 u32 untagged_rule_ft_ix;
470 u32 any_vlan_rule_ft_ix;
471 bool filter_disabled;
474 struct mlx5e_flow_table {
480 /* priv data path fields - start */
481 int default_vlan_prio;
482 struct mlx5e_sq **txq_to_sq_map;
483 int channeltc_to_txq_map[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
484 /* priv data path fields - end */
487 struct mutex state_lock; /* Protects Interface state */
488 struct mlx5_uar cq_uar;
491 struct mlx5_core_mr mr;
492 struct mlx5e_rq drop_rq;
494 struct mlx5e_channel **channel;
495 u32 tisn[MLX5E_MAX_NUM_TC];
496 u32 rqtn[MLX5E_NUM_RQT];
497 u32 tirn[MLX5E_NUM_TT];
499 struct mlx5e_flow_table ft;
500 struct mlx5e_eth_addr_db eth_addr;
501 struct mlx5e_vlan_db vlan;
503 struct mlx5e_params params;
504 spinlock_t async_events_spinlock; /* sync hw events */
505 struct work_struct update_carrier_work;
506 struct work_struct set_rx_mode_work;
507 struct delayed_work update_stats_work;
509 struct mlx5_core_dev *mdev;
510 struct net_device *netdev;
511 struct mlx5e_stats stats;
514 #define MLX5E_NET_IP_ALIGN 2
516 struct mlx5e_tx_wqe {
517 struct mlx5_wqe_ctrl_seg ctrl;
518 struct mlx5_wqe_eth_seg eth;
521 struct mlx5e_rx_wqe {
522 struct mlx5_wqe_srq_next_seg next;
523 struct mlx5_wqe_data_seg data;
526 enum mlx5e_link_mode {
527 MLX5E_1000BASE_CX_SGMII = 0,
528 MLX5E_1000BASE_KX = 1,
529 MLX5E_10GBASE_CX4 = 2,
530 MLX5E_10GBASE_KX4 = 3,
531 MLX5E_10GBASE_KR = 4,
532 MLX5E_20GBASE_KR2 = 5,
533 MLX5E_40GBASE_CR4 = 6,
534 MLX5E_40GBASE_KR4 = 7,
535 MLX5E_56GBASE_R4 = 8,
536 MLX5E_10GBASE_CR = 12,
537 MLX5E_10GBASE_SR = 13,
538 MLX5E_10GBASE_ER = 14,
539 MLX5E_40GBASE_SR4 = 15,
540 MLX5E_40GBASE_LR4 = 16,
541 MLX5E_100GBASE_CR4 = 20,
542 MLX5E_100GBASE_SR4 = 21,
543 MLX5E_100GBASE_KR4 = 22,
544 MLX5E_100GBASE_LR4 = 23,
545 MLX5E_100BASE_TX = 24,
546 MLX5E_1000BASE_T = 25,
547 MLX5E_10GBASE_T = 26,
548 MLX5E_25GBASE_CR = 27,
549 MLX5E_25GBASE_KR = 28,
550 MLX5E_25GBASE_SR = 29,
551 MLX5E_50GBASE_CR2 = 30,
552 MLX5E_50GBASE_KR2 = 31,
553 MLX5E_LINK_MODES_NUMBER,
556 #define MLX5E_PROT_MASK(link_mode) (1 << link_mode)
558 void mlx5e_send_nop(struct mlx5e_sq *sq, bool notify_hw);
559 u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
560 void *accel_priv, select_queue_fallback_t fallback);
561 netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
563 void mlx5e_completion_event(struct mlx5_core_cq *mcq);
564 void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
565 int mlx5e_napi_poll(struct napi_struct *napi, int budget);
566 bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq);
567 bool mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
568 bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
569 struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);
571 void mlx5e_update_stats(struct mlx5e_priv *priv);
573 int mlx5e_create_flow_tables(struct mlx5e_priv *priv);
574 void mlx5e_destroy_flow_tables(struct mlx5e_priv *priv);
575 void mlx5e_init_eth_addr(struct mlx5e_priv *priv);
576 void mlx5e_set_rx_mode_work(struct work_struct *work);
578 int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
580 int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
582 void mlx5e_enable_vlan_filter(struct mlx5e_priv *priv);
583 void mlx5e_disable_vlan_filter(struct mlx5e_priv *priv);
585 int mlx5e_redirect_rqt(struct mlx5e_priv *priv, enum mlx5e_rqt_ix rqt_ix);
587 int mlx5e_open_locked(struct net_device *netdev);
588 int mlx5e_close_locked(struct net_device *netdev);
589 void mlx5e_build_default_indir_rqt(u32 *indirection_rqt, int len,
592 static inline void mlx5e_tx_notify_hw(struct mlx5e_sq *sq,
593 struct mlx5e_tx_wqe *wqe, int bf_sz)
595 u16 ofst = MLX5_BF_OFFSET + sq->bf_offset;
597 /* ensure wqe is visible to device before updating doorbell record */
600 *sq->wq.db = cpu_to_be32(sq->pc);
602 /* ensure doorbell record is visible to device before ringing the
608 __iowrite64_copy(sq->uar_bf_map + ofst, &wqe->ctrl, bf_sz);
610 /* flush the write-combining mapped buffer */
614 mlx5_write64((__be32 *)&wqe->ctrl, sq->uar_map + ofst, NULL);
617 sq->bf_offset ^= sq->bf_buf_size;
620 static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
622 struct mlx5_core_cq *mcq;
625 mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, NULL, cq->wq.cc);
628 static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
630 return min_t(int, mdev->priv.eq_table.num_comp_vectors,
631 MLX5E_MAX_NUM_CHANNELS);
634 extern const struct ethtool_ops mlx5e_ethtool_ops;
635 u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);