falcon.c 85 KB

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