falcon.c 85 KB

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