falcon.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436
  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. 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. 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. /* Check to see if we have a serious error condition */
  334. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  335. if (unlikely(syserr))
  336. return efx_nic_fatal_interrupt(efx);
  337. /* Determine interrupting queues, clear interrupt status
  338. * register and acknowledge the device interrupt.
  339. */
  340. BUILD_BUG_ON(FSF_AZ_NET_IVEC_INT_Q_WIDTH > EFX_MAX_CHANNELS);
  341. queues = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_INT_Q);
  342. EFX_ZERO_OWORD(*int_ker);
  343. wmb(); /* Ensure the vector is cleared before interrupt ack */
  344. falcon_irq_ack_a1(efx);
  345. if (queues & 1)
  346. efx_schedule_channel_irq(efx_get_channel(efx, 0));
  347. if (queues & 2)
  348. efx_schedule_channel_irq(efx_get_channel(efx, 1));
  349. return IRQ_HANDLED;
  350. }
  351. /**************************************************************************
  352. *
  353. * EEPROM/flash
  354. *
  355. **************************************************************************
  356. */
  357. #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
  358. static int falcon_spi_poll(struct efx_nic *efx)
  359. {
  360. efx_oword_t reg;
  361. efx_reado(efx, &reg, FR_AB_EE_SPI_HCMD);
  362. return EFX_OWORD_FIELD(reg, FRF_AB_EE_SPI_HCMD_CMD_EN) ? -EBUSY : 0;
  363. }
  364. /* Wait for SPI command completion */
  365. static int falcon_spi_wait(struct efx_nic *efx)
  366. {
  367. /* Most commands will finish quickly, so we start polling at
  368. * very short intervals. Sometimes the command may have to
  369. * wait for VPD or expansion ROM access outside of our
  370. * control, so we allow up to 100 ms. */
  371. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10);
  372. int i;
  373. for (i = 0; i < 10; i++) {
  374. if (!falcon_spi_poll(efx))
  375. return 0;
  376. udelay(10);
  377. }
  378. for (;;) {
  379. if (!falcon_spi_poll(efx))
  380. return 0;
  381. if (time_after_eq(jiffies, timeout)) {
  382. netif_err(efx, hw, efx->net_dev,
  383. "timed out waiting for SPI\n");
  384. return -ETIMEDOUT;
  385. }
  386. schedule_timeout_uninterruptible(1);
  387. }
  388. }
  389. int falcon_spi_cmd(struct efx_nic *efx, const struct efx_spi_device *spi,
  390. unsigned int command, int address,
  391. const void *in, void *out, size_t len)
  392. {
  393. bool addressed = (address >= 0);
  394. bool reading = (out != NULL);
  395. efx_oword_t reg;
  396. int rc;
  397. /* Input validation */
  398. if (len > FALCON_SPI_MAX_LEN)
  399. return -EINVAL;
  400. /* Check that previous command is not still running */
  401. rc = falcon_spi_poll(efx);
  402. if (rc)
  403. return rc;
  404. /* Program address register, if we have an address */
  405. if (addressed) {
  406. EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address);
  407. efx_writeo(efx, &reg, FR_AB_EE_SPI_HADR);
  408. }
  409. /* Program data register, if we have data */
  410. if (in != NULL) {
  411. memcpy(&reg, in, len);
  412. efx_writeo(efx, &reg, FR_AB_EE_SPI_HDATA);
  413. }
  414. /* Issue read/write command */
  415. EFX_POPULATE_OWORD_7(reg,
  416. FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
  417. FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id,
  418. FRF_AB_EE_SPI_HCMD_DABCNT, len,
  419. FRF_AB_EE_SPI_HCMD_READ, reading,
  420. FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
  421. FRF_AB_EE_SPI_HCMD_ADBCNT,
  422. (addressed ? spi->addr_len : 0),
  423. FRF_AB_EE_SPI_HCMD_ENC, command);
  424. efx_writeo(efx, &reg, FR_AB_EE_SPI_HCMD);
  425. /* Wait for read/write to complete */
  426. rc = falcon_spi_wait(efx);
  427. if (rc)
  428. return rc;
  429. /* Read data */
  430. if (out != NULL) {
  431. efx_reado(efx, &reg, FR_AB_EE_SPI_HDATA);
  432. memcpy(out, &reg, len);
  433. }
  434. return 0;
  435. }
  436. static size_t
  437. falcon_spi_write_limit(const struct efx_spi_device *spi, size_t start)
  438. {
  439. return min(FALCON_SPI_MAX_LEN,
  440. (spi->block_size - (start & (spi->block_size - 1))));
  441. }
  442. static inline u8
  443. efx_spi_munge_command(const struct efx_spi_device *spi,
  444. const u8 command, const unsigned int address)
  445. {
  446. return command | (((address >> 8) & spi->munge_address) << 3);
  447. }
  448. /* Wait up to 10 ms for buffered write completion */
  449. int
  450. falcon_spi_wait_write(struct efx_nic *efx, const struct efx_spi_device *spi)
  451. {
  452. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100);
  453. u8 status;
  454. int rc;
  455. for (;;) {
  456. rc = falcon_spi_cmd(efx, spi, SPI_RDSR, -1, NULL,
  457. &status, sizeof(status));
  458. if (rc)
  459. return rc;
  460. if (!(status & SPI_STATUS_NRDY))
  461. return 0;
  462. if (time_after_eq(jiffies, timeout)) {
  463. netif_err(efx, hw, efx->net_dev,
  464. "SPI write timeout on device %d"
  465. " last status=0x%02x\n",
  466. spi->device_id, status);
  467. return -ETIMEDOUT;
  468. }
  469. schedule_timeout_uninterruptible(1);
  470. }
  471. }
  472. int falcon_spi_read(struct efx_nic *efx, const struct efx_spi_device *spi,
  473. loff_t start, size_t len, size_t *retlen, u8 *buffer)
  474. {
  475. size_t block_len, pos = 0;
  476. unsigned int command;
  477. int rc = 0;
  478. while (pos < len) {
  479. block_len = min(len - pos, FALCON_SPI_MAX_LEN);
  480. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  481. rc = falcon_spi_cmd(efx, spi, command, start + pos, NULL,
  482. buffer + pos, block_len);
  483. if (rc)
  484. break;
  485. pos += block_len;
  486. /* Avoid locking up the system */
  487. cond_resched();
  488. if (signal_pending(current)) {
  489. rc = -EINTR;
  490. break;
  491. }
  492. }
  493. if (retlen)
  494. *retlen = pos;
  495. return rc;
  496. }
  497. int
  498. falcon_spi_write(struct efx_nic *efx, const struct efx_spi_device *spi,
  499. loff_t start, size_t len, size_t *retlen, const u8 *buffer)
  500. {
  501. u8 verify_buffer[FALCON_SPI_MAX_LEN];
  502. size_t block_len, pos = 0;
  503. unsigned int command;
  504. int rc = 0;
  505. while (pos < len) {
  506. rc = falcon_spi_cmd(efx, spi, SPI_WREN, -1, NULL, NULL, 0);
  507. if (rc)
  508. break;
  509. block_len = min(len - pos,
  510. falcon_spi_write_limit(spi, start + pos));
  511. command = efx_spi_munge_command(spi, SPI_WRITE, start + pos);
  512. rc = falcon_spi_cmd(efx, spi, command, start + pos,
  513. buffer + pos, NULL, block_len);
  514. if (rc)
  515. break;
  516. rc = falcon_spi_wait_write(efx, spi);
  517. if (rc)
  518. break;
  519. command = efx_spi_munge_command(spi, SPI_READ, start + pos);
  520. rc = falcon_spi_cmd(efx, spi, command, start + pos,
  521. NULL, verify_buffer, block_len);
  522. if (memcmp(verify_buffer, buffer + pos, block_len)) {
  523. rc = -EIO;
  524. break;
  525. }
  526. pos += block_len;
  527. /* Avoid locking up the system */
  528. cond_resched();
  529. if (signal_pending(current)) {
  530. rc = -EINTR;
  531. break;
  532. }
  533. }
  534. if (retlen)
  535. *retlen = pos;
  536. return rc;
  537. }
  538. /**************************************************************************
  539. *
  540. * XMAC operations
  541. *
  542. **************************************************************************
  543. */
  544. /* Configure the XAUI driver that is an output from Falcon */
  545. static void falcon_setup_xaui(struct efx_nic *efx)
  546. {
  547. efx_oword_t sdctl, txdrv;
  548. /* Move the XAUI into low power, unless there is no PHY, in
  549. * which case the XAUI will have to drive a cable. */
  550. if (efx->phy_type == PHY_TYPE_NONE)
  551. return;
  552. efx_reado(efx, &sdctl, FR_AB_XX_SD_CTL);
  553. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVD, FFE_AB_XX_SD_CTL_DRV_DEF);
  554. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVD, FFE_AB_XX_SD_CTL_DRV_DEF);
  555. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVC, FFE_AB_XX_SD_CTL_DRV_DEF);
  556. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVC, FFE_AB_XX_SD_CTL_DRV_DEF);
  557. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVB, FFE_AB_XX_SD_CTL_DRV_DEF);
  558. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVB, FFE_AB_XX_SD_CTL_DRV_DEF);
  559. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVA, FFE_AB_XX_SD_CTL_DRV_DEF);
  560. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVA, FFE_AB_XX_SD_CTL_DRV_DEF);
  561. efx_writeo(efx, &sdctl, FR_AB_XX_SD_CTL);
  562. EFX_POPULATE_OWORD_8(txdrv,
  563. FRF_AB_XX_DEQD, FFE_AB_XX_TXDRV_DEQ_DEF,
  564. FRF_AB_XX_DEQC, FFE_AB_XX_TXDRV_DEQ_DEF,
  565. FRF_AB_XX_DEQB, FFE_AB_XX_TXDRV_DEQ_DEF,
  566. FRF_AB_XX_DEQA, FFE_AB_XX_TXDRV_DEQ_DEF,
  567. FRF_AB_XX_DTXD, FFE_AB_XX_TXDRV_DTX_DEF,
  568. FRF_AB_XX_DTXC, FFE_AB_XX_TXDRV_DTX_DEF,
  569. FRF_AB_XX_DTXB, FFE_AB_XX_TXDRV_DTX_DEF,
  570. FRF_AB_XX_DTXA, FFE_AB_XX_TXDRV_DTX_DEF);
  571. efx_writeo(efx, &txdrv, FR_AB_XX_TXDRV_CTL);
  572. }
  573. int falcon_reset_xaui(struct efx_nic *efx)
  574. {
  575. struct falcon_nic_data *nic_data = efx->nic_data;
  576. efx_oword_t reg;
  577. int count;
  578. /* Don't fetch MAC statistics over an XMAC reset */
  579. WARN_ON(nic_data->stats_disable_count == 0);
  580. /* Start reset sequence */
  581. EFX_POPULATE_OWORD_1(reg, FRF_AB_XX_RST_XX_EN, 1);
  582. efx_writeo(efx, &reg, FR_AB_XX_PWR_RST);
  583. /* Wait up to 10 ms for completion, then reinitialise */
  584. for (count = 0; count < 1000; count++) {
  585. efx_reado(efx, &reg, FR_AB_XX_PWR_RST);
  586. if (EFX_OWORD_FIELD(reg, FRF_AB_XX_RST_XX_EN) == 0 &&
  587. EFX_OWORD_FIELD(reg, FRF_AB_XX_SD_RST_ACT) == 0) {
  588. falcon_setup_xaui(efx);
  589. return 0;
  590. }
  591. udelay(10);
  592. }
  593. netif_err(efx, hw, efx->net_dev,
  594. "timed out waiting for XAUI/XGXS reset\n");
  595. return -ETIMEDOUT;
  596. }
  597. static void falcon_ack_status_intr(struct efx_nic *efx)
  598. {
  599. struct falcon_nic_data *nic_data = efx->nic_data;
  600. efx_oword_t reg;
  601. if ((efx_nic_rev(efx) != EFX_REV_FALCON_B0) || LOOPBACK_INTERNAL(efx))
  602. return;
  603. /* We expect xgmii faults if the wireside link is down */
  604. if (!EFX_WORKAROUND_5147(efx) || !efx->link_state.up)
  605. return;
  606. /* We can only use this interrupt to signal the negative edge of
  607. * xaui_align [we have to poll the positive edge]. */
  608. if (nic_data->xmac_poll_required)
  609. return;
  610. efx_reado(efx, &reg, FR_AB_XM_MGT_INT_MSK);
  611. }
  612. static bool falcon_xgxs_link_ok(struct efx_nic *efx)
  613. {
  614. efx_oword_t reg;
  615. bool align_done, link_ok = false;
  616. int sync_status;
  617. /* Read link status */
  618. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  619. align_done = EFX_OWORD_FIELD(reg, FRF_AB_XX_ALIGN_DONE);
  620. sync_status = EFX_OWORD_FIELD(reg, FRF_AB_XX_SYNC_STAT);
  621. if (align_done && (sync_status == FFE_AB_XX_STAT_ALL_LANES))
  622. link_ok = true;
  623. /* Clear link status ready for next read */
  624. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_COMMA_DET, FFE_AB_XX_STAT_ALL_LANES);
  625. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_CHAR_ERR, FFE_AB_XX_STAT_ALL_LANES);
  626. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_DISPERR, FFE_AB_XX_STAT_ALL_LANES);
  627. efx_writeo(efx, &reg, FR_AB_XX_CORE_STAT);
  628. return link_ok;
  629. }
  630. static bool falcon_xmac_link_ok(struct efx_nic *efx)
  631. {
  632. /*
  633. * Check MAC's XGXS link status except when using XGMII loopback
  634. * which bypasses the XGXS block.
  635. * If possible, check PHY's XGXS link status except when using
  636. * MAC loopback.
  637. */
  638. return (efx->loopback_mode == LOOPBACK_XGMII ||
  639. falcon_xgxs_link_ok(efx)) &&
  640. (!(efx->mdio.mmds & (1 << MDIO_MMD_PHYXS)) ||
  641. LOOPBACK_INTERNAL(efx) ||
  642. efx_mdio_phyxgxs_lane_sync(efx));
  643. }
  644. static void falcon_reconfigure_xmac_core(struct efx_nic *efx)
  645. {
  646. unsigned int max_frame_len;
  647. efx_oword_t reg;
  648. bool rx_fc = !!(efx->link_state.fc & EFX_FC_RX);
  649. bool tx_fc = !!(efx->link_state.fc & EFX_FC_TX);
  650. /* Configure MAC - cut-thru mode is hard wired on */
  651. EFX_POPULATE_OWORD_3(reg,
  652. FRF_AB_XM_RX_JUMBO_MODE, 1,
  653. FRF_AB_XM_TX_STAT_EN, 1,
  654. FRF_AB_XM_RX_STAT_EN, 1);
  655. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  656. /* Configure TX */
  657. EFX_POPULATE_OWORD_6(reg,
  658. FRF_AB_XM_TXEN, 1,
  659. FRF_AB_XM_TX_PRMBL, 1,
  660. FRF_AB_XM_AUTO_PAD, 1,
  661. FRF_AB_XM_TXCRC, 1,
  662. FRF_AB_XM_FCNTL, tx_fc,
  663. FRF_AB_XM_IPG, 0x3);
  664. efx_writeo(efx, &reg, FR_AB_XM_TX_CFG);
  665. /* Configure RX */
  666. EFX_POPULATE_OWORD_5(reg,
  667. FRF_AB_XM_RXEN, 1,
  668. FRF_AB_XM_AUTO_DEPAD, 0,
  669. FRF_AB_XM_ACPT_ALL_MCAST, 1,
  670. FRF_AB_XM_ACPT_ALL_UCAST, efx->promiscuous,
  671. FRF_AB_XM_PASS_CRC_ERR, 1);
  672. efx_writeo(efx, &reg, FR_AB_XM_RX_CFG);
  673. /* Set frame length */
  674. max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
  675. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_MAX_RX_FRM_SIZE, max_frame_len);
  676. efx_writeo(efx, &reg, FR_AB_XM_RX_PARAM);
  677. EFX_POPULATE_OWORD_2(reg,
  678. FRF_AB_XM_MAX_TX_FRM_SIZE, max_frame_len,
  679. FRF_AB_XM_TX_JUMBO_MODE, 1);
  680. efx_writeo(efx, &reg, FR_AB_XM_TX_PARAM);
  681. EFX_POPULATE_OWORD_2(reg,
  682. FRF_AB_XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */
  683. FRF_AB_XM_DIS_FCNTL, !rx_fc);
  684. efx_writeo(efx, &reg, FR_AB_XM_FC);
  685. /* Set MAC address */
  686. memcpy(&reg, &efx->net_dev->dev_addr[0], 4);
  687. efx_writeo(efx, &reg, FR_AB_XM_ADR_LO);
  688. memcpy(&reg, &efx->net_dev->dev_addr[4], 2);
  689. efx_writeo(efx, &reg, FR_AB_XM_ADR_HI);
  690. }
  691. static void falcon_reconfigure_xgxs_core(struct efx_nic *efx)
  692. {
  693. efx_oword_t reg;
  694. bool xgxs_loopback = (efx->loopback_mode == LOOPBACK_XGXS);
  695. bool xaui_loopback = (efx->loopback_mode == LOOPBACK_XAUI);
  696. bool xgmii_loopback = (efx->loopback_mode == LOOPBACK_XGMII);
  697. /* XGXS block is flaky and will need to be reset if moving
  698. * into our out of XGMII, XGXS or XAUI loopbacks. */
  699. if (EFX_WORKAROUND_5147(efx)) {
  700. bool old_xgmii_loopback, old_xgxs_loopback, old_xaui_loopback;
  701. bool reset_xgxs;
  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 =
  705. EFX_OWORD_FIELD(reg, FRF_AB_XX_XGMII_LB_EN);
  706. efx_reado(efx, &reg, FR_AB_XX_SD_CTL);
  707. old_xaui_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_LPBKA);
  708. /* The PHY driver may have turned XAUI off */
  709. reset_xgxs = ((xgxs_loopback != old_xgxs_loopback) ||
  710. (xaui_loopback != old_xaui_loopback) ||
  711. (xgmii_loopback != old_xgmii_loopback));
  712. if (reset_xgxs)
  713. falcon_reset_xaui(efx);
  714. }
  715. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  716. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_FORCE_SIG,
  717. (xgxs_loopback || xaui_loopback) ?
  718. FFE_AB_XX_FORCE_SIG_ALL_LANES : 0);
  719. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_XGXS_LB_EN, xgxs_loopback);
  720. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_XGMII_LB_EN, xgmii_loopback);
  721. efx_writeo(efx, &reg, FR_AB_XX_CORE_STAT);
  722. efx_reado(efx, &reg, FR_AB_XX_SD_CTL);
  723. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKD, xaui_loopback);
  724. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKC, xaui_loopback);
  725. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKB, xaui_loopback);
  726. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKA, xaui_loopback);
  727. efx_writeo(efx, &reg, FR_AB_XX_SD_CTL);
  728. }
  729. /* Try to bring up the Falcon side of the Falcon-Phy XAUI link */
  730. static bool falcon_xmac_link_ok_retry(struct efx_nic *efx, int tries)
  731. {
  732. bool mac_up = falcon_xmac_link_ok(efx);
  733. if (LOOPBACK_MASK(efx) & LOOPBACKS_EXTERNAL(efx) & LOOPBACKS_WS ||
  734. efx_phy_mode_disabled(efx->phy_mode))
  735. /* XAUI link is expected to be down */
  736. return mac_up;
  737. falcon_stop_nic_stats(efx);
  738. while (!mac_up && tries) {
  739. netif_dbg(efx, hw, efx->net_dev, "bashing xaui\n");
  740. falcon_reset_xaui(efx);
  741. udelay(200);
  742. mac_up = falcon_xmac_link_ok(efx);
  743. --tries;
  744. }
  745. falcon_start_nic_stats(efx);
  746. return mac_up;
  747. }
  748. static bool falcon_xmac_check_fault(struct efx_nic *efx)
  749. {
  750. return !falcon_xmac_link_ok_retry(efx, 5);
  751. }
  752. static int falcon_reconfigure_xmac(struct efx_nic *efx)
  753. {
  754. struct falcon_nic_data *nic_data = efx->nic_data;
  755. falcon_reconfigure_xgxs_core(efx);
  756. falcon_reconfigure_xmac_core(efx);
  757. falcon_reconfigure_mac_wrapper(efx);
  758. nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 5);
  759. falcon_ack_status_intr(efx);
  760. return 0;
  761. }
  762. static void falcon_update_stats_xmac(struct efx_nic *efx)
  763. {
  764. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  765. /* Update MAC stats from DMAed values */
  766. FALCON_STAT(efx, XgRxOctets, rx_bytes);
  767. FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes);
  768. FALCON_STAT(efx, XgRxPkts, rx_packets);
  769. FALCON_STAT(efx, XgRxPktsOK, rx_good);
  770. FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast);
  771. FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast);
  772. FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast);
  773. FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64);
  774. FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo);
  775. FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo);
  776. FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64);
  777. FALCON_STAT(efx, XgRxDropEvents, rx_overflow);
  778. FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad);
  779. FALCON_STAT(efx, XgRxAlignError, rx_align_error);
  780. FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error);
  781. FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error);
  782. FALCON_STAT(efx, XgRxControlPkts, rx_control);
  783. FALCON_STAT(efx, XgRxPausePkts, rx_pause);
  784. FALCON_STAT(efx, XgRxPkts64Octets, rx_64);
  785. FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127);
  786. FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255);
  787. FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511);
  788. FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023);
  789. FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx);
  790. FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo);
  791. FALCON_STAT(efx, XgRxLengthError, rx_length_error);
  792. FALCON_STAT(efx, XgTxPkts, tx_packets);
  793. FALCON_STAT(efx, XgTxOctets, tx_bytes);
  794. FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast);
  795. FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast);
  796. FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast);
  797. FALCON_STAT(efx, XgTxControlPkts, tx_control);
  798. FALCON_STAT(efx, XgTxPausePkts, tx_pause);
  799. FALCON_STAT(efx, XgTxPkts64Octets, tx_64);
  800. FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127);
  801. FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255);
  802. FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511);
  803. FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023);
  804. FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx);
  805. FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo);
  806. FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64);
  807. FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo);
  808. FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp);
  809. FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error);
  810. FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error);
  811. /* Update derived statistics */
  812. efx_update_diff_stat(&mac_stats->tx_good_bytes,
  813. mac_stats->tx_bytes - mac_stats->tx_bad_bytes -
  814. mac_stats->tx_control * 64);
  815. efx_update_diff_stat(&mac_stats->rx_bad_bytes,
  816. mac_stats->rx_bytes - mac_stats->rx_good_bytes -
  817. mac_stats->rx_control * 64);
  818. }
  819. static void falcon_poll_xmac(struct efx_nic *efx)
  820. {
  821. struct falcon_nic_data *nic_data = efx->nic_data;
  822. if (!EFX_WORKAROUND_5147(efx) || !efx->link_state.up ||
  823. !nic_data->xmac_poll_required)
  824. return;
  825. nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 1);
  826. falcon_ack_status_intr(efx);
  827. }
  828. /**************************************************************************
  829. *
  830. * MAC wrapper
  831. *
  832. **************************************************************************
  833. */
  834. static void falcon_push_multicast_hash(struct efx_nic *efx)
  835. {
  836. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  837. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  838. efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0);
  839. efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1);
  840. }
  841. static void falcon_reset_macs(struct efx_nic *efx)
  842. {
  843. struct falcon_nic_data *nic_data = efx->nic_data;
  844. efx_oword_t reg, mac_ctrl;
  845. int count;
  846. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
  847. /* It's not safe to use GLB_CTL_REG to reset the
  848. * macs, so instead use the internal MAC resets
  849. */
  850. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1);
  851. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  852. for (count = 0; count < 10000; count++) {
  853. efx_reado(efx, &reg, FR_AB_XM_GLB_CFG);
  854. if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) ==
  855. 0)
  856. return;
  857. udelay(10);
  858. }
  859. netif_err(efx, hw, efx->net_dev,
  860. "timed out waiting for XMAC core reset\n");
  861. }
  862. /* Mac stats will fail whist the TX fifo is draining */
  863. WARN_ON(nic_data->stats_disable_count == 0);
  864. efx_reado(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  865. EFX_SET_OWORD_FIELD(mac_ctrl, FRF_BB_TXFIFO_DRAIN_EN, 1);
  866. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  867. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  868. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1);
  869. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1);
  870. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1);
  871. efx_writeo(efx, &reg, FR_AB_GLB_CTL);
  872. count = 0;
  873. while (1) {
  874. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  875. if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) &&
  876. !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) &&
  877. !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) {
  878. netif_dbg(efx, hw, efx->net_dev,
  879. "Completed MAC reset after %d loops\n",
  880. count);
  881. break;
  882. }
  883. if (count > 20) {
  884. netif_err(efx, hw, efx->net_dev, "MAC reset failed\n");
  885. break;
  886. }
  887. count++;
  888. udelay(10);
  889. }
  890. /* Ensure the correct MAC is selected before statistics
  891. * are re-enabled by the caller */
  892. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  893. falcon_setup_xaui(efx);
  894. }
  895. static void falcon_drain_tx_fifo(struct efx_nic *efx)
  896. {
  897. efx_oword_t reg;
  898. if ((efx_nic_rev(efx) < EFX_REV_FALCON_B0) ||
  899. (efx->loopback_mode != LOOPBACK_NONE))
  900. return;
  901. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  902. /* There is no point in draining more than once */
  903. if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN))
  904. return;
  905. falcon_reset_macs(efx);
  906. }
  907. static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
  908. {
  909. efx_oword_t reg;
  910. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  911. return;
  912. /* Isolate the MAC -> RX */
  913. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  914. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0);
  915. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  916. /* Isolate TX -> MAC */
  917. falcon_drain_tx_fifo(efx);
  918. }
  919. static void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
  920. {
  921. struct efx_link_state *link_state = &efx->link_state;
  922. efx_oword_t reg;
  923. int link_speed, isolate;
  924. isolate = !!ACCESS_ONCE(efx->reset_pending);
  925. switch (link_state->speed) {
  926. case 10000: link_speed = 3; break;
  927. case 1000: link_speed = 2; break;
  928. case 100: link_speed = 1; break;
  929. default: link_speed = 0; break;
  930. }
  931. /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
  932. * as advertised. Disable to ensure packets are not
  933. * indefinitely held and TX queue can be flushed at any point
  934. * while the link is down. */
  935. EFX_POPULATE_OWORD_5(reg,
  936. FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */,
  937. FRF_AB_MAC_BCAD_ACPT, 1,
  938. FRF_AB_MAC_UC_PROM, efx->promiscuous,
  939. FRF_AB_MAC_LINK_STATUS, 1, /* always set */
  940. FRF_AB_MAC_SPEED, link_speed);
  941. /* On B0, MAC backpressure can be disabled and packets get
  942. * discarded. */
  943. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  944. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN,
  945. !link_state->up || isolate);
  946. }
  947. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  948. /* Restore the multicast hash registers. */
  949. falcon_push_multicast_hash(efx);
  950. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  951. /* Enable XOFF signal from RX FIFO (we enabled it during NIC
  952. * initialisation but it may read back as 0) */
  953. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  954. /* Unisolate the MAC -> RX */
  955. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  956. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, !isolate);
  957. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  958. }
  959. static void falcon_stats_request(struct efx_nic *efx)
  960. {
  961. struct falcon_nic_data *nic_data = efx->nic_data;
  962. efx_oword_t reg;
  963. WARN_ON(nic_data->stats_pending);
  964. WARN_ON(nic_data->stats_disable_count);
  965. if (nic_data->stats_dma_done == NULL)
  966. return; /* no mac selected */
  967. *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE;
  968. nic_data->stats_pending = true;
  969. wmb(); /* ensure done flag is clear */
  970. /* Initiate DMA transfer of stats */
  971. EFX_POPULATE_OWORD_2(reg,
  972. FRF_AB_MAC_STAT_DMA_CMD, 1,
  973. FRF_AB_MAC_STAT_DMA_ADR,
  974. efx->stats_buffer.dma_addr);
  975. efx_writeo(efx, &reg, FR_AB_MAC_STAT_DMA);
  976. mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2));
  977. }
  978. static void falcon_stats_complete(struct efx_nic *efx)
  979. {
  980. struct falcon_nic_data *nic_data = efx->nic_data;
  981. if (!nic_data->stats_pending)
  982. return;
  983. nic_data->stats_pending = false;
  984. if (*nic_data->stats_dma_done == FALCON_STATS_DONE) {
  985. rmb(); /* read the done flag before the stats */
  986. falcon_update_stats_xmac(efx);
  987. } else {
  988. netif_err(efx, hw, efx->net_dev,
  989. "timed out waiting for statistics\n");
  990. }
  991. }
  992. static void falcon_stats_timer_func(unsigned long context)
  993. {
  994. struct efx_nic *efx = (struct efx_nic *)context;
  995. struct falcon_nic_data *nic_data = efx->nic_data;
  996. spin_lock(&efx->stats_lock);
  997. falcon_stats_complete(efx);
  998. if (nic_data->stats_disable_count == 0)
  999. falcon_stats_request(efx);
  1000. spin_unlock(&efx->stats_lock);
  1001. }
  1002. static bool falcon_loopback_link_poll(struct efx_nic *efx)
  1003. {
  1004. struct efx_link_state old_state = efx->link_state;
  1005. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1006. WARN_ON(!LOOPBACK_INTERNAL(efx));
  1007. efx->link_state.fd = true;
  1008. efx->link_state.fc = efx->wanted_fc;
  1009. efx->link_state.up = true;
  1010. efx->link_state.speed = 10000;
  1011. return !efx_link_state_equal(&efx->link_state, &old_state);
  1012. }
  1013. static int falcon_reconfigure_port(struct efx_nic *efx)
  1014. {
  1015. int rc;
  1016. WARN_ON(efx_nic_rev(efx) > EFX_REV_FALCON_B0);
  1017. /* Poll the PHY link state *before* reconfiguring it. This means we
  1018. * will pick up the correct speed (in loopback) to select the correct
  1019. * MAC.
  1020. */
  1021. if (LOOPBACK_INTERNAL(efx))
  1022. falcon_loopback_link_poll(efx);
  1023. else
  1024. efx->phy_op->poll(efx);
  1025. falcon_stop_nic_stats(efx);
  1026. falcon_deconfigure_mac_wrapper(efx);
  1027. falcon_reset_macs(efx);
  1028. efx->phy_op->reconfigure(efx);
  1029. rc = falcon_reconfigure_xmac(efx);
  1030. BUG_ON(rc);
  1031. falcon_start_nic_stats(efx);
  1032. /* Synchronise efx->link_state with the kernel */
  1033. efx_link_status_changed(efx);
  1034. return 0;
  1035. }
  1036. /* TX flow control may automatically turn itself off if the link
  1037. * partner (intermittently) stops responding to pause frames. There
  1038. * isn't any indication that this has happened, so the best we do is
  1039. * leave it up to the user to spot this and fix it by cycling transmit
  1040. * flow control on this end.
  1041. */
  1042. static void falcon_a1_prepare_enable_fc_tx(struct efx_nic *efx)
  1043. {
  1044. /* Schedule a reset to recover */
  1045. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  1046. }
  1047. static void falcon_b0_prepare_enable_fc_tx(struct efx_nic *efx)
  1048. {
  1049. /* Recover by resetting the EM block */
  1050. falcon_stop_nic_stats(efx);
  1051. falcon_drain_tx_fifo(efx);
  1052. falcon_reconfigure_xmac(efx);
  1053. falcon_start_nic_stats(efx);
  1054. }
  1055. /**************************************************************************
  1056. *
  1057. * PHY access via GMII
  1058. *
  1059. **************************************************************************
  1060. */
  1061. /* Wait for GMII access to complete */
  1062. static int falcon_gmii_wait(struct efx_nic *efx)
  1063. {
  1064. efx_oword_t md_stat;
  1065. int count;
  1066. /* wait up to 50ms - taken max from datasheet */
  1067. for (count = 0; count < 5000; count++) {
  1068. efx_reado(efx, &md_stat, FR_AB_MD_STAT);
  1069. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) {
  1070. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 ||
  1071. EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) {
  1072. netif_err(efx, hw, efx->net_dev,
  1073. "error from GMII access "
  1074. EFX_OWORD_FMT"\n",
  1075. EFX_OWORD_VAL(md_stat));
  1076. return -EIO;
  1077. }
  1078. return 0;
  1079. }
  1080. udelay(10);
  1081. }
  1082. netif_err(efx, hw, efx->net_dev, "timed out waiting for GMII\n");
  1083. return -ETIMEDOUT;
  1084. }
  1085. /* Write an MDIO register of a PHY connected to Falcon. */
  1086. static int falcon_mdio_write(struct net_device *net_dev,
  1087. int prtad, int devad, u16 addr, u16 value)
  1088. {
  1089. struct efx_nic *efx = netdev_priv(net_dev);
  1090. struct falcon_nic_data *nic_data = efx->nic_data;
  1091. efx_oword_t reg;
  1092. int rc;
  1093. netif_vdbg(efx, hw, efx->net_dev,
  1094. "writing MDIO %d register %d.%d with 0x%04x\n",
  1095. prtad, devad, addr, value);
  1096. mutex_lock(&nic_data->mdio_lock);
  1097. /* Check MDIO not currently being accessed */
  1098. rc = falcon_gmii_wait(efx);
  1099. if (rc)
  1100. goto out;
  1101. /* Write the address/ID register */
  1102. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1103. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1104. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1105. FRF_AB_MD_DEV_ADR, devad);
  1106. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1107. /* Write data */
  1108. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value);
  1109. efx_writeo(efx, &reg, FR_AB_MD_TXD);
  1110. EFX_POPULATE_OWORD_2(reg,
  1111. FRF_AB_MD_WRC, 1,
  1112. FRF_AB_MD_GC, 0);
  1113. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1114. /* Wait for data to be written */
  1115. rc = falcon_gmii_wait(efx);
  1116. if (rc) {
  1117. /* Abort the write operation */
  1118. EFX_POPULATE_OWORD_2(reg,
  1119. FRF_AB_MD_WRC, 0,
  1120. FRF_AB_MD_GC, 1);
  1121. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1122. udelay(10);
  1123. }
  1124. out:
  1125. mutex_unlock(&nic_data->mdio_lock);
  1126. return rc;
  1127. }
  1128. /* Read an MDIO register of a PHY connected to Falcon. */
  1129. static int falcon_mdio_read(struct net_device *net_dev,
  1130. int prtad, int devad, u16 addr)
  1131. {
  1132. struct efx_nic *efx = netdev_priv(net_dev);
  1133. struct falcon_nic_data *nic_data = efx->nic_data;
  1134. efx_oword_t reg;
  1135. int rc;
  1136. mutex_lock(&nic_data->mdio_lock);
  1137. /* Check MDIO not currently being accessed */
  1138. rc = falcon_gmii_wait(efx);
  1139. if (rc)
  1140. goto out;
  1141. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1142. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1143. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1144. FRF_AB_MD_DEV_ADR, devad);
  1145. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1146. /* Request data to be read */
  1147. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
  1148. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1149. /* Wait for data to become available */
  1150. rc = falcon_gmii_wait(efx);
  1151. if (rc == 0) {
  1152. efx_reado(efx, &reg, FR_AB_MD_RXD);
  1153. rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
  1154. netif_vdbg(efx, hw, efx->net_dev,
  1155. "read from MDIO %d register %d.%d, got %04x\n",
  1156. prtad, devad, addr, rc);
  1157. } else {
  1158. /* Abort the read operation */
  1159. EFX_POPULATE_OWORD_2(reg,
  1160. FRF_AB_MD_RIC, 0,
  1161. FRF_AB_MD_GC, 1);
  1162. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1163. netif_dbg(efx, hw, efx->net_dev,
  1164. "read from MDIO %d register %d.%d, got error %d\n",
  1165. prtad, devad, addr, rc);
  1166. }
  1167. out:
  1168. mutex_unlock(&nic_data->mdio_lock);
  1169. return rc;
  1170. }
  1171. /* This call is responsible for hooking in the MAC and PHY operations */
  1172. static int falcon_probe_port(struct efx_nic *efx)
  1173. {
  1174. struct falcon_nic_data *nic_data = efx->nic_data;
  1175. int rc;
  1176. switch (efx->phy_type) {
  1177. case PHY_TYPE_SFX7101:
  1178. efx->phy_op = &falcon_sfx7101_phy_ops;
  1179. break;
  1180. case PHY_TYPE_QT2022C2:
  1181. case PHY_TYPE_QT2025C:
  1182. efx->phy_op = &falcon_qt202x_phy_ops;
  1183. break;
  1184. case PHY_TYPE_TXC43128:
  1185. efx->phy_op = &falcon_txc_phy_ops;
  1186. break;
  1187. default:
  1188. netif_err(efx, probe, efx->net_dev, "Unknown PHY type %d\n",
  1189. efx->phy_type);
  1190. return -ENODEV;
  1191. }
  1192. /* Fill out MDIO structure and loopback modes */
  1193. mutex_init(&nic_data->mdio_lock);
  1194. efx->mdio.mdio_read = falcon_mdio_read;
  1195. efx->mdio.mdio_write = falcon_mdio_write;
  1196. rc = efx->phy_op->probe(efx);
  1197. if (rc != 0)
  1198. return rc;
  1199. /* Initial assumption */
  1200. efx->link_state.speed = 10000;
  1201. efx->link_state.fd = true;
  1202. /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
  1203. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1204. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  1205. else
  1206. efx->wanted_fc = EFX_FC_RX;
  1207. if (efx->mdio.mmds & MDIO_DEVS_AN)
  1208. efx->wanted_fc |= EFX_FC_AUTO;
  1209. /* Allocate buffer for stats */
  1210. rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
  1211. FALCON_MAC_STATS_SIZE, GFP_KERNEL);
  1212. if (rc)
  1213. return rc;
  1214. netif_dbg(efx, probe, efx->net_dev,
  1215. "stats buffer at %llx (virt %p phys %llx)\n",
  1216. (u64)efx->stats_buffer.dma_addr,
  1217. efx->stats_buffer.addr,
  1218. (u64)virt_to_phys(efx->stats_buffer.addr));
  1219. nic_data->stats_dma_done = efx->stats_buffer.addr + XgDmaDone_offset;
  1220. return 0;
  1221. }
  1222. static void falcon_remove_port(struct efx_nic *efx)
  1223. {
  1224. efx->phy_op->remove(efx);
  1225. efx_nic_free_buffer(efx, &efx->stats_buffer);
  1226. }
  1227. /* Global events are basically PHY events */
  1228. static bool
  1229. falcon_handle_global_event(struct efx_channel *channel, efx_qword_t *event)
  1230. {
  1231. struct efx_nic *efx = channel->efx;
  1232. struct falcon_nic_data *nic_data = efx->nic_data;
  1233. if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
  1234. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
  1235. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR))
  1236. /* Ignored */
  1237. return true;
  1238. if ((efx_nic_rev(efx) == EFX_REV_FALCON_B0) &&
  1239. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
  1240. nic_data->xmac_poll_required = true;
  1241. return true;
  1242. }
  1243. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ?
  1244. EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
  1245. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
  1246. netif_err(efx, rx_err, efx->net_dev,
  1247. "channel %d seen global RX_RESET event. Resetting.\n",
  1248. channel->channel);
  1249. atomic_inc(&efx->rx_reset);
  1250. efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
  1251. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  1252. return true;
  1253. }
  1254. return false;
  1255. }
  1256. /**************************************************************************
  1257. *
  1258. * Falcon test code
  1259. *
  1260. **************************************************************************/
  1261. static int
  1262. falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
  1263. {
  1264. struct falcon_nic_data *nic_data = efx->nic_data;
  1265. struct falcon_nvconfig *nvconfig;
  1266. struct efx_spi_device *spi;
  1267. void *region;
  1268. int rc, magic_num, struct_ver;
  1269. __le16 *word, *limit;
  1270. u32 csum;
  1271. if (efx_spi_present(&nic_data->spi_flash))
  1272. spi = &nic_data->spi_flash;
  1273. else if (efx_spi_present(&nic_data->spi_eeprom))
  1274. spi = &nic_data->spi_eeprom;
  1275. else
  1276. return -EINVAL;
  1277. region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
  1278. if (!region)
  1279. return -ENOMEM;
  1280. nvconfig = region + FALCON_NVCONFIG_OFFSET;
  1281. mutex_lock(&nic_data->spi_lock);
  1282. rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region);
  1283. mutex_unlock(&nic_data->spi_lock);
  1284. if (rc) {
  1285. netif_err(efx, hw, efx->net_dev, "Failed to read %s\n",
  1286. efx_spi_present(&nic_data->spi_flash) ?
  1287. "flash" : "EEPROM");
  1288. rc = -EIO;
  1289. goto out;
  1290. }
  1291. magic_num = le16_to_cpu(nvconfig->board_magic_num);
  1292. struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
  1293. rc = -EINVAL;
  1294. if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
  1295. netif_err(efx, hw, efx->net_dev,
  1296. "NVRAM bad magic 0x%x\n", magic_num);
  1297. goto out;
  1298. }
  1299. if (struct_ver < 2) {
  1300. netif_err(efx, hw, efx->net_dev,
  1301. "NVRAM has ancient version 0x%x\n", struct_ver);
  1302. goto out;
  1303. } else if (struct_ver < 4) {
  1304. word = &nvconfig->board_magic_num;
  1305. limit = (__le16 *) (nvconfig + 1);
  1306. } else {
  1307. word = region;
  1308. limit = region + FALCON_NVCONFIG_END;
  1309. }
  1310. for (csum = 0; word < limit; ++word)
  1311. csum += le16_to_cpu(*word);
  1312. if (~csum & 0xffff) {
  1313. netif_err(efx, hw, efx->net_dev,
  1314. "NVRAM has incorrect checksum\n");
  1315. goto out;
  1316. }
  1317. rc = 0;
  1318. if (nvconfig_out)
  1319. memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
  1320. out:
  1321. kfree(region);
  1322. return rc;
  1323. }
  1324. static int falcon_test_nvram(struct efx_nic *efx)
  1325. {
  1326. return falcon_read_nvram(efx, NULL);
  1327. }
  1328. static const struct efx_nic_register_test falcon_b0_register_tests[] = {
  1329. { FR_AZ_ADR_REGION,
  1330. EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
  1331. { FR_AZ_RX_CFG,
  1332. EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
  1333. { FR_AZ_TX_CFG,
  1334. EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
  1335. { FR_AZ_TX_RESERVED,
  1336. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  1337. { FR_AB_MAC_CTRL,
  1338. EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
  1339. { FR_AZ_SRM_TX_DC_CFG,
  1340. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  1341. { FR_AZ_RX_DC_CFG,
  1342. EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
  1343. { FR_AZ_RX_DC_PF_WM,
  1344. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  1345. { FR_BZ_DP_CTRL,
  1346. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  1347. { FR_AB_GM_CFG2,
  1348. EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
  1349. { FR_AB_GMF_CFG0,
  1350. EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
  1351. { FR_AB_XM_GLB_CFG,
  1352. EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
  1353. { FR_AB_XM_TX_CFG,
  1354. EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
  1355. { FR_AB_XM_RX_CFG,
  1356. EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
  1357. { FR_AB_XM_RX_PARAM,
  1358. EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
  1359. { FR_AB_XM_FC,
  1360. EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
  1361. { FR_AB_XM_ADR_LO,
  1362. EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
  1363. { FR_AB_XX_SD_CTL,
  1364. EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
  1365. };
  1366. static int
  1367. falcon_b0_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
  1368. {
  1369. enum reset_type reset_method = RESET_TYPE_INVISIBLE;
  1370. int rc, rc2;
  1371. mutex_lock(&efx->mac_lock);
  1372. if (efx->loopback_modes) {
  1373. /* We need the 312 clock from the PHY to test the XMAC
  1374. * registers, so move into XGMII loopback if available */
  1375. if (efx->loopback_modes & (1 << LOOPBACK_XGMII))
  1376. efx->loopback_mode = LOOPBACK_XGMII;
  1377. else
  1378. efx->loopback_mode = __ffs(efx->loopback_modes);
  1379. }
  1380. __efx_reconfigure_port(efx);
  1381. mutex_unlock(&efx->mac_lock);
  1382. efx_reset_down(efx, reset_method);
  1383. tests->registers =
  1384. efx_nic_test_registers(efx, falcon_b0_register_tests,
  1385. ARRAY_SIZE(falcon_b0_register_tests))
  1386. ? -1 : 1;
  1387. rc = falcon_reset_hw(efx, reset_method);
  1388. rc2 = efx_reset_up(efx, reset_method, rc == 0);
  1389. return rc ? rc : rc2;
  1390. }
  1391. /**************************************************************************
  1392. *
  1393. * Device reset
  1394. *
  1395. **************************************************************************
  1396. */
  1397. static enum reset_type falcon_map_reset_reason(enum reset_type reason)
  1398. {
  1399. switch (reason) {
  1400. case RESET_TYPE_RX_RECOVERY:
  1401. case RESET_TYPE_RX_DESC_FETCH:
  1402. case RESET_TYPE_TX_DESC_FETCH:
  1403. case RESET_TYPE_TX_SKIP:
  1404. /* These can occasionally occur due to hardware bugs.
  1405. * We try to reset without disrupting the link.
  1406. */
  1407. return RESET_TYPE_INVISIBLE;
  1408. default:
  1409. return RESET_TYPE_ALL;
  1410. }
  1411. }
  1412. static int falcon_map_reset_flags(u32 *flags)
  1413. {
  1414. enum {
  1415. FALCON_RESET_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER |
  1416. ETH_RESET_OFFLOAD | ETH_RESET_MAC),
  1417. FALCON_RESET_ALL = FALCON_RESET_INVISIBLE | ETH_RESET_PHY,
  1418. FALCON_RESET_WORLD = FALCON_RESET_ALL | ETH_RESET_IRQ,
  1419. };
  1420. if ((*flags & FALCON_RESET_WORLD) == FALCON_RESET_WORLD) {
  1421. *flags &= ~FALCON_RESET_WORLD;
  1422. return RESET_TYPE_WORLD;
  1423. }
  1424. if ((*flags & FALCON_RESET_ALL) == FALCON_RESET_ALL) {
  1425. *flags &= ~FALCON_RESET_ALL;
  1426. return RESET_TYPE_ALL;
  1427. }
  1428. if ((*flags & FALCON_RESET_INVISIBLE) == FALCON_RESET_INVISIBLE) {
  1429. *flags &= ~FALCON_RESET_INVISIBLE;
  1430. return RESET_TYPE_INVISIBLE;
  1431. }
  1432. return -EINVAL;
  1433. }
  1434. /* Resets NIC to known state. This routine must be called in process
  1435. * context and is allowed to sleep. */
  1436. static int __falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  1437. {
  1438. struct falcon_nic_data *nic_data = efx->nic_data;
  1439. efx_oword_t glb_ctl_reg_ker;
  1440. int rc;
  1441. netif_dbg(efx, hw, efx->net_dev, "performing %s hardware reset\n",
  1442. RESET_TYPE(method));
  1443. /* Initiate device reset */
  1444. if (method == RESET_TYPE_WORLD) {
  1445. rc = pci_save_state(efx->pci_dev);
  1446. if (rc) {
  1447. netif_err(efx, drv, efx->net_dev,
  1448. "failed to backup PCI state of primary "
  1449. "function prior to hardware reset\n");
  1450. goto fail1;
  1451. }
  1452. if (efx_nic_is_dual_func(efx)) {
  1453. rc = pci_save_state(nic_data->pci_dev2);
  1454. if (rc) {
  1455. netif_err(efx, drv, efx->net_dev,
  1456. "failed to backup PCI state of "
  1457. "secondary function prior to "
  1458. "hardware reset\n");
  1459. goto fail2;
  1460. }
  1461. }
  1462. EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
  1463. FRF_AB_EXT_PHY_RST_DUR,
  1464. FFE_AB_EXT_PHY_RST_DUR_10240US,
  1465. FRF_AB_SWRST, 1);
  1466. } else {
  1467. EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
  1468. /* exclude PHY from "invisible" reset */
  1469. FRF_AB_EXT_PHY_RST_CTL,
  1470. method == RESET_TYPE_INVISIBLE,
  1471. /* exclude EEPROM/flash and PCIe */
  1472. FRF_AB_PCIE_CORE_RST_CTL, 1,
  1473. FRF_AB_PCIE_NSTKY_RST_CTL, 1,
  1474. FRF_AB_PCIE_SD_RST_CTL, 1,
  1475. FRF_AB_EE_RST_CTL, 1,
  1476. FRF_AB_EXT_PHY_RST_DUR,
  1477. FFE_AB_EXT_PHY_RST_DUR_10240US,
  1478. FRF_AB_SWRST, 1);
  1479. }
  1480. efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  1481. netif_dbg(efx, hw, efx->net_dev, "waiting for hardware reset\n");
  1482. schedule_timeout_uninterruptible(HZ / 20);
  1483. /* Restore PCI configuration if needed */
  1484. if (method == RESET_TYPE_WORLD) {
  1485. if (efx_nic_is_dual_func(efx))
  1486. pci_restore_state(nic_data->pci_dev2);
  1487. pci_restore_state(efx->pci_dev);
  1488. netif_dbg(efx, drv, efx->net_dev,
  1489. "successfully restored PCI config\n");
  1490. }
  1491. /* Assert that reset complete */
  1492. efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  1493. if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
  1494. rc = -ETIMEDOUT;
  1495. netif_err(efx, hw, efx->net_dev,
  1496. "timed out waiting for hardware reset\n");
  1497. goto fail3;
  1498. }
  1499. netif_dbg(efx, hw, efx->net_dev, "hardware reset complete\n");
  1500. return 0;
  1501. /* pci_save_state() and pci_restore_state() MUST be called in pairs */
  1502. fail2:
  1503. pci_restore_state(efx->pci_dev);
  1504. fail1:
  1505. fail3:
  1506. return rc;
  1507. }
  1508. static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  1509. {
  1510. struct falcon_nic_data *nic_data = efx->nic_data;
  1511. int rc;
  1512. mutex_lock(&nic_data->spi_lock);
  1513. rc = __falcon_reset_hw(efx, method);
  1514. mutex_unlock(&nic_data->spi_lock);
  1515. return rc;
  1516. }
  1517. static void falcon_monitor(struct efx_nic *efx)
  1518. {
  1519. bool link_changed;
  1520. int rc;
  1521. BUG_ON(!mutex_is_locked(&efx->mac_lock));
  1522. rc = falcon_board(efx)->type->monitor(efx);
  1523. if (rc) {
  1524. netif_err(efx, hw, efx->net_dev,
  1525. "Board sensor %s; shutting down PHY\n",
  1526. (rc == -ERANGE) ? "reported fault" : "failed");
  1527. efx->phy_mode |= PHY_MODE_LOW_POWER;
  1528. rc = __efx_reconfigure_port(efx);
  1529. WARN_ON(rc);
  1530. }
  1531. if (LOOPBACK_INTERNAL(efx))
  1532. link_changed = falcon_loopback_link_poll(efx);
  1533. else
  1534. link_changed = efx->phy_op->poll(efx);
  1535. if (link_changed) {
  1536. falcon_stop_nic_stats(efx);
  1537. falcon_deconfigure_mac_wrapper(efx);
  1538. falcon_reset_macs(efx);
  1539. rc = falcon_reconfigure_xmac(efx);
  1540. BUG_ON(rc);
  1541. falcon_start_nic_stats(efx);
  1542. efx_link_status_changed(efx);
  1543. }
  1544. falcon_poll_xmac(efx);
  1545. }
  1546. /* Zeroes out the SRAM contents. This routine must be called in
  1547. * process context and is allowed to sleep.
  1548. */
  1549. static int falcon_reset_sram(struct efx_nic *efx)
  1550. {
  1551. efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
  1552. int count;
  1553. /* Set the SRAM wake/sleep GPIO appropriately. */
  1554. efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1555. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
  1556. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
  1557. efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1558. /* Initiate SRAM reset */
  1559. EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
  1560. FRF_AZ_SRM_INIT_EN, 1,
  1561. FRF_AZ_SRM_NB_SZ, 0);
  1562. efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1563. /* Wait for SRAM reset to complete */
  1564. count = 0;
  1565. do {
  1566. netif_dbg(efx, hw, efx->net_dev,
  1567. "waiting for SRAM reset (attempt %d)...\n", count);
  1568. /* SRAM reset is slow; expect around 16ms */
  1569. schedule_timeout_uninterruptible(HZ / 50);
  1570. /* Check for reset complete */
  1571. efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1572. if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
  1573. netif_dbg(efx, hw, efx->net_dev,
  1574. "SRAM reset complete\n");
  1575. return 0;
  1576. }
  1577. } while (++count < 20); /* wait up to 0.4 sec */
  1578. netif_err(efx, hw, efx->net_dev, "timed out waiting for SRAM reset\n");
  1579. return -ETIMEDOUT;
  1580. }
  1581. static void falcon_spi_device_init(struct efx_nic *efx,
  1582. struct efx_spi_device *spi_device,
  1583. unsigned int device_id, u32 device_type)
  1584. {
  1585. if (device_type != 0) {
  1586. spi_device->device_id = device_id;
  1587. spi_device->size =
  1588. 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
  1589. spi_device->addr_len =
  1590. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
  1591. spi_device->munge_address = (spi_device->size == 1 << 9 &&
  1592. spi_device->addr_len == 1);
  1593. spi_device->erase_command =
  1594. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
  1595. spi_device->erase_size =
  1596. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1597. SPI_DEV_TYPE_ERASE_SIZE);
  1598. spi_device->block_size =
  1599. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1600. SPI_DEV_TYPE_BLOCK_SIZE);
  1601. } else {
  1602. spi_device->size = 0;
  1603. }
  1604. }
  1605. /* Extract non-volatile configuration */
  1606. static int falcon_probe_nvconfig(struct efx_nic *efx)
  1607. {
  1608. struct falcon_nic_data *nic_data = efx->nic_data;
  1609. struct falcon_nvconfig *nvconfig;
  1610. int rc;
  1611. nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
  1612. if (!nvconfig)
  1613. return -ENOMEM;
  1614. rc = falcon_read_nvram(efx, nvconfig);
  1615. if (rc)
  1616. goto out;
  1617. efx->phy_type = nvconfig->board_v2.port0_phy_type;
  1618. efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr;
  1619. if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
  1620. falcon_spi_device_init(
  1621. efx, &nic_data->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
  1622. le32_to_cpu(nvconfig->board_v3
  1623. .spi_device_type[FFE_AB_SPI_DEVICE_FLASH]));
  1624. falcon_spi_device_init(
  1625. efx, &nic_data->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
  1626. le32_to_cpu(nvconfig->board_v3
  1627. .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM]));
  1628. }
  1629. /* Read the MAC addresses */
  1630. memcpy(efx->net_dev->perm_addr, nvconfig->mac_address[0], ETH_ALEN);
  1631. netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n",
  1632. efx->phy_type, efx->mdio.prtad);
  1633. rc = falcon_probe_board(efx,
  1634. le16_to_cpu(nvconfig->board_v2.board_revision));
  1635. out:
  1636. kfree(nvconfig);
  1637. return rc;
  1638. }
  1639. static void falcon_dimension_resources(struct efx_nic *efx)
  1640. {
  1641. efx->rx_dc_base = 0x20000;
  1642. efx->tx_dc_base = 0x26000;
  1643. }
  1644. /* Probe all SPI devices on the NIC */
  1645. static void falcon_probe_spi_devices(struct efx_nic *efx)
  1646. {
  1647. struct falcon_nic_data *nic_data = efx->nic_data;
  1648. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  1649. int boot_dev;
  1650. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  1651. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1652. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1653. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  1654. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  1655. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  1656. netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n",
  1657. boot_dev == FFE_AB_SPI_DEVICE_FLASH ?
  1658. "flash" : "EEPROM");
  1659. } else {
  1660. /* Disable VPD and set clock dividers to safe
  1661. * values for initial programming. */
  1662. boot_dev = -1;
  1663. netif_dbg(efx, probe, efx->net_dev,
  1664. "Booted from internal ASIC settings;"
  1665. " setting SPI config\n");
  1666. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  1667. /* 125 MHz / 7 ~= 20 MHz */
  1668. FRF_AB_EE_SF_CLOCK_DIV, 7,
  1669. /* 125 MHz / 63 ~= 2 MHz */
  1670. FRF_AB_EE_EE_CLOCK_DIV, 63);
  1671. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1672. }
  1673. mutex_init(&nic_data->spi_lock);
  1674. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  1675. falcon_spi_device_init(efx, &nic_data->spi_flash,
  1676. FFE_AB_SPI_DEVICE_FLASH,
  1677. default_flash_type);
  1678. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  1679. falcon_spi_device_init(efx, &nic_data->spi_eeprom,
  1680. FFE_AB_SPI_DEVICE_EEPROM,
  1681. large_eeprom_type);
  1682. }
  1683. static int falcon_probe_nic(struct efx_nic *efx)
  1684. {
  1685. struct falcon_nic_data *nic_data;
  1686. struct falcon_board *board;
  1687. int rc;
  1688. /* Allocate storage for hardware specific data */
  1689. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  1690. if (!nic_data)
  1691. return -ENOMEM;
  1692. efx->nic_data = nic_data;
  1693. rc = -ENODEV;
  1694. if (efx_nic_fpga_ver(efx) != 0) {
  1695. netif_err(efx, probe, efx->net_dev,
  1696. "Falcon FPGA not supported\n");
  1697. goto fail1;
  1698. }
  1699. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1700. efx_oword_t nic_stat;
  1701. struct pci_dev *dev;
  1702. u8 pci_rev = efx->pci_dev->revision;
  1703. if ((pci_rev == 0xff) || (pci_rev == 0)) {
  1704. netif_err(efx, probe, efx->net_dev,
  1705. "Falcon rev A0 not supported\n");
  1706. goto fail1;
  1707. }
  1708. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1709. if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) {
  1710. netif_err(efx, probe, efx->net_dev,
  1711. "Falcon rev A1 1G not supported\n");
  1712. goto fail1;
  1713. }
  1714. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  1715. netif_err(efx, probe, efx->net_dev,
  1716. "Falcon rev A1 PCI-X not supported\n");
  1717. goto fail1;
  1718. }
  1719. dev = pci_dev_get(efx->pci_dev);
  1720. while ((dev = pci_get_device(PCI_VENDOR_ID_SOLARFLARE,
  1721. PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1,
  1722. dev))) {
  1723. if (dev->bus == efx->pci_dev->bus &&
  1724. dev->devfn == efx->pci_dev->devfn + 1) {
  1725. nic_data->pci_dev2 = dev;
  1726. break;
  1727. }
  1728. }
  1729. if (!nic_data->pci_dev2) {
  1730. netif_err(efx, probe, efx->net_dev,
  1731. "failed to find secondary function\n");
  1732. rc = -ENODEV;
  1733. goto fail2;
  1734. }
  1735. }
  1736. /* Now we can reset the NIC */
  1737. rc = __falcon_reset_hw(efx, RESET_TYPE_ALL);
  1738. if (rc) {
  1739. netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
  1740. goto fail3;
  1741. }
  1742. /* Allocate memory for INT_KER */
  1743. rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t),
  1744. GFP_KERNEL);
  1745. if (rc)
  1746. goto fail4;
  1747. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  1748. netif_dbg(efx, probe, efx->net_dev,
  1749. "INT_KER at %llx (virt %p phys %llx)\n",
  1750. (u64)efx->irq_status.dma_addr,
  1751. efx->irq_status.addr,
  1752. (u64)virt_to_phys(efx->irq_status.addr));
  1753. falcon_probe_spi_devices(efx);
  1754. /* Read in the non-volatile configuration */
  1755. rc = falcon_probe_nvconfig(efx);
  1756. if (rc) {
  1757. if (rc == -EINVAL)
  1758. netif_err(efx, probe, efx->net_dev, "NVRAM is invalid\n");
  1759. goto fail5;
  1760. }
  1761. efx->timer_quantum_ns = 4968; /* 621 cycles */
  1762. /* Initialise I2C adapter */
  1763. board = falcon_board(efx);
  1764. board->i2c_adap.owner = THIS_MODULE;
  1765. board->i2c_data = falcon_i2c_bit_operations;
  1766. board->i2c_data.data = efx;
  1767. board->i2c_adap.algo_data = &board->i2c_data;
  1768. board->i2c_adap.dev.parent = &efx->pci_dev->dev;
  1769. strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
  1770. sizeof(board->i2c_adap.name));
  1771. rc = i2c_bit_add_bus(&board->i2c_adap);
  1772. if (rc)
  1773. goto fail5;
  1774. rc = falcon_board(efx)->type->init(efx);
  1775. if (rc) {
  1776. netif_err(efx, probe, efx->net_dev,
  1777. "failed to initialise board\n");
  1778. goto fail6;
  1779. }
  1780. nic_data->stats_disable_count = 1;
  1781. setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
  1782. (unsigned long)efx);
  1783. return 0;
  1784. fail6:
  1785. i2c_del_adapter(&board->i2c_adap);
  1786. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1787. fail5:
  1788. efx_nic_free_buffer(efx, &efx->irq_status);
  1789. fail4:
  1790. fail3:
  1791. if (nic_data->pci_dev2) {
  1792. pci_dev_put(nic_data->pci_dev2);
  1793. nic_data->pci_dev2 = NULL;
  1794. }
  1795. fail2:
  1796. fail1:
  1797. kfree(efx->nic_data);
  1798. return rc;
  1799. }
  1800. static void falcon_init_rx_cfg(struct efx_nic *efx)
  1801. {
  1802. /* RX control FIFO thresholds (32 entries) */
  1803. const unsigned ctrl_xon_thr = 20;
  1804. const unsigned ctrl_xoff_thr = 25;
  1805. efx_oword_t reg;
  1806. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1807. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1808. /* Data FIFO size is 5.5K. The RX DMA engine only
  1809. * supports scattering for user-mode queues, but will
  1810. * split DMA writes at intervals of RX_USR_BUF_SIZE
  1811. * (32-byte units) even for kernel-mode queues. We
  1812. * set it to be so large that that never happens.
  1813. */
  1814. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  1815. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  1816. (3 * 4096) >> 5);
  1817. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, 512 >> 8);
  1818. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, 2048 >> 8);
  1819. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  1820. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1821. } else {
  1822. /* Data FIFO size is 80K; register fields moved */
  1823. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
  1824. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
  1825. EFX_RX_USR_BUF_SIZE >> 5);
  1826. /* Send XON and XOFF at ~3 * max MTU away from empty/full */
  1827. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, 27648 >> 8);
  1828. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, 54272 >> 8);
  1829. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  1830. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  1831. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  1832. /* Enable hash insertion. This is broken for the
  1833. * 'Falcon' hash so also select Toeplitz TCP/IPv4 and
  1834. * IPv4 hashes. */
  1835. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1);
  1836. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1);
  1837. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1);
  1838. }
  1839. /* Always enable XOFF signal from RX FIFO. We enable
  1840. * or disable transmission of pause frames at the MAC. */
  1841. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  1842. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1843. }
  1844. /* This call performs hardware-specific global initialisation, such as
  1845. * defining the descriptor cache sizes and number of RSS channels.
  1846. * It does not set up any buffers, descriptor rings or event queues.
  1847. */
  1848. static int falcon_init_nic(struct efx_nic *efx)
  1849. {
  1850. efx_oword_t temp;
  1851. int rc;
  1852. /* Use on-chip SRAM */
  1853. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  1854. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  1855. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  1856. rc = falcon_reset_sram(efx);
  1857. if (rc)
  1858. return rc;
  1859. /* Clear the parity enables on the TX data fifos as
  1860. * they produce false parity errors because of timing issues
  1861. */
  1862. if (EFX_WORKAROUND_5129(efx)) {
  1863. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  1864. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  1865. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  1866. }
  1867. if (EFX_WORKAROUND_7244(efx)) {
  1868. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1869. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  1870. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  1871. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  1872. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  1873. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  1874. }
  1875. /* XXX This is documented only for Falcon A0/A1 */
  1876. /* Setup RX. Wait for descriptor is broken and must
  1877. * be disabled. RXDP recovery shouldn't be needed, but is.
  1878. */
  1879. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  1880. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  1881. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  1882. if (EFX_WORKAROUND_5583(efx))
  1883. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  1884. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  1885. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  1886. * descriptors (which is bad).
  1887. */
  1888. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  1889. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  1890. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  1891. falcon_init_rx_cfg(efx);
  1892. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  1893. /* Set hash key for IPv4 */
  1894. memcpy(&temp, efx->rx_hash_key, sizeof(temp));
  1895. efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY);
  1896. /* Set destination of both TX and RX Flush events */
  1897. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  1898. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  1899. }
  1900. efx_nic_init_common(efx);
  1901. return 0;
  1902. }
  1903. static void falcon_remove_nic(struct efx_nic *efx)
  1904. {
  1905. struct falcon_nic_data *nic_data = efx->nic_data;
  1906. struct falcon_board *board = falcon_board(efx);
  1907. board->type->fini(efx);
  1908. /* Remove I2C adapter and clear it in preparation for a retry */
  1909. i2c_del_adapter(&board->i2c_adap);
  1910. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  1911. efx_nic_free_buffer(efx, &efx->irq_status);
  1912. __falcon_reset_hw(efx, RESET_TYPE_ALL);
  1913. /* Release the second function after the reset */
  1914. if (nic_data->pci_dev2) {
  1915. pci_dev_put(nic_data->pci_dev2);
  1916. nic_data->pci_dev2 = NULL;
  1917. }
  1918. /* Tear down the private nic state */
  1919. kfree(efx->nic_data);
  1920. efx->nic_data = NULL;
  1921. }
  1922. static void falcon_update_nic_stats(struct efx_nic *efx)
  1923. {
  1924. struct falcon_nic_data *nic_data = efx->nic_data;
  1925. efx_oword_t cnt;
  1926. if (nic_data->stats_disable_count)
  1927. return;
  1928. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  1929. efx->n_rx_nodesc_drop_cnt +=
  1930. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  1931. if (nic_data->stats_pending &&
  1932. *nic_data->stats_dma_done == FALCON_STATS_DONE) {
  1933. nic_data->stats_pending = false;
  1934. rmb(); /* read the done flag before the stats */
  1935. falcon_update_stats_xmac(efx);
  1936. }
  1937. }
  1938. void falcon_start_nic_stats(struct efx_nic *efx)
  1939. {
  1940. struct falcon_nic_data *nic_data = efx->nic_data;
  1941. spin_lock_bh(&efx->stats_lock);
  1942. if (--nic_data->stats_disable_count == 0)
  1943. falcon_stats_request(efx);
  1944. spin_unlock_bh(&efx->stats_lock);
  1945. }
  1946. void falcon_stop_nic_stats(struct efx_nic *efx)
  1947. {
  1948. struct falcon_nic_data *nic_data = efx->nic_data;
  1949. int i;
  1950. might_sleep();
  1951. spin_lock_bh(&efx->stats_lock);
  1952. ++nic_data->stats_disable_count;
  1953. spin_unlock_bh(&efx->stats_lock);
  1954. del_timer_sync(&nic_data->stats_timer);
  1955. /* Wait enough time for the most recent transfer to
  1956. * complete. */
  1957. for (i = 0; i < 4 && nic_data->stats_pending; i++) {
  1958. if (*nic_data->stats_dma_done == FALCON_STATS_DONE)
  1959. break;
  1960. msleep(1);
  1961. }
  1962. spin_lock_bh(&efx->stats_lock);
  1963. falcon_stats_complete(efx);
  1964. spin_unlock_bh(&efx->stats_lock);
  1965. }
  1966. static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  1967. {
  1968. falcon_board(efx)->type->set_id_led(efx, mode);
  1969. }
  1970. /**************************************************************************
  1971. *
  1972. * Wake on LAN
  1973. *
  1974. **************************************************************************
  1975. */
  1976. static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  1977. {
  1978. wol->supported = 0;
  1979. wol->wolopts = 0;
  1980. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1981. }
  1982. static int falcon_set_wol(struct efx_nic *efx, u32 type)
  1983. {
  1984. if (type != 0)
  1985. return -EINVAL;
  1986. return 0;
  1987. }
  1988. /**************************************************************************
  1989. *
  1990. * Revision-dependent attributes used by efx.c and nic.c
  1991. *
  1992. **************************************************************************
  1993. */
  1994. const struct efx_nic_type falcon_a1_nic_type = {
  1995. .probe = falcon_probe_nic,
  1996. .remove = falcon_remove_nic,
  1997. .init = falcon_init_nic,
  1998. .dimension_resources = falcon_dimension_resources,
  1999. .fini = efx_port_dummy_op_void,
  2000. .monitor = falcon_monitor,
  2001. .map_reset_reason = falcon_map_reset_reason,
  2002. .map_reset_flags = falcon_map_reset_flags,
  2003. .reset = falcon_reset_hw,
  2004. .probe_port = falcon_probe_port,
  2005. .remove_port = falcon_remove_port,
  2006. .handle_global_event = falcon_handle_global_event,
  2007. .prepare_flush = falcon_prepare_flush,
  2008. .finish_flush = efx_port_dummy_op_void,
  2009. .update_stats = falcon_update_nic_stats,
  2010. .start_stats = falcon_start_nic_stats,
  2011. .stop_stats = falcon_stop_nic_stats,
  2012. .set_id_led = falcon_set_id_led,
  2013. .push_irq_moderation = falcon_push_irq_moderation,
  2014. .reconfigure_port = falcon_reconfigure_port,
  2015. .prepare_enable_fc_tx = falcon_a1_prepare_enable_fc_tx,
  2016. .reconfigure_mac = falcon_reconfigure_xmac,
  2017. .check_mac_fault = falcon_xmac_check_fault,
  2018. .get_wol = falcon_get_wol,
  2019. .set_wol = falcon_set_wol,
  2020. .resume_wol = efx_port_dummy_op_void,
  2021. .test_nvram = falcon_test_nvram,
  2022. .revision = EFX_REV_FALCON_A1,
  2023. .mem_map_size = 0x20000,
  2024. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  2025. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  2026. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  2027. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  2028. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  2029. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2030. .rx_buffer_padding = 0x24,
  2031. .can_rx_scatter = false,
  2032. .max_interrupt_mode = EFX_INT_MODE_MSI,
  2033. .phys_addr_channels = 4,
  2034. .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH,
  2035. .offload_features = NETIF_F_IP_CSUM,
  2036. };
  2037. const struct efx_nic_type falcon_b0_nic_type = {
  2038. .probe = falcon_probe_nic,
  2039. .remove = falcon_remove_nic,
  2040. .init = falcon_init_nic,
  2041. .dimension_resources = falcon_dimension_resources,
  2042. .fini = efx_port_dummy_op_void,
  2043. .monitor = falcon_monitor,
  2044. .map_reset_reason = falcon_map_reset_reason,
  2045. .map_reset_flags = falcon_map_reset_flags,
  2046. .reset = falcon_reset_hw,
  2047. .probe_port = falcon_probe_port,
  2048. .remove_port = falcon_remove_port,
  2049. .handle_global_event = falcon_handle_global_event,
  2050. .prepare_flush = falcon_prepare_flush,
  2051. .finish_flush = efx_port_dummy_op_void,
  2052. .update_stats = falcon_update_nic_stats,
  2053. .start_stats = falcon_start_nic_stats,
  2054. .stop_stats = falcon_stop_nic_stats,
  2055. .set_id_led = falcon_set_id_led,
  2056. .push_irq_moderation = falcon_push_irq_moderation,
  2057. .reconfigure_port = falcon_reconfigure_port,
  2058. .prepare_enable_fc_tx = falcon_b0_prepare_enable_fc_tx,
  2059. .reconfigure_mac = falcon_reconfigure_xmac,
  2060. .check_mac_fault = falcon_xmac_check_fault,
  2061. .get_wol = falcon_get_wol,
  2062. .set_wol = falcon_set_wol,
  2063. .resume_wol = efx_port_dummy_op_void,
  2064. .test_chip = falcon_b0_test_chip,
  2065. .test_nvram = falcon_test_nvram,
  2066. .revision = EFX_REV_FALCON_B0,
  2067. /* Map everything up to and including the RSS indirection
  2068. * table. Don't map MSI-X table, MSI-X PBA since Linux
  2069. * requires that they not be mapped. */
  2070. .mem_map_size = (FR_BZ_RX_INDIRECTION_TBL +
  2071. FR_BZ_RX_INDIRECTION_TBL_STEP *
  2072. FR_BZ_RX_INDIRECTION_TBL_ROWS),
  2073. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  2074. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  2075. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  2076. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  2077. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  2078. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2079. .rx_buffer_hash_size = 0x10,
  2080. .rx_buffer_padding = 0,
  2081. .can_rx_scatter = true,
  2082. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  2083. .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
  2084. * interrupt handler only supports 32
  2085. * channels */
  2086. .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH,
  2087. .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH | NETIF_F_NTUPLE,
  2088. };