bnx2x.h 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108
  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. /* 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. u32 boot_mode;
  724. };
  725. /* IGU MSIX STATISTICS on 57712: 64 for VFs; 4 for PFs; 4 for Attentions */
  726. #define BNX2X_IGU_STAS_MSG_VF_CNT 64
  727. #define BNX2X_IGU_STAS_MSG_PF_CNT 4
  728. /* end of common */
  729. /* port */
  730. struct bnx2x_port {
  731. u32 pmf;
  732. u32 link_config[LINK_CONFIG_SIZE];
  733. u32 supported[LINK_CONFIG_SIZE];
  734. /* link settings - missing defines */
  735. #define SUPPORTED_2500baseX_Full (1 << 15)
  736. u32 advertising[LINK_CONFIG_SIZE];
  737. /* link settings - missing defines */
  738. #define ADVERTISED_2500baseX_Full (1 << 15)
  739. u32 phy_addr;
  740. /* used to synchronize phy accesses */
  741. struct mutex phy_mutex;
  742. int need_hw_lock;
  743. u32 port_stx;
  744. struct nig_stats old_nig_stats;
  745. };
  746. /* end of port */
  747. #define STATS_OFFSET32(stat_name) \
  748. (offsetof(struct bnx2x_eth_stats, stat_name) / 4)
  749. /* slow path */
  750. /* slow path work-queue */
  751. extern struct workqueue_struct *bnx2x_wq;
  752. #define BNX2X_MAX_NUM_OF_VFS 64
  753. #define BNX2X_VF_ID_INVALID 0xFF
  754. /*
  755. * The total number of L2 queues, MSIX vectors and HW contexts (CIDs) is
  756. * control by the number of fast-path status blocks supported by the
  757. * device (HW/FW). Each fast-path status block (FP-SB) aka non-default
  758. * status block represents an independent interrupts context that can
  759. * serve a regular L2 networking queue. However special L2 queues such
  760. * as the FCoE queue do not require a FP-SB and other components like
  761. * the CNIC may consume FP-SB reducing the number of possible L2 queues
  762. *
  763. * If the maximum number of FP-SB available is X then:
  764. * a. If CNIC is supported it consumes 1 FP-SB thus the max number of
  765. * regular L2 queues is Y=X-1
  766. * b. in MF mode the actual number of L2 queues is Y= (X-1/MF_factor)
  767. * c. If the FCoE L2 queue is supported the actual number of L2 queues
  768. * is Y+1
  769. * d. The number of irqs (MSIX vectors) is either Y+1 (one extra for
  770. * slow-path interrupts) or Y+2 if CNIC is supported (one additional
  771. * FP interrupt context for the CNIC).
  772. * e. The number of HW context (CID count) is always X or X+1 if FCoE
  773. * L2 queue is supported. the cid for the FCoE L2 queue is always X.
  774. */
  775. /* fast-path interrupt contexts E1x */
  776. #define FP_SB_MAX_E1x 16
  777. /* fast-path interrupt contexts E2 */
  778. #define FP_SB_MAX_E2 HC_SB_MAX_SB_E2
  779. union cdu_context {
  780. struct eth_context eth;
  781. char pad[1024];
  782. };
  783. /* CDU host DB constants */
  784. #define CDU_ILT_PAGE_SZ_HW 3
  785. #define CDU_ILT_PAGE_SZ (8192 << CDU_ILT_PAGE_SZ_HW) /* 64K */
  786. #define ILT_PAGE_CIDS (CDU_ILT_PAGE_SZ / sizeof(union cdu_context))
  787. #ifdef BCM_CNIC
  788. #define CNIC_ISCSI_CID_MAX 256
  789. #define CNIC_FCOE_CID_MAX 2048
  790. #define CNIC_CID_MAX (CNIC_ISCSI_CID_MAX + CNIC_FCOE_CID_MAX)
  791. #define CNIC_ILT_LINES DIV_ROUND_UP(CNIC_CID_MAX, ILT_PAGE_CIDS)
  792. #endif
  793. #define QM_ILT_PAGE_SZ_HW 0
  794. #define QM_ILT_PAGE_SZ (4096 << QM_ILT_PAGE_SZ_HW) /* 4K */
  795. #define QM_CID_ROUND 1024
  796. #ifdef BCM_CNIC
  797. /* TM (timers) host DB constants */
  798. #define TM_ILT_PAGE_SZ_HW 0
  799. #define TM_ILT_PAGE_SZ (4096 << TM_ILT_PAGE_SZ_HW) /* 4K */
  800. /* #define TM_CONN_NUM (CNIC_STARTING_CID+CNIC_ISCSI_CXT_MAX) */
  801. #define TM_CONN_NUM 1024
  802. #define TM_ILT_SZ (8 * TM_CONN_NUM)
  803. #define TM_ILT_LINES DIV_ROUND_UP(TM_ILT_SZ, TM_ILT_PAGE_SZ)
  804. /* SRC (Searcher) host DB constants */
  805. #define SRC_ILT_PAGE_SZ_HW 0
  806. #define SRC_ILT_PAGE_SZ (4096 << SRC_ILT_PAGE_SZ_HW) /* 4K */
  807. #define SRC_HASH_BITS 10
  808. #define SRC_CONN_NUM (1 << SRC_HASH_BITS) /* 1024 */
  809. #define SRC_ILT_SZ (sizeof(struct src_ent) * SRC_CONN_NUM)
  810. #define SRC_T2_SZ SRC_ILT_SZ
  811. #define SRC_ILT_LINES DIV_ROUND_UP(SRC_ILT_SZ, SRC_ILT_PAGE_SZ)
  812. #endif
  813. #define MAX_DMAE_C 8
  814. /* DMA memory not used in fastpath */
  815. struct bnx2x_slowpath {
  816. union {
  817. struct mac_configuration_cmd e1x;
  818. struct eth_classify_rules_ramrod_data e2;
  819. } mac_rdata;
  820. union {
  821. struct tstorm_eth_mac_filter_config e1x;
  822. struct eth_filter_rules_ramrod_data e2;
  823. } rx_mode_rdata;
  824. union {
  825. struct mac_configuration_cmd e1;
  826. struct eth_multicast_rules_ramrod_data e2;
  827. } mcast_rdata;
  828. struct eth_rss_update_ramrod_data rss_rdata;
  829. /* Queue State related ramrods are always sent under rtnl_lock */
  830. union {
  831. struct client_init_ramrod_data init_data;
  832. struct client_update_ramrod_data update_data;
  833. } q_rdata;
  834. union {
  835. struct function_start_data func_start;
  836. /* pfc configuration for DCBX ramrod */
  837. struct flow_control_configuration pfc_config;
  838. } func_rdata;
  839. /* used by dmae command executer */
  840. struct dmae_command dmae[MAX_DMAE_C];
  841. u32 stats_comp;
  842. union mac_stats mac_stats;
  843. struct nig_stats nig_stats;
  844. struct host_port_stats port_stats;
  845. struct host_func_stats func_stats;
  846. struct host_func_stats func_stats_base;
  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 z_stream_s *strm;
  1183. void *gunzip_buf;
  1184. dma_addr_t gunzip_mapping;
  1185. int gunzip_outlen;
  1186. #define FW_BUF_SIZE 0x8000
  1187. #define GUNZIP_BUF(bp) (bp->gunzip_buf)
  1188. #define GUNZIP_PHYS(bp) (bp->gunzip_mapping)
  1189. #define GUNZIP_OUTLEN(bp) (bp->gunzip_outlen)
  1190. struct raw_op *init_ops;
  1191. /* Init blocks offsets inside init_ops */
  1192. u16 *init_ops_offsets;
  1193. /* Data blob - has 32 bit granularity */
  1194. u32 *init_data;
  1195. u32 init_mode_flags;
  1196. #define INIT_MODE_FLAGS(bp) (bp->init_mode_flags)
  1197. /* Zipped PRAM blobs - raw data */
  1198. const u8 *tsem_int_table_data;
  1199. const u8 *tsem_pram_data;
  1200. const u8 *usem_int_table_data;
  1201. const u8 *usem_pram_data;
  1202. const u8 *xsem_int_table_data;
  1203. const u8 *xsem_pram_data;
  1204. const u8 *csem_int_table_data;
  1205. const u8 *csem_pram_data;
  1206. #define INIT_OPS(bp) (bp->init_ops)
  1207. #define INIT_OPS_OFFSETS(bp) (bp->init_ops_offsets)
  1208. #define INIT_DATA(bp) (bp->init_data)
  1209. #define INIT_TSEM_INT_TABLE_DATA(bp) (bp->tsem_int_table_data)
  1210. #define INIT_TSEM_PRAM_DATA(bp) (bp->tsem_pram_data)
  1211. #define INIT_USEM_INT_TABLE_DATA(bp) (bp->usem_int_table_data)
  1212. #define INIT_USEM_PRAM_DATA(bp) (bp->usem_pram_data)
  1213. #define INIT_XSEM_INT_TABLE_DATA(bp) (bp->xsem_int_table_data)
  1214. #define INIT_XSEM_PRAM_DATA(bp) (bp->xsem_pram_data)
  1215. #define INIT_CSEM_INT_TABLE_DATA(bp) (bp->csem_int_table_data)
  1216. #define INIT_CSEM_PRAM_DATA(bp) (bp->csem_pram_data)
  1217. #define PHY_FW_VER_LEN 20
  1218. char fw_ver[32];
  1219. const struct firmware *firmware;
  1220. /* DCB support on/off */
  1221. u16 dcb_state;
  1222. #define BNX2X_DCB_STATE_OFF 0
  1223. #define BNX2X_DCB_STATE_ON 1
  1224. /* DCBX engine mode */
  1225. int dcbx_enabled;
  1226. #define BNX2X_DCBX_ENABLED_OFF 0
  1227. #define BNX2X_DCBX_ENABLED_ON_NEG_OFF 1
  1228. #define BNX2X_DCBX_ENABLED_ON_NEG_ON 2
  1229. #define BNX2X_DCBX_ENABLED_INVALID (-1)
  1230. bool dcbx_mode_uset;
  1231. struct bnx2x_config_dcbx_params dcbx_config_params;
  1232. struct bnx2x_dcbx_port_params dcbx_port_params;
  1233. int dcb_version;
  1234. /* CAM credit pools */
  1235. struct bnx2x_credit_pool_obj macs_pool;
  1236. /* RX_MODE object */
  1237. struct bnx2x_rx_mode_obj rx_mode_obj;
  1238. /* MCAST object */
  1239. struct bnx2x_mcast_obj mcast_obj;
  1240. /* RSS configuration object */
  1241. struct bnx2x_rss_config_obj rss_conf_obj;
  1242. /* Function State controlling object */
  1243. struct bnx2x_func_sp_obj func_obj;
  1244. unsigned long sp_state;
  1245. /* operation indication for the sp_rtnl task */
  1246. unsigned long sp_rtnl_state;
  1247. /* DCBX Negotation results */
  1248. struct dcbx_features dcbx_local_feat;
  1249. u32 dcbx_error;
  1250. #ifdef BCM_DCBNL
  1251. struct dcbx_features dcbx_remote_feat;
  1252. u32 dcbx_remote_flags;
  1253. #endif
  1254. u32 pending_max;
  1255. /* multiple tx classes of service */
  1256. u8 max_cos;
  1257. /* priority to cos mapping */
  1258. u8 prio_to_cos[8];
  1259. };
  1260. /* Tx queues may be less or equal to Rx queues */
  1261. extern int num_queues;
  1262. #define BNX2X_NUM_QUEUES(bp) (bp->num_queues)
  1263. #define BNX2X_NUM_ETH_QUEUES(bp) (BNX2X_NUM_QUEUES(bp) - NON_ETH_CONTEXT_USE)
  1264. #define BNX2X_NUM_RX_QUEUES(bp) BNX2X_NUM_QUEUES(bp)
  1265. #define is_multi(bp) (BNX2X_NUM_QUEUES(bp) > 1)
  1266. #define BNX2X_MAX_QUEUES(bp) BNX2X_MAX_RSS_COUNT(bp)
  1267. /* #define is_eth_multi(bp) (BNX2X_NUM_ETH_QUEUES(bp) > 1) */
  1268. #define RSS_IPV4_CAP_MASK \
  1269. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY
  1270. #define RSS_IPV4_TCP_CAP_MASK \
  1271. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY
  1272. #define RSS_IPV6_CAP_MASK \
  1273. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY
  1274. #define RSS_IPV6_TCP_CAP_MASK \
  1275. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY
  1276. /* func init flags */
  1277. #define FUNC_FLG_RSS 0x0001
  1278. #define FUNC_FLG_STATS 0x0002
  1279. /* removed FUNC_FLG_UNMATCHED 0x0004 */
  1280. #define FUNC_FLG_TPA 0x0008
  1281. #define FUNC_FLG_SPQ 0x0010
  1282. #define FUNC_FLG_LEADING 0x0020 /* PF only */
  1283. struct bnx2x_func_init_params {
  1284. /* dma */
  1285. dma_addr_t fw_stat_map; /* valid iff FUNC_FLG_STATS */
  1286. dma_addr_t spq_map; /* valid iff FUNC_FLG_SPQ */
  1287. u16 func_flgs;
  1288. u16 func_id; /* abs fid */
  1289. u16 pf_id;
  1290. u16 spq_prod; /* valid iff FUNC_FLG_SPQ */
  1291. };
  1292. #define for_each_eth_queue(bp, var) \
  1293. for ((var) = 0; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
  1294. #define for_each_nondefault_eth_queue(bp, var) \
  1295. for ((var) = 1; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
  1296. #define for_each_queue(bp, var) \
  1297. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1298. if (skip_queue(bp, var)) \
  1299. continue; \
  1300. else
  1301. /* Skip forwarding FP */
  1302. #define for_each_rx_queue(bp, var) \
  1303. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1304. if (skip_rx_queue(bp, var)) \
  1305. continue; \
  1306. else
  1307. /* Skip OOO FP */
  1308. #define for_each_tx_queue(bp, var) \
  1309. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1310. if (skip_tx_queue(bp, var)) \
  1311. continue; \
  1312. else
  1313. #define for_each_nondefault_queue(bp, var) \
  1314. for ((var) = 1; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1315. if (skip_queue(bp, var)) \
  1316. continue; \
  1317. else
  1318. #define for_each_cos_in_tx_queue(fp, var) \
  1319. for ((var) = 0; (var) < (fp)->max_cos; (var)++)
  1320. /* skip rx queue
  1321. * if FCOE l2 support is disabled and this is the fcoe L2 queue
  1322. */
  1323. #define skip_rx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1324. /* skip tx queue
  1325. * if FCOE l2 support is disabled and this is the fcoe L2 queue
  1326. */
  1327. #define skip_tx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1328. #define skip_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1329. /**
  1330. * bnx2x_set_mac_one - configure a single MAC address
  1331. *
  1332. * @bp: driver handle
  1333. * @mac: MAC to configure
  1334. * @obj: MAC object handle
  1335. * @set: if 'true' add a new MAC, otherwise - delete
  1336. * @mac_type: the type of the MAC to configure (e.g. ETH, UC list)
  1337. * @ramrod_flags: RAMROD_XXX flags (e.g. RAMROD_CONT, RAMROD_COMP_WAIT)
  1338. *
  1339. * Configures one MAC according to provided parameters or continues the
  1340. * execution of previously scheduled commands if RAMROD_CONT is set in
  1341. * ramrod_flags.
  1342. *
  1343. * Returns zero if operation has successfully completed, a positive value if the
  1344. * operation has been successfully scheduled and a negative - if a requested
  1345. * operations has failed.
  1346. */
  1347. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  1348. struct bnx2x_vlan_mac_obj *obj, bool set,
  1349. int mac_type, unsigned long *ramrod_flags);
  1350. /**
  1351. * Deletes all MACs configured for the specific MAC object.
  1352. *
  1353. * @param bp Function driver instance
  1354. * @param mac_obj MAC object to cleanup
  1355. *
  1356. * @return zero if all MACs were cleaned
  1357. */
  1358. /**
  1359. * bnx2x_del_all_macs - delete all MACs configured for the specific MAC object
  1360. *
  1361. * @bp: driver handle
  1362. * @mac_obj: MAC object handle
  1363. * @mac_type: type of the MACs to clear (BNX2X_XXX_MAC)
  1364. * @wait_for_comp: if 'true' block until completion
  1365. *
  1366. * Deletes all MACs of the specific type (e.g. ETH, UC list).
  1367. *
  1368. * Returns zero if operation has successfully completed, a positive value if the
  1369. * operation has been successfully scheduled and a negative - if a requested
  1370. * operations has failed.
  1371. */
  1372. int bnx2x_del_all_macs(struct bnx2x *bp,
  1373. struct bnx2x_vlan_mac_obj *mac_obj,
  1374. int mac_type, bool wait_for_comp);
  1375. /* Init Function API */
  1376. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p);
  1377. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port);
  1378. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
  1379. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode);
  1380. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
  1381. void bnx2x_read_mf_cfg(struct bnx2x *bp);
  1382. /* dmae */
  1383. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
  1384. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  1385. u32 len32);
  1386. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx);
  1387. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type);
  1388. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode);
  1389. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  1390. bool with_comp, u8 comp_type);
  1391. void bnx2x_calc_fc_adv(struct bnx2x *bp);
  1392. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  1393. u32 data_hi, u32 data_lo, int cmd_type);
  1394. void bnx2x_update_coalesce(struct bnx2x *bp);
  1395. int bnx2x_get_cur_phy_idx(struct bnx2x *bp);
  1396. static inline u32 reg_poll(struct bnx2x *bp, u32 reg, u32 expected, int ms,
  1397. int wait)
  1398. {
  1399. u32 val;
  1400. do {
  1401. val = REG_RD(bp, reg);
  1402. if (val == expected)
  1403. break;
  1404. ms -= wait;
  1405. msleep(wait);
  1406. } while (ms > 0);
  1407. return val;
  1408. }
  1409. #define BNX2X_ILT_ZALLOC(x, y, size) \
  1410. do { \
  1411. x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
  1412. if (x) \
  1413. memset(x, 0, size); \
  1414. } while (0)
  1415. #define BNX2X_ILT_FREE(x, y, size) \
  1416. do { \
  1417. if (x) { \
  1418. dma_free_coherent(&bp->pdev->dev, size, x, y); \
  1419. x = NULL; \
  1420. y = 0; \
  1421. } \
  1422. } while (0)
  1423. #define ILOG2(x) (ilog2((x)))
  1424. #define ILT_NUM_PAGE_ENTRIES (3072)
  1425. /* In 57710/11 we use whole table since we have 8 func
  1426. * In 57712 we have only 4 func, but use same size per func, then only half of
  1427. * the table in use
  1428. */
  1429. #define ILT_PER_FUNC (ILT_NUM_PAGE_ENTRIES/8)
  1430. #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
  1431. /*
  1432. * the phys address is shifted right 12 bits and has an added
  1433. * 1=valid bit added to the 53rd bit
  1434. * then since this is a wide register(TM)
  1435. * we split it into two 32 bit writes
  1436. */
  1437. #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
  1438. #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
  1439. /* load/unload mode */
  1440. #define LOAD_NORMAL 0
  1441. #define LOAD_OPEN 1
  1442. #define LOAD_DIAG 2
  1443. #define UNLOAD_NORMAL 0
  1444. #define UNLOAD_CLOSE 1
  1445. #define UNLOAD_RECOVERY 2
  1446. /* DMAE command defines */
  1447. #define DMAE_TIMEOUT -1
  1448. #define DMAE_PCI_ERROR -2 /* E2 and onward */
  1449. #define DMAE_NOT_RDY -3
  1450. #define DMAE_PCI_ERR_FLAG 0x80000000
  1451. #define DMAE_SRC_PCI 0
  1452. #define DMAE_SRC_GRC 1
  1453. #define DMAE_DST_NONE 0
  1454. #define DMAE_DST_PCI 1
  1455. #define DMAE_DST_GRC 2
  1456. #define DMAE_COMP_PCI 0
  1457. #define DMAE_COMP_GRC 1
  1458. /* E2 and onward - PCI error handling in the completion */
  1459. #define DMAE_COMP_REGULAR 0
  1460. #define DMAE_COM_SET_ERR 1
  1461. #define DMAE_CMD_SRC_PCI (DMAE_SRC_PCI << \
  1462. DMAE_COMMAND_SRC_SHIFT)
  1463. #define DMAE_CMD_SRC_GRC (DMAE_SRC_GRC << \
  1464. DMAE_COMMAND_SRC_SHIFT)
  1465. #define DMAE_CMD_DST_PCI (DMAE_DST_PCI << \
  1466. DMAE_COMMAND_DST_SHIFT)
  1467. #define DMAE_CMD_DST_GRC (DMAE_DST_GRC << \
  1468. DMAE_COMMAND_DST_SHIFT)
  1469. #define DMAE_CMD_C_DST_PCI (DMAE_COMP_PCI << \
  1470. DMAE_COMMAND_C_DST_SHIFT)
  1471. #define DMAE_CMD_C_DST_GRC (DMAE_COMP_GRC << \
  1472. DMAE_COMMAND_C_DST_SHIFT)
  1473. #define DMAE_CMD_C_ENABLE DMAE_COMMAND_C_TYPE_ENABLE
  1474. #define DMAE_CMD_ENDIANITY_NO_SWAP (0 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1475. #define DMAE_CMD_ENDIANITY_B_SWAP (1 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1476. #define DMAE_CMD_ENDIANITY_DW_SWAP (2 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1477. #define DMAE_CMD_ENDIANITY_B_DW_SWAP (3 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1478. #define DMAE_CMD_PORT_0 0
  1479. #define DMAE_CMD_PORT_1 DMAE_COMMAND_PORT
  1480. #define DMAE_CMD_SRC_RESET DMAE_COMMAND_SRC_RESET
  1481. #define DMAE_CMD_DST_RESET DMAE_COMMAND_DST_RESET
  1482. #define DMAE_CMD_E1HVN_SHIFT DMAE_COMMAND_E1HVN_SHIFT
  1483. #define DMAE_SRC_PF 0
  1484. #define DMAE_SRC_VF 1
  1485. #define DMAE_DST_PF 0
  1486. #define DMAE_DST_VF 1
  1487. #define DMAE_C_SRC 0
  1488. #define DMAE_C_DST 1
  1489. #define DMAE_LEN32_RD_MAX 0x80
  1490. #define DMAE_LEN32_WR_MAX(bp) (CHIP_IS_E1(bp) ? 0x400 : 0x2000)
  1491. #define DMAE_COMP_VAL 0x60d0d0ae /* E2 and on - upper bit
  1492. indicates eror */
  1493. #define MAX_DMAE_C_PER_PORT 8
  1494. #define INIT_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
  1495. BP_VN(bp))
  1496. #define PMF_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
  1497. E1HVN_MAX)
  1498. /* PCIE link and speed */
  1499. #define PCICFG_LINK_WIDTH 0x1f00000
  1500. #define PCICFG_LINK_WIDTH_SHIFT 20
  1501. #define PCICFG_LINK_SPEED 0xf0000
  1502. #define PCICFG_LINK_SPEED_SHIFT 16
  1503. #define BNX2X_NUM_TESTS 7
  1504. #define BNX2X_PHY_LOOPBACK 0
  1505. #define BNX2X_MAC_LOOPBACK 1
  1506. #define BNX2X_PHY_LOOPBACK_FAILED 1
  1507. #define BNX2X_MAC_LOOPBACK_FAILED 2
  1508. #define BNX2X_LOOPBACK_FAILED (BNX2X_MAC_LOOPBACK_FAILED | \
  1509. BNX2X_PHY_LOOPBACK_FAILED)
  1510. #define STROM_ASSERT_ARRAY_SIZE 50
  1511. /* must be used on a CID before placing it on a HW ring */
  1512. #define HW_CID(bp, x) ((BP_PORT(bp) << 23) | \
  1513. (BP_VN(bp) << BNX2X_SWCID_SHIFT) | \
  1514. (x))
  1515. #define SP_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_spe))
  1516. #define MAX_SP_DESC_CNT (SP_DESC_CNT - 1)
  1517. #define BNX2X_BTR 4
  1518. #define MAX_SPQ_PENDING 8
  1519. /* CMNG constants, as derived from system spec calculations */
  1520. /* default MIN rate in case VNIC min rate is configured to zero - 100Mbps */
  1521. #define DEF_MIN_RATE 100
  1522. /* resolution of the rate shaping timer - 400 usec */
  1523. #define RS_PERIODIC_TIMEOUT_USEC 400
  1524. /* number of bytes in single QM arbitration cycle -
  1525. * coefficient for calculating the fairness timer */
  1526. #define QM_ARB_BYTES 160000
  1527. /* resolution of Min algorithm 1:100 */
  1528. #define MIN_RES 100
  1529. /* how many bytes above threshold for the minimal credit of Min algorithm*/
  1530. #define MIN_ABOVE_THRESH 32768
  1531. /* Fairness algorithm integration time coefficient -
  1532. * for calculating the actual Tfair */
  1533. #define T_FAIR_COEF ((MIN_ABOVE_THRESH + QM_ARB_BYTES) * 8 * MIN_RES)
  1534. /* Memory of fairness algorithm . 2 cycles */
  1535. #define FAIR_MEM 2
  1536. #define ATTN_NIG_FOR_FUNC (1L << 8)
  1537. #define ATTN_SW_TIMER_4_FUNC (1L << 9)
  1538. #define GPIO_2_FUNC (1L << 10)
  1539. #define GPIO_3_FUNC (1L << 11)
  1540. #define GPIO_4_FUNC (1L << 12)
  1541. #define ATTN_GENERAL_ATTN_1 (1L << 13)
  1542. #define ATTN_GENERAL_ATTN_2 (1L << 14)
  1543. #define ATTN_GENERAL_ATTN_3 (1L << 15)
  1544. #define ATTN_GENERAL_ATTN_4 (1L << 13)
  1545. #define ATTN_GENERAL_ATTN_5 (1L << 14)
  1546. #define ATTN_GENERAL_ATTN_6 (1L << 15)
  1547. #define ATTN_HARD_WIRED_MASK 0xff00
  1548. #define ATTENTION_ID 4
  1549. /* stuff added to make the code fit 80Col */
  1550. #define BNX2X_PMF_LINK_ASSERT \
  1551. GENERAL_ATTEN_OFFSET(LINK_SYNC_ATTENTION_BIT_FUNC_0 + BP_FUNC(bp))
  1552. #define BNX2X_MC_ASSERT_BITS \
  1553. (GENERAL_ATTEN_OFFSET(TSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1554. GENERAL_ATTEN_OFFSET(USTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1555. GENERAL_ATTEN_OFFSET(CSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1556. GENERAL_ATTEN_OFFSET(XSTORM_FATAL_ASSERT_ATTENTION_BIT))
  1557. #define BNX2X_MCP_ASSERT \
  1558. GENERAL_ATTEN_OFFSET(MCP_FATAL_ASSERT_ATTENTION_BIT)
  1559. #define BNX2X_GRC_TIMEOUT GENERAL_ATTEN_OFFSET(LATCHED_ATTN_TIMEOUT_GRC)
  1560. #define BNX2X_GRC_RSV (GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCR) | \
  1561. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCT) | \
  1562. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCN) | \
  1563. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCU) | \
  1564. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCP) | \
  1565. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RSVD_GRC))
  1566. #define HW_INTERRUT_ASSERT_SET_0 \
  1567. (AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT | \
  1568. AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT | \
  1569. AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT | \
  1570. AEU_INPUTS_ATTN_BITS_PBCLIENT_HW_INTERRUPT)
  1571. #define HW_PRTY_ASSERT_SET_0 (AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR | \
  1572. AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR | \
  1573. AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR | \
  1574. AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR |\
  1575. AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR |\
  1576. AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR |\
  1577. AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR)
  1578. #define HW_INTERRUT_ASSERT_SET_1 \
  1579. (AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT | \
  1580. AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT | \
  1581. AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT | \
  1582. AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT | \
  1583. AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT | \
  1584. AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT | \
  1585. AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT | \
  1586. AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT | \
  1587. AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT | \
  1588. AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT | \
  1589. AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT)
  1590. #define HW_PRTY_ASSERT_SET_1 (AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR |\
  1591. AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR | \
  1592. AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR |\
  1593. AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR | \
  1594. AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR |\
  1595. AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR | \
  1596. AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR |\
  1597. AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR |\
  1598. AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR |\
  1599. AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR | \
  1600. AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR | \
  1601. AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR |\
  1602. AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR | \
  1603. AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR | \
  1604. AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR |\
  1605. AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR)
  1606. #define HW_INTERRUT_ASSERT_SET_2 \
  1607. (AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT | \
  1608. AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT | \
  1609. AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT | \
  1610. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT |\
  1611. AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT)
  1612. #define HW_PRTY_ASSERT_SET_2 (AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR | \
  1613. AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR | \
  1614. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR |\
  1615. AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR | \
  1616. AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR | \
  1617. AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR |\
  1618. AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR | \
  1619. AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR)
  1620. #define HW_PRTY_ASSERT_SET_3 (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
  1621. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
  1622. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY | \
  1623. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
  1624. #define HW_PRTY_ASSERT_SET_4 (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | \
  1625. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)
  1626. #define MULTI_MASK 0x7f
  1627. #define DEF_USB_FUNC_OFF offsetof(struct cstorm_def_status_block_u, func)
  1628. #define DEF_CSB_FUNC_OFF offsetof(struct cstorm_def_status_block_c, func)
  1629. #define DEF_XSB_FUNC_OFF offsetof(struct xstorm_def_status_block, func)
  1630. #define DEF_TSB_FUNC_OFF offsetof(struct tstorm_def_status_block, func)
  1631. #define DEF_USB_IGU_INDEX_OFF \
  1632. offsetof(struct cstorm_def_status_block_u, igu_index)
  1633. #define DEF_CSB_IGU_INDEX_OFF \
  1634. offsetof(struct cstorm_def_status_block_c, igu_index)
  1635. #define DEF_XSB_IGU_INDEX_OFF \
  1636. offsetof(struct xstorm_def_status_block, igu_index)
  1637. #define DEF_TSB_IGU_INDEX_OFF \
  1638. offsetof(struct tstorm_def_status_block, igu_index)
  1639. #define DEF_USB_SEGMENT_OFF \
  1640. offsetof(struct cstorm_def_status_block_u, segment)
  1641. #define DEF_CSB_SEGMENT_OFF \
  1642. offsetof(struct cstorm_def_status_block_c, segment)
  1643. #define DEF_XSB_SEGMENT_OFF \
  1644. offsetof(struct xstorm_def_status_block, segment)
  1645. #define DEF_TSB_SEGMENT_OFF \
  1646. offsetof(struct tstorm_def_status_block, segment)
  1647. #define BNX2X_SP_DSB_INDEX \
  1648. (&bp->def_status_blk->sp_sb.\
  1649. index_values[HC_SP_INDEX_ETH_DEF_CONS])
  1650. #define SET_FLAG(value, mask, flag) \
  1651. do {\
  1652. (value) &= ~(mask);\
  1653. (value) |= ((flag) << (mask##_SHIFT));\
  1654. } while (0)
  1655. #define GET_FLAG(value, mask) \
  1656. (((value) & (mask)) >> (mask##_SHIFT))
  1657. #define GET_FIELD(value, fname) \
  1658. (((value) & (fname##_MASK)) >> (fname##_SHIFT))
  1659. #define CAM_IS_INVALID(x) \
  1660. (GET_FLAG(x.flags, \
  1661. MAC_CONFIGURATION_ENTRY_ACTION_TYPE) == \
  1662. (T_ETH_MAC_COMMAND_INVALIDATE))
  1663. /* Number of u32 elements in MC hash array */
  1664. #define MC_HASH_SIZE 8
  1665. #define MC_HASH_OFFSET(bp, i) (BAR_TSTRORM_INTMEM + \
  1666. TSTORM_APPROXIMATE_MATCH_MULTICAST_FILTERING_OFFSET(BP_FUNC(bp)) + i*4)
  1667. #ifndef PXP2_REG_PXP2_INT_STS
  1668. #define PXP2_REG_PXP2_INT_STS PXP2_REG_PXP2_INT_STS_0
  1669. #endif
  1670. #ifndef ETH_MAX_RX_CLIENTS_E2
  1671. #define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
  1672. #endif
  1673. #define BNX2X_VPD_LEN 128
  1674. #define VENDOR_ID_LEN 4
  1675. int bnx2x_close(struct net_device *dev);
  1676. /* Congestion management fairness mode */
  1677. #define CMNG_FNS_NONE 0
  1678. #define CMNG_FNS_MINMAX 1
  1679. #define HC_SEG_ACCESS_DEF 0 /*Driver decision 0-3*/
  1680. #define HC_SEG_ACCESS_ATTN 4
  1681. #define HC_SEG_ACCESS_NORM 0 /*Driver decision 0-1*/
  1682. static const u32 dmae_reg_go_c[] = {
  1683. DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
  1684. DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
  1685. DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
  1686. DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
  1687. };
  1688. void bnx2x_set_ethtool_ops(struct net_device *netdev);
  1689. void bnx2x_notify_link_changed(struct bnx2x *bp);
  1690. #define BNX2X_MF_PROTOCOL(bp) \
  1691. ((bp)->mf_config[BP_VN(bp)] & FUNC_MF_CFG_PROTOCOL_MASK)
  1692. #ifdef BCM_CNIC
  1693. #define BNX2X_IS_MF_PROTOCOL_ISCSI(bp) \
  1694. (BNX2X_MF_PROTOCOL(bp) == FUNC_MF_CFG_PROTOCOL_ISCSI)
  1695. #define IS_MF_ISCSI_SD(bp) (IS_MF_SD(bp) && BNX2X_IS_MF_PROTOCOL_ISCSI(bp))
  1696. #endif
  1697. #endif /* bnx2x.h */