falcon.c 85 KB

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