Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bnx2x.h
Go to the documentation of this file.
1 /* bnx2x.h: Broadcom Everest network driver.
2  *
3  * Copyright (c) 2007-2012 Broadcom Corporation
4  *
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  *
9  * Maintained by: Eilon Greenstein <[email protected]>
10  * Written by: Eliezer Tamir
11  * Based on code from Michael Chan's bnx2 driver
12  */
13 
14 #ifndef BNX2X_H
15 #define BNX2X_H
16 #include <linux/netdevice.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/types.h>
19 
20 /* compilation time flags */
21 
22 /* define this to make the driver freeze on error to allow getting debug info
23  * (you will need to reboot afterwards) */
24 /* #define BNX2X_STOP_ON_ERROR */
25 
26 #define DRV_MODULE_VERSION "1.78.00-0"
27 #define DRV_MODULE_RELDATE "2012/09/27"
28 #define BNX2X_BC_VER 0x040200
29 
30 #if defined(CONFIG_DCB)
31 #define BCM_DCBNL
32 #endif
33 
34 
35 #include "bnx2x_hsi.h"
36 
37 #if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
38 #define BCM_CNIC 1
39 #include "../cnic_if.h"
40 #endif
41 
42 #ifdef BCM_CNIC
43 #define BNX2X_MIN_MSIX_VEC_CNT 3
44 #define BNX2X_MSIX_VEC_FP_START 2
45 #else
46 #define BNX2X_MIN_MSIX_VEC_CNT 2
47 #define BNX2X_MSIX_VEC_FP_START 1
48 #endif
49 
50 #include <linux/mdio.h>
51 
52 #include "bnx2x_reg.h"
53 #include "bnx2x_fw_defs.h"
54 #include "bnx2x_mfw_req.h"
55 #include "bnx2x_hsi.h"
56 #include "bnx2x_link.h"
57 #include "bnx2x_sp.h"
58 #include "bnx2x_dcb.h"
59 #include "bnx2x_stats.h"
60 
61 /* error/debug prints */
62 
63 #define DRV_MODULE_NAME "bnx2x"
64 
65 /* for messages that are currently off */
66 #define BNX2X_MSG_OFF 0x0
67 #define BNX2X_MSG_MCP 0x0010000 /* was: NETIF_MSG_HW */
68 #define BNX2X_MSG_STATS 0x0020000 /* was: NETIF_MSG_TIMER */
69 #define BNX2X_MSG_NVM 0x0040000 /* was: NETIF_MSG_HW */
70 #define BNX2X_MSG_DMAE 0x0080000 /* was: NETIF_MSG_HW */
71 #define BNX2X_MSG_SP 0x0100000 /* was: NETIF_MSG_INTR */
72 #define BNX2X_MSG_FP 0x0200000 /* was: NETIF_MSG_INTR */
73 #define BNX2X_MSG_IOV 0x0800000
74 #define BNX2X_MSG_IDLE 0x2000000 /* used for idle check*/
75 #define BNX2X_MSG_ETHTOOL 0x4000000
76 #define BNX2X_MSG_DCB 0x8000000
77 
78 /* regular debug print */
79 #define DP(__mask, fmt, ...) \
80 do { \
81  if (unlikely(bp->msg_enable & (__mask))) \
82  pr_notice("[%s:%d(%s)]" fmt, \
83  __func__, __LINE__, \
84  bp->dev ? (bp->dev->name) : "?", \
85  ##__VA_ARGS__); \
86 } while (0)
87 
88 #define DP_CONT(__mask, fmt, ...) \
89 do { \
90  if (unlikely(bp->msg_enable & (__mask))) \
91  pr_cont(fmt, ##__VA_ARGS__); \
92 } while (0)
93 
94 /* errors debug print */
95 #define BNX2X_DBG_ERR(fmt, ...) \
96 do { \
97  if (unlikely(netif_msg_probe(bp))) \
98  pr_err("[%s:%d(%s)]" fmt, \
99  __func__, __LINE__, \
100  bp->dev ? (bp->dev->name) : "?", \
101  ##__VA_ARGS__); \
102 } while (0)
103 
104 /* for errors (never masked) */
105 #define BNX2X_ERR(fmt, ...) \
106 do { \
107  pr_err("[%s:%d(%s)]" fmt, \
108  __func__, __LINE__, \
109  bp->dev ? (bp->dev->name) : "?", \
110  ##__VA_ARGS__); \
111 } while (0)
112 
113 #define BNX2X_ERROR(fmt, ...) \
114  pr_err("[%s:%d]" fmt, __func__, __LINE__, ##__VA_ARGS__)
115 
116 
117 /* before we have a dev->name use dev_info() */
118 #define BNX2X_DEV_INFO(fmt, ...) \
119 do { \
120  if (unlikely(netif_msg_probe(bp))) \
121  dev_info(&bp->pdev->dev, fmt, ##__VA_ARGS__); \
122 } while (0)
123 
124 #ifdef BNX2X_STOP_ON_ERROR
125 void bnx2x_int_disable(struct bnx2x *bp);
126 #define bnx2x_panic() \
127 do { \
128  bp->panic = 1; \
129  BNX2X_ERR("driver assert\n"); \
130  bnx2x_int_disable(bp); \
131  bnx2x_panic_dump(bp); \
132 } while (0)
133 #else
134 #define bnx2x_panic() \
135 do { \
136  bp->panic = 1; \
137  BNX2X_ERR("driver assert\n"); \
138  bnx2x_panic_dump(bp); \
139 } while (0)
140 #endif
141 
142 #define bnx2x_mc_addr(ha) ((ha)->addr)
143 #define bnx2x_uc_addr(ha) ((ha)->addr)
144 
145 #define U64_LO(x) (u32)(((u64)(x)) & 0xffffffff)
146 #define U64_HI(x) (u32)(((u64)(x)) >> 32)
147 #define HILO_U64(hi, lo) ((((u64)(hi)) << 32) + (lo))
148 
149 
150 #define REG_ADDR(bp, offset) ((bp->regview) + (offset))
151 
152 #define REG_RD(bp, offset) readl(REG_ADDR(bp, offset))
153 #define REG_RD8(bp, offset) readb(REG_ADDR(bp, offset))
154 #define REG_RD16(bp, offset) readw(REG_ADDR(bp, offset))
155 
156 #define REG_WR(bp, offset, val) writel((u32)val, REG_ADDR(bp, offset))
157 #define REG_WR8(bp, offset, val) writeb((u8)val, REG_ADDR(bp, offset))
158 #define REG_WR16(bp, offset, val) writew((u16)val, REG_ADDR(bp, offset))
159 
160 #define REG_RD_IND(bp, offset) bnx2x_reg_rd_ind(bp, offset)
161 #define REG_WR_IND(bp, offset, val) bnx2x_reg_wr_ind(bp, offset, val)
162 
163 #define REG_RD_DMAE(bp, offset, valp, len32) \
164  do { \
165  bnx2x_read_dmae(bp, offset, len32);\
166  memcpy(valp, bnx2x_sp(bp, wb_data[0]), (len32) * 4); \
167  } while (0)
168 
169 #define REG_WR_DMAE(bp, offset, valp, len32) \
170  do { \
171  memcpy(bnx2x_sp(bp, wb_data[0]), valp, (len32) * 4); \
172  bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), \
173  offset, len32); \
174  } while (0)
175 
176 #define REG_WR_DMAE_LEN(bp, offset, valp, len32) \
177  REG_WR_DMAE(bp, offset, valp, len32)
178 
179 #define VIRT_WR_DMAE_LEN(bp, data, addr, len32, le32_swap) \
180  do { \
181  memcpy(GUNZIP_BUF(bp), data, (len32) * 4); \
182  bnx2x_write_big_buf_wb(bp, addr, len32); \
183  } while (0)
184 
185 #define SHMEM_ADDR(bp, field) (bp->common.shmem_base + \
186  offsetof(struct shmem_region, field))
187 #define SHMEM_RD(bp, field) REG_RD(bp, SHMEM_ADDR(bp, field))
188 #define SHMEM_WR(bp, field, val) REG_WR(bp, SHMEM_ADDR(bp, field), val)
189 
190 #define SHMEM2_ADDR(bp, field) (bp->common.shmem2_base + \
191  offsetof(struct shmem2_region, field))
192 #define SHMEM2_RD(bp, field) REG_RD(bp, SHMEM2_ADDR(bp, field))
193 #define SHMEM2_WR(bp, field, val) REG_WR(bp, SHMEM2_ADDR(bp, field), val)
194 #define MF_CFG_ADDR(bp, field) (bp->common.mf_cfg_base + \
195  offsetof(struct mf_cfg, field))
196 #define MF2_CFG_ADDR(bp, field) (bp->common.mf2_cfg_base + \
197  offsetof(struct mf2_cfg, field))
198 
199 #define MF_CFG_RD(bp, field) REG_RD(bp, MF_CFG_ADDR(bp, field))
200 #define MF_CFG_WR(bp, field, val) REG_WR(bp,\
201  MF_CFG_ADDR(bp, field), (val))
202 #define MF2_CFG_RD(bp, field) REG_RD(bp, MF2_CFG_ADDR(bp, field))
203 
204 #define SHMEM2_HAS(bp, field) ((bp)->common.shmem2_base && \
205  (SHMEM2_RD((bp), size) > \
206  offsetof(struct shmem2_region, field)))
207 
208 #define EMAC_RD(bp, reg) REG_RD(bp, emac_base + reg)
209 #define EMAC_WR(bp, reg, val) REG_WR(bp, emac_base + reg, val)
210 
211 /* SP SB indices */
212 
213 /* General SP events - stats query, cfc delete, etc */
214 #define HC_SP_INDEX_ETH_DEF_CONS 3
215 
216 /* EQ completions */
217 #define HC_SP_INDEX_EQ_CONS 7
218 
219 /* FCoE L2 connection completions */
220 #define HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS 6
221 #define HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS 4
222 /* iSCSI L2 */
223 #define HC_SP_INDEX_ETH_ISCSI_CQ_CONS 5
224 #define HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS 1
225 
226 /* Special clients parameters */
227 
228 /* SB indices */
229 /* FCoE L2 */
230 #define BNX2X_FCOE_L2_RX_INDEX \
231  (&bp->def_status_blk->sp_sb.\
232  index_values[HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS])
233 
234 #define BNX2X_FCOE_L2_TX_INDEX \
235  (&bp->def_status_blk->sp_sb.\
236  index_values[HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS])
237 
246 enum {
250 };
251 
252 #define BNX2X_CNIC_START_ETH_CID(bp) (BNX2X_NUM_NON_CNIC_QUEUES(bp) *\
253  (bp)->max_cos)
254  /* iSCSI L2 */
255 #define BNX2X_ISCSI_ETH_CID(bp) (BNX2X_CNIC_START_ETH_CID(bp))
256  /* FCoE L2 */
257 #define BNX2X_FCOE_ETH_CID(bp) (BNX2X_CNIC_START_ETH_CID(bp) + 1)
258 
260 #ifdef BCM_CNIC
261 #define CNIC_PRESENT 1
262 #define FCOE_PRESENT 1
263 #else
264 #define CNIC_PRESENT 0
265 #define FCOE_PRESENT 0
266 #endif /* BCM_CNIC */
267 #define NON_ETH_CONTEXT_USE (FCOE_PRESENT)
268 
269 #define AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR \
270  AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR
271 
272 #define SM_RX_ID 0
273 #define SM_TX_ID 1
274 
275 /* defines for multiple tx priority indices */
276 #define FIRST_TX_ONLY_COS_INDEX 1
277 #define FIRST_TX_COS_INDEX 0
278 
279 /* rules for calculating the cids of tx-only connections */
280 #define CID_TO_FP(cid, bp) ((cid) % BNX2X_NUM_NON_CNIC_QUEUES(bp))
281 #define CID_COS_TO_TX_ONLY_CID(cid, cos, bp) \
282  (cid + cos * BNX2X_NUM_NON_CNIC_QUEUES(bp))
283 
284 /* fp index inside class of service range */
285 #define FP_COS_TO_TXQ(fp, cos, bp) \
286  ((fp)->index + cos * BNX2X_NUM_NON_CNIC_QUEUES(bp))
287 
288 /* Indexes for transmission queues array:
289  * txdata for RSS i CoS j is at location i + (j * num of RSS)
290  * txdata for FCoE (if exist) is at location max cos * num of RSS
291  * txdata for FWD (if exist) is one location after FCoE
292  * txdata for OOO (if exist) is one location after FWD
293  */
294 enum {
298 };
299 #define MAX_ETH_TXQ_IDX(bp) (BNX2X_NUM_NON_CNIC_QUEUES(bp) * (bp)->max_cos)
300 #ifdef BCM_CNIC
301 #define FCOE_TXQ_IDX(bp) (MAX_ETH_TXQ_IDX(bp) + FCOE_TXQ_IDX_OFFSET)
302 #endif
303 
304 /* fast path */
305 /*
306  * This driver uses new build_skb() API :
307  * RX ring buffer contains pointer to kmalloc() data only,
308  * skb are built only after Hardware filled the frame.
309  */
310 struct sw_rx_bd {
313 };
314 
315 struct sw_tx_bd {
316  struct sk_buff *skb;
319 /* Set on the first BD descriptor when there is a split BD */
320 #define BNX2X_TSO_SPLIT_BD (1<<0)
321 };
322 
323 struct sw_rx_page {
324  struct page *page;
326 };
327 
328 union db_prod {
331 };
332 
333 /* dropless fc FW/HW related params */
334 #define BRB_SIZE(bp) (CHIP_IS_E3(bp) ? 1024 : 512)
335 #define MAX_AGG_QS(bp) (CHIP_IS_E1(bp) ? \
336  ETH_MAX_AGGREGATION_QUEUES_E1 :\
337  ETH_MAX_AGGREGATION_QUEUES_E1H_E2)
338 #define FW_DROP_LEVEL(bp) (3 + MAX_SPQ_PENDING + MAX_AGG_QS(bp))
339 #define FW_PREFETCH_CNT 16
340 #define DROPLESS_FC_HEADROOM 100
341 
342 /* MC hsi */
343 #define BCM_PAGE_SHIFT 12
344 #define BCM_PAGE_SIZE (1 << BCM_PAGE_SHIFT)
345 #define BCM_PAGE_MASK (~(BCM_PAGE_SIZE - 1))
346 #define BCM_PAGE_ALIGN(addr) (((addr) + BCM_PAGE_SIZE - 1) & BCM_PAGE_MASK)
347 
348 #define PAGES_PER_SGE_SHIFT 0
349 #define PAGES_PER_SGE (1 << PAGES_PER_SGE_SHIFT)
350 #define SGE_PAGE_SIZE PAGE_SIZE
351 #define SGE_PAGE_SHIFT PAGE_SHIFT
352 #define SGE_PAGE_ALIGN(addr) PAGE_ALIGN((typeof(PAGE_SIZE))(addr))
353 
354 /* SGE ring related macros */
355 #define NUM_RX_SGE_PAGES 2
356 #define RX_SGE_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_sge))
357 #define NEXT_PAGE_SGE_DESC_CNT 2
358 #define MAX_RX_SGE_CNT (RX_SGE_CNT - NEXT_PAGE_SGE_DESC_CNT)
359 /* RX_SGE_CNT is promised to be a power of 2 */
360 #define RX_SGE_MASK (RX_SGE_CNT - 1)
361 #define NUM_RX_SGE (RX_SGE_CNT * NUM_RX_SGE_PAGES)
362 #define MAX_RX_SGE (NUM_RX_SGE - 1)
363 #define NEXT_SGE_IDX(x) ((((x) & RX_SGE_MASK) == \
364  (MAX_RX_SGE_CNT - 1)) ? \
365  (x) + 1 + NEXT_PAGE_SGE_DESC_CNT : \
366  (x) + 1)
367 #define RX_SGE(x) ((x) & MAX_RX_SGE)
368 
369 /*
370  * Number of required SGEs is the sum of two:
371  * 1. Number of possible opened aggregations (next packet for
372  * these aggregations will probably consume SGE immidiatelly)
373  * 2. Rest of BRB blocks divided by 2 (block will consume new SGE only
374  * after placement on BD for new TPA aggregation)
375  *
376  * Takes into account NEXT_PAGE_SGE_DESC_CNT "next" elements on each page
377  */
378 #define NUM_SGE_REQ (MAX_AGG_QS(bp) + \
379  (BRB_SIZE(bp) - MAX_AGG_QS(bp)) / 2)
380 #define NUM_SGE_PG_REQ ((NUM_SGE_REQ + MAX_RX_SGE_CNT - 1) / \
381  MAX_RX_SGE_CNT)
382 #define SGE_TH_LO(bp) (NUM_SGE_REQ + \
383  NUM_SGE_PG_REQ * NEXT_PAGE_SGE_DESC_CNT)
384 #define SGE_TH_HI(bp) (SGE_TH_LO(bp) + DROPLESS_FC_HEADROOM)
385 
386 /* Manipulate a bit vector defined as an array of u64 */
387 
388 /* Number of bits in one sge_mask array element */
389 #define BIT_VEC64_ELEM_SZ 64
390 #define BIT_VEC64_ELEM_SHIFT 6
391 #define BIT_VEC64_ELEM_MASK ((u64)BIT_VEC64_ELEM_SZ - 1)
392 
393 
394 #define __BIT_VEC64_SET_BIT(el, bit) \
395  do { \
396  el = ((el) | ((u64)0x1 << (bit))); \
397  } while (0)
398 
399 #define __BIT_VEC64_CLEAR_BIT(el, bit) \
400  do { \
401  el = ((el) & (~((u64)0x1 << (bit)))); \
402  } while (0)
403 
404 
405 #define BIT_VEC64_SET_BIT(vec64, idx) \
406  __BIT_VEC64_SET_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
407  (idx) & BIT_VEC64_ELEM_MASK)
408 
409 #define BIT_VEC64_CLEAR_BIT(vec64, idx) \
410  __BIT_VEC64_CLEAR_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
411  (idx) & BIT_VEC64_ELEM_MASK)
412 
413 #define BIT_VEC64_TEST_BIT(vec64, idx) \
414  (((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT] >> \
415  ((idx) & BIT_VEC64_ELEM_MASK)) & 0x1)
416 
417 /* Creates a bitmask of all ones in less significant bits.
418  idx - index of the most significant bit in the created mask */
419 #define BIT_VEC64_ONES_MASK(idx) \
420  (((u64)0x1 << (((idx) & BIT_VEC64_ELEM_MASK) + 1)) - 1)
421 #define BIT_VEC64_ELEM_ONE_MASK ((u64)(~0))
422 
423 /*******************************************************/
424 
425 
426 
427 /* Number of u64 elements in SGE mask array */
428 #define RX_SGE_MASK_LEN (NUM_RX_SGE / BIT_VEC64_ELEM_SZ)
429 #define RX_SGE_MASK_LEN_MASK (RX_SGE_MASK_LEN - 1)
430 #define NEXT_SGE_MASK_ELEM(el) (((el) + 1) & RX_SGE_MASK_LEN_MASK)
431 
433  /* pointer to fp status block e1x */
435  /* pointer to fp status block e2 */
437 };
438 
440  /*
441  * First aggregation buffer is a data buffer, the following - are pages.
442  * We will preallocate the data buffer for each aggregation when
443  * we open the interface and will replace the BD at the consumer
444  * with this one when we receive the TPA_START CQE in order to
445  * keep the Rx BD ring consistent.
446  */
449 #define BNX2X_TPA_START 1
450 #define BNX2X_TPA_STOP 2
451 #define BNX2X_TPA_ERROR 3
457  bool l4_rxhash;
460 };
461 
462 #define Q_STATS_OFFSET32(stat_name) \
463  (offsetof(struct bnx2x_eth_q_stats, stat_name) / 4)
464 
466 
468 
471 
473 
474  union db_prod tx_db;
475 
480 
481  unsigned long tx_pkt;
482 
484 
488 };
489 
493 };
494 
496  struct bnx2x *bp; /* parent */
497 
498 #define BNX2X_NAPI_WEIGHT 128
501  /* chip independed shortcuts into sb structure */
504  /* chip independed shortcut into rx_prods_offset memory */
506 
508 
510 
512 
513  u8 max_cos; /* actual number of active tx coses */
515 
516  struct sw_rx_bd *rx_buf_ring; /* BDs mappings ring */
517  struct sw_rx_page *rx_page_ring; /* SGE pages mappings ring */
518 
521 
524 
525  /* SGE ring */
528 
530 
532 
534 
535  u8 index; /* number in fp array */
536  u8 rx_queue; /* index for skb_record */
537  u8 cl_id; /* eth client id */
539  u8 fw_sb_id; /* status block number in FW */
540  u8 igu_sb_id; /* status block number in HW */
541 
547  /* The last maximal completed SGE */
550  unsigned long rx_pkt,
551  rx_calls;
552 
553  /* TPA related */
556 #ifdef BNX2X_STOP_ON_ERROR
557  u64 tpa_queue_used;
558 #endif
559  /* The size is calculated using the following:
560  sizeof name field from netdev structure +
561  4 ('-Xx-' string) +
562  4 (for the digits and to make it DWORD aligned) */
563 #define FP_NAME_SIZE (sizeof(((struct net_device *)0)->name) + 8)
565 };
566 
567 #define bnx2x_fp(bp, nr, var) ((bp)->fp[(nr)].var)
568 #define bnx2x_sp_obj(bp, fp) ((bp)->sp_objs[(fp)->index])
569 #define bnx2x_fp_stats(bp, fp) (&((bp)->fp_stats[(fp)->index]))
570 #define bnx2x_fp_qstats(bp, fp) (&((bp)->fp_stats[(fp)->index].eth_q_stats))
571 
572 /* Use 2500 as a mini-jumbo MTU for FCoE */
573 #define BNX2X_FCOE_MINI_JUMBO_MTU 2500
574 
575 #define FCOE_IDX_OFFSET 0
576 
577 #define FCOE_IDX(bp) (BNX2X_NUM_NON_CNIC_QUEUES(bp) + \
578  FCOE_IDX_OFFSET)
579 #define bnx2x_fcoe_fp(bp) (&bp->fp[FCOE_IDX(bp)])
580 #define bnx2x_fcoe(bp, var) (bnx2x_fcoe_fp(bp)->var)
581 #define bnx2x_fcoe_inner_sp_obj(bp) (&bp->sp_objs[FCOE_IDX(bp)])
582 #define bnx2x_fcoe_sp_obj(bp, var) (bnx2x_fcoe_inner_sp_obj(bp)->var)
583 #define bnx2x_fcoe_tx(bp, var) (bnx2x_fcoe_fp(bp)-> \
584  txdata_ptr[FIRST_TX_COS_INDEX] \
585  ->var)
586 
587 
588 #define IS_ETH_FP(fp) (fp->index < \
589  BNX2X_NUM_ETH_QUEUES(fp->bp))
590 #ifdef BCM_CNIC
591 #define IS_FCOE_FP(fp) (fp->index == FCOE_IDX(fp->bp))
592 #define IS_FCOE_IDX(idx) ((idx) == FCOE_IDX(bp))
593 #else
594 #define IS_FCOE_FP(fp) false
595 #define IS_FCOE_IDX(idx) false
596 #endif
597 
598 
599 /* MC hsi */
600 #define MAX_FETCH_BD 13 /* HW max BDs per packet */
601 #define RX_COPY_THRESH 92
602 
603 #define NUM_TX_RINGS 16
604 #define TX_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_tx_bd_types))
605 #define NEXT_PAGE_TX_DESC_CNT 1
606 #define MAX_TX_DESC_CNT (TX_DESC_CNT - NEXT_PAGE_TX_DESC_CNT)
607 #define NUM_TX_BD (TX_DESC_CNT * NUM_TX_RINGS)
608 #define MAX_TX_BD (NUM_TX_BD - 1)
609 #define MAX_TX_AVAIL (MAX_TX_DESC_CNT * NUM_TX_RINGS - 2)
610 #define NEXT_TX_IDX(x) ((((x) & MAX_TX_DESC_CNT) == \
611  (MAX_TX_DESC_CNT - 1)) ? \
612  (x) + 1 + NEXT_PAGE_TX_DESC_CNT : \
613  (x) + 1)
614 #define TX_BD(x) ((x) & MAX_TX_BD)
615 #define TX_BD_POFF(x) ((x) & MAX_TX_DESC_CNT)
616 
617 /* number of NEXT_PAGE descriptors may be required during placement */
618 #define NEXT_CNT_PER_TX_PKT(bds) \
619  (((bds) + MAX_TX_DESC_CNT - 1) / \
620  MAX_TX_DESC_CNT * NEXT_PAGE_TX_DESC_CNT)
621 /* max BDs per tx packet w/o next_pages:
622  * START_BD - describes packed
623  * START_BD(splitted) - includes unpaged data segment for GSO
624  * PARSING_BD - for TSO and CSUM data
625  * Frag BDs - decribes pages for frags
626  */
627 #define BDS_PER_TX_PKT 3
628 #define MAX_BDS_PER_TX_PKT (MAX_SKB_FRAGS + BDS_PER_TX_PKT)
629 /* max BDs per tx packet including next pages */
630 #define MAX_DESC_PER_TX_PKT (MAX_BDS_PER_TX_PKT + \
631  NEXT_CNT_PER_TX_PKT(MAX_BDS_PER_TX_PKT))
632 
633 /* The RX BD ring is special, each bd is 8 bytes but the last one is 16 */
634 #define NUM_RX_RINGS 8
635 #define RX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_bd))
636 #define NEXT_PAGE_RX_DESC_CNT 2
637 #define MAX_RX_DESC_CNT (RX_DESC_CNT - NEXT_PAGE_RX_DESC_CNT)
638 #define RX_DESC_MASK (RX_DESC_CNT - 1)
639 #define NUM_RX_BD (RX_DESC_CNT * NUM_RX_RINGS)
640 #define MAX_RX_BD (NUM_RX_BD - 1)
641 #define MAX_RX_AVAIL (MAX_RX_DESC_CNT * NUM_RX_RINGS - 2)
642 
643 /* dropless fc calculations for BDs
644  *
645  * Number of BDs should as number of buffers in BRB:
646  * Low threshold takes into account NEXT_PAGE_RX_DESC_CNT
647  * "next" elements on each page
648  */
649 #define NUM_BD_REQ BRB_SIZE(bp)
650 #define NUM_BD_PG_REQ ((NUM_BD_REQ + MAX_RX_DESC_CNT - 1) / \
651  MAX_RX_DESC_CNT)
652 #define BD_TH_LO(bp) (NUM_BD_REQ + \
653  NUM_BD_PG_REQ * NEXT_PAGE_RX_DESC_CNT + \
654  FW_DROP_LEVEL(bp))
655 #define BD_TH_HI(bp) (BD_TH_LO(bp) + DROPLESS_FC_HEADROOM)
656 
657 #define MIN_RX_AVAIL ((bp)->dropless_fc ? BD_TH_HI(bp) + 128 : 128)
658 
659 #define MIN_RX_SIZE_TPA_HW (CHIP_IS_E1(bp) ? \
660  ETH_MIN_RX_CQES_WITH_TPA_E1 : \
661  ETH_MIN_RX_CQES_WITH_TPA_E1H_E2)
662 #define MIN_RX_SIZE_NONTPA_HW ETH_MIN_RX_CQES_WITHOUT_TPA
663 #define MIN_RX_SIZE_TPA (max_t(u32, MIN_RX_SIZE_TPA_HW, MIN_RX_AVAIL))
664 #define MIN_RX_SIZE_NONTPA (max_t(u32, MIN_RX_SIZE_NONTPA_HW,\
665  MIN_RX_AVAIL))
666 
667 #define NEXT_RX_IDX(x) ((((x) & RX_DESC_MASK) == \
668  (MAX_RX_DESC_CNT - 1)) ? \
669  (x) + 1 + NEXT_PAGE_RX_DESC_CNT : \
670  (x) + 1)
671 #define RX_BD(x) ((x) & MAX_RX_BD)
672 
673 /*
674  * As long as CQE is X times bigger than BD entry we have to allocate X times
675  * more pages for CQ ring in order to keep it balanced with BD ring
676  */
677 #define CQE_BD_REL (sizeof(union eth_rx_cqe) / sizeof(struct eth_rx_bd))
678 #define NUM_RCQ_RINGS (NUM_RX_RINGS * CQE_BD_REL)
679 #define RCQ_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_rx_cqe))
680 #define NEXT_PAGE_RCQ_DESC_CNT 1
681 #define MAX_RCQ_DESC_CNT (RCQ_DESC_CNT - NEXT_PAGE_RCQ_DESC_CNT)
682 #define NUM_RCQ_BD (RCQ_DESC_CNT * NUM_RCQ_RINGS)
683 #define MAX_RCQ_BD (NUM_RCQ_BD - 1)
684 #define MAX_RCQ_AVAIL (MAX_RCQ_DESC_CNT * NUM_RCQ_RINGS - 2)
685 #define NEXT_RCQ_IDX(x) ((((x) & MAX_RCQ_DESC_CNT) == \
686  (MAX_RCQ_DESC_CNT - 1)) ? \
687  (x) + 1 + NEXT_PAGE_RCQ_DESC_CNT : \
688  (x) + 1)
689 #define RCQ_BD(x) ((x) & MAX_RCQ_BD)
690 
691 /* dropless fc calculations for RCQs
692  *
693  * Number of RCQs should be as number of buffers in BRB:
694  * Low threshold takes into account NEXT_PAGE_RCQ_DESC_CNT
695  * "next" elements on each page
696  */
697 #define NUM_RCQ_REQ BRB_SIZE(bp)
698 #define NUM_RCQ_PG_REQ ((NUM_BD_REQ + MAX_RCQ_DESC_CNT - 1) / \
699  MAX_RCQ_DESC_CNT)
700 #define RCQ_TH_LO(bp) (NUM_RCQ_REQ + \
701  NUM_RCQ_PG_REQ * NEXT_PAGE_RCQ_DESC_CNT + \
702  FW_DROP_LEVEL(bp))
703 #define RCQ_TH_HI(bp) (RCQ_TH_LO(bp) + DROPLESS_FC_HEADROOM)
704 
705 
706 /* This is needed for determining of last_max */
707 #define SUB_S16(a, b) (s16)((s16)(a) - (s16)(b))
708 #define SUB_S32(a, b) (s32)((s32)(a) - (s32)(b))
709 
710 
711 #define BNX2X_SWCID_SHIFT 17
712 #define BNX2X_SWCID_MASK ((0x1 << BNX2X_SWCID_SHIFT) - 1)
713 
714 /* used on a CID received from the HW */
715 #define SW_CID(x) (le32_to_cpu(x) & BNX2X_SWCID_MASK)
716 #define CQE_CMD(x) (le32_to_cpu(x) >> \
717  COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT)
718 
719 #define BD_UNMAP_ADDR(bd) HILO_U64(le32_to_cpu((bd)->addr_hi), \
720  le32_to_cpu((bd)->addr_lo))
721 #define BD_UNMAP_LEN(bd) (le16_to_cpu((bd)->nbytes))
722 
723 #define BNX2X_DB_MIN_SHIFT 3 /* 8 bytes */
724 #define BNX2X_DB_SHIFT 7 /* 128 bytes*/
725 #if (BNX2X_DB_SHIFT < BNX2X_DB_MIN_SHIFT)
726 #error "Min DB doorbell stride is 8"
727 #endif
728 #define DPM_TRIGER_TYPE 0x40
729 #define DOORBELL(bp, cid, val) \
730  do { \
731  writel((u32)(val), bp->doorbells + (bp->db_size * (cid)) + \
732  DPM_TRIGER_TYPE); \
733  } while (0)
734 
735 
736 /* TX CSUM helpers */
737 #define SKB_CS_OFF(skb) (offsetof(struct tcphdr, check) - \
738  skb->csum_offset)
739 #define SKB_CS(skb) (*(u16 *)(skb_transport_header(skb) + \
740  skb->csum_offset))
741 
742 #define pbd_tcp_flags(skb) (ntohl(tcp_flag_word(tcp_hdr(skb)))>>16 & 0xff)
743 
744 #define XMIT_PLAIN 0
745 #define XMIT_CSUM_V4 0x1
746 #define XMIT_CSUM_V6 0x2
747 #define XMIT_CSUM_TCP 0x4
748 #define XMIT_GSO_V4 0x8
749 #define XMIT_GSO_V6 0x10
750 
751 #define XMIT_CSUM (XMIT_CSUM_V4 | XMIT_CSUM_V6)
752 #define XMIT_GSO (XMIT_GSO_V4 | XMIT_GSO_V6)
753 
754 
755 /* stuff added to make the code fit 80Col */
756 #define CQE_TYPE(cqe_fp_flags) ((cqe_fp_flags) & ETH_FAST_PATH_RX_CQE_TYPE)
757 #define CQE_TYPE_START(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_START_AGG)
758 #define CQE_TYPE_STOP(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_STOP_AGG)
759 #define CQE_TYPE_SLOW(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_RAMROD)
760 #define CQE_TYPE_FAST(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_FASTPATH)
761 
762 #define ETH_RX_ERROR_FALGS ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG
763 
764 #define BNX2X_PRS_FLAG_OVERETH_IPV4(flags) \
765  (((le16_to_cpu(flags) & \
766  PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) >> \
767  PARSING_FLAGS_OVER_ETHERNET_PROTOCOL_SHIFT) \
768  == PRS_FLAG_OVERETH_IPV4)
769 #define BNX2X_RX_SUM_FIX(cqe) \
770  BNX2X_PRS_FLAG_OVERETH_IPV4(cqe->fast_path_cqe.pars_flags.flags)
771 
772 
773 #define FP_USB_FUNC_OFF \
774  offsetof(struct cstorm_status_block_u, func)
775 #define FP_CSB_FUNC_OFF \
776  offsetof(struct cstorm_status_block_c, func)
777 
778 #define HC_INDEX_ETH_RX_CQ_CONS 1
779 
780 #define HC_INDEX_OOO_TX_CQ_CONS 4
781 
782 #define HC_INDEX_ETH_TX_CQ_CONS_COS0 5
783 
784 #define HC_INDEX_ETH_TX_CQ_CONS_COS1 6
785 
786 #define HC_INDEX_ETH_TX_CQ_CONS_COS2 7
787 
788 #define HC_INDEX_ETH_FIRST_TX_CQ_CONS HC_INDEX_ETH_TX_CQ_CONS_COS0
789 
790 #define BNX2X_RX_SB_INDEX \
791  (&fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS])
792 
793 #define BNX2X_TX_SB_INDEX_BASE BNX2X_TX_SB_INDEX_COS0
794 
795 #define BNX2X_TX_SB_INDEX_COS0 \
796  (&fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0])
797 
798 /* end of fast path */
799 
800 /* common */
801 
802 struct bnx2x_common {
803 
805 /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
806 #define CHIP_ID(bp) (bp->common.chip_id & 0xfffffff0)
807 
808 #define CHIP_NUM(bp) (bp->common.chip_id >> 16)
809 #define CHIP_NUM_57710 0x164e
810 #define CHIP_NUM_57711 0x164f
811 #define CHIP_NUM_57711E 0x1650
812 #define CHIP_NUM_57712 0x1662
813 #define CHIP_NUM_57712_MF 0x1663
814 #define CHIP_NUM_57713 0x1651
815 #define CHIP_NUM_57713E 0x1652
816 #define CHIP_NUM_57800 0x168a
817 #define CHIP_NUM_57800_MF 0x16a5
818 #define CHIP_NUM_57810 0x168e
819 #define CHIP_NUM_57810_MF 0x16ae
820 #define CHIP_NUM_57811 0x163d
821 #define CHIP_NUM_57811_MF 0x163e
822 #define CHIP_NUM_57840_OBSOLETE 0x168d
823 #define CHIP_NUM_57840_MF_OBSOLETE 0x16ab
824 #define CHIP_NUM_57840_4_10 0x16a1
825 #define CHIP_NUM_57840_2_20 0x16a2
826 #define CHIP_NUM_57840_MF 0x16a4
827 #define CHIP_IS_E1(bp) (CHIP_NUM(bp) == CHIP_NUM_57710)
828 #define CHIP_IS_57711(bp) (CHIP_NUM(bp) == CHIP_NUM_57711)
829 #define CHIP_IS_57711E(bp) (CHIP_NUM(bp) == CHIP_NUM_57711E)
830 #define CHIP_IS_57712(bp) (CHIP_NUM(bp) == CHIP_NUM_57712)
831 #define CHIP_IS_57712_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57712_MF)
832 #define CHIP_IS_57800(bp) (CHIP_NUM(bp) == CHIP_NUM_57800)
833 #define CHIP_IS_57800_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57800_MF)
834 #define CHIP_IS_57810(bp) (CHIP_NUM(bp) == CHIP_NUM_57810)
835 #define CHIP_IS_57810_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57810_MF)
836 #define CHIP_IS_57811(bp) (CHIP_NUM(bp) == CHIP_NUM_57811)
837 #define CHIP_IS_57811_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57811_MF)
838 #define CHIP_IS_57840(bp) \
839  ((CHIP_NUM(bp) == CHIP_NUM_57840_4_10) || \
840  (CHIP_NUM(bp) == CHIP_NUM_57840_2_20) || \
841  (CHIP_NUM(bp) == CHIP_NUM_57840_OBSOLETE))
842 #define CHIP_IS_57840_MF(bp) ((CHIP_NUM(bp) == CHIP_NUM_57840_MF) || \
843  (CHIP_NUM(bp) == CHIP_NUM_57840_MF_OBSOLETE))
844 #define CHIP_IS_E1H(bp) (CHIP_IS_57711(bp) || \
845  CHIP_IS_57711E(bp))
846 #define CHIP_IS_E2(bp) (CHIP_IS_57712(bp) || \
847  CHIP_IS_57712_MF(bp))
848 #define CHIP_IS_E3(bp) (CHIP_IS_57800(bp) || \
849  CHIP_IS_57800_MF(bp) || \
850  CHIP_IS_57810(bp) || \
851  CHIP_IS_57810_MF(bp) || \
852  CHIP_IS_57811(bp) || \
853  CHIP_IS_57811_MF(bp) || \
854  CHIP_IS_57840(bp) || \
855  CHIP_IS_57840_MF(bp))
856 #define CHIP_IS_E1x(bp) (CHIP_IS_E1((bp)) || CHIP_IS_E1H((bp)))
857 #define USES_WARPCORE(bp) (CHIP_IS_E3(bp))
858 #define IS_E1H_OFFSET (!CHIP_IS_E1(bp))
859 
860 #define CHIP_REV_SHIFT 12
861 #define CHIP_REV_MASK (0xF << CHIP_REV_SHIFT)
862 #define CHIP_REV_VAL(bp) (bp->common.chip_id & CHIP_REV_MASK)
863 #define CHIP_REV_Ax (0x0 << CHIP_REV_SHIFT)
864 #define CHIP_REV_Bx (0x1 << CHIP_REV_SHIFT)
865 /* assume maximum 5 revisions */
866 #define CHIP_REV_IS_SLOW(bp) (CHIP_REV_VAL(bp) > 0x00005000)
867 /* Emul versions are A=>0xe, B=>0xc, C=>0xa, D=>8, E=>6 */
868 #define CHIP_REV_IS_EMUL(bp) ((CHIP_REV_IS_SLOW(bp)) && \
869  !(CHIP_REV_VAL(bp) & 0x00001000))
870 /* FPGA versions are A=>0xf, B=>0xd, C=>0xb, D=>9, E=>7 */
871 #define CHIP_REV_IS_FPGA(bp) ((CHIP_REV_IS_SLOW(bp)) && \
872  (CHIP_REV_VAL(bp) & 0x00001000))
873 
874 #define CHIP_TIME(bp) ((CHIP_REV_IS_EMUL(bp)) ? 2000 : \
875  ((CHIP_REV_IS_FPGA(bp)) ? 200 : 1))
876 
877 #define CHIP_METAL(bp) (bp->common.chip_id & 0x00000ff0)
878 #define CHIP_BOND_ID(bp) (bp->common.chip_id & 0x0000000f)
879 #define CHIP_REV_SIM(bp) (((CHIP_REV_MASK - CHIP_REV_VAL(bp)) >>\
880  (CHIP_REV_SHIFT + 1)) \
881  << CHIP_REV_SHIFT)
882 #define CHIP_REV(bp) (CHIP_REV_IS_SLOW(bp) ? \
883  CHIP_REV_SIM(bp) :\
884  CHIP_REV_VAL(bp))
885 #define CHIP_IS_E3B0(bp) (CHIP_IS_E3(bp) && \
886  (CHIP_REV(bp) == CHIP_REV_Bx))
887 #define CHIP_IS_E3A0(bp) (CHIP_IS_E3(bp) && \
888  (CHIP_REV(bp) == CHIP_REV_Ax))
889 
891 #define BNX2X_NVRAM_1MB_SIZE 0x20000 /* 1M bit in bytes */
892 #define BNX2X_NVRAM_TIMEOUT_COUNT 30000
893 #define BNX2X_NVRAM_PAGE_SIZE 256
894 
899 
901 
903 
905 #define INT_BLOCK_HC 0
906 #define INT_BLOCK_IGU 1
907 #define INT_BLOCK_MODE_NORMAL 0
908 #define INT_BLOCK_MODE_BW_COMP 2
909 #define CHIP_INT_MODE_IS_NBC(bp) \
910  (!CHIP_IS_E1x(bp) && \
911  !((bp)->common.int_block & INT_BLOCK_MODE_BW_COMP))
912 #define CHIP_INT_MODE_IS_BC(bp) (!CHIP_INT_MODE_IS_NBC(bp))
913 
915 #define CHIP_4_PORT_MODE 0x0
916 #define CHIP_2_PORT_MODE 0x1
917 #define CHIP_PORT_MODE_NONE 0x2
918 #define CHIP_MODE(bp) (bp->common.chip_port_mode)
919 #define CHIP_MODE_IS_4_PORT(bp) (CHIP_MODE(bp) == CHIP_4_PORT_MODE)
920 
922 };
923 
924 /* IGU MSIX STATISTICS on 57712: 64 for VFs; 4 for PFs; 4 for Attentions */
925 #define BNX2X_IGU_STAS_MSG_VF_CNT 64
926 #define BNX2X_IGU_STAS_MSG_PF_CNT 4
927 
928 /* end of common */
929 
930 /* port */
931 
932 struct bnx2x_port {
934 
936 
938 /* link settings - missing defines */
939 #define SUPPORTED_2500baseX_Full (1 << 15)
940 
942 /* link settings - missing defines */
943 #define ADVERTISED_2500baseX_Full (1 << 15)
944 
946 
947  /* used to synchronize phy accesses */
948  struct mutex phy_mutex;
950 
952 
954 };
955 
956 /* end of port */
957 
958 #define STATS_OFFSET32(stat_name) \
959  (offsetof(struct bnx2x_eth_stats, stat_name) / 4)
960 
961 /* slow path */
962 
963 /* slow path work-queue */
964 extern struct workqueue_struct *bnx2x_wq;
965 
966 #define BNX2X_MAX_NUM_OF_VFS 64
967 #define BNX2X_VF_ID_INVALID 0xFF
968 
969 /*
970  * The total number of L2 queues, MSIX vectors and HW contexts (CIDs) is
971  * control by the number of fast-path status blocks supported by the
972  * device (HW/FW). Each fast-path status block (FP-SB) aka non-default
973  * status block represents an independent interrupts context that can
974  * serve a regular L2 networking queue. However special L2 queues such
975  * as the FCoE queue do not require a FP-SB and other components like
976  * the CNIC may consume FP-SB reducing the number of possible L2 queues
977  *
978  * If the maximum number of FP-SB available is X then:
979  * a. If CNIC is supported it consumes 1 FP-SB thus the max number of
980  * regular L2 queues is Y=X-1
981  * b. in MF mode the actual number of L2 queues is Y= (X-1/MF_factor)
982  * c. If the FCoE L2 queue is supported the actual number of L2 queues
983  * is Y+1
984  * d. The number of irqs (MSIX vectors) is either Y+1 (one extra for
985  * slow-path interrupts) or Y+2 if CNIC is supported (one additional
986  * FP interrupt context for the CNIC).
987  * e. The number of HW context (CID count) is always X or X+1 if FCoE
988  * L2 queue is supported. the cid for the FCoE L2 queue is always X.
989  */
990 
991 /* fast-path interrupt contexts E1x */
992 #define FP_SB_MAX_E1x 16
993 /* fast-path interrupt contexts E2 */
994 #define FP_SB_MAX_E2 HC_SB_MAX_SB_E2
995 
996 union cdu_context {
997  struct eth_context eth;
998  char pad[1024];
999 };
1000 
1001 /* CDU host DB constants */
1002 #define CDU_ILT_PAGE_SZ_HW 2
1003 #define CDU_ILT_PAGE_SZ (8192 << CDU_ILT_PAGE_SZ_HW) /* 32K */
1004 #define ILT_PAGE_CIDS (CDU_ILT_PAGE_SZ / sizeof(union cdu_context))
1005 
1006 #ifdef BCM_CNIC
1007 #define CNIC_ISCSI_CID_MAX 256
1008 #define CNIC_FCOE_CID_MAX 2048
1009 #define CNIC_CID_MAX (CNIC_ISCSI_CID_MAX + CNIC_FCOE_CID_MAX)
1010 #define CNIC_ILT_LINES DIV_ROUND_UP(CNIC_CID_MAX, ILT_PAGE_CIDS)
1011 #endif
1012 
1013 #define QM_ILT_PAGE_SZ_HW 0
1014 #define QM_ILT_PAGE_SZ (4096 << QM_ILT_PAGE_SZ_HW) /* 4K */
1015 #define QM_CID_ROUND 1024
1016 
1017 #ifdef BCM_CNIC
1018 /* TM (timers) host DB constants */
1019 #define TM_ILT_PAGE_SZ_HW 0
1020 #define TM_ILT_PAGE_SZ (4096 << TM_ILT_PAGE_SZ_HW) /* 4K */
1021 /* #define TM_CONN_NUM (CNIC_STARTING_CID+CNIC_ISCSI_CXT_MAX) */
1022 #define TM_CONN_NUM 1024
1023 #define TM_ILT_SZ (8 * TM_CONN_NUM)
1024 #define TM_ILT_LINES DIV_ROUND_UP(TM_ILT_SZ, TM_ILT_PAGE_SZ)
1025 
1026 /* SRC (Searcher) host DB constants */
1027 #define SRC_ILT_PAGE_SZ_HW 0
1028 #define SRC_ILT_PAGE_SZ (4096 << SRC_ILT_PAGE_SZ_HW) /* 4K */
1029 #define SRC_HASH_BITS 10
1030 #define SRC_CONN_NUM (1 << SRC_HASH_BITS) /* 1024 */
1031 #define SRC_ILT_SZ (sizeof(struct src_ent) * SRC_CONN_NUM)
1032 #define SRC_T2_SZ SRC_ILT_SZ
1033 #define SRC_ILT_LINES DIV_ROUND_UP(SRC_ILT_SZ, SRC_ILT_PAGE_SZ)
1034 
1035 #endif
1036 
1037 #define MAX_DMAE_C 8
1038 
1039 /* DMA memory not used in fastpath */
1041  union {
1044  } mac_rdata;
1045 
1046 
1047  union {
1050  } rx_mode_rdata;
1051 
1052  union {
1055  } mcast_rdata;
1056 
1058 
1059  /* Queue State related ramrods are always sent under rtnl_lock */
1060  union {
1063  } q_rdata;
1064 
1065  union {
1067  /* pfc configuration for DCBX ramrod */
1069  } func_rdata;
1070 
1071  /* afex ramrod can not be a part of func_rdata union because these
1072  * events might arrive in parallel to other events from func_rdata.
1073  * Therefore, if they would have been defined in the same union,
1074  * data can get corrupted.
1075  */
1077 
1078  /* used by dmae command executer */
1080 
1086 
1089 
1091 };
1092 
1093 #define bnx2x_sp(bp, var) (&bp->slowpath->var)
1094 #define bnx2x_sp_mapping(bp, var) \
1095  (bp->slowpath_mapping + offsetof(struct bnx2x_slowpath, var))
1096 
1097 
1098 /* attn group wiring */
1099 #define MAX_DYNAMIC_ATTN_GRPS 8
1100 
1101 struct attn_route {
1102  u32 sig[5];
1103 };
1104 
1105 struct iro {
1111 };
1112 
1113 struct hw_context {
1116  size_t size;
1117 };
1118 
1119 /* forward */
1120 struct bnx2x_ilt;
1121 
1122 
1129 };
1130 
1131 /*
1132  * Event queue (EQ or event ring) MC hsi
1133  * NUM_EQ_PAGES and EQ_DESC_CNT_PAGE must be power of 2
1134  */
1135 #define NUM_EQ_PAGES 1
1136 #define EQ_DESC_CNT_PAGE (BCM_PAGE_SIZE / sizeof(union event_ring_elem))
1137 #define EQ_DESC_MAX_PAGE (EQ_DESC_CNT_PAGE - 1)
1138 #define NUM_EQ_DESC (EQ_DESC_CNT_PAGE * NUM_EQ_PAGES)
1139 #define EQ_DESC_MASK (NUM_EQ_DESC - 1)
1140 #define MAX_EQ_AVAIL (EQ_DESC_MAX_PAGE * NUM_EQ_PAGES - 2)
1141 
1142 /* depends on EQ_DESC_CNT_PAGE being a power of 2 */
1143 #define NEXT_EQ_IDX(x) ((((x) & EQ_DESC_MAX_PAGE) == \
1144  (EQ_DESC_MAX_PAGE - 1)) ? (x) + 2 : (x) + 1)
1145 
1146 /* depends on the above and on NUM_EQ_PAGES being a power of 2 */
1147 #define EQ_DESC(x) ((x) & EQ_DESC_MASK)
1148 
1149 #define BNX2X_EQ_INDEX \
1150  (&bp->def_status_blk->sp_sb.\
1151  index_values[HC_SP_INDEX_EQ_CONS])
1152 
1153 /* This is a data that will be used to create a link report message.
1154  * We will keep the data used for the last link report in order
1155  * to prevent reporting the same link parameters twice.
1156  */
1158  u16 line_speed; /* Effective line speed */
1159  unsigned long link_report_flags;/* BNX2X_LINK_REPORT_XXX flags */
1160 };
1161 
1162 enum {
1163  BNX2X_LINK_REPORT_FD, /* Full DUPLEX */
1167 };
1168 
1169 enum {
1174 };
1175 
1180 };
1181 
1188 };
1189 
1190 /* Public slow path states */
1191 enum {
1196 };
1197 
1198 
1203  struct list_head list;
1204 };
1205 
1207  /* MACs object */
1209 
1210  /* Queue State object */
1212 };
1213 
1220 };
1221 
1222 struct bnx2x {
1223  /* Fields used in the tx and intr/napi performance paths
1224  * are grouped together in the beginning of the structure
1225  */
1234 
1235  u8 pf_num; /* absolute PF number */
1236  u8 pfid; /* per-path PF number */
1238 #define BP_PATH(bp) (CHIP_IS_E1x(bp) ? 0 : (bp->pf_num & 1))
1239 #define BP_PORT(bp) (bp->pfid & 1)
1240 #define BP_FUNC(bp) (bp->pfid)
1241 #define BP_ABS_FUNC(bp) (bp->pf_num)
1242 #define BP_VN(bp) ((bp)->pfid >> 1)
1243 #define BP_MAX_VN_NUM(bp) (CHIP_MODE_IS_4_PORT(bp) ? 2 : 4)
1244 #define BP_L_ID(bp) (BP_VN(bp) << 2)
1245 #define BP_FW_MB_IDX_VN(bp, vn) (BP_PORT(bp) +\
1246  (vn) * ((CHIP_IS_E1x(bp) || (CHIP_MODE_IS_4_PORT(bp))) ? 2 : 1))
1247 #define BP_FW_MB_IDX(bp) BP_FW_MB_IDX_VN(bp, BP_VN(bp))
1248 
1249  struct net_device *dev;
1250  struct pci_dev *pdev;
1251 
1252  const struct iro *iro_arr;
1253 #define IRO (bp->iro_arr)
1254 
1257  struct msix_entry *msix_table;
1258 
1260 
1261 /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
1262 #define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
1263 #define ETH_MIN_PACKET_SIZE 60
1264 #define ETH_MAX_PACKET_SIZE 1500
1265 #define ETH_MAX_JUMBO_PACKET_SIZE 9600
1266 /* TCP with Timestamp Option (32) + IPv6 (40) */
1267 #define ETH_MAX_TPA_HEADER_SIZE 72
1268 
1269  /* Max supported alignment is 256 (8 shift) */
1270 #define BNX2X_RX_ALIGN_SHIFT min(8, L1_CACHE_SHIFT)
1271 
1272  /* FW uses 2 Cache lines Alignment for start packet and size
1273  *
1274  * We assume skb_build() uses sizeof(struct skb_shared_info) bytes
1275  * at the end of skb->data, to avoid wasting a full cache line.
1276  * This reduces memory use (skb->truesize).
1277  */
1278 #define BNX2X_FW_RX_ALIGN_START (1UL << BNX2X_RX_ALIGN_SHIFT)
1279 
1280 #define BNX2X_FW_RX_ALIGN_END \
1281  max_t(u64, 1UL << BNX2X_RX_ALIGN_SHIFT, \
1282  SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
1283 
1284 #define BNX2X_PXP_DRAM_ALIGN (BNX2X_RX_ALIGN_SHIFT - 5)
1285 
1287 #define DEF_SB_IGU_ID 16
1288 #define DEF_SB_ID HC_SP_SB_ID
1293 
1294  /* slow path ring */
1295  struct eth_spe *spq;
1301  atomic_t cq_spq_left; /* ETH_XXX ramrods credit */
1302  /* used to synchronize spq accesses */
1304 
1305  /* event queue */
1311  atomic_t eq_spq_left; /* COMMON_XXX ramrods credit */
1312 
1313 
1314 
1315  /* Counter for marking that there is a STAT_QUERY ramrod pending */
1317  /* Counter for completed statistics ramrods */
1319 
1320  /* End of fields used in the performance code paths */
1321 
1322  int panic;
1324 
1326 #define PCIX_FLAG (1 << 0)
1327 #define PCI_32BIT_FLAG (1 << 1)
1328 #define ONE_PORT_FLAG (1 << 2)
1329 #define NO_WOL_FLAG (1 << 3)
1330 #define USING_DAC_FLAG (1 << 4)
1331 #define USING_MSIX_FLAG (1 << 5)
1332 #define USING_MSI_FLAG (1 << 6)
1333 #define DISABLE_MSI_FLAG (1 << 7)
1334 #define TPA_ENABLE_FLAG (1 << 8)
1335 #define NO_MCP_FLAG (1 << 9)
1336 
1337 #define BP_NOMCP(bp) (bp->flags & NO_MCP_FLAG)
1338 #define GRO_ENABLE_FLAG (1 << 10)
1339 #define MF_FUNC_DIS (1 << 11)
1340 #define OWN_CNIC_IRQ (1 << 12)
1341 #define NO_ISCSI_OOO_FLAG (1 << 13)
1342 #define NO_ISCSI_FLAG (1 << 14)
1343 #define NO_FCOE_FLAG (1 << 15)
1344 #define BC_SUPPORTS_PFC_STATS (1 << 17)
1345 #define BC_SUPPORTS_FCOE_FEATURES (1 << 19)
1346 #define USING_SINGLE_MSIX_FLAG (1 << 20)
1347 #define BC_SUPPORTS_DCBX_MSG_NON_PMF (1 << 21)
1348 
1349 #define NO_ISCSI(bp) ((bp)->flags & NO_ISCSI_FLAG)
1350 #define NO_ISCSI_OOO(bp) ((bp)->flags & NO_ISCSI_OOO_FLAG)
1351 #define NO_FCOE(bp) ((bp)->flags & NO_FCOE_FLAG)
1352 
1353  int pm_cap;
1354  int mrrs;
1355 
1358 
1362 
1366 
1371 
1373 
1376 
1377  struct cmng_init cmng;
1378 
1384 #define IS_MF(bp) (bp->mf_mode != 0)
1385 #define IS_MF_SI(bp) (bp->mf_mode == MULTI_FUNCTION_SI)
1386 #define IS_MF_SD(bp) (bp->mf_mode == MULTI_FUNCTION_SD)
1387 #define IS_MF_AFEX(bp) (bp->mf_mode == MULTI_FUNCTION_AFEX)
1388 
1390 
1392 
1397 
1402 /* Maximal coalescing timeout in us */
1403 #define BNX2X_MAX_COALESCE_TOUT (0xf0*12)
1404 
1406 
1408 #define BNX2X_STATE_CLOSED 0
1409 #define BNX2X_STATE_OPENING_WAIT4_LOAD 0x1000
1410 #define BNX2X_STATE_OPENING_WAIT4_PORT 0x2000
1411 #define BNX2X_STATE_OPEN 0x3000
1412 #define BNX2X_STATE_CLOSING_WAIT4_HALT 0x4000
1413 #define BNX2X_STATE_CLOSING_WAIT4_DELETE 0x5000
1414 
1415 #define BNX2X_STATE_DIAG 0xe000
1416 #define BNX2X_STATE_ERROR 0xf000
1417 
1418 #define BNX2X_MAX_PRIORITY 8
1419 #define BNX2X_MAX_ENTRIES_PER_PRI 16
1420 #define BNX2X_MAX_COS 3
1421 #define BNX2X_MAX_TX_COS 2
1425 
1427 #define BNX2X_RX_MODE_NONE 0
1428 #define BNX2X_RX_MODE_NORMAL 1
1429 #define BNX2X_RX_MODE_ALLMULTI 2
1430 #define BNX2X_RX_MODE_PROMISC 3
1431 #define BNX2X_MAX_MULTICAST 64
1432 
1436 
1438 
1441 
1442  /* Total number of FW statistics requests */
1444 
1445  /*
1446  * This is a memory buffer that will contain both statistics
1447  * ramrod request and data.
1448  */
1449  void *fw_stats;
1451 
1452  /*
1453  * FW statistics request shortcut (points at the
1454  * beginning of fw_stats buffer).
1455  */
1459 
1460  /*
1461  * FW statistics data shortcut (points at the beginning of
1462  * fw_stats buffer + fw_stats_req_sz).
1463  */
1467 
1468  /* For max 196 cids (64*3 + non-eth), 32KB ILT page size and 1KB
1469  * context size we need 8 ILT entries.
1470  */
1471 #define ILT_MAX_L2_LINES 8
1473 
1474  struct bnx2x_ilt *ilt;
1475 #define BP_ILT(bp) ((bp)->ilt)
1476 #define ILT_MAX_LINES 256
1477 /*
1478  * Maximum supported number of RSS queues: number of IGU SBs minus one that goes
1479  * to CNIC.
1480  */
1481 #define BNX2X_MAX_RSS_COUNT(bp) ((bp)->igu_sb_cnt - CNIC_PRESENT)
1482 
1483 /*
1484  * Maximum CID count that might be required by the bnx2x:
1485  * Max RSS * Max_Tx_Multi_Cos + FCoE + iSCSI
1486  */
1487 #define BNX2X_L2_CID_COUNT(bp) (BNX2X_NUM_ETH_QUEUES(bp) * BNX2X_MULTI_TX_COS \
1488  + NON_ETH_CONTEXT_USE + CNIC_PRESENT)
1489 #define BNX2X_L2_MAX_CID(bp) (BNX2X_MAX_RSS_COUNT(bp) * BNX2X_MULTI_TX_COS \
1490  + NON_ETH_CONTEXT_USE + CNIC_PRESENT)
1491 #define L2_ILT_LINES(bp) (DIV_ROUND_UP(BNX2X_L2_CID_COUNT(bp),\
1492  ILT_PAGE_CIDS))
1493 
1495 
1497 
1498 #ifdef BCM_CNIC
1499  u32 cnic_flags;
1500 #define BNX2X_CNIC_FLAG_MAC_SET 1
1501  void *t2;
1502  dma_addr_t t2_mapping;
1503  struct cnic_ops __rcu *cnic_ops;
1504  void *cnic_data;
1505  u32 cnic_tag;
1506  struct cnic_eth_dev cnic_eth_dev;
1507  union host_hc_status_block cnic_sb;
1508  dma_addr_t cnic_sb_mapping;
1509  struct eth_spe *cnic_kwq;
1510  struct eth_spe *cnic_kwq_prod;
1511  struct eth_spe *cnic_kwq_cons;
1512  struct eth_spe *cnic_kwq_last;
1513  u16 cnic_kwq_pending;
1514  u16 cnic_spq_pending;
1515  u8 fip_mac[ETH_ALEN];
1516  struct mutex cnic_mutex;
1517  struct bnx2x_vlan_mac_obj iscsi_l2_mac_obj;
1518 
1519  /* Start index of the "special" (CNIC related) L2 cleints */
1520  u8 cnic_base_cl_id;
1521 #endif
1522 
1524  /* used to synchronize dmae accesses */
1526 
1527  /* used to protect the FW mail box */
1529 
1530  /* used to synchronize stats collecting */
1532 
1533  /* used for synchronization of concurrent threads statistics handling */
1535 
1536  /* used by dmae command loader */
1539 
1547 
1548  struct z_stream_s *strm;
1549  void *gunzip_buf;
1552 #define FW_BUF_SIZE 0x8000
1553 #define GUNZIP_BUF(bp) (bp->gunzip_buf)
1554 #define GUNZIP_PHYS(bp) (bp->gunzip_mapping)
1555 #define GUNZIP_OUTLEN(bp) (bp->gunzip_outlen)
1556 
1557  struct raw_op *init_ops;
1558  /* Init blocks offsets inside init_ops */
1560  /* Data blob - has 32 bit granularity */
1563 #define INIT_MODE_FLAGS(bp) (bp->init_mode_flags)
1564  /* Zipped PRAM blobs - raw data */
1573 #define INIT_OPS(bp) (bp->init_ops)
1574 #define INIT_OPS_OFFSETS(bp) (bp->init_ops_offsets)
1575 #define INIT_DATA(bp) (bp->init_data)
1576 #define INIT_TSEM_INT_TABLE_DATA(bp) (bp->tsem_int_table_data)
1577 #define INIT_TSEM_PRAM_DATA(bp) (bp->tsem_pram_data)
1578 #define INIT_USEM_INT_TABLE_DATA(bp) (bp->usem_int_table_data)
1579 #define INIT_USEM_PRAM_DATA(bp) (bp->usem_pram_data)
1580 #define INIT_XSEM_INT_TABLE_DATA(bp) (bp->xsem_int_table_data)
1581 #define INIT_XSEM_PRAM_DATA(bp) (bp->xsem_pram_data)
1582 #define INIT_CSEM_INT_TABLE_DATA(bp) (bp->csem_int_table_data)
1583 #define INIT_CSEM_PRAM_DATA(bp) (bp->csem_pram_data)
1584 
1585 #define PHY_FW_VER_LEN 20
1586  char fw_ver[32];
1587  const struct firmware *firmware;
1588 
1589  /* DCB support on/off */
1591 #define BNX2X_DCB_STATE_OFF 0
1592 #define BNX2X_DCB_STATE_ON 1
1593 
1594  /* DCBX engine mode */
1596 #define BNX2X_DCBX_ENABLED_OFF 0
1597 #define BNX2X_DCBX_ENABLED_ON_NEG_OFF 1
1598 #define BNX2X_DCBX_ENABLED_ON_NEG_ON 2
1599 #define BNX2X_DCBX_ENABLED_INVALID (-1)
1600 
1602 
1606 
1607  /* CAM credit pools */
1609 
1610  /* RX_MODE object */
1612 
1613  /* MCAST object */
1615 
1616  /* RSS configuration object */
1618 
1619  /* Function State controlling object */
1621 
1622  unsigned long sp_state;
1623 
1624  /* operation indication for the sp_rtnl task */
1625  unsigned long sp_rtnl_state;
1626 
1627  /* DCBX Negotation results */
1630 
1631 #ifdef BCM_DCBNL
1632  struct dcbx_features dcbx_remote_feat;
1633  u32 dcbx_remote_flags;
1634 #endif
1635  /* AFEX: store default vlan used */
1639 
1640  /* multiple tx classes of service */
1642 
1643  /* priority to cos mapping */
1645 };
1646 
1647 /* Tx queues may be less or equal to Rx queues */
1648 extern int num_queues;
1649 #define BNX2X_NUM_QUEUES(bp) (bp->num_queues)
1650 #define BNX2X_NUM_ETH_QUEUES(bp) (BNX2X_NUM_QUEUES(bp) - NON_ETH_CONTEXT_USE)
1651 #define BNX2X_NUM_NON_CNIC_QUEUES(bp) (BNX2X_NUM_QUEUES(bp) - \
1652  NON_ETH_CONTEXT_USE)
1653 #define BNX2X_NUM_RX_QUEUES(bp) BNX2X_NUM_QUEUES(bp)
1654 
1655 #define is_multi(bp) (BNX2X_NUM_QUEUES(bp) > 1)
1656 
1657 #define BNX2X_MAX_QUEUES(bp) BNX2X_MAX_RSS_COUNT(bp)
1658 /* #define is_eth_multi(bp) (BNX2X_NUM_ETH_QUEUES(bp) > 1) */
1659 
1660 #define RSS_IPV4_CAP_MASK \
1661  TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY
1662 
1663 #define RSS_IPV4_TCP_CAP_MASK \
1664  TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY
1665 
1666 #define RSS_IPV6_CAP_MASK \
1667  TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY
1668 
1669 #define RSS_IPV6_TCP_CAP_MASK \
1670  TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY
1671 
1672 /* func init flags */
1673 #define FUNC_FLG_RSS 0x0001
1674 #define FUNC_FLG_STATS 0x0002
1675 /* removed FUNC_FLG_UNMATCHED 0x0004 */
1676 #define FUNC_FLG_TPA 0x0008
1677 #define FUNC_FLG_SPQ 0x0010
1678 #define FUNC_FLG_LEADING 0x0020 /* PF only */
1679 
1680 
1682  /* dma */
1683  dma_addr_t fw_stat_map; /* valid iff FUNC_FLG_STATS */
1684  dma_addr_t spq_map; /* valid iff FUNC_FLG_SPQ */
1685 
1687  u16 func_id; /* abs fid */
1689  u16 spq_prod; /* valid iff FUNC_FLG_SPQ */
1690 };
1691 
1692 #define for_each_eth_queue(bp, var) \
1693  for ((var) = 0; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
1694 
1695 #define for_each_nondefault_eth_queue(bp, var) \
1696  for ((var) = 1; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
1697 
1698 #define for_each_queue(bp, var) \
1699  for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
1700  if (skip_queue(bp, var)) \
1701  continue; \
1702  else
1703 
1704 /* Skip forwarding FP */
1705 #define for_each_rx_queue(bp, var) \
1706  for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
1707  if (skip_rx_queue(bp, var)) \
1708  continue; \
1709  else
1710 
1711 /* Skip OOO FP */
1712 #define for_each_tx_queue(bp, var) \
1713  for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
1714  if (skip_tx_queue(bp, var)) \
1715  continue; \
1716  else
1717 
1718 #define for_each_nondefault_queue(bp, var) \
1719  for ((var) = 1; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
1720  if (skip_queue(bp, var)) \
1721  continue; \
1722  else
1723 
1724 #define for_each_cos_in_tx_queue(fp, var) \
1725  for ((var) = 0; (var) < (fp)->max_cos; (var)++)
1726 
1727 /* skip rx queue
1728  * if FCOE l2 support is disabled and this is the fcoe L2 queue
1729  */
1730 #define skip_rx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
1731 
1732 /* skip tx queue
1733  * if FCOE l2 support is disabled and this is the fcoe L2 queue
1734  */
1735 #define skip_tx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
1736 
1737 #define skip_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
1738 
1739 
1740 
1741 
1760 int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
1761  struct bnx2x_vlan_mac_obj *obj, bool set,
1762  int mac_type, unsigned long *ramrod_flags);
1777 int bnx2x_del_all_macs(struct bnx2x *bp,
1778  struct bnx2x_vlan_mac_obj *mac_obj,
1779  int mac_type, bool wait_for_comp);
1780 
1781 /* Init Function API */
1782 void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p);
1783 int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port);
1784 int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
1785 int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode);
1786 int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
1787 void bnx2x_read_mf_cfg(struct bnx2x *bp);
1788 
1789 
1790 /* dmae */
1791 void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
1793  u32 len32);
1794 void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx);
1797 u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
1798  bool with_comp, u8 comp_type);
1799 
1800 
1801 void bnx2x_calc_fc_adv(struct bnx2x *bp);
1802 int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
1803  u32 data_hi, u32 data_lo, int cmd_type);
1804 void bnx2x_update_coalesce(struct bnx2x *bp);
1805 int bnx2x_get_cur_phy_idx(struct bnx2x *bp);
1806 
1807 static inline u32 reg_poll(struct bnx2x *bp, u32 reg, u32 expected, int ms,
1808  int wait)
1809 {
1810  u32 val;
1811 
1812  do {
1813  val = REG_RD(bp, reg);
1814  if (val == expected)
1815  break;
1816  ms -= wait;
1817  msleep(wait);
1818 
1819  } while (ms > 0);
1820 
1821  return val;
1822 }
1823 
1824 #define BNX2X_ILT_ZALLOC(x, y, size) \
1825  do { \
1826  x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
1827  if (x) \
1828  memset(x, 0, size); \
1829  } while (0)
1830 
1831 #define BNX2X_ILT_FREE(x, y, size) \
1832  do { \
1833  if (x) { \
1834  dma_free_coherent(&bp->pdev->dev, size, x, y); \
1835  x = NULL; \
1836  y = 0; \
1837  } \
1838  } while (0)
1839 
1840 #define ILOG2(x) (ilog2((x)))
1841 
1842 #define ILT_NUM_PAGE_ENTRIES (3072)
1843 /* In 57710/11 we use whole table since we have 8 func
1844  * In 57712 we have only 4 func, but use same size per func, then only half of
1845  * the table in use
1846  */
1847 #define ILT_PER_FUNC (ILT_NUM_PAGE_ENTRIES/8)
1848 
1849 #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
1850 /*
1851  * the phys address is shifted right 12 bits and has an added
1852  * 1=valid bit added to the 53rd bit
1853  * then since this is a wide register(TM)
1854  * we split it into two 32 bit writes
1855  */
1856 #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
1857 #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
1858 
1859 /* load/unload mode */
1860 #define LOAD_NORMAL 0
1861 #define LOAD_OPEN 1
1862 #define LOAD_DIAG 2
1863 #define LOAD_LOOPBACK_EXT 3
1864 #define UNLOAD_NORMAL 0
1865 #define UNLOAD_CLOSE 1
1866 #define UNLOAD_RECOVERY 2
1867 
1868 
1869 /* DMAE command defines */
1870 #define DMAE_TIMEOUT -1
1871 #define DMAE_PCI_ERROR -2 /* E2 and onward */
1872 #define DMAE_NOT_RDY -3
1873 #define DMAE_PCI_ERR_FLAG 0x80000000
1874 
1875 #define DMAE_SRC_PCI 0
1876 #define DMAE_SRC_GRC 1
1877 
1878 #define DMAE_DST_NONE 0
1879 #define DMAE_DST_PCI 1
1880 #define DMAE_DST_GRC 2
1881 
1882 #define DMAE_COMP_PCI 0
1883 #define DMAE_COMP_GRC 1
1884 
1885 /* E2 and onward - PCI error handling in the completion */
1886 
1887 #define DMAE_COMP_REGULAR 0
1888 #define DMAE_COM_SET_ERR 1
1889 
1890 #define DMAE_CMD_SRC_PCI (DMAE_SRC_PCI << \
1891  DMAE_COMMAND_SRC_SHIFT)
1892 #define DMAE_CMD_SRC_GRC (DMAE_SRC_GRC << \
1893  DMAE_COMMAND_SRC_SHIFT)
1894 
1895 #define DMAE_CMD_DST_PCI (DMAE_DST_PCI << \
1896  DMAE_COMMAND_DST_SHIFT)
1897 #define DMAE_CMD_DST_GRC (DMAE_DST_GRC << \
1898  DMAE_COMMAND_DST_SHIFT)
1899 
1900 #define DMAE_CMD_C_DST_PCI (DMAE_COMP_PCI << \
1901  DMAE_COMMAND_C_DST_SHIFT)
1902 #define DMAE_CMD_C_DST_GRC (DMAE_COMP_GRC << \
1903  DMAE_COMMAND_C_DST_SHIFT)
1904 
1905 #define DMAE_CMD_C_ENABLE DMAE_COMMAND_C_TYPE_ENABLE
1906 
1907 #define DMAE_CMD_ENDIANITY_NO_SWAP (0 << DMAE_COMMAND_ENDIANITY_SHIFT)
1908 #define DMAE_CMD_ENDIANITY_B_SWAP (1 << DMAE_COMMAND_ENDIANITY_SHIFT)
1909 #define DMAE_CMD_ENDIANITY_DW_SWAP (2 << DMAE_COMMAND_ENDIANITY_SHIFT)
1910 #define DMAE_CMD_ENDIANITY_B_DW_SWAP (3 << DMAE_COMMAND_ENDIANITY_SHIFT)
1911 
1912 #define DMAE_CMD_PORT_0 0
1913 #define DMAE_CMD_PORT_1 DMAE_COMMAND_PORT
1914 
1915 #define DMAE_CMD_SRC_RESET DMAE_COMMAND_SRC_RESET
1916 #define DMAE_CMD_DST_RESET DMAE_COMMAND_DST_RESET
1917 #define DMAE_CMD_E1HVN_SHIFT DMAE_COMMAND_E1HVN_SHIFT
1918 
1919 #define DMAE_SRC_PF 0
1920 #define DMAE_SRC_VF 1
1921 
1922 #define DMAE_DST_PF 0
1923 #define DMAE_DST_VF 1
1924 
1925 #define DMAE_C_SRC 0
1926 #define DMAE_C_DST 1
1927 
1928 #define DMAE_LEN32_RD_MAX 0x80
1929 #define DMAE_LEN32_WR_MAX(bp) (CHIP_IS_E1(bp) ? 0x400 : 0x2000)
1930 
1931 #define DMAE_COMP_VAL 0x60d0d0ae /* E2 and on - upper bit
1932  indicates eror */
1934 #define MAX_DMAE_C_PER_PORT 8
1935 #define INIT_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
1936  BP_VN(bp))
1937 #define PMF_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
1938  E1HVN_MAX)
1939 
1940 /* PCIE link and speed */
1941 #define PCICFG_LINK_WIDTH 0x1f00000
1942 #define PCICFG_LINK_WIDTH_SHIFT 20
1943 #define PCICFG_LINK_SPEED 0xf0000
1944 #define PCICFG_LINK_SPEED_SHIFT 16
1946 #define BNX2X_NUM_TESTS_SF 7
1947 #define BNX2X_NUM_TESTS_MF 3
1948 #define BNX2X_NUM_TESTS(bp) (IS_MF(bp) ? BNX2X_NUM_TESTS_MF : \
1949  BNX2X_NUM_TESTS_SF)
1951 #define BNX2X_PHY_LOOPBACK 0
1952 #define BNX2X_MAC_LOOPBACK 1
1953 #define BNX2X_EXT_LOOPBACK 2
1954 #define BNX2X_PHY_LOOPBACK_FAILED 1
1955 #define BNX2X_MAC_LOOPBACK_FAILED 2
1956 #define BNX2X_EXT_LOOPBACK_FAILED 3
1957 #define BNX2X_LOOPBACK_FAILED (BNX2X_MAC_LOOPBACK_FAILED | \
1958  BNX2X_PHY_LOOPBACK_FAILED)
1959 
1961 #define STROM_ASSERT_ARRAY_SIZE 50
1962 
1963 
1964 /* must be used on a CID before placing it on a HW ring */
1965 #define HW_CID(bp, x) ((BP_PORT(bp) << 23) | \
1966  (BP_VN(bp) << BNX2X_SWCID_SHIFT) | \
1967  (x))
1969 #define SP_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_spe))
1970 #define MAX_SP_DESC_CNT (SP_DESC_CNT - 1)
1971 
1973 #define BNX2X_BTR 4
1974 #define MAX_SPQ_PENDING 8
1975 
1976 /* CMNG constants, as derived from system spec calculations */
1977 /* default MIN rate in case VNIC min rate is configured to zero - 100Mbps */
1978 #define DEF_MIN_RATE 100
1979 /* resolution of the rate shaping timer - 400 usec */
1980 #define RS_PERIODIC_TIMEOUT_USEC 400
1981 /* number of bytes in single QM arbitration cycle -
1982  * coefficient for calculating the fairness timer */
1983 #define QM_ARB_BYTES 160000
1984 /* resolution of Min algorithm 1:100 */
1985 #define MIN_RES 100
1986 /* how many bytes above threshold for the minimal credit of Min algorithm*/
1987 #define MIN_ABOVE_THRESH 32768
1988 /* Fairness algorithm integration time coefficient -
1989  * for calculating the actual Tfair */
1990 #define T_FAIR_COEF ((MIN_ABOVE_THRESH + QM_ARB_BYTES) * 8 * MIN_RES)
1991 /* Memory of fairness algorithm . 2 cycles */
1992 #define FAIR_MEM 2
1993 
1995 #define ATTN_NIG_FOR_FUNC (1L << 8)
1996 #define ATTN_SW_TIMER_4_FUNC (1L << 9)
1997 #define GPIO_2_FUNC (1L << 10)
1998 #define GPIO_3_FUNC (1L << 11)
1999 #define GPIO_4_FUNC (1L << 12)
2000 #define ATTN_GENERAL_ATTN_1 (1L << 13)
2001 #define ATTN_GENERAL_ATTN_2 (1L << 14)
2002 #define ATTN_GENERAL_ATTN_3 (1L << 15)
2003 #define ATTN_GENERAL_ATTN_4 (1L << 13)
2004 #define ATTN_GENERAL_ATTN_5 (1L << 14)
2005 #define ATTN_GENERAL_ATTN_6 (1L << 15)
2007 #define ATTN_HARD_WIRED_MASK 0xff00
2008 #define ATTENTION_ID 4
2009 
2010 
2011 /* stuff added to make the code fit 80Col */
2013 #define BNX2X_PMF_LINK_ASSERT \
2014  GENERAL_ATTEN_OFFSET(LINK_SYNC_ATTENTION_BIT_FUNC_0 + BP_FUNC(bp))
2016 #define BNX2X_MC_ASSERT_BITS \
2017  (GENERAL_ATTEN_OFFSET(TSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
2018  GENERAL_ATTEN_OFFSET(USTORM_FATAL_ASSERT_ATTENTION_BIT) | \
2019  GENERAL_ATTEN_OFFSET(CSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
2020  GENERAL_ATTEN_OFFSET(XSTORM_FATAL_ASSERT_ATTENTION_BIT))
2022 #define BNX2X_MCP_ASSERT \
2023  GENERAL_ATTEN_OFFSET(MCP_FATAL_ASSERT_ATTENTION_BIT)
2025 #define BNX2X_GRC_TIMEOUT GENERAL_ATTEN_OFFSET(LATCHED_ATTN_TIMEOUT_GRC)
2026 #define BNX2X_GRC_RSV (GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCR) | \
2027  GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCT) | \
2028  GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCN) | \
2029  GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCU) | \
2030  GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCP) | \
2031  GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RSVD_GRC))
2033 #define HW_INTERRUT_ASSERT_SET_0 \
2034  (AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT | \
2035  AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT | \
2036  AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT | \
2037  AEU_INPUTS_ATTN_BITS_PBCLIENT_HW_INTERRUPT)
2038 #define HW_PRTY_ASSERT_SET_0 (AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR | \
2039  AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR | \
2040  AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR | \
2041  AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR |\
2042  AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR |\
2043  AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR |\
2044  AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR)
2045 #define HW_INTERRUT_ASSERT_SET_1 \
2046  (AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT | \
2047  AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT | \
2048  AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT | \
2049  AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT | \
2050  AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT | \
2051  AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT | \
2052  AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT | \
2053  AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT | \
2054  AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT | \
2055  AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT | \
2056  AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT)
2057 #define HW_PRTY_ASSERT_SET_1 (AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR |\
2058  AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR | \
2059  AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR |\
2060  AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR | \
2061  AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR |\
2062  AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR | \
2063  AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR |\
2064  AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR |\
2065  AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR |\
2066  AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR | \
2067  AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR | \
2068  AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR |\
2069  AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR | \
2070  AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR | \
2071  AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR |\
2072  AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR)
2073 #define HW_INTERRUT_ASSERT_SET_2 \
2074  (AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT | \
2075  AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT | \
2076  AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT | \
2077  AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT |\
2078  AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT)
2079 #define HW_PRTY_ASSERT_SET_2 (AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR | \
2080  AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR | \
2081  AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR |\
2082  AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR | \
2083  AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR | \
2084  AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR |\
2085  AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR | \
2086  AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR)
2088 #define HW_PRTY_ASSERT_SET_3 (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
2089  AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
2090  AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY | \
2091  AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
2093 #define HW_PRTY_ASSERT_SET_4 (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | \
2094  AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)
2096 #define MULTI_MASK 0x7f
2097 
2099 #define DEF_USB_FUNC_OFF offsetof(struct cstorm_def_status_block_u, func)
2100 #define DEF_CSB_FUNC_OFF offsetof(struct cstorm_def_status_block_c, func)
2101 #define DEF_XSB_FUNC_OFF offsetof(struct xstorm_def_status_block, func)
2102 #define DEF_TSB_FUNC_OFF offsetof(struct tstorm_def_status_block, func)
2104 #define DEF_USB_IGU_INDEX_OFF \
2105  offsetof(struct cstorm_def_status_block_u, igu_index)
2106 #define DEF_CSB_IGU_INDEX_OFF \
2107  offsetof(struct cstorm_def_status_block_c, igu_index)
2108 #define DEF_XSB_IGU_INDEX_OFF \
2109  offsetof(struct xstorm_def_status_block, igu_index)
2110 #define DEF_TSB_IGU_INDEX_OFF \
2111  offsetof(struct tstorm_def_status_block, igu_index)
2113 #define DEF_USB_SEGMENT_OFF \
2114  offsetof(struct cstorm_def_status_block_u, segment)
2115 #define DEF_CSB_SEGMENT_OFF \
2116  offsetof(struct cstorm_def_status_block_c, segment)
2117 #define DEF_XSB_SEGMENT_OFF \
2118  offsetof(struct xstorm_def_status_block, segment)
2119 #define DEF_TSB_SEGMENT_OFF \
2120  offsetof(struct tstorm_def_status_block, segment)
2122 #define BNX2X_SP_DSB_INDEX \
2123  (&bp->def_status_blk->sp_sb.\
2124  index_values[HC_SP_INDEX_ETH_DEF_CONS])
2126 #define SET_FLAG(value, mask, flag) \
2127  do {\
2128  (value) &= ~(mask);\
2129  (value) |= ((flag) << (mask##_SHIFT));\
2130  } while (0)
2132 #define GET_FLAG(value, mask) \
2133  (((value) & (mask)) >> (mask##_SHIFT))
2135 #define GET_FIELD(value, fname) \
2136  (((value) & (fname##_MASK)) >> (fname##_SHIFT))
2138 #define CAM_IS_INVALID(x) \
2139  (GET_FLAG(x.flags, \
2140  MAC_CONFIGURATION_ENTRY_ACTION_TYPE) == \
2141  (T_ETH_MAC_COMMAND_INVALIDATE))
2142 
2143 /* Number of u32 elements in MC hash array */
2144 #define MC_HASH_SIZE 8
2145 #define MC_HASH_OFFSET(bp, i) (BAR_TSTRORM_INTMEM + \
2146  TSTORM_APPROXIMATE_MATCH_MULTICAST_FILTERING_OFFSET(BP_FUNC(bp)) + i*4)
2147 
2148 
2149 #ifndef PXP2_REG_PXP2_INT_STS
2150 #define PXP2_REG_PXP2_INT_STS PXP2_REG_PXP2_INT_STS_0
2151 #endif
2152 
2153 #ifndef ETH_MAX_RX_CLIENTS_E2
2154 #define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
2155 #endif
2157 #define BNX2X_VPD_LEN 128
2158 #define VENDOR_ID_LEN 4
2159 
2160 /* Congestion management fairness mode */
2161 #define CMNG_FNS_NONE 0
2162 #define CMNG_FNS_MINMAX 1
2164 #define HC_SEG_ACCESS_DEF 0 /*Driver decision 0-3*/
2165 #define HC_SEG_ACCESS_ATTN 4
2166 #define HC_SEG_ACCESS_NORM 0 /*Driver decision 0-1*/
2167 
2168 static const u32 dmae_reg_go_c[] = {
2173 };
2174 
2175 void bnx2x_set_ethtool_ops(struct net_device *netdev);
2176 void bnx2x_notify_link_changed(struct bnx2x *bp);
2177 
2179 #define BNX2X_MF_SD_PROTOCOL(bp) \
2180  ((bp)->mf_config[BP_VN(bp)] & FUNC_MF_CFG_PROTOCOL_MASK)
2181 
2182 #ifdef BCM_CNIC
2183 #define BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp) \
2184  (BNX2X_MF_SD_PROTOCOL(bp) == FUNC_MF_CFG_PROTOCOL_ISCSI)
2185 
2186 #define BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) \
2187  (BNX2X_MF_SD_PROTOCOL(bp) == FUNC_MF_CFG_PROTOCOL_FCOE)
2188 
2189 #define IS_MF_ISCSI_SD(bp) (IS_MF_SD(bp) && BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp))
2190 #define IS_MF_FCOE_SD(bp) (IS_MF_SD(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))
2191 
2192 #define BNX2X_MF_EXT_PROTOCOL_FCOE(bp) ((bp)->mf_ext_config & \
2193  MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
2194 
2195 #define IS_MF_FCOE_AFEX(bp) (IS_MF_AFEX(bp) && BNX2X_MF_EXT_PROTOCOL_FCOE(bp))
2196 #define IS_MF_STORAGE_SD(bp) (IS_MF_SD(bp) && \
2197  (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp) || \
2198  BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
2199 #else
2200 #define IS_MF_FCOE_AFEX(bp) false
2201 #endif
2202 
2203 
2204 #endif /* bnx2x.h */