bnx2x.h 51 KB

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