1adfc5217SJeff Kirsher /* bnx2x.h: Broadcom Everest network driver.
2adfc5217SJeff Kirsher  *
385b26ea1SAriel Elior  * Copyright (c) 2007-2012 Broadcom Corporation
4adfc5217SJeff Kirsher  *
5adfc5217SJeff Kirsher  * This program is free software; you can redistribute it and/or modify
6adfc5217SJeff Kirsher  * it under the terms of the GNU General Public License as published by
7adfc5217SJeff Kirsher  * the Free Software Foundation.
8adfc5217SJeff Kirsher  *
9adfc5217SJeff Kirsher  * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10adfc5217SJeff Kirsher  * Written by: Eliezer Tamir
11adfc5217SJeff Kirsher  * Based on code from Michael Chan's bnx2 driver
12adfc5217SJeff Kirsher  */
13adfc5217SJeff Kirsher 
14adfc5217SJeff Kirsher #ifndef BNX2X_H
15adfc5217SJeff Kirsher #define BNX2X_H
16adfc5217SJeff Kirsher #include <linux/netdevice.h>
17adfc5217SJeff Kirsher #include <linux/dma-mapping.h>
18adfc5217SJeff Kirsher #include <linux/types.h>
19adfc5217SJeff Kirsher 
20adfc5217SJeff Kirsher /* compilation time flags */
21adfc5217SJeff Kirsher 
22adfc5217SJeff Kirsher /* define this to make the driver freeze on error to allow getting debug info
23adfc5217SJeff Kirsher  * (you will need to reboot afterwards) */
24adfc5217SJeff Kirsher /* #define BNX2X_STOP_ON_ERROR */
25adfc5217SJeff Kirsher 
26e29ecd51SBarak Witkowski #define DRV_MODULE_VERSION      "1.72.50-0"
27e29ecd51SBarak Witkowski #define DRV_MODULE_RELDATE      "2012/04/23"
28adfc5217SJeff Kirsher #define BNX2X_BC_VER            0x040200
29adfc5217SJeff Kirsher 
30adfc5217SJeff Kirsher #if defined(CONFIG_DCB)
31adfc5217SJeff Kirsher #define BCM_DCBNL
32adfc5217SJeff Kirsher #endif
33b475d78fSYuval Mintz 
34b475d78fSYuval Mintz 
35b475d78fSYuval Mintz #include "bnx2x_hsi.h"
36b475d78fSYuval Mintz 
37adfc5217SJeff Kirsher #if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
38adfc5217SJeff Kirsher #define BCM_CNIC 1
39adfc5217SJeff Kirsher #include "../cnic_if.h"
40adfc5217SJeff Kirsher #endif
41adfc5217SJeff Kirsher 
42adfc5217SJeff Kirsher #ifdef BCM_CNIC
43adfc5217SJeff Kirsher #define BNX2X_MIN_MSIX_VEC_CNT 3
44adfc5217SJeff Kirsher #define BNX2X_MSIX_VEC_FP_START 2
45adfc5217SJeff Kirsher #else
46adfc5217SJeff Kirsher #define BNX2X_MIN_MSIX_VEC_CNT 2
47adfc5217SJeff Kirsher #define BNX2X_MSIX_VEC_FP_START 1
48adfc5217SJeff Kirsher #endif
49adfc5217SJeff Kirsher 
50adfc5217SJeff Kirsher #include <linux/mdio.h>
51adfc5217SJeff Kirsher 
52adfc5217SJeff Kirsher #include "bnx2x_reg.h"
53adfc5217SJeff Kirsher #include "bnx2x_fw_defs.h"
54adfc5217SJeff Kirsher #include "bnx2x_hsi.h"
55adfc5217SJeff Kirsher #include "bnx2x_link.h"
56adfc5217SJeff Kirsher #include "bnx2x_sp.h"
57adfc5217SJeff Kirsher #include "bnx2x_dcb.h"
58adfc5217SJeff Kirsher #include "bnx2x_stats.h"
59adfc5217SJeff Kirsher 
60adfc5217SJeff Kirsher /* error/debug prints */
61adfc5217SJeff Kirsher 
62adfc5217SJeff Kirsher #define DRV_MODULE_NAME		"bnx2x"
63adfc5217SJeff Kirsher 
64adfc5217SJeff Kirsher /* for messages that are currently off */
6551c1a580SMerav Sicron #define BNX2X_MSG_OFF			0x0
6651c1a580SMerav Sicron #define BNX2X_MSG_MCP			0x0010000 /* was: NETIF_MSG_HW */
6751c1a580SMerav Sicron #define BNX2X_MSG_STATS			0x0020000 /* was: NETIF_MSG_TIMER */
6851c1a580SMerav Sicron #define BNX2X_MSG_NVM			0x0040000 /* was: NETIF_MSG_HW */
6951c1a580SMerav Sicron #define BNX2X_MSG_DMAE			0x0080000 /* was: NETIF_MSG_HW */
7051c1a580SMerav Sicron #define BNX2X_MSG_SP			0x0100000 /* was: NETIF_MSG_INTR */
7151c1a580SMerav Sicron #define BNX2X_MSG_FP			0x0200000 /* was: NETIF_MSG_INTR */
7251c1a580SMerav Sicron #define BNX2X_MSG_IOV			0x0800000
7351c1a580SMerav Sicron #define BNX2X_MSG_IDLE			0x2000000 /* used for idle check*/
7451c1a580SMerav Sicron #define BNX2X_MSG_ETHTOOL		0x4000000
7551c1a580SMerav Sicron #define BNX2X_MSG_DCB			0x8000000
76adfc5217SJeff Kirsher 
77adfc5217SJeff Kirsher /* regular debug print */
78f1deab50SJoe Perches #define DP(__mask, fmt, ...)					\
79adfc5217SJeff Kirsher do {								\
8051c1a580SMerav Sicron 	if (unlikely(bp->msg_enable & (__mask)))		\
81f1deab50SJoe Perches 		pr_notice("[%s:%d(%s)]" fmt,			\
82adfc5217SJeff Kirsher 			  __func__, __LINE__,			\
83adfc5217SJeff Kirsher 			  bp->dev ? (bp->dev->name) : "?",	\
84f1deab50SJoe Perches 			  ##__VA_ARGS__);			\
85adfc5217SJeff Kirsher } while (0)
86adfc5217SJeff Kirsher 
87f1deab50SJoe Perches #define DP_CONT(__mask, fmt, ...)				\
88adfc5217SJeff Kirsher do {								\
8951c1a580SMerav Sicron 	if (unlikely(bp->msg_enable & (__mask)))		\
90f1deab50SJoe Perches 		pr_cont(fmt, ##__VA_ARGS__);			\
91adfc5217SJeff Kirsher } while (0)
92adfc5217SJeff Kirsher 
93adfc5217SJeff Kirsher /* errors debug print */
94f1deab50SJoe Perches #define BNX2X_DBG_ERR(fmt, ...)					\
95adfc5217SJeff Kirsher do {								\
9651c1a580SMerav Sicron 	if (unlikely(netif_msg_probe(bp)))			\
97f1deab50SJoe Perches 		pr_err("[%s:%d(%s)]" fmt,			\
98adfc5217SJeff Kirsher 		       __func__, __LINE__,			\
99adfc5217SJeff Kirsher 		       bp->dev ? (bp->dev->name) : "?",		\
100f1deab50SJoe Perches 		       ##__VA_ARGS__);				\
101adfc5217SJeff Kirsher } while (0)
102adfc5217SJeff Kirsher 
103adfc5217SJeff Kirsher /* for errors (never masked) */
104f1deab50SJoe Perches #define BNX2X_ERR(fmt, ...)					\
105adfc5217SJeff Kirsher do {								\
106f1deab50SJoe Perches 	pr_err("[%s:%d(%s)]" fmt,				\
107adfc5217SJeff Kirsher 	       __func__, __LINE__,				\
108adfc5217SJeff Kirsher 	       bp->dev ? (bp->dev->name) : "?",			\
109f1deab50SJoe Perches 	       ##__VA_ARGS__);					\
110adfc5217SJeff Kirsher } while (0)
111adfc5217SJeff Kirsher 
112f1deab50SJoe Perches #define BNX2X_ERROR(fmt, ...)					\
113f1deab50SJoe Perches 	pr_err("[%s:%d]" fmt, __func__, __LINE__, ##__VA_ARGS__)
114adfc5217SJeff Kirsher 
115adfc5217SJeff Kirsher 
116adfc5217SJeff Kirsher /* before we have a dev->name use dev_info() */
117f1deab50SJoe Perches #define BNX2X_DEV_INFO(fmt, ...)				 \
118adfc5217SJeff Kirsher do {								 \
11951c1a580SMerav Sicron 	if (unlikely(netif_msg_probe(bp)))			 \
120f1deab50SJoe Perches 		dev_info(&bp->pdev->dev, fmt, ##__VA_ARGS__);	 \
121adfc5217SJeff Kirsher } while (0)
122adfc5217SJeff Kirsher 
123adfc5217SJeff Kirsher #ifdef BNX2X_STOP_ON_ERROR
124adfc5217SJeff Kirsher void bnx2x_int_disable(struct bnx2x *bp);
125f1deab50SJoe Perches #define bnx2x_panic()				\
126f1deab50SJoe Perches do {						\
127adfc5217SJeff Kirsher 	bp->panic = 1;				\
128adfc5217SJeff Kirsher 	BNX2X_ERR("driver assert\n");		\
129adfc5217SJeff Kirsher 	bnx2x_int_disable(bp);			\
130adfc5217SJeff Kirsher 	bnx2x_panic_dump(bp);			\
131adfc5217SJeff Kirsher } while (0)
132adfc5217SJeff Kirsher #else
133f1deab50SJoe Perches #define bnx2x_panic()				\
134f1deab50SJoe Perches do {						\
135adfc5217SJeff Kirsher 	bp->panic = 1;				\
136adfc5217SJeff Kirsher 	BNX2X_ERR("driver assert\n");		\
137adfc5217SJeff Kirsher 	bnx2x_panic_dump(bp);			\
138adfc5217SJeff Kirsher } while (0)
139adfc5217SJeff Kirsher #endif
140adfc5217SJeff Kirsher 
141adfc5217SJeff Kirsher #define bnx2x_mc_addr(ha)      ((ha)->addr)
142adfc5217SJeff Kirsher #define bnx2x_uc_addr(ha)      ((ha)->addr)
143adfc5217SJeff Kirsher 
144adfc5217SJeff Kirsher #define U64_LO(x)			(u32)(((u64)(x)) & 0xffffffff)
145adfc5217SJeff Kirsher #define U64_HI(x)			(u32)(((u64)(x)) >> 32)
146adfc5217SJeff Kirsher #define HILO_U64(hi, lo)		((((u64)(hi)) << 32) + (lo))
147adfc5217SJeff Kirsher 
148adfc5217SJeff Kirsher 
149adfc5217SJeff Kirsher #define REG_ADDR(bp, offset)		((bp->regview) + (offset))
150adfc5217SJeff Kirsher 
151adfc5217SJeff Kirsher #define REG_RD(bp, offset)		readl(REG_ADDR(bp, offset))
152adfc5217SJeff Kirsher #define REG_RD8(bp, offset)		readb(REG_ADDR(bp, offset))
153adfc5217SJeff Kirsher #define REG_RD16(bp, offset)		readw(REG_ADDR(bp, offset))
154adfc5217SJeff Kirsher 
155adfc5217SJeff Kirsher #define REG_WR(bp, offset, val)		writel((u32)val, REG_ADDR(bp, offset))
156adfc5217SJeff Kirsher #define REG_WR8(bp, offset, val)	writeb((u8)val, REG_ADDR(bp, offset))
157adfc5217SJeff Kirsher #define REG_WR16(bp, offset, val)	writew((u16)val, REG_ADDR(bp, offset))
158adfc5217SJeff Kirsher 
159adfc5217SJeff Kirsher #define REG_RD_IND(bp, offset)		bnx2x_reg_rd_ind(bp, offset)
160adfc5217SJeff Kirsher #define REG_WR_IND(bp, offset, val)	bnx2x_reg_wr_ind(bp, offset, val)
161adfc5217SJeff Kirsher 
162adfc5217SJeff Kirsher #define REG_RD_DMAE(bp, offset, valp, len32) \
163adfc5217SJeff Kirsher 	do { \
164adfc5217SJeff Kirsher 		bnx2x_read_dmae(bp, offset, len32);\
165adfc5217SJeff Kirsher 		memcpy(valp, bnx2x_sp(bp, wb_data[0]), (len32) * 4); \
166adfc5217SJeff Kirsher 	} while (0)
167adfc5217SJeff Kirsher 
168adfc5217SJeff Kirsher #define REG_WR_DMAE(bp, offset, valp, len32) \
169adfc5217SJeff Kirsher 	do { \
170adfc5217SJeff Kirsher 		memcpy(bnx2x_sp(bp, wb_data[0]), valp, (len32) * 4); \
171adfc5217SJeff Kirsher 		bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), \
172adfc5217SJeff Kirsher 				 offset, len32); \
173adfc5217SJeff Kirsher 	} while (0)
174adfc5217SJeff Kirsher 
175adfc5217SJeff Kirsher #define REG_WR_DMAE_LEN(bp, offset, valp, len32) \
176adfc5217SJeff Kirsher 	REG_WR_DMAE(bp, offset, valp, len32)
177adfc5217SJeff Kirsher 
178adfc5217SJeff Kirsher #define VIRT_WR_DMAE_LEN(bp, data, addr, len32, le32_swap) \
179adfc5217SJeff Kirsher 	do { \
180adfc5217SJeff Kirsher 		memcpy(GUNZIP_BUF(bp), data, (len32) * 4); \
181adfc5217SJeff Kirsher 		bnx2x_write_big_buf_wb(bp, addr, len32); \
182adfc5217SJeff Kirsher 	} while (0)
183adfc5217SJeff Kirsher 
184adfc5217SJeff Kirsher #define SHMEM_ADDR(bp, field)		(bp->common.shmem_base + \
185adfc5217SJeff Kirsher 					 offsetof(struct shmem_region, field))
186adfc5217SJeff Kirsher #define SHMEM_RD(bp, field)		REG_RD(bp, SHMEM_ADDR(bp, field))
187adfc5217SJeff Kirsher #define SHMEM_WR(bp, field, val)	REG_WR(bp, SHMEM_ADDR(bp, field), val)
188adfc5217SJeff Kirsher 
189adfc5217SJeff Kirsher #define SHMEM2_ADDR(bp, field)		(bp->common.shmem2_base + \
190adfc5217SJeff Kirsher 					 offsetof(struct shmem2_region, field))
191adfc5217SJeff Kirsher #define SHMEM2_RD(bp, field)		REG_RD(bp, SHMEM2_ADDR(bp, field))
192adfc5217SJeff Kirsher #define SHMEM2_WR(bp, field, val)	REG_WR(bp, SHMEM2_ADDR(bp, field), val)
193adfc5217SJeff Kirsher #define MF_CFG_ADDR(bp, field)		(bp->common.mf_cfg_base + \
194adfc5217SJeff Kirsher 					 offsetof(struct mf_cfg, field))
195adfc5217SJeff Kirsher #define MF2_CFG_ADDR(bp, field)		(bp->common.mf2_cfg_base + \
196adfc5217SJeff Kirsher 					 offsetof(struct mf2_cfg, field))
197adfc5217SJeff Kirsher 
198adfc5217SJeff Kirsher #define MF_CFG_RD(bp, field)		REG_RD(bp, MF_CFG_ADDR(bp, field))
199adfc5217SJeff Kirsher #define MF_CFG_WR(bp, field, val)	REG_WR(bp,\
200adfc5217SJeff Kirsher 					       MF_CFG_ADDR(bp, field), (val))
201adfc5217SJeff Kirsher #define MF2_CFG_RD(bp, field)		REG_RD(bp, MF2_CFG_ADDR(bp, field))
202adfc5217SJeff Kirsher 
203adfc5217SJeff Kirsher #define SHMEM2_HAS(bp, field)		((bp)->common.shmem2_base &&	\
204adfc5217SJeff Kirsher 					 (SHMEM2_RD((bp), size) >	\
205adfc5217SJeff Kirsher 					 offsetof(struct shmem2_region, field)))
206adfc5217SJeff Kirsher 
207adfc5217SJeff Kirsher #define EMAC_RD(bp, reg)		REG_RD(bp, emac_base + reg)
208adfc5217SJeff Kirsher #define EMAC_WR(bp, reg, val)		REG_WR(bp, emac_base + reg, val)
209adfc5217SJeff Kirsher 
210adfc5217SJeff Kirsher /* SP SB indices */
211adfc5217SJeff Kirsher 
212adfc5217SJeff Kirsher /* General SP events - stats query, cfc delete, etc  */
213adfc5217SJeff Kirsher #define HC_SP_INDEX_ETH_DEF_CONS		3
214adfc5217SJeff Kirsher 
215adfc5217SJeff Kirsher /* EQ completions */
216adfc5217SJeff Kirsher #define HC_SP_INDEX_EQ_CONS			7
217adfc5217SJeff Kirsher 
218adfc5217SJeff Kirsher /* FCoE L2 connection completions */
219adfc5217SJeff Kirsher #define HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS		6
220adfc5217SJeff Kirsher #define HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS		4
221adfc5217SJeff Kirsher /* iSCSI L2 */
222adfc5217SJeff Kirsher #define HC_SP_INDEX_ETH_ISCSI_CQ_CONS		5
223adfc5217SJeff Kirsher #define HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS	1
224adfc5217SJeff Kirsher 
225adfc5217SJeff Kirsher /* Special clients parameters */
226adfc5217SJeff Kirsher 
227adfc5217SJeff Kirsher /* SB indices */
228adfc5217SJeff Kirsher /* FCoE L2 */
229adfc5217SJeff Kirsher #define BNX2X_FCOE_L2_RX_INDEX \
230adfc5217SJeff Kirsher 	(&bp->def_status_blk->sp_sb.\
231adfc5217SJeff Kirsher 	index_values[HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS])
232adfc5217SJeff Kirsher 
233adfc5217SJeff Kirsher #define BNX2X_FCOE_L2_TX_INDEX \
234adfc5217SJeff Kirsher 	(&bp->def_status_blk->sp_sb.\
235adfc5217SJeff Kirsher 	index_values[HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS])
236adfc5217SJeff Kirsher 
237adfc5217SJeff Kirsher /**
238adfc5217SJeff Kirsher  *  CIDs and CLIDs:
239adfc5217SJeff Kirsher  *  CLIDs below is a CLID for func 0, then the CLID for other
240adfc5217SJeff Kirsher  *  functions will be calculated by the formula:
241adfc5217SJeff Kirsher  *
242adfc5217SJeff Kirsher  *  FUNC_N_CLID_X = N * NUM_SPECIAL_CLIENTS + FUNC_0_CLID_X
243adfc5217SJeff Kirsher  *
244adfc5217SJeff Kirsher  */
2451805b2f0SDavid S. Miller enum {
2461805b2f0SDavid S. Miller 	BNX2X_ISCSI_ETH_CL_ID_IDX,
2471805b2f0SDavid S. Miller 	BNX2X_FCOE_ETH_CL_ID_IDX,
2481805b2f0SDavid S. Miller 	BNX2X_MAX_CNIC_ETH_CL_ID_IDX,
2491805b2f0SDavid S. Miller };
250adfc5217SJeff Kirsher 
25137ae41a9SMerav Sicron #define BNX2X_CNIC_START_ETH_CID(bp)	(BNX2X_NUM_NON_CNIC_QUEUES(bp) *\
25237ae41a9SMerav Sicron 					 (bp)->max_cos)
2531805b2f0SDavid S. Miller 	/* iSCSI L2 */
25437ae41a9SMerav Sicron #define	BNX2X_ISCSI_ETH_CID(bp)		(BNX2X_CNIC_START_ETH_CID(bp))
255adfc5217SJeff Kirsher 	/* FCoE L2 */
25637ae41a9SMerav Sicron #define	BNX2X_FCOE_ETH_CID(bp)		(BNX2X_CNIC_START_ETH_CID(bp) + 1)
257adfc5217SJeff Kirsher 
258adfc5217SJeff Kirsher /** Additional rings budgeting */
259adfc5217SJeff Kirsher #ifdef BCM_CNIC
260adfc5217SJeff Kirsher #define CNIC_PRESENT			1
261adfc5217SJeff Kirsher #define FCOE_PRESENT			1
262adfc5217SJeff Kirsher #else
263adfc5217SJeff Kirsher #define CNIC_PRESENT			0
264adfc5217SJeff Kirsher #define FCOE_PRESENT			0
265adfc5217SJeff Kirsher #endif /* BCM_CNIC */
266adfc5217SJeff Kirsher #define NON_ETH_CONTEXT_USE	(FCOE_PRESENT)
267adfc5217SJeff Kirsher 
268adfc5217SJeff Kirsher #define AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR \
269adfc5217SJeff Kirsher 	AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR
270adfc5217SJeff Kirsher 
271adfc5217SJeff Kirsher #define SM_RX_ID			0
272adfc5217SJeff Kirsher #define SM_TX_ID			1
273adfc5217SJeff Kirsher 
274adfc5217SJeff Kirsher /* defines for multiple tx priority indices */
275adfc5217SJeff Kirsher #define FIRST_TX_ONLY_COS_INDEX		1
276adfc5217SJeff Kirsher #define FIRST_TX_COS_INDEX		0
277adfc5217SJeff Kirsher 
278adfc5217SJeff Kirsher /* rules for calculating the cids of tx-only connections */
27965565884SMerav Sicron #define CID_TO_FP(cid, bp)		((cid) % BNX2X_NUM_NON_CNIC_QUEUES(bp))
28065565884SMerav Sicron #define CID_COS_TO_TX_ONLY_CID(cid, cos, bp) \
28165565884SMerav Sicron 				(cid + cos * BNX2X_NUM_NON_CNIC_QUEUES(bp))
282adfc5217SJeff Kirsher 
283adfc5217SJeff Kirsher /* fp index inside class of service range */
28465565884SMerav Sicron #define FP_COS_TO_TXQ(fp, cos, bp) \
28565565884SMerav Sicron 			((fp)->index + cos * BNX2X_NUM_NON_CNIC_QUEUES(bp))
286adfc5217SJeff Kirsher 
28765565884SMerav Sicron /* Indexes for transmission queues array:
28865565884SMerav Sicron  * txdata for RSS i CoS j is at location i + (j * num of RSS)
28965565884SMerav Sicron  * txdata for FCoE (if exist) is at location max cos * num of RSS
29065565884SMerav Sicron  * txdata for FWD (if exist) is one location after FCoE
29165565884SMerav Sicron  * txdata for OOO (if exist) is one location after FWD
292adfc5217SJeff Kirsher  */
29365565884SMerav Sicron enum {
29465565884SMerav Sicron 	FCOE_TXQ_IDX_OFFSET,
29565565884SMerav Sicron 	FWD_TXQ_IDX_OFFSET,
29665565884SMerav Sicron 	OOO_TXQ_IDX_OFFSET,
29765565884SMerav Sicron };
29865565884SMerav Sicron #define MAX_ETH_TXQ_IDX(bp)	(BNX2X_NUM_NON_CNIC_QUEUES(bp) * (bp)->max_cos)
29965565884SMerav Sicron #ifdef BCM_CNIC
30065565884SMerav Sicron #define FCOE_TXQ_IDX(bp)	(MAX_ETH_TXQ_IDX(bp) + FCOE_TXQ_IDX_OFFSET)
30165565884SMerav Sicron #endif
302adfc5217SJeff Kirsher 
303adfc5217SJeff Kirsher /* fast path */
304e52fcb24SEric Dumazet /*
305e52fcb24SEric Dumazet  * This driver uses new build_skb() API :
306e52fcb24SEric Dumazet  * RX ring buffer contains pointer to kmalloc() data only,
307e52fcb24SEric Dumazet  * skb are built only after Hardware filled the frame.
308e52fcb24SEric Dumazet  */
309adfc5217SJeff Kirsher struct sw_rx_bd {
310e52fcb24SEric Dumazet 	u8		*data;
311adfc5217SJeff Kirsher 	DEFINE_DMA_UNMAP_ADDR(mapping);
312adfc5217SJeff Kirsher };
313adfc5217SJeff Kirsher 
314adfc5217SJeff Kirsher struct sw_tx_bd {
315adfc5217SJeff Kirsher 	struct sk_buff	*skb;
316adfc5217SJeff Kirsher 	u16		first_bd;
317adfc5217SJeff Kirsher 	u8		flags;
318adfc5217SJeff Kirsher /* Set on the first BD descriptor when there is a split BD */
319adfc5217SJeff Kirsher #define BNX2X_TSO_SPLIT_BD		(1<<0)
320adfc5217SJeff Kirsher };
321adfc5217SJeff Kirsher 
322adfc5217SJeff Kirsher struct sw_rx_page {
323adfc5217SJeff Kirsher 	struct page	*page;
324adfc5217SJeff Kirsher 	DEFINE_DMA_UNMAP_ADDR(mapping);
325adfc5217SJeff Kirsher };
326adfc5217SJeff Kirsher 
327adfc5217SJeff Kirsher union db_prod {
328adfc5217SJeff Kirsher 	struct doorbell_set_prod data;
329adfc5217SJeff Kirsher 	u32		raw;
330adfc5217SJeff Kirsher };
331adfc5217SJeff Kirsher 
3328decf868SDavid S. Miller /* dropless fc FW/HW related params */
3338decf868SDavid S. Miller #define BRB_SIZE(bp)		(CHIP_IS_E3(bp) ? 1024 : 512)
3348decf868SDavid S. Miller #define MAX_AGG_QS(bp)		(CHIP_IS_E1(bp) ? \
3358decf868SDavid S. Miller 					ETH_MAX_AGGREGATION_QUEUES_E1 :\
3368decf868SDavid S. Miller 					ETH_MAX_AGGREGATION_QUEUES_E1H_E2)
3378decf868SDavid S. Miller #define FW_DROP_LEVEL(bp)	(3 + MAX_SPQ_PENDING + MAX_AGG_QS(bp))
3388decf868SDavid S. Miller #define FW_PREFETCH_CNT		16
3398decf868SDavid S. Miller #define DROPLESS_FC_HEADROOM	100
340adfc5217SJeff Kirsher 
341adfc5217SJeff Kirsher /* MC hsi */
342adfc5217SJeff Kirsher #define BCM_PAGE_SHIFT		12
343adfc5217SJeff Kirsher #define BCM_PAGE_SIZE		(1 << BCM_PAGE_SHIFT)
344adfc5217SJeff Kirsher #define BCM_PAGE_MASK		(~(BCM_PAGE_SIZE - 1))
345adfc5217SJeff Kirsher #define BCM_PAGE_ALIGN(addr)	(((addr) + BCM_PAGE_SIZE - 1) & BCM_PAGE_MASK)
346adfc5217SJeff Kirsher 
347adfc5217SJeff Kirsher #define PAGES_PER_SGE_SHIFT	0
348adfc5217SJeff Kirsher #define PAGES_PER_SGE		(1 << PAGES_PER_SGE_SHIFT)
349adfc5217SJeff Kirsher #define SGE_PAGE_SIZE		PAGE_SIZE
350adfc5217SJeff Kirsher #define SGE_PAGE_SHIFT		PAGE_SHIFT
351adfc5217SJeff Kirsher #define SGE_PAGE_ALIGN(addr)	PAGE_ALIGN((typeof(PAGE_SIZE))(addr))
352adfc5217SJeff Kirsher 
353adfc5217SJeff Kirsher /* SGE ring related macros */
354adfc5217SJeff Kirsher #define NUM_RX_SGE_PAGES	2
355adfc5217SJeff Kirsher #define RX_SGE_CNT		(BCM_PAGE_SIZE / sizeof(struct eth_rx_sge))
3568decf868SDavid S. Miller #define NEXT_PAGE_SGE_DESC_CNT	2
3578decf868SDavid S. Miller #define MAX_RX_SGE_CNT		(RX_SGE_CNT - NEXT_PAGE_SGE_DESC_CNT)
358adfc5217SJeff Kirsher /* RX_SGE_CNT is promised to be a power of 2 */
359adfc5217SJeff Kirsher #define RX_SGE_MASK		(RX_SGE_CNT - 1)
360adfc5217SJeff Kirsher #define NUM_RX_SGE		(RX_SGE_CNT * NUM_RX_SGE_PAGES)
361adfc5217SJeff Kirsher #define MAX_RX_SGE		(NUM_RX_SGE - 1)
362adfc5217SJeff Kirsher #define NEXT_SGE_IDX(x)		((((x) & RX_SGE_MASK) == \
3638decf868SDavid S. Miller 				  (MAX_RX_SGE_CNT - 1)) ? \
3648decf868SDavid S. Miller 					(x) + 1 + NEXT_PAGE_SGE_DESC_CNT : \
3658decf868SDavid S. Miller 					(x) + 1)
366adfc5217SJeff Kirsher #define RX_SGE(x)		((x) & MAX_RX_SGE)
367adfc5217SJeff Kirsher 
3688decf868SDavid S. Miller /*
3698decf868SDavid S. Miller  * Number of required  SGEs is the sum of two:
3708decf868SDavid S. Miller  * 1. Number of possible opened aggregations (next packet for
3718decf868SDavid S. Miller  *    these aggregations will probably consume SGE immidiatelly)
3728decf868SDavid S. Miller  * 2. Rest of BRB blocks divided by 2 (block will consume new SGE only
3738decf868SDavid S. Miller  *    after placement on BD for new TPA aggregation)
3748decf868SDavid S. Miller  *
3758decf868SDavid S. Miller  * Takes into account NEXT_PAGE_SGE_DESC_CNT "next" elements on each page
3768decf868SDavid S. Miller  */
3778decf868SDavid S. Miller #define NUM_SGE_REQ		(MAX_AGG_QS(bp) + \
3788decf868SDavid S. Miller 					(BRB_SIZE(bp) - MAX_AGG_QS(bp)) / 2)
3798decf868SDavid S. Miller #define NUM_SGE_PG_REQ		((NUM_SGE_REQ + MAX_RX_SGE_CNT - 1) / \
3808decf868SDavid S. Miller 						MAX_RX_SGE_CNT)
3818decf868SDavid S. Miller #define SGE_TH_LO(bp)		(NUM_SGE_REQ + \
3828decf868SDavid S. Miller 				 NUM_SGE_PG_REQ * NEXT_PAGE_SGE_DESC_CNT)
3838decf868SDavid S. Miller #define SGE_TH_HI(bp)		(SGE_TH_LO(bp) + DROPLESS_FC_HEADROOM)
3848decf868SDavid S. Miller 
385adfc5217SJeff Kirsher /* Manipulate a bit vector defined as an array of u64 */
386adfc5217SJeff Kirsher 
387adfc5217SJeff Kirsher /* Number of bits in one sge_mask array element */
388adfc5217SJeff Kirsher #define BIT_VEC64_ELEM_SZ		64
389adfc5217SJeff Kirsher #define BIT_VEC64_ELEM_SHIFT		6
390adfc5217SJeff Kirsher #define BIT_VEC64_ELEM_MASK		((u64)BIT_VEC64_ELEM_SZ - 1)
391adfc5217SJeff Kirsher 
392adfc5217SJeff Kirsher 
393adfc5217SJeff Kirsher #define __BIT_VEC64_SET_BIT(el, bit) \
394adfc5217SJeff Kirsher 	do { \
395adfc5217SJeff Kirsher 		el = ((el) | ((u64)0x1 << (bit))); \
396adfc5217SJeff Kirsher 	} while (0)
397adfc5217SJeff Kirsher 
398adfc5217SJeff Kirsher #define __BIT_VEC64_CLEAR_BIT(el, bit) \
399adfc5217SJeff Kirsher 	do { \
400adfc5217SJeff Kirsher 		el = ((el) & (~((u64)0x1 << (bit)))); \
401adfc5217SJeff Kirsher 	} while (0)
402adfc5217SJeff Kirsher 
403adfc5217SJeff Kirsher 
404adfc5217SJeff Kirsher #define BIT_VEC64_SET_BIT(vec64, idx) \
405adfc5217SJeff Kirsher 	__BIT_VEC64_SET_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
406adfc5217SJeff Kirsher 			   (idx) & BIT_VEC64_ELEM_MASK)
407adfc5217SJeff Kirsher 
408adfc5217SJeff Kirsher #define BIT_VEC64_CLEAR_BIT(vec64, idx) \
409adfc5217SJeff Kirsher 	__BIT_VEC64_CLEAR_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
410adfc5217SJeff Kirsher 			     (idx) & BIT_VEC64_ELEM_MASK)
411adfc5217SJeff Kirsher 
412adfc5217SJeff Kirsher #define BIT_VEC64_TEST_BIT(vec64, idx) \
413adfc5217SJeff Kirsher 	(((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT] >> \
414adfc5217SJeff Kirsher 	((idx) & BIT_VEC64_ELEM_MASK)) & 0x1)
415adfc5217SJeff Kirsher 
416adfc5217SJeff Kirsher /* Creates a bitmask of all ones in less significant bits.
417adfc5217SJeff Kirsher    idx - index of the most significant bit in the created mask */
418adfc5217SJeff Kirsher #define BIT_VEC64_ONES_MASK(idx) \
419adfc5217SJeff Kirsher 		(((u64)0x1 << (((idx) & BIT_VEC64_ELEM_MASK) + 1)) - 1)
420adfc5217SJeff Kirsher #define BIT_VEC64_ELEM_ONE_MASK	((u64)(~0))
421adfc5217SJeff Kirsher 
422adfc5217SJeff Kirsher /*******************************************************/
423adfc5217SJeff Kirsher 
424adfc5217SJeff Kirsher 
425adfc5217SJeff Kirsher 
426adfc5217SJeff Kirsher /* Number of u64 elements in SGE mask array */
427b3637827SDmitry Kravkov #define RX_SGE_MASK_LEN			(NUM_RX_SGE / BIT_VEC64_ELEM_SZ)
428adfc5217SJeff Kirsher #define RX_SGE_MASK_LEN_MASK		(RX_SGE_MASK_LEN - 1)
429adfc5217SJeff Kirsher #define NEXT_SGE_MASK_ELEM(el)		(((el) + 1) & RX_SGE_MASK_LEN_MASK)
430adfc5217SJeff Kirsher 
431adfc5217SJeff Kirsher union host_hc_status_block {
432adfc5217SJeff Kirsher 	/* pointer to fp status block e1x */
433adfc5217SJeff Kirsher 	struct host_hc_status_block_e1x *e1x_sb;
434adfc5217SJeff Kirsher 	/* pointer to fp status block e2 */
435adfc5217SJeff Kirsher 	struct host_hc_status_block_e2  *e2_sb;
436adfc5217SJeff Kirsher };
437adfc5217SJeff Kirsher 
438adfc5217SJeff Kirsher struct bnx2x_agg_info {
439adfc5217SJeff Kirsher 	/*
440e52fcb24SEric Dumazet 	 * First aggregation buffer is a data buffer, the following - are pages.
441e52fcb24SEric Dumazet 	 * We will preallocate the data buffer for each aggregation when
442adfc5217SJeff Kirsher 	 * we open the interface and will replace the BD at the consumer
443adfc5217SJeff Kirsher 	 * with this one when we receive the TPA_START CQE in order to
444adfc5217SJeff Kirsher 	 * keep the Rx BD ring consistent.
445adfc5217SJeff Kirsher 	 */
446adfc5217SJeff Kirsher 	struct sw_rx_bd		first_buf;
447adfc5217SJeff Kirsher 	u8			tpa_state;
448adfc5217SJeff Kirsher #define BNX2X_TPA_START			1
449adfc5217SJeff Kirsher #define BNX2X_TPA_STOP			2
450adfc5217SJeff Kirsher #define BNX2X_TPA_ERROR			3
451adfc5217SJeff Kirsher 	u8			placement_offset;
452adfc5217SJeff Kirsher 	u16			parsing_flags;
453adfc5217SJeff Kirsher 	u16			vlan_tag;
454adfc5217SJeff Kirsher 	u16			len_on_bd;
455e52fcb24SEric Dumazet 	u32			rxhash;
456621b4d66SDmitry Kravkov 	u16			gro_size;
457621b4d66SDmitry Kravkov 	u16			full_page;
458adfc5217SJeff Kirsher };
459adfc5217SJeff Kirsher 
460adfc5217SJeff Kirsher #define Q_STATS_OFFSET32(stat_name) \
461adfc5217SJeff Kirsher 			(offsetof(struct bnx2x_eth_q_stats, stat_name) / 4)
462adfc5217SJeff Kirsher 
463adfc5217SJeff Kirsher struct bnx2x_fp_txdata {
464adfc5217SJeff Kirsher 
465adfc5217SJeff Kirsher 	struct sw_tx_bd		*tx_buf_ring;
466adfc5217SJeff Kirsher 
467adfc5217SJeff Kirsher 	union eth_tx_bd_types	*tx_desc_ring;
468adfc5217SJeff Kirsher 	dma_addr_t		tx_desc_mapping;
469adfc5217SJeff Kirsher 
470adfc5217SJeff Kirsher 	u32			cid;
471adfc5217SJeff Kirsher 
472adfc5217SJeff Kirsher 	union db_prod		tx_db;
473adfc5217SJeff Kirsher 
474adfc5217SJeff Kirsher 	u16			tx_pkt_prod;
475adfc5217SJeff Kirsher 	u16			tx_pkt_cons;
476adfc5217SJeff Kirsher 	u16			tx_bd_prod;
477adfc5217SJeff Kirsher 	u16			tx_bd_cons;
478adfc5217SJeff Kirsher 
479adfc5217SJeff Kirsher 	unsigned long		tx_pkt;
480adfc5217SJeff Kirsher 
481adfc5217SJeff Kirsher 	__le16			*tx_cons_sb;
482adfc5217SJeff Kirsher 
483adfc5217SJeff Kirsher 	int			txq_index;
48465565884SMerav Sicron 	struct bnx2x_fastpath	*parent_fp;
48565565884SMerav Sicron 	int			tx_ring_size;
486adfc5217SJeff Kirsher };
487adfc5217SJeff Kirsher 
488621b4d66SDmitry Kravkov enum bnx2x_tpa_mode_t {
489621b4d66SDmitry Kravkov 	TPA_MODE_LRO,
490621b4d66SDmitry Kravkov 	TPA_MODE_GRO
491621b4d66SDmitry Kravkov };
492621b4d66SDmitry Kravkov 
493adfc5217SJeff Kirsher struct bnx2x_fastpath {
494adfc5217SJeff Kirsher 	struct bnx2x		*bp; /* parent */
495adfc5217SJeff Kirsher 
496adfc5217SJeff Kirsher #define BNX2X_NAPI_WEIGHT       128
497adfc5217SJeff Kirsher 	struct napi_struct	napi;
498adfc5217SJeff Kirsher 	union host_hc_status_block	status_blk;
499adfc5217SJeff Kirsher 	/* chip independed shortcuts into sb structure */
500adfc5217SJeff Kirsher 	__le16			*sb_index_values;
501adfc5217SJeff Kirsher 	__le16			*sb_running_index;
502adfc5217SJeff Kirsher 	/* chip independed shortcut into rx_prods_offset memory */
503adfc5217SJeff Kirsher 	u32			ustorm_rx_prods_offset;
504adfc5217SJeff Kirsher 
505adfc5217SJeff Kirsher 	u32			rx_buf_size;
506adfc5217SJeff Kirsher 
507adfc5217SJeff Kirsher 	dma_addr_t		status_blk_mapping;
508adfc5217SJeff Kirsher 
509621b4d66SDmitry Kravkov 	enum bnx2x_tpa_mode_t	mode;
510621b4d66SDmitry Kravkov 
511adfc5217SJeff Kirsher 	u8			max_cos; /* actual number of active tx coses */
51265565884SMerav Sicron 	struct bnx2x_fp_txdata	*txdata_ptr[BNX2X_MULTI_TX_COS];
513adfc5217SJeff Kirsher 
514adfc5217SJeff Kirsher 	struct sw_rx_bd		*rx_buf_ring;	/* BDs mappings ring */
515adfc5217SJeff Kirsher 	struct sw_rx_page	*rx_page_ring;	/* SGE pages mappings ring */
516adfc5217SJeff Kirsher 
517adfc5217SJeff Kirsher 	struct eth_rx_bd	*rx_desc_ring;
518adfc5217SJeff Kirsher 	dma_addr_t		rx_desc_mapping;
519adfc5217SJeff Kirsher 
520adfc5217SJeff Kirsher 	union eth_rx_cqe	*rx_comp_ring;
521adfc5217SJeff Kirsher 	dma_addr_t		rx_comp_mapping;
522adfc5217SJeff Kirsher 
523adfc5217SJeff Kirsher 	/* SGE ring */
524adfc5217SJeff Kirsher 	struct eth_rx_sge	*rx_sge_ring;
525adfc5217SJeff Kirsher 	dma_addr_t		rx_sge_mapping;
526adfc5217SJeff Kirsher 
527adfc5217SJeff Kirsher 	u64			sge_mask[RX_SGE_MASK_LEN];
528adfc5217SJeff Kirsher 
529adfc5217SJeff Kirsher 	u32			cid;
530adfc5217SJeff Kirsher 
531adfc5217SJeff Kirsher 	__le16			fp_hc_idx;
532adfc5217SJeff Kirsher 
533adfc5217SJeff Kirsher 	u8			index;		/* number in fp array */
534f233cafeSDmitry Kravkov 	u8			rx_queue;	/* index for skb_record */
535adfc5217SJeff Kirsher 	u8			cl_id;		/* eth client id */
536adfc5217SJeff Kirsher 	u8			cl_qzone_id;
537adfc5217SJeff Kirsher 	u8			fw_sb_id;	/* status block number in FW */
538adfc5217SJeff Kirsher 	u8			igu_sb_id;	/* status block number in HW */
539adfc5217SJeff Kirsher 
540adfc5217SJeff Kirsher 	u16			rx_bd_prod;
541adfc5217SJeff Kirsher 	u16			rx_bd_cons;
542adfc5217SJeff Kirsher 	u16			rx_comp_prod;
543adfc5217SJeff Kirsher 	u16			rx_comp_cons;
544adfc5217SJeff Kirsher 	u16			rx_sge_prod;
545adfc5217SJeff Kirsher 	/* The last maximal completed SGE */
546adfc5217SJeff Kirsher 	u16			last_max_sge;
547adfc5217SJeff Kirsher 	__le16			*rx_cons_sb;
548adfc5217SJeff Kirsher 	unsigned long		rx_pkt,
549adfc5217SJeff Kirsher 				rx_calls;
550adfc5217SJeff Kirsher 
551adfc5217SJeff Kirsher 	/* TPA related */
55215192a8cSBarak Witkowski 	struct bnx2x_agg_info	*tpa_info;
553adfc5217SJeff Kirsher 	u8			disable_tpa;
554adfc5217SJeff Kirsher #ifdef BNX2X_STOP_ON_ERROR
555adfc5217SJeff Kirsher 	u64			tpa_queue_used;
556adfc5217SJeff Kirsher #endif
557adfc5217SJeff Kirsher 	/* The size is calculated using the following:
558adfc5217SJeff Kirsher 	     sizeof name field from netdev structure +
559adfc5217SJeff Kirsher 	     4 ('-Xx-' string) +
560adfc5217SJeff Kirsher 	     4 (for the digits and to make it DWORD aligned) */
561adfc5217SJeff Kirsher #define FP_NAME_SIZE		(sizeof(((struct net_device *)0)->name) + 8)
562adfc5217SJeff Kirsher 	char			name[FP_NAME_SIZE];
563adfc5217SJeff Kirsher };
564adfc5217SJeff Kirsher 
56515192a8cSBarak Witkowski #define bnx2x_fp(bp, nr, var)	((bp)->fp[(nr)].var)
56615192a8cSBarak Witkowski #define bnx2x_sp_obj(bp, fp)	((bp)->sp_objs[(fp)->index])
56715192a8cSBarak Witkowski #define bnx2x_fp_stats(bp, fp)	(&((bp)->fp_stats[(fp)->index]))
56815192a8cSBarak Witkowski #define bnx2x_fp_qstats(bp, fp)	(&((bp)->fp_stats[(fp)->index].eth_q_stats))
569adfc5217SJeff Kirsher 
570adfc5217SJeff Kirsher /* Use 2500 as a mini-jumbo MTU for FCoE */
571adfc5217SJeff Kirsher #define BNX2X_FCOE_MINI_JUMBO_MTU	2500
572adfc5217SJeff Kirsher 
57365565884SMerav Sicron #define	FCOE_IDX_OFFSET		0
57465565884SMerav Sicron 
57565565884SMerav Sicron #define FCOE_IDX(bp)		(BNX2X_NUM_NON_CNIC_QUEUES(bp) + \
57665565884SMerav Sicron 				 FCOE_IDX_OFFSET)
57765565884SMerav Sicron #define bnx2x_fcoe_fp(bp)	(&bp->fp[FCOE_IDX(bp)])
578adfc5217SJeff Kirsher #define bnx2x_fcoe(bp, var)	(bnx2x_fcoe_fp(bp)->var)
57915192a8cSBarak Witkowski #define bnx2x_fcoe_inner_sp_obj(bp)	(&bp->sp_objs[FCOE_IDX(bp)])
58015192a8cSBarak Witkowski #define bnx2x_fcoe_sp_obj(bp, var)	(bnx2x_fcoe_inner_sp_obj(bp)->var)
581adfc5217SJeff Kirsher #define bnx2x_fcoe_tx(bp, var)	(bnx2x_fcoe_fp(bp)-> \
58265565884SMerav Sicron 						txdata_ptr[FIRST_TX_COS_INDEX] \
58365565884SMerav Sicron 						->var)
584adfc5217SJeff Kirsher 
585adfc5217SJeff Kirsher 
586adfc5217SJeff Kirsher #define IS_ETH_FP(fp)			(fp->index < \
587adfc5217SJeff Kirsher 					 BNX2X_NUM_ETH_QUEUES(fp->bp))
588adfc5217SJeff Kirsher #ifdef BCM_CNIC
58965565884SMerav Sicron #define IS_FCOE_FP(fp)			(fp->index == FCOE_IDX(fp->bp))
59065565884SMerav Sicron #define IS_FCOE_IDX(idx)		((idx) == FCOE_IDX(bp))
591adfc5217SJeff Kirsher #else
592adfc5217SJeff Kirsher #define IS_FCOE_FP(fp)		false
593adfc5217SJeff Kirsher #define IS_FCOE_IDX(idx)	false
594adfc5217SJeff Kirsher #endif
595adfc5217SJeff Kirsher 
596adfc5217SJeff Kirsher 
597adfc5217SJeff Kirsher /* MC hsi */
598adfc5217SJeff Kirsher #define MAX_FETCH_BD		13	/* HW max BDs per packet */
599adfc5217SJeff Kirsher #define RX_COPY_THRESH		92
600adfc5217SJeff Kirsher 
601adfc5217SJeff Kirsher #define NUM_TX_RINGS		16
602adfc5217SJeff Kirsher #define TX_DESC_CNT		(BCM_PAGE_SIZE / sizeof(union eth_tx_bd_types))
6038decf868SDavid S. Miller #define NEXT_PAGE_TX_DESC_CNT	1
6048decf868SDavid S. Miller #define MAX_TX_DESC_CNT		(TX_DESC_CNT - NEXT_PAGE_TX_DESC_CNT)
605adfc5217SJeff Kirsher #define NUM_TX_BD		(TX_DESC_CNT * NUM_TX_RINGS)
606adfc5217SJeff Kirsher #define MAX_TX_BD		(NUM_TX_BD - 1)
607adfc5217SJeff Kirsher #define MAX_TX_AVAIL		(MAX_TX_DESC_CNT * NUM_TX_RINGS - 2)
608adfc5217SJeff Kirsher #define NEXT_TX_IDX(x)		((((x) & MAX_TX_DESC_CNT) == \
6098decf868SDavid S. Miller 				  (MAX_TX_DESC_CNT - 1)) ? \
6108decf868SDavid S. Miller 					(x) + 1 + NEXT_PAGE_TX_DESC_CNT : \
6118decf868SDavid S. Miller 					(x) + 1)
612adfc5217SJeff Kirsher #define TX_BD(x)		((x) & MAX_TX_BD)
613adfc5217SJeff Kirsher #define TX_BD_POFF(x)		((x) & MAX_TX_DESC_CNT)
614adfc5217SJeff Kirsher 
615adfc5217SJeff Kirsher /* The RX BD ring is special, each bd is 8 bytes but the last one is 16 */
616adfc5217SJeff Kirsher #define NUM_RX_RINGS		8
617adfc5217SJeff Kirsher #define RX_DESC_CNT		(BCM_PAGE_SIZE / sizeof(struct eth_rx_bd))
6188decf868SDavid S. Miller #define NEXT_PAGE_RX_DESC_CNT	2
6198decf868SDavid S. Miller #define MAX_RX_DESC_CNT		(RX_DESC_CNT - NEXT_PAGE_RX_DESC_CNT)
620adfc5217SJeff Kirsher #define RX_DESC_MASK		(RX_DESC_CNT - 1)
621adfc5217SJeff Kirsher #define NUM_RX_BD		(RX_DESC_CNT * NUM_RX_RINGS)
622adfc5217SJeff Kirsher #define MAX_RX_BD		(NUM_RX_BD - 1)
623adfc5217SJeff Kirsher #define MAX_RX_AVAIL		(MAX_RX_DESC_CNT * NUM_RX_RINGS - 2)
6248decf868SDavid S. Miller 
6258decf868SDavid S. Miller /* dropless fc calculations for BDs
6268decf868SDavid S. Miller  *
6278decf868SDavid S. Miller  * Number of BDs should as number of buffers in BRB:
6288decf868SDavid S. Miller  * Low threshold takes into account NEXT_PAGE_RX_DESC_CNT
6298decf868SDavid S. Miller  * "next" elements on each page
6308decf868SDavid S. Miller  */
6318decf868SDavid S. Miller #define NUM_BD_REQ		BRB_SIZE(bp)
6328decf868SDavid S. Miller #define NUM_BD_PG_REQ		((NUM_BD_REQ + MAX_RX_DESC_CNT - 1) / \
6338decf868SDavid S. Miller 					      MAX_RX_DESC_CNT)
6348decf868SDavid S. Miller #define BD_TH_LO(bp)		(NUM_BD_REQ + \
6358decf868SDavid S. Miller 				 NUM_BD_PG_REQ * NEXT_PAGE_RX_DESC_CNT + \
6368decf868SDavid S. Miller 				 FW_DROP_LEVEL(bp))
6378decf868SDavid S. Miller #define BD_TH_HI(bp)		(BD_TH_LO(bp) + DROPLESS_FC_HEADROOM)
6388decf868SDavid S. Miller 
6398decf868SDavid S. Miller #define MIN_RX_AVAIL		((bp)->dropless_fc ? BD_TH_HI(bp) + 128 : 128)
640adfc5217SJeff Kirsher 
641adfc5217SJeff Kirsher #define MIN_RX_SIZE_TPA_HW	(CHIP_IS_E1(bp) ? \
642adfc5217SJeff Kirsher 					ETH_MIN_RX_CQES_WITH_TPA_E1 : \
643adfc5217SJeff Kirsher 					ETH_MIN_RX_CQES_WITH_TPA_E1H_E2)
644adfc5217SJeff Kirsher #define MIN_RX_SIZE_NONTPA_HW   ETH_MIN_RX_CQES_WITHOUT_TPA
645adfc5217SJeff Kirsher #define MIN_RX_SIZE_TPA		(max_t(u32, MIN_RX_SIZE_TPA_HW, MIN_RX_AVAIL))
646adfc5217SJeff Kirsher #define MIN_RX_SIZE_NONTPA	(max_t(u32, MIN_RX_SIZE_NONTPA_HW,\
647adfc5217SJeff Kirsher 								MIN_RX_AVAIL))
648adfc5217SJeff Kirsher 
649adfc5217SJeff Kirsher #define NEXT_RX_IDX(x)		((((x) & RX_DESC_MASK) == \
6508decf868SDavid S. Miller 				  (MAX_RX_DESC_CNT - 1)) ? \
6518decf868SDavid S. Miller 					(x) + 1 + NEXT_PAGE_RX_DESC_CNT : \
6528decf868SDavid S. Miller 					(x) + 1)
653adfc5217SJeff Kirsher #define RX_BD(x)		((x) & MAX_RX_BD)
654adfc5217SJeff Kirsher 
655adfc5217SJeff Kirsher /*
656adfc5217SJeff Kirsher  * As long as CQE is X times bigger than BD entry we have to allocate X times
657adfc5217SJeff Kirsher  * more pages for CQ ring in order to keep it balanced with BD ring
658adfc5217SJeff Kirsher  */
659adfc5217SJeff Kirsher #define CQE_BD_REL	(sizeof(union eth_rx_cqe) / sizeof(struct eth_rx_bd))
660adfc5217SJeff Kirsher #define NUM_RCQ_RINGS		(NUM_RX_RINGS * CQE_BD_REL)
661adfc5217SJeff Kirsher #define RCQ_DESC_CNT		(BCM_PAGE_SIZE / sizeof(union eth_rx_cqe))
6628decf868SDavid S. Miller #define NEXT_PAGE_RCQ_DESC_CNT	1
6638decf868SDavid S. Miller #define MAX_RCQ_DESC_CNT	(RCQ_DESC_CNT - NEXT_PAGE_RCQ_DESC_CNT)
664adfc5217SJeff Kirsher #define NUM_RCQ_BD		(RCQ_DESC_CNT * NUM_RCQ_RINGS)
665adfc5217SJeff Kirsher #define MAX_RCQ_BD		(NUM_RCQ_BD - 1)
666adfc5217SJeff Kirsher #define MAX_RCQ_AVAIL		(MAX_RCQ_DESC_CNT * NUM_RCQ_RINGS - 2)
667adfc5217SJeff Kirsher #define NEXT_RCQ_IDX(x)		((((x) & MAX_RCQ_DESC_CNT) == \
6688decf868SDavid S. Miller 				  (MAX_RCQ_DESC_CNT - 1)) ? \
6698decf868SDavid S. Miller 					(x) + 1 + NEXT_PAGE_RCQ_DESC_CNT : \
6708decf868SDavid S. Miller 					(x) + 1)
671adfc5217SJeff Kirsher #define RCQ_BD(x)		((x) & MAX_RCQ_BD)
672adfc5217SJeff Kirsher 
6738decf868SDavid S. Miller /* dropless fc calculations for RCQs
6748decf868SDavid S. Miller  *
6758decf868SDavid S. Miller  * Number of RCQs should be as number of buffers in BRB:
6768decf868SDavid S. Miller  * Low threshold takes into account NEXT_PAGE_RCQ_DESC_CNT
6778decf868SDavid S. Miller  * "next" elements on each page
6788decf868SDavid S. Miller  */
6798decf868SDavid S. Miller #define NUM_RCQ_REQ		BRB_SIZE(bp)
6808decf868SDavid S. Miller #define NUM_RCQ_PG_REQ		((NUM_BD_REQ + MAX_RCQ_DESC_CNT - 1) / \
6818decf868SDavid S. Miller 					      MAX_RCQ_DESC_CNT)
6828decf868SDavid S. Miller #define RCQ_TH_LO(bp)		(NUM_RCQ_REQ + \
6838decf868SDavid S. Miller 				 NUM_RCQ_PG_REQ * NEXT_PAGE_RCQ_DESC_CNT + \
6848decf868SDavid S. Miller 				 FW_DROP_LEVEL(bp))
6858decf868SDavid S. Miller #define RCQ_TH_HI(bp)		(RCQ_TH_LO(bp) + DROPLESS_FC_HEADROOM)
6868decf868SDavid S. Miller 
687adfc5217SJeff Kirsher 
688adfc5217SJeff Kirsher /* This is needed for determining of last_max */
689adfc5217SJeff Kirsher #define SUB_S16(a, b)		(s16)((s16)(a) - (s16)(b))
690adfc5217SJeff Kirsher #define SUB_S32(a, b)		(s32)((s32)(a) - (s32)(b))
691adfc5217SJeff Kirsher 
692adfc5217SJeff Kirsher 
693adfc5217SJeff Kirsher #define BNX2X_SWCID_SHIFT	17
694adfc5217SJeff Kirsher #define BNX2X_SWCID_MASK	((0x1 << BNX2X_SWCID_SHIFT) - 1)
695adfc5217SJeff Kirsher 
696adfc5217SJeff Kirsher /* used on a CID received from the HW */
697adfc5217SJeff Kirsher #define SW_CID(x)			(le32_to_cpu(x) & BNX2X_SWCID_MASK)
698adfc5217SJeff Kirsher #define CQE_CMD(x)			(le32_to_cpu(x) >> \
699adfc5217SJeff Kirsher 					COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT)
700adfc5217SJeff Kirsher 
701adfc5217SJeff Kirsher #define BD_UNMAP_ADDR(bd)		HILO_U64(le32_to_cpu((bd)->addr_hi), \
702adfc5217SJeff Kirsher 						 le32_to_cpu((bd)->addr_lo))
703adfc5217SJeff Kirsher #define BD_UNMAP_LEN(bd)		(le16_to_cpu((bd)->nbytes))
704adfc5217SJeff Kirsher 
705adfc5217SJeff Kirsher #define BNX2X_DB_MIN_SHIFT		3	/* 8 bytes */
706adfc5217SJeff Kirsher #define BNX2X_DB_SHIFT			7	/* 128 bytes*/
707adfc5217SJeff Kirsher #if (BNX2X_DB_SHIFT < BNX2X_DB_MIN_SHIFT)
708adfc5217SJeff Kirsher #error "Min DB doorbell stride is 8"
709adfc5217SJeff Kirsher #endif
710adfc5217SJeff Kirsher #define DPM_TRIGER_TYPE			0x40
711adfc5217SJeff Kirsher #define DOORBELL(bp, cid, val) \
712adfc5217SJeff Kirsher 	do { \
713adfc5217SJeff Kirsher 		writel((u32)(val), bp->doorbells + (bp->db_size * (cid)) + \
714adfc5217SJeff Kirsher 		       DPM_TRIGER_TYPE); \
715adfc5217SJeff Kirsher 	} while (0)
716adfc5217SJeff Kirsher 
717adfc5217SJeff Kirsher 
718adfc5217SJeff Kirsher /* TX CSUM helpers */
719adfc5217SJeff Kirsher #define SKB_CS_OFF(skb)		(offsetof(struct tcphdr, check) - \
720adfc5217SJeff Kirsher 				 skb->csum_offset)
721adfc5217SJeff Kirsher #define SKB_CS(skb)		(*(u16 *)(skb_transport_header(skb) + \
722adfc5217SJeff Kirsher 					  skb->csum_offset))
723adfc5217SJeff Kirsher 
724adfc5217SJeff Kirsher #define pbd_tcp_flags(skb)	(ntohl(tcp_flag_word(tcp_hdr(skb)))>>16 & 0xff)
725adfc5217SJeff Kirsher 
726adfc5217SJeff Kirsher #define XMIT_PLAIN			0
727adfc5217SJeff Kirsher #define XMIT_CSUM_V4			0x1
728adfc5217SJeff Kirsher #define XMIT_CSUM_V6			0x2
729adfc5217SJeff Kirsher #define XMIT_CSUM_TCP			0x4
730adfc5217SJeff Kirsher #define XMIT_GSO_V4			0x8
731adfc5217SJeff Kirsher #define XMIT_GSO_V6			0x10
732adfc5217SJeff Kirsher 
733adfc5217SJeff Kirsher #define XMIT_CSUM			(XMIT_CSUM_V4 | XMIT_CSUM_V6)
734adfc5217SJeff Kirsher #define XMIT_GSO			(XMIT_GSO_V4 | XMIT_GSO_V6)
735adfc5217SJeff Kirsher 
736adfc5217SJeff Kirsher 
737adfc5217SJeff Kirsher /* stuff added to make the code fit 80Col */
738adfc5217SJeff Kirsher #define CQE_TYPE(cqe_fp_flags)	 ((cqe_fp_flags) & ETH_FAST_PATH_RX_CQE_TYPE)
739adfc5217SJeff Kirsher #define CQE_TYPE_START(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_START_AGG)
740adfc5217SJeff Kirsher #define CQE_TYPE_STOP(cqe_type)  ((cqe_type) == RX_ETH_CQE_TYPE_ETH_STOP_AGG)
741adfc5217SJeff Kirsher #define CQE_TYPE_SLOW(cqe_type)  ((cqe_type) == RX_ETH_CQE_TYPE_ETH_RAMROD)
742adfc5217SJeff Kirsher #define CQE_TYPE_FAST(cqe_type)  ((cqe_type) == RX_ETH_CQE_TYPE_ETH_FASTPATH)
743adfc5217SJeff Kirsher 
744adfc5217SJeff Kirsher #define ETH_RX_ERROR_FALGS		ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG
745adfc5217SJeff Kirsher 
746adfc5217SJeff Kirsher #define BNX2X_PRS_FLAG_OVERETH_IPV4(flags) \
747adfc5217SJeff Kirsher 				(((le16_to_cpu(flags) & \
748adfc5217SJeff Kirsher 				   PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) >> \
749adfc5217SJeff Kirsher 				  PARSING_FLAGS_OVER_ETHERNET_PROTOCOL_SHIFT) \
750adfc5217SJeff Kirsher 				 == PRS_FLAG_OVERETH_IPV4)
751adfc5217SJeff Kirsher #define BNX2X_RX_SUM_FIX(cqe) \
752adfc5217SJeff Kirsher 	BNX2X_PRS_FLAG_OVERETH_IPV4(cqe->fast_path_cqe.pars_flags.flags)
753adfc5217SJeff Kirsher 
754adfc5217SJeff Kirsher 
755adfc5217SJeff Kirsher #define FP_USB_FUNC_OFF	\
756adfc5217SJeff Kirsher 			offsetof(struct cstorm_status_block_u, func)
757adfc5217SJeff Kirsher #define FP_CSB_FUNC_OFF	\
758adfc5217SJeff Kirsher 			offsetof(struct cstorm_status_block_c, func)
759adfc5217SJeff Kirsher 
7608decf868SDavid S. Miller #define HC_INDEX_ETH_RX_CQ_CONS		1
761adfc5217SJeff Kirsher 
7628decf868SDavid S. Miller #define HC_INDEX_OOO_TX_CQ_CONS		4
7638decf868SDavid S. Miller 
7648decf868SDavid S. Miller #define HC_INDEX_ETH_TX_CQ_CONS_COS0	5
7658decf868SDavid S. Miller 
7668decf868SDavid S. Miller #define HC_INDEX_ETH_TX_CQ_CONS_COS1	6
7678decf868SDavid S. Miller 
7688decf868SDavid S. Miller #define HC_INDEX_ETH_TX_CQ_CONS_COS2	7
769adfc5217SJeff Kirsher 
770adfc5217SJeff Kirsher #define HC_INDEX_ETH_FIRST_TX_CQ_CONS	HC_INDEX_ETH_TX_CQ_CONS_COS0
771adfc5217SJeff Kirsher 
772adfc5217SJeff Kirsher #define BNX2X_RX_SB_INDEX \
773adfc5217SJeff Kirsher 	(&fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS])
774adfc5217SJeff Kirsher 
775adfc5217SJeff Kirsher #define BNX2X_TX_SB_INDEX_BASE BNX2X_TX_SB_INDEX_COS0
776adfc5217SJeff Kirsher 
777adfc5217SJeff Kirsher #define BNX2X_TX_SB_INDEX_COS0 \
778adfc5217SJeff Kirsher 	(&fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0])
779adfc5217SJeff Kirsher 
780adfc5217SJeff Kirsher /* end of fast path */
781adfc5217SJeff Kirsher 
782adfc5217SJeff Kirsher /* common */
783adfc5217SJeff Kirsher 
784adfc5217SJeff Kirsher struct bnx2x_common {
785adfc5217SJeff Kirsher 
786adfc5217SJeff Kirsher 	u32			chip_id;
787adfc5217SJeff Kirsher /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
788adfc5217SJeff Kirsher #define CHIP_ID(bp)			(bp->common.chip_id & 0xfffffff0)
789adfc5217SJeff Kirsher 
790adfc5217SJeff Kirsher #define CHIP_NUM(bp)			(bp->common.chip_id >> 16)
791adfc5217SJeff Kirsher #define CHIP_NUM_57710			0x164e
792adfc5217SJeff Kirsher #define CHIP_NUM_57711			0x164f
793adfc5217SJeff Kirsher #define CHIP_NUM_57711E			0x1650
794adfc5217SJeff Kirsher #define CHIP_NUM_57712			0x1662
795adfc5217SJeff Kirsher #define CHIP_NUM_57712_MF		0x1663
796adfc5217SJeff Kirsher #define CHIP_NUM_57713			0x1651
797adfc5217SJeff Kirsher #define CHIP_NUM_57713E			0x1652
798adfc5217SJeff Kirsher #define CHIP_NUM_57800			0x168a
799adfc5217SJeff Kirsher #define CHIP_NUM_57800_MF		0x16a5
800adfc5217SJeff Kirsher #define CHIP_NUM_57810			0x168e
801adfc5217SJeff Kirsher #define CHIP_NUM_57810_MF		0x16ae
8027e8e02dfSBarak Witkowski #define CHIP_NUM_57811			0x163d
8037e8e02dfSBarak Witkowski #define CHIP_NUM_57811_MF		0x163e
804adfc5217SJeff Kirsher #define CHIP_NUM_57840			0x168d
805adfc5217SJeff Kirsher #define CHIP_NUM_57840_MF		0x16ab
806adfc5217SJeff Kirsher #define CHIP_IS_E1(bp)			(CHIP_NUM(bp) == CHIP_NUM_57710)
807adfc5217SJeff Kirsher #define CHIP_IS_57711(bp)		(CHIP_NUM(bp) == CHIP_NUM_57711)
808adfc5217SJeff Kirsher #define CHIP_IS_57711E(bp)		(CHIP_NUM(bp) == CHIP_NUM_57711E)
809adfc5217SJeff Kirsher #define CHIP_IS_57712(bp)		(CHIP_NUM(bp) == CHIP_NUM_57712)
810adfc5217SJeff Kirsher #define CHIP_IS_57712_MF(bp)		(CHIP_NUM(bp) == CHIP_NUM_57712_MF)
811adfc5217SJeff Kirsher #define CHIP_IS_57800(bp)		(CHIP_NUM(bp) == CHIP_NUM_57800)
812adfc5217SJeff Kirsher #define CHIP_IS_57800_MF(bp)		(CHIP_NUM(bp) == CHIP_NUM_57800_MF)
813adfc5217SJeff Kirsher #define CHIP_IS_57810(bp)		(CHIP_NUM(bp) == CHIP_NUM_57810)
814adfc5217SJeff Kirsher #define CHIP_IS_57810_MF(bp)		(CHIP_NUM(bp) == CHIP_NUM_57810_MF)
8157e8e02dfSBarak Witkowski #define CHIP_IS_57811(bp)		(CHIP_NUM(bp) == CHIP_NUM_57811)
8167e8e02dfSBarak Witkowski #define CHIP_IS_57811_MF(bp)		(CHIP_NUM(bp) == CHIP_NUM_57811_MF)
817adfc5217SJeff Kirsher #define CHIP_IS_57840(bp)		(CHIP_NUM(bp) == CHIP_NUM_57840)
818adfc5217SJeff Kirsher #define CHIP_IS_57840_MF(bp)		(CHIP_NUM(bp) == CHIP_NUM_57840_MF)
819adfc5217SJeff Kirsher #define CHIP_IS_E1H(bp)			(CHIP_IS_57711(bp) || \
820adfc5217SJeff Kirsher 					 CHIP_IS_57711E(bp))
821adfc5217SJeff Kirsher #define CHIP_IS_E2(bp)			(CHIP_IS_57712(bp) || \
822adfc5217SJeff Kirsher 					 CHIP_IS_57712_MF(bp))
823adfc5217SJeff Kirsher #define CHIP_IS_E3(bp)			(CHIP_IS_57800(bp) || \
824adfc5217SJeff Kirsher 					 CHIP_IS_57800_MF(bp) || \
825adfc5217SJeff Kirsher 					 CHIP_IS_57810(bp) || \
826adfc5217SJeff Kirsher 					 CHIP_IS_57810_MF(bp) || \
8277e8e02dfSBarak Witkowski 					 CHIP_IS_57811(bp) || \
8287e8e02dfSBarak Witkowski 					 CHIP_IS_57811_MF(bp) || \
829adfc5217SJeff Kirsher 					 CHIP_IS_57840(bp) || \
830adfc5217SJeff Kirsher 					 CHIP_IS_57840_MF(bp))
831adfc5217SJeff Kirsher #define CHIP_IS_E1x(bp)			(CHIP_IS_E1((bp)) || CHIP_IS_E1H((bp)))
832adfc5217SJeff Kirsher #define USES_WARPCORE(bp)		(CHIP_IS_E3(bp))
833adfc5217SJeff Kirsher #define IS_E1H_OFFSET			(!CHIP_IS_E1(bp))
834adfc5217SJeff Kirsher 
835adfc5217SJeff Kirsher #define CHIP_REV_SHIFT			12
836adfc5217SJeff Kirsher #define CHIP_REV_MASK			(0xF << CHIP_REV_SHIFT)
837adfc5217SJeff Kirsher #define CHIP_REV_VAL(bp)		(bp->common.chip_id & CHIP_REV_MASK)
838adfc5217SJeff Kirsher #define CHIP_REV_Ax			(0x0 << CHIP_REV_SHIFT)
839adfc5217SJeff Kirsher #define CHIP_REV_Bx			(0x1 << CHIP_REV_SHIFT)
840adfc5217SJeff Kirsher /* assume maximum 5 revisions */
841adfc5217SJeff Kirsher #define CHIP_REV_IS_SLOW(bp)		(CHIP_REV_VAL(bp) > 0x00005000)
842adfc5217SJeff Kirsher /* Emul versions are A=>0xe, B=>0xc, C=>0xa, D=>8, E=>6 */
843adfc5217SJeff Kirsher #define CHIP_REV_IS_EMUL(bp)		((CHIP_REV_IS_SLOW(bp)) && \
844adfc5217SJeff Kirsher 					 !(CHIP_REV_VAL(bp) & 0x00001000))
845adfc5217SJeff Kirsher /* FPGA versions are A=>0xf, B=>0xd, C=>0xb, D=>9, E=>7 */
846adfc5217SJeff Kirsher #define CHIP_REV_IS_FPGA(bp)		((CHIP_REV_IS_SLOW(bp)) && \
847adfc5217SJeff Kirsher 					 (CHIP_REV_VAL(bp) & 0x00001000))
848adfc5217SJeff Kirsher 
849adfc5217SJeff Kirsher #define CHIP_TIME(bp)			((CHIP_REV_IS_EMUL(bp)) ? 2000 : \
850adfc5217SJeff Kirsher 					((CHIP_REV_IS_FPGA(bp)) ? 200 : 1))
851adfc5217SJeff Kirsher 
852adfc5217SJeff Kirsher #define CHIP_METAL(bp)			(bp->common.chip_id & 0x00000ff0)
853adfc5217SJeff Kirsher #define CHIP_BOND_ID(bp)		(bp->common.chip_id & 0x0000000f)
854adfc5217SJeff Kirsher #define CHIP_REV_SIM(bp)		(((CHIP_REV_MASK - CHIP_REV_VAL(bp)) >>\
855adfc5217SJeff Kirsher 					   (CHIP_REV_SHIFT + 1)) \
856adfc5217SJeff Kirsher 						<< CHIP_REV_SHIFT)
857adfc5217SJeff Kirsher #define CHIP_REV(bp)			(CHIP_REV_IS_SLOW(bp) ? \
858adfc5217SJeff Kirsher 						CHIP_REV_SIM(bp) :\
859adfc5217SJeff Kirsher 						CHIP_REV_VAL(bp))
860adfc5217SJeff Kirsher #define CHIP_IS_E3B0(bp)		(CHIP_IS_E3(bp) && \
861adfc5217SJeff Kirsher 					 (CHIP_REV(bp) == CHIP_REV_Bx))
862adfc5217SJeff Kirsher #define CHIP_IS_E3A0(bp)		(CHIP_IS_E3(bp) && \
863adfc5217SJeff Kirsher 					 (CHIP_REV(bp) == CHIP_REV_Ax))
864adfc5217SJeff Kirsher 
865adfc5217SJeff Kirsher 	int			flash_size;
866adfc5217SJeff Kirsher #define BNX2X_NVRAM_1MB_SIZE			0x20000	/* 1M bit in bytes */
867adfc5217SJeff Kirsher #define BNX2X_NVRAM_TIMEOUT_COUNT		30000
868adfc5217SJeff Kirsher #define BNX2X_NVRAM_PAGE_SIZE			256
869adfc5217SJeff Kirsher 
870adfc5217SJeff Kirsher 	u32			shmem_base;
871adfc5217SJeff Kirsher 	u32			shmem2_base;
872adfc5217SJeff Kirsher 	u32			mf_cfg_base;
873adfc5217SJeff Kirsher 	u32			mf2_cfg_base;
874adfc5217SJeff Kirsher 
875adfc5217SJeff Kirsher 	u32			hw_config;
876adfc5217SJeff Kirsher 
877adfc5217SJeff Kirsher 	u32			bc_ver;
878adfc5217SJeff Kirsher 
879adfc5217SJeff Kirsher 	u8			int_block;
880adfc5217SJeff Kirsher #define INT_BLOCK_HC			0
881adfc5217SJeff Kirsher #define INT_BLOCK_IGU			1
882adfc5217SJeff Kirsher #define INT_BLOCK_MODE_NORMAL		0
883adfc5217SJeff Kirsher #define INT_BLOCK_MODE_BW_COMP		2
884adfc5217SJeff Kirsher #define CHIP_INT_MODE_IS_NBC(bp)		\
885adfc5217SJeff Kirsher 			(!CHIP_IS_E1x(bp) &&	\
886adfc5217SJeff Kirsher 			!((bp)->common.int_block & INT_BLOCK_MODE_BW_COMP))
887adfc5217SJeff Kirsher #define CHIP_INT_MODE_IS_BC(bp) (!CHIP_INT_MODE_IS_NBC(bp))
888adfc5217SJeff Kirsher 
889adfc5217SJeff Kirsher 	u8			chip_port_mode;
890adfc5217SJeff Kirsher #define CHIP_4_PORT_MODE			0x0
891adfc5217SJeff Kirsher #define CHIP_2_PORT_MODE			0x1
892adfc5217SJeff Kirsher #define CHIP_PORT_MODE_NONE			0x2
893adfc5217SJeff Kirsher #define CHIP_MODE(bp)			(bp->common.chip_port_mode)
894adfc5217SJeff Kirsher #define CHIP_MODE_IS_4_PORT(bp) (CHIP_MODE(bp) == CHIP_4_PORT_MODE)
8951d187b34SBarak Witkowski 
8961d187b34SBarak Witkowski 	u32			boot_mode;
897adfc5217SJeff Kirsher };
898adfc5217SJeff Kirsher 
899adfc5217SJeff Kirsher /* IGU MSIX STATISTICS on 57712: 64 for VFs; 4 for PFs; 4 for Attentions */
900adfc5217SJeff Kirsher #define BNX2X_IGU_STAS_MSG_VF_CNT 64
901adfc5217SJeff Kirsher #define BNX2X_IGU_STAS_MSG_PF_CNT 4
902adfc5217SJeff Kirsher 
903adfc5217SJeff Kirsher /* end of common */
904adfc5217SJeff Kirsher 
905adfc5217SJeff Kirsher /* port */
906adfc5217SJeff Kirsher 
907adfc5217SJeff Kirsher struct bnx2x_port {
908adfc5217SJeff Kirsher 	u32			pmf;
909adfc5217SJeff Kirsher 
910adfc5217SJeff Kirsher 	u32			link_config[LINK_CONFIG_SIZE];
911adfc5217SJeff Kirsher 
912adfc5217SJeff Kirsher 	u32			supported[LINK_CONFIG_SIZE];
913adfc5217SJeff Kirsher /* link settings - missing defines */
914adfc5217SJeff Kirsher #define SUPPORTED_2500baseX_Full	(1 << 15)
915adfc5217SJeff Kirsher 
916adfc5217SJeff Kirsher 	u32			advertising[LINK_CONFIG_SIZE];
917adfc5217SJeff Kirsher /* link settings - missing defines */
918adfc5217SJeff Kirsher #define ADVERTISED_2500baseX_Full	(1 << 15)
919adfc5217SJeff Kirsher 
920adfc5217SJeff Kirsher 	u32			phy_addr;
921adfc5217SJeff Kirsher 
922adfc5217SJeff Kirsher 	/* used to synchronize phy accesses */
923adfc5217SJeff Kirsher 	struct mutex		phy_mutex;
924adfc5217SJeff Kirsher 	int			need_hw_lock;
925adfc5217SJeff Kirsher 
926adfc5217SJeff Kirsher 	u32			port_stx;
927adfc5217SJeff Kirsher 
928adfc5217SJeff Kirsher 	struct nig_stats	old_nig_stats;
929adfc5217SJeff Kirsher };
930adfc5217SJeff Kirsher 
931adfc5217SJeff Kirsher /* end of port */
932adfc5217SJeff Kirsher 
933adfc5217SJeff Kirsher #define STATS_OFFSET32(stat_name) \
934adfc5217SJeff Kirsher 			(offsetof(struct bnx2x_eth_stats, stat_name) / 4)
935adfc5217SJeff Kirsher 
936adfc5217SJeff Kirsher /* slow path */
937adfc5217SJeff Kirsher 
938adfc5217SJeff Kirsher /* slow path work-queue */
939adfc5217SJeff Kirsher extern struct workqueue_struct *bnx2x_wq;
940adfc5217SJeff Kirsher 
941adfc5217SJeff Kirsher #define BNX2X_MAX_NUM_OF_VFS	64
942adfc5217SJeff Kirsher #define BNX2X_VF_ID_INVALID	0xFF
943adfc5217SJeff Kirsher 
944adfc5217SJeff Kirsher /*
945adfc5217SJeff Kirsher  * The total number of L2 queues, MSIX vectors and HW contexts (CIDs) is
946adfc5217SJeff Kirsher  * control by the number of fast-path status blocks supported by the
947adfc5217SJeff Kirsher  * device (HW/FW). Each fast-path status block (FP-SB) aka non-default
948adfc5217SJeff Kirsher  * status block represents an independent interrupts context that can
949adfc5217SJeff Kirsher  * serve a regular L2 networking queue. However special L2 queues such
950adfc5217SJeff Kirsher  * as the FCoE queue do not require a FP-SB and other components like
951adfc5217SJeff Kirsher  * the CNIC may consume FP-SB reducing the number of possible L2 queues
952adfc5217SJeff Kirsher  *
953adfc5217SJeff Kirsher  * If the maximum number of FP-SB available is X then:
954adfc5217SJeff Kirsher  * a. If CNIC is supported it consumes 1 FP-SB thus the max number of
955adfc5217SJeff Kirsher  *    regular L2 queues is Y=X-1
956adfc5217SJeff Kirsher  * b. in MF mode the actual number of L2 queues is Y= (X-1/MF_factor)
957adfc5217SJeff Kirsher  * c. If the FCoE L2 queue is supported the actual number of L2 queues
958adfc5217SJeff Kirsher  *    is Y+1
959adfc5217SJeff Kirsher  * d. The number of irqs (MSIX vectors) is either Y+1 (one extra for
960adfc5217SJeff Kirsher  *    slow-path interrupts) or Y+2 if CNIC is supported (one additional
961adfc5217SJeff Kirsher  *    FP interrupt context for the CNIC).
962adfc5217SJeff Kirsher  * e. The number of HW context (CID count) is always X or X+1 if FCoE
963adfc5217SJeff Kirsher  *    L2 queue is supported. the cid for the FCoE L2 queue is always X.
964adfc5217SJeff Kirsher  */
965adfc5217SJeff Kirsher 
966adfc5217SJeff Kirsher /* fast-path interrupt contexts E1x */
967adfc5217SJeff Kirsher #define FP_SB_MAX_E1x		16
968adfc5217SJeff Kirsher /* fast-path interrupt contexts E2 */
969adfc5217SJeff Kirsher #define FP_SB_MAX_E2		HC_SB_MAX_SB_E2
970adfc5217SJeff Kirsher 
971adfc5217SJeff Kirsher union cdu_context {
972adfc5217SJeff Kirsher 	struct eth_context eth;
973adfc5217SJeff Kirsher 	char pad[1024];
974adfc5217SJeff Kirsher };
975adfc5217SJeff Kirsher 
976adfc5217SJeff Kirsher /* CDU host DB constants */
977a052997eSMerav Sicron #define CDU_ILT_PAGE_SZ_HW	2
978a052997eSMerav Sicron #define CDU_ILT_PAGE_SZ		(8192 << CDU_ILT_PAGE_SZ_HW) /* 32K */
979adfc5217SJeff Kirsher #define ILT_PAGE_CIDS		(CDU_ILT_PAGE_SZ / sizeof(union cdu_context))
980adfc5217SJeff Kirsher 
981adfc5217SJeff Kirsher #ifdef BCM_CNIC
982adfc5217SJeff Kirsher #define CNIC_ISCSI_CID_MAX	256
983adfc5217SJeff Kirsher #define CNIC_FCOE_CID_MAX	2048
984adfc5217SJeff Kirsher #define CNIC_CID_MAX		(CNIC_ISCSI_CID_MAX + CNIC_FCOE_CID_MAX)
985adfc5217SJeff Kirsher #define CNIC_ILT_LINES		DIV_ROUND_UP(CNIC_CID_MAX, ILT_PAGE_CIDS)
986adfc5217SJeff Kirsher #endif
987adfc5217SJeff Kirsher 
988adfc5217SJeff Kirsher #define QM_ILT_PAGE_SZ_HW	0
989adfc5217SJeff Kirsher #define QM_ILT_PAGE_SZ		(4096 << QM_ILT_PAGE_SZ_HW) /* 4K */
990adfc5217SJeff Kirsher #define QM_CID_ROUND		1024
991adfc5217SJeff Kirsher 
992adfc5217SJeff Kirsher #ifdef BCM_CNIC
993adfc5217SJeff Kirsher /* TM (timers) host DB constants */
994adfc5217SJeff Kirsher #define TM_ILT_PAGE_SZ_HW	0
995adfc5217SJeff Kirsher #define TM_ILT_PAGE_SZ		(4096 << TM_ILT_PAGE_SZ_HW) /* 4K */
996adfc5217SJeff Kirsher /* #define TM_CONN_NUM		(CNIC_STARTING_CID+CNIC_ISCSI_CXT_MAX) */
997adfc5217SJeff Kirsher #define TM_CONN_NUM		1024
998adfc5217SJeff Kirsher #define TM_ILT_SZ		(8 * TM_CONN_NUM)
999adfc5217SJeff Kirsher #define TM_ILT_LINES		DIV_ROUND_UP(TM_ILT_SZ, TM_ILT_PAGE_SZ)
1000adfc5217SJeff Kirsher 
1001adfc5217SJeff Kirsher /* SRC (Searcher) host DB constants */
1002adfc5217SJeff Kirsher #define SRC_ILT_PAGE_SZ_HW	0
1003adfc5217SJeff Kirsher #define SRC_ILT_PAGE_SZ		(4096 << SRC_ILT_PAGE_SZ_HW) /* 4K */
1004adfc5217SJeff Kirsher #define SRC_HASH_BITS		10
1005adfc5217SJeff Kirsher #define SRC_CONN_NUM		(1 << SRC_HASH_BITS) /* 1024 */
1006adfc5217SJeff Kirsher #define SRC_ILT_SZ		(sizeof(struct src_ent) * SRC_CONN_NUM)
1007adfc5217SJeff Kirsher #define SRC_T2_SZ		SRC_ILT_SZ
1008adfc5217SJeff Kirsher #define SRC_ILT_LINES		DIV_ROUND_UP(SRC_ILT_SZ, SRC_ILT_PAGE_SZ)
1009adfc5217SJeff Kirsher 
1010adfc5217SJeff Kirsher #endif
1011adfc5217SJeff Kirsher 
1012adfc5217SJeff Kirsher #define MAX_DMAE_C		8
1013adfc5217SJeff Kirsher 
1014adfc5217SJeff Kirsher /* DMA memory not used in fastpath */
1015adfc5217SJeff Kirsher struct bnx2x_slowpath {
1016adfc5217SJeff Kirsher 	union {
1017adfc5217SJeff Kirsher 		struct mac_configuration_cmd		e1x;
1018adfc5217SJeff Kirsher 		struct eth_classify_rules_ramrod_data	e2;
1019adfc5217SJeff Kirsher 	} mac_rdata;
1020adfc5217SJeff Kirsher 
1021adfc5217SJeff Kirsher 
1022adfc5217SJeff Kirsher 	union {
1023adfc5217SJeff Kirsher 		struct tstorm_eth_mac_filter_config	e1x;
1024adfc5217SJeff Kirsher 		struct eth_filter_rules_ramrod_data	e2;
1025adfc5217SJeff Kirsher 	} rx_mode_rdata;
1026adfc5217SJeff Kirsher 
1027adfc5217SJeff Kirsher 	union {
1028adfc5217SJeff Kirsher 		struct mac_configuration_cmd		e1;
1029adfc5217SJeff Kirsher 		struct eth_multicast_rules_ramrod_data  e2;
1030adfc5217SJeff Kirsher 	} mcast_rdata;
1031adfc5217SJeff Kirsher 
1032adfc5217SJeff Kirsher 	struct eth_rss_update_ramrod_data	rss_rdata;
1033adfc5217SJeff Kirsher 
1034adfc5217SJeff Kirsher 	/* Queue State related ramrods are always sent under rtnl_lock */
1035adfc5217SJeff Kirsher 	union {
1036adfc5217SJeff Kirsher 		struct client_init_ramrod_data  init_data;
1037adfc5217SJeff Kirsher 		struct client_update_ramrod_data update_data;
1038adfc5217SJeff Kirsher 	} q_rdata;
1039adfc5217SJeff Kirsher 
1040adfc5217SJeff Kirsher 	union {
1041adfc5217SJeff Kirsher 		struct function_start_data	func_start;
1042adfc5217SJeff Kirsher 		/* pfc configuration for DCBX ramrod */
1043adfc5217SJeff Kirsher 		struct flow_control_configuration pfc_config;
1044adfc5217SJeff Kirsher 	} func_rdata;
1045adfc5217SJeff Kirsher 
1046a3348722SBarak Witkowski 	/* afex ramrod can not be a part of func_rdata union because these
1047a3348722SBarak Witkowski 	 * events might arrive in parallel to other events from func_rdata.
1048a3348722SBarak Witkowski 	 * Therefore, if they would have been defined in the same union,
1049a3348722SBarak Witkowski 	 * data can get corrupted.
1050a3348722SBarak Witkowski 	 */
1051a3348722SBarak Witkowski 	struct afex_vif_list_ramrod_data func_afex_rdata;
1052a3348722SBarak Witkowski 
1053adfc5217SJeff Kirsher 	/* used by dmae command executer */
1054adfc5217SJeff Kirsher 	struct dmae_command		dmae[MAX_DMAE_C];
1055adfc5217SJeff Kirsher 
1056adfc5217SJeff Kirsher 	u32				stats_comp;
1057adfc5217SJeff Kirsher 	union mac_stats			mac_stats;
1058adfc5217SJeff Kirsher 	struct nig_stats		nig_stats;
1059adfc5217SJeff Kirsher 	struct host_port_stats		port_stats;
1060adfc5217SJeff Kirsher 	struct host_func_stats		func_stats;
1061adfc5217SJeff Kirsher 
1062adfc5217SJeff Kirsher 	u32				wb_comp;
1063adfc5217SJeff Kirsher 	u32				wb_data[4];
10641d187b34SBarak Witkowski 
10651d187b34SBarak Witkowski 	union drv_info_to_mcp		drv_info_to_mcp;
1066adfc5217SJeff Kirsher };
1067adfc5217SJeff Kirsher 
1068adfc5217SJeff Kirsher #define bnx2x_sp(bp, var)		(&bp->slowpath->var)
1069adfc5217SJeff Kirsher #define bnx2x_sp_mapping(bp, var) \
1070adfc5217SJeff Kirsher 		(bp->slowpath_mapping + offsetof(struct bnx2x_slowpath, var))
1071adfc5217SJeff Kirsher 
1072adfc5217SJeff Kirsher 
1073adfc5217SJeff Kirsher /* attn group wiring */
1074adfc5217SJeff Kirsher #define MAX_DYNAMIC_ATTN_GRPS		8
1075adfc5217SJeff Kirsher 
1076adfc5217SJeff Kirsher struct attn_route {
1077adfc5217SJeff Kirsher 	u32 sig[5];
1078adfc5217SJeff Kirsher };
1079adfc5217SJeff Kirsher 
1080adfc5217SJeff Kirsher struct iro {
1081adfc5217SJeff Kirsher 	u32 base;
1082adfc5217SJeff Kirsher 	u16 m1;
1083adfc5217SJeff Kirsher 	u16 m2;
1084adfc5217SJeff Kirsher 	u16 m3;
1085adfc5217SJeff Kirsher 	u16 size;
1086adfc5217SJeff Kirsher };
1087adfc5217SJeff Kirsher 
1088adfc5217SJeff Kirsher struct hw_context {
1089adfc5217SJeff Kirsher 	union cdu_context *vcxt;
1090adfc5217SJeff Kirsher 	dma_addr_t cxt_mapping;
1091adfc5217SJeff Kirsher 	size_t size;
1092adfc5217SJeff Kirsher };
1093adfc5217SJeff Kirsher 
1094adfc5217SJeff Kirsher /* forward */
1095adfc5217SJeff Kirsher struct bnx2x_ilt;
1096adfc5217SJeff Kirsher 
1097adfc5217SJeff Kirsher 
1098adfc5217SJeff Kirsher enum bnx2x_recovery_state {
1099adfc5217SJeff Kirsher 	BNX2X_RECOVERY_DONE,
1100adfc5217SJeff Kirsher 	BNX2X_RECOVERY_INIT,
1101adfc5217SJeff Kirsher 	BNX2X_RECOVERY_WAIT,
110295c6c616SAriel Elior 	BNX2X_RECOVERY_FAILED,
110395c6c616SAriel Elior 	BNX2X_RECOVERY_NIC_LOADING
1104adfc5217SJeff Kirsher };
1105adfc5217SJeff Kirsher 
1106adfc5217SJeff Kirsher /*
1107adfc5217SJeff Kirsher  * Event queue (EQ or event ring) MC hsi
1108adfc5217SJeff Kirsher  * NUM_EQ_PAGES and EQ_DESC_CNT_PAGE must be power of 2
1109adfc5217SJeff Kirsher  */
1110adfc5217SJeff Kirsher #define NUM_EQ_PAGES		1
1111adfc5217SJeff Kirsher #define EQ_DESC_CNT_PAGE	(BCM_PAGE_SIZE / sizeof(union event_ring_elem))
1112adfc5217SJeff Kirsher #define EQ_DESC_MAX_PAGE	(EQ_DESC_CNT_PAGE - 1)
1113adfc5217SJeff Kirsher #define NUM_EQ_DESC		(EQ_DESC_CNT_PAGE * NUM_EQ_PAGES)
1114adfc5217SJeff Kirsher #define EQ_DESC_MASK		(NUM_EQ_DESC - 1)
1115adfc5217SJeff Kirsher #define MAX_EQ_AVAIL		(EQ_DESC_MAX_PAGE * NUM_EQ_PAGES - 2)
1116adfc5217SJeff Kirsher 
1117adfc5217SJeff Kirsher /* depends on EQ_DESC_CNT_PAGE being a power of 2 */
1118adfc5217SJeff Kirsher #define NEXT_EQ_IDX(x)		((((x) & EQ_DESC_MAX_PAGE) == \
1119adfc5217SJeff Kirsher 				  (EQ_DESC_MAX_PAGE - 1)) ? (x) + 2 : (x) + 1)
1120adfc5217SJeff Kirsher 
1121adfc5217SJeff Kirsher /* depends on the above and on NUM_EQ_PAGES being a power of 2 */
1122adfc5217SJeff Kirsher #define EQ_DESC(x)		((x) & EQ_DESC_MASK)
1123adfc5217SJeff Kirsher 
1124adfc5217SJeff Kirsher #define BNX2X_EQ_INDEX \
1125adfc5217SJeff Kirsher 	(&bp->def_status_blk->sp_sb.\
1126adfc5217SJeff Kirsher 	index_values[HC_SP_INDEX_EQ_CONS])
1127adfc5217SJeff Kirsher 
1128adfc5217SJeff Kirsher /* This is a data that will be used to create a link report message.
1129adfc5217SJeff Kirsher  * We will keep the data used for the last link report in order
1130adfc5217SJeff Kirsher  * to prevent reporting the same link parameters twice.
1131adfc5217SJeff Kirsher  */
1132adfc5217SJeff Kirsher struct bnx2x_link_report_data {
1133adfc5217SJeff Kirsher 	u16 line_speed;			/* Effective line speed */
1134adfc5217SJeff Kirsher 	unsigned long link_report_flags;/* BNX2X_LINK_REPORT_XXX flags */
1135adfc5217SJeff Kirsher };
1136adfc5217SJeff Kirsher 
1137adfc5217SJeff Kirsher enum {
1138adfc5217SJeff Kirsher 	BNX2X_LINK_REPORT_FD,		/* Full DUPLEX */
1139adfc5217SJeff Kirsher 	BNX2X_LINK_REPORT_LINK_DOWN,
1140adfc5217SJeff Kirsher 	BNX2X_LINK_REPORT_RX_FC_ON,
1141adfc5217SJeff Kirsher 	BNX2X_LINK_REPORT_TX_FC_ON,
1142adfc5217SJeff Kirsher };
1143adfc5217SJeff Kirsher 
1144adfc5217SJeff Kirsher enum {
1145adfc5217SJeff Kirsher 	BNX2X_PORT_QUERY_IDX,
1146adfc5217SJeff Kirsher 	BNX2X_PF_QUERY_IDX,
114750f0a562SBarak Witkowski 	BNX2X_FCOE_QUERY_IDX,
1148adfc5217SJeff Kirsher 	BNX2X_FIRST_QUEUE_QUERY_IDX,
1149adfc5217SJeff Kirsher };
1150adfc5217SJeff Kirsher 
1151adfc5217SJeff Kirsher struct bnx2x_fw_stats_req {
1152adfc5217SJeff Kirsher 	struct stats_query_header hdr;
115350f0a562SBarak Witkowski 	struct stats_query_entry query[FP_SB_MAX_E1x+
115450f0a562SBarak Witkowski 		BNX2X_FIRST_QUEUE_QUERY_IDX];
1155adfc5217SJeff Kirsher };
1156adfc5217SJeff Kirsher 
1157adfc5217SJeff Kirsher struct bnx2x_fw_stats_data {
1158adfc5217SJeff Kirsher 	struct stats_counter	storm_counters;
1159adfc5217SJeff Kirsher 	struct per_port_stats	port;
1160adfc5217SJeff Kirsher 	struct per_pf_stats	pf;
116150f0a562SBarak Witkowski 	struct fcoe_statistics_params	fcoe;
1162adfc5217SJeff Kirsher 	struct per_queue_stats  queue_stats[1];
1163adfc5217SJeff Kirsher };
1164adfc5217SJeff Kirsher 
1165adfc5217SJeff Kirsher /* Public slow path states */
1166adfc5217SJeff Kirsher enum {
1167adfc5217SJeff Kirsher 	BNX2X_SP_RTNL_SETUP_TC,
1168adfc5217SJeff Kirsher 	BNX2X_SP_RTNL_TX_TIMEOUT,
1169a3348722SBarak Witkowski 	BNX2X_SP_RTNL_AFEX_F_UPDATE,
11708304859aSAriel Elior 	BNX2X_SP_RTNL_FAN_FAILURE,
1171adfc5217SJeff Kirsher };
1172adfc5217SJeff Kirsher 
1173adfc5217SJeff Kirsher 
1174452427b0SYuval Mintz struct bnx2x_prev_path_list {
1175452427b0SYuval Mintz 	u8 bus;
1176452427b0SYuval Mintz 	u8 slot;
1177452427b0SYuval Mintz 	u8 path;
1178452427b0SYuval Mintz 	struct list_head list;
1179452427b0SYuval Mintz };
1180452427b0SYuval Mintz 
118115192a8cSBarak Witkowski struct bnx2x_sp_objs {
118215192a8cSBarak Witkowski 	/* MACs object */
118315192a8cSBarak Witkowski 	struct bnx2x_vlan_mac_obj mac_obj;
118415192a8cSBarak Witkowski 
118515192a8cSBarak Witkowski 	/* Queue State object */
118615192a8cSBarak Witkowski 	struct bnx2x_queue_sp_obj q_obj;
118715192a8cSBarak Witkowski };
118815192a8cSBarak Witkowski 
118915192a8cSBarak Witkowski struct bnx2x_fp_stats {
119015192a8cSBarak Witkowski 	struct tstorm_per_queue_stats old_tclient;
119115192a8cSBarak Witkowski 	struct ustorm_per_queue_stats old_uclient;
119215192a8cSBarak Witkowski 	struct xstorm_per_queue_stats old_xclient;
119315192a8cSBarak Witkowski 	struct bnx2x_eth_q_stats eth_q_stats;
119415192a8cSBarak Witkowski 	struct bnx2x_eth_q_stats_old eth_q_stats_old;
119515192a8cSBarak Witkowski };
119615192a8cSBarak Witkowski 
1197adfc5217SJeff Kirsher struct bnx2x {
1198adfc5217SJeff Kirsher 	/* Fields used in the tx and intr/napi performance paths
1199adfc5217SJeff Kirsher 	 * are grouped together in the beginning of the structure
1200adfc5217SJeff Kirsher 	 */
1201adfc5217SJeff Kirsher 	struct bnx2x_fastpath	*fp;
120215192a8cSBarak Witkowski 	struct bnx2x_sp_objs	*sp_objs;
120315192a8cSBarak Witkowski 	struct bnx2x_fp_stats	*fp_stats;
120465565884SMerav Sicron 	struct bnx2x_fp_txdata	*bnx2x_txq;
120565565884SMerav Sicron 	int			bnx2x_txq_size;
1206adfc5217SJeff Kirsher 	void __iomem		*regview;
1207adfc5217SJeff Kirsher 	void __iomem		*doorbells;
1208adfc5217SJeff Kirsher 	u16			db_size;
1209adfc5217SJeff Kirsher 
1210adfc5217SJeff Kirsher 	u8			pf_num;	/* absolute PF number */
1211adfc5217SJeff Kirsher 	u8			pfid;	/* per-path PF number */
1212adfc5217SJeff Kirsher 	int			base_fw_ndsb; /**/
1213adfc5217SJeff Kirsher #define BP_PATH(bp)			(CHIP_IS_E1x(bp) ? 0 : (bp->pf_num & 1))
1214adfc5217SJeff Kirsher #define BP_PORT(bp)			(bp->pfid & 1)
1215adfc5217SJeff Kirsher #define BP_FUNC(bp)			(bp->pfid)
1216adfc5217SJeff Kirsher #define BP_ABS_FUNC(bp)			(bp->pf_num)
12178decf868SDavid S. Miller #define BP_VN(bp)			((bp)->pfid >> 1)
12188decf868SDavid S. Miller #define BP_MAX_VN_NUM(bp)		(CHIP_MODE_IS_4_PORT(bp) ? 2 : 4)
12198decf868SDavid S. Miller #define BP_L_ID(bp)			(BP_VN(bp) << 2)
12208decf868SDavid S. Miller #define BP_FW_MB_IDX_VN(bp, vn)		(BP_PORT(bp) +\
12218decf868SDavid S. Miller 	  (vn) * ((CHIP_IS_E1x(bp) || (CHIP_MODE_IS_4_PORT(bp))) ? 2  : 1))
12228decf868SDavid S. Miller #define BP_FW_MB_IDX(bp)		BP_FW_MB_IDX_VN(bp, BP_VN(bp))
1223adfc5217SJeff Kirsher 
1224adfc5217SJeff Kirsher 	struct net_device	*dev;
1225adfc5217SJeff Kirsher 	struct pci_dev		*pdev;
1226adfc5217SJeff Kirsher 
1227adfc5217SJeff Kirsher 	const struct iro	*iro_arr;
1228adfc5217SJeff Kirsher #define IRO (bp->iro_arr)
1229adfc5217SJeff Kirsher 
1230adfc5217SJeff Kirsher 	enum bnx2x_recovery_state recovery_state;
1231adfc5217SJeff Kirsher 	int			is_leader;
1232adfc5217SJeff Kirsher 	struct msix_entry	*msix_table;
1233adfc5217SJeff Kirsher 
1234adfc5217SJeff Kirsher 	int			tx_ring_size;
1235adfc5217SJeff Kirsher 
1236adfc5217SJeff Kirsher /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
1237adfc5217SJeff Kirsher #define ETH_OVREHEAD		(ETH_HLEN + 8 + 8)
1238adfc5217SJeff Kirsher #define ETH_MIN_PACKET_SIZE		60
1239adfc5217SJeff Kirsher #define ETH_MAX_PACKET_SIZE		1500
1240adfc5217SJeff Kirsher #define ETH_MAX_JUMBO_PACKET_SIZE	9600
1241621b4d66SDmitry Kravkov /* TCP with Timestamp Option (32) + IPv6 (40) */
1242621b4d66SDmitry Kravkov #define ETH_MAX_TPA_HEADER_SIZE		72
1243adfc5217SJeff Kirsher 
1244adfc5217SJeff Kirsher 	/* Max supported alignment is 256 (8 shift) */
1245e52fcb24SEric Dumazet #define BNX2X_RX_ALIGN_SHIFT		min(8, L1_CACHE_SHIFT)
1246e52fcb24SEric Dumazet 
1247e52fcb24SEric Dumazet 	/* FW uses 2 Cache lines Alignment for start packet and size
1248e52fcb24SEric Dumazet 	 *
1249e52fcb24SEric Dumazet 	 * We assume skb_build() uses sizeof(struct skb_shared_info) bytes
1250e52fcb24SEric Dumazet 	 * at the end of skb->data, to avoid wasting a full cache line.
1251e52fcb24SEric Dumazet 	 * This reduces memory use (skb->truesize).
1252e52fcb24SEric Dumazet 	 */
1253e52fcb24SEric Dumazet #define BNX2X_FW_RX_ALIGN_START	(1UL << BNX2X_RX_ALIGN_SHIFT)
1254e52fcb24SEric Dumazet 
1255e52fcb24SEric Dumazet #define BNX2X_FW_RX_ALIGN_END					\
1256e52fcb24SEric Dumazet 	max(1UL << BNX2X_RX_ALIGN_SHIFT, 			\
1257e52fcb24SEric Dumazet 	    SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
1258e52fcb24SEric Dumazet 
1259adfc5217SJeff Kirsher #define BNX2X_PXP_DRAM_ALIGN		(BNX2X_RX_ALIGN_SHIFT - 5)
1260adfc5217SJeff Kirsher 
1261adfc5217SJeff Kirsher 	struct host_sp_status_block *def_status_blk;
1262adfc5217SJeff Kirsher #define DEF_SB_IGU_ID			16
1263adfc5217SJeff Kirsher #define DEF_SB_ID			HC_SP_SB_ID
1264adfc5217SJeff Kirsher 	__le16			def_idx;
1265adfc5217SJeff Kirsher 	__le16			def_att_idx;
1266adfc5217SJeff Kirsher 	u32			attn_state;
1267adfc5217SJeff Kirsher 	struct attn_route	attn_group[MAX_DYNAMIC_ATTN_GRPS];
1268adfc5217SJeff Kirsher 
1269adfc5217SJeff Kirsher 	/* slow path ring */
1270adfc5217SJeff Kirsher 	struct eth_spe		*spq;
1271adfc5217SJeff Kirsher 	dma_addr_t		spq_mapping;
1272adfc5217SJeff Kirsher 	u16			spq_prod_idx;
1273adfc5217SJeff Kirsher 	struct eth_spe		*spq_prod_bd;
1274adfc5217SJeff Kirsher 	struct eth_spe		*spq_last_bd;
1275adfc5217SJeff Kirsher 	__le16			*dsb_sp_prod;
1276adfc5217SJeff Kirsher 	atomic_t		cq_spq_left; /* ETH_XXX ramrods credit */
1277adfc5217SJeff Kirsher 	/* used to synchronize spq accesses */
1278adfc5217SJeff Kirsher 	spinlock_t		spq_lock;
1279adfc5217SJeff Kirsher 
1280adfc5217SJeff Kirsher 	/* event queue */
1281adfc5217SJeff Kirsher 	union event_ring_elem	*eq_ring;
1282adfc5217SJeff Kirsher 	dma_addr_t		eq_mapping;
1283adfc5217SJeff Kirsher 	u16			eq_prod;
1284adfc5217SJeff Kirsher 	u16			eq_cons;
1285adfc5217SJeff Kirsher 	__le16			*eq_cons_sb;
1286adfc5217SJeff Kirsher 	atomic_t		eq_spq_left; /* COMMON_XXX ramrods credit */
1287adfc5217SJeff Kirsher 
1288adfc5217SJeff Kirsher 
1289adfc5217SJeff Kirsher 
1290adfc5217SJeff Kirsher 	/* Counter for marking that there is a STAT_QUERY ramrod pending */
1291adfc5217SJeff Kirsher 	u16			stats_pending;
1292adfc5217SJeff Kirsher 	/*  Counter for completed statistics ramrods */
1293adfc5217SJeff Kirsher 	u16			stats_comp;
1294adfc5217SJeff Kirsher 
1295adfc5217SJeff Kirsher 	/* End of fields used in the performance code paths */
1296adfc5217SJeff Kirsher 
1297adfc5217SJeff Kirsher 	int			panic;
1298adfc5217SJeff Kirsher 	int			msg_enable;
1299adfc5217SJeff Kirsher 
1300adfc5217SJeff Kirsher 	u32			flags;
1301adfc5217SJeff Kirsher #define PCIX_FLAG			(1 << 0)
1302adfc5217SJeff Kirsher #define PCI_32BIT_FLAG			(1 << 1)
1303adfc5217SJeff Kirsher #define ONE_PORT_FLAG			(1 << 2)
1304adfc5217SJeff Kirsher #define NO_WOL_FLAG			(1 << 3)
1305adfc5217SJeff Kirsher #define USING_DAC_FLAG			(1 << 4)
1306adfc5217SJeff Kirsher #define USING_MSIX_FLAG			(1 << 5)
1307adfc5217SJeff Kirsher #define USING_MSI_FLAG			(1 << 6)
1308adfc5217SJeff Kirsher #define DISABLE_MSI_FLAG		(1 << 7)
1309adfc5217SJeff Kirsher #define TPA_ENABLE_FLAG			(1 << 8)
1310adfc5217SJeff Kirsher #define NO_MCP_FLAG			(1 << 9)
1311adfc5217SJeff Kirsher 
1312adfc5217SJeff Kirsher #define BP_NOMCP(bp)			(bp->flags & NO_MCP_FLAG)
1313621b4d66SDmitry Kravkov #define GRO_ENABLE_FLAG			(1 << 10)
1314adfc5217SJeff Kirsher #define MF_FUNC_DIS			(1 << 11)
1315adfc5217SJeff Kirsher #define OWN_CNIC_IRQ			(1 << 12)
1316adfc5217SJeff Kirsher #define NO_ISCSI_OOO_FLAG		(1 << 13)
1317adfc5217SJeff Kirsher #define NO_ISCSI_FLAG			(1 << 14)
1318adfc5217SJeff Kirsher #define NO_FCOE_FLAG			(1 << 15)
13190e898dd7SBarak Witkowski #define BC_SUPPORTS_PFC_STATS		(1 << 17)
132030a5de77SDmitry Kravkov #define USING_SINGLE_MSIX_FLAG		(1 << 20)
13219876879fSBarak Witkowski #define BC_SUPPORTS_DCBX_MSG_NON_PMF	(1 << 21)
1322adfc5217SJeff Kirsher 
1323adfc5217SJeff Kirsher #define NO_ISCSI(bp)		((bp)->flags & NO_ISCSI_FLAG)
1324adfc5217SJeff Kirsher #define NO_ISCSI_OOO(bp)	((bp)->flags & NO_ISCSI_OOO_FLAG)
1325adfc5217SJeff Kirsher #define NO_FCOE(bp)		((bp)->flags & NO_FCOE_FLAG)
1326adfc5217SJeff Kirsher 
1327adfc5217SJeff Kirsher 	int			pm_cap;
1328adfc5217SJeff Kirsher 	int			mrrs;
1329adfc5217SJeff Kirsher 
1330adfc5217SJeff Kirsher 	struct delayed_work	sp_task;
1331adfc5217SJeff Kirsher 	struct delayed_work	sp_rtnl_task;
1332adfc5217SJeff Kirsher 
1333adfc5217SJeff Kirsher 	struct delayed_work	period_task;
1334adfc5217SJeff Kirsher 	struct timer_list	timer;
1335adfc5217SJeff Kirsher 	int			current_interval;
1336adfc5217SJeff Kirsher 
1337adfc5217SJeff Kirsher 	u16			fw_seq;
1338adfc5217SJeff Kirsher 	u16			fw_drv_pulse_wr_seq;
1339adfc5217SJeff Kirsher 	u32			func_stx;
1340adfc5217SJeff Kirsher 
1341adfc5217SJeff Kirsher 	struct link_params	link_params;
1342adfc5217SJeff Kirsher 	struct link_vars	link_vars;
1343adfc5217SJeff Kirsher 	u32			link_cnt;
1344adfc5217SJeff Kirsher 	struct bnx2x_link_report_data last_reported_link;
1345adfc5217SJeff Kirsher 
1346adfc5217SJeff Kirsher 	struct mdio_if_info	mdio;
1347adfc5217SJeff Kirsher 
1348adfc5217SJeff Kirsher 	struct bnx2x_common	common;
1349adfc5217SJeff Kirsher 	struct bnx2x_port	port;
1350adfc5217SJeff Kirsher 
1351b475d78fSYuval Mintz 	struct cmng_init	cmng;
1352b475d78fSYuval Mintz 
1353adfc5217SJeff Kirsher 	u32			mf_config[E1HVN_MAX];
1354a3348722SBarak Witkowski 	u32			mf_ext_config;
1355adfc5217SJeff Kirsher 	u32			path_has_ovlan; /* E3 */
1356adfc5217SJeff Kirsher 	u16			mf_ov;
1357adfc5217SJeff Kirsher 	u8			mf_mode;
1358adfc5217SJeff Kirsher #define IS_MF(bp)		(bp->mf_mode != 0)
1359adfc5217SJeff Kirsher #define IS_MF_SI(bp)		(bp->mf_mode == MULTI_FUNCTION_SI)
1360adfc5217SJeff Kirsher #define IS_MF_SD(bp)		(bp->mf_mode == MULTI_FUNCTION_SD)
1361a3348722SBarak Witkowski #define IS_MF_AFEX(bp)		(bp->mf_mode == MULTI_FUNCTION_AFEX)
1362adfc5217SJeff Kirsher 
1363adfc5217SJeff Kirsher 	u8			wol;
1364adfc5217SJeff Kirsher 
1365adfc5217SJeff Kirsher 	int			rx_ring_size;
1366adfc5217SJeff Kirsher 
1367adfc5217SJeff Kirsher 	u16			tx_quick_cons_trip_int;
1368adfc5217SJeff Kirsher 	u16			tx_quick_cons_trip;
1369adfc5217SJeff Kirsher 	u16			tx_ticks_int;
1370adfc5217SJeff Kirsher 	u16			tx_ticks;
1371adfc5217SJeff Kirsher 
1372adfc5217SJeff Kirsher 	u16			rx_quick_cons_trip_int;
1373adfc5217SJeff Kirsher 	u16			rx_quick_cons_trip;
1374adfc5217SJeff Kirsher 	u16			rx_ticks_int;
1375adfc5217SJeff Kirsher 	u16			rx_ticks;
1376adfc5217SJeff Kirsher /* Maximal coalescing timeout in us */
1377adfc5217SJeff Kirsher #define BNX2X_MAX_COALESCE_TOUT		(0xf0*12)
1378adfc5217SJeff Kirsher 
1379adfc5217SJeff Kirsher 	u32			lin_cnt;
1380adfc5217SJeff Kirsher 
1381adfc5217SJeff Kirsher 	u16			state;
1382adfc5217SJeff Kirsher #define BNX2X_STATE_CLOSED		0
1383adfc5217SJeff Kirsher #define BNX2X_STATE_OPENING_WAIT4_LOAD	0x1000
1384adfc5217SJeff Kirsher #define BNX2X_STATE_OPENING_WAIT4_PORT	0x2000
1385adfc5217SJeff Kirsher #define BNX2X_STATE_OPEN		0x3000
1386adfc5217SJeff Kirsher #define BNX2X_STATE_CLOSING_WAIT4_HALT	0x4000
1387adfc5217SJeff Kirsher #define BNX2X_STATE_CLOSING_WAIT4_DELETE 0x5000
1388adfc5217SJeff Kirsher 
1389adfc5217SJeff Kirsher #define BNX2X_STATE_DIAG		0xe000
1390adfc5217SJeff Kirsher #define BNX2X_STATE_ERROR		0xf000
1391adfc5217SJeff Kirsher 
1392adfc5217SJeff Kirsher #define BNX2X_MAX_PRIORITY		8
1393adfc5217SJeff Kirsher #define BNX2X_MAX_ENTRIES_PER_PRI	16
1394adfc5217SJeff Kirsher #define BNX2X_MAX_COS			3
1395adfc5217SJeff Kirsher #define BNX2X_MAX_TX_COS		2
1396adfc5217SJeff Kirsher 	int			num_queues;
13970e8d2ec5SMerav Sicron 	int			num_napi_queues;
1398adfc5217SJeff Kirsher 	int			disable_tpa;
1399adfc5217SJeff Kirsher 
1400adfc5217SJeff Kirsher 	u32			rx_mode;
1401adfc5217SJeff Kirsher #define BNX2X_RX_MODE_NONE		0
1402adfc5217SJeff Kirsher #define BNX2X_RX_MODE_NORMAL		1
1403adfc5217SJeff Kirsher #define BNX2X_RX_MODE_ALLMULTI		2
1404adfc5217SJeff Kirsher #define BNX2X_RX_MODE_PROMISC		3
1405adfc5217SJeff Kirsher #define BNX2X_MAX_MULTICAST		64
1406adfc5217SJeff Kirsher 
1407adfc5217SJeff Kirsher 	u8			igu_dsb_id;
1408adfc5217SJeff Kirsher 	u8			igu_base_sb;
1409adfc5217SJeff Kirsher 	u8			igu_sb_cnt;
141065565884SMerav Sicron 
1411adfc5217SJeff Kirsher 	dma_addr_t		def_status_blk_mapping;
1412adfc5217SJeff Kirsher 
1413adfc5217SJeff Kirsher 	struct bnx2x_slowpath	*slowpath;
1414adfc5217SJeff Kirsher 	dma_addr_t		slowpath_mapping;
1415adfc5217SJeff Kirsher 
1416adfc5217SJeff Kirsher 	/* Total number of FW statistics requests */
1417adfc5217SJeff Kirsher 	u8			fw_stats_num;
1418adfc5217SJeff Kirsher 
1419adfc5217SJeff Kirsher 	/*
1420adfc5217SJeff Kirsher 	 * This is a memory buffer that will contain both statistics
1421adfc5217SJeff Kirsher 	 * ramrod request and data.
1422adfc5217SJeff Kirsher 	 */
1423adfc5217SJeff Kirsher 	void			*fw_stats;
1424adfc5217SJeff Kirsher 	dma_addr_t		fw_stats_mapping;
1425adfc5217SJeff Kirsher 
1426adfc5217SJeff Kirsher 	/*
1427adfc5217SJeff Kirsher 	 * FW statistics request shortcut (points at the
1428adfc5217SJeff Kirsher 	 * beginning of fw_stats buffer).
1429adfc5217SJeff Kirsher 	 */
1430adfc5217SJeff Kirsher 	struct bnx2x_fw_stats_req	*fw_stats_req;
1431adfc5217SJeff Kirsher 	dma_addr_t			fw_stats_req_mapping;
1432adfc5217SJeff Kirsher 	int				fw_stats_req_sz;
1433adfc5217SJeff Kirsher 
1434adfc5217SJeff Kirsher 	/*
1435adfc5217SJeff Kirsher 	 * FW statistics data shortcut (points at the begining of
1436adfc5217SJeff Kirsher 	 * fw_stats buffer + fw_stats_req_sz).
1437adfc5217SJeff Kirsher 	 */
1438adfc5217SJeff Kirsher 	struct bnx2x_fw_stats_data	*fw_stats_data;
1439adfc5217SJeff Kirsher 	dma_addr_t			fw_stats_data_mapping;
1440adfc5217SJeff Kirsher 	int				fw_stats_data_sz;
1441adfc5217SJeff Kirsher 
1442a052997eSMerav Sicron 	/* For max 196 cids (64*3 + non-eth), 32KB ILT page size and 1KB
1443a052997eSMerav Sicron 	 * context size we need 8 ILT entries.
1444a052997eSMerav Sicron 	 */
1445a052997eSMerav Sicron #define ILT_MAX_L2_LINES	8
1446a052997eSMerav Sicron 	struct hw_context	context[ILT_MAX_L2_LINES];
1447adfc5217SJeff Kirsher 
1448adfc5217SJeff Kirsher 	struct bnx2x_ilt	*ilt;
1449adfc5217SJeff Kirsher #define BP_ILT(bp)		((bp)->ilt)
1450adfc5217SJeff Kirsher #define ILT_MAX_LINES		256
1451adfc5217SJeff Kirsher /*
1452adfc5217SJeff Kirsher  * Maximum supported number of RSS queues: number of IGU SBs minus one that goes
1453adfc5217SJeff Kirsher  * to CNIC.
1454adfc5217SJeff Kirsher  */
1455adfc5217SJeff Kirsher #define BNX2X_MAX_RSS_COUNT(bp)	((bp)->igu_sb_cnt - CNIC_PRESENT)
1456adfc5217SJeff Kirsher 
1457adfc5217SJeff Kirsher /*
1458adfc5217SJeff Kirsher  * Maximum CID count that might be required by the bnx2x:
145937ae41a9SMerav Sicron  * Max RSS * Max_Tx_Multi_Cos + FCoE + iSCSI
1460adfc5217SJeff Kirsher  */
146137ae41a9SMerav Sicron #define BNX2X_L2_CID_COUNT(bp)	(BNX2X_NUM_ETH_QUEUES(bp) * BNX2X_MULTI_TX_COS \
146237ae41a9SMerav Sicron 				+ NON_ETH_CONTEXT_USE + CNIC_PRESENT)
146337ae41a9SMerav Sicron #define BNX2X_L2_MAX_CID(bp)	(BNX2X_MAX_RSS_COUNT(bp) * BNX2X_MULTI_TX_COS \
146437ae41a9SMerav Sicron 				+ NON_ETH_CONTEXT_USE + CNIC_PRESENT)
1465adfc5217SJeff Kirsher #define L2_ILT_LINES(bp)	(DIV_ROUND_UP(BNX2X_L2_CID_COUNT(bp),\
1466adfc5217SJeff Kirsher 					ILT_PAGE_CIDS))
1467adfc5217SJeff Kirsher 
1468adfc5217SJeff Kirsher 	int			qm_cid_count;
1469adfc5217SJeff Kirsher 
1470adfc5217SJeff Kirsher 	int			dropless_fc;
1471adfc5217SJeff Kirsher 
1472adfc5217SJeff Kirsher #ifdef BCM_CNIC
1473adfc5217SJeff Kirsher 	u32			cnic_flags;
1474adfc5217SJeff Kirsher #define BNX2X_CNIC_FLAG_MAC_SET		1
1475adfc5217SJeff Kirsher 	void			*t2;
1476adfc5217SJeff Kirsher 	dma_addr_t		t2_mapping;
1477adfc5217SJeff Kirsher 	struct cnic_ops	__rcu	*cnic_ops;
1478adfc5217SJeff Kirsher 	void			*cnic_data;
1479adfc5217SJeff Kirsher 	u32			cnic_tag;
1480adfc5217SJeff Kirsher 	struct cnic_eth_dev	cnic_eth_dev;
1481adfc5217SJeff Kirsher 	union host_hc_status_block cnic_sb;
1482adfc5217SJeff Kirsher 	dma_addr_t		cnic_sb_mapping;
1483adfc5217SJeff Kirsher 	struct eth_spe		*cnic_kwq;
1484adfc5217SJeff Kirsher 	struct eth_spe		*cnic_kwq_prod;
1485adfc5217SJeff Kirsher 	struct eth_spe		*cnic_kwq_cons;
1486adfc5217SJeff Kirsher 	struct eth_spe		*cnic_kwq_last;
1487adfc5217SJeff Kirsher 	u16			cnic_kwq_pending;
1488adfc5217SJeff Kirsher 	u16			cnic_spq_pending;
1489adfc5217SJeff Kirsher 	u8			fip_mac[ETH_ALEN];
1490adfc5217SJeff Kirsher 	struct mutex		cnic_mutex;
1491adfc5217SJeff Kirsher 	struct bnx2x_vlan_mac_obj iscsi_l2_mac_obj;
1492adfc5217SJeff Kirsher 
1493adfc5217SJeff Kirsher 	/* Start index of the "special" (CNIC related) L2 cleints */
1494adfc5217SJeff Kirsher 	u8				cnic_base_cl_id;
1495adfc5217SJeff Kirsher #endif
1496adfc5217SJeff Kirsher 
1497adfc5217SJeff Kirsher 	int			dmae_ready;
1498adfc5217SJeff Kirsher 	/* used to synchronize dmae accesses */
1499adfc5217SJeff Kirsher 	spinlock_t		dmae_lock;
1500adfc5217SJeff Kirsher 
1501adfc5217SJeff Kirsher 	/* used to protect the FW mail box */
1502adfc5217SJeff Kirsher 	struct mutex		fw_mb_mutex;
1503adfc5217SJeff Kirsher 
1504adfc5217SJeff Kirsher 	/* used to synchronize stats collecting */
1505adfc5217SJeff Kirsher 	int			stats_state;
1506adfc5217SJeff Kirsher 
1507adfc5217SJeff Kirsher 	/* used for synchronization of concurrent threads statistics handling */
1508adfc5217SJeff Kirsher 	spinlock_t		stats_lock;
1509adfc5217SJeff Kirsher 
1510adfc5217SJeff Kirsher 	/* used by dmae command loader */
1511adfc5217SJeff Kirsher 	struct dmae_command	stats_dmae;
1512adfc5217SJeff Kirsher 	int			executer_idx;
1513adfc5217SJeff Kirsher 
1514adfc5217SJeff Kirsher 	u16			stats_counter;
1515adfc5217SJeff Kirsher 	struct bnx2x_eth_stats	eth_stats;
1516cb4dca27SYuval Mintz 	struct host_func_stats		func_stats;
15171355b704SMintz Yuval 	struct bnx2x_eth_stats_old	eth_stats_old;
15181355b704SMintz Yuval 	struct bnx2x_net_stats_old	net_stats_old;
15191355b704SMintz Yuval 	struct bnx2x_fw_port_stats_old	fw_stats_old;
15201355b704SMintz Yuval 	bool			stats_init;
1521adfc5217SJeff Kirsher 
1522adfc5217SJeff Kirsher 	struct z_stream_s	*strm;
1523adfc5217SJeff Kirsher 	void			*gunzip_buf;
1524adfc5217SJeff Kirsher 	dma_addr_t		gunzip_mapping;
1525adfc5217SJeff Kirsher 	int			gunzip_outlen;
1526adfc5217SJeff Kirsher #define FW_BUF_SIZE			0x8000
1527adfc5217SJeff Kirsher #define GUNZIP_BUF(bp)			(bp->gunzip_buf)
1528adfc5217SJeff Kirsher #define GUNZIP_PHYS(bp)			(bp->gunzip_mapping)
1529adfc5217SJeff Kirsher #define GUNZIP_OUTLEN(bp)		(bp->gunzip_outlen)
1530adfc5217SJeff Kirsher 
1531adfc5217SJeff Kirsher 	struct raw_op		*init_ops;
1532adfc5217SJeff Kirsher 	/* Init blocks offsets inside init_ops */
1533adfc5217SJeff Kirsher 	u16			*init_ops_offsets;
1534adfc5217SJeff Kirsher 	/* Data blob - has 32 bit granularity */
1535adfc5217SJeff Kirsher 	u32			*init_data;
1536adfc5217SJeff Kirsher 	u32			init_mode_flags;
1537adfc5217SJeff Kirsher #define INIT_MODE_FLAGS(bp)	(bp->init_mode_flags)
1538adfc5217SJeff Kirsher 	/* Zipped PRAM blobs - raw data */
1539adfc5217SJeff Kirsher 	const u8		*tsem_int_table_data;
1540adfc5217SJeff Kirsher 	const u8		*tsem_pram_data;
1541adfc5217SJeff Kirsher 	const u8		*usem_int_table_data;
1542adfc5217SJeff Kirsher 	const u8		*usem_pram_data;
1543adfc5217SJeff Kirsher 	const u8		*xsem_int_table_data;
1544adfc5217SJeff Kirsher 	const u8		*xsem_pram_data;
1545adfc5217SJeff Kirsher 	const u8		*csem_int_table_data;
1546adfc5217SJeff Kirsher 	const u8		*csem_pram_data;
1547adfc5217SJeff Kirsher #define INIT_OPS(bp)			(bp->init_ops)
1548adfc5217SJeff Kirsher #define INIT_OPS_OFFSETS(bp)		(bp->init_ops_offsets)
1549adfc5217SJeff Kirsher #define INIT_DATA(bp)			(bp->init_data)
1550adfc5217SJeff Kirsher #define INIT_TSEM_INT_TABLE_DATA(bp)	(bp->tsem_int_table_data)
1551adfc5217SJeff Kirsher #define INIT_TSEM_PRAM_DATA(bp)		(bp->tsem_pram_data)
1552adfc5217SJeff Kirsher #define INIT_USEM_INT_TABLE_DATA(bp)	(bp->usem_int_table_data)
1553adfc5217SJeff Kirsher #define INIT_USEM_PRAM_DATA(bp)		(bp->usem_pram_data)
1554adfc5217SJeff Kirsher #define INIT_XSEM_INT_TABLE_DATA(bp)	(bp->xsem_int_table_data)
1555adfc5217SJeff Kirsher #define INIT_XSEM_PRAM_DATA(bp)		(bp->xsem_pram_data)
1556adfc5217SJeff Kirsher #define INIT_CSEM_INT_TABLE_DATA(bp)	(bp->csem_int_table_data)
1557adfc5217SJeff Kirsher #define INIT_CSEM_PRAM_DATA(bp)		(bp->csem_pram_data)
1558adfc5217SJeff Kirsher 
1559adfc5217SJeff Kirsher #define PHY_FW_VER_LEN			20
1560adfc5217SJeff Kirsher 	char			fw_ver[32];
1561adfc5217SJeff Kirsher 	const struct firmware	*firmware;
1562adfc5217SJeff Kirsher 
1563adfc5217SJeff Kirsher 	/* DCB support on/off */
1564adfc5217SJeff Kirsher 	u16 dcb_state;
1565adfc5217SJeff Kirsher #define BNX2X_DCB_STATE_OFF			0
1566adfc5217SJeff Kirsher #define BNX2X_DCB_STATE_ON			1
1567adfc5217SJeff Kirsher 
1568adfc5217SJeff Kirsher 	/* DCBX engine mode */
1569adfc5217SJeff Kirsher 	int dcbx_enabled;
1570adfc5217SJeff Kirsher #define BNX2X_DCBX_ENABLED_OFF			0
1571adfc5217SJeff Kirsher #define BNX2X_DCBX_ENABLED_ON_NEG_OFF		1
1572adfc5217SJeff Kirsher #define BNX2X_DCBX_ENABLED_ON_NEG_ON		2
1573adfc5217SJeff Kirsher #define BNX2X_DCBX_ENABLED_INVALID		(-1)
1574adfc5217SJeff Kirsher 
1575adfc5217SJeff Kirsher 	bool dcbx_mode_uset;
1576adfc5217SJeff Kirsher 
1577adfc5217SJeff Kirsher 	struct bnx2x_config_dcbx_params		dcbx_config_params;
1578adfc5217SJeff Kirsher 	struct bnx2x_dcbx_port_params		dcbx_port_params;
1579adfc5217SJeff Kirsher 	int					dcb_version;
1580adfc5217SJeff Kirsher 
1581adfc5217SJeff Kirsher 	/* CAM credit pools */
1582adfc5217SJeff Kirsher 	struct bnx2x_credit_pool_obj		macs_pool;
1583adfc5217SJeff Kirsher 
1584adfc5217SJeff Kirsher 	/* RX_MODE object */
1585adfc5217SJeff Kirsher 	struct bnx2x_rx_mode_obj		rx_mode_obj;
1586adfc5217SJeff Kirsher 
1587adfc5217SJeff Kirsher 	/* MCAST object */
1588adfc5217SJeff Kirsher 	struct bnx2x_mcast_obj			mcast_obj;
1589adfc5217SJeff Kirsher 
1590adfc5217SJeff Kirsher 	/* RSS configuration object */
1591adfc5217SJeff Kirsher 	struct bnx2x_rss_config_obj		rss_conf_obj;
1592adfc5217SJeff Kirsher 
1593adfc5217SJeff Kirsher 	/* Function State controlling object */
1594adfc5217SJeff Kirsher 	struct bnx2x_func_sp_obj		func_obj;
1595adfc5217SJeff Kirsher 
1596adfc5217SJeff Kirsher 	unsigned long				sp_state;
1597adfc5217SJeff Kirsher 
1598adfc5217SJeff Kirsher 	/* operation indication for the sp_rtnl task */
1599adfc5217SJeff Kirsher 	unsigned long				sp_rtnl_state;
1600adfc5217SJeff Kirsher 
1601adfc5217SJeff Kirsher 	/* DCBX Negotation results */
1602adfc5217SJeff Kirsher 	struct dcbx_features			dcbx_local_feat;
1603adfc5217SJeff Kirsher 	u32					dcbx_error;
1604adfc5217SJeff Kirsher 
1605adfc5217SJeff Kirsher #ifdef BCM_DCBNL
1606adfc5217SJeff Kirsher 	struct dcbx_features			dcbx_remote_feat;
1607adfc5217SJeff Kirsher 	u32					dcbx_remote_flags;
1608adfc5217SJeff Kirsher #endif
1609a3348722SBarak Witkowski 	/* AFEX: store default vlan used */
1610a3348722SBarak Witkowski 	int					afex_def_vlan_tag;
1611a3348722SBarak Witkowski 	enum mf_cfg_afex_vlan_mode		afex_vlan_mode;
1612adfc5217SJeff Kirsher 	u32					pending_max;
1613adfc5217SJeff Kirsher 
1614adfc5217SJeff Kirsher 	/* multiple tx classes of service */
1615adfc5217SJeff Kirsher 	u8					max_cos;
1616adfc5217SJeff Kirsher 
1617adfc5217SJeff Kirsher 	/* priority to cos mapping */
1618adfc5217SJeff Kirsher 	u8					prio_to_cos[8];
1619adfc5217SJeff Kirsher };
1620adfc5217SJeff Kirsher 
1621adfc5217SJeff Kirsher /* Tx queues may be less or equal to Rx queues */
1622adfc5217SJeff Kirsher extern int num_queues;
1623adfc5217SJeff Kirsher #define BNX2X_NUM_QUEUES(bp)	(bp->num_queues)
1624adfc5217SJeff Kirsher #define BNX2X_NUM_ETH_QUEUES(bp) (BNX2X_NUM_QUEUES(bp) - NON_ETH_CONTEXT_USE)
162565565884SMerav Sicron #define BNX2X_NUM_NON_CNIC_QUEUES(bp)	(BNX2X_NUM_QUEUES(bp) - \
162665565884SMerav Sicron 					 NON_ETH_CONTEXT_USE)
1627adfc5217SJeff Kirsher #define BNX2X_NUM_RX_QUEUES(bp)	BNX2X_NUM_QUEUES(bp)
1628adfc5217SJeff Kirsher 
1629adfc5217SJeff Kirsher #define is_multi(bp)		(BNX2X_NUM_QUEUES(bp) > 1)
1630adfc5217SJeff Kirsher 
1631adfc5217SJeff Kirsher #define BNX2X_MAX_QUEUES(bp)	BNX2X_MAX_RSS_COUNT(bp)
1632adfc5217SJeff Kirsher /* #define is_eth_multi(bp)	(BNX2X_NUM_ETH_QUEUES(bp) > 1) */
1633adfc5217SJeff Kirsher 
1634adfc5217SJeff Kirsher #define RSS_IPV4_CAP_MASK						\
1635adfc5217SJeff Kirsher 	TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY
1636adfc5217SJeff Kirsher 
1637adfc5217SJeff Kirsher #define RSS_IPV4_TCP_CAP_MASK						\
1638adfc5217SJeff Kirsher 	TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY
1639adfc5217SJeff Kirsher 
1640adfc5217SJeff Kirsher #define RSS_IPV6_CAP_MASK						\
1641adfc5217SJeff Kirsher 	TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY
1642adfc5217SJeff Kirsher 
1643adfc5217SJeff Kirsher #define RSS_IPV6_TCP_CAP_MASK						\
1644adfc5217SJeff Kirsher 	TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY
1645adfc5217SJeff Kirsher 
1646adfc5217SJeff Kirsher /* func init flags */
1647adfc5217SJeff Kirsher #define FUNC_FLG_RSS		0x0001
1648adfc5217SJeff Kirsher #define FUNC_FLG_STATS		0x0002
1649adfc5217SJeff Kirsher /* removed  FUNC_FLG_UNMATCHED	0x0004 */
1650adfc5217SJeff Kirsher #define FUNC_FLG_TPA		0x0008
1651adfc5217SJeff Kirsher #define FUNC_FLG_SPQ		0x0010
1652adfc5217SJeff Kirsher #define FUNC_FLG_LEADING	0x0020	/* PF only */
1653adfc5217SJeff Kirsher 
1654adfc5217SJeff Kirsher 
1655adfc5217SJeff Kirsher struct bnx2x_func_init_params {
1656adfc5217SJeff Kirsher 	/* dma */
1657adfc5217SJeff Kirsher 	dma_addr_t	fw_stat_map;	/* valid iff FUNC_FLG_STATS */
1658adfc5217SJeff Kirsher 	dma_addr_t	spq_map;	/* valid iff FUNC_FLG_SPQ */
1659adfc5217SJeff Kirsher 
1660adfc5217SJeff Kirsher 	u16		func_flgs;
1661adfc5217SJeff Kirsher 	u16		func_id;	/* abs fid */
1662adfc5217SJeff Kirsher 	u16		pf_id;
1663adfc5217SJeff Kirsher 	u16		spq_prod;	/* valid iff FUNC_FLG_SPQ */
1664adfc5217SJeff Kirsher };
1665adfc5217SJeff Kirsher 
1666adfc5217SJeff Kirsher #define for_each_eth_queue(bp, var) \
1667adfc5217SJeff Kirsher 	for ((var) = 0; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
1668adfc5217SJeff Kirsher 
1669adfc5217SJeff Kirsher #define for_each_nondefault_eth_queue(bp, var) \
1670adfc5217SJeff Kirsher 	for ((var) = 1; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
1671adfc5217SJeff Kirsher 
1672adfc5217SJeff Kirsher #define for_each_queue(bp, var) \
1673adfc5217SJeff Kirsher 	for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
1674adfc5217SJeff Kirsher 		if (skip_queue(bp, var))	\
1675adfc5217SJeff Kirsher 			continue;		\
1676adfc5217SJeff Kirsher 		else
1677adfc5217SJeff Kirsher 
1678adfc5217SJeff Kirsher /* Skip forwarding FP */
1679adfc5217SJeff Kirsher #define for_each_rx_queue(bp, var) \
1680adfc5217SJeff Kirsher 	for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
1681adfc5217SJeff Kirsher 		if (skip_rx_queue(bp, var))	\
1682adfc5217SJeff Kirsher 			continue;		\
1683adfc5217SJeff Kirsher 		else
1684adfc5217SJeff Kirsher 
16850e8d2ec5SMerav Sicron #define for_each_napi_rx_queue(bp, var) \
16860e8d2ec5SMerav Sicron 	for ((var) = 0; (var) < bp->num_napi_queues; (var)++)
16870e8d2ec5SMerav Sicron 
1688adfc5217SJeff Kirsher /* Skip OOO FP */
1689adfc5217SJeff Kirsher #define for_each_tx_queue(bp, var) \
1690adfc5217SJeff Kirsher 	for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
1691adfc5217SJeff Kirsher 		if (skip_tx_queue(bp, var))	\
1692adfc5217SJeff Kirsher 			continue;		\
1693adfc5217SJeff Kirsher 		else
1694adfc5217SJeff Kirsher 
1695adfc5217SJeff Kirsher #define for_each_nondefault_queue(bp, var) \
1696adfc5217SJeff Kirsher 	for ((var) = 1; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
1697adfc5217SJeff Kirsher 		if (skip_queue(bp, var))	\
1698adfc5217SJeff Kirsher 			continue;		\
1699adfc5217SJeff Kirsher 		else
1700adfc5217SJeff Kirsher 
1701adfc5217SJeff Kirsher #define for_each_cos_in_tx_queue(fp, var) \
1702adfc5217SJeff Kirsher 	for ((var) = 0; (var) < (fp)->max_cos; (var)++)
1703adfc5217SJeff Kirsher 
1704adfc5217SJeff Kirsher /* skip rx queue
1705adfc5217SJeff Kirsher  * if FCOE l2 support is disabled and this is the fcoe L2 queue
1706adfc5217SJeff Kirsher  */
1707adfc5217SJeff Kirsher #define skip_rx_queue(bp, idx)	(NO_FCOE(bp) && IS_FCOE_IDX(idx))
1708adfc5217SJeff Kirsher 
1709adfc5217SJeff Kirsher /* skip tx queue
1710adfc5217SJeff Kirsher  * if FCOE l2 support is disabled and this is the fcoe L2 queue
1711adfc5217SJeff Kirsher  */
1712adfc5217SJeff Kirsher #define skip_tx_queue(bp, idx)	(NO_FCOE(bp) && IS_FCOE_IDX(idx))
1713adfc5217SJeff Kirsher 
1714adfc5217SJeff Kirsher #define skip_queue(bp, idx)	(NO_FCOE(bp) && IS_FCOE_IDX(idx))
1715adfc5217SJeff Kirsher 
1716adfc5217SJeff Kirsher 
1717adfc5217SJeff Kirsher 
1718adfc5217SJeff Kirsher 
1719adfc5217SJeff Kirsher /**
1720adfc5217SJeff Kirsher  * bnx2x_set_mac_one - configure a single MAC address
1721adfc5217SJeff Kirsher  *
1722adfc5217SJeff Kirsher  * @bp:			driver handle
1723adfc5217SJeff Kirsher  * @mac:		MAC to configure
1724adfc5217SJeff Kirsher  * @obj:		MAC object handle
1725adfc5217SJeff Kirsher  * @set:		if 'true' add a new MAC, otherwise - delete
1726adfc5217SJeff Kirsher  * @mac_type:		the type of the MAC to configure (e.g. ETH, UC list)
1727adfc5217SJeff Kirsher  * @ramrod_flags:	RAMROD_XXX flags (e.g. RAMROD_CONT, RAMROD_COMP_WAIT)
1728adfc5217SJeff Kirsher  *
1729adfc5217SJeff Kirsher  * Configures one MAC according to provided parameters or continues the
1730adfc5217SJeff Kirsher  * execution of previously scheduled commands if RAMROD_CONT is set in
1731adfc5217SJeff Kirsher  * ramrod_flags.
1732adfc5217SJeff Kirsher  *
1733adfc5217SJeff Kirsher  * Returns zero if operation has successfully completed, a positive value if the
1734adfc5217SJeff Kirsher  * operation has been successfully scheduled and a negative - if a requested
1735adfc5217SJeff Kirsher  * operations has failed.
1736adfc5217SJeff Kirsher  */
1737adfc5217SJeff Kirsher int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
1738adfc5217SJeff Kirsher 		      struct bnx2x_vlan_mac_obj *obj, bool set,
1739adfc5217SJeff Kirsher 		      int mac_type, unsigned long *ramrod_flags);
1740adfc5217SJeff Kirsher /**
1741adfc5217SJeff Kirsher  * Deletes all MACs configured for the specific MAC object.
1742adfc5217SJeff Kirsher  *
1743adfc5217SJeff Kirsher  * @param bp Function driver instance
1744adfc5217SJeff Kirsher  * @param mac_obj MAC object to cleanup
1745adfc5217SJeff Kirsher  *
1746adfc5217SJeff Kirsher  * @return zero if all MACs were cleaned
1747adfc5217SJeff Kirsher  */
1748adfc5217SJeff Kirsher 
1749adfc5217SJeff Kirsher /**
1750adfc5217SJeff Kirsher  * bnx2x_del_all_macs - delete all MACs configured for the specific MAC object
1751adfc5217SJeff Kirsher  *
1752adfc5217SJeff Kirsher  * @bp:			driver handle
1753adfc5217SJeff Kirsher  * @mac_obj:		MAC object handle
1754adfc5217SJeff Kirsher  * @mac_type:		type of the MACs to clear (BNX2X_XXX_MAC)
1755adfc5217SJeff Kirsher  * @wait_for_comp:	if 'true' block until completion
1756adfc5217SJeff Kirsher  *
1757adfc5217SJeff Kirsher  * Deletes all MACs of the specific type (e.g. ETH, UC list).
1758adfc5217SJeff Kirsher  *
1759adfc5217SJeff Kirsher  * Returns zero if operation has successfully completed, a positive value if the
1760adfc5217SJeff Kirsher  * operation has been successfully scheduled and a negative - if a requested
1761adfc5217SJeff Kirsher  * operations has failed.
1762adfc5217SJeff Kirsher  */
1763adfc5217SJeff Kirsher int bnx2x_del_all_macs(struct bnx2x *bp,
1764adfc5217SJeff Kirsher 		       struct bnx2x_vlan_mac_obj *mac_obj,
1765adfc5217SJeff Kirsher 		       int mac_type, bool wait_for_comp);
1766adfc5217SJeff Kirsher 
1767adfc5217SJeff Kirsher /* Init Function API  */
1768adfc5217SJeff Kirsher void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p);
1769adfc5217SJeff Kirsher int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port);
1770adfc5217SJeff Kirsher int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
1771adfc5217SJeff Kirsher int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode);
1772adfc5217SJeff Kirsher int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
1773adfc5217SJeff Kirsher void bnx2x_read_mf_cfg(struct bnx2x *bp);
1774adfc5217SJeff Kirsher 
1775adfc5217SJeff Kirsher 
1776adfc5217SJeff Kirsher /* dmae */
1777adfc5217SJeff Kirsher void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
1778adfc5217SJeff Kirsher void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
1779adfc5217SJeff Kirsher 		      u32 len32);
1780adfc5217SJeff Kirsher void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx);
1781adfc5217SJeff Kirsher u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type);
1782adfc5217SJeff Kirsher u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode);
1783adfc5217SJeff Kirsher u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
1784adfc5217SJeff Kirsher 		      bool with_comp, u8 comp_type);
1785adfc5217SJeff Kirsher 
1786adfc5217SJeff Kirsher 
1787adfc5217SJeff Kirsher void bnx2x_calc_fc_adv(struct bnx2x *bp);
1788adfc5217SJeff Kirsher int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
1789adfc5217SJeff Kirsher 		  u32 data_hi, u32 data_lo, int cmd_type);
1790adfc5217SJeff Kirsher void bnx2x_update_coalesce(struct bnx2x *bp);
1791adfc5217SJeff Kirsher int bnx2x_get_cur_phy_idx(struct bnx2x *bp);
1792adfc5217SJeff Kirsher 
1793adfc5217SJeff Kirsher static inline u32 reg_poll(struct bnx2x *bp, u32 reg, u32 expected, int ms,
1794adfc5217SJeff Kirsher 			   int wait)
1795adfc5217SJeff Kirsher {
1796adfc5217SJeff Kirsher 	u32 val;
1797adfc5217SJeff Kirsher 
1798adfc5217SJeff Kirsher 	do {
1799adfc5217SJeff Kirsher 		val = REG_RD(bp, reg);
1800adfc5217SJeff Kirsher 		if (val == expected)
1801adfc5217SJeff Kirsher 			break;
1802adfc5217SJeff Kirsher 		ms -= wait;
1803adfc5217SJeff Kirsher 		msleep(wait);
1804adfc5217SJeff Kirsher 
1805adfc5217SJeff Kirsher 	} while (ms > 0);
1806adfc5217SJeff Kirsher 
1807adfc5217SJeff Kirsher 	return val;
1808adfc5217SJeff Kirsher }
1809adfc5217SJeff Kirsher 
1810adfc5217SJeff Kirsher #define BNX2X_ILT_ZALLOC(x, y, size) \
1811adfc5217SJeff Kirsher 	do { \
1812adfc5217SJeff Kirsher 		x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
1813adfc5217SJeff Kirsher 		if (x) \
1814adfc5217SJeff Kirsher 			memset(x, 0, size); \
1815adfc5217SJeff Kirsher 	} while (0)
1816adfc5217SJeff Kirsher 
1817adfc5217SJeff Kirsher #define BNX2X_ILT_FREE(x, y, size) \
1818adfc5217SJeff Kirsher 	do { \
1819adfc5217SJeff Kirsher 		if (x) { \
1820adfc5217SJeff Kirsher 			dma_free_coherent(&bp->pdev->dev, size, x, y); \
1821adfc5217SJeff Kirsher 			x = NULL; \
1822adfc5217SJeff Kirsher 			y = 0; \
1823adfc5217SJeff Kirsher 		} \
1824adfc5217SJeff Kirsher 	} while (0)
1825adfc5217SJeff Kirsher 
1826adfc5217SJeff Kirsher #define ILOG2(x)	(ilog2((x)))
1827adfc5217SJeff Kirsher 
1828adfc5217SJeff Kirsher #define ILT_NUM_PAGE_ENTRIES	(3072)
1829adfc5217SJeff Kirsher /* In 57710/11 we use whole table since we have 8 func
1830adfc5217SJeff Kirsher  * In 57712 we have only 4 func, but use same size per func, then only half of
1831adfc5217SJeff Kirsher  * the table in use
1832adfc5217SJeff Kirsher  */
1833adfc5217SJeff Kirsher #define ILT_PER_FUNC		(ILT_NUM_PAGE_ENTRIES/8)
1834adfc5217SJeff Kirsher 
1835adfc5217SJeff Kirsher #define FUNC_ILT_BASE(func)	(func * ILT_PER_FUNC)
1836adfc5217SJeff Kirsher /*
1837adfc5217SJeff Kirsher  * the phys address is shifted right 12 bits and has an added
1838adfc5217SJeff Kirsher  * 1=valid bit added to the 53rd bit
1839adfc5217SJeff Kirsher  * then since this is a wide register(TM)
1840adfc5217SJeff Kirsher  * we split it into two 32 bit writes
1841adfc5217SJeff Kirsher  */
1842adfc5217SJeff Kirsher #define ONCHIP_ADDR1(x)		((u32)(((u64)x >> 12) & 0xFFFFFFFF))
1843adfc5217SJeff Kirsher #define ONCHIP_ADDR2(x)		((u32)((1 << 20) | ((u64)x >> 44)))
1844adfc5217SJeff Kirsher 
1845adfc5217SJeff Kirsher /* load/unload mode */
1846adfc5217SJeff Kirsher #define LOAD_NORMAL			0
1847adfc5217SJeff Kirsher #define LOAD_OPEN			1
1848adfc5217SJeff Kirsher #define LOAD_DIAG			2
18498970b2e4SMerav Sicron #define LOAD_LOOPBACK_EXT		3
1850adfc5217SJeff Kirsher #define UNLOAD_NORMAL			0
1851adfc5217SJeff Kirsher #define UNLOAD_CLOSE			1
1852adfc5217SJeff Kirsher #define UNLOAD_RECOVERY			2
1853adfc5217SJeff Kirsher 
1854adfc5217SJeff Kirsher 
1855adfc5217SJeff Kirsher /* DMAE command defines */
1856adfc5217SJeff Kirsher #define DMAE_TIMEOUT			-1
1857adfc5217SJeff Kirsher #define DMAE_PCI_ERROR			-2	/* E2 and onward */
1858adfc5217SJeff Kirsher #define DMAE_NOT_RDY			-3
1859adfc5217SJeff Kirsher #define DMAE_PCI_ERR_FLAG		0x80000000
1860adfc5217SJeff Kirsher 
1861adfc5217SJeff Kirsher #define DMAE_SRC_PCI			0
1862adfc5217SJeff Kirsher #define DMAE_SRC_GRC			1
1863adfc5217SJeff Kirsher 
1864adfc5217SJeff Kirsher #define DMAE_DST_NONE			0
1865adfc5217SJeff Kirsher #define DMAE_DST_PCI			1
1866adfc5217SJeff Kirsher #define DMAE_DST_GRC			2
1867adfc5217SJeff Kirsher 
1868adfc5217SJeff Kirsher #define DMAE_COMP_PCI			0
1869adfc5217SJeff Kirsher #define DMAE_COMP_GRC			1
1870adfc5217SJeff Kirsher 
1871adfc5217SJeff Kirsher /* E2 and onward - PCI error handling in the completion */
1872adfc5217SJeff Kirsher 
1873adfc5217SJeff Kirsher #define DMAE_COMP_REGULAR		0
1874adfc5217SJeff Kirsher #define DMAE_COM_SET_ERR		1
1875adfc5217SJeff Kirsher 
1876adfc5217SJeff Kirsher #define DMAE_CMD_SRC_PCI		(DMAE_SRC_PCI << \
1877adfc5217SJeff Kirsher 						DMAE_COMMAND_SRC_SHIFT)
1878adfc5217SJeff Kirsher #define DMAE_CMD_SRC_GRC		(DMAE_SRC_GRC << \
1879adfc5217SJeff Kirsher 						DMAE_COMMAND_SRC_SHIFT)
1880adfc5217SJeff Kirsher 
1881adfc5217SJeff Kirsher #define DMAE_CMD_DST_PCI		(DMAE_DST_PCI << \
1882adfc5217SJeff Kirsher 						DMAE_COMMAND_DST_SHIFT)
1883adfc5217SJeff Kirsher #define DMAE_CMD_DST_GRC		(DMAE_DST_GRC << \
1884adfc5217SJeff Kirsher 						DMAE_COMMAND_DST_SHIFT)
1885adfc5217SJeff Kirsher 
1886adfc5217SJeff Kirsher #define DMAE_CMD_C_DST_PCI		(DMAE_COMP_PCI << \
1887adfc5217SJeff Kirsher 						DMAE_COMMAND_C_DST_SHIFT)
1888adfc5217SJeff Kirsher #define DMAE_CMD_C_DST_GRC		(DMAE_COMP_GRC << \
1889adfc5217SJeff Kirsher 						DMAE_COMMAND_C_DST_SHIFT)
1890adfc5217SJeff Kirsher 
1891adfc5217SJeff Kirsher #define DMAE_CMD_C_ENABLE		DMAE_COMMAND_C_TYPE_ENABLE
1892adfc5217SJeff Kirsher 
1893adfc5217SJeff Kirsher #define DMAE_CMD_ENDIANITY_NO_SWAP	(0 << DMAE_COMMAND_ENDIANITY_SHIFT)
1894adfc5217SJeff Kirsher #define DMAE_CMD_ENDIANITY_B_SWAP	(1 << DMAE_COMMAND_ENDIANITY_SHIFT)
1895adfc5217SJeff Kirsher #define DMAE_CMD_ENDIANITY_DW_SWAP	(2 << DMAE_COMMAND_ENDIANITY_SHIFT)
1896adfc5217SJeff Kirsher #define DMAE_CMD_ENDIANITY_B_DW_SWAP	(3 << DMAE_COMMAND_ENDIANITY_SHIFT)
1897adfc5217SJeff Kirsher 
1898adfc5217SJeff Kirsher #define DMAE_CMD_PORT_0			0
1899adfc5217SJeff Kirsher #define DMAE_CMD_PORT_1			DMAE_COMMAND_PORT
1900adfc5217SJeff Kirsher 
1901adfc5217SJeff Kirsher #define DMAE_CMD_SRC_RESET		DMAE_COMMAND_SRC_RESET
1902adfc5217SJeff Kirsher #define DMAE_CMD_DST_RESET		DMAE_COMMAND_DST_RESET
1903adfc5217SJeff Kirsher #define DMAE_CMD_E1HVN_SHIFT		DMAE_COMMAND_E1HVN_SHIFT
1904adfc5217SJeff Kirsher 
1905adfc5217SJeff Kirsher #define DMAE_SRC_PF			0
1906adfc5217SJeff Kirsher #define DMAE_SRC_VF			1
1907adfc5217SJeff Kirsher 
1908adfc5217SJeff Kirsher #define DMAE_DST_PF			0
1909adfc5217SJeff Kirsher #define DMAE_DST_VF			1
1910adfc5217SJeff Kirsher 
1911adfc5217SJeff Kirsher #define DMAE_C_SRC			0
1912adfc5217SJeff Kirsher #define DMAE_C_DST			1
1913adfc5217SJeff Kirsher 
1914adfc5217SJeff Kirsher #define DMAE_LEN32_RD_MAX		0x80
1915adfc5217SJeff Kirsher #define DMAE_LEN32_WR_MAX(bp)		(CHIP_IS_E1(bp) ? 0x400 : 0x2000)
1916adfc5217SJeff Kirsher 
1917adfc5217SJeff Kirsher #define DMAE_COMP_VAL			0x60d0d0ae /* E2 and on - upper bit
1918adfc5217SJeff Kirsher 							indicates eror */
1919adfc5217SJeff Kirsher 
1920adfc5217SJeff Kirsher #define MAX_DMAE_C_PER_PORT		8
1921adfc5217SJeff Kirsher #define INIT_DMAE_C(bp)			(BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
19228decf868SDavid S. Miller 					 BP_VN(bp))
1923adfc5217SJeff Kirsher #define PMF_DMAE_C(bp)			(BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
1924adfc5217SJeff Kirsher 					 E1HVN_MAX)
1925adfc5217SJeff Kirsher 
1926adfc5217SJeff Kirsher /* PCIE link and speed */
1927adfc5217SJeff Kirsher #define PCICFG_LINK_WIDTH		0x1f00000
1928adfc5217SJeff Kirsher #define PCICFG_LINK_WIDTH_SHIFT		20
1929adfc5217SJeff Kirsher #define PCICFG_LINK_SPEED		0xf0000
1930adfc5217SJeff Kirsher #define PCICFG_LINK_SPEED_SHIFT		16
1931adfc5217SJeff Kirsher 
1932cf2c1df6SMerav Sicron #define BNX2X_NUM_TESTS_SF		7
1933cf2c1df6SMerav Sicron #define BNX2X_NUM_TESTS_MF		3
1934cf2c1df6SMerav Sicron #define BNX2X_NUM_TESTS(bp)		(IS_MF(bp) ? BNX2X_NUM_TESTS_MF : \
1935cf2c1df6SMerav Sicron 						     BNX2X_NUM_TESTS_SF)
1936adfc5217SJeff Kirsher 
1937adfc5217SJeff Kirsher #define BNX2X_PHY_LOOPBACK		0
1938adfc5217SJeff Kirsher #define BNX2X_MAC_LOOPBACK		1
19398970b2e4SMerav Sicron #define BNX2X_EXT_LOOPBACK		2
1940adfc5217SJeff Kirsher #define BNX2X_PHY_LOOPBACK_FAILED	1
1941adfc5217SJeff Kirsher #define BNX2X_MAC_LOOPBACK_FAILED	2
19428970b2e4SMerav Sicron #define BNX2X_EXT_LOOPBACK_FAILED	3
1943adfc5217SJeff Kirsher #define BNX2X_LOOPBACK_FAILED		(BNX2X_MAC_LOOPBACK_FAILED | \
1944adfc5217SJeff Kirsher 					 BNX2X_PHY_LOOPBACK_FAILED)
1945adfc5217SJeff Kirsher 
1946adfc5217SJeff Kirsher 
1947adfc5217SJeff Kirsher #define STROM_ASSERT_ARRAY_SIZE		50
1948adfc5217SJeff Kirsher 
1949adfc5217SJeff Kirsher 
1950adfc5217SJeff Kirsher /* must be used on a CID before placing it on a HW ring */
1951adfc5217SJeff Kirsher #define HW_CID(bp, x)			((BP_PORT(bp) << 23) | \
19528decf868SDavid S. Miller 					 (BP_VN(bp) << BNX2X_SWCID_SHIFT) | \
1953adfc5217SJeff Kirsher 					 (x))
1954adfc5217SJeff Kirsher 
1955adfc5217SJeff Kirsher #define SP_DESC_CNT		(BCM_PAGE_SIZE / sizeof(struct eth_spe))
1956adfc5217SJeff Kirsher #define MAX_SP_DESC_CNT			(SP_DESC_CNT - 1)
1957adfc5217SJeff Kirsher 
1958adfc5217SJeff Kirsher 
1959adfc5217SJeff Kirsher #define BNX2X_BTR			4
1960adfc5217SJeff Kirsher #define MAX_SPQ_PENDING			8
1961adfc5217SJeff Kirsher 
1962adfc5217SJeff Kirsher /* CMNG constants, as derived from system spec calculations */
1963adfc5217SJeff Kirsher /* default MIN rate in case VNIC min rate is configured to zero - 100Mbps */
1964adfc5217SJeff Kirsher #define DEF_MIN_RATE					100
1965adfc5217SJeff Kirsher /* resolution of the rate shaping timer - 400 usec */
1966adfc5217SJeff Kirsher #define RS_PERIODIC_TIMEOUT_USEC			400
1967adfc5217SJeff Kirsher /* number of bytes in single QM arbitration cycle -
1968adfc5217SJeff Kirsher  * coefficient for calculating the fairness timer */
1969adfc5217SJeff Kirsher #define QM_ARB_BYTES					160000
1970adfc5217SJeff Kirsher /* resolution of Min algorithm 1:100 */
1971adfc5217SJeff Kirsher #define MIN_RES						100
1972adfc5217SJeff Kirsher /* how many bytes above threshold for the minimal credit of Min algorithm*/
1973adfc5217SJeff Kirsher #define MIN_ABOVE_THRESH				32768
1974adfc5217SJeff Kirsher /* Fairness algorithm integration time coefficient -
1975adfc5217SJeff Kirsher  * for calculating the actual Tfair */
1976adfc5217SJeff Kirsher #define T_FAIR_COEF	((MIN_ABOVE_THRESH +  QM_ARB_BYTES) * 8 * MIN_RES)
1977adfc5217SJeff Kirsher /* Memory of fairness algorithm . 2 cycles */
1978adfc5217SJeff Kirsher #define FAIR_MEM					2
1979adfc5217SJeff Kirsher 
1980adfc5217SJeff Kirsher 
1981adfc5217SJeff Kirsher #define ATTN_NIG_FOR_FUNC		(1L << 8)
1982adfc5217SJeff Kirsher #define ATTN_SW_TIMER_4_FUNC		(1L << 9)
1983adfc5217SJeff Kirsher #define GPIO_2_FUNC			(1L << 10)
1984adfc5217SJeff Kirsher #define GPIO_3_FUNC			(1L << 11)
1985adfc5217SJeff Kirsher #define GPIO_4_FUNC			(1L << 12)
1986adfc5217SJeff Kirsher #define ATTN_GENERAL_ATTN_1		(1L << 13)
1987adfc5217SJeff Kirsher #define ATTN_GENERAL_ATTN_2		(1L << 14)
1988adfc5217SJeff Kirsher #define ATTN_GENERAL_ATTN_3		(1L << 15)
1989adfc5217SJeff Kirsher #define ATTN_GENERAL_ATTN_4		(1L << 13)
1990adfc5217SJeff Kirsher #define ATTN_GENERAL_ATTN_5		(1L << 14)
1991adfc5217SJeff Kirsher #define ATTN_GENERAL_ATTN_6		(1L << 15)
1992adfc5217SJeff Kirsher 
1993adfc5217SJeff Kirsher #define ATTN_HARD_WIRED_MASK		0xff00
1994adfc5217SJeff Kirsher #define ATTENTION_ID			4
1995adfc5217SJeff Kirsher 
1996adfc5217SJeff Kirsher 
1997adfc5217SJeff Kirsher /* stuff added to make the code fit 80Col */
1998adfc5217SJeff Kirsher 
1999adfc5217SJeff Kirsher #define BNX2X_PMF_LINK_ASSERT \
2000adfc5217SJeff Kirsher 	GENERAL_ATTEN_OFFSET(LINK_SYNC_ATTENTION_BIT_FUNC_0 + BP_FUNC(bp))
2001adfc5217SJeff Kirsher 
2002adfc5217SJeff Kirsher #define BNX2X_MC_ASSERT_BITS \
2003adfc5217SJeff Kirsher 	(GENERAL_ATTEN_OFFSET(TSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
2004adfc5217SJeff Kirsher 	 GENERAL_ATTEN_OFFSET(USTORM_FATAL_ASSERT_ATTENTION_BIT) | \
2005adfc5217SJeff Kirsher 	 GENERAL_ATTEN_OFFSET(CSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
2006adfc5217SJeff Kirsher 	 GENERAL_ATTEN_OFFSET(XSTORM_FATAL_ASSERT_ATTENTION_BIT))
2007adfc5217SJeff Kirsher 
2008adfc5217SJeff Kirsher #define BNX2X_MCP_ASSERT \
2009adfc5217SJeff Kirsher 	GENERAL_ATTEN_OFFSET(MCP_FATAL_ASSERT_ATTENTION_BIT)
2010adfc5217SJeff Kirsher 
2011adfc5217SJeff Kirsher #define BNX2X_GRC_TIMEOUT	GENERAL_ATTEN_OFFSET(LATCHED_ATTN_TIMEOUT_GRC)
2012adfc5217SJeff Kirsher #define BNX2X_GRC_RSV		(GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCR) | \
2013adfc5217SJeff Kirsher 				 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCT) | \
2014adfc5217SJeff Kirsher 				 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCN) | \
2015adfc5217SJeff Kirsher 				 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCU) | \
2016adfc5217SJeff Kirsher 				 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCP) | \
2017adfc5217SJeff Kirsher 				 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RSVD_GRC))
2018adfc5217SJeff Kirsher 
2019adfc5217SJeff Kirsher #define HW_INTERRUT_ASSERT_SET_0 \
2020adfc5217SJeff Kirsher 				(AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT | \
2021adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT | \
2022adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT | \
2023adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_PBCLIENT_HW_INTERRUPT)
2024adfc5217SJeff Kirsher #define HW_PRTY_ASSERT_SET_0	(AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR | \
2025adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR | \
2026adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR | \
2027adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR |\
2028adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR |\
2029adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR |\
2030adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR)
2031adfc5217SJeff Kirsher #define HW_INTERRUT_ASSERT_SET_1 \
2032adfc5217SJeff Kirsher 				(AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT | \
2033adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT | \
2034adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT | \
2035adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT | \
2036adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT | \
2037adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT | \
2038adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT | \
2039adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT | \
2040adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT | \
2041adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT | \
2042adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT)
2043adfc5217SJeff Kirsher #define HW_PRTY_ASSERT_SET_1	(AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR |\
2044adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR | \
2045adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR |\
2046adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR | \
2047adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR |\
2048adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR | \
2049adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR |\
2050adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR |\
2051adfc5217SJeff Kirsher 			     AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR |\
2052adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR | \
2053adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR | \
2054adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR |\
2055adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR | \
2056adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR | \
2057adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR |\
2058adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR)
2059adfc5217SJeff Kirsher #define HW_INTERRUT_ASSERT_SET_2 \
2060adfc5217SJeff Kirsher 				(AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT | \
2061adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT | \
2062adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT | \
2063adfc5217SJeff Kirsher 			AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT |\
2064adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT)
2065adfc5217SJeff Kirsher #define HW_PRTY_ASSERT_SET_2	(AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR | \
2066adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR | \
2067adfc5217SJeff Kirsher 			AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR |\
2068adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR | \
2069adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR | \
2070adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR |\
2071adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR | \
2072adfc5217SJeff Kirsher 				 AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR)
2073adfc5217SJeff Kirsher 
2074adfc5217SJeff Kirsher #define HW_PRTY_ASSERT_SET_3 (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
2075adfc5217SJeff Kirsher 		AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
2076adfc5217SJeff Kirsher 		AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY | \
2077adfc5217SJeff Kirsher 		AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
2078adfc5217SJeff Kirsher 
2079adfc5217SJeff Kirsher #define HW_PRTY_ASSERT_SET_4 (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | \
2080adfc5217SJeff Kirsher 			      AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)
2081adfc5217SJeff Kirsher 
2082adfc5217SJeff Kirsher #define MULTI_MASK			0x7f
2083adfc5217SJeff Kirsher 
2084adfc5217SJeff Kirsher 
2085adfc5217SJeff Kirsher #define DEF_USB_FUNC_OFF	offsetof(struct cstorm_def_status_block_u, func)
2086adfc5217SJeff Kirsher #define DEF_CSB_FUNC_OFF	offsetof(struct cstorm_def_status_block_c, func)
2087adfc5217SJeff Kirsher #define DEF_XSB_FUNC_OFF	offsetof(struct xstorm_def_status_block, func)
2088adfc5217SJeff Kirsher #define DEF_TSB_FUNC_OFF	offsetof(struct tstorm_def_status_block, func)
2089adfc5217SJeff Kirsher 
2090adfc5217SJeff Kirsher #define DEF_USB_IGU_INDEX_OFF \
2091adfc5217SJeff Kirsher 			offsetof(struct cstorm_def_status_block_u, igu_index)
2092adfc5217SJeff Kirsher #define DEF_CSB_IGU_INDEX_OFF \
2093adfc5217SJeff Kirsher 			offsetof(struct cstorm_def_status_block_c, igu_index)
2094adfc5217SJeff Kirsher #define DEF_XSB_IGU_INDEX_OFF \
2095adfc5217SJeff Kirsher 			offsetof(struct xstorm_def_status_block, igu_index)
2096adfc5217SJeff Kirsher #define DEF_TSB_IGU_INDEX_OFF \
2097adfc5217SJeff Kirsher 			offsetof(struct tstorm_def_status_block, igu_index)
2098adfc5217SJeff Kirsher 
2099adfc5217SJeff Kirsher #define DEF_USB_SEGMENT_OFF \
2100adfc5217SJeff Kirsher 			offsetof(struct cstorm_def_status_block_u, segment)
2101adfc5217SJeff Kirsher #define DEF_CSB_SEGMENT_OFF \
2102adfc5217SJeff Kirsher 			offsetof(struct cstorm_def_status_block_c, segment)
2103adfc5217SJeff Kirsher #define DEF_XSB_SEGMENT_OFF \
2104adfc5217SJeff Kirsher 			offsetof(struct xstorm_def_status_block, segment)
2105adfc5217SJeff Kirsher #define DEF_TSB_SEGMENT_OFF \
2106adfc5217SJeff Kirsher 			offsetof(struct tstorm_def_status_block, segment)
2107adfc5217SJeff Kirsher 
2108adfc5217SJeff Kirsher #define BNX2X_SP_DSB_INDEX \
2109adfc5217SJeff Kirsher 		(&bp->def_status_blk->sp_sb.\
2110adfc5217SJeff Kirsher 					index_values[HC_SP_INDEX_ETH_DEF_CONS])
2111adfc5217SJeff Kirsher 
2112adfc5217SJeff Kirsher #define SET_FLAG(value, mask, flag) \
2113adfc5217SJeff Kirsher 	do {\
2114adfc5217SJeff Kirsher 		(value) &= ~(mask);\
2115adfc5217SJeff Kirsher 		(value) |= ((flag) << (mask##_SHIFT));\
2116adfc5217SJeff Kirsher 	} while (0)
2117adfc5217SJeff Kirsher 
2118adfc5217SJeff Kirsher #define GET_FLAG(value, mask) \
2119adfc5217SJeff Kirsher 	(((value) & (mask)) >> (mask##_SHIFT))
2120adfc5217SJeff Kirsher 
2121adfc5217SJeff Kirsher #define GET_FIELD(value, fname) \
2122adfc5217SJeff Kirsher 	(((value) & (fname##_MASK)) >> (fname##_SHIFT))
2123adfc5217SJeff Kirsher 
2124adfc5217SJeff Kirsher #define CAM_IS_INVALID(x) \
2125adfc5217SJeff Kirsher 	(GET_FLAG(x.flags, \
2126adfc5217SJeff Kirsher 	MAC_CONFIGURATION_ENTRY_ACTION_TYPE) == \
2127adfc5217SJeff Kirsher 	(T_ETH_MAC_COMMAND_INVALIDATE))
2128adfc5217SJeff Kirsher 
2129adfc5217SJeff Kirsher /* Number of u32 elements in MC hash array */
2130adfc5217SJeff Kirsher #define MC_HASH_SIZE			8
2131adfc5217SJeff Kirsher #define MC_HASH_OFFSET(bp, i)		(BAR_TSTRORM_INTMEM + \
2132adfc5217SJeff Kirsher 	TSTORM_APPROXIMATE_MATCH_MULTICAST_FILTERING_OFFSET(BP_FUNC(bp)) + i*4)
2133adfc5217SJeff Kirsher 
2134adfc5217SJeff Kirsher 
2135adfc5217SJeff Kirsher #ifndef PXP2_REG_PXP2_INT_STS
2136adfc5217SJeff Kirsher #define PXP2_REG_PXP2_INT_STS		PXP2_REG_PXP2_INT_STS_0
2137adfc5217SJeff Kirsher #endif
2138adfc5217SJeff Kirsher 
2139adfc5217SJeff Kirsher #ifndef ETH_MAX_RX_CLIENTS_E2
2140adfc5217SJeff Kirsher #define ETH_MAX_RX_CLIENTS_E2		ETH_MAX_RX_CLIENTS_E1H
2141adfc5217SJeff Kirsher #endif
2142adfc5217SJeff Kirsher 
2143adfc5217SJeff Kirsher #define BNX2X_VPD_LEN			128
2144adfc5217SJeff Kirsher #define VENDOR_ID_LEN			4
2145adfc5217SJeff Kirsher 
2146adfc5217SJeff Kirsher /* Congestion management fairness mode */
2147adfc5217SJeff Kirsher #define CMNG_FNS_NONE		0
2148adfc5217SJeff Kirsher #define CMNG_FNS_MINMAX		1
2149adfc5217SJeff Kirsher 
2150adfc5217SJeff Kirsher #define HC_SEG_ACCESS_DEF		0   /*Driver decision 0-3*/
2151adfc5217SJeff Kirsher #define HC_SEG_ACCESS_ATTN		4
2152adfc5217SJeff Kirsher #define HC_SEG_ACCESS_NORM		0   /*Driver decision 0-1*/
2153adfc5217SJeff Kirsher 
2154adfc5217SJeff Kirsher static const u32 dmae_reg_go_c[] = {
2155adfc5217SJeff Kirsher 	DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
2156adfc5217SJeff Kirsher 	DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
2157adfc5217SJeff Kirsher 	DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
2158adfc5217SJeff Kirsher 	DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
2159adfc5217SJeff Kirsher };
2160adfc5217SJeff Kirsher 
2161adfc5217SJeff Kirsher void bnx2x_set_ethtool_ops(struct net_device *netdev);
2162adfc5217SJeff Kirsher void bnx2x_notify_link_changed(struct bnx2x *bp);
2163614c76dfSDmitry Kravkov 
2164614c76dfSDmitry Kravkov 
21659e62e912SDmitry Kravkov #define BNX2X_MF_SD_PROTOCOL(bp) \
2166614c76dfSDmitry Kravkov 	((bp)->mf_config[BP_VN(bp)] & FUNC_MF_CFG_PROTOCOL_MASK)
2167614c76dfSDmitry Kravkov 
2168614c76dfSDmitry Kravkov #ifdef BCM_CNIC
21699e62e912SDmitry Kravkov #define BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp) \
21709e62e912SDmitry Kravkov 	(BNX2X_MF_SD_PROTOCOL(bp) == FUNC_MF_CFG_PROTOCOL_ISCSI)
2171614c76dfSDmitry Kravkov 
21729e62e912SDmitry Kravkov #define BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) \
21739e62e912SDmitry Kravkov 	(BNX2X_MF_SD_PROTOCOL(bp) == FUNC_MF_CFG_PROTOCOL_FCOE)
21749e62e912SDmitry Kravkov 
21759e62e912SDmitry Kravkov #define IS_MF_ISCSI_SD(bp) (IS_MF_SD(bp) && BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp))
21769e62e912SDmitry Kravkov #define IS_MF_FCOE_SD(bp) (IS_MF_SD(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))
21779e62e912SDmitry Kravkov 
2178a3348722SBarak Witkowski #define BNX2X_MF_EXT_PROTOCOL_FCOE(bp)  ((bp)->mf_ext_config & \
2179a3348722SBarak Witkowski 					 MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
2180a3348722SBarak Witkowski 
2181a3348722SBarak Witkowski #define IS_MF_FCOE_AFEX(bp) (IS_MF_AFEX(bp) && BNX2X_MF_EXT_PROTOCOL_FCOE(bp))
21829e62e912SDmitry Kravkov #define IS_MF_STORAGE_SD(bp) (IS_MF_SD(bp) && \
21839e62e912SDmitry Kravkov 				(BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp) || \
21849e62e912SDmitry Kravkov 				 BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
2185a3348722SBarak Witkowski #else
2186a3348722SBarak Witkowski #define IS_MF_FCOE_AFEX(bp)	false
2187614c76dfSDmitry Kravkov #endif
2188614c76dfSDmitry Kravkov 
2189a3348722SBarak Witkowski 
2190adfc5217SJeff Kirsher #endif /* bnx2x.h */
2191