blob: 3c48a7a683086fecf1b5b3eba52e0de89af7d016 [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
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080023#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
24#define BCM_VLAN 1
25#endif
26
Michael Chan993ac7b2009-10-10 13:46:56 +000027#if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
28#define BCM_CNIC 1
29#include "cnic_if.h"
30#endif
Eilon Greenstein0c6671b2009-01-14 21:26:51 -080031
Eilon Greenstein555f6c72009-02-12 08:36:11 +000032#define BNX2X_MULTI_QUEUE
33
34#define BNX2X_NEW_NAPI
35
Eilon Greenstein359d8b12009-02-12 08:38:25 +000036
Eilon Greenstein01cd4522009-08-12 08:23:08 +000037
38#include <linux/mdio.h>
Eilon Greenstein359d8b12009-02-12 08:38:25 +000039#include "bnx2x_reg.h"
40#include "bnx2x_fw_defs.h"
41#include "bnx2x_hsi.h"
42#include "bnx2x_link.h"
43
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020044/* error/debug prints */
45
Eilon Greenstein34f80b02008-06-23 20:33:01 -070046#define DRV_MODULE_NAME "bnx2x"
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020047
48/* for messages that are currently off */
Eilon Greenstein34f80b02008-06-23 20:33:01 -070049#define BNX2X_MSG_OFF 0
50#define BNX2X_MSG_MCP 0x010000 /* was: NETIF_MSG_HW */
51#define BNX2X_MSG_STATS 0x020000 /* was: NETIF_MSG_TIMER */
52#define BNX2X_MSG_NVM 0x040000 /* was: NETIF_MSG_HW */
53#define BNX2X_MSG_DMAE 0x080000 /* was: NETIF_MSG_HW */
Eliezer Tamirf1410642008-02-28 11:51:50 -080054#define BNX2X_MSG_SP 0x100000 /* was: NETIF_MSG_INTR */
55#define BNX2X_MSG_FP 0x200000 /* was: NETIF_MSG_INTR */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020056
Eilon Greenstein34f80b02008-06-23 20:33:01 -070057#define DP_LEVEL KERN_NOTICE /* was: KERN_DEBUG */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020058
59/* regular debug print */
Joe Perches7995c642010-02-17 15:01:52 +000060#define DP(__mask, __fmt, __args...) \
61do { \
62 if (bp->msg_enable & (__mask)) \
63 printk(DP_LEVEL "[%s:%d(%s)]" __fmt, \
64 __func__, __LINE__, \
65 bp->dev ? (bp->dev->name) : "?", \
66 ##__args); \
67} while (0)
Eilon Greenstein34f80b02008-06-23 20:33:01 -070068
69/* errors debug print */
Joe Perches7995c642010-02-17 15:01:52 +000070#define BNX2X_DBG_ERR(__fmt, __args...) \
71do { \
72 if (netif_msg_probe(bp)) \
73 pr_err("[%s:%d(%s)]" __fmt, \
74 __func__, __LINE__, \
75 bp->dev ? (bp->dev->name) : "?", \
76 ##__args); \
77} while (0)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020078
79/* for errors (never masked) */
Joe Perches7995c642010-02-17 15:01:52 +000080#define BNX2X_ERR(__fmt, __args...) \
81do { \
82 pr_err("[%s:%d(%s)]" __fmt, \
83 __func__, __LINE__, \
84 bp->dev ? (bp->dev->name) : "?", \
85 ##__args); \
86} while (0)
Eliezer Tamirf1410642008-02-28 11:51:50 -080087
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020088/* before we have a dev->name use dev_info() */
Joe Perches7995c642010-02-17 15:01:52 +000089#define BNX2X_DEV_INFO(__fmt, __args...) \
90do { \
91 if (netif_msg_probe(bp)) \
92 dev_info(&bp->pdev->dev, __fmt, ##__args); \
93} while (0)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +020094
95
96#ifdef BNX2X_STOP_ON_ERROR
97#define bnx2x_panic() do { \
98 bp->panic = 1; \
99 BNX2X_ERR("driver assert\n"); \
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700100 bnx2x_int_disable(bp); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200101 bnx2x_panic_dump(bp); \
102 } while (0)
103#else
104#define bnx2x_panic() do { \
Eilon Greensteine3553b22009-08-12 08:23:31 +0000105 bp->panic = 1; \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200106 BNX2X_ERR("driver assert\n"); \
107 bnx2x_panic_dump(bp); \
108 } while (0)
109#endif
110
111
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700112#define U64_LO(x) (u32)(((u64)(x)) & 0xffffffff)
113#define U64_HI(x) (u32)(((u64)(x)) >> 32)
114#define HILO_U64(hi, lo) ((((u64)(hi)) << 32) + (lo))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200115
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200116
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700117#define REG_ADDR(bp, offset) (bp->regview + offset)
118
119#define REG_RD(bp, offset) readl(REG_ADDR(bp, offset))
120#define REG_RD8(bp, offset) readb(REG_ADDR(bp, offset))
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700121
122#define REG_WR(bp, offset, val) writel((u32)val, REG_ADDR(bp, offset))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200123#define REG_WR8(bp, offset, val) writeb((u8)val, REG_ADDR(bp, offset))
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700124#define REG_WR16(bp, offset, val) writew((u16)val, REG_ADDR(bp, offset))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200125
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700126#define REG_RD_IND(bp, offset) bnx2x_reg_rd_ind(bp, offset)
127#define REG_WR_IND(bp, offset, val) bnx2x_reg_wr_ind(bp, offset, val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200128
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700129#define REG_RD_DMAE(bp, offset, valp, len32) \
130 do { \
131 bnx2x_read_dmae(bp, offset, len32);\
Eilon Greenstein573f2032009-08-12 08:24:14 +0000132 memcpy(valp, bnx2x_sp(bp, wb_data[0]), (len32) * 4); \
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700133 } while (0)
134
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700135#define REG_WR_DMAE(bp, offset, valp, len32) \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200136 do { \
Eilon Greenstein573f2032009-08-12 08:24:14 +0000137 memcpy(bnx2x_sp(bp, wb_data[0]), valp, (len32) * 4); \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200138 bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), \
139 offset, len32); \
140 } while (0)
141
Vladislav Zolotarov3359fce2010-02-17 13:35:01 -0800142#define VIRT_WR_DMAE_LEN(bp, data, addr, len32, le32_swap) \
Eilon Greenstein573f2032009-08-12 08:24:14 +0000143 do { \
144 memcpy(GUNZIP_BUF(bp), data, (len32) * 4); \
145 bnx2x_write_big_buf_wb(bp, addr, len32); \
146 } while (0)
147
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700148#define SHMEM_ADDR(bp, field) (bp->common.shmem_base + \
149 offsetof(struct shmem_region, field))
150#define SHMEM_RD(bp, field) REG_RD(bp, SHMEM_ADDR(bp, field))
151#define SHMEM_WR(bp, field, val) REG_WR(bp, SHMEM_ADDR(bp, field), val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200152
Eilon Greenstein2691d512009-08-12 08:22:08 +0000153#define SHMEM2_ADDR(bp, field) (bp->common.shmem2_base + \
154 offsetof(struct shmem2_region, field))
155#define SHMEM2_RD(bp, field) REG_RD(bp, SHMEM2_ADDR(bp, field))
156#define SHMEM2_WR(bp, field, val) REG_WR(bp, SHMEM2_ADDR(bp, field), val)
157
Eilon Greenstein345b5d52008-08-13 15:58:12 -0700158#define EMAC_RD(bp, reg) REG_RD(bp, emac_base + reg)
Eilon Greenstein3196a882008-08-13 15:58:49 -0700159#define EMAC_WR(bp, reg, val) REG_WR(bp, emac_base + reg, val)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200160
161
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700162/* fast path */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200163
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200164struct sw_rx_bd {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700165 struct sk_buff *skb;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200166 DECLARE_PCI_UNMAP_ADDR(mapping)
167};
168
169struct sw_tx_bd {
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700170 struct sk_buff *skb;
171 u16 first_bd;
Eilon Greensteinca003922009-08-12 22:53:28 -0700172 u8 flags;
173/* Set on the first BD descriptor when there is a split BD */
174#define BNX2X_TSO_SPLIT_BD (1<<0)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200175};
176
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700177struct sw_rx_page {
178 struct page *page;
179 DECLARE_PCI_UNMAP_ADDR(mapping)
180};
181
Eilon Greensteinca003922009-08-12 22:53:28 -0700182union db_prod {
183 struct doorbell_set_prod data;
184 u32 raw;
185};
186
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700187
188/* MC hsi */
189#define BCM_PAGE_SHIFT 12
190#define BCM_PAGE_SIZE (1 << BCM_PAGE_SHIFT)
191#define BCM_PAGE_MASK (~(BCM_PAGE_SIZE - 1))
192#define BCM_PAGE_ALIGN(addr) (((addr) + BCM_PAGE_SIZE - 1) & BCM_PAGE_MASK)
193
194#define PAGES_PER_SGE_SHIFT 0
195#define PAGES_PER_SGE (1 << PAGES_PER_SGE_SHIFT)
Eilon Greenstein4f40f2c2009-01-14 21:24:17 -0800196#define SGE_PAGE_SIZE PAGE_SIZE
197#define SGE_PAGE_SHIFT PAGE_SHIFT
Eilon Greenstein5b6402d2009-07-21 05:47:51 +0000198#define SGE_PAGE_ALIGN(addr) PAGE_ALIGN((typeof(PAGE_SIZE))(addr))
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700199
200/* SGE ring related macros */
201#define NUM_RX_SGE_PAGES 2
202#define RX_SGE_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_sge))
203#define MAX_RX_SGE_CNT (RX_SGE_CNT - 2)
Eilon Greenstein33471622008-08-13 15:59:08 -0700204/* RX_SGE_CNT is promised to be a power of 2 */
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700205#define RX_SGE_MASK (RX_SGE_CNT - 1)
206#define NUM_RX_SGE (RX_SGE_CNT * NUM_RX_SGE_PAGES)
207#define MAX_RX_SGE (NUM_RX_SGE - 1)
208#define NEXT_SGE_IDX(x) ((((x) & RX_SGE_MASK) == \
209 (MAX_RX_SGE_CNT - 1)) ? (x) + 3 : (x) + 1)
210#define RX_SGE(x) ((x) & MAX_RX_SGE)
211
212/* SGE producer mask related macros */
213/* Number of bits in one sge_mask array element */
214#define RX_SGE_MASK_ELEM_SZ 64
215#define RX_SGE_MASK_ELEM_SHIFT 6
216#define RX_SGE_MASK_ELEM_MASK ((u64)RX_SGE_MASK_ELEM_SZ - 1)
217
218/* Creates a bitmask of all ones in less significant bits.
219 idx - index of the most significant bit in the created mask */
220#define RX_SGE_ONES_MASK(idx) \
221 (((u64)0x1 << (((idx) & RX_SGE_MASK_ELEM_MASK) + 1)) - 1)
222#define RX_SGE_MASK_ELEM_ONE_MASK ((u64)(~0))
223
224/* Number of u64 elements in SGE mask array */
225#define RX_SGE_MASK_LEN ((NUM_RX_SGE_PAGES * RX_SGE_CNT) / \
226 RX_SGE_MASK_ELEM_SZ)
227#define RX_SGE_MASK_LEN_MASK (RX_SGE_MASK_LEN - 1)
228#define NEXT_SGE_MASK_ELEM(el) (((el) + 1) & RX_SGE_MASK_LEN_MASK)
229
230
Eilon Greensteinde832a52009-02-12 08:36:33 +0000231struct bnx2x_eth_q_stats {
232 u32 total_bytes_received_hi;
233 u32 total_bytes_received_lo;
234 u32 total_bytes_transmitted_hi;
235 u32 total_bytes_transmitted_lo;
236 u32 total_unicast_packets_received_hi;
237 u32 total_unicast_packets_received_lo;
238 u32 total_multicast_packets_received_hi;
239 u32 total_multicast_packets_received_lo;
240 u32 total_broadcast_packets_received_hi;
241 u32 total_broadcast_packets_received_lo;
242 u32 total_unicast_packets_transmitted_hi;
243 u32 total_unicast_packets_transmitted_lo;
244 u32 total_multicast_packets_transmitted_hi;
245 u32 total_multicast_packets_transmitted_lo;
246 u32 total_broadcast_packets_transmitted_hi;
247 u32 total_broadcast_packets_transmitted_lo;
248 u32 valid_bytes_received_hi;
249 u32 valid_bytes_received_lo;
250
251 u32 error_bytes_received_hi;
252 u32 error_bytes_received_lo;
253 u32 etherstatsoverrsizepkts_hi;
254 u32 etherstatsoverrsizepkts_lo;
255 u32 no_buff_discard_hi;
256 u32 no_buff_discard_lo;
257
258 u32 driver_xoff;
259 u32 rx_err_discard_pkt;
260 u32 rx_skb_alloc_failed;
261 u32 hw_csum_err;
262};
263
264#define BNX2X_NUM_Q_STATS 11
265#define Q_STATS_OFFSET32(stat_name) \
266 (offsetof(struct bnx2x_eth_q_stats, stat_name) / 4)
267
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200268struct bnx2x_fastpath {
269
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700270 struct napi_struct napi;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200271 struct host_status_block *status_blk;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700272 dma_addr_t status_blk_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200273
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700274 struct sw_tx_bd *tx_buf_ring;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200275
Eilon Greensteinca003922009-08-12 22:53:28 -0700276 union eth_tx_bd_types *tx_desc_ring;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700277 dma_addr_t tx_desc_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200278
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700279 struct sw_rx_bd *rx_buf_ring; /* BDs mappings ring */
280 struct sw_rx_page *rx_page_ring; /* SGE pages mappings ring */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200281
282 struct eth_rx_bd *rx_desc_ring;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700283 dma_addr_t rx_desc_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200284
285 union eth_rx_cqe *rx_comp_ring;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700286 dma_addr_t rx_comp_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200287
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700288 /* SGE ring */
289 struct eth_rx_sge *rx_sge_ring;
290 dma_addr_t rx_sge_mapping;
291
292 u64 sge_mask[RX_SGE_MASK_LEN];
293
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700294 int state;
295#define BNX2X_FP_STATE_CLOSED 0
296#define BNX2X_FP_STATE_IRQ 0x80000
297#define BNX2X_FP_STATE_OPENING 0x90000
298#define BNX2X_FP_STATE_OPEN 0xa0000
299#define BNX2X_FP_STATE_HALTING 0xb0000
300#define BNX2X_FP_STATE_HALTED 0xc0000
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200301
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700302 u8 index; /* number in fp array */
303 u8 cl_id; /* eth client id */
304 u8 sb_id; /* status block number in HW */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200305
Eilon Greensteinca003922009-08-12 22:53:28 -0700306 union db_prod tx_db;
307
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700308 u16 tx_pkt_prod;
309 u16 tx_pkt_cons;
310 u16 tx_bd_prod;
311 u16 tx_bd_cons;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000312 __le16 *tx_cons_sb;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200313
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000314 __le16 fp_c_idx;
315 __le16 fp_u_idx;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200316
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700317 u16 rx_bd_prod;
318 u16 rx_bd_cons;
319 u16 rx_comp_prod;
320 u16 rx_comp_cons;
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700321 u16 rx_sge_prod;
322 /* The last maximal completed SGE */
323 u16 last_max_sge;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000324 __le16 *rx_cons_sb;
325 __le16 *rx_bd_cons_sb;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200326
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +0000327
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700328 unsigned long tx_pkt,
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200329 rx_pkt,
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700330 rx_calls;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +0000331
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700332 /* TPA related */
333 struct sw_rx_bd tpa_pool[ETH_MAX_AGGREGATION_QUEUES_E1H];
334 u8 tpa_state[ETH_MAX_AGGREGATION_QUEUES_E1H];
335#define BNX2X_TPA_START 1
336#define BNX2X_TPA_STOP 2
337 u8 disable_tpa;
338#ifdef BNX2X_STOP_ON_ERROR
339 u64 tpa_queue_used;
340#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200341
Eilon Greensteinde832a52009-02-12 08:36:33 +0000342 struct tstorm_per_client_stats old_tclient;
343 struct ustorm_per_client_stats old_uclient;
344 struct xstorm_per_client_stats old_xclient;
345 struct bnx2x_eth_q_stats eth_q_stats;
346
Eilon Greensteinca003922009-08-12 22:53:28 -0700347 /* The size is calculated using the following:
348 sizeof name field from netdev structure +
349 4 ('-Xx-' string) +
350 4 (for the digits and to make it DWORD aligned) */
351#define FP_NAME_SIZE (sizeof(((struct net_device *)0)->name) + 8)
352 char name[FP_NAME_SIZE];
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700353 struct bnx2x *bp; /* parent */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200354};
355
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700356#define bnx2x_fp(bp, nr, var) (bp->fp[nr].var)
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700357
358
359/* MC hsi */
360#define MAX_FETCH_BD 13 /* HW max BDs per packet */
361#define RX_COPY_THRESH 92
362
363#define NUM_TX_RINGS 16
Eilon Greensteinca003922009-08-12 22:53:28 -0700364#define TX_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_tx_bd_types))
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700365#define MAX_TX_DESC_CNT (TX_DESC_CNT - 1)
366#define NUM_TX_BD (TX_DESC_CNT * NUM_TX_RINGS)
367#define MAX_TX_BD (NUM_TX_BD - 1)
368#define MAX_TX_AVAIL (MAX_TX_DESC_CNT * NUM_TX_RINGS - 2)
369#define NEXT_TX_IDX(x) ((((x) & MAX_TX_DESC_CNT) == \
370 (MAX_TX_DESC_CNT - 1)) ? (x) + 2 : (x) + 1)
371#define TX_BD(x) ((x) & MAX_TX_BD)
372#define TX_BD_POFF(x) ((x) & MAX_TX_DESC_CNT)
373
374/* The RX BD ring is special, each bd is 8 bytes but the last one is 16 */
375#define NUM_RX_RINGS 8
376#define RX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_bd))
377#define MAX_RX_DESC_CNT (RX_DESC_CNT - 2)
378#define RX_DESC_MASK (RX_DESC_CNT - 1)
379#define NUM_RX_BD (RX_DESC_CNT * NUM_RX_RINGS)
380#define MAX_RX_BD (NUM_RX_BD - 1)
381#define MAX_RX_AVAIL (MAX_RX_DESC_CNT * NUM_RX_RINGS - 2)
382#define NEXT_RX_IDX(x) ((((x) & RX_DESC_MASK) == \
383 (MAX_RX_DESC_CNT - 1)) ? (x) + 3 : (x) + 1)
384#define RX_BD(x) ((x) & MAX_RX_BD)
385
386/* As long as CQE is 4 times bigger than BD entry we have to allocate
387 4 times more pages for CQ ring in order to keep it balanced with
388 BD ring */
389#define NUM_RCQ_RINGS (NUM_RX_RINGS * 4)
390#define RCQ_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_rx_cqe))
391#define MAX_RCQ_DESC_CNT (RCQ_DESC_CNT - 1)
392#define NUM_RCQ_BD (RCQ_DESC_CNT * NUM_RCQ_RINGS)
393#define MAX_RCQ_BD (NUM_RCQ_BD - 1)
394#define MAX_RCQ_AVAIL (MAX_RCQ_DESC_CNT * NUM_RCQ_RINGS - 2)
395#define NEXT_RCQ_IDX(x) ((((x) & MAX_RCQ_DESC_CNT) == \
396 (MAX_RCQ_DESC_CNT - 1)) ? (x) + 2 : (x) + 1)
397#define RCQ_BD(x) ((x) & MAX_RCQ_BD)
398
399
Eilon Greenstein33471622008-08-13 15:59:08 -0700400/* This is needed for determining of last_max */
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700401#define SUB_S16(a, b) (s16)((s16)(a) - (s16)(b))
402
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700403#define __SGE_MASK_SET_BIT(el, bit) \
404 do { \
405 el = ((el) | ((u64)0x1 << (bit))); \
406 } while (0)
407
408#define __SGE_MASK_CLEAR_BIT(el, bit) \
409 do { \
410 el = ((el) & (~((u64)0x1 << (bit)))); \
411 } while (0)
412
413#define SGE_MASK_SET_BIT(fp, idx) \
414 __SGE_MASK_SET_BIT(fp->sge_mask[(idx) >> RX_SGE_MASK_ELEM_SHIFT], \
415 ((idx) & RX_SGE_MASK_ELEM_MASK))
416
417#define SGE_MASK_CLEAR_BIT(fp, idx) \
418 __SGE_MASK_CLEAR_BIT(fp->sge_mask[(idx) >> RX_SGE_MASK_ELEM_SHIFT], \
419 ((idx) & RX_SGE_MASK_ELEM_MASK))
420
421
422/* used on a CID received from the HW */
423#define SW_CID(x) (le32_to_cpu(x) & \
424 (COMMON_RAMROD_ETH_RX_CQE_CID >> 7))
425#define CQE_CMD(x) (le32_to_cpu(x) >> \
426 COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT)
427
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700428#define BD_UNMAP_ADDR(bd) HILO_U64(le32_to_cpu((bd)->addr_hi), \
429 le32_to_cpu((bd)->addr_lo))
430#define BD_UNMAP_LEN(bd) (le16_to_cpu((bd)->nbytes))
431
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700432
433#define DPM_TRIGER_TYPE 0x40
434#define DOORBELL(bp, cid, val) \
435 do { \
Eilon Greensteinca003922009-08-12 22:53:28 -0700436 writel((u32)(val), bp->doorbells + (BCM_PAGE_SIZE * (cid)) + \
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700437 DPM_TRIGER_TYPE); \
438 } while (0)
439
440
441/* TX CSUM helpers */
442#define SKB_CS_OFF(skb) (offsetof(struct tcphdr, check) - \
443 skb->csum_offset)
444#define SKB_CS(skb) (*(u16 *)(skb_transport_header(skb) + \
445 skb->csum_offset))
446
447#define pbd_tcp_flags(skb) (ntohl(tcp_flag_word(tcp_hdr(skb)))>>16 & 0xff)
448
449#define XMIT_PLAIN 0
450#define XMIT_CSUM_V4 0x1
451#define XMIT_CSUM_V6 0x2
452#define XMIT_CSUM_TCP 0x4
453#define XMIT_GSO_V4 0x8
454#define XMIT_GSO_V6 0x10
455
456#define XMIT_CSUM (XMIT_CSUM_V4 | XMIT_CSUM_V6)
457#define XMIT_GSO (XMIT_GSO_V4 | XMIT_GSO_V6)
458
459
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700460/* stuff added to make the code fit 80Col */
461
462#define CQE_TYPE(cqe_fp_flags) ((cqe_fp_flags) & ETH_FAST_PATH_RX_CQE_TYPE)
463
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700464#define TPA_TYPE_START ETH_FAST_PATH_RX_CQE_START_FLG
465#define TPA_TYPE_END ETH_FAST_PATH_RX_CQE_END_FLG
466#define TPA_TYPE(cqe_fp_flags) ((cqe_fp_flags) & \
467 (TPA_TYPE_START | TPA_TYPE_END))
468
Eilon Greenstein1adcd8b2008-08-13 15:48:29 -0700469#define ETH_RX_ERROR_FALGS ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG
470
471#define BNX2X_IP_CSUM_ERR(cqe) \
472 (!((cqe)->fast_path_cqe.status_flags & \
473 ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG) && \
474 ((cqe)->fast_path_cqe.type_error_flags & \
475 ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG))
476
477#define BNX2X_L4_CSUM_ERR(cqe) \
478 (!((cqe)->fast_path_cqe.status_flags & \
479 ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG) && \
480 ((cqe)->fast_path_cqe.type_error_flags & \
481 ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG))
482
483#define BNX2X_RX_CSUM_OK(cqe) \
484 (!(BNX2X_L4_CSUM_ERR(cqe) || BNX2X_IP_CSUM_ERR(cqe)))
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700485
Eilon Greenstein052a38e2009-02-12 08:37:16 +0000486#define BNX2X_PRS_FLAG_OVERETH_IPV4(flags) \
487 (((le16_to_cpu(flags) & \
488 PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) >> \
489 PARSING_FLAGS_OVER_ETHERNET_PROTOCOL_SHIFT) \
490 == PRS_FLAG_OVERETH_IPV4)
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700491#define BNX2X_RX_SUM_FIX(cqe) \
Eilon Greenstein052a38e2009-02-12 08:37:16 +0000492 BNX2X_PRS_FLAG_OVERETH_IPV4(cqe->fast_path_cqe.pars_flags.flags)
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700493
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200494
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700495#define FP_USB_FUNC_OFF (2 + 2*HC_USTORM_SB_NUM_INDICES)
496#define FP_CSB_FUNC_OFF (2 + 2*HC_CSTORM_SB_NUM_INDICES)
497
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700498#define U_SB_ETH_RX_CQ_INDEX HC_INDEX_U_ETH_RX_CQ_CONS
499#define U_SB_ETH_RX_BD_INDEX HC_INDEX_U_ETH_RX_BD_CONS
500#define C_SB_ETH_TX_CQ_INDEX HC_INDEX_C_ETH_TX_CQ_CONS
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200501
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700502#define BNX2X_RX_SB_INDEX \
503 (&fp->status_blk->u_status_block.index_values[U_SB_ETH_RX_CQ_INDEX])
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200504
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700505#define BNX2X_RX_SB_BD_INDEX \
506 (&fp->status_blk->u_status_block.index_values[U_SB_ETH_RX_BD_INDEX])
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200507
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700508#define BNX2X_RX_SB_INDEX_NUM \
509 (((U_SB_ETH_RX_CQ_INDEX << \
510 USTORM_ETH_ST_CONTEXT_CONFIG_CQE_SB_INDEX_NUMBER_SHIFT) & \
511 USTORM_ETH_ST_CONTEXT_CONFIG_CQE_SB_INDEX_NUMBER) | \
512 ((U_SB_ETH_RX_BD_INDEX << \
513 USTORM_ETH_ST_CONTEXT_CONFIG_BD_SB_INDEX_NUMBER_SHIFT) & \
514 USTORM_ETH_ST_CONTEXT_CONFIG_BD_SB_INDEX_NUMBER))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200515
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700516#define BNX2X_TX_SB_INDEX \
517 (&fp->status_blk->c_status_block.index_values[C_SB_ETH_TX_CQ_INDEX])
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200518
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700519
520/* end of fast path */
521
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700522/* common */
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200523
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700524struct bnx2x_common {
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200525
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700526 u32 chip_id;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200527/* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700528#define CHIP_ID(bp) (bp->common.chip_id & 0xfffffff0)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200529
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700530#define CHIP_NUM(bp) (bp->common.chip_id >> 16)
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700531#define CHIP_NUM_57710 0x164e
532#define CHIP_NUM_57711 0x164f
533#define CHIP_NUM_57711E 0x1650
534#define CHIP_IS_E1(bp) (CHIP_NUM(bp) == CHIP_NUM_57710)
535#define CHIP_IS_57711(bp) (CHIP_NUM(bp) == CHIP_NUM_57711)
536#define CHIP_IS_57711E(bp) (CHIP_NUM(bp) == CHIP_NUM_57711E)
537#define CHIP_IS_E1H(bp) (CHIP_IS_57711(bp) || \
538 CHIP_IS_57711E(bp))
539#define IS_E1H_OFFSET CHIP_IS_E1H(bp)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200540
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700541#define CHIP_REV(bp) (bp->common.chip_id & 0x0000f000)
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700542#define CHIP_REV_Ax 0x00000000
543/* assume maximum 5 revisions */
544#define CHIP_REV_IS_SLOW(bp) (CHIP_REV(bp) > 0x00005000)
545/* Emul versions are A=>0xe, B=>0xc, C=>0xa, D=>8, E=>6 */
546#define CHIP_REV_IS_EMUL(bp) ((CHIP_REV_IS_SLOW(bp)) && \
547 !(CHIP_REV(bp) & 0x00001000))
548/* FPGA versions are A=>0xf, B=>0xd, C=>0xb, D=>9, E=>7 */
549#define CHIP_REV_IS_FPGA(bp) ((CHIP_REV_IS_SLOW(bp)) && \
550 (CHIP_REV(bp) & 0x00001000))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200551
Eilon Greensteinad8d3942008-06-23 20:29:02 -0700552#define CHIP_TIME(bp) ((CHIP_REV_IS_EMUL(bp)) ? 2000 : \
553 ((CHIP_REV_IS_FPGA(bp)) ? 200 : 1))
554
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700555#define CHIP_METAL(bp) (bp->common.chip_id & 0x00000ff0)
556#define CHIP_BOND_ID(bp) (bp->common.chip_id & 0x0000000f)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200557
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700558 int flash_size;
559#define NVRAM_1MB_SIZE 0x20000 /* 1M bit in bytes */
560#define NVRAM_TIMEOUT_COUNT 30000
561#define NVRAM_PAGE_SIZE 256
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200562
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700563 u32 shmem_base;
Eilon Greenstein2691d512009-08-12 08:22:08 +0000564 u32 shmem2_base;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700565
566 u32 hw_config;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200567
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700568 u32 bc_ver;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700569};
570
571
572/* end of common */
573
574/* port */
575
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700576struct nig_stats {
577 u32 brb_discard;
578 u32 brb_packet;
579 u32 brb_truncate;
580 u32 flow_ctrl_discard;
581 u32 flow_ctrl_octets;
582 u32 flow_ctrl_packet;
583 u32 mng_discard;
584 u32 mng_octet_inp;
585 u32 mng_octet_out;
586 u32 mng_packet_inp;
587 u32 mng_packet_out;
588 u32 pbf_octets;
589 u32 pbf_packet;
590 u32 safc_inp;
591 u32 egress_mac_pkt0_lo;
592 u32 egress_mac_pkt0_hi;
593 u32 egress_mac_pkt1_lo;
594 u32 egress_mac_pkt1_hi;
595};
596
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700597struct bnx2x_port {
598 u32 pmf;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200599
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700600 u32 link_config;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200601
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700602 u32 supported;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200603/* link settings - missing defines */
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700604#define SUPPORTED_2500baseX_Full (1 << 15)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200605
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700606 u32 advertising;
607/* link settings - missing defines */
608#define ADVERTISED_2500baseX_Full (1 << 15)
609
610 u32 phy_addr;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700611
612 /* used to synchronize phy accesses */
613 struct mutex phy_mutex;
Eilon Greenstein46c6a672009-02-12 08:36:58 +0000614 int need_hw_lock;
Yaniv Rosnerc18487e2008-06-23 20:27:52 -0700615
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700616 u32 port_stx;
617
618 struct nig_stats old_nig_stats;
619};
620
621/* end of port */
622
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700623
624enum bnx2x_stats_event {
625 STATS_EVENT_PMF = 0,
626 STATS_EVENT_LINK_UP,
627 STATS_EVENT_UPDATE,
628 STATS_EVENT_STOP,
629 STATS_EVENT_MAX
630};
631
632enum bnx2x_stats_state {
633 STATS_STATE_DISABLED = 0,
634 STATS_STATE_ENABLED,
635 STATS_STATE_MAX
636};
637
638struct bnx2x_eth_stats {
639 u32 total_bytes_received_hi;
640 u32 total_bytes_received_lo;
641 u32 total_bytes_transmitted_hi;
642 u32 total_bytes_transmitted_lo;
643 u32 total_unicast_packets_received_hi;
644 u32 total_unicast_packets_received_lo;
645 u32 total_multicast_packets_received_hi;
646 u32 total_multicast_packets_received_lo;
647 u32 total_broadcast_packets_received_hi;
648 u32 total_broadcast_packets_received_lo;
649 u32 total_unicast_packets_transmitted_hi;
650 u32 total_unicast_packets_transmitted_lo;
651 u32 total_multicast_packets_transmitted_hi;
652 u32 total_multicast_packets_transmitted_lo;
653 u32 total_broadcast_packets_transmitted_hi;
654 u32 total_broadcast_packets_transmitted_lo;
655 u32 valid_bytes_received_hi;
656 u32 valid_bytes_received_lo;
657
658 u32 error_bytes_received_hi;
659 u32 error_bytes_received_lo;
Eilon Greensteinde832a52009-02-12 08:36:33 +0000660 u32 etherstatsoverrsizepkts_hi;
661 u32 etherstatsoverrsizepkts_lo;
662 u32 no_buff_discard_hi;
663 u32 no_buff_discard_lo;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700664
665 u32 rx_stat_ifhcinbadoctets_hi;
666 u32 rx_stat_ifhcinbadoctets_lo;
667 u32 tx_stat_ifhcoutbadoctets_hi;
668 u32 tx_stat_ifhcoutbadoctets_lo;
669 u32 rx_stat_dot3statsfcserrors_hi;
670 u32 rx_stat_dot3statsfcserrors_lo;
671 u32 rx_stat_dot3statsalignmenterrors_hi;
672 u32 rx_stat_dot3statsalignmenterrors_lo;
673 u32 rx_stat_dot3statscarriersenseerrors_hi;
674 u32 rx_stat_dot3statscarriersenseerrors_lo;
675 u32 rx_stat_falsecarriererrors_hi;
676 u32 rx_stat_falsecarriererrors_lo;
677 u32 rx_stat_etherstatsundersizepkts_hi;
678 u32 rx_stat_etherstatsundersizepkts_lo;
679 u32 rx_stat_dot3statsframestoolong_hi;
680 u32 rx_stat_dot3statsframestoolong_lo;
681 u32 rx_stat_etherstatsfragments_hi;
682 u32 rx_stat_etherstatsfragments_lo;
683 u32 rx_stat_etherstatsjabbers_hi;
684 u32 rx_stat_etherstatsjabbers_lo;
685 u32 rx_stat_maccontrolframesreceived_hi;
686 u32 rx_stat_maccontrolframesreceived_lo;
687 u32 rx_stat_bmac_xpf_hi;
688 u32 rx_stat_bmac_xpf_lo;
689 u32 rx_stat_bmac_xcf_hi;
690 u32 rx_stat_bmac_xcf_lo;
691 u32 rx_stat_xoffstateentered_hi;
692 u32 rx_stat_xoffstateentered_lo;
693 u32 rx_stat_xonpauseframesreceived_hi;
694 u32 rx_stat_xonpauseframesreceived_lo;
695 u32 rx_stat_xoffpauseframesreceived_hi;
696 u32 rx_stat_xoffpauseframesreceived_lo;
697 u32 tx_stat_outxonsent_hi;
698 u32 tx_stat_outxonsent_lo;
699 u32 tx_stat_outxoffsent_hi;
700 u32 tx_stat_outxoffsent_lo;
701 u32 tx_stat_flowcontroldone_hi;
702 u32 tx_stat_flowcontroldone_lo;
703 u32 tx_stat_etherstatscollisions_hi;
704 u32 tx_stat_etherstatscollisions_lo;
705 u32 tx_stat_dot3statssinglecollisionframes_hi;
706 u32 tx_stat_dot3statssinglecollisionframes_lo;
707 u32 tx_stat_dot3statsmultiplecollisionframes_hi;
708 u32 tx_stat_dot3statsmultiplecollisionframes_lo;
709 u32 tx_stat_dot3statsdeferredtransmissions_hi;
710 u32 tx_stat_dot3statsdeferredtransmissions_lo;
711 u32 tx_stat_dot3statsexcessivecollisions_hi;
712 u32 tx_stat_dot3statsexcessivecollisions_lo;
713 u32 tx_stat_dot3statslatecollisions_hi;
714 u32 tx_stat_dot3statslatecollisions_lo;
715 u32 tx_stat_etherstatspkts64octets_hi;
716 u32 tx_stat_etherstatspkts64octets_lo;
717 u32 tx_stat_etherstatspkts65octetsto127octets_hi;
718 u32 tx_stat_etherstatspkts65octetsto127octets_lo;
719 u32 tx_stat_etherstatspkts128octetsto255octets_hi;
720 u32 tx_stat_etherstatspkts128octetsto255octets_lo;
721 u32 tx_stat_etherstatspkts256octetsto511octets_hi;
722 u32 tx_stat_etherstatspkts256octetsto511octets_lo;
723 u32 tx_stat_etherstatspkts512octetsto1023octets_hi;
724 u32 tx_stat_etherstatspkts512octetsto1023octets_lo;
725 u32 tx_stat_etherstatspkts1024octetsto1522octets_hi;
726 u32 tx_stat_etherstatspkts1024octetsto1522octets_lo;
727 u32 tx_stat_etherstatspktsover1522octets_hi;
728 u32 tx_stat_etherstatspktsover1522octets_lo;
729 u32 tx_stat_bmac_2047_hi;
730 u32 tx_stat_bmac_2047_lo;
731 u32 tx_stat_bmac_4095_hi;
732 u32 tx_stat_bmac_4095_lo;
733 u32 tx_stat_bmac_9216_hi;
734 u32 tx_stat_bmac_9216_lo;
735 u32 tx_stat_bmac_16383_hi;
736 u32 tx_stat_bmac_16383_lo;
737 u32 tx_stat_dot3statsinternalmactransmiterrors_hi;
738 u32 tx_stat_dot3statsinternalmactransmiterrors_lo;
739 u32 tx_stat_bmac_ufl_hi;
740 u32 tx_stat_bmac_ufl_lo;
741
Eilon Greensteinde832a52009-02-12 08:36:33 +0000742 u32 pause_frames_received_hi;
743 u32 pause_frames_received_lo;
744 u32 pause_frames_sent_hi;
745 u32 pause_frames_sent_lo;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700746
747 u32 etherstatspkts1024octetsto1522octets_hi;
748 u32 etherstatspkts1024octetsto1522octets_lo;
749 u32 etherstatspktsover1522octets_hi;
750 u32 etherstatspktsover1522octets_lo;
751
Eilon Greensteinde832a52009-02-12 08:36:33 +0000752 u32 brb_drop_hi;
753 u32 brb_drop_lo;
754 u32 brb_truncate_hi;
755 u32 brb_truncate_lo;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700756
757 u32 mac_filter_discard;
758 u32 xxoverflow_discard;
759 u32 brb_truncate_discard;
760 u32 mac_discard;
761
762 u32 driver_xoff;
Yitchak Gertner66e855f2008-08-13 15:49:05 -0700763 u32 rx_err_discard_pkt;
764 u32 rx_skb_alloc_failed;
765 u32 hw_csum_err;
Eilon Greensteinde832a52009-02-12 08:36:33 +0000766
767 u32 nig_timer_max;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700768};
769
Eilon Greensteinde832a52009-02-12 08:36:33 +0000770#define BNX2X_NUM_STATS 41
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700771#define STATS_OFFSET32(stat_name) \
772 (offsetof(struct bnx2x_eth_stats, stat_name) / 4)
773
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700774
Michael Chan37b091b2009-10-10 13:46:55 +0000775#ifdef BCM_CNIC
776#define MAX_CONTEXT 15
777#else
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700778#define MAX_CONTEXT 16
Michael Chan37b091b2009-10-10 13:46:55 +0000779#endif
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700780
781union cdu_context {
782 struct eth_context eth;
783 char pad[1024];
784};
785
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700786#define MAX_DMAE_C 8
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700787
788/* DMA memory not used in fastpath */
789struct bnx2x_slowpath {
790 union cdu_context context[MAX_CONTEXT];
791 struct eth_stats_query fw_stats;
792 struct mac_configuration_cmd mac_config;
793 struct mac_configuration_cmd mcast_config;
794
795 /* used by dmae command executer */
796 struct dmae_command dmae[MAX_DMAE_C];
797
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700798 u32 stats_comp;
799 union mac_stats mac_stats;
800 struct nig_stats nig_stats;
801 struct host_port_stats port_stats;
802 struct host_func_stats func_stats;
Eilon Greenstein6fe49bb2009-08-12 08:23:17 +0000803 struct host_func_stats func_stats_base;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700804
805 u32 wb_comp;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700806 u32 wb_data[4];
807};
808
809#define bnx2x_sp(bp, var) (&bp->slowpath->var)
810#define bnx2x_sp_mapping(bp, var) \
811 (bp->slowpath_mapping + offsetof(struct bnx2x_slowpath, var))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200812
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200813
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700814/* attn group wiring */
815#define MAX_DYNAMIC_ATTN_GRPS 8
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200816
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700817struct attn_route {
818 u32 sig[4];
819};
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200820
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700821struct bnx2x {
822 /* Fields used in the tx and intr/napi performance paths
823 * are grouped together in the beginning of the structure
824 */
825 struct bnx2x_fastpath fp[MAX_CONTEXT];
826 void __iomem *regview;
827 void __iomem *doorbells;
Michael Chan37b091b2009-10-10 13:46:55 +0000828#ifdef BCM_CNIC
829#define BNX2X_DB_SIZE (18*BCM_PAGE_SIZE)
830#else
Eilon Greensteina5f67a042009-01-14 21:28:13 -0800831#define BNX2X_DB_SIZE (16*BCM_PAGE_SIZE)
Michael Chan37b091b2009-10-10 13:46:55 +0000832#endif
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200833
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700834 struct net_device *dev;
835 struct pci_dev *pdev;
836
837 atomic_t intr_sem;
Michael Chan37b091b2009-10-10 13:46:55 +0000838#ifdef BCM_CNIC
839 struct msix_entry msix_table[MAX_CONTEXT+2];
840#else
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700841 struct msix_entry msix_table[MAX_CONTEXT+1];
Michael Chan37b091b2009-10-10 13:46:55 +0000842#endif
Eilon Greenstein8badd272009-02-12 08:36:15 +0000843#define INT_MODE_INTx 1
844#define INT_MODE_MSI 2
845#define INT_MODE_MSIX 3
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700846
847 int tx_ring_size;
848
849#ifdef BCM_VLAN
850 struct vlan_group *vlgrp;
851#endif
852
853 u32 rx_csum;
Eilon Greenstein437cf2f2008-09-03 14:38:00 -0700854 u32 rx_buf_size;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700855#define ETH_OVREHEAD (ETH_HLEN + 8) /* 8 for CRC + VLAN */
856#define ETH_MIN_PACKET_SIZE 60
857#define ETH_MAX_PACKET_SIZE 1500
858#define ETH_MAX_JUMBO_PACKET_SIZE 9600
859
Eilon Greenstein0f008462009-02-12 08:36:18 +0000860 /* Max supported alignment is 256 (8 shift) */
861#define BNX2X_RX_ALIGN_SHIFT ((L1_CACHE_SHIFT < 8) ? \
862 L1_CACHE_SHIFT : 8)
863#define BNX2X_RX_ALIGN (1 << BNX2X_RX_ALIGN_SHIFT)
864
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700865 struct host_def_status_block *def_status_blk;
866#define DEF_SB_ID 16
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000867 __le16 def_c_idx;
868 __le16 def_u_idx;
869 __le16 def_x_idx;
870 __le16 def_t_idx;
871 __le16 def_att_idx;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700872 u32 attn_state;
873 struct attn_route attn_group[MAX_DYNAMIC_ATTN_GRPS];
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700874
875 /* slow path ring */
876 struct eth_spe *spq;
877 dma_addr_t spq_mapping;
878 u16 spq_prod_idx;
879 struct eth_spe *spq_prod_bd;
880 struct eth_spe *spq_last_bd;
Eilon Greenstein4781bfa2009-02-12 08:38:17 +0000881 __le16 *dsb_sp_prod;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700882 u16 spq_left; /* serialize spq */
883 /* used to synchronize spq accesses */
884 spinlock_t spq_lock;
885
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -0700886 /* Flags for marking that there is a STAT_QUERY or
887 SET_MAC ramrod pending */
Michael Chane665bfd2009-10-10 13:46:54 +0000888 int stats_pending;
889 int set_mac_pending;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700890
Eilon Greenstein33471622008-08-13 15:59:08 -0700891 /* End of fields used in the performance code paths */
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700892
893 int panic;
Joe Perches7995c642010-02-17 15:01:52 +0000894 int msg_enable;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700895
896 u32 flags;
897#define PCIX_FLAG 1
898#define PCI_32BIT_FLAG 2
Eilon Greenstein1c063282009-02-12 08:36:43 +0000899#define ONE_PORT_FLAG 4
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700900#define NO_WOL_FLAG 8
901#define USING_DAC_FLAG 0x10
902#define USING_MSIX_FLAG 0x20
Eilon Greenstein8badd272009-02-12 08:36:15 +0000903#define USING_MSI_FLAG 0x40
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -0700904#define TPA_ENABLE_FLAG 0x80
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700905#define NO_MCP_FLAG 0x100
906#define BP_NOMCP(bp) (bp->flags & NO_MCP_FLAG)
Eilon Greenstein0c6671b2009-01-14 21:26:51 -0800907#define HW_VLAN_TX_FLAG 0x400
908#define HW_VLAN_RX_FLAG 0x800
Eilon Greensteinf34d28e2009-10-15 00:18:08 -0700909#define MF_FUNC_DIS 0x1000
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700910
911 int func;
912#define BP_PORT(bp) (bp->func % PORT_MAX)
913#define BP_FUNC(bp) (bp->func)
914#define BP_E1HVN(bp) (bp->func >> 1)
915#define BP_L_ID(bp) (BP_E1HVN(bp) << 2)
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700916
Michael Chan37b091b2009-10-10 13:46:55 +0000917#ifdef BCM_CNIC
918#define BCM_CNIC_CID_START 16
919#define BCM_ISCSI_ETH_CL_ID 17
920#endif
921
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700922 int pm_cap;
923 int pcie_cap;
Eilon Greenstein8d5726c2009-02-12 08:37:19 +0000924 int mrrs;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700925
Eilon Greenstein1cf167f2009-01-14 21:22:18 -0800926 struct delayed_work sp_task;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700927 struct work_struct reset_task;
928
929 struct timer_list timer;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700930 int current_interval;
931
932 u16 fw_seq;
933 u16 fw_drv_pulse_wr_seq;
934 u32 func_stx;
935
936 struct link_params link_params;
937 struct link_vars link_vars;
Eilon Greenstein01cd4522009-08-12 08:23:08 +0000938 struct mdio_if_info mdio;
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700939
940 struct bnx2x_common common;
941 struct bnx2x_port port;
942
Eilon Greenstein8a1c38d2009-02-12 08:36:40 +0000943 struct cmng_struct_per_port cmng;
944 u32 vn_weight_sum;
945
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700946 u32 mf_config;
947 u16 e1hov;
948 u8 e1hmf;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700949#define IS_E1HMF(bp) (bp->e1hmf != 0)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200950
Eliezer Tamirf1410642008-02-28 11:51:50 -0800951 u8 wol;
952
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700953 int rx_ring_size;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200954
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700955 u16 tx_quick_cons_trip_int;
956 u16 tx_quick_cons_trip;
957 u16 tx_ticks_int;
958 u16 tx_ticks;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200959
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700960 u16 rx_quick_cons_trip_int;
961 u16 rx_quick_cons_trip;
962 u16 rx_ticks_int;
963 u16 rx_ticks;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200964
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700965 u32 lin_cnt;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200966
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700967 int state;
Eilon Greenstein356e2382009-02-12 08:38:32 +0000968#define BNX2X_STATE_CLOSED 0
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700969#define BNX2X_STATE_OPENING_WAIT4_LOAD 0x1000
970#define BNX2X_STATE_OPENING_WAIT4_PORT 0x2000
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200971#define BNX2X_STATE_OPEN 0x3000
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700972#define BNX2X_STATE_CLOSING_WAIT4_HALT 0x4000
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200973#define BNX2X_STATE_CLOSING_WAIT4_DELETE 0x5000
974#define BNX2X_STATE_CLOSING_WAIT4_UNLOAD 0x6000
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700975#define BNX2X_STATE_DIAG 0xe000
976#define BNX2X_STATE_ERROR 0xf000
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200977
Eilon Greenstein555f6c72009-02-12 08:36:11 +0000978 int multi_mode;
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +0000979 int num_queues;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200980
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700981 u32 rx_mode;
982#define BNX2X_RX_MODE_NONE 0
983#define BNX2X_RX_MODE_NORMAL 1
984#define BNX2X_RX_MODE_ALLMULTI 2
985#define BNX2X_RX_MODE_PROMISC 3
986#define BNX2X_MAX_MULTICAST 64
987#define BNX2X_MAX_EMUL_MULTI 16
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200988
Michael Chan37b091b2009-10-10 13:46:55 +0000989 u32 rx_mode_cl_mask;
990
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700991 dma_addr_t def_status_blk_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200992
Eilon Greenstein34f80b02008-06-23 20:33:01 -0700993 struct bnx2x_slowpath *slowpath;
994 dma_addr_t slowpath_mapping;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +0200995
Eilon Greensteina18f5122009-08-12 08:23:26 +0000996 int dropless_fc;
997
Michael Chan37b091b2009-10-10 13:46:55 +0000998#ifdef BCM_CNIC
999 u32 cnic_flags;
1000#define BNX2X_CNIC_FLAG_MAC_SET 1
1001
1002 void *t1;
1003 dma_addr_t t1_mapping;
1004 void *t2;
1005 dma_addr_t t2_mapping;
1006 void *timers;
1007 dma_addr_t timers_mapping;
1008 void *qm;
1009 dma_addr_t qm_mapping;
1010 struct cnic_ops *cnic_ops;
1011 void *cnic_data;
1012 u32 cnic_tag;
1013 struct cnic_eth_dev cnic_eth_dev;
1014 struct host_status_block *cnic_sb;
1015 dma_addr_t cnic_sb_mapping;
1016#define CNIC_SB_ID(bp) BP_L_ID(bp)
1017 struct eth_spe *cnic_kwq;
1018 struct eth_spe *cnic_kwq_prod;
1019 struct eth_spe *cnic_kwq_cons;
1020 struct eth_spe *cnic_kwq_last;
1021 u16 cnic_kwq_pending;
1022 u16 cnic_spq_pending;
1023 struct mutex cnic_mutex;
1024 u8 iscsi_mac[6];
1025#endif
1026
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001027 int dmae_ready;
1028 /* used to synchronize dmae accesses */
1029 struct mutex dmae_mutex;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001030
Eilon Greensteinc4ff7cb2009-10-15 00:18:27 -07001031 /* used to protect the FW mail box */
1032 struct mutex fw_mb_mutex;
1033
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001034 /* used to synchronize stats collecting */
1035 int stats_state;
1036 /* used by dmae command loader */
1037 struct dmae_command stats_dmae;
1038 int executer_idx;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001039
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001040 u16 stats_counter;
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001041 struct bnx2x_eth_stats eth_stats;
1042
1043 struct z_stream_s *strm;
1044 void *gunzip_buf;
1045 dma_addr_t gunzip_mapping;
1046 int gunzip_outlen;
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001047#define FW_BUF_SIZE 0x8000
Eilon Greenstein573f2032009-08-12 08:24:14 +00001048#define GUNZIP_BUF(bp) (bp->gunzip_buf)
1049#define GUNZIP_PHYS(bp) (bp->gunzip_mapping)
1050#define GUNZIP_OUTLEN(bp) (bp->gunzip_outlen)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001051
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001052 struct raw_op *init_ops;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07001053 /* Init blocks offsets inside init_ops */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001054 u16 *init_ops_offsets;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07001055 /* Data blob - has 32 bit granularity */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001056 u32 *init_data;
Vladislav Zolotarov94a78b72009-04-27 03:27:43 -07001057 /* Zipped PRAM blobs - raw data */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001058 const u8 *tsem_int_table_data;
1059 const u8 *tsem_pram_data;
1060 const u8 *usem_int_table_data;
1061 const u8 *usem_pram_data;
1062 const u8 *xsem_int_table_data;
1063 const u8 *xsem_pram_data;
1064 const u8 *csem_int_table_data;
1065 const u8 *csem_pram_data;
Eilon Greenstein573f2032009-08-12 08:24:14 +00001066#define INIT_OPS(bp) (bp->init_ops)
1067#define INIT_OPS_OFFSETS(bp) (bp->init_ops_offsets)
1068#define INIT_DATA(bp) (bp->init_data)
1069#define INIT_TSEM_INT_TABLE_DATA(bp) (bp->tsem_int_table_data)
1070#define INIT_TSEM_PRAM_DATA(bp) (bp->tsem_pram_data)
1071#define INIT_USEM_INT_TABLE_DATA(bp) (bp->usem_int_table_data)
1072#define INIT_USEM_PRAM_DATA(bp) (bp->usem_pram_data)
1073#define INIT_XSEM_INT_TABLE_DATA(bp) (bp->xsem_int_table_data)
1074#define INIT_XSEM_PRAM_DATA(bp) (bp->xsem_pram_data)
1075#define INIT_CSEM_INT_TABLE_DATA(bp) (bp->csem_int_table_data)
1076#define INIT_CSEM_PRAM_DATA(bp) (bp->csem_pram_data)
1077
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001078 const struct firmware *firmware;
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001079};
1080
1081
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001082#define BNX2X_MAX_QUEUES(bp) (IS_E1HMF(bp) ? (MAX_CONTEXT/E1HVN_MAX) \
1083 : MAX_CONTEXT)
1084#define BNX2X_NUM_QUEUES(bp) (bp->num_queues)
1085#define is_multi(bp) (BNX2X_NUM_QUEUES(bp) > 1)
Eilon Greenstein3196a882008-08-13 15:58:49 -07001086
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001087#define for_each_queue(bp, var) \
1088 for (var = 0; var < BNX2X_NUM_QUEUES(bp); var++)
Eilon Greenstein3196a882008-08-13 15:58:49 -07001089#define for_each_nondefault_queue(bp, var) \
Vladislav Zolotarov54b9dda2009-11-16 06:05:58 +00001090 for (var = 1; var < BNX2X_NUM_QUEUES(bp); var++)
Eilon Greenstein3196a882008-08-13 15:58:49 -07001091
1092
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001093void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
1094void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
1095 u32 len32);
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001096int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port);
Eilon Greenstein17de50b2008-08-13 15:56:59 -07001097int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
Eilon Greenstein4acac6a2009-02-12 08:36:52 +00001098int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00001099u32 bnx2x_fw_command(struct bnx2x *bp, u32 command);
Eilon Greenstein573f2032009-08-12 08:24:14 +00001100void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val);
1101void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
1102 u32 addr, u32 len);
Yaniv Rosnerc18487e2008-06-23 20:27:52 -07001103
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001104static inline u32 reg_poll(struct bnx2x *bp, u32 reg, u32 expected, int ms,
1105 int wait)
1106{
1107 u32 val;
1108
1109 do {
1110 val = REG_RD(bp, reg);
1111 if (val == expected)
1112 break;
1113 ms -= wait;
1114 msleep(wait);
1115
1116 } while (ms > 0);
1117
1118 return val;
1119}
1120
1121
1122/* load/unload mode */
1123#define LOAD_NORMAL 0
1124#define LOAD_OPEN 1
1125#define LOAD_DIAG 2
1126#define UNLOAD_NORMAL 0
1127#define UNLOAD_CLOSE 1
1128
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001129
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001130/* DMAE command defines */
1131#define DMAE_CMD_SRC_PCI 0
1132#define DMAE_CMD_SRC_GRC DMAE_COMMAND_SRC
1133
1134#define DMAE_CMD_DST_PCI (1 << DMAE_COMMAND_DST_SHIFT)
1135#define DMAE_CMD_DST_GRC (2 << DMAE_COMMAND_DST_SHIFT)
1136
1137#define DMAE_CMD_C_DST_PCI 0
1138#define DMAE_CMD_C_DST_GRC (1 << DMAE_COMMAND_C_DST_SHIFT)
1139
1140#define DMAE_CMD_C_ENABLE DMAE_COMMAND_C_TYPE_ENABLE
1141
1142#define DMAE_CMD_ENDIANITY_NO_SWAP (0 << DMAE_COMMAND_ENDIANITY_SHIFT)
1143#define DMAE_CMD_ENDIANITY_B_SWAP (1 << DMAE_COMMAND_ENDIANITY_SHIFT)
1144#define DMAE_CMD_ENDIANITY_DW_SWAP (2 << DMAE_COMMAND_ENDIANITY_SHIFT)
1145#define DMAE_CMD_ENDIANITY_B_DW_SWAP (3 << DMAE_COMMAND_ENDIANITY_SHIFT)
1146
1147#define DMAE_CMD_PORT_0 0
1148#define DMAE_CMD_PORT_1 DMAE_COMMAND_PORT
1149
1150#define DMAE_CMD_SRC_RESET DMAE_COMMAND_SRC_RESET
1151#define DMAE_CMD_DST_RESET DMAE_COMMAND_DST_RESET
1152#define DMAE_CMD_E1HVN_SHIFT DMAE_COMMAND_E1HVN_SHIFT
1153
1154#define DMAE_LEN32_RD_MAX 0x80
1155#define DMAE_LEN32_WR_MAX 0x400
1156
1157#define DMAE_COMP_VAL 0xe0d0d0ae
1158
1159#define MAX_DMAE_C_PER_PORT 8
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001160#define INIT_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001161 BP_E1HVN(bp))
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001162#define PMF_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
Eilon Greensteinad8d3942008-06-23 20:29:02 -07001163 E1HVN_MAX)
1164
1165
Eliezer Tamir25047952008-02-28 11:50:16 -08001166/* PCIE link and speed */
1167#define PCICFG_LINK_WIDTH 0x1f00000
1168#define PCICFG_LINK_WIDTH_SHIFT 20
1169#define PCICFG_LINK_SPEED 0xf0000
1170#define PCICFG_LINK_SPEED_SHIFT 16
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001171
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001172
Eilon Greensteind3d4f492009-02-12 08:36:27 +00001173#define BNX2X_NUM_TESTS 7
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001174
Eilon Greensteinb5bf9062009-02-12 08:38:08 +00001175#define BNX2X_PHY_LOOPBACK 0
1176#define BNX2X_MAC_LOOPBACK 1
1177#define BNX2X_PHY_LOOPBACK_FAILED 1
1178#define BNX2X_MAC_LOOPBACK_FAILED 2
Yitchak Gertnerbb2a0f72008-06-23 20:33:36 -07001179#define BNX2X_LOOPBACK_FAILED (BNX2X_MAC_LOOPBACK_FAILED | \
1180 BNX2X_PHY_LOOPBACK_FAILED)
Eliezer Tamir96fc1782008-02-28 11:57:55 -08001181
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001182
1183#define STROM_ASSERT_ARRAY_SIZE 50
1184
Eliezer Tamir96fc1782008-02-28 11:57:55 -08001185
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001186/* must be used on a CID before placing it on a HW ring */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001187#define HW_CID(bp, x) ((BP_PORT(bp) << 23) | \
1188 (BP_E1HVN(bp) << 17) | (x))
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001189
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001190#define SP_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_spe))
1191#define MAX_SP_DESC_CNT (SP_DESC_CNT - 1)
1192
1193
Eilon Greenstein7d323bf2009-11-09 06:09:35 +00001194#define BNX2X_BTR 1
Vladislav Zolotarov7a9b2552008-06-23 20:34:36 -07001195#define MAX_SPQ_PENDING 8
1196
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001197
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001198/* CMNG constants
1199 derived from lab experiments, and not from system spec calculations !!! */
1200#define DEF_MIN_RATE 100
1201/* resolution of the rate shaping timer - 100 usec */
1202#define RS_PERIODIC_TIMEOUT_USEC 100
1203/* resolution of fairness algorithm in usecs -
Eilon Greenstein33471622008-08-13 15:59:08 -07001204 coefficient for calculating the actual t fair */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001205#define T_FAIR_COEF 10000000
1206/* number of bytes in single QM arbitration cycle -
Eilon Greenstein33471622008-08-13 15:59:08 -07001207 coefficient for calculating the fairness timer */
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001208#define QM_ARB_BYTES 40000
1209#define FAIR_MEM 2
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001210
1211
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001212#define ATTN_NIG_FOR_FUNC (1L << 8)
1213#define ATTN_SW_TIMER_4_FUNC (1L << 9)
1214#define GPIO_2_FUNC (1L << 10)
1215#define GPIO_3_FUNC (1L << 11)
1216#define GPIO_4_FUNC (1L << 12)
1217#define ATTN_GENERAL_ATTN_1 (1L << 13)
1218#define ATTN_GENERAL_ATTN_2 (1L << 14)
1219#define ATTN_GENERAL_ATTN_3 (1L << 15)
1220#define ATTN_GENERAL_ATTN_4 (1L << 13)
1221#define ATTN_GENERAL_ATTN_5 (1L << 14)
1222#define ATTN_GENERAL_ATTN_6 (1L << 15)
1223
1224#define ATTN_HARD_WIRED_MASK 0xff00
1225#define ATTENTION_ID 4
1226
1227
1228/* stuff added to make the code fit 80Col */
1229
1230#define BNX2X_PMF_LINK_ASSERT \
1231 GENERAL_ATTEN_OFFSET(LINK_SYNC_ATTENTION_BIT_FUNC_0 + BP_FUNC(bp))
1232
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001233#define BNX2X_MC_ASSERT_BITS \
1234 (GENERAL_ATTEN_OFFSET(TSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
1235 GENERAL_ATTEN_OFFSET(USTORM_FATAL_ASSERT_ATTENTION_BIT) | \
1236 GENERAL_ATTEN_OFFSET(CSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
1237 GENERAL_ATTEN_OFFSET(XSTORM_FATAL_ASSERT_ATTENTION_BIT))
1238
1239#define BNX2X_MCP_ASSERT \
1240 GENERAL_ATTEN_OFFSET(MCP_FATAL_ASSERT_ATTENTION_BIT)
1241
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001242#define BNX2X_GRC_TIMEOUT GENERAL_ATTEN_OFFSET(LATCHED_ATTN_TIMEOUT_GRC)
1243#define BNX2X_GRC_RSV (GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCR) | \
1244 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCT) | \
1245 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCN) | \
1246 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCU) | \
1247 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCP) | \
1248 GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RSVD_GRC))
1249
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001250#define HW_INTERRUT_ASSERT_SET_0 \
1251 (AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT | \
1252 AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT | \
1253 AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT | \
1254 AEU_INPUTS_ATTN_BITS_PBF_HW_INTERRUPT)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001255#define HW_PRTY_ASSERT_SET_0 (AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR | \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001256 AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR | \
1257 AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR | \
1258 AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR |\
1259 AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR)
1260#define HW_INTERRUT_ASSERT_SET_1 \
1261 (AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT | \
1262 AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT | \
1263 AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT | \
1264 AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT | \
1265 AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT | \
1266 AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT | \
1267 AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT | \
1268 AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT | \
1269 AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT | \
1270 AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT | \
1271 AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001272#define HW_PRTY_ASSERT_SET_1 (AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR |\
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001273 AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR | \
1274 AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR | \
1275 AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR | \
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001276 AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR |\
1277 AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR |\
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001278 AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR | \
1279 AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR | \
1280 AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR | \
1281 AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR | \
1282 AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR)
1283#define HW_INTERRUT_ASSERT_SET_2 \
1284 (AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT | \
1285 AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT | \
1286 AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT | \
1287 AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT |\
1288 AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT)
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001289#define HW_PRTY_ASSERT_SET_2 (AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR | \
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001290 AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR | \
1291 AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR |\
1292 AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR | \
1293 AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR | \
1294 AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR | \
1295 AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR)
1296
1297
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001298#define MULTI_FLAGS(bp) \
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001299 (TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY | \
1300 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY | \
1301 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY | \
1302 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY | \
Eilon Greenstein555f6c72009-02-12 08:36:11 +00001303 (bp->multi_mode << \
1304 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_MODE_SHIFT))
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001305#define MULTI_MASK 0x7f
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001306
1307
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001308#define DEF_USB_FUNC_OFF (2 + 2*HC_USTORM_DEF_SB_NUM_INDICES)
1309#define DEF_CSB_FUNC_OFF (2 + 2*HC_CSTORM_DEF_SB_NUM_INDICES)
1310#define DEF_XSB_FUNC_OFF (2 + 2*HC_XSTORM_DEF_SB_NUM_INDICES)
1311#define DEF_TSB_FUNC_OFF (2 + 2*HC_TSTORM_DEF_SB_NUM_INDICES)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001312
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001313#define C_DEF_SB_SP_INDEX HC_INDEX_DEF_C_ETH_SLOW_PATH
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001314
1315#define BNX2X_SP_DSB_INDEX \
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001316(&bp->def_status_blk->c_def_status_block.index_values[C_DEF_SB_SP_INDEX])
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001317
1318
1319#define CAM_IS_INVALID(x) \
1320(x.target_table_entry.flags == TSTORM_CAM_TARGET_TABLE_ENTRY_ACTION_TYPE)
1321
1322#define CAM_INVALIDATE(x) \
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001323 (x.target_table_entry.flags = TSTORM_CAM_TARGET_TABLE_ENTRY_ACTION_TYPE)
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001324
1325
Eilon Greenstein34f80b02008-06-23 20:33:01 -07001326/* Number of u32 elements in MC hash array */
1327#define MC_HASH_SIZE 8
1328#define MC_HASH_OFFSET(bp, i) (BAR_TSTRORM_INTMEM + \
1329 TSTORM_APPROXIMATE_MATCH_MULTICAST_FILTERING_OFFSET(BP_FUNC(bp)) + i*4)
1330
1331
1332#ifndef PXP2_REG_PXP2_INT_STS
1333#define PXP2_REG_PXP2_INT_STS PXP2_REG_PXP2_INT_STS_0
1334#endif
1335
Eliezer Tamira2fbb9e2007-11-15 20:09:02 +02001336/* MISC_REG_RESET_REG - this is here for the hsi to work don't touch */
1337
1338#endif /* bnx2x.h */