falcon.c 84 KB

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