bnx2x.h 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112
  1. /* bnx2x.h: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2012 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <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.72.00-0"
  23. #define DRV_MODULE_RELDATE "2012/01/26"
  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. struct bnx2x_eth_q_stats_old eth_q_stats_old;
  440. /* The size is calculated using the following:
  441. sizeof name field from netdev structure +
  442. 4 ('-Xx-' string) +
  443. 4 (for the digits and to make it DWORD aligned) */
  444. #define FP_NAME_SIZE (sizeof(((struct net_device *)0)->name) + 8)
  445. char name[FP_NAME_SIZE];
  446. /* MACs object */
  447. struct bnx2x_vlan_mac_obj mac_obj;
  448. /* Queue State object */
  449. struct bnx2x_queue_sp_obj q_obj;
  450. };
  451. #define bnx2x_fp(bp, nr, var) (bp->fp[nr].var)
  452. /* Use 2500 as a mini-jumbo MTU for FCoE */
  453. #define BNX2X_FCOE_MINI_JUMBO_MTU 2500
  454. /* FCoE L2 `fastpath' entry is right after the eth entries */
  455. #define FCOE_IDX BNX2X_NUM_ETH_QUEUES(bp)
  456. #define bnx2x_fcoe_fp(bp) (&bp->fp[FCOE_IDX])
  457. #define bnx2x_fcoe(bp, var) (bnx2x_fcoe_fp(bp)->var)
  458. #define bnx2x_fcoe_tx(bp, var) (bnx2x_fcoe_fp(bp)-> \
  459. txdata[FIRST_TX_COS_INDEX].var)
  460. #define IS_ETH_FP(fp) (fp->index < \
  461. BNX2X_NUM_ETH_QUEUES(fp->bp))
  462. #ifdef BCM_CNIC
  463. #define IS_FCOE_FP(fp) (fp->index == FCOE_IDX)
  464. #define IS_FCOE_IDX(idx) ((idx) == FCOE_IDX)
  465. #else
  466. #define IS_FCOE_FP(fp) false
  467. #define IS_FCOE_IDX(idx) false
  468. #endif
  469. /* MC hsi */
  470. #define MAX_FETCH_BD 13 /* HW max BDs per packet */
  471. #define RX_COPY_THRESH 92
  472. #define NUM_TX_RINGS 16
  473. #define TX_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_tx_bd_types))
  474. #define NEXT_PAGE_TX_DESC_CNT 1
  475. #define MAX_TX_DESC_CNT (TX_DESC_CNT - NEXT_PAGE_TX_DESC_CNT)
  476. #define NUM_TX_BD (TX_DESC_CNT * NUM_TX_RINGS)
  477. #define MAX_TX_BD (NUM_TX_BD - 1)
  478. #define MAX_TX_AVAIL (MAX_TX_DESC_CNT * NUM_TX_RINGS - 2)
  479. #define NEXT_TX_IDX(x) ((((x) & MAX_TX_DESC_CNT) == \
  480. (MAX_TX_DESC_CNT - 1)) ? \
  481. (x) + 1 + NEXT_PAGE_TX_DESC_CNT : \
  482. (x) + 1)
  483. #define TX_BD(x) ((x) & MAX_TX_BD)
  484. #define TX_BD_POFF(x) ((x) & MAX_TX_DESC_CNT)
  485. /* The RX BD ring is special, each bd is 8 bytes but the last one is 16 */
  486. #define NUM_RX_RINGS 8
  487. #define RX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_bd))
  488. #define NEXT_PAGE_RX_DESC_CNT 2
  489. #define MAX_RX_DESC_CNT (RX_DESC_CNT - NEXT_PAGE_RX_DESC_CNT)
  490. #define RX_DESC_MASK (RX_DESC_CNT - 1)
  491. #define NUM_RX_BD (RX_DESC_CNT * NUM_RX_RINGS)
  492. #define MAX_RX_BD (NUM_RX_BD - 1)
  493. #define MAX_RX_AVAIL (MAX_RX_DESC_CNT * NUM_RX_RINGS - 2)
  494. /* dropless fc calculations for BDs
  495. *
  496. * Number of BDs should as number of buffers in BRB:
  497. * Low threshold takes into account NEXT_PAGE_RX_DESC_CNT
  498. * "next" elements on each page
  499. */
  500. #define NUM_BD_REQ BRB_SIZE(bp)
  501. #define NUM_BD_PG_REQ ((NUM_BD_REQ + MAX_RX_DESC_CNT - 1) / \
  502. MAX_RX_DESC_CNT)
  503. #define BD_TH_LO(bp) (NUM_BD_REQ + \
  504. NUM_BD_PG_REQ * NEXT_PAGE_RX_DESC_CNT + \
  505. FW_DROP_LEVEL(bp))
  506. #define BD_TH_HI(bp) (BD_TH_LO(bp) + DROPLESS_FC_HEADROOM)
  507. #define MIN_RX_AVAIL ((bp)->dropless_fc ? BD_TH_HI(bp) + 128 : 128)
  508. #define MIN_RX_SIZE_TPA_HW (CHIP_IS_E1(bp) ? \
  509. ETH_MIN_RX_CQES_WITH_TPA_E1 : \
  510. ETH_MIN_RX_CQES_WITH_TPA_E1H_E2)
  511. #define MIN_RX_SIZE_NONTPA_HW ETH_MIN_RX_CQES_WITHOUT_TPA
  512. #define MIN_RX_SIZE_TPA (max_t(u32, MIN_RX_SIZE_TPA_HW, MIN_RX_AVAIL))
  513. #define MIN_RX_SIZE_NONTPA (max_t(u32, MIN_RX_SIZE_NONTPA_HW,\
  514. MIN_RX_AVAIL))
  515. #define NEXT_RX_IDX(x) ((((x) & RX_DESC_MASK) == \
  516. (MAX_RX_DESC_CNT - 1)) ? \
  517. (x) + 1 + NEXT_PAGE_RX_DESC_CNT : \
  518. (x) + 1)
  519. #define RX_BD(x) ((x) & MAX_RX_BD)
  520. /*
  521. * As long as CQE is X times bigger than BD entry we have to allocate X times
  522. * more pages for CQ ring in order to keep it balanced with BD ring
  523. */
  524. #define CQE_BD_REL (sizeof(union eth_rx_cqe) / sizeof(struct eth_rx_bd))
  525. #define NUM_RCQ_RINGS (NUM_RX_RINGS * CQE_BD_REL)
  526. #define RCQ_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_rx_cqe))
  527. #define NEXT_PAGE_RCQ_DESC_CNT 1
  528. #define MAX_RCQ_DESC_CNT (RCQ_DESC_CNT - NEXT_PAGE_RCQ_DESC_CNT)
  529. #define NUM_RCQ_BD (RCQ_DESC_CNT * NUM_RCQ_RINGS)
  530. #define MAX_RCQ_BD (NUM_RCQ_BD - 1)
  531. #define MAX_RCQ_AVAIL (MAX_RCQ_DESC_CNT * NUM_RCQ_RINGS - 2)
  532. #define NEXT_RCQ_IDX(x) ((((x) & MAX_RCQ_DESC_CNT) == \
  533. (MAX_RCQ_DESC_CNT - 1)) ? \
  534. (x) + 1 + NEXT_PAGE_RCQ_DESC_CNT : \
  535. (x) + 1)
  536. #define RCQ_BD(x) ((x) & MAX_RCQ_BD)
  537. /* dropless fc calculations for RCQs
  538. *
  539. * Number of RCQs should be as number of buffers in BRB:
  540. * Low threshold takes into account NEXT_PAGE_RCQ_DESC_CNT
  541. * "next" elements on each page
  542. */
  543. #define NUM_RCQ_REQ BRB_SIZE(bp)
  544. #define NUM_RCQ_PG_REQ ((NUM_BD_REQ + MAX_RCQ_DESC_CNT - 1) / \
  545. MAX_RCQ_DESC_CNT)
  546. #define RCQ_TH_LO(bp) (NUM_RCQ_REQ + \
  547. NUM_RCQ_PG_REQ * NEXT_PAGE_RCQ_DESC_CNT + \
  548. FW_DROP_LEVEL(bp))
  549. #define RCQ_TH_HI(bp) (RCQ_TH_LO(bp) + DROPLESS_FC_HEADROOM)
  550. /* This is needed for determining of last_max */
  551. #define SUB_S16(a, b) (s16)((s16)(a) - (s16)(b))
  552. #define SUB_S32(a, b) (s32)((s32)(a) - (s32)(b))
  553. #define BNX2X_SWCID_SHIFT 17
  554. #define BNX2X_SWCID_MASK ((0x1 << BNX2X_SWCID_SHIFT) - 1)
  555. /* used on a CID received from the HW */
  556. #define SW_CID(x) (le32_to_cpu(x) & BNX2X_SWCID_MASK)
  557. #define CQE_CMD(x) (le32_to_cpu(x) >> \
  558. COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT)
  559. #define BD_UNMAP_ADDR(bd) HILO_U64(le32_to_cpu((bd)->addr_hi), \
  560. le32_to_cpu((bd)->addr_lo))
  561. #define BD_UNMAP_LEN(bd) (le16_to_cpu((bd)->nbytes))
  562. #define BNX2X_DB_MIN_SHIFT 3 /* 8 bytes */
  563. #define BNX2X_DB_SHIFT 7 /* 128 bytes*/
  564. #if (BNX2X_DB_SHIFT < BNX2X_DB_MIN_SHIFT)
  565. #error "Min DB doorbell stride is 8"
  566. #endif
  567. #define DPM_TRIGER_TYPE 0x40
  568. #define DOORBELL(bp, cid, val) \
  569. do { \
  570. writel((u32)(val), bp->doorbells + (bp->db_size * (cid)) + \
  571. DPM_TRIGER_TYPE); \
  572. } while (0)
  573. /* TX CSUM helpers */
  574. #define SKB_CS_OFF(skb) (offsetof(struct tcphdr, check) - \
  575. skb->csum_offset)
  576. #define SKB_CS(skb) (*(u16 *)(skb_transport_header(skb) + \
  577. skb->csum_offset))
  578. #define pbd_tcp_flags(skb) (ntohl(tcp_flag_word(tcp_hdr(skb)))>>16 & 0xff)
  579. #define XMIT_PLAIN 0
  580. #define XMIT_CSUM_V4 0x1
  581. #define XMIT_CSUM_V6 0x2
  582. #define XMIT_CSUM_TCP 0x4
  583. #define XMIT_GSO_V4 0x8
  584. #define XMIT_GSO_V6 0x10
  585. #define XMIT_CSUM (XMIT_CSUM_V4 | XMIT_CSUM_V6)
  586. #define XMIT_GSO (XMIT_GSO_V4 | XMIT_GSO_V6)
  587. /* stuff added to make the code fit 80Col */
  588. #define CQE_TYPE(cqe_fp_flags) ((cqe_fp_flags) & ETH_FAST_PATH_RX_CQE_TYPE)
  589. #define CQE_TYPE_START(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_START_AGG)
  590. #define CQE_TYPE_STOP(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_STOP_AGG)
  591. #define CQE_TYPE_SLOW(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_RAMROD)
  592. #define CQE_TYPE_FAST(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_FASTPATH)
  593. #define ETH_RX_ERROR_FALGS ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG
  594. #define BNX2X_IP_CSUM_ERR(cqe) \
  595. (!((cqe)->fast_path_cqe.status_flags & \
  596. ETH_FAST_PATH_RX_CQE_IP_XSUM_NO_VALIDATION_FLG) && \
  597. ((cqe)->fast_path_cqe.type_error_flags & \
  598. ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG))
  599. #define BNX2X_L4_CSUM_ERR(cqe) \
  600. (!((cqe)->fast_path_cqe.status_flags & \
  601. ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG) && \
  602. ((cqe)->fast_path_cqe.type_error_flags & \
  603. ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG))
  604. #define BNX2X_RX_CSUM_OK(cqe) \
  605. (!(BNX2X_L4_CSUM_ERR(cqe) || BNX2X_IP_CSUM_ERR(cqe)))
  606. #define BNX2X_PRS_FLAG_OVERETH_IPV4(flags) \
  607. (((le16_to_cpu(flags) & \
  608. PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) >> \
  609. PARSING_FLAGS_OVER_ETHERNET_PROTOCOL_SHIFT) \
  610. == PRS_FLAG_OVERETH_IPV4)
  611. #define BNX2X_RX_SUM_FIX(cqe) \
  612. BNX2X_PRS_FLAG_OVERETH_IPV4(cqe->fast_path_cqe.pars_flags.flags)
  613. #define FP_USB_FUNC_OFF \
  614. offsetof(struct cstorm_status_block_u, func)
  615. #define FP_CSB_FUNC_OFF \
  616. offsetof(struct cstorm_status_block_c, func)
  617. #define HC_INDEX_ETH_RX_CQ_CONS 1
  618. #define HC_INDEX_OOO_TX_CQ_CONS 4
  619. #define HC_INDEX_ETH_TX_CQ_CONS_COS0 5
  620. #define HC_INDEX_ETH_TX_CQ_CONS_COS1 6
  621. #define HC_INDEX_ETH_TX_CQ_CONS_COS2 7
  622. #define HC_INDEX_ETH_FIRST_TX_CQ_CONS HC_INDEX_ETH_TX_CQ_CONS_COS0
  623. #define BNX2X_RX_SB_INDEX \
  624. (&fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS])
  625. #define BNX2X_TX_SB_INDEX_BASE BNX2X_TX_SB_INDEX_COS0
  626. #define BNX2X_TX_SB_INDEX_COS0 \
  627. (&fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0])
  628. /* end of fast path */
  629. /* common */
  630. struct bnx2x_common {
  631. u32 chip_id;
  632. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  633. #define CHIP_ID(bp) (bp->common.chip_id & 0xfffffff0)
  634. #define CHIP_NUM(bp) (bp->common.chip_id >> 16)
  635. #define CHIP_NUM_57710 0x164e
  636. #define CHIP_NUM_57711 0x164f
  637. #define CHIP_NUM_57711E 0x1650
  638. #define CHIP_NUM_57712 0x1662
  639. #define CHIP_NUM_57712_MF 0x1663
  640. #define CHIP_NUM_57713 0x1651
  641. #define CHIP_NUM_57713E 0x1652
  642. #define CHIP_NUM_57800 0x168a
  643. #define CHIP_NUM_57800_MF 0x16a5
  644. #define CHIP_NUM_57810 0x168e
  645. #define CHIP_NUM_57810_MF 0x16ae
  646. #define CHIP_NUM_57840 0x168d
  647. #define CHIP_NUM_57840_MF 0x16ab
  648. #define CHIP_IS_E1(bp) (CHIP_NUM(bp) == CHIP_NUM_57710)
  649. #define CHIP_IS_57711(bp) (CHIP_NUM(bp) == CHIP_NUM_57711)
  650. #define CHIP_IS_57711E(bp) (CHIP_NUM(bp) == CHIP_NUM_57711E)
  651. #define CHIP_IS_57712(bp) (CHIP_NUM(bp) == CHIP_NUM_57712)
  652. #define CHIP_IS_57712_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57712_MF)
  653. #define CHIP_IS_57800(bp) (CHIP_NUM(bp) == CHIP_NUM_57800)
  654. #define CHIP_IS_57800_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57800_MF)
  655. #define CHIP_IS_57810(bp) (CHIP_NUM(bp) == CHIP_NUM_57810)
  656. #define CHIP_IS_57810_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57810_MF)
  657. #define CHIP_IS_57840(bp) (CHIP_NUM(bp) == CHIP_NUM_57840)
  658. #define CHIP_IS_57840_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57840_MF)
  659. #define CHIP_IS_E1H(bp) (CHIP_IS_57711(bp) || \
  660. CHIP_IS_57711E(bp))
  661. #define CHIP_IS_E2(bp) (CHIP_IS_57712(bp) || \
  662. CHIP_IS_57712_MF(bp))
  663. #define CHIP_IS_E3(bp) (CHIP_IS_57800(bp) || \
  664. CHIP_IS_57800_MF(bp) || \
  665. CHIP_IS_57810(bp) || \
  666. CHIP_IS_57810_MF(bp) || \
  667. CHIP_IS_57840(bp) || \
  668. CHIP_IS_57840_MF(bp))
  669. #define CHIP_IS_E1x(bp) (CHIP_IS_E1((bp)) || CHIP_IS_E1H((bp)))
  670. #define USES_WARPCORE(bp) (CHIP_IS_E3(bp))
  671. #define IS_E1H_OFFSET (!CHIP_IS_E1(bp))
  672. #define CHIP_REV_SHIFT 12
  673. #define CHIP_REV_MASK (0xF << CHIP_REV_SHIFT)
  674. #define CHIP_REV_VAL(bp) (bp->common.chip_id & CHIP_REV_MASK)
  675. #define CHIP_REV_Ax (0x0 << CHIP_REV_SHIFT)
  676. #define CHIP_REV_Bx (0x1 << CHIP_REV_SHIFT)
  677. /* assume maximum 5 revisions */
  678. #define CHIP_REV_IS_SLOW(bp) (CHIP_REV_VAL(bp) > 0x00005000)
  679. /* Emul versions are A=>0xe, B=>0xc, C=>0xa, D=>8, E=>6 */
  680. #define CHIP_REV_IS_EMUL(bp) ((CHIP_REV_IS_SLOW(bp)) && \
  681. !(CHIP_REV_VAL(bp) & 0x00001000))
  682. /* FPGA versions are A=>0xf, B=>0xd, C=>0xb, D=>9, E=>7 */
  683. #define CHIP_REV_IS_FPGA(bp) ((CHIP_REV_IS_SLOW(bp)) && \
  684. (CHIP_REV_VAL(bp) & 0x00001000))
  685. #define CHIP_TIME(bp) ((CHIP_REV_IS_EMUL(bp)) ? 2000 : \
  686. ((CHIP_REV_IS_FPGA(bp)) ? 200 : 1))
  687. #define CHIP_METAL(bp) (bp->common.chip_id & 0x00000ff0)
  688. #define CHIP_BOND_ID(bp) (bp->common.chip_id & 0x0000000f)
  689. #define CHIP_REV_SIM(bp) (((CHIP_REV_MASK - CHIP_REV_VAL(bp)) >>\
  690. (CHIP_REV_SHIFT + 1)) \
  691. << CHIP_REV_SHIFT)
  692. #define CHIP_REV(bp) (CHIP_REV_IS_SLOW(bp) ? \
  693. CHIP_REV_SIM(bp) :\
  694. CHIP_REV_VAL(bp))
  695. #define CHIP_IS_E3B0(bp) (CHIP_IS_E3(bp) && \
  696. (CHIP_REV(bp) == CHIP_REV_Bx))
  697. #define CHIP_IS_E3A0(bp) (CHIP_IS_E3(bp) && \
  698. (CHIP_REV(bp) == CHIP_REV_Ax))
  699. int flash_size;
  700. #define BNX2X_NVRAM_1MB_SIZE 0x20000 /* 1M bit in bytes */
  701. #define BNX2X_NVRAM_TIMEOUT_COUNT 30000
  702. #define BNX2X_NVRAM_PAGE_SIZE 256
  703. u32 shmem_base;
  704. u32 shmem2_base;
  705. u32 mf_cfg_base;
  706. u32 mf2_cfg_base;
  707. u32 hw_config;
  708. u32 bc_ver;
  709. u8 int_block;
  710. #define INT_BLOCK_HC 0
  711. #define INT_BLOCK_IGU 1
  712. #define INT_BLOCK_MODE_NORMAL 0
  713. #define INT_BLOCK_MODE_BW_COMP 2
  714. #define CHIP_INT_MODE_IS_NBC(bp) \
  715. (!CHIP_IS_E1x(bp) && \
  716. !((bp)->common.int_block & INT_BLOCK_MODE_BW_COMP))
  717. #define CHIP_INT_MODE_IS_BC(bp) (!CHIP_INT_MODE_IS_NBC(bp))
  718. u8 chip_port_mode;
  719. #define CHIP_4_PORT_MODE 0x0
  720. #define CHIP_2_PORT_MODE 0x1
  721. #define CHIP_PORT_MODE_NONE 0x2
  722. #define CHIP_MODE(bp) (bp->common.chip_port_mode)
  723. #define CHIP_MODE_IS_4_PORT(bp) (CHIP_MODE(bp) == CHIP_4_PORT_MODE)
  724. u32 boot_mode;
  725. };
  726. /* IGU MSIX STATISTICS on 57712: 64 for VFs; 4 for PFs; 4 for Attentions */
  727. #define BNX2X_IGU_STAS_MSG_VF_CNT 64
  728. #define BNX2X_IGU_STAS_MSG_PF_CNT 4
  729. /* end of common */
  730. /* port */
  731. struct bnx2x_port {
  732. u32 pmf;
  733. u32 link_config[LINK_CONFIG_SIZE];
  734. u32 supported[LINK_CONFIG_SIZE];
  735. /* link settings - missing defines */
  736. #define SUPPORTED_2500baseX_Full (1 << 15)
  737. u32 advertising[LINK_CONFIG_SIZE];
  738. /* link settings - missing defines */
  739. #define ADVERTISED_2500baseX_Full (1 << 15)
  740. u32 phy_addr;
  741. /* used to synchronize phy accesses */
  742. struct mutex phy_mutex;
  743. int need_hw_lock;
  744. u32 port_stx;
  745. struct nig_stats old_nig_stats;
  746. };
  747. /* end of port */
  748. #define STATS_OFFSET32(stat_name) \
  749. (offsetof(struct bnx2x_eth_stats, stat_name) / 4)
  750. /* slow path */
  751. /* slow path work-queue */
  752. extern struct workqueue_struct *bnx2x_wq;
  753. #define BNX2X_MAX_NUM_OF_VFS 64
  754. #define BNX2X_VF_ID_INVALID 0xFF
  755. /*
  756. * The total number of L2 queues, MSIX vectors and HW contexts (CIDs) is
  757. * control by the number of fast-path status blocks supported by the
  758. * device (HW/FW). Each fast-path status block (FP-SB) aka non-default
  759. * status block represents an independent interrupts context that can
  760. * serve a regular L2 networking queue. However special L2 queues such
  761. * as the FCoE queue do not require a FP-SB and other components like
  762. * the CNIC may consume FP-SB reducing the number of possible L2 queues
  763. *
  764. * If the maximum number of FP-SB available is X then:
  765. * a. If CNIC is supported it consumes 1 FP-SB thus the max number of
  766. * regular L2 queues is Y=X-1
  767. * b. in MF mode the actual number of L2 queues is Y= (X-1/MF_factor)
  768. * c. If the FCoE L2 queue is supported the actual number of L2 queues
  769. * is Y+1
  770. * d. The number of irqs (MSIX vectors) is either Y+1 (one extra for
  771. * slow-path interrupts) or Y+2 if CNIC is supported (one additional
  772. * FP interrupt context for the CNIC).
  773. * e. The number of HW context (CID count) is always X or X+1 if FCoE
  774. * L2 queue is supported. the cid for the FCoE L2 queue is always X.
  775. */
  776. /* fast-path interrupt contexts E1x */
  777. #define FP_SB_MAX_E1x 16
  778. /* fast-path interrupt contexts E2 */
  779. #define FP_SB_MAX_E2 HC_SB_MAX_SB_E2
  780. union cdu_context {
  781. struct eth_context eth;
  782. char pad[1024];
  783. };
  784. /* CDU host DB constants */
  785. #define CDU_ILT_PAGE_SZ_HW 3
  786. #define CDU_ILT_PAGE_SZ (8192 << CDU_ILT_PAGE_SZ_HW) /* 64K */
  787. #define ILT_PAGE_CIDS (CDU_ILT_PAGE_SZ / sizeof(union cdu_context))
  788. #ifdef BCM_CNIC
  789. #define CNIC_ISCSI_CID_MAX 256
  790. #define CNIC_FCOE_CID_MAX 2048
  791. #define CNIC_CID_MAX (CNIC_ISCSI_CID_MAX + CNIC_FCOE_CID_MAX)
  792. #define CNIC_ILT_LINES DIV_ROUND_UP(CNIC_CID_MAX, ILT_PAGE_CIDS)
  793. #endif
  794. #define QM_ILT_PAGE_SZ_HW 0
  795. #define QM_ILT_PAGE_SZ (4096 << QM_ILT_PAGE_SZ_HW) /* 4K */
  796. #define QM_CID_ROUND 1024
  797. #ifdef BCM_CNIC
  798. /* TM (timers) host DB constants */
  799. #define TM_ILT_PAGE_SZ_HW 0
  800. #define TM_ILT_PAGE_SZ (4096 << TM_ILT_PAGE_SZ_HW) /* 4K */
  801. /* #define TM_CONN_NUM (CNIC_STARTING_CID+CNIC_ISCSI_CXT_MAX) */
  802. #define TM_CONN_NUM 1024
  803. #define TM_ILT_SZ (8 * TM_CONN_NUM)
  804. #define TM_ILT_LINES DIV_ROUND_UP(TM_ILT_SZ, TM_ILT_PAGE_SZ)
  805. /* SRC (Searcher) host DB constants */
  806. #define SRC_ILT_PAGE_SZ_HW 0
  807. #define SRC_ILT_PAGE_SZ (4096 << SRC_ILT_PAGE_SZ_HW) /* 4K */
  808. #define SRC_HASH_BITS 10
  809. #define SRC_CONN_NUM (1 << SRC_HASH_BITS) /* 1024 */
  810. #define SRC_ILT_SZ (sizeof(struct src_ent) * SRC_CONN_NUM)
  811. #define SRC_T2_SZ SRC_ILT_SZ
  812. #define SRC_ILT_LINES DIV_ROUND_UP(SRC_ILT_SZ, SRC_ILT_PAGE_SZ)
  813. #endif
  814. #define MAX_DMAE_C 8
  815. /* DMA memory not used in fastpath */
  816. struct bnx2x_slowpath {
  817. union {
  818. struct mac_configuration_cmd e1x;
  819. struct eth_classify_rules_ramrod_data e2;
  820. } mac_rdata;
  821. union {
  822. struct tstorm_eth_mac_filter_config e1x;
  823. struct eth_filter_rules_ramrod_data e2;
  824. } rx_mode_rdata;
  825. union {
  826. struct mac_configuration_cmd e1;
  827. struct eth_multicast_rules_ramrod_data e2;
  828. } mcast_rdata;
  829. struct eth_rss_update_ramrod_data rss_rdata;
  830. /* Queue State related ramrods are always sent under rtnl_lock */
  831. union {
  832. struct client_init_ramrod_data init_data;
  833. struct client_update_ramrod_data update_data;
  834. } q_rdata;
  835. union {
  836. struct function_start_data func_start;
  837. /* pfc configuration for DCBX ramrod */
  838. struct flow_control_configuration pfc_config;
  839. } func_rdata;
  840. /* used by dmae command executer */
  841. struct dmae_command dmae[MAX_DMAE_C];
  842. u32 stats_comp;
  843. union mac_stats mac_stats;
  844. struct nig_stats nig_stats;
  845. struct host_port_stats port_stats;
  846. struct host_func_stats func_stats;
  847. u32 wb_comp;
  848. u32 wb_data[4];
  849. union drv_info_to_mcp drv_info_to_mcp;
  850. };
  851. #define bnx2x_sp(bp, var) (&bp->slowpath->var)
  852. #define bnx2x_sp_mapping(bp, var) \
  853. (bp->slowpath_mapping + offsetof(struct bnx2x_slowpath, var))
  854. /* attn group wiring */
  855. #define MAX_DYNAMIC_ATTN_GRPS 8
  856. struct attn_route {
  857. u32 sig[5];
  858. };
  859. struct iro {
  860. u32 base;
  861. u16 m1;
  862. u16 m2;
  863. u16 m3;
  864. u16 size;
  865. };
  866. struct hw_context {
  867. union cdu_context *vcxt;
  868. dma_addr_t cxt_mapping;
  869. size_t size;
  870. };
  871. /* forward */
  872. struct bnx2x_ilt;
  873. enum bnx2x_recovery_state {
  874. BNX2X_RECOVERY_DONE,
  875. BNX2X_RECOVERY_INIT,
  876. BNX2X_RECOVERY_WAIT,
  877. BNX2X_RECOVERY_FAILED,
  878. BNX2X_RECOVERY_NIC_LOADING
  879. };
  880. /*
  881. * Event queue (EQ or event ring) MC hsi
  882. * NUM_EQ_PAGES and EQ_DESC_CNT_PAGE must be power of 2
  883. */
  884. #define NUM_EQ_PAGES 1
  885. #define EQ_DESC_CNT_PAGE (BCM_PAGE_SIZE / sizeof(union event_ring_elem))
  886. #define EQ_DESC_MAX_PAGE (EQ_DESC_CNT_PAGE - 1)
  887. #define NUM_EQ_DESC (EQ_DESC_CNT_PAGE * NUM_EQ_PAGES)
  888. #define EQ_DESC_MASK (NUM_EQ_DESC - 1)
  889. #define MAX_EQ_AVAIL (EQ_DESC_MAX_PAGE * NUM_EQ_PAGES - 2)
  890. /* depends on EQ_DESC_CNT_PAGE being a power of 2 */
  891. #define NEXT_EQ_IDX(x) ((((x) & EQ_DESC_MAX_PAGE) == \
  892. (EQ_DESC_MAX_PAGE - 1)) ? (x) + 2 : (x) + 1)
  893. /* depends on the above and on NUM_EQ_PAGES being a power of 2 */
  894. #define EQ_DESC(x) ((x) & EQ_DESC_MASK)
  895. #define BNX2X_EQ_INDEX \
  896. (&bp->def_status_blk->sp_sb.\
  897. index_values[HC_SP_INDEX_EQ_CONS])
  898. /* This is a data that will be used to create a link report message.
  899. * We will keep the data used for the last link report in order
  900. * to prevent reporting the same link parameters twice.
  901. */
  902. struct bnx2x_link_report_data {
  903. u16 line_speed; /* Effective line speed */
  904. unsigned long link_report_flags;/* BNX2X_LINK_REPORT_XXX flags */
  905. };
  906. enum {
  907. BNX2X_LINK_REPORT_FD, /* Full DUPLEX */
  908. BNX2X_LINK_REPORT_LINK_DOWN,
  909. BNX2X_LINK_REPORT_RX_FC_ON,
  910. BNX2X_LINK_REPORT_TX_FC_ON,
  911. };
  912. enum {
  913. BNX2X_PORT_QUERY_IDX,
  914. BNX2X_PF_QUERY_IDX,
  915. BNX2X_FCOE_QUERY_IDX,
  916. BNX2X_FIRST_QUEUE_QUERY_IDX,
  917. };
  918. struct bnx2x_fw_stats_req {
  919. struct stats_query_header hdr;
  920. struct stats_query_entry query[FP_SB_MAX_E1x+
  921. BNX2X_FIRST_QUEUE_QUERY_IDX];
  922. };
  923. struct bnx2x_fw_stats_data {
  924. struct stats_counter storm_counters;
  925. struct per_port_stats port;
  926. struct per_pf_stats pf;
  927. struct fcoe_statistics_params fcoe;
  928. struct per_queue_stats queue_stats[1];
  929. };
  930. /* Public slow path states */
  931. enum {
  932. BNX2X_SP_RTNL_SETUP_TC,
  933. BNX2X_SP_RTNL_TX_TIMEOUT,
  934. BNX2X_SP_RTNL_FAN_FAILURE,
  935. };
  936. struct bnx2x {
  937. /* Fields used in the tx and intr/napi performance paths
  938. * are grouped together in the beginning of the structure
  939. */
  940. struct bnx2x_fastpath *fp;
  941. void __iomem *regview;
  942. void __iomem *doorbells;
  943. u16 db_size;
  944. u8 pf_num; /* absolute PF number */
  945. u8 pfid; /* per-path PF number */
  946. int base_fw_ndsb; /**/
  947. #define BP_PATH(bp) (CHIP_IS_E1x(bp) ? 0 : (bp->pf_num & 1))
  948. #define BP_PORT(bp) (bp->pfid & 1)
  949. #define BP_FUNC(bp) (bp->pfid)
  950. #define BP_ABS_FUNC(bp) (bp->pf_num)
  951. #define BP_VN(bp) ((bp)->pfid >> 1)
  952. #define BP_MAX_VN_NUM(bp) (CHIP_MODE_IS_4_PORT(bp) ? 2 : 4)
  953. #define BP_L_ID(bp) (BP_VN(bp) << 2)
  954. #define BP_FW_MB_IDX_VN(bp, vn) (BP_PORT(bp) +\
  955. (vn) * ((CHIP_IS_E1x(bp) || (CHIP_MODE_IS_4_PORT(bp))) ? 2 : 1))
  956. #define BP_FW_MB_IDX(bp) BP_FW_MB_IDX_VN(bp, BP_VN(bp))
  957. struct net_device *dev;
  958. struct pci_dev *pdev;
  959. const struct iro *iro_arr;
  960. #define IRO (bp->iro_arr)
  961. enum bnx2x_recovery_state recovery_state;
  962. int is_leader;
  963. struct msix_entry *msix_table;
  964. int tx_ring_size;
  965. /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
  966. #define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
  967. #define ETH_MIN_PACKET_SIZE 60
  968. #define ETH_MAX_PACKET_SIZE 1500
  969. #define ETH_MAX_JUMBO_PACKET_SIZE 9600
  970. /* Max supported alignment is 256 (8 shift) */
  971. #define BNX2X_RX_ALIGN_SHIFT min(8, L1_CACHE_SHIFT)
  972. /* FW uses 2 Cache lines Alignment for start packet and size
  973. *
  974. * We assume skb_build() uses sizeof(struct skb_shared_info) bytes
  975. * at the end of skb->data, to avoid wasting a full cache line.
  976. * This reduces memory use (skb->truesize).
  977. */
  978. #define BNX2X_FW_RX_ALIGN_START (1UL << BNX2X_RX_ALIGN_SHIFT)
  979. #define BNX2X_FW_RX_ALIGN_END \
  980. max(1UL << BNX2X_RX_ALIGN_SHIFT, \
  981. SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
  982. #define BNX2X_PXP_DRAM_ALIGN (BNX2X_RX_ALIGN_SHIFT - 5)
  983. struct host_sp_status_block *def_status_blk;
  984. #define DEF_SB_IGU_ID 16
  985. #define DEF_SB_ID HC_SP_SB_ID
  986. __le16 def_idx;
  987. __le16 def_att_idx;
  988. u32 attn_state;
  989. struct attn_route attn_group[MAX_DYNAMIC_ATTN_GRPS];
  990. /* slow path ring */
  991. struct eth_spe *spq;
  992. dma_addr_t spq_mapping;
  993. u16 spq_prod_idx;
  994. struct eth_spe *spq_prod_bd;
  995. struct eth_spe *spq_last_bd;
  996. __le16 *dsb_sp_prod;
  997. atomic_t cq_spq_left; /* ETH_XXX ramrods credit */
  998. /* used to synchronize spq accesses */
  999. spinlock_t spq_lock;
  1000. /* event queue */
  1001. union event_ring_elem *eq_ring;
  1002. dma_addr_t eq_mapping;
  1003. u16 eq_prod;
  1004. u16 eq_cons;
  1005. __le16 *eq_cons_sb;
  1006. atomic_t eq_spq_left; /* COMMON_XXX ramrods credit */
  1007. /* Counter for marking that there is a STAT_QUERY ramrod pending */
  1008. u16 stats_pending;
  1009. /* Counter for completed statistics ramrods */
  1010. u16 stats_comp;
  1011. /* End of fields used in the performance code paths */
  1012. int panic;
  1013. int msg_enable;
  1014. u32 flags;
  1015. #define PCIX_FLAG (1 << 0)
  1016. #define PCI_32BIT_FLAG (1 << 1)
  1017. #define ONE_PORT_FLAG (1 << 2)
  1018. #define NO_WOL_FLAG (1 << 3)
  1019. #define USING_DAC_FLAG (1 << 4)
  1020. #define USING_MSIX_FLAG (1 << 5)
  1021. #define USING_MSI_FLAG (1 << 6)
  1022. #define DISABLE_MSI_FLAG (1 << 7)
  1023. #define TPA_ENABLE_FLAG (1 << 8)
  1024. #define NO_MCP_FLAG (1 << 9)
  1025. #define BP_NOMCP(bp) (bp->flags & NO_MCP_FLAG)
  1026. #define MF_FUNC_DIS (1 << 11)
  1027. #define OWN_CNIC_IRQ (1 << 12)
  1028. #define NO_ISCSI_OOO_FLAG (1 << 13)
  1029. #define NO_ISCSI_FLAG (1 << 14)
  1030. #define NO_FCOE_FLAG (1 << 15)
  1031. #define BC_SUPPORTS_PFC_STATS (1 << 17)
  1032. #define NO_ISCSI(bp) ((bp)->flags & NO_ISCSI_FLAG)
  1033. #define NO_ISCSI_OOO(bp) ((bp)->flags & NO_ISCSI_OOO_FLAG)
  1034. #define NO_FCOE(bp) ((bp)->flags & NO_FCOE_FLAG)
  1035. int pm_cap;
  1036. int mrrs;
  1037. struct delayed_work sp_task;
  1038. struct delayed_work sp_rtnl_task;
  1039. struct delayed_work period_task;
  1040. struct timer_list timer;
  1041. int current_interval;
  1042. u16 fw_seq;
  1043. u16 fw_drv_pulse_wr_seq;
  1044. u32 func_stx;
  1045. struct link_params link_params;
  1046. struct link_vars link_vars;
  1047. u32 link_cnt;
  1048. struct bnx2x_link_report_data last_reported_link;
  1049. struct mdio_if_info mdio;
  1050. struct bnx2x_common common;
  1051. struct bnx2x_port port;
  1052. struct cmng_struct_per_port cmng;
  1053. u32 vn_weight_sum;
  1054. u32 mf_config[E1HVN_MAX];
  1055. u32 mf2_config[E2_FUNC_MAX];
  1056. u32 path_has_ovlan; /* E3 */
  1057. u16 mf_ov;
  1058. u8 mf_mode;
  1059. #define IS_MF(bp) (bp->mf_mode != 0)
  1060. #define IS_MF_SI(bp) (bp->mf_mode == MULTI_FUNCTION_SI)
  1061. #define IS_MF_SD(bp) (bp->mf_mode == MULTI_FUNCTION_SD)
  1062. u8 wol;
  1063. int rx_ring_size;
  1064. u16 tx_quick_cons_trip_int;
  1065. u16 tx_quick_cons_trip;
  1066. u16 tx_ticks_int;
  1067. u16 tx_ticks;
  1068. u16 rx_quick_cons_trip_int;
  1069. u16 rx_quick_cons_trip;
  1070. u16 rx_ticks_int;
  1071. u16 rx_ticks;
  1072. /* Maximal coalescing timeout in us */
  1073. #define BNX2X_MAX_COALESCE_TOUT (0xf0*12)
  1074. u32 lin_cnt;
  1075. u16 state;
  1076. #define BNX2X_STATE_CLOSED 0
  1077. #define BNX2X_STATE_OPENING_WAIT4_LOAD 0x1000
  1078. #define BNX2X_STATE_OPENING_WAIT4_PORT 0x2000
  1079. #define BNX2X_STATE_OPEN 0x3000
  1080. #define BNX2X_STATE_CLOSING_WAIT4_HALT 0x4000
  1081. #define BNX2X_STATE_CLOSING_WAIT4_DELETE 0x5000
  1082. #define BNX2X_STATE_DIAG 0xe000
  1083. #define BNX2X_STATE_ERROR 0xf000
  1084. int multi_mode;
  1085. #define BNX2X_MAX_PRIORITY 8
  1086. #define BNX2X_MAX_ENTRIES_PER_PRI 16
  1087. #define BNX2X_MAX_COS 3
  1088. #define BNX2X_MAX_TX_COS 2
  1089. int num_queues;
  1090. int disable_tpa;
  1091. u32 rx_mode;
  1092. #define BNX2X_RX_MODE_NONE 0
  1093. #define BNX2X_RX_MODE_NORMAL 1
  1094. #define BNX2X_RX_MODE_ALLMULTI 2
  1095. #define BNX2X_RX_MODE_PROMISC 3
  1096. #define BNX2X_MAX_MULTICAST 64
  1097. u8 igu_dsb_id;
  1098. u8 igu_base_sb;
  1099. u8 igu_sb_cnt;
  1100. dma_addr_t def_status_blk_mapping;
  1101. struct bnx2x_slowpath *slowpath;
  1102. dma_addr_t slowpath_mapping;
  1103. /* Total number of FW statistics requests */
  1104. u8 fw_stats_num;
  1105. /*
  1106. * This is a memory buffer that will contain both statistics
  1107. * ramrod request and data.
  1108. */
  1109. void *fw_stats;
  1110. dma_addr_t fw_stats_mapping;
  1111. /*
  1112. * FW statistics request shortcut (points at the
  1113. * beginning of fw_stats buffer).
  1114. */
  1115. struct bnx2x_fw_stats_req *fw_stats_req;
  1116. dma_addr_t fw_stats_req_mapping;
  1117. int fw_stats_req_sz;
  1118. /*
  1119. * FW statistics data shortcut (points at the begining of
  1120. * fw_stats buffer + fw_stats_req_sz).
  1121. */
  1122. struct bnx2x_fw_stats_data *fw_stats_data;
  1123. dma_addr_t fw_stats_data_mapping;
  1124. int fw_stats_data_sz;
  1125. struct hw_context context;
  1126. struct bnx2x_ilt *ilt;
  1127. #define BP_ILT(bp) ((bp)->ilt)
  1128. #define ILT_MAX_LINES 256
  1129. /*
  1130. * Maximum supported number of RSS queues: number of IGU SBs minus one that goes
  1131. * to CNIC.
  1132. */
  1133. #define BNX2X_MAX_RSS_COUNT(bp) ((bp)->igu_sb_cnt - CNIC_PRESENT)
  1134. /*
  1135. * Maximum CID count that might be required by the bnx2x:
  1136. * Max Tss * Max_Tx_Multi_Cos + CNIC L2 Clients (FCoE and iSCSI related)
  1137. */
  1138. #define BNX2X_L2_CID_COUNT(bp) (MAX_TXQS_PER_COS * BNX2X_MULTI_TX_COS +\
  1139. NON_ETH_CONTEXT_USE + CNIC_PRESENT)
  1140. #define L2_ILT_LINES(bp) (DIV_ROUND_UP(BNX2X_L2_CID_COUNT(bp),\
  1141. ILT_PAGE_CIDS))
  1142. #define BNX2X_DB_SIZE(bp) (BNX2X_L2_CID_COUNT(bp) * (1 << BNX2X_DB_SHIFT))
  1143. int qm_cid_count;
  1144. int dropless_fc;
  1145. #ifdef BCM_CNIC
  1146. u32 cnic_flags;
  1147. #define BNX2X_CNIC_FLAG_MAC_SET 1
  1148. void *t2;
  1149. dma_addr_t t2_mapping;
  1150. struct cnic_ops __rcu *cnic_ops;
  1151. void *cnic_data;
  1152. u32 cnic_tag;
  1153. struct cnic_eth_dev cnic_eth_dev;
  1154. union host_hc_status_block cnic_sb;
  1155. dma_addr_t cnic_sb_mapping;
  1156. struct eth_spe *cnic_kwq;
  1157. struct eth_spe *cnic_kwq_prod;
  1158. struct eth_spe *cnic_kwq_cons;
  1159. struct eth_spe *cnic_kwq_last;
  1160. u16 cnic_kwq_pending;
  1161. u16 cnic_spq_pending;
  1162. u8 fip_mac[ETH_ALEN];
  1163. struct mutex cnic_mutex;
  1164. struct bnx2x_vlan_mac_obj iscsi_l2_mac_obj;
  1165. /* Start index of the "special" (CNIC related) L2 cleints */
  1166. u8 cnic_base_cl_id;
  1167. #endif
  1168. int dmae_ready;
  1169. /* used to synchronize dmae accesses */
  1170. spinlock_t dmae_lock;
  1171. /* used to protect the FW mail box */
  1172. struct mutex fw_mb_mutex;
  1173. /* used to synchronize stats collecting */
  1174. int stats_state;
  1175. /* used for synchronization of concurrent threads statistics handling */
  1176. spinlock_t stats_lock;
  1177. /* used by dmae command loader */
  1178. struct dmae_command stats_dmae;
  1179. int executer_idx;
  1180. u16 stats_counter;
  1181. struct bnx2x_eth_stats eth_stats;
  1182. struct bnx2x_eth_stats_old eth_stats_old;
  1183. struct bnx2x_net_stats_old net_stats_old;
  1184. struct bnx2x_fw_port_stats_old fw_stats_old;
  1185. bool stats_init;
  1186. struct z_stream_s *strm;
  1187. void *gunzip_buf;
  1188. dma_addr_t gunzip_mapping;
  1189. int gunzip_outlen;
  1190. #define FW_BUF_SIZE 0x8000
  1191. #define GUNZIP_BUF(bp) (bp->gunzip_buf)
  1192. #define GUNZIP_PHYS(bp) (bp->gunzip_mapping)
  1193. #define GUNZIP_OUTLEN(bp) (bp->gunzip_outlen)
  1194. struct raw_op *init_ops;
  1195. /* Init blocks offsets inside init_ops */
  1196. u16 *init_ops_offsets;
  1197. /* Data blob - has 32 bit granularity */
  1198. u32 *init_data;
  1199. u32 init_mode_flags;
  1200. #define INIT_MODE_FLAGS(bp) (bp->init_mode_flags)
  1201. /* Zipped PRAM blobs - raw data */
  1202. const u8 *tsem_int_table_data;
  1203. const u8 *tsem_pram_data;
  1204. const u8 *usem_int_table_data;
  1205. const u8 *usem_pram_data;
  1206. const u8 *xsem_int_table_data;
  1207. const u8 *xsem_pram_data;
  1208. const u8 *csem_int_table_data;
  1209. const u8 *csem_pram_data;
  1210. #define INIT_OPS(bp) (bp->init_ops)
  1211. #define INIT_OPS_OFFSETS(bp) (bp->init_ops_offsets)
  1212. #define INIT_DATA(bp) (bp->init_data)
  1213. #define INIT_TSEM_INT_TABLE_DATA(bp) (bp->tsem_int_table_data)
  1214. #define INIT_TSEM_PRAM_DATA(bp) (bp->tsem_pram_data)
  1215. #define INIT_USEM_INT_TABLE_DATA(bp) (bp->usem_int_table_data)
  1216. #define INIT_USEM_PRAM_DATA(bp) (bp->usem_pram_data)
  1217. #define INIT_XSEM_INT_TABLE_DATA(bp) (bp->xsem_int_table_data)
  1218. #define INIT_XSEM_PRAM_DATA(bp) (bp->xsem_pram_data)
  1219. #define INIT_CSEM_INT_TABLE_DATA(bp) (bp->csem_int_table_data)
  1220. #define INIT_CSEM_PRAM_DATA(bp) (bp->csem_pram_data)
  1221. #define PHY_FW_VER_LEN 20
  1222. char fw_ver[32];
  1223. const struct firmware *firmware;
  1224. /* DCB support on/off */
  1225. u16 dcb_state;
  1226. #define BNX2X_DCB_STATE_OFF 0
  1227. #define BNX2X_DCB_STATE_ON 1
  1228. /* DCBX engine mode */
  1229. int dcbx_enabled;
  1230. #define BNX2X_DCBX_ENABLED_OFF 0
  1231. #define BNX2X_DCBX_ENABLED_ON_NEG_OFF 1
  1232. #define BNX2X_DCBX_ENABLED_ON_NEG_ON 2
  1233. #define BNX2X_DCBX_ENABLED_INVALID (-1)
  1234. bool dcbx_mode_uset;
  1235. struct bnx2x_config_dcbx_params dcbx_config_params;
  1236. struct bnx2x_dcbx_port_params dcbx_port_params;
  1237. int dcb_version;
  1238. /* CAM credit pools */
  1239. struct bnx2x_credit_pool_obj macs_pool;
  1240. /* RX_MODE object */
  1241. struct bnx2x_rx_mode_obj rx_mode_obj;
  1242. /* MCAST object */
  1243. struct bnx2x_mcast_obj mcast_obj;
  1244. /* RSS configuration object */
  1245. struct bnx2x_rss_config_obj rss_conf_obj;
  1246. /* Function State controlling object */
  1247. struct bnx2x_func_sp_obj func_obj;
  1248. unsigned long sp_state;
  1249. /* operation indication for the sp_rtnl task */
  1250. unsigned long sp_rtnl_state;
  1251. /* DCBX Negotation results */
  1252. struct dcbx_features dcbx_local_feat;
  1253. u32 dcbx_error;
  1254. #ifdef BCM_DCBNL
  1255. struct dcbx_features dcbx_remote_feat;
  1256. u32 dcbx_remote_flags;
  1257. #endif
  1258. u32 pending_max;
  1259. /* multiple tx classes of service */
  1260. u8 max_cos;
  1261. /* priority to cos mapping */
  1262. u8 prio_to_cos[8];
  1263. };
  1264. /* Tx queues may be less or equal to Rx queues */
  1265. extern int num_queues;
  1266. #define BNX2X_NUM_QUEUES(bp) (bp->num_queues)
  1267. #define BNX2X_NUM_ETH_QUEUES(bp) (BNX2X_NUM_QUEUES(bp) - NON_ETH_CONTEXT_USE)
  1268. #define BNX2X_NUM_RX_QUEUES(bp) BNX2X_NUM_QUEUES(bp)
  1269. #define is_multi(bp) (BNX2X_NUM_QUEUES(bp) > 1)
  1270. #define BNX2X_MAX_QUEUES(bp) BNX2X_MAX_RSS_COUNT(bp)
  1271. /* #define is_eth_multi(bp) (BNX2X_NUM_ETH_QUEUES(bp) > 1) */
  1272. #define RSS_IPV4_CAP_MASK \
  1273. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY
  1274. #define RSS_IPV4_TCP_CAP_MASK \
  1275. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY
  1276. #define RSS_IPV6_CAP_MASK \
  1277. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY
  1278. #define RSS_IPV6_TCP_CAP_MASK \
  1279. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY
  1280. /* func init flags */
  1281. #define FUNC_FLG_RSS 0x0001
  1282. #define FUNC_FLG_STATS 0x0002
  1283. /* removed FUNC_FLG_UNMATCHED 0x0004 */
  1284. #define FUNC_FLG_TPA 0x0008
  1285. #define FUNC_FLG_SPQ 0x0010
  1286. #define FUNC_FLG_LEADING 0x0020 /* PF only */
  1287. struct bnx2x_func_init_params {
  1288. /* dma */
  1289. dma_addr_t fw_stat_map; /* valid iff FUNC_FLG_STATS */
  1290. dma_addr_t spq_map; /* valid iff FUNC_FLG_SPQ */
  1291. u16 func_flgs;
  1292. u16 func_id; /* abs fid */
  1293. u16 pf_id;
  1294. u16 spq_prod; /* valid iff FUNC_FLG_SPQ */
  1295. };
  1296. #define for_each_eth_queue(bp, var) \
  1297. for ((var) = 0; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
  1298. #define for_each_nondefault_eth_queue(bp, var) \
  1299. for ((var) = 1; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
  1300. #define for_each_queue(bp, var) \
  1301. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1302. if (skip_queue(bp, var)) \
  1303. continue; \
  1304. else
  1305. /* Skip forwarding FP */
  1306. #define for_each_rx_queue(bp, var) \
  1307. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1308. if (skip_rx_queue(bp, var)) \
  1309. continue; \
  1310. else
  1311. /* Skip OOO FP */
  1312. #define for_each_tx_queue(bp, var) \
  1313. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1314. if (skip_tx_queue(bp, var)) \
  1315. continue; \
  1316. else
  1317. #define for_each_nondefault_queue(bp, var) \
  1318. for ((var) = 1; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1319. if (skip_queue(bp, var)) \
  1320. continue; \
  1321. else
  1322. #define for_each_cos_in_tx_queue(fp, var) \
  1323. for ((var) = 0; (var) < (fp)->max_cos; (var)++)
  1324. /* skip rx queue
  1325. * if FCOE l2 support is disabled and this is the fcoe L2 queue
  1326. */
  1327. #define skip_rx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1328. /* skip tx queue
  1329. * if FCOE l2 support is disabled and this is the fcoe L2 queue
  1330. */
  1331. #define skip_tx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1332. #define skip_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1333. /**
  1334. * bnx2x_set_mac_one - configure a single MAC address
  1335. *
  1336. * @bp: driver handle
  1337. * @mac: MAC to configure
  1338. * @obj: MAC object handle
  1339. * @set: if 'true' add a new MAC, otherwise - delete
  1340. * @mac_type: the type of the MAC to configure (e.g. ETH, UC list)
  1341. * @ramrod_flags: RAMROD_XXX flags (e.g. RAMROD_CONT, RAMROD_COMP_WAIT)
  1342. *
  1343. * Configures one MAC according to provided parameters or continues the
  1344. * execution of previously scheduled commands if RAMROD_CONT is set in
  1345. * ramrod_flags.
  1346. *
  1347. * Returns zero if operation has successfully completed, a positive value if the
  1348. * operation has been successfully scheduled and a negative - if a requested
  1349. * operations has failed.
  1350. */
  1351. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  1352. struct bnx2x_vlan_mac_obj *obj, bool set,
  1353. int mac_type, unsigned long *ramrod_flags);
  1354. /**
  1355. * Deletes all MACs configured for the specific MAC object.
  1356. *
  1357. * @param bp Function driver instance
  1358. * @param mac_obj MAC object to cleanup
  1359. *
  1360. * @return zero if all MACs were cleaned
  1361. */
  1362. /**
  1363. * bnx2x_del_all_macs - delete all MACs configured for the specific MAC object
  1364. *
  1365. * @bp: driver handle
  1366. * @mac_obj: MAC object handle
  1367. * @mac_type: type of the MACs to clear (BNX2X_XXX_MAC)
  1368. * @wait_for_comp: if 'true' block until completion
  1369. *
  1370. * Deletes all MACs of the specific type (e.g. ETH, UC list).
  1371. *
  1372. * Returns zero if operation has successfully completed, a positive value if the
  1373. * operation has been successfully scheduled and a negative - if a requested
  1374. * operations has failed.
  1375. */
  1376. int bnx2x_del_all_macs(struct bnx2x *bp,
  1377. struct bnx2x_vlan_mac_obj *mac_obj,
  1378. int mac_type, bool wait_for_comp);
  1379. /* Init Function API */
  1380. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p);
  1381. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port);
  1382. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
  1383. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode);
  1384. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
  1385. void bnx2x_read_mf_cfg(struct bnx2x *bp);
  1386. /* dmae */
  1387. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
  1388. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  1389. u32 len32);
  1390. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx);
  1391. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type);
  1392. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode);
  1393. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  1394. bool with_comp, u8 comp_type);
  1395. void bnx2x_calc_fc_adv(struct bnx2x *bp);
  1396. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  1397. u32 data_hi, u32 data_lo, int cmd_type);
  1398. void bnx2x_update_coalesce(struct bnx2x *bp);
  1399. int bnx2x_get_cur_phy_idx(struct bnx2x *bp);
  1400. static inline u32 reg_poll(struct bnx2x *bp, u32 reg, u32 expected, int ms,
  1401. int wait)
  1402. {
  1403. u32 val;
  1404. do {
  1405. val = REG_RD(bp, reg);
  1406. if (val == expected)
  1407. break;
  1408. ms -= wait;
  1409. msleep(wait);
  1410. } while (ms > 0);
  1411. return val;
  1412. }
  1413. #define BNX2X_ILT_ZALLOC(x, y, size) \
  1414. do { \
  1415. x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
  1416. if (x) \
  1417. memset(x, 0, size); \
  1418. } while (0)
  1419. #define BNX2X_ILT_FREE(x, y, size) \
  1420. do { \
  1421. if (x) { \
  1422. dma_free_coherent(&bp->pdev->dev, size, x, y); \
  1423. x = NULL; \
  1424. y = 0; \
  1425. } \
  1426. } while (0)
  1427. #define ILOG2(x) (ilog2((x)))
  1428. #define ILT_NUM_PAGE_ENTRIES (3072)
  1429. /* In 57710/11 we use whole table since we have 8 func
  1430. * In 57712 we have only 4 func, but use same size per func, then only half of
  1431. * the table in use
  1432. */
  1433. #define ILT_PER_FUNC (ILT_NUM_PAGE_ENTRIES/8)
  1434. #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
  1435. /*
  1436. * the phys address is shifted right 12 bits and has an added
  1437. * 1=valid bit added to the 53rd bit
  1438. * then since this is a wide register(TM)
  1439. * we split it into two 32 bit writes
  1440. */
  1441. #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
  1442. #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
  1443. /* load/unload mode */
  1444. #define LOAD_NORMAL 0
  1445. #define LOAD_OPEN 1
  1446. #define LOAD_DIAG 2
  1447. #define UNLOAD_NORMAL 0
  1448. #define UNLOAD_CLOSE 1
  1449. #define UNLOAD_RECOVERY 2
  1450. /* DMAE command defines */
  1451. #define DMAE_TIMEOUT -1
  1452. #define DMAE_PCI_ERROR -2 /* E2 and onward */
  1453. #define DMAE_NOT_RDY -3
  1454. #define DMAE_PCI_ERR_FLAG 0x80000000
  1455. #define DMAE_SRC_PCI 0
  1456. #define DMAE_SRC_GRC 1
  1457. #define DMAE_DST_NONE 0
  1458. #define DMAE_DST_PCI 1
  1459. #define DMAE_DST_GRC 2
  1460. #define DMAE_COMP_PCI 0
  1461. #define DMAE_COMP_GRC 1
  1462. /* E2 and onward - PCI error handling in the completion */
  1463. #define DMAE_COMP_REGULAR 0
  1464. #define DMAE_COM_SET_ERR 1
  1465. #define DMAE_CMD_SRC_PCI (DMAE_SRC_PCI << \
  1466. DMAE_COMMAND_SRC_SHIFT)
  1467. #define DMAE_CMD_SRC_GRC (DMAE_SRC_GRC << \
  1468. DMAE_COMMAND_SRC_SHIFT)
  1469. #define DMAE_CMD_DST_PCI (DMAE_DST_PCI << \
  1470. DMAE_COMMAND_DST_SHIFT)
  1471. #define DMAE_CMD_DST_GRC (DMAE_DST_GRC << \
  1472. DMAE_COMMAND_DST_SHIFT)
  1473. #define DMAE_CMD_C_DST_PCI (DMAE_COMP_PCI << \
  1474. DMAE_COMMAND_C_DST_SHIFT)
  1475. #define DMAE_CMD_C_DST_GRC (DMAE_COMP_GRC << \
  1476. DMAE_COMMAND_C_DST_SHIFT)
  1477. #define DMAE_CMD_C_ENABLE DMAE_COMMAND_C_TYPE_ENABLE
  1478. #define DMAE_CMD_ENDIANITY_NO_SWAP (0 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1479. #define DMAE_CMD_ENDIANITY_B_SWAP (1 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1480. #define DMAE_CMD_ENDIANITY_DW_SWAP (2 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1481. #define DMAE_CMD_ENDIANITY_B_DW_SWAP (3 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1482. #define DMAE_CMD_PORT_0 0
  1483. #define DMAE_CMD_PORT_1 DMAE_COMMAND_PORT
  1484. #define DMAE_CMD_SRC_RESET DMAE_COMMAND_SRC_RESET
  1485. #define DMAE_CMD_DST_RESET DMAE_COMMAND_DST_RESET
  1486. #define DMAE_CMD_E1HVN_SHIFT DMAE_COMMAND_E1HVN_SHIFT
  1487. #define DMAE_SRC_PF 0
  1488. #define DMAE_SRC_VF 1
  1489. #define DMAE_DST_PF 0
  1490. #define DMAE_DST_VF 1
  1491. #define DMAE_C_SRC 0
  1492. #define DMAE_C_DST 1
  1493. #define DMAE_LEN32_RD_MAX 0x80
  1494. #define DMAE_LEN32_WR_MAX(bp) (CHIP_IS_E1(bp) ? 0x400 : 0x2000)
  1495. #define DMAE_COMP_VAL 0x60d0d0ae /* E2 and on - upper bit
  1496. indicates eror */
  1497. #define MAX_DMAE_C_PER_PORT 8
  1498. #define INIT_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
  1499. BP_VN(bp))
  1500. #define PMF_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
  1501. E1HVN_MAX)
  1502. /* PCIE link and speed */
  1503. #define PCICFG_LINK_WIDTH 0x1f00000
  1504. #define PCICFG_LINK_WIDTH_SHIFT 20
  1505. #define PCICFG_LINK_SPEED 0xf0000
  1506. #define PCICFG_LINK_SPEED_SHIFT 16
  1507. #define BNX2X_NUM_TESTS 7
  1508. #define BNX2X_PHY_LOOPBACK 0
  1509. #define BNX2X_MAC_LOOPBACK 1
  1510. #define BNX2X_PHY_LOOPBACK_FAILED 1
  1511. #define BNX2X_MAC_LOOPBACK_FAILED 2
  1512. #define BNX2X_LOOPBACK_FAILED (BNX2X_MAC_LOOPBACK_FAILED | \
  1513. BNX2X_PHY_LOOPBACK_FAILED)
  1514. #define STROM_ASSERT_ARRAY_SIZE 50
  1515. /* must be used on a CID before placing it on a HW ring */
  1516. #define HW_CID(bp, x) ((BP_PORT(bp) << 23) | \
  1517. (BP_VN(bp) << BNX2X_SWCID_SHIFT) | \
  1518. (x))
  1519. #define SP_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_spe))
  1520. #define MAX_SP_DESC_CNT (SP_DESC_CNT - 1)
  1521. #define BNX2X_BTR 4
  1522. #define MAX_SPQ_PENDING 8
  1523. /* CMNG constants, as derived from system spec calculations */
  1524. /* default MIN rate in case VNIC min rate is configured to zero - 100Mbps */
  1525. #define DEF_MIN_RATE 100
  1526. /* resolution of the rate shaping timer - 400 usec */
  1527. #define RS_PERIODIC_TIMEOUT_USEC 400
  1528. /* number of bytes in single QM arbitration cycle -
  1529. * coefficient for calculating the fairness timer */
  1530. #define QM_ARB_BYTES 160000
  1531. /* resolution of Min algorithm 1:100 */
  1532. #define MIN_RES 100
  1533. /* how many bytes above threshold for the minimal credit of Min algorithm*/
  1534. #define MIN_ABOVE_THRESH 32768
  1535. /* Fairness algorithm integration time coefficient -
  1536. * for calculating the actual Tfair */
  1537. #define T_FAIR_COEF ((MIN_ABOVE_THRESH + QM_ARB_BYTES) * 8 * MIN_RES)
  1538. /* Memory of fairness algorithm . 2 cycles */
  1539. #define FAIR_MEM 2
  1540. #define ATTN_NIG_FOR_FUNC (1L << 8)
  1541. #define ATTN_SW_TIMER_4_FUNC (1L << 9)
  1542. #define GPIO_2_FUNC (1L << 10)
  1543. #define GPIO_3_FUNC (1L << 11)
  1544. #define GPIO_4_FUNC (1L << 12)
  1545. #define ATTN_GENERAL_ATTN_1 (1L << 13)
  1546. #define ATTN_GENERAL_ATTN_2 (1L << 14)
  1547. #define ATTN_GENERAL_ATTN_3 (1L << 15)
  1548. #define ATTN_GENERAL_ATTN_4 (1L << 13)
  1549. #define ATTN_GENERAL_ATTN_5 (1L << 14)
  1550. #define ATTN_GENERAL_ATTN_6 (1L << 15)
  1551. #define ATTN_HARD_WIRED_MASK 0xff00
  1552. #define ATTENTION_ID 4
  1553. /* stuff added to make the code fit 80Col */
  1554. #define BNX2X_PMF_LINK_ASSERT \
  1555. GENERAL_ATTEN_OFFSET(LINK_SYNC_ATTENTION_BIT_FUNC_0 + BP_FUNC(bp))
  1556. #define BNX2X_MC_ASSERT_BITS \
  1557. (GENERAL_ATTEN_OFFSET(TSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1558. GENERAL_ATTEN_OFFSET(USTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1559. GENERAL_ATTEN_OFFSET(CSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1560. GENERAL_ATTEN_OFFSET(XSTORM_FATAL_ASSERT_ATTENTION_BIT))
  1561. #define BNX2X_MCP_ASSERT \
  1562. GENERAL_ATTEN_OFFSET(MCP_FATAL_ASSERT_ATTENTION_BIT)
  1563. #define BNX2X_GRC_TIMEOUT GENERAL_ATTEN_OFFSET(LATCHED_ATTN_TIMEOUT_GRC)
  1564. #define BNX2X_GRC_RSV (GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCR) | \
  1565. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCT) | \
  1566. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCN) | \
  1567. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCU) | \
  1568. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCP) | \
  1569. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RSVD_GRC))
  1570. #define HW_INTERRUT_ASSERT_SET_0 \
  1571. (AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT | \
  1572. AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT | \
  1573. AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT | \
  1574. AEU_INPUTS_ATTN_BITS_PBCLIENT_HW_INTERRUPT)
  1575. #define HW_PRTY_ASSERT_SET_0 (AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR | \
  1576. AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR | \
  1577. AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR | \
  1578. AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR |\
  1579. AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR |\
  1580. AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR |\
  1581. AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR)
  1582. #define HW_INTERRUT_ASSERT_SET_1 \
  1583. (AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT | \
  1584. AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT | \
  1585. AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT | \
  1586. AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT | \
  1587. AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT | \
  1588. AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT | \
  1589. AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT | \
  1590. AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT | \
  1591. AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT | \
  1592. AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT | \
  1593. AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT)
  1594. #define HW_PRTY_ASSERT_SET_1 (AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR |\
  1595. AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR | \
  1596. AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR |\
  1597. AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR | \
  1598. AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR |\
  1599. AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR | \
  1600. AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR |\
  1601. AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR |\
  1602. AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR |\
  1603. AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR | \
  1604. AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR | \
  1605. AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR |\
  1606. AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR | \
  1607. AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR | \
  1608. AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR |\
  1609. AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR)
  1610. #define HW_INTERRUT_ASSERT_SET_2 \
  1611. (AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT | \
  1612. AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT | \
  1613. AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT | \
  1614. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT |\
  1615. AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT)
  1616. #define HW_PRTY_ASSERT_SET_2 (AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR | \
  1617. AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR | \
  1618. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR |\
  1619. AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR | \
  1620. AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR | \
  1621. AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR |\
  1622. AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR | \
  1623. AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR)
  1624. #define HW_PRTY_ASSERT_SET_3 (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
  1625. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
  1626. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY | \
  1627. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
  1628. #define HW_PRTY_ASSERT_SET_4 (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | \
  1629. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)
  1630. #define MULTI_MASK 0x7f
  1631. #define DEF_USB_FUNC_OFF offsetof(struct cstorm_def_status_block_u, func)
  1632. #define DEF_CSB_FUNC_OFF offsetof(struct cstorm_def_status_block_c, func)
  1633. #define DEF_XSB_FUNC_OFF offsetof(struct xstorm_def_status_block, func)
  1634. #define DEF_TSB_FUNC_OFF offsetof(struct tstorm_def_status_block, func)
  1635. #define DEF_USB_IGU_INDEX_OFF \
  1636. offsetof(struct cstorm_def_status_block_u, igu_index)
  1637. #define DEF_CSB_IGU_INDEX_OFF \
  1638. offsetof(struct cstorm_def_status_block_c, igu_index)
  1639. #define DEF_XSB_IGU_INDEX_OFF \
  1640. offsetof(struct xstorm_def_status_block, igu_index)
  1641. #define DEF_TSB_IGU_INDEX_OFF \
  1642. offsetof(struct tstorm_def_status_block, igu_index)
  1643. #define DEF_USB_SEGMENT_OFF \
  1644. offsetof(struct cstorm_def_status_block_u, segment)
  1645. #define DEF_CSB_SEGMENT_OFF \
  1646. offsetof(struct cstorm_def_status_block_c, segment)
  1647. #define DEF_XSB_SEGMENT_OFF \
  1648. offsetof(struct xstorm_def_status_block, segment)
  1649. #define DEF_TSB_SEGMENT_OFF \
  1650. offsetof(struct tstorm_def_status_block, segment)
  1651. #define BNX2X_SP_DSB_INDEX \
  1652. (&bp->def_status_blk->sp_sb.\
  1653. index_values[HC_SP_INDEX_ETH_DEF_CONS])
  1654. #define SET_FLAG(value, mask, flag) \
  1655. do {\
  1656. (value) &= ~(mask);\
  1657. (value) |= ((flag) << (mask##_SHIFT));\
  1658. } while (0)
  1659. #define GET_FLAG(value, mask) \
  1660. (((value) & (mask)) >> (mask##_SHIFT))
  1661. #define GET_FIELD(value, fname) \
  1662. (((value) & (fname##_MASK)) >> (fname##_SHIFT))
  1663. #define CAM_IS_INVALID(x) \
  1664. (GET_FLAG(x.flags, \
  1665. MAC_CONFIGURATION_ENTRY_ACTION_TYPE) == \
  1666. (T_ETH_MAC_COMMAND_INVALIDATE))
  1667. /* Number of u32 elements in MC hash array */
  1668. #define MC_HASH_SIZE 8
  1669. #define MC_HASH_OFFSET(bp, i) (BAR_TSTRORM_INTMEM + \
  1670. TSTORM_APPROXIMATE_MATCH_MULTICAST_FILTERING_OFFSET(BP_FUNC(bp)) + i*4)
  1671. #ifndef PXP2_REG_PXP2_INT_STS
  1672. #define PXP2_REG_PXP2_INT_STS PXP2_REG_PXP2_INT_STS_0
  1673. #endif
  1674. #ifndef ETH_MAX_RX_CLIENTS_E2
  1675. #define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
  1676. #endif
  1677. #define BNX2X_VPD_LEN 128
  1678. #define VENDOR_ID_LEN 4
  1679. int bnx2x_close(struct net_device *dev);
  1680. /* Congestion management fairness mode */
  1681. #define CMNG_FNS_NONE 0
  1682. #define CMNG_FNS_MINMAX 1
  1683. #define HC_SEG_ACCESS_DEF 0 /*Driver decision 0-3*/
  1684. #define HC_SEG_ACCESS_ATTN 4
  1685. #define HC_SEG_ACCESS_NORM 0 /*Driver decision 0-1*/
  1686. static const u32 dmae_reg_go_c[] = {
  1687. DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
  1688. DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
  1689. DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
  1690. DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
  1691. };
  1692. void bnx2x_set_ethtool_ops(struct net_device *netdev);
  1693. void bnx2x_notify_link_changed(struct bnx2x *bp);
  1694. #define BNX2X_MF_PROTOCOL(bp) \
  1695. ((bp)->mf_config[BP_VN(bp)] & FUNC_MF_CFG_PROTOCOL_MASK)
  1696. #ifdef BCM_CNIC
  1697. #define BNX2X_IS_MF_PROTOCOL_ISCSI(bp) \
  1698. (BNX2X_MF_PROTOCOL(bp) == FUNC_MF_CFG_PROTOCOL_ISCSI)
  1699. #define IS_MF_ISCSI_SD(bp) (IS_MF_SD(bp) && BNX2X_IS_MF_PROTOCOL_ISCSI(bp))
  1700. #endif
  1701. #endif /* bnx2x.h */