18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
58c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
68c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
78c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
88c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
118c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
128c2ecf20Sopenharmony_ci *     conditions are met:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
158c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
168c2ecf20Sopenharmony_ci *        disclaimer.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
198c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
208c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
218c2ecf20Sopenharmony_ci *        provided with the distribution.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
248c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
258c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
268c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
278c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
288c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
298c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
308c2ecf20Sopenharmony_ci * SOFTWARE.
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#ifndef _MLX4_EN_H_
358c2ecf20Sopenharmony_ci#define _MLX4_EN_H_
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#include <linux/bitops.h>
388c2ecf20Sopenharmony_ci#include <linux/compiler.h>
398c2ecf20Sopenharmony_ci#include <linux/list.h>
408c2ecf20Sopenharmony_ci#include <linux/mutex.h>
418c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
428c2ecf20Sopenharmony_ci#include <linux/if_vlan.h>
438c2ecf20Sopenharmony_ci#include <linux/net_tstamp.h>
448c2ecf20Sopenharmony_ci#ifdef CONFIG_MLX4_EN_DCB
458c2ecf20Sopenharmony_ci#include <linux/dcbnl.h>
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ci#include <linux/cpu_rmap.h>
488c2ecf20Sopenharmony_ci#include <linux/ptp_clock_kernel.h>
498c2ecf20Sopenharmony_ci#include <net/xdp.h>
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#include <linux/mlx4/device.h>
528c2ecf20Sopenharmony_ci#include <linux/mlx4/qp.h>
538c2ecf20Sopenharmony_ci#include <linux/mlx4/cq.h>
548c2ecf20Sopenharmony_ci#include <linux/mlx4/srq.h>
558c2ecf20Sopenharmony_ci#include <linux/mlx4/doorbell.h>
568c2ecf20Sopenharmony_ci#include <linux/mlx4/cmd.h>
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#include "en_port.h"
598c2ecf20Sopenharmony_ci#include "mlx4_stats.h"
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define DRV_NAME	"mlx4_en"
628c2ecf20Sopenharmony_ci#define DRV_VERSION	"4.0-0"
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define MLX4_EN_MSG_LEVEL	(NETIF_MSG_LINK | NETIF_MSG_IFDOWN)
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/*
678c2ecf20Sopenharmony_ci * Device constants
688c2ecf20Sopenharmony_ci */
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define MLX4_EN_PAGE_SHIFT	12
728c2ecf20Sopenharmony_ci#define MLX4_EN_PAGE_SIZE	(1 << MLX4_EN_PAGE_SHIFT)
738c2ecf20Sopenharmony_ci#define DEF_RX_RINGS		16
748c2ecf20Sopenharmony_ci#define MAX_RX_RINGS		128
758c2ecf20Sopenharmony_ci#define MIN_RX_RINGS		1
768c2ecf20Sopenharmony_ci#define LOG_TXBB_SIZE		6
778c2ecf20Sopenharmony_ci#define TXBB_SIZE		BIT(LOG_TXBB_SIZE)
788c2ecf20Sopenharmony_ci#define HEADROOM		(2048 / TXBB_SIZE + 1)
798c2ecf20Sopenharmony_ci#define STAMP_STRIDE		64
808c2ecf20Sopenharmony_ci#define STAMP_DWORDS		(STAMP_STRIDE / 4)
818c2ecf20Sopenharmony_ci#define STAMP_SHIFT		31
828c2ecf20Sopenharmony_ci#define STAMP_VAL		0x7fffffff
838c2ecf20Sopenharmony_ci#define STATS_DELAY		(HZ / 4)
848c2ecf20Sopenharmony_ci#define SERVICE_TASK_DELAY	(HZ / 4)
858c2ecf20Sopenharmony_ci#define MAX_NUM_OF_FS_RULES	256
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define MLX4_EN_FILTER_HASH_SHIFT 4
888c2ecf20Sopenharmony_ci#define MLX4_EN_FILTER_EXPIRY_QUOTA 60
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* Typical TSO descriptor with 16 gather entries is 352 bytes... */
918c2ecf20Sopenharmony_ci#define MAX_DESC_SIZE		512
928c2ecf20Sopenharmony_ci#define MAX_DESC_TXBBS		(MAX_DESC_SIZE / TXBB_SIZE)
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/*
958c2ecf20Sopenharmony_ci * OS related constants and tunables
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#define MLX4_EN_PRIV_FLAGS_BLUEFLAME 1
998c2ecf20Sopenharmony_ci#define MLX4_EN_PRIV_FLAGS_PHV	     2
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define MLX4_EN_WATCHDOG_TIMEOUT	(15 * HZ)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* Use the maximum between 16384 and a single page */
1048c2ecf20Sopenharmony_ci#define MLX4_EN_ALLOC_SIZE	PAGE_ALIGN(16384)
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define MLX4_EN_MAX_RX_FRAGS	4
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* Maximum ring sizes */
1098c2ecf20Sopenharmony_ci#define MLX4_EN_MAX_TX_SIZE	8192
1108c2ecf20Sopenharmony_ci#define MLX4_EN_MAX_RX_SIZE	8192
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/* Minimum ring size for our page-allocation scheme to work */
1138c2ecf20Sopenharmony_ci#define MLX4_EN_MIN_RX_SIZE	(MLX4_EN_ALLOC_SIZE / SMP_CACHE_BYTES)
1148c2ecf20Sopenharmony_ci#define MLX4_EN_MIN_TX_SIZE	(4096 / TXBB_SIZE)
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define MLX4_EN_SMALL_PKT_SIZE		64
1178c2ecf20Sopenharmony_ci#define MLX4_EN_MIN_TX_RING_P_UP	1
1188c2ecf20Sopenharmony_ci#define MLX4_EN_MAX_TX_RING_P_UP	32
1198c2ecf20Sopenharmony_ci#define MLX4_EN_NUM_UP_LOW		1
1208c2ecf20Sopenharmony_ci#define MLX4_EN_NUM_UP_HIGH		8
1218c2ecf20Sopenharmony_ci#define MLX4_EN_DEF_RX_RING_SIZE  	1024
1228c2ecf20Sopenharmony_ci#define MLX4_EN_DEF_TX_RING_SIZE	MLX4_EN_DEF_RX_RING_SIZE
1238c2ecf20Sopenharmony_ci#define MAX_TX_RINGS			(MLX4_EN_MAX_TX_RING_P_UP * \
1248c2ecf20Sopenharmony_ci					 MLX4_EN_NUM_UP_HIGH)
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#define MLX4_EN_DEFAULT_TX_WORK		256
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/* Target number of packets to coalesce with interrupt moderation */
1298c2ecf20Sopenharmony_ci#define MLX4_EN_RX_COAL_TARGET	44
1308c2ecf20Sopenharmony_ci#define MLX4_EN_RX_COAL_TIME	0x10
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci#define MLX4_EN_TX_COAL_PKTS	16
1338c2ecf20Sopenharmony_ci#define MLX4_EN_TX_COAL_TIME	0x10
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#define MLX4_EN_MAX_COAL_PKTS	U16_MAX
1368c2ecf20Sopenharmony_ci#define MLX4_EN_MAX_COAL_TIME	U16_MAX
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#define MLX4_EN_RX_RATE_LOW		400000
1398c2ecf20Sopenharmony_ci#define MLX4_EN_RX_COAL_TIME_LOW	0
1408c2ecf20Sopenharmony_ci#define MLX4_EN_RX_RATE_HIGH		450000
1418c2ecf20Sopenharmony_ci#define MLX4_EN_RX_COAL_TIME_HIGH	128
1428c2ecf20Sopenharmony_ci#define MLX4_EN_RX_SIZE_THRESH		1024
1438c2ecf20Sopenharmony_ci#define MLX4_EN_RX_RATE_THRESH		(1000000 / MLX4_EN_RX_COAL_TIME_HIGH)
1448c2ecf20Sopenharmony_ci#define MLX4_EN_SAMPLE_INTERVAL		0
1458c2ecf20Sopenharmony_ci#define MLX4_EN_AVG_PKT_SMALL		256
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci#define MLX4_EN_AUTO_CONF	0xffff
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#define MLX4_EN_DEF_RX_PAUSE	1
1508c2ecf20Sopenharmony_ci#define MLX4_EN_DEF_TX_PAUSE	1
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/* Interval between successive polls in the Tx routine when polling is used
1538c2ecf20Sopenharmony_ci   instead of interrupts (in per-core Tx rings) - should be power of 2 */
1548c2ecf20Sopenharmony_ci#define MLX4_EN_TX_POLL_MODER	16
1558c2ecf20Sopenharmony_ci#define MLX4_EN_TX_POLL_TIMEOUT	(HZ / 4)
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#define SMALL_PACKET_SIZE      (256 - NET_IP_ALIGN)
1588c2ecf20Sopenharmony_ci#define HEADER_COPY_SIZE       (128 - NET_IP_ALIGN)
1598c2ecf20Sopenharmony_ci#define MLX4_LOOPBACK_TEST_PAYLOAD (HEADER_COPY_SIZE - ETH_HLEN)
1608c2ecf20Sopenharmony_ci#define PREAMBLE_LEN           8
1618c2ecf20Sopenharmony_ci#define MLX4_SELFTEST_LB_MIN_MTU (MLX4_LOOPBACK_TEST_PAYLOAD + NET_IP_ALIGN + \
1628c2ecf20Sopenharmony_ci				  ETH_HLEN + PREAMBLE_LEN)
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/* VLAN_HLEN is added twice,to support skb vlan tagged with multiple
1658c2ecf20Sopenharmony_ci * headers. (For example: ETH_P_8021Q and ETH_P_8021AD).
1668c2ecf20Sopenharmony_ci */
1678c2ecf20Sopenharmony_ci#define MLX4_EN_EFF_MTU(mtu)	((mtu) + ETH_HLEN + (2 * VLAN_HLEN))
1688c2ecf20Sopenharmony_ci#define ETH_BCAST		0xffffffffffffULL
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci#define MLX4_EN_LOOPBACK_RETRIES	5
1718c2ecf20Sopenharmony_ci#define MLX4_EN_LOOPBACK_TIMEOUT	100
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#ifdef MLX4_EN_PERF_STAT
1748c2ecf20Sopenharmony_ci/* Number of samples to 'average' */
1758c2ecf20Sopenharmony_ci#define AVG_SIZE			128
1768c2ecf20Sopenharmony_ci#define AVG_FACTOR			1024
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#define INC_PERF_COUNTER(cnt)		(++(cnt))
1798c2ecf20Sopenharmony_ci#define ADD_PERF_COUNTER(cnt, add)	((cnt) += (add))
1808c2ecf20Sopenharmony_ci#define AVG_PERF_COUNTER(cnt, sample) \
1818c2ecf20Sopenharmony_ci	((cnt) = ((cnt) * (AVG_SIZE - 1) + (sample) * AVG_FACTOR) / AVG_SIZE)
1828c2ecf20Sopenharmony_ci#define GET_PERF_COUNTER(cnt)		(cnt)
1838c2ecf20Sopenharmony_ci#define GET_AVG_PERF_COUNTER(cnt)	((cnt) / AVG_FACTOR)
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci#else
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci#define INC_PERF_COUNTER(cnt)		do {} while (0)
1888c2ecf20Sopenharmony_ci#define ADD_PERF_COUNTER(cnt, add)	do {} while (0)
1898c2ecf20Sopenharmony_ci#define AVG_PERF_COUNTER(cnt, sample)	do {} while (0)
1908c2ecf20Sopenharmony_ci#define GET_PERF_COUNTER(cnt)		(0)
1918c2ecf20Sopenharmony_ci#define GET_AVG_PERF_COUNTER(cnt)	(0)
1928c2ecf20Sopenharmony_ci#endif /* MLX4_EN_PERF_STAT */
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci/* Constants for TX flow */
1958c2ecf20Sopenharmony_cienum {
1968c2ecf20Sopenharmony_ci	MAX_INLINE = 104, /* 128 - 16 - 4 - 4 */
1978c2ecf20Sopenharmony_ci	MAX_BF = 256,
1988c2ecf20Sopenharmony_ci	MIN_PKT_LEN = 17,
1998c2ecf20Sopenharmony_ci};
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/*
2028c2ecf20Sopenharmony_ci * Configurables
2038c2ecf20Sopenharmony_ci */
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_cienum cq_type {
2068c2ecf20Sopenharmony_ci	/* keep tx types first */
2078c2ecf20Sopenharmony_ci	TX,
2088c2ecf20Sopenharmony_ci	TX_XDP,
2098c2ecf20Sopenharmony_ci#define MLX4_EN_NUM_TX_TYPES (TX_XDP + 1)
2108c2ecf20Sopenharmony_ci	RX,
2118c2ecf20Sopenharmony_ci};
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/*
2158c2ecf20Sopenharmony_ci * Useful macros
2168c2ecf20Sopenharmony_ci */
2178c2ecf20Sopenharmony_ci#define ROUNDUP_LOG2(x)		ilog2(roundup_pow_of_two(x))
2188c2ecf20Sopenharmony_ci#define XNOR(x, y)		(!(x) == !(y))
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_cistruct mlx4_en_tx_info {
2228c2ecf20Sopenharmony_ci	union {
2238c2ecf20Sopenharmony_ci		struct sk_buff *skb;
2248c2ecf20Sopenharmony_ci		struct page *page;
2258c2ecf20Sopenharmony_ci	};
2268c2ecf20Sopenharmony_ci	dma_addr_t	map0_dma;
2278c2ecf20Sopenharmony_ci	u32		map0_byte_count;
2288c2ecf20Sopenharmony_ci	u32		nr_txbb;
2298c2ecf20Sopenharmony_ci	u32		nr_bytes;
2308c2ecf20Sopenharmony_ci	u8		linear;
2318c2ecf20Sopenharmony_ci	u8		data_offset;
2328c2ecf20Sopenharmony_ci	u8		inl;
2338c2ecf20Sopenharmony_ci	u8		ts_requested;
2348c2ecf20Sopenharmony_ci	u8		nr_maps;
2358c2ecf20Sopenharmony_ci} ____cacheline_aligned_in_smp;
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci#define MLX4_EN_BIT_DESC_OWN	0x80000000
2398c2ecf20Sopenharmony_ci#define CTRL_SIZE	sizeof(struct mlx4_wqe_ctrl_seg)
2408c2ecf20Sopenharmony_ci#define MLX4_EN_MEMTYPE_PAD	0x100
2418c2ecf20Sopenharmony_ci#define DS_SIZE		sizeof(struct mlx4_wqe_data_seg)
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_cistruct mlx4_en_tx_desc {
2458c2ecf20Sopenharmony_ci	struct mlx4_wqe_ctrl_seg ctrl;
2468c2ecf20Sopenharmony_ci	union {
2478c2ecf20Sopenharmony_ci		struct mlx4_wqe_data_seg data; /* at least one data segment */
2488c2ecf20Sopenharmony_ci		struct mlx4_wqe_lso_seg lso;
2498c2ecf20Sopenharmony_ci		struct mlx4_wqe_inline_seg inl;
2508c2ecf20Sopenharmony_ci	};
2518c2ecf20Sopenharmony_ci};
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci#define MLX4_EN_USE_SRQ		0x01000000
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci#define MLX4_EN_CX3_LOW_ID	0x1000
2568c2ecf20Sopenharmony_ci#define MLX4_EN_CX3_HIGH_ID	0x1005
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_cistruct mlx4_en_rx_alloc {
2598c2ecf20Sopenharmony_ci	struct page	*page;
2608c2ecf20Sopenharmony_ci	dma_addr_t	dma;
2618c2ecf20Sopenharmony_ci	u32		page_offset;
2628c2ecf20Sopenharmony_ci};
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci#define MLX4_EN_CACHE_SIZE (2 * NAPI_POLL_WEIGHT)
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cistruct mlx4_en_page_cache {
2678c2ecf20Sopenharmony_ci	u32 index;
2688c2ecf20Sopenharmony_ci	struct {
2698c2ecf20Sopenharmony_ci		struct page	*page;
2708c2ecf20Sopenharmony_ci		dma_addr_t	dma;
2718c2ecf20Sopenharmony_ci	} buf[MLX4_EN_CACHE_SIZE];
2728c2ecf20Sopenharmony_ci};
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_cienum {
2758c2ecf20Sopenharmony_ci	MLX4_EN_TX_RING_STATE_RECOVERING,
2768c2ecf20Sopenharmony_ci};
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_cistruct mlx4_en_priv;
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_cistruct mlx4_en_tx_ring {
2818c2ecf20Sopenharmony_ci	/* cache line used and dirtied in tx completion
2828c2ecf20Sopenharmony_ci	 * (mlx4_en_free_tx_buf())
2838c2ecf20Sopenharmony_ci	 */
2848c2ecf20Sopenharmony_ci	u32			last_nr_txbb;
2858c2ecf20Sopenharmony_ci	u32			cons;
2868c2ecf20Sopenharmony_ci	unsigned long		wake_queue;
2878c2ecf20Sopenharmony_ci	struct netdev_queue	*tx_queue;
2888c2ecf20Sopenharmony_ci	u32			(*free_tx_desc)(struct mlx4_en_priv *priv,
2898c2ecf20Sopenharmony_ci						struct mlx4_en_tx_ring *ring,
2908c2ecf20Sopenharmony_ci						int index,
2918c2ecf20Sopenharmony_ci						u64 timestamp, int napi_mode);
2928c2ecf20Sopenharmony_ci	struct mlx4_en_rx_ring	*recycle_ring;
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	/* cache line used and dirtied in mlx4_en_xmit() */
2958c2ecf20Sopenharmony_ci	u32			prod ____cacheline_aligned_in_smp;
2968c2ecf20Sopenharmony_ci	unsigned int		tx_dropped;
2978c2ecf20Sopenharmony_ci	unsigned long		bytes;
2988c2ecf20Sopenharmony_ci	unsigned long		packets;
2998c2ecf20Sopenharmony_ci	unsigned long		tx_csum;
3008c2ecf20Sopenharmony_ci	unsigned long		tso_packets;
3018c2ecf20Sopenharmony_ci	unsigned long		xmit_more;
3028c2ecf20Sopenharmony_ci	struct mlx4_bf		bf;
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	/* Following part should be mostly read */
3058c2ecf20Sopenharmony_ci	__be32			doorbell_qpn;
3068c2ecf20Sopenharmony_ci	__be32			mr_key;
3078c2ecf20Sopenharmony_ci	u32			size; /* number of TXBBs */
3088c2ecf20Sopenharmony_ci	u32			size_mask;
3098c2ecf20Sopenharmony_ci	u32			full_size;
3108c2ecf20Sopenharmony_ci	u32			buf_size;
3118c2ecf20Sopenharmony_ci	void			*buf;
3128c2ecf20Sopenharmony_ci	struct mlx4_en_tx_info	*tx_info;
3138c2ecf20Sopenharmony_ci	int			qpn;
3148c2ecf20Sopenharmony_ci	u8			queue_index;
3158c2ecf20Sopenharmony_ci	bool			bf_enabled;
3168c2ecf20Sopenharmony_ci	bool			bf_alloced;
3178c2ecf20Sopenharmony_ci	u8			hwtstamp_tx_type;
3188c2ecf20Sopenharmony_ci	u8			*bounce_buf;
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	/* Not used in fast path
3218c2ecf20Sopenharmony_ci	 * Only queue_stopped might be used if BQL is not properly working.
3228c2ecf20Sopenharmony_ci	 */
3238c2ecf20Sopenharmony_ci	unsigned long		queue_stopped;
3248c2ecf20Sopenharmony_ci	unsigned long		state;
3258c2ecf20Sopenharmony_ci	struct mlx4_hwq_resources sp_wqres;
3268c2ecf20Sopenharmony_ci	struct mlx4_qp		sp_qp;
3278c2ecf20Sopenharmony_ci	struct mlx4_qp_context	sp_context;
3288c2ecf20Sopenharmony_ci	cpumask_t		sp_affinity_mask;
3298c2ecf20Sopenharmony_ci	enum mlx4_qp_state	sp_qp_state;
3308c2ecf20Sopenharmony_ci	u16			sp_stride;
3318c2ecf20Sopenharmony_ci	u16			sp_cqn;	/* index of port CQ associated with this ring */
3328c2ecf20Sopenharmony_ci} ____cacheline_aligned_in_smp;
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_cistruct mlx4_en_rx_desc {
3358c2ecf20Sopenharmony_ci	/* actual number of entries depends on rx ring stride */
3368c2ecf20Sopenharmony_ci	struct mlx4_wqe_data_seg data[0];
3378c2ecf20Sopenharmony_ci};
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_cistruct mlx4_en_rx_ring {
3408c2ecf20Sopenharmony_ci	struct mlx4_hwq_resources wqres;
3418c2ecf20Sopenharmony_ci	u32 size ;	/* number of Rx descs*/
3428c2ecf20Sopenharmony_ci	u32 actual_size;
3438c2ecf20Sopenharmony_ci	u32 size_mask;
3448c2ecf20Sopenharmony_ci	u16 stride;
3458c2ecf20Sopenharmony_ci	u16 log_stride;
3468c2ecf20Sopenharmony_ci	u16 cqn;	/* index of port CQ associated with this ring */
3478c2ecf20Sopenharmony_ci	u32 prod;
3488c2ecf20Sopenharmony_ci	u32 cons;
3498c2ecf20Sopenharmony_ci	u32 buf_size;
3508c2ecf20Sopenharmony_ci	u8  fcs_del;
3518c2ecf20Sopenharmony_ci	void *buf;
3528c2ecf20Sopenharmony_ci	void *rx_info;
3538c2ecf20Sopenharmony_ci	struct bpf_prog __rcu *xdp_prog;
3548c2ecf20Sopenharmony_ci	struct mlx4_en_page_cache page_cache;
3558c2ecf20Sopenharmony_ci	unsigned long bytes;
3568c2ecf20Sopenharmony_ci	unsigned long packets;
3578c2ecf20Sopenharmony_ci	unsigned long csum_ok;
3588c2ecf20Sopenharmony_ci	unsigned long csum_none;
3598c2ecf20Sopenharmony_ci	unsigned long csum_complete;
3608c2ecf20Sopenharmony_ci	unsigned long rx_alloc_pages;
3618c2ecf20Sopenharmony_ci	unsigned long xdp_drop;
3628c2ecf20Sopenharmony_ci	unsigned long xdp_tx;
3638c2ecf20Sopenharmony_ci	unsigned long xdp_tx_full;
3648c2ecf20Sopenharmony_ci	unsigned long dropped;
3658c2ecf20Sopenharmony_ci	int hwtstamp_rx_filter;
3668c2ecf20Sopenharmony_ci	cpumask_var_t affinity_mask;
3678c2ecf20Sopenharmony_ci	struct xdp_rxq_info xdp_rxq;
3688c2ecf20Sopenharmony_ci};
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_cistruct mlx4_en_cq {
3718c2ecf20Sopenharmony_ci	struct mlx4_cq          mcq;
3728c2ecf20Sopenharmony_ci	struct mlx4_hwq_resources wqres;
3738c2ecf20Sopenharmony_ci	int                     ring;
3748c2ecf20Sopenharmony_ci	struct net_device      *dev;
3758c2ecf20Sopenharmony_ci	union {
3768c2ecf20Sopenharmony_ci		struct napi_struct napi;
3778c2ecf20Sopenharmony_ci		bool               xdp_busy;
3788c2ecf20Sopenharmony_ci	};
3798c2ecf20Sopenharmony_ci	int size;
3808c2ecf20Sopenharmony_ci	int buf_size;
3818c2ecf20Sopenharmony_ci	int vector;
3828c2ecf20Sopenharmony_ci	enum cq_type type;
3838c2ecf20Sopenharmony_ci	u16 moder_time;
3848c2ecf20Sopenharmony_ci	u16 moder_cnt;
3858c2ecf20Sopenharmony_ci	struct mlx4_cqe *buf;
3868c2ecf20Sopenharmony_ci#define MLX4_EN_OPCODE_ERROR	0x1e
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	struct irq_desc *irq_desc;
3898c2ecf20Sopenharmony_ci};
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_cistruct mlx4_en_port_profile {
3928c2ecf20Sopenharmony_ci	u32 flags;
3938c2ecf20Sopenharmony_ci	u32 tx_ring_num[MLX4_EN_NUM_TX_TYPES];
3948c2ecf20Sopenharmony_ci	u32 rx_ring_num;
3958c2ecf20Sopenharmony_ci	u32 tx_ring_size;
3968c2ecf20Sopenharmony_ci	u32 rx_ring_size;
3978c2ecf20Sopenharmony_ci	u8 num_tx_rings_p_up;
3988c2ecf20Sopenharmony_ci	u8 rx_pause;
3998c2ecf20Sopenharmony_ci	u8 rx_ppp;
4008c2ecf20Sopenharmony_ci	u8 tx_pause;
4018c2ecf20Sopenharmony_ci	u8 tx_ppp;
4028c2ecf20Sopenharmony_ci	u8 num_up;
4038c2ecf20Sopenharmony_ci	int rss_rings;
4048c2ecf20Sopenharmony_ci	int inline_thold;
4058c2ecf20Sopenharmony_ci	struct hwtstamp_config hwtstamp_config;
4068c2ecf20Sopenharmony_ci};
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_cistruct mlx4_en_profile {
4098c2ecf20Sopenharmony_ci	int udp_rss;
4108c2ecf20Sopenharmony_ci	u8 rss_mask;
4118c2ecf20Sopenharmony_ci	u32 active_ports;
4128c2ecf20Sopenharmony_ci	u32 small_pkt_int;
4138c2ecf20Sopenharmony_ci	u8 no_reset;
4148c2ecf20Sopenharmony_ci	u8 max_num_tx_rings_p_up;
4158c2ecf20Sopenharmony_ci	struct mlx4_en_port_profile prof[MLX4_MAX_PORTS + 1];
4168c2ecf20Sopenharmony_ci};
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_cistruct mlx4_en_dev {
4198c2ecf20Sopenharmony_ci	struct mlx4_dev         *dev;
4208c2ecf20Sopenharmony_ci	struct pci_dev		*pdev;
4218c2ecf20Sopenharmony_ci	struct mutex		state_lock;
4228c2ecf20Sopenharmony_ci	struct net_device       *pndev[MLX4_MAX_PORTS + 1];
4238c2ecf20Sopenharmony_ci	struct net_device       *upper[MLX4_MAX_PORTS + 1];
4248c2ecf20Sopenharmony_ci	u32                     port_cnt;
4258c2ecf20Sopenharmony_ci	bool			device_up;
4268c2ecf20Sopenharmony_ci	struct mlx4_en_profile  profile;
4278c2ecf20Sopenharmony_ci	u32			LSO_support;
4288c2ecf20Sopenharmony_ci	struct workqueue_struct *workqueue;
4298c2ecf20Sopenharmony_ci	struct device           *dma_device;
4308c2ecf20Sopenharmony_ci	void __iomem            *uar_map;
4318c2ecf20Sopenharmony_ci	struct mlx4_uar         priv_uar;
4328c2ecf20Sopenharmony_ci	struct mlx4_mr		mr;
4338c2ecf20Sopenharmony_ci	u32                     priv_pdn;
4348c2ecf20Sopenharmony_ci	spinlock_t              uar_lock;
4358c2ecf20Sopenharmony_ci	u8			mac_removed[MLX4_MAX_PORTS + 1];
4368c2ecf20Sopenharmony_ci	u32			nominal_c_mult;
4378c2ecf20Sopenharmony_ci	struct cyclecounter	cycles;
4388c2ecf20Sopenharmony_ci	seqlock_t		clock_lock;
4398c2ecf20Sopenharmony_ci	struct timecounter	clock;
4408c2ecf20Sopenharmony_ci	unsigned long		last_overflow_check;
4418c2ecf20Sopenharmony_ci	struct ptp_clock	*ptp_clock;
4428c2ecf20Sopenharmony_ci	struct ptp_clock_info	ptp_clock_info;
4438c2ecf20Sopenharmony_ci	struct notifier_block	nb;
4448c2ecf20Sopenharmony_ci};
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_cistruct mlx4_en_rss_map {
4488c2ecf20Sopenharmony_ci	int base_qpn;
4498c2ecf20Sopenharmony_ci	struct mlx4_qp qps[MAX_RX_RINGS];
4508c2ecf20Sopenharmony_ci	enum mlx4_qp_state state[MAX_RX_RINGS];
4518c2ecf20Sopenharmony_ci	struct mlx4_qp *indir_qp;
4528c2ecf20Sopenharmony_ci	enum mlx4_qp_state indir_state;
4538c2ecf20Sopenharmony_ci};
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_cienum mlx4_en_port_flag {
4568c2ecf20Sopenharmony_ci	MLX4_EN_PORT_ANC = 1<<0, /* Auto-negotiation complete */
4578c2ecf20Sopenharmony_ci	MLX4_EN_PORT_ANE = 1<<1, /* Auto-negotiation enabled */
4588c2ecf20Sopenharmony_ci};
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_cistruct mlx4_en_port_state {
4618c2ecf20Sopenharmony_ci	int link_state;
4628c2ecf20Sopenharmony_ci	int link_speed;
4638c2ecf20Sopenharmony_ci	int transceiver;
4648c2ecf20Sopenharmony_ci	u32 flags;
4658c2ecf20Sopenharmony_ci};
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_cienum mlx4_en_mclist_act {
4688c2ecf20Sopenharmony_ci	MCLIST_NONE,
4698c2ecf20Sopenharmony_ci	MCLIST_REM,
4708c2ecf20Sopenharmony_ci	MCLIST_ADD,
4718c2ecf20Sopenharmony_ci};
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_cistruct mlx4_en_mc_list {
4748c2ecf20Sopenharmony_ci	struct list_head	list;
4758c2ecf20Sopenharmony_ci	enum mlx4_en_mclist_act	action;
4768c2ecf20Sopenharmony_ci	u8			addr[ETH_ALEN];
4778c2ecf20Sopenharmony_ci	u64			reg_id;
4788c2ecf20Sopenharmony_ci	u64			tunnel_reg_id;
4798c2ecf20Sopenharmony_ci};
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_cistruct mlx4_en_frag_info {
4828c2ecf20Sopenharmony_ci	u16 frag_size;
4838c2ecf20Sopenharmony_ci	u32 frag_stride;
4848c2ecf20Sopenharmony_ci};
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci#ifdef CONFIG_MLX4_EN_DCB
4878c2ecf20Sopenharmony_ci/* Minimal TC BW - setting to 0 will block traffic */
4888c2ecf20Sopenharmony_ci#define MLX4_EN_BW_MIN 1
4898c2ecf20Sopenharmony_ci#define MLX4_EN_BW_MAX 100 /* Utilize 100% of the line */
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci#define MLX4_EN_TC_VENDOR 0
4928c2ecf20Sopenharmony_ci#define MLX4_EN_TC_ETS 7
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_cienum dcb_pfc_type {
4958c2ecf20Sopenharmony_ci	pfc_disabled = 0,
4968c2ecf20Sopenharmony_ci	pfc_enabled_full,
4978c2ecf20Sopenharmony_ci	pfc_enabled_tx,
4988c2ecf20Sopenharmony_ci	pfc_enabled_rx
4998c2ecf20Sopenharmony_ci};
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_cistruct mlx4_en_cee_config {
5028c2ecf20Sopenharmony_ci	bool	pfc_state;
5038c2ecf20Sopenharmony_ci	enum	dcb_pfc_type dcb_pfc[MLX4_EN_NUM_UP_HIGH];
5048c2ecf20Sopenharmony_ci};
5058c2ecf20Sopenharmony_ci#endif
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_cistruct ethtool_flow_id {
5088c2ecf20Sopenharmony_ci	struct list_head list;
5098c2ecf20Sopenharmony_ci	struct ethtool_rx_flow_spec flow_spec;
5108c2ecf20Sopenharmony_ci	u64 id;
5118c2ecf20Sopenharmony_ci};
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_cienum {
5148c2ecf20Sopenharmony_ci	MLX4_EN_FLAG_PROMISC		= (1 << 0),
5158c2ecf20Sopenharmony_ci	MLX4_EN_FLAG_MC_PROMISC		= (1 << 1),
5168c2ecf20Sopenharmony_ci	/* whether we need to enable hardware loopback by putting dmac
5178c2ecf20Sopenharmony_ci	 * in Tx WQE
5188c2ecf20Sopenharmony_ci	 */
5198c2ecf20Sopenharmony_ci	MLX4_EN_FLAG_ENABLE_HW_LOOPBACK	= (1 << 2),
5208c2ecf20Sopenharmony_ci	/* whether we need to drop packets that hardware loopback-ed */
5218c2ecf20Sopenharmony_ci	MLX4_EN_FLAG_RX_FILTER_NEEDED	= (1 << 3),
5228c2ecf20Sopenharmony_ci	MLX4_EN_FLAG_FORCE_PROMISC	= (1 << 4),
5238c2ecf20Sopenharmony_ci	MLX4_EN_FLAG_RX_CSUM_NON_TCP_UDP	= (1 << 5),
5248c2ecf20Sopenharmony_ci#ifdef CONFIG_MLX4_EN_DCB
5258c2ecf20Sopenharmony_ci	MLX4_EN_FLAG_DCB_ENABLED        = (1 << 6),
5268c2ecf20Sopenharmony_ci#endif
5278c2ecf20Sopenharmony_ci};
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci#define PORT_BEACON_MAX_LIMIT (65535)
5308c2ecf20Sopenharmony_ci#define MLX4_EN_MAC_HASH_SIZE (1 << BITS_PER_BYTE)
5318c2ecf20Sopenharmony_ci#define MLX4_EN_MAC_HASH_IDX 5
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_cistruct mlx4_en_stats_bitmap {
5348c2ecf20Sopenharmony_ci	DECLARE_BITMAP(bitmap, NUM_ALL_STATS);
5358c2ecf20Sopenharmony_ci	struct mutex mutex; /* for mutual access to stats bitmap */
5368c2ecf20Sopenharmony_ci};
5378c2ecf20Sopenharmony_ci
5388c2ecf20Sopenharmony_cienum {
5398c2ecf20Sopenharmony_ci	MLX4_EN_STATE_FLAG_RESTARTING,
5408c2ecf20Sopenharmony_ci};
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_cistruct mlx4_en_priv {
5438c2ecf20Sopenharmony_ci	struct mlx4_en_dev *mdev;
5448c2ecf20Sopenharmony_ci	struct mlx4_en_port_profile *prof;
5458c2ecf20Sopenharmony_ci	struct net_device *dev;
5468c2ecf20Sopenharmony_ci	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
5478c2ecf20Sopenharmony_ci	struct mlx4_en_port_state port_state;
5488c2ecf20Sopenharmony_ci	spinlock_t stats_lock;
5498c2ecf20Sopenharmony_ci	struct ethtool_flow_id ethtool_rules[MAX_NUM_OF_FS_RULES];
5508c2ecf20Sopenharmony_ci	/* To allow rules removal while port is going down */
5518c2ecf20Sopenharmony_ci	struct list_head ethtool_list;
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_ci	unsigned long last_moder_packets[MAX_RX_RINGS];
5548c2ecf20Sopenharmony_ci	unsigned long last_moder_tx_packets;
5558c2ecf20Sopenharmony_ci	unsigned long last_moder_bytes[MAX_RX_RINGS];
5568c2ecf20Sopenharmony_ci	unsigned long last_moder_jiffies;
5578c2ecf20Sopenharmony_ci	int last_moder_time[MAX_RX_RINGS];
5588c2ecf20Sopenharmony_ci	u16 rx_usecs;
5598c2ecf20Sopenharmony_ci	u16 rx_frames;
5608c2ecf20Sopenharmony_ci	u16 tx_usecs;
5618c2ecf20Sopenharmony_ci	u16 tx_frames;
5628c2ecf20Sopenharmony_ci	u32 pkt_rate_low;
5638c2ecf20Sopenharmony_ci	u16 rx_usecs_low;
5648c2ecf20Sopenharmony_ci	u32 pkt_rate_high;
5658c2ecf20Sopenharmony_ci	u16 rx_usecs_high;
5668c2ecf20Sopenharmony_ci	u32 sample_interval;
5678c2ecf20Sopenharmony_ci	u32 adaptive_rx_coal;
5688c2ecf20Sopenharmony_ci	u32 msg_enable;
5698c2ecf20Sopenharmony_ci	u32 loopback_ok;
5708c2ecf20Sopenharmony_ci	u32 validate_loopback;
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci	struct mlx4_hwq_resources res;
5738c2ecf20Sopenharmony_ci	int link_state;
5748c2ecf20Sopenharmony_ci	int last_link_state;
5758c2ecf20Sopenharmony_ci	bool port_up;
5768c2ecf20Sopenharmony_ci	int port;
5778c2ecf20Sopenharmony_ci	int registered;
5788c2ecf20Sopenharmony_ci	int allocated;
5798c2ecf20Sopenharmony_ci	int stride;
5808c2ecf20Sopenharmony_ci	unsigned char current_mac[ETH_ALEN + 2];
5818c2ecf20Sopenharmony_ci	int mac_index;
5828c2ecf20Sopenharmony_ci	unsigned max_mtu;
5838c2ecf20Sopenharmony_ci	int base_qpn;
5848c2ecf20Sopenharmony_ci	int cqe_factor;
5858c2ecf20Sopenharmony_ci	int cqe_size;
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	struct mlx4_en_rss_map rss_map;
5888c2ecf20Sopenharmony_ci	__be32 ctrl_flags;
5898c2ecf20Sopenharmony_ci	u32 flags;
5908c2ecf20Sopenharmony_ci	u8 num_tx_rings_p_up;
5918c2ecf20Sopenharmony_ci	u32 tx_work_limit;
5928c2ecf20Sopenharmony_ci	u32 tx_ring_num[MLX4_EN_NUM_TX_TYPES];
5938c2ecf20Sopenharmony_ci	u32 rx_ring_num;
5948c2ecf20Sopenharmony_ci	u32 rx_skb_size;
5958c2ecf20Sopenharmony_ci	struct mlx4_en_frag_info frag_info[MLX4_EN_MAX_RX_FRAGS];
5968c2ecf20Sopenharmony_ci	u8 num_frags;
5978c2ecf20Sopenharmony_ci	u8 log_rx_info;
5988c2ecf20Sopenharmony_ci	u8 dma_dir;
5998c2ecf20Sopenharmony_ci	u16 rx_headroom;
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ci	struct mlx4_en_tx_ring **tx_ring[MLX4_EN_NUM_TX_TYPES];
6028c2ecf20Sopenharmony_ci	struct mlx4_en_rx_ring *rx_ring[MAX_RX_RINGS];
6038c2ecf20Sopenharmony_ci	struct mlx4_en_cq **tx_cq[MLX4_EN_NUM_TX_TYPES];
6048c2ecf20Sopenharmony_ci	struct mlx4_en_cq *rx_cq[MAX_RX_RINGS];
6058c2ecf20Sopenharmony_ci	struct mlx4_qp drop_qp;
6068c2ecf20Sopenharmony_ci	struct work_struct rx_mode_task;
6078c2ecf20Sopenharmony_ci	struct work_struct restart_task;
6088c2ecf20Sopenharmony_ci	struct work_struct linkstate_task;
6098c2ecf20Sopenharmony_ci	struct delayed_work stats_task;
6108c2ecf20Sopenharmony_ci	struct delayed_work service_task;
6118c2ecf20Sopenharmony_ci	struct mlx4_en_perf_stats pstats;
6128c2ecf20Sopenharmony_ci	struct mlx4_en_pkt_stats pkstats;
6138c2ecf20Sopenharmony_ci	struct mlx4_en_counter_stats pf_stats;
6148c2ecf20Sopenharmony_ci	struct mlx4_en_flow_stats_rx rx_priority_flowstats[MLX4_NUM_PRIORITIES];
6158c2ecf20Sopenharmony_ci	struct mlx4_en_flow_stats_tx tx_priority_flowstats[MLX4_NUM_PRIORITIES];
6168c2ecf20Sopenharmony_ci	struct mlx4_en_flow_stats_rx rx_flowstats;
6178c2ecf20Sopenharmony_ci	struct mlx4_en_flow_stats_tx tx_flowstats;
6188c2ecf20Sopenharmony_ci	struct mlx4_en_port_stats port_stats;
6198c2ecf20Sopenharmony_ci	struct mlx4_en_xdp_stats xdp_stats;
6208c2ecf20Sopenharmony_ci	struct mlx4_en_phy_stats phy_stats;
6218c2ecf20Sopenharmony_ci	struct mlx4_en_stats_bitmap stats_bitmap;
6228c2ecf20Sopenharmony_ci	struct list_head mc_list;
6238c2ecf20Sopenharmony_ci	struct list_head curr_list;
6248c2ecf20Sopenharmony_ci	u64 broadcast_id;
6258c2ecf20Sopenharmony_ci	struct mlx4_en_stat_out_mbox hw_stats;
6268c2ecf20Sopenharmony_ci	int vids[128];
6278c2ecf20Sopenharmony_ci	bool wol;
6288c2ecf20Sopenharmony_ci	struct device *ddev;
6298c2ecf20Sopenharmony_ci	struct hlist_head mac_hash[MLX4_EN_MAC_HASH_SIZE];
6308c2ecf20Sopenharmony_ci	struct hwtstamp_config hwtstamp_config;
6318c2ecf20Sopenharmony_ci	u32 counter_index;
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci#ifdef CONFIG_MLX4_EN_DCB
6348c2ecf20Sopenharmony_ci#define MLX4_EN_DCB_ENABLED	0x3
6358c2ecf20Sopenharmony_ci	struct ieee_ets ets;
6368c2ecf20Sopenharmony_ci	u16 maxrate[IEEE_8021QAZ_MAX_TCS];
6378c2ecf20Sopenharmony_ci	enum dcbnl_cndd_states cndd_state[IEEE_8021QAZ_MAX_TCS];
6388c2ecf20Sopenharmony_ci	struct mlx4_en_cee_config cee_config;
6398c2ecf20Sopenharmony_ci	u8 dcbx_cap;
6408c2ecf20Sopenharmony_ci#endif
6418c2ecf20Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL
6428c2ecf20Sopenharmony_ci	spinlock_t filters_lock;
6438c2ecf20Sopenharmony_ci	int last_filter_id;
6448c2ecf20Sopenharmony_ci	struct list_head filters;
6458c2ecf20Sopenharmony_ci	struct hlist_head filter_hash[1 << MLX4_EN_FILTER_HASH_SHIFT];
6468c2ecf20Sopenharmony_ci#endif
6478c2ecf20Sopenharmony_ci	u64 tunnel_reg_id;
6488c2ecf20Sopenharmony_ci	__be16 vxlan_port;
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci	u32 pflags;
6518c2ecf20Sopenharmony_ci	u8 rss_key[MLX4_EN_RSS_KEY_SIZE];
6528c2ecf20Sopenharmony_ci	u8 rss_hash_fn;
6538c2ecf20Sopenharmony_ci	unsigned long state;
6548c2ecf20Sopenharmony_ci};
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_cienum mlx4_en_wol {
6578c2ecf20Sopenharmony_ci	MLX4_EN_WOL_MAGIC = (1ULL << 61),
6588c2ecf20Sopenharmony_ci	MLX4_EN_WOL_ENABLED = (1ULL << 62),
6598c2ecf20Sopenharmony_ci};
6608c2ecf20Sopenharmony_ci
6618c2ecf20Sopenharmony_cistruct mlx4_mac_entry {
6628c2ecf20Sopenharmony_ci	struct hlist_node hlist;
6638c2ecf20Sopenharmony_ci	unsigned char mac[ETH_ALEN + 2];
6648c2ecf20Sopenharmony_ci	u64 reg_id;
6658c2ecf20Sopenharmony_ci	struct rcu_head rcu;
6668c2ecf20Sopenharmony_ci};
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_cistatic inline struct mlx4_cqe *mlx4_en_get_cqe(void *buf, int idx, int cqe_sz)
6698c2ecf20Sopenharmony_ci{
6708c2ecf20Sopenharmony_ci	return buf + idx * cqe_sz;
6718c2ecf20Sopenharmony_ci}
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci#define MLX4_EN_WOL_DO_MODIFY (1ULL << 63)
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_civoid mlx4_en_init_ptys2ethtool_map(void);
6768c2ecf20Sopenharmony_civoid mlx4_en_update_loopback_state(struct net_device *dev,
6778c2ecf20Sopenharmony_ci				   netdev_features_t features);
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_civoid mlx4_en_destroy_netdev(struct net_device *dev);
6808c2ecf20Sopenharmony_ciint mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
6818c2ecf20Sopenharmony_ci			struct mlx4_en_port_profile *prof);
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ciint mlx4_en_start_port(struct net_device *dev);
6848c2ecf20Sopenharmony_civoid mlx4_en_stop_port(struct net_device *dev, int detach);
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_civoid mlx4_en_set_stats_bitmap(struct mlx4_dev *dev,
6878c2ecf20Sopenharmony_ci			      struct mlx4_en_stats_bitmap *stats_bitmap,
6888c2ecf20Sopenharmony_ci			      u8 rx_ppp, u8 rx_pause,
6898c2ecf20Sopenharmony_ci			      u8 tx_ppp, u8 tx_pause);
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ciint mlx4_en_try_alloc_resources(struct mlx4_en_priv *priv,
6928c2ecf20Sopenharmony_ci				struct mlx4_en_priv *tmp,
6938c2ecf20Sopenharmony_ci				struct mlx4_en_port_profile *prof,
6948c2ecf20Sopenharmony_ci				bool carry_xdp_prog);
6958c2ecf20Sopenharmony_civoid mlx4_en_safe_replace_resources(struct mlx4_en_priv *priv,
6968c2ecf20Sopenharmony_ci				    struct mlx4_en_priv *tmp);
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_ciint mlx4_en_create_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq,
6998c2ecf20Sopenharmony_ci		      int entries, int ring, enum cq_type mode, int node);
7008c2ecf20Sopenharmony_civoid mlx4_en_destroy_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq);
7018c2ecf20Sopenharmony_ciint mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,
7028c2ecf20Sopenharmony_ci			int cq_idx);
7038c2ecf20Sopenharmony_civoid mlx4_en_deactivate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
7048c2ecf20Sopenharmony_ciint mlx4_en_set_cq_moder(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
7058c2ecf20Sopenharmony_civoid mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_civoid mlx4_en_tx_irq(struct mlx4_cq *mcq);
7088c2ecf20Sopenharmony_ciu16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,
7098c2ecf20Sopenharmony_ci			 struct net_device *sb_dev);
7108c2ecf20Sopenharmony_cinetdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev);
7118c2ecf20Sopenharmony_cinetdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring,
7128c2ecf20Sopenharmony_ci			       struct mlx4_en_rx_alloc *frame,
7138c2ecf20Sopenharmony_ci			       struct mlx4_en_priv *priv, unsigned int length,
7148c2ecf20Sopenharmony_ci			       int tx_ind, bool *doorbell_pending);
7158c2ecf20Sopenharmony_civoid mlx4_en_xmit_doorbell(struct mlx4_en_tx_ring *ring);
7168c2ecf20Sopenharmony_cibool mlx4_en_rx_recycle(struct mlx4_en_rx_ring *ring,
7178c2ecf20Sopenharmony_ci			struct mlx4_en_rx_alloc *frame);
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_ciint mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
7208c2ecf20Sopenharmony_ci			   struct mlx4_en_tx_ring **pring,
7218c2ecf20Sopenharmony_ci			   u32 size, u16 stride,
7228c2ecf20Sopenharmony_ci			   int node, int queue_index);
7238c2ecf20Sopenharmony_civoid mlx4_en_destroy_tx_ring(struct mlx4_en_priv *priv,
7248c2ecf20Sopenharmony_ci			     struct mlx4_en_tx_ring **pring);
7258c2ecf20Sopenharmony_civoid mlx4_en_init_tx_xdp_ring_descs(struct mlx4_en_priv *priv,
7268c2ecf20Sopenharmony_ci				    struct mlx4_en_tx_ring *ring);
7278c2ecf20Sopenharmony_ciint mlx4_en_activate_tx_ring(struct mlx4_en_priv *priv,
7288c2ecf20Sopenharmony_ci			     struct mlx4_en_tx_ring *ring,
7298c2ecf20Sopenharmony_ci			     int cq, int user_prio);
7308c2ecf20Sopenharmony_civoid mlx4_en_deactivate_tx_ring(struct mlx4_en_priv *priv,
7318c2ecf20Sopenharmony_ci				struct mlx4_en_tx_ring *ring);
7328c2ecf20Sopenharmony_civoid mlx4_en_set_num_rx_rings(struct mlx4_en_dev *mdev);
7338c2ecf20Sopenharmony_civoid mlx4_en_recover_from_oom(struct mlx4_en_priv *priv);
7348c2ecf20Sopenharmony_ciint mlx4_en_create_rx_ring(struct mlx4_en_priv *priv,
7358c2ecf20Sopenharmony_ci			   struct mlx4_en_rx_ring **pring,
7368c2ecf20Sopenharmony_ci			   u32 size, u16 stride, int node, int queue_index);
7378c2ecf20Sopenharmony_civoid mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv,
7388c2ecf20Sopenharmony_ci			     struct mlx4_en_rx_ring **pring,
7398c2ecf20Sopenharmony_ci			     u32 size, u16 stride);
7408c2ecf20Sopenharmony_ciint mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv);
7418c2ecf20Sopenharmony_civoid mlx4_en_deactivate_rx_ring(struct mlx4_en_priv *priv,
7428c2ecf20Sopenharmony_ci				struct mlx4_en_rx_ring *ring);
7438c2ecf20Sopenharmony_ciint mlx4_en_process_rx_cq(struct net_device *dev,
7448c2ecf20Sopenharmony_ci			  struct mlx4_en_cq *cq,
7458c2ecf20Sopenharmony_ci			  int budget);
7468c2ecf20Sopenharmony_ciint mlx4_en_poll_rx_cq(struct napi_struct *napi, int budget);
7478c2ecf20Sopenharmony_ciint mlx4_en_poll_tx_cq(struct napi_struct *napi, int budget);
7488c2ecf20Sopenharmony_ciint mlx4_en_process_tx_cq(struct net_device *dev,
7498c2ecf20Sopenharmony_ci			  struct mlx4_en_cq *cq, int napi_budget);
7508c2ecf20Sopenharmony_ciu32 mlx4_en_free_tx_desc(struct mlx4_en_priv *priv,
7518c2ecf20Sopenharmony_ci			 struct mlx4_en_tx_ring *ring,
7528c2ecf20Sopenharmony_ci			 int index, u64 timestamp,
7538c2ecf20Sopenharmony_ci			 int napi_mode);
7548c2ecf20Sopenharmony_ciu32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,
7558c2ecf20Sopenharmony_ci			    struct mlx4_en_tx_ring *ring,
7568c2ecf20Sopenharmony_ci			    int index, u64 timestamp,
7578c2ecf20Sopenharmony_ci			    int napi_mode);
7588c2ecf20Sopenharmony_civoid mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
7598c2ecf20Sopenharmony_ci		int is_tx, int rss, int qpn, int cqn, int user_prio,
7608c2ecf20Sopenharmony_ci		struct mlx4_qp_context *context);
7618c2ecf20Sopenharmony_civoid mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event);
7628c2ecf20Sopenharmony_ciint mlx4_en_change_mcast_lb(struct mlx4_en_priv *priv, struct mlx4_qp *qp,
7638c2ecf20Sopenharmony_ci			    int loopback);
7648c2ecf20Sopenharmony_civoid mlx4_en_calc_rx_buf(struct net_device *dev);
7658c2ecf20Sopenharmony_ciint mlx4_en_config_rss_steer(struct mlx4_en_priv *priv);
7668c2ecf20Sopenharmony_civoid mlx4_en_release_rss_steer(struct mlx4_en_priv *priv);
7678c2ecf20Sopenharmony_ciint mlx4_en_create_drop_qp(struct mlx4_en_priv *priv);
7688c2ecf20Sopenharmony_civoid mlx4_en_destroy_drop_qp(struct mlx4_en_priv *priv);
7698c2ecf20Sopenharmony_ciint mlx4_en_free_tx_buf(struct net_device *dev, struct mlx4_en_tx_ring *ring);
7708c2ecf20Sopenharmony_civoid mlx4_en_rx_irq(struct mlx4_cq *mcq);
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ciint mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port, u64 mac, u64 clear, u8 mode);
7738c2ecf20Sopenharmony_ciint mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, struct mlx4_en_priv *priv);
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_civoid mlx4_en_fold_software_stats(struct net_device *dev);
7768c2ecf20Sopenharmony_ciint mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset);
7778c2ecf20Sopenharmony_ciint mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port);
7788c2ecf20Sopenharmony_ci
7798c2ecf20Sopenharmony_ci#ifdef CONFIG_MLX4_EN_DCB
7808c2ecf20Sopenharmony_ciextern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_ops;
7818c2ecf20Sopenharmony_ciextern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_pfc_ops;
7828c2ecf20Sopenharmony_ci#endif
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ciint mlx4_en_setup_tc(struct net_device *dev, u8 up);
7858c2ecf20Sopenharmony_ciint mlx4_en_alloc_tx_queue_per_tc(struct net_device *dev, u8 tc);
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_ci#ifdef CONFIG_RFS_ACCEL
7888c2ecf20Sopenharmony_civoid mlx4_en_cleanup_filters(struct mlx4_en_priv *priv);
7898c2ecf20Sopenharmony_ci#endif
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci#define MLX4_EN_NUM_SELF_TEST	5
7928c2ecf20Sopenharmony_civoid mlx4_en_ex_selftest(struct net_device *dev, u32 *flags, u64 *buf);
7938c2ecf20Sopenharmony_civoid mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev);
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_ci#define DEV_FEATURE_CHANGED(dev, new_features, feature) \
7968c2ecf20Sopenharmony_ci	((dev->features & feature) ^ (new_features & feature))
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ciint mlx4_en_moderation_update(struct mlx4_en_priv *priv);
7998c2ecf20Sopenharmony_ciint mlx4_en_reset_config(struct net_device *dev,
8008c2ecf20Sopenharmony_ci			 struct hwtstamp_config ts_config,
8018c2ecf20Sopenharmony_ci			 netdev_features_t new_features);
8028c2ecf20Sopenharmony_civoid mlx4_en_update_pfc_stats_bitmap(struct mlx4_dev *dev,
8038c2ecf20Sopenharmony_ci				     struct mlx4_en_stats_bitmap *stats_bitmap,
8048c2ecf20Sopenharmony_ci				     u8 rx_ppp, u8 rx_pause,
8058c2ecf20Sopenharmony_ci				     u8 tx_ppp, u8 tx_pause);
8068c2ecf20Sopenharmony_ciint mlx4_en_netdev_event(struct notifier_block *this,
8078c2ecf20Sopenharmony_ci			 unsigned long event, void *ptr);
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci/*
8108c2ecf20Sopenharmony_ci * Functions for time stamping
8118c2ecf20Sopenharmony_ci */
8128c2ecf20Sopenharmony_ciu64 mlx4_en_get_cqe_ts(struct mlx4_cqe *cqe);
8138c2ecf20Sopenharmony_civoid mlx4_en_fill_hwtstamps(struct mlx4_en_dev *mdev,
8148c2ecf20Sopenharmony_ci			    struct skb_shared_hwtstamps *hwts,
8158c2ecf20Sopenharmony_ci			    u64 timestamp);
8168c2ecf20Sopenharmony_civoid mlx4_en_init_timestamp(struct mlx4_en_dev *mdev);
8178c2ecf20Sopenharmony_civoid mlx4_en_remove_timestamp(struct mlx4_en_dev *mdev);
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci/* Globals
8208c2ecf20Sopenharmony_ci */
8218c2ecf20Sopenharmony_ciextern const struct ethtool_ops mlx4_en_ethtool_ops;
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_ci
8258c2ecf20Sopenharmony_ci/*
8268c2ecf20Sopenharmony_ci * printk / logging functions
8278c2ecf20Sopenharmony_ci */
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_ci__printf(3, 4)
8308c2ecf20Sopenharmony_civoid en_print(const char *level, const struct mlx4_en_priv *priv,
8318c2ecf20Sopenharmony_ci	      const char *format, ...);
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_ci#define en_dbg(mlevel, priv, format, ...)				\
8348c2ecf20Sopenharmony_cido {									\
8358c2ecf20Sopenharmony_ci	if (NETIF_MSG_##mlevel & (priv)->msg_enable)			\
8368c2ecf20Sopenharmony_ci		en_print(KERN_DEBUG, priv, format, ##__VA_ARGS__);	\
8378c2ecf20Sopenharmony_ci} while (0)
8388c2ecf20Sopenharmony_ci#define en_warn(priv, format, ...)					\
8398c2ecf20Sopenharmony_ci	en_print(KERN_WARNING, priv, format, ##__VA_ARGS__)
8408c2ecf20Sopenharmony_ci#define en_err(priv, format, ...)					\
8418c2ecf20Sopenharmony_ci	en_print(KERN_ERR, priv, format, ##__VA_ARGS__)
8428c2ecf20Sopenharmony_ci#define en_info(priv, format, ...)					\
8438c2ecf20Sopenharmony_ci	en_print(KERN_INFO, priv, format, ##__VA_ARGS__)
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci#define mlx4_err(mdev, format, ...)					\
8468c2ecf20Sopenharmony_ci	pr_err(DRV_NAME " %s: " format,					\
8478c2ecf20Sopenharmony_ci	       dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
8488c2ecf20Sopenharmony_ci#define mlx4_info(mdev, format, ...)					\
8498c2ecf20Sopenharmony_ci	pr_info(DRV_NAME " %s: " format,				\
8508c2ecf20Sopenharmony_ci		dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
8518c2ecf20Sopenharmony_ci#define mlx4_warn(mdev, format, ...)					\
8528c2ecf20Sopenharmony_ci	pr_warn(DRV_NAME " %s: " format,				\
8538c2ecf20Sopenharmony_ci		dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci#endif
856