xref: /freebsd/sys/dev/mlx4/mlx4_en/en.h (revision c44fbfdb56862c4c8d2563483b4fff8f9a5a1d43)
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/if_vlan.h>
4397549c34SHans Petter Selasky #include <linux/if_ether.h>
4497549c34SHans Petter Selasky #ifdef CONFIG_MLX4_EN_DCB
4597549c34SHans Petter Selasky #include <linux/dcbnl.h>
4697549c34SHans Petter Selasky #endif
4797549c34SHans Petter Selasky 
489d593d5aSBjoern A. Zeeb #include <sys/socket.h>
499d593d5aSBjoern A. Zeeb #include <sys/taskqueue.h>
509d593d5aSBjoern A. Zeeb 
519d593d5aSBjoern A. Zeeb #include <net/if_types.h>
529d593d5aSBjoern A. Zeeb #include <net/if.h>
539d593d5aSBjoern A. Zeeb #include <net/if_var.h>
549d593d5aSBjoern A. Zeeb #include <net/if_dl.h>
559d593d5aSBjoern A. Zeeb 
5697549c34SHans Petter Selasky #include <dev/mlx4/device.h>
5797549c34SHans Petter Selasky #include <dev/mlx4/qp.h>
5897549c34SHans Petter Selasky #include <dev/mlx4/cq.h>
5997549c34SHans Petter Selasky #include <dev/mlx4/srq.h>
6097549c34SHans Petter Selasky #include <dev/mlx4/doorbell.h>
6197549c34SHans Petter Selasky #include <dev/mlx4/cmd.h>
6297549c34SHans Petter Selasky 
637790c8c1SConrad Meyer #include <net/debugnet.h>
6497549c34SHans Petter Selasky #include <netinet/tcp_lro.h>
6597549c34SHans Petter Selasky 
6697549c34SHans Petter Selasky #include "en_port.h"
6797549c34SHans Petter Selasky #include <dev/mlx4/stats.h>
6897549c34SHans Petter Selasky 
6997549c34SHans Petter Selasky #define DRV_NAME	"mlx4_en"
7097549c34SHans Petter Selasky 
7197549c34SHans Petter Selasky #define MLX4_EN_MSG_LEVEL	(NETIF_MSG_LINK | NETIF_MSG_IFDOWN)
7297549c34SHans Petter Selasky 
7397549c34SHans Petter Selasky /*
7497549c34SHans Petter Selasky  * Device constants
7597549c34SHans Petter Selasky  */
7697549c34SHans Petter Selasky 
7797549c34SHans Petter Selasky 
7897549c34SHans Petter Selasky #define MLX4_EN_PAGE_SHIFT	12
7997549c34SHans Petter Selasky #define MLX4_EN_PAGE_SIZE	(1 << MLX4_EN_PAGE_SHIFT)
8097549c34SHans Petter Selasky #define	MLX4_NET_IP_ALIGN	2	/* bytes */
8197549c34SHans Petter Selasky #define DEF_RX_RINGS		16
8297549c34SHans Petter Selasky #define MAX_RX_RINGS		128
8397549c34SHans Petter Selasky #define MIN_RX_RINGS		4
8497549c34SHans Petter Selasky #define TXBB_SIZE		64
8593bf8216SSlava Shwartsman 
8693bf8216SSlava Shwartsman #ifndef MLX4_EN_MAX_RX_SEGS
8793bf8216SSlava Shwartsman #define	MLX4_EN_MAX_RX_SEGS 1	/* or 8 */
8893bf8216SSlava Shwartsman #endif
8993bf8216SSlava Shwartsman 
9093bf8216SSlava Shwartsman #ifndef MLX4_EN_MAX_RX_BYTES
9193bf8216SSlava Shwartsman #define	MLX4_EN_MAX_RX_BYTES MCLBYTES
9293bf8216SSlava Shwartsman #endif
9393bf8216SSlava Shwartsman 
9497549c34SHans Petter Selasky #define HEADROOM		(2048 / TXBB_SIZE + 1)
95c3191c2eSHans Petter Selasky #define INIT_OWNER_BIT		0xffffffff
9697549c34SHans Petter Selasky #define STAMP_STRIDE		64
9797549c34SHans Petter Selasky #define STAMP_DWORDS		(STAMP_STRIDE / 4)
9897549c34SHans Petter Selasky #define STAMP_SHIFT		31
9997549c34SHans Petter Selasky #define STAMP_VAL		0x7fffffff
10097549c34SHans Petter Selasky #define STATS_DELAY		(HZ / 4)
10197549c34SHans Petter Selasky #define SERVICE_TASK_DELAY	(HZ / 4)
10297549c34SHans Petter Selasky #define MAX_NUM_OF_FS_RULES	256
10397549c34SHans Petter Selasky 
10497549c34SHans Petter Selasky #define MLX4_EN_FILTER_HASH_SHIFT 4
10597549c34SHans Petter Selasky #define MLX4_EN_FILTER_EXPIRY_QUOTA 60
10697549c34SHans Petter Selasky 
10797549c34SHans Petter Selasky #ifdef CONFIG_NET_RX_BUSY_POLL
10897549c34SHans Petter Selasky #define LL_EXTENDED_STATS
10997549c34SHans Petter Selasky #endif
11097549c34SHans Petter Selasky 
11197549c34SHans Petter Selasky /* vlan valid range */
11297549c34SHans Petter Selasky #define VLAN_MIN_VALUE		1
11397549c34SHans Petter Selasky #define VLAN_MAX_VALUE		4094
11497549c34SHans Petter Selasky 
11597549c34SHans Petter Selasky /*
11697549c34SHans Petter Selasky  * OS related constants and tunables
11797549c34SHans Petter Selasky  */
11897549c34SHans Petter Selasky 
11997549c34SHans Petter Selasky #define MLX4_EN_WATCHDOG_TIMEOUT	(15 * HZ)
12097549c34SHans Petter Selasky 
12197549c34SHans Petter Selasky #define MLX4_EN_ALLOC_SIZE     PAGE_ALIGN(PAGE_SIZE)
12297549c34SHans Petter Selasky #define MLX4_EN_ALLOC_ORDER    get_order(MLX4_EN_ALLOC_SIZE)
12397549c34SHans Petter Selasky 
12497549c34SHans Petter Selasky enum mlx4_en_alloc_type {
12597549c34SHans Petter Selasky 	MLX4_EN_ALLOC_NEW = 0,
12697549c34SHans Petter Selasky 	MLX4_EN_ALLOC_REPLACEMENT = 1,
12797549c34SHans Petter Selasky };
12897549c34SHans Petter Selasky 
12997549c34SHans Petter Selasky /* Maximum ring sizes */
13097549c34SHans Petter Selasky #define MLX4_EN_DEF_TX_QUEUE_SIZE       4096
13197549c34SHans Petter Selasky 
13297549c34SHans Petter Selasky /* Minimum packet number till arming the CQ */
13397549c34SHans Petter Selasky #define MLX4_EN_MIN_RX_ARM	2048
13497549c34SHans Petter Selasky #define MLX4_EN_MIN_TX_ARM	2048
13597549c34SHans Petter Selasky 
13697549c34SHans Petter Selasky /* Maximum ring sizes */
13797549c34SHans Petter Selasky #define MLX4_EN_MAX_TX_SIZE	8192
13897549c34SHans Petter Selasky #define MLX4_EN_MAX_RX_SIZE	8192
13997549c34SHans Petter Selasky 
14097549c34SHans Petter Selasky /* Minimum ring sizes */
14197549c34SHans Petter Selasky #define MLX4_EN_MIN_RX_SIZE	(4096 / TXBB_SIZE)
14297549c34SHans Petter Selasky #define MLX4_EN_MIN_TX_SIZE	(4096 / TXBB_SIZE)
14397549c34SHans Petter Selasky 
14497549c34SHans Petter Selasky #define MLX4_EN_SMALL_PKT_SIZE		64
14597549c34SHans Petter Selasky 
14697549c34SHans Petter Selasky #define MLX4_EN_MAX_TX_RING_P_UP	32
14797549c34SHans Petter Selasky #define MLX4_EN_NUM_UP			1
14897549c34SHans Petter Selasky 
14997549c34SHans Petter Selasky #define MAX_TX_RINGS			(MLX4_EN_MAX_TX_RING_P_UP * \
15097549c34SHans Petter Selasky 					MLX4_EN_NUM_UP)
15197549c34SHans Petter Selasky 
152c3191c2eSHans Petter Selasky #define MLX4_EN_NO_VLAN			0xffff
153c3191c2eSHans Petter Selasky 
15497549c34SHans Petter Selasky #define MLX4_EN_DEF_TX_RING_SIZE	1024
15597549c34SHans Petter Selasky #define MLX4_EN_DEF_RX_RING_SIZE  	1024
15697549c34SHans Petter Selasky 
15797549c34SHans Petter Selasky /* Target number of bytes to coalesce with interrupt moderation */
158c3191c2eSHans Petter Selasky #define MLX4_EN_RX_COAL_TARGET	44
15997549c34SHans Petter Selasky #define MLX4_EN_RX_COAL_TIME	0x10
16097549c34SHans Petter Selasky 
16197549c34SHans Petter Selasky #define MLX4_EN_TX_COAL_PKTS	64
16297549c34SHans Petter Selasky #define MLX4_EN_TX_COAL_TIME	64
16397549c34SHans Petter Selasky 
16497549c34SHans Petter Selasky #define MLX4_EN_RX_RATE_LOW		400000
16597549c34SHans Petter Selasky #define MLX4_EN_RX_COAL_TIME_LOW	0
16697549c34SHans Petter Selasky #define MLX4_EN_RX_RATE_HIGH		450000
16797549c34SHans Petter Selasky #define MLX4_EN_RX_COAL_TIME_HIGH	128
16897549c34SHans Petter Selasky #define MLX4_EN_RX_SIZE_THRESH		1024
16997549c34SHans Petter Selasky #define MLX4_EN_RX_RATE_THRESH		(1000000 / MLX4_EN_RX_COAL_TIME_HIGH)
17097549c34SHans Petter Selasky #define MLX4_EN_SAMPLE_INTERVAL		0
17197549c34SHans Petter Selasky #define MLX4_EN_AVG_PKT_SMALL		256
17297549c34SHans Petter Selasky 
17397549c34SHans Petter Selasky #define MLX4_EN_AUTO_CONF	0xffff
17497549c34SHans Petter Selasky 
17597549c34SHans Petter Selasky #define MLX4_EN_DEF_RX_PAUSE	1
17697549c34SHans Petter Selasky #define MLX4_EN_DEF_TX_PAUSE	1
17797549c34SHans Petter Selasky 
17897549c34SHans Petter Selasky /* Interval between successive polls in the Tx routine when polling is used
17997549c34SHans Petter Selasky    instead of interrupts (in per-core Tx rings) - should be power of 2 */
18097549c34SHans Petter Selasky #define MLX4_EN_TX_POLL_MODER	16
18197549c34SHans Petter Selasky #define MLX4_EN_TX_POLL_TIMEOUT	(HZ / 4)
18297549c34SHans Petter Selasky 
18397549c34SHans Petter Selasky #define MLX4_EN_64_ALIGN	(64 - NET_SKB_PAD)
18497549c34SHans Petter Selasky #define SMALL_PACKET_SIZE      (256 - NET_IP_ALIGN)
18597549c34SHans Petter Selasky #define HEADER_COPY_SIZE       (128)
18697549c34SHans Petter Selasky #define MLX4_LOOPBACK_TEST_PAYLOAD (HEADER_COPY_SIZE - ETHER_HDR_LEN)
18797549c34SHans Petter Selasky 
18897549c34SHans Petter Selasky #define MLX4_EN_MIN_MTU		46
18997549c34SHans Petter Selasky #define ETH_BCAST		0xffffffffffffULL
19097549c34SHans Petter Selasky 
19197549c34SHans Petter Selasky #define MLX4_EN_LOOPBACK_RETRIES	5
19297549c34SHans Petter Selasky #define MLX4_EN_LOOPBACK_TIMEOUT	100
19397549c34SHans Petter Selasky 
19497549c34SHans Petter Selasky #ifdef MLX4_EN_PERF_STAT
19597549c34SHans Petter Selasky /* Number of samples to 'average' */
19697549c34SHans Petter Selasky #define AVG_SIZE			128
19797549c34SHans Petter Selasky #define AVG_FACTOR			1024
19897549c34SHans Petter Selasky 
19997549c34SHans Petter Selasky #define INC_PERF_COUNTER(cnt)		(++(cnt))
20097549c34SHans Petter Selasky #define ADD_PERF_COUNTER(cnt, add)	((cnt) += (add))
20197549c34SHans Petter Selasky #define AVG_PERF_COUNTER(cnt, sample) \
20297549c34SHans Petter Selasky 	((cnt) = ((cnt) * (AVG_SIZE - 1) + (sample) * AVG_FACTOR) / AVG_SIZE)
20397549c34SHans Petter Selasky #define GET_PERF_COUNTER(cnt)		(cnt)
20497549c34SHans Petter Selasky #define GET_AVG_PERF_COUNTER(cnt)	((cnt) / AVG_FACTOR)
20597549c34SHans Petter Selasky 
20697549c34SHans Petter Selasky #else
20797549c34SHans Petter Selasky 
20897549c34SHans Petter Selasky #define INC_PERF_COUNTER(cnt)		do {} while (0)
20997549c34SHans Petter Selasky #define ADD_PERF_COUNTER(cnt, add)	do {} while (0)
21097549c34SHans Petter Selasky #define AVG_PERF_COUNTER(cnt, sample)	do {} while (0)
21197549c34SHans Petter Selasky #define GET_PERF_COUNTER(cnt)		(0)
21297549c34SHans Petter Selasky #define GET_AVG_PERF_COUNTER(cnt)	(0)
21397549c34SHans Petter Selasky #endif /* MLX4_EN_PERF_STAT */
21497549c34SHans Petter Selasky 
215c3191c2eSHans Petter Selasky /* Constants for TX flow */
216c3191c2eSHans Petter Selasky enum {
217c3191c2eSHans Petter Selasky 	MAX_INLINE = 104, /* 128 - 16 - 4 - 4 */
218c3191c2eSHans Petter Selasky 	MAX_BF = 256,
219c3191c2eSHans Petter Selasky 	MIN_PKT_LEN = 17,
220c3191c2eSHans Petter Selasky };
221c3191c2eSHans Petter Selasky 
22297549c34SHans Petter Selasky /*
22397549c34SHans Petter Selasky  * Configurables
22497549c34SHans Petter Selasky  */
22597549c34SHans Petter Selasky 
22697549c34SHans Petter Selasky enum cq_type {
22797549c34SHans Petter Selasky 	RX = 0,
22897549c34SHans Petter Selasky 	TX = 1,
22997549c34SHans Petter Selasky };
23097549c34SHans Petter Selasky 
23197549c34SHans Petter Selasky 
23297549c34SHans Petter Selasky /*
23397549c34SHans Petter Selasky  * Useful macros
23497549c34SHans Petter Selasky  */
235*c44fbfdbSDoug Moore #define ROUNDUP_LOG2(x)		order_base_2(x)
23697549c34SHans Petter Selasky #define XNOR(x, y)		(!(x) == !(y))
23797549c34SHans Petter Selasky #define ILLEGAL_MAC(addr)	(addr == 0xffffffffffffULL || addr == 0x0)
23897549c34SHans Petter Selasky 
23997549c34SHans Petter Selasky struct mlx4_en_tx_info {
24097549c34SHans Petter Selasky 	bus_dmamap_t dma_map;
24197549c34SHans Petter Selasky         struct mbuf *mb;
24297549c34SHans Petter Selasky         u32 nr_txbb;
24397549c34SHans Petter Selasky 	u32 nr_bytes;
24497549c34SHans Petter Selasky };
24597549c34SHans Petter Selasky 
24697549c34SHans Petter Selasky 
24797549c34SHans Petter Selasky #define MLX4_EN_BIT_DESC_OWN	0x80000000
24897549c34SHans Petter Selasky #define CTRL_SIZE	sizeof(struct mlx4_wqe_ctrl_seg)
24997549c34SHans Petter Selasky #define MLX4_EN_MEMTYPE_PAD	0x100
25097549c34SHans Petter Selasky #define DS_SIZE		sizeof(struct mlx4_wqe_data_seg)
25197549c34SHans Petter Selasky 
25297549c34SHans Petter Selasky 
25397549c34SHans Petter Selasky struct mlx4_en_tx_desc {
25497549c34SHans Petter Selasky 	struct mlx4_wqe_ctrl_seg ctrl;
25597549c34SHans Petter Selasky 	union {
25697549c34SHans Petter Selasky 		struct mlx4_wqe_data_seg data; /* at least one data segment */
25797549c34SHans Petter Selasky 		struct mlx4_wqe_lso_seg lso;
25897549c34SHans Petter Selasky 		struct mlx4_wqe_inline_seg inl;
25997549c34SHans Petter Selasky 	};
26097549c34SHans Petter Selasky };
26197549c34SHans Petter Selasky 
26297549c34SHans Petter Selasky #define MLX4_EN_USE_SRQ		0x01000000
26397549c34SHans Petter Selasky 
26497549c34SHans Petter Selasky #define MLX4_EN_RX_BUDGET 64
26597549c34SHans Petter Selasky 
26697549c34SHans Petter Selasky #define	MLX4_EN_TX_MAX_DESC_SIZE 512	/* bytes */
26797549c34SHans Petter Selasky #define	MLX4_EN_TX_MAX_MBUF_SIZE 65536	/* bytes */
26897549c34SHans Petter Selasky #define	MLX4_EN_TX_MAX_PAYLOAD_SIZE 65536	/* bytes */
26997549c34SHans Petter Selasky #define	MLX4_EN_TX_MAX_MBUF_FRAGS \
27097549c34SHans Petter Selasky     ((MLX4_EN_TX_MAX_DESC_SIZE - 128) / DS_SIZE_ALIGNMENT) /* units */
27197549c34SHans Petter Selasky #define	MLX4_EN_TX_WQE_MAX_WQEBBS			\
27297549c34SHans Petter Selasky     (MLX4_EN_TX_MAX_DESC_SIZE / TXBB_SIZE) /* units */
27397549c34SHans Petter Selasky 
27497549c34SHans Petter Selasky #define MLX4_EN_CX3_LOW_ID	0x1000
27597549c34SHans Petter Selasky #define MLX4_EN_CX3_HIGH_ID	0x1005
27697549c34SHans Petter Selasky 
27797549c34SHans Petter Selasky struct mlx4_en_tx_ring {
27897549c34SHans Petter Selasky         spinlock_t tx_lock;
27997549c34SHans Petter Selasky 	bus_dma_tag_t dma_tag;
28097549c34SHans Petter Selasky 	struct mlx4_hwq_resources wqres;
28197549c34SHans Petter Selasky 	u32 size ; /* number of TXBBs */
28297549c34SHans Petter Selasky 	u32 size_mask;
28397549c34SHans Petter Selasky 	u16 stride;
28497549c34SHans Petter Selasky 	u16 cqn;	/* index of port CQ associated with this ring */
28597549c34SHans Petter Selasky 	u32 prod;
28697549c34SHans Petter Selasky 	u32 cons;
28797549c34SHans Petter Selasky 	u32 buf_size;
28897549c34SHans Petter Selasky 	u32 doorbell_qpn;
28997549c34SHans Petter Selasky 	u8 *buf;
29097549c34SHans Petter Selasky 	u16 poll_cnt;
29197549c34SHans Petter Selasky 	struct mlx4_en_tx_info *tx_info;
29297549c34SHans Petter Selasky 	u8 queue_index;
29397549c34SHans Petter Selasky 	u32 last_nr_txbb;
29497549c34SHans Petter Selasky 	struct mlx4_qp qp;
29597549c34SHans Petter Selasky 	struct mlx4_qp_context context;
29697549c34SHans Petter Selasky 	int qpn;
29797549c34SHans Petter Selasky 	enum mlx4_qp_state qp_state;
29897549c34SHans Petter Selasky 	struct mlx4_srq dummy;
299c3191c2eSHans Petter Selasky 	u64 bytes;
300c3191c2eSHans Petter Selasky 	u64 packets;
301c3191c2eSHans Petter Selasky 	u64 tx_csum;
302c3191c2eSHans Petter Selasky 	u64 queue_stopped;
303c3191c2eSHans Petter Selasky 	u64 oversized_packets;
304c3191c2eSHans Petter Selasky 	u64 wake_queue;
305c3191c2eSHans Petter Selasky 	u64 tso_packets;
306c3191c2eSHans Petter Selasky 	u64 defrag_attempts;
30797549c34SHans Petter Selasky 	struct mlx4_bf bf;
30897549c34SHans Petter Selasky 	bool bf_enabled;
30997549c34SHans Petter Selasky 	int hwtstamp_tx_type;
31097549c34SHans Petter Selasky 	spinlock_t comp_lock;
31197549c34SHans Petter Selasky 	int inline_thold;
31297549c34SHans Petter Selasky 	u64 watchdog_time;
31397549c34SHans Petter Selasky };
31497549c34SHans Petter Selasky 
31597549c34SHans Petter Selasky struct mlx4_en_rx_desc {
31693bf8216SSlava Shwartsman 	struct mlx4_wqe_data_seg data[MLX4_EN_MAX_RX_SEGS];
31797549c34SHans Petter Selasky };
31897549c34SHans Petter Selasky 
31993bf8216SSlava Shwartsman /* the size of the structure above must be power of two */
32093bf8216SSlava Shwartsman CTASSERT(powerof2(sizeof(struct mlx4_en_rx_desc)));
32193bf8216SSlava Shwartsman 
32297549c34SHans Petter Selasky struct mlx4_en_rx_mbuf {
32397549c34SHans Petter Selasky 	bus_dmamap_t dma_map;
32497549c34SHans Petter Selasky 	struct mbuf *mbuf;
32597549c34SHans Petter Selasky };
32697549c34SHans Petter Selasky 
32797549c34SHans Petter Selasky struct mlx4_en_rx_spare {
32897549c34SHans Petter Selasky 	bus_dmamap_t dma_map;
32997549c34SHans Petter Selasky 	struct mbuf *mbuf;
33093bf8216SSlava Shwartsman 	bus_dma_segment_t segs[MLX4_EN_MAX_RX_SEGS];
33197549c34SHans Petter Selasky };
33297549c34SHans Petter Selasky 
33397549c34SHans Petter Selasky struct mlx4_en_rx_ring {
33497549c34SHans Petter Selasky 	struct mlx4_hwq_resources wqres;
33597549c34SHans Petter Selasky 	bus_dma_tag_t dma_tag;
33697549c34SHans Petter Selasky 	struct mlx4_en_rx_spare spare;
33797549c34SHans Petter Selasky 	u32 size ;	/* number of Rx descs*/
33897549c34SHans Petter Selasky 	u32 actual_size;
33997549c34SHans Petter Selasky 	u32 size_mask;
34097549c34SHans Petter Selasky 	u16 log_stride;
34197549c34SHans Petter Selasky 	u16 cqn;	/* index of port CQ associated with this ring */
34297549c34SHans Petter Selasky 	u32 prod;
34397549c34SHans Petter Selasky 	u32 cons;
34497549c34SHans Petter Selasky 	u32 buf_size;
34597549c34SHans Petter Selasky 	u8  fcs_del;
34697549c34SHans Petter Selasky 	u32 rx_mb_size;
34793bf8216SSlava Shwartsman 	u32 rx_mr_key_be;
34897549c34SHans Petter Selasky 	int qpn;
34997549c34SHans Petter Selasky 	u8 *buf;
35097549c34SHans Petter Selasky 	struct mlx4_en_rx_mbuf *mbuf;
351c3191c2eSHans Petter Selasky 	u64 errors;
352c3191c2eSHans Petter Selasky 	u64 bytes;
353c3191c2eSHans Petter Selasky 	u64 packets;
35497549c34SHans Petter Selasky #ifdef LL_EXTENDED_STATS
355c3191c2eSHans Petter Selasky 	u64 yields;
356c3191c2eSHans Petter Selasky 	u64 misses;
357c3191c2eSHans Petter Selasky 	u64 cleaned;
35897549c34SHans Petter Selasky #endif
359c3191c2eSHans Petter Selasky 	u64 csum_ok;
360c3191c2eSHans Petter Selasky 	u64 csum_none;
36197549c34SHans Petter Selasky 	int hwtstamp_rx_filter;
36297549c34SHans Petter Selasky 	int numa_node;
36397549c34SHans Petter Selasky 	struct lro_ctrl lro;
36497549c34SHans Petter Selasky };
36597549c34SHans Petter Selasky 
mlx4_en_can_lro(__be16 status)36697549c34SHans Petter Selasky static inline int mlx4_en_can_lro(__be16 status)
36797549c34SHans Petter Selasky {
36897549c34SHans Petter Selasky 	const __be16 status_all = cpu_to_be16(
36997549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV4    |
37097549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV4F   |
37197549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV6    |
37297549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV4OPT |
37397549c34SHans Petter Selasky 			MLX4_CQE_STATUS_TCP     |
37497549c34SHans Petter Selasky 			MLX4_CQE_STATUS_UDP     |
37597549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPOK);
37697549c34SHans Petter Selasky 	const __be16 status_ipv4_ipok_tcp = cpu_to_be16(
37797549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV4    |
37897549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPOK    |
37997549c34SHans Petter Selasky 			MLX4_CQE_STATUS_TCP);
38097549c34SHans Petter Selasky 	const __be16 status_ipv6_ipok_tcp = cpu_to_be16(
38197549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPV6    |
38297549c34SHans Petter Selasky 			MLX4_CQE_STATUS_IPOK    |
38397549c34SHans Petter Selasky 			MLX4_CQE_STATUS_TCP);
38497549c34SHans Petter Selasky 
38597549c34SHans Petter Selasky 	status &= status_all;
38697549c34SHans Petter Selasky 	return (status == status_ipv4_ipok_tcp ||
38797549c34SHans Petter Selasky 			status == status_ipv6_ipok_tcp);
38897549c34SHans Petter Selasky }
38997549c34SHans Petter Selasky 
39097549c34SHans Petter Selasky struct mlx4_en_cq {
39197549c34SHans Petter Selasky 	struct mlx4_cq          mcq;
39297549c34SHans Petter Selasky 	struct mlx4_hwq_resources wqres;
39397549c34SHans Petter Selasky 	int                     ring;
39497549c34SHans Petter Selasky 	spinlock_t              lock;
3950b281376SJustin Hibbits 	if_t			dev;
39697549c34SHans Petter Selasky         /* Per-core Tx cq processing support */
39797549c34SHans Petter Selasky         struct timer_list timer;
39897549c34SHans Petter Selasky 	int size;
39997549c34SHans Petter Selasky 	int buf_size;
40097549c34SHans Petter Selasky 	unsigned vector;
40197549c34SHans Petter Selasky 	enum cq_type is_tx;
40297549c34SHans Petter Selasky 	u16 moder_time;
40397549c34SHans Petter Selasky 	u16 moder_cnt;
40497549c34SHans Petter Selasky 	struct mlx4_cqe *buf;
40597549c34SHans Petter Selasky 	struct task cq_task;
40697549c34SHans Petter Selasky 	struct taskqueue *tq;
40797549c34SHans Petter Selasky #define MLX4_EN_OPCODE_ERROR	0x1e
40897549c34SHans Petter Selasky 	u32 tot_rx;
40997549c34SHans Petter Selasky 	u32 tot_tx;
41097549c34SHans Petter Selasky 	u32 curr_poll_rx_cpu_id;
41197549c34SHans Petter Selasky 
41297549c34SHans Petter Selasky #ifdef CONFIG_NET_RX_BUSY_POLL
41397549c34SHans Petter Selasky 	unsigned int state;
414c3191c2eSHans Petter Selasky #define MLX4_EN_CQ_STATE_IDLE        0
415c3191c2eSHans Petter Selasky #define MLX4_EN_CQ_STATE_NAPI     1    /* NAPI owns this CQ */
416c3191c2eSHans Petter Selasky #define MLX4_EN_CQ_STATE_POLL     2    /* poll owns this CQ */
417c3191c2eSHans Petter Selasky #define MLX4_CQ_LOCKED (MLX4_EN_CQ_STATE_NAPI | MLX4_EN_CQ_STATE_POLL)
418c3191c2eSHans Petter Selasky #define MLX4_EN_CQ_STATE_NAPI_YIELD  4    /* NAPI yielded this CQ */
419c3191c2eSHans Petter Selasky #define MLX4_EN_CQ_STATE_POLL_YIELD  8    /* poll yielded this CQ */
420c3191c2eSHans Petter Selasky #define CQ_YIELD (MLX4_EN_CQ_STATE_NAPI_YIELD | MLX4_EN_CQ_STATE_POLL_YIELD)
421c3191c2eSHans Petter Selasky #define CQ_USER_PEND (MLX4_EN_CQ_STATE_POLL | MLX4_EN_CQ_STATE_POLL_YIELD)
42297549c34SHans Petter Selasky 	spinlock_t poll_lock; /* protects from LLS/napi conflicts */
42397549c34SHans Petter Selasky #endif  /* CONFIG_NET_RX_BUSY_POLL */
42497549c34SHans Petter Selasky };
42597549c34SHans Petter Selasky 
42697549c34SHans Petter Selasky struct mlx4_en_port_profile {
42797549c34SHans Petter Selasky 	u32 flags;
42897549c34SHans Petter Selasky 	u32 tx_ring_num;
42997549c34SHans Petter Selasky 	u32 rx_ring_num;
43097549c34SHans Petter Selasky 	u32 tx_ring_size;
43197549c34SHans Petter Selasky 	u32 rx_ring_size;
43297549c34SHans Petter Selasky 	u8 rx_pause;
43397549c34SHans Petter Selasky 	u8 rx_ppp;
43497549c34SHans Petter Selasky 	u8 tx_pause;
43597549c34SHans Petter Selasky 	u8 tx_ppp;
43697549c34SHans Petter Selasky 	int rss_rings;
437c3191c2eSHans Petter Selasky 	int inline_thold;
43897549c34SHans Petter Selasky };
43997549c34SHans Petter Selasky 
44097549c34SHans Petter Selasky struct mlx4_en_profile {
44197549c34SHans Petter Selasky 	int rss_xor;
44297549c34SHans Petter Selasky 	int udp_rss;
44397549c34SHans Petter Selasky 	u8 rss_mask;
44497549c34SHans Petter Selasky 	u32 active_ports;
44597549c34SHans Petter Selasky 	u32 small_pkt_int;
44697549c34SHans Petter Selasky 	u8 no_reset;
44797549c34SHans Petter Selasky 	u8 num_tx_rings_p_up;
44897549c34SHans Petter Selasky 	struct mlx4_en_port_profile prof[MLX4_MAX_PORTS + 1];
44997549c34SHans Petter Selasky };
45097549c34SHans Petter Selasky 
45197549c34SHans Petter Selasky struct mlx4_en_dev {
45297549c34SHans Petter Selasky 	struct mlx4_dev		*dev;
45397549c34SHans Petter Selasky 	struct pci_dev		*pdev;
45497549c34SHans Petter Selasky 	struct mutex		state_lock;
4550b281376SJustin Hibbits 	if_t			pndev[MLX4_MAX_PORTS + 1];
45697549c34SHans Petter Selasky 	u32			port_cnt;
45797549c34SHans Petter Selasky 	bool			device_up;
45897549c34SHans Petter Selasky 	struct mlx4_en_profile	profile;
45997549c34SHans Petter Selasky 	u32			LSO_support;
46097549c34SHans Petter Selasky 	struct workqueue_struct *workqueue;
46197549c34SHans Petter Selasky 	struct device		*dma_device;
46297549c34SHans Petter Selasky 	void __iomem		*uar_map;
46397549c34SHans Petter Selasky 	struct mlx4_uar		priv_uar;
46497549c34SHans Petter Selasky 	struct mlx4_mr		mr;
46597549c34SHans Petter Selasky 	u32			priv_pdn;
46697549c34SHans Petter Selasky 	spinlock_t		uar_lock;
46797549c34SHans Petter Selasky 	u8			mac_removed[MLX4_MAX_PORTS + 1];
46897549c34SHans Petter Selasky 	unsigned long		last_overflow_check;
46997549c34SHans Petter Selasky 	unsigned long		overflow_period;
47097549c34SHans Petter Selasky };
47197549c34SHans Petter Selasky 
47297549c34SHans Petter Selasky 
47397549c34SHans Petter Selasky struct mlx4_en_rss_map {
47497549c34SHans Petter Selasky 	int base_qpn;
47597549c34SHans Petter Selasky 	struct mlx4_qp qps[MAX_RX_RINGS];
47697549c34SHans Petter Selasky 	enum mlx4_qp_state state[MAX_RX_RINGS];
47797549c34SHans Petter Selasky 	struct mlx4_qp indir_qp;
47897549c34SHans Petter Selasky 	enum mlx4_qp_state indir_state;
47997549c34SHans Petter Selasky };
48097549c34SHans Petter Selasky 
481c3191c2eSHans Petter Selasky enum mlx4_en_port_flag {
482c3191c2eSHans Petter Selasky 	MLX4_EN_PORT_ANC = 1<<0, /* Auto-negotiation complete */
483c3191c2eSHans Petter Selasky 	MLX4_EN_PORT_ANE = 1<<1, /* Auto-negotiation enabled */
484c3191c2eSHans Petter Selasky };
485c3191c2eSHans Petter Selasky 
48697549c34SHans Petter Selasky struct mlx4_en_port_state {
48797549c34SHans Petter Selasky 	int link_state;
48897549c34SHans Petter Selasky 	int link_speed;
489c3191c2eSHans Petter Selasky 	int transceiver;
490c3191c2eSHans Petter Selasky 	u32 flags;
49197549c34SHans Petter Selasky };
49297549c34SHans Petter Selasky 
493c3191c2eSHans Petter Selasky enum mlx4_en_addr_list_act {
494c3191c2eSHans Petter Selasky 	MLX4_ADDR_LIST_NONE,
495c3191c2eSHans Petter Selasky 	MLX4_ADDR_LIST_REM,
496c3191c2eSHans Petter Selasky 	MLX4_ADDR_LIST_ADD,
49797549c34SHans Petter Selasky };
49897549c34SHans Petter Selasky 
499c3191c2eSHans Petter Selasky struct mlx4_en_addr_list {
50097549c34SHans Petter Selasky 	struct list_head	list;
501c3191c2eSHans Petter Selasky 	enum mlx4_en_addr_list_act	action;
50297549c34SHans Petter Selasky 	u8			addr[ETH_ALEN];
50397549c34SHans Petter Selasky 	u64			reg_id;
504c3191c2eSHans Petter Selasky 	u64			tunnel_reg_id;
50597549c34SHans Petter Selasky };
50697549c34SHans Petter Selasky 
50797549c34SHans Petter Selasky #ifdef CONFIG_MLX4_EN_DCB
50897549c34SHans Petter Selasky /* Minimal TC BW - setting to 0 will block traffic */
50997549c34SHans Petter Selasky #define MLX4_EN_BW_MIN 1
51097549c34SHans Petter Selasky #define MLX4_EN_BW_MAX 100 /* Utilize 100% of the line */
51197549c34SHans Petter Selasky 
512c3191c2eSHans Petter Selasky #define MLX4_EN_TC_VENDOR 0
51397549c34SHans Petter Selasky #define MLX4_EN_TC_ETS 7
51497549c34SHans Petter Selasky 
51597549c34SHans Petter Selasky #endif
51697549c34SHans Petter Selasky 
51797549c34SHans Petter Selasky 
51897549c34SHans Petter Selasky enum {
51997549c34SHans Petter Selasky 	MLX4_EN_FLAG_PROMISC		= (1 << 0),
52097549c34SHans Petter Selasky 	MLX4_EN_FLAG_MC_PROMISC		= (1 << 1),
52197549c34SHans Petter Selasky 	/* whether we need to enable hardware loopback by putting dmac
52297549c34SHans Petter Selasky 	 * in Tx WQE
52397549c34SHans Petter Selasky 	 */
52497549c34SHans Petter Selasky 	MLX4_EN_FLAG_ENABLE_HW_LOOPBACK	= (1 << 2),
52597549c34SHans Petter Selasky 	/* whether we need to drop packets that hardware loopback-ed */
52697549c34SHans Petter Selasky 	MLX4_EN_FLAG_RX_FILTER_NEEDED	= (1 << 3),
52797549c34SHans Petter Selasky 	MLX4_EN_FLAG_FORCE_PROMISC	= (1 << 4),
52897549c34SHans Petter Selasky #ifdef CONFIG_MLX4_EN_DCB
52997549c34SHans Petter Selasky 	MLX4_EN_FLAG_DCB_ENABLED	= (1 << 5)
53097549c34SHans Petter Selasky #endif
53197549c34SHans Petter Selasky };
53297549c34SHans Petter Selasky 
53397549c34SHans Petter Selasky #define MLX4_EN_MAC_HASH_SIZE (1 << BITS_PER_BYTE)
53497549c34SHans Petter Selasky #define MLX4_EN_MAC_HASH_IDX 5
53597549c34SHans Petter Selasky 
53697549c34SHans Petter Selasky struct en_port {
53797549c34SHans Petter Selasky 	struct kobject		kobj;
53897549c34SHans Petter Selasky 	struct mlx4_dev		*dev;
53997549c34SHans Petter Selasky 	u8			port_num;
54097549c34SHans Petter Selasky 	u8			vport_num;
54197549c34SHans Petter Selasky };
54297549c34SHans Petter Selasky 
54397549c34SHans Petter Selasky struct mlx4_en_priv {
54497549c34SHans Petter Selasky 	struct mlx4_en_dev *mdev;
54597549c34SHans Petter Selasky 	struct mlx4_en_port_profile *prof;
5460b281376SJustin Hibbits 	if_t dev;
54797549c34SHans Petter Selasky 	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
54897549c34SHans Petter Selasky 	struct mlx4_en_port_state port_state;
54997549c34SHans Petter Selasky 	spinlock_t stats_lock;
55097549c34SHans Petter Selasky 	/* To allow rules removal while port is going down */
55197549c34SHans Petter Selasky 	struct list_head ethtool_list;
55297549c34SHans Petter Selasky 
55397549c34SHans Petter Selasky 	unsigned long last_moder_packets[MAX_RX_RINGS];
55497549c34SHans Petter Selasky 	unsigned long last_moder_tx_packets;
55597549c34SHans Petter Selasky 	unsigned long last_moder_bytes[MAX_RX_RINGS];
55697549c34SHans Petter Selasky 	unsigned long last_moder_jiffies;
55797549c34SHans Petter Selasky 	int last_moder_time[MAX_RX_RINGS];
55897549c34SHans Petter Selasky 	u16 rx_usecs;
55997549c34SHans Petter Selasky 	u16 rx_frames;
56097549c34SHans Petter Selasky 	u16 tx_usecs;
56197549c34SHans Petter Selasky 	u16 tx_frames;
56297549c34SHans Petter Selasky 	u32 pkt_rate_low;
56397549c34SHans Petter Selasky 	u32 rx_usecs_low;
56497549c34SHans Petter Selasky 	u32 pkt_rate_high;
56597549c34SHans Petter Selasky 	u32 rx_usecs_high;
56697549c34SHans Petter Selasky 	u32 sample_interval;
56797549c34SHans Petter Selasky 	u32 adaptive_rx_coal;
56897549c34SHans Petter Selasky 	u32 msg_enable;
56997549c34SHans Petter Selasky 	u32 loopback_ok;
57097549c34SHans Petter Selasky 	u32 validate_loopback;
57197549c34SHans Petter Selasky 
57297549c34SHans Petter Selasky 	struct mlx4_hwq_resources res;
57397549c34SHans Petter Selasky 	int link_state;
57497549c34SHans Petter Selasky 	int last_link_state;
57597549c34SHans Petter Selasky 	bool port_up;
57697549c34SHans Petter Selasky 	int port;
57797549c34SHans Petter Selasky 	int registered;
578c3191c2eSHans Petter Selasky 	int gone;
57997549c34SHans Petter Selasky 	int allocated;
58097549c34SHans Petter Selasky 	unsigned char current_mac[ETH_ALEN + 2];
58197549c34SHans Petter Selasky         u64 mac;
58297549c34SHans Petter Selasky 	int mac_index;
58397549c34SHans Petter Selasky 	unsigned max_mtu;
58497549c34SHans Petter Selasky 	int base_qpn;
58597549c34SHans Petter Selasky 	int cqe_factor;
58697549c34SHans Petter Selasky 
58797549c34SHans Petter Selasky 	struct mlx4_en_rss_map rss_map;
58897549c34SHans Petter Selasky 	u32 flags;
58997549c34SHans Petter Selasky 	u8 num_tx_rings_p_up;
59097549c34SHans Petter Selasky 	u32 tx_ring_num;
59197549c34SHans Petter Selasky 	u32 rx_ring_num;
59297549c34SHans Petter Selasky 	u32 rx_mb_size;
59397549c34SHans Petter Selasky 
59497549c34SHans Petter Selasky 	struct mlx4_en_tx_ring **tx_ring;
59597549c34SHans Petter Selasky 	struct mlx4_en_rx_ring *rx_ring[MAX_RX_RINGS];
59697549c34SHans Petter Selasky 	struct mlx4_en_cq **tx_cq;
59797549c34SHans Petter Selasky 	struct mlx4_en_cq *rx_cq[MAX_RX_RINGS];
59897549c34SHans Petter Selasky 	struct mlx4_qp drop_qp;
59997549c34SHans Petter Selasky 	struct work_struct rx_mode_task;
60097549c34SHans Petter Selasky 	struct work_struct watchdog_task;
60197549c34SHans Petter Selasky 	struct work_struct linkstate_task;
60297549c34SHans Petter Selasky 	struct delayed_work stats_task;
60397549c34SHans Petter Selasky 	struct delayed_work service_task;
60497549c34SHans Petter Selasky 	struct mlx4_en_perf_stats pstats;
60597549c34SHans Petter Selasky 	struct mlx4_en_pkt_stats pkstats;
60697549c34SHans Petter Selasky 	struct mlx4_en_pkt_stats pkstats_last;
607c3191c2eSHans Petter Selasky 	struct mlx4_en_flow_stats_rx rx_priority_flowstats[MLX4_NUM_PRIORITIES];
608c3191c2eSHans Petter Selasky 	struct mlx4_en_flow_stats_tx tx_priority_flowstats[MLX4_NUM_PRIORITIES];
609c3191c2eSHans Petter Selasky 	struct mlx4_en_flow_stats_rx rx_flowstats;
610c3191c2eSHans Petter Selasky 	struct mlx4_en_flow_stats_tx tx_flowstats;
61197549c34SHans Petter Selasky 	struct mlx4_en_port_stats port_stats;
61297549c34SHans Petter Selasky 	struct mlx4_en_vport_stats vport_stats;
61397549c34SHans Petter Selasky 	struct mlx4_en_vf_stats vf_stats;
61497549c34SHans Petter Selasky 	struct list_head mc_list;
615c3191c2eSHans Petter Selasky 	struct list_head uc_list;
616c3191c2eSHans Petter Selasky 	struct list_head curr_mc_list;
617c3191c2eSHans Petter Selasky 	struct list_head curr_uc_list;
61897549c34SHans Petter Selasky 	u64 broadcast_id;
61997549c34SHans Petter Selasky 	struct mlx4_en_stat_out_mbox hw_stats;
62097549c34SHans Petter Selasky 	int vids[128];
62197549c34SHans Petter Selasky 	bool wol;
62297549c34SHans Petter Selasky 	struct device *ddev;
62397549c34SHans Petter Selasky 	struct dentry *dev_root;
62497549c34SHans Petter Selasky 	u32 counter_index;
62597549c34SHans Petter Selasky 	eventhandler_tag vlan_attach;
62697549c34SHans Petter Selasky 	eventhandler_tag vlan_detach;
62797549c34SHans Petter Selasky 	struct callout watchdog_timer;
62897549c34SHans Petter Selasky         struct ifmedia media;
62997549c34SHans Petter Selasky 	volatile int blocked;
630791c9d78SHans Petter Selasky 	struct sysctl_oid *conf_sysctl;
631791c9d78SHans Petter Selasky 	struct sysctl_oid *stat_sysctl;
63297549c34SHans Petter Selasky 	struct sysctl_ctx_list conf_ctx;
63397549c34SHans Petter Selasky 	struct sysctl_ctx_list stat_ctx;
63497549c34SHans Petter Selasky 
63597549c34SHans Petter Selasky #ifdef CONFIG_MLX4_EN_DCB
63697549c34SHans Petter Selasky 	struct ieee_ets ets;
63797549c34SHans Petter Selasky 	u16 maxrate[IEEE_8021QAZ_MAX_TCS];
63897549c34SHans Petter Selasky 	u8 dcbx_cap;
63997549c34SHans Petter Selasky #endif
64097549c34SHans Petter Selasky #ifdef CONFIG_RFS_ACCEL
64197549c34SHans Petter Selasky 	spinlock_t filters_lock;
64297549c34SHans Petter Selasky 	int last_filter_id;
64397549c34SHans Petter Selasky 	struct list_head filters;
64497549c34SHans Petter Selasky 	struct hlist_head filter_hash[1 << MLX4_EN_FILTER_HASH_SHIFT];
64597549c34SHans Petter Selasky #endif
646c3191c2eSHans Petter Selasky 	u64 tunnel_reg_id;
64797549c34SHans Petter Selasky 	struct en_port *vf_ports[MLX4_MAX_NUM_VF];
64897549c34SHans Petter Selasky 	unsigned long last_ifq_jiffies;
64997549c34SHans Petter Selasky 	u64 if_counters_rx_errors;
65097549c34SHans Petter Selasky 	u64 if_counters_rx_no_buffer;
65197549c34SHans Petter Selasky };
65297549c34SHans Petter Selasky 
65397549c34SHans Petter Selasky enum mlx4_en_wol {
65497549c34SHans Petter Selasky 	MLX4_EN_WOL_MAGIC = (1ULL << 61),
65597549c34SHans Petter Selasky 	MLX4_EN_WOL_ENABLED = (1ULL << 62),
65697549c34SHans Petter Selasky };
65797549c34SHans Petter Selasky 
65897549c34SHans Petter Selasky struct mlx4_mac_entry {
65997549c34SHans Petter Selasky 	struct hlist_node hlist;
66097549c34SHans Petter Selasky 	unsigned char mac[ETH_ALEN + 2];
66197549c34SHans Petter Selasky 	u64 reg_id;
66297549c34SHans Petter Selasky };
66397549c34SHans Petter Selasky 
664c35034b3SBjoern A. Zeeb static inline void *
mlx4_netdev_priv(const if_t dev)6650b281376SJustin Hibbits mlx4_netdev_priv(const if_t dev)
666c35034b3SBjoern A. Zeeb {
6670b281376SJustin Hibbits 	return (if_getsoftc(dev));
668c35034b3SBjoern A. Zeeb }
669c35034b3SBjoern A. Zeeb 
mlx4_en_get_cqe(u8 * buf,int idx,int cqe_sz)670c3191c2eSHans Petter Selasky static inline struct mlx4_cqe *mlx4_en_get_cqe(u8 *buf, int idx, int cqe_sz)
671c3191c2eSHans Petter Selasky {
672c3191c2eSHans Petter Selasky 	return (struct mlx4_cqe *)(buf + idx * cqe_sz);
673c3191c2eSHans Petter Selasky }
674c3191c2eSHans Petter Selasky 
67597549c34SHans Petter Selasky #ifdef CONFIG_NET_RX_BUSY_POLL
mlx4_en_cq_init_lock(struct mlx4_en_cq * cq)67697549c34SHans Petter Selasky static inline void mlx4_en_cq_init_lock(struct mlx4_en_cq *cq)
67797549c34SHans Petter Selasky {
67897549c34SHans Petter Selasky 	spin_lock_init(&cq->poll_lock);
679c3191c2eSHans Petter Selasky 	cq->state = MLX4_EN_CQ_STATE_IDLE;
68097549c34SHans Petter Selasky }
68197549c34SHans Petter Selasky 
68297549c34SHans Petter Selasky /* called from the device poll rutine to get ownership of a cq */
mlx4_en_cq_lock_napi(struct mlx4_en_cq * cq)68397549c34SHans Petter Selasky static inline bool mlx4_en_cq_lock_napi(struct mlx4_en_cq *cq)
68497549c34SHans Petter Selasky {
68597549c34SHans Petter Selasky 	int rc = true;
68697549c34SHans Petter Selasky 	spin_lock(&cq->poll_lock);
68797549c34SHans Petter Selasky 	if (cq->state & MLX4_CQ_LOCKED) {
688c3191c2eSHans Petter Selasky 		WARN_ON(cq->state & MLX4_EN_CQ_STATE_NAPI);
689c3191c2eSHans Petter Selasky 		cq->state |= MLX4_EN_CQ_STATE_NAPI_YIELD;
69097549c34SHans Petter Selasky 		rc = false;
69197549c34SHans Petter Selasky 	} else
69297549c34SHans Petter Selasky 		/* we don't care if someone yielded */
693c3191c2eSHans Petter Selasky 		cq->state = MLX4_EN_CQ_STATE_NAPI;
69497549c34SHans Petter Selasky 	spin_unlock(&cq->poll_lock);
69597549c34SHans Petter Selasky 	return rc;
69697549c34SHans Petter Selasky }
69797549c34SHans Petter Selasky 
69897549c34SHans Petter Selasky /* returns true is someone tried to get the cq while napi had it */
mlx4_en_cq_unlock_napi(struct mlx4_en_cq * cq)69997549c34SHans Petter Selasky static inline bool mlx4_en_cq_unlock_napi(struct mlx4_en_cq *cq)
70097549c34SHans Petter Selasky {
70197549c34SHans Petter Selasky 	int rc = false;
70297549c34SHans Petter Selasky 	spin_lock(&cq->poll_lock);
703c3191c2eSHans Petter Selasky 	WARN_ON(cq->state & (MLX4_EN_CQ_STATE_POLL |
704c3191c2eSHans Petter Selasky 			       MLX4_EN_CQ_STATE_NAPI_YIELD));
70597549c34SHans Petter Selasky 
706c3191c2eSHans Petter Selasky 	if (cq->state & MLX4_EN_CQ_STATE_POLL_YIELD)
70797549c34SHans Petter Selasky 		rc = true;
708c3191c2eSHans Petter Selasky 	cq->state = MLX4_EN_CQ_STATE_IDLE;
70997549c34SHans Petter Selasky 	spin_unlock(&cq->poll_lock);
71097549c34SHans Petter Selasky 	return rc;
71197549c34SHans Petter Selasky }
71297549c34SHans Petter Selasky 
71397549c34SHans Petter Selasky /* called from mlx4_en_low_latency_poll() */
mlx4_en_cq_lock_poll(struct mlx4_en_cq * cq)71497549c34SHans Petter Selasky static inline bool mlx4_en_cq_lock_poll(struct mlx4_en_cq *cq)
71597549c34SHans Petter Selasky {
71697549c34SHans Petter Selasky 	int rc = true;
71797549c34SHans Petter Selasky 	spin_lock_bh(&cq->poll_lock);
71897549c34SHans Petter Selasky 	if ((cq->state & MLX4_CQ_LOCKED)) {
7190b281376SJustin Hibbits 		if_t dev = cq->dev;
7209d593d5aSBjoern A. Zeeb 		struct mlx4_en_priv *priv = mlx4_netdev_priv(dev);
72197549c34SHans Petter Selasky 		struct mlx4_en_rx_ring *rx_ring = priv->rx_ring[cq->ring];
72297549c34SHans Petter Selasky 
723c3191c2eSHans Petter Selasky 		cq->state |= MLX4_EN_CQ_STATE_POLL_YIELD;
72497549c34SHans Petter Selasky 		rc = false;
72597549c34SHans Petter Selasky #ifdef LL_EXTENDED_STATS
72697549c34SHans Petter Selasky 		rx_ring->yields++;
72797549c34SHans Petter Selasky #endif
72897549c34SHans Petter Selasky 	} else
72997549c34SHans Petter Selasky 		/* preserve yield marks */
730c3191c2eSHans Petter Selasky 		cq->state |= MLX4_EN_CQ_STATE_POLL;
73197549c34SHans Petter Selasky 	spin_unlock_bh(&cq->poll_lock);
73297549c34SHans Petter Selasky 	return rc;
73397549c34SHans Petter Selasky }
73497549c34SHans Petter Selasky 
73597549c34SHans Petter Selasky /* returns true if someone tried to get the cq while it was locked */
mlx4_en_cq_unlock_poll(struct mlx4_en_cq * cq)73697549c34SHans Petter Selasky static inline bool mlx4_en_cq_unlock_poll(struct mlx4_en_cq *cq)
73797549c34SHans Petter Selasky {
73897549c34SHans Petter Selasky 	int rc = false;
73997549c34SHans Petter Selasky 	spin_lock_bh(&cq->poll_lock);
740c3191c2eSHans Petter Selasky 	WARN_ON(cq->state & (MLX4_EN_CQ_STATE_NAPI));
74197549c34SHans Petter Selasky 
742c3191c2eSHans Petter Selasky 	if (cq->state & MLX4_EN_CQ_STATE_POLL_YIELD)
74397549c34SHans Petter Selasky 		rc = true;
744c3191c2eSHans Petter Selasky 	cq->state = MLX4_EN_CQ_STATE_IDLE;
74597549c34SHans Petter Selasky 	spin_unlock_bh(&cq->poll_lock);
74697549c34SHans Petter Selasky 	return rc;
74797549c34SHans Petter Selasky }
74897549c34SHans Petter Selasky 
74997549c34SHans Petter Selasky /* true if a socket is polling, even if it did not get the lock */
mlx4_en_cq_busy_polling(struct mlx4_en_cq * cq)750c3191c2eSHans Petter Selasky static inline bool mlx4_en_cq_busy_polling(struct mlx4_en_cq *cq)
75197549c34SHans Petter Selasky {
75297549c34SHans Petter Selasky 	WARN_ON(!(cq->state & MLX4_CQ_LOCKED));
75397549c34SHans Petter Selasky 	return cq->state & CQ_USER_PEND;
75497549c34SHans Petter Selasky }
75597549c34SHans Petter Selasky #else
mlx4_en_cq_init_lock(struct mlx4_en_cq * cq)75697549c34SHans Petter Selasky static inline void mlx4_en_cq_init_lock(struct mlx4_en_cq *cq)
75797549c34SHans Petter Selasky {
75897549c34SHans Petter Selasky }
75997549c34SHans Petter Selasky 
mlx4_en_cq_lock_napi(struct mlx4_en_cq * cq)76097549c34SHans Petter Selasky static inline bool mlx4_en_cq_lock_napi(struct mlx4_en_cq *cq)
76197549c34SHans Petter Selasky {
76297549c34SHans Petter Selasky 	return true;
76397549c34SHans Petter Selasky }
76497549c34SHans Petter Selasky 
mlx4_en_cq_unlock_napi(struct mlx4_en_cq * cq)76597549c34SHans Petter Selasky static inline bool mlx4_en_cq_unlock_napi(struct mlx4_en_cq *cq)
76697549c34SHans Petter Selasky {
76797549c34SHans Petter Selasky 	return false;
76897549c34SHans Petter Selasky }
76997549c34SHans Petter Selasky 
mlx4_en_cq_lock_poll(struct mlx4_en_cq * cq)77097549c34SHans Petter Selasky static inline bool mlx4_en_cq_lock_poll(struct mlx4_en_cq *cq)
77197549c34SHans Petter Selasky {
77297549c34SHans Petter Selasky 	return false;
77397549c34SHans Petter Selasky }
77497549c34SHans Petter Selasky 
mlx4_en_cq_unlock_poll(struct mlx4_en_cq * cq)77597549c34SHans Petter Selasky static inline bool mlx4_en_cq_unlock_poll(struct mlx4_en_cq *cq)
77697549c34SHans Petter Selasky {
77797549c34SHans Petter Selasky 	return false;
77897549c34SHans Petter Selasky }
77997549c34SHans Petter Selasky 
mlx4_en_cq_busy_polling(struct mlx4_en_cq * cq)780c3191c2eSHans Petter Selasky static inline bool mlx4_en_cq_busy_polling(struct mlx4_en_cq *cq)
78197549c34SHans Petter Selasky {
78297549c34SHans Petter Selasky 	return false;
78397549c34SHans Petter Selasky }
78497549c34SHans Petter Selasky #endif /* CONFIG_NET_RX_BUSY_POLL */
78597549c34SHans Petter Selasky 
78697549c34SHans Petter Selasky #define MLX4_EN_WOL_DO_MODIFY (1ULL << 63)
78797549c34SHans Petter Selasky 
7880b281376SJustin Hibbits void mlx4_en_destroy_netdev(if_t dev);
78997549c34SHans Petter Selasky int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
79097549c34SHans Petter Selasky 			struct mlx4_en_port_profile *prof);
79197549c34SHans Petter Selasky 
7920b281376SJustin Hibbits int mlx4_en_start_port(if_t dev);
7930b281376SJustin Hibbits void mlx4_en_stop_port(if_t dev);
79497549c34SHans Petter Selasky 
79597549c34SHans Petter Selasky void mlx4_en_free_resources(struct mlx4_en_priv *priv);
79697549c34SHans Petter Selasky int mlx4_en_alloc_resources(struct mlx4_en_priv *priv);
79797549c34SHans Petter Selasky 
79897549c34SHans Petter Selasky int mlx4_en_pre_config(struct mlx4_en_priv *priv);
79997549c34SHans Petter Selasky int mlx4_en_create_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq,
80097549c34SHans Petter Selasky 		      int entries, int ring, enum cq_type mode, int node);
80197549c34SHans Petter Selasky void mlx4_en_destroy_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq);
80297549c34SHans Petter Selasky int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,
80397549c34SHans Petter Selasky 			int cq_idx);
80497549c34SHans Petter Selasky void mlx4_en_deactivate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
80597549c34SHans Petter Selasky int mlx4_en_set_cq_moder(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
80697549c34SHans Petter Selasky int mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
80797549c34SHans Petter Selasky 
80897549c34SHans Petter Selasky void mlx4_en_tx_irq(struct mlx4_cq *mcq);
8090b281376SJustin Hibbits u16 mlx4_en_select_queue(if_t dev, struct mbuf *mb);
81097549c34SHans Petter Selasky 
81163d7a8d9SSlava Shwartsman int mlx4_en_xmit(struct mlx4_en_priv *priv, int tx_ind, struct mbuf **mbp);
8120b281376SJustin Hibbits int mlx4_en_transmit(if_t dev, struct mbuf *m);
81397549c34SHans Petter Selasky int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
81497549c34SHans Petter Selasky 			   struct mlx4_en_tx_ring **pring,
81597549c34SHans Petter Selasky 			   u32 size, u16 stride, int node, int queue_idx);
81697549c34SHans Petter Selasky void mlx4_en_destroy_tx_ring(struct mlx4_en_priv *priv,
81797549c34SHans Petter Selasky 			     struct mlx4_en_tx_ring **pring);
81897549c34SHans Petter Selasky int mlx4_en_activate_tx_ring(struct mlx4_en_priv *priv,
81997549c34SHans Petter Selasky 			     struct mlx4_en_tx_ring *ring,
82097549c34SHans Petter Selasky 			     int cq, int user_prio);
82197549c34SHans Petter Selasky void mlx4_en_deactivate_tx_ring(struct mlx4_en_priv *priv,
82297549c34SHans Petter Selasky 				struct mlx4_en_tx_ring *ring);
823c3191c2eSHans Petter Selasky void mlx4_en_set_num_rx_rings(struct mlx4_en_dev *mdev);
8240b281376SJustin Hibbits void mlx4_en_qflush(if_t dev);
82597549c34SHans Petter Selasky 
82697549c34SHans Petter Selasky int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv,
82797549c34SHans Petter Selasky 			   struct mlx4_en_rx_ring **pring,
82897549c34SHans Petter Selasky 			   u32 size, int node);
82997549c34SHans Petter Selasky void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv,
83097549c34SHans Petter Selasky 			     struct mlx4_en_rx_ring **pring,
83193bf8216SSlava Shwartsman 			     u32 size);
83297549c34SHans Petter Selasky void mlx4_en_rx_que(void *context, int pending);
83397549c34SHans Petter Selasky int mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv);
83497549c34SHans Petter Selasky void mlx4_en_deactivate_rx_ring(struct mlx4_en_priv *priv,
83597549c34SHans Petter Selasky 				struct mlx4_en_rx_ring *ring);
8360b281376SJustin Hibbits int mlx4_en_process_rx_cq(if_t dev,
83797549c34SHans Petter Selasky 			  struct mlx4_en_cq *cq,
83897549c34SHans Petter Selasky 			  int budget);
83997549c34SHans Petter Selasky void mlx4_en_poll_tx_cq(unsigned long data);
84097549c34SHans Petter Selasky void mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
84197549c34SHans Petter Selasky 		int is_tx, int rss, int qpn, int cqn, int user_prio,
84297549c34SHans Petter Selasky 		struct mlx4_qp_context *context);
84397549c34SHans Petter Selasky void mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event);
84497549c34SHans Petter Selasky int mlx4_en_map_buffer(struct mlx4_buf *buf);
84597549c34SHans Petter Selasky void mlx4_en_unmap_buffer(struct mlx4_buf *buf);
8460b281376SJustin Hibbits void mlx4_en_calc_rx_buf(if_t dev);
84797549c34SHans Petter Selasky 
84829d6b8abSHans Petter Selasky const u32 *mlx4_en_get_rss_key(struct mlx4_en_priv *priv, u16 *keylen);
84929d6b8abSHans Petter Selasky u8 mlx4_en_get_rss_mask(struct mlx4_en_priv *priv);
85097549c34SHans Petter Selasky int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv);
85197549c34SHans Petter Selasky void mlx4_en_release_rss_steer(struct mlx4_en_priv *priv);
85297549c34SHans Petter Selasky int mlx4_en_create_drop_qp(struct mlx4_en_priv *priv);
85397549c34SHans Petter Selasky void mlx4_en_destroy_drop_qp(struct mlx4_en_priv *priv);
8540b281376SJustin Hibbits int mlx4_en_free_tx_buf(if_t dev, struct mlx4_en_tx_ring *ring);
85597549c34SHans Petter Selasky void mlx4_en_rx_irq(struct mlx4_cq *mcq);
85697549c34SHans Petter Selasky 
85797549c34SHans Petter Selasky int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, struct mlx4_en_priv *priv);
85897549c34SHans Petter Selasky 
85997549c34SHans Petter Selasky int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset);
86097549c34SHans Petter Selasky int mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port);
86197549c34SHans Petter Selasky int mlx4_en_get_vport_stats(struct mlx4_en_dev *mdev, u8 port);
86297549c34SHans Petter Selasky void mlx4_en_create_debug_files(struct mlx4_en_priv *priv);
86397549c34SHans Petter Selasky void mlx4_en_delete_debug_files(struct mlx4_en_priv *priv);
86497549c34SHans Petter Selasky int mlx4_en_register_debugfs(void);
86597549c34SHans Petter Selasky void mlx4_en_unregister_debugfs(void);
86697549c34SHans Petter Selasky 
86797549c34SHans Petter Selasky #ifdef CONFIG_MLX4_EN_DCB
86897549c34SHans Petter Selasky extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_ops;
86997549c34SHans Petter Selasky extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_pfc_ops;
87097549c34SHans Petter Selasky #endif
87197549c34SHans Petter Selasky 
8720b281376SJustin Hibbits int mlx4_en_setup_tc(if_t dev, u8 up);
87397549c34SHans Petter Selasky 
87497549c34SHans Petter Selasky #ifdef CONFIG_RFS_ACCEL
87597549c34SHans Petter Selasky void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv,
87697549c34SHans Petter Selasky 			     struct mlx4_en_rx_ring *rx_ring);
87797549c34SHans Petter Selasky #endif
87897549c34SHans Petter Selasky 
87997549c34SHans Petter Selasky #define MLX4_EN_NUM_SELF_TEST	5
8800b281376SJustin Hibbits void mlx4_en_ex_selftest(if_t dev, u32 *flags, u64 *buf);
88197549c34SHans Petter Selasky void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev);
88297549c34SHans Petter Selasky 
88397549c34SHans Petter Selasky /*
88497549c34SHans Petter Selasky  * Functions for time stamping
88597549c34SHans Petter Selasky  */
88697549c34SHans Petter Selasky #define SKBTX_HW_TSTAMP (1 << 0)
88797549c34SHans Petter Selasky #define SKBTX_IN_PROGRESS (1 << 2)
88897549c34SHans Petter Selasky 
88997549c34SHans Petter Selasky u64 mlx4_en_get_cqe_ts(struct mlx4_cqe *cqe);
89097549c34SHans Petter Selasky 
89197549c34SHans Petter Selasky /* Functions for caching and restoring statistics */
8920b281376SJustin Hibbits int mlx4_en_get_sset_count(if_t dev, int sset);
89397549c34SHans Petter Selasky void mlx4_en_restore_ethtool_stats(struct mlx4_en_priv *priv,
89497549c34SHans Petter Selasky 				    u64 *data);
89597549c34SHans Petter Selasky 
89697549c34SHans Petter Selasky /*
89797549c34SHans Petter Selasky  * Globals
89897549c34SHans Petter Selasky  */
89997549c34SHans Petter Selasky extern const struct ethtool_ops mlx4_en_ethtool_ops;
90097549c34SHans Petter Selasky 
90197549c34SHans Petter Selasky /*
90297549c34SHans Petter Selasky  * Defines for link speed - needed by selftest
90397549c34SHans Petter Selasky  */
90497549c34SHans Petter Selasky #define MLX4_EN_LINK_SPEED_1G	1000
90597549c34SHans Petter Selasky #define MLX4_EN_LINK_SPEED_10G	10000
90697549c34SHans Petter Selasky #define MLX4_EN_LINK_SPEED_40G	40000
90797549c34SHans Petter Selasky 
90897549c34SHans Petter Selasky enum {
90997549c34SHans Petter Selasky         NETIF_MSG_DRV           = 0x0001,
91097549c34SHans Petter Selasky         NETIF_MSG_PROBE         = 0x0002,
91197549c34SHans Petter Selasky         NETIF_MSG_LINK          = 0x0004,
91297549c34SHans Petter Selasky         NETIF_MSG_TIMER         = 0x0008,
91397549c34SHans Petter Selasky         NETIF_MSG_IFDOWN        = 0x0010,
91497549c34SHans Petter Selasky         NETIF_MSG_IFUP          = 0x0020,
91597549c34SHans Petter Selasky         NETIF_MSG_RX_ERR        = 0x0040,
91697549c34SHans Petter Selasky         NETIF_MSG_TX_ERR        = 0x0080,
91797549c34SHans Petter Selasky         NETIF_MSG_TX_QUEUED     = 0x0100,
91897549c34SHans Petter Selasky         NETIF_MSG_INTR          = 0x0200,
91997549c34SHans Petter Selasky         NETIF_MSG_TX_DONE       = 0x0400,
92097549c34SHans Petter Selasky         NETIF_MSG_RX_STATUS     = 0x0800,
92197549c34SHans Petter Selasky         NETIF_MSG_PKTDATA       = 0x1000,
92297549c34SHans Petter Selasky         NETIF_MSG_HW            = 0x2000,
92397549c34SHans Petter Selasky         NETIF_MSG_WOL           = 0x4000,
92497549c34SHans Petter Selasky };
92597549c34SHans Petter Selasky 
92697549c34SHans Petter Selasky 
92797549c34SHans Petter Selasky /*
92897549c34SHans Petter Selasky  * printk / logging functions
92997549c34SHans Petter Selasky  */
93097549c34SHans Petter Selasky 
93197549c34SHans Petter Selasky #define en_print(level, priv, format, arg...)                   \
93297549c34SHans Petter Selasky         {                                                       \
93397549c34SHans Petter Selasky         if ((priv)->registered)                                 \
93497549c34SHans Petter Selasky                 printk(level "%s: %s: " format, DRV_NAME,       \
9350b281376SJustin Hibbits                         if_name((priv)->dev), ## arg); \
93697549c34SHans Petter Selasky         else                                                    \
93797549c34SHans Petter Selasky                 printk(level "%s: %s: Port %d: " format,        \
938c3191c2eSHans Petter Selasky                         DRV_NAME, dev_name(&(priv)->mdev->pdev->dev), \
93997549c34SHans Petter Selasky                         (priv)->port, ## arg);                  \
94097549c34SHans Petter Selasky         }
94197549c34SHans Petter Selasky 
94297549c34SHans Petter Selasky 
94397549c34SHans Petter Selasky #define en_dbg(mlevel, priv, format, arg...)			\
94497549c34SHans Petter Selasky do {								\
94597549c34SHans Petter Selasky 	if (NETIF_MSG_##mlevel & priv->msg_enable)		\
94697549c34SHans Petter Selasky 		en_print(KERN_DEBUG, priv, format, ##arg);	\
94797549c34SHans Petter Selasky } while (0)
94897549c34SHans Petter Selasky #define en_warn(priv, format, arg...)			\
94997549c34SHans Petter Selasky 	en_print(KERN_WARNING, priv, format, ##arg)
95097549c34SHans Petter Selasky #define en_err(priv, format, arg...)			\
95197549c34SHans Petter Selasky 	en_print(KERN_ERR, priv, format, ##arg)
95297549c34SHans Petter Selasky #define en_info(priv, format, arg...)			\
95397549c34SHans Petter Selasky 	en_print(KERN_INFO, priv, format, ## arg)
95497549c34SHans Petter Selasky 
95597549c34SHans Petter Selasky #define mlx4_err(mdev, format, arg...)			\
95697549c34SHans Petter Selasky 	pr_err("%s %s: " format, DRV_NAME,		\
957c3191c2eSHans Petter Selasky 	       dev_name(&(mdev)->pdev->dev), ##arg)
95897549c34SHans Petter Selasky #define mlx4_info(mdev, format, arg...)			\
95997549c34SHans Petter Selasky 	pr_info("%s %s: " format, DRV_NAME,		\
960c3191c2eSHans Petter Selasky 		dev_name(&(mdev)->pdev->dev), ##arg)
96197549c34SHans Petter Selasky #define mlx4_warn(mdev, format, arg...)			\
96297549c34SHans Petter Selasky 	pr_warning("%s %s: " format, DRV_NAME,		\
963c3191c2eSHans Petter Selasky 		   dev_name(&(mdev)->pdev->dev), ##arg)
96497549c34SHans Petter Selasky 
96597549c34SHans Petter Selasky #endif
966