falcon.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910
  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 int dummy_rx_push_rss_config(struct efx_nic *efx, bool user,
  437. const u32 *rx_indir_table)
  438. {
  439. (void) efx;
  440. (void) user;
  441. (void) rx_indir_table;
  442. return -ENOSYS;
  443. }
  444. static int falcon_b0_rx_push_rss_config(struct efx_nic *efx, bool user,
  445. const u32 *rx_indir_table)
  446. {
  447. efx_oword_t temp;
  448. (void) user;
  449. /* Set hash key for IPv4 */
  450. memcpy(&temp, efx->rx_hash_key, sizeof(temp));
  451. efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY);
  452. memcpy(efx->rx_indir_table, rx_indir_table,
  453. sizeof(efx->rx_indir_table));
  454. efx_farch_rx_push_indir_table(efx);
  455. return 0;
  456. }
  457. /**************************************************************************
  458. *
  459. * EEPROM/flash
  460. *
  461. **************************************************************************
  462. */
  463. #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
  464. static int falcon_spi_poll(struct efx_nic *efx)
  465. {
  466. efx_oword_t reg;
  467. efx_reado(efx, &reg, FR_AB_EE_SPI_HCMD);
  468. return EFX_OWORD_FIELD(reg, FRF_AB_EE_SPI_HCMD_CMD_EN) ? -EBUSY : 0;
  469. }
  470. /* Wait for SPI command completion */
  471. static int falcon_spi_wait(struct efx_nic *efx)
  472. {
  473. /* Most commands will finish quickly, so we start polling at
  474. * very short intervals. Sometimes the command may have to
  475. * wait for VPD or expansion ROM access outside of our
  476. * control, so we allow up to 100 ms. */
  477. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10);
  478. int i;
  479. for (i = 0; i < 10; i++) {
  480. if (!falcon_spi_poll(efx))
  481. return 0;
  482. udelay(10);
  483. }
  484. for (;;) {
  485. if (!falcon_spi_poll(efx))
  486. return 0;
  487. if (time_after_eq(jiffies, timeout)) {
  488. netif_err(efx, hw, efx->net_dev,
  489. "timed out waiting for SPI\n");
  490. return -ETIMEDOUT;
  491. }
  492. schedule_timeout_uninterruptible(1);
  493. }
  494. }
  495. static int
  496. falcon_spi_cmd(struct efx_nic *efx, const struct falcon_spi_device *spi,
  497. unsigned int command, int address,
  498. const void *in, void *out, size_t len)
  499. {
  500. bool addressed = (address >= 0);
  501. bool reading = (out != NULL);
  502. efx_oword_t reg;
  503. int rc;
  504. /* Input validation */
  505. if (len > FALCON_SPI_MAX_LEN)
  506. return -EINVAL;
  507. /* Check that previous command is not still running */
  508. rc = falcon_spi_poll(efx);
  509. if (rc)
  510. return rc;
  511. /* Program address register, if we have an address */
  512. if (addressed) {
  513. EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address);
  514. efx_writeo(efx, &reg, FR_AB_EE_SPI_HADR);
  515. }
  516. /* Program data register, if we have data */
  517. if (in != NULL) {
  518. memcpy(&reg, in, len);
  519. efx_writeo(efx, &reg, FR_AB_EE_SPI_HDATA);
  520. }
  521. /* Issue read/write command */
  522. EFX_POPULATE_OWORD_7(reg,
  523. FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
  524. FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id,
  525. FRF_AB_EE_SPI_HCMD_DABCNT, len,
  526. FRF_AB_EE_SPI_HCMD_READ, reading,
  527. FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
  528. FRF_AB_EE_SPI_HCMD_ADBCNT,
  529. (addressed ? spi->addr_len : 0),
  530. FRF_AB_EE_SPI_HCMD_ENC, command);
  531. efx_writeo(efx, &reg, FR_AB_EE_SPI_HCMD);
  532. /* Wait for read/write to complete */
  533. rc = falcon_spi_wait(efx);
  534. if (rc)
  535. return rc;
  536. /* Read data */
  537. if (out != NULL) {
  538. efx_reado(efx, &reg, FR_AB_EE_SPI_HDATA);
  539. memcpy(out, &reg, len);
  540. }
  541. return 0;
  542. }
  543. static inline u8
  544. falcon_spi_munge_command(const struct falcon_spi_device *spi,
  545. const u8 command, const unsigned int address)
  546. {
  547. return command | (((address >> 8) & spi->munge_address) << 3);
  548. }
  549. static int
  550. falcon_spi_read(struct efx_nic *efx, const struct falcon_spi_device *spi,
  551. loff_t start, size_t len, size_t *retlen, u8 *buffer)
  552. {
  553. size_t block_len, pos = 0;
  554. unsigned int command;
  555. int rc = 0;
  556. while (pos < len) {
  557. block_len = min(len - pos, FALCON_SPI_MAX_LEN);
  558. command = falcon_spi_munge_command(spi, SPI_READ, start + pos);
  559. rc = falcon_spi_cmd(efx, spi, command, start + pos, NULL,
  560. buffer + pos, block_len);
  561. if (rc)
  562. break;
  563. pos += block_len;
  564. /* Avoid locking up the system */
  565. cond_resched();
  566. if (signal_pending(current)) {
  567. rc = -EINTR;
  568. break;
  569. }
  570. }
  571. if (retlen)
  572. *retlen = pos;
  573. return rc;
  574. }
  575. #ifdef CONFIG_SFC_MTD
  576. struct falcon_mtd_partition {
  577. struct efx_mtd_partition common;
  578. const struct falcon_spi_device *spi;
  579. size_t offset;
  580. };
  581. #define to_falcon_mtd_partition(mtd) \
  582. container_of(mtd, struct falcon_mtd_partition, common.mtd)
  583. static size_t
  584. falcon_spi_write_limit(const struct falcon_spi_device *spi, size_t start)
  585. {
  586. return min(FALCON_SPI_MAX_LEN,
  587. (spi->block_size - (start & (spi->block_size - 1))));
  588. }
  589. /* Wait up to 10 ms for buffered write completion */
  590. static int
  591. falcon_spi_wait_write(struct efx_nic *efx, const struct falcon_spi_device *spi)
  592. {
  593. unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100);
  594. u8 status;
  595. int rc;
  596. for (;;) {
  597. rc = falcon_spi_cmd(efx, spi, SPI_RDSR, -1, NULL,
  598. &status, sizeof(status));
  599. if (rc)
  600. return rc;
  601. if (!(status & SPI_STATUS_NRDY))
  602. return 0;
  603. if (time_after_eq(jiffies, timeout)) {
  604. netif_err(efx, hw, efx->net_dev,
  605. "SPI write timeout on device %d"
  606. " last status=0x%02x\n",
  607. spi->device_id, status);
  608. return -ETIMEDOUT;
  609. }
  610. schedule_timeout_uninterruptible(1);
  611. }
  612. }
  613. static int
  614. falcon_spi_write(struct efx_nic *efx, const struct falcon_spi_device *spi,
  615. loff_t start, size_t len, size_t *retlen, const u8 *buffer)
  616. {
  617. u8 verify_buffer[FALCON_SPI_MAX_LEN];
  618. size_t block_len, pos = 0;
  619. unsigned int command;
  620. int rc = 0;
  621. while (pos < len) {
  622. rc = falcon_spi_cmd(efx, spi, SPI_WREN, -1, NULL, NULL, 0);
  623. if (rc)
  624. break;
  625. block_len = min(len - pos,
  626. falcon_spi_write_limit(spi, start + pos));
  627. command = falcon_spi_munge_command(spi, SPI_WRITE, start + pos);
  628. rc = falcon_spi_cmd(efx, spi, command, start + pos,
  629. buffer + pos, NULL, block_len);
  630. if (rc)
  631. break;
  632. rc = falcon_spi_wait_write(efx, spi);
  633. if (rc)
  634. break;
  635. command = falcon_spi_munge_command(spi, SPI_READ, start + pos);
  636. rc = falcon_spi_cmd(efx, spi, command, start + pos,
  637. NULL, verify_buffer, block_len);
  638. if (memcmp(verify_buffer, buffer + pos, block_len)) {
  639. rc = -EIO;
  640. break;
  641. }
  642. pos += block_len;
  643. /* Avoid locking up the system */
  644. cond_resched();
  645. if (signal_pending(current)) {
  646. rc = -EINTR;
  647. break;
  648. }
  649. }
  650. if (retlen)
  651. *retlen = pos;
  652. return rc;
  653. }
  654. static int
  655. falcon_spi_slow_wait(struct falcon_mtd_partition *part, bool uninterruptible)
  656. {
  657. const struct falcon_spi_device *spi = part->spi;
  658. struct efx_nic *efx = part->common.mtd.priv;
  659. u8 status;
  660. int rc, i;
  661. /* Wait up to 4s for flash/EEPROM to finish a slow operation. */
  662. for (i = 0; i < 40; i++) {
  663. __set_current_state(uninterruptible ?
  664. TASK_UNINTERRUPTIBLE : TASK_INTERRUPTIBLE);
  665. schedule_timeout(HZ / 10);
  666. rc = falcon_spi_cmd(efx, spi, SPI_RDSR, -1, NULL,
  667. &status, sizeof(status));
  668. if (rc)
  669. return rc;
  670. if (!(status & SPI_STATUS_NRDY))
  671. return 0;
  672. if (signal_pending(current))
  673. return -EINTR;
  674. }
  675. pr_err("%s: timed out waiting for %s\n",
  676. part->common.name, part->common.dev_type_name);
  677. return -ETIMEDOUT;
  678. }
  679. static int
  680. falcon_spi_unlock(struct efx_nic *efx, const struct falcon_spi_device *spi)
  681. {
  682. const u8 unlock_mask = (SPI_STATUS_BP2 | SPI_STATUS_BP1 |
  683. SPI_STATUS_BP0);
  684. u8 status;
  685. int rc;
  686. rc = falcon_spi_cmd(efx, spi, SPI_RDSR, -1, NULL,
  687. &status, sizeof(status));
  688. if (rc)
  689. return rc;
  690. if (!(status & unlock_mask))
  691. return 0; /* already unlocked */
  692. rc = falcon_spi_cmd(efx, spi, SPI_WREN, -1, NULL, NULL, 0);
  693. if (rc)
  694. return rc;
  695. rc = falcon_spi_cmd(efx, spi, SPI_SST_EWSR, -1, NULL, NULL, 0);
  696. if (rc)
  697. return rc;
  698. status &= ~unlock_mask;
  699. rc = falcon_spi_cmd(efx, spi, SPI_WRSR, -1, &status,
  700. NULL, sizeof(status));
  701. if (rc)
  702. return rc;
  703. rc = falcon_spi_wait_write(efx, spi);
  704. if (rc)
  705. return rc;
  706. return 0;
  707. }
  708. #define FALCON_SPI_VERIFY_BUF_LEN 16
  709. static int
  710. falcon_spi_erase(struct falcon_mtd_partition *part, loff_t start, size_t len)
  711. {
  712. const struct falcon_spi_device *spi = part->spi;
  713. struct efx_nic *efx = part->common.mtd.priv;
  714. unsigned pos, block_len;
  715. u8 empty[FALCON_SPI_VERIFY_BUF_LEN];
  716. u8 buffer[FALCON_SPI_VERIFY_BUF_LEN];
  717. int rc;
  718. if (len != spi->erase_size)
  719. return -EINVAL;
  720. if (spi->erase_command == 0)
  721. return -EOPNOTSUPP;
  722. rc = falcon_spi_unlock(efx, spi);
  723. if (rc)
  724. return rc;
  725. rc = falcon_spi_cmd(efx, spi, SPI_WREN, -1, NULL, NULL, 0);
  726. if (rc)
  727. return rc;
  728. rc = falcon_spi_cmd(efx, spi, spi->erase_command, start, NULL,
  729. NULL, 0);
  730. if (rc)
  731. return rc;
  732. rc = falcon_spi_slow_wait(part, false);
  733. /* Verify the entire region has been wiped */
  734. memset(empty, 0xff, sizeof(empty));
  735. for (pos = 0; pos < len; pos += block_len) {
  736. block_len = min(len - pos, sizeof(buffer));
  737. rc = falcon_spi_read(efx, spi, start + pos, block_len,
  738. NULL, buffer);
  739. if (rc)
  740. return rc;
  741. if (memcmp(empty, buffer, block_len))
  742. return -EIO;
  743. /* Avoid locking up the system */
  744. cond_resched();
  745. if (signal_pending(current))
  746. return -EINTR;
  747. }
  748. return rc;
  749. }
  750. static void falcon_mtd_rename(struct efx_mtd_partition *part)
  751. {
  752. struct efx_nic *efx = part->mtd.priv;
  753. snprintf(part->name, sizeof(part->name), "%s %s",
  754. efx->name, part->type_name);
  755. }
  756. static int falcon_mtd_read(struct mtd_info *mtd, loff_t start,
  757. size_t len, size_t *retlen, u8 *buffer)
  758. {
  759. struct falcon_mtd_partition *part = to_falcon_mtd_partition(mtd);
  760. struct efx_nic *efx = mtd->priv;
  761. struct falcon_nic_data *nic_data = efx->nic_data;
  762. int rc;
  763. rc = mutex_lock_interruptible(&nic_data->spi_lock);
  764. if (rc)
  765. return rc;
  766. rc = falcon_spi_read(efx, part->spi, part->offset + start,
  767. len, retlen, buffer);
  768. mutex_unlock(&nic_data->spi_lock);
  769. return rc;
  770. }
  771. static int falcon_mtd_erase(struct mtd_info *mtd, loff_t start, size_t len)
  772. {
  773. struct falcon_mtd_partition *part = to_falcon_mtd_partition(mtd);
  774. struct efx_nic *efx = mtd->priv;
  775. struct falcon_nic_data *nic_data = efx->nic_data;
  776. int rc;
  777. rc = mutex_lock_interruptible(&nic_data->spi_lock);
  778. if (rc)
  779. return rc;
  780. rc = falcon_spi_erase(part, part->offset + start, len);
  781. mutex_unlock(&nic_data->spi_lock);
  782. return rc;
  783. }
  784. static int falcon_mtd_write(struct mtd_info *mtd, loff_t start,
  785. size_t len, size_t *retlen, const u8 *buffer)
  786. {
  787. struct falcon_mtd_partition *part = to_falcon_mtd_partition(mtd);
  788. struct efx_nic *efx = mtd->priv;
  789. struct falcon_nic_data *nic_data = efx->nic_data;
  790. int rc;
  791. rc = mutex_lock_interruptible(&nic_data->spi_lock);
  792. if (rc)
  793. return rc;
  794. rc = falcon_spi_write(efx, part->spi, part->offset + start,
  795. len, retlen, buffer);
  796. mutex_unlock(&nic_data->spi_lock);
  797. return rc;
  798. }
  799. static int falcon_mtd_sync(struct mtd_info *mtd)
  800. {
  801. struct falcon_mtd_partition *part = to_falcon_mtd_partition(mtd);
  802. struct efx_nic *efx = mtd->priv;
  803. struct falcon_nic_data *nic_data = efx->nic_data;
  804. int rc;
  805. mutex_lock(&nic_data->spi_lock);
  806. rc = falcon_spi_slow_wait(part, true);
  807. mutex_unlock(&nic_data->spi_lock);
  808. return rc;
  809. }
  810. static int falcon_mtd_probe(struct efx_nic *efx)
  811. {
  812. struct falcon_nic_data *nic_data = efx->nic_data;
  813. struct falcon_mtd_partition *parts;
  814. struct falcon_spi_device *spi;
  815. size_t n_parts;
  816. int rc = -ENODEV;
  817. ASSERT_RTNL();
  818. /* Allocate space for maximum number of partitions */
  819. parts = kcalloc(2, sizeof(*parts), GFP_KERNEL);
  820. if (!parts)
  821. return -ENOMEM;
  822. n_parts = 0;
  823. spi = &nic_data->spi_flash;
  824. if (falcon_spi_present(spi) && spi->size > FALCON_FLASH_BOOTCODE_START) {
  825. parts[n_parts].spi = spi;
  826. parts[n_parts].offset = FALCON_FLASH_BOOTCODE_START;
  827. parts[n_parts].common.dev_type_name = "flash";
  828. parts[n_parts].common.type_name = "sfc_flash_bootrom";
  829. parts[n_parts].common.mtd.type = MTD_NORFLASH;
  830. parts[n_parts].common.mtd.flags = MTD_CAP_NORFLASH;
  831. parts[n_parts].common.mtd.size = spi->size - FALCON_FLASH_BOOTCODE_START;
  832. parts[n_parts].common.mtd.erasesize = spi->erase_size;
  833. n_parts++;
  834. }
  835. spi = &nic_data->spi_eeprom;
  836. if (falcon_spi_present(spi) && spi->size > FALCON_EEPROM_BOOTCONFIG_START) {
  837. parts[n_parts].spi = spi;
  838. parts[n_parts].offset = FALCON_EEPROM_BOOTCONFIG_START;
  839. parts[n_parts].common.dev_type_name = "EEPROM";
  840. parts[n_parts].common.type_name = "sfc_bootconfig";
  841. parts[n_parts].common.mtd.type = MTD_RAM;
  842. parts[n_parts].common.mtd.flags = MTD_CAP_RAM;
  843. parts[n_parts].common.mtd.size =
  844. min(spi->size, FALCON_EEPROM_BOOTCONFIG_END) -
  845. FALCON_EEPROM_BOOTCONFIG_START;
  846. parts[n_parts].common.mtd.erasesize = spi->erase_size;
  847. n_parts++;
  848. }
  849. rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
  850. if (rc)
  851. kfree(parts);
  852. return rc;
  853. }
  854. #endif /* CONFIG_SFC_MTD */
  855. /**************************************************************************
  856. *
  857. * XMAC operations
  858. *
  859. **************************************************************************
  860. */
  861. /* Configure the XAUI driver that is an output from Falcon */
  862. static void falcon_setup_xaui(struct efx_nic *efx)
  863. {
  864. efx_oword_t sdctl, txdrv;
  865. /* Move the XAUI into low power, unless there is no PHY, in
  866. * which case the XAUI will have to drive a cable. */
  867. if (efx->phy_type == PHY_TYPE_NONE)
  868. return;
  869. efx_reado(efx, &sdctl, FR_AB_XX_SD_CTL);
  870. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVD, FFE_AB_XX_SD_CTL_DRV_DEF);
  871. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVD, FFE_AB_XX_SD_CTL_DRV_DEF);
  872. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVC, FFE_AB_XX_SD_CTL_DRV_DEF);
  873. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVC, FFE_AB_XX_SD_CTL_DRV_DEF);
  874. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVB, FFE_AB_XX_SD_CTL_DRV_DEF);
  875. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVB, FFE_AB_XX_SD_CTL_DRV_DEF);
  876. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVA, FFE_AB_XX_SD_CTL_DRV_DEF);
  877. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVA, FFE_AB_XX_SD_CTL_DRV_DEF);
  878. efx_writeo(efx, &sdctl, FR_AB_XX_SD_CTL);
  879. EFX_POPULATE_OWORD_8(txdrv,
  880. FRF_AB_XX_DEQD, FFE_AB_XX_TXDRV_DEQ_DEF,
  881. FRF_AB_XX_DEQC, FFE_AB_XX_TXDRV_DEQ_DEF,
  882. FRF_AB_XX_DEQB, FFE_AB_XX_TXDRV_DEQ_DEF,
  883. FRF_AB_XX_DEQA, FFE_AB_XX_TXDRV_DEQ_DEF,
  884. FRF_AB_XX_DTXD, FFE_AB_XX_TXDRV_DTX_DEF,
  885. FRF_AB_XX_DTXC, FFE_AB_XX_TXDRV_DTX_DEF,
  886. FRF_AB_XX_DTXB, FFE_AB_XX_TXDRV_DTX_DEF,
  887. FRF_AB_XX_DTXA, FFE_AB_XX_TXDRV_DTX_DEF);
  888. efx_writeo(efx, &txdrv, FR_AB_XX_TXDRV_CTL);
  889. }
  890. int falcon_reset_xaui(struct efx_nic *efx)
  891. {
  892. struct falcon_nic_data *nic_data = efx->nic_data;
  893. efx_oword_t reg;
  894. int count;
  895. /* Don't fetch MAC statistics over an XMAC reset */
  896. WARN_ON(nic_data->stats_disable_count == 0);
  897. /* Start reset sequence */
  898. EFX_POPULATE_OWORD_1(reg, FRF_AB_XX_RST_XX_EN, 1);
  899. efx_writeo(efx, &reg, FR_AB_XX_PWR_RST);
  900. /* Wait up to 10 ms for completion, then reinitialise */
  901. for (count = 0; count < 1000; count++) {
  902. efx_reado(efx, &reg, FR_AB_XX_PWR_RST);
  903. if (EFX_OWORD_FIELD(reg, FRF_AB_XX_RST_XX_EN) == 0 &&
  904. EFX_OWORD_FIELD(reg, FRF_AB_XX_SD_RST_ACT) == 0) {
  905. falcon_setup_xaui(efx);
  906. return 0;
  907. }
  908. udelay(10);
  909. }
  910. netif_err(efx, hw, efx->net_dev,
  911. "timed out waiting for XAUI/XGXS reset\n");
  912. return -ETIMEDOUT;
  913. }
  914. static void falcon_ack_status_intr(struct efx_nic *efx)
  915. {
  916. struct falcon_nic_data *nic_data = efx->nic_data;
  917. efx_oword_t reg;
  918. if ((efx_nic_rev(efx) != EFX_REV_FALCON_B0) || LOOPBACK_INTERNAL(efx))
  919. return;
  920. /* We expect xgmii faults if the wireside link is down */
  921. if (!efx->link_state.up)
  922. return;
  923. /* We can only use this interrupt to signal the negative edge of
  924. * xaui_align [we have to poll the positive edge]. */
  925. if (nic_data->xmac_poll_required)
  926. return;
  927. efx_reado(efx, &reg, FR_AB_XM_MGT_INT_MSK);
  928. }
  929. static bool falcon_xgxs_link_ok(struct efx_nic *efx)
  930. {
  931. efx_oword_t reg;
  932. bool align_done, link_ok = false;
  933. int sync_status;
  934. /* Read link status */
  935. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  936. align_done = EFX_OWORD_FIELD(reg, FRF_AB_XX_ALIGN_DONE);
  937. sync_status = EFX_OWORD_FIELD(reg, FRF_AB_XX_SYNC_STAT);
  938. if (align_done && (sync_status == FFE_AB_XX_STAT_ALL_LANES))
  939. link_ok = true;
  940. /* Clear link status ready for next read */
  941. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_COMMA_DET, FFE_AB_XX_STAT_ALL_LANES);
  942. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_CHAR_ERR, FFE_AB_XX_STAT_ALL_LANES);
  943. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_DISPERR, FFE_AB_XX_STAT_ALL_LANES);
  944. efx_writeo(efx, &reg, FR_AB_XX_CORE_STAT);
  945. return link_ok;
  946. }
  947. static bool falcon_xmac_link_ok(struct efx_nic *efx)
  948. {
  949. /*
  950. * Check MAC's XGXS link status except when using XGMII loopback
  951. * which bypasses the XGXS block.
  952. * If possible, check PHY's XGXS link status except when using
  953. * MAC loopback.
  954. */
  955. return (efx->loopback_mode == LOOPBACK_XGMII ||
  956. falcon_xgxs_link_ok(efx)) &&
  957. (!(efx->mdio.mmds & (1 << MDIO_MMD_PHYXS)) ||
  958. LOOPBACK_INTERNAL(efx) ||
  959. efx_mdio_phyxgxs_lane_sync(efx));
  960. }
  961. static void falcon_reconfigure_xmac_core(struct efx_nic *efx)
  962. {
  963. unsigned int max_frame_len;
  964. efx_oword_t reg;
  965. bool rx_fc = !!(efx->link_state.fc & EFX_FC_RX);
  966. bool tx_fc = !!(efx->link_state.fc & EFX_FC_TX);
  967. /* Configure MAC - cut-thru mode is hard wired on */
  968. EFX_POPULATE_OWORD_3(reg,
  969. FRF_AB_XM_RX_JUMBO_MODE, 1,
  970. FRF_AB_XM_TX_STAT_EN, 1,
  971. FRF_AB_XM_RX_STAT_EN, 1);
  972. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  973. /* Configure TX */
  974. EFX_POPULATE_OWORD_6(reg,
  975. FRF_AB_XM_TXEN, 1,
  976. FRF_AB_XM_TX_PRMBL, 1,
  977. FRF_AB_XM_AUTO_PAD, 1,
  978. FRF_AB_XM_TXCRC, 1,
  979. FRF_AB_XM_FCNTL, tx_fc,
  980. FRF_AB_XM_IPG, 0x3);
  981. efx_writeo(efx, &reg, FR_AB_XM_TX_CFG);
  982. /* Configure RX */
  983. EFX_POPULATE_OWORD_5(reg,
  984. FRF_AB_XM_RXEN, 1,
  985. FRF_AB_XM_AUTO_DEPAD, 0,
  986. FRF_AB_XM_ACPT_ALL_MCAST, 1,
  987. FRF_AB_XM_ACPT_ALL_UCAST, !efx->unicast_filter,
  988. FRF_AB_XM_PASS_CRC_ERR, 1);
  989. efx_writeo(efx, &reg, FR_AB_XM_RX_CFG);
  990. /* Set frame length */
  991. max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
  992. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_MAX_RX_FRM_SIZE, max_frame_len);
  993. efx_writeo(efx, &reg, FR_AB_XM_RX_PARAM);
  994. EFX_POPULATE_OWORD_2(reg,
  995. FRF_AB_XM_MAX_TX_FRM_SIZE, max_frame_len,
  996. FRF_AB_XM_TX_JUMBO_MODE, 1);
  997. efx_writeo(efx, &reg, FR_AB_XM_TX_PARAM);
  998. EFX_POPULATE_OWORD_2(reg,
  999. FRF_AB_XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */
  1000. FRF_AB_XM_DIS_FCNTL, !rx_fc);
  1001. efx_writeo(efx, &reg, FR_AB_XM_FC);
  1002. /* Set MAC address */
  1003. memcpy(&reg, &efx->net_dev->dev_addr[0], 4);
  1004. efx_writeo(efx, &reg, FR_AB_XM_ADR_LO);
  1005. memcpy(&reg, &efx->net_dev->dev_addr[4], 2);
  1006. efx_writeo(efx, &reg, FR_AB_XM_ADR_HI);
  1007. }
  1008. static void falcon_reconfigure_xgxs_core(struct efx_nic *efx)
  1009. {
  1010. efx_oword_t reg;
  1011. bool xgxs_loopback = (efx->loopback_mode == LOOPBACK_XGXS);
  1012. bool xaui_loopback = (efx->loopback_mode == LOOPBACK_XAUI);
  1013. bool xgmii_loopback = (efx->loopback_mode == LOOPBACK_XGMII);
  1014. bool old_xgmii_loopback, old_xgxs_loopback, old_xaui_loopback;
  1015. /* XGXS block is flaky and will need to be reset if moving
  1016. * into our out of XGMII, XGXS or XAUI loopbacks. */
  1017. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  1018. old_xgxs_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_XGXS_LB_EN);
  1019. old_xgmii_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_XGMII_LB_EN);
  1020. efx_reado(efx, &reg, FR_AB_XX_SD_CTL);
  1021. old_xaui_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_LPBKA);
  1022. /* The PHY driver may have turned XAUI off */
  1023. if ((xgxs_loopback != old_xgxs_loopback) ||
  1024. (xaui_loopback != old_xaui_loopback) ||
  1025. (xgmii_loopback != old_xgmii_loopback))
  1026. falcon_reset_xaui(efx);
  1027. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  1028. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_FORCE_SIG,
  1029. (xgxs_loopback || xaui_loopback) ?
  1030. FFE_AB_XX_FORCE_SIG_ALL_LANES : 0);
  1031. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_XGXS_LB_EN, xgxs_loopback);
  1032. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_XGMII_LB_EN, xgmii_loopback);
  1033. efx_writeo(efx, &reg, FR_AB_XX_CORE_STAT);
  1034. efx_reado(efx, &reg, FR_AB_XX_SD_CTL);
  1035. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKD, xaui_loopback);
  1036. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKC, xaui_loopback);
  1037. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKB, xaui_loopback);
  1038. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKA, xaui_loopback);
  1039. efx_writeo(efx, &reg, FR_AB_XX_SD_CTL);
  1040. }
  1041. /* Try to bring up the Falcon side of the Falcon-Phy XAUI link */
  1042. static bool falcon_xmac_link_ok_retry(struct efx_nic *efx, int tries)
  1043. {
  1044. bool mac_up = falcon_xmac_link_ok(efx);
  1045. if (LOOPBACK_MASK(efx) & LOOPBACKS_EXTERNAL(efx) & LOOPBACKS_WS ||
  1046. efx_phy_mode_disabled(efx->phy_mode))
  1047. /* XAUI link is expected to be down */
  1048. return mac_up;
  1049. falcon_stop_nic_stats(efx);
  1050. while (!mac_up && tries) {
  1051. netif_dbg(efx, hw, efx->net_dev, "bashing xaui\n");
  1052. falcon_reset_xaui(efx);
  1053. udelay(200);
  1054. mac_up = falcon_xmac_link_ok(efx);
  1055. --tries;
  1056. }
  1057. falcon_start_nic_stats(efx);
  1058. return mac_up;
  1059. }
  1060. static bool falcon_xmac_check_fault(struct efx_nic *efx)
  1061. {
  1062. return !falcon_xmac_link_ok_retry(efx, 5);
  1063. }
  1064. static int falcon_reconfigure_xmac(struct efx_nic *efx)
  1065. {
  1066. struct falcon_nic_data *nic_data = efx->nic_data;
  1067. efx_farch_filter_sync_rx_mode(efx);
  1068. falcon_reconfigure_xgxs_core(efx);
  1069. falcon_reconfigure_xmac_core(efx);
  1070. falcon_reconfigure_mac_wrapper(efx);
  1071. nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 5);
  1072. falcon_ack_status_intr(efx);
  1073. return 0;
  1074. }
  1075. static void falcon_poll_xmac(struct efx_nic *efx)
  1076. {
  1077. struct falcon_nic_data *nic_data = efx->nic_data;
  1078. /* We expect xgmii faults if the wireside link is down */
  1079. if (!efx->link_state.up || !nic_data->xmac_poll_required)
  1080. return;
  1081. nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 1);
  1082. falcon_ack_status_intr(efx);
  1083. }
  1084. /**************************************************************************
  1085. *
  1086. * MAC wrapper
  1087. *
  1088. **************************************************************************
  1089. */
  1090. static void falcon_push_multicast_hash(struct efx_nic *efx)
  1091. {
  1092. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  1093. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1094. efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0);
  1095. efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1);
  1096. }
  1097. static void falcon_reset_macs(struct efx_nic *efx)
  1098. {
  1099. struct falcon_nic_data *nic_data = efx->nic_data;
  1100. efx_oword_t reg, mac_ctrl;
  1101. int count;
  1102. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
  1103. /* It's not safe to use GLB_CTL_REG to reset the
  1104. * macs, so instead use the internal MAC resets
  1105. */
  1106. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1);
  1107. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  1108. for (count = 0; count < 10000; count++) {
  1109. efx_reado(efx, &reg, FR_AB_XM_GLB_CFG);
  1110. if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) ==
  1111. 0)
  1112. return;
  1113. udelay(10);
  1114. }
  1115. netif_err(efx, hw, efx->net_dev,
  1116. "timed out waiting for XMAC core reset\n");
  1117. }
  1118. /* Mac stats will fail whist the TX fifo is draining */
  1119. WARN_ON(nic_data->stats_disable_count == 0);
  1120. efx_reado(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  1121. EFX_SET_OWORD_FIELD(mac_ctrl, FRF_BB_TXFIFO_DRAIN_EN, 1);
  1122. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  1123. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  1124. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1);
  1125. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1);
  1126. EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1);
  1127. efx_writeo(efx, &reg, FR_AB_GLB_CTL);
  1128. count = 0;
  1129. while (1) {
  1130. efx_reado(efx, &reg, FR_AB_GLB_CTL);
  1131. if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) &&
  1132. !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) &&
  1133. !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) {
  1134. netif_dbg(efx, hw, efx->net_dev,
  1135. "Completed MAC reset after %d loops\n",
  1136. count);
  1137. break;
  1138. }
  1139. if (count > 20) {
  1140. netif_err(efx, hw, efx->net_dev, "MAC reset failed\n");
  1141. break;
  1142. }
  1143. count++;
  1144. udelay(10);
  1145. }
  1146. /* Ensure the correct MAC is selected before statistics
  1147. * are re-enabled by the caller */
  1148. efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL);
  1149. falcon_setup_xaui(efx);
  1150. }
  1151. static void falcon_drain_tx_fifo(struct efx_nic *efx)
  1152. {
  1153. efx_oword_t reg;
  1154. if ((efx_nic_rev(efx) < EFX_REV_FALCON_B0) ||
  1155. (efx->loopback_mode != LOOPBACK_NONE))
  1156. return;
  1157. efx_reado(efx, &reg, FR_AB_MAC_CTRL);
  1158. /* There is no point in draining more than once */
  1159. if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN))
  1160. return;
  1161. falcon_reset_macs(efx);
  1162. }
  1163. static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
  1164. {
  1165. efx_oword_t reg;
  1166. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  1167. return;
  1168. /* Isolate the MAC -> RX */
  1169. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1170. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0);
  1171. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1172. /* Isolate TX -> MAC */
  1173. falcon_drain_tx_fifo(efx);
  1174. }
  1175. static void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
  1176. {
  1177. struct efx_link_state *link_state = &efx->link_state;
  1178. efx_oword_t reg;
  1179. int link_speed, isolate;
  1180. isolate = !!ACCESS_ONCE(efx->reset_pending);
  1181. switch (link_state->speed) {
  1182. case 10000: link_speed = 3; break;
  1183. case 1000: link_speed = 2; break;
  1184. case 100: link_speed = 1; break;
  1185. default: link_speed = 0; break;
  1186. }
  1187. /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
  1188. * as advertised. Disable to ensure packets are not
  1189. * indefinitely held and TX queue can be flushed at any point
  1190. * while the link is down. */
  1191. EFX_POPULATE_OWORD_5(reg,
  1192. FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */,
  1193. FRF_AB_MAC_BCAD_ACPT, 1,
  1194. FRF_AB_MAC_UC_PROM, !efx->unicast_filter,
  1195. FRF_AB_MAC_LINK_STATUS, 1, /* always set */
  1196. FRF_AB_MAC_SPEED, link_speed);
  1197. /* On B0, MAC backpressure can be disabled and packets get
  1198. * discarded. */
  1199. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  1200. EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN,
  1201. !link_state->up || isolate);
  1202. }
  1203. efx_writeo(efx, &reg, FR_AB_MAC_CTRL);
  1204. /* Restore the multicast hash registers. */
  1205. falcon_push_multicast_hash(efx);
  1206. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  1207. /* Enable XOFF signal from RX FIFO (we enabled it during NIC
  1208. * initialisation but it may read back as 0) */
  1209. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  1210. /* Unisolate the MAC -> RX */
  1211. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1212. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, !isolate);
  1213. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  1214. }
  1215. static void falcon_stats_request(struct efx_nic *efx)
  1216. {
  1217. struct falcon_nic_data *nic_data = efx->nic_data;
  1218. efx_oword_t reg;
  1219. WARN_ON(nic_data->stats_pending);
  1220. WARN_ON(nic_data->stats_disable_count);
  1221. FALCON_XMAC_STATS_DMA_FLAG(efx) = 0;
  1222. nic_data->stats_pending = true;
  1223. wmb(); /* ensure done flag is clear */
  1224. /* Initiate DMA transfer of stats */
  1225. EFX_POPULATE_OWORD_2(reg,
  1226. FRF_AB_MAC_STAT_DMA_CMD, 1,
  1227. FRF_AB_MAC_STAT_DMA_ADR,
  1228. efx->stats_buffer.dma_addr);
  1229. efx_writeo(efx, &reg, FR_AB_MAC_STAT_DMA);
  1230. mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2));
  1231. }
  1232. static void falcon_stats_complete(struct efx_nic *efx)
  1233. {
  1234. struct falcon_nic_data *nic_data = efx->nic_data;
  1235. if (!nic_data->stats_pending)
  1236. return;
  1237. nic_data->stats_pending = false;
  1238. if (FALCON_XMAC_STATS_DMA_FLAG(efx)) {
  1239. rmb(); /* read the done flag before the stats */
  1240. efx_nic_update_stats(falcon_stat_desc, FALCON_STAT_COUNT,
  1241. falcon_stat_mask, nic_data->stats,
  1242. efx->stats_buffer.addr, true);
  1243. } else {
  1244. netif_err(efx, hw, efx->net_dev,
  1245. "timed out waiting for statistics\n");
  1246. }
  1247. }
  1248. static void falcon_stats_timer_func(unsigned long context)
  1249. {
  1250. struct efx_nic *efx = (struct efx_nic *)context;
  1251. struct falcon_nic_data *nic_data = efx->nic_data;
  1252. spin_lock(&efx->stats_lock);
  1253. falcon_stats_complete(efx);
  1254. if (nic_data->stats_disable_count == 0)
  1255. falcon_stats_request(efx);
  1256. spin_unlock(&efx->stats_lock);
  1257. }
  1258. static bool falcon_loopback_link_poll(struct efx_nic *efx)
  1259. {
  1260. struct efx_link_state old_state = efx->link_state;
  1261. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  1262. WARN_ON(!LOOPBACK_INTERNAL(efx));
  1263. efx->link_state.fd = true;
  1264. efx->link_state.fc = efx->wanted_fc;
  1265. efx->link_state.up = true;
  1266. efx->link_state.speed = 10000;
  1267. return !efx_link_state_equal(&efx->link_state, &old_state);
  1268. }
  1269. static int falcon_reconfigure_port(struct efx_nic *efx)
  1270. {
  1271. int rc;
  1272. WARN_ON(efx_nic_rev(efx) > EFX_REV_FALCON_B0);
  1273. /* Poll the PHY link state *before* reconfiguring it. This means we
  1274. * will pick up the correct speed (in loopback) to select the correct
  1275. * MAC.
  1276. */
  1277. if (LOOPBACK_INTERNAL(efx))
  1278. falcon_loopback_link_poll(efx);
  1279. else
  1280. efx->phy_op->poll(efx);
  1281. falcon_stop_nic_stats(efx);
  1282. falcon_deconfigure_mac_wrapper(efx);
  1283. falcon_reset_macs(efx);
  1284. efx->phy_op->reconfigure(efx);
  1285. rc = falcon_reconfigure_xmac(efx);
  1286. BUG_ON(rc);
  1287. falcon_start_nic_stats(efx);
  1288. /* Synchronise efx->link_state with the kernel */
  1289. efx_link_status_changed(efx);
  1290. return 0;
  1291. }
  1292. /* TX flow control may automatically turn itself off if the link
  1293. * partner (intermittently) stops responding to pause frames. There
  1294. * isn't any indication that this has happened, so the best we do is
  1295. * leave it up to the user to spot this and fix it by cycling transmit
  1296. * flow control on this end.
  1297. */
  1298. static void falcon_a1_prepare_enable_fc_tx(struct efx_nic *efx)
  1299. {
  1300. /* Schedule a reset to recover */
  1301. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  1302. }
  1303. static void falcon_b0_prepare_enable_fc_tx(struct efx_nic *efx)
  1304. {
  1305. /* Recover by resetting the EM block */
  1306. falcon_stop_nic_stats(efx);
  1307. falcon_drain_tx_fifo(efx);
  1308. falcon_reconfigure_xmac(efx);
  1309. falcon_start_nic_stats(efx);
  1310. }
  1311. /**************************************************************************
  1312. *
  1313. * PHY access via GMII
  1314. *
  1315. **************************************************************************
  1316. */
  1317. /* Wait for GMII access to complete */
  1318. static int falcon_gmii_wait(struct efx_nic *efx)
  1319. {
  1320. efx_oword_t md_stat;
  1321. int count;
  1322. /* wait up to 50ms - taken max from datasheet */
  1323. for (count = 0; count < 5000; count++) {
  1324. efx_reado(efx, &md_stat, FR_AB_MD_STAT);
  1325. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) {
  1326. if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 ||
  1327. EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) {
  1328. netif_err(efx, hw, efx->net_dev,
  1329. "error from GMII access "
  1330. EFX_OWORD_FMT"\n",
  1331. EFX_OWORD_VAL(md_stat));
  1332. return -EIO;
  1333. }
  1334. return 0;
  1335. }
  1336. udelay(10);
  1337. }
  1338. netif_err(efx, hw, efx->net_dev, "timed out waiting for GMII\n");
  1339. return -ETIMEDOUT;
  1340. }
  1341. /* Write an MDIO register of a PHY connected to Falcon. */
  1342. static int falcon_mdio_write(struct net_device *net_dev,
  1343. int prtad, int devad, u16 addr, u16 value)
  1344. {
  1345. struct efx_nic *efx = netdev_priv(net_dev);
  1346. struct falcon_nic_data *nic_data = efx->nic_data;
  1347. efx_oword_t reg;
  1348. int rc;
  1349. netif_vdbg(efx, hw, efx->net_dev,
  1350. "writing MDIO %d register %d.%d with 0x%04x\n",
  1351. prtad, devad, addr, value);
  1352. mutex_lock(&nic_data->mdio_lock);
  1353. /* Check MDIO not currently being accessed */
  1354. rc = falcon_gmii_wait(efx);
  1355. if (rc)
  1356. goto out;
  1357. /* Write the address/ID register */
  1358. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1359. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1360. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1361. FRF_AB_MD_DEV_ADR, devad);
  1362. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1363. /* Write data */
  1364. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value);
  1365. efx_writeo(efx, &reg, FR_AB_MD_TXD);
  1366. EFX_POPULATE_OWORD_2(reg,
  1367. FRF_AB_MD_WRC, 1,
  1368. FRF_AB_MD_GC, 0);
  1369. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1370. /* Wait for data to be written */
  1371. rc = falcon_gmii_wait(efx);
  1372. if (rc) {
  1373. /* Abort the write operation */
  1374. EFX_POPULATE_OWORD_2(reg,
  1375. FRF_AB_MD_WRC, 0,
  1376. FRF_AB_MD_GC, 1);
  1377. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1378. udelay(10);
  1379. }
  1380. out:
  1381. mutex_unlock(&nic_data->mdio_lock);
  1382. return rc;
  1383. }
  1384. /* Read an MDIO register of a PHY connected to Falcon. */
  1385. static int falcon_mdio_read(struct net_device *net_dev,
  1386. int prtad, int devad, u16 addr)
  1387. {
  1388. struct efx_nic *efx = netdev_priv(net_dev);
  1389. struct falcon_nic_data *nic_data = efx->nic_data;
  1390. efx_oword_t reg;
  1391. int rc;
  1392. mutex_lock(&nic_data->mdio_lock);
  1393. /* Check MDIO not currently being accessed */
  1394. rc = falcon_gmii_wait(efx);
  1395. if (rc)
  1396. goto out;
  1397. EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr);
  1398. efx_writeo(efx, &reg, FR_AB_MD_PHY_ADR);
  1399. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad,
  1400. FRF_AB_MD_DEV_ADR, devad);
  1401. efx_writeo(efx, &reg, FR_AB_MD_ID);
  1402. /* Request data to be read */
  1403. EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0);
  1404. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1405. /* Wait for data to become available */
  1406. rc = falcon_gmii_wait(efx);
  1407. if (rc == 0) {
  1408. efx_reado(efx, &reg, FR_AB_MD_RXD);
  1409. rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD);
  1410. netif_vdbg(efx, hw, efx->net_dev,
  1411. "read from MDIO %d register %d.%d, got %04x\n",
  1412. prtad, devad, addr, rc);
  1413. } else {
  1414. /* Abort the read operation */
  1415. EFX_POPULATE_OWORD_2(reg,
  1416. FRF_AB_MD_RIC, 0,
  1417. FRF_AB_MD_GC, 1);
  1418. efx_writeo(efx, &reg, FR_AB_MD_CS);
  1419. netif_dbg(efx, hw, efx->net_dev,
  1420. "read from MDIO %d register %d.%d, got error %d\n",
  1421. prtad, devad, addr, rc);
  1422. }
  1423. out:
  1424. mutex_unlock(&nic_data->mdio_lock);
  1425. return rc;
  1426. }
  1427. /* This call is responsible for hooking in the MAC and PHY operations */
  1428. static int falcon_probe_port(struct efx_nic *efx)
  1429. {
  1430. struct falcon_nic_data *nic_data = efx->nic_data;
  1431. int rc;
  1432. switch (efx->phy_type) {
  1433. case PHY_TYPE_SFX7101:
  1434. efx->phy_op = &falcon_sfx7101_phy_ops;
  1435. break;
  1436. case PHY_TYPE_QT2022C2:
  1437. case PHY_TYPE_QT2025C:
  1438. efx->phy_op = &falcon_qt202x_phy_ops;
  1439. break;
  1440. case PHY_TYPE_TXC43128:
  1441. efx->phy_op = &falcon_txc_phy_ops;
  1442. break;
  1443. default:
  1444. netif_err(efx, probe, efx->net_dev, "Unknown PHY type %d\n",
  1445. efx->phy_type);
  1446. return -ENODEV;
  1447. }
  1448. /* Fill out MDIO structure and loopback modes */
  1449. mutex_init(&nic_data->mdio_lock);
  1450. efx->mdio.mdio_read = falcon_mdio_read;
  1451. efx->mdio.mdio_write = falcon_mdio_write;
  1452. rc = efx->phy_op->probe(efx);
  1453. if (rc != 0)
  1454. return rc;
  1455. /* Initial assumption */
  1456. efx->link_state.speed = 10000;
  1457. efx->link_state.fd = true;
  1458. /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
  1459. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1460. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  1461. else
  1462. efx->wanted_fc = EFX_FC_RX;
  1463. if (efx->mdio.mmds & MDIO_DEVS_AN)
  1464. efx->wanted_fc |= EFX_FC_AUTO;
  1465. /* Allocate buffer for stats */
  1466. rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
  1467. FALCON_MAC_STATS_SIZE, GFP_KERNEL);
  1468. if (rc)
  1469. return rc;
  1470. netif_dbg(efx, probe, efx->net_dev,
  1471. "stats buffer at %llx (virt %p phys %llx)\n",
  1472. (u64)efx->stats_buffer.dma_addr,
  1473. efx->stats_buffer.addr,
  1474. (u64)virt_to_phys(efx->stats_buffer.addr));
  1475. return 0;
  1476. }
  1477. static void falcon_remove_port(struct efx_nic *efx)
  1478. {
  1479. efx->phy_op->remove(efx);
  1480. efx_nic_free_buffer(efx, &efx->stats_buffer);
  1481. }
  1482. /* Global events are basically PHY events */
  1483. static bool
  1484. falcon_handle_global_event(struct efx_channel *channel, efx_qword_t *event)
  1485. {
  1486. struct efx_nic *efx = channel->efx;
  1487. struct falcon_nic_data *nic_data = efx->nic_data;
  1488. if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
  1489. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
  1490. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR))
  1491. /* Ignored */
  1492. return true;
  1493. if ((efx_nic_rev(efx) == EFX_REV_FALCON_B0) &&
  1494. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
  1495. nic_data->xmac_poll_required = true;
  1496. return true;
  1497. }
  1498. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ?
  1499. EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
  1500. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
  1501. netif_err(efx, rx_err, efx->net_dev,
  1502. "channel %d seen global RX_RESET event. Resetting.\n",
  1503. channel->channel);
  1504. atomic_inc(&efx->rx_reset);
  1505. efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
  1506. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  1507. return true;
  1508. }
  1509. return false;
  1510. }
  1511. /**************************************************************************
  1512. *
  1513. * Falcon test code
  1514. *
  1515. **************************************************************************/
  1516. static int
  1517. falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
  1518. {
  1519. struct falcon_nic_data *nic_data = efx->nic_data;
  1520. struct falcon_nvconfig *nvconfig;
  1521. struct falcon_spi_device *spi;
  1522. void *region;
  1523. int rc, magic_num, struct_ver;
  1524. __le16 *word, *limit;
  1525. u32 csum;
  1526. if (falcon_spi_present(&nic_data->spi_flash))
  1527. spi = &nic_data->spi_flash;
  1528. else if (falcon_spi_present(&nic_data->spi_eeprom))
  1529. spi = &nic_data->spi_eeprom;
  1530. else
  1531. return -EINVAL;
  1532. region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
  1533. if (!region)
  1534. return -ENOMEM;
  1535. nvconfig = region + FALCON_NVCONFIG_OFFSET;
  1536. mutex_lock(&nic_data->spi_lock);
  1537. rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region);
  1538. mutex_unlock(&nic_data->spi_lock);
  1539. if (rc) {
  1540. netif_err(efx, hw, efx->net_dev, "Failed to read %s\n",
  1541. falcon_spi_present(&nic_data->spi_flash) ?
  1542. "flash" : "EEPROM");
  1543. rc = -EIO;
  1544. goto out;
  1545. }
  1546. magic_num = le16_to_cpu(nvconfig->board_magic_num);
  1547. struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
  1548. rc = -EINVAL;
  1549. if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) {
  1550. netif_err(efx, hw, efx->net_dev,
  1551. "NVRAM bad magic 0x%x\n", magic_num);
  1552. goto out;
  1553. }
  1554. if (struct_ver < 2) {
  1555. netif_err(efx, hw, efx->net_dev,
  1556. "NVRAM has ancient version 0x%x\n", struct_ver);
  1557. goto out;
  1558. } else if (struct_ver < 4) {
  1559. word = &nvconfig->board_magic_num;
  1560. limit = (__le16 *) (nvconfig + 1);
  1561. } else {
  1562. word = region;
  1563. limit = region + FALCON_NVCONFIG_END;
  1564. }
  1565. for (csum = 0; word < limit; ++word)
  1566. csum += le16_to_cpu(*word);
  1567. if (~csum & 0xffff) {
  1568. netif_err(efx, hw, efx->net_dev,
  1569. "NVRAM has incorrect checksum\n");
  1570. goto out;
  1571. }
  1572. rc = 0;
  1573. if (nvconfig_out)
  1574. memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig));
  1575. out:
  1576. kfree(region);
  1577. return rc;
  1578. }
  1579. static int falcon_test_nvram(struct efx_nic *efx)
  1580. {
  1581. return falcon_read_nvram(efx, NULL);
  1582. }
  1583. static const struct efx_farch_register_test falcon_b0_register_tests[] = {
  1584. { FR_AZ_ADR_REGION,
  1585. EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
  1586. { FR_AZ_RX_CFG,
  1587. EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
  1588. { FR_AZ_TX_CFG,
  1589. EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
  1590. { FR_AZ_TX_RESERVED,
  1591. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  1592. { FR_AB_MAC_CTRL,
  1593. EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
  1594. { FR_AZ_SRM_TX_DC_CFG,
  1595. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  1596. { FR_AZ_RX_DC_CFG,
  1597. EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
  1598. { FR_AZ_RX_DC_PF_WM,
  1599. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  1600. { FR_BZ_DP_CTRL,
  1601. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  1602. { FR_AB_GM_CFG2,
  1603. EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
  1604. { FR_AB_GMF_CFG0,
  1605. EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
  1606. { FR_AB_XM_GLB_CFG,
  1607. EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
  1608. { FR_AB_XM_TX_CFG,
  1609. EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
  1610. { FR_AB_XM_RX_CFG,
  1611. EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
  1612. { FR_AB_XM_RX_PARAM,
  1613. EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
  1614. { FR_AB_XM_FC,
  1615. EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
  1616. { FR_AB_XM_ADR_LO,
  1617. EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
  1618. { FR_AB_XX_SD_CTL,
  1619. EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
  1620. };
  1621. static int
  1622. falcon_b0_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
  1623. {
  1624. enum reset_type reset_method = RESET_TYPE_INVISIBLE;
  1625. int rc, rc2;
  1626. mutex_lock(&efx->mac_lock);
  1627. if (efx->loopback_modes) {
  1628. /* We need the 312 clock from the PHY to test the XMAC
  1629. * registers, so move into XGMII loopback if available */
  1630. if (efx->loopback_modes & (1 << LOOPBACK_XGMII))
  1631. efx->loopback_mode = LOOPBACK_XGMII;
  1632. else
  1633. efx->loopback_mode = __ffs(efx->loopback_modes);
  1634. }
  1635. __efx_reconfigure_port(efx);
  1636. mutex_unlock(&efx->mac_lock);
  1637. efx_reset_down(efx, reset_method);
  1638. tests->registers =
  1639. efx_farch_test_registers(efx, falcon_b0_register_tests,
  1640. ARRAY_SIZE(falcon_b0_register_tests))
  1641. ? -1 : 1;
  1642. rc = falcon_reset_hw(efx, reset_method);
  1643. rc2 = efx_reset_up(efx, reset_method, rc == 0);
  1644. return rc ? rc : rc2;
  1645. }
  1646. /**************************************************************************
  1647. *
  1648. * Device reset
  1649. *
  1650. **************************************************************************
  1651. */
  1652. static enum reset_type falcon_map_reset_reason(enum reset_type reason)
  1653. {
  1654. switch (reason) {
  1655. case RESET_TYPE_RX_RECOVERY:
  1656. case RESET_TYPE_DMA_ERROR:
  1657. case RESET_TYPE_TX_SKIP:
  1658. /* These can occasionally occur due to hardware bugs.
  1659. * We try to reset without disrupting the link.
  1660. */
  1661. return RESET_TYPE_INVISIBLE;
  1662. default:
  1663. return RESET_TYPE_ALL;
  1664. }
  1665. }
  1666. static int falcon_map_reset_flags(u32 *flags)
  1667. {
  1668. enum {
  1669. FALCON_RESET_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER |
  1670. ETH_RESET_OFFLOAD | ETH_RESET_MAC),
  1671. FALCON_RESET_ALL = FALCON_RESET_INVISIBLE | ETH_RESET_PHY,
  1672. FALCON_RESET_WORLD = FALCON_RESET_ALL | ETH_RESET_IRQ,
  1673. };
  1674. if ((*flags & FALCON_RESET_WORLD) == FALCON_RESET_WORLD) {
  1675. *flags &= ~FALCON_RESET_WORLD;
  1676. return RESET_TYPE_WORLD;
  1677. }
  1678. if ((*flags & FALCON_RESET_ALL) == FALCON_RESET_ALL) {
  1679. *flags &= ~FALCON_RESET_ALL;
  1680. return RESET_TYPE_ALL;
  1681. }
  1682. if ((*flags & FALCON_RESET_INVISIBLE) == FALCON_RESET_INVISIBLE) {
  1683. *flags &= ~FALCON_RESET_INVISIBLE;
  1684. return RESET_TYPE_INVISIBLE;
  1685. }
  1686. return -EINVAL;
  1687. }
  1688. /* Resets NIC to known state. This routine must be called in process
  1689. * context and is allowed to sleep. */
  1690. static int __falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  1691. {
  1692. struct falcon_nic_data *nic_data = efx->nic_data;
  1693. efx_oword_t glb_ctl_reg_ker;
  1694. int rc;
  1695. netif_dbg(efx, hw, efx->net_dev, "performing %s hardware reset\n",
  1696. RESET_TYPE(method));
  1697. /* Initiate device reset */
  1698. if (method == RESET_TYPE_WORLD) {
  1699. rc = pci_save_state(efx->pci_dev);
  1700. if (rc) {
  1701. netif_err(efx, drv, efx->net_dev,
  1702. "failed to backup PCI state of primary "
  1703. "function prior to hardware reset\n");
  1704. goto fail1;
  1705. }
  1706. if (efx_nic_is_dual_func(efx)) {
  1707. rc = pci_save_state(nic_data->pci_dev2);
  1708. if (rc) {
  1709. netif_err(efx, drv, efx->net_dev,
  1710. "failed to backup PCI state of "
  1711. "secondary function prior to "
  1712. "hardware reset\n");
  1713. goto fail2;
  1714. }
  1715. }
  1716. EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
  1717. FRF_AB_EXT_PHY_RST_DUR,
  1718. FFE_AB_EXT_PHY_RST_DUR_10240US,
  1719. FRF_AB_SWRST, 1);
  1720. } else {
  1721. EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
  1722. /* exclude PHY from "invisible" reset */
  1723. FRF_AB_EXT_PHY_RST_CTL,
  1724. method == RESET_TYPE_INVISIBLE,
  1725. /* exclude EEPROM/flash and PCIe */
  1726. FRF_AB_PCIE_CORE_RST_CTL, 1,
  1727. FRF_AB_PCIE_NSTKY_RST_CTL, 1,
  1728. FRF_AB_PCIE_SD_RST_CTL, 1,
  1729. FRF_AB_EE_RST_CTL, 1,
  1730. FRF_AB_EXT_PHY_RST_DUR,
  1731. FFE_AB_EXT_PHY_RST_DUR_10240US,
  1732. FRF_AB_SWRST, 1);
  1733. }
  1734. efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  1735. netif_dbg(efx, hw, efx->net_dev, "waiting for hardware reset\n");
  1736. schedule_timeout_uninterruptible(HZ / 20);
  1737. /* Restore PCI configuration if needed */
  1738. if (method == RESET_TYPE_WORLD) {
  1739. if (efx_nic_is_dual_func(efx))
  1740. pci_restore_state(nic_data->pci_dev2);
  1741. pci_restore_state(efx->pci_dev);
  1742. netif_dbg(efx, drv, efx->net_dev,
  1743. "successfully restored PCI config\n");
  1744. }
  1745. /* Assert that reset complete */
  1746. efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL);
  1747. if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) {
  1748. rc = -ETIMEDOUT;
  1749. netif_err(efx, hw, efx->net_dev,
  1750. "timed out waiting for hardware reset\n");
  1751. goto fail3;
  1752. }
  1753. netif_dbg(efx, hw, efx->net_dev, "hardware reset complete\n");
  1754. return 0;
  1755. /* pci_save_state() and pci_restore_state() MUST be called in pairs */
  1756. fail2:
  1757. pci_restore_state(efx->pci_dev);
  1758. fail1:
  1759. fail3:
  1760. return rc;
  1761. }
  1762. static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
  1763. {
  1764. struct falcon_nic_data *nic_data = efx->nic_data;
  1765. int rc;
  1766. mutex_lock(&nic_data->spi_lock);
  1767. rc = __falcon_reset_hw(efx, method);
  1768. mutex_unlock(&nic_data->spi_lock);
  1769. return rc;
  1770. }
  1771. static void falcon_monitor(struct efx_nic *efx)
  1772. {
  1773. bool link_changed;
  1774. int rc;
  1775. BUG_ON(!mutex_is_locked(&efx->mac_lock));
  1776. rc = falcon_board(efx)->type->monitor(efx);
  1777. if (rc) {
  1778. netif_err(efx, hw, efx->net_dev,
  1779. "Board sensor %s; shutting down PHY\n",
  1780. (rc == -ERANGE) ? "reported fault" : "failed");
  1781. efx->phy_mode |= PHY_MODE_LOW_POWER;
  1782. rc = __efx_reconfigure_port(efx);
  1783. WARN_ON(rc);
  1784. }
  1785. if (LOOPBACK_INTERNAL(efx))
  1786. link_changed = falcon_loopback_link_poll(efx);
  1787. else
  1788. link_changed = efx->phy_op->poll(efx);
  1789. if (link_changed) {
  1790. falcon_stop_nic_stats(efx);
  1791. falcon_deconfigure_mac_wrapper(efx);
  1792. falcon_reset_macs(efx);
  1793. rc = falcon_reconfigure_xmac(efx);
  1794. BUG_ON(rc);
  1795. falcon_start_nic_stats(efx);
  1796. efx_link_status_changed(efx);
  1797. }
  1798. falcon_poll_xmac(efx);
  1799. }
  1800. /* Zeroes out the SRAM contents. This routine must be called in
  1801. * process context and is allowed to sleep.
  1802. */
  1803. static int falcon_reset_sram(struct efx_nic *efx)
  1804. {
  1805. efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
  1806. int count;
  1807. /* Set the SRAM wake/sleep GPIO appropriately. */
  1808. efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1809. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1);
  1810. EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1);
  1811. efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL);
  1812. /* Initiate SRAM reset */
  1813. EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
  1814. FRF_AZ_SRM_INIT_EN, 1,
  1815. FRF_AZ_SRM_NB_SZ, 0);
  1816. efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1817. /* Wait for SRAM reset to complete */
  1818. count = 0;
  1819. do {
  1820. netif_dbg(efx, hw, efx->net_dev,
  1821. "waiting for SRAM reset (attempt %d)...\n", count);
  1822. /* SRAM reset is slow; expect around 16ms */
  1823. schedule_timeout_uninterruptible(HZ / 50);
  1824. /* Check for reset complete */
  1825. efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG);
  1826. if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) {
  1827. netif_dbg(efx, hw, efx->net_dev,
  1828. "SRAM reset complete\n");
  1829. return 0;
  1830. }
  1831. } while (++count < 20); /* wait up to 0.4 sec */
  1832. netif_err(efx, hw, efx->net_dev, "timed out waiting for SRAM reset\n");
  1833. return -ETIMEDOUT;
  1834. }
  1835. static void falcon_spi_device_init(struct efx_nic *efx,
  1836. struct falcon_spi_device *spi_device,
  1837. unsigned int device_id, u32 device_type)
  1838. {
  1839. if (device_type != 0) {
  1840. spi_device->device_id = device_id;
  1841. spi_device->size =
  1842. 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
  1843. spi_device->addr_len =
  1844. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
  1845. spi_device->munge_address = (spi_device->size == 1 << 9 &&
  1846. spi_device->addr_len == 1);
  1847. spi_device->erase_command =
  1848. SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
  1849. spi_device->erase_size =
  1850. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1851. SPI_DEV_TYPE_ERASE_SIZE);
  1852. spi_device->block_size =
  1853. 1 << SPI_DEV_TYPE_FIELD(device_type,
  1854. SPI_DEV_TYPE_BLOCK_SIZE);
  1855. } else {
  1856. spi_device->size = 0;
  1857. }
  1858. }
  1859. /* Extract non-volatile configuration */
  1860. static int falcon_probe_nvconfig(struct efx_nic *efx)
  1861. {
  1862. struct falcon_nic_data *nic_data = efx->nic_data;
  1863. struct falcon_nvconfig *nvconfig;
  1864. int rc;
  1865. nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
  1866. if (!nvconfig)
  1867. return -ENOMEM;
  1868. rc = falcon_read_nvram(efx, nvconfig);
  1869. if (rc)
  1870. goto out;
  1871. efx->phy_type = nvconfig->board_v2.port0_phy_type;
  1872. efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr;
  1873. if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
  1874. falcon_spi_device_init(
  1875. efx, &nic_data->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
  1876. le32_to_cpu(nvconfig->board_v3
  1877. .spi_device_type[FFE_AB_SPI_DEVICE_FLASH]));
  1878. falcon_spi_device_init(
  1879. efx, &nic_data->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
  1880. le32_to_cpu(nvconfig->board_v3
  1881. .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM]));
  1882. }
  1883. /* Read the MAC addresses */
  1884. ether_addr_copy(efx->net_dev->perm_addr, nvconfig->mac_address[0]);
  1885. netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n",
  1886. efx->phy_type, efx->mdio.prtad);
  1887. rc = falcon_probe_board(efx,
  1888. le16_to_cpu(nvconfig->board_v2.board_revision));
  1889. out:
  1890. kfree(nvconfig);
  1891. return rc;
  1892. }
  1893. static int falcon_dimension_resources(struct efx_nic *efx)
  1894. {
  1895. efx->rx_dc_base = 0x20000;
  1896. efx->tx_dc_base = 0x26000;
  1897. return 0;
  1898. }
  1899. /* Probe all SPI devices on the NIC */
  1900. static void falcon_probe_spi_devices(struct efx_nic *efx)
  1901. {
  1902. struct falcon_nic_data *nic_data = efx->nic_data;
  1903. efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
  1904. int boot_dev;
  1905. efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL);
  1906. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1907. efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1908. if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) {
  1909. boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ?
  1910. FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM);
  1911. netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n",
  1912. boot_dev == FFE_AB_SPI_DEVICE_FLASH ?
  1913. "flash" : "EEPROM");
  1914. } else {
  1915. /* Disable VPD and set clock dividers to safe
  1916. * values for initial programming. */
  1917. boot_dev = -1;
  1918. netif_dbg(efx, probe, efx->net_dev,
  1919. "Booted from internal ASIC settings;"
  1920. " setting SPI config\n");
  1921. EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0,
  1922. /* 125 MHz / 7 ~= 20 MHz */
  1923. FRF_AB_EE_SF_CLOCK_DIV, 7,
  1924. /* 125 MHz / 63 ~= 2 MHz */
  1925. FRF_AB_EE_EE_CLOCK_DIV, 63);
  1926. efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
  1927. }
  1928. mutex_init(&nic_data->spi_lock);
  1929. if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
  1930. falcon_spi_device_init(efx, &nic_data->spi_flash,
  1931. FFE_AB_SPI_DEVICE_FLASH,
  1932. default_flash_type);
  1933. if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
  1934. falcon_spi_device_init(efx, &nic_data->spi_eeprom,
  1935. FFE_AB_SPI_DEVICE_EEPROM,
  1936. large_eeprom_type);
  1937. }
  1938. static unsigned int falcon_a1_mem_map_size(struct efx_nic *efx)
  1939. {
  1940. return 0x20000;
  1941. }
  1942. static unsigned int falcon_b0_mem_map_size(struct efx_nic *efx)
  1943. {
  1944. /* Map everything up to and including the RSS indirection table.
  1945. * The PCI core takes care of mapping the MSI-X tables.
  1946. */
  1947. return FR_BZ_RX_INDIRECTION_TBL +
  1948. FR_BZ_RX_INDIRECTION_TBL_STEP * FR_BZ_RX_INDIRECTION_TBL_ROWS;
  1949. }
  1950. static int falcon_probe_nic(struct efx_nic *efx)
  1951. {
  1952. struct falcon_nic_data *nic_data;
  1953. struct falcon_board *board;
  1954. int rc;
  1955. efx->primary = efx; /* only one usable function per controller */
  1956. /* Allocate storage for hardware specific data */
  1957. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  1958. if (!nic_data)
  1959. return -ENOMEM;
  1960. efx->nic_data = nic_data;
  1961. rc = -ENODEV;
  1962. if (efx_farch_fpga_ver(efx) != 0) {
  1963. netif_err(efx, probe, efx->net_dev,
  1964. "Falcon FPGA not supported\n");
  1965. goto fail1;
  1966. }
  1967. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  1968. efx_oword_t nic_stat;
  1969. struct pci_dev *dev;
  1970. u8 pci_rev = efx->pci_dev->revision;
  1971. if ((pci_rev == 0xff) || (pci_rev == 0)) {
  1972. netif_err(efx, probe, efx->net_dev,
  1973. "Falcon rev A0 not supported\n");
  1974. goto fail1;
  1975. }
  1976. efx_reado(efx, &nic_stat, FR_AB_NIC_STAT);
  1977. if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) {
  1978. netif_err(efx, probe, efx->net_dev,
  1979. "Falcon rev A1 1G not supported\n");
  1980. goto fail1;
  1981. }
  1982. if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) {
  1983. netif_err(efx, probe, efx->net_dev,
  1984. "Falcon rev A1 PCI-X not supported\n");
  1985. goto fail1;
  1986. }
  1987. dev = pci_dev_get(efx->pci_dev);
  1988. while ((dev = pci_get_device(PCI_VENDOR_ID_SOLARFLARE,
  1989. PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1,
  1990. dev))) {
  1991. if (dev->bus == efx->pci_dev->bus &&
  1992. dev->devfn == efx->pci_dev->devfn + 1) {
  1993. nic_data->pci_dev2 = dev;
  1994. break;
  1995. }
  1996. }
  1997. if (!nic_data->pci_dev2) {
  1998. netif_err(efx, probe, efx->net_dev,
  1999. "failed to find secondary function\n");
  2000. rc = -ENODEV;
  2001. goto fail2;
  2002. }
  2003. }
  2004. /* Now we can reset the NIC */
  2005. rc = __falcon_reset_hw(efx, RESET_TYPE_ALL);
  2006. if (rc) {
  2007. netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
  2008. goto fail3;
  2009. }
  2010. /* Allocate memory for INT_KER */
  2011. rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t),
  2012. GFP_KERNEL);
  2013. if (rc)
  2014. goto fail4;
  2015. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  2016. netif_dbg(efx, probe, efx->net_dev,
  2017. "INT_KER at %llx (virt %p phys %llx)\n",
  2018. (u64)efx->irq_status.dma_addr,
  2019. efx->irq_status.addr,
  2020. (u64)virt_to_phys(efx->irq_status.addr));
  2021. falcon_probe_spi_devices(efx);
  2022. /* Read in the non-volatile configuration */
  2023. rc = falcon_probe_nvconfig(efx);
  2024. if (rc) {
  2025. if (rc == -EINVAL)
  2026. netif_err(efx, probe, efx->net_dev, "NVRAM is invalid\n");
  2027. goto fail5;
  2028. }
  2029. efx->max_channels = (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ? 4 :
  2030. EFX_MAX_CHANNELS);
  2031. efx->max_tx_channels = efx->max_channels;
  2032. efx->timer_quantum_ns = 4968; /* 621 cycles */
  2033. /* Initialise I2C adapter */
  2034. board = falcon_board(efx);
  2035. board->i2c_adap.owner = THIS_MODULE;
  2036. board->i2c_data = falcon_i2c_bit_operations;
  2037. board->i2c_data.data = efx;
  2038. board->i2c_adap.algo_data = &board->i2c_data;
  2039. board->i2c_adap.dev.parent = &efx->pci_dev->dev;
  2040. strlcpy(board->i2c_adap.name, "SFC4000 GPIO",
  2041. sizeof(board->i2c_adap.name));
  2042. rc = i2c_bit_add_bus(&board->i2c_adap);
  2043. if (rc)
  2044. goto fail5;
  2045. rc = falcon_board(efx)->type->init(efx);
  2046. if (rc) {
  2047. netif_err(efx, probe, efx->net_dev,
  2048. "failed to initialise board\n");
  2049. goto fail6;
  2050. }
  2051. nic_data->stats_disable_count = 1;
  2052. setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func,
  2053. (unsigned long)efx);
  2054. return 0;
  2055. fail6:
  2056. i2c_del_adapter(&board->i2c_adap);
  2057. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  2058. fail5:
  2059. efx_nic_free_buffer(efx, &efx->irq_status);
  2060. fail4:
  2061. fail3:
  2062. if (nic_data->pci_dev2) {
  2063. pci_dev_put(nic_data->pci_dev2);
  2064. nic_data->pci_dev2 = NULL;
  2065. }
  2066. fail2:
  2067. fail1:
  2068. kfree(efx->nic_data);
  2069. return rc;
  2070. }
  2071. static void falcon_init_rx_cfg(struct efx_nic *efx)
  2072. {
  2073. /* RX control FIFO thresholds (32 entries) */
  2074. const unsigned ctrl_xon_thr = 20;
  2075. const unsigned ctrl_xoff_thr = 25;
  2076. efx_oword_t reg;
  2077. efx_reado(efx, &reg, FR_AZ_RX_CFG);
  2078. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) {
  2079. /* Data FIFO size is 5.5K. The RX DMA engine only
  2080. * supports scattering for user-mode queues, but will
  2081. * split DMA writes at intervals of RX_USR_BUF_SIZE
  2082. * (32-byte units) even for kernel-mode queues. We
  2083. * set it to be so large that that never happens.
  2084. */
  2085. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0);
  2086. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE,
  2087. (3 * 4096) >> 5);
  2088. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, 512 >> 8);
  2089. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, 2048 >> 8);
  2090. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr);
  2091. EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr);
  2092. } else {
  2093. /* Data FIFO size is 80K; register fields moved */
  2094. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0);
  2095. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE,
  2096. EFX_RX_USR_BUF_SIZE >> 5);
  2097. /* Send XON and XOFF at ~3 * max MTU away from empty/full */
  2098. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, 27648 >> 8);
  2099. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, 54272 >> 8);
  2100. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr);
  2101. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr);
  2102. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1);
  2103. /* Enable hash insertion. This is broken for the
  2104. * 'Falcon' hash so also select Toeplitz TCP/IPv4 and
  2105. * IPv4 hashes. */
  2106. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1);
  2107. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1);
  2108. EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1);
  2109. }
  2110. /* Always enable XOFF signal from RX FIFO. We enable
  2111. * or disable transmission of pause frames at the MAC. */
  2112. EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1);
  2113. efx_writeo(efx, &reg, FR_AZ_RX_CFG);
  2114. }
  2115. /* This call performs hardware-specific global initialisation, such as
  2116. * defining the descriptor cache sizes and number of RSS channels.
  2117. * It does not set up any buffers, descriptor rings or event queues.
  2118. */
  2119. static int falcon_init_nic(struct efx_nic *efx)
  2120. {
  2121. efx_oword_t temp;
  2122. int rc;
  2123. /* Use on-chip SRAM */
  2124. efx_reado(efx, &temp, FR_AB_NIC_STAT);
  2125. EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1);
  2126. efx_writeo(efx, &temp, FR_AB_NIC_STAT);
  2127. rc = falcon_reset_sram(efx);
  2128. if (rc)
  2129. return rc;
  2130. /* Clear the parity enables on the TX data fifos as
  2131. * they produce false parity errors because of timing issues
  2132. */
  2133. if (EFX_WORKAROUND_5129(efx)) {
  2134. efx_reado(efx, &temp, FR_AZ_CSR_SPARE);
  2135. EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0);
  2136. efx_writeo(efx, &temp, FR_AZ_CSR_SPARE);
  2137. }
  2138. if (EFX_WORKAROUND_7244(efx)) {
  2139. efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL);
  2140. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8);
  2141. EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8);
  2142. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8);
  2143. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8);
  2144. efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL);
  2145. }
  2146. /* XXX This is documented only for Falcon A0/A1 */
  2147. /* Setup RX. Wait for descriptor is broken and must
  2148. * be disabled. RXDP recovery shouldn't be needed, but is.
  2149. */
  2150. efx_reado(efx, &temp, FR_AA_RX_SELF_RST);
  2151. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1);
  2152. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1);
  2153. if (EFX_WORKAROUND_5583(efx))
  2154. EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1);
  2155. efx_writeo(efx, &temp, FR_AA_RX_SELF_RST);
  2156. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  2157. * descriptors (which is bad).
  2158. */
  2159. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  2160. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  2161. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  2162. falcon_init_rx_cfg(efx);
  2163. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  2164. falcon_b0_rx_push_rss_config(efx, false, efx->rx_indir_table);
  2165. /* Set destination of both TX and RX Flush events */
  2166. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  2167. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  2168. }
  2169. efx_farch_init_common(efx);
  2170. return 0;
  2171. }
  2172. static void falcon_remove_nic(struct efx_nic *efx)
  2173. {
  2174. struct falcon_nic_data *nic_data = efx->nic_data;
  2175. struct falcon_board *board = falcon_board(efx);
  2176. board->type->fini(efx);
  2177. /* Remove I2C adapter and clear it in preparation for a retry */
  2178. i2c_del_adapter(&board->i2c_adap);
  2179. memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
  2180. efx_nic_free_buffer(efx, &efx->irq_status);
  2181. __falcon_reset_hw(efx, RESET_TYPE_ALL);
  2182. /* Release the second function after the reset */
  2183. if (nic_data->pci_dev2) {
  2184. pci_dev_put(nic_data->pci_dev2);
  2185. nic_data->pci_dev2 = NULL;
  2186. }
  2187. /* Tear down the private nic state */
  2188. kfree(efx->nic_data);
  2189. efx->nic_data = NULL;
  2190. }
  2191. static size_t falcon_describe_nic_stats(struct efx_nic *efx, u8 *names)
  2192. {
  2193. return efx_nic_describe_stats(falcon_stat_desc, FALCON_STAT_COUNT,
  2194. falcon_stat_mask, names);
  2195. }
  2196. static size_t falcon_update_nic_stats(struct efx_nic *efx, u64 *full_stats,
  2197. struct rtnl_link_stats64 *core_stats)
  2198. {
  2199. struct falcon_nic_data *nic_data = efx->nic_data;
  2200. u64 *stats = nic_data->stats;
  2201. efx_oword_t cnt;
  2202. if (!nic_data->stats_disable_count) {
  2203. efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP);
  2204. stats[FALCON_STAT_rx_nodesc_drop_cnt] +=
  2205. EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT);
  2206. if (nic_data->stats_pending &&
  2207. FALCON_XMAC_STATS_DMA_FLAG(efx)) {
  2208. nic_data->stats_pending = false;
  2209. rmb(); /* read the done flag before the stats */
  2210. efx_nic_update_stats(
  2211. falcon_stat_desc, FALCON_STAT_COUNT,
  2212. falcon_stat_mask,
  2213. stats, efx->stats_buffer.addr, true);
  2214. }
  2215. /* Update derived statistic */
  2216. efx_update_diff_stat(&stats[FALCON_STAT_rx_bad_bytes],
  2217. stats[FALCON_STAT_rx_bytes] -
  2218. stats[FALCON_STAT_rx_good_bytes] -
  2219. stats[FALCON_STAT_rx_control] * 64);
  2220. efx_update_sw_stats(efx, stats);
  2221. }
  2222. if (full_stats)
  2223. memcpy(full_stats, stats, sizeof(u64) * FALCON_STAT_COUNT);
  2224. if (core_stats) {
  2225. core_stats->rx_packets = stats[FALCON_STAT_rx_packets];
  2226. core_stats->tx_packets = stats[FALCON_STAT_tx_packets];
  2227. core_stats->rx_bytes = stats[FALCON_STAT_rx_bytes];
  2228. core_stats->tx_bytes = stats[FALCON_STAT_tx_bytes];
  2229. core_stats->rx_dropped = stats[FALCON_STAT_rx_nodesc_drop_cnt] +
  2230. stats[GENERIC_STAT_rx_nodesc_trunc] +
  2231. stats[GENERIC_STAT_rx_noskb_drops];
  2232. core_stats->multicast = stats[FALCON_STAT_rx_multicast];
  2233. core_stats->rx_length_errors =
  2234. stats[FALCON_STAT_rx_gtjumbo] +
  2235. stats[FALCON_STAT_rx_length_error];
  2236. core_stats->rx_crc_errors = stats[FALCON_STAT_rx_bad];
  2237. core_stats->rx_frame_errors = stats[FALCON_STAT_rx_align_error];
  2238. core_stats->rx_fifo_errors = stats[FALCON_STAT_rx_overflow];
  2239. core_stats->rx_errors = (core_stats->rx_length_errors +
  2240. core_stats->rx_crc_errors +
  2241. core_stats->rx_frame_errors +
  2242. stats[FALCON_STAT_rx_symbol_error]);
  2243. }
  2244. return FALCON_STAT_COUNT;
  2245. }
  2246. void falcon_start_nic_stats(struct efx_nic *efx)
  2247. {
  2248. struct falcon_nic_data *nic_data = efx->nic_data;
  2249. spin_lock_bh(&efx->stats_lock);
  2250. if (--nic_data->stats_disable_count == 0)
  2251. falcon_stats_request(efx);
  2252. spin_unlock_bh(&efx->stats_lock);
  2253. }
  2254. /* We don't acutally pull stats on falcon. Wait 10ms so that
  2255. * they arrive when we call this just after start_stats
  2256. */
  2257. static void falcon_pull_nic_stats(struct efx_nic *efx)
  2258. {
  2259. msleep(10);
  2260. }
  2261. void falcon_stop_nic_stats(struct efx_nic *efx)
  2262. {
  2263. struct falcon_nic_data *nic_data = efx->nic_data;
  2264. int i;
  2265. might_sleep();
  2266. spin_lock_bh(&efx->stats_lock);
  2267. ++nic_data->stats_disable_count;
  2268. spin_unlock_bh(&efx->stats_lock);
  2269. del_timer_sync(&nic_data->stats_timer);
  2270. /* Wait enough time for the most recent transfer to
  2271. * complete. */
  2272. for (i = 0; i < 4 && nic_data->stats_pending; i++) {
  2273. if (FALCON_XMAC_STATS_DMA_FLAG(efx))
  2274. break;
  2275. msleep(1);
  2276. }
  2277. spin_lock_bh(&efx->stats_lock);
  2278. falcon_stats_complete(efx);
  2279. spin_unlock_bh(&efx->stats_lock);
  2280. }
  2281. static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  2282. {
  2283. falcon_board(efx)->type->set_id_led(efx, mode);
  2284. }
  2285. /**************************************************************************
  2286. *
  2287. * Wake on LAN
  2288. *
  2289. **************************************************************************
  2290. */
  2291. static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  2292. {
  2293. wol->supported = 0;
  2294. wol->wolopts = 0;
  2295. memset(&wol->sopass, 0, sizeof(wol->sopass));
  2296. }
  2297. static int falcon_set_wol(struct efx_nic *efx, u32 type)
  2298. {
  2299. if (type != 0)
  2300. return -EINVAL;
  2301. return 0;
  2302. }
  2303. /**************************************************************************
  2304. *
  2305. * Revision-dependent attributes used by efx.c and nic.c
  2306. *
  2307. **************************************************************************
  2308. */
  2309. const struct efx_nic_type falcon_a1_nic_type = {
  2310. .is_vf = false,
  2311. .mem_bar = EFX_MEM_BAR,
  2312. .mem_map_size = falcon_a1_mem_map_size,
  2313. .probe = falcon_probe_nic,
  2314. .remove = falcon_remove_nic,
  2315. .init = falcon_init_nic,
  2316. .dimension_resources = falcon_dimension_resources,
  2317. .fini = falcon_irq_ack_a1,
  2318. .monitor = falcon_monitor,
  2319. .map_reset_reason = falcon_map_reset_reason,
  2320. .map_reset_flags = falcon_map_reset_flags,
  2321. .reset = falcon_reset_hw,
  2322. .probe_port = falcon_probe_port,
  2323. .remove_port = falcon_remove_port,
  2324. .handle_global_event = falcon_handle_global_event,
  2325. .fini_dmaq = efx_farch_fini_dmaq,
  2326. .prepare_flush = falcon_prepare_flush,
  2327. .finish_flush = efx_port_dummy_op_void,
  2328. .prepare_flr = efx_port_dummy_op_void,
  2329. .finish_flr = efx_farch_finish_flr,
  2330. .describe_stats = falcon_describe_nic_stats,
  2331. .update_stats = falcon_update_nic_stats,
  2332. .start_stats = falcon_start_nic_stats,
  2333. .pull_stats = falcon_pull_nic_stats,
  2334. .stop_stats = falcon_stop_nic_stats,
  2335. .set_id_led = falcon_set_id_led,
  2336. .push_irq_moderation = falcon_push_irq_moderation,
  2337. .reconfigure_port = falcon_reconfigure_port,
  2338. .prepare_enable_fc_tx = falcon_a1_prepare_enable_fc_tx,
  2339. .reconfigure_mac = falcon_reconfigure_xmac,
  2340. .check_mac_fault = falcon_xmac_check_fault,
  2341. .get_wol = falcon_get_wol,
  2342. .set_wol = falcon_set_wol,
  2343. .resume_wol = efx_port_dummy_op_void,
  2344. .test_nvram = falcon_test_nvram,
  2345. .irq_enable_master = efx_farch_irq_enable_master,
  2346. .irq_test_generate = efx_farch_irq_test_generate,
  2347. .irq_disable_non_ev = efx_farch_irq_disable_master,
  2348. .irq_handle_msi = efx_farch_msi_interrupt,
  2349. .irq_handle_legacy = falcon_legacy_interrupt_a1,
  2350. .tx_probe = efx_farch_tx_probe,
  2351. .tx_init = efx_farch_tx_init,
  2352. .tx_remove = efx_farch_tx_remove,
  2353. .tx_write = efx_farch_tx_write,
  2354. .rx_push_rss_config = dummy_rx_push_rss_config,
  2355. .rx_probe = efx_farch_rx_probe,
  2356. .rx_init = efx_farch_rx_init,
  2357. .rx_remove = efx_farch_rx_remove,
  2358. .rx_write = efx_farch_rx_write,
  2359. .rx_defer_refill = efx_farch_rx_defer_refill,
  2360. .ev_probe = efx_farch_ev_probe,
  2361. .ev_init = efx_farch_ev_init,
  2362. .ev_fini = efx_farch_ev_fini,
  2363. .ev_remove = efx_farch_ev_remove,
  2364. .ev_process = efx_farch_ev_process,
  2365. .ev_read_ack = efx_farch_ev_read_ack,
  2366. .ev_test_generate = efx_farch_ev_test_generate,
  2367. /* We don't expose the filter table on Falcon A1 as it is not
  2368. * mapped into function 0, but these implementations still
  2369. * work with a degenerate case of all tables set to size 0.
  2370. */
  2371. .filter_table_probe = efx_farch_filter_table_probe,
  2372. .filter_table_restore = efx_farch_filter_table_restore,
  2373. .filter_table_remove = efx_farch_filter_table_remove,
  2374. .filter_insert = efx_farch_filter_insert,
  2375. .filter_remove_safe = efx_farch_filter_remove_safe,
  2376. .filter_get_safe = efx_farch_filter_get_safe,
  2377. .filter_clear_rx = efx_farch_filter_clear_rx,
  2378. .filter_count_rx_used = efx_farch_filter_count_rx_used,
  2379. .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit,
  2380. .filter_get_rx_ids = efx_farch_filter_get_rx_ids,
  2381. #ifdef CONFIG_SFC_MTD
  2382. .mtd_probe = falcon_mtd_probe,
  2383. .mtd_rename = falcon_mtd_rename,
  2384. .mtd_read = falcon_mtd_read,
  2385. .mtd_erase = falcon_mtd_erase,
  2386. .mtd_write = falcon_mtd_write,
  2387. .mtd_sync = falcon_mtd_sync,
  2388. #endif
  2389. .revision = EFX_REV_FALCON_A1,
  2390. .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER,
  2391. .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER,
  2392. .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER,
  2393. .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER,
  2394. .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER,
  2395. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2396. .rx_buffer_padding = 0x24,
  2397. .can_rx_scatter = false,
  2398. .max_interrupt_mode = EFX_INT_MODE_MSI,
  2399. .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH,
  2400. .offload_features = NETIF_F_IP_CSUM,
  2401. .mcdi_max_ver = -1,
  2402. #ifdef CONFIG_SFC_SRIOV
  2403. .vswitching_probe = efx_port_dummy_op_int,
  2404. .vswitching_restore = efx_port_dummy_op_int,
  2405. .vswitching_remove = efx_port_dummy_op_void,
  2406. #endif
  2407. };
  2408. const struct efx_nic_type falcon_b0_nic_type = {
  2409. .is_vf = false,
  2410. .mem_bar = EFX_MEM_BAR,
  2411. .mem_map_size = falcon_b0_mem_map_size,
  2412. .probe = falcon_probe_nic,
  2413. .remove = falcon_remove_nic,
  2414. .init = falcon_init_nic,
  2415. .dimension_resources = falcon_dimension_resources,
  2416. .fini = efx_port_dummy_op_void,
  2417. .monitor = falcon_monitor,
  2418. .map_reset_reason = falcon_map_reset_reason,
  2419. .map_reset_flags = falcon_map_reset_flags,
  2420. .reset = falcon_reset_hw,
  2421. .probe_port = falcon_probe_port,
  2422. .remove_port = falcon_remove_port,
  2423. .handle_global_event = falcon_handle_global_event,
  2424. .fini_dmaq = efx_farch_fini_dmaq,
  2425. .prepare_flush = falcon_prepare_flush,
  2426. .finish_flush = efx_port_dummy_op_void,
  2427. .prepare_flr = efx_port_dummy_op_void,
  2428. .finish_flr = efx_farch_finish_flr,
  2429. .describe_stats = falcon_describe_nic_stats,
  2430. .update_stats = falcon_update_nic_stats,
  2431. .start_stats = falcon_start_nic_stats,
  2432. .pull_stats = falcon_pull_nic_stats,
  2433. .stop_stats = falcon_stop_nic_stats,
  2434. .set_id_led = falcon_set_id_led,
  2435. .push_irq_moderation = falcon_push_irq_moderation,
  2436. .reconfigure_port = falcon_reconfigure_port,
  2437. .prepare_enable_fc_tx = falcon_b0_prepare_enable_fc_tx,
  2438. .reconfigure_mac = falcon_reconfigure_xmac,
  2439. .check_mac_fault = falcon_xmac_check_fault,
  2440. .get_wol = falcon_get_wol,
  2441. .set_wol = falcon_set_wol,
  2442. .resume_wol = efx_port_dummy_op_void,
  2443. .test_chip = falcon_b0_test_chip,
  2444. .test_nvram = falcon_test_nvram,
  2445. .irq_enable_master = efx_farch_irq_enable_master,
  2446. .irq_test_generate = efx_farch_irq_test_generate,
  2447. .irq_disable_non_ev = efx_farch_irq_disable_master,
  2448. .irq_handle_msi = efx_farch_msi_interrupt,
  2449. .irq_handle_legacy = efx_farch_legacy_interrupt,
  2450. .tx_probe = efx_farch_tx_probe,
  2451. .tx_init = efx_farch_tx_init,
  2452. .tx_remove = efx_farch_tx_remove,
  2453. .tx_write = efx_farch_tx_write,
  2454. .rx_push_rss_config = falcon_b0_rx_push_rss_config,
  2455. .rx_probe = efx_farch_rx_probe,
  2456. .rx_init = efx_farch_rx_init,
  2457. .rx_remove = efx_farch_rx_remove,
  2458. .rx_write = efx_farch_rx_write,
  2459. .rx_defer_refill = efx_farch_rx_defer_refill,
  2460. .ev_probe = efx_farch_ev_probe,
  2461. .ev_init = efx_farch_ev_init,
  2462. .ev_fini = efx_farch_ev_fini,
  2463. .ev_remove = efx_farch_ev_remove,
  2464. .ev_process = efx_farch_ev_process,
  2465. .ev_read_ack = efx_farch_ev_read_ack,
  2466. .ev_test_generate = efx_farch_ev_test_generate,
  2467. .filter_table_probe = efx_farch_filter_table_probe,
  2468. .filter_table_restore = efx_farch_filter_table_restore,
  2469. .filter_table_remove = efx_farch_filter_table_remove,
  2470. .filter_update_rx_scatter = efx_farch_filter_update_rx_scatter,
  2471. .filter_insert = efx_farch_filter_insert,
  2472. .filter_remove_safe = efx_farch_filter_remove_safe,
  2473. .filter_get_safe = efx_farch_filter_get_safe,
  2474. .filter_clear_rx = efx_farch_filter_clear_rx,
  2475. .filter_count_rx_used = efx_farch_filter_count_rx_used,
  2476. .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit,
  2477. .filter_get_rx_ids = efx_farch_filter_get_rx_ids,
  2478. #ifdef CONFIG_RFS_ACCEL
  2479. .filter_rfs_insert = efx_farch_filter_rfs_insert,
  2480. .filter_rfs_expire_one = efx_farch_filter_rfs_expire_one,
  2481. #endif
  2482. #ifdef CONFIG_SFC_MTD
  2483. .mtd_probe = falcon_mtd_probe,
  2484. .mtd_rename = falcon_mtd_rename,
  2485. .mtd_read = falcon_mtd_read,
  2486. .mtd_erase = falcon_mtd_erase,
  2487. .mtd_write = falcon_mtd_write,
  2488. .mtd_sync = falcon_mtd_sync,
  2489. #endif
  2490. .revision = EFX_REV_FALCON_B0,
  2491. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  2492. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  2493. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  2494. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  2495. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  2496. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  2497. .rx_prefix_size = FS_BZ_RX_PREFIX_SIZE,
  2498. .rx_hash_offset = FS_BZ_RX_PREFIX_HASH_OFST,
  2499. .rx_buffer_padding = 0,
  2500. .can_rx_scatter = true,
  2501. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  2502. .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH,
  2503. .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH | NETIF_F_NTUPLE,
  2504. .mcdi_max_ver = -1,
  2505. .max_rx_ip_filters = FR_BZ_RX_FILTER_TBL0_ROWS,
  2506. #ifdef CONFIG_SFC_SRIOV
  2507. .vswitching_probe = efx_port_dummy_op_int,
  2508. .vswitching_restore = efx_port_dummy_op_int,
  2509. .vswitching_remove = efx_port_dummy_op_void,
  2510. #endif
  2511. };