bnx2x.h 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562
  1. /* bnx2x.h: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 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: Ariel Elior <ariel.elior@qlogic.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/pci.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/types.h>
  19. #include <linux/pci_regs.h>
  20. /* compilation time flags */
  21. /* define this to make the driver freeze on error to allow getting debug info
  22. * (you will need to reboot afterwards) */
  23. /* #define BNX2X_STOP_ON_ERROR */
  24. #define DRV_MODULE_VERSION "1.78.19-0"
  25. #define DRV_MODULE_RELDATE "2014/02/10"
  26. #define BNX2X_BC_VER 0x040200
  27. #if defined(CONFIG_DCB)
  28. #define BCM_DCBNL
  29. #endif
  30. #include "bnx2x_hsi.h"
  31. #include "../cnic_if.h"
  32. #define BNX2X_MIN_MSIX_VEC_CNT(bp) ((bp)->min_msix_vec_cnt)
  33. #include <linux/mdio.h>
  34. #include "bnx2x_reg.h"
  35. #include "bnx2x_fw_defs.h"
  36. #include "bnx2x_mfw_req.h"
  37. #include "bnx2x_link.h"
  38. #include "bnx2x_sp.h"
  39. #include "bnx2x_dcb.h"
  40. #include "bnx2x_stats.h"
  41. #include "bnx2x_vfpf.h"
  42. enum bnx2x_int_mode {
  43. BNX2X_INT_MODE_MSIX,
  44. BNX2X_INT_MODE_INTX,
  45. BNX2X_INT_MODE_MSI
  46. };
  47. /* error/debug prints */
  48. #define DRV_MODULE_NAME "bnx2x"
  49. /* for messages that are currently off */
  50. #define BNX2X_MSG_OFF 0x0
  51. #define BNX2X_MSG_MCP 0x0010000 /* was: NETIF_MSG_HW */
  52. #define BNX2X_MSG_STATS 0x0020000 /* was: NETIF_MSG_TIMER */
  53. #define BNX2X_MSG_NVM 0x0040000 /* was: NETIF_MSG_HW */
  54. #define BNX2X_MSG_DMAE 0x0080000 /* was: NETIF_MSG_HW */
  55. #define BNX2X_MSG_SP 0x0100000 /* was: NETIF_MSG_INTR */
  56. #define BNX2X_MSG_FP 0x0200000 /* was: NETIF_MSG_INTR */
  57. #define BNX2X_MSG_IOV 0x0800000
  58. #define BNX2X_MSG_IDLE 0x2000000 /* used for idle check*/
  59. #define BNX2X_MSG_ETHTOOL 0x4000000
  60. #define BNX2X_MSG_DCB 0x8000000
  61. /* regular debug print */
  62. #define DP_INNER(fmt, ...) \
  63. pr_notice("[%s:%d(%s)]" fmt, \
  64. __func__, __LINE__, \
  65. bp->dev ? (bp->dev->name) : "?", \
  66. ##__VA_ARGS__);
  67. #define DP(__mask, fmt, ...) \
  68. do { \
  69. if (unlikely(bp->msg_enable & (__mask))) \
  70. DP_INNER(fmt, ##__VA_ARGS__); \
  71. } while (0)
  72. #define DP_AND(__mask, fmt, ...) \
  73. do { \
  74. if (unlikely((bp->msg_enable & (__mask)) == __mask)) \
  75. DP_INNER(fmt, ##__VA_ARGS__); \
  76. } while (0)
  77. #define DP_CONT(__mask, fmt, ...) \
  78. do { \
  79. if (unlikely(bp->msg_enable & (__mask))) \
  80. pr_cont(fmt, ##__VA_ARGS__); \
  81. } while (0)
  82. /* errors debug print */
  83. #define BNX2X_DBG_ERR(fmt, ...) \
  84. do { \
  85. if (unlikely(netif_msg_probe(bp))) \
  86. pr_err("[%s:%d(%s)]" fmt, \
  87. __func__, __LINE__, \
  88. bp->dev ? (bp->dev->name) : "?", \
  89. ##__VA_ARGS__); \
  90. } while (0)
  91. /* for errors (never masked) */
  92. #define BNX2X_ERR(fmt, ...) \
  93. do { \
  94. pr_err("[%s:%d(%s)]" fmt, \
  95. __func__, __LINE__, \
  96. bp->dev ? (bp->dev->name) : "?", \
  97. ##__VA_ARGS__); \
  98. } while (0)
  99. #define BNX2X_ERROR(fmt, ...) \
  100. pr_err("[%s:%d]" fmt, __func__, __LINE__, ##__VA_ARGS__)
  101. /* before we have a dev->name use dev_info() */
  102. #define BNX2X_DEV_INFO(fmt, ...) \
  103. do { \
  104. if (unlikely(netif_msg_probe(bp))) \
  105. dev_info(&bp->pdev->dev, fmt, ##__VA_ARGS__); \
  106. } while (0)
  107. /* Error handling */
  108. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int);
  109. #ifdef BNX2X_STOP_ON_ERROR
  110. #define bnx2x_panic() \
  111. do { \
  112. bp->panic = 1; \
  113. BNX2X_ERR("driver assert\n"); \
  114. bnx2x_panic_dump(bp, true); \
  115. } while (0)
  116. #else
  117. #define bnx2x_panic() \
  118. do { \
  119. bp->panic = 1; \
  120. BNX2X_ERR("driver assert\n"); \
  121. bnx2x_panic_dump(bp, false); \
  122. } while (0)
  123. #endif
  124. #define bnx2x_mc_addr(ha) ((ha)->addr)
  125. #define bnx2x_uc_addr(ha) ((ha)->addr)
  126. #define U64_LO(x) ((u32)(((u64)(x)) & 0xffffffff))
  127. #define U64_HI(x) ((u32)(((u64)(x)) >> 32))
  128. #define HILO_U64(hi, lo) ((((u64)(hi)) << 32) + (lo))
  129. #define REG_ADDR(bp, offset) ((bp->regview) + (offset))
  130. #define REG_RD(bp, offset) readl(REG_ADDR(bp, offset))
  131. #define REG_RD8(bp, offset) readb(REG_ADDR(bp, offset))
  132. #define REG_RD16(bp, offset) readw(REG_ADDR(bp, offset))
  133. #define REG_WR(bp, offset, val) writel((u32)val, REG_ADDR(bp, offset))
  134. #define REG_WR8(bp, offset, val) writeb((u8)val, REG_ADDR(bp, offset))
  135. #define REG_WR16(bp, offset, val) writew((u16)val, REG_ADDR(bp, offset))
  136. #define REG_RD_IND(bp, offset) bnx2x_reg_rd_ind(bp, offset)
  137. #define REG_WR_IND(bp, offset, val) bnx2x_reg_wr_ind(bp, offset, val)
  138. #define REG_RD_DMAE(bp, offset, valp, len32) \
  139. do { \
  140. bnx2x_read_dmae(bp, offset, len32);\
  141. memcpy(valp, bnx2x_sp(bp, wb_data[0]), (len32) * 4); \
  142. } while (0)
  143. #define REG_WR_DMAE(bp, offset, valp, len32) \
  144. do { \
  145. memcpy(bnx2x_sp(bp, wb_data[0]), valp, (len32) * 4); \
  146. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data), \
  147. offset, len32); \
  148. } while (0)
  149. #define REG_WR_DMAE_LEN(bp, offset, valp, len32) \
  150. REG_WR_DMAE(bp, offset, valp, len32)
  151. #define VIRT_WR_DMAE_LEN(bp, data, addr, len32, le32_swap) \
  152. do { \
  153. memcpy(GUNZIP_BUF(bp), data, (len32) * 4); \
  154. bnx2x_write_big_buf_wb(bp, addr, len32); \
  155. } while (0)
  156. #define SHMEM_ADDR(bp, field) (bp->common.shmem_base + \
  157. offsetof(struct shmem_region, field))
  158. #define SHMEM_RD(bp, field) REG_RD(bp, SHMEM_ADDR(bp, field))
  159. #define SHMEM_WR(bp, field, val) REG_WR(bp, SHMEM_ADDR(bp, field), val)
  160. #define SHMEM2_ADDR(bp, field) (bp->common.shmem2_base + \
  161. offsetof(struct shmem2_region, field))
  162. #define SHMEM2_RD(bp, field) REG_RD(bp, SHMEM2_ADDR(bp, field))
  163. #define SHMEM2_WR(bp, field, val) REG_WR(bp, SHMEM2_ADDR(bp, field), val)
  164. #define MF_CFG_ADDR(bp, field) (bp->common.mf_cfg_base + \
  165. offsetof(struct mf_cfg, field))
  166. #define MF2_CFG_ADDR(bp, field) (bp->common.mf2_cfg_base + \
  167. offsetof(struct mf2_cfg, field))
  168. #define MF_CFG_RD(bp, field) REG_RD(bp, MF_CFG_ADDR(bp, field))
  169. #define MF_CFG_WR(bp, field, val) REG_WR(bp,\
  170. MF_CFG_ADDR(bp, field), (val))
  171. #define MF2_CFG_RD(bp, field) REG_RD(bp, MF2_CFG_ADDR(bp, field))
  172. #define SHMEM2_HAS(bp, field) ((bp)->common.shmem2_base && \
  173. (SHMEM2_RD((bp), size) > \
  174. offsetof(struct shmem2_region, field)))
  175. #define EMAC_RD(bp, reg) REG_RD(bp, emac_base + reg)
  176. #define EMAC_WR(bp, reg, val) REG_WR(bp, emac_base + reg, val)
  177. /* SP SB indices */
  178. /* General SP events - stats query, cfc delete, etc */
  179. #define HC_SP_INDEX_ETH_DEF_CONS 3
  180. /* EQ completions */
  181. #define HC_SP_INDEX_EQ_CONS 7
  182. /* FCoE L2 connection completions */
  183. #define HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS 6
  184. #define HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS 4
  185. /* iSCSI L2 */
  186. #define HC_SP_INDEX_ETH_ISCSI_CQ_CONS 5
  187. #define HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS 1
  188. /* Special clients parameters */
  189. /* SB indices */
  190. /* FCoE L2 */
  191. #define BNX2X_FCOE_L2_RX_INDEX \
  192. (&bp->def_status_blk->sp_sb.\
  193. index_values[HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS])
  194. #define BNX2X_FCOE_L2_TX_INDEX \
  195. (&bp->def_status_blk->sp_sb.\
  196. index_values[HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS])
  197. /**
  198. * CIDs and CLIDs:
  199. * CLIDs below is a CLID for func 0, then the CLID for other
  200. * functions will be calculated by the formula:
  201. *
  202. * FUNC_N_CLID_X = N * NUM_SPECIAL_CLIENTS + FUNC_0_CLID_X
  203. *
  204. */
  205. enum {
  206. BNX2X_ISCSI_ETH_CL_ID_IDX,
  207. BNX2X_FCOE_ETH_CL_ID_IDX,
  208. BNX2X_MAX_CNIC_ETH_CL_ID_IDX,
  209. };
  210. /* use a value high enough to be above all the PFs, which has least significant
  211. * nibble as 8, so when cnic needs to come up with a CID for UIO to use to
  212. * calculate doorbell address according to old doorbell configuration scheme
  213. * (db_msg_sz 1 << 7 * cid + 0x40 DPM offset) it can come up with a valid number
  214. * We must avoid coming up with cid 8 for iscsi since according to this method
  215. * the designated UIO cid will come out 0 and it has a special handling for that
  216. * case which doesn't suit us. Therefore will will cieling to closes cid which
  217. * has least signigifcant nibble 8 and if it is 8 we will move forward to 0x18.
  218. */
  219. #define BNX2X_1st_NON_L2_ETH_CID(bp) (BNX2X_NUM_NON_CNIC_QUEUES(bp) * \
  220. (bp)->max_cos)
  221. /* amount of cids traversed by UIO's DPM addition to doorbell */
  222. #define UIO_DPM 8
  223. /* roundup to DPM offset */
  224. #define UIO_ROUNDUP(bp) (roundup(BNX2X_1st_NON_L2_ETH_CID(bp), \
  225. UIO_DPM))
  226. /* offset to nearest value which has lsb nibble matching DPM */
  227. #define UIO_CID_OFFSET(bp) ((UIO_ROUNDUP(bp) + UIO_DPM) % \
  228. (UIO_DPM * 2))
  229. /* add offset to rounded-up cid to get a value which could be used with UIO */
  230. #define UIO_DPM_ALIGN(bp) (UIO_ROUNDUP(bp) + UIO_CID_OFFSET(bp))
  231. /* but wait - avoid UIO special case for cid 0 */
  232. #define UIO_DPM_CID0_OFFSET(bp) ((UIO_DPM * 2) * \
  233. (UIO_DPM_ALIGN(bp) == UIO_DPM))
  234. /* Properly DPM aligned CID dajusted to cid 0 secal case */
  235. #define BNX2X_CNIC_START_ETH_CID(bp) (UIO_DPM_ALIGN(bp) + \
  236. (UIO_DPM_CID0_OFFSET(bp)))
  237. /* how many cids were wasted - need this value for cid allocation */
  238. #define UIO_CID_PAD(bp) (BNX2X_CNIC_START_ETH_CID(bp) - \
  239. BNX2X_1st_NON_L2_ETH_CID(bp))
  240. /* iSCSI L2 */
  241. #define BNX2X_ISCSI_ETH_CID(bp) (BNX2X_CNIC_START_ETH_CID(bp))
  242. /* FCoE L2 */
  243. #define BNX2X_FCOE_ETH_CID(bp) (BNX2X_CNIC_START_ETH_CID(bp) + 1)
  244. #define CNIC_SUPPORT(bp) ((bp)->cnic_support)
  245. #define CNIC_ENABLED(bp) ((bp)->cnic_enabled)
  246. #define CNIC_LOADED(bp) ((bp)->cnic_loaded)
  247. #define FCOE_INIT(bp) ((bp)->fcoe_init)
  248. #define AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR \
  249. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR
  250. #define SM_RX_ID 0
  251. #define SM_TX_ID 1
  252. /* defines for multiple tx priority indices */
  253. #define FIRST_TX_ONLY_COS_INDEX 1
  254. #define FIRST_TX_COS_INDEX 0
  255. /* rules for calculating the cids of tx-only connections */
  256. #define CID_TO_FP(cid, bp) ((cid) % BNX2X_NUM_NON_CNIC_QUEUES(bp))
  257. #define CID_COS_TO_TX_ONLY_CID(cid, cos, bp) \
  258. (cid + cos * BNX2X_NUM_NON_CNIC_QUEUES(bp))
  259. /* fp index inside class of service range */
  260. #define FP_COS_TO_TXQ(fp, cos, bp) \
  261. ((fp)->index + cos * BNX2X_NUM_NON_CNIC_QUEUES(bp))
  262. /* Indexes for transmission queues array:
  263. * txdata for RSS i CoS j is at location i + (j * num of RSS)
  264. * txdata for FCoE (if exist) is at location max cos * num of RSS
  265. * txdata for FWD (if exist) is one location after FCoE
  266. * txdata for OOO (if exist) is one location after FWD
  267. */
  268. enum {
  269. FCOE_TXQ_IDX_OFFSET,
  270. FWD_TXQ_IDX_OFFSET,
  271. OOO_TXQ_IDX_OFFSET,
  272. };
  273. #define MAX_ETH_TXQ_IDX(bp) (BNX2X_NUM_NON_CNIC_QUEUES(bp) * (bp)->max_cos)
  274. #define FCOE_TXQ_IDX(bp) (MAX_ETH_TXQ_IDX(bp) + FCOE_TXQ_IDX_OFFSET)
  275. /* fast path */
  276. /*
  277. * This driver uses new build_skb() API :
  278. * RX ring buffer contains pointer to kmalloc() data only,
  279. * skb are built only after Hardware filled the frame.
  280. */
  281. struct sw_rx_bd {
  282. u8 *data;
  283. DEFINE_DMA_UNMAP_ADDR(mapping);
  284. };
  285. struct sw_tx_bd {
  286. struct sk_buff *skb;
  287. u16 first_bd;
  288. u8 flags;
  289. /* Set on the first BD descriptor when there is a split BD */
  290. #define BNX2X_TSO_SPLIT_BD (1<<0)
  291. #define BNX2X_HAS_SECOND_PBD (1<<1)
  292. };
  293. struct sw_rx_page {
  294. struct page *page;
  295. DEFINE_DMA_UNMAP_ADDR(mapping);
  296. };
  297. union db_prod {
  298. struct doorbell_set_prod data;
  299. u32 raw;
  300. };
  301. /* dropless fc FW/HW related params */
  302. #define BRB_SIZE(bp) (CHIP_IS_E3(bp) ? 1024 : 512)
  303. #define MAX_AGG_QS(bp) (CHIP_IS_E1(bp) ? \
  304. ETH_MAX_AGGREGATION_QUEUES_E1 :\
  305. ETH_MAX_AGGREGATION_QUEUES_E1H_E2)
  306. #define FW_DROP_LEVEL(bp) (3 + MAX_SPQ_PENDING + MAX_AGG_QS(bp))
  307. #define FW_PREFETCH_CNT 16
  308. #define DROPLESS_FC_HEADROOM 100
  309. /* MC hsi */
  310. #define BCM_PAGE_SHIFT 12
  311. #define BCM_PAGE_SIZE (1 << BCM_PAGE_SHIFT)
  312. #define BCM_PAGE_MASK (~(BCM_PAGE_SIZE - 1))
  313. #define BCM_PAGE_ALIGN(addr) (((addr) + BCM_PAGE_SIZE - 1) & BCM_PAGE_MASK)
  314. #define PAGES_PER_SGE_SHIFT 0
  315. #define PAGES_PER_SGE (1 << PAGES_PER_SGE_SHIFT)
  316. #define SGE_PAGE_SIZE PAGE_SIZE
  317. #define SGE_PAGE_SHIFT PAGE_SHIFT
  318. #define SGE_PAGE_ALIGN(addr) PAGE_ALIGN((typeof(PAGE_SIZE))(addr))
  319. #define SGE_PAGES (SGE_PAGE_SIZE * PAGES_PER_SGE)
  320. #define TPA_AGG_SIZE min_t(u32, (min_t(u32, 8, MAX_SKB_FRAGS) * \
  321. SGE_PAGES), 0xffff)
  322. /* SGE ring related macros */
  323. #define NUM_RX_SGE_PAGES 2
  324. #define RX_SGE_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_sge))
  325. #define NEXT_PAGE_SGE_DESC_CNT 2
  326. #define MAX_RX_SGE_CNT (RX_SGE_CNT - NEXT_PAGE_SGE_DESC_CNT)
  327. /* RX_SGE_CNT is promised to be a power of 2 */
  328. #define RX_SGE_MASK (RX_SGE_CNT - 1)
  329. #define NUM_RX_SGE (RX_SGE_CNT * NUM_RX_SGE_PAGES)
  330. #define MAX_RX_SGE (NUM_RX_SGE - 1)
  331. #define NEXT_SGE_IDX(x) ((((x) & RX_SGE_MASK) == \
  332. (MAX_RX_SGE_CNT - 1)) ? \
  333. (x) + 1 + NEXT_PAGE_SGE_DESC_CNT : \
  334. (x) + 1)
  335. #define RX_SGE(x) ((x) & MAX_RX_SGE)
  336. /*
  337. * Number of required SGEs is the sum of two:
  338. * 1. Number of possible opened aggregations (next packet for
  339. * these aggregations will probably consume SGE immediately)
  340. * 2. Rest of BRB blocks divided by 2 (block will consume new SGE only
  341. * after placement on BD for new TPA aggregation)
  342. *
  343. * Takes into account NEXT_PAGE_SGE_DESC_CNT "next" elements on each page
  344. */
  345. #define NUM_SGE_REQ (MAX_AGG_QS(bp) + \
  346. (BRB_SIZE(bp) - MAX_AGG_QS(bp)) / 2)
  347. #define NUM_SGE_PG_REQ ((NUM_SGE_REQ + MAX_RX_SGE_CNT - 1) / \
  348. MAX_RX_SGE_CNT)
  349. #define SGE_TH_LO(bp) (NUM_SGE_REQ + \
  350. NUM_SGE_PG_REQ * NEXT_PAGE_SGE_DESC_CNT)
  351. #define SGE_TH_HI(bp) (SGE_TH_LO(bp) + DROPLESS_FC_HEADROOM)
  352. /* Manipulate a bit vector defined as an array of u64 */
  353. /* Number of bits in one sge_mask array element */
  354. #define BIT_VEC64_ELEM_SZ 64
  355. #define BIT_VEC64_ELEM_SHIFT 6
  356. #define BIT_VEC64_ELEM_MASK ((u64)BIT_VEC64_ELEM_SZ - 1)
  357. #define __BIT_VEC64_SET_BIT(el, bit) \
  358. do { \
  359. el = ((el) | ((u64)0x1 << (bit))); \
  360. } while (0)
  361. #define __BIT_VEC64_CLEAR_BIT(el, bit) \
  362. do { \
  363. el = ((el) & (~((u64)0x1 << (bit)))); \
  364. } while (0)
  365. #define BIT_VEC64_SET_BIT(vec64, idx) \
  366. __BIT_VEC64_SET_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
  367. (idx) & BIT_VEC64_ELEM_MASK)
  368. #define BIT_VEC64_CLEAR_BIT(vec64, idx) \
  369. __BIT_VEC64_CLEAR_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
  370. (idx) & BIT_VEC64_ELEM_MASK)
  371. #define BIT_VEC64_TEST_BIT(vec64, idx) \
  372. (((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT] >> \
  373. ((idx) & BIT_VEC64_ELEM_MASK)) & 0x1)
  374. /* Creates a bitmask of all ones in less significant bits.
  375. idx - index of the most significant bit in the created mask */
  376. #define BIT_VEC64_ONES_MASK(idx) \
  377. (((u64)0x1 << (((idx) & BIT_VEC64_ELEM_MASK) + 1)) - 1)
  378. #define BIT_VEC64_ELEM_ONE_MASK ((u64)(~0))
  379. /*******************************************************/
  380. /* Number of u64 elements in SGE mask array */
  381. #define RX_SGE_MASK_LEN (NUM_RX_SGE / BIT_VEC64_ELEM_SZ)
  382. #define RX_SGE_MASK_LEN_MASK (RX_SGE_MASK_LEN - 1)
  383. #define NEXT_SGE_MASK_ELEM(el) (((el) + 1) & RX_SGE_MASK_LEN_MASK)
  384. union host_hc_status_block {
  385. /* pointer to fp status block e1x */
  386. struct host_hc_status_block_e1x *e1x_sb;
  387. /* pointer to fp status block e2 */
  388. struct host_hc_status_block_e2 *e2_sb;
  389. };
  390. struct bnx2x_agg_info {
  391. /*
  392. * First aggregation buffer is a data buffer, the following - are pages.
  393. * We will preallocate the data buffer for each aggregation when
  394. * we open the interface and will replace the BD at the consumer
  395. * with this one when we receive the TPA_START CQE in order to
  396. * keep the Rx BD ring consistent.
  397. */
  398. struct sw_rx_bd first_buf;
  399. u8 tpa_state;
  400. #define BNX2X_TPA_START 1
  401. #define BNX2X_TPA_STOP 2
  402. #define BNX2X_TPA_ERROR 3
  403. u8 placement_offset;
  404. u16 parsing_flags;
  405. u16 vlan_tag;
  406. u16 len_on_bd;
  407. u32 rxhash;
  408. enum pkt_hash_types rxhash_type;
  409. u16 gro_size;
  410. u16 full_page;
  411. };
  412. #define Q_STATS_OFFSET32(stat_name) \
  413. (offsetof(struct bnx2x_eth_q_stats, stat_name) / 4)
  414. struct bnx2x_fp_txdata {
  415. struct sw_tx_bd *tx_buf_ring;
  416. union eth_tx_bd_types *tx_desc_ring;
  417. dma_addr_t tx_desc_mapping;
  418. u32 cid;
  419. union db_prod tx_db;
  420. u16 tx_pkt_prod;
  421. u16 tx_pkt_cons;
  422. u16 tx_bd_prod;
  423. u16 tx_bd_cons;
  424. unsigned long tx_pkt;
  425. __le16 *tx_cons_sb;
  426. int txq_index;
  427. struct bnx2x_fastpath *parent_fp;
  428. int tx_ring_size;
  429. };
  430. enum bnx2x_tpa_mode_t {
  431. TPA_MODE_LRO,
  432. TPA_MODE_GRO
  433. };
  434. struct bnx2x_fastpath {
  435. struct bnx2x *bp; /* parent */
  436. struct napi_struct napi;
  437. #ifdef CONFIG_NET_RX_BUSY_POLL
  438. unsigned int state;
  439. #define BNX2X_FP_STATE_IDLE 0
  440. #define BNX2X_FP_STATE_NAPI (1 << 0) /* NAPI owns this FP */
  441. #define BNX2X_FP_STATE_POLL (1 << 1) /* poll owns this FP */
  442. #define BNX2X_FP_STATE_DISABLED (1 << 2)
  443. #define BNX2X_FP_STATE_NAPI_YIELD (1 << 3) /* NAPI yielded this FP */
  444. #define BNX2X_FP_STATE_POLL_YIELD (1 << 4) /* poll yielded this FP */
  445. #define BNX2X_FP_OWNED (BNX2X_FP_STATE_NAPI | BNX2X_FP_STATE_POLL)
  446. #define BNX2X_FP_YIELD (BNX2X_FP_STATE_NAPI_YIELD | BNX2X_FP_STATE_POLL_YIELD)
  447. #define BNX2X_FP_LOCKED (BNX2X_FP_OWNED | BNX2X_FP_STATE_DISABLED)
  448. #define BNX2X_FP_USER_PEND (BNX2X_FP_STATE_POLL | BNX2X_FP_STATE_POLL_YIELD)
  449. /* protect state */
  450. spinlock_t lock;
  451. #endif /* CONFIG_NET_RX_BUSY_POLL */
  452. union host_hc_status_block status_blk;
  453. /* chip independent shortcuts into sb structure */
  454. __le16 *sb_index_values;
  455. __le16 *sb_running_index;
  456. /* chip independent shortcut into rx_prods_offset memory */
  457. u32 ustorm_rx_prods_offset;
  458. u32 rx_buf_size;
  459. u32 rx_frag_size; /* 0 if kmalloced(), or rx_buf_size + NET_SKB_PAD */
  460. dma_addr_t status_blk_mapping;
  461. enum bnx2x_tpa_mode_t mode;
  462. u8 max_cos; /* actual number of active tx coses */
  463. struct bnx2x_fp_txdata *txdata_ptr[BNX2X_MULTI_TX_COS];
  464. struct sw_rx_bd *rx_buf_ring; /* BDs mappings ring */
  465. struct sw_rx_page *rx_page_ring; /* SGE pages mappings ring */
  466. struct eth_rx_bd *rx_desc_ring;
  467. dma_addr_t rx_desc_mapping;
  468. union eth_rx_cqe *rx_comp_ring;
  469. dma_addr_t rx_comp_mapping;
  470. /* SGE ring */
  471. struct eth_rx_sge *rx_sge_ring;
  472. dma_addr_t rx_sge_mapping;
  473. u64 sge_mask[RX_SGE_MASK_LEN];
  474. u32 cid;
  475. __le16 fp_hc_idx;
  476. u8 index; /* number in fp array */
  477. u8 rx_queue; /* index for skb_record */
  478. u8 cl_id; /* eth client id */
  479. u8 cl_qzone_id;
  480. u8 fw_sb_id; /* status block number in FW */
  481. u8 igu_sb_id; /* status block number in HW */
  482. u16 rx_bd_prod;
  483. u16 rx_bd_cons;
  484. u16 rx_comp_prod;
  485. u16 rx_comp_cons;
  486. u16 rx_sge_prod;
  487. /* The last maximal completed SGE */
  488. u16 last_max_sge;
  489. __le16 *rx_cons_sb;
  490. unsigned long rx_pkt,
  491. rx_calls;
  492. /* TPA related */
  493. struct bnx2x_agg_info *tpa_info;
  494. u8 disable_tpa;
  495. #ifdef BNX2X_STOP_ON_ERROR
  496. u64 tpa_queue_used;
  497. #endif
  498. /* The size is calculated using the following:
  499. sizeof name field from netdev structure +
  500. 4 ('-Xx-' string) +
  501. 4 (for the digits and to make it DWORD aligned) */
  502. #define FP_NAME_SIZE (sizeof(((struct net_device *)0)->name) + 8)
  503. char name[FP_NAME_SIZE];
  504. };
  505. #define bnx2x_fp(bp, nr, var) ((bp)->fp[(nr)].var)
  506. #define bnx2x_sp_obj(bp, fp) ((bp)->sp_objs[(fp)->index])
  507. #define bnx2x_fp_stats(bp, fp) (&((bp)->fp_stats[(fp)->index]))
  508. #define bnx2x_fp_qstats(bp, fp) (&((bp)->fp_stats[(fp)->index].eth_q_stats))
  509. #ifdef CONFIG_NET_RX_BUSY_POLL
  510. static inline void bnx2x_fp_init_lock(struct bnx2x_fastpath *fp)
  511. {
  512. spin_lock_init(&fp->lock);
  513. fp->state = BNX2X_FP_STATE_IDLE;
  514. }
  515. /* called from the device poll routine to get ownership of a FP */
  516. static inline bool bnx2x_fp_lock_napi(struct bnx2x_fastpath *fp)
  517. {
  518. bool rc = true;
  519. spin_lock_bh(&fp->lock);
  520. if (fp->state & BNX2X_FP_LOCKED) {
  521. WARN_ON(fp->state & BNX2X_FP_STATE_NAPI);
  522. fp->state |= BNX2X_FP_STATE_NAPI_YIELD;
  523. rc = false;
  524. } else {
  525. /* we don't care if someone yielded */
  526. fp->state = BNX2X_FP_STATE_NAPI;
  527. }
  528. spin_unlock_bh(&fp->lock);
  529. return rc;
  530. }
  531. /* returns true is someone tried to get the FP while napi had it */
  532. static inline bool bnx2x_fp_unlock_napi(struct bnx2x_fastpath *fp)
  533. {
  534. bool rc = false;
  535. spin_lock_bh(&fp->lock);
  536. WARN_ON(fp->state &
  537. (BNX2X_FP_STATE_POLL | BNX2X_FP_STATE_NAPI_YIELD));
  538. if (fp->state & BNX2X_FP_STATE_POLL_YIELD)
  539. rc = true;
  540. /* state ==> idle, unless currently disabled */
  541. fp->state &= BNX2X_FP_STATE_DISABLED;
  542. spin_unlock_bh(&fp->lock);
  543. return rc;
  544. }
  545. /* called from bnx2x_low_latency_poll() */
  546. static inline bool bnx2x_fp_lock_poll(struct bnx2x_fastpath *fp)
  547. {
  548. bool rc = true;
  549. spin_lock_bh(&fp->lock);
  550. if ((fp->state & BNX2X_FP_LOCKED)) {
  551. fp->state |= BNX2X_FP_STATE_POLL_YIELD;
  552. rc = false;
  553. } else {
  554. /* preserve yield marks */
  555. fp->state |= BNX2X_FP_STATE_POLL;
  556. }
  557. spin_unlock_bh(&fp->lock);
  558. return rc;
  559. }
  560. /* returns true if someone tried to get the FP while it was locked */
  561. static inline bool bnx2x_fp_unlock_poll(struct bnx2x_fastpath *fp)
  562. {
  563. bool rc = false;
  564. spin_lock_bh(&fp->lock);
  565. WARN_ON(fp->state & BNX2X_FP_STATE_NAPI);
  566. if (fp->state & BNX2X_FP_STATE_POLL_YIELD)
  567. rc = true;
  568. /* state ==> idle, unless currently disabled */
  569. fp->state &= BNX2X_FP_STATE_DISABLED;
  570. spin_unlock_bh(&fp->lock);
  571. return rc;
  572. }
  573. /* true if a socket is polling, even if it did not get the lock */
  574. static inline bool bnx2x_fp_ll_polling(struct bnx2x_fastpath *fp)
  575. {
  576. WARN_ON(!(fp->state & BNX2X_FP_OWNED));
  577. return fp->state & BNX2X_FP_USER_PEND;
  578. }
  579. /* false if fp is currently owned */
  580. static inline bool bnx2x_fp_ll_disable(struct bnx2x_fastpath *fp)
  581. {
  582. int rc = true;
  583. spin_lock_bh(&fp->lock);
  584. if (fp->state & BNX2X_FP_OWNED)
  585. rc = false;
  586. fp->state |= BNX2X_FP_STATE_DISABLED;
  587. spin_unlock_bh(&fp->lock);
  588. return rc;
  589. }
  590. #else
  591. static inline void bnx2x_fp_init_lock(struct bnx2x_fastpath *fp)
  592. {
  593. }
  594. static inline bool bnx2x_fp_lock_napi(struct bnx2x_fastpath *fp)
  595. {
  596. return true;
  597. }
  598. static inline bool bnx2x_fp_unlock_napi(struct bnx2x_fastpath *fp)
  599. {
  600. return false;
  601. }
  602. static inline bool bnx2x_fp_lock_poll(struct bnx2x_fastpath *fp)
  603. {
  604. return false;
  605. }
  606. static inline bool bnx2x_fp_unlock_poll(struct bnx2x_fastpath *fp)
  607. {
  608. return false;
  609. }
  610. static inline bool bnx2x_fp_ll_polling(struct bnx2x_fastpath *fp)
  611. {
  612. return false;
  613. }
  614. static inline bool bnx2x_fp_ll_disable(struct bnx2x_fastpath *fp)
  615. {
  616. return true;
  617. }
  618. #endif /* CONFIG_NET_RX_BUSY_POLL */
  619. /* Use 2500 as a mini-jumbo MTU for FCoE */
  620. #define BNX2X_FCOE_MINI_JUMBO_MTU 2500
  621. #define FCOE_IDX_OFFSET 0
  622. #define FCOE_IDX(bp) (BNX2X_NUM_NON_CNIC_QUEUES(bp) + \
  623. FCOE_IDX_OFFSET)
  624. #define bnx2x_fcoe_fp(bp) (&bp->fp[FCOE_IDX(bp)])
  625. #define bnx2x_fcoe(bp, var) (bnx2x_fcoe_fp(bp)->var)
  626. #define bnx2x_fcoe_inner_sp_obj(bp) (&bp->sp_objs[FCOE_IDX(bp)])
  627. #define bnx2x_fcoe_sp_obj(bp, var) (bnx2x_fcoe_inner_sp_obj(bp)->var)
  628. #define bnx2x_fcoe_tx(bp, var) (bnx2x_fcoe_fp(bp)-> \
  629. txdata_ptr[FIRST_TX_COS_INDEX] \
  630. ->var)
  631. #define IS_ETH_FP(fp) ((fp)->index < BNX2X_NUM_ETH_QUEUES((fp)->bp))
  632. #define IS_FCOE_FP(fp) ((fp)->index == FCOE_IDX((fp)->bp))
  633. #define IS_FCOE_IDX(idx) ((idx) == FCOE_IDX(bp))
  634. /* MC hsi */
  635. #define MAX_FETCH_BD 13 /* HW max BDs per packet */
  636. #define RX_COPY_THRESH 92
  637. #define NUM_TX_RINGS 16
  638. #define TX_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_tx_bd_types))
  639. #define NEXT_PAGE_TX_DESC_CNT 1
  640. #define MAX_TX_DESC_CNT (TX_DESC_CNT - NEXT_PAGE_TX_DESC_CNT)
  641. #define NUM_TX_BD (TX_DESC_CNT * NUM_TX_RINGS)
  642. #define MAX_TX_BD (NUM_TX_BD - 1)
  643. #define MAX_TX_AVAIL (MAX_TX_DESC_CNT * NUM_TX_RINGS - 2)
  644. #define NEXT_TX_IDX(x) ((((x) & MAX_TX_DESC_CNT) == \
  645. (MAX_TX_DESC_CNT - 1)) ? \
  646. (x) + 1 + NEXT_PAGE_TX_DESC_CNT : \
  647. (x) + 1)
  648. #define TX_BD(x) ((x) & MAX_TX_BD)
  649. #define TX_BD_POFF(x) ((x) & MAX_TX_DESC_CNT)
  650. /* number of NEXT_PAGE descriptors may be required during placement */
  651. #define NEXT_CNT_PER_TX_PKT(bds) \
  652. (((bds) + MAX_TX_DESC_CNT - 1) / \
  653. MAX_TX_DESC_CNT * NEXT_PAGE_TX_DESC_CNT)
  654. /* max BDs per tx packet w/o next_pages:
  655. * START_BD - describes packed
  656. * START_BD(splitted) - includes unpaged data segment for GSO
  657. * PARSING_BD - for TSO and CSUM data
  658. * PARSING_BD2 - for encapsulation data
  659. * Frag BDs - describes pages for frags
  660. */
  661. #define BDS_PER_TX_PKT 4
  662. #define MAX_BDS_PER_TX_PKT (MAX_SKB_FRAGS + BDS_PER_TX_PKT)
  663. /* max BDs per tx packet including next pages */
  664. #define MAX_DESC_PER_TX_PKT (MAX_BDS_PER_TX_PKT + \
  665. NEXT_CNT_PER_TX_PKT(MAX_BDS_PER_TX_PKT))
  666. /* The RX BD ring is special, each bd is 8 bytes but the last one is 16 */
  667. #define NUM_RX_RINGS 8
  668. #define RX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_bd))
  669. #define NEXT_PAGE_RX_DESC_CNT 2
  670. #define MAX_RX_DESC_CNT (RX_DESC_CNT - NEXT_PAGE_RX_DESC_CNT)
  671. #define RX_DESC_MASK (RX_DESC_CNT - 1)
  672. #define NUM_RX_BD (RX_DESC_CNT * NUM_RX_RINGS)
  673. #define MAX_RX_BD (NUM_RX_BD - 1)
  674. #define MAX_RX_AVAIL (MAX_RX_DESC_CNT * NUM_RX_RINGS - 2)
  675. /* dropless fc calculations for BDs
  676. *
  677. * Number of BDs should as number of buffers in BRB:
  678. * Low threshold takes into account NEXT_PAGE_RX_DESC_CNT
  679. * "next" elements on each page
  680. */
  681. #define NUM_BD_REQ BRB_SIZE(bp)
  682. #define NUM_BD_PG_REQ ((NUM_BD_REQ + MAX_RX_DESC_CNT - 1) / \
  683. MAX_RX_DESC_CNT)
  684. #define BD_TH_LO(bp) (NUM_BD_REQ + \
  685. NUM_BD_PG_REQ * NEXT_PAGE_RX_DESC_CNT + \
  686. FW_DROP_LEVEL(bp))
  687. #define BD_TH_HI(bp) (BD_TH_LO(bp) + DROPLESS_FC_HEADROOM)
  688. #define MIN_RX_AVAIL ((bp)->dropless_fc ? BD_TH_HI(bp) + 128 : 128)
  689. #define MIN_RX_SIZE_TPA_HW (CHIP_IS_E1(bp) ? \
  690. ETH_MIN_RX_CQES_WITH_TPA_E1 : \
  691. ETH_MIN_RX_CQES_WITH_TPA_E1H_E2)
  692. #define MIN_RX_SIZE_NONTPA_HW ETH_MIN_RX_CQES_WITHOUT_TPA
  693. #define MIN_RX_SIZE_TPA (max_t(u32, MIN_RX_SIZE_TPA_HW, MIN_RX_AVAIL))
  694. #define MIN_RX_SIZE_NONTPA (max_t(u32, MIN_RX_SIZE_NONTPA_HW,\
  695. MIN_RX_AVAIL))
  696. #define NEXT_RX_IDX(x) ((((x) & RX_DESC_MASK) == \
  697. (MAX_RX_DESC_CNT - 1)) ? \
  698. (x) + 1 + NEXT_PAGE_RX_DESC_CNT : \
  699. (x) + 1)
  700. #define RX_BD(x) ((x) & MAX_RX_BD)
  701. /*
  702. * As long as CQE is X times bigger than BD entry we have to allocate X times
  703. * more pages for CQ ring in order to keep it balanced with BD ring
  704. */
  705. #define CQE_BD_REL (sizeof(union eth_rx_cqe) / sizeof(struct eth_rx_bd))
  706. #define NUM_RCQ_RINGS (NUM_RX_RINGS * CQE_BD_REL)
  707. #define RCQ_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_rx_cqe))
  708. #define NEXT_PAGE_RCQ_DESC_CNT 1
  709. #define MAX_RCQ_DESC_CNT (RCQ_DESC_CNT - NEXT_PAGE_RCQ_DESC_CNT)
  710. #define NUM_RCQ_BD (RCQ_DESC_CNT * NUM_RCQ_RINGS)
  711. #define MAX_RCQ_BD (NUM_RCQ_BD - 1)
  712. #define MAX_RCQ_AVAIL (MAX_RCQ_DESC_CNT * NUM_RCQ_RINGS - 2)
  713. #define NEXT_RCQ_IDX(x) ((((x) & MAX_RCQ_DESC_CNT) == \
  714. (MAX_RCQ_DESC_CNT - 1)) ? \
  715. (x) + 1 + NEXT_PAGE_RCQ_DESC_CNT : \
  716. (x) + 1)
  717. #define RCQ_BD(x) ((x) & MAX_RCQ_BD)
  718. /* dropless fc calculations for RCQs
  719. *
  720. * Number of RCQs should be as number of buffers in BRB:
  721. * Low threshold takes into account NEXT_PAGE_RCQ_DESC_CNT
  722. * "next" elements on each page
  723. */
  724. #define NUM_RCQ_REQ BRB_SIZE(bp)
  725. #define NUM_RCQ_PG_REQ ((NUM_BD_REQ + MAX_RCQ_DESC_CNT - 1) / \
  726. MAX_RCQ_DESC_CNT)
  727. #define RCQ_TH_LO(bp) (NUM_RCQ_REQ + \
  728. NUM_RCQ_PG_REQ * NEXT_PAGE_RCQ_DESC_CNT + \
  729. FW_DROP_LEVEL(bp))
  730. #define RCQ_TH_HI(bp) (RCQ_TH_LO(bp) + DROPLESS_FC_HEADROOM)
  731. /* This is needed for determining of last_max */
  732. #define SUB_S16(a, b) (s16)((s16)(a) - (s16)(b))
  733. #define SUB_S32(a, b) (s32)((s32)(a) - (s32)(b))
  734. #define BNX2X_SWCID_SHIFT 17
  735. #define BNX2X_SWCID_MASK ((0x1 << BNX2X_SWCID_SHIFT) - 1)
  736. /* used on a CID received from the HW */
  737. #define SW_CID(x) (le32_to_cpu(x) & BNX2X_SWCID_MASK)
  738. #define CQE_CMD(x) (le32_to_cpu(x) >> \
  739. COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT)
  740. #define BD_UNMAP_ADDR(bd) HILO_U64(le32_to_cpu((bd)->addr_hi), \
  741. le32_to_cpu((bd)->addr_lo))
  742. #define BD_UNMAP_LEN(bd) (le16_to_cpu((bd)->nbytes))
  743. #define BNX2X_DB_MIN_SHIFT 3 /* 8 bytes */
  744. #define BNX2X_DB_SHIFT 3 /* 8 bytes*/
  745. #if (BNX2X_DB_SHIFT < BNX2X_DB_MIN_SHIFT)
  746. #error "Min DB doorbell stride is 8"
  747. #endif
  748. #define DOORBELL(bp, cid, val) \
  749. do { \
  750. writel((u32)(val), bp->doorbells + (bp->db_size * (cid))); \
  751. } while (0)
  752. /* TX CSUM helpers */
  753. #define SKB_CS_OFF(skb) (offsetof(struct tcphdr, check) - \
  754. skb->csum_offset)
  755. #define SKB_CS(skb) (*(u16 *)(skb_transport_header(skb) + \
  756. skb->csum_offset))
  757. #define pbd_tcp_flags(tcp_hdr) (ntohl(tcp_flag_word(tcp_hdr))>>16 & 0xff)
  758. #define XMIT_PLAIN 0
  759. #define XMIT_CSUM_V4 (1 << 0)
  760. #define XMIT_CSUM_V6 (1 << 1)
  761. #define XMIT_CSUM_TCP (1 << 2)
  762. #define XMIT_GSO_V4 (1 << 3)
  763. #define XMIT_GSO_V6 (1 << 4)
  764. #define XMIT_CSUM_ENC_V4 (1 << 5)
  765. #define XMIT_CSUM_ENC_V6 (1 << 6)
  766. #define XMIT_GSO_ENC_V4 (1 << 7)
  767. #define XMIT_GSO_ENC_V6 (1 << 8)
  768. #define XMIT_CSUM_ENC (XMIT_CSUM_ENC_V4 | XMIT_CSUM_ENC_V6)
  769. #define XMIT_GSO_ENC (XMIT_GSO_ENC_V4 | XMIT_GSO_ENC_V6)
  770. #define XMIT_CSUM (XMIT_CSUM_V4 | XMIT_CSUM_V6 | XMIT_CSUM_ENC)
  771. #define XMIT_GSO (XMIT_GSO_V4 | XMIT_GSO_V6 | XMIT_GSO_ENC)
  772. /* stuff added to make the code fit 80Col */
  773. #define CQE_TYPE(cqe_fp_flags) ((cqe_fp_flags) & ETH_FAST_PATH_RX_CQE_TYPE)
  774. #define CQE_TYPE_START(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_START_AGG)
  775. #define CQE_TYPE_STOP(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_STOP_AGG)
  776. #define CQE_TYPE_SLOW(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_RAMROD)
  777. #define CQE_TYPE_FAST(cqe_type) ((cqe_type) == RX_ETH_CQE_TYPE_ETH_FASTPATH)
  778. #define ETH_RX_ERROR_FALGS ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG
  779. #define BNX2X_PRS_FLAG_OVERETH_IPV4(flags) \
  780. (((le16_to_cpu(flags) & \
  781. PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) >> \
  782. PARSING_FLAGS_OVER_ETHERNET_PROTOCOL_SHIFT) \
  783. == PRS_FLAG_OVERETH_IPV4)
  784. #define BNX2X_RX_SUM_FIX(cqe) \
  785. BNX2X_PRS_FLAG_OVERETH_IPV4(cqe->fast_path_cqe.pars_flags.flags)
  786. #define FP_USB_FUNC_OFF \
  787. offsetof(struct cstorm_status_block_u, func)
  788. #define FP_CSB_FUNC_OFF \
  789. offsetof(struct cstorm_status_block_c, func)
  790. #define HC_INDEX_ETH_RX_CQ_CONS 1
  791. #define HC_INDEX_OOO_TX_CQ_CONS 4
  792. #define HC_INDEX_ETH_TX_CQ_CONS_COS0 5
  793. #define HC_INDEX_ETH_TX_CQ_CONS_COS1 6
  794. #define HC_INDEX_ETH_TX_CQ_CONS_COS2 7
  795. #define HC_INDEX_ETH_FIRST_TX_CQ_CONS HC_INDEX_ETH_TX_CQ_CONS_COS0
  796. #define BNX2X_RX_SB_INDEX \
  797. (&fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS])
  798. #define BNX2X_TX_SB_INDEX_BASE BNX2X_TX_SB_INDEX_COS0
  799. #define BNX2X_TX_SB_INDEX_COS0 \
  800. (&fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0])
  801. /* end of fast path */
  802. /* common */
  803. struct bnx2x_common {
  804. u32 chip_id;
  805. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  806. #define CHIP_ID(bp) (bp->common.chip_id & 0xfffffff0)
  807. #define CHIP_NUM(bp) (bp->common.chip_id >> 16)
  808. #define CHIP_NUM_57710 0x164e
  809. #define CHIP_NUM_57711 0x164f
  810. #define CHIP_NUM_57711E 0x1650
  811. #define CHIP_NUM_57712 0x1662
  812. #define CHIP_NUM_57712_MF 0x1663
  813. #define CHIP_NUM_57712_VF 0x166f
  814. #define CHIP_NUM_57713 0x1651
  815. #define CHIP_NUM_57713E 0x1652
  816. #define CHIP_NUM_57800 0x168a
  817. #define CHIP_NUM_57800_MF 0x16a5
  818. #define CHIP_NUM_57800_VF 0x16a9
  819. #define CHIP_NUM_57810 0x168e
  820. #define CHIP_NUM_57810_MF 0x16ae
  821. #define CHIP_NUM_57810_VF 0x16af
  822. #define CHIP_NUM_57811 0x163d
  823. #define CHIP_NUM_57811_MF 0x163e
  824. #define CHIP_NUM_57811_VF 0x163f
  825. #define CHIP_NUM_57840_OBSOLETE 0x168d
  826. #define CHIP_NUM_57840_MF_OBSOLETE 0x16ab
  827. #define CHIP_NUM_57840_4_10 0x16a1
  828. #define CHIP_NUM_57840_2_20 0x16a2
  829. #define CHIP_NUM_57840_MF 0x16a4
  830. #define CHIP_NUM_57840_VF 0x16ad
  831. #define CHIP_IS_E1(bp) (CHIP_NUM(bp) == CHIP_NUM_57710)
  832. #define CHIP_IS_57711(bp) (CHIP_NUM(bp) == CHIP_NUM_57711)
  833. #define CHIP_IS_57711E(bp) (CHIP_NUM(bp) == CHIP_NUM_57711E)
  834. #define CHIP_IS_57712(bp) (CHIP_NUM(bp) == CHIP_NUM_57712)
  835. #define CHIP_IS_57712_VF(bp) (CHIP_NUM(bp) == CHIP_NUM_57712_VF)
  836. #define CHIP_IS_57712_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57712_MF)
  837. #define CHIP_IS_57800(bp) (CHIP_NUM(bp) == CHIP_NUM_57800)
  838. #define CHIP_IS_57800_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57800_MF)
  839. #define CHIP_IS_57800_VF(bp) (CHIP_NUM(bp) == CHIP_NUM_57800_VF)
  840. #define CHIP_IS_57810(bp) (CHIP_NUM(bp) == CHIP_NUM_57810)
  841. #define CHIP_IS_57810_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57810_MF)
  842. #define CHIP_IS_57810_VF(bp) (CHIP_NUM(bp) == CHIP_NUM_57810_VF)
  843. #define CHIP_IS_57811(bp) (CHIP_NUM(bp) == CHIP_NUM_57811)
  844. #define CHIP_IS_57811_MF(bp) (CHIP_NUM(bp) == CHIP_NUM_57811_MF)
  845. #define CHIP_IS_57811_VF(bp) (CHIP_NUM(bp) == CHIP_NUM_57811_VF)
  846. #define CHIP_IS_57840(bp) \
  847. ((CHIP_NUM(bp) == CHIP_NUM_57840_4_10) || \
  848. (CHIP_NUM(bp) == CHIP_NUM_57840_2_20) || \
  849. (CHIP_NUM(bp) == CHIP_NUM_57840_OBSOLETE))
  850. #define CHIP_IS_57840_MF(bp) ((CHIP_NUM(bp) == CHIP_NUM_57840_MF) || \
  851. (CHIP_NUM(bp) == CHIP_NUM_57840_MF_OBSOLETE))
  852. #define CHIP_IS_57840_VF(bp) (CHIP_NUM(bp) == CHIP_NUM_57840_VF)
  853. #define CHIP_IS_E1H(bp) (CHIP_IS_57711(bp) || \
  854. CHIP_IS_57711E(bp))
  855. #define CHIP_IS_57811xx(bp) (CHIP_IS_57811(bp) || \
  856. CHIP_IS_57811_MF(bp) || \
  857. CHIP_IS_57811_VF(bp))
  858. #define CHIP_IS_E2(bp) (CHIP_IS_57712(bp) || \
  859. CHIP_IS_57712_MF(bp) || \
  860. CHIP_IS_57712_VF(bp))
  861. #define CHIP_IS_E3(bp) (CHIP_IS_57800(bp) || \
  862. CHIP_IS_57800_MF(bp) || \
  863. CHIP_IS_57800_VF(bp) || \
  864. CHIP_IS_57810(bp) || \
  865. CHIP_IS_57810_MF(bp) || \
  866. CHIP_IS_57810_VF(bp) || \
  867. CHIP_IS_57811xx(bp) || \
  868. CHIP_IS_57840(bp) || \
  869. CHIP_IS_57840_MF(bp) || \
  870. CHIP_IS_57840_VF(bp))
  871. #define CHIP_IS_E1x(bp) (CHIP_IS_E1((bp)) || CHIP_IS_E1H((bp)))
  872. #define USES_WARPCORE(bp) (CHIP_IS_E3(bp))
  873. #define IS_E1H_OFFSET (!CHIP_IS_E1(bp))
  874. #define CHIP_REV_SHIFT 12
  875. #define CHIP_REV_MASK (0xF << CHIP_REV_SHIFT)
  876. #define CHIP_REV_VAL(bp) (bp->common.chip_id & CHIP_REV_MASK)
  877. #define CHIP_REV_Ax (0x0 << CHIP_REV_SHIFT)
  878. #define CHIP_REV_Bx (0x1 << CHIP_REV_SHIFT)
  879. /* assume maximum 5 revisions */
  880. #define CHIP_REV_IS_SLOW(bp) (CHIP_REV_VAL(bp) > 0x00005000)
  881. /* Emul versions are A=>0xe, B=>0xc, C=>0xa, D=>8, E=>6 */
  882. #define CHIP_REV_IS_EMUL(bp) ((CHIP_REV_IS_SLOW(bp)) && \
  883. !(CHIP_REV_VAL(bp) & 0x00001000))
  884. /* FPGA versions are A=>0xf, B=>0xd, C=>0xb, D=>9, E=>7 */
  885. #define CHIP_REV_IS_FPGA(bp) ((CHIP_REV_IS_SLOW(bp)) && \
  886. (CHIP_REV_VAL(bp) & 0x00001000))
  887. #define CHIP_TIME(bp) ((CHIP_REV_IS_EMUL(bp)) ? 2000 : \
  888. ((CHIP_REV_IS_FPGA(bp)) ? 200 : 1))
  889. #define CHIP_METAL(bp) (bp->common.chip_id & 0x00000ff0)
  890. #define CHIP_BOND_ID(bp) (bp->common.chip_id & 0x0000000f)
  891. #define CHIP_REV_SIM(bp) (((CHIP_REV_MASK - CHIP_REV_VAL(bp)) >>\
  892. (CHIP_REV_SHIFT + 1)) \
  893. << CHIP_REV_SHIFT)
  894. #define CHIP_REV(bp) (CHIP_REV_IS_SLOW(bp) ? \
  895. CHIP_REV_SIM(bp) :\
  896. CHIP_REV_VAL(bp))
  897. #define CHIP_IS_E3B0(bp) (CHIP_IS_E3(bp) && \
  898. (CHIP_REV(bp) == CHIP_REV_Bx))
  899. #define CHIP_IS_E3A0(bp) (CHIP_IS_E3(bp) && \
  900. (CHIP_REV(bp) == CHIP_REV_Ax))
  901. /* This define is used in two main places:
  902. * 1. In the early stages of nic_load, to know if to configure Parser / Searcher
  903. * to nic-only mode or to offload mode. Offload mode is configured if either the
  904. * chip is E1x (where MIC_MODE register is not applicable), or if cnic already
  905. * registered for this port (which means that the user wants storage services).
  906. * 2. During cnic-related load, to know if offload mode is already configured in
  907. * the HW or needs to be configured.
  908. * Since the transition from nic-mode to offload-mode in HW causes traffic
  909. * corruption, nic-mode is configured only in ports on which storage services
  910. * where never requested.
  911. */
  912. #define CONFIGURE_NIC_MODE(bp) (!CHIP_IS_E1x(bp) && !CNIC_ENABLED(bp))
  913. int flash_size;
  914. #define BNX2X_NVRAM_1MB_SIZE 0x20000 /* 1M bit in bytes */
  915. #define BNX2X_NVRAM_TIMEOUT_COUNT 30000
  916. #define BNX2X_NVRAM_PAGE_SIZE 256
  917. u32 shmem_base;
  918. u32 shmem2_base;
  919. u32 mf_cfg_base;
  920. u32 mf2_cfg_base;
  921. u32 hw_config;
  922. u32 bc_ver;
  923. u8 int_block;
  924. #define INT_BLOCK_HC 0
  925. #define INT_BLOCK_IGU 1
  926. #define INT_BLOCK_MODE_NORMAL 0
  927. #define INT_BLOCK_MODE_BW_COMP 2
  928. #define CHIP_INT_MODE_IS_NBC(bp) \
  929. (!CHIP_IS_E1x(bp) && \
  930. !((bp)->common.int_block & INT_BLOCK_MODE_BW_COMP))
  931. #define CHIP_INT_MODE_IS_BC(bp) (!CHIP_INT_MODE_IS_NBC(bp))
  932. u8 chip_port_mode;
  933. #define CHIP_4_PORT_MODE 0x0
  934. #define CHIP_2_PORT_MODE 0x1
  935. #define CHIP_PORT_MODE_NONE 0x2
  936. #define CHIP_MODE(bp) (bp->common.chip_port_mode)
  937. #define CHIP_MODE_IS_4_PORT(bp) (CHIP_MODE(bp) == CHIP_4_PORT_MODE)
  938. u32 boot_mode;
  939. };
  940. /* IGU MSIX STATISTICS on 57712: 64 for VFs; 4 for PFs; 4 for Attentions */
  941. #define BNX2X_IGU_STAS_MSG_VF_CNT 64
  942. #define BNX2X_IGU_STAS_MSG_PF_CNT 4
  943. #define MAX_IGU_ATTN_ACK_TO 100
  944. /* end of common */
  945. /* port */
  946. struct bnx2x_port {
  947. u32 pmf;
  948. u32 link_config[LINK_CONFIG_SIZE];
  949. u32 supported[LINK_CONFIG_SIZE];
  950. /* link settings - missing defines */
  951. #define SUPPORTED_2500baseX_Full (1 << 15)
  952. u32 advertising[LINK_CONFIG_SIZE];
  953. /* link settings - missing defines */
  954. #define ADVERTISED_2500baseX_Full (1 << 15)
  955. u32 phy_addr;
  956. /* used to synchronize phy accesses */
  957. struct mutex phy_mutex;
  958. u32 port_stx;
  959. struct nig_stats old_nig_stats;
  960. };
  961. /* end of port */
  962. #define STATS_OFFSET32(stat_name) \
  963. (offsetof(struct bnx2x_eth_stats, stat_name) / 4)
  964. /* slow path */
  965. #define BNX2X_MAX_NUM_OF_VFS 64
  966. #define BNX2X_VF_CID_WND 4 /* log num of queues per VF. HW config. */
  967. #define BNX2X_CIDS_PER_VF (1 << BNX2X_VF_CID_WND)
  968. /* We need to reserve doorbell addresses for all VF and queue combinations */
  969. #define BNX2X_VF_CIDS (BNX2X_MAX_NUM_OF_VFS * BNX2X_CIDS_PER_VF)
  970. /* The doorbell is configured to have the same number of CIDs for PFs and for
  971. * VFs. For this reason the PF CID zone is as large as the VF zone.
  972. */
  973. #define BNX2X_FIRST_VF_CID BNX2X_VF_CIDS
  974. #define BNX2X_MAX_NUM_VF_QUEUES 64
  975. #define BNX2X_VF_ID_INVALID 0xFF
  976. /* the number of VF CIDS multiplied by the amount of bytes reserved for each
  977. * cid must not exceed the size of the VF doorbell
  978. */
  979. #define BNX2X_VF_BAR_SIZE 512
  980. #if (BNX2X_VF_BAR_SIZE < BNX2X_CIDS_PER_VF * (1 << BNX2X_DB_SHIFT))
  981. #error "VF doorbell bar size is 512"
  982. #endif
  983. /*
  984. * The total number of L2 queues, MSIX vectors and HW contexts (CIDs) is
  985. * control by the number of fast-path status blocks supported by the
  986. * device (HW/FW). Each fast-path status block (FP-SB) aka non-default
  987. * status block represents an independent interrupts context that can
  988. * serve a regular L2 networking queue. However special L2 queues such
  989. * as the FCoE queue do not require a FP-SB and other components like
  990. * the CNIC may consume FP-SB reducing the number of possible L2 queues
  991. *
  992. * If the maximum number of FP-SB available is X then:
  993. * a. If CNIC is supported it consumes 1 FP-SB thus the max number of
  994. * regular L2 queues is Y=X-1
  995. * b. In MF mode the actual number of L2 queues is Y= (X-1/MF_factor)
  996. * c. If the FCoE L2 queue is supported the actual number of L2 queues
  997. * is Y+1
  998. * d. The number of irqs (MSIX vectors) is either Y+1 (one extra for
  999. * slow-path interrupts) or Y+2 if CNIC is supported (one additional
  1000. * FP interrupt context for the CNIC).
  1001. * e. The number of HW context (CID count) is always X or X+1 if FCoE
  1002. * L2 queue is supported. The cid for the FCoE L2 queue is always X.
  1003. */
  1004. /* fast-path interrupt contexts E1x */
  1005. #define FP_SB_MAX_E1x 16
  1006. /* fast-path interrupt contexts E2 */
  1007. #define FP_SB_MAX_E2 HC_SB_MAX_SB_E2
  1008. union cdu_context {
  1009. struct eth_context eth;
  1010. char pad[1024];
  1011. };
  1012. /* CDU host DB constants */
  1013. #define CDU_ILT_PAGE_SZ_HW 2
  1014. #define CDU_ILT_PAGE_SZ (8192 << CDU_ILT_PAGE_SZ_HW) /* 32K */
  1015. #define ILT_PAGE_CIDS (CDU_ILT_PAGE_SZ / sizeof(union cdu_context))
  1016. #define CNIC_ISCSI_CID_MAX 256
  1017. #define CNIC_FCOE_CID_MAX 2048
  1018. #define CNIC_CID_MAX (CNIC_ISCSI_CID_MAX + CNIC_FCOE_CID_MAX)
  1019. #define CNIC_ILT_LINES DIV_ROUND_UP(CNIC_CID_MAX, ILT_PAGE_CIDS)
  1020. #define QM_ILT_PAGE_SZ_HW 0
  1021. #define QM_ILT_PAGE_SZ (4096 << QM_ILT_PAGE_SZ_HW) /* 4K */
  1022. #define QM_CID_ROUND 1024
  1023. /* TM (timers) host DB constants */
  1024. #define TM_ILT_PAGE_SZ_HW 0
  1025. #define TM_ILT_PAGE_SZ (4096 << TM_ILT_PAGE_SZ_HW) /* 4K */
  1026. #define TM_CONN_NUM (BNX2X_FIRST_VF_CID + \
  1027. BNX2X_VF_CIDS + \
  1028. CNIC_ISCSI_CID_MAX)
  1029. #define TM_ILT_SZ (8 * TM_CONN_NUM)
  1030. #define TM_ILT_LINES DIV_ROUND_UP(TM_ILT_SZ, TM_ILT_PAGE_SZ)
  1031. /* SRC (Searcher) host DB constants */
  1032. #define SRC_ILT_PAGE_SZ_HW 0
  1033. #define SRC_ILT_PAGE_SZ (4096 << SRC_ILT_PAGE_SZ_HW) /* 4K */
  1034. #define SRC_HASH_BITS 10
  1035. #define SRC_CONN_NUM (1 << SRC_HASH_BITS) /* 1024 */
  1036. #define SRC_ILT_SZ (sizeof(struct src_ent) * SRC_CONN_NUM)
  1037. #define SRC_T2_SZ SRC_ILT_SZ
  1038. #define SRC_ILT_LINES DIV_ROUND_UP(SRC_ILT_SZ, SRC_ILT_PAGE_SZ)
  1039. #define MAX_DMAE_C 8
  1040. /* DMA memory not used in fastpath */
  1041. struct bnx2x_slowpath {
  1042. union {
  1043. struct mac_configuration_cmd e1x;
  1044. struct eth_classify_rules_ramrod_data e2;
  1045. } mac_rdata;
  1046. union {
  1047. struct tstorm_eth_mac_filter_config e1x;
  1048. struct eth_filter_rules_ramrod_data e2;
  1049. } rx_mode_rdata;
  1050. union {
  1051. struct mac_configuration_cmd e1;
  1052. struct eth_multicast_rules_ramrod_data e2;
  1053. } mcast_rdata;
  1054. struct eth_rss_update_ramrod_data rss_rdata;
  1055. /* Queue State related ramrods are always sent under rtnl_lock */
  1056. union {
  1057. struct client_init_ramrod_data init_data;
  1058. struct client_update_ramrod_data update_data;
  1059. struct tpa_update_ramrod_data tpa_data;
  1060. } q_rdata;
  1061. union {
  1062. struct function_start_data func_start;
  1063. /* pfc configuration for DCBX ramrod */
  1064. struct flow_control_configuration pfc_config;
  1065. } func_rdata;
  1066. /* afex ramrod can not be a part of func_rdata union because these
  1067. * events might arrive in parallel to other events from func_rdata.
  1068. * Therefore, if they would have been defined in the same union,
  1069. * data can get corrupted.
  1070. */
  1071. union {
  1072. struct afex_vif_list_ramrod_data viflist_data;
  1073. struct function_update_data func_update;
  1074. } func_afex_rdata;
  1075. /* used by dmae command executer */
  1076. struct dmae_command dmae[MAX_DMAE_C];
  1077. u32 stats_comp;
  1078. union mac_stats mac_stats;
  1079. struct nig_stats nig_stats;
  1080. struct host_port_stats port_stats;
  1081. struct host_func_stats func_stats;
  1082. u32 wb_comp;
  1083. u32 wb_data[4];
  1084. union drv_info_to_mcp drv_info_to_mcp;
  1085. };
  1086. #define bnx2x_sp(bp, var) (&bp->slowpath->var)
  1087. #define bnx2x_sp_mapping(bp, var) \
  1088. (bp->slowpath_mapping + offsetof(struct bnx2x_slowpath, var))
  1089. /* attn group wiring */
  1090. #define MAX_DYNAMIC_ATTN_GRPS 8
  1091. struct attn_route {
  1092. u32 sig[5];
  1093. };
  1094. struct iro {
  1095. u32 base;
  1096. u16 m1;
  1097. u16 m2;
  1098. u16 m3;
  1099. u16 size;
  1100. };
  1101. struct hw_context {
  1102. union cdu_context *vcxt;
  1103. dma_addr_t cxt_mapping;
  1104. size_t size;
  1105. };
  1106. /* forward */
  1107. struct bnx2x_ilt;
  1108. struct bnx2x_vfdb;
  1109. enum bnx2x_recovery_state {
  1110. BNX2X_RECOVERY_DONE,
  1111. BNX2X_RECOVERY_INIT,
  1112. BNX2X_RECOVERY_WAIT,
  1113. BNX2X_RECOVERY_FAILED,
  1114. BNX2X_RECOVERY_NIC_LOADING
  1115. };
  1116. /*
  1117. * Event queue (EQ or event ring) MC hsi
  1118. * NUM_EQ_PAGES and EQ_DESC_CNT_PAGE must be power of 2
  1119. */
  1120. #define NUM_EQ_PAGES 1
  1121. #define EQ_DESC_CNT_PAGE (BCM_PAGE_SIZE / sizeof(union event_ring_elem))
  1122. #define EQ_DESC_MAX_PAGE (EQ_DESC_CNT_PAGE - 1)
  1123. #define NUM_EQ_DESC (EQ_DESC_CNT_PAGE * NUM_EQ_PAGES)
  1124. #define EQ_DESC_MASK (NUM_EQ_DESC - 1)
  1125. #define MAX_EQ_AVAIL (EQ_DESC_MAX_PAGE * NUM_EQ_PAGES - 2)
  1126. /* depends on EQ_DESC_CNT_PAGE being a power of 2 */
  1127. #define NEXT_EQ_IDX(x) ((((x) & EQ_DESC_MAX_PAGE) == \
  1128. (EQ_DESC_MAX_PAGE - 1)) ? (x) + 2 : (x) + 1)
  1129. /* depends on the above and on NUM_EQ_PAGES being a power of 2 */
  1130. #define EQ_DESC(x) ((x) & EQ_DESC_MASK)
  1131. #define BNX2X_EQ_INDEX \
  1132. (&bp->def_status_blk->sp_sb.\
  1133. index_values[HC_SP_INDEX_EQ_CONS])
  1134. /* This is a data that will be used to create a link report message.
  1135. * We will keep the data used for the last link report in order
  1136. * to prevent reporting the same link parameters twice.
  1137. */
  1138. struct bnx2x_link_report_data {
  1139. u16 line_speed; /* Effective line speed */
  1140. unsigned long link_report_flags;/* BNX2X_LINK_REPORT_XXX flags */
  1141. };
  1142. enum {
  1143. BNX2X_LINK_REPORT_FD, /* Full DUPLEX */
  1144. BNX2X_LINK_REPORT_LINK_DOWN,
  1145. BNX2X_LINK_REPORT_RX_FC_ON,
  1146. BNX2X_LINK_REPORT_TX_FC_ON,
  1147. };
  1148. enum {
  1149. BNX2X_PORT_QUERY_IDX,
  1150. BNX2X_PF_QUERY_IDX,
  1151. BNX2X_FCOE_QUERY_IDX,
  1152. BNX2X_FIRST_QUEUE_QUERY_IDX,
  1153. };
  1154. struct bnx2x_fw_stats_req {
  1155. struct stats_query_header hdr;
  1156. struct stats_query_entry query[FP_SB_MAX_E1x+
  1157. BNX2X_FIRST_QUEUE_QUERY_IDX];
  1158. };
  1159. struct bnx2x_fw_stats_data {
  1160. struct stats_counter storm_counters;
  1161. struct per_port_stats port;
  1162. struct per_pf_stats pf;
  1163. struct fcoe_statistics_params fcoe;
  1164. struct per_queue_stats queue_stats[1];
  1165. };
  1166. /* Public slow path states */
  1167. enum sp_rtnl_flag {
  1168. BNX2X_SP_RTNL_SETUP_TC,
  1169. BNX2X_SP_RTNL_TX_TIMEOUT,
  1170. BNX2X_SP_RTNL_FAN_FAILURE,
  1171. BNX2X_SP_RTNL_AFEX_F_UPDATE,
  1172. BNX2X_SP_RTNL_ENABLE_SRIOV,
  1173. BNX2X_SP_RTNL_VFPF_MCAST,
  1174. BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  1175. BNX2X_SP_RTNL_RX_MODE,
  1176. BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  1177. BNX2X_SP_RTNL_TX_STOP,
  1178. BNX2X_SP_RTNL_GET_DRV_VERSION,
  1179. };
  1180. enum bnx2x_iov_flag {
  1181. BNX2X_IOV_HANDLE_VF_MSG,
  1182. BNX2X_IOV_HANDLE_FLR,
  1183. };
  1184. struct bnx2x_prev_path_list {
  1185. struct list_head list;
  1186. u8 bus;
  1187. u8 slot;
  1188. u8 path;
  1189. u8 aer;
  1190. u8 undi;
  1191. };
  1192. struct bnx2x_sp_objs {
  1193. /* MACs object */
  1194. struct bnx2x_vlan_mac_obj mac_obj;
  1195. /* Queue State object */
  1196. struct bnx2x_queue_sp_obj q_obj;
  1197. };
  1198. struct bnx2x_fp_stats {
  1199. struct tstorm_per_queue_stats old_tclient;
  1200. struct ustorm_per_queue_stats old_uclient;
  1201. struct xstorm_per_queue_stats old_xclient;
  1202. struct bnx2x_eth_q_stats eth_q_stats;
  1203. struct bnx2x_eth_q_stats_old eth_q_stats_old;
  1204. };
  1205. struct bnx2x {
  1206. /* Fields used in the tx and intr/napi performance paths
  1207. * are grouped together in the beginning of the structure
  1208. */
  1209. struct bnx2x_fastpath *fp;
  1210. struct bnx2x_sp_objs *sp_objs;
  1211. struct bnx2x_fp_stats *fp_stats;
  1212. struct bnx2x_fp_txdata *bnx2x_txq;
  1213. void __iomem *regview;
  1214. void __iomem *doorbells;
  1215. u16 db_size;
  1216. u8 pf_num; /* absolute PF number */
  1217. u8 pfid; /* per-path PF number */
  1218. int base_fw_ndsb; /**/
  1219. #define BP_PATH(bp) (CHIP_IS_E1x(bp) ? 0 : (bp->pf_num & 1))
  1220. #define BP_PORT(bp) (bp->pfid & 1)
  1221. #define BP_FUNC(bp) (bp->pfid)
  1222. #define BP_ABS_FUNC(bp) (bp->pf_num)
  1223. #define BP_VN(bp) ((bp)->pfid >> 1)
  1224. #define BP_MAX_VN_NUM(bp) (CHIP_MODE_IS_4_PORT(bp) ? 2 : 4)
  1225. #define BP_L_ID(bp) (BP_VN(bp) << 2)
  1226. #define BP_FW_MB_IDX_VN(bp, vn) (BP_PORT(bp) +\
  1227. (vn) * ((CHIP_IS_E1x(bp) || (CHIP_MODE_IS_4_PORT(bp))) ? 2 : 1))
  1228. #define BP_FW_MB_IDX(bp) BP_FW_MB_IDX_VN(bp, BP_VN(bp))
  1229. #ifdef CONFIG_BNX2X_SRIOV
  1230. /* protects vf2pf mailbox from simultaneous access */
  1231. struct mutex vf2pf_mutex;
  1232. /* vf pf channel mailbox contains request and response buffers */
  1233. struct bnx2x_vf_mbx_msg *vf2pf_mbox;
  1234. dma_addr_t vf2pf_mbox_mapping;
  1235. /* we set aside a copy of the acquire response */
  1236. struct pfvf_acquire_resp_tlv acquire_resp;
  1237. /* bulletin board for messages from pf to vf */
  1238. union pf_vf_bulletin *pf2vf_bulletin;
  1239. dma_addr_t pf2vf_bulletin_mapping;
  1240. union pf_vf_bulletin shadow_bulletin;
  1241. struct pf_vf_bulletin_content old_bulletin;
  1242. u16 requested_nr_virtfn;
  1243. #endif /* CONFIG_BNX2X_SRIOV */
  1244. struct net_device *dev;
  1245. struct pci_dev *pdev;
  1246. const struct iro *iro_arr;
  1247. #define IRO (bp->iro_arr)
  1248. enum bnx2x_recovery_state recovery_state;
  1249. int is_leader;
  1250. struct msix_entry *msix_table;
  1251. int tx_ring_size;
  1252. /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
  1253. #define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
  1254. #define ETH_MIN_PACKET_SIZE 60
  1255. #define ETH_MAX_PACKET_SIZE 1500
  1256. #define ETH_MAX_JUMBO_PACKET_SIZE 9600
  1257. /* TCP with Timestamp Option (32) + IPv6 (40) */
  1258. #define ETH_MAX_TPA_HEADER_SIZE 72
  1259. /* Max supported alignment is 256 (8 shift)
  1260. * minimal alignment shift 6 is optimal for 57xxx HW performance
  1261. */
  1262. #define BNX2X_RX_ALIGN_SHIFT max(6, min(8, L1_CACHE_SHIFT))
  1263. /* FW uses 2 Cache lines Alignment for start packet and size
  1264. *
  1265. * We assume skb_build() uses sizeof(struct skb_shared_info) bytes
  1266. * at the end of skb->data, to avoid wasting a full cache line.
  1267. * This reduces memory use (skb->truesize).
  1268. */
  1269. #define BNX2X_FW_RX_ALIGN_START (1UL << BNX2X_RX_ALIGN_SHIFT)
  1270. #define BNX2X_FW_RX_ALIGN_END \
  1271. max_t(u64, 1UL << BNX2X_RX_ALIGN_SHIFT, \
  1272. SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
  1273. #define BNX2X_PXP_DRAM_ALIGN (BNX2X_RX_ALIGN_SHIFT - 5)
  1274. struct host_sp_status_block *def_status_blk;
  1275. #define DEF_SB_IGU_ID 16
  1276. #define DEF_SB_ID HC_SP_SB_ID
  1277. __le16 def_idx;
  1278. __le16 def_att_idx;
  1279. u32 attn_state;
  1280. struct attn_route attn_group[MAX_DYNAMIC_ATTN_GRPS];
  1281. /* slow path ring */
  1282. struct eth_spe *spq;
  1283. dma_addr_t spq_mapping;
  1284. u16 spq_prod_idx;
  1285. struct eth_spe *spq_prod_bd;
  1286. struct eth_spe *spq_last_bd;
  1287. __le16 *dsb_sp_prod;
  1288. atomic_t cq_spq_left; /* ETH_XXX ramrods credit */
  1289. /* used to synchronize spq accesses */
  1290. spinlock_t spq_lock;
  1291. /* event queue */
  1292. union event_ring_elem *eq_ring;
  1293. dma_addr_t eq_mapping;
  1294. u16 eq_prod;
  1295. u16 eq_cons;
  1296. __le16 *eq_cons_sb;
  1297. atomic_t eq_spq_left; /* COMMON_XXX ramrods credit */
  1298. /* Counter for marking that there is a STAT_QUERY ramrod pending */
  1299. u16 stats_pending;
  1300. /* Counter for completed statistics ramrods */
  1301. u16 stats_comp;
  1302. /* End of fields used in the performance code paths */
  1303. int panic;
  1304. int msg_enable;
  1305. u32 flags;
  1306. #define PCIX_FLAG (1 << 0)
  1307. #define PCI_32BIT_FLAG (1 << 1)
  1308. #define ONE_PORT_FLAG (1 << 2)
  1309. #define NO_WOL_FLAG (1 << 3)
  1310. #define USING_MSIX_FLAG (1 << 5)
  1311. #define USING_MSI_FLAG (1 << 6)
  1312. #define DISABLE_MSI_FLAG (1 << 7)
  1313. #define TPA_ENABLE_FLAG (1 << 8)
  1314. #define NO_MCP_FLAG (1 << 9)
  1315. #define GRO_ENABLE_FLAG (1 << 10)
  1316. #define MF_FUNC_DIS (1 << 11)
  1317. #define OWN_CNIC_IRQ (1 << 12)
  1318. #define NO_ISCSI_OOO_FLAG (1 << 13)
  1319. #define NO_ISCSI_FLAG (1 << 14)
  1320. #define NO_FCOE_FLAG (1 << 15)
  1321. #define BC_SUPPORTS_PFC_STATS (1 << 17)
  1322. #define TX_SWITCHING (1 << 18)
  1323. #define BC_SUPPORTS_FCOE_FEATURES (1 << 19)
  1324. #define USING_SINGLE_MSIX_FLAG (1 << 20)
  1325. #define BC_SUPPORTS_DCBX_MSG_NON_PMF (1 << 21)
  1326. #define IS_VF_FLAG (1 << 22)
  1327. #define INTERRUPTS_ENABLED_FLAG (1 << 23)
  1328. #define BC_SUPPORTS_RMMOD_CMD (1 << 24)
  1329. #define HAS_PHYS_PORT_ID (1 << 25)
  1330. #define AER_ENABLED (1 << 26)
  1331. #define BP_NOMCP(bp) ((bp)->flags & NO_MCP_FLAG)
  1332. #ifdef CONFIG_BNX2X_SRIOV
  1333. #define IS_VF(bp) ((bp)->flags & IS_VF_FLAG)
  1334. #define IS_PF(bp) (!((bp)->flags & IS_VF_FLAG))
  1335. #else
  1336. #define IS_VF(bp) false
  1337. #define IS_PF(bp) true
  1338. #endif
  1339. #define NO_ISCSI(bp) ((bp)->flags & NO_ISCSI_FLAG)
  1340. #define NO_ISCSI_OOO(bp) ((bp)->flags & NO_ISCSI_OOO_FLAG)
  1341. #define NO_FCOE(bp) ((bp)->flags & NO_FCOE_FLAG)
  1342. u8 cnic_support;
  1343. bool cnic_enabled;
  1344. bool cnic_loaded;
  1345. struct cnic_eth_dev *(*cnic_probe)(struct net_device *);
  1346. /* Flag that indicates that we can start looking for FCoE L2 queue
  1347. * completions in the default status block.
  1348. */
  1349. bool fcoe_init;
  1350. int mrrs;
  1351. struct delayed_work sp_task;
  1352. struct delayed_work iov_task;
  1353. atomic_t interrupt_occurred;
  1354. struct delayed_work sp_rtnl_task;
  1355. struct delayed_work period_task;
  1356. struct timer_list timer;
  1357. int current_interval;
  1358. u16 fw_seq;
  1359. u16 fw_drv_pulse_wr_seq;
  1360. u32 func_stx;
  1361. struct link_params link_params;
  1362. struct link_vars link_vars;
  1363. u32 link_cnt;
  1364. struct bnx2x_link_report_data last_reported_link;
  1365. struct mdio_if_info mdio;
  1366. struct bnx2x_common common;
  1367. struct bnx2x_port port;
  1368. struct cmng_init cmng;
  1369. u32 mf_config[E1HVN_MAX];
  1370. u32 mf_ext_config;
  1371. u32 path_has_ovlan; /* E3 */
  1372. u16 mf_ov;
  1373. u8 mf_mode;
  1374. #define IS_MF(bp) (bp->mf_mode != 0)
  1375. #define IS_MF_SI(bp) (bp->mf_mode == MULTI_FUNCTION_SI)
  1376. #define IS_MF_SD(bp) (bp->mf_mode == MULTI_FUNCTION_SD)
  1377. #define IS_MF_AFEX(bp) (bp->mf_mode == MULTI_FUNCTION_AFEX)
  1378. u8 wol;
  1379. int rx_ring_size;
  1380. u16 tx_quick_cons_trip_int;
  1381. u16 tx_quick_cons_trip;
  1382. u16 tx_ticks_int;
  1383. u16 tx_ticks;
  1384. u16 rx_quick_cons_trip_int;
  1385. u16 rx_quick_cons_trip;
  1386. u16 rx_ticks_int;
  1387. u16 rx_ticks;
  1388. /* Maximal coalescing timeout in us */
  1389. #define BNX2X_MAX_COALESCE_TOUT (0xff*BNX2X_BTR)
  1390. u32 lin_cnt;
  1391. u16 state;
  1392. #define BNX2X_STATE_CLOSED 0
  1393. #define BNX2X_STATE_OPENING_WAIT4_LOAD 0x1000
  1394. #define BNX2X_STATE_OPENING_WAIT4_PORT 0x2000
  1395. #define BNX2X_STATE_OPEN 0x3000
  1396. #define BNX2X_STATE_CLOSING_WAIT4_HALT 0x4000
  1397. #define BNX2X_STATE_CLOSING_WAIT4_DELETE 0x5000
  1398. #define BNX2X_STATE_DIAG 0xe000
  1399. #define BNX2X_STATE_ERROR 0xf000
  1400. #define BNX2X_MAX_PRIORITY 8
  1401. #define BNX2X_MAX_ENTRIES_PER_PRI 16
  1402. #define BNX2X_MAX_COS 3
  1403. #define BNX2X_MAX_TX_COS 2
  1404. int num_queues;
  1405. uint num_ethernet_queues;
  1406. uint num_cnic_queues;
  1407. int num_napi_queues;
  1408. int disable_tpa;
  1409. u32 rx_mode;
  1410. #define BNX2X_RX_MODE_NONE 0
  1411. #define BNX2X_RX_MODE_NORMAL 1
  1412. #define BNX2X_RX_MODE_ALLMULTI 2
  1413. #define BNX2X_RX_MODE_PROMISC 3
  1414. #define BNX2X_MAX_MULTICAST 64
  1415. u8 igu_dsb_id;
  1416. u8 igu_base_sb;
  1417. u8 igu_sb_cnt;
  1418. u8 min_msix_vec_cnt;
  1419. u32 igu_base_addr;
  1420. dma_addr_t def_status_blk_mapping;
  1421. struct bnx2x_slowpath *slowpath;
  1422. dma_addr_t slowpath_mapping;
  1423. /* Mechanism protecting the drv_info_to_mcp */
  1424. struct mutex drv_info_mutex;
  1425. bool drv_info_mng_owner;
  1426. /* Total number of FW statistics requests */
  1427. u8 fw_stats_num;
  1428. /*
  1429. * This is a memory buffer that will contain both statistics
  1430. * ramrod request and data.
  1431. */
  1432. void *fw_stats;
  1433. dma_addr_t fw_stats_mapping;
  1434. /*
  1435. * FW statistics request shortcut (points at the
  1436. * beginning of fw_stats buffer).
  1437. */
  1438. struct bnx2x_fw_stats_req *fw_stats_req;
  1439. dma_addr_t fw_stats_req_mapping;
  1440. int fw_stats_req_sz;
  1441. /*
  1442. * FW statistics data shortcut (points at the beginning of
  1443. * fw_stats buffer + fw_stats_req_sz).
  1444. */
  1445. struct bnx2x_fw_stats_data *fw_stats_data;
  1446. dma_addr_t fw_stats_data_mapping;
  1447. int fw_stats_data_sz;
  1448. /* For max 1024 cids (VF RSS), 32KB ILT page size and 1KB
  1449. * context size we need 8 ILT entries.
  1450. */
  1451. #define ILT_MAX_L2_LINES 32
  1452. struct hw_context context[ILT_MAX_L2_LINES];
  1453. struct bnx2x_ilt *ilt;
  1454. #define BP_ILT(bp) ((bp)->ilt)
  1455. #define ILT_MAX_LINES 256
  1456. /*
  1457. * Maximum supported number of RSS queues: number of IGU SBs minus one that goes
  1458. * to CNIC.
  1459. */
  1460. #define BNX2X_MAX_RSS_COUNT(bp) ((bp)->igu_sb_cnt - CNIC_SUPPORT(bp))
  1461. /*
  1462. * Maximum CID count that might be required by the bnx2x:
  1463. * Max RSS * Max_Tx_Multi_Cos + FCoE + iSCSI
  1464. */
  1465. #define BNX2X_L2_CID_COUNT(bp) (BNX2X_NUM_ETH_QUEUES(bp) * BNX2X_MULTI_TX_COS \
  1466. + CNIC_SUPPORT(bp) * (2 + UIO_CID_PAD(bp)))
  1467. #define BNX2X_L2_MAX_CID(bp) (BNX2X_MAX_RSS_COUNT(bp) * BNX2X_MULTI_TX_COS \
  1468. + CNIC_SUPPORT(bp) * (2 + UIO_CID_PAD(bp)))
  1469. #define L2_ILT_LINES(bp) (DIV_ROUND_UP(BNX2X_L2_CID_COUNT(bp),\
  1470. ILT_PAGE_CIDS))
  1471. int qm_cid_count;
  1472. bool dropless_fc;
  1473. void *t2;
  1474. dma_addr_t t2_mapping;
  1475. struct cnic_ops __rcu *cnic_ops;
  1476. void *cnic_data;
  1477. u32 cnic_tag;
  1478. struct cnic_eth_dev cnic_eth_dev;
  1479. union host_hc_status_block cnic_sb;
  1480. dma_addr_t cnic_sb_mapping;
  1481. struct eth_spe *cnic_kwq;
  1482. struct eth_spe *cnic_kwq_prod;
  1483. struct eth_spe *cnic_kwq_cons;
  1484. struct eth_spe *cnic_kwq_last;
  1485. u16 cnic_kwq_pending;
  1486. u16 cnic_spq_pending;
  1487. u8 fip_mac[ETH_ALEN];
  1488. struct mutex cnic_mutex;
  1489. struct bnx2x_vlan_mac_obj iscsi_l2_mac_obj;
  1490. /* Start index of the "special" (CNIC related) L2 clients */
  1491. u8 cnic_base_cl_id;
  1492. int dmae_ready;
  1493. /* used to synchronize dmae accesses */
  1494. spinlock_t dmae_lock;
  1495. /* used to protect the FW mail box */
  1496. struct mutex fw_mb_mutex;
  1497. /* used to synchronize stats collecting */
  1498. int stats_state;
  1499. /* used for synchronization of concurrent threads statistics handling */
  1500. spinlock_t stats_lock;
  1501. /* used by dmae command loader */
  1502. struct dmae_command stats_dmae;
  1503. int executer_idx;
  1504. u16 stats_counter;
  1505. struct bnx2x_eth_stats eth_stats;
  1506. struct host_func_stats func_stats;
  1507. struct bnx2x_eth_stats_old eth_stats_old;
  1508. struct bnx2x_net_stats_old net_stats_old;
  1509. struct bnx2x_fw_port_stats_old fw_stats_old;
  1510. bool stats_init;
  1511. struct z_stream_s *strm;
  1512. void *gunzip_buf;
  1513. dma_addr_t gunzip_mapping;
  1514. int gunzip_outlen;
  1515. #define FW_BUF_SIZE 0x8000
  1516. #define GUNZIP_BUF(bp) (bp->gunzip_buf)
  1517. #define GUNZIP_PHYS(bp) (bp->gunzip_mapping)
  1518. #define GUNZIP_OUTLEN(bp) (bp->gunzip_outlen)
  1519. struct raw_op *init_ops;
  1520. /* Init blocks offsets inside init_ops */
  1521. u16 *init_ops_offsets;
  1522. /* Data blob - has 32 bit granularity */
  1523. u32 *init_data;
  1524. u32 init_mode_flags;
  1525. #define INIT_MODE_FLAGS(bp) (bp->init_mode_flags)
  1526. /* Zipped PRAM blobs - raw data */
  1527. const u8 *tsem_int_table_data;
  1528. const u8 *tsem_pram_data;
  1529. const u8 *usem_int_table_data;
  1530. const u8 *usem_pram_data;
  1531. const u8 *xsem_int_table_data;
  1532. const u8 *xsem_pram_data;
  1533. const u8 *csem_int_table_data;
  1534. const u8 *csem_pram_data;
  1535. #define INIT_OPS(bp) (bp->init_ops)
  1536. #define INIT_OPS_OFFSETS(bp) (bp->init_ops_offsets)
  1537. #define INIT_DATA(bp) (bp->init_data)
  1538. #define INIT_TSEM_INT_TABLE_DATA(bp) (bp->tsem_int_table_data)
  1539. #define INIT_TSEM_PRAM_DATA(bp) (bp->tsem_pram_data)
  1540. #define INIT_USEM_INT_TABLE_DATA(bp) (bp->usem_int_table_data)
  1541. #define INIT_USEM_PRAM_DATA(bp) (bp->usem_pram_data)
  1542. #define INIT_XSEM_INT_TABLE_DATA(bp) (bp->xsem_int_table_data)
  1543. #define INIT_XSEM_PRAM_DATA(bp) (bp->xsem_pram_data)
  1544. #define INIT_CSEM_INT_TABLE_DATA(bp) (bp->csem_int_table_data)
  1545. #define INIT_CSEM_PRAM_DATA(bp) (bp->csem_pram_data)
  1546. #define PHY_FW_VER_LEN 20
  1547. char fw_ver[32];
  1548. const struct firmware *firmware;
  1549. struct bnx2x_vfdb *vfdb;
  1550. #define IS_SRIOV(bp) ((bp)->vfdb)
  1551. /* DCB support on/off */
  1552. u16 dcb_state;
  1553. #define BNX2X_DCB_STATE_OFF 0
  1554. #define BNX2X_DCB_STATE_ON 1
  1555. /* DCBX engine mode */
  1556. int dcbx_enabled;
  1557. #define BNX2X_DCBX_ENABLED_OFF 0
  1558. #define BNX2X_DCBX_ENABLED_ON_NEG_OFF 1
  1559. #define BNX2X_DCBX_ENABLED_ON_NEG_ON 2
  1560. #define BNX2X_DCBX_ENABLED_INVALID (-1)
  1561. bool dcbx_mode_uset;
  1562. struct bnx2x_config_dcbx_params dcbx_config_params;
  1563. struct bnx2x_dcbx_port_params dcbx_port_params;
  1564. int dcb_version;
  1565. /* CAM credit pools */
  1566. /* used only in sriov */
  1567. struct bnx2x_credit_pool_obj vlans_pool;
  1568. struct bnx2x_credit_pool_obj macs_pool;
  1569. /* RX_MODE object */
  1570. struct bnx2x_rx_mode_obj rx_mode_obj;
  1571. /* MCAST object */
  1572. struct bnx2x_mcast_obj mcast_obj;
  1573. /* RSS configuration object */
  1574. struct bnx2x_rss_config_obj rss_conf_obj;
  1575. /* Function State controlling object */
  1576. struct bnx2x_func_sp_obj func_obj;
  1577. unsigned long sp_state;
  1578. /* operation indication for the sp_rtnl task */
  1579. unsigned long sp_rtnl_state;
  1580. /* Indication of the IOV tasks */
  1581. unsigned long iov_task_state;
  1582. /* DCBX Negotiation results */
  1583. struct dcbx_features dcbx_local_feat;
  1584. u32 dcbx_error;
  1585. #ifdef BCM_DCBNL
  1586. struct dcbx_features dcbx_remote_feat;
  1587. u32 dcbx_remote_flags;
  1588. #endif
  1589. /* AFEX: store default vlan used */
  1590. int afex_def_vlan_tag;
  1591. enum mf_cfg_afex_vlan_mode afex_vlan_mode;
  1592. u32 pending_max;
  1593. /* multiple tx classes of service */
  1594. u8 max_cos;
  1595. /* priority to cos mapping */
  1596. u8 prio_to_cos[8];
  1597. int fp_array_size;
  1598. u32 dump_preset_idx;
  1599. bool stats_started;
  1600. struct semaphore stats_sema;
  1601. u8 phys_port_id[ETH_ALEN];
  1602. struct bnx2x_link_report_data vf_link_vars;
  1603. };
  1604. /* Tx queues may be less or equal to Rx queues */
  1605. extern int num_queues;
  1606. #define BNX2X_NUM_QUEUES(bp) (bp->num_queues)
  1607. #define BNX2X_NUM_ETH_QUEUES(bp) ((bp)->num_ethernet_queues)
  1608. #define BNX2X_NUM_NON_CNIC_QUEUES(bp) (BNX2X_NUM_QUEUES(bp) - \
  1609. (bp)->num_cnic_queues)
  1610. #define BNX2X_NUM_RX_QUEUES(bp) BNX2X_NUM_QUEUES(bp)
  1611. #define is_multi(bp) (BNX2X_NUM_QUEUES(bp) > 1)
  1612. #define BNX2X_MAX_QUEUES(bp) BNX2X_MAX_RSS_COUNT(bp)
  1613. /* #define is_eth_multi(bp) (BNX2X_NUM_ETH_QUEUES(bp) > 1) */
  1614. #define RSS_IPV4_CAP_MASK \
  1615. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_CAPABILITY
  1616. #define RSS_IPV4_TCP_CAP_MASK \
  1617. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV4_TCP_CAPABILITY
  1618. #define RSS_IPV6_CAP_MASK \
  1619. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_CAPABILITY
  1620. #define RSS_IPV6_TCP_CAP_MASK \
  1621. TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_IPV6_TCP_CAPABILITY
  1622. /* func init flags */
  1623. #define FUNC_FLG_RSS 0x0001
  1624. #define FUNC_FLG_STATS 0x0002
  1625. /* removed FUNC_FLG_UNMATCHED 0x0004 */
  1626. #define FUNC_FLG_TPA 0x0008
  1627. #define FUNC_FLG_SPQ 0x0010
  1628. #define FUNC_FLG_LEADING 0x0020 /* PF only */
  1629. #define FUNC_FLG_LEADING_STATS 0x0040
  1630. struct bnx2x_func_init_params {
  1631. /* dma */
  1632. dma_addr_t fw_stat_map; /* valid iff FUNC_FLG_STATS */
  1633. dma_addr_t spq_map; /* valid iff FUNC_FLG_SPQ */
  1634. u16 func_flgs;
  1635. u16 func_id; /* abs fid */
  1636. u16 pf_id;
  1637. u16 spq_prod; /* valid iff FUNC_FLG_SPQ */
  1638. };
  1639. #define for_each_cnic_queue(bp, var) \
  1640. for ((var) = BNX2X_NUM_ETH_QUEUES(bp); (var) < BNX2X_NUM_QUEUES(bp); \
  1641. (var)++) \
  1642. if (skip_queue(bp, var)) \
  1643. continue; \
  1644. else
  1645. #define for_each_eth_queue(bp, var) \
  1646. for ((var) = 0; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
  1647. #define for_each_nondefault_eth_queue(bp, var) \
  1648. for ((var) = 1; (var) < BNX2X_NUM_ETH_QUEUES(bp); (var)++)
  1649. #define for_each_queue(bp, var) \
  1650. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1651. if (skip_queue(bp, var)) \
  1652. continue; \
  1653. else
  1654. /* Skip forwarding FP */
  1655. #define for_each_valid_rx_queue(bp, var) \
  1656. for ((var) = 0; \
  1657. (var) < (CNIC_LOADED(bp) ? BNX2X_NUM_QUEUES(bp) : \
  1658. BNX2X_NUM_ETH_QUEUES(bp)); \
  1659. (var)++) \
  1660. if (skip_rx_queue(bp, var)) \
  1661. continue; \
  1662. else
  1663. #define for_each_rx_queue_cnic(bp, var) \
  1664. for ((var) = BNX2X_NUM_ETH_QUEUES(bp); (var) < BNX2X_NUM_QUEUES(bp); \
  1665. (var)++) \
  1666. if (skip_rx_queue(bp, var)) \
  1667. continue; \
  1668. else
  1669. #define for_each_rx_queue(bp, var) \
  1670. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1671. if (skip_rx_queue(bp, var)) \
  1672. continue; \
  1673. else
  1674. /* Skip OOO FP */
  1675. #define for_each_valid_tx_queue(bp, var) \
  1676. for ((var) = 0; \
  1677. (var) < (CNIC_LOADED(bp) ? BNX2X_NUM_QUEUES(bp) : \
  1678. BNX2X_NUM_ETH_QUEUES(bp)); \
  1679. (var)++) \
  1680. if (skip_tx_queue(bp, var)) \
  1681. continue; \
  1682. else
  1683. #define for_each_tx_queue_cnic(bp, var) \
  1684. for ((var) = BNX2X_NUM_ETH_QUEUES(bp); (var) < BNX2X_NUM_QUEUES(bp); \
  1685. (var)++) \
  1686. if (skip_tx_queue(bp, var)) \
  1687. continue; \
  1688. else
  1689. #define for_each_tx_queue(bp, var) \
  1690. for ((var) = 0; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1691. if (skip_tx_queue(bp, var)) \
  1692. continue; \
  1693. else
  1694. #define for_each_nondefault_queue(bp, var) \
  1695. for ((var) = 1; (var) < BNX2X_NUM_QUEUES(bp); (var)++) \
  1696. if (skip_queue(bp, var)) \
  1697. continue; \
  1698. else
  1699. #define for_each_cos_in_tx_queue(fp, var) \
  1700. for ((var) = 0; (var) < (fp)->max_cos; (var)++)
  1701. /* skip rx queue
  1702. * if FCOE l2 support is disabled and this is the fcoe L2 queue
  1703. */
  1704. #define skip_rx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1705. /* skip tx queue
  1706. * if FCOE l2 support is disabled and this is the fcoe L2 queue
  1707. */
  1708. #define skip_tx_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1709. #define skip_queue(bp, idx) (NO_FCOE(bp) && IS_FCOE_IDX(idx))
  1710. /**
  1711. * bnx2x_set_mac_one - configure a single MAC address
  1712. *
  1713. * @bp: driver handle
  1714. * @mac: MAC to configure
  1715. * @obj: MAC object handle
  1716. * @set: if 'true' add a new MAC, otherwise - delete
  1717. * @mac_type: the type of the MAC to configure (e.g. ETH, UC list)
  1718. * @ramrod_flags: RAMROD_XXX flags (e.g. RAMROD_CONT, RAMROD_COMP_WAIT)
  1719. *
  1720. * Configures one MAC according to provided parameters or continues the
  1721. * execution of previously scheduled commands if RAMROD_CONT is set in
  1722. * ramrod_flags.
  1723. *
  1724. * Returns zero if operation has successfully completed, a positive value if the
  1725. * operation has been successfully scheduled and a negative - if a requested
  1726. * operations has failed.
  1727. */
  1728. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  1729. struct bnx2x_vlan_mac_obj *obj, bool set,
  1730. int mac_type, unsigned long *ramrod_flags);
  1731. /**
  1732. * bnx2x_del_all_macs - delete all MACs configured for the specific MAC object
  1733. *
  1734. * @bp: driver handle
  1735. * @mac_obj: MAC object handle
  1736. * @mac_type: type of the MACs to clear (BNX2X_XXX_MAC)
  1737. * @wait_for_comp: if 'true' block until completion
  1738. *
  1739. * Deletes all MACs of the specific type (e.g. ETH, UC list).
  1740. *
  1741. * Returns zero if operation has successfully completed, a positive value if the
  1742. * operation has been successfully scheduled and a negative - if a requested
  1743. * operations has failed.
  1744. */
  1745. int bnx2x_del_all_macs(struct bnx2x *bp,
  1746. struct bnx2x_vlan_mac_obj *mac_obj,
  1747. int mac_type, bool wait_for_comp);
  1748. /* Init Function API */
  1749. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p);
  1750. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  1751. u8 vf_valid, int fw_sb_id, int igu_sb_id);
  1752. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port);
  1753. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
  1754. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode);
  1755. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
  1756. void bnx2x_read_mf_cfg(struct bnx2x *bp);
  1757. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val);
  1758. /* dmae */
  1759. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
  1760. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  1761. u32 len32);
  1762. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx);
  1763. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type);
  1764. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode);
  1765. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  1766. bool with_comp, u8 comp_type);
  1767. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  1768. u8 src_type, u8 dst_type);
  1769. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  1770. u32 *comp);
  1771. /* FLR related routines */
  1772. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp);
  1773. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count);
  1774. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt);
  1775. u8 bnx2x_is_pcie_pending(struct pci_dev *dev);
  1776. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1777. char *msg, u32 poll_cnt);
  1778. void bnx2x_calc_fc_adv(struct bnx2x *bp);
  1779. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  1780. u32 data_hi, u32 data_lo, int cmd_type);
  1781. void bnx2x_update_coalesce(struct bnx2x *bp);
  1782. int bnx2x_get_cur_phy_idx(struct bnx2x *bp);
  1783. bool bnx2x_port_after_undi(struct bnx2x *bp);
  1784. static inline u32 reg_poll(struct bnx2x *bp, u32 reg, u32 expected, int ms,
  1785. int wait)
  1786. {
  1787. u32 val;
  1788. do {
  1789. val = REG_RD(bp, reg);
  1790. if (val == expected)
  1791. break;
  1792. ms -= wait;
  1793. msleep(wait);
  1794. } while (ms > 0);
  1795. return val;
  1796. }
  1797. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id,
  1798. bool is_pf);
  1799. #define BNX2X_ILT_ZALLOC(x, y, size) \
  1800. x = dma_zalloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL)
  1801. #define BNX2X_ILT_FREE(x, y, size) \
  1802. do { \
  1803. if (x) { \
  1804. dma_free_coherent(&bp->pdev->dev, size, x, y); \
  1805. x = NULL; \
  1806. y = 0; \
  1807. } \
  1808. } while (0)
  1809. #define ILOG2(x) (ilog2((x)))
  1810. #define ILT_NUM_PAGE_ENTRIES (3072)
  1811. /* In 57710/11 we use whole table since we have 8 func
  1812. * In 57712 we have only 4 func, but use same size per func, then only half of
  1813. * the table in use
  1814. */
  1815. #define ILT_PER_FUNC (ILT_NUM_PAGE_ENTRIES/8)
  1816. #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
  1817. /*
  1818. * the phys address is shifted right 12 bits and has an added
  1819. * 1=valid bit added to the 53rd bit
  1820. * then since this is a wide register(TM)
  1821. * we split it into two 32 bit writes
  1822. */
  1823. #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
  1824. #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
  1825. /* load/unload mode */
  1826. #define LOAD_NORMAL 0
  1827. #define LOAD_OPEN 1
  1828. #define LOAD_DIAG 2
  1829. #define LOAD_LOOPBACK_EXT 3
  1830. #define UNLOAD_NORMAL 0
  1831. #define UNLOAD_CLOSE 1
  1832. #define UNLOAD_RECOVERY 2
  1833. /* DMAE command defines */
  1834. #define DMAE_TIMEOUT -1
  1835. #define DMAE_PCI_ERROR -2 /* E2 and onward */
  1836. #define DMAE_NOT_RDY -3
  1837. #define DMAE_PCI_ERR_FLAG 0x80000000
  1838. #define DMAE_SRC_PCI 0
  1839. #define DMAE_SRC_GRC 1
  1840. #define DMAE_DST_NONE 0
  1841. #define DMAE_DST_PCI 1
  1842. #define DMAE_DST_GRC 2
  1843. #define DMAE_COMP_PCI 0
  1844. #define DMAE_COMP_GRC 1
  1845. /* E2 and onward - PCI error handling in the completion */
  1846. #define DMAE_COMP_REGULAR 0
  1847. #define DMAE_COM_SET_ERR 1
  1848. #define DMAE_CMD_SRC_PCI (DMAE_SRC_PCI << \
  1849. DMAE_COMMAND_SRC_SHIFT)
  1850. #define DMAE_CMD_SRC_GRC (DMAE_SRC_GRC << \
  1851. DMAE_COMMAND_SRC_SHIFT)
  1852. #define DMAE_CMD_DST_PCI (DMAE_DST_PCI << \
  1853. DMAE_COMMAND_DST_SHIFT)
  1854. #define DMAE_CMD_DST_GRC (DMAE_DST_GRC << \
  1855. DMAE_COMMAND_DST_SHIFT)
  1856. #define DMAE_CMD_C_DST_PCI (DMAE_COMP_PCI << \
  1857. DMAE_COMMAND_C_DST_SHIFT)
  1858. #define DMAE_CMD_C_DST_GRC (DMAE_COMP_GRC << \
  1859. DMAE_COMMAND_C_DST_SHIFT)
  1860. #define DMAE_CMD_C_ENABLE DMAE_COMMAND_C_TYPE_ENABLE
  1861. #define DMAE_CMD_ENDIANITY_NO_SWAP (0 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1862. #define DMAE_CMD_ENDIANITY_B_SWAP (1 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1863. #define DMAE_CMD_ENDIANITY_DW_SWAP (2 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1864. #define DMAE_CMD_ENDIANITY_B_DW_SWAP (3 << DMAE_COMMAND_ENDIANITY_SHIFT)
  1865. #define DMAE_CMD_PORT_0 0
  1866. #define DMAE_CMD_PORT_1 DMAE_COMMAND_PORT
  1867. #define DMAE_CMD_SRC_RESET DMAE_COMMAND_SRC_RESET
  1868. #define DMAE_CMD_DST_RESET DMAE_COMMAND_DST_RESET
  1869. #define DMAE_CMD_E1HVN_SHIFT DMAE_COMMAND_E1HVN_SHIFT
  1870. #define DMAE_SRC_PF 0
  1871. #define DMAE_SRC_VF 1
  1872. #define DMAE_DST_PF 0
  1873. #define DMAE_DST_VF 1
  1874. #define DMAE_C_SRC 0
  1875. #define DMAE_C_DST 1
  1876. #define DMAE_LEN32_RD_MAX 0x80
  1877. #define DMAE_LEN32_WR_MAX(bp) (CHIP_IS_E1(bp) ? 0x400 : 0x2000)
  1878. #define DMAE_COMP_VAL 0x60d0d0ae /* E2 and on - upper bit
  1879. * indicates error
  1880. */
  1881. #define MAX_DMAE_C_PER_PORT 8
  1882. #define INIT_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
  1883. BP_VN(bp))
  1884. #define PMF_DMAE_C(bp) (BP_PORT(bp) * MAX_DMAE_C_PER_PORT + \
  1885. E1HVN_MAX)
  1886. /* PCIE link and speed */
  1887. #define PCICFG_LINK_WIDTH 0x1f00000
  1888. #define PCICFG_LINK_WIDTH_SHIFT 20
  1889. #define PCICFG_LINK_SPEED 0xf0000
  1890. #define PCICFG_LINK_SPEED_SHIFT 16
  1891. #define BNX2X_NUM_TESTS_SF 7
  1892. #define BNX2X_NUM_TESTS_MF 3
  1893. #define BNX2X_NUM_TESTS(bp) (IS_MF(bp) ? BNX2X_NUM_TESTS_MF : \
  1894. IS_VF(bp) ? 0 : BNX2X_NUM_TESTS_SF)
  1895. #define BNX2X_PHY_LOOPBACK 0
  1896. #define BNX2X_MAC_LOOPBACK 1
  1897. #define BNX2X_EXT_LOOPBACK 2
  1898. #define BNX2X_PHY_LOOPBACK_FAILED 1
  1899. #define BNX2X_MAC_LOOPBACK_FAILED 2
  1900. #define BNX2X_EXT_LOOPBACK_FAILED 3
  1901. #define BNX2X_LOOPBACK_FAILED (BNX2X_MAC_LOOPBACK_FAILED | \
  1902. BNX2X_PHY_LOOPBACK_FAILED)
  1903. #define STROM_ASSERT_ARRAY_SIZE 50
  1904. /* must be used on a CID before placing it on a HW ring */
  1905. #define HW_CID(bp, x) ((BP_PORT(bp) << 23) | \
  1906. (BP_VN(bp) << BNX2X_SWCID_SHIFT) | \
  1907. (x))
  1908. #define SP_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_spe))
  1909. #define MAX_SP_DESC_CNT (SP_DESC_CNT - 1)
  1910. #define BNX2X_BTR 4
  1911. #define MAX_SPQ_PENDING 8
  1912. /* CMNG constants, as derived from system spec calculations */
  1913. /* default MIN rate in case VNIC min rate is configured to zero - 100Mbps */
  1914. #define DEF_MIN_RATE 100
  1915. /* resolution of the rate shaping timer - 400 usec */
  1916. #define RS_PERIODIC_TIMEOUT_USEC 400
  1917. /* number of bytes in single QM arbitration cycle -
  1918. * coefficient for calculating the fairness timer */
  1919. #define QM_ARB_BYTES 160000
  1920. /* resolution of Min algorithm 1:100 */
  1921. #define MIN_RES 100
  1922. /* how many bytes above threshold for the minimal credit of Min algorithm*/
  1923. #define MIN_ABOVE_THRESH 32768
  1924. /* Fairness algorithm integration time coefficient -
  1925. * for calculating the actual Tfair */
  1926. #define T_FAIR_COEF ((MIN_ABOVE_THRESH + QM_ARB_BYTES) * 8 * MIN_RES)
  1927. /* Memory of fairness algorithm . 2 cycles */
  1928. #define FAIR_MEM 2
  1929. #define ATTN_NIG_FOR_FUNC (1L << 8)
  1930. #define ATTN_SW_TIMER_4_FUNC (1L << 9)
  1931. #define GPIO_2_FUNC (1L << 10)
  1932. #define GPIO_3_FUNC (1L << 11)
  1933. #define GPIO_4_FUNC (1L << 12)
  1934. #define ATTN_GENERAL_ATTN_1 (1L << 13)
  1935. #define ATTN_GENERAL_ATTN_2 (1L << 14)
  1936. #define ATTN_GENERAL_ATTN_3 (1L << 15)
  1937. #define ATTN_GENERAL_ATTN_4 (1L << 13)
  1938. #define ATTN_GENERAL_ATTN_5 (1L << 14)
  1939. #define ATTN_GENERAL_ATTN_6 (1L << 15)
  1940. #define ATTN_HARD_WIRED_MASK 0xff00
  1941. #define ATTENTION_ID 4
  1942. #define IS_MF_STORAGE_ONLY(bp) (IS_MF_STORAGE_SD(bp) || \
  1943. IS_MF_FCOE_AFEX(bp))
  1944. /* stuff added to make the code fit 80Col */
  1945. #define BNX2X_PMF_LINK_ASSERT \
  1946. GENERAL_ATTEN_OFFSET(LINK_SYNC_ATTENTION_BIT_FUNC_0 + BP_FUNC(bp))
  1947. #define BNX2X_MC_ASSERT_BITS \
  1948. (GENERAL_ATTEN_OFFSET(TSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1949. GENERAL_ATTEN_OFFSET(USTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1950. GENERAL_ATTEN_OFFSET(CSTORM_FATAL_ASSERT_ATTENTION_BIT) | \
  1951. GENERAL_ATTEN_OFFSET(XSTORM_FATAL_ASSERT_ATTENTION_BIT))
  1952. #define BNX2X_MCP_ASSERT \
  1953. GENERAL_ATTEN_OFFSET(MCP_FATAL_ASSERT_ATTENTION_BIT)
  1954. #define BNX2X_GRC_TIMEOUT GENERAL_ATTEN_OFFSET(LATCHED_ATTN_TIMEOUT_GRC)
  1955. #define BNX2X_GRC_RSV (GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCR) | \
  1956. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCT) | \
  1957. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCN) | \
  1958. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCU) | \
  1959. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RBCP) | \
  1960. GENERAL_ATTEN_OFFSET(LATCHED_ATTN_RSVD_GRC))
  1961. #define HW_INTERRUT_ASSERT_SET_0 \
  1962. (AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT | \
  1963. AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT | \
  1964. AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT | \
  1965. AEU_INPUTS_ATTN_BITS_BRB_HW_INTERRUPT | \
  1966. AEU_INPUTS_ATTN_BITS_PBCLIENT_HW_INTERRUPT)
  1967. #define HW_PRTY_ASSERT_SET_0 (AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR | \
  1968. AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR | \
  1969. AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR | \
  1970. AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR |\
  1971. AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR |\
  1972. AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR |\
  1973. AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR)
  1974. #define HW_INTERRUT_ASSERT_SET_1 \
  1975. (AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT | \
  1976. AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT | \
  1977. AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT | \
  1978. AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT | \
  1979. AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT | \
  1980. AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT | \
  1981. AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT | \
  1982. AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT | \
  1983. AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT | \
  1984. AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT | \
  1985. AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT)
  1986. #define HW_PRTY_ASSERT_SET_1 (AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR |\
  1987. AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR | \
  1988. AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR |\
  1989. AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR | \
  1990. AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR |\
  1991. AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR | \
  1992. AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR |\
  1993. AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR |\
  1994. AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR |\
  1995. AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR | \
  1996. AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR | \
  1997. AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR |\
  1998. AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR | \
  1999. AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR | \
  2000. AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR |\
  2001. AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR)
  2002. #define HW_INTERRUT_ASSERT_SET_2 \
  2003. (AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT | \
  2004. AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT | \
  2005. AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT | \
  2006. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT |\
  2007. AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT)
  2008. #define HW_PRTY_ASSERT_SET_2 (AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR | \
  2009. AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR | \
  2010. AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR |\
  2011. AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR | \
  2012. AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR | \
  2013. AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR |\
  2014. AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR | \
  2015. AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR)
  2016. #define HW_PRTY_ASSERT_SET_3 (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
  2017. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
  2018. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY | \
  2019. AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
  2020. #define HW_PRTY_ASSERT_SET_4 (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR | \
  2021. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)
  2022. #define MULTI_MASK 0x7f
  2023. #define DEF_USB_FUNC_OFF offsetof(struct cstorm_def_status_block_u, func)
  2024. #define DEF_CSB_FUNC_OFF offsetof(struct cstorm_def_status_block_c, func)
  2025. #define DEF_XSB_FUNC_OFF offsetof(struct xstorm_def_status_block, func)
  2026. #define DEF_TSB_FUNC_OFF offsetof(struct tstorm_def_status_block, func)
  2027. #define DEF_USB_IGU_INDEX_OFF \
  2028. offsetof(struct cstorm_def_status_block_u, igu_index)
  2029. #define DEF_CSB_IGU_INDEX_OFF \
  2030. offsetof(struct cstorm_def_status_block_c, igu_index)
  2031. #define DEF_XSB_IGU_INDEX_OFF \
  2032. offsetof(struct xstorm_def_status_block, igu_index)
  2033. #define DEF_TSB_IGU_INDEX_OFF \
  2034. offsetof(struct tstorm_def_status_block, igu_index)
  2035. #define DEF_USB_SEGMENT_OFF \
  2036. offsetof(struct cstorm_def_status_block_u, segment)
  2037. #define DEF_CSB_SEGMENT_OFF \
  2038. offsetof(struct cstorm_def_status_block_c, segment)
  2039. #define DEF_XSB_SEGMENT_OFF \
  2040. offsetof(struct xstorm_def_status_block, segment)
  2041. #define DEF_TSB_SEGMENT_OFF \
  2042. offsetof(struct tstorm_def_status_block, segment)
  2043. #define BNX2X_SP_DSB_INDEX \
  2044. (&bp->def_status_blk->sp_sb.\
  2045. index_values[HC_SP_INDEX_ETH_DEF_CONS])
  2046. #define CAM_IS_INVALID(x) \
  2047. (GET_FLAG(x.flags, \
  2048. MAC_CONFIGURATION_ENTRY_ACTION_TYPE) == \
  2049. (T_ETH_MAC_COMMAND_INVALIDATE))
  2050. /* Number of u32 elements in MC hash array */
  2051. #define MC_HASH_SIZE 8
  2052. #define MC_HASH_OFFSET(bp, i) (BAR_TSTRORM_INTMEM + \
  2053. TSTORM_APPROXIMATE_MATCH_MULTICAST_FILTERING_OFFSET(BP_FUNC(bp)) + i*4)
  2054. #ifndef PXP2_REG_PXP2_INT_STS
  2055. #define PXP2_REG_PXP2_INT_STS PXP2_REG_PXP2_INT_STS_0
  2056. #endif
  2057. #ifndef ETH_MAX_RX_CLIENTS_E2
  2058. #define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
  2059. #endif
  2060. #define BNX2X_VPD_LEN 128
  2061. #define VENDOR_ID_LEN 4
  2062. #define VF_ACQUIRE_THRESH 3
  2063. #define VF_ACQUIRE_MAC_FILTERS 1
  2064. #define VF_ACQUIRE_MC_FILTERS 10
  2065. #define GOOD_ME_REG(me_reg) (((me_reg) & ME_REG_VF_VALID) && \
  2066. (!((me_reg) & ME_REG_VF_ERR)))
  2067. int bnx2x_compare_fw_ver(struct bnx2x *bp, u32 load_code, bool print_err);
  2068. /* Congestion management fairness mode */
  2069. #define CMNG_FNS_NONE 0
  2070. #define CMNG_FNS_MINMAX 1
  2071. #define HC_SEG_ACCESS_DEF 0 /*Driver decision 0-3*/
  2072. #define HC_SEG_ACCESS_ATTN 4
  2073. #define HC_SEG_ACCESS_NORM 0 /*Driver decision 0-1*/
  2074. static const u32 dmae_reg_go_c[] = {
  2075. DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
  2076. DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
  2077. DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
  2078. DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
  2079. };
  2080. void bnx2x_set_ethtool_ops(struct bnx2x *bp, struct net_device *netdev);
  2081. void bnx2x_notify_link_changed(struct bnx2x *bp);
  2082. #define BNX2X_MF_SD_PROTOCOL(bp) \
  2083. ((bp)->mf_config[BP_VN(bp)] & FUNC_MF_CFG_PROTOCOL_MASK)
  2084. #define BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp) \
  2085. (BNX2X_MF_SD_PROTOCOL(bp) == FUNC_MF_CFG_PROTOCOL_ISCSI)
  2086. #define BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) \
  2087. (BNX2X_MF_SD_PROTOCOL(bp) == FUNC_MF_CFG_PROTOCOL_FCOE)
  2088. #define IS_MF_ISCSI_SD(bp) (IS_MF_SD(bp) && BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp))
  2089. #define IS_MF_FCOE_SD(bp) (IS_MF_SD(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))
  2090. #define BNX2X_MF_EXT_PROTOCOL_FCOE(bp) ((bp)->mf_ext_config & \
  2091. MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
  2092. #define IS_MF_FCOE_AFEX(bp) (IS_MF_AFEX(bp) && BNX2X_MF_EXT_PROTOCOL_FCOE(bp))
  2093. #define IS_MF_STORAGE_SD(bp) (IS_MF_SD(bp) && \
  2094. (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp) || \
  2095. BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
  2096. #define SET_FLAG(value, mask, flag) \
  2097. do {\
  2098. (value) &= ~(mask);\
  2099. (value) |= ((flag) << (mask##_SHIFT));\
  2100. } while (0)
  2101. #define GET_FLAG(value, mask) \
  2102. (((value) & (mask)) >> (mask##_SHIFT))
  2103. #define GET_FIELD(value, fname) \
  2104. (((value) & (fname##_MASK)) >> (fname##_SHIFT))
  2105. enum {
  2106. SWITCH_UPDATE,
  2107. AFEX_UPDATE,
  2108. };
  2109. #define NUM_MACS 8
  2110. void bnx2x_set_local_cmng(struct bnx2x *bp);
  2111. void bnx2x_update_mng_version(struct bnx2x *bp);
  2112. #define MCPR_SCRATCH_BASE(bp) \
  2113. (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  2114. #define E1H_MAX_MF_SB_COUNT (HC_SB_MAX_SB_E1X/(E1HVN_MAX * PORT_MAX))
  2115. #endif /* bnx2x.h */