bnx2x.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  1. /* bnx2x.h: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2010 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 <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. */
  13. #ifndef BNX2X_H
  14. #define BNX2X_H
  15. #include <linux/netdevice.h>
  16. #include <linux/types.h>
  17. /* compilation time flags */
  18. /* define this to make the driver freeze on error to allow getting debug info
  19. * (you will need to reboot afterwards) */
  20. /* #define BNX2X_STOP_ON_ERROR */
  21. #define DRV_MODULE_VERSION "1.60.00-7"
  22. #define DRV_MODULE_RELDATE "2010/12/08"
  23. #define BNX2X_BC_VER 0x040200
  24. #define BNX2X_MULTI_QUEUE
  25. #define BNX2X_NEW_NAPI
  26. #if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
  27. #define BCM_CNIC 1
  28. #include "../cnic_if.h"
  29. #endif
  30. #ifdef BCM_CNIC
  31. #define BNX2X_MIN_MSIX_VEC_CNT 3
  32. #define BNX2X_MSIX_VEC_FP_START 2
  33. #else
  34. #define BNX2X_MIN_MSIX_VEC_CNT 2
  35. #define BNX2X_MSIX_VEC_FP_START 1
  36. #endif
  37. #include <linux/mdio.h>
  38. #include <linux/pci.h>
  39. #include "bnx2x_reg.h"
  40. #include "bnx2x_fw_defs.h"
  41. #include "bnx2x_hsi.h"
  42. #include "bnx2x_link.h"
  43. #include "bnx2x_dcb.h"
  44. #include "bnx2x_stats.h"
  45. /* error/debug prints */
  46. #define DRV_MODULE_NAME "bnx2x"
  47. /* for messages that are currently off */
  48. #define BNX2X_MSG_OFF 0
  49. #define BNX2X_MSG_MCP 0x010000 /* was: NETIF_MSG_HW */
  50. #define BNX2X_MSG_STATS 0x020000 /* was: NETIF_MSG_TIMER */
  51. #define BNX2X_MSG_NVM 0x040000 /* was: NETIF_MSG_HW */
  52. #define BNX2X_MSG_DMAE 0x080000 /* was: NETIF_MSG_HW */
  53. #define BNX2X_MSG_SP 0x100000 /* was: NETIF_MSG_INTR */
  54. #define BNX2X_MSG_FP 0x200000 /* was: NETIF_MSG_INTR */
  55. #define DP_LEVEL KERN_NOTICE /* was: KERN_DEBUG */
  56. /* regular debug print */
  57. #define DP(__mask, __fmt, __args...) \
  58. do { \
  59. if (bp->msg_enable & (__mask)) \
  60. printk(DP_LEVEL "[%s:%d(%s)]" __fmt, \
  61. __func__, __LINE__, \
  62. bp->dev ? (bp->dev->name) : "?", \
  63. ##__args); \
  64. } while (0)
  65. /* errors debug print */
  66. #define BNX2X_DBG_ERR(__fmt, __args...) \
  67. do { \
  68. if (netif_msg_probe(bp)) \
  69. pr_err("[%s:%d(%s)]" __fmt, \
  70. __func__, __LINE__, \
  71. bp->dev ? (bp->dev->name) : "?", \
  72. ##__args); \
  73. } while (0)
  74. /* for errors (never masked) */
  75. #define BNX2X_ERR(__fmt, __args...) \
  76. do { \
  77. pr_err("[%s:%d(%s)]" __fmt, \
  78. __func__, __LINE__, \
  79. bp->dev ? (bp->dev->name) : "?", \
  80. ##__args); \
  81. } while (0)
  82. #define BNX2X_ERROR(__fmt, __args...) do { \
  83. pr_err("[%s:%d]" __fmt, __func__, __LINE__, ##__args); \
  84. } while (0)
  85. /* before we have a dev->name use dev_info() */
  86. #define BNX2X_DEV_INFO(__fmt, __args...) \
  87. do { \
  88. if (netif_msg_probe(bp)) \
  89. dev_info(&bp->pdev->dev, __fmt, ##__args); \
  90. } while (0)
  91. void bnx2x_panic_dump(struct bnx2x *bp);
  92. #ifdef BNX2X_STOP_ON_ERROR
  93. #define bnx2x_panic() do { \
  94. bp->panic = 1; \
  95. BNX2X_ERR("driver assert\n"); \
  96. bnx2x_int_disable(bp); \
  97. bnx2x_panic_dump(bp); \
  98. } while (0)
  99. #else
  100. #define bnx2x_panic() do { \
  101. bp->panic = 1; \
  102. BNX2X_ERR("driver assert\n"); \
  103. bnx2x_panic_dump(bp); \
  104. } while (0)
  105. #endif
  106. #define bnx2x_mc_addr(ha) ((ha)->addr)
  107. #define U64_LO(x) (u32)(((u64)(x)) & 0xffffffff)
  108. #define U64_HI(x) (u32)(((u64)(x)) >> 32)
  109. #define HILO_U64(hi, lo) ((((u64)(hi)) << 32) + (lo))
  110. #define REG_ADDR(bp, offset) ((bp->regview) + (offset))
  111. #define REG_RD(bp, offset) readl(REG_ADDR(bp, offset))
  112. #define REG_RD8(bp, offset) readb(REG_ADDR(bp, offset))
  113. #define REG_RD16(bp, offset) readw(REG_ADDR(bp, offset))
  114. #define REG_WR(bp, offset, val) writel((u32)val, REG_ADDR(bp, offset))
  115. #define REG_WR8(bp, offset, val) writeb((u8)val, REG_ADDR(bp, offset))
  116. #define REG_WR16(bp, offset, val) writew((u16)val, REG_ADDR(bp, offset))
  117. #define REG_RD_IND(bp, offset) bnx2x_reg_rd_ind(bp, offset)
  118. #define REG_WR_IND(bp, offset, val) bnx2x_reg_wr_ind(bp, offset, val)
  119. #define REG_RD_DMAE(bp, offset, valp, len32) \
  120. do { \
  121. bnx2x_read_dmae(bp, offset, len32);\
  122. memcpy(valp, bnx2x_sp(bp, wb_data[0]), (len32) * 4); \
  123. } while (0)
  124. #define REG_WR_DMAE(bp, offset, valp, len32) \
  125. do { \
  126. memcpy(bnx2x_sp(bp, wb_data[0]), valp, (len32) * 4); \
  127. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), \
  128. offset, len32); \
  129. } while (0)
  130. #define REG_WR_DMAE_LEN(bp, offset, valp, len32) \
  131. REG_WR_DMAE(bp, offset, valp, len32)
  132. #define VIRT_WR_DMAE_LEN(bp, data, addr, len32, le32_swap) \
  133. do { \
  134. memcpy(GUNZIP_BUF(bp), data, (len32) * 4); \
  135. bnx2x_write_big_buf_wb(bp, addr, len32); \
  136. } while (0)
  137. #define SHMEM_ADDR(bp, field) (bp->common.shmem_base + \
  138. offsetof(struct shmem_region, field))
  139. #define SHMEM_RD(bp, field) REG_RD(bp, SHMEM_ADDR(bp, field))
  140. #define SHMEM_WR(bp, field, val) REG_WR(bp, SHMEM_ADDR(bp, field), val)
  141. #define SHMEM2_ADDR(bp, field) (bp->common.shmem2_base + \
  142. offsetof(struct shmem2_region, field))
  143. #define SHMEM2_RD(bp, field) REG_RD(bp, SHMEM2_ADDR(bp, field))
  144. #define SHMEM2_WR(bp, field, val) REG_WR(bp, SHMEM2_ADDR(bp, field), val)
  145. #define MF_CFG_ADDR(bp, field) (bp->common.mf_cfg_base + \
  146. offsetof(struct mf_cfg, field))
  147. #define MF2_CFG_ADDR(bp, field) (bp->common.mf2_cfg_base + \
  148. offsetof(struct mf2_cfg, field))
  149. #define MF_CFG_RD(bp, field) REG_RD(bp, MF_CFG_ADDR(bp, field))
  150. #define MF_CFG_WR(bp, field, val) REG_WR(bp,\
  151. MF_CFG_ADDR(bp, field), (val))
  152. #define MF2_CFG_RD(bp, field) REG_RD(bp, MF2_CFG_ADDR(bp, field))
  153. #define SHMEM2_HAS(bp, field) ((bp)->common.shmem2_base && \
  154. (SHMEM2_RD((bp), size) > \
  155. offsetof(struct shmem2_region, field)))
  156. #define EMAC_RD(bp, reg) REG_RD(bp, emac_base + reg)
  157. #define EMAC_WR(bp, reg, val) REG_WR(bp, emac_base + reg, val)
  158. /* SP SB indices */
  159. /* General SP events - stats query, cfc delete, etc */
  160. #define HC_SP_INDEX_ETH_DEF_CONS 3
  161. /* EQ completions */
  162. #define HC_SP_INDEX_EQ_CONS 7
  163. /* FCoE L2 connection completions */
  164. #define HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS 6
  165. #define HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS 4
  166. /* iSCSI L2 */
  167. #define HC_SP_INDEX_ETH_ISCSI_CQ_CONS 5
  168. #define HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS 1
  169. /* Special clients parameters */
  170. /* SB indices */
  171. /* FCoE L2 */
  172. #define BNX2X_FCOE_L2_RX_INDEX \
  173. (&bp->def_status_blk->sp_sb.\
  174. index_values[HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS])
  175. #define BNX2X_FCOE_L2_TX_INDEX \
  176. (&bp->def_status_blk->sp_sb.\
  177. index_values[HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS])
  178. /**
  179. * CIDs and CLIDs:
  180. * CLIDs below is a CLID for func 0, then the CLID for other
  181. * functions will be calculated by the formula:
  182. *
  183. * FUNC_N_CLID_X = N * NUM_SPECIAL_CLIENTS + FUNC_0_CLID_X
  184. *
  185. */
  186. /* iSCSI L2 */
  187. #define BNX2X_ISCSI_ETH_CL_ID 17
  188. #define BNX2X_ISCSI_ETH_CID 17
  189. /* FCoE L2 */
  190. #define BNX2X_FCOE_ETH_CL_ID 18
  191. #define BNX2X_FCOE_ETH_CID 18
  192. /** Additional rings budgeting */
  193. #ifdef BCM_CNIC
  194. #define CNIC_CONTEXT_USE 1
  195. #define FCOE_CONTEXT_USE 1
  196. #else
  197. #define CNIC_CONTEXT_USE 0
  198. #define FCOE_CONTEXT_USE 0
  199. #endif /* BCM_CNIC */
  200. #define NONE_ETH_CONTEXT_USE (FCOE_CONTEXT_USE)
  201. #define AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR \
  202. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR
  203. #define SM_RX_ID 0
  204. #define SM_TX_ID 1
  205. /* fast path */
  206. struct sw_rx_bd {
  207. struct sk_buff *skb;
  208. DEFINE_DMA_UNMAP_ADDR(mapping);
  209. };
  210. struct sw_tx_bd {
  211. struct sk_buff *skb;
  212. u16 first_bd;
  213. u8 flags;
  214. /* Set on the first BD descriptor when there is a split BD */
  215. #define BNX2X_TSO_SPLIT_BD (1<<0)
  216. };
  217. struct sw_rx_page {
  218. struct page *page;
  219. DEFINE_DMA_UNMAP_ADDR(mapping);
  220. };
  221. union db_prod {
  222. struct doorbell_set_prod data;
  223. u32 raw;
  224. };
  225. /* MC hsi */
  226. #define BCM_PAGE_SHIFT 12
  227. #define BCM_PAGE_SIZE (1 << BCM_PAGE_SHIFT)
  228. #define BCM_PAGE_MASK (~(BCM_PAGE_SIZE - 1))
  229. #define BCM_PAGE_ALIGN(addr) (((addr) + BCM_PAGE_SIZE - 1) & BCM_PAGE_MASK)
  230. #define PAGES_PER_SGE_SHIFT 0
  231. #define PAGES_PER_SGE (1 << PAGES_PER_SGE_SHIFT)
  232. #define SGE_PAGE_SIZE PAGE_SIZE
  233. #define SGE_PAGE_SHIFT PAGE_SHIFT
  234. #define SGE_PAGE_ALIGN(addr) PAGE_ALIGN((typeof(PAGE_SIZE))(addr))
  235. /* SGE ring related macros */
  236. #define NUM_RX_SGE_PAGES 2
  237. #define RX_SGE_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_sge))
  238. #define MAX_RX_SGE_CNT (RX_SGE_CNT - 2)
  239. /* RX_SGE_CNT is promised to be a power of 2 */
  240. #define RX_SGE_MASK (RX_SGE_CNT - 1)
  241. #define NUM_RX_SGE (RX_SGE_CNT * NUM_RX_SGE_PAGES)
  242. #define MAX_RX_SGE (NUM_RX_SGE - 1)
  243. #define NEXT_SGE_IDX(x) ((((x) & RX_SGE_MASK) == \
  244. (MAX_RX_SGE_CNT - 1)) ? (x) + 3 : (x) + 1)
  245. #define RX_SGE(x) ((x) & MAX_RX_SGE)
  246. /* SGE producer mask related macros */
  247. /* Number of bits in one sge_mask array element */
  248. #define RX_SGE_MASK_ELEM_SZ 64
  249. #define RX_SGE_MASK_ELEM_SHIFT 6
  250. #define RX_SGE_MASK_ELEM_MASK ((u64)RX_SGE_MASK_ELEM_SZ - 1)
  251. /* Creates a bitmask of all ones in less significant bits.
  252. idx - index of the most significant bit in the created mask */
  253. #define RX_SGE_ONES_MASK(idx) \
  254. (((u64)0x1 << (((idx) & RX_SGE_MASK_ELEM_MASK) + 1)) - 1)
  255. #define RX_SGE_MASK_ELEM_ONE_MASK ((u64)(~0))
  256. /* Number of u64 elements in SGE mask array */
  257. #define RX_SGE_MASK_LEN ((NUM_RX_SGE_PAGES * RX_SGE_CNT) / \
  258. RX_SGE_MASK_ELEM_SZ)
  259. #define RX_SGE_MASK_LEN_MASK (RX_SGE_MASK_LEN - 1)
  260. #define NEXT_SGE_MASK_ELEM(el) (((el) + 1) & RX_SGE_MASK_LEN_MASK)
  261. union host_hc_status_block {
  262. /* pointer to fp status block e1x */
  263. struct host_hc_status_block_e1x *e1x_sb;
  264. /* pointer to fp status block e2 */
  265. struct host_hc_status_block_e2 *e2_sb;
  266. };
  267. struct bnx2x_fastpath {
  268. #define BNX2X_NAPI_WEIGHT 128
  269. struct napi_struct napi;
  270. union host_hc_status_block status_blk;
  271. /* chip independed shortcuts into sb structure */
  272. __le16 *sb_index_values;
  273. __le16 *sb_running_index;
  274. /* chip independed shortcut into rx_prods_offset memory */
  275. u32 ustorm_rx_prods_offset;
  276. dma_addr_t status_blk_mapping;
  277. struct sw_tx_bd *tx_buf_ring;
  278. union eth_tx_bd_types *tx_desc_ring;
  279. dma_addr_t tx_desc_mapping;
  280. struct sw_rx_bd *rx_buf_ring; /* BDs mappings ring */
  281. struct sw_rx_page *rx_page_ring; /* SGE pages mappings ring */
  282. struct eth_rx_bd *rx_desc_ring;
  283. dma_addr_t rx_desc_mapping;
  284. union eth_rx_cqe *rx_comp_ring;
  285. dma_addr_t rx_comp_mapping;
  286. /* SGE ring */
  287. struct eth_rx_sge *rx_sge_ring;
  288. dma_addr_t rx_sge_mapping;
  289. u64 sge_mask[RX_SGE_MASK_LEN];
  290. int state;
  291. #define BNX2X_FP_STATE_CLOSED 0
  292. #define BNX2X_FP_STATE_IRQ 0x80000
  293. #define BNX2X_FP_STATE_OPENING 0x90000
  294. #define BNX2X_FP_STATE_OPEN 0xa0000
  295. #define BNX2X_FP_STATE_HALTING 0xb0000
  296. #define BNX2X_FP_STATE_HALTED 0xc0000
  297. #define BNX2X_FP_STATE_TERMINATING 0xd0000
  298. #define BNX2X_FP_STATE_TERMINATED 0xe0000
  299. u8 index; /* number in fp array */
  300. u8 cl_id; /* eth client id */
  301. u8 cl_qzone_id;
  302. u8 fw_sb_id; /* status block number in FW */
  303. u8 igu_sb_id; /* status block number in HW */
  304. u32 cid;
  305. union db_prod tx_db;
  306. u16 tx_pkt_prod;
  307. u16 tx_pkt_cons;
  308. u16 tx_bd_prod;
  309. u16 tx_bd_cons;
  310. __le16 *tx_cons_sb;
  311. __le16 fp_hc_idx;
  312. u16 rx_bd_prod;
  313. u16 rx_bd_cons;
  314. u16 rx_comp_prod;
  315. u16 rx_comp_cons;
  316. u16 rx_sge_prod;
  317. /* The last maximal completed SGE */
  318. u16 last_max_sge;
  319. __le16 *rx_cons_sb;
  320. unsigned long tx_pkt,
  321. rx_pkt,
  322. rx_calls;
  323. /* TPA related */
  324. struct sw_rx_bd tpa_pool[ETH_MAX_AGGREGATION_QUEUES_E1H];
  325. u8 tpa_state[ETH_MAX_AGGREGATION_QUEUES_E1H];
  326. #define BNX2X_TPA_START 1
  327. #define BNX2X_TPA_STOP 2
  328. u8 disable_tpa;
  329. #ifdef BNX2X_STOP_ON_ERROR
  330. u64 tpa_queue_used;
  331. #endif
  332. struct tstorm_per_client_stats old_tclient;
  333. struct ustorm_per_client_stats old_uclient;
  334. struct xstorm_per_client_stats old_xclient;
  335. struct bnx2x_eth_q_stats eth_q_stats;
  336. /* The size is calculated using the following:
  337. sizeof name field from netdev structure +
  338. 4 ('-Xx-' string) +
  339. 4 (for the digits and to make it DWORD aligned) */
  340. #define FP_NAME_SIZE (sizeof(((struct net_device *)0)->name) + 8)
  341. char name[FP_NAME_SIZE];
  342. struct bnx2x *bp; /* parent */
  343. };
  344. #define bnx2x_fp(bp, nr, var) (bp->fp[nr].var)
  345. #ifdef BCM_CNIC
  346. /* FCoE L2 `fastpath' is right after the eth entries */
  347. #define FCOE_IDX BNX2X_NUM_ETH_QUEUES(bp)
  348. #define bnx2x_fcoe_fp(bp) (&bp->fp[FCOE_IDX])
  349. #define bnx2x_fcoe(bp, var) (bnx2x_fcoe_fp(bp)->var)
  350. #define IS_FCOE_FP(fp) (fp->index == FCOE_IDX)
  351. #define IS_FCOE_IDX(idx) ((idx) == FCOE_IDX)
  352. #else
  353. #define IS_FCOE_FP(fp) false
  354. #define IS_FCOE_IDX(idx) false
  355. #endif
  356. /* MC hsi */
  357. #define MAX_FETCH_BD 13 /* HW max BDs per packet */
  358. #define RX_COPY_THRESH 92
  359. #define NUM_TX_RINGS 16
  360. #define TX_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_tx_bd_types))
  361. #define MAX_TX_DESC_CNT (TX_DESC_CNT - 1)
  362. #define NUM_TX_BD (TX_DESC_CNT * NUM_TX_RINGS)
  363. #define MAX_TX_BD (NUM_TX_BD - 1)
  364. #define MAX_TX_AVAIL (MAX_TX_DESC_CNT * NUM_TX_RINGS - 2)
  365. #define INIT_JUMBO_TX_RING_SIZE MAX_TX_AVAIL
  366. #define INIT_TX_RING_SIZE MAX_TX_AVAIL
  367. #define NEXT_TX_IDX(x) ((((x) & MAX_TX_DESC_CNT) == \
  368. (MAX_TX_DESC_CNT - 1)) ? (x) + 2 : (x) + 1)
  369. #define TX_BD(x) ((x) & MAX_TX_BD)
  370. #define TX_BD_POFF(x) ((x) & MAX_TX_DESC_CNT)
  371. /* The RX BD ring is special, each bd is 8 bytes but the last one is 16 */
  372. #define NUM_RX_RINGS 8
  373. #define RX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_bd))
  374. #define MAX_RX_DESC_CNT (RX_DESC_CNT - 2)
  375. #define RX_DESC_MASK (RX_DESC_CNT - 1)
  376. #define NUM_RX_BD (RX_DESC_CNT * NUM_RX_RINGS)
  377. #define MAX_RX_BD (NUM_RX_BD - 1)
  378. #define MAX_RX_AVAIL (MAX_RX_DESC_CNT * NUM_RX_RINGS - 2)
  379. #define MIN_RX_AVAIL 128
  380. #define INIT_JUMBO_RX_RING_SIZE MAX_RX_AVAIL
  381. #define INIT_RX_RING_SIZE MAX_RX_AVAIL
  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. /* As long as CQE is 4 times bigger than BD entry we have to allocate
  386. 4 times more pages for CQ ring in order to keep it balanced with
  387. BD ring */
  388. #define NUM_RCQ_RINGS (NUM_RX_RINGS * 4)
  389. #define RCQ_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_rx_cqe))
  390. #define MAX_RCQ_DESC_CNT (RCQ_DESC_CNT - 1)
  391. #define NUM_RCQ_BD (RCQ_DESC_CNT * NUM_RCQ_RINGS)
  392. #define MAX_RCQ_BD (NUM_RCQ_BD - 1)
  393. #define MAX_RCQ_AVAIL (MAX_RCQ_DESC_CNT * NUM_RCQ_RINGS - 2)
  394. #define NEXT_RCQ_IDX(x) ((((x) & MAX_RCQ_DESC_CNT) == \
  395. (MAX_RCQ_DESC_CNT - 1)) ? (x) + 2 : (x) + 1)
  396. #define RCQ_BD(x) ((x) & MAX_RCQ_BD)
  397. /* This is needed for determining of last_max */
  398. #define SUB_S16(a, b) (s16)((s16)(a) - (s16)(b))
  399. #define __SGE_MASK_SET_BIT(el, bit) \
  400. do { \
  401. el = ((el) | ((u64)0x1 << (bit))); \
  402. } while (0)
  403. #define __SGE_MASK_CLEAR_BIT(el, bit) \
  404. do { \
  405. el = ((el) & (~((u64)0x1 << (bit)))); \
  406. } while (0)
  407. #define SGE_MASK_SET_BIT(fp, idx) \
  408. __SGE_MASK_SET_BIT(fp->sge_mask[(idx) >> RX_SGE_MASK_ELEM_SHIFT], \
  409. ((idx) & RX_SGE_MASK_ELEM_MASK))
  410. #define SGE_MASK_CLEAR_BIT(fp, idx) \
  411. __SGE_MASK_CLEAR_BIT(fp->sge_mask[(idx) >> RX_SGE_MASK_ELEM_SHIFT], \
  412. ((idx) & RX_SGE_MASK_ELEM_MASK))
  413. /* used on a CID received from the HW */
  414. #define SW_CID(x) (le32_to_cpu(x) & \
  415. (COMMON_RAMROD_ETH_RX_CQE_CID >> 7))
  416. #define CQE_CMD(x) (le32_to_cpu(x) >> \
  417. COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT)
  418. #define BD_UNMAP_ADDR(bd) HILO_U64(le32_to_cpu((bd)->addr_hi), \
  419. le32_to_cpu((bd)->addr_lo))
  420. #define BD_UNMAP_LEN(bd) (le16_to_cpu((bd)->nbytes))
  421. #define BNX2X_DB_MIN_SHIFT 3 /* 8 bytes */
  422. #define BNX2X_DB_SHIFT 7 /* 128 bytes*/
  423. #define DPM_TRIGER_TYPE 0x40
  424. #define DOORBELL(bp, cid, val) \
  425. do { \
  426. writel((u32)(val), bp->doorbells + (bp->db_size * (cid)) + \
  427. DPM_TRIGER_TYPE); \
  428. } while (0)
  429. /* TX CSUM helpers */
  430. #define SKB_CS_OFF(skb) (offsetof(struct tcphdr, check) - \
  431. skb->csum_offset)
  432. #define SKB_CS(skb) (*(u16 *)(skb_transport_header(skb) + \
  433. skb->csum_offset))
  434. #define pbd_tcp_flags(skb) (ntohl(tcp_flag_word(tcp_hdr(skb)))>>16 & 0xff)
  435. #define XMIT_PLAIN 0
  436. #define XMIT_CSUM_V4 0x1
  437. #define XMIT_CSUM_V6 0x2
  438. #define XMIT_CSUM_TCP 0x4
  439. #define XMIT_GSO_V4 0x8
  440. #define XMIT_GSO_V6 0x10
  441. #define XMIT_CSUM (XMIT_CSUM_V4 | XMIT_CSUM_V6)
  442. #define XMIT_GSO (XMIT_GSO_V4 | XMIT_GSO_V6)
  443. /* stuff added to make the code fit 80Col */
  444. #define CQE_TYPE(cqe_fp_flags) ((cqe_fp_flags) & ETH_FAST_PATH_RX_CQE_TYPE)
  445. #define TPA_TYPE_START ETH_FAST_PATH_RX_CQE_START_FLG
  446. #define TPA_TYPE_END ETH_FAST_PATH_RX_CQE_END_FLG
  447. #define TPA_TYPE(cqe_fp_flags) ((cqe_fp_flags) & \
  448. (TPA_TYPE_START | TPA_TYPE_END))
  449. #define ETH_RX_ERROR_FALGS ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG
  450. #define BNX2X_IP_CSUM_ERR(cqe) \
  451. (!((cqe)->fast_path_cqe.status_flags & \
  452. ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG) && \
  453. ((cqe)->fast_path_cqe.type_error_flags & \
  454. ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG))
  455. #define BNX2X_L4_CSUM_ERR(cqe) \
  456. (!((cqe)->fast_path_cqe.status_flags & \
  457. ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG) && \
  458. ((cqe)->fast_path_cqe.type_error_flags & \
  459. ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG))
  460. #define BNX2X_RX_CSUM_OK(cqe) \
  461. (!(BNX2X_L4_CSUM_ERR(cqe) || BNX2X_IP_CSUM_ERR(cqe)))
  462. #define BNX2X_PRS_FLAG_OVERETH_IPV4(flags) \
  463. (((le16_to_cpu(flags) & \
  464. PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) >> \
  465. PARSING_FLAGS_OVER_ETHERNET_PROTOCOL_SHIFT) \
  466. == PRS_FLAG_OVERETH_IPV4)
  467. #define BNX2X_RX_SUM_FIX(cqe) \
  468. BNX2X_PRS_FLAG_OVERETH_IPV4(cqe->fast_path_cqe.pars_flags.flags)
  469. #define U_SB_ETH_RX_CQ_INDEX 1
  470. #define U_SB_ETH_RX_BD_INDEX 2
  471. #define C_SB_ETH_TX_CQ_INDEX 5
  472. #define BNX2X_RX_SB_INDEX \
  473. (&fp->sb_index_values[U_SB_ETH_RX_CQ_INDEX])
  474. #define BNX2X_TX_SB_INDEX \
  475. (&fp->sb_index_values[C_SB_ETH_TX_CQ_INDEX])
  476. /* end of fast path */
  477. /* common */
  478. struct bnx2x_common {
  479. u32 chip_id;
  480. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  481. #define CHIP_ID(bp) (bp->common.chip_id & 0xfffffff0)
  482. #define CHIP_NUM(bp) (bp->common.chip_id >> 16)
  483. #define CHIP_NUM_57710 0x164e
  484. #define CHIP_NUM_57711 0x164f
  485. #define CHIP_NUM_57711E 0x1650
  486. #define CHIP_NUM_57712 0x1662
  487. #define CHIP_NUM_57712E 0x1663
  488. #define CHIP_IS_E1(bp) (CHIP_NUM(bp) == CHIP_NUM_57710)
  489. #define CHIP_IS_57711(bp) (CHIP_NUM(bp) == CHIP_NUM_57711)
  490. #define CHIP_IS_57711E(bp) (CHIP_NUM(bp) == CHIP_NUM_57711E)
  491. #define CHIP_IS_57712(bp) (CHIP_NUM(bp) == CHIP_NUM_57712)
  492. #define CHIP_IS_57712E(bp) (CHIP_NUM(bp) == CHIP_NUM_57712E)
  493. #define CHIP_IS_E1H(bp) (CHIP_IS_57711(bp) || \
  494. CHIP_IS_57711E(bp))
  495. #define CHIP_IS_E2(bp) (CHIP_IS_57712(bp) || \
  496. CHIP_IS_57712E(bp))
  497. #define CHIP_IS_E1x(bp) (CHIP_IS_E1((bp)) || CHIP_IS_E1H((bp)))
  498. #define IS_E1H_OFFSET (CHIP_IS_E1H(bp) || CHIP_IS_E2(bp))
  499. #define CHIP_REV(bp) (bp->common.chip_id & 0x0000f000)
  500. #define CHIP_REV_Ax 0x00000000
  501. /* assume maximum 5 revisions */
  502. #define CHIP_REV_IS_SLOW(bp) (CHIP_REV(bp) > 0x00005000)
  503. /* Emul versions are A=>0xe, B=>0xc, C=>0xa, D=>8, E=>6 */
  504. #define CHIP_REV_IS_EMUL(bp) ((CHIP_REV_IS_SLOW(bp)) && \
  505. !(CHIP_REV(bp) & 0x00001000))
  506. /* FPGA versions are A=>0xf, B=>0xd, C=>0xb, D=>9, E=>7 */
  507. #define CHIP_REV_IS_FPGA(bp) ((CHIP_REV_IS_SLOW(bp)) && \
  508. (CHIP_REV(bp) & 0x00001000))
  509. #define CHIP_TIME(bp) ((CHIP_REV_IS_EMUL(bp)) ? 2000 : \
  510. ((CHIP_REV_IS_FPGA(bp)) ? 200 : 1))
  511. #define CHIP_METAL(bp) (bp->common.chip_id & 0x00000ff0)
  512. #define CHIP_BOND_ID(bp) (bp->common.chip_id & 0x0000000f)
  513. int flash_size;
  514. #define NVRAM_1MB_SIZE 0x20000 /* 1M bit in bytes */
  515. #define NVRAM_TIMEOUT_COUNT 30000
  516. #define NVRAM_PAGE_SIZE 256
  517. u32 shmem_base;
  518. u32 shmem2_base;
  519. u32 mf_cfg_base;
  520. u32 mf2_cfg_base;
  521. u32 hw_config;
  522. u32 bc_ver;
  523. u8 int_block;
  524. #define INT_BLOCK_HC 0
  525. #define INT_BLOCK_IGU 1
  526. #define INT_BLOCK_MODE_NORMAL 0
  527. #define INT_BLOCK_MODE_BW_COMP 2
  528. #define CHIP_INT_MODE_IS_NBC(bp) \
  529. (CHIP_IS_E2(bp) && \
  530. !((bp)->common.int_block & INT_BLOCK_MODE_BW_COMP))
  531. #define CHIP_INT_MODE_IS_BC(bp) (!CHIP_INT_MODE_IS_NBC(bp))
  532. u8 chip_port_mode;
  533. #define CHIP_4_PORT_MODE 0x0
  534. #define CHIP_2_PORT_MODE 0x1
  535. #define CHIP_PORT_MODE_NONE 0x2
  536. #define CHIP_MODE(bp) (bp->common.chip_port_mode)
  537. #define CHIP_MODE_IS_4_PORT(bp) (CHIP_MODE(bp) == CHIP_4_PORT_MODE)
  538. };
  539. /* IGU MSIX STATISTICS on 57712: 64 for VFs; 4 for PFs; 4 for Attentions */
  540. #define BNX2X_IGU_STAS_MSG_VF_CNT 64
  541. #define BNX2X_IGU_STAS_MSG_PF_CNT 4
  542. /* end of common */
  543. /* port */
  544. struct bnx2x_port {
  545. u32 pmf;
  546. u32 link_config[LINK_CONFIG_SIZE];
  547. u32 supported[LINK_CONFIG_SIZE];
  548. /* link settings - missing defines */
  549. #define SUPPORTED_2500baseX_Full (1 << 15)
  550. u32 advertising[LINK_CONFIG_SIZE];
  551. /* link settings - missing defines */
  552. #define ADVERTISED_2500baseX_Full (1 << 15)
  553. u32 phy_addr;
  554. /* used to synchronize phy accesses */
  555. struct mutex phy_mutex;
  556. int need_hw_lock;
  557. u32 port_stx;
  558. struct nig_stats old_nig_stats;
  559. };
  560. /* end of port */
  561. /* e1h Classification CAM line allocations */
  562. enum {
  563. CAM_ETH_LINE = 0,
  564. CAM_ISCSI_ETH_LINE,
  565. CAM_FIP_ETH_LINE,
  566. CAM_FIP_MCAST_LINE,
  567. CAM_MAX_PF_LINE = CAM_FIP_MCAST_LINE
  568. };
  569. /* number of MACs per function in NIG memory - used for SI mode */
  570. #define NIG_LLH_FUNC_MEM_SIZE 16
  571. /* number of entries in NIG_REG_LLHX_FUNC_MEM */
  572. #define NIG_LLH_FUNC_MEM_MAX_OFFSET 8
  573. #define BNX2X_VF_ID_INVALID 0xFF
  574. /*
  575. * The total number of L2 queues, MSIX vectors and HW contexts (CIDs) is
  576. * control by the number of fast-path status blocks supported by the
  577. * device (HW/FW). Each fast-path status block (FP-SB) aka non-default
  578. * status block represents an independent interrupts context that can
  579. * serve a regular L2 networking queue. However special L2 queues such
  580. * as the FCoE queue do not require a FP-SB and other components like
  581. * the CNIC may consume FP-SB reducing the number of possible L2 queues
  582. *
  583. * If the maximum number of FP-SB available is X then:
  584. * a. If CNIC is supported it consumes 1 FP-SB thus the max number of
  585. * regular L2 queues is Y=X-1
  586. * b. in MF mode the actual number of L2 queues is Y= (X-1/MF_factor)
  587. * c. If the FCoE L2 queue is supported the actual number of L2 queues
  588. * is Y+1
  589. * d. The number of irqs (MSIX vectors) is either Y+1 (one extra for
  590. * slow-path interrupts) or Y+2 if CNIC is supported (one additional
  591. * FP interrupt context for the CNIC).
  592. * e. The number of HW context (CID count) is always X or X+1 if FCoE
  593. * L2 queue is supported. the cid for the FCoE L2 queue is always X.
  594. */
  595. #define FP_SB_MAX_E1x 16 /* fast-path interrupt contexts E1x */
  596. #define FP_SB_MAX_E2 16 /* fast-path interrupt contexts E2 */
  597. /*
  598. * cid_cnt paramter below refers to the value returned by
  599. * 'bnx2x_get_l2_cid_count()' routine
  600. */
  601. /*
  602. * The number of FP context allocated by the driver == max number of regular
  603. * L2 queues + 1 for the FCoE L2 queue
  604. */
  605. #define L2_FP_COUNT(cid_cnt) ((cid_cnt) - CNIC_CONTEXT_USE)
  606. /*
  607. * The number of FP-SB allocated by the driver == max number of regular L2
  608. * queues + 1 for the CNIC which also consumes an FP-SB
  609. */
  610. #define FP_SB_COUNT(cid_cnt) ((cid_cnt) - FCOE_CONTEXT_USE)
  611. #define NUM_IGU_SB_REQUIRED(cid_cnt) \
  612. (FP_SB_COUNT(cid_cnt) - NONE_ETH_CONTEXT_USE)
  613. union cdu_context {
  614. struct eth_context eth;
  615. char pad[1024];
  616. };
  617. /* CDU host DB constants */
  618. #define CDU_ILT_PAGE_SZ_HW 3
  619. #define CDU_ILT_PAGE_SZ (4096 << CDU_ILT_PAGE_SZ_HW) /* 32K */
  620. #define ILT_PAGE_CIDS (CDU_ILT_PAGE_SZ / sizeof(union cdu_context))
  621. #ifdef BCM_CNIC
  622. #define CNIC_ISCSI_CID_MAX 256
  623. #define CNIC_FCOE_CID_MAX 2048
  624. #define CNIC_CID_MAX (CNIC_ISCSI_CID_MAX + CNIC_FCOE_CID_MAX)
  625. #define CNIC_ILT_LINES DIV_ROUND_UP(CNIC_CID_MAX, ILT_PAGE_CIDS)
  626. #endif
  627. #define QM_ILT_PAGE_SZ_HW 3
  628. #define QM_ILT_PAGE_SZ (4096 << QM_ILT_PAGE_SZ_HW) /* 32K */
  629. #define QM_CID_ROUND 1024
  630. #ifdef BCM_CNIC
  631. /* TM (timers) host DB constants */
  632. #define TM_ILT_PAGE_SZ_HW 2
  633. #define TM_ILT_PAGE_SZ (4096 << TM_ILT_PAGE_SZ_HW) /* 16K */
  634. /* #define TM_CONN_NUM (CNIC_STARTING_CID+CNIC_ISCSI_CXT_MAX) */
  635. #define TM_CONN_NUM 1024
  636. #define TM_ILT_SZ (8 * TM_CONN_NUM)
  637. #define TM_ILT_LINES DIV_ROUND_UP(TM_ILT_SZ, TM_ILT_PAGE_SZ)
  638. /* SRC (Searcher) host DB constants */
  639. #define SRC_ILT_PAGE_SZ_HW 3
  640. #define SRC_ILT_PAGE_SZ (4096 << SRC_ILT_PAGE_SZ_HW) /* 32K */
  641. #define SRC_HASH_BITS 10
  642. #define SRC_CONN_NUM (1 << SRC_HASH_BITS) /* 1024 */
  643. #define SRC_ILT_SZ (sizeof(struct src_ent) * SRC_CONN_NUM)
  644. #define SRC_T2_SZ SRC_ILT_SZ
  645. #define SRC_ILT_LINES DIV_ROUND_UP(SRC_ILT_SZ, SRC_ILT_PAGE_SZ)
  646. #endif
  647. #define MAX_DMAE_C 8
  648. /* DMA memory not used in fastpath */
  649. struct bnx2x_slowpath {
  650. struct eth_stats_query fw_stats;
  651. struct mac_configuration_cmd mac_config;
  652. struct mac_configuration_cmd mcast_config;
  653. struct client_init_ramrod_data client_init_data;
  654. /* used by dmae command executer */
  655. struct dmae_command dmae[MAX_DMAE_C];
  656. u32 stats_comp;
  657. union mac_stats mac_stats;
  658. struct nig_stats nig_stats;
  659. struct host_port_stats port_stats;
  660. struct host_func_stats func_stats;
  661. struct host_func_stats func_stats_base;
  662. u32 wb_comp;
  663. u32 wb_data[4];
  664. /* pfc configuration for DCBX ramrod */
  665. struct flow_control_configuration pfc_config;
  666. };
  667. #define bnx2x_sp(bp, var) (&bp->slowpath->var)
  668. #define bnx2x_sp_mapping(bp, var) \
  669. (bp->slowpath_mapping + offsetof(struct bnx2x_slowpath, var))
  670. /* attn group wiring */
  671. #define MAX_DYNAMIC_ATTN_GRPS 8
  672. struct attn_route {
  673. u32 sig[5];
  674. };
  675. struct iro {
  676. u32 base;
  677. u16 m1;
  678. u16 m2;
  679. u16 m3;
  680. u16 size;
  681. };
  682. struct hw_context {
  683. union cdu_context *vcxt;
  684. dma_addr_t cxt_mapping;
  685. size_t size;
  686. };
  687. /* forward */
  688. struct bnx2x_ilt;
  689. typedef enum {
  690. BNX2X_RECOVERY_DONE,
  691. BNX2X_RECOVERY_INIT,
  692. BNX2X_RECOVERY_WAIT,
  693. } bnx2x_recovery_state_t;
  694. /**
  695. * Event queue (EQ or event ring) MC hsi
  696. * NUM_EQ_PAGES and EQ_DESC_CNT_PAGE must be power of 2
  697. */
  698. #define NUM_EQ_PAGES 1
  699. #define EQ_DESC_CNT_PAGE (BCM_PAGE_SIZE / sizeof(union event_ring_elem))
  700. #define EQ_DESC_MAX_PAGE (EQ_DESC_CNT_PAGE - 1)
  701. #define NUM_EQ_DESC (EQ_DESC_CNT_PAGE * NUM_EQ_PAGES)
  702. #define EQ_DESC_MASK (NUM_EQ_DESC - 1)
  703. #define MAX_EQ_AVAIL (EQ_DESC_MAX_PAGE * NUM_EQ_PAGES - 2)
  704. /* depends on EQ_DESC_CNT_PAGE being a power of 2 */
  705. #define NEXT_EQ_IDX(x) ((((x) & EQ_DESC_MAX_PAGE) == \
  706. (EQ_DESC_MAX_PAGE - 1)) ? (x) + 2 : (x) + 1)
  707. /* depends on the above and on NUM_EQ_PAGES being a power of 2 */
  708. #define EQ_DESC(x) ((x) & EQ_DESC_MASK)
  709. #define BNX2X_EQ_INDEX \
  710. (&bp->def_status_blk->sp_sb.\
  711. index_values[HC_SP_INDEX_EQ_CONS])
  712. struct bnx2x {
  713. /* Fields used in the tx and intr/napi performance paths
  714. * are grouped together in the beginning of the structure
  715. */
  716. struct bnx2x_fastpath *fp;
  717. void __iomem *regview;
  718. void __iomem *doorbells;
  719. u16 db_size;
  720. struct net_device *dev;
  721. struct pci_dev *pdev;
  722. struct iro *iro_arr;
  723. #define IRO (bp->iro_arr)
  724. atomic_t intr_sem;
  725. bnx2x_recovery_state_t recovery_state;
  726. int is_leader;
  727. struct msix_entry *msix_table;
  728. #define INT_MODE_INTx 1
  729. #define INT_MODE_MSI 2
  730. int tx_ring_size;
  731. u32 rx_csum;
  732. u32 rx_buf_size;
  733. /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
  734. #define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
  735. #define ETH_MIN_PACKET_SIZE 60
  736. #define ETH_MAX_PACKET_SIZE 1500
  737. #define ETH_MAX_JUMBO_PACKET_SIZE 9600
  738. /* Max supported alignment is 256 (8 shift) */
  739. #define BNX2X_RX_ALIGN_SHIFT ((L1_CACHE_SHIFT < 8) ? \
  740. L1_CACHE_SHIFT : 8)
  741. #define BNX2X_RX_ALIGN (1 << BNX2X_RX_ALIGN_SHIFT)
  742. #define BNX2X_PXP_DRAM_ALIGN (BNX2X_RX_ALIGN_SHIFT - 5)
  743. struct host_sp_status_block *def_status_blk;
  744. #define DEF_SB_IGU_ID 16
  745. #define DEF_SB_ID HC_SP_SB_ID
  746. __le16 def_idx;
  747. __le16 def_att_idx;
  748. u32 attn_state;
  749. struct attn_route attn_group[MAX_DYNAMIC_ATTN_GRPS];
  750. /* slow path ring */
  751. struct eth_spe *spq;
  752. dma_addr_t spq_mapping;
  753. u16 spq_prod_idx;
  754. struct eth_spe *spq_prod_bd;
  755. struct eth_spe *spq_last_bd;
  756. __le16 *dsb_sp_prod;
  757. atomic_t spq_left; /* serialize spq */
  758. /* used to synchronize spq accesses */
  759. spinlock_t spq_lock;
  760. /* event queue */
  761. union event_ring_elem *eq_ring;
  762. dma_addr_t eq_mapping;
  763. u16 eq_prod;
  764. u16 eq_cons;
  765. __le16 *eq_cons_sb;
  766. /* Flags for marking that there is a STAT_QUERY or
  767. SET_MAC ramrod pending */
  768. int stats_pending;
  769. int set_mac_pending;
  770. /* End of fields used in the performance code paths */
  771. int panic;
  772. int msg_enable;
  773. u32 flags;
  774. #define PCIX_FLAG 1
  775. #define PCI_32BIT_FLAG 2
  776. #define ONE_PORT_FLAG 4
  777. #define NO_WOL_FLAG 8
  778. #define USING_DAC_FLAG 0x10
  779. #define USING_MSIX_FLAG 0x20
  780. #define USING_MSI_FLAG 0x40
  781. #define TPA_ENABLE_FLAG 0x80
  782. #define NO_MCP_FLAG 0x100
  783. #define DISABLE_MSI_FLAG 0x200
  784. #define BP_NOMCP(bp) (bp->flags & NO_MCP_FLAG)
  785. #define MF_FUNC_DIS 0x1000
  786. #define FCOE_MACS_SET 0x2000
  787. #define NO_FCOE_FLAG 0x4000
  788. #define NO_FCOE(bp) ((bp)->flags & NO_FCOE_FLAG)
  789. int pf_num; /* absolute PF number */
  790. int pfid; /* per-path PF number */
  791. int base_fw_ndsb;
  792. #define BP_PATH(bp) (!CHIP_IS_E2(bp) ? \
  793. 0 : (bp->pf_num & 1))
  794. #define BP_PORT(bp) (bp->pfid & 1)
  795. #define BP_FUNC(bp) (bp->pfid)
  796. #define BP_ABS_FUNC(bp) (bp->pf_num)
  797. #define BP_E1HVN(bp) (bp->pfid >> 1)
  798. #define BP_VN(bp) (CHIP_MODE_IS_4_PORT(bp) ? \
  799. 0 : BP_E1HVN(bp))
  800. #define BP_L_ID(bp) (BP_E1HVN(bp) << 2)
  801. #define BP_FW_MB_IDX(bp) (BP_PORT(bp) +\
  802. BP_VN(bp) * (CHIP_IS_E1x(bp) ? 2 : 1))
  803. #ifdef BCM_CNIC
  804. #define BCM_CNIC_CID_START 16
  805. #define BCM_ISCSI_ETH_CL_ID 17
  806. #endif
  807. int pm_cap;
  808. int pcie_cap;
  809. int mrrs;
  810. struct delayed_work sp_task;
  811. struct delayed_work reset_task;
  812. struct timer_list timer;
  813. int current_interval;
  814. u16 fw_seq;
  815. u16 fw_drv_pulse_wr_seq;
  816. u32 func_stx;
  817. struct link_params link_params;
  818. struct link_vars link_vars;
  819. struct mdio_if_info mdio;
  820. struct bnx2x_common common;
  821. struct bnx2x_port port;
  822. struct cmng_struct_per_port cmng;
  823. u32 vn_weight_sum;
  824. u32 mf_config[E1HVN_MAX];
  825. u32 mf2_config[E2_FUNC_MAX];
  826. u16 mf_ov;
  827. u8 mf_mode;
  828. #define IS_MF(bp) (bp->mf_mode != 0)
  829. #define IS_MF_SI(bp) (bp->mf_mode == MULTI_FUNCTION_SI)
  830. #define IS_MF_SD(bp) (bp->mf_mode == MULTI_FUNCTION_SD)
  831. u8 wol;
  832. int rx_ring_size;
  833. u16 tx_quick_cons_trip_int;
  834. u16 tx_quick_cons_trip;
  835. u16 tx_ticks_int;
  836. u16 tx_ticks;
  837. u16 rx_quick_cons_trip_int;
  838. u16 rx_quick_cons_trip;
  839. u16 rx_ticks_int;
  840. u16 rx_ticks;
  841. /* Maximal coalescing timeout in us */
  842. #define BNX2X_MAX_COALESCE_TOUT (0xf0*12)
  843. u32 lin_cnt;
  844. int state;
  845. #define BNX2X_STATE_CLOSED 0
  846. #define BNX2X_STATE_OPENING_WAIT4_LOAD 0x1000
  847. #define BNX2X_STATE_OPENING_WAIT4_PORT 0x2000
  848. #define BNX2X_STATE_OPEN 0x3000
  849. #define BNX2X_STATE_CLOSING_WAIT4_HALT 0x4000
  850. #define BNX2X_STATE_CLOSING_WAIT4_DELETE 0x5000
  851. #define BNX2X_STATE_CLOSING_WAIT4_UNLOAD 0x6000
  852. #define BNX2X_STATE_FUNC_STARTED 0x7000
  853. #define BNX2X_STATE_DIAG 0xe000
  854. #define BNX2X_STATE_ERROR 0xf000
  855. int multi_mode;
  856. int num_queues;
  857. int disable_tpa;
  858. int int_mode;
  859. struct tstorm_eth_mac_filter_config mac_filters;
  860. #define BNX2X_ACCEPT_NONE 0x0000
  861. #define BNX2X_ACCEPT_UNICAST 0x0001
  862. #define BNX2X_ACCEPT_MULTICAST 0x0002
  863. #define BNX2X_ACCEPT_ALL_UNICAST 0x0004
  864. #define BNX2X_ACCEPT_ALL_MULTICAST 0x0008
  865. #define BNX2X_ACCEPT_BROADCAST 0x0010
  866. #define BNX2X_ACCEPT_UNMATCHED_UCAST 0x0020
  867. #define BNX2X_PROMISCUOUS_MODE 0x10000
  868. u32 rx_mode;
  869. #define BNX2X_RX_MODE_NONE 0
  870. #define BNX2X_RX_MODE_NORMAL 1
  871. #define BNX2X_RX_MODE_ALLMULTI 2
  872. #define BNX2X_RX_MODE_PROMISC 3
  873. #define BNX2X_MAX_MULTICAST 64
  874. #define BNX2X_MAX_EMUL_MULTI 16
  875. u8 igu_dsb_id;
  876. u8 igu_base_sb;
  877. u8 igu_sb_cnt;
  878. dma_addr_t def_status_blk_mapping;
  879. struct bnx2x_slowpath *slowpath;
  880. dma_addr_t slowpath_mapping;
  881. struct hw_context context;
  882. struct bnx2x_ilt *ilt;
  883. #define BP_ILT(bp) ((bp)->ilt)
  884. #define ILT_MAX_LINES 128
  885. int l2_cid_count;
  886. #define L2_ILT_LINES(bp) (DIV_ROUND_UP((bp)->l2_cid_count, \
  887. ILT_PAGE_CIDS))
  888. #define BNX2X_DB_SIZE(bp) ((bp)->l2_cid_count * (1 << BNX2X_DB_SHIFT))
  889. int qm_cid_count;
  890. int dropless_fc;
  891. #ifdef BCM_CNIC
  892. u32 cnic_flags;
  893. #define BNX2X_CNIC_FLAG_MAC_SET 1
  894. void *t2;
  895. dma_addr_t t2_mapping;
  896. struct cnic_ops *cnic_ops;
  897. void *cnic_data;
  898. u32 cnic_tag;
  899. struct cnic_eth_dev cnic_eth_dev;
  900. union host_hc_status_block cnic_sb;
  901. dma_addr_t cnic_sb_mapping;
  902. #define CNIC_SB_ID(bp) ((bp)->base_fw_ndsb + BP_L_ID(bp))
  903. #define CNIC_IGU_SB_ID(bp) ((bp)->igu_base_sb)
  904. struct eth_spe *cnic_kwq;
  905. struct eth_spe *cnic_kwq_prod;
  906. struct eth_spe *cnic_kwq_cons;
  907. struct eth_spe *cnic_kwq_last;
  908. u16 cnic_kwq_pending;
  909. u16 cnic_spq_pending;
  910. struct mutex cnic_mutex;
  911. u8 iscsi_mac[ETH_ALEN];
  912. u8 fip_mac[ETH_ALEN];
  913. #endif
  914. int dmae_ready;
  915. /* used to synchronize dmae accesses */
  916. struct mutex dmae_mutex;
  917. /* used to protect the FW mail box */
  918. struct mutex fw_mb_mutex;
  919. /* used to synchronize stats collecting */
  920. int stats_state;
  921. /* used for synchronization of concurrent threads statistics handling */
  922. spinlock_t stats_lock;
  923. /* used by dmae command loader */
  924. struct dmae_command stats_dmae;
  925. int executer_idx;
  926. u16 stats_counter;
  927. struct bnx2x_eth_stats eth_stats;
  928. struct z_stream_s *strm;
  929. void *gunzip_buf;
  930. dma_addr_t gunzip_mapping;
  931. int gunzip_outlen;
  932. #define FW_BUF_SIZE 0x8000
  933. #define GUNZIP_BUF(bp) (bp->gunzip_buf)
  934. #define GUNZIP_PHYS(bp) (bp->gunzip_mapping)
  935. #define GUNZIP_OUTLEN(bp) (bp->gunzip_outlen)
  936. struct raw_op *init_ops;
  937. /* Init blocks offsets inside init_ops */
  938. u16 *init_ops_offsets;
  939. /* Data blob - has 32 bit granularity */
  940. u32 *init_data;
  941. /* Zipped PRAM blobs - raw data */
  942. const u8 *tsem_int_table_data;
  943. const u8 *tsem_pram_data;
  944. const u8 *usem_int_table_data;
  945. const u8 *usem_pram_data;
  946. const u8 *xsem_int_table_data;
  947. const u8 *xsem_pram_data;
  948. const u8 *csem_int_table_data;
  949. const u8 *csem_pram_data;
  950. #define INIT_OPS(bp) (bp->init_ops)
  951. #define INIT_OPS_OFFSETS(bp) (bp->init_ops_offsets)
  952. #define INIT_DATA(bp) (bp->init_data)
  953. #define INIT_TSEM_INT_TABLE_DATA(bp) (bp->tsem_int_table_data)
  954. #define INIT_TSEM_PRAM_DATA(bp) (bp->tsem_pram_data)
  955. #define INIT_USEM_INT_TABLE_DATA(bp) (bp->usem_int_table_data)
  956. #define INIT_USEM_PRAM_DATA(bp) (bp->usem_pram_data)
  957. #define INIT_XSEM_INT_TABLE_DATA(bp) (bp->xsem_int_table_data)
  958. #define INIT_XSEM_PRAM_DATA(bp) (bp->xsem_pram_data)
  959. #define INIT_CSEM_INT_TABLE_DATA(bp) (bp->csem_int_table_data)
  960. #define INIT_CSEM_PRAM_DATA(bp) (bp->csem_pram_data)
  961. char fw_ver[32];
  962. const struct firmware *firmware;
  963. /* LLDP params */
  964. struct bnx2x_config_lldp_params lldp_config_params;
  965. /* DCBX params */
  966. struct bnx2x_config_dcbx_params dcbx_config_params;
  967. struct bnx2x_dcbx_port_params dcbx_port_params;
  968. int dcb_version;
  969. /* DCBX Negotation results */
  970. struct dcbx_features dcbx_local_feat;
  971. u32 dcbx_error;
  972. };
  973. /**
  974. * Init queue/func interface
  975. */
  976. /* queue init flags */
  977. #define QUEUE_FLG_TPA 0x0001
  978. #define QUEUE_FLG_CACHE_ALIGN 0x0002
  979. #define QUEUE_FLG_STATS 0x0004
  980. #define QUEUE_FLG_OV 0x0008
  981. #define QUEUE_FLG_VLAN 0x0010
  982. #define QUEUE_FLG_COS 0x0020
  983. #define QUEUE_FLG_HC 0x0040
  984. #define QUEUE_FLG_DHC 0x0080
  985. #define QUEUE_FLG_OOO 0x0100
  986. #define QUEUE_DROP_IP_CS_ERR TSTORM_ETH_CLIENT_CONFIG_DROP_IP_CS_ERR
  987. #define QUEUE_DROP_TCP_CS_ERR TSTORM_ETH_CLIENT_CONFIG_DROP_TCP_CS_ERR
  988. #define QUEUE_DROP_TTL0 TSTORM_ETH_CLIENT_CONFIG_DROP_TTL0
  989. #define QUEUE_DROP_UDP_CS_ERR TSTORM_ETH_CLIENT_CONFIG_DROP_UDP_CS_ERR
  990. /* rss capabilities */
  991. #define RSS_IPV4_CAP 0x0001
  992. #define RSS_IPV4_TCP_CAP 0x0002
  993. #define RSS_IPV6_CAP 0x0004
  994. #define RSS_IPV6_TCP_CAP 0x0008
  995. #define BNX2X_NUM_QUEUES(bp) (bp->num_queues)
  996. #define BNX2X_NUM_ETH_QUEUES(bp) (BNX2X_NUM_QUEUES(bp) - NONE_ETH_CONTEXT_USE)
  997. /* ethtool statistics are displayed for all regular ethernet queues and the
  998. * fcoe L2 queue if not disabled
  999. */
  1000. #define BNX2X_NUM_STAT_QUEUES(bp) (NO_FCOE(bp) ? BNX2X_NUM_ETH_QUEUES(bp) : \
  1001. (BNX2X_NUM_ETH_QUEUES(bp) + FCOE_CONTEXT_USE))
  1002. #define is_multi(bp) (BNX2X_NUM_QUEUES(bp) > 1)
  1003. #define BNX2X_MAX_QUEUES(bp) (bp->igu_sb_cnt - CNIC_CONTEXT_USE)
  1004. #define RSS_IPV4_CAP_MASK \
  1005. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY
  1006. #define RSS_IPV4_TCP_CAP_MASK \
  1007. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY
  1008. #define RSS_IPV6_CAP_MASK \
  1009. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY
  1010. #define RSS_IPV6_TCP_CAP_MASK \
  1011. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY
  1012. /* func init flags */
  1013. #define FUNC_FLG_STATS 0x0001
  1014. #define FUNC_FLG_TPA 0x0002
  1015. #define FUNC_FLG_SPQ 0x0004
  1016. #define FUNC_FLG_LEADING 0x0008 /* PF only */
  1017. struct rxq_pause_params {
  1018. u16 bd_th_lo;
  1019. u16 bd_th_hi;
  1020. u16 rcq_th_lo;
  1021. u16 rcq_th_hi;
  1022. u16 sge_th_lo; /* valid iff QUEUE_FLG_TPA */
  1023. u16 sge_th_hi; /* valid iff QUEUE_FLG_TPA */
  1024. u16 pri_map;
  1025. };
  1026. struct bnx2x_rxq_init_params {
  1027. /* cxt*/
  1028. struct eth_context *cxt;
  1029. /* dma */
  1030. dma_addr_t dscr_map;
  1031. dma_addr_t sge_map;
  1032. dma_addr_t rcq_map;
  1033. dma_addr_t rcq_np_map;
  1034. u16 flags;
  1035. u16 drop_flags;
  1036. u16 mtu;
  1037. u16 buf_sz;
  1038. u16 fw_sb_id;
  1039. u16 cl_id;
  1040. u16 spcl_id;
  1041. u16 cl_qzone_id;
  1042. /* valid iff QUEUE_FLG_STATS */
  1043. u16 stat_id;
  1044. /* valid iff QUEUE_FLG_TPA */
  1045. u16 tpa_agg_sz;
  1046. u16 sge_buf_sz;
  1047. u16 max_sges_pkt;
  1048. /* valid iff QUEUE_FLG_CACHE_ALIGN */
  1049. u8 cache_line_log;
  1050. u8 sb_cq_index;
  1051. u32 cid;
  1052. /* desired interrupts per sec. valid iff QUEUE_FLG_HC */
  1053. u32 hc_rate;
  1054. };
  1055. struct bnx2x_txq_init_params {
  1056. /* cxt*/
  1057. struct eth_context *cxt;
  1058. /* dma */
  1059. dma_addr_t dscr_map;
  1060. u16 flags;
  1061. u16 fw_sb_id;
  1062. u8 sb_cq_index;
  1063. u8 cos; /* valid iff QUEUE_FLG_COS */
  1064. u16 stat_id; /* valid iff QUEUE_FLG_STATS */
  1065. u16 traffic_type;
  1066. u32 cid;
  1067. u16 hc_rate; /* desired interrupts per sec.*/
  1068. /* valid iff QUEUE_FLG_HC */
  1069. };
  1070. struct bnx2x_client_ramrod_params {
  1071. int *pstate;
  1072. int state;
  1073. u16 index;
  1074. u16 cl_id;
  1075. u32 cid;
  1076. u8 poll;
  1077. #define CLIENT_IS_FCOE 0x01
  1078. #define CLIENT_IS_LEADING_RSS 0x02
  1079. u8 flags;
  1080. };
  1081. struct bnx2x_client_init_params {
  1082. struct rxq_pause_params pause;
  1083. struct bnx2x_rxq_init_params rxq_params;
  1084. struct bnx2x_txq_init_params txq_params;
  1085. struct bnx2x_client_ramrod_params ramrod_params;
  1086. };
  1087. struct bnx2x_rss_params {
  1088. int mode;
  1089. u16 cap;
  1090. u16 result_mask;
  1091. };
  1092. struct bnx2x_func_init_params {
  1093. /* rss */
  1094. struct bnx2x_rss_params *rss; /* valid iff FUNC_FLG_RSS */
  1095. /* dma */
  1096. dma_addr_t fw_stat_map; /* valid iff FUNC_FLG_STATS */
  1097. dma_addr_t spq_map; /* valid iff FUNC_FLG_SPQ */
  1098. u16 func_flgs;
  1099. u16 func_id; /* abs fid */
  1100. u16 pf_id;
  1101. u16 spq_prod; /* valid iff FUNC_FLG_SPQ */
  1102. };
  1103. #define for_each_eth_queue(bp, var) \
  1104. for (var = 0; var < BNX2X_NUM_ETH_QUEUES(bp); var++)
  1105. #define for_each_nondefault_eth_queue(bp, var) \
  1106. for (var = 1; var < BNX2X_NUM_ETH_QUEUES(bp); var++)
  1107. #define for_each_napi_queue(bp, var) \
  1108. for (var = 0; \
  1109. var < BNX2X_NUM_ETH_QUEUES(bp) + FCOE_CONTEXT_USE; var++) \
  1110. if (skip_queue(bp, var)) \
  1111. continue; \
  1112. else
  1113. #define for_each_queue(bp, var) \
  1114. for (var = 0; var < BNX2X_NUM_QUEUES(bp); var++) \
  1115. if (skip_queue(bp, var)) \
  1116. continue; \
  1117. else
  1118. #define for_each_rx_queue(bp, var) \
  1119. for (var = 0; var < BNX2X_NUM_QUEUES(bp); var++) \
  1120. if (skip_rx_queue(bp, var)) \
  1121. continue; \
  1122. else
  1123. #define for_each_tx_queue(bp, var) \
  1124. for (var = 0; var < BNX2X_NUM_QUEUES(bp); var++) \
  1125. if (skip_tx_queue(bp, var)) \
  1126. continue; \
  1127. else
  1128. #define for_each_nondefault_queue(bp, var) \
  1129. for (var = 1; var < BNX2X_NUM_QUEUES(bp); var++) \
  1130. if (skip_queue(bp, var)) \
  1131. continue; \
  1132. else
  1133. /* skip rx queue
  1134. * if FCOE l2 support is diabled and this is the fcoe L2 queue
  1135. */
  1136. #define skip_rx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1137. /* skip tx queue
  1138. * if FCOE l2 support is diabled and this is the fcoe L2 queue
  1139. */
  1140. #define skip_tx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1141. #define skip_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1142. #define WAIT_RAMROD_POLL 0x01
  1143. #define WAIT_RAMROD_COMMON 0x02
  1144. /* dmae */
  1145. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
  1146. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  1147. u32 len32);
  1148. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx);
  1149. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type);
  1150. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode);
  1151. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  1152. bool with_comp, u8 comp_type);
  1153. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port);
  1154. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
  1155. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
  1156. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param);
  1157. void bnx2x_calc_fc_adv(struct bnx2x *bp);
  1158. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  1159. u32 data_hi, u32 data_lo, int common);
  1160. void bnx2x_update_coalesce(struct bnx2x *bp);
  1161. int bnx2x_get_link_cfg_idx(struct bnx2x *bp);
  1162. static inline u32 reg_poll(struct bnx2x *bp, u32 reg, u32 expected, int ms,
  1163. int wait)
  1164. {
  1165. u32 val;
  1166. do {
  1167. val = REG_RD(bp, reg);
  1168. if (val == expected)
  1169. break;
  1170. ms -= wait;
  1171. msleep(wait);
  1172. } while (ms > 0);
  1173. return val;
  1174. }
  1175. #define BNX2X_ILT_ZALLOC(x, y, size) \
  1176. do { \
  1177. x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
  1178. if (x) \
  1179. memset(x, 0, size); \
  1180. } while (0)
  1181. #define BNX2X_ILT_FREE(x, y, size) \
  1182. do { \
  1183. if (x) { \
  1184. dma_free_coherent(&bp->pdev->dev, size, x, y); \
  1185. x = NULL; \
  1186. y = 0; \
  1187. } \
  1188. } while (0)
  1189. #define ILOG2(x) (ilog2((x)))
  1190. #define ILT_NUM_PAGE_ENTRIES (3072)
  1191. /* In 57710/11 we use whole table since we have 8 func
  1192. * In 57712 we have only 4 func, but use same size per func, then only half of
  1193. * the table in use
  1194. */
  1195. #define ILT_PER_FUNC (ILT_NUM_PAGE_ENTRIES/8)
  1196. #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
  1197. /*
  1198. * the phys address is shifted right 12 bits and has an added
  1199. * 1=valid bit added to the 53rd bit
  1200. * then since this is a wide register(TM)
  1201. * we split it into two 32 bit writes
  1202. */
  1203. #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
  1204. #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
  1205. /* load/unload mode */
  1206. #define LOAD_NORMAL 0
  1207. #define LOAD_OPEN 1
  1208. #define LOAD_DIAG 2
  1209. #define UNLOAD_NORMAL 0
  1210. #define UNLOAD_CLOSE 1
  1211. #define UNLOAD_RECOVERY 2
  1212. /* DMAE command defines */
  1213. #define DMAE_TIMEOUT -1
  1214. #define DMAE_PCI_ERROR -2 /* E2 and onward */
  1215. #define DMAE_NOT_RDY -3
  1216. #define DMAE_PCI_ERR_FLAG 0x80000000
  1217. #define DMAE_SRC_PCI 0
  1218. #define DMAE_SRC_GRC 1
  1219. #define DMAE_DST_NONE 0
  1220. #define DMAE_DST_PCI 1
  1221. #define DMAE_DST_GRC 2
  1222. #define DMAE_COMP_PCI 0
  1223. #define DMAE_COMP_GRC 1
  1224. /* E2 and onward - PCI error handling in the completion */
  1225. #define DMAE_COMP_REGULAR 0
  1226. #define DMAE_COM_SET_ERR 1
  1227. #define DMAE_CMD_SRC_PCI (DMAE_SRC_PCI << \
  1228. DMAE_COMMAND_SRC_SHIFT)
  1229. #define DMAE_CMD_SRC_GRC (DMAE_SRC_GRC << \
  1230. DMAE_COMMAND_SRC_SHIFT)
  1231. #define DMAE_CMD_DST_PCI (DMAE_DST_PCI << \
  1232. DMAE_COMMAND_DST_SHIFT)
  1233. #define DMAE_CMD_DST_GRC (DMAE_DST_GRC << \
  1234. DMAE_COMMAND_DST_SHIFT)
  1235. #define DMAE_CMD_C_DST_PCI (DMAE_COMP_PCI << \
  1236. DMAE_COMMAND_C_DST_SHIFT)
  1237. #define DMAE_CMD_C_DST_GRC (DMAE_COMP_GRC << \
  1238. DMAE_COMMAND_C_DST_SHIFT)
  1239. #define DMAE_CMD_C_ENABLE DMAE_COMMAND_C_TYPE_ENABLE
  1240. #define DMAE_CMD_ENDIANITY_NO_SWAP (0 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1241. #define DMAE_CMD_ENDIANITY_B_SWAP (1 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1242. #define DMAE_CMD_ENDIANITY_DW_SWAP (2 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1243. #define DMAE_CMD_ENDIANITY_B_DW_SWAP (3 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1244. #define DMAE_CMD_PORT_0 0
  1245. #define DMAE_CMD_PORT_1 DMAE_COMMAND_PORT
  1246. #define DMAE_CMD_SRC_RESET DMAE_COMMAND_SRC_RESET
  1247. #define DMAE_CMD_DST_RESET DMAE_COMMAND_DST_RESET
  1248. #define DMAE_CMD_E1HVN_SHIFT DMAE_COMMAND_E1HVN_SHIFT
  1249. #define DMAE_SRC_PF 0
  1250. #define DMAE_SRC_VF 1
  1251. #define DMAE_DST_PF 0
  1252. #define DMAE_DST_VF 1
  1253. #define DMAE_C_SRC 0
  1254. #define DMAE_C_DST 1
  1255. #define DMAE_LEN32_RD_MAX 0x80
  1256. #define DMAE_LEN32_WR_MAX(bp) (CHIP_IS_E1(bp) ? 0x400 : 0x2000)
  1257. #define DMAE_COMP_VAL 0x60d0d0ae /* E2 and on - upper bit
  1258. indicates eror */
  1259. #define MAX_DMAE_C_PER_PORT 8
  1260. #define INIT_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
  1261. BP_E1HVN(bp))
  1262. #define PMF_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
  1263. E1HVN_MAX)
  1264. /* PCIE link and speed */
  1265. #define PCICFG_LINK_WIDTH 0x1f00000
  1266. #define PCICFG_LINK_WIDTH_SHIFT 20
  1267. #define PCICFG_LINK_SPEED 0xf0000
  1268. #define PCICFG_LINK_SPEED_SHIFT 16
  1269. #define BNX2X_NUM_TESTS 7
  1270. #define BNX2X_PHY_LOOPBACK 0
  1271. #define BNX2X_MAC_LOOPBACK 1
  1272. #define BNX2X_PHY_LOOPBACK_FAILED 1
  1273. #define BNX2X_MAC_LOOPBACK_FAILED 2
  1274. #define BNX2X_LOOPBACK_FAILED (BNX2X_MAC_LOOPBACK_FAILED | \
  1275. BNX2X_PHY_LOOPBACK_FAILED)
  1276. #define STROM_ASSERT_ARRAY_SIZE 50
  1277. /* must be used on a CID before placing it on a HW ring */
  1278. #define HW_CID(bp, x) ((BP_PORT(bp) << 23) | \
  1279. (BP_E1HVN(bp) << 17) | (x))
  1280. #define SP_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_spe))
  1281. #define MAX_SP_DESC_CNT (SP_DESC_CNT - 1)
  1282. #define BNX2X_BTR 4
  1283. #define MAX_SPQ_PENDING 8
  1284. /* CMNG constants
  1285. derived from lab experiments, and not from system spec calculations !!! */
  1286. #define DEF_MIN_RATE 100
  1287. /* resolution of the rate shaping timer - 100 usec */
  1288. #define RS_PERIODIC_TIMEOUT_USEC 100
  1289. /* resolution of fairness algorithm in usecs -
  1290. coefficient for calculating the actual t fair */
  1291. #define T_FAIR_COEF 10000000
  1292. /* number of bytes in single QM arbitration cycle -
  1293. coefficient for calculating the fairness timer */
  1294. #define QM_ARB_BYTES 40000
  1295. #define FAIR_MEM 2
  1296. #define ATTN_NIG_FOR_FUNC (1L << 8)
  1297. #define ATTN_SW_TIMER_4_FUNC (1L << 9)
  1298. #define GPIO_2_FUNC (1L << 10)
  1299. #define GPIO_3_FUNC (1L << 11)
  1300. #define GPIO_4_FUNC (1L << 12)
  1301. #define ATTN_GENERAL_ATTN_1 (1L << 13)
  1302. #define ATTN_GENERAL_ATTN_2 (1L << 14)
  1303. #define ATTN_GENERAL_ATTN_3 (1L << 15)
  1304. #define ATTN_GENERAL_ATTN_4 (1L << 13)
  1305. #define ATTN_GENERAL_ATTN_5 (1L << 14)
  1306. #define ATTN_GENERAL_ATTN_6 (1L << 15)
  1307. #define ATTN_HARD_WIRED_MASK 0xff00
  1308. #define ATTENTION_ID 4
  1309. /* stuff added to make the code fit 80Col */
  1310. #define BNX2X_PMF_LINK_ASSERT \
  1311. GENERAL_ATTEN_OFFSET(LINK_SYNC_ATTENTION_BIT_FUNC_0 + BP_FUNC(bp))
  1312. #define BNX2X_MC_ASSERT_BITS \
  1313. (GENERAL_ATTEN_OFFSET(TSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1314. GENERAL_ATTEN_OFFSET(USTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1315. GENERAL_ATTEN_OFFSET(CSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1316. GENERAL_ATTEN_OFFSET(XSTORM_FATAL_ASSERT_ATTENTION_BIT))
  1317. #define BNX2X_MCP_ASSERT \
  1318. GENERAL_ATTEN_OFFSET(MCP_FATAL_ASSERT_ATTENTION_BIT)
  1319. #define BNX2X_GRC_TIMEOUT GENERAL_ATTEN_OFFSET(LATCHED_ATTN_TIMEOUT_GRC)
  1320. #define BNX2X_GRC_RSV (GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCR) | \
  1321. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCT) | \
  1322. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCN) | \
  1323. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCU) | \
  1324. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCP) | \
  1325. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RSVD_GRC))
  1326. #define HW_INTERRUT_ASSERT_SET_0 \
  1327. (AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT | \
  1328. AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT | \
  1329. AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT | \
  1330. AEU_INPUTS_ATTN_BITS_PBF_HW_INTERRUPT)
  1331. #define HW_PRTY_ASSERT_SET_0 (AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR | \
  1332. AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR | \
  1333. AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR | \
  1334. AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR |\
  1335. AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR)
  1336. #define HW_INTERRUT_ASSERT_SET_1 \
  1337. (AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT | \
  1338. AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT | \
  1339. AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT | \
  1340. AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT | \
  1341. AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT | \
  1342. AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT | \
  1343. AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT | \
  1344. AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT | \
  1345. AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT | \
  1346. AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT | \
  1347. AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT)
  1348. #define HW_PRTY_ASSERT_SET_1 (AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR |\
  1349. AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR | \
  1350. AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR | \
  1351. AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR | \
  1352. AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR |\
  1353. AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR |\
  1354. AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR | \
  1355. AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR | \
  1356. AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR | \
  1357. AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR | \
  1358. AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR)
  1359. #define HW_INTERRUT_ASSERT_SET_2 \
  1360. (AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT | \
  1361. AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT | \
  1362. AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT | \
  1363. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT |\
  1364. AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT)
  1365. #define HW_PRTY_ASSERT_SET_2 (AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR | \
  1366. AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR | \
  1367. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR |\
  1368. AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR | \
  1369. AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR | \
  1370. AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR | \
  1371. AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR)
  1372. #define HW_PRTY_ASSERT_SET_3 (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
  1373. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
  1374. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY | \
  1375. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
  1376. #define RSS_FLAGS(bp) \
  1377. (TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY | \
  1378. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY | \
  1379. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY | \
  1380. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY | \
  1381. (bp->multi_mode << \
  1382. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_MODE_SHIFT))
  1383. #define MULTI_MASK 0x7f
  1384. #define BNX2X_SP_DSB_INDEX \
  1385. (&bp->def_status_blk->sp_sb.\
  1386. index_values[HC_SP_INDEX_ETH_DEF_CONS])
  1387. #define SET_FLAG(value, mask, flag) \
  1388. do {\
  1389. (value) &= ~(mask);\
  1390. (value) |= ((flag) << (mask##_SHIFT));\
  1391. } while (0)
  1392. #define GET_FLAG(value, mask) \
  1393. (((value) &= (mask)) >> (mask##_SHIFT))
  1394. #define GET_FIELD(value, fname) \
  1395. (((value) & (fname##_MASK)) >> (fname##_SHIFT))
  1396. #define CAM_IS_INVALID(x) \
  1397. (GET_FLAG(x.flags, \
  1398. MAC_CONFIGURATION_ENTRY_ACTION_TYPE) == \
  1399. (T_ETH_MAC_COMMAND_INVALIDATE))
  1400. /* Number of u32 elements in MC hash array */
  1401. #define MC_HASH_SIZE 8
  1402. #define MC_HASH_OFFSET(bp, i) (BAR_TSTRORM_INTMEM + \
  1403. TSTORM_APPROXIMATE_MATCH_MULTICAST_FILTERING_OFFSET(BP_FUNC(bp)) + i*4)
  1404. #ifndef PXP2_REG_PXP2_INT_STS
  1405. #define PXP2_REG_PXP2_INT_STS PXP2_REG_PXP2_INT_STS_0
  1406. #endif
  1407. #ifndef ETH_MAX_RX_CLIENTS_E2
  1408. #define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
  1409. #endif
  1410. #define BNX2X_VPD_LEN 128
  1411. #define VENDOR_ID_LEN 4
  1412. /* Congestion management fairness mode */
  1413. #define CMNG_FNS_NONE 0
  1414. #define CMNG_FNS_MINMAX 1
  1415. #define HC_SEG_ACCESS_DEF 0 /*Driver decision 0-3*/
  1416. #define HC_SEG_ACCESS_ATTN 4
  1417. #define HC_SEG_ACCESS_NORM 0 /*Driver decision 0-1*/
  1418. #ifdef BNX2X_MAIN
  1419. #define BNX2X_EXTERN
  1420. #else
  1421. #define BNX2X_EXTERN extern
  1422. #endif
  1423. BNX2X_EXTERN int load_count[2][3]; /* per path: 0-common, 1-port0, 2-port1 */
  1424. extern void bnx2x_set_ethtool_ops(struct net_device *netdev);
  1425. #endif /* bnx2x.h */