bnx2x.h 77 KB

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