falcon.c 85 KB

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