falcon.c 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2010 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #include <linux/bitops.h>
  11. #include <linux/delay.h>
  12. #include <linux/pci.h>
  13. #include <linux/module.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/i2c.h>
  16. #include <linux/mii.h>
  17. #include <linux/slab.h>
  18. #include "net_driver.h"
  19. #include "bitfield.h"
  20. #include "efx.h"
  21. #include "spi.h"
  22. #include "nic.h"
  23. #include "farch_regs.h"
  24. #include "io.h"
  25. #include "phy.h"
  26. #include "workarounds.h"
  27. #include "selftest.h"
  28. #include "mdio_10g.h"
  29. /* Hardware control for SFC4000 (aka Falcon). */
  30. /**************************************************************************
  31. *
  32. * MAC stats DMA format
  33. *
  34. **************************************************************************
  35. */
  36. #define FALCON_MAC_STATS_SIZE 0x100
  37. #define XgRxOctets_offset 0x0
  38. #define XgRxOctets_WIDTH 48
  39. #define XgRxOctetsOK_offset 0x8
  40. #define XgRxOctetsOK_WIDTH 48
  41. #define XgRxPkts_offset 0x10
  42. #define XgRxPkts_WIDTH 32
  43. #define XgRxPktsOK_offset 0x14
  44. #define XgRxPktsOK_WIDTH 32
  45. #define XgRxBroadcastPkts_offset 0x18
  46. #define XgRxBroadcastPkts_WIDTH 32
  47. #define XgRxMulticastPkts_offset 0x1C
  48. #define XgRxMulticastPkts_WIDTH 32
  49. #define XgRxUnicastPkts_offset 0x20
  50. #define XgRxUnicastPkts_WIDTH 32
  51. #define XgRxUndersizePkts_offset 0x24
  52. #define XgRxUndersizePkts_WIDTH 32
  53. #define XgRxOversizePkts_offset 0x28
  54. #define XgRxOversizePkts_WIDTH 32
  55. #define XgRxJabberPkts_offset 0x2C
  56. #define XgRxJabberPkts_WIDTH 32
  57. #define XgRxUndersizeFCSerrorPkts_offset 0x30
  58. #define XgRxUndersizeFCSerrorPkts_WIDTH 32
  59. #define XgRxDropEvents_offset 0x34
  60. #define XgRxDropEvents_WIDTH 32
  61. #define XgRxFCSerrorPkts_offset 0x38
  62. #define XgRxFCSerrorPkts_WIDTH 32
  63. #define XgRxAlignError_offset 0x3C
  64. #define XgRxAlignError_WIDTH 32
  65. #define XgRxSymbolError_offset 0x40
  66. #define XgRxSymbolError_WIDTH 32
  67. #define XgRxInternalMACError_offset 0x44
  68. #define XgRxInternalMACError_WIDTH 32
  69. #define XgRxControlPkts_offset 0x48
  70. #define XgRxControlPkts_WIDTH 32
  71. #define XgRxPausePkts_offset 0x4C
  72. #define XgRxPausePkts_WIDTH 32
  73. #define XgRxPkts64Octets_offset 0x50
  74. #define XgRxPkts64Octets_WIDTH 32
  75. #define XgRxPkts65to127Octets_offset 0x54
  76. #define XgRxPkts65to127Octets_WIDTH 32
  77. #define XgRxPkts128to255Octets_offset 0x58
  78. #define XgRxPkts128to255Octets_WIDTH 32
  79. #define XgRxPkts256to511Octets_offset 0x5C
  80. #define XgRxPkts256to511Octets_WIDTH 32
  81. #define XgRxPkts512to1023Octets_offset 0x60
  82. #define XgRxPkts512to1023Octets_WIDTH 32
  83. #define XgRxPkts1024to15xxOctets_offset 0x64
  84. #define XgRxPkts1024to15xxOctets_WIDTH 32
  85. #define XgRxPkts15xxtoMaxOctets_offset 0x68
  86. #define XgRxPkts15xxtoMaxOctets_WIDTH 32
  87. #define XgRxLengthError_offset 0x6C
  88. #define XgRxLengthError_WIDTH 32
  89. #define XgTxPkts_offset 0x80
  90. #define XgTxPkts_WIDTH 32
  91. #define XgTxOctets_offset 0x88
  92. #define XgTxOctets_WIDTH 48
  93. #define XgTxMulticastPkts_offset 0x90
  94. #define XgTxMulticastPkts_WIDTH 32
  95. #define XgTxBroadcastPkts_offset 0x94
  96. #define XgTxBroadcastPkts_WIDTH 32
  97. #define XgTxUnicastPkts_offset 0x98
  98. #define XgTxUnicastPkts_WIDTH 32
  99. #define XgTxControlPkts_offset 0x9C
  100. #define XgTxControlPkts_WIDTH 32
  101. #define XgTxPausePkts_offset 0xA0
  102. #define XgTxPausePkts_WIDTH 32
  103. #define XgTxPkts64Octets_offset 0xA4
  104. #define XgTxPkts64Octets_WIDTH 32
  105. #define XgTxPkts65to127Octets_offset 0xA8
  106. #define XgTxPkts65to127Octets_WIDTH 32
  107. #define XgTxPkts128to255Octets_offset 0xAC
  108. #define XgTxPkts128to255Octets_WIDTH 32
  109. #define XgTxPkts256to511Octets_offset 0xB0
  110. #define XgTxPkts256to511Octets_WIDTH 32
  111. #define XgTxPkts512to1023Octets_offset 0xB4
  112. #define XgTxPkts512to1023Octets_WIDTH 32
  113. #define XgTxPkts1024to15xxOctets_offset 0xB8
  114. #define XgTxPkts1024to15xxOctets_WIDTH 32
  115. #define XgTxPkts1519toMaxOctets_offset 0xBC
  116. #define XgTxPkts1519toMaxOctets_WIDTH 32
  117. #define XgTxUndersizePkts_offset 0xC0
  118. #define XgTxUndersizePkts_WIDTH 32
  119. #define XgTxOversizePkts_offset 0xC4
  120. #define XgTxOversizePkts_WIDTH 32
  121. #define XgTxNonTcpUdpPkt_offset 0xC8
  122. #define XgTxNonTcpUdpPkt_WIDTH 16
  123. #define XgTxMacSrcErrPkt_offset 0xCC
  124. #define XgTxMacSrcErrPkt_WIDTH 16
  125. #define XgTxIpSrcErrPkt_offset 0xD0
  126. #define XgTxIpSrcErrPkt_WIDTH 16
  127. #define XgDmaDone_offset 0xD4
  128. #define XgDmaDone_WIDTH 32
  129. #define FALCON_STATS_NOT_DONE 0x00000000
  130. #define FALCON_STATS_DONE 0xffffffff
  131. #define FALCON_STAT_OFFSET(falcon_stat) EFX_VAL(falcon_stat, offset)
  132. #define FALCON_STAT_WIDTH(falcon_stat) EFX_VAL(falcon_stat, WIDTH)
  133. /* Retrieve statistic from statistics block */
  134. #define FALCON_STAT(efx, falcon_stat, efx_stat) do { \
  135. if (FALCON_STAT_WIDTH(falcon_stat) == 16) \
  136. (efx)->mac_stats.efx_stat += le16_to_cpu( \
  137. *((__force __le16 *) \
  138. (efx->stats_buffer.addr + \
  139. FALCON_STAT_OFFSET(falcon_stat)))); \
  140. else if (FALCON_STAT_WIDTH(falcon_stat) == 32) \
  141. (efx)->mac_stats.efx_stat += le32_to_cpu( \
  142. *((__force __le32 *) \
  143. (efx->stats_buffer.addr + \
  144. FALCON_STAT_OFFSET(falcon_stat)))); \
  145. else \
  146. (efx)->mac_stats.efx_stat += le64_to_cpu( \
  147. *((__force __le64 *) \
  148. (efx->stats_buffer.addr + \
  149. FALCON_STAT_OFFSET(falcon_stat)))); \
  150. } while (0)
  151. /**************************************************************************
  152. *
  153. * Non-volatile configuration
  154. *
  155. **************************************************************************
  156. */
  157. /* Board configuration v2 (v1 is obsolete; later versions are compatible) */
  158. struct falcon_nvconfig_board_v2 {
  159. __le16 nports;
  160. u8 port0_phy_addr;
  161. u8 port0_phy_type;
  162. u8 port1_phy_addr;
  163. u8 port1_phy_type;
  164. __le16 asic_sub_revision;
  165. __le16 board_revision;
  166. } __packed;
  167. /* Board configuration v3 extra information */
  168. struct falcon_nvconfig_board_v3 {
  169. __le32 spi_device_type[2];
  170. } __packed;
  171. /* Bit numbers for spi_device_type */
  172. #define SPI_DEV_TYPE_SIZE_LBN 0
  173. #define SPI_DEV_TYPE_SIZE_WIDTH 5
  174. #define SPI_DEV_TYPE_ADDR_LEN_LBN 6
  175. #define SPI_DEV_TYPE_ADDR_LEN_WIDTH 2
  176. #define SPI_DEV_TYPE_ERASE_CMD_LBN 8
  177. #define SPI_DEV_TYPE_ERASE_CMD_WIDTH 8
  178. #define SPI_DEV_TYPE_ERASE_SIZE_LBN 16
  179. #define SPI_DEV_TYPE_ERASE_SIZE_WIDTH 5
  180. #define SPI_DEV_TYPE_BLOCK_SIZE_LBN 24
  181. #define SPI_DEV_TYPE_BLOCK_SIZE_WIDTH 5
  182. #define SPI_DEV_TYPE_FIELD(type, field) \
  183. (((type) >> EFX_LOW_BIT(field)) & EFX_MASK32(EFX_WIDTH(field)))
  184. #define FALCON_NVCONFIG_OFFSET 0x300
  185. #define FALCON_NVCONFIG_BOARD_MAGIC_NUM 0xFA1C
  186. struct falcon_nvconfig {
  187. efx_oword_t ee_vpd_cfg_reg; /* 0x300 */
  188. u8 mac_address[2][8]; /* 0x310 */
  189. efx_oword_t pcie_sd_ctl0123_reg; /* 0x320 */
  190. efx_oword_t pcie_sd_ctl45_reg; /* 0x330 */
  191. efx_oword_t pcie_pcs_ctl_stat_reg; /* 0x340 */
  192. efx_oword_t hw_init_reg; /* 0x350 */
  193. efx_oword_t nic_stat_reg; /* 0x360 */
  194. efx_oword_t glb_ctl_reg; /* 0x370 */
  195. efx_oword_t srm_cfg_reg; /* 0x380 */
  196. efx_oword_t spare_reg; /* 0x390 */
  197. __le16 board_magic_num; /* 0x3A0 */
  198. __le16 board_struct_ver;
  199. __le16 board_checksum;
  200. struct falcon_nvconfig_board_v2 board_v2;
  201. efx_oword_t ee_base_page_reg; /* 0x3B0 */
  202. struct falcon_nvconfig_board_v3 board_v3; /* 0x3C0 */
  203. } __packed;
  204. /*************************************************************************/
  205. static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method);
  206. static void falcon_reconfigure_mac_wrapper(struct efx_nic *efx);
  207. static const unsigned int
  208. /* "Large" EEPROM device: Atmel AT25640 or similar
  209. * 8 KB, 16-bit address, 32 B write block */
  210. large_eeprom_type = ((13 << SPI_DEV_TYPE_SIZE_LBN)
  211. | (2 << SPI_DEV_TYPE_ADDR_LEN_LBN)
  212. | (5 << SPI_DEV_TYPE_BLOCK_SIZE_LBN)),
  213. /* Default flash device: Atmel AT25F1024
  214. * 128 KB, 24-bit address, 32 KB erase block, 256 B write block */
  215. default_flash_type = ((17 << SPI_DEV_TYPE_SIZE_LBN)
  216. | (3 << SPI_DEV_TYPE_ADDR_LEN_LBN)
  217. | (0x52 << SPI_DEV_TYPE_ERASE_CMD_LBN)
  218. | (15 << SPI_DEV_TYPE_ERASE_SIZE_LBN)
  219. | (8 << SPI_DEV_TYPE_BLOCK_SIZE_LBN));
  220. /**************************************************************************
  221. *
  222. * I2C bus - this is a bit-bashing interface using GPIO pins
  223. * Note that it uses the output enables to tristate the outputs
  224. * SDA is the data pin and SCL is the clock
  225. *
  226. **************************************************************************
  227. */
  228. static void falcon_setsda(void *data, int state)
  229. {
  230. struct efx_nic *efx = (struct efx_nic *)data;
  231. efx_oword_t reg;
  232. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  233. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN, !state);
  234. efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
  235. }
  236. static void falcon_setscl(void *data, int state)
  237. {
  238. struct efx_nic *efx = (struct efx_nic *)data;
  239. efx_oword_t reg;
  240. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  241. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO0_OEN, !state);
  242. efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
  243. }
  244. static int falcon_getsda(void *data)
  245. {
  246. struct efx_nic *efx = (struct efx_nic *)data;
  247. efx_oword_t reg;
  248. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  249. return EFX_OWORD_FIELD(reg, FRF_AB_GPIO3_IN);
  250. }
  251. static int falcon_getscl(void *data)
  252. {
  253. struct efx_nic *efx = (struct efx_nic *)data;
  254. efx_oword_t reg;
  255. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  256. return EFX_OWORD_FIELD(reg, FRF_AB_GPIO0_IN);
  257. }
  258. static const struct i2c_algo_bit_data falcon_i2c_bit_operations = {
  259. .setsda = falcon_setsda,
  260. .setscl = falcon_setscl,
  261. .getsda = falcon_getsda,
  262. .getscl = falcon_getscl,
  263. .udelay = 5,
  264. /* Wait up to 50 ms for slave to let us pull SCL high */
  265. .timeout = DIV_ROUND_UP(HZ, 20),
  266. };
  267. static void falcon_push_irq_moderation(struct efx_channel *channel)
  268. {
  269. efx_dword_t timer_cmd;
  270. struct efx_nic *efx = channel->efx;
  271. /* Set timer register */
  272. if (channel->irq_moderation) {
  273. EFX_POPULATE_DWORD_2(timer_cmd,
  274. FRF_AB_TC_TIMER_MODE,
  275. FFE_BB_TIMER_MODE_INT_HLDOFF,
  276. FRF_AB_TC_TIMER_VAL,
  277. channel->irq_moderation - 1);
  278. } else {
  279. EFX_POPULATE_DWORD_2(timer_cmd,
  280. FRF_AB_TC_TIMER_MODE,
  281. FFE_BB_TIMER_MODE_DIS,
  282. FRF_AB_TC_TIMER_VAL, 0);
  283. }
  284. BUILD_BUG_ON(FR_AA_TIMER_COMMAND_KER != FR_BZ_TIMER_COMMAND_P0);
  285. efx_writed_page_locked(efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0,
  286. channel->channel);
  287. }
  288. static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx);
  289. static void falcon_prepare_flush(struct efx_nic *efx)
  290. {
  291. falcon_deconfigure_mac_wrapper(efx);
  292. /* Wait for the tx and rx fifo's to get to the next packet boundary
  293. * (~1ms without back-pressure), then to drain the remainder of the
  294. * fifo's at data path speeds (negligible), with a healthy margin. */
  295. msleep(10);
  296. }
  297. /* Acknowledge a legacy interrupt from Falcon
  298. *
  299. * This acknowledges a legacy (not MSI) interrupt via INT_ACK_KER_REG.
  300. *
  301. * Due to SFC bug 3706 (silicon revision <=A1) reads can be duplicated in the
  302. * BIU. Interrupt acknowledge is read sensitive so must write instead
  303. * (then read to ensure the BIU collector is flushed)
  304. *
  305. * NB most hardware supports MSI interrupts
  306. */
  307. static inline void falcon_irq_ack_a1(struct efx_nic *efx)
  308. {
  309. efx_dword_t reg;
  310. EFX_POPULATE_DWORD_1(reg, FRF_AA_INT_ACK_KER_FIELD, 0xb7eb7e);
  311. efx_writed(efx, &reg, FR_AA_INT_ACK_KER);
  312. efx_readd(efx, &reg, FR_AA_WORK_AROUND_BROKEN_PCI_READS);
  313. }
  314. static irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)
  315. {
  316. struct efx_nic *efx = dev_id;
  317. efx_oword_t *int_ker = efx->irq_status.addr;
  318. int syserr;
  319. int queues;
  320. /* Check to see if this is our interrupt. If it isn't, we
  321. * exit without having touched the hardware.
  322. */
  323. if (unlikely(EFX_OWORD_IS_ZERO(*int_ker))) {
  324. netif_vdbg(efx, intr, efx->net_dev,
  325. "IRQ %d on CPU %d not for me\n", irq,
  326. raw_smp_processor_id());
  327. return IRQ_NONE;
  328. }
  329. efx->last_irq_cpu = raw_smp_processor_id();
  330. netif_vdbg(efx, intr, efx->net_dev,
  331. "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  332. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  333. if (!likely(ACCESS_ONCE(efx->irq_soft_enabled)))
  334. return IRQ_HANDLED;
  335. /* Check to see if we have a serious error condition */
  336. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  337. if (unlikely(syserr))
  338. return efx_farch_fatal_interrupt(efx);
  339. /* Determine interrupting queues, clear interrupt status
  340. * register and acknowledge the device interrupt.
  341. */
  342. BUILD_BUG_ON(FSF_AZ_NET_IVEC_INT_Q_WIDTH > EFX_MAX_CHANNELS);
  343. queues = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_INT_Q);
  344. EFX_ZERO_OWORD(*int_ker);
  345. wmb(); /* Ensure the vector is cleared before interrupt ack */
  346. falcon_irq_ack_a1(efx);
  347. if (queues & 1)
  348. efx_schedule_channel_irq(efx_get_channel(efx, 0));
  349. if (queues & 2)
  350. efx_schedule_channel_irq(efx_get_channel(efx, 1));
  351. return IRQ_HANDLED;
  352. }
  353. /**************************************************************************
  354. *
  355. * EEPROM/flash
  356. *
  357. **************************************************************************
  358. */
  359. #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
  360. static int falcon_spi_poll(struct efx_nic *efx)
  361. {
  362. efx_oword_t reg;
  363. efx_reado(efx, &reg, FR_AB_EE_SPI_HCMD);
  364. return EFX_OWORD_FIELD(reg, FRF_AB_EE_SPI_HCMD_CMD_EN) ? -EBUSY : 0;
  365. }
  366. /* Wait for SPI command completion */
  367. static int falcon_spi_wait(struct efx_nic *efx)
  368. {
  369. /* Most commands will finish quickly, so we start polling at
  370. * very short intervals. Sometimes the command may have to
  371. * wait for VPD or expansion ROM access outside of our
  372. * control, so we allow up to 100 ms. */
  373. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10);
  374. int i;
  375. for (i = 0; i < 10; i++) {
  376. if (!falcon_spi_poll(efx))
  377. return 0;
  378. udelay(10);
  379. }
  380. for (;;) {
  381. if (!falcon_spi_poll(efx))
  382. return 0;
  383. if (time_after_eq(jiffies, timeout)) {
  384. netif_err(efx, hw, efx->net_dev,
  385. "timed out waiting for SPI\n");
  386. return -ETIMEDOUT;
  387. }
  388. schedule_timeout_uninterruptible(1);
  389. }
  390. }
  391. int falcon_spi_cmd(struct efx_nic *efx, const struct efx_spi_device *spi,
  392. unsigned int command, int address,
  393. const void *in, void *out, size_t len)
  394. {
  395. bool addressed = (address >= 0);
  396. bool reading = (out != NULL);
  397. efx_oword_t reg;
  398. int rc;
  399. /* Input validation */
  400. if (len > FALCON_SPI_MAX_LEN)
  401. return -EINVAL;
  402. /* Check that previous command is not still running */
  403. rc = falcon_spi_poll(efx);
  404. if (rc)
  405. return rc;
  406. /* Program address register, if we have an address */
  407. if (addressed) {
  408. EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address);
  409. efx_writeo(efx, &reg, FR_AB_EE_SPI_HADR);
  410. }
  411. /* Program data register, if we have data */
  412. if (in != NULL) {
  413. memcpy(&reg, in, len);
  414. efx_writeo(efx, &reg, FR_AB_EE_SPI_HDATA);
  415. }
  416. /* Issue read/write command */
  417. EFX_POPULATE_OWORD_7(reg,
  418. FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
  419. FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id,
  420. FRF_AB_EE_SPI_HCMD_DABCNT, len,
  421. FRF_AB_EE_SPI_HCMD_READ, reading,
  422. FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
  423. FRF_AB_EE_SPI_HCMD_ADBCNT,
  424. (addressed ? spi->addr_len : 0),
  425. FRF_AB_EE_SPI_HCMD_ENC, command);
  426. efx_writeo(efx, &reg, FR_AB_EE_SPI_HCMD);
  427. /* Wait for read/write to complete */
  428. rc = falcon_spi_wait(efx);
  429. if (rc)
  430. return rc;
  431. /* Read data */
  432. if (out != NULL) {
  433. efx_reado(efx, &reg, FR_AB_EE_SPI_HDATA);
  434. memcpy(out, &reg, len);
  435. }
  436. return 0;
  437. }
  438. static size_t
  439. falcon_spi_write_limit(const struct efx_spi_device *spi, size_t start)
  440. {
  441. return min(FALCON_SPI_MAX_LEN,
  442. (spi->block_size - (start & (spi->block_size - 1))));
  443. }
  444. static inline u8
  445. efx_spi_munge_command(const struct efx_spi_device *spi,
  446. const u8 command, const unsigned int address)
  447. {
  448. return command | (((address >> 8) & spi->munge_address) << 3);
  449. }
  450. /* Wait up to 10 ms for buffered write completion */
  451. int
  452. falcon_spi_wait_write(struct efx_nic *efx, const struct efx_spi_device *spi)
  453. {
  454. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100);
  455. u8 status;
  456. int rc;
  457. for (;;) {
  458. rc = falcon_spi_cmd(efx, spi, SPI_RDSR, -1, NULL,
  459. &status, sizeof(status));
  460. if (rc)
  461. return rc;
  462. if (!(status & SPI_STATUS_NRDY))
  463. return 0;
  464. if (time_after_eq(jiffies, timeout)) {
  465. netif_err(efx, hw, efx->net_dev,
  466. "SPI write timeout on device %d"
  467. " last status=0x%02x\n",
  468. spi->device_id, status);
  469. return -ETIMEDOUT;
  470. }
  471. schedule_timeout_uninterruptible(1);
  472. }
  473. }
  474. int falcon_spi_read(struct efx_nic *efx, const struct efx_spi_device *spi,
  475. loff_t start, size_t len, size_t *retlen, u8 *buffer)
  476. {
  477. size_t block_len, pos = 0;
  478. unsigned int command;
  479. int rc = 0;
  480. while (pos < len) {
  481. block_len = min(len - pos, FALCON_SPI_MAX_LEN);
  482. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  483. rc = falcon_spi_cmd(efx, spi, command, start + pos, NULL,
  484. buffer + pos, block_len);
  485. if (rc)
  486. break;
  487. pos += block_len;
  488. /* Avoid locking up the system */
  489. cond_resched();
  490. if (signal_pending(current)) {
  491. rc = -EINTR;
  492. break;
  493. }
  494. }
  495. if (retlen)
  496. *retlen = pos;
  497. return rc;
  498. }
  499. int
  500. falcon_spi_write(struct efx_nic *efx, const struct efx_spi_device *spi,
  501. loff_t start, size_t len, size_t *retlen, const u8 *buffer)
  502. {
  503. u8 verify_buffer[FALCON_SPI_MAX_LEN];
  504. size_t block_len, pos = 0;
  505. unsigned int command;
  506. int rc = 0;
  507. while (pos < len) {
  508. rc = falcon_spi_cmd(efx, spi, SPI_WREN, -1, NULL, NULL, 0);
  509. if (rc)
  510. break;
  511. block_len = min(len - pos,
  512. falcon_spi_write_limit(spi, start + pos));
  513. command = efx_spi_munge_command(spi, SPI_WRITE, start + pos);
  514. rc = falcon_spi_cmd(efx, spi, command, start + pos,
  515. buffer + pos, NULL, block_len);
  516. if (rc)
  517. break;
  518. rc = falcon_spi_wait_write(efx, spi);
  519. if (rc)
  520. break;
  521. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  522. rc = falcon_spi_cmd(efx, spi, command, start + pos,
  523. NULL, verify_buffer, block_len);
  524. if (memcmp(verify_buffer, buffer + pos, block_len)) {
  525. rc = -EIO;
  526. break;
  527. }
  528. pos += block_len;
  529. /* Avoid locking up the system */
  530. cond_resched();
  531. if (signal_pending(current)) {
  532. rc = -EINTR;
  533. break;
  534. }
  535. }
  536. if (retlen)
  537. *retlen = pos;
  538. return rc;
  539. }
  540. /**************************************************************************
  541. *
  542. * XMAC operations
  543. *
  544. **************************************************************************
  545. */
  546. /* Configure the XAUI driver that is an output from Falcon */
  547. static void falcon_setup_xaui(struct efx_nic *efx)
  548. {
  549. efx_oword_t sdctl, txdrv;
  550. /* Move the XAUI into low power, unless there is no PHY, in
  551. * which case the XAUI will have to drive a cable. */
  552. if (efx->phy_type == PHY_TYPE_NONE)
  553. return;
  554. efx_reado(efx, &sdctl, FR_AB_XX_SD_CTL);
  555. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVD, FFE_AB_XX_SD_CTL_DRV_DEF);
  556. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVD, FFE_AB_XX_SD_CTL_DRV_DEF);
  557. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVC, FFE_AB_XX_SD_CTL_DRV_DEF);
  558. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVC, FFE_AB_XX_SD_CTL_DRV_DEF);
  559. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVB, FFE_AB_XX_SD_CTL_DRV_DEF);
  560. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVB, FFE_AB_XX_SD_CTL_DRV_DEF);
  561. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVA, FFE_AB_XX_SD_CTL_DRV_DEF);
  562. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVA, FFE_AB_XX_SD_CTL_DRV_DEF);
  563. efx_writeo(efx, &sdctl, FR_AB_XX_SD_CTL);
  564. EFX_POPULATE_OWORD_8(txdrv,
  565. FRF_AB_XX_DEQD, FFE_AB_XX_TXDRV_DEQ_DEF,
  566. FRF_AB_XX_DEQC, FFE_AB_XX_TXDRV_DEQ_DEF,
  567. FRF_AB_XX_DEQB, FFE_AB_XX_TXDRV_DEQ_DEF,
  568. FRF_AB_XX_DEQA, FFE_AB_XX_TXDRV_DEQ_DEF,
  569. FRF_AB_XX_DTXD, FFE_AB_XX_TXDRV_DTX_DEF,
  570. FRF_AB_XX_DTXC, FFE_AB_XX_TXDRV_DTX_DEF,
  571. FRF_AB_XX_DTXB, FFE_AB_XX_TXDRV_DTX_DEF,
  572. FRF_AB_XX_DTXA, FFE_AB_XX_TXDRV_DTX_DEF);
  573. efx_writeo(efx, &txdrv, FR_AB_XX_TXDRV_CTL);
  574. }
  575. int falcon_reset_xaui(struct efx_nic *efx)
  576. {
  577. struct falcon_nic_data *nic_data = efx->nic_data;
  578. efx_oword_t reg;
  579. int count;
  580. /* Don't fetch MAC statistics over an XMAC reset */
  581. WARN_ON(nic_data->stats_disable_count == 0);
  582. /* Start reset sequence */
  583. EFX_POPULATE_OWORD_1(reg, FRF_AB_XX_RST_XX_EN, 1);
  584. efx_writeo(efx, &reg, FR_AB_XX_PWR_RST);
  585. /* Wait up to 10 ms for completion, then reinitialise */
  586. for (count = 0; count < 1000; count++) {
  587. efx_reado(efx, &reg, FR_AB_XX_PWR_RST);
  588. if (EFX_OWORD_FIELD(reg, FRF_AB_XX_RST_XX_EN) == 0 &&
  589. EFX_OWORD_FIELD(reg, FRF_AB_XX_SD_RST_ACT) == 0) {
  590. falcon_setup_xaui(efx);
  591. return 0;
  592. }
  593. udelay(10);
  594. }
  595. netif_err(efx, hw, efx->net_dev,
  596. "timed out waiting for XAUI/XGXS reset\n");
  597. return -ETIMEDOUT;
  598. }
  599. static void falcon_ack_status_intr(struct efx_nic *efx)
  600. {
  601. struct falcon_nic_data *nic_data = efx->nic_data;
  602. efx_oword_t reg;
  603. if ((efx_nic_rev(efx) != EFX_REV_FALCON_B0) || LOOPBACK_INTERNAL(efx))
  604. return;
  605. /* We expect xgmii faults if the wireside link is down */
  606. if (!efx->link_state.up)
  607. return;
  608. /* We can only use this interrupt to signal the negative edge of
  609. * xaui_align [we have to poll the positive edge]. */
  610. if (nic_data->xmac_poll_required)
  611. return;
  612. efx_reado(efx, &reg, FR_AB_XM_MGT_INT_MSK);
  613. }
  614. static bool falcon_xgxs_link_ok(struct efx_nic *efx)
  615. {
  616. efx_oword_t reg;
  617. bool align_done, link_ok = false;
  618. int sync_status;
  619. /* Read link status */
  620. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  621. align_done = EFX_OWORD_FIELD(reg, FRF_AB_XX_ALIGN_DONE);
  622. sync_status = EFX_OWORD_FIELD(reg, FRF_AB_XX_SYNC_STAT);
  623. if (align_done && (sync_status == FFE_AB_XX_STAT_ALL_LANES))
  624. link_ok = true;
  625. /* Clear link status ready for next read */
  626. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_COMMA_DET, FFE_AB_XX_STAT_ALL_LANES);
  627. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_CHAR_ERR, FFE_AB_XX_STAT_ALL_LANES);
  628. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_DISPERR, FFE_AB_XX_STAT_ALL_LANES);
  629. efx_writeo(efx, &reg, FR_AB_XX_CORE_STAT);
  630. return link_ok;
  631. }
  632. static bool falcon_xmac_link_ok(struct efx_nic *efx)
  633. {
  634. /*
  635. * Check MAC's XGXS link status except when using XGMII loopback
  636. * which bypasses the XGXS block.
  637. * If possible, check PHY's XGXS link status except when using
  638. * MAC loopback.
  639. */
  640. return (efx->loopback_mode == LOOPBACK_XGMII ||
  641. falcon_xgxs_link_ok(efx)) &&
  642. (!(efx->mdio.mmds & (1 << MDIO_MMD_PHYXS)) ||
  643. LOOPBACK_INTERNAL(efx) ||
  644. efx_mdio_phyxgxs_lane_sync(efx));
  645. }
  646. static void falcon_reconfigure_xmac_core(struct efx_nic *efx)
  647. {
  648. unsigned int max_frame_len;
  649. efx_oword_t reg;
  650. bool rx_fc = !!(efx->link_state.fc & EFX_FC_RX);
  651. bool tx_fc = !!(efx->link_state.fc & EFX_FC_TX);
  652. /* Configure MAC - cut-thru mode is hard wired on */
  653. EFX_POPULATE_OWORD_3(reg,
  654. FRF_AB_XM_RX_JUMBO_MODE, 1,
  655. FRF_AB_XM_TX_STAT_EN, 1,
  656. FRF_AB_XM_RX_STAT_EN, 1);
  657. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  658. /* Configure TX */
  659. EFX_POPULATE_OWORD_6(reg,
  660. FRF_AB_XM_TXEN, 1,
  661. FRF_AB_XM_TX_PRMBL, 1,
  662. FRF_AB_XM_AUTO_PAD, 1,
  663. FRF_AB_XM_TXCRC, 1,
  664. FRF_AB_XM_FCNTL, tx_fc,
  665. FRF_AB_XM_IPG, 0x3);
  666. efx_writeo(efx, &reg, FR_AB_XM_TX_CFG);
  667. /* Configure RX */
  668. EFX_POPULATE_OWORD_5(reg,
  669. FRF_AB_XM_RXEN, 1,
  670. FRF_AB_XM_AUTO_DEPAD, 0,
  671. FRF_AB_XM_ACPT_ALL_MCAST, 1,
  672. FRF_AB_XM_ACPT_ALL_UCAST, efx->promiscuous,
  673. FRF_AB_XM_PASS_CRC_ERR, 1);
  674. efx_writeo(efx, &reg, FR_AB_XM_RX_CFG);
  675. /* Set frame length */
  676. max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
  677. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_MAX_RX_FRM_SIZE, max_frame_len);
  678. efx_writeo(efx, &reg, FR_AB_XM_RX_PARAM);
  679. EFX_POPULATE_OWORD_2(reg,
  680. FRF_AB_XM_MAX_TX_FRM_SIZE, max_frame_len,
  681. FRF_AB_XM_TX_JUMBO_MODE, 1);
  682. efx_writeo(efx, &reg, FR_AB_XM_TX_PARAM);
  683. EFX_POPULATE_OWORD_2(reg,
  684. FRF_AB_XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */
  685. FRF_AB_XM_DIS_FCNTL, !rx_fc);
  686. efx_writeo(efx, &reg, FR_AB_XM_FC);
  687. /* Set MAC address */
  688. memcpy(&reg, &efx->net_dev->dev_addr[0], 4);
  689. efx_writeo(efx, &reg, FR_AB_XM_ADR_LO);
  690. memcpy(&reg, &efx->net_dev->dev_addr[4], 2);
  691. efx_writeo(efx, &reg, FR_AB_XM_ADR_HI);
  692. }
  693. static void falcon_reconfigure_xgxs_core(struct efx_nic *efx)
  694. {
  695. efx_oword_t reg;
  696. bool xgxs_loopback = (efx->loopback_mode == LOOPBACK_XGXS);
  697. bool xaui_loopback = (efx->loopback_mode == LOOPBACK_XAUI);
  698. bool xgmii_loopback = (efx->loopback_mode == LOOPBACK_XGMII);
  699. bool old_xgmii_loopback, old_xgxs_loopback, old_xaui_loopback;
  700. /* XGXS block is flaky and will need to be reset if moving
  701. * into our out of XGMII, XGXS or XAUI loopbacks. */
  702. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  703. old_xgxs_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_XGXS_LB_EN);
  704. old_xgmii_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_XGMII_LB_EN);
  705. efx_reado(efx, &reg, FR_AB_XX_SD_CTL);
  706. old_xaui_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_LPBKA);
  707. /* The PHY driver may have turned XAUI off */
  708. if ((xgxs_loopback != old_xgxs_loopback) ||
  709. (xaui_loopback != old_xaui_loopback) ||
  710. (xgmii_loopback != old_xgmii_loopback))
  711. falcon_reset_xaui(efx);
  712. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  713. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_FORCE_SIG,
  714. (xgxs_loopback || xaui_loopback) ?
  715. FFE_AB_XX_FORCE_SIG_ALL_LANES : 0);
  716. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_XGXS_LB_EN, xgxs_loopback);
  717. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_XGMII_LB_EN, xgmii_loopback);
  718. efx_writeo(efx, &reg, FR_AB_XX_CORE_STAT);
  719. efx_reado(efx, &reg, FR_AB_XX_SD_CTL);
  720. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKD, xaui_loopback);
  721. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKC, xaui_loopback);
  722. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKB, xaui_loopback);
  723. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKA, xaui_loopback);
  724. efx_writeo(efx, &reg, FR_AB_XX_SD_CTL);
  725. }
  726. /* Try to bring up the Falcon side of the Falcon-Phy XAUI link */
  727. static bool falcon_xmac_link_ok_retry(struct efx_nic *efx, int tries)
  728. {
  729. bool mac_up = falcon_xmac_link_ok(efx);
  730. if (LOOPBACK_MASK(efx) & LOOPBACKS_EXTERNAL(efx) & LOOPBACKS_WS ||
  731. efx_phy_mode_disabled(efx->phy_mode))
  732. /* XAUI link is expected to be down */
  733. return mac_up;
  734. falcon_stop_nic_stats(efx);
  735. while (!mac_up && tries) {
  736. netif_dbg(efx, hw, efx->net_dev, "bashing xaui\n");
  737. falcon_reset_xaui(efx);
  738. udelay(200);
  739. mac_up = falcon_xmac_link_ok(efx);
  740. --tries;
  741. }
  742. falcon_start_nic_stats(efx);
  743. return mac_up;
  744. }
  745. static bool falcon_xmac_check_fault(struct efx_nic *efx)
  746. {
  747. return !falcon_xmac_link_ok_retry(efx, 5);
  748. }
  749. static int falcon_reconfigure_xmac(struct efx_nic *efx)
  750. {
  751. struct falcon_nic_data *nic_data = efx->nic_data;
  752. falcon_reconfigure_xgxs_core(efx);
  753. falcon_reconfigure_xmac_core(efx);
  754. falcon_reconfigure_mac_wrapper(efx);
  755. nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 5);
  756. falcon_ack_status_intr(efx);
  757. return 0;
  758. }
  759. static void falcon_update_stats_xmac(struct efx_nic *efx)
  760. {
  761. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  762. /* Update MAC stats from DMAed values */
  763. FALCON_STAT(efx, XgRxOctets, rx_bytes);
  764. FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes);
  765. FALCON_STAT(efx, XgRxPkts, rx_packets);
  766. FALCON_STAT(efx, XgRxPktsOK, rx_good);
  767. FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast);
  768. FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast);
  769. FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast);
  770. FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64);
  771. FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo);
  772. FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo);
  773. FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64);
  774. FALCON_STAT(efx, XgRxDropEvents, rx_overflow);
  775. FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad);
  776. FALCON_STAT(efx, XgRxAlignError, rx_align_error);
  777. FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error);
  778. FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error);
  779. FALCON_STAT(efx, XgRxControlPkts, rx_control);
  780. FALCON_STAT(efx, XgRxPausePkts, rx_pause);
  781. FALCON_STAT(efx, XgRxPkts64Octets, rx_64);
  782. FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127);
  783. FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255);
  784. FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511);
  785. FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023);
  786. FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx);
  787. FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo);
  788. FALCON_STAT(efx, XgRxLengthError, rx_length_error);
  789. FALCON_STAT(efx, XgTxPkts, tx_packets);
  790. FALCON_STAT(efx, XgTxOctets, tx_bytes);
  791. FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast);
  792. FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast);
  793. FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast);
  794. FALCON_STAT(efx, XgTxControlPkts, tx_control);
  795. FALCON_STAT(efx, XgTxPausePkts, tx_pause);
  796. FALCON_STAT(efx, XgTxPkts64Octets, tx_64);
  797. FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127);
  798. FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255);
  799. FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511);
  800. FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023);
  801. FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx);
  802. FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo);
  803. FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64);
  804. FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo);
  805. FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp);
  806. FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error);
  807. FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error);
  808. /* Update derived statistics */
  809. efx_update_diff_stat(&mac_stats->tx_good_bytes,
  810. mac_stats->tx_bytes - mac_stats->tx_bad_bytes -
  811. mac_stats->tx_control * 64);
  812. efx_update_diff_stat(&mac_stats->rx_bad_bytes,
  813. mac_stats->rx_bytes - mac_stats->rx_good_bytes -
  814. mac_stats->rx_control * 64);
  815. }
  816. static void falcon_poll_xmac(struct efx_nic *efx)
  817. {
  818. struct falcon_nic_data *nic_data = efx->nic_data;
  819. /* We expect xgmii faults if the wireside link is down */
  820. if (!efx->link_state.up || !nic_data->xmac_poll_required)
  821. return;
  822. nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 1);
  823. falcon_ack_status_intr(efx);
  824. }
  825. /**************************************************************************
  826. *
  827. * MAC wrapper
  828. *
  829. **************************************************************************
  830. */
  831. static void falcon_push_multicast_hash(struct efx_nic *efx)
  832. {
  833. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  834. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  835. efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0);
  836. efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1);
  837. }
  838. static void falcon_reset_macs(struct efx_nic *efx)
  839. {
  840. struct falcon_nic_data *nic_data = efx->nic_data;
  841. efx_oword_t reg, mac_ctrl;
  842. int count;
  843. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
  844. /* It's not safe to use GLB_CTL_REG to reset the
  845. * macs, so instead use the internal MAC resets
  846. */
  847. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1);
  848. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  849. for (count = 0; count < 10000; count++) {
  850. efx_reado(efx, &reg, FR_AB_XM_GLB_CFG);
  851. if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) ==
  852. 0)
  853. return;
  854. udelay(10);
  855. }
  856. netif_err(efx, hw, efx->net_dev,
  857. "timed out waiting for XMAC core reset\n");
  858. }
  859. /* Mac stats will fail whist the TX fifo is draining */
  860. WARN_ON(nic_data->stats_disable_count == 0);
  861. efx_reado(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  862. EFX_SET_OWORD_FIELD(mac_ctrl, FRF_BB_TXFIFO_DRAIN_EN, 1);
  863. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  864. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  865. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1);
  866. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1);
  867. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1);
  868. efx_writeo(efx, &reg, FR_AB_GLB_CTL);
  869. count = 0;
  870. while (1) {
  871. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  872. if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) &&
  873. !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) &&
  874. !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) {
  875. netif_dbg(efx, hw, efx->net_dev,
  876. "Completed MAC reset after %d loops\n",
  877. count);
  878. break;
  879. }
  880. if (count > 20) {
  881. netif_err(efx, hw, efx->net_dev, "MAC reset failed\n");
  882. break;
  883. }
  884. count++;
  885. udelay(10);
  886. }
  887. /* Ensure the correct MAC is selected before statistics
  888. * are re-enabled by the caller */
  889. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  890. falcon_setup_xaui(efx);
  891. }
  892. static void falcon_drain_tx_fifo(struct efx_nic *efx)
  893. {
  894. efx_oword_t reg;
  895. if ((efx_nic_rev(efx) < EFX_REV_FALCON_B0) ||
  896. (efx->loopback_mode != LOOPBACK_NONE))
  897. return;
  898. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  899. /* There is no point in draining more than once */
  900. if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN))
  901. return;
  902. falcon_reset_macs(efx);
  903. }
  904. static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
  905. {
  906. efx_oword_t reg;
  907. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  908. return;
  909. /* Isolate the MAC -> RX */
  910. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  911. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0);
  912. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  913. /* Isolate TX -> MAC */
  914. falcon_drain_tx_fifo(efx);
  915. }
  916. static void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
  917. {
  918. struct efx_link_state *link_state = &efx->link_state;
  919. efx_oword_t reg;
  920. int link_speed, isolate;
  921. isolate = !!ACCESS_ONCE(efx->reset_pending);
  922. switch (link_state->speed) {
  923. case 10000: link_speed = 3; break;
  924. case 1000: link_speed = 2; break;
  925. case 100: link_speed = 1; break;
  926. default: link_speed = 0; break;
  927. }
  928. /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
  929. * as advertised. Disable to ensure packets are not
  930. * indefinitely held and TX queue can be flushed at any point
  931. * while the link is down. */
  932. EFX_POPULATE_OWORD_5(reg,
  933. FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */,
  934. FRF_AB_MAC_BCAD_ACPT, 1,
  935. FRF_AB_MAC_UC_PROM, efx->promiscuous,
  936. FRF_AB_MAC_LINK_STATUS, 1, /* always set */
  937. FRF_AB_MAC_SPEED, link_speed);
  938. /* On B0, MAC backpressure can be disabled and packets get
  939. * discarded. */
  940. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  941. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN,
  942. !link_state->up || isolate);
  943. }
  944. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  945. /* Restore the multicast hash registers. */
  946. falcon_push_multicast_hash(efx);
  947. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  948. /* Enable XOFF signal from RX FIFO (we enabled it during NIC
  949. * initialisation but it may read back as 0) */
  950. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  951. /* Unisolate the MAC -> RX */
  952. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  953. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, !isolate);
  954. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  955. }
  956. static void falcon_stats_request(struct efx_nic *efx)
  957. {
  958. struct falcon_nic_data *nic_data = efx->nic_data;
  959. efx_oword_t reg;
  960. WARN_ON(nic_data->stats_pending);
  961. WARN_ON(nic_data->stats_disable_count);
  962. if (nic_data->stats_dma_done == NULL)
  963. return; /* no mac selected */
  964. *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE;
  965. nic_data->stats_pending = true;
  966. wmb(); /* ensure done flag is clear */
  967. /* Initiate DMA transfer of stats */
  968. EFX_POPULATE_OWORD_2(reg,
  969. FRF_AB_MAC_STAT_DMA_CMD, 1,
  970. FRF_AB_MAC_STAT_DMA_ADR,
  971. efx->stats_buffer.dma_addr);
  972. efx_writeo(efx, &reg, FR_AB_MAC_STAT_DMA);
  973. mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2));
  974. }
  975. static void falcon_stats_complete(struct efx_nic *efx)
  976. {
  977. struct falcon_nic_data *nic_data = efx->nic_data;
  978. if (!nic_data->stats_pending)
  979. return;
  980. nic_data->stats_pending = false;
  981. if (*nic_data->stats_dma_done == FALCON_STATS_DONE) {
  982. rmb(); /* read the done flag before the stats */
  983. falcon_update_stats_xmac(efx);
  984. } else {
  985. netif_err(efx, hw, efx->net_dev,
  986. "timed out waiting for statistics\n");
  987. }
  988. }
  989. static void falcon_stats_timer_func(unsigned long context)
  990. {
  991. struct efx_nic *efx = (struct efx_nic *)context;
  992. struct falcon_nic_data *nic_data = efx->nic_data;
  993. spin_lock(&efx->stats_lock);
  994. falcon_stats_complete(efx);
  995. if (nic_data->stats_disable_count == 0)
  996. falcon_stats_request(efx);
  997. spin_unlock(&efx->stats_lock);
  998. }
  999. static bool falcon_loopback_link_poll(struct efx_nic *efx)
  1000. {
  1001. struct efx_link_state old_state = efx->link_state;
  1002. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1003. WARN_ON(!LOOPBACK_INTERNAL(efx));
  1004. efx->link_state.fd = true;
  1005. efx->link_state.fc = efx->wanted_fc;
  1006. efx->link_state.up = true;
  1007. efx->link_state.speed = 10000;
  1008. return !efx_link_state_equal(&efx->link_state, &old_state);
  1009. }
  1010. static int falcon_reconfigure_port(struct efx_nic *efx)
  1011. {
  1012. int rc;
  1013. WARN_ON(efx_nic_rev(efx) > EFX_REV_FALCON_B0);
  1014. /* Poll the PHY link state *before* reconfiguring it. This means we
  1015. * will pick up the correct speed (in loopback) to select the correct
  1016. * MAC.
  1017. */
  1018. if (LOOPBACK_INTERNAL(efx))
  1019. falcon_loopback_link_poll(efx);
  1020. else
  1021. efx->phy_op->poll(efx);
  1022. falcon_stop_nic_stats(efx);
  1023. falcon_deconfigure_mac_wrapper(efx);
  1024. falcon_reset_macs(efx);
  1025. efx->phy_op->reconfigure(efx);
  1026. rc = falcon_reconfigure_xmac(efx);
  1027. BUG_ON(rc);
  1028. falcon_start_nic_stats(efx);
  1029. /* Synchronise efx->link_state with the kernel */
  1030. efx_link_status_changed(efx);
  1031. return 0;
  1032. }
  1033. /* TX flow control may automatically turn itself off if the link
  1034. * partner (intermittently) stops responding to pause frames. There
  1035. * isn't any indication that this has happened, so the best we do is
  1036. * leave it up to the user to spot this and fix it by cycling transmit
  1037. * flow control on this end.
  1038. */
  1039. static void falcon_a1_prepare_enable_fc_tx(struct efx_nic *efx)
  1040. {
  1041. /* Schedule a reset to recover */
  1042. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  1043. }
  1044. static void falcon_b0_prepare_enable_fc_tx(struct efx_nic *efx)
  1045. {
  1046. /* Recover by resetting the EM block */
  1047. falcon_stop_nic_stats(efx);
  1048. falcon_drain_tx_fifo(efx);
  1049. falcon_reconfigure_xmac(efx);
  1050. falcon_start_nic_stats(efx);
  1051. }
  1052. /**************************************************************************
  1053. *
  1054. * PHY access via GMII
  1055. *
  1056. **************************************************************************
  1057. */
  1058. /* Wait for GMII access to complete */
  1059. static int falcon_gmii_wait(struct efx_nic *efx)
  1060. {
  1061. efx_oword_t md_stat;
  1062. int count;
  1063. /* wait up to 50ms - taken max from datasheet */
  1064. for (count = 0; count < 5000; count++) {
  1065. efx_reado(efx, &md_stat, FR_AB_MD_STAT);
  1066. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) {
  1067. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 ||
  1068. EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) {
  1069. netif_err(efx, hw, efx->net_dev,
  1070. "error from GMII access "
  1071. EFX_OWORD_FMT"\n",
  1072. EFX_OWORD_VAL(md_stat));
  1073. return -EIO;
  1074. }
  1075. return 0;
  1076. }
  1077. udelay(10);
  1078. }
  1079. netif_err(efx, hw, efx->net_dev, "timed out waiting for GMII\n");
  1080. return -ETIMEDOUT;
  1081. }
  1082. /* Write an MDIO register of a PHY connected to Falcon. */
  1083. static int falcon_mdio_write(struct net_device *net_dev,
  1084. int prtad, int devad, u16 addr, u16 value)
  1085. {
  1086. struct efx_nic *efx = netdev_priv(net_dev);
  1087. struct falcon_nic_data *nic_data = efx->nic_data;
  1088. efx_oword_t reg;
  1089. int rc;
  1090. netif_vdbg(efx, hw, efx->net_dev,
  1091. "writing MDIO %d register %d.%d with 0x%04x\n",
  1092. prtad, devad, addr, value);
  1093. mutex_lock(&nic_data->mdio_lock);
  1094. /* Check MDIO not currently being accessed */
  1095. rc = falcon_gmii_wait(efx);
  1096. if (rc)
  1097. goto out;
  1098. /* Write the address/ID register */
  1099. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1100. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1101. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1102. FRF_AB_MD_DEV_ADR, devad);
  1103. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1104. /* Write data */
  1105. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value);
  1106. efx_writeo(efx, &reg, FR_AB_MD_TXD);
  1107. EFX_POPULATE_OWORD_2(reg,
  1108. FRF_AB_MD_WRC, 1,
  1109. FRF_AB_MD_GC, 0);
  1110. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1111. /* Wait for data to be written */
  1112. rc = falcon_gmii_wait(efx);
  1113. if (rc) {
  1114. /* Abort the write operation */
  1115. EFX_POPULATE_OWORD_2(reg,
  1116. FRF_AB_MD_WRC, 0,
  1117. FRF_AB_MD_GC, 1);
  1118. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1119. udelay(10);
  1120. }
  1121. out:
  1122. mutex_unlock(&nic_data->mdio_lock);
  1123. return rc;
  1124. }
  1125. /* Read an MDIO register of a PHY connected to Falcon. */
  1126. static int falcon_mdio_read(struct net_device *net_dev,
  1127. int prtad, int devad, u16 addr)
  1128. {
  1129. struct efx_nic *efx = netdev_priv(net_dev);
  1130. struct falcon_nic_data *nic_data = efx->nic_data;
  1131. efx_oword_t reg;
  1132. int rc;
  1133. mutex_lock(&nic_data->mdio_lock);
  1134. /* Check MDIO not currently being accessed */
  1135. rc = falcon_gmii_wait(efx);
  1136. if (rc)
  1137. goto out;
  1138. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1139. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1140. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1141. FRF_AB_MD_DEV_ADR, devad);
  1142. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1143. /* Request data to be read */
  1144. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
  1145. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1146. /* Wait for data to become available */
  1147. rc = falcon_gmii_wait(efx);
  1148. if (rc == 0) {
  1149. efx_reado(efx, &reg, FR_AB_MD_RXD);
  1150. rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
  1151. netif_vdbg(efx, hw, efx->net_dev,
  1152. "read from MDIO %d register %d.%d, got %04x\n",
  1153. prtad, devad, addr, rc);
  1154. } else {
  1155. /* Abort the read operation */
  1156. EFX_POPULATE_OWORD_2(reg,
  1157. FRF_AB_MD_RIC, 0,
  1158. FRF_AB_MD_GC, 1);
  1159. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1160. netif_dbg(efx, hw, efx->net_dev,
  1161. "read from MDIO %d register %d.%d, got error %d\n",
  1162. prtad, devad, addr, rc);
  1163. }
  1164. out:
  1165. mutex_unlock(&nic_data->mdio_lock);
  1166. return rc;
  1167. }
  1168. /* This call is responsible for hooking in the MAC and PHY operations */
  1169. static int falcon_probe_port(struct efx_nic *efx)
  1170. {
  1171. struct falcon_nic_data *nic_data = efx->nic_data;
  1172. int rc;
  1173. switch (efx->phy_type) {
  1174. case PHY_TYPE_SFX7101:
  1175. efx->phy_op = &falcon_sfx7101_phy_ops;
  1176. break;
  1177. case PHY_TYPE_QT2022C2:
  1178. case PHY_TYPE_QT2025C:
  1179. efx->phy_op = &falcon_qt202x_phy_ops;
  1180. break;
  1181. case PHY_TYPE_TXC43128:
  1182. efx->phy_op = &falcon_txc_phy_ops;
  1183. break;
  1184. default:
  1185. netif_err(efx, probe, efx->net_dev, "Unknown PHY type %d\n",
  1186. efx->phy_type);
  1187. return -ENODEV;
  1188. }
  1189. /* Fill out MDIO structure and loopback modes */
  1190. mutex_init(&nic_data->mdio_lock);
  1191. efx->mdio.mdio_read = falcon_mdio_read;
  1192. efx->mdio.mdio_write = falcon_mdio_write;
  1193. rc = efx->phy_op->probe(efx);
  1194. if (rc != 0)
  1195. return rc;
  1196. /* Initial assumption */
  1197. efx->link_state.speed = 10000;
  1198. efx->link_state.fd = true;
  1199. /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
  1200. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1201. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  1202. else
  1203. efx->wanted_fc = EFX_FC_RX;
  1204. if (efx->mdio.mmds & MDIO_DEVS_AN)
  1205. efx->wanted_fc |= EFX_FC_AUTO;
  1206. /* Allocate buffer for stats */
  1207. rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
  1208. FALCON_MAC_STATS_SIZE, GFP_KERNEL);
  1209. if (rc)
  1210. return rc;
  1211. netif_dbg(efx, probe, efx->net_dev,
  1212. "stats buffer at %llx (virt %p phys %llx)\n",
  1213. (u64)efx->stats_buffer.dma_addr,
  1214. efx->stats_buffer.addr,
  1215. (u64)virt_to_phys(efx->stats_buffer.addr));
  1216. nic_data->stats_dma_done = efx->stats_buffer.addr + XgDmaDone_offset;
  1217. return 0;
  1218. }
  1219. static void falcon_remove_port(struct efx_nic *efx)
  1220. {
  1221. efx->phy_op->remove(efx);
  1222. efx_nic_free_buffer(efx, &efx->stats_buffer);
  1223. }
  1224. /* Global events are basically PHY events */
  1225. static bool
  1226. falcon_handle_global_event(struct efx_channel *channel, efx_qword_t *event)
  1227. {
  1228. struct efx_nic *efx = channel->efx;
  1229. struct falcon_nic_data *nic_data = efx->nic_data;
  1230. if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
  1231. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
  1232. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR))
  1233. /* Ignored */
  1234. return true;
  1235. if ((efx_nic_rev(efx) == EFX_REV_FALCON_B0) &&
  1236. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
  1237. nic_data->xmac_poll_required = true;
  1238. return true;
  1239. }
  1240. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ?
  1241. EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
  1242. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
  1243. netif_err(efx, rx_err, efx->net_dev,
  1244. "channel %d seen global RX_RESET event. Resetting.\n",
  1245. channel->channel);
  1246. atomic_inc(&efx->rx_reset);
  1247. efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
  1248. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  1249. return true;
  1250. }
  1251. return false;
  1252. }
  1253. /**************************************************************************
  1254. *
  1255. * Falcon test code
  1256. *
  1257. **************************************************************************/
  1258. static int
  1259. falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
  1260. {
  1261. struct falcon_nic_data *nic_data = efx->nic_data;
  1262. struct falcon_nvconfig *nvconfig;
  1263. struct efx_spi_device *spi;
  1264. void *region;
  1265. int rc, magic_num, struct_ver;
  1266. __le16 *word, *limit;
  1267. u32 csum;
  1268. if (efx_spi_present(&nic_data->spi_flash))
  1269. spi = &nic_data->spi_flash;
  1270. else if (efx_spi_present(&nic_data->spi_eeprom))
  1271. spi = &nic_data->spi_eeprom;
  1272. else
  1273. return -EINVAL;
  1274. region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
  1275. if (!region)
  1276. return -ENOMEM;
  1277. nvconfig = region + FALCON_NVCONFIG_OFFSET;
  1278. mutex_lock(&nic_data->spi_lock);
  1279. rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region);
  1280. mutex_unlock(&nic_data->spi_lock);
  1281. if (rc) {
  1282. netif_err(efx, hw, efx->net_dev, "Failed to read %s\n",
  1283. efx_spi_present(&nic_data->spi_flash) ?
  1284. "flash" : "EEPROM");
  1285. rc = -EIO;
  1286. goto out;
  1287. }
  1288. magic_num = le16_to_cpu(nvconfig->board_magic_num);
  1289. struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
  1290. rc = -EINVAL;
  1291. if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
  1292. netif_err(efx, hw, efx->net_dev,
  1293. "NVRAM bad magic 0x%x\n", magic_num);
  1294. goto out;
  1295. }
  1296. if (struct_ver < 2) {
  1297. netif_err(efx, hw, efx->net_dev,
  1298. "NVRAM has ancient version 0x%x\n", struct_ver);
  1299. goto out;
  1300. } else if (struct_ver < 4) {
  1301. word = &nvconfig->board_magic_num;
  1302. limit = (__le16 *) (nvconfig + 1);
  1303. } else {
  1304. word = region;
  1305. limit = region + FALCON_NVCONFIG_END;
  1306. }
  1307. for (csum = 0; word < limit; ++word)
  1308. csum += le16_to_cpu(*word);
  1309. if (~csum & 0xffff) {
  1310. netif_err(efx, hw, efx->net_dev,
  1311. "NVRAM has incorrect checksum\n");
  1312. goto out;
  1313. }
  1314. rc = 0;
  1315. if (nvconfig_out)
  1316. memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
  1317. out:
  1318. kfree(region);
  1319. return rc;
  1320. }
  1321. static int falcon_test_nvram(struct efx_nic *efx)
  1322. {
  1323. return falcon_read_nvram(efx, NULL);
  1324. }
  1325. static const struct efx_farch_register_test falcon_b0_register_tests[] = {
  1326. { FR_AZ_ADR_REGION,
  1327. EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
  1328. { FR_AZ_RX_CFG,
  1329. EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
  1330. { FR_AZ_TX_CFG,
  1331. EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
  1332. { FR_AZ_TX_RESERVED,
  1333. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  1334. { FR_AB_MAC_CTRL,
  1335. EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
  1336. { FR_AZ_SRM_TX_DC_CFG,
  1337. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  1338. { FR_AZ_RX_DC_CFG,
  1339. EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
  1340. { FR_AZ_RX_DC_PF_WM,
  1341. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  1342. { FR_BZ_DP_CTRL,
  1343. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  1344. { FR_AB_GM_CFG2,
  1345. EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
  1346. { FR_AB_GMF_CFG0,
  1347. EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
  1348. { FR_AB_XM_GLB_CFG,
  1349. EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
  1350. { FR_AB_XM_TX_CFG,
  1351. EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
  1352. { FR_AB_XM_RX_CFG,
  1353. EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
  1354. { FR_AB_XM_RX_PARAM,
  1355. EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
  1356. { FR_AB_XM_FC,
  1357. EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
  1358. { FR_AB_XM_ADR_LO,
  1359. EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
  1360. { FR_AB_XX_SD_CTL,
  1361. EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
  1362. };
  1363. static int
  1364. falcon_b0_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
  1365. {
  1366. enum reset_type reset_method = RESET_TYPE_INVISIBLE;
  1367. int rc, rc2;
  1368. mutex_lock(&efx->mac_lock);
  1369. if (efx->loopback_modes) {
  1370. /* We need the 312 clock from the PHY to test the XMAC
  1371. * registers, so move into XGMII loopback if available */
  1372. if (efx->loopback_modes & (1 << LOOPBACK_XGMII))
  1373. efx->loopback_mode = LOOPBACK_XGMII;
  1374. else
  1375. efx->loopback_mode = __ffs(efx->loopback_modes);
  1376. }
  1377. __efx_reconfigure_port(efx);
  1378. mutex_unlock(&efx->mac_lock);
  1379. efx_reset_down(efx, reset_method);
  1380. tests->registers =
  1381. efx_farch_test_registers(efx, falcon_b0_register_tests,
  1382. ARRAY_SIZE(falcon_b0_register_tests))
  1383. ? -1 : 1;
  1384. rc = falcon_reset_hw(efx, reset_method);
  1385. rc2 = efx_reset_up(efx, reset_method, rc == 0);
  1386. return rc ? rc : rc2;
  1387. }
  1388. /**************************************************************************
  1389. *
  1390. * Device reset
  1391. *
  1392. **************************************************************************
  1393. */
  1394. static enum reset_type falcon_map_reset_reason(enum reset_type reason)
  1395. {
  1396. switch (reason) {
  1397. case RESET_TYPE_RX_RECOVERY:
  1398. case RESET_TYPE_RX_DESC_FETCH:
  1399. case RESET_TYPE_TX_DESC_FETCH:
  1400. case RESET_TYPE_TX_SKIP:
  1401. /* These can occasionally occur due to hardware bugs.
  1402. * We try to reset without disrupting the link.
  1403. */
  1404. return RESET_TYPE_INVISIBLE;
  1405. default:
  1406. return RESET_TYPE_ALL;
  1407. }
  1408. }
  1409. static int falcon_map_reset_flags(u32 *flags)
  1410. {
  1411. enum {
  1412. FALCON_RESET_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER |
  1413. ETH_RESET_OFFLOAD | ETH_RESET_MAC),
  1414. FALCON_RESET_ALL = FALCON_RESET_INVISIBLE | ETH_RESET_PHY,
  1415. FALCON_RESET_WORLD = FALCON_RESET_ALL | ETH_RESET_IRQ,
  1416. };
  1417. if ((*flags & FALCON_RESET_WORLD) == FALCON_RESET_WORLD) {
  1418. *flags &= ~FALCON_RESET_WORLD;
  1419. return RESET_TYPE_WORLD;
  1420. }
  1421. if ((*flags & FALCON_RESET_ALL) == FALCON_RESET_ALL) {
  1422. *flags &= ~FALCON_RESET_ALL;
  1423. return RESET_TYPE_ALL;
  1424. }
  1425. if ((*flags & FALCON_RESET_INVISIBLE) == FALCON_RESET_INVISIBLE) {
  1426. *flags &= ~FALCON_RESET_INVISIBLE;
  1427. return RESET_TYPE_INVISIBLE;
  1428. }
  1429. return -EINVAL;
  1430. }
  1431. /* Resets NIC to known state. This routine must be called in process
  1432. * context and is allowed to sleep. */
  1433. static int __falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  1434. {
  1435. struct falcon_nic_data *nic_data = efx->nic_data;
  1436. efx_oword_t glb_ctl_reg_ker;
  1437. int rc;
  1438. netif_dbg(efx, hw, efx->net_dev, "performing %s hardware reset\n",
  1439. RESET_TYPE(method));
  1440. /* Initiate device reset */
  1441. if (method == RESET_TYPE_WORLD) {
  1442. rc = pci_save_state(efx->pci_dev);
  1443. if (rc) {
  1444. netif_err(efx, drv, efx->net_dev,
  1445. "failed to backup PCI state of primary "
  1446. "function prior to hardware reset\n");
  1447. goto fail1;
  1448. }
  1449. if (efx_nic_is_dual_func(efx)) {
  1450. rc = pci_save_state(nic_data->pci_dev2);
  1451. if (rc) {
  1452. netif_err(efx, drv, efx->net_dev,
  1453. "failed to backup PCI state of "
  1454. "secondary function prior to "
  1455. "hardware reset\n");
  1456. goto fail2;
  1457. }
  1458. }
  1459. EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
  1460. FRF_AB_EXT_PHY_RST_DUR,
  1461. FFE_AB_EXT_PHY_RST_DUR_10240US,
  1462. FRF_AB_SWRST, 1);
  1463. } else {
  1464. EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
  1465. /* exclude PHY from "invisible" reset */
  1466. FRF_AB_EXT_PHY_RST_CTL,
  1467. method == RESET_TYPE_INVISIBLE,
  1468. /* exclude EEPROM/flash and PCIe */
  1469. FRF_AB_PCIE_CORE_RST_CTL, 1,
  1470. FRF_AB_PCIE_NSTKY_RST_CTL, 1,
  1471. FRF_AB_PCIE_SD_RST_CTL, 1,
  1472. FRF_AB_EE_RST_CTL, 1,
  1473. FRF_AB_EXT_PHY_RST_DUR,
  1474. FFE_AB_EXT_PHY_RST_DUR_10240US,
  1475. FRF_AB_SWRST, 1);
  1476. }
  1477. efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  1478. netif_dbg(efx, hw, efx->net_dev, "waiting for hardware reset\n");
  1479. schedule_timeout_uninterruptible(HZ / 20);
  1480. /* Restore PCI configuration if needed */
  1481. if (method == RESET_TYPE_WORLD) {
  1482. if (efx_nic_is_dual_func(efx))
  1483. pci_restore_state(nic_data->pci_dev2);
  1484. pci_restore_state(efx->pci_dev);
  1485. netif_dbg(efx, drv, efx->net_dev,
  1486. "successfully restored PCI config\n");
  1487. }
  1488. /* Assert that reset complete */
  1489. efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  1490. if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
  1491. rc = -ETIMEDOUT;
  1492. netif_err(efx, hw, efx->net_dev,
  1493. "timed out waiting for hardware reset\n");
  1494. goto fail3;
  1495. }
  1496. netif_dbg(efx, hw, efx->net_dev, "hardware reset complete\n");
  1497. return 0;
  1498. /* pci_save_state() and pci_restore_state() MUST be called in pairs */
  1499. fail2:
  1500. pci_restore_state(efx->pci_dev);
  1501. fail1:
  1502. fail3:
  1503. return rc;
  1504. }
  1505. static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  1506. {
  1507. struct falcon_nic_data *nic_data = efx->nic_data;
  1508. int rc;
  1509. mutex_lock(&nic_data->spi_lock);
  1510. rc = __falcon_reset_hw(efx, method);
  1511. mutex_unlock(&nic_data->spi_lock);
  1512. return rc;
  1513. }
  1514. static void falcon_monitor(struct efx_nic *efx)
  1515. {
  1516. bool link_changed;
  1517. int rc;
  1518. BUG_ON(!mutex_is_locked(&efx->mac_lock));
  1519. rc = falcon_board(efx)->type->monitor(efx);
  1520. if (rc) {
  1521. netif_err(efx, hw, efx->net_dev,
  1522. "Board sensor %s; shutting down PHY\n",
  1523. (rc == -ERANGE) ? "reported fault" : "failed");
  1524. efx->phy_mode |= PHY_MODE_LOW_POWER;
  1525. rc = __efx_reconfigure_port(efx);
  1526. WARN_ON(rc);
  1527. }
  1528. if (LOOPBACK_INTERNAL(efx))
  1529. link_changed = falcon_loopback_link_poll(efx);
  1530. else
  1531. link_changed = efx->phy_op->poll(efx);
  1532. if (link_changed) {
  1533. falcon_stop_nic_stats(efx);
  1534. falcon_deconfigure_mac_wrapper(efx);
  1535. falcon_reset_macs(efx);
  1536. rc = falcon_reconfigure_xmac(efx);
  1537. BUG_ON(rc);
  1538. falcon_start_nic_stats(efx);
  1539. efx_link_status_changed(efx);
  1540. }
  1541. falcon_poll_xmac(efx);
  1542. }
  1543. /* Zeroes out the SRAM contents. This routine must be called in
  1544. * process context and is allowed to sleep.
  1545. */
  1546. static int falcon_reset_sram(struct efx_nic *efx)
  1547. {
  1548. efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
  1549. int count;
  1550. /* Set the SRAM wake/sleep GPIO appropriately. */
  1551. efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1552. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
  1553. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
  1554. efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1555. /* Initiate SRAM reset */
  1556. EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
  1557. FRF_AZ_SRM_INIT_EN, 1,
  1558. FRF_AZ_SRM_NB_SZ, 0);
  1559. efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1560. /* Wait for SRAM reset to complete */
  1561. count = 0;
  1562. do {
  1563. netif_dbg(efx, hw, efx->net_dev,
  1564. "waiting for SRAM reset (attempt %d)...\n", count);
  1565. /* SRAM reset is slow; expect around 16ms */
  1566. schedule_timeout_uninterruptible(HZ / 50);
  1567. /* Check for reset complete */
  1568. efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1569. if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
  1570. netif_dbg(efx, hw, efx->net_dev,
  1571. "SRAM reset complete\n");
  1572. return 0;
  1573. }
  1574. } while (++count < 20); /* wait up to 0.4 sec */
  1575. netif_err(efx, hw, efx->net_dev, "timed out waiting for SRAM reset\n");
  1576. return -ETIMEDOUT;
  1577. }
  1578. static void falcon_spi_device_init(struct efx_nic *efx,
  1579. struct efx_spi_device *spi_device,
  1580. unsigned int device_id, u32 device_type)
  1581. {
  1582. if (device_type != 0) {
  1583. spi_device->device_id = device_id;
  1584. spi_device->size =
  1585. 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
  1586. spi_device->addr_len =
  1587. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
  1588. spi_device->munge_address = (spi_device->size == 1 << 9 &&
  1589. spi_device->addr_len == 1);
  1590. spi_device->erase_command =
  1591. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
  1592. spi_device->erase_size =
  1593. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1594. SPI_DEV_TYPE_ERASE_SIZE);
  1595. spi_device->block_size =
  1596. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1597. SPI_DEV_TYPE_BLOCK_SIZE);
  1598. } else {
  1599. spi_device->size = 0;
  1600. }
  1601. }
  1602. /* Extract non-volatile configuration */
  1603. static int falcon_probe_nvconfig(struct efx_nic *efx)
  1604. {
  1605. struct falcon_nic_data *nic_data = efx->nic_data;
  1606. struct falcon_nvconfig *nvconfig;
  1607. int rc;
  1608. nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
  1609. if (!nvconfig)
  1610. return -ENOMEM;
  1611. rc = falcon_read_nvram(efx, nvconfig);
  1612. if (rc)
  1613. goto out;
  1614. efx->phy_type = nvconfig->board_v2.port0_phy_type;
  1615. efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr;
  1616. if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
  1617. falcon_spi_device_init(
  1618. efx, &nic_data->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
  1619. le32_to_cpu(nvconfig->board_v3
  1620. .spi_device_type[FFE_AB_SPI_DEVICE_FLASH]));
  1621. falcon_spi_device_init(
  1622. efx, &nic_data->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
  1623. le32_to_cpu(nvconfig->board_v3
  1624. .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM]));
  1625. }
  1626. /* Read the MAC addresses */
  1627. memcpy(efx->net_dev->perm_addr, nvconfig->mac_address[0], ETH_ALEN);
  1628. netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n",
  1629. efx->phy_type, efx->mdio.prtad);
  1630. rc = falcon_probe_board(efx,
  1631. le16_to_cpu(nvconfig->board_v2.board_revision));
  1632. out:
  1633. kfree(nvconfig);
  1634. return rc;
  1635. }
  1636. static void falcon_dimension_resources(struct efx_nic *efx)
  1637. {
  1638. efx->rx_dc_base = 0x20000;
  1639. efx->tx_dc_base = 0x26000;
  1640. }
  1641. /* Probe all SPI devices on the NIC */
  1642. static void falcon_probe_spi_devices(struct efx_nic *efx)
  1643. {
  1644. struct falcon_nic_data *nic_data = efx->nic_data;
  1645. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  1646. int boot_dev;
  1647. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  1648. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1649. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1650. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  1651. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  1652. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  1653. netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n",
  1654. boot_dev == FFE_AB_SPI_DEVICE_FLASH ?
  1655. "flash" : "EEPROM");
  1656. } else {
  1657. /* Disable VPD and set clock dividers to safe
  1658. * values for initial programming. */
  1659. boot_dev = -1;
  1660. netif_dbg(efx, probe, efx->net_dev,
  1661. "Booted from internal ASIC settings;"
  1662. " setting SPI config\n");
  1663. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  1664. /* 125 MHz / 7 ~= 20 MHz */
  1665. FRF_AB_EE_SF_CLOCK_DIV, 7,
  1666. /* 125 MHz / 63 ~= 2 MHz */
  1667. FRF_AB_EE_EE_CLOCK_DIV, 63);
  1668. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1669. }
  1670. mutex_init(&nic_data->spi_lock);
  1671. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  1672. falcon_spi_device_init(efx, &nic_data->spi_flash,
  1673. FFE_AB_SPI_DEVICE_FLASH,
  1674. default_flash_type);
  1675. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  1676. falcon_spi_device_init(efx, &nic_data->spi_eeprom,
  1677. FFE_AB_SPI_DEVICE_EEPROM,
  1678. large_eeprom_type);
  1679. }
  1680. static unsigned int falcon_a1_mem_map_size(struct efx_nic *efx)
  1681. {
  1682. return 0x20000;
  1683. }
  1684. static unsigned int falcon_b0_mem_map_size(struct efx_nic *efx)
  1685. {
  1686. /* Map everything up to and including the RSS indirection table.
  1687. * The PCI core takes care of mapping the MSI-X tables.
  1688. */
  1689. return FR_BZ_RX_INDIRECTION_TBL +
  1690. FR_BZ_RX_INDIRECTION_TBL_STEP * FR_BZ_RX_INDIRECTION_TBL_ROWS;
  1691. }
  1692. static int falcon_probe_nic(struct efx_nic *efx)
  1693. {
  1694. struct falcon_nic_data *nic_data;
  1695. struct falcon_board *board;
  1696. int rc;
  1697. /* Allocate storage for hardware specific data */
  1698. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  1699. if (!nic_data)
  1700. return -ENOMEM;
  1701. efx->nic_data = nic_data;
  1702. rc = -ENODEV;
  1703. if (efx_farch_fpga_ver(efx) != 0) {
  1704. netif_err(efx, probe, efx->net_dev,
  1705. "Falcon FPGA not supported\n");
  1706. goto fail1;
  1707. }
  1708. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1709. efx_oword_t nic_stat;
  1710. struct pci_dev *dev;
  1711. u8 pci_rev = efx->pci_dev->revision;
  1712. if ((pci_rev == 0xff) || (pci_rev == 0)) {
  1713. netif_err(efx, probe, efx->net_dev,
  1714. "Falcon rev A0 not supported\n");
  1715. goto fail1;
  1716. }
  1717. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1718. if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) {
  1719. netif_err(efx, probe, efx->net_dev,
  1720. "Falcon rev A1 1G not supported\n");
  1721. goto fail1;
  1722. }
  1723. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  1724. netif_err(efx, probe, efx->net_dev,
  1725. "Falcon rev A1 PCI-X not supported\n");
  1726. goto fail1;
  1727. }
  1728. dev = pci_dev_get(efx->pci_dev);
  1729. while ((dev = pci_get_device(PCI_VENDOR_ID_SOLARFLARE,
  1730. PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1,
  1731. dev))) {
  1732. if (dev->bus == efx->pci_dev->bus &&
  1733. dev->devfn == efx->pci_dev->devfn + 1) {
  1734. nic_data->pci_dev2 = dev;
  1735. break;
  1736. }
  1737. }
  1738. if (!nic_data->pci_dev2) {
  1739. netif_err(efx, probe, efx->net_dev,
  1740. "failed to find secondary function\n");
  1741. rc = -ENODEV;
  1742. goto fail2;
  1743. }
  1744. }
  1745. /* Now we can reset the NIC */
  1746. rc = __falcon_reset_hw(efx, RESET_TYPE_ALL);
  1747. if (rc) {
  1748. netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
  1749. goto fail3;
  1750. }
  1751. /* Allocate memory for INT_KER */
  1752. rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t),
  1753. GFP_KERNEL);
  1754. if (rc)
  1755. goto fail4;
  1756. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  1757. netif_dbg(efx, probe, efx->net_dev,
  1758. "INT_KER at %llx (virt %p phys %llx)\n",
  1759. (u64)efx->irq_status.dma_addr,
  1760. efx->irq_status.addr,
  1761. (u64)virt_to_phys(efx->irq_status.addr));
  1762. falcon_probe_spi_devices(efx);
  1763. /* Read in the non-volatile configuration */
  1764. rc = falcon_probe_nvconfig(efx);
  1765. if (rc) {
  1766. if (rc == -EINVAL)
  1767. netif_err(efx, probe, efx->net_dev, "NVRAM is invalid\n");
  1768. goto fail5;
  1769. }
  1770. efx->max_channels = (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ? 4 :
  1771. EFX_MAX_CHANNELS);
  1772. efx->timer_quantum_ns = 4968; /* 621 cycles */
  1773. /* Initialise I2C adapter */
  1774. board = falcon_board(efx);
  1775. board->i2c_adap.owner = THIS_MODULE;
  1776. board->i2c_data = falcon_i2c_bit_operations;
  1777. board->i2c_data.data = efx;
  1778. board->i2c_adap.algo_data = &board->i2c_data;
  1779. board->i2c_adap.dev.parent = &efx->pci_dev->dev;
  1780. strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
  1781. sizeof(board->i2c_adap.name));
  1782. rc = i2c_bit_add_bus(&board->i2c_adap);
  1783. if (rc)
  1784. goto fail5;
  1785. rc = falcon_board(efx)->type->init(efx);
  1786. if (rc) {
  1787. netif_err(efx, probe, efx->net_dev,
  1788. "failed to initialise board\n");
  1789. goto fail6;
  1790. }
  1791. nic_data->stats_disable_count = 1;
  1792. setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
  1793. (unsigned long)efx);
  1794. return 0;
  1795. fail6:
  1796. i2c_del_adapter(&board->i2c_adap);
  1797. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1798. fail5:
  1799. efx_nic_free_buffer(efx, &efx->irq_status);
  1800. fail4:
  1801. fail3:
  1802. if (nic_data->pci_dev2) {
  1803. pci_dev_put(nic_data->pci_dev2);
  1804. nic_data->pci_dev2 = NULL;
  1805. }
  1806. fail2:
  1807. fail1:
  1808. kfree(efx->nic_data);
  1809. return rc;
  1810. }
  1811. static void falcon_init_rx_cfg(struct efx_nic *efx)
  1812. {
  1813. /* RX control FIFO thresholds (32 entries) */
  1814. const unsigned ctrl_xon_thr = 20;
  1815. const unsigned ctrl_xoff_thr = 25;
  1816. efx_oword_t reg;
  1817. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1818. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1819. /* Data FIFO size is 5.5K. The RX DMA engine only
  1820. * supports scattering for user-mode queues, but will
  1821. * split DMA writes at intervals of RX_USR_BUF_SIZE
  1822. * (32-byte units) even for kernel-mode queues. We
  1823. * set it to be so large that that never happens.
  1824. */
  1825. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  1826. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  1827. (3 * 4096) >> 5);
  1828. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, 512 >> 8);
  1829. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, 2048 >> 8);
  1830. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  1831. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1832. } else {
  1833. /* Data FIFO size is 80K; register fields moved */
  1834. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
  1835. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
  1836. EFX_RX_USR_BUF_SIZE >> 5);
  1837. /* Send XON and XOFF at ~3 * max MTU away from empty/full */
  1838. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, 27648 >> 8);
  1839. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, 54272 >> 8);
  1840. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  1841. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1842. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  1843. /* Enable hash insertion. This is broken for the
  1844. * 'Falcon' hash so also select Toeplitz TCP/IPv4 and
  1845. * IPv4 hashes. */
  1846. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1);
  1847. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1);
  1848. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1);
  1849. }
  1850. /* Always enable XOFF signal from RX FIFO. We enable
  1851. * or disable transmission of pause frames at the MAC. */
  1852. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  1853. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1854. }
  1855. /* This call performs hardware-specific global initialisation, such as
  1856. * defining the descriptor cache sizes and number of RSS channels.
  1857. * It does not set up any buffers, descriptor rings or event queues.
  1858. */
  1859. static int falcon_init_nic(struct efx_nic *efx)
  1860. {
  1861. efx_oword_t temp;
  1862. int rc;
  1863. /* Use on-chip SRAM */
  1864. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  1865. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  1866. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  1867. rc = falcon_reset_sram(efx);
  1868. if (rc)
  1869. return rc;
  1870. /* Clear the parity enables on the TX data fifos as
  1871. * they produce false parity errors because of timing issues
  1872. */
  1873. if (EFX_WORKAROUND_5129(efx)) {
  1874. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  1875. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  1876. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  1877. }
  1878. if (EFX_WORKAROUND_7244(efx)) {
  1879. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1880. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  1881. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  1882. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  1883. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  1884. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1885. }
  1886. /* XXX This is documented only for Falcon A0/A1 */
  1887. /* Setup RX. Wait for descriptor is broken and must
  1888. * be disabled. RXDP recovery shouldn't be needed, but is.
  1889. */
  1890. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  1891. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  1892. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  1893. if (EFX_WORKAROUND_5583(efx))
  1894. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  1895. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  1896. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  1897. * descriptors (which is bad).
  1898. */
  1899. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  1900. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  1901. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  1902. falcon_init_rx_cfg(efx);
  1903. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  1904. /* Set hash key for IPv4 */
  1905. memcpy(&temp, efx->rx_hash_key, sizeof(temp));
  1906. efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY);
  1907. /* Set destination of both TX and RX Flush events */
  1908. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  1909. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  1910. }
  1911. efx_farch_init_common(efx);
  1912. return 0;
  1913. }
  1914. static void falcon_remove_nic(struct efx_nic *efx)
  1915. {
  1916. struct falcon_nic_data *nic_data = efx->nic_data;
  1917. struct falcon_board *board = falcon_board(efx);
  1918. board->type->fini(efx);
  1919. /* Remove I2C adapter and clear it in preparation for a retry */
  1920. i2c_del_adapter(&board->i2c_adap);
  1921. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1922. efx_nic_free_buffer(efx, &efx->irq_status);
  1923. __falcon_reset_hw(efx, RESET_TYPE_ALL);
  1924. /* Release the second function after the reset */
  1925. if (nic_data->pci_dev2) {
  1926. pci_dev_put(nic_data->pci_dev2);
  1927. nic_data->pci_dev2 = NULL;
  1928. }
  1929. /* Tear down the private nic state */
  1930. kfree(efx->nic_data);
  1931. efx->nic_data = NULL;
  1932. }
  1933. static void falcon_update_nic_stats(struct efx_nic *efx)
  1934. {
  1935. struct falcon_nic_data *nic_data = efx->nic_data;
  1936. efx_oword_t cnt;
  1937. if (nic_data->stats_disable_count)
  1938. return;
  1939. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  1940. efx->n_rx_nodesc_drop_cnt +=
  1941. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  1942. if (nic_data->stats_pending &&
  1943. *nic_data->stats_dma_done == FALCON_STATS_DONE) {
  1944. nic_data->stats_pending = false;
  1945. rmb(); /* read the done flag before the stats */
  1946. falcon_update_stats_xmac(efx);
  1947. }
  1948. }
  1949. void falcon_start_nic_stats(struct efx_nic *efx)
  1950. {
  1951. struct falcon_nic_data *nic_data = efx->nic_data;
  1952. spin_lock_bh(&efx->stats_lock);
  1953. if (--nic_data->stats_disable_count == 0)
  1954. falcon_stats_request(efx);
  1955. spin_unlock_bh(&efx->stats_lock);
  1956. }
  1957. void falcon_stop_nic_stats(struct efx_nic *efx)
  1958. {
  1959. struct falcon_nic_data *nic_data = efx->nic_data;
  1960. int i;
  1961. might_sleep();
  1962. spin_lock_bh(&efx->stats_lock);
  1963. ++nic_data->stats_disable_count;
  1964. spin_unlock_bh(&efx->stats_lock);
  1965. del_timer_sync(&nic_data->stats_timer);
  1966. /* Wait enough time for the most recent transfer to
  1967. * complete. */
  1968. for (i = 0; i < 4 && nic_data->stats_pending; i++) {
  1969. if (*nic_data->stats_dma_done == FALCON_STATS_DONE)
  1970. break;
  1971. msleep(1);
  1972. }
  1973. spin_lock_bh(&efx->stats_lock);
  1974. falcon_stats_complete(efx);
  1975. spin_unlock_bh(&efx->stats_lock);
  1976. }
  1977. static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  1978. {
  1979. falcon_board(efx)->type->set_id_led(efx, mode);
  1980. }
  1981. /**************************************************************************
  1982. *
  1983. * Wake on LAN
  1984. *
  1985. **************************************************************************
  1986. */
  1987. static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  1988. {
  1989. wol->supported = 0;
  1990. wol->wolopts = 0;
  1991. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1992. }
  1993. static int falcon_set_wol(struct efx_nic *efx, u32 type)
  1994. {
  1995. if (type != 0)
  1996. return -EINVAL;
  1997. return 0;
  1998. }
  1999. /**************************************************************************
  2000. *
  2001. * Revision-dependent attributes used by efx.c and nic.c
  2002. *
  2003. **************************************************************************
  2004. */
  2005. const struct efx_nic_type falcon_a1_nic_type = {
  2006. .mem_map_size = falcon_a1_mem_map_size,
  2007. .probe = falcon_probe_nic,
  2008. .remove = falcon_remove_nic,
  2009. .init = falcon_init_nic,
  2010. .dimension_resources = falcon_dimension_resources,
  2011. .fini = falcon_irq_ack_a1,
  2012. .monitor = falcon_monitor,
  2013. .map_reset_reason = falcon_map_reset_reason,
  2014. .map_reset_flags = falcon_map_reset_flags,
  2015. .reset = falcon_reset_hw,
  2016. .probe_port = falcon_probe_port,
  2017. .remove_port = falcon_remove_port,
  2018. .handle_global_event = falcon_handle_global_event,
  2019. .fini_dmaq = efx_farch_fini_dmaq,
  2020. .prepare_flush = falcon_prepare_flush,
  2021. .finish_flush = efx_port_dummy_op_void,
  2022. .update_stats = falcon_update_nic_stats,
  2023. .start_stats = falcon_start_nic_stats,
  2024. .stop_stats = falcon_stop_nic_stats,
  2025. .set_id_led = falcon_set_id_led,
  2026. .push_irq_moderation = falcon_push_irq_moderation,
  2027. .reconfigure_port = falcon_reconfigure_port,
  2028. .prepare_enable_fc_tx = falcon_a1_prepare_enable_fc_tx,
  2029. .reconfigure_mac = falcon_reconfigure_xmac,
  2030. .check_mac_fault = falcon_xmac_check_fault,
  2031. .get_wol = falcon_get_wol,
  2032. .set_wol = falcon_set_wol,
  2033. .resume_wol = efx_port_dummy_op_void,
  2034. .test_nvram = falcon_test_nvram,
  2035. .irq_enable_master = efx_farch_irq_enable_master,
  2036. .irq_test_generate = efx_farch_irq_test_generate,
  2037. .irq_disable_non_ev = efx_farch_irq_disable_master,
  2038. .irq_handle_msi = efx_farch_msi_interrupt,
  2039. .irq_handle_legacy = falcon_legacy_interrupt_a1,
  2040. .tx_probe = efx_farch_tx_probe,
  2041. .tx_init = efx_farch_tx_init,
  2042. .tx_remove = efx_farch_tx_remove,
  2043. .tx_write = efx_farch_tx_write,
  2044. .rx_push_indir_table = efx_farch_rx_push_indir_table,
  2045. .rx_probe = efx_farch_rx_probe,
  2046. .rx_init = efx_farch_rx_init,
  2047. .rx_remove = efx_farch_rx_remove,
  2048. .rx_write = efx_farch_rx_write,
  2049. .rx_defer_refill = efx_farch_rx_defer_refill,
  2050. .ev_probe = efx_farch_ev_probe,
  2051. .ev_init = efx_farch_ev_init,
  2052. .ev_fini = efx_farch_ev_fini,
  2053. .ev_remove = efx_farch_ev_remove,
  2054. .ev_process = efx_farch_ev_process,
  2055. .ev_read_ack = efx_farch_ev_read_ack,
  2056. .ev_test_generate = efx_farch_ev_test_generate,
  2057. /* We don't expose the filter table on Falcon A1 as it is not
  2058. * mapped into function 0, but these implementations still
  2059. * work with a degenerate case of all tables set to size 0.
  2060. */
  2061. .filter_table_probe = efx_farch_filter_table_probe,
  2062. .filter_table_restore = efx_farch_filter_table_restore,
  2063. .filter_table_remove = efx_farch_filter_table_remove,
  2064. .filter_insert = efx_farch_filter_insert,
  2065. .filter_remove_safe = efx_farch_filter_remove_safe,
  2066. .filter_get_safe = efx_farch_filter_get_safe,
  2067. .filter_clear_rx = efx_farch_filter_clear_rx,
  2068. .filter_count_rx_used = efx_farch_filter_count_rx_used,
  2069. .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit,
  2070. .filter_get_rx_ids = efx_farch_filter_get_rx_ids,
  2071. .revision = EFX_REV_FALCON_A1,
  2072. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  2073. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  2074. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  2075. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  2076. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  2077. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2078. .rx_buffer_padding = 0x24,
  2079. .can_rx_scatter = false,
  2080. .max_interrupt_mode = EFX_INT_MODE_MSI,
  2081. .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH,
  2082. .offload_features = NETIF_F_IP_CSUM,
  2083. .mcdi_max_ver = -1,
  2084. };
  2085. const struct efx_nic_type falcon_b0_nic_type = {
  2086. .mem_map_size = falcon_b0_mem_map_size,
  2087. .probe = falcon_probe_nic,
  2088. .remove = falcon_remove_nic,
  2089. .init = falcon_init_nic,
  2090. .dimension_resources = falcon_dimension_resources,
  2091. .fini = efx_port_dummy_op_void,
  2092. .monitor = falcon_monitor,
  2093. .map_reset_reason = falcon_map_reset_reason,
  2094. .map_reset_flags = falcon_map_reset_flags,
  2095. .reset = falcon_reset_hw,
  2096. .probe_port = falcon_probe_port,
  2097. .remove_port = falcon_remove_port,
  2098. .handle_global_event = falcon_handle_global_event,
  2099. .fini_dmaq = efx_farch_fini_dmaq,
  2100. .prepare_flush = falcon_prepare_flush,
  2101. .finish_flush = efx_port_dummy_op_void,
  2102. .update_stats = falcon_update_nic_stats,
  2103. .start_stats = falcon_start_nic_stats,
  2104. .stop_stats = falcon_stop_nic_stats,
  2105. .set_id_led = falcon_set_id_led,
  2106. .push_irq_moderation = falcon_push_irq_moderation,
  2107. .reconfigure_port = falcon_reconfigure_port,
  2108. .prepare_enable_fc_tx = falcon_b0_prepare_enable_fc_tx,
  2109. .reconfigure_mac = falcon_reconfigure_xmac,
  2110. .check_mac_fault = falcon_xmac_check_fault,
  2111. .get_wol = falcon_get_wol,
  2112. .set_wol = falcon_set_wol,
  2113. .resume_wol = efx_port_dummy_op_void,
  2114. .test_chip = falcon_b0_test_chip,
  2115. .test_nvram = falcon_test_nvram,
  2116. .irq_enable_master = efx_farch_irq_enable_master,
  2117. .irq_test_generate = efx_farch_irq_test_generate,
  2118. .irq_disable_non_ev = efx_farch_irq_disable_master,
  2119. .irq_handle_msi = efx_farch_msi_interrupt,
  2120. .irq_handle_legacy = efx_farch_legacy_interrupt,
  2121. .tx_probe = efx_farch_tx_probe,
  2122. .tx_init = efx_farch_tx_init,
  2123. .tx_remove = efx_farch_tx_remove,
  2124. .tx_write = efx_farch_tx_write,
  2125. .rx_push_indir_table = efx_farch_rx_push_indir_table,
  2126. .rx_probe = efx_farch_rx_probe,
  2127. .rx_init = efx_farch_rx_init,
  2128. .rx_remove = efx_farch_rx_remove,
  2129. .rx_write = efx_farch_rx_write,
  2130. .rx_defer_refill = efx_farch_rx_defer_refill,
  2131. .ev_probe = efx_farch_ev_probe,
  2132. .ev_init = efx_farch_ev_init,
  2133. .ev_fini = efx_farch_ev_fini,
  2134. .ev_remove = efx_farch_ev_remove,
  2135. .ev_process = efx_farch_ev_process,
  2136. .ev_read_ack = efx_farch_ev_read_ack,
  2137. .ev_test_generate = efx_farch_ev_test_generate,
  2138. .filter_table_probe = efx_farch_filter_table_probe,
  2139. .filter_table_restore = efx_farch_filter_table_restore,
  2140. .filter_table_remove = efx_farch_filter_table_remove,
  2141. .filter_update_rx_scatter = efx_farch_filter_update_rx_scatter,
  2142. .filter_insert = efx_farch_filter_insert,
  2143. .filter_remove_safe = efx_farch_filter_remove_safe,
  2144. .filter_get_safe = efx_farch_filter_get_safe,
  2145. .filter_clear_rx = efx_farch_filter_clear_rx,
  2146. .filter_count_rx_used = efx_farch_filter_count_rx_used,
  2147. .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit,
  2148. .filter_get_rx_ids = efx_farch_filter_get_rx_ids,
  2149. #ifdef CONFIG_RFS_ACCEL
  2150. .filter_rfs_insert = efx_farch_filter_rfs_insert,
  2151. .filter_rfs_expire_one = efx_farch_filter_rfs_expire_one,
  2152. #endif
  2153. .revision = EFX_REV_FALCON_B0,
  2154. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  2155. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  2156. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  2157. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  2158. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  2159. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2160. .rx_buffer_hash_size = 0x10,
  2161. .rx_buffer_padding = 0,
  2162. .can_rx_scatter = true,
  2163. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  2164. .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH,
  2165. .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH | NETIF_F_NTUPLE,
  2166. .mcdi_max_ver = -1,
  2167. .max_rx_ip_filters = FR_BZ_RX_FILTER_TBL0_ROWS,
  2168. };