bnx2x.h 52 KB

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