falcon.c 85 KB

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