falcon.c 70 KB

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