bnx2x.h 78 KB

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