xref: /freebsd/sys/dev/mlx4/mlx4_en/en.h (revision 63d7a8d9a890e9f07b518aed596cf26438767cdf)
197549c34SHans Petter Selasky /*
297549c34SHans Petter Selasky  * Copyright (c) 2007, 2014 Mellanox Technologies. All rights reserved.
397549c34SHans Petter Selasky  *
497549c34SHans Petter Selasky  * This software is available to you under a choice of one of two
597549c34SHans Petter Selasky  * licenses.  You may choose to be licensed under the terms of the GNU
697549c34SHans Petter Selasky  * General Public License (GPL) Version 2, available from the file
797549c34SHans Petter Selasky  * COPYING in the main directory of this source tree, or the
897549c34SHans Petter Selasky  * OpenIB.org BSD license below:
997549c34SHans Petter Selasky  *
1097549c34SHans Petter Selasky  *     Redistribution and use in source and binary forms, with or
1197549c34SHans Petter Selasky  *     without modification, are permitted provided that the following
1297549c34SHans Petter Selasky  *     conditions are met:
1397549c34SHans Petter Selasky  *
1497549c34SHans Petter Selasky  *      - Redistributions of source code must retain the above
1597549c34SHans Petter Selasky  *        copyright notice, this list of conditions and the following
1697549c34SHans Petter Selasky  *        disclaimer.
1797549c34SHans Petter Selasky  *
1897549c34SHans Petter Selasky  *      - Redistributions in binary form must reproduce the above
1997549c34SHans Petter Selasky  *        copyright notice, this list of conditions and the following
2097549c34SHans Petter Selasky  *        disclaimer in the documentation and/or other materials
2197549c34SHans Petter Selasky  *        provided with the distribution.
2297549c34SHans Petter Selasky  *
2397549c34SHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2497549c34SHans Petter Selasky  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2597549c34SHans Petter Selasky  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2697549c34SHans Petter Selasky  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2797549c34SHans Petter Selasky  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2897549c34SHans Petter Selasky  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2997549c34SHans Petter Selasky  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3097549c34SHans Petter Selasky  * SOFTWARE.
3197549c34SHans Petter Selasky  *
3297549c34SHans Petter Selasky  */
3397549c34SHans Petter Selasky 
3497549c34SHans Petter Selasky #ifndef _MLX4_EN_H_
3597549c34SHans Petter Selasky #define _MLX4_EN_H_
3697549c34SHans Petter Selasky 
3797549c34SHans Petter Selasky #include <linux/bitops.h>
3897549c34SHans Petter Selasky #include <linux/compiler.h>
3997549c34SHans Petter Selasky #include <linux/list.h>
4097549c34SHans Petter Selasky #include <linux/mutex.h>
4197549c34SHans Petter Selasky #include <linux/kobject.h>
4297549c34SHans Petter Selasky #include <linux/netdevice.h>
4397549c34SHans Petter Selasky #include <linux/if_vlan.h>
4497549c34SHans Petter Selasky #include <linux/if_ether.h>
4597549c34SHans Petter Selasky #ifdef CONFIG_MLX4_EN_DCB
4697549c34SHans Petter Selasky #include <linux/dcbnl.h>
4797549c34SHans Petter Selasky #endif
4897549c34SHans Petter Selasky 
4997549c34SHans Petter Selasky #include <dev/mlx4/device.h>
5097549c34SHans Petter Selasky #include <dev/mlx4/qp.h>
5197549c34SHans Petter Selasky #include <dev/mlx4/cq.h>
5297549c34SHans Petter Selasky #include <dev/mlx4/srq.h>
5397549c34SHans Petter Selasky #include <dev/mlx4/doorbell.h>
5497549c34SHans Petter Selasky #include <dev/mlx4/cmd.h>
5597549c34SHans Petter Selasky 
5697549c34SHans Petter Selasky #include <netinet/tcp_lro.h>
57*63d7a8d9SSlava Shwartsman #include <netinet/netdump/netdump.h>
5897549c34SHans Petter Selasky 
5997549c34SHans Petter Selasky #include "en_port.h"
6097549c34SHans Petter Selasky #include <dev/mlx4/stats.h>
6197549c34SHans Petter Selasky 
6297549c34SHans Petter Selasky #define DRV_NAME	"mlx4_en"
6397549c34SHans Petter Selasky 
6497549c34SHans Petter Selasky #define MLX4_EN_MSG_LEVEL	(NETIF_MSG_LINK | NETIF_MSG_IFDOWN)
6597549c34SHans Petter Selasky 
6697549c34SHans Petter Selasky /*
6797549c34SHans Petter Selasky  * Device constants
6897549c34SHans Petter Selasky  */
6997549c34SHans Petter Selasky 
7097549c34SHans Petter Selasky 
7197549c34SHans Petter Selasky #define MLX4_EN_PAGE_SHIFT	12
7297549c34SHans Petter Selasky #define MLX4_EN_PAGE_SIZE	(1 << MLX4_EN_PAGE_SHIFT)
7397549c34SHans Petter Selasky #define	MLX4_NET_IP_ALIGN	2	/* bytes */
7497549c34SHans Petter Selasky #define DEF_RX_RINGS		16
7597549c34SHans Petter Selasky #define MAX_RX_RINGS		128
7697549c34SHans Petter Selasky #define MIN_RX_RINGS		4
7797549c34SHans Petter Selasky #define TXBB_SIZE		64
7897549c34SHans Petter Selasky #define HEADROOM		(2048 / TXBB_SIZE + 1)
79c3191c2eSHans Petter Selasky #define INIT_OWNER_BIT		0xffffffff
8097549c34SHans Petter Selasky #define STAMP_STRIDE		64
8197549c34SHans Petter Selasky #define STAMP_DWORDS		(STAMP_STRIDE / 4)
8297549c34SHans Petter Selasky #define STAMP_SHIFT		31
8397549c34SHans Petter Selasky #define STAMP_VAL		0x7fffffff
8497549c34SHans Petter Selasky #define STATS_DELAY		(HZ / 4)
8597549c34SHans Petter Selasky #define SERVICE_TASK_DELAY	(HZ / 4)
8697549c34SHans Petter Selasky #define MAX_NUM_OF_FS_RULES	256
8797549c34SHans Petter Selasky 
8897549c34SHans Petter Selasky #define MLX4_EN_FILTER_HASH_SHIFT 4
8997549c34SHans Petter Selasky #define MLX4_EN_FILTER_EXPIRY_QUOTA 60
9097549c34SHans Petter Selasky 
9197549c34SHans Petter Selasky #ifdef CONFIG_NET_RX_BUSY_POLL
9297549c34SHans Petter Selasky #define LL_EXTENDED_STATS
9397549c34SHans Petter Selasky #endif
9497549c34SHans Petter Selasky 
9597549c34SHans Petter Selasky /* vlan valid range */
9697549c34SHans Petter Selasky #define VLAN_MIN_VALUE		1
9797549c34SHans Petter Selasky #define VLAN_MAX_VALUE		4094
9897549c34SHans Petter Selasky 
9997549c34SHans Petter Selasky /*
10097549c34SHans Petter Selasky  * OS related constants and tunables
10197549c34SHans Petter Selasky  */
10297549c34SHans Petter Selasky 
10397549c34SHans Petter Selasky #define MLX4_EN_WATCHDOG_TIMEOUT	(15 * HZ)
10497549c34SHans Petter Selasky 
10597549c34SHans Petter Selasky #define MLX4_EN_ALLOC_SIZE     PAGE_ALIGN(PAGE_SIZE)
10697549c34SHans Petter Selasky #define MLX4_EN_ALLOC_ORDER    get_order(MLX4_EN_ALLOC_SIZE)
10797549c34SHans Petter Selasky 
10897549c34SHans Petter Selasky enum mlx4_en_alloc_type {
10997549c34SHans Petter Selasky 	MLX4_EN_ALLOC_NEW = 0,
11097549c34SHans Petter Selasky 	MLX4_EN_ALLOC_REPLACEMENT = 1,
11197549c34SHans Petter Selasky };
11297549c34SHans Petter Selasky 
11397549c34SHans Petter Selasky /* Maximum ring sizes */
11497549c34SHans Petter Selasky #define MLX4_EN_DEF_TX_QUEUE_SIZE       4096
11597549c34SHans Petter Selasky 
11697549c34SHans Petter Selasky /* Minimum packet number till arming the CQ */
11797549c34SHans Petter Selasky #define MLX4_EN_MIN_RX_ARM	2048
11897549c34SHans Petter Selasky #define MLX4_EN_MIN_TX_ARM	2048
11997549c34SHans Petter Selasky 
12097549c34SHans Petter Selasky /* Maximum ring sizes */
12197549c34SHans Petter Selasky #define MLX4_EN_MAX_TX_SIZE	8192
12297549c34SHans Petter Selasky #define MLX4_EN_MAX_RX_SIZE	8192
12397549c34SHans Petter Selasky 
12497549c34SHans Petter Selasky /* Minimum ring sizes */
12597549c34SHans Petter Selasky #define MLX4_EN_MIN_RX_SIZE	(4096 / TXBB_SIZE)
12697549c34SHans Petter Selasky #define MLX4_EN_MIN_TX_SIZE	(4096 / TXBB_SIZE)
12797549c34SHans Petter Selasky 
12897549c34SHans Petter Selasky #define MLX4_EN_SMALL_PKT_SIZE		64
12997549c34SHans Petter Selasky 
13097549c34SHans Petter Selasky #define MLX4_EN_MAX_TX_RING_P_UP	32
13197549c34SHans Petter Selasky #define MLX4_EN_NUM_UP			1
13297549c34SHans Petter Selasky 
13397549c34SHans Petter Selasky #define MAX_TX_RINGS			(MLX4_EN_MAX_TX_RING_P_UP * \
13497549c34SHans Petter Selasky 					MLX4_EN_NUM_UP)
13597549c34SHans Petter Selasky 
136c3191c2eSHans Petter Selasky #define MLX4_EN_NO_VLAN			0xffff
137c3191c2eSHans Petter Selasky 
13897549c34SHans Petter Selasky #define MLX4_EN_DEF_TX_RING_SIZE	1024
13997549c34SHans Petter Selasky #define MLX4_EN_DEF_RX_RING_SIZE  	1024
14097549c34SHans Petter Selasky 
14197549c34SHans Petter Selasky /* Target number of bytes to coalesce with interrupt moderation */
142c3191c2eSHans Petter Selasky #define MLX4_EN_RX_COAL_TARGET	44
14397549c34SHans Petter Selasky #define MLX4_EN_RX_COAL_TIME	0x10
14497549c34SHans Petter Selasky 
14597549c34SHans Petter Selasky #define MLX4_EN_TX_COAL_PKTS	64
14697549c34SHans Petter Selasky #define MLX4_EN_TX_COAL_TIME	64
14797549c34SHans Petter Selasky 
14897549c34SHans Petter Selasky #define MLX4_EN_RX_RATE_LOW		400000
14997549c34SHans Petter Selasky #define MLX4_EN_RX_COAL_TIME_LOW	0
15097549c34SHans Petter Selasky #define MLX4_EN_RX_RATE_HIGH		450000
15197549c34SHans Petter Selasky #define MLX4_EN_RX_COAL_TIME_HIGH	128
15297549c34SHans Petter Selasky #define MLX4_EN_RX_SIZE_THRESH		1024
15397549c34SHans Petter Selasky #define MLX4_EN_RX_RATE_THRESH		(1000000 / MLX4_EN_RX_COAL_TIME_HIGH)
15497549c34SHans Petter Selasky #define MLX4_EN_SAMPLE_INTERVAL		0
15597549c34SHans Petter Selasky #define MLX4_EN_AVG_PKT_SMALL		256
15697549c34SHans Petter Selasky 
15797549c34SHans Petter Selasky #define MLX4_EN_AUTO_CONF	0xffff
15897549c34SHans Petter Selasky 
15997549c34SHans Petter Selasky #define MLX4_EN_DEF_RX_PAUSE	1
16097549c34SHans Petter Selasky #define MLX4_EN_DEF_TX_PAUSE	1
16197549c34SHans Petter Selasky 
16297549c34SHans Petter Selasky /* Interval between successive polls in the Tx routine when polling is used
16397549c34SHans Petter Selasky    instead of interrupts (in per-core Tx rings) - should be power of 2 */
16497549c34SHans Petter Selasky #define MLX4_EN_TX_POLL_MODER	16
16597549c34SHans Petter Selasky #define MLX4_EN_TX_POLL_TIMEOUT	(HZ / 4)
16697549c34SHans Petter Selasky 
16797549c34SHans Petter Selasky #define MLX4_EN_64_ALIGN	(64 - NET_SKB_PAD)
16897549c34SHans Petter Selasky #define SMALL_PACKET_SIZE      (256 - NET_IP_ALIGN)
16997549c34SHans Petter Selasky #define HEADER_COPY_SIZE       (128)
17097549c34SHans Petter Selasky #define MLX4_LOOPBACK_TEST_PAYLOAD (HEADER_COPY_SIZE - ETHER_HDR_LEN)
17197549c34SHans Petter Selasky 
17297549c34SHans Petter Selasky #define MLX4_EN_MIN_MTU		46
17397549c34SHans Petter Selasky #define ETH_BCAST		0xffffffffffffULL
17497549c34SHans Petter Selasky 
17597549c34SHans Petter Selasky #define MLX4_EN_LOOPBACK_RETRIES	5
17697549c34SHans Petter Selasky #define MLX4_EN_LOOPBACK_TIMEOUT	100
17797549c34SHans Petter Selasky 
17897549c34SHans Petter Selasky #ifdef MLX4_EN_PERF_STAT
17997549c34SHans Petter Selasky /* Number of samples to 'average' */
18097549c34SHans Petter Selasky #define AVG_SIZE			128
18197549c34SHans Petter Selasky #define AVG_FACTOR			1024
18297549c34SHans Petter Selasky 
18397549c34SHans Petter Selasky #define INC_PERF_COUNTER(cnt)		(++(cnt))
18497549c34SHans Petter Selasky #define ADD_PERF_COUNTER(cnt, add)	((cnt) += (add))
18597549c34SHans Petter Selasky #define AVG_PERF_COUNTER(cnt, sample) \
18697549c34SHans Petter Selasky 	((cnt) = ((cnt) * (AVG_SIZE - 1) + (sample) * AVG_FACTOR) / AVG_SIZE)
18797549c34SHans Petter Selasky #define GET_PERF_COUNTER(cnt)		(cnt)
18897549c34SHans Petter Selasky #define GET_AVG_PERF_COUNTER(cnt)	((cnt) / AVG_FACTOR)
18997549c34SHans Petter Selasky 
19097549c34SHans Petter Selasky #else
19197549c34SHans Petter Selasky 
19297549c34SHans Petter Selasky #define INC_PERF_COUNTER(cnt)		do {} while (0)
19397549c34SHans Petter Selasky #define ADD_PERF_COUNTER(cnt, add)	do {} while (0)
19497549c34SHans Petter Selasky #define AVG_PERF_COUNTER(cnt, sample)	do {} while (0)
19597549c34SHans Petter Selasky #define GET_PERF_COUNTER(cnt)		(0)
19697549c34SHans Petter Selasky #define GET_AVG_PERF_COUNTER(cnt)	(0)
19797549c34SHans Petter Selasky #endif /* MLX4_EN_PERF_STAT */
19897549c34SHans Petter Selasky 
199c3191c2eSHans Petter Selasky /* Constants for TX flow */
200c3191c2eSHans Petter Selasky enum {
201c3191c2eSHans Petter Selasky 	MAX_INLINE = 104, /* 128 - 16 - 4 - 4 */
202c3191c2eSHans Petter Selasky 	MAX_BF = 256,
203c3191c2eSHans Petter Selasky 	MIN_PKT_LEN = 17,
204c3191c2eSHans Petter Selasky };
205c3191c2eSHans Petter Selasky 
20697549c34SHans Petter Selasky /*
20797549c34SHans Petter Selasky  * Configurables
20897549c34SHans Petter Selasky  */
20997549c34SHans Petter Selasky 
21097549c34SHans Petter Selasky enum cq_type {
21197549c34SHans Petter Selasky 	RX = 0,
21297549c34SHans Petter Selasky 	TX = 1,
21397549c34SHans Petter Selasky };
21497549c34SHans Petter Selasky 
21597549c34SHans Petter Selasky 
21697549c34SHans Petter Selasky /*
21797549c34SHans Petter Selasky  * Useful macros
21897549c34SHans Petter Selasky  */
21997549c34SHans Petter Selasky #define ROUNDUP_LOG2(x)		ilog2(roundup_pow_of_two(x))
22097549c34SHans Petter Selasky #define XNOR(x, y)		(!(x) == !(y))
22197549c34SHans Petter Selasky #define ILLEGAL_MAC(addr)	(addr == 0xffffffffffffULL || addr == 0x0)
22297549c34SHans Petter Selasky 
22397549c34SHans Petter Selasky struct mlx4_en_tx_info {
22497549c34SHans Petter Selasky 	bus_dmamap_t dma_map;
22597549c34SHans Petter Selasky         struct mbuf *mb;
22697549c34SHans Petter Selasky         u32 nr_txbb;
22797549c34SHans Petter Selasky 	u32 nr_bytes;
22897549c34SHans Petter Selasky };
22997549c34SHans Petter Selasky 
23097549c34SHans Petter Selasky 
23197549c34SHans Petter Selasky #define MLX4_EN_BIT_DESC_OWN	0x80000000
23297549c34SHans Petter Selasky #define CTRL_SIZE	sizeof(struct mlx4_wqe_ctrl_seg)
23397549c34SHans Petter Selasky #define MLX4_EN_MEMTYPE_PAD	0x100
23497549c34SHans Petter Selasky #define DS_SIZE		sizeof(struct mlx4_wqe_data_seg)
23597549c34SHans Petter Selasky 
23697549c34SHans Petter Selasky 
23797549c34SHans Petter Selasky struct mlx4_en_tx_desc {
23897549c34SHans Petter Selasky 	struct mlx4_wqe_ctrl_seg ctrl;
23997549c34SHans Petter Selasky 	union {
24097549c34SHans Petter Selasky 		struct mlx4_wqe_data_seg data; /* at least one data segment */
24197549c34SHans Petter Selasky 		struct mlx4_wqe_lso_seg lso;
24297549c34SHans Petter Selasky 		struct mlx4_wqe_inline_seg inl;
24397549c34SHans Petter Selasky 	};
24497549c34SHans Petter Selasky };
24597549c34SHans Petter Selasky 
24697549c34SHans Petter Selasky #define MLX4_EN_USE_SRQ		0x01000000
24797549c34SHans Petter Selasky 
24897549c34SHans Petter Selasky #define MLX4_EN_RX_BUDGET 64
24997549c34SHans Petter Selasky 
25097549c34SHans Petter Selasky #define	MLX4_EN_TX_MAX_DESC_SIZE 512	/* bytes */
25197549c34SHans Petter Selasky #define	MLX4_EN_TX_MAX_MBUF_SIZE 65536	/* bytes */
25297549c34SHans Petter Selasky #define	MLX4_EN_TX_MAX_PAYLOAD_SIZE 65536	/* bytes */
25397549c34SHans Petter Selasky #define	MLX4_EN_TX_MAX_MBUF_FRAGS \
25497549c34SHans Petter Selasky     ((MLX4_EN_TX_MAX_DESC_SIZE - 128) / DS_SIZE_ALIGNMENT) /* units */
25597549c34SHans Petter Selasky #define	MLX4_EN_TX_WQE_MAX_WQEBBS			\
25697549c34SHans Petter Selasky     (MLX4_EN_TX_MAX_DESC_SIZE / TXBB_SIZE) /* units */
25797549c34SHans Petter Selasky 
25897549c34SHans Petter Selasky #define MLX4_EN_CX3_LOW_ID	0x1000
25997549c34SHans Petter Selasky #define MLX4_EN_CX3_HIGH_ID	0x1005
26097549c34SHans Petter Selasky 
26197549c34SHans Petter Selasky struct mlx4_en_tx_ring {
26297549c34SHans Petter Selasky         spinlock_t tx_lock;
26397549c34SHans Petter Selasky 	bus_dma_tag_t dma_tag;
26497549c34SHans Petter Selasky 	struct mlx4_hwq_resources wqres;
26597549c34SHans Petter Selasky 	u32 size ; /* number of TXBBs */
26697549c34SHans Petter Selasky 	u32 size_mask;
26797549c34SHans Petter Selasky 	u16 stride;
26897549c34SHans Petter Selasky 	u16 cqn;	/* index of port CQ associated with this ring */
26997549c34SHans Petter Selasky 	u32 prod;
27097549c34SHans Petter Selasky 	u32 cons;
27197549c34SHans Petter Selasky 	u32 buf_size;
27297549c34SHans Petter Selasky 	u32 doorbell_qpn;
27397549c34SHans Petter Selasky 	u8 *buf;
27497549c34SHans Petter Selasky 	u16 poll_cnt;
27597549c34SHans Petter Selasky 	struct mlx4_en_tx_info *tx_info;
27697549c34SHans Petter Selasky 	u8 queue_index;
27797549c34SHans Petter Selasky 	u32 last_nr_txbb;
27897549c34SHans Petter Selasky 	struct mlx4_qp qp;
27997549c34SHans Petter Selasky 	struct mlx4_qp_context context;
28097549c34SHans Petter Selasky 	int qpn;
28197549c34SHans Petter Selasky 	enum mlx4_qp_state qp_state;
28297549c34SHans Petter Selasky 	struct mlx4_srq dummy;
283c3191c2eSHans Petter Selasky 	u64 bytes;
284c3191c2eSHans Petter Selasky 	u64 packets;
285c3191c2eSHans Petter Selasky 	u64 tx_csum;
286c3191c2eSHans Petter Selasky 	u64 queue_stopped;
287c3191c2eSHans Petter Selasky 	u64 oversized_packets;
288c3191c2eSHans Petter Selasky 	u64 wake_queue;
289c3191c2eSHans Petter Selasky 	u64 tso_packets;
290c3191c2eSHans Petter Selasky 	u64 defrag_attempts;
29197549c34SHans Petter Selasky 	struct mlx4_bf bf;
29297549c34SHans Petter Selasky 	bool bf_enabled;
29397549c34SHans Petter Selasky 	int hwtstamp_tx_type;
29497549c34SHans Petter Selasky 	spinlock_t comp_lock;
29597549c34SHans Petter Selasky 	int inline_thold;
29697549c34SHans Petter Selasky 	u64 watchdog_time;
29797549c34SHans Petter Selasky };
29897549c34SHans Petter Selasky 
29997549c34SHans Petter Selasky struct mlx4_en_rx_desc {
30097549c34SHans Petter Selasky 	/* actual number of entries depends on rx ring stride */
30197549c34SHans Petter Selasky 	struct mlx4_wqe_data_seg data[0];
30297549c34SHans Petter Selasky };
30397549c34SHans Petter Selasky 
30497549c34SHans Petter Selasky struct mlx4_en_rx_mbuf {
30597549c34SHans Petter Selasky 	bus_dmamap_t dma_map;
30697549c34SHans Petter Selasky 	struct mbuf *mbuf;
30797549c34SHans Petter Selasky };
30897549c34SHans Petter Selasky 
30997549c34SHans Petter Selasky struct mlx4_en_rx_spare {
31097549c34SHans Petter Selasky 	bus_dmamap_t dma_map;
31197549c34SHans Petter Selasky 	struct mbuf *mbuf;
31297549c34SHans Petter Selasky 	u64 paddr_be;
31397549c34SHans Petter Selasky };
31497549c34SHans Petter Selasky 
31597549c34SHans Petter Selasky struct mlx4_en_rx_ring {
31697549c34SHans Petter Selasky 	struct mlx4_hwq_resources wqres;
31797549c34SHans Petter Selasky 	bus_dma_tag_t dma_tag;
31897549c34SHans Petter Selasky 	struct mlx4_en_rx_spare spare;
31997549c34SHans Petter Selasky 	u32 size ;	/* number of Rx descs*/
32097549c34SHans Petter Selasky 	u32 actual_size;
32197549c34SHans Petter Selasky 	u32 size_mask;
32297549c34SHans Petter Selasky 	u16 stride;
32397549c34SHans Petter Selasky 	u16 log_stride;
32497549c34SHans Petter Selasky 	u16 cqn;	/* index of port CQ associated with this ring */
32597549c34SHans Petter Selasky 	u32 prod;
32697549c34SHans Petter Selasky 	u32 cons;
32797549c34SHans Petter Selasky 	u32 buf_size;
32897549c34SHans Petter Selasky 	u8  fcs_del;
32997549c34SHans Petter Selasky 	u32 rx_mb_size;
33097549c34SHans Petter Selasky 	int qpn;
33197549c34SHans Petter Selasky 	u8 *buf;
33297549c34SHans Petter Selasky 	struct mlx4_en_rx_mbuf *mbuf;
333c3191c2eSHans Petter Selasky 	u64 errors;
334c3191c2eSHans Petter Selasky 	u64 bytes;
335c3191c2eSHans Petter Selasky 	u64 packets;
33697549c34SHans Petter Selasky #ifdef LL_EXTENDED_STATS
337c3191c2eSHans Petter Selasky 	u64 yields;
338c3191c2eSHans Petter Selasky 	u64 misses;
339c3191c2eSHans Petter Selasky 	u64 cleaned;
34097549c34SHans Petter Selasky #endif
341c3191c2eSHans Petter Selasky 	u64 csum_ok;
342c3191c2eSHans Petter Selasky 	u64 csum_none;
34397549c34SHans Petter Selasky 	int hwtstamp_rx_filter;
34497549c34SHans Petter Selasky 	int numa_node;
34597549c34SHans Petter Selasky 	struct lro_ctrl lro;
34697549c34SHans Petter Selasky };
34797549c34SHans Petter Selasky 
34897549c34SHans Petter Selasky static inline int mlx4_en_can_lro(__be16 status)
34997549c34SHans Petter Selasky {
35097549c34SHans Petter Selasky 	const __be16 status_all = cpu_to_be16(
35197549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV4    |
35297549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV4F   |
35397549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV6    |
35497549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV4OPT |
35597549c34SHans Petter Selasky 			MLX4_CQE_STATUS_TCP     |
35697549c34SHans Petter Selasky 			MLX4_CQE_STATUS_UDP     |
35797549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPOK);
35897549c34SHans Petter Selasky 	const __be16 status_ipv4_ipok_tcp = cpu_to_be16(
35997549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV4    |
36097549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPOK    |
36197549c34SHans Petter Selasky 			MLX4_CQE_STATUS_TCP);
36297549c34SHans Petter Selasky 	const __be16 status_ipv6_ipok_tcp = cpu_to_be16(
36397549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV6    |
36497549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPOK    |
36597549c34SHans Petter Selasky 			MLX4_CQE_STATUS_TCP);
36697549c34SHans Petter Selasky 
36797549c34SHans Petter Selasky 	status &= status_all;
36897549c34SHans Petter Selasky 	return (status == status_ipv4_ipok_tcp ||
36997549c34SHans Petter Selasky 			status == status_ipv6_ipok_tcp);
37097549c34SHans Petter Selasky }
37197549c34SHans Petter Selasky 
37297549c34SHans Petter Selasky struct mlx4_en_cq {
37397549c34SHans Petter Selasky 	struct mlx4_cq          mcq;
37497549c34SHans Petter Selasky 	struct mlx4_hwq_resources wqres;
37597549c34SHans Petter Selasky 	int                     ring;
37697549c34SHans Petter Selasky 	spinlock_t              lock;
37797549c34SHans Petter Selasky 	struct net_device      *dev;
37897549c34SHans Petter Selasky         /* Per-core Tx cq processing support */
37997549c34SHans Petter Selasky         struct timer_list timer;
38097549c34SHans Petter Selasky 	int size;
38197549c34SHans Petter Selasky 	int buf_size;
38297549c34SHans Petter Selasky 	unsigned vector;
38397549c34SHans Petter Selasky 	enum cq_type is_tx;
38497549c34SHans Petter Selasky 	u16 moder_time;
38597549c34SHans Petter Selasky 	u16 moder_cnt;
38697549c34SHans Petter Selasky 	struct mlx4_cqe *buf;
38797549c34SHans Petter Selasky 	struct task cq_task;
38897549c34SHans Petter Selasky 	struct taskqueue *tq;
38997549c34SHans Petter Selasky #define MLX4_EN_OPCODE_ERROR	0x1e
39097549c34SHans Petter Selasky 	u32 tot_rx;
39197549c34SHans Petter Selasky 	u32 tot_tx;
39297549c34SHans Petter Selasky 	u32 curr_poll_rx_cpu_id;
39397549c34SHans Petter Selasky 
39497549c34SHans Petter Selasky #ifdef CONFIG_NET_RX_BUSY_POLL
39597549c34SHans Petter Selasky 	unsigned int state;
396c3191c2eSHans Petter Selasky #define MLX4_EN_CQ_STATE_IDLE        0
397c3191c2eSHans Petter Selasky #define MLX4_EN_CQ_STATE_NAPI     1    /* NAPI owns this CQ */
398c3191c2eSHans Petter Selasky #define MLX4_EN_CQ_STATE_POLL     2    /* poll owns this CQ */
399c3191c2eSHans Petter Selasky #define MLX4_CQ_LOCKED (MLX4_EN_CQ_STATE_NAPI | MLX4_EN_CQ_STATE_POLL)
400c3191c2eSHans Petter Selasky #define MLX4_EN_CQ_STATE_NAPI_YIELD  4    /* NAPI yielded this CQ */
401c3191c2eSHans Petter Selasky #define MLX4_EN_CQ_STATE_POLL_YIELD  8    /* poll yielded this CQ */
402c3191c2eSHans Petter Selasky #define CQ_YIELD (MLX4_EN_CQ_STATE_NAPI_YIELD | MLX4_EN_CQ_STATE_POLL_YIELD)
403c3191c2eSHans Petter Selasky #define CQ_USER_PEND (MLX4_EN_CQ_STATE_POLL | MLX4_EN_CQ_STATE_POLL_YIELD)
40497549c34SHans Petter Selasky 	spinlock_t poll_lock; /* protects from LLS/napi conflicts */
40597549c34SHans Petter Selasky #endif  /* CONFIG_NET_RX_BUSY_POLL */
40697549c34SHans Petter Selasky };
40797549c34SHans Petter Selasky 
40897549c34SHans Petter Selasky struct mlx4_en_port_profile {
40997549c34SHans Petter Selasky 	u32 flags;
41097549c34SHans Petter Selasky 	u32 tx_ring_num;
41197549c34SHans Petter Selasky 	u32 rx_ring_num;
41297549c34SHans Petter Selasky 	u32 tx_ring_size;
41397549c34SHans Petter Selasky 	u32 rx_ring_size;
41497549c34SHans Petter Selasky 	u8 rx_pause;
41597549c34SHans Petter Selasky 	u8 rx_ppp;
41697549c34SHans Petter Selasky 	u8 tx_pause;
41797549c34SHans Petter Selasky 	u8 tx_ppp;
41897549c34SHans Petter Selasky 	int rss_rings;
419c3191c2eSHans Petter Selasky 	int inline_thold;
42097549c34SHans Petter Selasky };
42197549c34SHans Petter Selasky 
42297549c34SHans Petter Selasky struct mlx4_en_profile {
42397549c34SHans Petter Selasky 	int rss_xor;
42497549c34SHans Petter Selasky 	int udp_rss;
42597549c34SHans Petter Selasky 	u8 rss_mask;
42697549c34SHans Petter Selasky 	u32 active_ports;
42797549c34SHans Petter Selasky 	u32 small_pkt_int;
42897549c34SHans Petter Selasky 	u8 no_reset;
42997549c34SHans Petter Selasky 	u8 num_tx_rings_p_up;
43097549c34SHans Petter Selasky 	struct mlx4_en_port_profile prof[MLX4_MAX_PORTS + 1];
43197549c34SHans Petter Selasky };
43297549c34SHans Petter Selasky 
43397549c34SHans Petter Selasky struct mlx4_en_dev {
43497549c34SHans Petter Selasky 	struct mlx4_dev		*dev;
43597549c34SHans Petter Selasky 	struct pci_dev		*pdev;
43697549c34SHans Petter Selasky 	struct mutex		state_lock;
43797549c34SHans Petter Selasky 	struct net_device	*pndev[MLX4_MAX_PORTS + 1];
43897549c34SHans Petter Selasky 	u32			port_cnt;
43997549c34SHans Petter Selasky 	bool			device_up;
44097549c34SHans Petter Selasky 	struct mlx4_en_profile	profile;
44197549c34SHans Petter Selasky 	u32			LSO_support;
44297549c34SHans Petter Selasky 	struct workqueue_struct *workqueue;
44397549c34SHans Petter Selasky 	struct device		*dma_device;
44497549c34SHans Petter Selasky 	void __iomem		*uar_map;
44597549c34SHans Petter Selasky 	struct mlx4_uar		priv_uar;
44697549c34SHans Petter Selasky 	struct mlx4_mr		mr;
44797549c34SHans Petter Selasky 	u32			priv_pdn;
44897549c34SHans Petter Selasky 	spinlock_t		uar_lock;
44997549c34SHans Petter Selasky 	u8			mac_removed[MLX4_MAX_PORTS + 1];
45097549c34SHans Petter Selasky 	unsigned long		last_overflow_check;
45197549c34SHans Petter Selasky 	unsigned long		overflow_period;
45297549c34SHans Petter Selasky };
45397549c34SHans Petter Selasky 
45497549c34SHans Petter Selasky 
45597549c34SHans Petter Selasky struct mlx4_en_rss_map {
45697549c34SHans Petter Selasky 	int base_qpn;
45797549c34SHans Petter Selasky 	struct mlx4_qp qps[MAX_RX_RINGS];
45897549c34SHans Petter Selasky 	enum mlx4_qp_state state[MAX_RX_RINGS];
45997549c34SHans Petter Selasky 	struct mlx4_qp indir_qp;
46097549c34SHans Petter Selasky 	enum mlx4_qp_state indir_state;
46197549c34SHans Petter Selasky };
46297549c34SHans Petter Selasky 
463c3191c2eSHans Petter Selasky enum mlx4_en_port_flag {
464c3191c2eSHans Petter Selasky 	MLX4_EN_PORT_ANC = 1<<0, /* Auto-negotiation complete */
465c3191c2eSHans Petter Selasky 	MLX4_EN_PORT_ANE = 1<<1, /* Auto-negotiation enabled */
466c3191c2eSHans Petter Selasky };
467c3191c2eSHans Petter Selasky 
46897549c34SHans Petter Selasky struct mlx4_en_port_state {
46997549c34SHans Petter Selasky 	int link_state;
47097549c34SHans Petter Selasky 	int link_speed;
471c3191c2eSHans Petter Selasky 	int transceiver;
472c3191c2eSHans Petter Selasky 	u32 flags;
47397549c34SHans Petter Selasky };
47497549c34SHans Petter Selasky 
475c3191c2eSHans Petter Selasky enum mlx4_en_addr_list_act {
476c3191c2eSHans Petter Selasky 	MLX4_ADDR_LIST_NONE,
477c3191c2eSHans Petter Selasky 	MLX4_ADDR_LIST_REM,
478c3191c2eSHans Petter Selasky 	MLX4_ADDR_LIST_ADD,
47997549c34SHans Petter Selasky };
48097549c34SHans Petter Selasky 
481c3191c2eSHans Petter Selasky struct mlx4_en_addr_list {
48297549c34SHans Petter Selasky 	struct list_head	list;
483c3191c2eSHans Petter Selasky 	enum mlx4_en_addr_list_act	action;
48497549c34SHans Petter Selasky 	u8			addr[ETH_ALEN];
48597549c34SHans Petter Selasky 	u64			reg_id;
486c3191c2eSHans Petter Selasky 	u64			tunnel_reg_id;
48797549c34SHans Petter Selasky };
48897549c34SHans Petter Selasky 
48997549c34SHans Petter Selasky #ifdef CONFIG_MLX4_EN_DCB
49097549c34SHans Petter Selasky /* Minimal TC BW - setting to 0 will block traffic */
49197549c34SHans Petter Selasky #define MLX4_EN_BW_MIN 1
49297549c34SHans Petter Selasky #define MLX4_EN_BW_MAX 100 /* Utilize 100% of the line */
49397549c34SHans Petter Selasky 
494c3191c2eSHans Petter Selasky #define MLX4_EN_TC_VENDOR 0
49597549c34SHans Petter Selasky #define MLX4_EN_TC_ETS 7
49697549c34SHans Petter Selasky 
49797549c34SHans Petter Selasky #endif
49897549c34SHans Petter Selasky 
49997549c34SHans Petter Selasky 
50097549c34SHans Petter Selasky enum {
50197549c34SHans Petter Selasky 	MLX4_EN_FLAG_PROMISC		= (1 << 0),
50297549c34SHans Petter Selasky 	MLX4_EN_FLAG_MC_PROMISC		= (1 << 1),
50397549c34SHans Petter Selasky 	/* whether we need to enable hardware loopback by putting dmac
50497549c34SHans Petter Selasky 	 * in Tx WQE
50597549c34SHans Petter Selasky 	 */
50697549c34SHans Petter Selasky 	MLX4_EN_FLAG_ENABLE_HW_LOOPBACK	= (1 << 2),
50797549c34SHans Petter Selasky 	/* whether we need to drop packets that hardware loopback-ed */
50897549c34SHans Petter Selasky 	MLX4_EN_FLAG_RX_FILTER_NEEDED	= (1 << 3),
50997549c34SHans Petter Selasky 	MLX4_EN_FLAG_FORCE_PROMISC	= (1 << 4),
51097549c34SHans Petter Selasky #ifdef CONFIG_MLX4_EN_DCB
51197549c34SHans Petter Selasky 	MLX4_EN_FLAG_DCB_ENABLED	= (1 << 5)
51297549c34SHans Petter Selasky #endif
51397549c34SHans Petter Selasky };
51497549c34SHans Petter Selasky 
51597549c34SHans Petter Selasky #define MLX4_EN_MAC_HASH_SIZE (1 << BITS_PER_BYTE)
51697549c34SHans Petter Selasky #define MLX4_EN_MAC_HASH_IDX 5
51797549c34SHans Petter Selasky 
51897549c34SHans Petter Selasky struct en_port {
51997549c34SHans Petter Selasky 	struct kobject		kobj;
52097549c34SHans Petter Selasky 	struct mlx4_dev		*dev;
52197549c34SHans Petter Selasky 	u8			port_num;
52297549c34SHans Petter Selasky 	u8			vport_num;
52397549c34SHans Petter Selasky };
52497549c34SHans Petter Selasky 
52597549c34SHans Petter Selasky struct mlx4_en_priv {
52697549c34SHans Petter Selasky 	struct mlx4_en_dev *mdev;
52797549c34SHans Petter Selasky 	struct mlx4_en_port_profile *prof;
52897549c34SHans Petter Selasky 	struct net_device *dev;
52997549c34SHans Petter Selasky 	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
53097549c34SHans Petter Selasky 	struct mlx4_en_port_state port_state;
53197549c34SHans Petter Selasky 	spinlock_t stats_lock;
53297549c34SHans Petter Selasky 	/* To allow rules removal while port is going down */
53397549c34SHans Petter Selasky 	struct list_head ethtool_list;
53497549c34SHans Petter Selasky 
53597549c34SHans Petter Selasky 	unsigned long last_moder_packets[MAX_RX_RINGS];
53697549c34SHans Petter Selasky 	unsigned long last_moder_tx_packets;
53797549c34SHans Petter Selasky 	unsigned long last_moder_bytes[MAX_RX_RINGS];
53897549c34SHans Petter Selasky 	unsigned long last_moder_jiffies;
53997549c34SHans Petter Selasky 	int last_moder_time[MAX_RX_RINGS];
54097549c34SHans Petter Selasky 	u16 rx_usecs;
54197549c34SHans Petter Selasky 	u16 rx_frames;
54297549c34SHans Petter Selasky 	u16 tx_usecs;
54397549c34SHans Petter Selasky 	u16 tx_frames;
54497549c34SHans Petter Selasky 	u32 pkt_rate_low;
54597549c34SHans Petter Selasky 	u32 rx_usecs_low;
54697549c34SHans Petter Selasky 	u32 pkt_rate_high;
54797549c34SHans Petter Selasky 	u32 rx_usecs_high;
54897549c34SHans Petter Selasky 	u32 sample_interval;
54997549c34SHans Petter Selasky 	u32 adaptive_rx_coal;
55097549c34SHans Petter Selasky 	u32 msg_enable;
55197549c34SHans Petter Selasky 	u32 loopback_ok;
55297549c34SHans Petter Selasky 	u32 validate_loopback;
55397549c34SHans Petter Selasky 
55497549c34SHans Petter Selasky 	struct mlx4_hwq_resources res;
55597549c34SHans Petter Selasky 	int link_state;
55697549c34SHans Petter Selasky 	int last_link_state;
55797549c34SHans Petter Selasky 	bool port_up;
55897549c34SHans Petter Selasky 	int port;
55997549c34SHans Petter Selasky 	int registered;
560c3191c2eSHans Petter Selasky 	int gone;
56197549c34SHans Petter Selasky 	int allocated;
56297549c34SHans Petter Selasky 	int stride;
56397549c34SHans Petter Selasky 	unsigned char current_mac[ETH_ALEN + 2];
56497549c34SHans Petter Selasky         u64 mac;
56597549c34SHans Petter Selasky 	int mac_index;
56697549c34SHans Petter Selasky 	unsigned max_mtu;
56797549c34SHans Petter Selasky 	int base_qpn;
56897549c34SHans Petter Selasky 	int cqe_factor;
56997549c34SHans Petter Selasky 
57097549c34SHans Petter Selasky 	struct mlx4_en_rss_map rss_map;
57197549c34SHans Petter Selasky 	u32 flags;
57297549c34SHans Petter Selasky 	u8 num_tx_rings_p_up;
57397549c34SHans Petter Selasky 	u32 tx_ring_num;
57497549c34SHans Petter Selasky 	u32 rx_ring_num;
57597549c34SHans Petter Selasky 	u32 rx_mb_size;
57697549c34SHans Petter Selasky 
57797549c34SHans Petter Selasky 	struct mlx4_en_tx_ring **tx_ring;
57897549c34SHans Petter Selasky 	struct mlx4_en_rx_ring *rx_ring[MAX_RX_RINGS];
57997549c34SHans Petter Selasky 	struct mlx4_en_cq **tx_cq;
58097549c34SHans Petter Selasky 	struct mlx4_en_cq *rx_cq[MAX_RX_RINGS];
58197549c34SHans Petter Selasky 	struct mlx4_qp drop_qp;
58297549c34SHans Petter Selasky 	struct work_struct rx_mode_task;
58397549c34SHans Petter Selasky 	struct work_struct watchdog_task;
58497549c34SHans Petter Selasky 	struct work_struct linkstate_task;
58597549c34SHans Petter Selasky 	struct delayed_work stats_task;
58697549c34SHans Petter Selasky 	struct delayed_work service_task;
58797549c34SHans Petter Selasky 	struct mlx4_en_perf_stats pstats;
58897549c34SHans Petter Selasky 	struct mlx4_en_pkt_stats pkstats;
58997549c34SHans Petter Selasky 	struct mlx4_en_pkt_stats pkstats_last;
590c3191c2eSHans Petter Selasky 	struct mlx4_en_flow_stats_rx rx_priority_flowstats[MLX4_NUM_PRIORITIES];
591c3191c2eSHans Petter Selasky 	struct mlx4_en_flow_stats_tx tx_priority_flowstats[MLX4_NUM_PRIORITIES];
592c3191c2eSHans Petter Selasky 	struct mlx4_en_flow_stats_rx rx_flowstats;
593c3191c2eSHans Petter Selasky 	struct mlx4_en_flow_stats_tx tx_flowstats;
59497549c34SHans Petter Selasky 	struct mlx4_en_port_stats port_stats;
59597549c34SHans Petter Selasky 	struct mlx4_en_vport_stats vport_stats;
59697549c34SHans Petter Selasky 	struct mlx4_en_vf_stats vf_stats;
59797549c34SHans Petter Selasky 	struct list_head mc_list;
598c3191c2eSHans Petter Selasky 	struct list_head uc_list;
599c3191c2eSHans Petter Selasky 	struct list_head curr_mc_list;
600c3191c2eSHans Petter Selasky 	struct list_head curr_uc_list;
60197549c34SHans Petter Selasky 	u64 broadcast_id;
60297549c34SHans Petter Selasky 	struct mlx4_en_stat_out_mbox hw_stats;
60397549c34SHans Petter Selasky 	int vids[128];
60497549c34SHans Petter Selasky 	bool wol;
60597549c34SHans Petter Selasky 	struct device *ddev;
60697549c34SHans Petter Selasky 	struct dentry *dev_root;
60797549c34SHans Petter Selasky 	u32 counter_index;
60897549c34SHans Petter Selasky 	eventhandler_tag vlan_attach;
60997549c34SHans Petter Selasky 	eventhandler_tag vlan_detach;
61097549c34SHans Petter Selasky 	struct callout watchdog_timer;
61197549c34SHans Petter Selasky         struct ifmedia media;
61297549c34SHans Petter Selasky 	volatile int blocked;
613791c9d78SHans Petter Selasky 	struct sysctl_oid *conf_sysctl;
614791c9d78SHans Petter Selasky 	struct sysctl_oid *stat_sysctl;
61597549c34SHans Petter Selasky 	struct sysctl_ctx_list conf_ctx;
61697549c34SHans Petter Selasky 	struct sysctl_ctx_list stat_ctx;
61797549c34SHans Petter Selasky 
61897549c34SHans Petter Selasky #ifdef CONFIG_MLX4_EN_DCB
61997549c34SHans Petter Selasky 	struct ieee_ets ets;
62097549c34SHans Petter Selasky 	u16 maxrate[IEEE_8021QAZ_MAX_TCS];
62197549c34SHans Petter Selasky 	u8 dcbx_cap;
62297549c34SHans Petter Selasky #endif
62397549c34SHans Petter Selasky #ifdef CONFIG_RFS_ACCEL
62497549c34SHans Petter Selasky 	spinlock_t filters_lock;
62597549c34SHans Petter Selasky 	int last_filter_id;
62697549c34SHans Petter Selasky 	struct list_head filters;
62797549c34SHans Petter Selasky 	struct hlist_head filter_hash[1 << MLX4_EN_FILTER_HASH_SHIFT];
62897549c34SHans Petter Selasky #endif
629c3191c2eSHans Petter Selasky 	u64 tunnel_reg_id;
63097549c34SHans Petter Selasky 	struct en_port *vf_ports[MLX4_MAX_NUM_VF];
63197549c34SHans Petter Selasky 	unsigned long last_ifq_jiffies;
63297549c34SHans Petter Selasky 	u64 if_counters_rx_errors;
63397549c34SHans Petter Selasky 	u64 if_counters_rx_no_buffer;
63497549c34SHans Petter Selasky };
63597549c34SHans Petter Selasky 
63697549c34SHans Petter Selasky enum mlx4_en_wol {
63797549c34SHans Petter Selasky 	MLX4_EN_WOL_MAGIC = (1ULL << 61),
63897549c34SHans Petter Selasky 	MLX4_EN_WOL_ENABLED = (1ULL << 62),
63997549c34SHans Petter Selasky };
64097549c34SHans Petter Selasky 
64197549c34SHans Petter Selasky struct mlx4_mac_entry {
64297549c34SHans Petter Selasky 	struct hlist_node hlist;
64397549c34SHans Petter Selasky 	unsigned char mac[ETH_ALEN + 2];
64497549c34SHans Petter Selasky 	u64 reg_id;
64597549c34SHans Petter Selasky };
64697549c34SHans Petter Selasky 
647c3191c2eSHans Petter Selasky static inline struct mlx4_cqe *mlx4_en_get_cqe(u8 *buf, int idx, int cqe_sz)
648c3191c2eSHans Petter Selasky {
649c3191c2eSHans Petter Selasky 	return (struct mlx4_cqe *)(buf + idx * cqe_sz);
650c3191c2eSHans Petter Selasky }
651c3191c2eSHans Petter Selasky 
65297549c34SHans Petter Selasky #ifdef CONFIG_NET_RX_BUSY_POLL
65397549c34SHans Petter Selasky static inline void mlx4_en_cq_init_lock(struct mlx4_en_cq *cq)
65497549c34SHans Petter Selasky {
65597549c34SHans Petter Selasky 	spin_lock_init(&cq->poll_lock);
656c3191c2eSHans Petter Selasky 	cq->state = MLX4_EN_CQ_STATE_IDLE;
65797549c34SHans Petter Selasky }
65897549c34SHans Petter Selasky 
65997549c34SHans Petter Selasky /* called from the device poll rutine to get ownership of a cq */
66097549c34SHans Petter Selasky static inline bool mlx4_en_cq_lock_napi(struct mlx4_en_cq *cq)
66197549c34SHans Petter Selasky {
66297549c34SHans Petter Selasky 	int rc = true;
66397549c34SHans Petter Selasky 	spin_lock(&cq->poll_lock);
66497549c34SHans Petter Selasky 	if (cq->state & MLX4_CQ_LOCKED) {
665c3191c2eSHans Petter Selasky 		WARN_ON(cq->state & MLX4_EN_CQ_STATE_NAPI);
666c3191c2eSHans Petter Selasky 		cq->state |= MLX4_EN_CQ_STATE_NAPI_YIELD;
66797549c34SHans Petter Selasky 		rc = false;
66897549c34SHans Petter Selasky 	} else
66997549c34SHans Petter Selasky 		/* we don't care if someone yielded */
670c3191c2eSHans Petter Selasky 		cq->state = MLX4_EN_CQ_STATE_NAPI;
67197549c34SHans Petter Selasky 	spin_unlock(&cq->poll_lock);
67297549c34SHans Petter Selasky 	return rc;
67397549c34SHans Petter Selasky }
67497549c34SHans Petter Selasky 
67597549c34SHans Petter Selasky /* returns true is someone tried to get the cq while napi had it */
67697549c34SHans Petter Selasky static inline bool mlx4_en_cq_unlock_napi(struct mlx4_en_cq *cq)
67797549c34SHans Petter Selasky {
67897549c34SHans Petter Selasky 	int rc = false;
67997549c34SHans Petter Selasky 	spin_lock(&cq->poll_lock);
680c3191c2eSHans Petter Selasky 	WARN_ON(cq->state & (MLX4_EN_CQ_STATE_POLL |
681c3191c2eSHans Petter Selasky 			       MLX4_EN_CQ_STATE_NAPI_YIELD));
68297549c34SHans Petter Selasky 
683c3191c2eSHans Petter Selasky 	if (cq->state & MLX4_EN_CQ_STATE_POLL_YIELD)
68497549c34SHans Petter Selasky 		rc = true;
685c3191c2eSHans Petter Selasky 	cq->state = MLX4_EN_CQ_STATE_IDLE;
68697549c34SHans Petter Selasky 	spin_unlock(&cq->poll_lock);
68797549c34SHans Petter Selasky 	return rc;
68897549c34SHans Petter Selasky }
68997549c34SHans Petter Selasky 
69097549c34SHans Petter Selasky /* called from mlx4_en_low_latency_poll() */
69197549c34SHans Petter Selasky static inline bool mlx4_en_cq_lock_poll(struct mlx4_en_cq *cq)
69297549c34SHans Petter Selasky {
69397549c34SHans Petter Selasky 	int rc = true;
69497549c34SHans Petter Selasky 	spin_lock_bh(&cq->poll_lock);
69597549c34SHans Petter Selasky 	if ((cq->state & MLX4_CQ_LOCKED)) {
69697549c34SHans Petter Selasky 		struct net_device *dev = cq->dev;
69797549c34SHans Petter Selasky 		struct mlx4_en_priv *priv = netdev_priv(dev);
69897549c34SHans Petter Selasky 		struct mlx4_en_rx_ring *rx_ring = priv->rx_ring[cq->ring];
69997549c34SHans Petter Selasky 
700c3191c2eSHans Petter Selasky 		cq->state |= MLX4_EN_CQ_STATE_POLL_YIELD;
70197549c34SHans Petter Selasky 		rc = false;
70297549c34SHans Petter Selasky #ifdef LL_EXTENDED_STATS
70397549c34SHans Petter Selasky 		rx_ring->yields++;
70497549c34SHans Petter Selasky #endif
70597549c34SHans Petter Selasky 	} else
70697549c34SHans Petter Selasky 		/* preserve yield marks */
707c3191c2eSHans Petter Selasky 		cq->state |= MLX4_EN_CQ_STATE_POLL;
70897549c34SHans Petter Selasky 	spin_unlock_bh(&cq->poll_lock);
70997549c34SHans Petter Selasky 	return rc;
71097549c34SHans Petter Selasky }
71197549c34SHans Petter Selasky 
71297549c34SHans Petter Selasky /* returns true if someone tried to get the cq while it was locked */
71397549c34SHans Petter Selasky static inline bool mlx4_en_cq_unlock_poll(struct mlx4_en_cq *cq)
71497549c34SHans Petter Selasky {
71597549c34SHans Petter Selasky 	int rc = false;
71697549c34SHans Petter Selasky 	spin_lock_bh(&cq->poll_lock);
717c3191c2eSHans Petter Selasky 	WARN_ON(cq->state & (MLX4_EN_CQ_STATE_NAPI));
71897549c34SHans Petter Selasky 
719c3191c2eSHans Petter Selasky 	if (cq->state & MLX4_EN_CQ_STATE_POLL_YIELD)
72097549c34SHans Petter Selasky 		rc = true;
721c3191c2eSHans Petter Selasky 	cq->state = MLX4_EN_CQ_STATE_IDLE;
72297549c34SHans Petter Selasky 	spin_unlock_bh(&cq->poll_lock);
72397549c34SHans Petter Selasky 	return rc;
72497549c34SHans Petter Selasky }
72597549c34SHans Petter Selasky 
72697549c34SHans Petter Selasky /* true if a socket is polling, even if it did not get the lock */
727c3191c2eSHans Petter Selasky static inline bool mlx4_en_cq_busy_polling(struct mlx4_en_cq *cq)
72897549c34SHans Petter Selasky {
72997549c34SHans Petter Selasky 	WARN_ON(!(cq->state & MLX4_CQ_LOCKED));
73097549c34SHans Petter Selasky 	return cq->state & CQ_USER_PEND;
73197549c34SHans Petter Selasky }
73297549c34SHans Petter Selasky #else
73397549c34SHans Petter Selasky static inline void mlx4_en_cq_init_lock(struct mlx4_en_cq *cq)
73497549c34SHans Petter Selasky {
73597549c34SHans Petter Selasky }
73697549c34SHans Petter Selasky 
73797549c34SHans Petter Selasky static inline bool mlx4_en_cq_lock_napi(struct mlx4_en_cq *cq)
73897549c34SHans Petter Selasky {
73997549c34SHans Petter Selasky 	return true;
74097549c34SHans Petter Selasky }
74197549c34SHans Petter Selasky 
74297549c34SHans Petter Selasky static inline bool mlx4_en_cq_unlock_napi(struct mlx4_en_cq *cq)
74397549c34SHans Petter Selasky {
74497549c34SHans Petter Selasky 	return false;
74597549c34SHans Petter Selasky }
74697549c34SHans Petter Selasky 
74797549c34SHans Petter Selasky static inline bool mlx4_en_cq_lock_poll(struct mlx4_en_cq *cq)
74897549c34SHans Petter Selasky {
74997549c34SHans Petter Selasky 	return false;
75097549c34SHans Petter Selasky }
75197549c34SHans Petter Selasky 
75297549c34SHans Petter Selasky static inline bool mlx4_en_cq_unlock_poll(struct mlx4_en_cq *cq)
75397549c34SHans Petter Selasky {
75497549c34SHans Petter Selasky 	return false;
75597549c34SHans Petter Selasky }
75697549c34SHans Petter Selasky 
757c3191c2eSHans Petter Selasky static inline bool mlx4_en_cq_busy_polling(struct mlx4_en_cq *cq)
75897549c34SHans Petter Selasky {
75997549c34SHans Petter Selasky 	return false;
76097549c34SHans Petter Selasky }
76197549c34SHans Petter Selasky #endif /* CONFIG_NET_RX_BUSY_POLL */
76297549c34SHans Petter Selasky 
76397549c34SHans Petter Selasky #define MLX4_EN_WOL_DO_MODIFY (1ULL << 63)
76497549c34SHans Petter Selasky 
76597549c34SHans Petter Selasky void mlx4_en_destroy_netdev(struct net_device *dev);
76697549c34SHans Petter Selasky int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
76797549c34SHans Petter Selasky 			struct mlx4_en_port_profile *prof);
76897549c34SHans Petter Selasky 
76997549c34SHans Petter Selasky int mlx4_en_start_port(struct net_device *dev);
77097549c34SHans Petter Selasky void mlx4_en_stop_port(struct net_device *dev);
77197549c34SHans Petter Selasky 
77297549c34SHans Petter Selasky void mlx4_en_free_resources(struct mlx4_en_priv *priv);
77397549c34SHans Petter Selasky int mlx4_en_alloc_resources(struct mlx4_en_priv *priv);
77497549c34SHans Petter Selasky 
77597549c34SHans Petter Selasky int mlx4_en_pre_config(struct mlx4_en_priv *priv);
77697549c34SHans Petter Selasky int mlx4_en_create_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq,
77797549c34SHans Petter Selasky 		      int entries, int ring, enum cq_type mode, int node);
77897549c34SHans Petter Selasky void mlx4_en_destroy_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq);
77997549c34SHans Petter Selasky int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,
78097549c34SHans Petter Selasky 			int cq_idx);
78197549c34SHans Petter Selasky void mlx4_en_deactivate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
78297549c34SHans Petter Selasky int mlx4_en_set_cq_moder(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
78397549c34SHans Petter Selasky int mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
78497549c34SHans Petter Selasky 
78597549c34SHans Petter Selasky void mlx4_en_tx_irq(struct mlx4_cq *mcq);
78697549c34SHans Petter Selasky u16 mlx4_en_select_queue(struct net_device *dev, struct mbuf *mb);
78797549c34SHans Petter Selasky 
788*63d7a8d9SSlava Shwartsman int mlx4_en_xmit(struct mlx4_en_priv *priv, int tx_ind, struct mbuf **mbp);
78997549c34SHans Petter Selasky int mlx4_en_transmit(struct ifnet *dev, struct mbuf *m);
79097549c34SHans Petter Selasky int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
79197549c34SHans Petter Selasky 			   struct mlx4_en_tx_ring **pring,
79297549c34SHans Petter Selasky 			   u32 size, u16 stride, int node, int queue_idx);
79397549c34SHans Petter Selasky void mlx4_en_destroy_tx_ring(struct mlx4_en_priv *priv,
79497549c34SHans Petter Selasky 			     struct mlx4_en_tx_ring **pring);
79597549c34SHans Petter Selasky int mlx4_en_activate_tx_ring(struct mlx4_en_priv *priv,
79697549c34SHans Petter Selasky 			     struct mlx4_en_tx_ring *ring,
79797549c34SHans Petter Selasky 			     int cq, int user_prio);
79897549c34SHans Petter Selasky void mlx4_en_deactivate_tx_ring(struct mlx4_en_priv *priv,
79997549c34SHans Petter Selasky 				struct mlx4_en_tx_ring *ring);
800c3191c2eSHans Petter Selasky void mlx4_en_set_num_rx_rings(struct mlx4_en_dev *mdev);
80197549c34SHans Petter Selasky void mlx4_en_qflush(struct ifnet *dev);
80297549c34SHans Petter Selasky 
80397549c34SHans Petter Selasky int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv,
80497549c34SHans Petter Selasky 			   struct mlx4_en_rx_ring **pring,
80597549c34SHans Petter Selasky 			   u32 size, int node);
80697549c34SHans Petter Selasky void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv,
80797549c34SHans Petter Selasky 			     struct mlx4_en_rx_ring **pring,
80897549c34SHans Petter Selasky 			     u32 size, u16 stride);
80997549c34SHans Petter Selasky void mlx4_en_rx_que(void *context, int pending);
81097549c34SHans Petter Selasky int mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv);
81197549c34SHans Petter Selasky void mlx4_en_deactivate_rx_ring(struct mlx4_en_priv *priv,
81297549c34SHans Petter Selasky 				struct mlx4_en_rx_ring *ring);
81397549c34SHans Petter Selasky int mlx4_en_process_rx_cq(struct net_device *dev,
81497549c34SHans Petter Selasky 			  struct mlx4_en_cq *cq,
81597549c34SHans Petter Selasky 			  int budget);
81697549c34SHans Petter Selasky void mlx4_en_poll_tx_cq(unsigned long data);
81797549c34SHans Petter Selasky void mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
81897549c34SHans Petter Selasky 		int is_tx, int rss, int qpn, int cqn, int user_prio,
81997549c34SHans Petter Selasky 		struct mlx4_qp_context *context);
82097549c34SHans Petter Selasky void mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event);
82197549c34SHans Petter Selasky int mlx4_en_map_buffer(struct mlx4_buf *buf);
82297549c34SHans Petter Selasky void mlx4_en_unmap_buffer(struct mlx4_buf *buf);
82397549c34SHans Petter Selasky void mlx4_en_calc_rx_buf(struct net_device *dev);
82497549c34SHans Petter Selasky 
82529d6b8abSHans Petter Selasky const u32 *mlx4_en_get_rss_key(struct mlx4_en_priv *priv, u16 *keylen);
82629d6b8abSHans Petter Selasky u8 mlx4_en_get_rss_mask(struct mlx4_en_priv *priv);
82797549c34SHans Petter Selasky int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv);
82897549c34SHans Petter Selasky void mlx4_en_release_rss_steer(struct mlx4_en_priv *priv);
82997549c34SHans Petter Selasky int mlx4_en_create_drop_qp(struct mlx4_en_priv *priv);
83097549c34SHans Petter Selasky void mlx4_en_destroy_drop_qp(struct mlx4_en_priv *priv);
83197549c34SHans Petter Selasky int mlx4_en_free_tx_buf(struct net_device *dev, struct mlx4_en_tx_ring *ring);
83297549c34SHans Petter Selasky void mlx4_en_rx_irq(struct mlx4_cq *mcq);
83397549c34SHans Petter Selasky 
83497549c34SHans Petter Selasky int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, struct mlx4_en_priv *priv);
83597549c34SHans Petter Selasky 
83697549c34SHans Petter Selasky int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset);
83797549c34SHans Petter Selasky int mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port);
83897549c34SHans Petter Selasky int mlx4_en_get_vport_stats(struct mlx4_en_dev *mdev, u8 port);
83997549c34SHans Petter Selasky void mlx4_en_create_debug_files(struct mlx4_en_priv *priv);
84097549c34SHans Petter Selasky void mlx4_en_delete_debug_files(struct mlx4_en_priv *priv);
84197549c34SHans Petter Selasky int mlx4_en_register_debugfs(void);
84297549c34SHans Petter Selasky void mlx4_en_unregister_debugfs(void);
84397549c34SHans Petter Selasky 
84497549c34SHans Petter Selasky #ifdef CONFIG_MLX4_EN_DCB
84597549c34SHans Petter Selasky extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_ops;
84697549c34SHans Petter Selasky extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_pfc_ops;
84797549c34SHans Petter Selasky #endif
84897549c34SHans Petter Selasky 
84997549c34SHans Petter Selasky int mlx4_en_setup_tc(struct net_device *dev, u8 up);
85097549c34SHans Petter Selasky 
85197549c34SHans Petter Selasky #ifdef CONFIG_RFS_ACCEL
85297549c34SHans Petter Selasky void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv,
85397549c34SHans Petter Selasky 			     struct mlx4_en_rx_ring *rx_ring);
85497549c34SHans Petter Selasky #endif
85597549c34SHans Petter Selasky 
85697549c34SHans Petter Selasky #define MLX4_EN_NUM_SELF_TEST	5
85797549c34SHans Petter Selasky void mlx4_en_ex_selftest(struct net_device *dev, u32 *flags, u64 *buf);
85897549c34SHans Petter Selasky void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev);
85997549c34SHans Petter Selasky 
86097549c34SHans Petter Selasky /*
86197549c34SHans Petter Selasky  * Functions for time stamping
86297549c34SHans Petter Selasky  */
86397549c34SHans Petter Selasky #define SKBTX_HW_TSTAMP (1 << 0)
86497549c34SHans Petter Selasky #define SKBTX_IN_PROGRESS (1 << 2)
86597549c34SHans Petter Selasky 
86697549c34SHans Petter Selasky u64 mlx4_en_get_cqe_ts(struct mlx4_cqe *cqe);
86797549c34SHans Petter Selasky 
86897549c34SHans Petter Selasky /* Functions for caching and restoring statistics */
86997549c34SHans Petter Selasky int mlx4_en_get_sset_count(struct net_device *dev, int sset);
87097549c34SHans Petter Selasky void mlx4_en_restore_ethtool_stats(struct mlx4_en_priv *priv,
87197549c34SHans Petter Selasky 				    u64 *data);
87297549c34SHans Petter Selasky 
87397549c34SHans Petter Selasky /*
87497549c34SHans Petter Selasky  * Globals
87597549c34SHans Petter Selasky  */
87697549c34SHans Petter Selasky extern const struct ethtool_ops mlx4_en_ethtool_ops;
87797549c34SHans Petter Selasky 
87897549c34SHans Petter Selasky /*
87997549c34SHans Petter Selasky  * Defines for link speed - needed by selftest
88097549c34SHans Petter Selasky  */
88197549c34SHans Petter Selasky #define MLX4_EN_LINK_SPEED_1G	1000
88297549c34SHans Petter Selasky #define MLX4_EN_LINK_SPEED_10G	10000
88397549c34SHans Petter Selasky #define MLX4_EN_LINK_SPEED_40G	40000
88497549c34SHans Petter Selasky 
88597549c34SHans Petter Selasky enum {
88697549c34SHans Petter Selasky         NETIF_MSG_DRV           = 0x0001,
88797549c34SHans Petter Selasky         NETIF_MSG_PROBE         = 0x0002,
88897549c34SHans Petter Selasky         NETIF_MSG_LINK          = 0x0004,
88997549c34SHans Petter Selasky         NETIF_MSG_TIMER         = 0x0008,
89097549c34SHans Petter Selasky         NETIF_MSG_IFDOWN        = 0x0010,
89197549c34SHans Petter Selasky         NETIF_MSG_IFUP          = 0x0020,
89297549c34SHans Petter Selasky         NETIF_MSG_RX_ERR        = 0x0040,
89397549c34SHans Petter Selasky         NETIF_MSG_TX_ERR        = 0x0080,
89497549c34SHans Petter Selasky         NETIF_MSG_TX_QUEUED     = 0x0100,
89597549c34SHans Petter Selasky         NETIF_MSG_INTR          = 0x0200,
89697549c34SHans Petter Selasky         NETIF_MSG_TX_DONE       = 0x0400,
89797549c34SHans Petter Selasky         NETIF_MSG_RX_STATUS     = 0x0800,
89897549c34SHans Petter Selasky         NETIF_MSG_PKTDATA       = 0x1000,
89997549c34SHans Petter Selasky         NETIF_MSG_HW            = 0x2000,
90097549c34SHans Petter Selasky         NETIF_MSG_WOL           = 0x4000,
90197549c34SHans Petter Selasky };
90297549c34SHans Petter Selasky 
90397549c34SHans Petter Selasky 
90497549c34SHans Petter Selasky /*
90597549c34SHans Petter Selasky  * printk / logging functions
90697549c34SHans Petter Selasky  */
90797549c34SHans Petter Selasky 
90897549c34SHans Petter Selasky #define en_print(level, priv, format, arg...)                   \
90997549c34SHans Petter Selasky         {                                                       \
91097549c34SHans Petter Selasky         if ((priv)->registered)                                 \
91197549c34SHans Petter Selasky                 printk(level "%s: %s: " format, DRV_NAME,       \
912c3191c2eSHans Petter Selasky                         (priv)->dev->if_xname, ## arg); \
91397549c34SHans Petter Selasky         else                                                    \
91497549c34SHans Petter Selasky                 printk(level "%s: %s: Port %d: " format,        \
915c3191c2eSHans Petter Selasky                         DRV_NAME, dev_name(&(priv)->mdev->pdev->dev), \
91697549c34SHans Petter Selasky                         (priv)->port, ## arg);                  \
91797549c34SHans Petter Selasky         }
91897549c34SHans Petter Selasky 
91997549c34SHans Petter Selasky 
92097549c34SHans Petter Selasky #define en_dbg(mlevel, priv, format, arg...)			\
92197549c34SHans Petter Selasky do {								\
92297549c34SHans Petter Selasky 	if (NETIF_MSG_##mlevel & priv->msg_enable)		\
92397549c34SHans Petter Selasky 		en_print(KERN_DEBUG, priv, format, ##arg);	\
92497549c34SHans Petter Selasky } while (0)
92597549c34SHans Petter Selasky #define en_warn(priv, format, arg...)			\
92697549c34SHans Petter Selasky 	en_print(KERN_WARNING, priv, format, ##arg)
92797549c34SHans Petter Selasky #define en_err(priv, format, arg...)			\
92897549c34SHans Petter Selasky 	en_print(KERN_ERR, priv, format, ##arg)
92997549c34SHans Petter Selasky #define en_info(priv, format, arg...)			\
93097549c34SHans Petter Selasky 	en_print(KERN_INFO, priv, format, ## arg)
93197549c34SHans Petter Selasky 
93297549c34SHans Petter Selasky #define mlx4_err(mdev, format, arg...)			\
93397549c34SHans Petter Selasky 	pr_err("%s %s: " format, DRV_NAME,		\
934c3191c2eSHans Petter Selasky 	       dev_name(&(mdev)->pdev->dev), ##arg)
93597549c34SHans Petter Selasky #define mlx4_info(mdev, format, arg...)			\
93697549c34SHans Petter Selasky 	pr_info("%s %s: " format, DRV_NAME,		\
937c3191c2eSHans Petter Selasky 		dev_name(&(mdev)->pdev->dev), ##arg)
93897549c34SHans Petter Selasky #define mlx4_warn(mdev, format, arg...)			\
93997549c34SHans Petter Selasky 	pr_warning("%s %s: " format, DRV_NAME,		\
940c3191c2eSHans Petter Selasky 		   dev_name(&(mdev)->pdev->dev), ##arg)
94197549c34SHans Petter Selasky 
94297549c34SHans Petter Selasky #endif
943