blob: abbdf6d5b84ea018041ba6acc33a1ddc6379733e [file] [log] [blame]
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001/* bnx2x.h: Broadcom Everest network driver.
2 *
Vladislav Zolotarov3359fce2010-02-17 13:35:01 -08003 * Copyright (c) 2007-2010 Broadcom Corporation
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
8 *
Eilon Greenstein24e3fce2008-06-12 14:30:28 -07009 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020011 * Based on code from Michael Chan's bnx2 driver
12 */
13
14#ifndef BNX2X_H
15#define BNX2X_H
16
Eilon Greenstein34f80b02008-06-23 20:33:01 -070017/* compilation time flags */
18
19/* define this to make the driver freeze on error to allow getting debug info
20 * (you will need to reboot afterwards) */
21/* #define BNX2X_STOP_ON_ERROR */
22
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -080023#define DRV_MODULE_VERSION "1.60.00-6"
24#define DRV_MODULE_RELDATE "2010/11/29"
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +000025#define BNX2X_BC_VER 0x040200
26
Eilon Greenstein555f6c72009-02-12 08:36:11 +000027#define BNX2X_MULTI_QUEUE
28
29#define BNX2X_NEW_NAPI
30
Eilon Greenstein359d8b12009-02-12 08:38:25 +000031
Vladislav Zolotarov1ac218c2010-04-19 01:14:18 +000032#if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
33#define BCM_CNIC 1
Dmitry Kravkov5d1e8592010-07-27 12:31:10 +000034#include "../cnic_if.h"
Vladislav Zolotarov1ac218c2010-04-19 01:14:18 +000035#endif
36
Vladislav Zolotarov1ac218c2010-04-19 01:14:18 +000037#ifdef BCM_CNIC
38#define BNX2X_MIN_MSIX_VEC_CNT 3
39#define BNX2X_MSIX_VEC_FP_START 2
40#else
41#define BNX2X_MIN_MSIX_VEC_CNT 2
42#define BNX2X_MSIX_VEC_FP_START 1
43#endif
44
Eilon Greenstein01cd4522009-08-12 08:23:08 +000045#include <linux/mdio.h>
Dmitry Kravkov9f6c9252010-07-27 12:34:34 +000046#include <linux/pci.h>
Eilon Greenstein359d8b12009-02-12 08:38:25 +000047#include "bnx2x_reg.h"
48#include "bnx2x_fw_defs.h"
49#include "bnx2x_hsi.h"
50#include "bnx2x_link.h"
Dmitry Kravkov6c719d02010-07-27 12:36:15 +000051#include "bnx2x_stats.h"
Eilon Greenstein359d8b12009-02-12 08:38:25 +000052
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020053/* error/debug prints */
54
Eilon Greenstein34f80b02008-06-23 20:33:01 -070055#define DRV_MODULE_NAME "bnx2x"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020056
57/* for messages that are currently off */
Eilon Greenstein34f80b02008-06-23 20:33:01 -070058#define BNX2X_MSG_OFF 0
59#define BNX2X_MSG_MCP 0x010000 /* was: NETIF_MSG_HW */
60#define BNX2X_MSG_STATS 0x020000 /* was: NETIF_MSG_TIMER */
61#define BNX2X_MSG_NVM 0x040000 /* was: NETIF_MSG_HW */
62#define BNX2X_MSG_DMAE 0x080000 /* was: NETIF_MSG_HW */
Eliezer Tamirf1410642008-02-28 11:51:50 -080063#define BNX2X_MSG_SP 0x100000 /* was: NETIF_MSG_INTR */
64#define BNX2X_MSG_FP 0x200000 /* was: NETIF_MSG_INTR */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020065
Eilon Greenstein34f80b02008-06-23 20:33:01 -070066#define DP_LEVEL KERN_NOTICE /* was: KERN_DEBUG */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020067
68/* regular debug print */
Joe Perches7995c642010-02-17 15:01:52 +000069#define DP(__mask, __fmt, __args...) \
70do { \
71 if (bp->msg_enable & (__mask)) \
72 printk(DP_LEVEL "[%s:%d(%s)]" __fmt, \
73 __func__, __LINE__, \
74 bp->dev ? (bp->dev->name) : "?", \
75 ##__args); \
76} while (0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070077
78/* errors debug print */
Joe Perches7995c642010-02-17 15:01:52 +000079#define BNX2X_DBG_ERR(__fmt, __args...) \
80do { \
81 if (netif_msg_probe(bp)) \
82 pr_err("[%s:%d(%s)]" __fmt, \
83 __func__, __LINE__, \
84 bp->dev ? (bp->dev->name) : "?", \
85 ##__args); \
86} while (0)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020087
88/* for errors (never masked) */
Joe Perches7995c642010-02-17 15:01:52 +000089#define BNX2X_ERR(__fmt, __args...) \
90do { \
91 pr_err("[%s:%d(%s)]" __fmt, \
92 __func__, __LINE__, \
93 bp->dev ? (bp->dev->name) : "?", \
94 ##__args); \
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +000095 } while (0)
96
97#define BNX2X_ERROR(__fmt, __args...) do { \
98 pr_err("[%s:%d]" __fmt, __func__, __LINE__, ##__args); \
99 } while (0)
100
Eliezer Tamirf1410642008-02-28 11:51:50 -0800101
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200102/* before we have a dev->name use dev_info() */
Joe Perches7995c642010-02-17 15:01:52 +0000103#define BNX2X_DEV_INFO(__fmt, __args...) \
104do { \
105 if (netif_msg_probe(bp)) \
106 dev_info(&bp->pdev->dev, __fmt, ##__args); \
107} while (0)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200108
Dmitry Kravkov6c719d02010-07-27 12:36:15 +0000109void bnx2x_panic_dump(struct bnx2x *bp);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200110
111#ifdef BNX2X_STOP_ON_ERROR
112#define bnx2x_panic() do { \
113 bp->panic = 1; \
114 BNX2X_ERR("driver assert\n"); \
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700115 bnx2x_int_disable(bp); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200116 bnx2x_panic_dump(bp); \
117 } while (0)
118#else
119#define bnx2x_panic() do { \
Eilon Greensteine3553b22009-08-12 08:23:31 +0000120 bp->panic = 1; \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200121 BNX2X_ERR("driver assert\n"); \
122 bnx2x_panic_dump(bp); \
123 } while (0)
124#endif
125
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000126#define bnx2x_mc_addr(ha) ((ha)->addr)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200127
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700128#define U64_LO(x) (u32)(((u64)(x)) & 0xffffffff)
129#define U64_HI(x) (u32)(((u64)(x)) >> 32)
130#define HILO_U64(hi, lo) ((((u64)(hi)) << 32) + (lo))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200131
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200132
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000133#define REG_ADDR(bp, offset) ((bp->regview) + (offset))
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700134
135#define REG_RD(bp, offset) readl(REG_ADDR(bp, offset))
136#define REG_RD8(bp, offset) readb(REG_ADDR(bp, offset))
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000137#define REG_RD16(bp, offset) readw(REG_ADDR(bp, offset))
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700138
139#define REG_WR(bp, offset, val) writel((u32)val, REG_ADDR(bp, offset))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200140#define REG_WR8(bp, offset, val) writeb((u8)val, REG_ADDR(bp, offset))
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700141#define REG_WR16(bp, offset, val) writew((u16)val, REG_ADDR(bp, offset))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200142
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700143#define REG_RD_IND(bp, offset) bnx2x_reg_rd_ind(bp, offset)
144#define REG_WR_IND(bp, offset, val) bnx2x_reg_wr_ind(bp, offset, val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200145
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700146#define REG_RD_DMAE(bp, offset, valp, len32) \
147 do { \
148 bnx2x_read_dmae(bp, offset, len32);\
Eilon Greenstein573f2032009-08-12 08:24:14 +0000149 memcpy(valp, bnx2x_sp(bp, wb_data[0]), (len32) * 4); \
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700150 } while (0)
151
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700152#define REG_WR_DMAE(bp, offset, valp, len32) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200153 do { \
Eilon Greenstein573f2032009-08-12 08:24:14 +0000154 memcpy(bnx2x_sp(bp, wb_data[0]), valp, (len32) * 4); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200155 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), \
156 offset, len32); \
157 } while (0)
158
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000159#define REG_WR_DMAE_LEN(bp, offset, valp, len32) \
160 REG_WR_DMAE(bp, offset, valp, len32)
161
Vladislav Zolotarov3359fce2010-02-17 13:35:01 -0800162#define VIRT_WR_DMAE_LEN(bp, data, addr, len32, le32_swap) \
Eilon Greenstein573f2032009-08-12 08:24:14 +0000163 do { \
164 memcpy(GUNZIP_BUF(bp), data, (len32) * 4); \
165 bnx2x_write_big_buf_wb(bp, addr, len32); \
166 } while (0)
167
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700168#define SHMEM_ADDR(bp, field) (bp->common.shmem_base + \
169 offsetof(struct shmem_region, field))
170#define SHMEM_RD(bp, field) REG_RD(bp, SHMEM_ADDR(bp, field))
171#define SHMEM_WR(bp, field, val) REG_WR(bp, SHMEM_ADDR(bp, field), val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200172
Eilon Greenstein2691d512009-08-12 08:22:08 +0000173#define SHMEM2_ADDR(bp, field) (bp->common.shmem2_base + \
174 offsetof(struct shmem2_region, field))
175#define SHMEM2_RD(bp, field) REG_RD(bp, SHMEM2_ADDR(bp, field))
176#define SHMEM2_WR(bp, field, val) REG_WR(bp, SHMEM2_ADDR(bp, field), val)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000177#define MF_CFG_ADDR(bp, field) (bp->common.mf_cfg_base + \
178 offsetof(struct mf_cfg, field))
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000179#define MF2_CFG_ADDR(bp, field) (bp->common.mf2_cfg_base + \
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000180 offsetof(struct mf2_cfg, field))
Eilon Greenstein2691d512009-08-12 08:22:08 +0000181
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000182#define MF_CFG_RD(bp, field) REG_RD(bp, MF_CFG_ADDR(bp, field))
183#define MF_CFG_WR(bp, field, val) REG_WR(bp,\
184 MF_CFG_ADDR(bp, field), (val))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000185#define MF2_CFG_RD(bp, field) REG_RD(bp, MF2_CFG_ADDR(bp, field))
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000186
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000187#define SHMEM2_HAS(bp, field) ((bp)->common.shmem2_base && \
188 (SHMEM2_RD((bp), size) > \
189 offsetof(struct shmem2_region, field)))
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +0000190
Eilon Greenstein345b5d52008-08-13 15:58:12 -0700191#define EMAC_RD(bp, reg) REG_RD(bp, emac_base + reg)
Eilon Greenstein3196a882008-08-13 15:58:49 -0700192#define EMAC_WR(bp, reg, val) REG_WR(bp, emac_base + reg, val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200193
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000194/* SP SB indices */
195
196/* General SP events - stats query, cfc delete, etc */
197#define HC_SP_INDEX_ETH_DEF_CONS 3
198
199/* EQ completions */
200#define HC_SP_INDEX_EQ_CONS 7
201
202/* iSCSI L2 */
203#define HC_SP_INDEX_ETH_ISCSI_CQ_CONS 5
204#define HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS 1
205
206/**
207 * CIDs and CLIDs:
208 * CLIDs below is a CLID for func 0, then the CLID for other
209 * functions will be calculated by the formula:
210 *
211 * FUNC_N_CLID_X = N * NUM_SPECIAL_CLIENTS + FUNC_0_CLID_X
212 *
213 */
214/* iSCSI L2 */
215#define BNX2X_ISCSI_ETH_CL_ID 17
216#define BNX2X_ISCSI_ETH_CID 17
217
218/** Additional rings budgeting */
219#ifdef BCM_CNIC
220#define CNIC_CONTEXT_USE 1
221#else
222#define CNIC_CONTEXT_USE 0
223#endif /* BCM_CNIC */
224
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +0000225#define AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR \
226 AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR
227
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000228#define SM_RX_ID 0
229#define SM_TX_ID 1
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200230
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700231/* fast path */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200232
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200233struct sw_rx_bd {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700234 struct sk_buff *skb;
FUJITA Tomonori1a983142010-04-04 01:51:03 +0000235 DEFINE_DMA_UNMAP_ADDR(mapping);
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200236};
237
238struct sw_tx_bd {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700239 struct sk_buff *skb;
240 u16 first_bd;
Eilon Greensteinca003922009-08-12 22:53:28 -0700241 u8 flags;
242/* Set on the first BD descriptor when there is a split BD */
243#define BNX2X_TSO_SPLIT_BD (1<<0)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200244};
245
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700246struct sw_rx_page {
247 struct page *page;
FUJITA Tomonori1a983142010-04-04 01:51:03 +0000248 DEFINE_DMA_UNMAP_ADDR(mapping);
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700249};
250
Eilon Greensteinca003922009-08-12 22:53:28 -0700251union db_prod {
252 struct doorbell_set_prod data;
253 u32 raw;
254};
255
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700256
257/* MC hsi */
258#define BCM_PAGE_SHIFT 12
259#define BCM_PAGE_SIZE (1 << BCM_PAGE_SHIFT)
260#define BCM_PAGE_MASK (~(BCM_PAGE_SIZE - 1))
261#define BCM_PAGE_ALIGN(addr) (((addr) + BCM_PAGE_SIZE - 1) & BCM_PAGE_MASK)
262
263#define PAGES_PER_SGE_SHIFT 0
264#define PAGES_PER_SGE (1 << PAGES_PER_SGE_SHIFT)
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -0800265#define SGE_PAGE_SIZE PAGE_SIZE
266#define SGE_PAGE_SHIFT PAGE_SHIFT
Eilon Greenstein5b6402d2009-07-21 05:47:51 +0000267#define SGE_PAGE_ALIGN(addr) PAGE_ALIGN((typeof(PAGE_SIZE))(addr))
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700268
269/* SGE ring related macros */
270#define NUM_RX_SGE_PAGES 2
271#define RX_SGE_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_sge))
272#define MAX_RX_SGE_CNT (RX_SGE_CNT - 2)
Eilon Greenstein33471622008-08-13 15:59:08 -0700273/* RX_SGE_CNT is promised to be a power of 2 */
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700274#define RX_SGE_MASK (RX_SGE_CNT - 1)
275#define NUM_RX_SGE (RX_SGE_CNT * NUM_RX_SGE_PAGES)
276#define MAX_RX_SGE (NUM_RX_SGE - 1)
277#define NEXT_SGE_IDX(x) ((((x) & RX_SGE_MASK) == \
278 (MAX_RX_SGE_CNT - 1)) ? (x) + 3 : (x) + 1)
279#define RX_SGE(x) ((x) & MAX_RX_SGE)
280
281/* SGE producer mask related macros */
282/* Number of bits in one sge_mask array element */
283#define RX_SGE_MASK_ELEM_SZ 64
284#define RX_SGE_MASK_ELEM_SHIFT 6
285#define RX_SGE_MASK_ELEM_MASK ((u64)RX_SGE_MASK_ELEM_SZ - 1)
286
287/* Creates a bitmask of all ones in less significant bits.
288 idx - index of the most significant bit in the created mask */
289#define RX_SGE_ONES_MASK(idx) \
290 (((u64)0x1 << (((idx) & RX_SGE_MASK_ELEM_MASK) + 1)) - 1)
291#define RX_SGE_MASK_ELEM_ONE_MASK ((u64)(~0))
292
293/* Number of u64 elements in SGE mask array */
294#define RX_SGE_MASK_LEN ((NUM_RX_SGE_PAGES * RX_SGE_CNT) / \
295 RX_SGE_MASK_ELEM_SZ)
296#define RX_SGE_MASK_LEN_MASK (RX_SGE_MASK_LEN - 1)
297#define NEXT_SGE_MASK_ELEM(el) (((el) + 1) & RX_SGE_MASK_LEN_MASK)
298
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000299union host_hc_status_block {
300 /* pointer to fp status block e1x */
301 struct host_hc_status_block_e1x *e1x_sb;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000302 /* pointer to fp status block e2 */
303 struct host_hc_status_block_e2 *e2_sb;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000304};
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700305
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200306struct bnx2x_fastpath {
307
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000308#define BNX2X_NAPI_WEIGHT 128
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700309 struct napi_struct napi;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000310 union host_hc_status_block status_blk;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000311 /* chip independed shortcuts into sb structure */
312 __le16 *sb_index_values;
313 __le16 *sb_running_index;
314 /* chip independed shortcut into rx_prods_offset memory */
315 u32 ustorm_rx_prods_offset;
316
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700317 dma_addr_t status_blk_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200318
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700319 struct sw_tx_bd *tx_buf_ring;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200320
Eilon Greensteinca003922009-08-12 22:53:28 -0700321 union eth_tx_bd_types *tx_desc_ring;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700322 dma_addr_t tx_desc_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200323
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700324 struct sw_rx_bd *rx_buf_ring; /* BDs mappings ring */
325 struct sw_rx_page *rx_page_ring; /* SGE pages mappings ring */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200326
327 struct eth_rx_bd *rx_desc_ring;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700328 dma_addr_t rx_desc_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200329
330 union eth_rx_cqe *rx_comp_ring;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700331 dma_addr_t rx_comp_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200332
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700333 /* SGE ring */
334 struct eth_rx_sge *rx_sge_ring;
335 dma_addr_t rx_sge_mapping;
336
337 u64 sge_mask[RX_SGE_MASK_LEN];
338
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700339 int state;
340#define BNX2X_FP_STATE_CLOSED 0
341#define BNX2X_FP_STATE_IRQ 0x80000
342#define BNX2X_FP_STATE_OPENING 0x90000
343#define BNX2X_FP_STATE_OPEN 0xa0000
344#define BNX2X_FP_STATE_HALTING 0xb0000
345#define BNX2X_FP_STATE_HALTED 0xc0000
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000346#define BNX2X_FP_STATE_TERMINATING 0xd0000
347#define BNX2X_FP_STATE_TERMINATED 0xe0000
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200348
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000349 u8 index; /* number in fp array */
350 u8 cl_id; /* eth client id */
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000351 u8 cl_qzone_id;
352 u8 fw_sb_id; /* status block number in FW */
353 u8 igu_sb_id; /* status block number in HW */
354 u32 cid;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200355
Eilon Greensteinca003922009-08-12 22:53:28 -0700356 union db_prod tx_db;
357
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700358 u16 tx_pkt_prod;
359 u16 tx_pkt_cons;
360 u16 tx_bd_prod;
361 u16 tx_bd_cons;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000362 __le16 *tx_cons_sb;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200363
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000364 __le16 fp_hc_idx;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200365
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700366 u16 rx_bd_prod;
367 u16 rx_bd_cons;
368 u16 rx_comp_prod;
369 u16 rx_comp_cons;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700370 u16 rx_sge_prod;
371 /* The last maximal completed SGE */
372 u16 last_max_sge;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000373 __le16 *rx_cons_sb;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000374
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700375 unsigned long tx_pkt,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200376 rx_pkt,
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700377 rx_calls;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +0000378
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700379 /* TPA related */
380 struct sw_rx_bd tpa_pool[ETH_MAX_AGGREGATION_QUEUES_E1H];
381 u8 tpa_state[ETH_MAX_AGGREGATION_QUEUES_E1H];
382#define BNX2X_TPA_START 1
383#define BNX2X_TPA_STOP 2
384 u8 disable_tpa;
385#ifdef BNX2X_STOP_ON_ERROR
386 u64 tpa_queue_used;
387#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200388
Eilon Greensteinde832a52009-02-12 08:36:33 +0000389 struct tstorm_per_client_stats old_tclient;
390 struct ustorm_per_client_stats old_uclient;
391 struct xstorm_per_client_stats old_xclient;
392 struct bnx2x_eth_q_stats eth_q_stats;
393
Eilon Greensteinca003922009-08-12 22:53:28 -0700394 /* The size is calculated using the following:
395 sizeof name field from netdev structure +
396 4 ('-Xx-' string) +
397 4 (for the digits and to make it DWORD aligned) */
398#define FP_NAME_SIZE (sizeof(((struct net_device *)0)->name) + 8)
399 char name[FP_NAME_SIZE];
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700400 struct bnx2x *bp; /* parent */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200401};
402
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700403#define bnx2x_fp(bp, nr, var) (bp->fp[nr].var)
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700404
405
406/* MC hsi */
407#define MAX_FETCH_BD 13 /* HW max BDs per packet */
408#define RX_COPY_THRESH 92
409
410#define NUM_TX_RINGS 16
Eilon Greensteinca003922009-08-12 22:53:28 -0700411#define TX_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_tx_bd_types))
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700412#define MAX_TX_DESC_CNT (TX_DESC_CNT - 1)
413#define NUM_TX_BD (TX_DESC_CNT * NUM_TX_RINGS)
414#define MAX_TX_BD (NUM_TX_BD - 1)
415#define MAX_TX_AVAIL (MAX_TX_DESC_CNT * NUM_TX_RINGS - 2)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000416#define INIT_JUMBO_TX_RING_SIZE MAX_TX_AVAIL
417#define INIT_TX_RING_SIZE MAX_TX_AVAIL
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700418#define NEXT_TX_IDX(x) ((((x) & MAX_TX_DESC_CNT) == \
419 (MAX_TX_DESC_CNT - 1)) ? (x) + 2 : (x) + 1)
420#define TX_BD(x) ((x) & MAX_TX_BD)
421#define TX_BD_POFF(x) ((x) & MAX_TX_DESC_CNT)
422
423/* The RX BD ring is special, each bd is 8 bytes but the last one is 16 */
424#define NUM_RX_RINGS 8
425#define RX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_bd))
426#define MAX_RX_DESC_CNT (RX_DESC_CNT - 2)
427#define RX_DESC_MASK (RX_DESC_CNT - 1)
428#define NUM_RX_BD (RX_DESC_CNT * NUM_RX_RINGS)
429#define MAX_RX_BD (NUM_RX_BD - 1)
430#define MAX_RX_AVAIL (MAX_RX_DESC_CNT * NUM_RX_RINGS - 2)
Dmitry Kravkov25141582010-09-12 05:48:28 +0000431#define MIN_RX_AVAIL 128
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000432#define INIT_JUMBO_RX_RING_SIZE MAX_RX_AVAIL
433#define INIT_RX_RING_SIZE MAX_RX_AVAIL
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700434#define NEXT_RX_IDX(x) ((((x) & RX_DESC_MASK) == \
435 (MAX_RX_DESC_CNT - 1)) ? (x) + 3 : (x) + 1)
436#define RX_BD(x) ((x) & MAX_RX_BD)
437
438/* As long as CQE is 4 times bigger than BD entry we have to allocate
439 4 times more pages for CQ ring in order to keep it balanced with
440 BD ring */
441#define NUM_RCQ_RINGS (NUM_RX_RINGS * 4)
442#define RCQ_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_rx_cqe))
443#define MAX_RCQ_DESC_CNT (RCQ_DESC_CNT - 1)
444#define NUM_RCQ_BD (RCQ_DESC_CNT * NUM_RCQ_RINGS)
445#define MAX_RCQ_BD (NUM_RCQ_BD - 1)
446#define MAX_RCQ_AVAIL (MAX_RCQ_DESC_CNT * NUM_RCQ_RINGS - 2)
447#define NEXT_RCQ_IDX(x) ((((x) & MAX_RCQ_DESC_CNT) == \
448 (MAX_RCQ_DESC_CNT - 1)) ? (x) + 2 : (x) + 1)
449#define RCQ_BD(x) ((x) & MAX_RCQ_BD)
450
451
Eilon Greenstein33471622008-08-13 15:59:08 -0700452/* This is needed for determining of last_max */
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700453#define SUB_S16(a, b) (s16)((s16)(a) - (s16)(b))
454
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700455#define __SGE_MASK_SET_BIT(el, bit) \
456 do { \
457 el = ((el) | ((u64)0x1 << (bit))); \
458 } while (0)
459
460#define __SGE_MASK_CLEAR_BIT(el, bit) \
461 do { \
462 el = ((el) & (~((u64)0x1 << (bit)))); \
463 } while (0)
464
465#define SGE_MASK_SET_BIT(fp, idx) \
466 __SGE_MASK_SET_BIT(fp->sge_mask[(idx) >> RX_SGE_MASK_ELEM_SHIFT], \
467 ((idx) & RX_SGE_MASK_ELEM_MASK))
468
469#define SGE_MASK_CLEAR_BIT(fp, idx) \
470 __SGE_MASK_CLEAR_BIT(fp->sge_mask[(idx) >> RX_SGE_MASK_ELEM_SHIFT], \
471 ((idx) & RX_SGE_MASK_ELEM_MASK))
472
473
474/* used on a CID received from the HW */
475#define SW_CID(x) (le32_to_cpu(x) & \
476 (COMMON_RAMROD_ETH_RX_CQE_CID >> 7))
477#define CQE_CMD(x) (le32_to_cpu(x) >> \
478 COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT)
479
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700480#define BD_UNMAP_ADDR(bd) HILO_U64(le32_to_cpu((bd)->addr_hi), \
481 le32_to_cpu((bd)->addr_lo))
482#define BD_UNMAP_LEN(bd) (le16_to_cpu((bd)->nbytes))
483
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000484#define BNX2X_DB_MIN_SHIFT 3 /* 8 bytes */
485#define BNX2X_DB_SHIFT 7 /* 128 bytes*/
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700486#define DPM_TRIGER_TYPE 0x40
487#define DOORBELL(bp, cid, val) \
488 do { \
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000489 writel((u32)(val), bp->doorbells + (bp->db_size * (cid)) + \
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700490 DPM_TRIGER_TYPE); \
491 } while (0)
492
493
494/* TX CSUM helpers */
495#define SKB_CS_OFF(skb) (offsetof(struct tcphdr, check) - \
496 skb->csum_offset)
497#define SKB_CS(skb) (*(u16 *)(skb_transport_header(skb) + \
498 skb->csum_offset))
499
500#define pbd_tcp_flags(skb) (ntohl(tcp_flag_word(tcp_hdr(skb)))>>16 & 0xff)
501
502#define XMIT_PLAIN 0
503#define XMIT_CSUM_V4 0x1
504#define XMIT_CSUM_V6 0x2
505#define XMIT_CSUM_TCP 0x4
506#define XMIT_GSO_V4 0x8
507#define XMIT_GSO_V6 0x10
508
509#define XMIT_CSUM (XMIT_CSUM_V4 | XMIT_CSUM_V6)
510#define XMIT_GSO (XMIT_GSO_V4 | XMIT_GSO_V6)
511
512
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700513/* stuff added to make the code fit 80Col */
514
515#define CQE_TYPE(cqe_fp_flags) ((cqe_fp_flags) & ETH_FAST_PATH_RX_CQE_TYPE)
516
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700517#define TPA_TYPE_START ETH_FAST_PATH_RX_CQE_START_FLG
518#define TPA_TYPE_END ETH_FAST_PATH_RX_CQE_END_FLG
519#define TPA_TYPE(cqe_fp_flags) ((cqe_fp_flags) & \
520 (TPA_TYPE_START | TPA_TYPE_END))
521
Eilon Greenstein1adcd8b2008-08-13 15:48:29 -0700522#define ETH_RX_ERROR_FALGS ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG
523
524#define BNX2X_IP_CSUM_ERR(cqe) \
525 (!((cqe)->fast_path_cqe.status_flags & \
526 ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG) && \
527 ((cqe)->fast_path_cqe.type_error_flags & \
528 ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG))
529
530#define BNX2X_L4_CSUM_ERR(cqe) \
531 (!((cqe)->fast_path_cqe.status_flags & \
532 ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG) && \
533 ((cqe)->fast_path_cqe.type_error_flags & \
534 ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG))
535
536#define BNX2X_RX_CSUM_OK(cqe) \
537 (!(BNX2X_L4_CSUM_ERR(cqe) || BNX2X_IP_CSUM_ERR(cqe)))
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700538
Eilon Greenstein052a38e2009-02-12 08:37:16 +0000539#define BNX2X_PRS_FLAG_OVERETH_IPV4(flags) \
540 (((le16_to_cpu(flags) & \
541 PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) >> \
542 PARSING_FLAGS_OVER_ETHERNET_PROTOCOL_SHIFT) \
543 == PRS_FLAG_OVERETH_IPV4)
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700544#define BNX2X_RX_SUM_FIX(cqe) \
Eilon Greenstein052a38e2009-02-12 08:37:16 +0000545 BNX2X_PRS_FLAG_OVERETH_IPV4(cqe->fast_path_cqe.pars_flags.flags)
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700546
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000547#define U_SB_ETH_RX_CQ_INDEX 1
548#define U_SB_ETH_RX_BD_INDEX 2
549#define C_SB_ETH_TX_CQ_INDEX 5
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200550
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700551#define BNX2X_RX_SB_INDEX \
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000552 (&fp->sb_index_values[U_SB_ETH_RX_CQ_INDEX])
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200553
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700554#define BNX2X_TX_SB_INDEX \
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000555 (&fp->sb_index_values[C_SB_ETH_TX_CQ_INDEX])
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700556
557/* end of fast path */
558
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700559/* common */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200560
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700561struct bnx2x_common {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200562
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700563 u32 chip_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200564/* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700565#define CHIP_ID(bp) (bp->common.chip_id & 0xfffffff0)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200566
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700567#define CHIP_NUM(bp) (bp->common.chip_id >> 16)
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700568#define CHIP_NUM_57710 0x164e
569#define CHIP_NUM_57711 0x164f
570#define CHIP_NUM_57711E 0x1650
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000571#define CHIP_NUM_57712 0x1662
572#define CHIP_NUM_57712E 0x1663
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700573#define CHIP_IS_E1(bp) (CHIP_NUM(bp) == CHIP_NUM_57710)
574#define CHIP_IS_57711(bp) (CHIP_NUM(bp) == CHIP_NUM_57711)
575#define CHIP_IS_57711E(bp) (CHIP_NUM(bp) == CHIP_NUM_57711E)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000576#define CHIP_IS_57712(bp) (CHIP_NUM(bp) == CHIP_NUM_57712)
577#define CHIP_IS_57712E(bp) (CHIP_NUM(bp) == CHIP_NUM_57712E)
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700578#define CHIP_IS_E1H(bp) (CHIP_IS_57711(bp) || \
579 CHIP_IS_57711E(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000580#define CHIP_IS_E2(bp) (CHIP_IS_57712(bp) || \
581 CHIP_IS_57712E(bp))
582#define CHIP_IS_E1x(bp) (CHIP_IS_E1((bp)) || CHIP_IS_E1H((bp)))
583#define IS_E1H_OFFSET (CHIP_IS_E1H(bp) || CHIP_IS_E2(bp))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200584
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700585#define CHIP_REV(bp) (bp->common.chip_id & 0x0000f000)
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700586#define CHIP_REV_Ax 0x00000000
587/* assume maximum 5 revisions */
588#define CHIP_REV_IS_SLOW(bp) (CHIP_REV(bp) > 0x00005000)
589/* Emul versions are A=>0xe, B=>0xc, C=>0xa, D=>8, E=>6 */
590#define CHIP_REV_IS_EMUL(bp) ((CHIP_REV_IS_SLOW(bp)) && \
591 !(CHIP_REV(bp) & 0x00001000))
592/* FPGA versions are A=>0xf, B=>0xd, C=>0xb, D=>9, E=>7 */
593#define CHIP_REV_IS_FPGA(bp) ((CHIP_REV_IS_SLOW(bp)) && \
594 (CHIP_REV(bp) & 0x00001000))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200595
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700596#define CHIP_TIME(bp) ((CHIP_REV_IS_EMUL(bp)) ? 2000 : \
597 ((CHIP_REV_IS_FPGA(bp)) ? 200 : 1))
598
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700599#define CHIP_METAL(bp) (bp->common.chip_id & 0x00000ff0)
600#define CHIP_BOND_ID(bp) (bp->common.chip_id & 0x0000000f)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200601
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700602 int flash_size;
603#define NVRAM_1MB_SIZE 0x20000 /* 1M bit in bytes */
604#define NVRAM_TIMEOUT_COUNT 30000
605#define NVRAM_PAGE_SIZE 256
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200606
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700607 u32 shmem_base;
Eilon Greenstein2691d512009-08-12 08:22:08 +0000608 u32 shmem2_base;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000609 u32 mf_cfg_base;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000610 u32 mf2_cfg_base;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700611
612 u32 hw_config;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200613
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700614 u32 bc_ver;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000615
616 u8 int_block;
617#define INT_BLOCK_HC 0
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000618#define INT_BLOCK_IGU 1
619#define INT_BLOCK_MODE_NORMAL 0
620#define INT_BLOCK_MODE_BW_COMP 2
621#define CHIP_INT_MODE_IS_NBC(bp) \
622 (CHIP_IS_E2(bp) && \
623 !((bp)->common.int_block & INT_BLOCK_MODE_BW_COMP))
624#define CHIP_INT_MODE_IS_BC(bp) (!CHIP_INT_MODE_IS_NBC(bp))
625
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000626 u8 chip_port_mode;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000627#define CHIP_4_PORT_MODE 0x0
628#define CHIP_2_PORT_MODE 0x1
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000629#define CHIP_PORT_MODE_NONE 0x2
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000630#define CHIP_MODE(bp) (bp->common.chip_port_mode)
631#define CHIP_MODE_IS_4_PORT(bp) (CHIP_MODE(bp) == CHIP_4_PORT_MODE)
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700632};
633
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000634/* IGU MSIX STATISTICS on 57712: 64 for VFs; 4 for PFs; 4 for Attentions */
635#define BNX2X_IGU_STAS_MSG_VF_CNT 64
636#define BNX2X_IGU_STAS_MSG_PF_CNT 4
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700637
638/* end of common */
639
640/* port */
641
642struct bnx2x_port {
643 u32 pmf;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200644
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000645 u32 link_config[LINK_CONFIG_SIZE];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200646
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000647 u32 supported[LINK_CONFIG_SIZE];
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200648/* link settings - missing defines */
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700649#define SUPPORTED_2500baseX_Full (1 << 15)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200650
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000651 u32 advertising[LINK_CONFIG_SIZE];
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700652/* link settings - missing defines */
653#define ADVERTISED_2500baseX_Full (1 << 15)
654
655 u32 phy_addr;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700656
657 /* used to synchronize phy accesses */
658 struct mutex phy_mutex;
Eilon Greenstein46c6a672009-02-12 08:36:58 +0000659 int need_hw_lock;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700660
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700661 u32 port_stx;
662
663 struct nig_stats old_nig_stats;
664};
665
666/* end of port */
667
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000668/* e1h Classification CAM line allocations */
669enum {
670 CAM_ETH_LINE = 0,
671 CAM_ISCSI_ETH_LINE,
672 CAM_MAX_PF_LINE = CAM_ISCSI_ETH_LINE
673};
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800674/* number of MACs per function in NIG memory - used for SI mode */
675#define NIG_LLH_FUNC_MEM_SIZE 16
676/* number of entries in NIG_REG_LLHX_FUNC_MEM */
677#define NIG_LLH_FUNC_MEM_MAX_OFFSET 8
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700678
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000679#define BNX2X_VF_ID_INVALID 0xFF
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700680
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000681/*
682 * The total number of L2 queues, MSIX vectors and HW contexts (CIDs) is
683 * control by the number of fast-path status blocks supported by the
684 * device (HW/FW). Each fast-path status block (FP-SB) aka non-default
685 * status block represents an independent interrupts context that can
686 * serve a regular L2 networking queue. However special L2 queues such
687 * as the FCoE queue do not require a FP-SB and other components like
688 * the CNIC may consume FP-SB reducing the number of possible L2 queues
689 *
690 * If the maximum number of FP-SB available is X then:
691 * a. If CNIC is supported it consumes 1 FP-SB thus the max number of
692 * regular L2 queues is Y=X-1
693 * b. in MF mode the actual number of L2 queues is Y= (X-1/MF_factor)
694 * c. If the FCoE L2 queue is supported the actual number of L2 queues
695 * is Y+1
696 * d. The number of irqs (MSIX vectors) is either Y+1 (one extra for
697 * slow-path interrupts) or Y+2 if CNIC is supported (one additional
698 * FP interrupt context for the CNIC).
699 * e. The number of HW context (CID count) is always X or X+1 if FCoE
700 * L2 queue is supported. the cid for the FCoE L2 queue is always X.
701 */
702
703#define FP_SB_MAX_E1x 16 /* fast-path interrupt contexts E1x */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000704#define FP_SB_MAX_E2 16 /* fast-path interrupt contexts E2 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000705
706/*
707 * cid_cnt paramter below refers to the value returned by
708 * 'bnx2x_get_l2_cid_count()' routine
709 */
710
711/*
712 * The number of FP context allocated by the driver == max number of regular
713 * L2 queues + 1 for the FCoE L2 queue
714 */
715#define L2_FP_COUNT(cid_cnt) ((cid_cnt) - CNIC_CONTEXT_USE)
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700716
717union cdu_context {
718 struct eth_context eth;
719 char pad[1024];
720};
721
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000722/* CDU host DB constants */
723#define CDU_ILT_PAGE_SZ_HW 3
724#define CDU_ILT_PAGE_SZ (4096 << CDU_ILT_PAGE_SZ_HW) /* 32K */
725#define ILT_PAGE_CIDS (CDU_ILT_PAGE_SZ / sizeof(union cdu_context))
726
727#ifdef BCM_CNIC
728#define CNIC_ISCSI_CID_MAX 256
729#define CNIC_CID_MAX (CNIC_ISCSI_CID_MAX)
730#define CNIC_ILT_LINES DIV_ROUND_UP(CNIC_CID_MAX, ILT_PAGE_CIDS)
731#endif
732
733#define QM_ILT_PAGE_SZ_HW 3
734#define QM_ILT_PAGE_SZ (4096 << QM_ILT_PAGE_SZ_HW) /* 32K */
735#define QM_CID_ROUND 1024
736
737#ifdef BCM_CNIC
738/* TM (timers) host DB constants */
739#define TM_ILT_PAGE_SZ_HW 2
740#define TM_ILT_PAGE_SZ (4096 << TM_ILT_PAGE_SZ_HW) /* 16K */
741/* #define TM_CONN_NUM (CNIC_STARTING_CID+CNIC_ISCSI_CXT_MAX) */
742#define TM_CONN_NUM 1024
743#define TM_ILT_SZ (8 * TM_CONN_NUM)
744#define TM_ILT_LINES DIV_ROUND_UP(TM_ILT_SZ, TM_ILT_PAGE_SZ)
745
746/* SRC (Searcher) host DB constants */
747#define SRC_ILT_PAGE_SZ_HW 3
748#define SRC_ILT_PAGE_SZ (4096 << SRC_ILT_PAGE_SZ_HW) /* 32K */
749#define SRC_HASH_BITS 10
750#define SRC_CONN_NUM (1 << SRC_HASH_BITS) /* 1024 */
751#define SRC_ILT_SZ (sizeof(struct src_ent) * SRC_CONN_NUM)
752#define SRC_T2_SZ SRC_ILT_SZ
753#define SRC_ILT_LINES DIV_ROUND_UP(SRC_ILT_SZ, SRC_ILT_PAGE_SZ)
754#endif
755
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700756#define MAX_DMAE_C 8
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700757
758/* DMA memory not used in fastpath */
759struct bnx2x_slowpath {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700760 struct eth_stats_query fw_stats;
761 struct mac_configuration_cmd mac_config;
762 struct mac_configuration_cmd mcast_config;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000763 struct client_init_ramrod_data client_init_data;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700764
765 /* used by dmae command executer */
766 struct dmae_command dmae[MAX_DMAE_C];
767
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700768 u32 stats_comp;
769 union mac_stats mac_stats;
770 struct nig_stats nig_stats;
771 struct host_port_stats port_stats;
772 struct host_func_stats func_stats;
Eilon Greenstein6fe49bb2009-08-12 08:23:17 +0000773 struct host_func_stats func_stats_base;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700774
775 u32 wb_comp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700776 u32 wb_data[4];
777};
778
779#define bnx2x_sp(bp, var) (&bp->slowpath->var)
780#define bnx2x_sp_mapping(bp, var) \
781 (bp->slowpath_mapping + offsetof(struct bnx2x_slowpath, var))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200782
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200783
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700784/* attn group wiring */
785#define MAX_DYNAMIC_ATTN_GRPS 8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200786
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700787struct attn_route {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000788 u32 sig[5];
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700789};
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200790
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000791struct iro {
792 u32 base;
793 u16 m1;
794 u16 m2;
795 u16 m3;
796 u16 size;
797};
798
799struct hw_context {
800 union cdu_context *vcxt;
801 dma_addr_t cxt_mapping;
802 size_t size;
803};
804
805/* forward */
806struct bnx2x_ilt;
807
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +0000808typedef enum {
809 BNX2X_RECOVERY_DONE,
810 BNX2X_RECOVERY_INIT,
811 BNX2X_RECOVERY_WAIT,
812} bnx2x_recovery_state_t;
813
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000814/**
815 * Event queue (EQ or event ring) MC hsi
816 * NUM_EQ_PAGES and EQ_DESC_CNT_PAGE must be power of 2
817 */
818#define NUM_EQ_PAGES 1
819#define EQ_DESC_CNT_PAGE (BCM_PAGE_SIZE / sizeof(union event_ring_elem))
820#define EQ_DESC_MAX_PAGE (EQ_DESC_CNT_PAGE - 1)
821#define NUM_EQ_DESC (EQ_DESC_CNT_PAGE * NUM_EQ_PAGES)
822#define EQ_DESC_MASK (NUM_EQ_DESC - 1)
823#define MAX_EQ_AVAIL (EQ_DESC_MAX_PAGE * NUM_EQ_PAGES - 2)
824
825/* depends on EQ_DESC_CNT_PAGE being a power of 2 */
826#define NEXT_EQ_IDX(x) ((((x) & EQ_DESC_MAX_PAGE) == \
827 (EQ_DESC_MAX_PAGE - 1)) ? (x) + 2 : (x) + 1)
828
829/* depends on the above and on NUM_EQ_PAGES being a power of 2 */
830#define EQ_DESC(x) ((x) & EQ_DESC_MASK)
831
832#define BNX2X_EQ_INDEX \
833 (&bp->def_status_blk->sp_sb.\
834 index_values[HC_SP_INDEX_EQ_CONS])
835
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700836struct bnx2x {
837 /* Fields used in the tx and intr/napi performance paths
838 * are grouped together in the beginning of the structure
839 */
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000840 struct bnx2x_fastpath *fp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700841 void __iomem *regview;
842 void __iomem *doorbells;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000843 u16 db_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200844
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700845 struct net_device *dev;
846 struct pci_dev *pdev;
847
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000848 struct iro *iro_arr;
849#define IRO (bp->iro_arr)
850
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700851 atomic_t intr_sem;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +0000852
853 bnx2x_recovery_state_t recovery_state;
854 int is_leader;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000855 struct msix_entry *msix_table;
Eilon Greenstein8badd272009-02-12 08:36:15 +0000856#define INT_MODE_INTx 1
857#define INT_MODE_MSI 2
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700858
859 int tx_ring_size;
860
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700861 u32 rx_csum;
Eilon Greenstein437cf2f2008-09-03 14:38:00 -0700862 u32 rx_buf_size;
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000863/* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
864#define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700865#define ETH_MIN_PACKET_SIZE 60
866#define ETH_MAX_PACKET_SIZE 1500
867#define ETH_MAX_JUMBO_PACKET_SIZE 9600
868
Eilon Greenstein0f008462009-02-12 08:36:18 +0000869 /* Max supported alignment is 256 (8 shift) */
870#define BNX2X_RX_ALIGN_SHIFT ((L1_CACHE_SHIFT < 8) ? \
871 L1_CACHE_SHIFT : 8)
872#define BNX2X_RX_ALIGN (1 << BNX2X_RX_ALIGN_SHIFT)
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000873#define BNX2X_PXP_DRAM_ALIGN (BNX2X_RX_ALIGN_SHIFT - 5)
Eilon Greenstein0f008462009-02-12 08:36:18 +0000874
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000875 struct host_sp_status_block *def_status_blk;
876#define DEF_SB_IGU_ID 16
877#define DEF_SB_ID HC_SP_SB_ID
878 __le16 def_idx;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000879 __le16 def_att_idx;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700880 u32 attn_state;
881 struct attn_route attn_group[MAX_DYNAMIC_ATTN_GRPS];
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700882
883 /* slow path ring */
884 struct eth_spe *spq;
885 dma_addr_t spq_mapping;
886 u16 spq_prod_idx;
887 struct eth_spe *spq_prod_bd;
888 struct eth_spe *spq_last_bd;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000889 __le16 *dsb_sp_prod;
Dmitry Kravkov8fe23fb2010-10-06 03:27:41 +0000890 atomic_t spq_left; /* serialize spq */
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700891 /* used to synchronize spq accesses */
892 spinlock_t spq_lock;
893
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000894 /* event queue */
895 union event_ring_elem *eq_ring;
896 dma_addr_t eq_mapping;
897 u16 eq_prod;
898 u16 eq_cons;
899 __le16 *eq_cons_sb;
900
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700901 /* Flags for marking that there is a STAT_QUERY or
902 SET_MAC ramrod pending */
Michael Chane665bfd2009-10-10 13:46:54 +0000903 int stats_pending;
904 int set_mac_pending;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700905
Eilon Greenstein33471622008-08-13 15:59:08 -0700906 /* End of fields used in the performance code paths */
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700907
908 int panic;
Joe Perches7995c642010-02-17 15:01:52 +0000909 int msg_enable;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700910
911 u32 flags;
912#define PCIX_FLAG 1
913#define PCI_32BIT_FLAG 2
Eilon Greenstein1c063282009-02-12 08:36:43 +0000914#define ONE_PORT_FLAG 4
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700915#define NO_WOL_FLAG 8
916#define USING_DAC_FLAG 0x10
917#define USING_MSIX_FLAG 0x20
Eilon Greenstein8badd272009-02-12 08:36:15 +0000918#define USING_MSI_FLAG 0x40
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000919
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700920#define TPA_ENABLE_FLAG 0x80
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700921#define NO_MCP_FLAG 0x100
Dmitry Kravkovd6214d72010-10-06 03:32:10 +0000922#define DISABLE_MSI_FLAG 0x200
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700923#define BP_NOMCP(bp) (bp->flags & NO_MCP_FLAG)
Eilon Greensteinf34d28e2009-10-15 00:18:08 -0700924#define MF_FUNC_DIS 0x1000
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700925
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000926 int pf_num; /* absolute PF number */
927 int pfid; /* per-path PF number */
Dmitry Kravkov523224a2010-10-06 03:23:26 +0000928 int base_fw_ndsb;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000929#define BP_PATH(bp) (!CHIP_IS_E2(bp) ? \
930 0 : (bp->pf_num & 1))
931#define BP_PORT(bp) (bp->pfid & 1)
932#define BP_FUNC(bp) (bp->pfid)
933#define BP_ABS_FUNC(bp) (bp->pf_num)
934#define BP_E1HVN(bp) (bp->pfid >> 1)
935#define BP_VN(bp) (CHIP_MODE_IS_4_PORT(bp) ? \
936 0 : BP_E1HVN(bp))
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700937#define BP_L_ID(bp) (BP_E1HVN(bp) << 2)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000938#define BP_FW_MB_IDX(bp) (BP_PORT(bp) +\
939 BP_VN(bp) * (CHIP_IS_E1x(bp) ? 2 : 1))
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700940
Michael Chan37b091b2009-10-10 13:46:55 +0000941#ifdef BCM_CNIC
942#define BCM_CNIC_CID_START 16
943#define BCM_ISCSI_ETH_CL_ID 17
944#endif
945
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700946 int pm_cap;
947 int pcie_cap;
Eilon Greenstein8d5726c2009-02-12 08:37:19 +0000948 int mrrs;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700949
Eilon Greenstein1cf167f2009-01-14 21:22:18 -0800950 struct delayed_work sp_task;
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +0000951 struct delayed_work reset_task;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700952 struct timer_list timer;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700953 int current_interval;
954
955 u16 fw_seq;
956 u16 fw_drv_pulse_wr_seq;
957 u32 func_stx;
958
959 struct link_params link_params;
960 struct link_vars link_vars;
Eilon Greenstein01cd4522009-08-12 08:23:08 +0000961 struct mdio_if_info mdio;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700962
963 struct bnx2x_common common;
964 struct bnx2x_port port;
965
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +0000966 struct cmng_struct_per_port cmng;
967 u32 vn_weight_sum;
968
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000969 u32 mf_config[E1HVN_MAX];
970 u32 mf2_config[E2_FUNC_MAX];
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +0000971 u16 mf_ov;
972 u8 mf_mode;
Dmitry Kravkovf85582f2010-10-06 03:34:21 +0000973#define IS_MF(bp) (bp->mf_mode != 0)
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800974#define IS_MF_SI(bp) (bp->mf_mode == MULTI_FUNCTION_SI)
975#define IS_MF_SD(bp) (bp->mf_mode == MULTI_FUNCTION_SD)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200976
Eliezer Tamirf1410642008-02-28 11:51:50 -0800977 u8 wol;
978
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700979 int rx_ring_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200980
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700981 u16 tx_quick_cons_trip_int;
982 u16 tx_quick_cons_trip;
983 u16 tx_ticks_int;
984 u16 tx_ticks;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200985
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700986 u16 rx_quick_cons_trip_int;
987 u16 rx_quick_cons_trip;
988 u16 rx_ticks_int;
989 u16 rx_ticks;
Vladislav Zolotarovcdaa7cb2010-04-19 01:13:57 +0000990/* Maximal coalescing timeout in us */
991#define BNX2X_MAX_COALESCE_TOUT (0xf0*12)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200992
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700993 u32 lin_cnt;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200994
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700995 int state;
Eilon Greenstein356e2382009-02-12 08:38:32 +0000996#define BNX2X_STATE_CLOSED 0
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700997#define BNX2X_STATE_OPENING_WAIT4_LOAD 0x1000
998#define BNX2X_STATE_OPENING_WAIT4_PORT 0x2000
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200999#define BNX2X_STATE_OPEN 0x3000
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001000#define BNX2X_STATE_CLOSING_WAIT4_HALT 0x4000
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001001#define BNX2X_STATE_CLOSING_WAIT4_DELETE 0x5000
1002#define BNX2X_STATE_CLOSING_WAIT4_UNLOAD 0x6000
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001003#define BNX2X_STATE_FUNC_STARTED 0x7000
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001004#define BNX2X_STATE_DIAG 0xe000
1005#define BNX2X_STATE_ERROR 0xf000
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001006
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001007 int multi_mode;
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001008 int num_queues;
Dmitry Kravkov5d7cd492010-07-27 12:32:19 +00001009 int disable_tpa;
1010 int int_mode;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001011
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001012 struct tstorm_eth_mac_filter_config mac_filters;
1013#define BNX2X_ACCEPT_NONE 0x0000
1014#define BNX2X_ACCEPT_UNICAST 0x0001
1015#define BNX2X_ACCEPT_MULTICAST 0x0002
1016#define BNX2X_ACCEPT_ALL_UNICAST 0x0004
1017#define BNX2X_ACCEPT_ALL_MULTICAST 0x0008
1018#define BNX2X_ACCEPT_BROADCAST 0x0010
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -08001019#define BNX2X_ACCEPT_UNMATCHED_UCAST 0x0020
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001020#define BNX2X_PROMISCUOUS_MODE 0x10000
1021
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001022 u32 rx_mode;
1023#define BNX2X_RX_MODE_NONE 0
1024#define BNX2X_RX_MODE_NORMAL 1
1025#define BNX2X_RX_MODE_ALLMULTI 2
1026#define BNX2X_RX_MODE_PROMISC 3
1027#define BNX2X_MAX_MULTICAST 64
1028#define BNX2X_MAX_EMUL_MULTI 16
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001029
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001030 u8 igu_dsb_id;
1031 u8 igu_base_sb;
1032 u8 igu_sb_cnt;
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001033 dma_addr_t def_status_blk_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001034
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001035 struct bnx2x_slowpath *slowpath;
1036 dma_addr_t slowpath_mapping;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001037 struct hw_context context;
1038
1039 struct bnx2x_ilt *ilt;
1040#define BP_ILT(bp) ((bp)->ilt)
1041#define ILT_MAX_LINES 128
1042
1043 int l2_cid_count;
1044#define L2_ILT_LINES(bp) (DIV_ROUND_UP((bp)->l2_cid_count, \
1045 ILT_PAGE_CIDS))
1046#define BNX2X_DB_SIZE(bp) ((bp)->l2_cid_count * (1 << BNX2X_DB_SHIFT))
1047
1048 int qm_cid_count;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001049
Eilon Greensteina18f5122009-08-12 08:23:26 +00001050 int dropless_fc;
1051
Michael Chan37b091b2009-10-10 13:46:55 +00001052#ifdef BCM_CNIC
1053 u32 cnic_flags;
1054#define BNX2X_CNIC_FLAG_MAC_SET 1
Michael Chan37b091b2009-10-10 13:46:55 +00001055 void *t2;
1056 dma_addr_t t2_mapping;
Michael Chan37b091b2009-10-10 13:46:55 +00001057 struct cnic_ops *cnic_ops;
1058 void *cnic_data;
1059 u32 cnic_tag;
1060 struct cnic_eth_dev cnic_eth_dev;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001061 union host_hc_status_block cnic_sb;
Michael Chan37b091b2009-10-10 13:46:55 +00001062 dma_addr_t cnic_sb_mapping;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001063#define CNIC_SB_ID(bp) ((bp)->base_fw_ndsb + BP_L_ID(bp))
1064#define CNIC_IGU_SB_ID(bp) ((bp)->igu_base_sb)
Michael Chan37b091b2009-10-10 13:46:55 +00001065 struct eth_spe *cnic_kwq;
1066 struct eth_spe *cnic_kwq_prod;
1067 struct eth_spe *cnic_kwq_cons;
1068 struct eth_spe *cnic_kwq_last;
1069 u16 cnic_kwq_pending;
1070 u16 cnic_spq_pending;
1071 struct mutex cnic_mutex;
1072 u8 iscsi_mac[6];
1073#endif
1074
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001075 int dmae_ready;
1076 /* used to synchronize dmae accesses */
1077 struct mutex dmae_mutex;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001078
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07001079 /* used to protect the FW mail box */
1080 struct mutex fw_mb_mutex;
1081
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001082 /* used to synchronize stats collecting */
1083 int stats_state;
Vladislav Zolotarova13773a2010-07-21 05:59:01 +00001084
1085 /* used for synchronization of concurrent threads statistics handling */
1086 spinlock_t stats_lock;
1087
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001088 /* used by dmae command loader */
1089 struct dmae_command stats_dmae;
1090 int executer_idx;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001091
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001092 u16 stats_counter;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001093 struct bnx2x_eth_stats eth_stats;
1094
1095 struct z_stream_s *strm;
1096 void *gunzip_buf;
1097 dma_addr_t gunzip_mapping;
1098 int gunzip_outlen;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001099#define FW_BUF_SIZE 0x8000
Eilon Greenstein573f2032009-08-12 08:24:14 +00001100#define GUNZIP_BUF(bp) (bp->gunzip_buf)
1101#define GUNZIP_PHYS(bp) (bp->gunzip_mapping)
1102#define GUNZIP_OUTLEN(bp) (bp->gunzip_outlen)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001103
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001104 struct raw_op *init_ops;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07001105 /* Init blocks offsets inside init_ops */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001106 u16 *init_ops_offsets;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07001107 /* Data blob - has 32 bit granularity */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001108 u32 *init_data;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07001109 /* Zipped PRAM blobs - raw data */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001110 const u8 *tsem_int_table_data;
1111 const u8 *tsem_pram_data;
1112 const u8 *usem_int_table_data;
1113 const u8 *usem_pram_data;
1114 const u8 *xsem_int_table_data;
1115 const u8 *xsem_pram_data;
1116 const u8 *csem_int_table_data;
1117 const u8 *csem_pram_data;
Eilon Greenstein573f2032009-08-12 08:24:14 +00001118#define INIT_OPS(bp) (bp->init_ops)
1119#define INIT_OPS_OFFSETS(bp) (bp->init_ops_offsets)
1120#define INIT_DATA(bp) (bp->init_data)
1121#define INIT_TSEM_INT_TABLE_DATA(bp) (bp->tsem_int_table_data)
1122#define INIT_TSEM_PRAM_DATA(bp) (bp->tsem_pram_data)
1123#define INIT_USEM_INT_TABLE_DATA(bp) (bp->usem_int_table_data)
1124#define INIT_USEM_PRAM_DATA(bp) (bp->usem_pram_data)
1125#define INIT_XSEM_INT_TABLE_DATA(bp) (bp->xsem_int_table_data)
1126#define INIT_XSEM_PRAM_DATA(bp) (bp->xsem_pram_data)
1127#define INIT_CSEM_INT_TABLE_DATA(bp) (bp->csem_int_table_data)
1128#define INIT_CSEM_PRAM_DATA(bp) (bp->csem_pram_data)
1129
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +00001130 char fw_ver[32];
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001131 const struct firmware *firmware;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001132};
1133
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001134/**
1135 * Init queue/func interface
1136 */
1137/* queue init flags */
1138#define QUEUE_FLG_TPA 0x0001
1139#define QUEUE_FLG_CACHE_ALIGN 0x0002
1140#define QUEUE_FLG_STATS 0x0004
1141#define QUEUE_FLG_OV 0x0008
1142#define QUEUE_FLG_VLAN 0x0010
1143#define QUEUE_FLG_COS 0x0020
1144#define QUEUE_FLG_HC 0x0040
1145#define QUEUE_FLG_DHC 0x0080
1146#define QUEUE_FLG_OOO 0x0100
1147
1148#define QUEUE_DROP_IP_CS_ERR TSTORM_ETH_CLIENT_CONFIG_DROP_IP_CS_ERR
1149#define QUEUE_DROP_TCP_CS_ERR TSTORM_ETH_CLIENT_CONFIG_DROP_TCP_CS_ERR
1150#define QUEUE_DROP_TTL0 TSTORM_ETH_CLIENT_CONFIG_DROP_TTL0
1151#define QUEUE_DROP_UDP_CS_ERR TSTORM_ETH_CLIENT_CONFIG_DROP_UDP_CS_ERR
1152
1153
1154
1155/* rss capabilities */
1156#define RSS_IPV4_CAP 0x0001
1157#define RSS_IPV4_TCP_CAP 0x0002
1158#define RSS_IPV6_CAP 0x0004
1159#define RSS_IPV6_TCP_CAP 0x0008
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001160
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001161#define BNX2X_NUM_QUEUES(bp) (bp->num_queues)
1162#define is_multi(bp) (BNX2X_NUM_QUEUES(bp) > 1)
Eilon Greenstein3196a882008-08-13 15:58:49 -07001163
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001164#define BNX2X_MAX_QUEUES(bp) (bp->igu_sb_cnt - CNIC_CONTEXT_USE)
1165#define is_eth_multi(bp) (BNX2X_NUM_ETH_QUEUES(bp) > 1)
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001166
1167#define RSS_IPV4_CAP_MASK \
1168 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY
1169
1170#define RSS_IPV4_TCP_CAP_MASK \
1171 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY
1172
1173#define RSS_IPV6_CAP_MASK \
1174 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY
1175
1176#define RSS_IPV6_TCP_CAP_MASK \
1177 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY
1178
1179/* func init flags */
Dmitry Kravkov030f3352010-10-17 23:08:53 +00001180#define FUNC_FLG_STATS 0x0001
1181#define FUNC_FLG_TPA 0x0002
1182#define FUNC_FLG_SPQ 0x0004
1183#define FUNC_FLG_LEADING 0x0008 /* PF only */
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001184
1185struct rxq_pause_params {
1186 u16 bd_th_lo;
1187 u16 bd_th_hi;
1188 u16 rcq_th_lo;
1189 u16 rcq_th_hi;
1190 u16 sge_th_lo; /* valid iff QUEUE_FLG_TPA */
1191 u16 sge_th_hi; /* valid iff QUEUE_FLG_TPA */
1192 u16 pri_map;
1193};
1194
1195struct bnx2x_rxq_init_params {
1196 /* cxt*/
1197 struct eth_context *cxt;
1198
1199 /* dma */
1200 dma_addr_t dscr_map;
1201 dma_addr_t sge_map;
1202 dma_addr_t rcq_map;
1203 dma_addr_t rcq_np_map;
1204
1205 u16 flags;
1206 u16 drop_flags;
1207 u16 mtu;
1208 u16 buf_sz;
1209 u16 fw_sb_id;
1210 u16 cl_id;
1211 u16 spcl_id;
1212 u16 cl_qzone_id;
1213
1214 /* valid iff QUEUE_FLG_STATS */
1215 u16 stat_id;
1216
1217 /* valid iff QUEUE_FLG_TPA */
1218 u16 tpa_agg_sz;
1219 u16 sge_buf_sz;
1220 u16 max_sges_pkt;
1221
1222 /* valid iff QUEUE_FLG_CACHE_ALIGN */
1223 u8 cache_line_log;
1224
1225 u8 sb_cq_index;
1226 u32 cid;
1227
1228 /* desired interrupts per sec. valid iff QUEUE_FLG_HC */
1229 u32 hc_rate;
1230};
1231
1232struct bnx2x_txq_init_params {
1233 /* cxt*/
1234 struct eth_context *cxt;
1235
1236 /* dma */
1237 dma_addr_t dscr_map;
1238
1239 u16 flags;
1240 u16 fw_sb_id;
1241 u8 sb_cq_index;
1242 u8 cos; /* valid iff QUEUE_FLG_COS */
1243 u16 stat_id; /* valid iff QUEUE_FLG_STATS */
1244 u16 traffic_type;
1245 u32 cid;
1246 u16 hc_rate; /* desired interrupts per sec.*/
1247 /* valid iff QUEUE_FLG_HC */
1248
1249};
1250
1251struct bnx2x_client_ramrod_params {
1252 int *pstate;
1253 int state;
1254 u16 index;
1255 u16 cl_id;
1256 u32 cid;
1257 u8 poll;
1258#define CLIENT_IS_LEADING_RSS 0x02
1259 u8 flags;
1260};
1261
1262struct bnx2x_client_init_params {
1263 struct rxq_pause_params pause;
1264 struct bnx2x_rxq_init_params rxq_params;
1265 struct bnx2x_txq_init_params txq_params;
1266 struct bnx2x_client_ramrod_params ramrod_params;
1267};
1268
1269struct bnx2x_rss_params {
1270 int mode;
1271 u16 cap;
1272 u16 result_mask;
1273};
1274
1275struct bnx2x_func_init_params {
1276
1277 /* rss */
1278 struct bnx2x_rss_params *rss; /* valid iff FUNC_FLG_RSS */
1279
1280 /* dma */
1281 dma_addr_t fw_stat_map; /* valid iff FUNC_FLG_STATS */
1282 dma_addr_t spq_map; /* valid iff FUNC_FLG_SPQ */
1283
1284 u16 func_flgs;
1285 u16 func_id; /* abs fid */
1286 u16 pf_id;
1287 u16 spq_prod; /* valid iff FUNC_FLG_SPQ */
1288};
1289
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001290#define for_each_queue(bp, var) \
1291 for (var = 0; var < BNX2X_NUM_QUEUES(bp); var++)
Eilon Greenstein3196a882008-08-13 15:58:49 -07001292#define for_each_nondefault_queue(bp, var) \
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001293 for (var = 1; var < BNX2X_NUM_QUEUES(bp); var++)
Eilon Greenstein3196a882008-08-13 15:58:49 -07001294
1295
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001296#define WAIT_RAMROD_POLL 0x01
1297#define WAIT_RAMROD_COMMON 0x02
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001298
1299/* dmae */
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001300void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
1301void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
1302 u32 len32);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001303void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx);
1304u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type);
1305u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode);
1306u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
1307 bool with_comp, u8 comp_type);
1308
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001309int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port);
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001310int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001311int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001312u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001313
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001314void bnx2x_calc_fc_adv(struct bnx2x *bp);
1315int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
1316 u32 data_hi, u32 data_lo, int common);
1317void bnx2x_update_coalesce(struct bnx2x *bp);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001318int bnx2x_get_link_cfg_idx(struct bnx2x *bp);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001319
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001320static inline u32 reg_poll(struct bnx2x *bp, u32 reg, u32 expected, int ms,
1321 int wait)
1322{
1323 u32 val;
1324
1325 do {
1326 val = REG_RD(bp, reg);
1327 if (val == expected)
1328 break;
1329 ms -= wait;
1330 msleep(wait);
1331
1332 } while (ms > 0);
1333
1334 return val;
1335}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001336
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001337#define BNX2X_ILT_ZALLOC(x, y, size) \
1338 do { \
Vladislav Zolotarovd245a112010-12-08 01:43:17 +00001339 x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001340 if (x) \
1341 memset(x, 0, size); \
1342 } while (0)
1343
1344#define BNX2X_ILT_FREE(x, y, size) \
1345 do { \
1346 if (x) { \
Vladislav Zolotarovd245a112010-12-08 01:43:17 +00001347 dma_free_coherent(&bp->pdev->dev, size, x, y); \
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001348 x = NULL; \
1349 y = 0; \
1350 } \
1351 } while (0)
1352
1353#define ILOG2(x) (ilog2((x)))
1354
1355#define ILT_NUM_PAGE_ENTRIES (3072)
1356/* In 57710/11 we use whole table since we have 8 func
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001357 * In 57712 we have only 4 func, but use same size per func, then only half of
1358 * the table in use
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001359 */
1360#define ILT_PER_FUNC (ILT_NUM_PAGE_ENTRIES/8)
1361
1362#define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
1363/*
1364 * the phys address is shifted right 12 bits and has an added
1365 * 1=valid bit added to the 53rd bit
1366 * then since this is a wide register(TM)
1367 * we split it into two 32 bit writes
1368 */
1369#define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
1370#define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001371
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001372/* load/unload mode */
1373#define LOAD_NORMAL 0
1374#define LOAD_OPEN 1
1375#define LOAD_DIAG 2
1376#define UNLOAD_NORMAL 0
1377#define UNLOAD_CLOSE 1
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001378#define UNLOAD_RECOVERY 2
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001379
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001380
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001381/* DMAE command defines */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001382#define DMAE_TIMEOUT -1
1383#define DMAE_PCI_ERROR -2 /* E2 and onward */
1384#define DMAE_NOT_RDY -3
1385#define DMAE_PCI_ERR_FLAG 0x80000000
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001386
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001387#define DMAE_SRC_PCI 0
1388#define DMAE_SRC_GRC 1
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001389
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001390#define DMAE_DST_NONE 0
1391#define DMAE_DST_PCI 1
1392#define DMAE_DST_GRC 2
1393
1394#define DMAE_COMP_PCI 0
1395#define DMAE_COMP_GRC 1
1396
1397/* E2 and onward - PCI error handling in the completion */
1398
1399#define DMAE_COMP_REGULAR 0
1400#define DMAE_COM_SET_ERR 1
1401
1402#define DMAE_CMD_SRC_PCI (DMAE_SRC_PCI << \
1403 DMAE_COMMAND_SRC_SHIFT)
1404#define DMAE_CMD_SRC_GRC (DMAE_SRC_GRC << \
1405 DMAE_COMMAND_SRC_SHIFT)
1406
1407#define DMAE_CMD_DST_PCI (DMAE_DST_PCI << \
1408 DMAE_COMMAND_DST_SHIFT)
1409#define DMAE_CMD_DST_GRC (DMAE_DST_GRC << \
1410 DMAE_COMMAND_DST_SHIFT)
1411
1412#define DMAE_CMD_C_DST_PCI (DMAE_COMP_PCI << \
1413 DMAE_COMMAND_C_DST_SHIFT)
1414#define DMAE_CMD_C_DST_GRC (DMAE_COMP_GRC << \
1415 DMAE_COMMAND_C_DST_SHIFT)
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001416
1417#define DMAE_CMD_C_ENABLE DMAE_COMMAND_C_TYPE_ENABLE
1418
1419#define DMAE_CMD_ENDIANITY_NO_SWAP (0 << DMAE_COMMAND_ENDIANITY_SHIFT)
1420#define DMAE_CMD_ENDIANITY_B_SWAP (1 << DMAE_COMMAND_ENDIANITY_SHIFT)
1421#define DMAE_CMD_ENDIANITY_DW_SWAP (2 << DMAE_COMMAND_ENDIANITY_SHIFT)
1422#define DMAE_CMD_ENDIANITY_B_DW_SWAP (3 << DMAE_COMMAND_ENDIANITY_SHIFT)
1423
1424#define DMAE_CMD_PORT_0 0
1425#define DMAE_CMD_PORT_1 DMAE_COMMAND_PORT
1426
1427#define DMAE_CMD_SRC_RESET DMAE_COMMAND_SRC_RESET
1428#define DMAE_CMD_DST_RESET DMAE_COMMAND_DST_RESET
1429#define DMAE_CMD_E1HVN_SHIFT DMAE_COMMAND_E1HVN_SHIFT
1430
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001431#define DMAE_SRC_PF 0
1432#define DMAE_SRC_VF 1
1433
1434#define DMAE_DST_PF 0
1435#define DMAE_DST_VF 1
1436
1437#define DMAE_C_SRC 0
1438#define DMAE_C_DST 1
1439
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001440#define DMAE_LEN32_RD_MAX 0x80
Vladislav Zolotarov02e3c6c2010-04-19 01:13:33 +00001441#define DMAE_LEN32_WR_MAX(bp) (CHIP_IS_E1(bp) ? 0x400 : 0x2000)
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001442
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001443#define DMAE_COMP_VAL 0x60d0d0ae /* E2 and on - upper bit
1444 indicates eror */
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001445
1446#define MAX_DMAE_C_PER_PORT 8
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001447#define INIT_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001448 BP_E1HVN(bp))
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001449#define PMF_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001450 E1HVN_MAX)
1451
Eliezer Tamir25047952008-02-28 11:50:16 -08001452/* PCIE link and speed */
1453#define PCICFG_LINK_WIDTH 0x1f00000
1454#define PCICFG_LINK_WIDTH_SHIFT 20
1455#define PCICFG_LINK_SPEED 0xf0000
1456#define PCICFG_LINK_SPEED_SHIFT 16
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001457
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001458
Eilon Greensteind3d4f492009-02-12 08:36:27 +00001459#define BNX2X_NUM_TESTS 7
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001460
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00001461#define BNX2X_PHY_LOOPBACK 0
1462#define BNX2X_MAC_LOOPBACK 1
1463#define BNX2X_PHY_LOOPBACK_FAILED 1
1464#define BNX2X_MAC_LOOPBACK_FAILED 2
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001465#define BNX2X_LOOPBACK_FAILED (BNX2X_MAC_LOOPBACK_FAILED | \
1466 BNX2X_PHY_LOOPBACK_FAILED)
Eliezer Tamir96fc1782008-02-28 11:57:55 -08001467
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001468
1469#define STROM_ASSERT_ARRAY_SIZE 50
1470
Eliezer Tamir96fc1782008-02-28 11:57:55 -08001471
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001472/* must be used on a CID before placing it on a HW ring */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001473#define HW_CID(bp, x) ((BP_PORT(bp) << 23) | \
1474 (BP_E1HVN(bp) << 17) | (x))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001475
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001476#define SP_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_spe))
1477#define MAX_SP_DESC_CNT (SP_DESC_CNT - 1)
1478
1479
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001480#define BNX2X_BTR 4
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001481#define MAX_SPQ_PENDING 8
1482
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001483
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001484/* CMNG constants
1485 derived from lab experiments, and not from system spec calculations !!! */
1486#define DEF_MIN_RATE 100
1487/* resolution of the rate shaping timer - 100 usec */
1488#define RS_PERIODIC_TIMEOUT_USEC 100
1489/* resolution of fairness algorithm in usecs -
Eilon Greenstein33471622008-08-13 15:59:08 -07001490 coefficient for calculating the actual t fair */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001491#define T_FAIR_COEF 10000000
1492/* number of bytes in single QM arbitration cycle -
Eilon Greenstein33471622008-08-13 15:59:08 -07001493 coefficient for calculating the fairness timer */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001494#define QM_ARB_BYTES 40000
1495#define FAIR_MEM 2
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001496
1497
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001498#define ATTN_NIG_FOR_FUNC (1L << 8)
1499#define ATTN_SW_TIMER_4_FUNC (1L << 9)
1500#define GPIO_2_FUNC (1L << 10)
1501#define GPIO_3_FUNC (1L << 11)
1502#define GPIO_4_FUNC (1L << 12)
1503#define ATTN_GENERAL_ATTN_1 (1L << 13)
1504#define ATTN_GENERAL_ATTN_2 (1L << 14)
1505#define ATTN_GENERAL_ATTN_3 (1L << 15)
1506#define ATTN_GENERAL_ATTN_4 (1L << 13)
1507#define ATTN_GENERAL_ATTN_5 (1L << 14)
1508#define ATTN_GENERAL_ATTN_6 (1L << 15)
1509
1510#define ATTN_HARD_WIRED_MASK 0xff00
1511#define ATTENTION_ID 4
1512
1513
1514/* stuff added to make the code fit 80Col */
1515
1516#define BNX2X_PMF_LINK_ASSERT \
1517 GENERAL_ATTEN_OFFSET(LINK_SYNC_ATTENTION_BIT_FUNC_0 + BP_FUNC(bp))
1518
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001519#define BNX2X_MC_ASSERT_BITS \
1520 (GENERAL_ATTEN_OFFSET(TSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
1521 GENERAL_ATTEN_OFFSET(USTORM_FATAL_ASSERT_ATTENTION_BIT) | \
1522 GENERAL_ATTEN_OFFSET(CSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
1523 GENERAL_ATTEN_OFFSET(XSTORM_FATAL_ASSERT_ATTENTION_BIT))
1524
1525#define BNX2X_MCP_ASSERT \
1526 GENERAL_ATTEN_OFFSET(MCP_FATAL_ASSERT_ATTENTION_BIT)
1527
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001528#define BNX2X_GRC_TIMEOUT GENERAL_ATTEN_OFFSET(LATCHED_ATTN_TIMEOUT_GRC)
1529#define BNX2X_GRC_RSV (GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCR) | \
1530 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCT) | \
1531 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCN) | \
1532 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCU) | \
1533 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCP) | \
1534 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RSVD_GRC))
1535
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001536#define HW_INTERRUT_ASSERT_SET_0 \
1537 (AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT | \
1538 AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT | \
1539 AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT | \
1540 AEU_INPUTS_ATTN_BITS_PBF_HW_INTERRUPT)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001541#define HW_PRTY_ASSERT_SET_0 (AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR | \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001542 AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR | \
1543 AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR | \
1544 AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR |\
1545 AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR)
1546#define HW_INTERRUT_ASSERT_SET_1 \
1547 (AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT | \
1548 AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT | \
1549 AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT | \
1550 AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT | \
1551 AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT | \
1552 AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT | \
1553 AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT | \
1554 AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT | \
1555 AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT | \
1556 AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT | \
1557 AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001558#define HW_PRTY_ASSERT_SET_1 (AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR |\
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001559 AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR | \
1560 AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR | \
1561 AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR | \
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001562 AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR |\
1563 AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR |\
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001564 AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR | \
1565 AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR | \
1566 AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR | \
1567 AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR | \
1568 AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR)
1569#define HW_INTERRUT_ASSERT_SET_2 \
1570 (AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT | \
1571 AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT | \
1572 AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT | \
1573 AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT |\
1574 AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001575#define HW_PRTY_ASSERT_SET_2 (AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR | \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001576 AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR | \
1577 AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR |\
1578 AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR | \
1579 AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR | \
1580 AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR | \
1581 AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR)
1582
Vladislav Zolotarov72fd0712010-04-19 01:13:12 +00001583#define HW_PRTY_ASSERT_SET_3 (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
1584 AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
1585 AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY | \
1586 AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001587
Tom Herbertc68ed252010-04-23 00:10:52 -07001588#define RSS_FLAGS(bp) \
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001589 (TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY | \
1590 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY | \
1591 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY | \
1592 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY | \
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001593 (bp->multi_mode << \
1594 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_MODE_SHIFT))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001595#define MULTI_MASK 0x7f
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001596
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001597#define BNX2X_SP_DSB_INDEX \
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001598 (&bp->def_status_blk->sp_sb.\
1599 index_values[HC_SP_INDEX_ETH_DEF_CONS])
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001600
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001601#define SET_FLAG(value, mask, flag) \
1602 do {\
1603 (value) &= ~(mask);\
1604 (value) |= ((flag) << (mask##_SHIFT));\
1605 } while (0)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001606
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001607#define GET_FLAG(value, mask) \
1608 (((value) &= (mask)) >> (mask##_SHIFT))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001609
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001610#define GET_FIELD(value, fname) \
1611 (((value) & (fname##_MASK)) >> (fname##_SHIFT))
1612
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001613#define CAM_IS_INVALID(x) \
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001614 (GET_FLAG(x.flags, \
1615 MAC_CONFIGURATION_ENTRY_ACTION_TYPE) == \
1616 (T_ETH_MAC_COMMAND_INVALIDATE))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001617
1618#define CAM_INVALIDATE(x) \
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001619 (x.target_table_entry.flags = TSTORM_CAM_TARGET_TABLE_ENTRY_ACTION_TYPE)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001620
1621
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001622/* Number of u32 elements in MC hash array */
1623#define MC_HASH_SIZE 8
1624#define MC_HASH_OFFSET(bp, i) (BAR_TSTRORM_INTMEM + \
1625 TSTORM_APPROXIMATE_MATCH_MULTICAST_FILTERING_OFFSET(BP_FUNC(bp)) + i*4)
1626
1627
1628#ifndef PXP2_REG_PXP2_INT_STS
1629#define PXP2_REG_PXP2_INT_STS PXP2_REG_PXP2_INT_STS_0
1630#endif
1631
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001632#ifndef ETH_MAX_RX_CLIENTS_E2
1633#define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
1634#endif
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001635
Vladislav Zolotarov34f24c72010-04-19 01:13:23 +00001636#define BNX2X_VPD_LEN 128
1637#define VENDOR_ID_LEN 4
1638
Dmitry Kravkov523224a2010-10-06 03:23:26 +00001639/* Congestion management fairness mode */
1640#define CMNG_FNS_NONE 0
1641#define CMNG_FNS_MINMAX 1
1642
1643#define HC_SEG_ACCESS_DEF 0 /*Driver decision 0-3*/
1644#define HC_SEG_ACCESS_ATTN 4
1645#define HC_SEG_ACCESS_NORM 0 /*Driver decision 0-1*/
1646
Dmitry Kravkovb0efbb92010-07-27 12:33:43 +00001647#ifdef BNX2X_MAIN
1648#define BNX2X_EXTERN
1649#else
1650#define BNX2X_EXTERN extern
1651#endif
1652
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001653BNX2X_EXTERN int load_count[2][3]; /* per path: 0-common, 1-port0, 2-port1 */
Dmitry Kravkovb0efbb92010-07-27 12:33:43 +00001654
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001655extern void bnx2x_set_ethtool_ops(struct net_device *netdev);
1656
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001657#endif /* bnx2x.h */