falcon.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520
  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->unicast_filter,
  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. efx_farch_filter_sync_rx_mode(efx);
  753. falcon_reconfigure_xgxs_core(efx);
  754. falcon_reconfigure_xmac_core(efx);
  755. falcon_reconfigure_mac_wrapper(efx);
  756. nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 5);
  757. falcon_ack_status_intr(efx);
  758. return 0;
  759. }
  760. static void falcon_update_stats_xmac(struct efx_nic *efx)
  761. {
  762. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  763. /* Update MAC stats from DMAed values */
  764. FALCON_STAT(efx, XgRxOctets, rx_bytes);
  765. FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes);
  766. FALCON_STAT(efx, XgRxPkts, rx_packets);
  767. FALCON_STAT(efx, XgRxPktsOK, rx_good);
  768. FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast);
  769. FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast);
  770. FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast);
  771. FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64);
  772. FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo);
  773. FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo);
  774. FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64);
  775. FALCON_STAT(efx, XgRxDropEvents, rx_overflow);
  776. FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad);
  777. FALCON_STAT(efx, XgRxAlignError, rx_align_error);
  778. FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error);
  779. FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error);
  780. FALCON_STAT(efx, XgRxControlPkts, rx_control);
  781. FALCON_STAT(efx, XgRxPausePkts, rx_pause);
  782. FALCON_STAT(efx, XgRxPkts64Octets, rx_64);
  783. FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127);
  784. FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255);
  785. FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511);
  786. FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023);
  787. FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx);
  788. FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo);
  789. FALCON_STAT(efx, XgRxLengthError, rx_length_error);
  790. FALCON_STAT(efx, XgTxPkts, tx_packets);
  791. FALCON_STAT(efx, XgTxOctets, tx_bytes);
  792. FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast);
  793. FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast);
  794. FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast);
  795. FALCON_STAT(efx, XgTxControlPkts, tx_control);
  796. FALCON_STAT(efx, XgTxPausePkts, tx_pause);
  797. FALCON_STAT(efx, XgTxPkts64Octets, tx_64);
  798. FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127);
  799. FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255);
  800. FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511);
  801. FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023);
  802. FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx);
  803. FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo);
  804. FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64);
  805. FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo);
  806. FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp);
  807. FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error);
  808. FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error);
  809. /* Update derived statistics */
  810. efx_update_diff_stat(&mac_stats->tx_good_bytes,
  811. mac_stats->tx_bytes - mac_stats->tx_bad_bytes -
  812. mac_stats->tx_control * 64);
  813. efx_update_diff_stat(&mac_stats->rx_bad_bytes,
  814. mac_stats->rx_bytes - mac_stats->rx_good_bytes -
  815. mac_stats->rx_control * 64);
  816. }
  817. static void falcon_poll_xmac(struct efx_nic *efx)
  818. {
  819. struct falcon_nic_data *nic_data = efx->nic_data;
  820. /* We expect xgmii faults if the wireside link is down */
  821. if (!efx->link_state.up || !nic_data->xmac_poll_required)
  822. return;
  823. nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 1);
  824. falcon_ack_status_intr(efx);
  825. }
  826. /**************************************************************************
  827. *
  828. * MAC wrapper
  829. *
  830. **************************************************************************
  831. */
  832. static void falcon_push_multicast_hash(struct efx_nic *efx)
  833. {
  834. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  835. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  836. efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0);
  837. efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1);
  838. }
  839. static void falcon_reset_macs(struct efx_nic *efx)
  840. {
  841. struct falcon_nic_data *nic_data = efx->nic_data;
  842. efx_oword_t reg, mac_ctrl;
  843. int count;
  844. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
  845. /* It's not safe to use GLB_CTL_REG to reset the
  846. * macs, so instead use the internal MAC resets
  847. */
  848. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1);
  849. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  850. for (count = 0; count < 10000; count++) {
  851. efx_reado(efx, &reg, FR_AB_XM_GLB_CFG);
  852. if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) ==
  853. 0)
  854. return;
  855. udelay(10);
  856. }
  857. netif_err(efx, hw, efx->net_dev,
  858. "timed out waiting for XMAC core reset\n");
  859. }
  860. /* Mac stats will fail whist the TX fifo is draining */
  861. WARN_ON(nic_data->stats_disable_count == 0);
  862. efx_reado(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  863. EFX_SET_OWORD_FIELD(mac_ctrl, FRF_BB_TXFIFO_DRAIN_EN, 1);
  864. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  865. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  866. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1);
  867. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1);
  868. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1);
  869. efx_writeo(efx, &reg, FR_AB_GLB_CTL);
  870. count = 0;
  871. while (1) {
  872. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  873. if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) &&
  874. !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) &&
  875. !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) {
  876. netif_dbg(efx, hw, efx->net_dev,
  877. "Completed MAC reset after %d loops\n",
  878. count);
  879. break;
  880. }
  881. if (count > 20) {
  882. netif_err(efx, hw, efx->net_dev, "MAC reset failed\n");
  883. break;
  884. }
  885. count++;
  886. udelay(10);
  887. }
  888. /* Ensure the correct MAC is selected before statistics
  889. * are re-enabled by the caller */
  890. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  891. falcon_setup_xaui(efx);
  892. }
  893. static void falcon_drain_tx_fifo(struct efx_nic *efx)
  894. {
  895. efx_oword_t reg;
  896. if ((efx_nic_rev(efx) < EFX_REV_FALCON_B0) ||
  897. (efx->loopback_mode != LOOPBACK_NONE))
  898. return;
  899. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  900. /* There is no point in draining more than once */
  901. if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN))
  902. return;
  903. falcon_reset_macs(efx);
  904. }
  905. static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
  906. {
  907. efx_oword_t reg;
  908. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  909. return;
  910. /* Isolate the MAC -> RX */
  911. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  912. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0);
  913. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  914. /* Isolate TX -> MAC */
  915. falcon_drain_tx_fifo(efx);
  916. }
  917. static void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
  918. {
  919. struct efx_link_state *link_state = &efx->link_state;
  920. efx_oword_t reg;
  921. int link_speed, isolate;
  922. isolate = !!ACCESS_ONCE(efx->reset_pending);
  923. switch (link_state->speed) {
  924. case 10000: link_speed = 3; break;
  925. case 1000: link_speed = 2; break;
  926. case 100: link_speed = 1; break;
  927. default: link_speed = 0; break;
  928. }
  929. /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
  930. * as advertised. Disable to ensure packets are not
  931. * indefinitely held and TX queue can be flushed at any point
  932. * while the link is down. */
  933. EFX_POPULATE_OWORD_5(reg,
  934. FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */,
  935. FRF_AB_MAC_BCAD_ACPT, 1,
  936. FRF_AB_MAC_UC_PROM, !efx->unicast_filter,
  937. FRF_AB_MAC_LINK_STATUS, 1, /* always set */
  938. FRF_AB_MAC_SPEED, link_speed);
  939. /* On B0, MAC backpressure can be disabled and packets get
  940. * discarded. */
  941. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  942. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN,
  943. !link_state->up || isolate);
  944. }
  945. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  946. /* Restore the multicast hash registers. */
  947. falcon_push_multicast_hash(efx);
  948. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  949. /* Enable XOFF signal from RX FIFO (we enabled it during NIC
  950. * initialisation but it may read back as 0) */
  951. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  952. /* Unisolate the MAC -> RX */
  953. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  954. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, !isolate);
  955. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  956. }
  957. static void falcon_stats_request(struct efx_nic *efx)
  958. {
  959. struct falcon_nic_data *nic_data = efx->nic_data;
  960. efx_oword_t reg;
  961. WARN_ON(nic_data->stats_pending);
  962. WARN_ON(nic_data->stats_disable_count);
  963. if (nic_data->stats_dma_done == NULL)
  964. return; /* no mac selected */
  965. *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE;
  966. nic_data->stats_pending = true;
  967. wmb(); /* ensure done flag is clear */
  968. /* Initiate DMA transfer of stats */
  969. EFX_POPULATE_OWORD_2(reg,
  970. FRF_AB_MAC_STAT_DMA_CMD, 1,
  971. FRF_AB_MAC_STAT_DMA_ADR,
  972. efx->stats_buffer.dma_addr);
  973. efx_writeo(efx, &reg, FR_AB_MAC_STAT_DMA);
  974. mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2));
  975. }
  976. static void falcon_stats_complete(struct efx_nic *efx)
  977. {
  978. struct falcon_nic_data *nic_data = efx->nic_data;
  979. if (!nic_data->stats_pending)
  980. return;
  981. nic_data->stats_pending = false;
  982. if (*nic_data->stats_dma_done == FALCON_STATS_DONE) {
  983. rmb(); /* read the done flag before the stats */
  984. falcon_update_stats_xmac(efx);
  985. } else {
  986. netif_err(efx, hw, efx->net_dev,
  987. "timed out waiting for statistics\n");
  988. }
  989. }
  990. static void falcon_stats_timer_func(unsigned long context)
  991. {
  992. struct efx_nic *efx = (struct efx_nic *)context;
  993. struct falcon_nic_data *nic_data = efx->nic_data;
  994. spin_lock(&efx->stats_lock);
  995. falcon_stats_complete(efx);
  996. if (nic_data->stats_disable_count == 0)
  997. falcon_stats_request(efx);
  998. spin_unlock(&efx->stats_lock);
  999. }
  1000. static bool falcon_loopback_link_poll(struct efx_nic *efx)
  1001. {
  1002. struct efx_link_state old_state = efx->link_state;
  1003. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1004. WARN_ON(!LOOPBACK_INTERNAL(efx));
  1005. efx->link_state.fd = true;
  1006. efx->link_state.fc = efx->wanted_fc;
  1007. efx->link_state.up = true;
  1008. efx->link_state.speed = 10000;
  1009. return !efx_link_state_equal(&efx->link_state, &old_state);
  1010. }
  1011. static int falcon_reconfigure_port(struct efx_nic *efx)
  1012. {
  1013. int rc;
  1014. WARN_ON(efx_nic_rev(efx) > EFX_REV_FALCON_B0);
  1015. /* Poll the PHY link state *before* reconfiguring it. This means we
  1016. * will pick up the correct speed (in loopback) to select the correct
  1017. * MAC.
  1018. */
  1019. if (LOOPBACK_INTERNAL(efx))
  1020. falcon_loopback_link_poll(efx);
  1021. else
  1022. efx->phy_op->poll(efx);
  1023. falcon_stop_nic_stats(efx);
  1024. falcon_deconfigure_mac_wrapper(efx);
  1025. falcon_reset_macs(efx);
  1026. efx->phy_op->reconfigure(efx);
  1027. rc = falcon_reconfigure_xmac(efx);
  1028. BUG_ON(rc);
  1029. falcon_start_nic_stats(efx);
  1030. /* Synchronise efx->link_state with the kernel */
  1031. efx_link_status_changed(efx);
  1032. return 0;
  1033. }
  1034. /* TX flow control may automatically turn itself off if the link
  1035. * partner (intermittently) stops responding to pause frames. There
  1036. * isn't any indication that this has happened, so the best we do is
  1037. * leave it up to the user to spot this and fix it by cycling transmit
  1038. * flow control on this end.
  1039. */
  1040. static void falcon_a1_prepare_enable_fc_tx(struct efx_nic *efx)
  1041. {
  1042. /* Schedule a reset to recover */
  1043. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  1044. }
  1045. static void falcon_b0_prepare_enable_fc_tx(struct efx_nic *efx)
  1046. {
  1047. /* Recover by resetting the EM block */
  1048. falcon_stop_nic_stats(efx);
  1049. falcon_drain_tx_fifo(efx);
  1050. falcon_reconfigure_xmac(efx);
  1051. falcon_start_nic_stats(efx);
  1052. }
  1053. /**************************************************************************
  1054. *
  1055. * PHY access via GMII
  1056. *
  1057. **************************************************************************
  1058. */
  1059. /* Wait for GMII access to complete */
  1060. static int falcon_gmii_wait(struct efx_nic *efx)
  1061. {
  1062. efx_oword_t md_stat;
  1063. int count;
  1064. /* wait up to 50ms - taken max from datasheet */
  1065. for (count = 0; count < 5000; count++) {
  1066. efx_reado(efx, &md_stat, FR_AB_MD_STAT);
  1067. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) {
  1068. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 ||
  1069. EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) {
  1070. netif_err(efx, hw, efx->net_dev,
  1071. "error from GMII access "
  1072. EFX_OWORD_FMT"\n",
  1073. EFX_OWORD_VAL(md_stat));
  1074. return -EIO;
  1075. }
  1076. return 0;
  1077. }
  1078. udelay(10);
  1079. }
  1080. netif_err(efx, hw, efx->net_dev, "timed out waiting for GMII\n");
  1081. return -ETIMEDOUT;
  1082. }
  1083. /* Write an MDIO register of a PHY connected to Falcon. */
  1084. static int falcon_mdio_write(struct net_device *net_dev,
  1085. int prtad, int devad, u16 addr, u16 value)
  1086. {
  1087. struct efx_nic *efx = netdev_priv(net_dev);
  1088. struct falcon_nic_data *nic_data = efx->nic_data;
  1089. efx_oword_t reg;
  1090. int rc;
  1091. netif_vdbg(efx, hw, efx->net_dev,
  1092. "writing MDIO %d register %d.%d with 0x%04x\n",
  1093. prtad, devad, addr, value);
  1094. mutex_lock(&nic_data->mdio_lock);
  1095. /* Check MDIO not currently being accessed */
  1096. rc = falcon_gmii_wait(efx);
  1097. if (rc)
  1098. goto out;
  1099. /* Write the address/ID register */
  1100. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1101. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1102. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1103. FRF_AB_MD_DEV_ADR, devad);
  1104. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1105. /* Write data */
  1106. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value);
  1107. efx_writeo(efx, &reg, FR_AB_MD_TXD);
  1108. EFX_POPULATE_OWORD_2(reg,
  1109. FRF_AB_MD_WRC, 1,
  1110. FRF_AB_MD_GC, 0);
  1111. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1112. /* Wait for data to be written */
  1113. rc = falcon_gmii_wait(efx);
  1114. if (rc) {
  1115. /* Abort the write operation */
  1116. EFX_POPULATE_OWORD_2(reg,
  1117. FRF_AB_MD_WRC, 0,
  1118. FRF_AB_MD_GC, 1);
  1119. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1120. udelay(10);
  1121. }
  1122. out:
  1123. mutex_unlock(&nic_data->mdio_lock);
  1124. return rc;
  1125. }
  1126. /* Read an MDIO register of a PHY connected to Falcon. */
  1127. static int falcon_mdio_read(struct net_device *net_dev,
  1128. int prtad, int devad, u16 addr)
  1129. {
  1130. struct efx_nic *efx = netdev_priv(net_dev);
  1131. struct falcon_nic_data *nic_data = efx->nic_data;
  1132. efx_oword_t reg;
  1133. int rc;
  1134. mutex_lock(&nic_data->mdio_lock);
  1135. /* Check MDIO not currently being accessed */
  1136. rc = falcon_gmii_wait(efx);
  1137. if (rc)
  1138. goto out;
  1139. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1140. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1141. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1142. FRF_AB_MD_DEV_ADR, devad);
  1143. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1144. /* Request data to be read */
  1145. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
  1146. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1147. /* Wait for data to become available */
  1148. rc = falcon_gmii_wait(efx);
  1149. if (rc == 0) {
  1150. efx_reado(efx, &reg, FR_AB_MD_RXD);
  1151. rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
  1152. netif_vdbg(efx, hw, efx->net_dev,
  1153. "read from MDIO %d register %d.%d, got %04x\n",
  1154. prtad, devad, addr, rc);
  1155. } else {
  1156. /* Abort the read operation */
  1157. EFX_POPULATE_OWORD_2(reg,
  1158. FRF_AB_MD_RIC, 0,
  1159. FRF_AB_MD_GC, 1);
  1160. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1161. netif_dbg(efx, hw, efx->net_dev,
  1162. "read from MDIO %d register %d.%d, got error %d\n",
  1163. prtad, devad, addr, rc);
  1164. }
  1165. out:
  1166. mutex_unlock(&nic_data->mdio_lock);
  1167. return rc;
  1168. }
  1169. /* This call is responsible for hooking in the MAC and PHY operations */
  1170. static int falcon_probe_port(struct efx_nic *efx)
  1171. {
  1172. struct falcon_nic_data *nic_data = efx->nic_data;
  1173. int rc;
  1174. switch (efx->phy_type) {
  1175. case PHY_TYPE_SFX7101:
  1176. efx->phy_op = &falcon_sfx7101_phy_ops;
  1177. break;
  1178. case PHY_TYPE_QT2022C2:
  1179. case PHY_TYPE_QT2025C:
  1180. efx->phy_op = &falcon_qt202x_phy_ops;
  1181. break;
  1182. case PHY_TYPE_TXC43128:
  1183. efx->phy_op = &falcon_txc_phy_ops;
  1184. break;
  1185. default:
  1186. netif_err(efx, probe, efx->net_dev, "Unknown PHY type %d\n",
  1187. efx->phy_type);
  1188. return -ENODEV;
  1189. }
  1190. /* Fill out MDIO structure and loopback modes */
  1191. mutex_init(&nic_data->mdio_lock);
  1192. efx->mdio.mdio_read = falcon_mdio_read;
  1193. efx->mdio.mdio_write = falcon_mdio_write;
  1194. rc = efx->phy_op->probe(efx);
  1195. if (rc != 0)
  1196. return rc;
  1197. /* Initial assumption */
  1198. efx->link_state.speed = 10000;
  1199. efx->link_state.fd = true;
  1200. /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
  1201. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1202. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  1203. else
  1204. efx->wanted_fc = EFX_FC_RX;
  1205. if (efx->mdio.mmds & MDIO_DEVS_AN)
  1206. efx->wanted_fc |= EFX_FC_AUTO;
  1207. /* Allocate buffer for stats */
  1208. rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
  1209. FALCON_MAC_STATS_SIZE, GFP_KERNEL);
  1210. if (rc)
  1211. return rc;
  1212. netif_dbg(efx, probe, efx->net_dev,
  1213. "stats buffer at %llx (virt %p phys %llx)\n",
  1214. (u64)efx->stats_buffer.dma_addr,
  1215. efx->stats_buffer.addr,
  1216. (u64)virt_to_phys(efx->stats_buffer.addr));
  1217. nic_data->stats_dma_done = efx->stats_buffer.addr + XgDmaDone_offset;
  1218. return 0;
  1219. }
  1220. static void falcon_remove_port(struct efx_nic *efx)
  1221. {
  1222. efx->phy_op->remove(efx);
  1223. efx_nic_free_buffer(efx, &efx->stats_buffer);
  1224. }
  1225. /* Global events are basically PHY events */
  1226. static bool
  1227. falcon_handle_global_event(struct efx_channel *channel, efx_qword_t *event)
  1228. {
  1229. struct efx_nic *efx = channel->efx;
  1230. struct falcon_nic_data *nic_data = efx->nic_data;
  1231. if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
  1232. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
  1233. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR))
  1234. /* Ignored */
  1235. return true;
  1236. if ((efx_nic_rev(efx) == EFX_REV_FALCON_B0) &&
  1237. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
  1238. nic_data->xmac_poll_required = true;
  1239. return true;
  1240. }
  1241. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ?
  1242. EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
  1243. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
  1244. netif_err(efx, rx_err, efx->net_dev,
  1245. "channel %d seen global RX_RESET event. Resetting.\n",
  1246. channel->channel);
  1247. atomic_inc(&efx->rx_reset);
  1248. efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
  1249. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  1250. return true;
  1251. }
  1252. return false;
  1253. }
  1254. /**************************************************************************
  1255. *
  1256. * Falcon test code
  1257. *
  1258. **************************************************************************/
  1259. static int
  1260. falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
  1261. {
  1262. struct falcon_nic_data *nic_data = efx->nic_data;
  1263. struct falcon_nvconfig *nvconfig;
  1264. struct efx_spi_device *spi;
  1265. void *region;
  1266. int rc, magic_num, struct_ver;
  1267. __le16 *word, *limit;
  1268. u32 csum;
  1269. if (efx_spi_present(&nic_data->spi_flash))
  1270. spi = &nic_data->spi_flash;
  1271. else if (efx_spi_present(&nic_data->spi_eeprom))
  1272. spi = &nic_data->spi_eeprom;
  1273. else
  1274. return -EINVAL;
  1275. region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
  1276. if (!region)
  1277. return -ENOMEM;
  1278. nvconfig = region + FALCON_NVCONFIG_OFFSET;
  1279. mutex_lock(&nic_data->spi_lock);
  1280. rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region);
  1281. mutex_unlock(&nic_data->spi_lock);
  1282. if (rc) {
  1283. netif_err(efx, hw, efx->net_dev, "Failed to read %s\n",
  1284. efx_spi_present(&nic_data->spi_flash) ?
  1285. "flash" : "EEPROM");
  1286. rc = -EIO;
  1287. goto out;
  1288. }
  1289. magic_num = le16_to_cpu(nvconfig->board_magic_num);
  1290. struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
  1291. rc = -EINVAL;
  1292. if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
  1293. netif_err(efx, hw, efx->net_dev,
  1294. "NVRAM bad magic 0x%x\n", magic_num);
  1295. goto out;
  1296. }
  1297. if (struct_ver < 2) {
  1298. netif_err(efx, hw, efx->net_dev,
  1299. "NVRAM has ancient version 0x%x\n", struct_ver);
  1300. goto out;
  1301. } else if (struct_ver < 4) {
  1302. word = &nvconfig->board_magic_num;
  1303. limit = (__le16 *) (nvconfig + 1);
  1304. } else {
  1305. word = region;
  1306. limit = region + FALCON_NVCONFIG_END;
  1307. }
  1308. for (csum = 0; word < limit; ++word)
  1309. csum += le16_to_cpu(*word);
  1310. if (~csum & 0xffff) {
  1311. netif_err(efx, hw, efx->net_dev,
  1312. "NVRAM has incorrect checksum\n");
  1313. goto out;
  1314. }
  1315. rc = 0;
  1316. if (nvconfig_out)
  1317. memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
  1318. out:
  1319. kfree(region);
  1320. return rc;
  1321. }
  1322. static int falcon_test_nvram(struct efx_nic *efx)
  1323. {
  1324. return falcon_read_nvram(efx, NULL);
  1325. }
  1326. static const struct efx_farch_register_test falcon_b0_register_tests[] = {
  1327. { FR_AZ_ADR_REGION,
  1328. EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
  1329. { FR_AZ_RX_CFG,
  1330. EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
  1331. { FR_AZ_TX_CFG,
  1332. EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
  1333. { FR_AZ_TX_RESERVED,
  1334. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  1335. { FR_AB_MAC_CTRL,
  1336. EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
  1337. { FR_AZ_SRM_TX_DC_CFG,
  1338. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  1339. { FR_AZ_RX_DC_CFG,
  1340. EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
  1341. { FR_AZ_RX_DC_PF_WM,
  1342. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  1343. { FR_BZ_DP_CTRL,
  1344. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  1345. { FR_AB_GM_CFG2,
  1346. EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
  1347. { FR_AB_GMF_CFG0,
  1348. EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
  1349. { FR_AB_XM_GLB_CFG,
  1350. EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
  1351. { FR_AB_XM_TX_CFG,
  1352. EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
  1353. { FR_AB_XM_RX_CFG,
  1354. EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
  1355. { FR_AB_XM_RX_PARAM,
  1356. EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
  1357. { FR_AB_XM_FC,
  1358. EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
  1359. { FR_AB_XM_ADR_LO,
  1360. EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
  1361. { FR_AB_XX_SD_CTL,
  1362. EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
  1363. };
  1364. static int
  1365. falcon_b0_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
  1366. {
  1367. enum reset_type reset_method = RESET_TYPE_INVISIBLE;
  1368. int rc, rc2;
  1369. mutex_lock(&efx->mac_lock);
  1370. if (efx->loopback_modes) {
  1371. /* We need the 312 clock from the PHY to test the XMAC
  1372. * registers, so move into XGMII loopback if available */
  1373. if (efx->loopback_modes & (1 << LOOPBACK_XGMII))
  1374. efx->loopback_mode = LOOPBACK_XGMII;
  1375. else
  1376. efx->loopback_mode = __ffs(efx->loopback_modes);
  1377. }
  1378. __efx_reconfigure_port(efx);
  1379. mutex_unlock(&efx->mac_lock);
  1380. efx_reset_down(efx, reset_method);
  1381. tests->registers =
  1382. efx_farch_test_registers(efx, falcon_b0_register_tests,
  1383. ARRAY_SIZE(falcon_b0_register_tests))
  1384. ? -1 : 1;
  1385. rc = falcon_reset_hw(efx, reset_method);
  1386. rc2 = efx_reset_up(efx, reset_method, rc == 0);
  1387. return rc ? rc : rc2;
  1388. }
  1389. /**************************************************************************
  1390. *
  1391. * Device reset
  1392. *
  1393. **************************************************************************
  1394. */
  1395. static enum reset_type falcon_map_reset_reason(enum reset_type reason)
  1396. {
  1397. switch (reason) {
  1398. case RESET_TYPE_RX_RECOVERY:
  1399. case RESET_TYPE_RX_DESC_FETCH:
  1400. case RESET_TYPE_TX_DESC_FETCH:
  1401. case RESET_TYPE_TX_SKIP:
  1402. /* These can occasionally occur due to hardware bugs.
  1403. * We try to reset without disrupting the link.
  1404. */
  1405. return RESET_TYPE_INVISIBLE;
  1406. default:
  1407. return RESET_TYPE_ALL;
  1408. }
  1409. }
  1410. static int falcon_map_reset_flags(u32 *flags)
  1411. {
  1412. enum {
  1413. FALCON_RESET_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER |
  1414. ETH_RESET_OFFLOAD | ETH_RESET_MAC),
  1415. FALCON_RESET_ALL = FALCON_RESET_INVISIBLE | ETH_RESET_PHY,
  1416. FALCON_RESET_WORLD = FALCON_RESET_ALL | ETH_RESET_IRQ,
  1417. };
  1418. if ((*flags & FALCON_RESET_WORLD) == FALCON_RESET_WORLD) {
  1419. *flags &= ~FALCON_RESET_WORLD;
  1420. return RESET_TYPE_WORLD;
  1421. }
  1422. if ((*flags & FALCON_RESET_ALL) == FALCON_RESET_ALL) {
  1423. *flags &= ~FALCON_RESET_ALL;
  1424. return RESET_TYPE_ALL;
  1425. }
  1426. if ((*flags & FALCON_RESET_INVISIBLE) == FALCON_RESET_INVISIBLE) {
  1427. *flags &= ~FALCON_RESET_INVISIBLE;
  1428. return RESET_TYPE_INVISIBLE;
  1429. }
  1430. return -EINVAL;
  1431. }
  1432. /* Resets NIC to known state. This routine must be called in process
  1433. * context and is allowed to sleep. */
  1434. static int __falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  1435. {
  1436. struct falcon_nic_data *nic_data = efx->nic_data;
  1437. efx_oword_t glb_ctl_reg_ker;
  1438. int rc;
  1439. netif_dbg(efx, hw, efx->net_dev, "performing %s hardware reset\n",
  1440. RESET_TYPE(method));
  1441. /* Initiate device reset */
  1442. if (method == RESET_TYPE_WORLD) {
  1443. rc = pci_save_state(efx->pci_dev);
  1444. if (rc) {
  1445. netif_err(efx, drv, efx->net_dev,
  1446. "failed to backup PCI state of primary "
  1447. "function prior to hardware reset\n");
  1448. goto fail1;
  1449. }
  1450. if (efx_nic_is_dual_func(efx)) {
  1451. rc = pci_save_state(nic_data->pci_dev2);
  1452. if (rc) {
  1453. netif_err(efx, drv, efx->net_dev,
  1454. "failed to backup PCI state of "
  1455. "secondary function prior to "
  1456. "hardware reset\n");
  1457. goto fail2;
  1458. }
  1459. }
  1460. EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
  1461. FRF_AB_EXT_PHY_RST_DUR,
  1462. FFE_AB_EXT_PHY_RST_DUR_10240US,
  1463. FRF_AB_SWRST, 1);
  1464. } else {
  1465. EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
  1466. /* exclude PHY from "invisible" reset */
  1467. FRF_AB_EXT_PHY_RST_CTL,
  1468. method == RESET_TYPE_INVISIBLE,
  1469. /* exclude EEPROM/flash and PCIe */
  1470. FRF_AB_PCIE_CORE_RST_CTL, 1,
  1471. FRF_AB_PCIE_NSTKY_RST_CTL, 1,
  1472. FRF_AB_PCIE_SD_RST_CTL, 1,
  1473. FRF_AB_EE_RST_CTL, 1,
  1474. FRF_AB_EXT_PHY_RST_DUR,
  1475. FFE_AB_EXT_PHY_RST_DUR_10240US,
  1476. FRF_AB_SWRST, 1);
  1477. }
  1478. efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  1479. netif_dbg(efx, hw, efx->net_dev, "waiting for hardware reset\n");
  1480. schedule_timeout_uninterruptible(HZ / 20);
  1481. /* Restore PCI configuration if needed */
  1482. if (method == RESET_TYPE_WORLD) {
  1483. if (efx_nic_is_dual_func(efx))
  1484. pci_restore_state(nic_data->pci_dev2);
  1485. pci_restore_state(efx->pci_dev);
  1486. netif_dbg(efx, drv, efx->net_dev,
  1487. "successfully restored PCI config\n");
  1488. }
  1489. /* Assert that reset complete */
  1490. efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  1491. if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
  1492. rc = -ETIMEDOUT;
  1493. netif_err(efx, hw, efx->net_dev,
  1494. "timed out waiting for hardware reset\n");
  1495. goto fail3;
  1496. }
  1497. netif_dbg(efx, hw, efx->net_dev, "hardware reset complete\n");
  1498. return 0;
  1499. /* pci_save_state() and pci_restore_state() MUST be called in pairs */
  1500. fail2:
  1501. pci_restore_state(efx->pci_dev);
  1502. fail1:
  1503. fail3:
  1504. return rc;
  1505. }
  1506. static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  1507. {
  1508. struct falcon_nic_data *nic_data = efx->nic_data;
  1509. int rc;
  1510. mutex_lock(&nic_data->spi_lock);
  1511. rc = __falcon_reset_hw(efx, method);
  1512. mutex_unlock(&nic_data->spi_lock);
  1513. return rc;
  1514. }
  1515. static void falcon_monitor(struct efx_nic *efx)
  1516. {
  1517. bool link_changed;
  1518. int rc;
  1519. BUG_ON(!mutex_is_locked(&efx->mac_lock));
  1520. rc = falcon_board(efx)->type->monitor(efx);
  1521. if (rc) {
  1522. netif_err(efx, hw, efx->net_dev,
  1523. "Board sensor %s; shutting down PHY\n",
  1524. (rc == -ERANGE) ? "reported fault" : "failed");
  1525. efx->phy_mode |= PHY_MODE_LOW_POWER;
  1526. rc = __efx_reconfigure_port(efx);
  1527. WARN_ON(rc);
  1528. }
  1529. if (LOOPBACK_INTERNAL(efx))
  1530. link_changed = falcon_loopback_link_poll(efx);
  1531. else
  1532. link_changed = efx->phy_op->poll(efx);
  1533. if (link_changed) {
  1534. falcon_stop_nic_stats(efx);
  1535. falcon_deconfigure_mac_wrapper(efx);
  1536. falcon_reset_macs(efx);
  1537. rc = falcon_reconfigure_xmac(efx);
  1538. BUG_ON(rc);
  1539. falcon_start_nic_stats(efx);
  1540. efx_link_status_changed(efx);
  1541. }
  1542. falcon_poll_xmac(efx);
  1543. }
  1544. /* Zeroes out the SRAM contents. This routine must be called in
  1545. * process context and is allowed to sleep.
  1546. */
  1547. static int falcon_reset_sram(struct efx_nic *efx)
  1548. {
  1549. efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
  1550. int count;
  1551. /* Set the SRAM wake/sleep GPIO appropriately. */
  1552. efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1553. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
  1554. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
  1555. efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1556. /* Initiate SRAM reset */
  1557. EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
  1558. FRF_AZ_SRM_INIT_EN, 1,
  1559. FRF_AZ_SRM_NB_SZ, 0);
  1560. efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1561. /* Wait for SRAM reset to complete */
  1562. count = 0;
  1563. do {
  1564. netif_dbg(efx, hw, efx->net_dev,
  1565. "waiting for SRAM reset (attempt %d)...\n", count);
  1566. /* SRAM reset is slow; expect around 16ms */
  1567. schedule_timeout_uninterruptible(HZ / 50);
  1568. /* Check for reset complete */
  1569. efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1570. if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
  1571. netif_dbg(efx, hw, efx->net_dev,
  1572. "SRAM reset complete\n");
  1573. return 0;
  1574. }
  1575. } while (++count < 20); /* wait up to 0.4 sec */
  1576. netif_err(efx, hw, efx->net_dev, "timed out waiting for SRAM reset\n");
  1577. return -ETIMEDOUT;
  1578. }
  1579. static void falcon_spi_device_init(struct efx_nic *efx,
  1580. struct efx_spi_device *spi_device,
  1581. unsigned int device_id, u32 device_type)
  1582. {
  1583. if (device_type != 0) {
  1584. spi_device->device_id = device_id;
  1585. spi_device->size =
  1586. 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
  1587. spi_device->addr_len =
  1588. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
  1589. spi_device->munge_address = (spi_device->size == 1 << 9 &&
  1590. spi_device->addr_len == 1);
  1591. spi_device->erase_command =
  1592. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
  1593. spi_device->erase_size =
  1594. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1595. SPI_DEV_TYPE_ERASE_SIZE);
  1596. spi_device->block_size =
  1597. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1598. SPI_DEV_TYPE_BLOCK_SIZE);
  1599. } else {
  1600. spi_device->size = 0;
  1601. }
  1602. }
  1603. /* Extract non-volatile configuration */
  1604. static int falcon_probe_nvconfig(struct efx_nic *efx)
  1605. {
  1606. struct falcon_nic_data *nic_data = efx->nic_data;
  1607. struct falcon_nvconfig *nvconfig;
  1608. int rc;
  1609. nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
  1610. if (!nvconfig)
  1611. return -ENOMEM;
  1612. rc = falcon_read_nvram(efx, nvconfig);
  1613. if (rc)
  1614. goto out;
  1615. efx->phy_type = nvconfig->board_v2.port0_phy_type;
  1616. efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr;
  1617. if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
  1618. falcon_spi_device_init(
  1619. efx, &nic_data->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
  1620. le32_to_cpu(nvconfig->board_v3
  1621. .spi_device_type[FFE_AB_SPI_DEVICE_FLASH]));
  1622. falcon_spi_device_init(
  1623. efx, &nic_data->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
  1624. le32_to_cpu(nvconfig->board_v3
  1625. .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM]));
  1626. }
  1627. /* Read the MAC addresses */
  1628. memcpy(efx->net_dev->perm_addr, nvconfig->mac_address[0], ETH_ALEN);
  1629. netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n",
  1630. efx->phy_type, efx->mdio.prtad);
  1631. rc = falcon_probe_board(efx,
  1632. le16_to_cpu(nvconfig->board_v2.board_revision));
  1633. out:
  1634. kfree(nvconfig);
  1635. return rc;
  1636. }
  1637. static void falcon_dimension_resources(struct efx_nic *efx)
  1638. {
  1639. efx->rx_dc_base = 0x20000;
  1640. efx->tx_dc_base = 0x26000;
  1641. }
  1642. /* Probe all SPI devices on the NIC */
  1643. static void falcon_probe_spi_devices(struct efx_nic *efx)
  1644. {
  1645. struct falcon_nic_data *nic_data = efx->nic_data;
  1646. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  1647. int boot_dev;
  1648. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  1649. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1650. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1651. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  1652. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  1653. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  1654. netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n",
  1655. boot_dev == FFE_AB_SPI_DEVICE_FLASH ?
  1656. "flash" : "EEPROM");
  1657. } else {
  1658. /* Disable VPD and set clock dividers to safe
  1659. * values for initial programming. */
  1660. boot_dev = -1;
  1661. netif_dbg(efx, probe, efx->net_dev,
  1662. "Booted from internal ASIC settings;"
  1663. " setting SPI config\n");
  1664. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  1665. /* 125 MHz / 7 ~= 20 MHz */
  1666. FRF_AB_EE_SF_CLOCK_DIV, 7,
  1667. /* 125 MHz / 63 ~= 2 MHz */
  1668. FRF_AB_EE_EE_CLOCK_DIV, 63);
  1669. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1670. }
  1671. mutex_init(&nic_data->spi_lock);
  1672. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  1673. falcon_spi_device_init(efx, &nic_data->spi_flash,
  1674. FFE_AB_SPI_DEVICE_FLASH,
  1675. default_flash_type);
  1676. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  1677. falcon_spi_device_init(efx, &nic_data->spi_eeprom,
  1678. FFE_AB_SPI_DEVICE_EEPROM,
  1679. large_eeprom_type);
  1680. }
  1681. static unsigned int falcon_a1_mem_map_size(struct efx_nic *efx)
  1682. {
  1683. return 0x20000;
  1684. }
  1685. static unsigned int falcon_b0_mem_map_size(struct efx_nic *efx)
  1686. {
  1687. /* Map everything up to and including the RSS indirection table.
  1688. * The PCI core takes care of mapping the MSI-X tables.
  1689. */
  1690. return FR_BZ_RX_INDIRECTION_TBL +
  1691. FR_BZ_RX_INDIRECTION_TBL_STEP * FR_BZ_RX_INDIRECTION_TBL_ROWS;
  1692. }
  1693. static int falcon_probe_nic(struct efx_nic *efx)
  1694. {
  1695. struct falcon_nic_data *nic_data;
  1696. struct falcon_board *board;
  1697. int rc;
  1698. /* Allocate storage for hardware specific data */
  1699. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  1700. if (!nic_data)
  1701. return -ENOMEM;
  1702. efx->nic_data = nic_data;
  1703. rc = -ENODEV;
  1704. if (efx_farch_fpga_ver(efx) != 0) {
  1705. netif_err(efx, probe, efx->net_dev,
  1706. "Falcon FPGA not supported\n");
  1707. goto fail1;
  1708. }
  1709. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1710. efx_oword_t nic_stat;
  1711. struct pci_dev *dev;
  1712. u8 pci_rev = efx->pci_dev->revision;
  1713. if ((pci_rev == 0xff) || (pci_rev == 0)) {
  1714. netif_err(efx, probe, efx->net_dev,
  1715. "Falcon rev A0 not supported\n");
  1716. goto fail1;
  1717. }
  1718. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1719. if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) {
  1720. netif_err(efx, probe, efx->net_dev,
  1721. "Falcon rev A1 1G not supported\n");
  1722. goto fail1;
  1723. }
  1724. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  1725. netif_err(efx, probe, efx->net_dev,
  1726. "Falcon rev A1 PCI-X not supported\n");
  1727. goto fail1;
  1728. }
  1729. dev = pci_dev_get(efx->pci_dev);
  1730. while ((dev = pci_get_device(PCI_VENDOR_ID_SOLARFLARE,
  1731. PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1,
  1732. dev))) {
  1733. if (dev->bus == efx->pci_dev->bus &&
  1734. dev->devfn == efx->pci_dev->devfn + 1) {
  1735. nic_data->pci_dev2 = dev;
  1736. break;
  1737. }
  1738. }
  1739. if (!nic_data->pci_dev2) {
  1740. netif_err(efx, probe, efx->net_dev,
  1741. "failed to find secondary function\n");
  1742. rc = -ENODEV;
  1743. goto fail2;
  1744. }
  1745. }
  1746. /* Now we can reset the NIC */
  1747. rc = __falcon_reset_hw(efx, RESET_TYPE_ALL);
  1748. if (rc) {
  1749. netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
  1750. goto fail3;
  1751. }
  1752. /* Allocate memory for INT_KER */
  1753. rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t),
  1754. GFP_KERNEL);
  1755. if (rc)
  1756. goto fail4;
  1757. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  1758. netif_dbg(efx, probe, efx->net_dev,
  1759. "INT_KER at %llx (virt %p phys %llx)\n",
  1760. (u64)efx->irq_status.dma_addr,
  1761. efx->irq_status.addr,
  1762. (u64)virt_to_phys(efx->irq_status.addr));
  1763. falcon_probe_spi_devices(efx);
  1764. /* Read in the non-volatile configuration */
  1765. rc = falcon_probe_nvconfig(efx);
  1766. if (rc) {
  1767. if (rc == -EINVAL)
  1768. netif_err(efx, probe, efx->net_dev, "NVRAM is invalid\n");
  1769. goto fail5;
  1770. }
  1771. efx->max_channels = (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ? 4 :
  1772. EFX_MAX_CHANNELS);
  1773. efx->timer_quantum_ns = 4968; /* 621 cycles */
  1774. /* Initialise I2C adapter */
  1775. board = falcon_board(efx);
  1776. board->i2c_adap.owner = THIS_MODULE;
  1777. board->i2c_data = falcon_i2c_bit_operations;
  1778. board->i2c_data.data = efx;
  1779. board->i2c_adap.algo_data = &board->i2c_data;
  1780. board->i2c_adap.dev.parent = &efx->pci_dev->dev;
  1781. strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
  1782. sizeof(board->i2c_adap.name));
  1783. rc = i2c_bit_add_bus(&board->i2c_adap);
  1784. if (rc)
  1785. goto fail5;
  1786. rc = falcon_board(efx)->type->init(efx);
  1787. if (rc) {
  1788. netif_err(efx, probe, efx->net_dev,
  1789. "failed to initialise board\n");
  1790. goto fail6;
  1791. }
  1792. nic_data->stats_disable_count = 1;
  1793. setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
  1794. (unsigned long)efx);
  1795. return 0;
  1796. fail6:
  1797. i2c_del_adapter(&board->i2c_adap);
  1798. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1799. fail5:
  1800. efx_nic_free_buffer(efx, &efx->irq_status);
  1801. fail4:
  1802. fail3:
  1803. if (nic_data->pci_dev2) {
  1804. pci_dev_put(nic_data->pci_dev2);
  1805. nic_data->pci_dev2 = NULL;
  1806. }
  1807. fail2:
  1808. fail1:
  1809. kfree(efx->nic_data);
  1810. return rc;
  1811. }
  1812. static void falcon_init_rx_cfg(struct efx_nic *efx)
  1813. {
  1814. /* RX control FIFO thresholds (32 entries) */
  1815. const unsigned ctrl_xon_thr = 20;
  1816. const unsigned ctrl_xoff_thr = 25;
  1817. efx_oword_t reg;
  1818. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1819. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1820. /* Data FIFO size is 5.5K. The RX DMA engine only
  1821. * supports scattering for user-mode queues, but will
  1822. * split DMA writes at intervals of RX_USR_BUF_SIZE
  1823. * (32-byte units) even for kernel-mode queues. We
  1824. * set it to be so large that that never happens.
  1825. */
  1826. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  1827. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  1828. (3 * 4096) >> 5);
  1829. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, 512 >> 8);
  1830. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, 2048 >> 8);
  1831. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  1832. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1833. } else {
  1834. /* Data FIFO size is 80K; register fields moved */
  1835. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
  1836. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
  1837. EFX_RX_USR_BUF_SIZE >> 5);
  1838. /* Send XON and XOFF at ~3 * max MTU away from empty/full */
  1839. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, 27648 >> 8);
  1840. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, 54272 >> 8);
  1841. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  1842. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1843. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  1844. /* Enable hash insertion. This is broken for the
  1845. * 'Falcon' hash so also select Toeplitz TCP/IPv4 and
  1846. * IPv4 hashes. */
  1847. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1);
  1848. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1);
  1849. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1);
  1850. }
  1851. /* Always enable XOFF signal from RX FIFO. We enable
  1852. * or disable transmission of pause frames at the MAC. */
  1853. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  1854. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1855. }
  1856. /* This call performs hardware-specific global initialisation, such as
  1857. * defining the descriptor cache sizes and number of RSS channels.
  1858. * It does not set up any buffers, descriptor rings or event queues.
  1859. */
  1860. static int falcon_init_nic(struct efx_nic *efx)
  1861. {
  1862. efx_oword_t temp;
  1863. int rc;
  1864. /* Use on-chip SRAM */
  1865. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  1866. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  1867. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  1868. rc = falcon_reset_sram(efx);
  1869. if (rc)
  1870. return rc;
  1871. /* Clear the parity enables on the TX data fifos as
  1872. * they produce false parity errors because of timing issues
  1873. */
  1874. if (EFX_WORKAROUND_5129(efx)) {
  1875. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  1876. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  1877. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  1878. }
  1879. if (EFX_WORKAROUND_7244(efx)) {
  1880. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1881. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  1882. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  1883. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  1884. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  1885. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1886. }
  1887. /* XXX This is documented only for Falcon A0/A1 */
  1888. /* Setup RX. Wait for descriptor is broken and must
  1889. * be disabled. RXDP recovery shouldn't be needed, but is.
  1890. */
  1891. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  1892. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  1893. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  1894. if (EFX_WORKAROUND_5583(efx))
  1895. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  1896. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  1897. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  1898. * descriptors (which is bad).
  1899. */
  1900. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  1901. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  1902. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  1903. falcon_init_rx_cfg(efx);
  1904. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  1905. /* Set hash key for IPv4 */
  1906. memcpy(&temp, efx->rx_hash_key, sizeof(temp));
  1907. efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY);
  1908. /* Set destination of both TX and RX Flush events */
  1909. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  1910. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  1911. }
  1912. efx_farch_init_common(efx);
  1913. return 0;
  1914. }
  1915. static void falcon_remove_nic(struct efx_nic *efx)
  1916. {
  1917. struct falcon_nic_data *nic_data = efx->nic_data;
  1918. struct falcon_board *board = falcon_board(efx);
  1919. board->type->fini(efx);
  1920. /* Remove I2C adapter and clear it in preparation for a retry */
  1921. i2c_del_adapter(&board->i2c_adap);
  1922. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1923. efx_nic_free_buffer(efx, &efx->irq_status);
  1924. __falcon_reset_hw(efx, RESET_TYPE_ALL);
  1925. /* Release the second function after the reset */
  1926. if (nic_data->pci_dev2) {
  1927. pci_dev_put(nic_data->pci_dev2);
  1928. nic_data->pci_dev2 = NULL;
  1929. }
  1930. /* Tear down the private nic state */
  1931. kfree(efx->nic_data);
  1932. efx->nic_data = NULL;
  1933. }
  1934. static void falcon_update_nic_stats(struct efx_nic *efx)
  1935. {
  1936. struct falcon_nic_data *nic_data = efx->nic_data;
  1937. efx_oword_t cnt;
  1938. if (nic_data->stats_disable_count)
  1939. return;
  1940. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  1941. efx->n_rx_nodesc_drop_cnt +=
  1942. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  1943. if (nic_data->stats_pending &&
  1944. *nic_data->stats_dma_done == FALCON_STATS_DONE) {
  1945. nic_data->stats_pending = false;
  1946. rmb(); /* read the done flag before the stats */
  1947. falcon_update_stats_xmac(efx);
  1948. }
  1949. }
  1950. void falcon_start_nic_stats(struct efx_nic *efx)
  1951. {
  1952. struct falcon_nic_data *nic_data = efx->nic_data;
  1953. spin_lock_bh(&efx->stats_lock);
  1954. if (--nic_data->stats_disable_count == 0)
  1955. falcon_stats_request(efx);
  1956. spin_unlock_bh(&efx->stats_lock);
  1957. }
  1958. void falcon_stop_nic_stats(struct efx_nic *efx)
  1959. {
  1960. struct falcon_nic_data *nic_data = efx->nic_data;
  1961. int i;
  1962. might_sleep();
  1963. spin_lock_bh(&efx->stats_lock);
  1964. ++nic_data->stats_disable_count;
  1965. spin_unlock_bh(&efx->stats_lock);
  1966. del_timer_sync(&nic_data->stats_timer);
  1967. /* Wait enough time for the most recent transfer to
  1968. * complete. */
  1969. for (i = 0; i < 4 && nic_data->stats_pending; i++) {
  1970. if (*nic_data->stats_dma_done == FALCON_STATS_DONE)
  1971. break;
  1972. msleep(1);
  1973. }
  1974. spin_lock_bh(&efx->stats_lock);
  1975. falcon_stats_complete(efx);
  1976. spin_unlock_bh(&efx->stats_lock);
  1977. }
  1978. static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  1979. {
  1980. falcon_board(efx)->type->set_id_led(efx, mode);
  1981. }
  1982. /**************************************************************************
  1983. *
  1984. * Wake on LAN
  1985. *
  1986. **************************************************************************
  1987. */
  1988. static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  1989. {
  1990. wol->supported = 0;
  1991. wol->wolopts = 0;
  1992. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1993. }
  1994. static int falcon_set_wol(struct efx_nic *efx, u32 type)
  1995. {
  1996. if (type != 0)
  1997. return -EINVAL;
  1998. return 0;
  1999. }
  2000. /**************************************************************************
  2001. *
  2002. * Revision-dependent attributes used by efx.c and nic.c
  2003. *
  2004. **************************************************************************
  2005. */
  2006. const struct efx_nic_type falcon_a1_nic_type = {
  2007. .mem_map_size = falcon_a1_mem_map_size,
  2008. .probe = falcon_probe_nic,
  2009. .remove = falcon_remove_nic,
  2010. .init = falcon_init_nic,
  2011. .dimension_resources = falcon_dimension_resources,
  2012. .fini = falcon_irq_ack_a1,
  2013. .monitor = falcon_monitor,
  2014. .map_reset_reason = falcon_map_reset_reason,
  2015. .map_reset_flags = falcon_map_reset_flags,
  2016. .reset = falcon_reset_hw,
  2017. .probe_port = falcon_probe_port,
  2018. .remove_port = falcon_remove_port,
  2019. .handle_global_event = falcon_handle_global_event,
  2020. .fini_dmaq = efx_farch_fini_dmaq,
  2021. .prepare_flush = falcon_prepare_flush,
  2022. .finish_flush = efx_port_dummy_op_void,
  2023. .update_stats = falcon_update_nic_stats,
  2024. .start_stats = falcon_start_nic_stats,
  2025. .stop_stats = falcon_stop_nic_stats,
  2026. .set_id_led = falcon_set_id_led,
  2027. .push_irq_moderation = falcon_push_irq_moderation,
  2028. .reconfigure_port = falcon_reconfigure_port,
  2029. .prepare_enable_fc_tx = falcon_a1_prepare_enable_fc_tx,
  2030. .reconfigure_mac = falcon_reconfigure_xmac,
  2031. .check_mac_fault = falcon_xmac_check_fault,
  2032. .get_wol = falcon_get_wol,
  2033. .set_wol = falcon_set_wol,
  2034. .resume_wol = efx_port_dummy_op_void,
  2035. .test_nvram = falcon_test_nvram,
  2036. .irq_enable_master = efx_farch_irq_enable_master,
  2037. .irq_test_generate = efx_farch_irq_test_generate,
  2038. .irq_disable_non_ev = efx_farch_irq_disable_master,
  2039. .irq_handle_msi = efx_farch_msi_interrupt,
  2040. .irq_handle_legacy = falcon_legacy_interrupt_a1,
  2041. .tx_probe = efx_farch_tx_probe,
  2042. .tx_init = efx_farch_tx_init,
  2043. .tx_remove = efx_farch_tx_remove,
  2044. .tx_write = efx_farch_tx_write,
  2045. .rx_push_indir_table = efx_farch_rx_push_indir_table,
  2046. .rx_probe = efx_farch_rx_probe,
  2047. .rx_init = efx_farch_rx_init,
  2048. .rx_remove = efx_farch_rx_remove,
  2049. .rx_write = efx_farch_rx_write,
  2050. .rx_defer_refill = efx_farch_rx_defer_refill,
  2051. .ev_probe = efx_farch_ev_probe,
  2052. .ev_init = efx_farch_ev_init,
  2053. .ev_fini = efx_farch_ev_fini,
  2054. .ev_remove = efx_farch_ev_remove,
  2055. .ev_process = efx_farch_ev_process,
  2056. .ev_read_ack = efx_farch_ev_read_ack,
  2057. .ev_test_generate = efx_farch_ev_test_generate,
  2058. /* We don't expose the filter table on Falcon A1 as it is not
  2059. * mapped into function 0, but these implementations still
  2060. * work with a degenerate case of all tables set to size 0.
  2061. */
  2062. .filter_table_probe = efx_farch_filter_table_probe,
  2063. .filter_table_restore = efx_farch_filter_table_restore,
  2064. .filter_table_remove = efx_farch_filter_table_remove,
  2065. .filter_insert = efx_farch_filter_insert,
  2066. .filter_remove_safe = efx_farch_filter_remove_safe,
  2067. .filter_get_safe = efx_farch_filter_get_safe,
  2068. .filter_clear_rx = efx_farch_filter_clear_rx,
  2069. .filter_count_rx_used = efx_farch_filter_count_rx_used,
  2070. .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit,
  2071. .filter_get_rx_ids = efx_farch_filter_get_rx_ids,
  2072. .revision = EFX_REV_FALCON_A1,
  2073. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  2074. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  2075. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  2076. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  2077. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  2078. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2079. .rx_buffer_padding = 0x24,
  2080. .can_rx_scatter = false,
  2081. .max_interrupt_mode = EFX_INT_MODE_MSI,
  2082. .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH,
  2083. .offload_features = NETIF_F_IP_CSUM,
  2084. .mcdi_max_ver = -1,
  2085. };
  2086. const struct efx_nic_type falcon_b0_nic_type = {
  2087. .mem_map_size = falcon_b0_mem_map_size,
  2088. .probe = falcon_probe_nic,
  2089. .remove = falcon_remove_nic,
  2090. .init = falcon_init_nic,
  2091. .dimension_resources = falcon_dimension_resources,
  2092. .fini = efx_port_dummy_op_void,
  2093. .monitor = falcon_monitor,
  2094. .map_reset_reason = falcon_map_reset_reason,
  2095. .map_reset_flags = falcon_map_reset_flags,
  2096. .reset = falcon_reset_hw,
  2097. .probe_port = falcon_probe_port,
  2098. .remove_port = falcon_remove_port,
  2099. .handle_global_event = falcon_handle_global_event,
  2100. .fini_dmaq = efx_farch_fini_dmaq,
  2101. .prepare_flush = falcon_prepare_flush,
  2102. .finish_flush = efx_port_dummy_op_void,
  2103. .update_stats = falcon_update_nic_stats,
  2104. .start_stats = falcon_start_nic_stats,
  2105. .stop_stats = falcon_stop_nic_stats,
  2106. .set_id_led = falcon_set_id_led,
  2107. .push_irq_moderation = falcon_push_irq_moderation,
  2108. .reconfigure_port = falcon_reconfigure_port,
  2109. .prepare_enable_fc_tx = falcon_b0_prepare_enable_fc_tx,
  2110. .reconfigure_mac = falcon_reconfigure_xmac,
  2111. .check_mac_fault = falcon_xmac_check_fault,
  2112. .get_wol = falcon_get_wol,
  2113. .set_wol = falcon_set_wol,
  2114. .resume_wol = efx_port_dummy_op_void,
  2115. .test_chip = falcon_b0_test_chip,
  2116. .test_nvram = falcon_test_nvram,
  2117. .irq_enable_master = efx_farch_irq_enable_master,
  2118. .irq_test_generate = efx_farch_irq_test_generate,
  2119. .irq_disable_non_ev = efx_farch_irq_disable_master,
  2120. .irq_handle_msi = efx_farch_msi_interrupt,
  2121. .irq_handle_legacy = efx_farch_legacy_interrupt,
  2122. .tx_probe = efx_farch_tx_probe,
  2123. .tx_init = efx_farch_tx_init,
  2124. .tx_remove = efx_farch_tx_remove,
  2125. .tx_write = efx_farch_tx_write,
  2126. .rx_push_indir_table = efx_farch_rx_push_indir_table,
  2127. .rx_probe = efx_farch_rx_probe,
  2128. .rx_init = efx_farch_rx_init,
  2129. .rx_remove = efx_farch_rx_remove,
  2130. .rx_write = efx_farch_rx_write,
  2131. .rx_defer_refill = efx_farch_rx_defer_refill,
  2132. .ev_probe = efx_farch_ev_probe,
  2133. .ev_init = efx_farch_ev_init,
  2134. .ev_fini = efx_farch_ev_fini,
  2135. .ev_remove = efx_farch_ev_remove,
  2136. .ev_process = efx_farch_ev_process,
  2137. .ev_read_ack = efx_farch_ev_read_ack,
  2138. .ev_test_generate = efx_farch_ev_test_generate,
  2139. .filter_table_probe = efx_farch_filter_table_probe,
  2140. .filter_table_restore = efx_farch_filter_table_restore,
  2141. .filter_table_remove = efx_farch_filter_table_remove,
  2142. .filter_update_rx_scatter = efx_farch_filter_update_rx_scatter,
  2143. .filter_insert = efx_farch_filter_insert,
  2144. .filter_remove_safe = efx_farch_filter_remove_safe,
  2145. .filter_get_safe = efx_farch_filter_get_safe,
  2146. .filter_clear_rx = efx_farch_filter_clear_rx,
  2147. .filter_count_rx_used = efx_farch_filter_count_rx_used,
  2148. .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit,
  2149. .filter_get_rx_ids = efx_farch_filter_get_rx_ids,
  2150. #ifdef CONFIG_RFS_ACCEL
  2151. .filter_rfs_insert = efx_farch_filter_rfs_insert,
  2152. .filter_rfs_expire_one = efx_farch_filter_rfs_expire_one,
  2153. #endif
  2154. .revision = EFX_REV_FALCON_B0,
  2155. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  2156. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  2157. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  2158. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  2159. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  2160. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2161. .rx_buffer_hash_size = 0x10,
  2162. .rx_buffer_padding = 0,
  2163. .can_rx_scatter = true,
  2164. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  2165. .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH,
  2166. .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH | NETIF_F_NTUPLE,
  2167. .mcdi_max_ver = -1,
  2168. .max_rx_ip_filters = FR_BZ_RX_FILTER_TBL0_ROWS,
  2169. };