bnx2x.h 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103
  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/dma-mapping.h>
  17. #include <linux/types.h>
  18. /* compilation time flags */
  19. /* define this to make the driver freeze on error to allow getting debug info
  20. * (you will need to reboot afterwards) */
  21. /* #define BNX2X_STOP_ON_ERROR */
  22. #define DRV_MODULE_VERSION "1.70.35-0"
  23. #define DRV_MODULE_RELDATE "2011/11/10"
  24. #define BNX2X_BC_VER 0x040200
  25. #if defined(CONFIG_DCB)
  26. #define BCM_DCBNL
  27. #endif
  28. #if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
  29. #define BCM_CNIC 1
  30. #include "../cnic_if.h"
  31. #endif
  32. #ifdef BCM_CNIC
  33. #define BNX2X_MIN_MSIX_VEC_CNT 3
  34. #define BNX2X_MSIX_VEC_FP_START 2
  35. #else
  36. #define BNX2X_MIN_MSIX_VEC_CNT 2
  37. #define BNX2X_MSIX_VEC_FP_START 1
  38. #endif
  39. #include <linux/mdio.h>
  40. #include "bnx2x_reg.h"
  41. #include "bnx2x_fw_defs.h"
  42. #include "bnx2x_hsi.h"
  43. #include "bnx2x_link.h"
  44. #include "bnx2x_sp.h"
  45. #include "bnx2x_dcb.h"
  46. #include "bnx2x_stats.h"
  47. /* error/debug prints */
  48. #define DRV_MODULE_NAME "bnx2x"
  49. /* for messages that are currently off */
  50. #define BNX2X_MSG_OFF 0
  51. #define BNX2X_MSG_MCP 0x010000 /* was: NETIF_MSG_HW */
  52. #define BNX2X_MSG_STATS 0x020000 /* was: NETIF_MSG_TIMER */
  53. #define BNX2X_MSG_NVM 0x040000 /* was: NETIF_MSG_HW */
  54. #define BNX2X_MSG_DMAE 0x080000 /* was: NETIF_MSG_HW */
  55. #define BNX2X_MSG_SP 0x100000 /* was: NETIF_MSG_INTR */
  56. #define BNX2X_MSG_FP 0x200000 /* was: NETIF_MSG_INTR */
  57. /* regular debug print */
  58. #define DP(__mask, fmt, ...) \
  59. do { \
  60. if (bp->msg_enable & (__mask)) \
  61. pr_notice("[%s:%d(%s)]" fmt, \
  62. __func__, __LINE__, \
  63. bp->dev ? (bp->dev->name) : "?", \
  64. ##__VA_ARGS__); \
  65. } while (0)
  66. #define DP_CONT(__mask, fmt, ...) \
  67. do { \
  68. if (bp->msg_enable & (__mask)) \
  69. pr_cont(fmt, ##__VA_ARGS__); \
  70. } while (0)
  71. /* errors debug print */
  72. #define BNX2X_DBG_ERR(fmt, ...) \
  73. do { \
  74. if (netif_msg_probe(bp)) \
  75. pr_err("[%s:%d(%s)]" fmt, \
  76. __func__, __LINE__, \
  77. bp->dev ? (bp->dev->name) : "?", \
  78. ##__VA_ARGS__); \
  79. } while (0)
  80. /* for errors (never masked) */
  81. #define BNX2X_ERR(fmt, ...) \
  82. do { \
  83. pr_err("[%s:%d(%s)]" fmt, \
  84. __func__, __LINE__, \
  85. bp->dev ? (bp->dev->name) : "?", \
  86. ##__VA_ARGS__); \
  87. } while (0)
  88. #define BNX2X_ERROR(fmt, ...) \
  89. pr_err("[%s:%d]" fmt, __func__, __LINE__, ##__VA_ARGS__)
  90. /* before we have a dev->name use dev_info() */
  91. #define BNX2X_DEV_INFO(fmt, ...) \
  92. do { \
  93. if (netif_msg_probe(bp)) \
  94. dev_info(&bp->pdev->dev, fmt, ##__VA_ARGS__); \
  95. } while (0)
  96. #ifdef BNX2X_STOP_ON_ERROR
  97. void bnx2x_int_disable(struct bnx2x *bp);
  98. #define bnx2x_panic() \
  99. do { \
  100. bp->panic = 1; \
  101. BNX2X_ERR("driver assert\n"); \
  102. bnx2x_int_disable(bp); \
  103. bnx2x_panic_dump(bp); \
  104. } while (0)
  105. #else
  106. #define bnx2x_panic() \
  107. do { \
  108. bp->panic = 1; \
  109. BNX2X_ERR("driver assert\n"); \
  110. bnx2x_panic_dump(bp); \
  111. } while (0)
  112. #endif
  113. #define bnx2x_mc_addr(ha) ((ha)->addr)
  114. #define bnx2x_uc_addr(ha) ((ha)->addr)
  115. #define U64_LO(x) (u32)(((u64)(x)) & 0xffffffff)
  116. #define U64_HI(x) (u32)(((u64)(x)) >> 32)
  117. #define HILO_U64(hi, lo) ((((u64)(hi)) << 32) + (lo))
  118. #define REG_ADDR(bp, offset) ((bp->regview) + (offset))
  119. #define REG_RD(bp, offset) readl(REG_ADDR(bp, offset))
  120. #define REG_RD8(bp, offset) readb(REG_ADDR(bp, offset))
  121. #define REG_RD16(bp, offset) readw(REG_ADDR(bp, offset))
  122. #define REG_WR(bp, offset, val) writel((u32)val, REG_ADDR(bp, offset))
  123. #define REG_WR8(bp, offset, val) writeb((u8)val, REG_ADDR(bp, offset))
  124. #define REG_WR16(bp, offset, val) writew((u16)val, REG_ADDR(bp, offset))
  125. #define REG_RD_IND(bp, offset) bnx2x_reg_rd_ind(bp, offset)
  126. #define REG_WR_IND(bp, offset, val) bnx2x_reg_wr_ind(bp, offset, val)
  127. #define REG_RD_DMAE(bp, offset, valp, len32) \
  128. do { \
  129. bnx2x_read_dmae(bp, offset, len32);\
  130. memcpy(valp, bnx2x_sp(bp, wb_data[0]), (len32) * 4); \
  131. } while (0)
  132. #define REG_WR_DMAE(bp, offset, valp, len32) \
  133. do { \
  134. memcpy(bnx2x_sp(bp, wb_data[0]), valp, (len32) * 4); \
  135. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), \
  136. offset, len32); \
  137. } while (0)
  138. #define REG_WR_DMAE_LEN(bp, offset, valp, len32) \
  139. REG_WR_DMAE(bp, offset, valp, len32)
  140. #define VIRT_WR_DMAE_LEN(bp, data, addr, len32, le32_swap) \
  141. do { \
  142. memcpy(GUNZIP_BUF(bp), data, (len32) * 4); \
  143. bnx2x_write_big_buf_wb(bp, addr, len32); \
  144. } while (0)
  145. #define SHMEM_ADDR(bp, field) (bp->common.shmem_base + \
  146. offsetof(struct shmem_region, field))
  147. #define SHMEM_RD(bp, field) REG_RD(bp, SHMEM_ADDR(bp, field))
  148. #define SHMEM_WR(bp, field, val) REG_WR(bp, SHMEM_ADDR(bp, field), val)
  149. #define SHMEM2_ADDR(bp, field) (bp->common.shmem2_base + \
  150. offsetof(struct shmem2_region, field))
  151. #define SHMEM2_RD(bp, field) REG_RD(bp, SHMEM2_ADDR(bp, field))
  152. #define SHMEM2_WR(bp, field, val) REG_WR(bp, SHMEM2_ADDR(bp, field), val)
  153. #define MF_CFG_ADDR(bp, field) (bp->common.mf_cfg_base + \
  154. offsetof(struct mf_cfg, field))
  155. #define MF2_CFG_ADDR(bp, field) (bp->common.mf2_cfg_base + \
  156. offsetof(struct mf2_cfg, field))
  157. #define MF_CFG_RD(bp, field) REG_RD(bp, MF_CFG_ADDR(bp, field))
  158. #define MF_CFG_WR(bp, field, val) REG_WR(bp,\
  159. MF_CFG_ADDR(bp, field), (val))
  160. #define MF2_CFG_RD(bp, field) REG_RD(bp, MF2_CFG_ADDR(bp, field))
  161. #define SHMEM2_HAS(bp, field) ((bp)->common.shmem2_base && \
  162. (SHMEM2_RD((bp), size) > \
  163. offsetof(struct shmem2_region, field)))
  164. #define EMAC_RD(bp, reg) REG_RD(bp, emac_base + reg)
  165. #define EMAC_WR(bp, reg, val) REG_WR(bp, emac_base + reg, val)
  166. /* SP SB indices */
  167. /* General SP events - stats query, cfc delete, etc */
  168. #define HC_SP_INDEX_ETH_DEF_CONS 3
  169. /* EQ completions */
  170. #define HC_SP_INDEX_EQ_CONS 7
  171. /* FCoE L2 connection completions */
  172. #define HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS 6
  173. #define HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS 4
  174. /* iSCSI L2 */
  175. #define HC_SP_INDEX_ETH_ISCSI_CQ_CONS 5
  176. #define HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS 1
  177. /* Special clients parameters */
  178. /* SB indices */
  179. /* FCoE L2 */
  180. #define BNX2X_FCOE_L2_RX_INDEX \
  181. (&bp->def_status_blk->sp_sb.\
  182. index_values[HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS])
  183. #define BNX2X_FCOE_L2_TX_INDEX \
  184. (&bp->def_status_blk->sp_sb.\
  185. index_values[HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS])
  186. /**
  187. * CIDs and CLIDs:
  188. * CLIDs below is a CLID for func 0, then the CLID for other
  189. * functions will be calculated by the formula:
  190. *
  191. * FUNC_N_CLID_X = N * NUM_SPECIAL_CLIENTS + FUNC_0_CLID_X
  192. *
  193. */
  194. enum {
  195. BNX2X_ISCSI_ETH_CL_ID_IDX,
  196. BNX2X_FCOE_ETH_CL_ID_IDX,
  197. BNX2X_MAX_CNIC_ETH_CL_ID_IDX,
  198. };
  199. #define BNX2X_CNIC_START_ETH_CID 48
  200. enum {
  201. /* iSCSI L2 */
  202. BNX2X_ISCSI_ETH_CID = BNX2X_CNIC_START_ETH_CID,
  203. /* FCoE L2 */
  204. BNX2X_FCOE_ETH_CID,
  205. };
  206. /** Additional rings budgeting */
  207. #ifdef BCM_CNIC
  208. #define CNIC_PRESENT 1
  209. #define FCOE_PRESENT 1
  210. #else
  211. #define CNIC_PRESENT 0
  212. #define FCOE_PRESENT 0
  213. #endif /* BCM_CNIC */
  214. #define NON_ETH_CONTEXT_USE (FCOE_PRESENT)
  215. #define AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR \
  216. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR
  217. #define SM_RX_ID 0
  218. #define SM_TX_ID 1
  219. /* defines for multiple tx priority indices */
  220. #define FIRST_TX_ONLY_COS_INDEX 1
  221. #define FIRST_TX_COS_INDEX 0
  222. /* defines for decodeing the fastpath index and the cos index out of the
  223. * transmission queue index
  224. */
  225. #define MAX_TXQS_PER_COS FP_SB_MAX_E1x
  226. #define TXQ_TO_FP(txq_index) ((txq_index) % MAX_TXQS_PER_COS)
  227. #define TXQ_TO_COS(txq_index) ((txq_index) / MAX_TXQS_PER_COS)
  228. /* rules for calculating the cids of tx-only connections */
  229. #define CID_TO_FP(cid) ((cid) % MAX_TXQS_PER_COS)
  230. #define CID_COS_TO_TX_ONLY_CID(cid, cos) (cid + cos * MAX_TXQS_PER_COS)
  231. /* fp index inside class of service range */
  232. #define FP_COS_TO_TXQ(fp, cos) ((fp)->index + cos * MAX_TXQS_PER_COS)
  233. /*
  234. * 0..15 eth cos0
  235. * 16..31 eth cos1 if applicable
  236. * 32..47 eth cos2 If applicable
  237. * fcoe queue follows eth queues (16, 32, 48 depending on cos)
  238. */
  239. #define MAX_ETH_TXQ_IDX(bp) (MAX_TXQS_PER_COS * (bp)->max_cos)
  240. #define FCOE_TXQ_IDX(bp) (MAX_ETH_TXQ_IDX(bp))
  241. /* fast path */
  242. /*
  243. * This driver uses new build_skb() API :
  244. * RX ring buffer contains pointer to kmalloc() data only,
  245. * skb are built only after Hardware filled the frame.
  246. */
  247. struct sw_rx_bd {
  248. u8 *data;
  249. DEFINE_DMA_UNMAP_ADDR(mapping);
  250. };
  251. struct sw_tx_bd {
  252. struct sk_buff *skb;
  253. u16 first_bd;
  254. u8 flags;
  255. /* Set on the first BD descriptor when there is a split BD */
  256. #define BNX2X_TSO_SPLIT_BD (1<<0)
  257. };
  258. struct sw_rx_page {
  259. struct page *page;
  260. DEFINE_DMA_UNMAP_ADDR(mapping);
  261. };
  262. union db_prod {
  263. struct doorbell_set_prod data;
  264. u32 raw;
  265. };
  266. /* dropless fc FW/HW related params */
  267. #define BRB_SIZE(bp) (CHIP_IS_E3(bp) ? 1024 : 512)
  268. #define MAX_AGG_QS(bp) (CHIP_IS_E1(bp) ? \
  269. ETH_MAX_AGGREGATION_QUEUES_E1 :\
  270. ETH_MAX_AGGREGATION_QUEUES_E1H_E2)
  271. #define FW_DROP_LEVEL(bp) (3 + MAX_SPQ_PENDING + MAX_AGG_QS(bp))
  272. #define FW_PREFETCH_CNT 16
  273. #define DROPLESS_FC_HEADROOM 100
  274. /* MC hsi */
  275. #define BCM_PAGE_SHIFT 12
  276. #define BCM_PAGE_SIZE (1 << BCM_PAGE_SHIFT)
  277. #define BCM_PAGE_MASK (~(BCM_PAGE_SIZE - 1))
  278. #define BCM_PAGE_ALIGN(addr) (((addr) + BCM_PAGE_SIZE - 1) & BCM_PAGE_MASK)
  279. #define PAGES_PER_SGE_SHIFT 0
  280. #define PAGES_PER_SGE (1 << PAGES_PER_SGE_SHIFT)
  281. #define SGE_PAGE_SIZE PAGE_SIZE
  282. #define SGE_PAGE_SHIFT PAGE_SHIFT
  283. #define SGE_PAGE_ALIGN(addr) PAGE_ALIGN((typeof(PAGE_SIZE))(addr))
  284. /* SGE ring related macros */
  285. #define NUM_RX_SGE_PAGES 2
  286. #define RX_SGE_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_sge))
  287. #define NEXT_PAGE_SGE_DESC_CNT 2
  288. #define MAX_RX_SGE_CNT (RX_SGE_CNT - NEXT_PAGE_SGE_DESC_CNT)
  289. /* RX_SGE_CNT is promised to be a power of 2 */
  290. #define RX_SGE_MASK (RX_SGE_CNT - 1)
  291. #define NUM_RX_SGE (RX_SGE_CNT * NUM_RX_SGE_PAGES)
  292. #define MAX_RX_SGE (NUM_RX_SGE - 1)
  293. #define NEXT_SGE_IDX(x) ((((x) & RX_SGE_MASK) == \
  294. (MAX_RX_SGE_CNT - 1)) ? \
  295. (x) + 1 + NEXT_PAGE_SGE_DESC_CNT : \
  296. (x) + 1)
  297. #define RX_SGE(x) ((x) & MAX_RX_SGE)
  298. /*
  299. * Number of required SGEs is the sum of two:
  300. * 1. Number of possible opened aggregations (next packet for
  301. * these aggregations will probably consume SGE immidiatelly)
  302. * 2. Rest of BRB blocks divided by 2 (block will consume new SGE only
  303. * after placement on BD for new TPA aggregation)
  304. *
  305. * Takes into account NEXT_PAGE_SGE_DESC_CNT "next" elements on each page
  306. */
  307. #define NUM_SGE_REQ (MAX_AGG_QS(bp) + \
  308. (BRB_SIZE(bp) - MAX_AGG_QS(bp)) / 2)
  309. #define NUM_SGE_PG_REQ ((NUM_SGE_REQ + MAX_RX_SGE_CNT - 1) / \
  310. MAX_RX_SGE_CNT)
  311. #define SGE_TH_LO(bp) (NUM_SGE_REQ + \
  312. NUM_SGE_PG_REQ * NEXT_PAGE_SGE_DESC_CNT)
  313. #define SGE_TH_HI(bp) (SGE_TH_LO(bp) + DROPLESS_FC_HEADROOM)
  314. /* Manipulate a bit vector defined as an array of u64 */
  315. /* Number of bits in one sge_mask array element */
  316. #define BIT_VEC64_ELEM_SZ 64
  317. #define BIT_VEC64_ELEM_SHIFT 6
  318. #define BIT_VEC64_ELEM_MASK ((u64)BIT_VEC64_ELEM_SZ - 1)
  319. #define __BIT_VEC64_SET_BIT(el, bit) \
  320. do { \
  321. el = ((el) | ((u64)0x1 << (bit))); \
  322. } while (0)
  323. #define __BIT_VEC64_CLEAR_BIT(el, bit) \
  324. do { \
  325. el = ((el) & (~((u64)0x1 << (bit)))); \
  326. } while (0)
  327. #define BIT_VEC64_SET_BIT(vec64, idx) \
  328. __BIT_VEC64_SET_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
  329. (idx) & BIT_VEC64_ELEM_MASK)
  330. #define BIT_VEC64_CLEAR_BIT(vec64, idx) \
  331. __BIT_VEC64_CLEAR_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
  332. (idx) & BIT_VEC64_ELEM_MASK)
  333. #define BIT_VEC64_TEST_BIT(vec64, idx) \
  334. (((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT] >> \
  335. ((idx) & BIT_VEC64_ELEM_MASK)) & 0x1)
  336. /* Creates a bitmask of all ones in less significant bits.
  337. idx - index of the most significant bit in the created mask */
  338. #define BIT_VEC64_ONES_MASK(idx) \
  339. (((u64)0x1 << (((idx) & BIT_VEC64_ELEM_MASK) + 1)) - 1)
  340. #define BIT_VEC64_ELEM_ONE_MASK ((u64)(~0))
  341. /*******************************************************/
  342. /* Number of u64 elements in SGE mask array */
  343. #define RX_SGE_MASK_LEN (NUM_RX_SGE / BIT_VEC64_ELEM_SZ)
  344. #define RX_SGE_MASK_LEN_MASK (RX_SGE_MASK_LEN - 1)
  345. #define NEXT_SGE_MASK_ELEM(el) (((el) + 1) & RX_SGE_MASK_LEN_MASK)
  346. union host_hc_status_block {
  347. /* pointer to fp status block e1x */
  348. struct host_hc_status_block_e1x *e1x_sb;
  349. /* pointer to fp status block e2 */
  350. struct host_hc_status_block_e2 *e2_sb;
  351. };
  352. struct bnx2x_agg_info {
  353. /*
  354. * First aggregation buffer is a data buffer, the following - are pages.
  355. * We will preallocate the data buffer for each aggregation when
  356. * we open the interface and will replace the BD at the consumer
  357. * with this one when we receive the TPA_START CQE in order to
  358. * keep the Rx BD ring consistent.
  359. */
  360. struct sw_rx_bd first_buf;
  361. u8 tpa_state;
  362. #define BNX2X_TPA_START 1
  363. #define BNX2X_TPA_STOP 2
  364. #define BNX2X_TPA_ERROR 3
  365. u8 placement_offset;
  366. u16 parsing_flags;
  367. u16 vlan_tag;
  368. u16 len_on_bd;
  369. u32 rxhash;
  370. };
  371. #define Q_STATS_OFFSET32(stat_name) \
  372. (offsetof(struct bnx2x_eth_q_stats, stat_name) / 4)
  373. struct bnx2x_fp_txdata {
  374. struct sw_tx_bd *tx_buf_ring;
  375. union eth_tx_bd_types *tx_desc_ring;
  376. dma_addr_t tx_desc_mapping;
  377. u32 cid;
  378. union db_prod tx_db;
  379. u16 tx_pkt_prod;
  380. u16 tx_pkt_cons;
  381. u16 tx_bd_prod;
  382. u16 tx_bd_cons;
  383. unsigned long tx_pkt;
  384. __le16 *tx_cons_sb;
  385. int txq_index;
  386. };
  387. struct bnx2x_fastpath {
  388. struct bnx2x *bp; /* parent */
  389. #define BNX2X_NAPI_WEIGHT 128
  390. struct napi_struct napi;
  391. union host_hc_status_block status_blk;
  392. /* chip independed shortcuts into sb structure */
  393. __le16 *sb_index_values;
  394. __le16 *sb_running_index;
  395. /* chip independed shortcut into rx_prods_offset memory */
  396. u32 ustorm_rx_prods_offset;
  397. u32 rx_buf_size;
  398. dma_addr_t status_blk_mapping;
  399. u8 max_cos; /* actual number of active tx coses */
  400. struct bnx2x_fp_txdata txdata[BNX2X_MULTI_TX_COS];
  401. struct sw_rx_bd *rx_buf_ring; /* BDs mappings ring */
  402. struct sw_rx_page *rx_page_ring; /* SGE pages mappings ring */
  403. struct eth_rx_bd *rx_desc_ring;
  404. dma_addr_t rx_desc_mapping;
  405. union eth_rx_cqe *rx_comp_ring;
  406. dma_addr_t rx_comp_mapping;
  407. /* SGE ring */
  408. struct eth_rx_sge *rx_sge_ring;
  409. dma_addr_t rx_sge_mapping;
  410. u64 sge_mask[RX_SGE_MASK_LEN];
  411. u32 cid;
  412. __le16 fp_hc_idx;
  413. u8 index; /* number in fp array */
  414. u8 rx_queue; /* index for skb_record */
  415. u8 cl_id; /* eth client id */
  416. u8 cl_qzone_id;
  417. u8 fw_sb_id; /* status block number in FW */
  418. u8 igu_sb_id; /* status block number in HW */
  419. u16 rx_bd_prod;
  420. u16 rx_bd_cons;
  421. u16 rx_comp_prod;
  422. u16 rx_comp_cons;
  423. u16 rx_sge_prod;
  424. /* The last maximal completed SGE */
  425. u16 last_max_sge;
  426. __le16 *rx_cons_sb;
  427. unsigned long rx_pkt,
  428. rx_calls;
  429. /* TPA related */
  430. struct bnx2x_agg_info tpa_info[ETH_MAX_AGGREGATION_QUEUES_E1H_E2];
  431. u8 disable_tpa;
  432. #ifdef BNX2X_STOP_ON_ERROR
  433. u64 tpa_queue_used;
  434. #endif
  435. struct tstorm_per_queue_stats old_tclient;
  436. struct ustorm_per_queue_stats old_uclient;
  437. struct xstorm_per_queue_stats old_xclient;
  438. struct bnx2x_eth_q_stats eth_q_stats;
  439. /* The size is calculated using the following:
  440. sizeof name field from netdev structure +
  441. 4 ('-Xx-' string) +
  442. 4 (for the digits and to make it DWORD aligned) */
  443. #define FP_NAME_SIZE (sizeof(((struct net_device *)0)->name) + 8)
  444. char name[FP_NAME_SIZE];
  445. /* MACs object */
  446. struct bnx2x_vlan_mac_obj mac_obj;
  447. /* Queue State object */
  448. struct bnx2x_queue_sp_obj q_obj;
  449. };
  450. #define bnx2x_fp(bp, nr, var) (bp->fp[nr].var)
  451. /* Use 2500 as a mini-jumbo MTU for FCoE */
  452. #define BNX2X_FCOE_MINI_JUMBO_MTU 2500
  453. /* FCoE L2 `fastpath' entry is right after the eth entries */
  454. #define FCOE_IDX BNX2X_NUM_ETH_QUEUES(bp)
  455. #define bnx2x_fcoe_fp(bp) (&bp->fp[FCOE_IDX])
  456. #define bnx2x_fcoe(bp, var) (bnx2x_fcoe_fp(bp)->var)
  457. #define bnx2x_fcoe_tx(bp, var) (bnx2x_fcoe_fp(bp)-> \
  458. txdata[FIRST_TX_COS_INDEX].var)
  459. #define IS_ETH_FP(fp) (fp->index < \
  460. BNX2X_NUM_ETH_QUEUES(fp->bp))
  461. #ifdef BCM_CNIC
  462. #define IS_FCOE_FP(fp) (fp->index == FCOE_IDX)
  463. #define IS_FCOE_IDX(idx) ((idx) == FCOE_IDX)
  464. #else
  465. #define IS_FCOE_FP(fp) false
  466. #define IS_FCOE_IDX(idx) false
  467. #endif
  468. /* MC hsi */
  469. #define MAX_FETCH_BD 13 /* HW max BDs per packet */
  470. #define RX_COPY_THRESH 92
  471. #define NUM_TX_RINGS 16
  472. #define TX_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_tx_bd_types))
  473. #define NEXT_PAGE_TX_DESC_CNT 1
  474. #define MAX_TX_DESC_CNT (TX_DESC_CNT - NEXT_PAGE_TX_DESC_CNT)
  475. #define NUM_TX_BD (TX_DESC_CNT * NUM_TX_RINGS)
  476. #define MAX_TX_BD (NUM_TX_BD - 1)
  477. #define MAX_TX_AVAIL (MAX_TX_DESC_CNT * NUM_TX_RINGS - 2)
  478. #define NEXT_TX_IDX(x) ((((x) & MAX_TX_DESC_CNT) == \
  479. (MAX_TX_DESC_CNT - 1)) ? \
  480. (x) + 1 + NEXT_PAGE_TX_DESC_CNT : \
  481. (x) + 1)
  482. #define TX_BD(x) ((x) & MAX_TX_BD)
  483. #define TX_BD_POFF(x) ((x) & MAX_TX_DESC_CNT)
  484. /* The RX BD ring is special, each bd is 8 bytes but the last one is 16 */
  485. #define NUM_RX_RINGS 8
  486. #define RX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_bd))
  487. #define NEXT_PAGE_RX_DESC_CNT 2
  488. #define MAX_RX_DESC_CNT (RX_DESC_CNT - NEXT_PAGE_RX_DESC_CNT)
  489. #define RX_DESC_MASK (RX_DESC_CNT - 1)
  490. #define NUM_RX_BD (RX_DESC_CNT * NUM_RX_RINGS)
  491. #define MAX_RX_BD (NUM_RX_BD - 1)
  492. #define MAX_RX_AVAIL (MAX_RX_DESC_CNT * NUM_RX_RINGS - 2)
  493. /* dropless fc calculations for BDs
  494. *
  495. * Number of BDs should as number of buffers in BRB:
  496. * Low threshold takes into account NEXT_PAGE_RX_DESC_CNT
  497. * "next" elements on each page
  498. */
  499. #define NUM_BD_REQ BRB_SIZE(bp)
  500. #define NUM_BD_PG_REQ ((NUM_BD_REQ + MAX_RX_DESC_CNT - 1) / \
  501. MAX_RX_DESC_CNT)
  502. #define BD_TH_LO(bp) (NUM_BD_REQ + \
  503. NUM_BD_PG_REQ * NEXT_PAGE_RX_DESC_CNT + \
  504. FW_DROP_LEVEL(bp))
  505. #define BD_TH_HI(bp) (BD_TH_LO(bp) + DROPLESS_FC_HEADROOM)
  506. #define MIN_RX_AVAIL ((bp)->dropless_fc ? BD_TH_HI(bp) + 128 : 128)
  507. #define MIN_RX_SIZE_TPA_HW (CHIP_IS_E1(bp) ? \
  508. ETH_MIN_RX_CQES_WITH_TPA_E1 : \
  509. ETH_MIN_RX_CQES_WITH_TPA_E1H_E2)
  510. #define MIN_RX_SIZE_NONTPA_HW ETH_MIN_RX_CQES_WITHOUT_TPA
  511. #define MIN_RX_SIZE_TPA (max_t(u32, MIN_RX_SIZE_TPA_HW, MIN_RX_AVAIL))
  512. #define MIN_RX_SIZE_NONTPA (max_t(u32, MIN_RX_SIZE_NONTPA_HW,\
  513. MIN_RX_AVAIL))
  514. #define NEXT_RX_IDX(x) ((((x) & RX_DESC_MASK) == \
  515. (MAX_RX_DESC_CNT - 1)) ? \
  516. (x) + 1 + NEXT_PAGE_RX_DESC_CNT : \
  517. (x) + 1)
  518. #define RX_BD(x) ((x) & MAX_RX_BD)
  519. /*
  520. * As long as CQE is X times bigger than BD entry we have to allocate X times
  521. * more pages for CQ ring in order to keep it balanced with BD ring
  522. */
  523. #define CQE_BD_REL (sizeof(union eth_rx_cqe) / sizeof(struct eth_rx_bd))
  524. #define NUM_RCQ_RINGS (NUM_RX_RINGS * CQE_BD_REL)
  525. #define RCQ_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_rx_cqe))
  526. #define NEXT_PAGE_RCQ_DESC_CNT 1
  527. #define MAX_RCQ_DESC_CNT (RCQ_DESC_CNT - NEXT_PAGE_RCQ_DESC_CNT)
  528. #define NUM_RCQ_BD (RCQ_DESC_CNT * NUM_RCQ_RINGS)
  529. #define MAX_RCQ_BD (NUM_RCQ_BD - 1)
  530. #define MAX_RCQ_AVAIL (MAX_RCQ_DESC_CNT * NUM_RCQ_RINGS - 2)
  531. #define NEXT_RCQ_IDX(x) ((((x) & MAX_RCQ_DESC_CNT) == \
  532. (MAX_RCQ_DESC_CNT - 1)) ? \
  533. (x) + 1 + NEXT_PAGE_RCQ_DESC_CNT : \
  534. (x) + 1)
  535. #define RCQ_BD(x) ((x) & MAX_RCQ_BD)
  536. /* dropless fc calculations for RCQs
  537. *
  538. * Number of RCQs should be as number of buffers in BRB:
  539. * Low threshold takes into account NEXT_PAGE_RCQ_DESC_CNT
  540. * "next" elements on each page
  541. */
  542. #define NUM_RCQ_REQ BRB_SIZE(bp)
  543. #define NUM_RCQ_PG_REQ ((NUM_BD_REQ + MAX_RCQ_DESC_CNT - 1) / \
  544. MAX_RCQ_DESC_CNT)
  545. #define RCQ_TH_LO(bp) (NUM_RCQ_REQ + \
  546. NUM_RCQ_PG_REQ * NEXT_PAGE_RCQ_DESC_CNT + \
  547. FW_DROP_LEVEL(bp))
  548. #define RCQ_TH_HI(bp) (RCQ_TH_LO(bp) + DROPLESS_FC_HEADROOM)
  549. /* This is needed for determining of last_max */
  550. #define SUB_S16(a, b) (s16)((s16)(a) - (s16)(b))
  551. #define SUB_S32(a, b) (s32)((s32)(a) - (s32)(b))
  552. #define BNX2X_SWCID_SHIFT 17
  553. #define BNX2X_SWCID_MASK ((0x1 << BNX2X_SWCID_SHIFT) - 1)
  554. /* used on a CID received from the HW */
  555. #define SW_CID(x) (le32_to_cpu(x) & BNX2X_SWCID_MASK)
  556. #define CQE_CMD(x) (le32_to_cpu(x) >> \
  557. COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT)
  558. #define BD_UNMAP_ADDR(bd) HILO_U64(le32_to_cpu((bd)->addr_hi), \
  559. le32_to_cpu((bd)->addr_lo))
  560. #define BD_UNMAP_LEN(bd) (le16_to_cpu((bd)->nbytes))
  561. #define BNX2X_DB_MIN_SHIFT 3 /* 8 bytes */
  562. #define BNX2X_DB_SHIFT 7 /* 128 bytes*/
  563. #if (BNX2X_DB_SHIFT < BNX2X_DB_MIN_SHIFT)
  564. #error "Min DB doorbell stride is 8"
  565. #endif
  566. #define DPM_TRIGER_TYPE 0x40
  567. #define DOORBELL(bp, cid, val) \
  568. do { \
  569. writel((u32)(val), bp->doorbells + (bp->db_size * (cid)) + \
  570. DPM_TRIGER_TYPE); \
  571. } while (0)
  572. /* TX CSUM helpers */
  573. #define SKB_CS_OFF(skb) (offsetof(struct tcphdr, check) - \
  574. skb->csum_offset)
  575. #define SKB_CS(skb) (*(u16 *)(skb_transport_header(skb) + \
  576. skb->csum_offset))
  577. #define pbd_tcp_flags(skb) (ntohl(tcp_flag_word(tcp_hdr(skb)))>>16 & 0xff)
  578. #define XMIT_PLAIN 0
  579. #define XMIT_CSUM_V4 0x1
  580. #define XMIT_CSUM_V6 0x2
  581. #define XMIT_CSUM_TCP 0x4
  582. #define XMIT_GSO_V4 0x8
  583. #define XMIT_GSO_V6 0x10
  584. #define XMIT_CSUM (XMIT_CSUM_V4 | XMIT_CSUM_V6)
  585. #define XMIT_GSO (XMIT_GSO_V4 | XMIT_GSO_V6)
  586. /* stuff added to make the code fit 80Col */
  587. #define CQE_TYPE(cqe_fp_flags) ((cqe_fp_flags) & ETH_FAST_PATH_RX_CQE_TYPE)
  588. #define CQE_TYPE_START(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_START_AGG)
  589. #define CQE_TYPE_STOP(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_STOP_AGG)
  590. #define CQE_TYPE_SLOW(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_RAMROD)
  591. #define CQE_TYPE_FAST(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_FASTPATH)
  592. #define ETH_RX_ERROR_FALGS ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG
  593. #define BNX2X_IP_CSUM_ERR(cqe) \
  594. (!((cqe)->fast_path_cqe.status_flags & \
  595. ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG) && \
  596. ((cqe)->fast_path_cqe.type_error_flags & \
  597. ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG))
  598. #define BNX2X_L4_CSUM_ERR(cqe) \
  599. (!((cqe)->fast_path_cqe.status_flags & \
  600. ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG) && \
  601. ((cqe)->fast_path_cqe.type_error_flags & \
  602. ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG))
  603. #define BNX2X_RX_CSUM_OK(cqe) \
  604. (!(BNX2X_L4_CSUM_ERR(cqe) || BNX2X_IP_CSUM_ERR(cqe)))
  605. #define BNX2X_PRS_FLAG_OVERETH_IPV4(flags) \
  606. (((le16_to_cpu(flags) & \
  607. PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) >> \
  608. PARSING_FLAGS_OVER_ETHERNET_PROTOCOL_SHIFT) \
  609. == PRS_FLAG_OVERETH_IPV4)
  610. #define BNX2X_RX_SUM_FIX(cqe) \
  611. BNX2X_PRS_FLAG_OVERETH_IPV4(cqe->fast_path_cqe.pars_flags.flags)
  612. #define FP_USB_FUNC_OFF \
  613. offsetof(struct cstorm_status_block_u, func)
  614. #define FP_CSB_FUNC_OFF \
  615. offsetof(struct cstorm_status_block_c, func)
  616. #define HC_INDEX_ETH_RX_CQ_CONS 1
  617. #define HC_INDEX_OOO_TX_CQ_CONS 4
  618. #define HC_INDEX_ETH_TX_CQ_CONS_COS0 5
  619. #define HC_INDEX_ETH_TX_CQ_CONS_COS1 6
  620. #define HC_INDEX_ETH_TX_CQ_CONS_COS2 7
  621. #define HC_INDEX_ETH_FIRST_TX_CQ_CONS HC_INDEX_ETH_TX_CQ_CONS_COS0
  622. #define BNX2X_RX_SB_INDEX \
  623. (&fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS])
  624. #define BNX2X_TX_SB_INDEX_BASE BNX2X_TX_SB_INDEX_COS0
  625. #define BNX2X_TX_SB_INDEX_COS0 \
  626. (&fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0])
  627. /* end of fast path */
  628. /* common */
  629. struct bnx2x_common {
  630. u32 chip_id;
  631. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  632. #define CHIP_ID(bp) (bp->common.chip_id & 0xfffffff0)
  633. #define CHIP_NUM(bp) (bp->common.chip_id >> 16)
  634. #define CHIP_NUM_57710 0x164e
  635. #define CHIP_NUM_57711 0x164f
  636. #define CHIP_NUM_57711E 0x1650
  637. #define CHIP_NUM_57712 0x1662
  638. #define CHIP_NUM_57712_MF 0x1663
  639. #define CHIP_NUM_57713 0x1651
  640. #define CHIP_NUM_57713E 0x1652
  641. #define CHIP_NUM_57800 0x168a
  642. #define CHIP_NUM_57800_MF 0x16a5
  643. #define CHIP_NUM_57810 0x168e
  644. #define CHIP_NUM_57810_MF 0x16ae
  645. #define CHIP_NUM_57840 0x168d
  646. #define CHIP_NUM_57840_MF 0x16ab
  647. #define CHIP_IS_E1(bp) (CHIP_NUM(bp) == CHIP_NUM_57710)
  648. #define CHIP_IS_57711(bp) (CHIP_NUM(bp) == CHIP_NUM_57711)
  649. #define CHIP_IS_57711E(bp) (CHIP_NUM(bp) == CHIP_NUM_57711E)
  650. #define CHIP_IS_57712(bp) (CHIP_NUM(bp) == CHIP_NUM_57712)
  651. #define CHIP_IS_57712_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57712_MF)
  652. #define CHIP_IS_57800(bp) (CHIP_NUM(bp) == CHIP_NUM_57800)
  653. #define CHIP_IS_57800_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57800_MF)
  654. #define CHIP_IS_57810(bp) (CHIP_NUM(bp) == CHIP_NUM_57810)
  655. #define CHIP_IS_57810_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57810_MF)
  656. #define CHIP_IS_57840(bp) (CHIP_NUM(bp) == CHIP_NUM_57840)
  657. #define CHIP_IS_57840_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57840_MF)
  658. #define CHIP_IS_E1H(bp) (CHIP_IS_57711(bp) || \
  659. CHIP_IS_57711E(bp))
  660. #define CHIP_IS_E2(bp) (CHIP_IS_57712(bp) || \
  661. CHIP_IS_57712_MF(bp))
  662. #define CHIP_IS_E3(bp) (CHIP_IS_57800(bp) || \
  663. CHIP_IS_57800_MF(bp) || \
  664. CHIP_IS_57810(bp) || \
  665. CHIP_IS_57810_MF(bp) || \
  666. CHIP_IS_57840(bp) || \
  667. CHIP_IS_57840_MF(bp))
  668. #define CHIP_IS_E1x(bp) (CHIP_IS_E1((bp)) || CHIP_IS_E1H((bp)))
  669. #define USES_WARPCORE(bp) (CHIP_IS_E3(bp))
  670. #define IS_E1H_OFFSET (!CHIP_IS_E1(bp))
  671. #define CHIP_REV_SHIFT 12
  672. #define CHIP_REV_MASK (0xF << CHIP_REV_SHIFT)
  673. #define CHIP_REV_VAL(bp) (bp->common.chip_id & CHIP_REV_MASK)
  674. #define CHIP_REV_Ax (0x0 << CHIP_REV_SHIFT)
  675. #define CHIP_REV_Bx (0x1 << CHIP_REV_SHIFT)
  676. /* assume maximum 5 revisions */
  677. #define CHIP_REV_IS_SLOW(bp) (CHIP_REV_VAL(bp) > 0x00005000)
  678. /* Emul versions are A=>0xe, B=>0xc, C=>0xa, D=>8, E=>6 */
  679. #define CHIP_REV_IS_EMUL(bp) ((CHIP_REV_IS_SLOW(bp)) && \
  680. !(CHIP_REV_VAL(bp) & 0x00001000))
  681. /* FPGA versions are A=>0xf, B=>0xd, C=>0xb, D=>9, E=>7 */
  682. #define CHIP_REV_IS_FPGA(bp) ((CHIP_REV_IS_SLOW(bp)) && \
  683. (CHIP_REV_VAL(bp) & 0x00001000))
  684. #define CHIP_TIME(bp) ((CHIP_REV_IS_EMUL(bp)) ? 2000 : \
  685. ((CHIP_REV_IS_FPGA(bp)) ? 200 : 1))
  686. #define CHIP_METAL(bp) (bp->common.chip_id & 0x00000ff0)
  687. #define CHIP_BOND_ID(bp) (bp->common.chip_id & 0x0000000f)
  688. #define CHIP_REV_SIM(bp) (((CHIP_REV_MASK - CHIP_REV_VAL(bp)) >>\
  689. (CHIP_REV_SHIFT + 1)) \
  690. << CHIP_REV_SHIFT)
  691. #define CHIP_REV(bp) (CHIP_REV_IS_SLOW(bp) ? \
  692. CHIP_REV_SIM(bp) :\
  693. CHIP_REV_VAL(bp))
  694. #define CHIP_IS_E3B0(bp) (CHIP_IS_E3(bp) && \
  695. (CHIP_REV(bp) == CHIP_REV_Bx))
  696. #define CHIP_IS_E3A0(bp) (CHIP_IS_E3(bp) && \
  697. (CHIP_REV(bp) == CHIP_REV_Ax))
  698. int flash_size;
  699. #define BNX2X_NVRAM_1MB_SIZE 0x20000 /* 1M bit in bytes */
  700. #define BNX2X_NVRAM_TIMEOUT_COUNT 30000
  701. #define BNX2X_NVRAM_PAGE_SIZE 256
  702. u32 shmem_base;
  703. u32 shmem2_base;
  704. u32 mf_cfg_base;
  705. u32 mf2_cfg_base;
  706. u32 hw_config;
  707. u32 bc_ver;
  708. u8 int_block;
  709. #define INT_BLOCK_HC 0
  710. #define INT_BLOCK_IGU 1
  711. #define INT_BLOCK_MODE_NORMAL 0
  712. #define INT_BLOCK_MODE_BW_COMP 2
  713. #define CHIP_INT_MODE_IS_NBC(bp) \
  714. (!CHIP_IS_E1x(bp) && \
  715. !((bp)->common.int_block & INT_BLOCK_MODE_BW_COMP))
  716. #define CHIP_INT_MODE_IS_BC(bp) (!CHIP_INT_MODE_IS_NBC(bp))
  717. u8 chip_port_mode;
  718. #define CHIP_4_PORT_MODE 0x0
  719. #define CHIP_2_PORT_MODE 0x1
  720. #define CHIP_PORT_MODE_NONE 0x2
  721. #define CHIP_MODE(bp) (bp->common.chip_port_mode)
  722. #define CHIP_MODE_IS_4_PORT(bp) (CHIP_MODE(bp) == CHIP_4_PORT_MODE)
  723. };
  724. /* IGU MSIX STATISTICS on 57712: 64 for VFs; 4 for PFs; 4 for Attentions */
  725. #define BNX2X_IGU_STAS_MSG_VF_CNT 64
  726. #define BNX2X_IGU_STAS_MSG_PF_CNT 4
  727. /* end of common */
  728. /* port */
  729. struct bnx2x_port {
  730. u32 pmf;
  731. u32 link_config[LINK_CONFIG_SIZE];
  732. u32 supported[LINK_CONFIG_SIZE];
  733. /* link settings - missing defines */
  734. #define SUPPORTED_2500baseX_Full (1 << 15)
  735. u32 advertising[LINK_CONFIG_SIZE];
  736. /* link settings - missing defines */
  737. #define ADVERTISED_2500baseX_Full (1 << 15)
  738. u32 phy_addr;
  739. /* used to synchronize phy accesses */
  740. struct mutex phy_mutex;
  741. int need_hw_lock;
  742. u32 port_stx;
  743. struct nig_stats old_nig_stats;
  744. };
  745. /* end of port */
  746. #define STATS_OFFSET32(stat_name) \
  747. (offsetof(struct bnx2x_eth_stats, stat_name) / 4)
  748. /* slow path */
  749. /* slow path work-queue */
  750. extern struct workqueue_struct *bnx2x_wq;
  751. #define BNX2X_MAX_NUM_OF_VFS 64
  752. #define BNX2X_VF_ID_INVALID 0xFF
  753. /*
  754. * The total number of L2 queues, MSIX vectors and HW contexts (CIDs) is
  755. * control by the number of fast-path status blocks supported by the
  756. * device (HW/FW). Each fast-path status block (FP-SB) aka non-default
  757. * status block represents an independent interrupts context that can
  758. * serve a regular L2 networking queue. However special L2 queues such
  759. * as the FCoE queue do not require a FP-SB and other components like
  760. * the CNIC may consume FP-SB reducing the number of possible L2 queues
  761. *
  762. * If the maximum number of FP-SB available is X then:
  763. * a. If CNIC is supported it consumes 1 FP-SB thus the max number of
  764. * regular L2 queues is Y=X-1
  765. * b. in MF mode the actual number of L2 queues is Y= (X-1/MF_factor)
  766. * c. If the FCoE L2 queue is supported the actual number of L2 queues
  767. * is Y+1
  768. * d. The number of irqs (MSIX vectors) is either Y+1 (one extra for
  769. * slow-path interrupts) or Y+2 if CNIC is supported (one additional
  770. * FP interrupt context for the CNIC).
  771. * e. The number of HW context (CID count) is always X or X+1 if FCoE
  772. * L2 queue is supported. the cid for the FCoE L2 queue is always X.
  773. */
  774. /* fast-path interrupt contexts E1x */
  775. #define FP_SB_MAX_E1x 16
  776. /* fast-path interrupt contexts E2 */
  777. #define FP_SB_MAX_E2 HC_SB_MAX_SB_E2
  778. union cdu_context {
  779. struct eth_context eth;
  780. char pad[1024];
  781. };
  782. /* CDU host DB constants */
  783. #define CDU_ILT_PAGE_SZ_HW 3
  784. #define CDU_ILT_PAGE_SZ (8192 << CDU_ILT_PAGE_SZ_HW) /* 64K */
  785. #define ILT_PAGE_CIDS (CDU_ILT_PAGE_SZ / sizeof(union cdu_context))
  786. #ifdef BCM_CNIC
  787. #define CNIC_ISCSI_CID_MAX 256
  788. #define CNIC_FCOE_CID_MAX 2048
  789. #define CNIC_CID_MAX (CNIC_ISCSI_CID_MAX + CNIC_FCOE_CID_MAX)
  790. #define CNIC_ILT_LINES DIV_ROUND_UP(CNIC_CID_MAX, ILT_PAGE_CIDS)
  791. #endif
  792. #define QM_ILT_PAGE_SZ_HW 0
  793. #define QM_ILT_PAGE_SZ (4096 << QM_ILT_PAGE_SZ_HW) /* 4K */
  794. #define QM_CID_ROUND 1024
  795. #ifdef BCM_CNIC
  796. /* TM (timers) host DB constants */
  797. #define TM_ILT_PAGE_SZ_HW 0
  798. #define TM_ILT_PAGE_SZ (4096 << TM_ILT_PAGE_SZ_HW) /* 4K */
  799. /* #define TM_CONN_NUM (CNIC_STARTING_CID+CNIC_ISCSI_CXT_MAX) */
  800. #define TM_CONN_NUM 1024
  801. #define TM_ILT_SZ (8 * TM_CONN_NUM)
  802. #define TM_ILT_LINES DIV_ROUND_UP(TM_ILT_SZ, TM_ILT_PAGE_SZ)
  803. /* SRC (Searcher) host DB constants */
  804. #define SRC_ILT_PAGE_SZ_HW 0
  805. #define SRC_ILT_PAGE_SZ (4096 << SRC_ILT_PAGE_SZ_HW) /* 4K */
  806. #define SRC_HASH_BITS 10
  807. #define SRC_CONN_NUM (1 << SRC_HASH_BITS) /* 1024 */
  808. #define SRC_ILT_SZ (sizeof(struct src_ent) * SRC_CONN_NUM)
  809. #define SRC_T2_SZ SRC_ILT_SZ
  810. #define SRC_ILT_LINES DIV_ROUND_UP(SRC_ILT_SZ, SRC_ILT_PAGE_SZ)
  811. #endif
  812. #define MAX_DMAE_C 8
  813. /* DMA memory not used in fastpath */
  814. struct bnx2x_slowpath {
  815. union {
  816. struct mac_configuration_cmd e1x;
  817. struct eth_classify_rules_ramrod_data e2;
  818. } mac_rdata;
  819. union {
  820. struct tstorm_eth_mac_filter_config e1x;
  821. struct eth_filter_rules_ramrod_data e2;
  822. } rx_mode_rdata;
  823. union {
  824. struct mac_configuration_cmd e1;
  825. struct eth_multicast_rules_ramrod_data e2;
  826. } mcast_rdata;
  827. struct eth_rss_update_ramrod_data rss_rdata;
  828. /* Queue State related ramrods are always sent under rtnl_lock */
  829. union {
  830. struct client_init_ramrod_data init_data;
  831. struct client_update_ramrod_data update_data;
  832. } q_rdata;
  833. union {
  834. struct function_start_data func_start;
  835. /* pfc configuration for DCBX ramrod */
  836. struct flow_control_configuration pfc_config;
  837. } func_rdata;
  838. /* used by dmae command executer */
  839. struct dmae_command dmae[MAX_DMAE_C];
  840. u32 stats_comp;
  841. union mac_stats mac_stats;
  842. struct nig_stats nig_stats;
  843. struct host_port_stats port_stats;
  844. struct host_func_stats func_stats;
  845. struct host_func_stats func_stats_base;
  846. u32 wb_comp;
  847. u32 wb_data[4];
  848. };
  849. #define bnx2x_sp(bp, var) (&bp->slowpath->var)
  850. #define bnx2x_sp_mapping(bp, var) \
  851. (bp->slowpath_mapping + offsetof(struct bnx2x_slowpath, var))
  852. /* attn group wiring */
  853. #define MAX_DYNAMIC_ATTN_GRPS 8
  854. struct attn_route {
  855. u32 sig[5];
  856. };
  857. struct iro {
  858. u32 base;
  859. u16 m1;
  860. u16 m2;
  861. u16 m3;
  862. u16 size;
  863. };
  864. struct hw_context {
  865. union cdu_context *vcxt;
  866. dma_addr_t cxt_mapping;
  867. size_t size;
  868. };
  869. /* forward */
  870. struct bnx2x_ilt;
  871. enum bnx2x_recovery_state {
  872. BNX2X_RECOVERY_DONE,
  873. BNX2X_RECOVERY_INIT,
  874. BNX2X_RECOVERY_WAIT,
  875. BNX2X_RECOVERY_FAILED
  876. };
  877. /*
  878. * Event queue (EQ or event ring) MC hsi
  879. * NUM_EQ_PAGES and EQ_DESC_CNT_PAGE must be power of 2
  880. */
  881. #define NUM_EQ_PAGES 1
  882. #define EQ_DESC_CNT_PAGE (BCM_PAGE_SIZE / sizeof(union event_ring_elem))
  883. #define EQ_DESC_MAX_PAGE (EQ_DESC_CNT_PAGE - 1)
  884. #define NUM_EQ_DESC (EQ_DESC_CNT_PAGE * NUM_EQ_PAGES)
  885. #define EQ_DESC_MASK (NUM_EQ_DESC - 1)
  886. #define MAX_EQ_AVAIL (EQ_DESC_MAX_PAGE * NUM_EQ_PAGES - 2)
  887. /* depends on EQ_DESC_CNT_PAGE being a power of 2 */
  888. #define NEXT_EQ_IDX(x) ((((x) & EQ_DESC_MAX_PAGE) == \
  889. (EQ_DESC_MAX_PAGE - 1)) ? (x) + 2 : (x) + 1)
  890. /* depends on the above and on NUM_EQ_PAGES being a power of 2 */
  891. #define EQ_DESC(x) ((x) & EQ_DESC_MASK)
  892. #define BNX2X_EQ_INDEX \
  893. (&bp->def_status_blk->sp_sb.\
  894. index_values[HC_SP_INDEX_EQ_CONS])
  895. /* This is a data that will be used to create a link report message.
  896. * We will keep the data used for the last link report in order
  897. * to prevent reporting the same link parameters twice.
  898. */
  899. struct bnx2x_link_report_data {
  900. u16 line_speed; /* Effective line speed */
  901. unsigned long link_report_flags;/* BNX2X_LINK_REPORT_XXX flags */
  902. };
  903. enum {
  904. BNX2X_LINK_REPORT_FD, /* Full DUPLEX */
  905. BNX2X_LINK_REPORT_LINK_DOWN,
  906. BNX2X_LINK_REPORT_RX_FC_ON,
  907. BNX2X_LINK_REPORT_TX_FC_ON,
  908. };
  909. enum {
  910. BNX2X_PORT_QUERY_IDX,
  911. BNX2X_PF_QUERY_IDX,
  912. BNX2X_FCOE_QUERY_IDX,
  913. BNX2X_FIRST_QUEUE_QUERY_IDX,
  914. };
  915. struct bnx2x_fw_stats_req {
  916. struct stats_query_header hdr;
  917. struct stats_query_entry query[FP_SB_MAX_E1x+
  918. BNX2X_FIRST_QUEUE_QUERY_IDX];
  919. };
  920. struct bnx2x_fw_stats_data {
  921. struct stats_counter storm_counters;
  922. struct per_port_stats port;
  923. struct per_pf_stats pf;
  924. struct fcoe_statistics_params fcoe;
  925. struct per_queue_stats queue_stats[1];
  926. };
  927. /* Public slow path states */
  928. enum {
  929. BNX2X_SP_RTNL_SETUP_TC,
  930. BNX2X_SP_RTNL_TX_TIMEOUT,
  931. BNX2X_SP_RTNL_FAN_FAILURE,
  932. };
  933. struct bnx2x {
  934. /* Fields used in the tx and intr/napi performance paths
  935. * are grouped together in the beginning of the structure
  936. */
  937. struct bnx2x_fastpath *fp;
  938. void __iomem *regview;
  939. void __iomem *doorbells;
  940. u16 db_size;
  941. u8 pf_num; /* absolute PF number */
  942. u8 pfid; /* per-path PF number */
  943. int base_fw_ndsb; /**/
  944. #define BP_PATH(bp) (CHIP_IS_E1x(bp) ? 0 : (bp->pf_num & 1))
  945. #define BP_PORT(bp) (bp->pfid & 1)
  946. #define BP_FUNC(bp) (bp->pfid)
  947. #define BP_ABS_FUNC(bp) (bp->pf_num)
  948. #define BP_VN(bp) ((bp)->pfid >> 1)
  949. #define BP_MAX_VN_NUM(bp) (CHIP_MODE_IS_4_PORT(bp) ? 2 : 4)
  950. #define BP_L_ID(bp) (BP_VN(bp) << 2)
  951. #define BP_FW_MB_IDX_VN(bp, vn) (BP_PORT(bp) +\
  952. (vn) * ((CHIP_IS_E1x(bp) || (CHIP_MODE_IS_4_PORT(bp))) ? 2 : 1))
  953. #define BP_FW_MB_IDX(bp) BP_FW_MB_IDX_VN(bp, BP_VN(bp))
  954. struct net_device *dev;
  955. struct pci_dev *pdev;
  956. const struct iro *iro_arr;
  957. #define IRO (bp->iro_arr)
  958. enum bnx2x_recovery_state recovery_state;
  959. int is_leader;
  960. struct msix_entry *msix_table;
  961. int tx_ring_size;
  962. /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
  963. #define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
  964. #define ETH_MIN_PACKET_SIZE 60
  965. #define ETH_MAX_PACKET_SIZE 1500
  966. #define ETH_MAX_JUMBO_PACKET_SIZE 9600
  967. /* Max supported alignment is 256 (8 shift) */
  968. #define BNX2X_RX_ALIGN_SHIFT min(8, L1_CACHE_SHIFT)
  969. /* FW uses 2 Cache lines Alignment for start packet and size
  970. *
  971. * We assume skb_build() uses sizeof(struct skb_shared_info) bytes
  972. * at the end of skb->data, to avoid wasting a full cache line.
  973. * This reduces memory use (skb->truesize).
  974. */
  975. #define BNX2X_FW_RX_ALIGN_START (1UL << BNX2X_RX_ALIGN_SHIFT)
  976. #define BNX2X_FW_RX_ALIGN_END \
  977. max(1UL << BNX2X_RX_ALIGN_SHIFT, \
  978. SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
  979. #define BNX2X_PXP_DRAM_ALIGN (BNX2X_RX_ALIGN_SHIFT - 5)
  980. struct host_sp_status_block *def_status_blk;
  981. #define DEF_SB_IGU_ID 16
  982. #define DEF_SB_ID HC_SP_SB_ID
  983. __le16 def_idx;
  984. __le16 def_att_idx;
  985. u32 attn_state;
  986. struct attn_route attn_group[MAX_DYNAMIC_ATTN_GRPS];
  987. /* slow path ring */
  988. struct eth_spe *spq;
  989. dma_addr_t spq_mapping;
  990. u16 spq_prod_idx;
  991. struct eth_spe *spq_prod_bd;
  992. struct eth_spe *spq_last_bd;
  993. __le16 *dsb_sp_prod;
  994. atomic_t cq_spq_left; /* ETH_XXX ramrods credit */
  995. /* used to synchronize spq accesses */
  996. spinlock_t spq_lock;
  997. /* event queue */
  998. union event_ring_elem *eq_ring;
  999. dma_addr_t eq_mapping;
  1000. u16 eq_prod;
  1001. u16 eq_cons;
  1002. __le16 *eq_cons_sb;
  1003. atomic_t eq_spq_left; /* COMMON_XXX ramrods credit */
  1004. /* Counter for marking that there is a STAT_QUERY ramrod pending */
  1005. u16 stats_pending;
  1006. /* Counter for completed statistics ramrods */
  1007. u16 stats_comp;
  1008. /* End of fields used in the performance code paths */
  1009. int panic;
  1010. int msg_enable;
  1011. u32 flags;
  1012. #define PCIX_FLAG (1 << 0)
  1013. #define PCI_32BIT_FLAG (1 << 1)
  1014. #define ONE_PORT_FLAG (1 << 2)
  1015. #define NO_WOL_FLAG (1 << 3)
  1016. #define USING_DAC_FLAG (1 << 4)
  1017. #define USING_MSIX_FLAG (1 << 5)
  1018. #define USING_MSI_FLAG (1 << 6)
  1019. #define DISABLE_MSI_FLAG (1 << 7)
  1020. #define TPA_ENABLE_FLAG (1 << 8)
  1021. #define NO_MCP_FLAG (1 << 9)
  1022. #define BP_NOMCP(bp) (bp->flags & NO_MCP_FLAG)
  1023. #define MF_FUNC_DIS (1 << 11)
  1024. #define OWN_CNIC_IRQ (1 << 12)
  1025. #define NO_ISCSI_OOO_FLAG (1 << 13)
  1026. #define NO_ISCSI_FLAG (1 << 14)
  1027. #define NO_FCOE_FLAG (1 << 15)
  1028. #define BC_SUPPORTS_PFC_STATS (1 << 17)
  1029. #define NO_ISCSI(bp) ((bp)->flags & NO_ISCSI_FLAG)
  1030. #define NO_ISCSI_OOO(bp) ((bp)->flags & NO_ISCSI_OOO_FLAG)
  1031. #define NO_FCOE(bp) ((bp)->flags & NO_FCOE_FLAG)
  1032. int pm_cap;
  1033. int mrrs;
  1034. struct delayed_work sp_task;
  1035. struct delayed_work sp_rtnl_task;
  1036. struct delayed_work period_task;
  1037. struct timer_list timer;
  1038. int current_interval;
  1039. u16 fw_seq;
  1040. u16 fw_drv_pulse_wr_seq;
  1041. u32 func_stx;
  1042. struct link_params link_params;
  1043. struct link_vars link_vars;
  1044. u32 link_cnt;
  1045. struct bnx2x_link_report_data last_reported_link;
  1046. struct mdio_if_info mdio;
  1047. struct bnx2x_common common;
  1048. struct bnx2x_port port;
  1049. struct cmng_struct_per_port cmng;
  1050. u32 vn_weight_sum;
  1051. u32 mf_config[E1HVN_MAX];
  1052. u32 mf2_config[E2_FUNC_MAX];
  1053. u32 path_has_ovlan; /* E3 */
  1054. u16 mf_ov;
  1055. u8 mf_mode;
  1056. #define IS_MF(bp) (bp->mf_mode != 0)
  1057. #define IS_MF_SI(bp) (bp->mf_mode == MULTI_FUNCTION_SI)
  1058. #define IS_MF_SD(bp) (bp->mf_mode == MULTI_FUNCTION_SD)
  1059. u8 wol;
  1060. int rx_ring_size;
  1061. u16 tx_quick_cons_trip_int;
  1062. u16 tx_quick_cons_trip;
  1063. u16 tx_ticks_int;
  1064. u16 tx_ticks;
  1065. u16 rx_quick_cons_trip_int;
  1066. u16 rx_quick_cons_trip;
  1067. u16 rx_ticks_int;
  1068. u16 rx_ticks;
  1069. /* Maximal coalescing timeout in us */
  1070. #define BNX2X_MAX_COALESCE_TOUT (0xf0*12)
  1071. u32 lin_cnt;
  1072. u16 state;
  1073. #define BNX2X_STATE_CLOSED 0
  1074. #define BNX2X_STATE_OPENING_WAIT4_LOAD 0x1000
  1075. #define BNX2X_STATE_OPENING_WAIT4_PORT 0x2000
  1076. #define BNX2X_STATE_OPEN 0x3000
  1077. #define BNX2X_STATE_CLOSING_WAIT4_HALT 0x4000
  1078. #define BNX2X_STATE_CLOSING_WAIT4_DELETE 0x5000
  1079. #define BNX2X_STATE_DIAG 0xe000
  1080. #define BNX2X_STATE_ERROR 0xf000
  1081. int multi_mode;
  1082. #define BNX2X_MAX_PRIORITY 8
  1083. #define BNX2X_MAX_ENTRIES_PER_PRI 16
  1084. #define BNX2X_MAX_COS 3
  1085. #define BNX2X_MAX_TX_COS 2
  1086. int num_queues;
  1087. int disable_tpa;
  1088. u32 rx_mode;
  1089. #define BNX2X_RX_MODE_NONE 0
  1090. #define BNX2X_RX_MODE_NORMAL 1
  1091. #define BNX2X_RX_MODE_ALLMULTI 2
  1092. #define BNX2X_RX_MODE_PROMISC 3
  1093. #define BNX2X_MAX_MULTICAST 64
  1094. u8 igu_dsb_id;
  1095. u8 igu_base_sb;
  1096. u8 igu_sb_cnt;
  1097. dma_addr_t def_status_blk_mapping;
  1098. struct bnx2x_slowpath *slowpath;
  1099. dma_addr_t slowpath_mapping;
  1100. /* Total number of FW statistics requests */
  1101. u8 fw_stats_num;
  1102. /*
  1103. * This is a memory buffer that will contain both statistics
  1104. * ramrod request and data.
  1105. */
  1106. void *fw_stats;
  1107. dma_addr_t fw_stats_mapping;
  1108. /*
  1109. * FW statistics request shortcut (points at the
  1110. * beginning of fw_stats buffer).
  1111. */
  1112. struct bnx2x_fw_stats_req *fw_stats_req;
  1113. dma_addr_t fw_stats_req_mapping;
  1114. int fw_stats_req_sz;
  1115. /*
  1116. * FW statistics data shortcut (points at the begining of
  1117. * fw_stats buffer + fw_stats_req_sz).
  1118. */
  1119. struct bnx2x_fw_stats_data *fw_stats_data;
  1120. dma_addr_t fw_stats_data_mapping;
  1121. int fw_stats_data_sz;
  1122. struct hw_context context;
  1123. struct bnx2x_ilt *ilt;
  1124. #define BP_ILT(bp) ((bp)->ilt)
  1125. #define ILT_MAX_LINES 256
  1126. /*
  1127. * Maximum supported number of RSS queues: number of IGU SBs minus one that goes
  1128. * to CNIC.
  1129. */
  1130. #define BNX2X_MAX_RSS_COUNT(bp) ((bp)->igu_sb_cnt - CNIC_PRESENT)
  1131. /*
  1132. * Maximum CID count that might be required by the bnx2x:
  1133. * Max Tss * Max_Tx_Multi_Cos + CNIC L2 Clients (FCoE and iSCSI related)
  1134. */
  1135. #define BNX2X_L2_CID_COUNT(bp) (MAX_TXQS_PER_COS * BNX2X_MULTI_TX_COS +\
  1136. NON_ETH_CONTEXT_USE + CNIC_PRESENT)
  1137. #define L2_ILT_LINES(bp) (DIV_ROUND_UP(BNX2X_L2_CID_COUNT(bp),\
  1138. ILT_PAGE_CIDS))
  1139. #define BNX2X_DB_SIZE(bp) (BNX2X_L2_CID_COUNT(bp) * (1 << BNX2X_DB_SHIFT))
  1140. int qm_cid_count;
  1141. int dropless_fc;
  1142. #ifdef BCM_CNIC
  1143. u32 cnic_flags;
  1144. #define BNX2X_CNIC_FLAG_MAC_SET 1
  1145. void *t2;
  1146. dma_addr_t t2_mapping;
  1147. struct cnic_ops __rcu *cnic_ops;
  1148. void *cnic_data;
  1149. u32 cnic_tag;
  1150. struct cnic_eth_dev cnic_eth_dev;
  1151. union host_hc_status_block cnic_sb;
  1152. dma_addr_t cnic_sb_mapping;
  1153. struct eth_spe *cnic_kwq;
  1154. struct eth_spe *cnic_kwq_prod;
  1155. struct eth_spe *cnic_kwq_cons;
  1156. struct eth_spe *cnic_kwq_last;
  1157. u16 cnic_kwq_pending;
  1158. u16 cnic_spq_pending;
  1159. u8 fip_mac[ETH_ALEN];
  1160. struct mutex cnic_mutex;
  1161. struct bnx2x_vlan_mac_obj iscsi_l2_mac_obj;
  1162. /* Start index of the "special" (CNIC related) L2 cleints */
  1163. u8 cnic_base_cl_id;
  1164. #endif
  1165. int dmae_ready;
  1166. /* used to synchronize dmae accesses */
  1167. spinlock_t dmae_lock;
  1168. /* used to protect the FW mail box */
  1169. struct mutex fw_mb_mutex;
  1170. /* used to synchronize stats collecting */
  1171. int stats_state;
  1172. /* used for synchronization of concurrent threads statistics handling */
  1173. spinlock_t stats_lock;
  1174. /* used by dmae command loader */
  1175. struct dmae_command stats_dmae;
  1176. int executer_idx;
  1177. u16 stats_counter;
  1178. struct bnx2x_eth_stats eth_stats;
  1179. struct z_stream_s *strm;
  1180. void *gunzip_buf;
  1181. dma_addr_t gunzip_mapping;
  1182. int gunzip_outlen;
  1183. #define FW_BUF_SIZE 0x8000
  1184. #define GUNZIP_BUF(bp) (bp->gunzip_buf)
  1185. #define GUNZIP_PHYS(bp) (bp->gunzip_mapping)
  1186. #define GUNZIP_OUTLEN(bp) (bp->gunzip_outlen)
  1187. struct raw_op *init_ops;
  1188. /* Init blocks offsets inside init_ops */
  1189. u16 *init_ops_offsets;
  1190. /* Data blob - has 32 bit granularity */
  1191. u32 *init_data;
  1192. u32 init_mode_flags;
  1193. #define INIT_MODE_FLAGS(bp) (bp->init_mode_flags)
  1194. /* Zipped PRAM blobs - raw data */
  1195. const u8 *tsem_int_table_data;
  1196. const u8 *tsem_pram_data;
  1197. const u8 *usem_int_table_data;
  1198. const u8 *usem_pram_data;
  1199. const u8 *xsem_int_table_data;
  1200. const u8 *xsem_pram_data;
  1201. const u8 *csem_int_table_data;
  1202. const u8 *csem_pram_data;
  1203. #define INIT_OPS(bp) (bp->init_ops)
  1204. #define INIT_OPS_OFFSETS(bp) (bp->init_ops_offsets)
  1205. #define INIT_DATA(bp) (bp->init_data)
  1206. #define INIT_TSEM_INT_TABLE_DATA(bp) (bp->tsem_int_table_data)
  1207. #define INIT_TSEM_PRAM_DATA(bp) (bp->tsem_pram_data)
  1208. #define INIT_USEM_INT_TABLE_DATA(bp) (bp->usem_int_table_data)
  1209. #define INIT_USEM_PRAM_DATA(bp) (bp->usem_pram_data)
  1210. #define INIT_XSEM_INT_TABLE_DATA(bp) (bp->xsem_int_table_data)
  1211. #define INIT_XSEM_PRAM_DATA(bp) (bp->xsem_pram_data)
  1212. #define INIT_CSEM_INT_TABLE_DATA(bp) (bp->csem_int_table_data)
  1213. #define INIT_CSEM_PRAM_DATA(bp) (bp->csem_pram_data)
  1214. #define PHY_FW_VER_LEN 20
  1215. char fw_ver[32];
  1216. const struct firmware *firmware;
  1217. /* DCB support on/off */
  1218. u16 dcb_state;
  1219. #define BNX2X_DCB_STATE_OFF 0
  1220. #define BNX2X_DCB_STATE_ON 1
  1221. /* DCBX engine mode */
  1222. int dcbx_enabled;
  1223. #define BNX2X_DCBX_ENABLED_OFF 0
  1224. #define BNX2X_DCBX_ENABLED_ON_NEG_OFF 1
  1225. #define BNX2X_DCBX_ENABLED_ON_NEG_ON 2
  1226. #define BNX2X_DCBX_ENABLED_INVALID (-1)
  1227. bool dcbx_mode_uset;
  1228. struct bnx2x_config_dcbx_params dcbx_config_params;
  1229. struct bnx2x_dcbx_port_params dcbx_port_params;
  1230. int dcb_version;
  1231. /* CAM credit pools */
  1232. struct bnx2x_credit_pool_obj macs_pool;
  1233. /* RX_MODE object */
  1234. struct bnx2x_rx_mode_obj rx_mode_obj;
  1235. /* MCAST object */
  1236. struct bnx2x_mcast_obj mcast_obj;
  1237. /* RSS configuration object */
  1238. struct bnx2x_rss_config_obj rss_conf_obj;
  1239. /* Function State controlling object */
  1240. struct bnx2x_func_sp_obj func_obj;
  1241. unsigned long sp_state;
  1242. /* operation indication for the sp_rtnl task */
  1243. unsigned long sp_rtnl_state;
  1244. /* DCBX Negotation results */
  1245. struct dcbx_features dcbx_local_feat;
  1246. u32 dcbx_error;
  1247. #ifdef BCM_DCBNL
  1248. struct dcbx_features dcbx_remote_feat;
  1249. u32 dcbx_remote_flags;
  1250. #endif
  1251. u32 pending_max;
  1252. /* multiple tx classes of service */
  1253. u8 max_cos;
  1254. /* priority to cos mapping */
  1255. u8 prio_to_cos[8];
  1256. };
  1257. /* Tx queues may be less or equal to Rx queues */
  1258. extern int num_queues;
  1259. #define BNX2X_NUM_QUEUES(bp) (bp->num_queues)
  1260. #define BNX2X_NUM_ETH_QUEUES(bp) (BNX2X_NUM_QUEUES(bp) - NON_ETH_CONTEXT_USE)
  1261. #define BNX2X_NUM_RX_QUEUES(bp) BNX2X_NUM_QUEUES(bp)
  1262. #define is_multi(bp) (BNX2X_NUM_QUEUES(bp) > 1)
  1263. #define BNX2X_MAX_QUEUES(bp) BNX2X_MAX_RSS_COUNT(bp)
  1264. /* #define is_eth_multi(bp) (BNX2X_NUM_ETH_QUEUES(bp) > 1) */
  1265. #define RSS_IPV4_CAP_MASK \
  1266. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY
  1267. #define RSS_IPV4_TCP_CAP_MASK \
  1268. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY
  1269. #define RSS_IPV6_CAP_MASK \
  1270. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY
  1271. #define RSS_IPV6_TCP_CAP_MASK \
  1272. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY
  1273. /* func init flags */
  1274. #define FUNC_FLG_RSS 0x0001
  1275. #define FUNC_FLG_STATS 0x0002
  1276. /* removed FUNC_FLG_UNMATCHED 0x0004 */
  1277. #define FUNC_FLG_TPA 0x0008
  1278. #define FUNC_FLG_SPQ 0x0010
  1279. #define FUNC_FLG_LEADING 0x0020 /* PF only */
  1280. struct bnx2x_func_init_params {
  1281. /* dma */
  1282. dma_addr_t fw_stat_map; /* valid iff FUNC_FLG_STATS */
  1283. dma_addr_t spq_map; /* valid iff FUNC_FLG_SPQ */
  1284. u16 func_flgs;
  1285. u16 func_id; /* abs fid */
  1286. u16 pf_id;
  1287. u16 spq_prod; /* valid iff FUNC_FLG_SPQ */
  1288. };
  1289. #define for_each_eth_queue(bp, var) \
  1290. for ((var) = 0; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
  1291. #define for_each_nondefault_eth_queue(bp, var) \
  1292. for ((var) = 1; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
  1293. #define for_each_queue(bp, var) \
  1294. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1295. if (skip_queue(bp, var)) \
  1296. continue; \
  1297. else
  1298. /* Skip forwarding FP */
  1299. #define for_each_rx_queue(bp, var) \
  1300. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1301. if (skip_rx_queue(bp, var)) \
  1302. continue; \
  1303. else
  1304. /* Skip OOO FP */
  1305. #define for_each_tx_queue(bp, var) \
  1306. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1307. if (skip_tx_queue(bp, var)) \
  1308. continue; \
  1309. else
  1310. #define for_each_nondefault_queue(bp, var) \
  1311. for ((var) = 1; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1312. if (skip_queue(bp, var)) \
  1313. continue; \
  1314. else
  1315. #define for_each_cos_in_tx_queue(fp, var) \
  1316. for ((var) = 0; (var) < (fp)->max_cos; (var)++)
  1317. /* skip rx queue
  1318. * if FCOE l2 support is disabled and this is the fcoe L2 queue
  1319. */
  1320. #define skip_rx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1321. /* skip tx queue
  1322. * if FCOE l2 support is disabled and this is the fcoe L2 queue
  1323. */
  1324. #define skip_tx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1325. #define skip_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1326. /**
  1327. * bnx2x_set_mac_one - configure a single MAC address
  1328. *
  1329. * @bp: driver handle
  1330. * @mac: MAC to configure
  1331. * @obj: MAC object handle
  1332. * @set: if 'true' add a new MAC, otherwise - delete
  1333. * @mac_type: the type of the MAC to configure (e.g. ETH, UC list)
  1334. * @ramrod_flags: RAMROD_XXX flags (e.g. RAMROD_CONT, RAMROD_COMP_WAIT)
  1335. *
  1336. * Configures one MAC according to provided parameters or continues the
  1337. * execution of previously scheduled commands if RAMROD_CONT is set in
  1338. * ramrod_flags.
  1339. *
  1340. * Returns zero if operation has successfully completed, a positive value if the
  1341. * operation has been successfully scheduled and a negative - if a requested
  1342. * operations has failed.
  1343. */
  1344. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  1345. struct bnx2x_vlan_mac_obj *obj, bool set,
  1346. int mac_type, unsigned long *ramrod_flags);
  1347. /**
  1348. * Deletes all MACs configured for the specific MAC object.
  1349. *
  1350. * @param bp Function driver instance
  1351. * @param mac_obj MAC object to cleanup
  1352. *
  1353. * @return zero if all MACs were cleaned
  1354. */
  1355. /**
  1356. * bnx2x_del_all_macs - delete all MACs configured for the specific MAC object
  1357. *
  1358. * @bp: driver handle
  1359. * @mac_obj: MAC object handle
  1360. * @mac_type: type of the MACs to clear (BNX2X_XXX_MAC)
  1361. * @wait_for_comp: if 'true' block until completion
  1362. *
  1363. * Deletes all MACs of the specific type (e.g. ETH, UC list).
  1364. *
  1365. * Returns zero if operation has successfully completed, a positive value if the
  1366. * operation has been successfully scheduled and a negative - if a requested
  1367. * operations has failed.
  1368. */
  1369. int bnx2x_del_all_macs(struct bnx2x *bp,
  1370. struct bnx2x_vlan_mac_obj *mac_obj,
  1371. int mac_type, bool wait_for_comp);
  1372. /* Init Function API */
  1373. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p);
  1374. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port);
  1375. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
  1376. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode);
  1377. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
  1378. void bnx2x_read_mf_cfg(struct bnx2x *bp);
  1379. /* dmae */
  1380. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
  1381. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  1382. u32 len32);
  1383. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx);
  1384. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type);
  1385. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode);
  1386. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  1387. bool with_comp, u8 comp_type);
  1388. void bnx2x_calc_fc_adv(struct bnx2x *bp);
  1389. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  1390. u32 data_hi, u32 data_lo, int cmd_type);
  1391. void bnx2x_update_coalesce(struct bnx2x *bp);
  1392. int bnx2x_get_cur_phy_idx(struct bnx2x *bp);
  1393. static inline u32 reg_poll(struct bnx2x *bp, u32 reg, u32 expected, int ms,
  1394. int wait)
  1395. {
  1396. u32 val;
  1397. do {
  1398. val = REG_RD(bp, reg);
  1399. if (val == expected)
  1400. break;
  1401. ms -= wait;
  1402. msleep(wait);
  1403. } while (ms > 0);
  1404. return val;
  1405. }
  1406. #define BNX2X_ILT_ZALLOC(x, y, size) \
  1407. do { \
  1408. x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
  1409. if (x) \
  1410. memset(x, 0, size); \
  1411. } while (0)
  1412. #define BNX2X_ILT_FREE(x, y, size) \
  1413. do { \
  1414. if (x) { \
  1415. dma_free_coherent(&bp->pdev->dev, size, x, y); \
  1416. x = NULL; \
  1417. y = 0; \
  1418. } \
  1419. } while (0)
  1420. #define ILOG2(x) (ilog2((x)))
  1421. #define ILT_NUM_PAGE_ENTRIES (3072)
  1422. /* In 57710/11 we use whole table since we have 8 func
  1423. * In 57712 we have only 4 func, but use same size per func, then only half of
  1424. * the table in use
  1425. */
  1426. #define ILT_PER_FUNC (ILT_NUM_PAGE_ENTRIES/8)
  1427. #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
  1428. /*
  1429. * the phys address is shifted right 12 bits and has an added
  1430. * 1=valid bit added to the 53rd bit
  1431. * then since this is a wide register(TM)
  1432. * we split it into two 32 bit writes
  1433. */
  1434. #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
  1435. #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
  1436. /* load/unload mode */
  1437. #define LOAD_NORMAL 0
  1438. #define LOAD_OPEN 1
  1439. #define LOAD_DIAG 2
  1440. #define UNLOAD_NORMAL 0
  1441. #define UNLOAD_CLOSE 1
  1442. #define UNLOAD_RECOVERY 2
  1443. /* DMAE command defines */
  1444. #define DMAE_TIMEOUT -1
  1445. #define DMAE_PCI_ERROR -2 /* E2 and onward */
  1446. #define DMAE_NOT_RDY -3
  1447. #define DMAE_PCI_ERR_FLAG 0x80000000
  1448. #define DMAE_SRC_PCI 0
  1449. #define DMAE_SRC_GRC 1
  1450. #define DMAE_DST_NONE 0
  1451. #define DMAE_DST_PCI 1
  1452. #define DMAE_DST_GRC 2
  1453. #define DMAE_COMP_PCI 0
  1454. #define DMAE_COMP_GRC 1
  1455. /* E2 and onward - PCI error handling in the completion */
  1456. #define DMAE_COMP_REGULAR 0
  1457. #define DMAE_COM_SET_ERR 1
  1458. #define DMAE_CMD_SRC_PCI (DMAE_SRC_PCI << \
  1459. DMAE_COMMAND_SRC_SHIFT)
  1460. #define DMAE_CMD_SRC_GRC (DMAE_SRC_GRC << \
  1461. DMAE_COMMAND_SRC_SHIFT)
  1462. #define DMAE_CMD_DST_PCI (DMAE_DST_PCI << \
  1463. DMAE_COMMAND_DST_SHIFT)
  1464. #define DMAE_CMD_DST_GRC (DMAE_DST_GRC << \
  1465. DMAE_COMMAND_DST_SHIFT)
  1466. #define DMAE_CMD_C_DST_PCI (DMAE_COMP_PCI << \
  1467. DMAE_COMMAND_C_DST_SHIFT)
  1468. #define DMAE_CMD_C_DST_GRC (DMAE_COMP_GRC << \
  1469. DMAE_COMMAND_C_DST_SHIFT)
  1470. #define DMAE_CMD_C_ENABLE DMAE_COMMAND_C_TYPE_ENABLE
  1471. #define DMAE_CMD_ENDIANITY_NO_SWAP (0 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1472. #define DMAE_CMD_ENDIANITY_B_SWAP (1 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1473. #define DMAE_CMD_ENDIANITY_DW_SWAP (2 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1474. #define DMAE_CMD_ENDIANITY_B_DW_SWAP (3 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1475. #define DMAE_CMD_PORT_0 0
  1476. #define DMAE_CMD_PORT_1 DMAE_COMMAND_PORT
  1477. #define DMAE_CMD_SRC_RESET DMAE_COMMAND_SRC_RESET
  1478. #define DMAE_CMD_DST_RESET DMAE_COMMAND_DST_RESET
  1479. #define DMAE_CMD_E1HVN_SHIFT DMAE_COMMAND_E1HVN_SHIFT
  1480. #define DMAE_SRC_PF 0
  1481. #define DMAE_SRC_VF 1
  1482. #define DMAE_DST_PF 0
  1483. #define DMAE_DST_VF 1
  1484. #define DMAE_C_SRC 0
  1485. #define DMAE_C_DST 1
  1486. #define DMAE_LEN32_RD_MAX 0x80
  1487. #define DMAE_LEN32_WR_MAX(bp) (CHIP_IS_E1(bp) ? 0x400 : 0x2000)
  1488. #define DMAE_COMP_VAL 0x60d0d0ae /* E2 and on - upper bit
  1489. indicates eror */
  1490. #define MAX_DMAE_C_PER_PORT 8
  1491. #define INIT_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
  1492. BP_VN(bp))
  1493. #define PMF_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
  1494. E1HVN_MAX)
  1495. /* PCIE link and speed */
  1496. #define PCICFG_LINK_WIDTH 0x1f00000
  1497. #define PCICFG_LINK_WIDTH_SHIFT 20
  1498. #define PCICFG_LINK_SPEED 0xf0000
  1499. #define PCICFG_LINK_SPEED_SHIFT 16
  1500. #define BNX2X_NUM_TESTS 7
  1501. #define BNX2X_PHY_LOOPBACK 0
  1502. #define BNX2X_MAC_LOOPBACK 1
  1503. #define BNX2X_PHY_LOOPBACK_FAILED 1
  1504. #define BNX2X_MAC_LOOPBACK_FAILED 2
  1505. #define BNX2X_LOOPBACK_FAILED (BNX2X_MAC_LOOPBACK_FAILED | \
  1506. BNX2X_PHY_LOOPBACK_FAILED)
  1507. #define STROM_ASSERT_ARRAY_SIZE 50
  1508. /* must be used on a CID before placing it on a HW ring */
  1509. #define HW_CID(bp, x) ((BP_PORT(bp) << 23) | \
  1510. (BP_VN(bp) << BNX2X_SWCID_SHIFT) | \
  1511. (x))
  1512. #define SP_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_spe))
  1513. #define MAX_SP_DESC_CNT (SP_DESC_CNT - 1)
  1514. #define BNX2X_BTR 4
  1515. #define MAX_SPQ_PENDING 8
  1516. /* CMNG constants, as derived from system spec calculations */
  1517. /* default MIN rate in case VNIC min rate is configured to zero - 100Mbps */
  1518. #define DEF_MIN_RATE 100
  1519. /* resolution of the rate shaping timer - 400 usec */
  1520. #define RS_PERIODIC_TIMEOUT_USEC 400
  1521. /* number of bytes in single QM arbitration cycle -
  1522. * coefficient for calculating the fairness timer */
  1523. #define QM_ARB_BYTES 160000
  1524. /* resolution of Min algorithm 1:100 */
  1525. #define MIN_RES 100
  1526. /* how many bytes above threshold for the minimal credit of Min algorithm*/
  1527. #define MIN_ABOVE_THRESH 32768
  1528. /* Fairness algorithm integration time coefficient -
  1529. * for calculating the actual Tfair */
  1530. #define T_FAIR_COEF ((MIN_ABOVE_THRESH + QM_ARB_BYTES) * 8 * MIN_RES)
  1531. /* Memory of fairness algorithm . 2 cycles */
  1532. #define FAIR_MEM 2
  1533. #define ATTN_NIG_FOR_FUNC (1L << 8)
  1534. #define ATTN_SW_TIMER_4_FUNC (1L << 9)
  1535. #define GPIO_2_FUNC (1L << 10)
  1536. #define GPIO_3_FUNC (1L << 11)
  1537. #define GPIO_4_FUNC (1L << 12)
  1538. #define ATTN_GENERAL_ATTN_1 (1L << 13)
  1539. #define ATTN_GENERAL_ATTN_2 (1L << 14)
  1540. #define ATTN_GENERAL_ATTN_3 (1L << 15)
  1541. #define ATTN_GENERAL_ATTN_4 (1L << 13)
  1542. #define ATTN_GENERAL_ATTN_5 (1L << 14)
  1543. #define ATTN_GENERAL_ATTN_6 (1L << 15)
  1544. #define ATTN_HARD_WIRED_MASK 0xff00
  1545. #define ATTENTION_ID 4
  1546. /* stuff added to make the code fit 80Col */
  1547. #define BNX2X_PMF_LINK_ASSERT \
  1548. GENERAL_ATTEN_OFFSET(LINK_SYNC_ATTENTION_BIT_FUNC_0 + BP_FUNC(bp))
  1549. #define BNX2X_MC_ASSERT_BITS \
  1550. (GENERAL_ATTEN_OFFSET(TSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1551. GENERAL_ATTEN_OFFSET(USTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1552. GENERAL_ATTEN_OFFSET(CSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1553. GENERAL_ATTEN_OFFSET(XSTORM_FATAL_ASSERT_ATTENTION_BIT))
  1554. #define BNX2X_MCP_ASSERT \
  1555. GENERAL_ATTEN_OFFSET(MCP_FATAL_ASSERT_ATTENTION_BIT)
  1556. #define BNX2X_GRC_TIMEOUT GENERAL_ATTEN_OFFSET(LATCHED_ATTN_TIMEOUT_GRC)
  1557. #define BNX2X_GRC_RSV (GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCR) | \
  1558. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCT) | \
  1559. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCN) | \
  1560. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCU) | \
  1561. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCP) | \
  1562. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RSVD_GRC))
  1563. #define HW_INTERRUT_ASSERT_SET_0 \
  1564. (AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT | \
  1565. AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT | \
  1566. AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT | \
  1567. AEU_INPUTS_ATTN_BITS_PBCLIENT_HW_INTERRUPT)
  1568. #define HW_PRTY_ASSERT_SET_0 (AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR | \
  1569. AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR | \
  1570. AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR | \
  1571. AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR |\
  1572. AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR |\
  1573. AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR |\
  1574. AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR)
  1575. #define HW_INTERRUT_ASSERT_SET_1 \
  1576. (AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT | \
  1577. AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT | \
  1578. AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT | \
  1579. AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT | \
  1580. AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT | \
  1581. AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT | \
  1582. AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT | \
  1583. AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT | \
  1584. AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT | \
  1585. AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT | \
  1586. AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT)
  1587. #define HW_PRTY_ASSERT_SET_1 (AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR |\
  1588. AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR | \
  1589. AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR |\
  1590. AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR | \
  1591. AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR |\
  1592. AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR | \
  1593. AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR |\
  1594. AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR |\
  1595. AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR |\
  1596. AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR | \
  1597. AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR | \
  1598. AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR |\
  1599. AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR | \
  1600. AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR | \
  1601. AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR |\
  1602. AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR)
  1603. #define HW_INTERRUT_ASSERT_SET_2 \
  1604. (AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT | \
  1605. AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT | \
  1606. AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT | \
  1607. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT |\
  1608. AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT)
  1609. #define HW_PRTY_ASSERT_SET_2 (AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR | \
  1610. AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR | \
  1611. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR |\
  1612. AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR | \
  1613. AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR | \
  1614. AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR |\
  1615. AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR | \
  1616. AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR)
  1617. #define HW_PRTY_ASSERT_SET_3 (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
  1618. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
  1619. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY | \
  1620. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
  1621. #define HW_PRTY_ASSERT_SET_4 (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | \
  1622. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)
  1623. #define MULTI_MASK 0x7f
  1624. #define DEF_USB_FUNC_OFF offsetof(struct cstorm_def_status_block_u, func)
  1625. #define DEF_CSB_FUNC_OFF offsetof(struct cstorm_def_status_block_c, func)
  1626. #define DEF_XSB_FUNC_OFF offsetof(struct xstorm_def_status_block, func)
  1627. #define DEF_TSB_FUNC_OFF offsetof(struct tstorm_def_status_block, func)
  1628. #define DEF_USB_IGU_INDEX_OFF \
  1629. offsetof(struct cstorm_def_status_block_u, igu_index)
  1630. #define DEF_CSB_IGU_INDEX_OFF \
  1631. offsetof(struct cstorm_def_status_block_c, igu_index)
  1632. #define DEF_XSB_IGU_INDEX_OFF \
  1633. offsetof(struct xstorm_def_status_block, igu_index)
  1634. #define DEF_TSB_IGU_INDEX_OFF \
  1635. offsetof(struct tstorm_def_status_block, igu_index)
  1636. #define DEF_USB_SEGMENT_OFF \
  1637. offsetof(struct cstorm_def_status_block_u, segment)
  1638. #define DEF_CSB_SEGMENT_OFF \
  1639. offsetof(struct cstorm_def_status_block_c, segment)
  1640. #define DEF_XSB_SEGMENT_OFF \
  1641. offsetof(struct xstorm_def_status_block, segment)
  1642. #define DEF_TSB_SEGMENT_OFF \
  1643. offsetof(struct tstorm_def_status_block, segment)
  1644. #define BNX2X_SP_DSB_INDEX \
  1645. (&bp->def_status_blk->sp_sb.\
  1646. index_values[HC_SP_INDEX_ETH_DEF_CONS])
  1647. #define SET_FLAG(value, mask, flag) \
  1648. do {\
  1649. (value) &= ~(mask);\
  1650. (value) |= ((flag) << (mask##_SHIFT));\
  1651. } while (0)
  1652. #define GET_FLAG(value, mask) \
  1653. (((value) & (mask)) >> (mask##_SHIFT))
  1654. #define GET_FIELD(value, fname) \
  1655. (((value) & (fname##_MASK)) >> (fname##_SHIFT))
  1656. #define CAM_IS_INVALID(x) \
  1657. (GET_FLAG(x.flags, \
  1658. MAC_CONFIGURATION_ENTRY_ACTION_TYPE) == \
  1659. (T_ETH_MAC_COMMAND_INVALIDATE))
  1660. /* Number of u32 elements in MC hash array */
  1661. #define MC_HASH_SIZE 8
  1662. #define MC_HASH_OFFSET(bp, i) (BAR_TSTRORM_INTMEM + \
  1663. TSTORM_APPROXIMATE_MATCH_MULTICAST_FILTERING_OFFSET(BP_FUNC(bp)) + i*4)
  1664. #ifndef PXP2_REG_PXP2_INT_STS
  1665. #define PXP2_REG_PXP2_INT_STS PXP2_REG_PXP2_INT_STS_0
  1666. #endif
  1667. #ifndef ETH_MAX_RX_CLIENTS_E2
  1668. #define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
  1669. #endif
  1670. #define BNX2X_VPD_LEN 128
  1671. #define VENDOR_ID_LEN 4
  1672. int bnx2x_close(struct net_device *dev);
  1673. /* Congestion management fairness mode */
  1674. #define CMNG_FNS_NONE 0
  1675. #define CMNG_FNS_MINMAX 1
  1676. #define HC_SEG_ACCESS_DEF 0 /*Driver decision 0-3*/
  1677. #define HC_SEG_ACCESS_ATTN 4
  1678. #define HC_SEG_ACCESS_NORM 0 /*Driver decision 0-1*/
  1679. static const u32 dmae_reg_go_c[] = {
  1680. DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
  1681. DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
  1682. DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
  1683. DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
  1684. };
  1685. void bnx2x_set_ethtool_ops(struct net_device *netdev);
  1686. void bnx2x_notify_link_changed(struct bnx2x *bp);
  1687. #define BNX2X_MF_PROTOCOL(bp) \
  1688. ((bp)->mf_config[BP_VN(bp)] & FUNC_MF_CFG_PROTOCOL_MASK)
  1689. #ifdef BCM_CNIC
  1690. #define BNX2X_IS_MF_PROTOCOL_ISCSI(bp) \
  1691. (BNX2X_MF_PROTOCOL(bp) == FUNC_MF_CFG_PROTOCOL_ISCSI)
  1692. #define IS_MF_ISCSI_SD(bp) (IS_MF_SD(bp) && BNX2X_IS_MF_PROTOCOL_ISCSI(bp))
  1693. #endif
  1694. #endif /* bnx2x.h */