701-stmmac_update_to_4.3.patch 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258
  1. --- a/include/linux/stmmac.h
  2. +++ b/include/linux/stmmac.h
  3. @@ -99,6 +99,7 @@ struct plat_stmmacenet_data {
  4. int phy_addr;
  5. int interface;
  6. struct stmmac_mdio_bus_data *mdio_bus_data;
  7. + struct device_node *phy_node;
  8. struct stmmac_dma_cfg *dma_cfg;
  9. int clk_csr;
  10. int has_gmac;
  11. @@ -114,32 +115,12 @@ struct plat_stmmacenet_data {
  12. int maxmtu;
  13. int multicast_filter_bins;
  14. int unicast_filter_entries;
  15. + int tx_fifo_size;
  16. + int rx_fifo_size;
  17. void (*fix_mac_speed)(void *priv, unsigned int speed);
  18. void (*bus_setup)(void __iomem *ioaddr);
  19. - void *(*setup)(struct platform_device *pdev);
  20. - void (*free)(struct platform_device *pdev, void *priv);
  21. int (*init)(struct platform_device *pdev, void *priv);
  22. void (*exit)(struct platform_device *pdev, void *priv);
  23. - void *custom_cfg;
  24. - void *custom_data;
  25. void *bsp_priv;
  26. };
  27. -
  28. -/* of_data for SoC glue layer device tree bindings */
  29. -
  30. -struct stmmac_of_data {
  31. - int has_gmac;
  32. - int enh_desc;
  33. - int tx_coe;
  34. - int rx_coe;
  35. - int bugged_jumbo;
  36. - int pmt;
  37. - int riwt_off;
  38. - void (*fix_mac_speed)(void *priv, unsigned int speed);
  39. - void (*bus_setup)(void __iomem *ioaddr);
  40. - void *(*setup)(struct platform_device *pdev);
  41. - void (*free)(struct platform_device *pdev, void *priv);
  42. - int (*init)(struct platform_device *pdev, void *priv);
  43. - void (*exit)(struct platform_device *pdev, void *priv);
  44. -};
  45. #endif
  46. --- a/drivers/net/ethernet/stmicro/Kconfig
  47. +++ b/drivers/net/ethernet/stmicro/Kconfig
  48. @@ -7,9 +7,7 @@ config NET_VENDOR_STMICRO
  49. default y
  50. depends on HAS_IOMEM
  51. ---help---
  52. - If you have a network (Ethernet) card belonging to this class, say Y
  53. - and read the Ethernet-HOWTO, available from
  54. - <http://www.tldp.org/docs.html#howto>.
  55. + If you have a network (Ethernet) card belonging to this class, say Y.
  56. Note that the answer to this question doesn't directly affect the
  57. kernel: saying N will just cause the configurator to skip all
  58. --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
  59. +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
  60. @@ -14,21 +14,54 @@ config STMMAC_ETH
  61. if STMMAC_ETH
  62. config STMMAC_PLATFORM
  63. - bool "STMMAC Platform bus support"
  64. + tristate "STMMAC Platform bus support"
  65. depends on STMMAC_ETH
  66. + select MFD_SYSCON
  67. default y
  68. ---help---
  69. - This selects the platform specific bus support for
  70. - the stmmac device driver. This is the driver used
  71. - on many embedded STM platforms based on ARM and SuperH
  72. - processors.
  73. + This selects the platform specific bus support for the stmmac driver.
  74. + This is the driver used on several SoCs:
  75. + STi, Allwinner, Amlogic Meson, Altera SOCFPGA.
  76. +
  77. If you have a controller with this interface, say Y or M here.
  78. If unsure, say N.
  79. +if STMMAC_PLATFORM
  80. +
  81. +config DWMAC_GENERIC
  82. + tristate "Generic driver for DWMAC"
  83. + default STMMAC_PLATFORM
  84. + ---help---
  85. + Generic DWMAC driver for platforms that don't require any
  86. + platform specific code to function or is using platform
  87. + data for setup.
  88. +
  89. +config DWMAC_IPQ806X
  90. + tristate "QCA IPQ806x DWMAC support"
  91. + default ARCH_QCOM
  92. + depends on OF
  93. + select MFD_SYSCON
  94. + help
  95. + Support for QCA IPQ806X DWMAC Ethernet.
  96. +
  97. + This selects the IPQ806x SoC glue layer support for the stmmac
  98. + device driver. This driver does not use any of the hardware
  99. + acceleration features available on this SoC. Network devices
  100. + will behave like standard non-accelerated ethernet interfaces.
  101. +
  102. +config DWMAC_LPC18XX
  103. + tristate "NXP LPC18xx/43xx DWMAC support"
  104. + default ARCH_LPC18XX
  105. + depends on OF
  106. + select MFD_SYSCON
  107. + ---help---
  108. + Support for NXP LPC18xx/43xx DWMAC Ethernet.
  109. +
  110. config DWMAC_MESON
  111. - bool "Amlogic Meson dwmac support"
  112. - depends on STMMAC_PLATFORM && ARCH_MESON
  113. + tristate "Amlogic Meson dwmac support"
  114. + default ARCH_MESON
  115. + depends on OF
  116. help
  117. Support for Ethernet controller on Amlogic Meson SoCs.
  118. @@ -36,9 +69,22 @@ config DWMAC_MESON
  119. the stmmac device driver. This driver is used for Meson6 and
  120. Meson8 SoCs.
  121. +config DWMAC_ROCKCHIP
  122. + tristate "Rockchip dwmac support"
  123. + default ARCH_ROCKCHIP
  124. + depends on OF
  125. + select MFD_SYSCON
  126. + help
  127. + Support for Ethernet controller on Rockchip RK3288 SoC.
  128. +
  129. + This selects the Rockchip RK3288 SoC glue layer support for
  130. + the stmmac device driver.
  131. +
  132. config DWMAC_SOCFPGA
  133. - bool "SOCFPGA dwmac support"
  134. - depends on STMMAC_PLATFORM && MFD_SYSCON && (ARCH_SOCFPGA || COMPILE_TEST)
  135. + tristate "SOCFPGA dwmac support"
  136. + default ARCH_SOCFPGA
  137. + depends on OF
  138. + select MFD_SYSCON
  139. help
  140. Support for ethernet controller on Altera SOCFPGA
  141. @@ -46,21 +92,11 @@ config DWMAC_SOCFPGA
  142. for the stmmac device driver. This driver is used for
  143. arria5 and cyclone5 FPGA SoCs.
  144. -config DWMAC_SUNXI
  145. - bool "Allwinner GMAC support"
  146. - depends on STMMAC_PLATFORM && ARCH_SUNXI
  147. - default y
  148. - ---help---
  149. - Support for Allwinner A20/A31 GMAC ethernet controllers.
  150. -
  151. - This selects Allwinner SoC glue layer support for the
  152. - stmmac device driver. This driver is used for A20/A31
  153. - GMAC ethernet controller.
  154. -
  155. config DWMAC_STI
  156. - bool "STi GMAC support"
  157. - depends on STMMAC_PLATFORM && ARCH_STI
  158. - default y
  159. + tristate "STi GMAC support"
  160. + default ARCH_STI
  161. + depends on OF
  162. + select MFD_SYSCON
  163. ---help---
  164. Support for ethernet controller on STi SOCs.
  165. @@ -68,8 +104,20 @@ config DWMAC_STI
  166. device driver. This driver is used on for the STi series
  167. SOCs GMAC ethernet controller.
  168. +config DWMAC_SUNXI
  169. + tristate "Allwinner GMAC support"
  170. + default ARCH_SUNXI
  171. + depends on OF
  172. + ---help---
  173. + Support for Allwinner A20/A31 GMAC ethernet controllers.
  174. +
  175. + This selects Allwinner SoC glue layer support for the
  176. + stmmac device driver. This driver is used for A20/A31
  177. + GMAC ethernet controller.
  178. +endif
  179. +
  180. config STMMAC_PCI
  181. - bool "STMMAC PCI bus support"
  182. + tristate "STMMAC PCI bus support"
  183. depends on STMMAC_ETH && PCI
  184. ---help---
  185. This is to select the Synopsys DWMAC available on PCI devices,
  186. @@ -79,22 +127,4 @@ config STMMAC_PCI
  187. D1215994A VIRTEX FPGA board.
  188. If unsure, say N.
  189. -
  190. -config STMMAC_DEBUG_FS
  191. - bool "Enable monitoring via sysFS "
  192. - default n
  193. - depends on STMMAC_ETH && DEBUG_FS
  194. - ---help---
  195. - The stmmac entry in /sys reports DMA TX/RX rings
  196. - or (if supported) the HW cap register.
  197. -
  198. -config STMMAC_DA
  199. - bool "STMMAC DMA arbitration scheme"
  200. - default n
  201. - ---help---
  202. - Selecting this option, rx has priority over Tx (only for Giga
  203. - Ethernet device).
  204. - By default, the DMA arbitration scheme is based on Round-robin
  205. - (rx:tx priority is 1:1).
  206. -
  207. endif
  208. --- a/drivers/net/ethernet/stmicro/stmmac/Makefile
  209. +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
  210. @@ -1,11 +1,20 @@
  211. obj-$(CONFIG_STMMAC_ETH) += stmmac.o
  212. -stmmac-$(CONFIG_STMMAC_PLATFORM) += stmmac_platform.o
  213. -stmmac-$(CONFIG_STMMAC_PCI) += stmmac_pci.o
  214. -stmmac-$(CONFIG_DWMAC_MESON) += dwmac-meson.o
  215. -stmmac-$(CONFIG_DWMAC_SUNXI) += dwmac-sunxi.o
  216. -stmmac-$(CONFIG_DWMAC_STI) += dwmac-sti.o
  217. -stmmac-$(CONFIG_DWMAC_SOCFPGA) += dwmac-socfpga.o
  218. stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o \
  219. - chain_mode.o dwmac_lib.o dwmac1000_core.o dwmac1000_dma.o \
  220. - dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o \
  221. + chain_mode.o dwmac_lib.o dwmac1000_core.o dwmac1000_dma.o \
  222. + dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o \
  223. mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o $(stmmac-y)
  224. +
  225. +# Ordering matters. Generic driver must be last.
  226. +obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o
  227. +obj-$(CONFIG_DWMAC_IPQ806X) += dwmac-ipq806x.o
  228. +obj-$(CONFIG_DWMAC_LPC18XX) += dwmac-lpc18xx.o
  229. +obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o
  230. +obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o
  231. +obj-$(CONFIG_DWMAC_SOCFPGA) += dwmac-socfpga.o
  232. +obj-$(CONFIG_DWMAC_STI) += dwmac-sti.o
  233. +obj-$(CONFIG_DWMAC_SUNXI) += dwmac-sunxi.o
  234. +obj-$(CONFIG_DWMAC_GENERIC) += dwmac-generic.o
  235. +stmmac-platform-objs:= stmmac_platform.o
  236. +
  237. +obj-$(CONFIG_STMMAC_PCI) += stmmac-pci.o
  238. +stmmac-pci-objs:= stmmac_pci.o
  239. --- a/drivers/net/ethernet/stmicro/stmmac/common.h
  240. +++ b/drivers/net/ethernet/stmicro/stmmac/common.h
  241. @@ -44,6 +44,7 @@
  242. #undef FRAME_FILTER_DEBUG
  243. /* #define FRAME_FILTER_DEBUG */
  244. +/* Extra statistic and debug information exposed by ethtool */
  245. struct stmmac_extra_stats {
  246. /* Transmit errors */
  247. unsigned long tx_underflow ____cacheline_aligned;
  248. @@ -149,7 +150,7 @@ struct stmmac_extra_stats {
  249. #define MAC_CSR_H_FRQ_MASK 0x20
  250. #define HASH_TABLE_SIZE 64
  251. -#define PAUSE_TIME 0x200
  252. +#define PAUSE_TIME 0xffff
  253. /* Flow Control defines */
  254. #define FLOW_OFF 0
  255. @@ -220,6 +221,7 @@ enum dma_irq_status {
  256. handle_tx = 0x8,
  257. };
  258. +/* EEE and LPI defines */
  259. #define CORE_IRQ_TX_PATH_IN_LPI_MODE (1 << 0)
  260. #define CORE_IRQ_TX_PATH_EXIT_LPI_MODE (1 << 1)
  261. #define CORE_IRQ_RX_PATH_IN_LPI_MODE (1 << 2)
  262. @@ -229,6 +231,7 @@ enum dma_irq_status {
  263. #define CORE_PCS_LINK_STATUS (1 << 6)
  264. #define CORE_RGMII_IRQ (1 << 7)
  265. +/* Physical Coding Sublayer */
  266. struct rgmii_adv {
  267. unsigned int pause;
  268. unsigned int duplex;
  269. @@ -294,6 +297,7 @@ struct dma_features {
  270. #define JUMBO_LEN 9000
  271. +/* Descriptors helpers */
  272. struct stmmac_desc_ops {
  273. /* DMA RX descriptor ring initialization */
  274. void (*init_rx_desc) (struct dma_desc *p, int disable_rx_ic, int mode,
  275. @@ -341,6 +345,10 @@ struct stmmac_desc_ops {
  276. int (*get_rx_timestamp_status) (void *desc, u32 ats);
  277. };
  278. +extern const struct stmmac_desc_ops enh_desc_ops;
  279. +extern const struct stmmac_desc_ops ndesc_ops;
  280. +
  281. +/* Specific DMA helpers */
  282. struct stmmac_dma_ops {
  283. /* DMA core initialization */
  284. int (*init) (void __iomem *ioaddr, int pbl, int fb, int mb,
  285. @@ -349,7 +357,8 @@ struct stmmac_dma_ops {
  286. void (*dump_regs) (void __iomem *ioaddr);
  287. /* Set tx/rx threshold in the csr6 register
  288. * An invalid value enables the store-and-forward mode */
  289. - void (*dma_mode) (void __iomem *ioaddr, int txmode, int rxmode);
  290. + void (*dma_mode)(void __iomem *ioaddr, int txmode, int rxmode,
  291. + int rxfifosz);
  292. /* To track extra statistic (if supported) */
  293. void (*dma_diagnostic_fr) (void *data, struct stmmac_extra_stats *x,
  294. void __iomem *ioaddr);
  295. @@ -370,6 +379,7 @@ struct stmmac_dma_ops {
  296. struct mac_device_info;
  297. +/* Helpers to program the MAC core */
  298. struct stmmac_ops {
  299. /* MAC core initialization */
  300. void (*core_init)(struct mac_device_info *hw, int mtu);
  301. @@ -400,6 +410,7 @@ struct stmmac_ops {
  302. void (*get_adv)(struct mac_device_info *hw, struct rgmii_adv *adv);
  303. };
  304. +/* PTP and HW Timer helpers */
  305. struct stmmac_hwtimestamp {
  306. void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
  307. void (*config_sub_second_increment) (void __iomem *ioaddr);
  308. @@ -410,6 +421,8 @@ struct stmmac_hwtimestamp {
  309. u64(*get_systime) (void __iomem *ioaddr);
  310. };
  311. +extern const struct stmmac_hwtimestamp stmmac_ptp;
  312. +
  313. struct mac_link {
  314. int port;
  315. int duplex;
  316. @@ -421,6 +434,7 @@ struct mii_regs {
  317. unsigned int data; /* MII Data */
  318. };
  319. +/* Helpers to manage the descriptors for chain and ring modes */
  320. struct stmmac_mode_ops {
  321. void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
  322. unsigned int extend_desc);
  323. --- /dev/null
  324. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
  325. @@ -0,0 +1,81 @@
  326. +/*
  327. + * Generic DWMAC platform driver
  328. + *
  329. + * Copyright (C) 2007-2011 STMicroelectronics Ltd
  330. + * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
  331. + *
  332. + * This file is licensed under the terms of the GNU General Public
  333. + * License version 2. This program is licensed "as is" without any
  334. + * warranty of any kind, whether express or implied.
  335. + */
  336. +
  337. +#include <linux/module.h>
  338. +#include <linux/of.h>
  339. +#include <linux/platform_device.h>
  340. +
  341. +#include "stmmac.h"
  342. +#include "stmmac_platform.h"
  343. +
  344. +static int dwmac_generic_probe(struct platform_device *pdev)
  345. +{
  346. + struct plat_stmmacenet_data *plat_dat;
  347. + struct stmmac_resources stmmac_res;
  348. + int ret;
  349. +
  350. + ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  351. + if (ret)
  352. + return ret;
  353. +
  354. + if (pdev->dev.of_node) {
  355. + plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  356. + if (IS_ERR(plat_dat)) {
  357. + dev_err(&pdev->dev, "dt configuration failed\n");
  358. + return PTR_ERR(plat_dat);
  359. + }
  360. + } else {
  361. + plat_dat = dev_get_platdata(&pdev->dev);
  362. + if (!plat_dat) {
  363. + dev_err(&pdev->dev, "no platform data provided\n");
  364. + return -EINVAL;
  365. + }
  366. +
  367. + /* Set default value for multicast hash bins */
  368. + plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
  369. +
  370. + /* Set default value for unicast filter entries */
  371. + plat_dat->unicast_filter_entries = 1;
  372. + }
  373. +
  374. + /* Custom initialisation (if needed) */
  375. + if (plat_dat->init) {
  376. + ret = plat_dat->init(pdev, plat_dat->bsp_priv);
  377. + if (ret)
  378. + return ret;
  379. + }
  380. +
  381. + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  382. +}
  383. +
  384. +static const struct of_device_id dwmac_generic_match[] = {
  385. + { .compatible = "st,spear600-gmac"},
  386. + { .compatible = "snps,dwmac-3.610"},
  387. + { .compatible = "snps,dwmac-3.70a"},
  388. + { .compatible = "snps,dwmac-3.710"},
  389. + { .compatible = "snps,dwmac"},
  390. + { }
  391. +};
  392. +MODULE_DEVICE_TABLE(of, dwmac_generic_match);
  393. +
  394. +static struct platform_driver dwmac_generic_driver = {
  395. + .probe = dwmac_generic_probe,
  396. + .remove = stmmac_pltfr_remove,
  397. + .driver = {
  398. + .name = STMMAC_RESOURCE_NAME,
  399. + .pm = &stmmac_pltfr_pm_ops,
  400. + .of_match_table = of_match_ptr(dwmac_generic_match),
  401. + },
  402. +};
  403. +module_platform_driver(dwmac_generic_driver);
  404. +
  405. +MODULE_DESCRIPTION("Generic dwmac driver");
  406. +MODULE_LICENSE("GPL v2");
  407. --- /dev/null
  408. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
  409. @@ -0,0 +1,373 @@
  410. +/*
  411. + * Qualcomm Atheros IPQ806x GMAC glue layer
  412. + *
  413. + * Copyright (C) 2015 The Linux Foundation
  414. + *
  415. + * Permission to use, copy, modify, and/or distribute this software for any
  416. + * purpose with or without fee is hereby granted, provided that the above
  417. + * copyright notice and this permission notice appear in all copies.
  418. + *
  419. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  420. + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  421. + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  422. + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  423. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  424. + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  425. + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  426. + */
  427. +
  428. +#include <linux/device.h>
  429. +#include <linux/platform_device.h>
  430. +#include <linux/phy.h>
  431. +#include <linux/regmap.h>
  432. +#include <linux/clk.h>
  433. +#include <linux/reset.h>
  434. +#include <linux/of_net.h>
  435. +#include <linux/mfd/syscon.h>
  436. +#include <linux/stmmac.h>
  437. +#include <linux/of_mdio.h>
  438. +#include <linux/module.h>
  439. +
  440. +#include "stmmac_platform.h"
  441. +
  442. +#define NSS_COMMON_CLK_GATE 0x8
  443. +#define NSS_COMMON_CLK_GATE_PTP_EN(x) BIT(0x10 + x)
  444. +#define NSS_COMMON_CLK_GATE_RGMII_RX_EN(x) BIT(0x9 + (x * 2))
  445. +#define NSS_COMMON_CLK_GATE_RGMII_TX_EN(x) BIT(0x8 + (x * 2))
  446. +#define NSS_COMMON_CLK_GATE_GMII_RX_EN(x) BIT(0x4 + x)
  447. +#define NSS_COMMON_CLK_GATE_GMII_TX_EN(x) BIT(0x0 + x)
  448. +
  449. +#define NSS_COMMON_CLK_DIV0 0xC
  450. +#define NSS_COMMON_CLK_DIV_OFFSET(x) (x * 8)
  451. +#define NSS_COMMON_CLK_DIV_MASK 0x7f
  452. +
  453. +#define NSS_COMMON_CLK_SRC_CTRL 0x14
  454. +#define NSS_COMMON_CLK_SRC_CTRL_OFFSET(x) (x)
  455. +/* Mode is coded on 1 bit but is different depending on the MAC ID:
  456. + * MAC0: QSGMII=0 RGMII=1
  457. + * MAC1: QSGMII=0 SGMII=0 RGMII=1
  458. + * MAC2 & MAC3: QSGMII=0 SGMII=1
  459. + */
  460. +#define NSS_COMMON_CLK_SRC_CTRL_RGMII(x) 1
  461. +#define NSS_COMMON_CLK_SRC_CTRL_SGMII(x) ((x >= 2) ? 1 : 0)
  462. +
  463. +#define NSS_COMMON_MACSEC_CTL 0x28
  464. +#define NSS_COMMON_MACSEC_CTL_EXT_BYPASS_EN(x) (1 << x)
  465. +
  466. +#define NSS_COMMON_GMAC_CTL(x) (0x30 + (x * 4))
  467. +#define NSS_COMMON_GMAC_CTL_CSYS_REQ BIT(19)
  468. +#define NSS_COMMON_GMAC_CTL_PHY_IFACE_SEL BIT(16)
  469. +#define NSS_COMMON_GMAC_CTL_IFG_LIMIT_OFFSET 8
  470. +#define NSS_COMMON_GMAC_CTL_IFG_OFFSET 0
  471. +#define NSS_COMMON_GMAC_CTL_IFG_MASK 0x3f
  472. +
  473. +#define NSS_COMMON_CLK_DIV_RGMII_1000 1
  474. +#define NSS_COMMON_CLK_DIV_RGMII_100 9
  475. +#define NSS_COMMON_CLK_DIV_RGMII_10 99
  476. +#define NSS_COMMON_CLK_DIV_SGMII_1000 0
  477. +#define NSS_COMMON_CLK_DIV_SGMII_100 4
  478. +#define NSS_COMMON_CLK_DIV_SGMII_10 49
  479. +
  480. +#define QSGMII_PCS_MODE_CTL 0x68
  481. +#define QSGMII_PCS_MODE_CTL_AUTONEG_EN(x) BIT((x * 8) + 7)
  482. +
  483. +#define QSGMII_PCS_CAL_LCKDT_CTL 0x120
  484. +#define QSGMII_PCS_CAL_LCKDT_CTL_RST BIT(19)
  485. +
  486. +/* Only GMAC1/2/3 support SGMII and their CTL register are not contiguous */
  487. +#define QSGMII_PHY_SGMII_CTL(x) ((x == 1) ? 0x134 : \
  488. + (0x13c + (4 * (x - 2))))
  489. +#define QSGMII_PHY_CDR_EN BIT(0)
  490. +#define QSGMII_PHY_RX_FRONT_EN BIT(1)
  491. +#define QSGMII_PHY_RX_SIGNAL_DETECT_EN BIT(2)
  492. +#define QSGMII_PHY_TX_DRIVER_EN BIT(3)
  493. +#define QSGMII_PHY_QSGMII_EN BIT(7)
  494. +#define QSGMII_PHY_PHASE_LOOP_GAIN_OFFSET 12
  495. +#define QSGMII_PHY_PHASE_LOOP_GAIN_MASK 0x7
  496. +#define QSGMII_PHY_RX_DC_BIAS_OFFSET 18
  497. +#define QSGMII_PHY_RX_DC_BIAS_MASK 0x3
  498. +#define QSGMII_PHY_RX_INPUT_EQU_OFFSET 20
  499. +#define QSGMII_PHY_RX_INPUT_EQU_MASK 0x3
  500. +#define QSGMII_PHY_CDR_PI_SLEW_OFFSET 22
  501. +#define QSGMII_PHY_CDR_PI_SLEW_MASK 0x3
  502. +#define QSGMII_PHY_TX_DRV_AMP_OFFSET 28
  503. +#define QSGMII_PHY_TX_DRV_AMP_MASK 0xf
  504. +
  505. +struct ipq806x_gmac {
  506. + struct platform_device *pdev;
  507. + struct regmap *nss_common;
  508. + struct regmap *qsgmii_csr;
  509. + uint32_t id;
  510. + struct clk *core_clk;
  511. + phy_interface_t phy_mode;
  512. +};
  513. +
  514. +static int get_clk_div_sgmii(struct ipq806x_gmac *gmac, unsigned int speed)
  515. +{
  516. + struct device *dev = &gmac->pdev->dev;
  517. + int div;
  518. +
  519. + switch (speed) {
  520. + case SPEED_1000:
  521. + div = NSS_COMMON_CLK_DIV_SGMII_1000;
  522. + break;
  523. +
  524. + case SPEED_100:
  525. + div = NSS_COMMON_CLK_DIV_SGMII_100;
  526. + break;
  527. +
  528. + case SPEED_10:
  529. + div = NSS_COMMON_CLK_DIV_SGMII_10;
  530. + break;
  531. +
  532. + default:
  533. + dev_err(dev, "Speed %dMbps not supported in SGMII\n", speed);
  534. + return -EINVAL;
  535. + }
  536. +
  537. + return div;
  538. +}
  539. +
  540. +static int get_clk_div_rgmii(struct ipq806x_gmac *gmac, unsigned int speed)
  541. +{
  542. + struct device *dev = &gmac->pdev->dev;
  543. + int div;
  544. +
  545. + switch (speed) {
  546. + case SPEED_1000:
  547. + div = NSS_COMMON_CLK_DIV_RGMII_1000;
  548. + break;
  549. +
  550. + case SPEED_100:
  551. + div = NSS_COMMON_CLK_DIV_RGMII_100;
  552. + break;
  553. +
  554. + case SPEED_10:
  555. + div = NSS_COMMON_CLK_DIV_RGMII_10;
  556. + break;
  557. +
  558. + default:
  559. + dev_err(dev, "Speed %dMbps not supported in RGMII\n", speed);
  560. + return -EINVAL;
  561. + }
  562. +
  563. + return div;
  564. +}
  565. +
  566. +static int ipq806x_gmac_set_speed(struct ipq806x_gmac *gmac, unsigned int speed)
  567. +{
  568. + uint32_t clk_bits, val;
  569. + int div;
  570. +
  571. + switch (gmac->phy_mode) {
  572. + case PHY_INTERFACE_MODE_RGMII:
  573. + div = get_clk_div_rgmii(gmac, speed);
  574. + clk_bits = NSS_COMMON_CLK_GATE_RGMII_RX_EN(gmac->id) |
  575. + NSS_COMMON_CLK_GATE_RGMII_TX_EN(gmac->id);
  576. + break;
  577. +
  578. + case PHY_INTERFACE_MODE_SGMII:
  579. + div = get_clk_div_sgmii(gmac, speed);
  580. + clk_bits = NSS_COMMON_CLK_GATE_GMII_RX_EN(gmac->id) |
  581. + NSS_COMMON_CLK_GATE_GMII_TX_EN(gmac->id);
  582. + break;
  583. +
  584. + default:
  585. + dev_err(&gmac->pdev->dev, "Unsupported PHY mode: \"%s\"\n",
  586. + phy_modes(gmac->phy_mode));
  587. + return -EINVAL;
  588. + }
  589. +
  590. + /* Disable the clocks */
  591. + regmap_read(gmac->nss_common, NSS_COMMON_CLK_GATE, &val);
  592. + val &= ~clk_bits;
  593. + regmap_write(gmac->nss_common, NSS_COMMON_CLK_GATE, val);
  594. +
  595. + /* Set the divider */
  596. + regmap_read(gmac->nss_common, NSS_COMMON_CLK_DIV0, &val);
  597. + val &= ~(NSS_COMMON_CLK_DIV_MASK
  598. + << NSS_COMMON_CLK_DIV_OFFSET(gmac->id));
  599. + val |= div << NSS_COMMON_CLK_DIV_OFFSET(gmac->id);
  600. + regmap_write(gmac->nss_common, NSS_COMMON_CLK_DIV0, val);
  601. +
  602. + /* Enable the clock back */
  603. + regmap_read(gmac->nss_common, NSS_COMMON_CLK_GATE, &val);
  604. + val |= clk_bits;
  605. + regmap_write(gmac->nss_common, NSS_COMMON_CLK_GATE, val);
  606. +
  607. + return 0;
  608. +}
  609. +
  610. +static void *ipq806x_gmac_of_parse(struct ipq806x_gmac *gmac)
  611. +{
  612. + struct device *dev = &gmac->pdev->dev;
  613. +
  614. + gmac->phy_mode = of_get_phy_mode(dev->of_node);
  615. + if (gmac->phy_mode < 0) {
  616. + dev_err(dev, "missing phy mode property\n");
  617. + return ERR_PTR(-EINVAL);
  618. + }
  619. +
  620. + if (of_property_read_u32(dev->of_node, "qcom,id", &gmac->id) < 0) {
  621. + dev_err(dev, "missing qcom id property\n");
  622. + return ERR_PTR(-EINVAL);
  623. + }
  624. +
  625. + /* The GMACs are called 1 to 4 in the documentation, but to simplify the
  626. + * code and keep it consistent with the Linux convention, we'll number
  627. + * them from 0 to 3 here.
  628. + */
  629. + if (gmac->id < 0 || gmac->id > 3) {
  630. + dev_err(dev, "invalid gmac id\n");
  631. + return ERR_PTR(-EINVAL);
  632. + }
  633. +
  634. + gmac->core_clk = devm_clk_get(dev, "stmmaceth");
  635. + if (IS_ERR(gmac->core_clk)) {
  636. + dev_err(dev, "missing stmmaceth clk property\n");
  637. + return gmac->core_clk;
  638. + }
  639. + clk_set_rate(gmac->core_clk, 266000000);
  640. +
  641. + /* Setup the register map for the nss common registers */
  642. + gmac->nss_common = syscon_regmap_lookup_by_phandle(dev->of_node,
  643. + "qcom,nss-common");
  644. + if (IS_ERR(gmac->nss_common)) {
  645. + dev_err(dev, "missing nss-common node\n");
  646. + return gmac->nss_common;
  647. + }
  648. +
  649. + /* Setup the register map for the qsgmii csr registers */
  650. + gmac->qsgmii_csr = syscon_regmap_lookup_by_phandle(dev->of_node,
  651. + "qcom,qsgmii-csr");
  652. + if (IS_ERR(gmac->qsgmii_csr)) {
  653. + dev_err(dev, "missing qsgmii-csr node\n");
  654. + return gmac->qsgmii_csr;
  655. + }
  656. +
  657. + return NULL;
  658. +}
  659. +
  660. +static void ipq806x_gmac_fix_mac_speed(void *priv, unsigned int speed)
  661. +{
  662. + struct ipq806x_gmac *gmac = priv;
  663. +
  664. + ipq806x_gmac_set_speed(gmac, speed);
  665. +}
  666. +
  667. +static int ipq806x_gmac_probe(struct platform_device *pdev)
  668. +{
  669. + struct plat_stmmacenet_data *plat_dat;
  670. + struct stmmac_resources stmmac_res;
  671. + struct device *dev = &pdev->dev;
  672. + struct ipq806x_gmac *gmac;
  673. + int val;
  674. + void *err;
  675. +
  676. + val = stmmac_get_platform_resources(pdev, &stmmac_res);
  677. + if (val)
  678. + return val;
  679. +
  680. + plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  681. + if (IS_ERR(plat_dat))
  682. + return PTR_ERR(plat_dat);
  683. +
  684. + gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL);
  685. + if (!gmac)
  686. + return -ENOMEM;
  687. +
  688. + gmac->pdev = pdev;
  689. +
  690. + err = ipq806x_gmac_of_parse(gmac);
  691. + if (IS_ERR(err)) {
  692. + dev_err(dev, "device tree parsing error\n");
  693. + return PTR_ERR(err);
  694. + }
  695. +
  696. + regmap_write(gmac->qsgmii_csr, QSGMII_PCS_CAL_LCKDT_CTL,
  697. + QSGMII_PCS_CAL_LCKDT_CTL_RST);
  698. +
  699. + /* Inter frame gap is set to 12 */
  700. + val = 12 << NSS_COMMON_GMAC_CTL_IFG_OFFSET |
  701. + 12 << NSS_COMMON_GMAC_CTL_IFG_LIMIT_OFFSET;
  702. + /* We also initiate an AXI low power exit request */
  703. + val |= NSS_COMMON_GMAC_CTL_CSYS_REQ;
  704. + switch (gmac->phy_mode) {
  705. + case PHY_INTERFACE_MODE_RGMII:
  706. + val |= NSS_COMMON_GMAC_CTL_PHY_IFACE_SEL;
  707. + break;
  708. + case PHY_INTERFACE_MODE_SGMII:
  709. + val &= ~NSS_COMMON_GMAC_CTL_PHY_IFACE_SEL;
  710. + break;
  711. + default:
  712. + dev_err(&pdev->dev, "Unsupported PHY mode: \"%s\"\n",
  713. + phy_modes(gmac->phy_mode));
  714. + return -EINVAL;
  715. + }
  716. + regmap_write(gmac->nss_common, NSS_COMMON_GMAC_CTL(gmac->id), val);
  717. +
  718. + /* Configure the clock src according to the mode */
  719. + regmap_read(gmac->nss_common, NSS_COMMON_CLK_SRC_CTRL, &val);
  720. + val &= ~(1 << NSS_COMMON_CLK_SRC_CTRL_OFFSET(gmac->id));
  721. + switch (gmac->phy_mode) {
  722. + case PHY_INTERFACE_MODE_RGMII:
  723. + val |= NSS_COMMON_CLK_SRC_CTRL_RGMII(gmac->id) <<
  724. + NSS_COMMON_CLK_SRC_CTRL_OFFSET(gmac->id);
  725. + break;
  726. + case PHY_INTERFACE_MODE_SGMII:
  727. + val |= NSS_COMMON_CLK_SRC_CTRL_SGMII(gmac->id) <<
  728. + NSS_COMMON_CLK_SRC_CTRL_OFFSET(gmac->id);
  729. + break;
  730. + default:
  731. + dev_err(&pdev->dev, "Unsupported PHY mode: \"%s\"\n",
  732. + phy_modes(gmac->phy_mode));
  733. + return -EINVAL;
  734. + }
  735. + regmap_write(gmac->nss_common, NSS_COMMON_CLK_SRC_CTRL, val);
  736. +
  737. + /* Enable PTP clock */
  738. + regmap_read(gmac->nss_common, NSS_COMMON_CLK_GATE, &val);
  739. + val |= NSS_COMMON_CLK_GATE_PTP_EN(gmac->id);
  740. + regmap_write(gmac->nss_common, NSS_COMMON_CLK_GATE, val);
  741. +
  742. + if (gmac->phy_mode == PHY_INTERFACE_MODE_SGMII) {
  743. + regmap_write(gmac->qsgmii_csr, QSGMII_PHY_SGMII_CTL(gmac->id),
  744. + QSGMII_PHY_CDR_EN |
  745. + QSGMII_PHY_RX_FRONT_EN |
  746. + QSGMII_PHY_RX_SIGNAL_DETECT_EN |
  747. + QSGMII_PHY_TX_DRIVER_EN |
  748. + QSGMII_PHY_QSGMII_EN |
  749. + 0x4 << QSGMII_PHY_PHASE_LOOP_GAIN_OFFSET |
  750. + 0x3 << QSGMII_PHY_RX_DC_BIAS_OFFSET |
  751. + 0x1 << QSGMII_PHY_RX_INPUT_EQU_OFFSET |
  752. + 0x2 << QSGMII_PHY_CDR_PI_SLEW_OFFSET |
  753. + 0xC << QSGMII_PHY_TX_DRV_AMP_OFFSET);
  754. + }
  755. +
  756. + plat_dat->has_gmac = true;
  757. + plat_dat->bsp_priv = gmac;
  758. + plat_dat->fix_mac_speed = ipq806x_gmac_fix_mac_speed;
  759. +
  760. + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  761. +}
  762. +
  763. +static const struct of_device_id ipq806x_gmac_dwmac_match[] = {
  764. + { .compatible = "qcom,ipq806x-gmac" },
  765. + { }
  766. +};
  767. +MODULE_DEVICE_TABLE(of, ipq806x_gmac_dwmac_match);
  768. +
  769. +static struct platform_driver ipq806x_gmac_dwmac_driver = {
  770. + .probe = ipq806x_gmac_probe,
  771. + .remove = stmmac_pltfr_remove,
  772. + .driver = {
  773. + .name = "ipq806x-gmac-dwmac",
  774. + .pm = &stmmac_pltfr_pm_ops,
  775. + .of_match_table = ipq806x_gmac_dwmac_match,
  776. + },
  777. +};
  778. +module_platform_driver(ipq806x_gmac_dwmac_driver);
  779. +
  780. +MODULE_AUTHOR("Mathieu Olivari <mathieu@codeaurora.org>");
  781. +MODULE_DESCRIPTION("Qualcomm Atheros IPQ806x DWMAC specific glue layer");
  782. +MODULE_LICENSE("Dual BSD/GPL");
  783. --- /dev/null
  784. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
  785. @@ -0,0 +1,86 @@
  786. +/*
  787. + * DWMAC glue for NXP LPC18xx/LPC43xx Ethernet
  788. + *
  789. + * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
  790. + *
  791. + * This file is licensed under the terms of the GNU General Public
  792. + * License version 2. This program is licensed "as is" without any
  793. + * warranty of any kind, whether express or implied.
  794. + */
  795. +
  796. +#include <linux/mfd/syscon.h>
  797. +#include <linux/module.h>
  798. +#include <linux/of.h>
  799. +#include <linux/of_net.h>
  800. +#include <linux/phy.h>
  801. +#include <linux/platform_device.h>
  802. +#include <linux/regmap.h>
  803. +#include <linux/stmmac.h>
  804. +
  805. +#include "stmmac_platform.h"
  806. +
  807. +/* Register defines for CREG syscon */
  808. +#define LPC18XX_CREG_CREG6 0x12c
  809. +# define LPC18XX_CREG_CREG6_ETHMODE_MASK 0x7
  810. +# define LPC18XX_CREG_CREG6_ETHMODE_MII 0x0
  811. +# define LPC18XX_CREG_CREG6_ETHMODE_RMII 0x4
  812. +
  813. +static int lpc18xx_dwmac_probe(struct platform_device *pdev)
  814. +{
  815. + struct plat_stmmacenet_data *plat_dat;
  816. + struct stmmac_resources stmmac_res;
  817. + struct regmap *reg;
  818. + u8 ethmode;
  819. + int ret;
  820. +
  821. + ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  822. + if (ret)
  823. + return ret;
  824. +
  825. + plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  826. + if (IS_ERR(plat_dat))
  827. + return PTR_ERR(plat_dat);
  828. +
  829. + plat_dat->has_gmac = true;
  830. +
  831. + reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
  832. + if (IS_ERR(reg)) {
  833. + dev_err(&pdev->dev, "syscon lookup failed\n");
  834. + return PTR_ERR(reg);
  835. + }
  836. +
  837. + if (plat_dat->interface == PHY_INTERFACE_MODE_MII) {
  838. + ethmode = LPC18XX_CREG_CREG6_ETHMODE_MII;
  839. + } else if (plat_dat->interface == PHY_INTERFACE_MODE_RMII) {
  840. + ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII;
  841. + } else {
  842. + dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
  843. + return -EINVAL;
  844. + }
  845. +
  846. + regmap_update_bits(reg, LPC18XX_CREG_CREG6,
  847. + LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
  848. +
  849. + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  850. +}
  851. +
  852. +static const struct of_device_id lpc18xx_dwmac_match[] = {
  853. + { .compatible = "nxp,lpc1850-dwmac" },
  854. + { }
  855. +};
  856. +MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
  857. +
  858. +static struct platform_driver lpc18xx_dwmac_driver = {
  859. + .probe = lpc18xx_dwmac_probe,
  860. + .remove = stmmac_pltfr_remove,
  861. + .driver = {
  862. + .name = "lpc18xx-dwmac",
  863. + .pm = &stmmac_pltfr_pm_ops,
  864. + .of_match_table = lpc18xx_dwmac_match,
  865. + },
  866. +};
  867. +module_platform_driver(lpc18xx_dwmac_driver);
  868. +
  869. +MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
  870. +MODULE_DESCRIPTION("DWMAC glue for LPC18xx/43xx Ethernet");
  871. +MODULE_LICENSE("GPL v2");
  872. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c
  873. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c
  874. @@ -15,9 +15,12 @@
  875. #include <linux/ethtool.h>
  876. #include <linux/io.h>
  877. #include <linux/ioport.h>
  878. +#include <linux/module.h>
  879. #include <linux/platform_device.h>
  880. #include <linux/stmmac.h>
  881. +#include "stmmac_platform.h"
  882. +
  883. #define ETHMAC_SPEED_100 BIT(1)
  884. struct meson_dwmac {
  885. @@ -44,24 +47,54 @@ static void meson6_dwmac_fix_mac_speed(v
  886. writel(val, dwmac->reg);
  887. }
  888. -static void *meson6_dwmac_setup(struct platform_device *pdev)
  889. +static int meson6_dwmac_probe(struct platform_device *pdev)
  890. {
  891. + struct plat_stmmacenet_data *plat_dat;
  892. + struct stmmac_resources stmmac_res;
  893. struct meson_dwmac *dwmac;
  894. struct resource *res;
  895. + int ret;
  896. +
  897. + ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  898. + if (ret)
  899. + return ret;
  900. +
  901. + plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  902. + if (IS_ERR(plat_dat))
  903. + return PTR_ERR(plat_dat);
  904. dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
  905. if (!dwmac)
  906. - return ERR_PTR(-ENOMEM);
  907. + return -ENOMEM;
  908. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  909. dwmac->reg = devm_ioremap_resource(&pdev->dev, res);
  910. if (IS_ERR(dwmac->reg))
  911. - return dwmac->reg;
  912. + return PTR_ERR(dwmac->reg);
  913. +
  914. + plat_dat->bsp_priv = dwmac;
  915. + plat_dat->fix_mac_speed = meson6_dwmac_fix_mac_speed;
  916. - return dwmac;
  917. + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  918. }
  919. -const struct stmmac_of_data meson6_dwmac_data = {
  920. - .setup = meson6_dwmac_setup,
  921. - .fix_mac_speed = meson6_dwmac_fix_mac_speed,
  922. +static const struct of_device_id meson6_dwmac_match[] = {
  923. + { .compatible = "amlogic,meson6-dwmac" },
  924. + { }
  925. };
  926. +MODULE_DEVICE_TABLE(of, meson6_dwmac_match);
  927. +
  928. +static struct platform_driver meson6_dwmac_driver = {
  929. + .probe = meson6_dwmac_probe,
  930. + .remove = stmmac_pltfr_remove,
  931. + .driver = {
  932. + .name = "meson6-dwmac",
  933. + .pm = &stmmac_pltfr_pm_ops,
  934. + .of_match_table = meson6_dwmac_match,
  935. + },
  936. +};
  937. +module_platform_driver(meson6_dwmac_driver);
  938. +
  939. +MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
  940. +MODULE_DESCRIPTION("Amlogic Meson DWMAC glue layer");
  941. +MODULE_LICENSE("GPL v2");
  942. --- /dev/null
  943. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
  944. @@ -0,0 +1,626 @@
  945. +/**
  946. + * dwmac-rk.c - Rockchip RK3288 DWMAC specific glue layer
  947. + *
  948. + * Copyright (C) 2014 Chen-Zhi (Roger Chen)
  949. + *
  950. + * Chen-Zhi (Roger Chen) <roger.chen@rock-chips.com>
  951. + *
  952. + * This program is free software; you can redistribute it and/or modify
  953. + * it under the terms of the GNU General Public License as published by
  954. + * the Free Software Foundation; either version 2 of the License, or
  955. + * (at your option) any later version.
  956. + *
  957. + * This program is distributed in the hope that it will be useful,
  958. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  959. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  960. + * GNU General Public License for more details.
  961. + */
  962. +
  963. +#include <linux/stmmac.h>
  964. +#include <linux/bitops.h>
  965. +#include <linux/clk.h>
  966. +#include <linux/phy.h>
  967. +#include <linux/of_net.h>
  968. +#include <linux/gpio.h>
  969. +#include <linux/module.h>
  970. +#include <linux/of_gpio.h>
  971. +#include <linux/of_device.h>
  972. +#include <linux/platform_device.h>
  973. +#include <linux/regulator/consumer.h>
  974. +#include <linux/delay.h>
  975. +#include <linux/mfd/syscon.h>
  976. +#include <linux/regmap.h>
  977. +
  978. +#include "stmmac_platform.h"
  979. +
  980. +struct rk_priv_data;
  981. +struct rk_gmac_ops {
  982. + void (*set_to_rgmii)(struct rk_priv_data *bsp_priv,
  983. + int tx_delay, int rx_delay);
  984. + void (*set_to_rmii)(struct rk_priv_data *bsp_priv);
  985. + void (*set_rgmii_speed)(struct rk_priv_data *bsp_priv, int speed);
  986. + void (*set_rmii_speed)(struct rk_priv_data *bsp_priv, int speed);
  987. +};
  988. +
  989. +struct rk_priv_data {
  990. + struct platform_device *pdev;
  991. + int phy_iface;
  992. + struct regulator *regulator;
  993. + const struct rk_gmac_ops *ops;
  994. +
  995. + bool clk_enabled;
  996. + bool clock_input;
  997. +
  998. + struct clk *clk_mac;
  999. + struct clk *gmac_clkin;
  1000. + struct clk *mac_clk_rx;
  1001. + struct clk *mac_clk_tx;
  1002. + struct clk *clk_mac_ref;
  1003. + struct clk *clk_mac_refout;
  1004. + struct clk *aclk_mac;
  1005. + struct clk *pclk_mac;
  1006. +
  1007. + int tx_delay;
  1008. + int rx_delay;
  1009. +
  1010. + struct regmap *grf;
  1011. +};
  1012. +
  1013. +#define HIWORD_UPDATE(val, mask, shift) \
  1014. + ((val) << (shift) | (mask) << ((shift) + 16))
  1015. +
  1016. +#define GRF_BIT(nr) (BIT(nr) | BIT(nr+16))
  1017. +#define GRF_CLR_BIT(nr) (BIT(nr+16))
  1018. +
  1019. +#define RK3288_GRF_SOC_CON1 0x0248
  1020. +#define RK3288_GRF_SOC_CON3 0x0250
  1021. +
  1022. +/*RK3288_GRF_SOC_CON1*/
  1023. +#define RK3288_GMAC_PHY_INTF_SEL_RGMII (GRF_BIT(6) | GRF_CLR_BIT(7) | \
  1024. + GRF_CLR_BIT(8))
  1025. +#define RK3288_GMAC_PHY_INTF_SEL_RMII (GRF_CLR_BIT(6) | GRF_CLR_BIT(7) | \
  1026. + GRF_BIT(8))
  1027. +#define RK3288_GMAC_FLOW_CTRL GRF_BIT(9)
  1028. +#define RK3288_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(9)
  1029. +#define RK3288_GMAC_SPEED_10M GRF_CLR_BIT(10)
  1030. +#define RK3288_GMAC_SPEED_100M GRF_BIT(10)
  1031. +#define RK3288_GMAC_RMII_CLK_25M GRF_BIT(11)
  1032. +#define RK3288_GMAC_RMII_CLK_2_5M GRF_CLR_BIT(11)
  1033. +#define RK3288_GMAC_CLK_125M (GRF_CLR_BIT(12) | GRF_CLR_BIT(13))
  1034. +#define RK3288_GMAC_CLK_25M (GRF_BIT(12) | GRF_BIT(13))
  1035. +#define RK3288_GMAC_CLK_2_5M (GRF_CLR_BIT(12) | GRF_BIT(13))
  1036. +#define RK3288_GMAC_RMII_MODE GRF_BIT(14)
  1037. +#define RK3288_GMAC_RMII_MODE_CLR GRF_CLR_BIT(14)
  1038. +
  1039. +/*RK3288_GRF_SOC_CON3*/
  1040. +#define RK3288_GMAC_TXCLK_DLY_ENABLE GRF_BIT(14)
  1041. +#define RK3288_GMAC_TXCLK_DLY_DISABLE GRF_CLR_BIT(14)
  1042. +#define RK3288_GMAC_RXCLK_DLY_ENABLE GRF_BIT(15)
  1043. +#define RK3288_GMAC_RXCLK_DLY_DISABLE GRF_CLR_BIT(15)
  1044. +#define RK3288_GMAC_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 7)
  1045. +#define RK3288_GMAC_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 0)
  1046. +
  1047. +static void rk3288_set_to_rgmii(struct rk_priv_data *bsp_priv,
  1048. + int tx_delay, int rx_delay)
  1049. +{
  1050. + struct device *dev = &bsp_priv->pdev->dev;
  1051. +
  1052. + if (IS_ERR(bsp_priv->grf)) {
  1053. + dev_err(dev, "Missing rockchip,grf property\n");
  1054. + return;
  1055. + }
  1056. +
  1057. + regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  1058. + RK3288_GMAC_PHY_INTF_SEL_RGMII |
  1059. + RK3288_GMAC_RMII_MODE_CLR);
  1060. + regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON3,
  1061. + RK3288_GMAC_RXCLK_DLY_ENABLE |
  1062. + RK3288_GMAC_TXCLK_DLY_ENABLE |
  1063. + RK3288_GMAC_CLK_RX_DL_CFG(rx_delay) |
  1064. + RK3288_GMAC_CLK_TX_DL_CFG(tx_delay));
  1065. +}
  1066. +
  1067. +static void rk3288_set_to_rmii(struct rk_priv_data *bsp_priv)
  1068. +{
  1069. + struct device *dev = &bsp_priv->pdev->dev;
  1070. +
  1071. + if (IS_ERR(bsp_priv->grf)) {
  1072. + dev_err(dev, "Missing rockchip,grf property\n");
  1073. + return;
  1074. + }
  1075. +
  1076. + regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  1077. + RK3288_GMAC_PHY_INTF_SEL_RMII | RK3288_GMAC_RMII_MODE);
  1078. +}
  1079. +
  1080. +static void rk3288_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed)
  1081. +{
  1082. + struct device *dev = &bsp_priv->pdev->dev;
  1083. +
  1084. + if (IS_ERR(bsp_priv->grf)) {
  1085. + dev_err(dev, "Missing rockchip,grf property\n");
  1086. + return;
  1087. + }
  1088. +
  1089. + if (speed == 10)
  1090. + regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  1091. + RK3288_GMAC_CLK_2_5M);
  1092. + else if (speed == 100)
  1093. + regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  1094. + RK3288_GMAC_CLK_25M);
  1095. + else if (speed == 1000)
  1096. + regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  1097. + RK3288_GMAC_CLK_125M);
  1098. + else
  1099. + dev_err(dev, "unknown speed value for RGMII! speed=%d", speed);
  1100. +}
  1101. +
  1102. +static void rk3288_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed)
  1103. +{
  1104. + struct device *dev = &bsp_priv->pdev->dev;
  1105. +
  1106. + if (IS_ERR(bsp_priv->grf)) {
  1107. + dev_err(dev, "Missing rockchip,grf property\n");
  1108. + return;
  1109. + }
  1110. +
  1111. + if (speed == 10) {
  1112. + regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  1113. + RK3288_GMAC_RMII_CLK_2_5M |
  1114. + RK3288_GMAC_SPEED_10M);
  1115. + } else if (speed == 100) {
  1116. + regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1,
  1117. + RK3288_GMAC_RMII_CLK_25M |
  1118. + RK3288_GMAC_SPEED_100M);
  1119. + } else {
  1120. + dev_err(dev, "unknown speed value for RMII! speed=%d", speed);
  1121. + }
  1122. +}
  1123. +
  1124. +static const struct rk_gmac_ops rk3288_ops = {
  1125. + .set_to_rgmii = rk3288_set_to_rgmii,
  1126. + .set_to_rmii = rk3288_set_to_rmii,
  1127. + .set_rgmii_speed = rk3288_set_rgmii_speed,
  1128. + .set_rmii_speed = rk3288_set_rmii_speed,
  1129. +};
  1130. +
  1131. +#define RK3368_GRF_SOC_CON15 0x043c
  1132. +#define RK3368_GRF_SOC_CON16 0x0440
  1133. +
  1134. +/* RK3368_GRF_SOC_CON15 */
  1135. +#define RK3368_GMAC_PHY_INTF_SEL_RGMII (GRF_BIT(9) | GRF_CLR_BIT(10) | \
  1136. + GRF_CLR_BIT(11))
  1137. +#define RK3368_GMAC_PHY_INTF_SEL_RMII (GRF_CLR_BIT(9) | GRF_CLR_BIT(10) | \
  1138. + GRF_BIT(11))
  1139. +#define RK3368_GMAC_FLOW_CTRL GRF_BIT(8)
  1140. +#define RK3368_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(8)
  1141. +#define RK3368_GMAC_SPEED_10M GRF_CLR_BIT(7)
  1142. +#define RK3368_GMAC_SPEED_100M GRF_BIT(7)
  1143. +#define RK3368_GMAC_RMII_CLK_25M GRF_BIT(3)
  1144. +#define RK3368_GMAC_RMII_CLK_2_5M GRF_CLR_BIT(3)
  1145. +#define RK3368_GMAC_CLK_125M (GRF_CLR_BIT(4) | GRF_CLR_BIT(5))
  1146. +#define RK3368_GMAC_CLK_25M (GRF_BIT(4) | GRF_BIT(5))
  1147. +#define RK3368_GMAC_CLK_2_5M (GRF_CLR_BIT(4) | GRF_BIT(5))
  1148. +#define RK3368_GMAC_RMII_MODE GRF_BIT(6)
  1149. +#define RK3368_GMAC_RMII_MODE_CLR GRF_CLR_BIT(6)
  1150. +
  1151. +/* RK3368_GRF_SOC_CON16 */
  1152. +#define RK3368_GMAC_TXCLK_DLY_ENABLE GRF_BIT(7)
  1153. +#define RK3368_GMAC_TXCLK_DLY_DISABLE GRF_CLR_BIT(7)
  1154. +#define RK3368_GMAC_RXCLK_DLY_ENABLE GRF_BIT(15)
  1155. +#define RK3368_GMAC_RXCLK_DLY_DISABLE GRF_CLR_BIT(15)
  1156. +#define RK3368_GMAC_CLK_RX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 8)
  1157. +#define RK3368_GMAC_CLK_TX_DL_CFG(val) HIWORD_UPDATE(val, 0x7F, 0)
  1158. +
  1159. +static void rk3368_set_to_rgmii(struct rk_priv_data *bsp_priv,
  1160. + int tx_delay, int rx_delay)
  1161. +{
  1162. + struct device *dev = &bsp_priv->pdev->dev;
  1163. +
  1164. + if (IS_ERR(bsp_priv->grf)) {
  1165. + dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  1166. + return;
  1167. + }
  1168. +
  1169. + regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  1170. + RK3368_GMAC_PHY_INTF_SEL_RGMII |
  1171. + RK3368_GMAC_RMII_MODE_CLR);
  1172. + regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON16,
  1173. + RK3368_GMAC_RXCLK_DLY_ENABLE |
  1174. + RK3368_GMAC_TXCLK_DLY_ENABLE |
  1175. + RK3368_GMAC_CLK_RX_DL_CFG(rx_delay) |
  1176. + RK3368_GMAC_CLK_TX_DL_CFG(tx_delay));
  1177. +}
  1178. +
  1179. +static void rk3368_set_to_rmii(struct rk_priv_data *bsp_priv)
  1180. +{
  1181. + struct device *dev = &bsp_priv->pdev->dev;
  1182. +
  1183. + if (IS_ERR(bsp_priv->grf)) {
  1184. + dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  1185. + return;
  1186. + }
  1187. +
  1188. + regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  1189. + RK3368_GMAC_PHY_INTF_SEL_RMII | RK3368_GMAC_RMII_MODE);
  1190. +}
  1191. +
  1192. +static void rk3368_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed)
  1193. +{
  1194. + struct device *dev = &bsp_priv->pdev->dev;
  1195. +
  1196. + if (IS_ERR(bsp_priv->grf)) {
  1197. + dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  1198. + return;
  1199. + }
  1200. +
  1201. + if (speed == 10)
  1202. + regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  1203. + RK3368_GMAC_CLK_2_5M);
  1204. + else if (speed == 100)
  1205. + regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  1206. + RK3368_GMAC_CLK_25M);
  1207. + else if (speed == 1000)
  1208. + regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  1209. + RK3368_GMAC_CLK_125M);
  1210. + else
  1211. + dev_err(dev, "unknown speed value for RGMII! speed=%d", speed);
  1212. +}
  1213. +
  1214. +static void rk3368_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed)
  1215. +{
  1216. + struct device *dev = &bsp_priv->pdev->dev;
  1217. +
  1218. + if (IS_ERR(bsp_priv->grf)) {
  1219. + dev_err(dev, "%s: Missing rockchip,grf property\n", __func__);
  1220. + return;
  1221. + }
  1222. +
  1223. + if (speed == 10) {
  1224. + regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  1225. + RK3368_GMAC_RMII_CLK_2_5M |
  1226. + RK3368_GMAC_SPEED_10M);
  1227. + } else if (speed == 100) {
  1228. + regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15,
  1229. + RK3368_GMAC_RMII_CLK_25M |
  1230. + RK3368_GMAC_SPEED_100M);
  1231. + } else {
  1232. + dev_err(dev, "unknown speed value for RMII! speed=%d", speed);
  1233. + }
  1234. +}
  1235. +
  1236. +static const struct rk_gmac_ops rk3368_ops = {
  1237. + .set_to_rgmii = rk3368_set_to_rgmii,
  1238. + .set_to_rmii = rk3368_set_to_rmii,
  1239. + .set_rgmii_speed = rk3368_set_rgmii_speed,
  1240. + .set_rmii_speed = rk3368_set_rmii_speed,
  1241. +};
  1242. +
  1243. +static int gmac_clk_init(struct rk_priv_data *bsp_priv)
  1244. +{
  1245. + struct device *dev = &bsp_priv->pdev->dev;
  1246. +
  1247. + bsp_priv->clk_enabled = false;
  1248. +
  1249. + bsp_priv->mac_clk_rx = devm_clk_get(dev, "mac_clk_rx");
  1250. + if (IS_ERR(bsp_priv->mac_clk_rx))
  1251. + dev_err(dev, "cannot get clock %s\n",
  1252. + "mac_clk_rx");
  1253. +
  1254. + bsp_priv->mac_clk_tx = devm_clk_get(dev, "mac_clk_tx");
  1255. + if (IS_ERR(bsp_priv->mac_clk_tx))
  1256. + dev_err(dev, "cannot get clock %s\n",
  1257. + "mac_clk_tx");
  1258. +
  1259. + bsp_priv->aclk_mac = devm_clk_get(dev, "aclk_mac");
  1260. + if (IS_ERR(bsp_priv->aclk_mac))
  1261. + dev_err(dev, "cannot get clock %s\n",
  1262. + "aclk_mac");
  1263. +
  1264. + bsp_priv->pclk_mac = devm_clk_get(dev, "pclk_mac");
  1265. + if (IS_ERR(bsp_priv->pclk_mac))
  1266. + dev_err(dev, "cannot get clock %s\n",
  1267. + "pclk_mac");
  1268. +
  1269. + bsp_priv->clk_mac = devm_clk_get(dev, "stmmaceth");
  1270. + if (IS_ERR(bsp_priv->clk_mac))
  1271. + dev_err(dev, "cannot get clock %s\n",
  1272. + "stmmaceth");
  1273. +
  1274. + if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) {
  1275. + bsp_priv->clk_mac_ref = devm_clk_get(dev, "clk_mac_ref");
  1276. + if (IS_ERR(bsp_priv->clk_mac_ref))
  1277. + dev_err(dev, "cannot get clock %s\n",
  1278. + "clk_mac_ref");
  1279. +
  1280. + if (!bsp_priv->clock_input) {
  1281. + bsp_priv->clk_mac_refout =
  1282. + devm_clk_get(dev, "clk_mac_refout");
  1283. + if (IS_ERR(bsp_priv->clk_mac_refout))
  1284. + dev_err(dev, "cannot get clock %s\n",
  1285. + "clk_mac_refout");
  1286. + }
  1287. + }
  1288. +
  1289. + if (bsp_priv->clock_input) {
  1290. + dev_info(dev, "clock input from PHY\n");
  1291. + } else {
  1292. + if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII)
  1293. + clk_set_rate(bsp_priv->clk_mac, 50000000);
  1294. + }
  1295. +
  1296. + return 0;
  1297. +}
  1298. +
  1299. +static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable)
  1300. +{
  1301. + int phy_iface = phy_iface = bsp_priv->phy_iface;
  1302. +
  1303. + if (enable) {
  1304. + if (!bsp_priv->clk_enabled) {
  1305. + if (phy_iface == PHY_INTERFACE_MODE_RMII) {
  1306. + if (!IS_ERR(bsp_priv->mac_clk_rx))
  1307. + clk_prepare_enable(
  1308. + bsp_priv->mac_clk_rx);
  1309. +
  1310. + if (!IS_ERR(bsp_priv->clk_mac_ref))
  1311. + clk_prepare_enable(
  1312. + bsp_priv->clk_mac_ref);
  1313. +
  1314. + if (!IS_ERR(bsp_priv->clk_mac_refout))
  1315. + clk_prepare_enable(
  1316. + bsp_priv->clk_mac_refout);
  1317. + }
  1318. +
  1319. + if (!IS_ERR(bsp_priv->aclk_mac))
  1320. + clk_prepare_enable(bsp_priv->aclk_mac);
  1321. +
  1322. + if (!IS_ERR(bsp_priv->pclk_mac))
  1323. + clk_prepare_enable(bsp_priv->pclk_mac);
  1324. +
  1325. + if (!IS_ERR(bsp_priv->mac_clk_tx))
  1326. + clk_prepare_enable(bsp_priv->mac_clk_tx);
  1327. +
  1328. + /**
  1329. + * if (!IS_ERR(bsp_priv->clk_mac))
  1330. + * clk_prepare_enable(bsp_priv->clk_mac);
  1331. + */
  1332. + mdelay(5);
  1333. + bsp_priv->clk_enabled = true;
  1334. + }
  1335. + } else {
  1336. + if (bsp_priv->clk_enabled) {
  1337. + if (phy_iface == PHY_INTERFACE_MODE_RMII) {
  1338. + if (!IS_ERR(bsp_priv->mac_clk_rx))
  1339. + clk_disable_unprepare(
  1340. + bsp_priv->mac_clk_rx);
  1341. +
  1342. + if (!IS_ERR(bsp_priv->clk_mac_ref))
  1343. + clk_disable_unprepare(
  1344. + bsp_priv->clk_mac_ref);
  1345. +
  1346. + if (!IS_ERR(bsp_priv->clk_mac_refout))
  1347. + clk_disable_unprepare(
  1348. + bsp_priv->clk_mac_refout);
  1349. + }
  1350. +
  1351. + if (!IS_ERR(bsp_priv->aclk_mac))
  1352. + clk_disable_unprepare(bsp_priv->aclk_mac);
  1353. +
  1354. + if (!IS_ERR(bsp_priv->pclk_mac))
  1355. + clk_disable_unprepare(bsp_priv->pclk_mac);
  1356. +
  1357. + if (!IS_ERR(bsp_priv->mac_clk_tx))
  1358. + clk_disable_unprepare(bsp_priv->mac_clk_tx);
  1359. + /**
  1360. + * if (!IS_ERR(bsp_priv->clk_mac))
  1361. + * clk_disable_unprepare(bsp_priv->clk_mac);
  1362. + */
  1363. + bsp_priv->clk_enabled = false;
  1364. + }
  1365. + }
  1366. +
  1367. + return 0;
  1368. +}
  1369. +
  1370. +static int phy_power_on(struct rk_priv_data *bsp_priv, bool enable)
  1371. +{
  1372. + struct regulator *ldo = bsp_priv->regulator;
  1373. + int ret;
  1374. + struct device *dev = &bsp_priv->pdev->dev;
  1375. +
  1376. + if (!ldo) {
  1377. + dev_err(dev, "no regulator found\n");
  1378. + return -1;
  1379. + }
  1380. +
  1381. + if (enable) {
  1382. + ret = regulator_enable(ldo);
  1383. + if (ret)
  1384. + dev_err(dev, "fail to enable phy-supply\n");
  1385. + } else {
  1386. + ret = regulator_disable(ldo);
  1387. + if (ret)
  1388. + dev_err(dev, "fail to disable phy-supply\n");
  1389. + }
  1390. +
  1391. + return 0;
  1392. +}
  1393. +
  1394. +static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev,
  1395. + const struct rk_gmac_ops *ops)
  1396. +{
  1397. + struct rk_priv_data *bsp_priv;
  1398. + struct device *dev = &pdev->dev;
  1399. + int ret;
  1400. + const char *strings = NULL;
  1401. + int value;
  1402. +
  1403. + bsp_priv = devm_kzalloc(dev, sizeof(*bsp_priv), GFP_KERNEL);
  1404. + if (!bsp_priv)
  1405. + return ERR_PTR(-ENOMEM);
  1406. +
  1407. + bsp_priv->phy_iface = of_get_phy_mode(dev->of_node);
  1408. + bsp_priv->ops = ops;
  1409. +
  1410. + bsp_priv->regulator = devm_regulator_get_optional(dev, "phy");
  1411. + if (IS_ERR(bsp_priv->regulator)) {
  1412. + if (PTR_ERR(bsp_priv->regulator) == -EPROBE_DEFER) {
  1413. + dev_err(dev, "phy regulator is not available yet, deferred probing\n");
  1414. + return ERR_PTR(-EPROBE_DEFER);
  1415. + }
  1416. + dev_err(dev, "no regulator found\n");
  1417. + bsp_priv->regulator = NULL;
  1418. + }
  1419. +
  1420. + ret = of_property_read_string(dev->of_node, "clock_in_out", &strings);
  1421. + if (ret) {
  1422. + dev_err(dev, "Can not read property: clock_in_out.\n");
  1423. + bsp_priv->clock_input = true;
  1424. + } else {
  1425. + dev_info(dev, "clock input or output? (%s).\n",
  1426. + strings);
  1427. + if (!strcmp(strings, "input"))
  1428. + bsp_priv->clock_input = true;
  1429. + else
  1430. + bsp_priv->clock_input = false;
  1431. + }
  1432. +
  1433. + ret = of_property_read_u32(dev->of_node, "tx_delay", &value);
  1434. + if (ret) {
  1435. + bsp_priv->tx_delay = 0x30;
  1436. + dev_err(dev, "Can not read property: tx_delay.");
  1437. + dev_err(dev, "set tx_delay to 0x%x\n",
  1438. + bsp_priv->tx_delay);
  1439. + } else {
  1440. + dev_info(dev, "TX delay(0x%x).\n", value);
  1441. + bsp_priv->tx_delay = value;
  1442. + }
  1443. +
  1444. + ret = of_property_read_u32(dev->of_node, "rx_delay", &value);
  1445. + if (ret) {
  1446. + bsp_priv->rx_delay = 0x10;
  1447. + dev_err(dev, "Can not read property: rx_delay.");
  1448. + dev_err(dev, "set rx_delay to 0x%x\n",
  1449. + bsp_priv->rx_delay);
  1450. + } else {
  1451. + dev_info(dev, "RX delay(0x%x).\n", value);
  1452. + bsp_priv->rx_delay = value;
  1453. + }
  1454. +
  1455. + bsp_priv->grf = syscon_regmap_lookup_by_phandle(dev->of_node,
  1456. + "rockchip,grf");
  1457. + bsp_priv->pdev = pdev;
  1458. +
  1459. + /*rmii or rgmii*/
  1460. + if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RGMII) {
  1461. + dev_info(dev, "init for RGMII\n");
  1462. + bsp_priv->ops->set_to_rgmii(bsp_priv, bsp_priv->tx_delay,
  1463. + bsp_priv->rx_delay);
  1464. + } else if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) {
  1465. + dev_info(dev, "init for RMII\n");
  1466. + bsp_priv->ops->set_to_rmii(bsp_priv);
  1467. + } else {
  1468. + dev_err(dev, "NO interface defined!\n");
  1469. + }
  1470. +
  1471. + gmac_clk_init(bsp_priv);
  1472. +
  1473. + return bsp_priv;
  1474. +}
  1475. +
  1476. +static int rk_gmac_init(struct platform_device *pdev, void *priv)
  1477. +{
  1478. + struct rk_priv_data *bsp_priv = priv;
  1479. + int ret;
  1480. +
  1481. + ret = phy_power_on(bsp_priv, true);
  1482. + if (ret)
  1483. + return ret;
  1484. +
  1485. + ret = gmac_clk_enable(bsp_priv, true);
  1486. + if (ret)
  1487. + return ret;
  1488. +
  1489. + return 0;
  1490. +}
  1491. +
  1492. +static void rk_gmac_exit(struct platform_device *pdev, void *priv)
  1493. +{
  1494. + struct rk_priv_data *gmac = priv;
  1495. +
  1496. + phy_power_on(gmac, false);
  1497. + gmac_clk_enable(gmac, false);
  1498. +}
  1499. +
  1500. +static void rk_fix_speed(void *priv, unsigned int speed)
  1501. +{
  1502. + struct rk_priv_data *bsp_priv = priv;
  1503. + struct device *dev = &bsp_priv->pdev->dev;
  1504. +
  1505. + if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RGMII)
  1506. + bsp_priv->ops->set_rgmii_speed(bsp_priv, speed);
  1507. + else if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII)
  1508. + bsp_priv->ops->set_rmii_speed(bsp_priv, speed);
  1509. + else
  1510. + dev_err(dev, "unsupported interface %d", bsp_priv->phy_iface);
  1511. +}
  1512. +
  1513. +static int rk_gmac_probe(struct platform_device *pdev)
  1514. +{
  1515. + struct plat_stmmacenet_data *plat_dat;
  1516. + struct stmmac_resources stmmac_res;
  1517. + const struct rk_gmac_ops *data;
  1518. + int ret;
  1519. +
  1520. + data = of_device_get_match_data(&pdev->dev);
  1521. + if (!data) {
  1522. + dev_err(&pdev->dev, "no of match data provided\n");
  1523. + return -EINVAL;
  1524. + }
  1525. +
  1526. + ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  1527. + if (ret)
  1528. + return ret;
  1529. +
  1530. + plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1531. + if (IS_ERR(plat_dat))
  1532. + return PTR_ERR(plat_dat);
  1533. +
  1534. + plat_dat->has_gmac = true;
  1535. + plat_dat->init = rk_gmac_init;
  1536. + plat_dat->exit = rk_gmac_exit;
  1537. + plat_dat->fix_mac_speed = rk_fix_speed;
  1538. +
  1539. + plat_dat->bsp_priv = rk_gmac_setup(pdev, data);
  1540. + if (IS_ERR(plat_dat->bsp_priv))
  1541. + return PTR_ERR(plat_dat->bsp_priv);
  1542. +
  1543. + ret = rk_gmac_init(pdev, plat_dat->bsp_priv);
  1544. + if (ret)
  1545. + return ret;
  1546. +
  1547. + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  1548. +}
  1549. +
  1550. +static const struct of_device_id rk_gmac_dwmac_match[] = {
  1551. + { .compatible = "rockchip,rk3288-gmac", .data = &rk3288_ops },
  1552. + { .compatible = "rockchip,rk3368-gmac", .data = &rk3368_ops },
  1553. + { }
  1554. +};
  1555. +MODULE_DEVICE_TABLE(of, rk_gmac_dwmac_match);
  1556. +
  1557. +static struct platform_driver rk_gmac_dwmac_driver = {
  1558. + .probe = rk_gmac_probe,
  1559. + .remove = stmmac_pltfr_remove,
  1560. + .driver = {
  1561. + .name = "rk_gmac-dwmac",
  1562. + .pm = &stmmac_pltfr_pm_ops,
  1563. + .of_match_table = rk_gmac_dwmac_match,
  1564. + },
  1565. +};
  1566. +module_platform_driver(rk_gmac_dwmac_driver);
  1567. +
  1568. +MODULE_AUTHOR("Chen-Zhi (Roger Chen) <roger.chen@rock-chips.com>");
  1569. +MODULE_DESCRIPTION("Rockchip RK3288 DWMAC specific glue layer");
  1570. +MODULE_LICENSE("GPL");
  1571. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
  1572. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
  1573. @@ -23,7 +23,9 @@
  1574. #include <linux/regmap.h>
  1575. #include <linux/reset.h>
  1576. #include <linux/stmmac.h>
  1577. +
  1578. #include "stmmac.h"
  1579. +#include "stmmac_platform.h"
  1580. #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII 0x0
  1581. #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII 0x1
  1582. @@ -89,7 +91,9 @@ static int socfpga_dwmac_parse_data(stru
  1583. STMMAC_RESOURCE_NAME);
  1584. if (IS_ERR(dwmac->stmmac_rst)) {
  1585. dev_info(dev, "Could not get reset control!\n");
  1586. - return -EINVAL;
  1587. + if (PTR_ERR(dwmac->stmmac_rst) == -EPROBE_DEFER)
  1588. + return -EPROBE_DEFER;
  1589. + dwmac->stmmac_rst = NULL;
  1590. }
  1591. dwmac->interface = of_get_phy_mode(np);
  1592. @@ -171,31 +175,6 @@ static int socfpga_dwmac_setup(struct so
  1593. return 0;
  1594. }
  1595. -static void *socfpga_dwmac_probe(struct platform_device *pdev)
  1596. -{
  1597. - struct device *dev = &pdev->dev;
  1598. - int ret;
  1599. - struct socfpga_dwmac *dwmac;
  1600. -
  1601. - dwmac = devm_kzalloc(dev, sizeof(*dwmac), GFP_KERNEL);
  1602. - if (!dwmac)
  1603. - return ERR_PTR(-ENOMEM);
  1604. -
  1605. - ret = socfpga_dwmac_parse_data(dwmac, dev);
  1606. - if (ret) {
  1607. - dev_err(dev, "Unable to parse OF data\n");
  1608. - return ERR_PTR(ret);
  1609. - }
  1610. -
  1611. - ret = socfpga_dwmac_setup(dwmac);
  1612. - if (ret) {
  1613. - dev_err(dev, "couldn't setup SoC glue (%d)\n", ret);
  1614. - return ERR_PTR(ret);
  1615. - }
  1616. -
  1617. - return dwmac;
  1618. -}
  1619. -
  1620. static void socfpga_dwmac_exit(struct platform_device *pdev, void *priv)
  1621. {
  1622. struct socfpga_dwmac *dwmac = priv;
  1623. @@ -253,9 +232,65 @@ static int socfpga_dwmac_init(struct pla
  1624. return ret;
  1625. }
  1626. -const struct stmmac_of_data socfpga_gmac_data = {
  1627. - .setup = socfpga_dwmac_probe,
  1628. - .init = socfpga_dwmac_init,
  1629. - .exit = socfpga_dwmac_exit,
  1630. - .fix_mac_speed = socfpga_dwmac_fix_mac_speed,
  1631. +static int socfpga_dwmac_probe(struct platform_device *pdev)
  1632. +{
  1633. + struct plat_stmmacenet_data *plat_dat;
  1634. + struct stmmac_resources stmmac_res;
  1635. + struct device *dev = &pdev->dev;
  1636. + int ret;
  1637. + struct socfpga_dwmac *dwmac;
  1638. +
  1639. + ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  1640. + if (ret)
  1641. + return ret;
  1642. +
  1643. + plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1644. + if (IS_ERR(plat_dat))
  1645. + return PTR_ERR(plat_dat);
  1646. +
  1647. + dwmac = devm_kzalloc(dev, sizeof(*dwmac), GFP_KERNEL);
  1648. + if (!dwmac)
  1649. + return -ENOMEM;
  1650. +
  1651. + ret = socfpga_dwmac_parse_data(dwmac, dev);
  1652. + if (ret) {
  1653. + dev_err(dev, "Unable to parse OF data\n");
  1654. + return ret;
  1655. + }
  1656. +
  1657. + ret = socfpga_dwmac_setup(dwmac);
  1658. + if (ret) {
  1659. + dev_err(dev, "couldn't setup SoC glue (%d)\n", ret);
  1660. + return ret;
  1661. + }
  1662. +
  1663. + plat_dat->bsp_priv = dwmac;
  1664. + plat_dat->init = socfpga_dwmac_init;
  1665. + plat_dat->exit = socfpga_dwmac_exit;
  1666. + plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed;
  1667. +
  1668. + ret = socfpga_dwmac_init(pdev, plat_dat->bsp_priv);
  1669. + if (ret)
  1670. + return ret;
  1671. +
  1672. + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  1673. +}
  1674. +
  1675. +static const struct of_device_id socfpga_dwmac_match[] = {
  1676. + { .compatible = "altr,socfpga-stmmac" },
  1677. + { }
  1678. };
  1679. +MODULE_DEVICE_TABLE(of, socfpga_dwmac_match);
  1680. +
  1681. +static struct platform_driver socfpga_dwmac_driver = {
  1682. + .probe = socfpga_dwmac_probe,
  1683. + .remove = stmmac_pltfr_remove,
  1684. + .driver = {
  1685. + .name = "socfpga-dwmac",
  1686. + .pm = &stmmac_pltfr_pm_ops,
  1687. + .of_match_table = socfpga_dwmac_match,
  1688. + },
  1689. +};
  1690. +module_platform_driver(socfpga_dwmac_driver);
  1691. +
  1692. +MODULE_LICENSE("GPL v2");
  1693. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
  1694. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
  1695. @@ -1,4 +1,4 @@
  1696. -/**
  1697. +/*
  1698. * dwmac-sti.c - STMicroelectronics DWMAC Specific Glue layer
  1699. *
  1700. * Copyright (C) 2003-2014 STMicroelectronics (R&D) Limited
  1701. @@ -17,11 +17,15 @@
  1702. #include <linux/stmmac.h>
  1703. #include <linux/phy.h>
  1704. #include <linux/mfd/syscon.h>
  1705. +#include <linux/module.h>
  1706. #include <linux/regmap.h>
  1707. #include <linux/clk.h>
  1708. #include <linux/of.h>
  1709. +#include <linux/of_device.h>
  1710. #include <linux/of_net.h>
  1711. +#include "stmmac_platform.h"
  1712. +
  1713. #define DWMAC_125MHZ 125000000
  1714. #define DWMAC_50MHZ 50000000
  1715. #define DWMAC_25MHZ 25000000
  1716. @@ -35,9 +39,8 @@
  1717. #define IS_PHY_IF_MODE_GBIT(iface) (IS_PHY_IF_MODE_RGMII(iface) || \
  1718. iface == PHY_INTERFACE_MODE_GMII)
  1719. -/* STiH4xx register definitions (STiH415/STiH416/STiH407/STiH410 families) */
  1720. -
  1721. -/**
  1722. +/* STiH4xx register definitions (STiH415/STiH416/STiH407/STiH410 families)
  1723. + *
  1724. * Below table summarizes the clock requirement and clock sources for
  1725. * supported phy interface modes with link speeds.
  1726. * ________________________________________________
  1727. @@ -76,9 +79,7 @@
  1728. #define STIH4XX_ETH_SEL_INTERNAL_NOTEXT_PHYCLK BIT(7)
  1729. #define STIH4XX_ETH_SEL_TXCLK_NOT_CLK125 BIT(6)
  1730. -/* STiD127 register definitions */
  1731. -
  1732. -/**
  1733. +/* STiD127 register definitions
  1734. *-----------------------
  1735. * src |BIT(6)| BIT(7)|
  1736. *-----------------------
  1737. @@ -104,13 +105,13 @@
  1738. #define EN_MASK GENMASK(1, 1)
  1739. #define EN BIT(1)
  1740. -/**
  1741. +/*
  1742. * 3 bits [4:2]
  1743. * 000-GMII/MII
  1744. * 001-RGMII
  1745. * 010-SGMII
  1746. * 100-RMII
  1747. -*/
  1748. + */
  1749. #define MII_PHY_SEL_MASK GENMASK(4, 2)
  1750. #define ETH_PHY_SEL_RMII BIT(4)
  1751. #define ETH_PHY_SEL_SGMII BIT(3)
  1752. @@ -123,11 +124,16 @@ struct sti_dwmac {
  1753. bool ext_phyclk; /* Clock from external PHY */
  1754. u32 tx_retime_src; /* TXCLK Retiming*/
  1755. struct clk *clk; /* PHY clock */
  1756. - int ctrl_reg; /* GMAC glue-logic control register */
  1757. + u32 ctrl_reg; /* GMAC glue-logic control register */
  1758. int clk_sel_reg; /* GMAC ext clk selection register */
  1759. struct device *dev;
  1760. struct regmap *regmap;
  1761. u32 speed;
  1762. + void (*fix_retime_src)(void *priv, unsigned int speed);
  1763. +};
  1764. +
  1765. +struct sti_dwmac_of_data {
  1766. + void (*fix_retime_src)(void *priv, unsigned int speed);
  1767. };
  1768. static u32 phy_intf_sels[] = {
  1769. @@ -222,8 +228,9 @@ static void stid127_fix_retime_src(void
  1770. regmap_update_bits(dwmac->regmap, reg, STID127_RETIME_SRC_MASK, val);
  1771. }
  1772. -static void sti_dwmac_ctrl_init(struct sti_dwmac *dwmac)
  1773. +static int sti_dwmac_init(struct platform_device *pdev, void *priv)
  1774. {
  1775. + struct sti_dwmac *dwmac = priv;
  1776. struct regmap *regmap = dwmac->regmap;
  1777. int iface = dwmac->interface;
  1778. struct device *dev = dwmac->dev;
  1779. @@ -241,28 +248,8 @@ static void sti_dwmac_ctrl_init(struct s
  1780. val = (iface == PHY_INTERFACE_MODE_REVMII) ? 0 : ENMII;
  1781. regmap_update_bits(regmap, reg, ENMII_MASK, val);
  1782. -}
  1783. -static int stix4xx_init(struct platform_device *pdev, void *priv)
  1784. -{
  1785. - struct sti_dwmac *dwmac = priv;
  1786. - u32 spd = dwmac->speed;
  1787. -
  1788. - sti_dwmac_ctrl_init(dwmac);
  1789. -
  1790. - stih4xx_fix_retime_src(priv, spd);
  1791. -
  1792. - return 0;
  1793. -}
  1794. -
  1795. -static int stid127_init(struct platform_device *pdev, void *priv)
  1796. -{
  1797. - struct sti_dwmac *dwmac = priv;
  1798. - u32 spd = dwmac->speed;
  1799. -
  1800. - sti_dwmac_ctrl_init(dwmac);
  1801. -
  1802. - stid127_fix_retime_src(priv, spd);
  1803. + dwmac->fix_retime_src(priv, dwmac->speed);
  1804. return 0;
  1805. }
  1806. @@ -286,11 +273,6 @@ static int sti_dwmac_parse_data(struct s
  1807. if (!np)
  1808. return -EINVAL;
  1809. - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sti-ethconf");
  1810. - if (!res)
  1811. - return -ENODATA;
  1812. - dwmac->ctrl_reg = res->start;
  1813. -
  1814. /* clk selection from extra syscfg register */
  1815. dwmac->clk_sel_reg = -ENXIO;
  1816. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sti-clkconf");
  1817. @@ -301,6 +283,12 @@ static int sti_dwmac_parse_data(struct s
  1818. if (IS_ERR(regmap))
  1819. return PTR_ERR(regmap);
  1820. + err = of_property_read_u32_index(np, "st,syscon", 1, &dwmac->ctrl_reg);
  1821. + if (err) {
  1822. + dev_err(dev, "Can't get sysconfig ctrl offset (%d)\n", err);
  1823. + return err;
  1824. + }
  1825. +
  1826. dwmac->dev = dev;
  1827. dwmac->interface = of_get_phy_mode(np);
  1828. dwmac->regmap = regmap;
  1829. @@ -310,16 +298,16 @@ static int sti_dwmac_parse_data(struct s
  1830. if (IS_PHY_IF_MODE_GBIT(dwmac->interface)) {
  1831. const char *rs;
  1832. - dwmac->tx_retime_src = TX_RETIME_SRC_CLKGEN;
  1833. err = of_property_read_string(np, "st,tx-retime-src", &rs);
  1834. - if (err < 0)
  1835. + if (err < 0) {
  1836. dev_warn(dev, "Use internal clock source\n");
  1837. -
  1838. - if (!strcasecmp(rs, "clk_125"))
  1839. + dwmac->tx_retime_src = TX_RETIME_SRC_CLKGEN;
  1840. + } else if (!strcasecmp(rs, "clk_125")) {
  1841. dwmac->tx_retime_src = TX_RETIME_SRC_CLK_125;
  1842. - else if (!strcasecmp(rs, "txclk"))
  1843. + } else if (!strcasecmp(rs, "txclk")) {
  1844. dwmac->tx_retime_src = TX_RETIME_SRC_TXCLK;
  1845. + }
  1846. dwmac->speed = SPEED_1000;
  1847. }
  1848. @@ -333,34 +321,80 @@ static int sti_dwmac_parse_data(struct s
  1849. return 0;
  1850. }
  1851. -static void *sti_dwmac_setup(struct platform_device *pdev)
  1852. +static int sti_dwmac_probe(struct platform_device *pdev)
  1853. {
  1854. + struct plat_stmmacenet_data *plat_dat;
  1855. + const struct sti_dwmac_of_data *data;
  1856. + struct stmmac_resources stmmac_res;
  1857. struct sti_dwmac *dwmac;
  1858. int ret;
  1859. + data = of_device_get_match_data(&pdev->dev);
  1860. + if (!data) {
  1861. + dev_err(&pdev->dev, "No OF match data provided\n");
  1862. + return -EINVAL;
  1863. + }
  1864. +
  1865. + ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  1866. + if (ret)
  1867. + return ret;
  1868. +
  1869. + plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  1870. + if (IS_ERR(plat_dat))
  1871. + return PTR_ERR(plat_dat);
  1872. +
  1873. dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
  1874. if (!dwmac)
  1875. - return ERR_PTR(-ENOMEM);
  1876. + return -ENOMEM;
  1877. ret = sti_dwmac_parse_data(dwmac, pdev);
  1878. if (ret) {
  1879. dev_err(&pdev->dev, "Unable to parse OF data\n");
  1880. - return ERR_PTR(ret);
  1881. + return ret;
  1882. }
  1883. - return dwmac;
  1884. + dwmac->fix_retime_src = data->fix_retime_src;
  1885. +
  1886. + plat_dat->bsp_priv = dwmac;
  1887. + plat_dat->init = sti_dwmac_init;
  1888. + plat_dat->exit = sti_dwmac_exit;
  1889. + plat_dat->fix_mac_speed = data->fix_retime_src;
  1890. +
  1891. + ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);
  1892. + if (ret)
  1893. + return ret;
  1894. +
  1895. + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  1896. }
  1897. -const struct stmmac_of_data stih4xx_dwmac_data = {
  1898. - .fix_mac_speed = stih4xx_fix_retime_src,
  1899. - .setup = sti_dwmac_setup,
  1900. - .init = stix4xx_init,
  1901. - .exit = sti_dwmac_exit,
  1902. +static const struct sti_dwmac_of_data stih4xx_dwmac_data = {
  1903. + .fix_retime_src = stih4xx_fix_retime_src,
  1904. };
  1905. -const struct stmmac_of_data stid127_dwmac_data = {
  1906. - .fix_mac_speed = stid127_fix_retime_src,
  1907. - .setup = sti_dwmac_setup,
  1908. - .init = stid127_init,
  1909. - .exit = sti_dwmac_exit,
  1910. +static const struct sti_dwmac_of_data stid127_dwmac_data = {
  1911. + .fix_retime_src = stid127_fix_retime_src,
  1912. };
  1913. +
  1914. +static const struct of_device_id sti_dwmac_match[] = {
  1915. + { .compatible = "st,stih415-dwmac", .data = &stih4xx_dwmac_data},
  1916. + { .compatible = "st,stih416-dwmac", .data = &stih4xx_dwmac_data},
  1917. + { .compatible = "st,stid127-dwmac", .data = &stid127_dwmac_data},
  1918. + { .compatible = "st,stih407-dwmac", .data = &stih4xx_dwmac_data},
  1919. + { }
  1920. +};
  1921. +MODULE_DEVICE_TABLE(of, sti_dwmac_match);
  1922. +
  1923. +static struct platform_driver sti_dwmac_driver = {
  1924. + .probe = sti_dwmac_probe,
  1925. + .remove = stmmac_pltfr_remove,
  1926. + .driver = {
  1927. + .name = "sti-dwmac",
  1928. + .pm = &stmmac_pltfr_pm_ops,
  1929. + .of_match_table = sti_dwmac_match,
  1930. + },
  1931. +};
  1932. +module_platform_driver(sti_dwmac_driver);
  1933. +
  1934. +MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@st.com>");
  1935. +MODULE_DESCRIPTION("STMicroelectronics DWMAC Specific Glue layer");
  1936. +MODULE_LICENSE("GPL");
  1937. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
  1938. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
  1939. @@ -1,4 +1,4 @@
  1940. -/**
  1941. +/*
  1942. * dwmac-sunxi.c - Allwinner sunxi DWMAC specific glue layer
  1943. *
  1944. * Copyright (C) 2013 Chen-Yu Tsai
  1945. @@ -18,10 +18,14 @@
  1946. #include <linux/stmmac.h>
  1947. #include <linux/clk.h>
  1948. +#include <linux/module.h>
  1949. #include <linux/phy.h>
  1950. +#include <linux/platform_device.h>
  1951. #include <linux/of_net.h>
  1952. #include <linux/regulator/consumer.h>
  1953. +#include "stmmac_platform.h"
  1954. +
  1955. struct sunxi_priv_data {
  1956. int interface;
  1957. int clk_enabled;
  1958. @@ -29,35 +33,6 @@ struct sunxi_priv_data {
  1959. struct regulator *regulator;
  1960. };
  1961. -static void *sun7i_gmac_setup(struct platform_device *pdev)
  1962. -{
  1963. - struct sunxi_priv_data *gmac;
  1964. - struct device *dev = &pdev->dev;
  1965. -
  1966. - gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL);
  1967. - if (!gmac)
  1968. - return ERR_PTR(-ENOMEM);
  1969. -
  1970. - gmac->interface = of_get_phy_mode(dev->of_node);
  1971. -
  1972. - gmac->tx_clk = devm_clk_get(dev, "allwinner_gmac_tx");
  1973. - if (IS_ERR(gmac->tx_clk)) {
  1974. - dev_err(dev, "could not get tx clock\n");
  1975. - return gmac->tx_clk;
  1976. - }
  1977. -
  1978. - /* Optional regulator for PHY */
  1979. - gmac->regulator = devm_regulator_get_optional(dev, "phy");
  1980. - if (IS_ERR(gmac->regulator)) {
  1981. - if (PTR_ERR(gmac->regulator) == -EPROBE_DEFER)
  1982. - return ERR_PTR(-EPROBE_DEFER);
  1983. - dev_info(dev, "no regulator found\n");
  1984. - gmac->regulator = NULL;
  1985. - }
  1986. -
  1987. - return gmac;
  1988. -}
  1989. -
  1990. #define SUN7I_GMAC_GMII_RGMII_RATE 125000000
  1991. #define SUN7I_GMAC_MII_RATE 25000000
  1992. @@ -128,13 +103,76 @@ static void sun7i_fix_speed(void *priv,
  1993. }
  1994. }
  1995. -/* of_data specifying hardware features and callbacks.
  1996. - * hardware features were copied from Allwinner drivers. */
  1997. -const struct stmmac_of_data sun7i_gmac_data = {
  1998. - .has_gmac = 1,
  1999. - .tx_coe = 1,
  2000. - .fix_mac_speed = sun7i_fix_speed,
  2001. - .setup = sun7i_gmac_setup,
  2002. - .init = sun7i_gmac_init,
  2003. - .exit = sun7i_gmac_exit,
  2004. +static int sun7i_gmac_probe(struct platform_device *pdev)
  2005. +{
  2006. + struct plat_stmmacenet_data *plat_dat;
  2007. + struct stmmac_resources stmmac_res;
  2008. + struct sunxi_priv_data *gmac;
  2009. + struct device *dev = &pdev->dev;
  2010. + int ret;
  2011. +
  2012. + ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  2013. + if (ret)
  2014. + return ret;
  2015. +
  2016. + plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  2017. + if (IS_ERR(plat_dat))
  2018. + return PTR_ERR(plat_dat);
  2019. +
  2020. + gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL);
  2021. + if (!gmac)
  2022. + return -ENOMEM;
  2023. +
  2024. + gmac->interface = of_get_phy_mode(dev->of_node);
  2025. +
  2026. + gmac->tx_clk = devm_clk_get(dev, "allwinner_gmac_tx");
  2027. + if (IS_ERR(gmac->tx_clk)) {
  2028. + dev_err(dev, "could not get tx clock\n");
  2029. + return PTR_ERR(gmac->tx_clk);
  2030. + }
  2031. +
  2032. + /* Optional regulator for PHY */
  2033. + gmac->regulator = devm_regulator_get_optional(dev, "phy");
  2034. + if (IS_ERR(gmac->regulator)) {
  2035. + if (PTR_ERR(gmac->regulator) == -EPROBE_DEFER)
  2036. + return -EPROBE_DEFER;
  2037. + dev_info(dev, "no regulator found\n");
  2038. + gmac->regulator = NULL;
  2039. + }
  2040. +
  2041. + /* platform data specifying hardware features and callbacks.
  2042. + * hardware features were copied from Allwinner drivers. */
  2043. + plat_dat->tx_coe = 1;
  2044. + plat_dat->has_gmac = true;
  2045. + plat_dat->bsp_priv = gmac;
  2046. + plat_dat->init = sun7i_gmac_init;
  2047. + plat_dat->exit = sun7i_gmac_exit;
  2048. + plat_dat->fix_mac_speed = sun7i_fix_speed;
  2049. +
  2050. + ret = sun7i_gmac_init(pdev, plat_dat->bsp_priv);
  2051. + if (ret)
  2052. + return ret;
  2053. +
  2054. + return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  2055. +}
  2056. +
  2057. +static const struct of_device_id sun7i_dwmac_match[] = {
  2058. + { .compatible = "allwinner,sun7i-a20-gmac" },
  2059. + { }
  2060. };
  2061. +MODULE_DEVICE_TABLE(of, sun7i_dwmac_match);
  2062. +
  2063. +static struct platform_driver sun7i_dwmac_driver = {
  2064. + .probe = sun7i_gmac_probe,
  2065. + .remove = stmmac_pltfr_remove,
  2066. + .driver = {
  2067. + .name = "sun7i-dwmac",
  2068. + .pm = &stmmac_pltfr_pm_ops,
  2069. + .of_match_table = sun7i_dwmac_match,
  2070. + },
  2071. +};
  2072. +module_platform_driver(sun7i_dwmac_driver);
  2073. +
  2074. +MODULE_AUTHOR("Chen-Yu Tsai <wens@csie.org>");
  2075. +MODULE_DESCRIPTION("Allwinner sunxi DWMAC specific glue layer");
  2076. +MODULE_LICENSE("GPL");
  2077. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
  2078. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
  2079. @@ -172,6 +172,7 @@ enum inter_frame_gap {
  2080. /* GMAC FLOW CTRL defines */
  2081. #define GMAC_FLOW_CTRL_PT_MASK 0xffff0000 /* Pause Time Mask */
  2082. #define GMAC_FLOW_CTRL_PT_SHIFT 16
  2083. +#define GMAC_FLOW_CTRL_UP 0x00000008 /* Unicast pause frame enable */
  2084. #define GMAC_FLOW_CTRL_RFE 0x00000004 /* Rx Flow Control Enable */
  2085. #define GMAC_FLOW_CTRL_TFE 0x00000002 /* Tx Flow Control Enable */
  2086. #define GMAC_FLOW_CTRL_FCB_BPA 0x00000001 /* Flow Control Busy ... */
  2087. @@ -246,6 +247,56 @@ enum ttc_control {
  2088. #define DMA_CONTROL_FEF 0x00000080
  2089. #define DMA_CONTROL_FUF 0x00000040
  2090. +/* Receive flow control activation field
  2091. + * RFA field in DMA control register, bits 23,10:9
  2092. + */
  2093. +#define DMA_CONTROL_RFA_MASK 0x00800600
  2094. +
  2095. +/* Receive flow control deactivation field
  2096. + * RFD field in DMA control register, bits 22,12:11
  2097. + */
  2098. +#define DMA_CONTROL_RFD_MASK 0x00401800
  2099. +
  2100. +/* RFD and RFA fields are encoded as follows
  2101. + *
  2102. + * Bit Field
  2103. + * 0,00 - Full minus 1KB (only valid when rxfifo >= 4KB and EFC enabled)
  2104. + * 0,01 - Full minus 2KB (only valid when rxfifo >= 4KB and EFC enabled)
  2105. + * 0,10 - Full minus 3KB (only valid when rxfifo >= 4KB and EFC enabled)
  2106. + * 0,11 - Full minus 4KB (only valid when rxfifo > 4KB and EFC enabled)
  2107. + * 1,00 - Full minus 5KB (only valid when rxfifo > 8KB and EFC enabled)
  2108. + * 1,01 - Full minus 6KB (only valid when rxfifo > 8KB and EFC enabled)
  2109. + * 1,10 - Full minus 7KB (only valid when rxfifo > 8KB and EFC enabled)
  2110. + * 1,11 - Reserved
  2111. + *
  2112. + * RFD should always be > RFA for a given FIFO size. RFD == RFA may work,
  2113. + * but packet throughput performance may not be as expected.
  2114. + *
  2115. + * Be sure that bit 3 in GMAC Register 6 is set for Unicast Pause frame
  2116. + * detection (IEEE Specification Requirement, Annex 31B, 31B.1, Pause
  2117. + * Description).
  2118. + *
  2119. + * Be sure that DZPA (bit 7 in Flow Control Register, GMAC Register 6),
  2120. + * is set to 0. This allows pause frames with a quanta of 0 to be sent
  2121. + * as an XOFF message to the link peer.
  2122. + */
  2123. +
  2124. +#define RFA_FULL_MINUS_1K 0x00000000
  2125. +#define RFA_FULL_MINUS_2K 0x00000200
  2126. +#define RFA_FULL_MINUS_3K 0x00000400
  2127. +#define RFA_FULL_MINUS_4K 0x00000600
  2128. +#define RFA_FULL_MINUS_5K 0x00800000
  2129. +#define RFA_FULL_MINUS_6K 0x00800200
  2130. +#define RFA_FULL_MINUS_7K 0x00800400
  2131. +
  2132. +#define RFD_FULL_MINUS_1K 0x00000000
  2133. +#define RFD_FULL_MINUS_2K 0x00000800
  2134. +#define RFD_FULL_MINUS_3K 0x00001000
  2135. +#define RFD_FULL_MINUS_4K 0x00001800
  2136. +#define RFD_FULL_MINUS_5K 0x00400000
  2137. +#define RFD_FULL_MINUS_6K 0x00400800
  2138. +#define RFD_FULL_MINUS_7K 0x00401000
  2139. +
  2140. enum rtc_control {
  2141. DMA_CONTROL_RTC_64 = 0x00000000,
  2142. DMA_CONTROL_RTC_32 = 0x00000008,
  2143. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
  2144. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
  2145. @@ -201,7 +201,10 @@ static void dwmac1000_flow_ctrl(struct m
  2146. unsigned int fc, unsigned int pause_time)
  2147. {
  2148. void __iomem *ioaddr = hw->pcsr;
  2149. - unsigned int flow = 0;
  2150. + /* Set flow such that DZPQ in Mac Register 6 is 0,
  2151. + * and unicast pause detect is enabled.
  2152. + */
  2153. + unsigned int flow = GMAC_FLOW_CTRL_UP;
  2154. pr_debug("GMAC Flow-Control:\n");
  2155. if (fc & FLOW_RX) {
  2156. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
  2157. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
  2158. @@ -70,10 +70,6 @@ static int dwmac1000_dma_init(void __iom
  2159. if (mb)
  2160. value |= DMA_BUS_MODE_MB;
  2161. -#ifdef CONFIG_STMMAC_DA
  2162. - value |= DMA_BUS_MODE_DA; /* Rx has priority over tx */
  2163. -#endif
  2164. -
  2165. if (atds)
  2166. value |= DMA_BUS_MODE_ATDS;
  2167. @@ -110,8 +106,29 @@ static int dwmac1000_dma_init(void __iom
  2168. return 0;
  2169. }
  2170. +static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
  2171. +{
  2172. + csr6 &= ~DMA_CONTROL_RFA_MASK;
  2173. + csr6 &= ~DMA_CONTROL_RFD_MASK;
  2174. +
  2175. + /* Leave flow control disabled if receive fifo size is less than
  2176. + * 4K or 0. Otherwise, send XOFF when fifo is 1K less than full,
  2177. + * and send XON when 2K less than full.
  2178. + */
  2179. + if (rxfifosz < 4096) {
  2180. + csr6 &= ~DMA_CONTROL_EFC;
  2181. + pr_debug("GMAC: disabling flow control, rxfifo too small(%d)\n",
  2182. + rxfifosz);
  2183. + } else {
  2184. + csr6 |= DMA_CONTROL_EFC;
  2185. + csr6 |= RFA_FULL_MINUS_1K;
  2186. + csr6 |= RFD_FULL_MINUS_2K;
  2187. + }
  2188. + return csr6;
  2189. +}
  2190. +
  2191. static void dwmac1000_dma_operation_mode(void __iomem *ioaddr, int txmode,
  2192. - int rxmode)
  2193. + int rxmode, int rxfifosz)
  2194. {
  2195. u32 csr6 = readl(ioaddr + DMA_CONTROL);
  2196. @@ -157,6 +174,9 @@ static void dwmac1000_dma_operation_mode
  2197. csr6 |= DMA_CONTROL_RTC_128;
  2198. }
  2199. + /* Configure flow control based on rx fifo size */
  2200. + csr6 = dwmac1000_configure_fc(csr6, rxfifosz);
  2201. +
  2202. writel(csr6, ioaddr + DMA_CONTROL);
  2203. }
  2204. --- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c
  2205. +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c
  2206. @@ -72,7 +72,7 @@ static int dwmac100_dma_init(void __iome
  2207. * control register.
  2208. */
  2209. static void dwmac100_dma_operation_mode(void __iomem *ioaddr, int txmode,
  2210. - int rxmode)
  2211. + int rxmode, int rxfifosz)
  2212. {
  2213. u32 csr6 = readl(ioaddr + DMA_CONTROL);
  2214. --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
  2215. +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
  2216. @@ -73,7 +73,7 @@
  2217. #define MMC_RX_OCTETCOUNT_G 0x00000188
  2218. #define MMC_RX_BROADCASTFRAME_G 0x0000018c
  2219. #define MMC_RX_MULTICASTFRAME_G 0x00000190
  2220. -#define MMC_RX_CRC_ERRROR 0x00000194
  2221. +#define MMC_RX_CRC_ERROR 0x00000194
  2222. #define MMC_RX_ALIGN_ERROR 0x00000198
  2223. #define MMC_RX_RUN_ERROR 0x0000019C
  2224. #define MMC_RX_JABBER_ERROR 0x000001A0
  2225. @@ -196,7 +196,7 @@ void dwmac_mmc_read(void __iomem *ioaddr
  2226. mmc->mmc_rx_octetcount_g += readl(ioaddr + MMC_RX_OCTETCOUNT_G);
  2227. mmc->mmc_rx_broadcastframe_g += readl(ioaddr + MMC_RX_BROADCASTFRAME_G);
  2228. mmc->mmc_rx_multicastframe_g += readl(ioaddr + MMC_RX_MULTICASTFRAME_G);
  2229. - mmc->mmc_rx_crc_error += readl(ioaddr + MMC_RX_CRC_ERRROR);
  2230. + mmc->mmc_rx_crc_error += readl(ioaddr + MMC_RX_CRC_ERROR);
  2231. mmc->mmc_rx_align_error += readl(ioaddr + MMC_RX_ALIGN_ERROR);
  2232. mmc->mmc_rx_run_error += readl(ioaddr + MMC_RX_RUN_ERROR);
  2233. mmc->mmc_rx_jabber_error += readl(ioaddr + MMC_RX_JABBER_ERROR);
  2234. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
  2235. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
  2236. @@ -34,6 +34,14 @@
  2237. #include <linux/ptp_clock_kernel.h>
  2238. #include <linux/reset.h>
  2239. +struct stmmac_resources {
  2240. + void __iomem *addr;
  2241. + const char *mac;
  2242. + int wol_irq;
  2243. + int lpi_irq;
  2244. + int irq;
  2245. +};
  2246. +
  2247. struct stmmac_tx_info {
  2248. dma_addr_t buf;
  2249. bool map_as_page;
  2250. @@ -97,6 +105,7 @@ struct stmmac_priv {
  2251. int wolopts;
  2252. int wol_irq;
  2253. struct clk *stmmac_clk;
  2254. + struct clk *pclk;
  2255. struct reset_control *stmmac_rst;
  2256. int clk_csr;
  2257. struct timer_list eee_ctrl_timer;
  2258. @@ -116,97 +125,28 @@ struct stmmac_priv {
  2259. int use_riwt;
  2260. int irq_wake;
  2261. spinlock_t ptp_lock;
  2262. +
  2263. +#ifdef CONFIG_DEBUG_FS
  2264. + struct dentry *dbgfs_dir;
  2265. + struct dentry *dbgfs_rings_status;
  2266. + struct dentry *dbgfs_dma_cap;
  2267. +#endif
  2268. };
  2269. int stmmac_mdio_unregister(struct net_device *ndev);
  2270. int stmmac_mdio_register(struct net_device *ndev);
  2271. int stmmac_mdio_reset(struct mii_bus *mii);
  2272. void stmmac_set_ethtool_ops(struct net_device *netdev);
  2273. -extern const struct stmmac_desc_ops enh_desc_ops;
  2274. -extern const struct stmmac_desc_ops ndesc_ops;
  2275. -extern const struct stmmac_hwtimestamp stmmac_ptp;
  2276. +
  2277. int stmmac_ptp_register(struct stmmac_priv *priv);
  2278. void stmmac_ptp_unregister(struct stmmac_priv *priv);
  2279. int stmmac_resume(struct net_device *ndev);
  2280. int stmmac_suspend(struct net_device *ndev);
  2281. int stmmac_dvr_remove(struct net_device *ndev);
  2282. -struct stmmac_priv *stmmac_dvr_probe(struct device *device,
  2283. - struct plat_stmmacenet_data *plat_dat,
  2284. - void __iomem *addr);
  2285. +int stmmac_dvr_probe(struct device *device,
  2286. + struct plat_stmmacenet_data *plat_dat,
  2287. + struct stmmac_resources *res);
  2288. void stmmac_disable_eee_mode(struct stmmac_priv *priv);
  2289. bool stmmac_eee_init(struct stmmac_priv *priv);
  2290. -#ifdef CONFIG_STMMAC_PLATFORM
  2291. -#ifdef CONFIG_DWMAC_MESON
  2292. -extern const struct stmmac_of_data meson6_dwmac_data;
  2293. -#endif
  2294. -#ifdef CONFIG_DWMAC_SUNXI
  2295. -extern const struct stmmac_of_data sun7i_gmac_data;
  2296. -#endif
  2297. -#ifdef CONFIG_DWMAC_STI
  2298. -extern const struct stmmac_of_data stih4xx_dwmac_data;
  2299. -extern const struct stmmac_of_data stid127_dwmac_data;
  2300. -#endif
  2301. -#ifdef CONFIG_DWMAC_SOCFPGA
  2302. -extern const struct stmmac_of_data socfpga_gmac_data;
  2303. -#endif
  2304. -extern struct platform_driver stmmac_pltfr_driver;
  2305. -static inline int stmmac_register_platform(void)
  2306. -{
  2307. - int err;
  2308. -
  2309. - err = platform_driver_register(&stmmac_pltfr_driver);
  2310. - if (err)
  2311. - pr_err("stmmac: failed to register the platform driver\n");
  2312. -
  2313. - return err;
  2314. -}
  2315. -
  2316. -static inline void stmmac_unregister_platform(void)
  2317. -{
  2318. - platform_driver_unregister(&stmmac_pltfr_driver);
  2319. -}
  2320. -#else
  2321. -static inline int stmmac_register_platform(void)
  2322. -{
  2323. - pr_debug("stmmac: do not register the platf driver\n");
  2324. -
  2325. - return 0;
  2326. -}
  2327. -
  2328. -static inline void stmmac_unregister_platform(void)
  2329. -{
  2330. -}
  2331. -#endif /* CONFIG_STMMAC_PLATFORM */
  2332. -
  2333. -#ifdef CONFIG_STMMAC_PCI
  2334. -extern struct pci_driver stmmac_pci_driver;
  2335. -static inline int stmmac_register_pci(void)
  2336. -{
  2337. - int err;
  2338. -
  2339. - err = pci_register_driver(&stmmac_pci_driver);
  2340. - if (err)
  2341. - pr_err("stmmac: failed to register the PCI driver\n");
  2342. -
  2343. - return err;
  2344. -}
  2345. -
  2346. -static inline void stmmac_unregister_pci(void)
  2347. -{
  2348. - pci_unregister_driver(&stmmac_pci_driver);
  2349. -}
  2350. -#else
  2351. -static inline int stmmac_register_pci(void)
  2352. -{
  2353. - pr_debug("stmmac: do not register the PCI driver\n");
  2354. -
  2355. - return 0;
  2356. -}
  2357. -
  2358. -static inline void stmmac_unregister_pci(void)
  2359. -{
  2360. -}
  2361. -#endif /* CONFIG_STMMAC_PCI */
  2362. -
  2363. #endif /* __STMMAC_H__ */
  2364. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
  2365. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
  2366. @@ -696,7 +696,7 @@ static int stmmac_set_coalesce(struct ne
  2367. (ec->tx_max_coalesced_frames == 0))
  2368. return -EINVAL;
  2369. - if ((ec->tx_coalesce_usecs > STMMAC_COAL_TX_TIMER) ||
  2370. + if ((ec->tx_coalesce_usecs > STMMAC_MAX_COAL_TX_TICK) ||
  2371. (ec->tx_max_coalesced_frames > STMMAC_TX_MAX_FRAMES))
  2372. return -EINVAL;
  2373. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
  2374. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
  2375. @@ -44,14 +44,15 @@
  2376. #include <linux/slab.h>
  2377. #include <linux/prefetch.h>
  2378. #include <linux/pinctrl/consumer.h>
  2379. -#ifdef CONFIG_STMMAC_DEBUG_FS
  2380. +#ifdef CONFIG_DEBUG_FS
  2381. #include <linux/debugfs.h>
  2382. #include <linux/seq_file.h>
  2383. -#endif /* CONFIG_STMMAC_DEBUG_FS */
  2384. +#endif /* CONFIG_DEBUG_FS */
  2385. #include <linux/net_tstamp.h>
  2386. #include "stmmac_ptp.h"
  2387. #include "stmmac.h"
  2388. #include <linux/reset.h>
  2389. +#include <linux/of_mdio.h>
  2390. #define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x)
  2391. @@ -116,17 +117,17 @@ MODULE_PARM_DESC(chain_mode, "To use cha
  2392. static irqreturn_t stmmac_interrupt(int irq, void *dev_id);
  2393. -#ifdef CONFIG_STMMAC_DEBUG_FS
  2394. +#ifdef CONFIG_DEBUG_FS
  2395. static int stmmac_init_fs(struct net_device *dev);
  2396. -static void stmmac_exit_fs(void);
  2397. +static void stmmac_exit_fs(struct net_device *dev);
  2398. #endif
  2399. #define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x))
  2400. /**
  2401. * stmmac_verify_args - verify the driver parameters.
  2402. - * Description: it verifies if some wrong parameter is passed to the driver.
  2403. - * Note that wrong parameters are replaced with the default values.
  2404. + * Description: it checks the driver parameters and set a default in case of
  2405. + * errors.
  2406. */
  2407. static void stmmac_verify_args(void)
  2408. {
  2409. @@ -191,14 +192,8 @@ static void stmmac_clk_csr_set(struct st
  2410. static void print_pkt(unsigned char *buf, int len)
  2411. {
  2412. - int j;
  2413. - pr_debug("len = %d byte, buf addr: 0x%p", len, buf);
  2414. - for (j = 0; j < len; j++) {
  2415. - if ((j % 16) == 0)
  2416. - pr_debug("\n %03x:", j);
  2417. - pr_debug(" %02x", buf[j]);
  2418. - }
  2419. - pr_debug("\n");
  2420. + pr_debug("len = %d byte, buf addr: 0x%p\n", len, buf);
  2421. + print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, len);
  2422. }
  2423. /* minimum number of free TX descriptors required to wake up TX process */
  2424. @@ -210,7 +205,7 @@ static inline u32 stmmac_tx_avail(struct
  2425. }
  2426. /**
  2427. - * stmmac_hw_fix_mac_speed: callback for speed selection
  2428. + * stmmac_hw_fix_mac_speed - callback for speed selection
  2429. * @priv: driver private structure
  2430. * Description: on some platforms (e.g. ST), some HW system configuraton
  2431. * registers have to be set according to the link speed negotiated.
  2432. @@ -224,9 +219,10 @@ static inline void stmmac_hw_fix_mac_spe
  2433. }
  2434. /**
  2435. - * stmmac_enable_eee_mode: Check and enter in LPI mode
  2436. + * stmmac_enable_eee_mode - check and enter in LPI mode
  2437. * @priv: driver private structure
  2438. - * Description: this function is to verify and enter in LPI mode for EEE.
  2439. + * Description: this function is to verify and enter in LPI mode in case of
  2440. + * EEE.
  2441. */
  2442. static void stmmac_enable_eee_mode(struct stmmac_priv *priv)
  2443. {
  2444. @@ -237,7 +233,7 @@ static void stmmac_enable_eee_mode(struc
  2445. }
  2446. /**
  2447. - * stmmac_disable_eee_mode: disable/exit from EEE
  2448. + * stmmac_disable_eee_mode - disable and exit from LPI mode
  2449. * @priv: driver private structure
  2450. * Description: this function is to exit and disable EEE in case of
  2451. * LPI state is true. This is called by the xmit.
  2452. @@ -250,7 +246,7 @@ void stmmac_disable_eee_mode(struct stmm
  2453. }
  2454. /**
  2455. - * stmmac_eee_ctrl_timer: EEE TX SW timer.
  2456. + * stmmac_eee_ctrl_timer - EEE TX SW timer.
  2457. * @arg : data hook
  2458. * Description:
  2459. * if there is no data transfer and if we are not in LPI state,
  2460. @@ -265,13 +261,12 @@ static void stmmac_eee_ctrl_timer(unsign
  2461. }
  2462. /**
  2463. - * stmmac_eee_init: init EEE
  2464. + * stmmac_eee_init - init EEE
  2465. * @priv: driver private structure
  2466. * Description:
  2467. - * If the EEE support has been enabled while configuring the driver,
  2468. - * if the GMAC actually supports the EEE (from the HW cap reg) and the
  2469. - * phy can also manage EEE, so enable the LPI state and start the timer
  2470. - * to verify if the tx path can enter in LPI state.
  2471. + * if the GMAC supports the EEE (from the HW cap reg) and the phy device
  2472. + * can also manage EEE, this function enable the LPI state and start related
  2473. + * timer.
  2474. */
  2475. bool stmmac_eee_init(struct stmmac_priv *priv)
  2476. {
  2477. @@ -316,11 +311,11 @@ bool stmmac_eee_init(struct stmmac_priv
  2478. spin_lock_irqsave(&priv->lock, flags);
  2479. if (!priv->eee_active) {
  2480. priv->eee_active = 1;
  2481. - init_timer(&priv->eee_ctrl_timer);
  2482. - priv->eee_ctrl_timer.function = stmmac_eee_ctrl_timer;
  2483. - priv->eee_ctrl_timer.data = (unsigned long)priv;
  2484. - priv->eee_ctrl_timer.expires = STMMAC_LPI_T(eee_timer);
  2485. - add_timer(&priv->eee_ctrl_timer);
  2486. + setup_timer(&priv->eee_ctrl_timer,
  2487. + stmmac_eee_ctrl_timer,
  2488. + (unsigned long)priv);
  2489. + mod_timer(&priv->eee_ctrl_timer,
  2490. + STMMAC_LPI_T(eee_timer));
  2491. priv->hw->mac->set_eee_timer(priv->hw,
  2492. STMMAC_DEFAULT_LIT_LS,
  2493. @@ -338,7 +333,7 @@ out:
  2494. return ret;
  2495. }
  2496. -/* stmmac_get_tx_hwtstamp: get HW TX timestamps
  2497. +/* stmmac_get_tx_hwtstamp - get HW TX timestamps
  2498. * @priv: driver private structure
  2499. * @entry : descriptor index to be used.
  2500. * @skb : the socket buffer
  2501. @@ -380,7 +375,7 @@ static void stmmac_get_tx_hwtstamp(struc
  2502. return;
  2503. }
  2504. -/* stmmac_get_rx_hwtstamp: get HW RX timestamps
  2505. +/* stmmac_get_rx_hwtstamp - get HW RX timestamps
  2506. * @priv: driver private structure
  2507. * @entry : descriptor index to be used.
  2508. * @skb : the socket buffer
  2509. @@ -615,7 +610,7 @@ static int stmmac_hwtstamp_ioctl(struct
  2510. * where, freq_div_ratio = clk_ptp_ref_i/50MHz
  2511. * hence, addend = ((2^32) * 50MHz)/clk_ptp_ref_i;
  2512. * NOTE: clk_ptp_ref_i should be >= 50MHz to
  2513. - * achive 20ns accuracy.
  2514. + * achieve 20ns accuracy.
  2515. *
  2516. * 2^x * y == (y << x), hence
  2517. * 2^32 * 50000000 ==> (50000000 << 32)
  2518. @@ -636,11 +631,11 @@ static int stmmac_hwtstamp_ioctl(struct
  2519. }
  2520. /**
  2521. - * stmmac_init_ptp: init PTP
  2522. + * stmmac_init_ptp - init PTP
  2523. * @priv: driver private structure
  2524. - * Description: this is to verify if the HW supports the PTPv1 or v2.
  2525. + * Description: this is to verify if the HW supports the PTPv1 or PTPv2.
  2526. * This is done by looking at the HW cap. register.
  2527. - * Also it registers the ptp driver.
  2528. + * This function also registers the ptp driver.
  2529. */
  2530. static int stmmac_init_ptp(struct stmmac_priv *priv)
  2531. {
  2532. @@ -682,9 +677,13 @@ static void stmmac_release_ptp(struct st
  2533. }
  2534. /**
  2535. - * stmmac_adjust_link
  2536. + * stmmac_adjust_link - adjusts the link parameters
  2537. * @dev: net device structure
  2538. - * Description: it adjusts the link parameters.
  2539. + * Description: this is the helper called by the physical abstraction layer
  2540. + * drivers to communicate the phy link status. According the speed and duplex
  2541. + * this driver can invoke registered glue-logic as well.
  2542. + * It also invoke the eee initialization because it could happen when switch
  2543. + * on different networks (that are eee capable).
  2544. */
  2545. static void stmmac_adjust_link(struct net_device *dev)
  2546. {
  2547. @@ -774,7 +773,7 @@ static void stmmac_adjust_link(struct ne
  2548. }
  2549. /**
  2550. - * stmmac_check_pcs_mode: verify if RGMII/SGMII is supported
  2551. + * stmmac_check_pcs_mode - verify if RGMII/SGMII is supported
  2552. * @priv: driver private structure
  2553. * Description: this is to verify if the HW supports the PCS.
  2554. * Physical Coding Sublayer (PCS) interface that can be used when the MAC is
  2555. @@ -818,21 +817,31 @@ static int stmmac_init_phy(struct net_de
  2556. priv->speed = 0;
  2557. priv->oldduplex = -1;
  2558. - if (priv->plat->phy_bus_name)
  2559. - snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
  2560. - priv->plat->phy_bus_name, priv->plat->bus_id);
  2561. - else
  2562. - snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
  2563. - priv->plat->bus_id);
  2564. + if (priv->plat->phy_node) {
  2565. + phydev = of_phy_connect(dev, priv->plat->phy_node,
  2566. + &stmmac_adjust_link, 0, interface);
  2567. + } else {
  2568. + if (priv->plat->phy_bus_name)
  2569. + snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
  2570. + priv->plat->phy_bus_name, priv->plat->bus_id);
  2571. + else
  2572. + snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
  2573. + priv->plat->bus_id);
  2574. - snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
  2575. - priv->plat->phy_addr);
  2576. - pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id_fmt);
  2577. + snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
  2578. + priv->plat->phy_addr);
  2579. + pr_debug("stmmac_init_phy: trying to attach to %s\n",
  2580. + phy_id_fmt);
  2581. - phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link, interface);
  2582. + phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link,
  2583. + interface);
  2584. + }
  2585. - if (IS_ERR(phydev)) {
  2586. + if (IS_ERR_OR_NULL(phydev)) {
  2587. pr_err("%s: Could not attach to PHY\n", dev->name);
  2588. + if (!phydev)
  2589. + return -ENODEV;
  2590. +
  2591. return PTR_ERR(phydev);
  2592. }
  2593. @@ -850,7 +859,7 @@ static int stmmac_init_phy(struct net_de
  2594. * device as well.
  2595. * Note: phydev->phy_id is the result of reading the UID PHY registers.
  2596. */
  2597. - if (phydev->phy_id == 0) {
  2598. + if (!priv->plat->phy_node && phydev->phy_id == 0) {
  2599. phy_disconnect(phydev);
  2600. return -ENODEV;
  2601. }
  2602. @@ -863,7 +872,7 @@ static int stmmac_init_phy(struct net_de
  2603. }
  2604. /**
  2605. - * stmmac_display_ring: display ring
  2606. + * stmmac_display_ring - display ring
  2607. * @head: pointer to the head of the ring passed.
  2608. * @size: size of the ring.
  2609. * @extend_desc: to verify if extended descriptors are used.
  2610. @@ -931,7 +940,7 @@ static int stmmac_set_bfsize(int mtu, in
  2611. }
  2612. /**
  2613. - * stmmac_clear_descriptors: clear descriptors
  2614. + * stmmac_clear_descriptors - clear descriptors
  2615. * @priv: driver private structure
  2616. * Description: this function is called to clear the tx and rx descriptors
  2617. * in case of both basic and extended descriptors are used.
  2618. @@ -963,18 +972,25 @@ static void stmmac_clear_descriptors(str
  2619. (i == txsize - 1));
  2620. }
  2621. +/**
  2622. + * stmmac_init_rx_buffers - init the RX descriptor buffer.
  2623. + * @priv: driver private structure
  2624. + * @p: descriptor pointer
  2625. + * @i: descriptor index
  2626. + * @flags: gfp flag.
  2627. + * Description: this function is called to allocate a receive buffer, perform
  2628. + * the DMA mapping and init the descriptor.
  2629. + */
  2630. static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
  2631. int i, gfp_t flags)
  2632. {
  2633. struct sk_buff *skb;
  2634. - skb = __netdev_alloc_skb(priv->dev, priv->dma_buf_sz + NET_IP_ALIGN,
  2635. - flags);
  2636. + skb = __netdev_alloc_skb_ip_align(priv->dev, priv->dma_buf_sz, flags);
  2637. if (!skb) {
  2638. pr_err("%s: Rx init fails; skb is NULL\n", __func__);
  2639. return -ENOMEM;
  2640. }
  2641. - skb_reserve(skb, NET_IP_ALIGN);
  2642. priv->rx_skbuff[i] = skb;
  2643. priv->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data,
  2644. priv->dma_buf_sz,
  2645. @@ -1007,7 +1023,8 @@ static void stmmac_free_rx_buffers(struc
  2646. /**
  2647. * init_dma_desc_rings - init the RX/TX descriptor rings
  2648. * @dev: net device structure
  2649. - * Description: this function initializes the DMA RX/TX descriptors
  2650. + * @flags: gfp flag.
  2651. + * Description: this function initializes the DMA RX/TX descriptors
  2652. * and allocates the socket buffers. It suppors the chained and ring
  2653. * modes.
  2654. */
  2655. @@ -1089,6 +1106,7 @@ static int init_dma_desc_rings(struct ne
  2656. priv->dirty_tx = 0;
  2657. priv->cur_tx = 0;
  2658. + netdev_reset_queue(priv->dev);
  2659. stmmac_clear_descriptors(priv);
  2660. @@ -1144,6 +1162,14 @@ static void dma_free_tx_skbufs(struct st
  2661. }
  2662. }
  2663. +/**
  2664. + * alloc_dma_desc_resources - alloc TX/RX resources.
  2665. + * @priv: private structure
  2666. + * Description: according to which descriptor can be used (extend or basic)
  2667. + * this function allocates the resources for TX and RX paths. In case of
  2668. + * reception, for example, it pre-allocated the RX socket buffer in order to
  2669. + * allow zero-copy mechanism.
  2670. + */
  2671. static int alloc_dma_desc_resources(struct stmmac_priv *priv)
  2672. {
  2673. unsigned int txsize = priv->dma_tx_size;
  2674. @@ -1255,13 +1281,15 @@ static void free_dma_desc_resources(stru
  2675. /**
  2676. * stmmac_dma_operation_mode - HW DMA operation mode
  2677. * @priv: driver private structure
  2678. - * Description: it sets the DMA operation mode: tx/rx DMA thresholds
  2679. - * or Store-And-Forward capability.
  2680. + * Description: it is used for configuring the DMA operation mode register in
  2681. + * order to program the tx/rx DMA thresholds or Store-And-Forward mode.
  2682. */
  2683. static void stmmac_dma_operation_mode(struct stmmac_priv *priv)
  2684. {
  2685. + int rxfifosz = priv->plat->rx_fifo_size;
  2686. +
  2687. if (priv->plat->force_thresh_dma_mode)
  2688. - priv->hw->dma->dma_mode(priv->ioaddr, tc, tc);
  2689. + priv->hw->dma->dma_mode(priv->ioaddr, tc, tc, rxfifosz);
  2690. else if (priv->plat->force_sf_dma_mode || priv->plat->tx_coe) {
  2691. /*
  2692. * In case of GMAC, SF mode can be enabled
  2693. @@ -1270,20 +1298,23 @@ static void stmmac_dma_operation_mode(st
  2694. * 2) There is no bugged Jumbo frame support
  2695. * that needs to not insert csum in the TDES.
  2696. */
  2697. - priv->hw->dma->dma_mode(priv->ioaddr, SF_DMA_MODE, SF_DMA_MODE);
  2698. - tc = SF_DMA_MODE;
  2699. + priv->hw->dma->dma_mode(priv->ioaddr, SF_DMA_MODE, SF_DMA_MODE,
  2700. + rxfifosz);
  2701. + priv->xstats.threshold = SF_DMA_MODE;
  2702. } else
  2703. - priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
  2704. + priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE,
  2705. + rxfifosz);
  2706. }
  2707. /**
  2708. - * stmmac_tx_clean:
  2709. + * stmmac_tx_clean - to manage the transmission completion
  2710. * @priv: driver private structure
  2711. - * Description: it reclaims resources after transmission completes.
  2712. + * Description: it reclaims the transmit resources after transmission completes.
  2713. */
  2714. static void stmmac_tx_clean(struct stmmac_priv *priv)
  2715. {
  2716. unsigned int txsize = priv->dma_tx_size;
  2717. + unsigned int bytes_compl = 0, pkts_compl = 0;
  2718. spin_lock(&priv->tx_lock);
  2719. @@ -1340,6 +1371,8 @@ static void stmmac_tx_clean(struct stmma
  2720. priv->hw->mode->clean_desc3(priv, p);
  2721. if (likely(skb != NULL)) {
  2722. + pkts_compl++;
  2723. + bytes_compl += skb->len;
  2724. dev_consume_skb_any(skb);
  2725. priv->tx_skbuff[entry] = NULL;
  2726. }
  2727. @@ -1348,6 +1381,9 @@ static void stmmac_tx_clean(struct stmma
  2728. priv->dirty_tx++;
  2729. }
  2730. +
  2731. + netdev_completed_queue(priv->dev, pkts_compl, bytes_compl);
  2732. +
  2733. if (unlikely(netif_queue_stopped(priv->dev) &&
  2734. stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv))) {
  2735. netif_tx_lock(priv->dev);
  2736. @@ -1378,10 +1414,10 @@ static inline void stmmac_disable_dma_ir
  2737. }
  2738. /**
  2739. - * stmmac_tx_err: irq tx error mng function
  2740. + * stmmac_tx_err - to manage the tx error
  2741. * @priv: driver private structure
  2742. * Description: it cleans the descriptors and restarts the transmission
  2743. - * in case of errors.
  2744. + * in case of transmission errors.
  2745. */
  2746. static void stmmac_tx_err(struct stmmac_priv *priv)
  2747. {
  2748. @@ -1402,6 +1438,7 @@ static void stmmac_tx_err(struct stmmac_
  2749. (i == txsize - 1));
  2750. priv->dirty_tx = 0;
  2751. priv->cur_tx = 0;
  2752. + netdev_reset_queue(priv->dev);
  2753. priv->hw->dma->start_tx(priv->ioaddr);
  2754. priv->dev->stats.tx_errors++;
  2755. @@ -1409,16 +1446,16 @@ static void stmmac_tx_err(struct stmmac_
  2756. }
  2757. /**
  2758. - * stmmac_dma_interrupt: DMA ISR
  2759. + * stmmac_dma_interrupt - DMA ISR
  2760. * @priv: driver private structure
  2761. * Description: this is the DMA ISR. It is called by the main ISR.
  2762. - * It calls the dwmac dma routine to understand which type of interrupt
  2763. - * happened. In case of there is a Normal interrupt and either TX or RX
  2764. - * interrupt happened so the NAPI is scheduled.
  2765. + * It calls the dwmac dma routine and schedule poll method in case of some
  2766. + * work can be done.
  2767. */
  2768. static void stmmac_dma_interrupt(struct stmmac_priv *priv)
  2769. {
  2770. int status;
  2771. + int rxfifosz = priv->plat->rx_fifo_size;
  2772. status = priv->hw->dma->dma_interrupt(priv->ioaddr, &priv->xstats);
  2773. if (likely((status & handle_rx)) || (status & handle_tx)) {
  2774. @@ -1429,9 +1466,15 @@ static void stmmac_dma_interrupt(struct
  2775. }
  2776. if (unlikely(status & tx_hard_error_bump_tc)) {
  2777. /* Try to bump up the dma threshold on this failure */
  2778. - if (unlikely(tc != SF_DMA_MODE) && (tc <= 256)) {
  2779. + if (unlikely(priv->xstats.threshold != SF_DMA_MODE) &&
  2780. + (tc <= 256)) {
  2781. tc += 64;
  2782. - priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
  2783. + if (priv->plat->force_thresh_dma_mode)
  2784. + priv->hw->dma->dma_mode(priv->ioaddr, tc, tc,
  2785. + rxfifosz);
  2786. + else
  2787. + priv->hw->dma->dma_mode(priv->ioaddr, tc,
  2788. + SF_DMA_MODE, rxfifosz);
  2789. priv->xstats.threshold = tc;
  2790. }
  2791. } else if (unlikely(status == tx_hard_error))
  2792. @@ -1457,6 +1500,12 @@ static void stmmac_mmc_setup(struct stmm
  2793. pr_info(" No MAC Management Counters available\n");
  2794. }
  2795. +/**
  2796. + * stmmac_get_synopsys_id - return the SYINID.
  2797. + * @priv: driver private structure
  2798. + * Description: this simple function is to decode and return the SYINID
  2799. + * starting from the HW core register.
  2800. + */
  2801. static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
  2802. {
  2803. u32 hwid = priv->hw->synopsys_uid;
  2804. @@ -1475,11 +1524,11 @@ static u32 stmmac_get_synopsys_id(struct
  2805. }
  2806. /**
  2807. - * stmmac_selec_desc_mode: to select among: normal/alternate/extend descriptors
  2808. + * stmmac_selec_desc_mode - to select among: normal/alternate/extend descriptors
  2809. * @priv: driver private structure
  2810. * Description: select the Enhanced/Alternate or Normal descriptors.
  2811. - * In case of Enhanced/Alternate, it looks at the extended descriptors are
  2812. - * supported by the HW cap. register.
  2813. + * In case of Enhanced/Alternate, it checks if the extended descriptors are
  2814. + * supported by the HW capability register.
  2815. */
  2816. static void stmmac_selec_desc_mode(struct stmmac_priv *priv)
  2817. {
  2818. @@ -1501,7 +1550,7 @@ static void stmmac_selec_desc_mode(struc
  2819. }
  2820. /**
  2821. - * stmmac_get_hw_features: get MAC capabilities from the HW cap. register.
  2822. + * stmmac_get_hw_features - get MAC capabilities from the HW cap. register.
  2823. * @priv: driver private structure
  2824. * Description:
  2825. * new GMAC chip generations have a new register to indicate the
  2826. @@ -1559,7 +1608,7 @@ static int stmmac_get_hw_features(struct
  2827. }
  2828. /**
  2829. - * stmmac_check_ether_addr: check if the MAC addr is valid
  2830. + * stmmac_check_ether_addr - check if the MAC addr is valid
  2831. * @priv: driver private structure
  2832. * Description:
  2833. * it is to verify if the MAC address is valid, in case of failures it
  2834. @@ -1578,7 +1627,7 @@ static void stmmac_check_ether_addr(stru
  2835. }
  2836. /**
  2837. - * stmmac_init_dma_engine: DMA init.
  2838. + * stmmac_init_dma_engine - DMA init.
  2839. * @priv: driver private structure
  2840. * Description:
  2841. * It inits the DMA invoking the specific MAC/GMAC callback.
  2842. @@ -1607,7 +1656,7 @@ static int stmmac_init_dma_engine(struct
  2843. }
  2844. /**
  2845. - * stmmac_tx_timer: mitigation sw timer for tx.
  2846. + * stmmac_tx_timer - mitigation sw timer for tx.
  2847. * @data: data pointer
  2848. * Description:
  2849. * This is the timer handler to directly invoke the stmmac_tx_clean.
  2850. @@ -1620,7 +1669,7 @@ static void stmmac_tx_timer(unsigned lon
  2851. }
  2852. /**
  2853. - * stmmac_init_tx_coalesce: init tx mitigation options.
  2854. + * stmmac_init_tx_coalesce - init tx mitigation options.
  2855. * @priv: driver private structure
  2856. * Description:
  2857. * This inits the transmit coalesce parameters: i.e. timer rate,
  2858. @@ -1639,15 +1688,18 @@ static void stmmac_init_tx_coalesce(stru
  2859. }
  2860. /**
  2861. - * stmmac_hw_setup: setup mac in a usable state.
  2862. + * stmmac_hw_setup - setup mac in a usable state.
  2863. * @dev : pointer to the device structure.
  2864. * Description:
  2865. - * This function sets up the ip in a usable state.
  2866. + * this is the main function to setup the HW in a usable state because the
  2867. + * dma engine is reset, the core registers are configured (e.g. AXI,
  2868. + * Checksum features, timers). The DMA is ready to start receiving and
  2869. + * transmitting.
  2870. * Return value:
  2871. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  2872. * file on failure.
  2873. */
  2874. -static int stmmac_hw_setup(struct net_device *dev)
  2875. +static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
  2876. {
  2877. struct stmmac_priv *priv = netdev_priv(dev);
  2878. int ret;
  2879. @@ -1684,11 +1736,13 @@ static int stmmac_hw_setup(struct net_de
  2880. stmmac_mmc_setup(priv);
  2881. - ret = stmmac_init_ptp(priv);
  2882. - if (ret && ret != -EOPNOTSUPP)
  2883. - pr_warn("%s: failed PTP initialisation\n", __func__);
  2884. + if (init_ptp) {
  2885. + ret = stmmac_init_ptp(priv);
  2886. + if (ret && ret != -EOPNOTSUPP)
  2887. + pr_warn("%s: failed PTP initialisation\n", __func__);
  2888. + }
  2889. -#ifdef CONFIG_STMMAC_DEBUG_FS
  2890. +#ifdef CONFIG_DEBUG_FS
  2891. ret = stmmac_init_fs(dev);
  2892. if (ret < 0)
  2893. pr_warn("%s: failed debugFS registration\n", __func__);
  2894. @@ -1763,7 +1817,7 @@ static int stmmac_open(struct net_device
  2895. goto init_error;
  2896. }
  2897. - ret = stmmac_hw_setup(dev);
  2898. + ret = stmmac_hw_setup(dev, true);
  2899. if (ret < 0) {
  2900. pr_err("%s: Hw setup failed\n", __func__);
  2901. goto init_error;
  2902. @@ -1870,8 +1924,8 @@ static int stmmac_release(struct net_dev
  2903. netif_carrier_off(dev);
  2904. -#ifdef CONFIG_STMMAC_DEBUG_FS
  2905. - stmmac_exit_fs();
  2906. +#ifdef CONFIG_DEBUG_FS
  2907. + stmmac_exit_fs(dev);
  2908. #endif
  2909. stmmac_release_ptp(priv);
  2910. @@ -1880,7 +1934,7 @@ static int stmmac_release(struct net_dev
  2911. }
  2912. /**
  2913. - * stmmac_xmit: Tx entry point of the driver
  2914. + * stmmac_xmit - Tx entry point of the driver
  2915. * @skb : the socket buffer
  2916. * @dev : device pointer
  2917. * Description : this is the tx entry point of the driver.
  2918. @@ -2024,6 +2078,7 @@ static netdev_tx_t stmmac_xmit(struct sk
  2919. if (!priv->hwts_tx_en)
  2920. skb_tx_timestamp(skb);
  2921. + netdev_sent_queue(dev, skb->len);
  2922. priv->hw->dma->enable_dma_transmission(priv->ioaddr);
  2923. spin_unlock(&priv->tx_lock);
  2924. @@ -2055,7 +2110,7 @@ static void stmmac_rx_vlan(struct net_de
  2925. /**
  2926. - * stmmac_rx_refill: refill used skb preallocated buffers
  2927. + * stmmac_rx_refill - refill used skb preallocated buffers
  2928. * @priv: driver private structure
  2929. * Description : this is to reallocate the skb for the reception process
  2930. * that is based on zero-copy.
  2931. @@ -2106,7 +2161,7 @@ static inline void stmmac_rx_refill(stru
  2932. }
  2933. /**
  2934. - * stmmac_rx_refill: refill used skb preallocated buffers
  2935. + * stmmac_rx - manage the receive process
  2936. * @priv: driver private structure
  2937. * @limit: napi bugget.
  2938. * Description : this the function called by the napi poll method.
  2939. @@ -2375,8 +2430,11 @@ static int stmmac_set_features(struct ne
  2940. * @irq: interrupt number.
  2941. * @dev_id: to pass the net device pointer.
  2942. * Description: this is the main driver interrupt service routine.
  2943. - * It calls the DMA ISR and also the core ISR to manage PMT, MMC, LPI
  2944. - * interrupts.
  2945. + * It can call:
  2946. + * o DMA service routine (to manage incoming frame reception and transmission
  2947. + * status)
  2948. + * o Core interrupts to manage: remote wake-up, management counter, LPI
  2949. + * interrupts.
  2950. */
  2951. static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
  2952. {
  2953. @@ -2457,10 +2515,8 @@ static int stmmac_ioctl(struct net_devic
  2954. return ret;
  2955. }
  2956. -#ifdef CONFIG_STMMAC_DEBUG_FS
  2957. +#ifdef CONFIG_DEBUG_FS
  2958. static struct dentry *stmmac_fs_dir;
  2959. -static struct dentry *stmmac_rings_status;
  2960. -static struct dentry *stmmac_dma_cap;
  2961. static void sysfs_display_ring(void *head, int size, int extend_desc,
  2962. struct seq_file *seq)
  2963. @@ -2599,36 +2655,39 @@ static const struct file_operations stmm
  2964. static int stmmac_init_fs(struct net_device *dev)
  2965. {
  2966. - /* Create debugfs entries */
  2967. - stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
  2968. + struct stmmac_priv *priv = netdev_priv(dev);
  2969. - if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
  2970. - pr_err("ERROR %s, debugfs create directory failed\n",
  2971. - STMMAC_RESOURCE_NAME);
  2972. + /* Create per netdev entries */
  2973. + priv->dbgfs_dir = debugfs_create_dir(dev->name, stmmac_fs_dir);
  2974. +
  2975. + if (!priv->dbgfs_dir || IS_ERR(priv->dbgfs_dir)) {
  2976. + pr_err("ERROR %s/%s, debugfs create directory failed\n",
  2977. + STMMAC_RESOURCE_NAME, dev->name);
  2978. return -ENOMEM;
  2979. }
  2980. /* Entry to report DMA RX/TX rings */
  2981. - stmmac_rings_status = debugfs_create_file("descriptors_status",
  2982. - S_IRUGO, stmmac_fs_dir, dev,
  2983. - &stmmac_rings_status_fops);
  2984. + priv->dbgfs_rings_status =
  2985. + debugfs_create_file("descriptors_status", S_IRUGO,
  2986. + priv->dbgfs_dir, dev,
  2987. + &stmmac_rings_status_fops);
  2988. - if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) {
  2989. + if (!priv->dbgfs_rings_status || IS_ERR(priv->dbgfs_rings_status)) {
  2990. pr_info("ERROR creating stmmac ring debugfs file\n");
  2991. - debugfs_remove(stmmac_fs_dir);
  2992. + debugfs_remove_recursive(priv->dbgfs_dir);
  2993. return -ENOMEM;
  2994. }
  2995. /* Entry to report the DMA HW features */
  2996. - stmmac_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, stmmac_fs_dir,
  2997. - dev, &stmmac_dma_cap_fops);
  2998. + priv->dbgfs_dma_cap = debugfs_create_file("dma_cap", S_IRUGO,
  2999. + priv->dbgfs_dir,
  3000. + dev, &stmmac_dma_cap_fops);
  3001. - if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) {
  3002. + if (!priv->dbgfs_dma_cap || IS_ERR(priv->dbgfs_dma_cap)) {
  3003. pr_info("ERROR creating stmmac MMC debugfs file\n");
  3004. - debugfs_remove(stmmac_rings_status);
  3005. - debugfs_remove(stmmac_fs_dir);
  3006. + debugfs_remove_recursive(priv->dbgfs_dir);
  3007. return -ENOMEM;
  3008. }
  3009. @@ -2636,13 +2695,13 @@ static int stmmac_init_fs(struct net_dev
  3010. return 0;
  3011. }
  3012. -static void stmmac_exit_fs(void)
  3013. +static void stmmac_exit_fs(struct net_device *dev)
  3014. {
  3015. - debugfs_remove(stmmac_rings_status);
  3016. - debugfs_remove(stmmac_dma_cap);
  3017. - debugfs_remove(stmmac_fs_dir);
  3018. + struct stmmac_priv *priv = netdev_priv(dev);
  3019. +
  3020. + debugfs_remove_recursive(priv->dbgfs_dir);
  3021. }
  3022. -#endif /* CONFIG_STMMAC_DEBUG_FS */
  3023. +#endif /* CONFIG_DEBUG_FS */
  3024. static const struct net_device_ops stmmac_netdev_ops = {
  3025. .ndo_open = stmmac_open,
  3026. @@ -2663,11 +2722,10 @@ static const struct net_device_ops stmma
  3027. /**
  3028. * stmmac_hw_init - Init the MAC device
  3029. * @priv: driver private structure
  3030. - * Description: this function detects which MAC device
  3031. - * (GMAC/MAC10-100) has to attached, checks the HW capability
  3032. - * (if supported) and sets the driver's features (for example
  3033. - * to use the ring or chaine mode or support the normal/enh
  3034. - * descriptor structure).
  3035. + * Description: this function is to configure the MAC device according to
  3036. + * some platform parameters or the HW capability register. It prepares the
  3037. + * driver to use either ring or chain modes and to setup either enhanced or
  3038. + * normal descriptors.
  3039. */
  3040. static int stmmac_hw_init(struct stmmac_priv *priv)
  3041. {
  3042. @@ -2714,7 +2772,11 @@ static int stmmac_hw_init(struct stmmac_
  3043. priv->plat->enh_desc = priv->dma_cap.enh_desc;
  3044. priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
  3045. - priv->plat->tx_coe = priv->dma_cap.tx_coe;
  3046. + /* TXCOE doesn't work in thresh DMA mode */
  3047. + if (priv->plat->force_thresh_dma_mode)
  3048. + priv->plat->tx_coe = 0;
  3049. + else
  3050. + priv->plat->tx_coe = priv->dma_cap.tx_coe;
  3051. if (priv->dma_cap.rx_coe_type2)
  3052. priv->plat->rx_coe = STMMAC_RX_COE_TYPE2;
  3053. @@ -2747,13 +2809,15 @@ static int stmmac_hw_init(struct stmmac_
  3054. * stmmac_dvr_probe
  3055. * @device: device pointer
  3056. * @plat_dat: platform data pointer
  3057. - * @addr: iobase memory address
  3058. + * @res: stmmac resource pointer
  3059. * Description: this is the main probe function used to
  3060. * call the alloc_etherdev, allocate the priv structure.
  3061. + * Return:
  3062. + * returns 0 on success, otherwise errno.
  3063. */
  3064. -struct stmmac_priv *stmmac_dvr_probe(struct device *device,
  3065. - struct plat_stmmacenet_data *plat_dat,
  3066. - void __iomem *addr)
  3067. +int stmmac_dvr_probe(struct device *device,
  3068. + struct plat_stmmacenet_data *plat_dat,
  3069. + struct stmmac_resources *res)
  3070. {
  3071. int ret = 0;
  3072. struct net_device *ndev = NULL;
  3073. @@ -2761,7 +2825,7 @@ struct stmmac_priv *stmmac_dvr_probe(str
  3074. ndev = alloc_etherdev(sizeof(struct stmmac_priv));
  3075. if (!ndev)
  3076. - return NULL;
  3077. + return -ENOMEM;
  3078. SET_NETDEV_DEV(ndev, device);
  3079. @@ -2772,8 +2836,17 @@ struct stmmac_priv *stmmac_dvr_probe(str
  3080. stmmac_set_ethtool_ops(ndev);
  3081. priv->pause = pause;
  3082. priv->plat = plat_dat;
  3083. - priv->ioaddr = addr;
  3084. - priv->dev->base_addr = (unsigned long)addr;
  3085. + priv->ioaddr = res->addr;
  3086. + priv->dev->base_addr = (unsigned long)res->addr;
  3087. +
  3088. + priv->dev->irq = res->irq;
  3089. + priv->wol_irq = res->wol_irq;
  3090. + priv->lpi_irq = res->lpi_irq;
  3091. +
  3092. + if (res->mac)
  3093. + memcpy(priv->dev->dev_addr, res->mac, ETH_ALEN);
  3094. +
  3095. + dev_set_drvdata(device, priv->dev);
  3096. /* Verify driver arguments */
  3097. stmmac_verify_args();
  3098. @@ -2800,6 +2873,16 @@ struct stmmac_priv *stmmac_dvr_probe(str
  3099. }
  3100. clk_prepare_enable(priv->stmmac_clk);
  3101. + priv->pclk = devm_clk_get(priv->device, "pclk");
  3102. + if (IS_ERR(priv->pclk)) {
  3103. + if (PTR_ERR(priv->pclk) == -EPROBE_DEFER) {
  3104. + ret = -EPROBE_DEFER;
  3105. + goto error_pclk_get;
  3106. + }
  3107. + priv->pclk = NULL;
  3108. + }
  3109. + clk_prepare_enable(priv->pclk);
  3110. +
  3111. priv->stmmac_rst = devm_reset_control_get(priv->device,
  3112. STMMAC_RESOURCE_NAME);
  3113. if (IS_ERR(priv->stmmac_rst)) {
  3114. @@ -2878,19 +2961,22 @@ struct stmmac_priv *stmmac_dvr_probe(str
  3115. }
  3116. }
  3117. - return priv;
  3118. + return 0;
  3119. error_mdio_register:
  3120. unregister_netdev(ndev);
  3121. error_netdev_register:
  3122. netif_napi_del(&priv->napi);
  3123. error_hw_init:
  3124. + clk_disable_unprepare(priv->pclk);
  3125. +error_pclk_get:
  3126. clk_disable_unprepare(priv->stmmac_clk);
  3127. error_clk_get:
  3128. free_netdev(ndev);
  3129. - return ERR_PTR(ret);
  3130. + return ret;
  3131. }
  3132. +EXPORT_SYMBOL_GPL(stmmac_dvr_probe);
  3133. /**
  3134. * stmmac_dvr_remove
  3135. @@ -2908,20 +2994,28 @@ int stmmac_dvr_remove(struct net_device
  3136. priv->hw->dma->stop_tx(priv->ioaddr);
  3137. stmmac_set_mac(priv->ioaddr, false);
  3138. - if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI &&
  3139. - priv->pcs != STMMAC_PCS_RTBI)
  3140. - stmmac_mdio_unregister(ndev);
  3141. netif_carrier_off(ndev);
  3142. unregister_netdev(ndev);
  3143. if (priv->stmmac_rst)
  3144. reset_control_assert(priv->stmmac_rst);
  3145. + clk_disable_unprepare(priv->pclk);
  3146. clk_disable_unprepare(priv->stmmac_clk);
  3147. + if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI &&
  3148. + priv->pcs != STMMAC_PCS_RTBI)
  3149. + stmmac_mdio_unregister(ndev);
  3150. free_netdev(ndev);
  3151. return 0;
  3152. }
  3153. +EXPORT_SYMBOL_GPL(stmmac_dvr_remove);
  3154. -#ifdef CONFIG_PM
  3155. +/**
  3156. + * stmmac_suspend - suspend callback
  3157. + * @ndev: net device pointer
  3158. + * Description: this is the function to suspend the device and it is called
  3159. + * by the platform driver to stop the network queue, release the resources,
  3160. + * program the PMT register (for WoL), clean and release driver resources.
  3161. + */
  3162. int stmmac_suspend(struct net_device *ndev)
  3163. {
  3164. struct stmmac_priv *priv = netdev_priv(ndev);
  3165. @@ -2954,6 +3048,7 @@ int stmmac_suspend(struct net_device *nd
  3166. stmmac_set_mac(priv->ioaddr, false);
  3167. pinctrl_pm_select_sleep_state(priv->device);
  3168. /* Disable clock in case of PWM is off */
  3169. + clk_disable(priv->pclk);
  3170. clk_disable(priv->stmmac_clk);
  3171. }
  3172. spin_unlock_irqrestore(&priv->lock, flags);
  3173. @@ -2963,7 +3058,14 @@ int stmmac_suspend(struct net_device *nd
  3174. priv->oldduplex = -1;
  3175. return 0;
  3176. }
  3177. +EXPORT_SYMBOL_GPL(stmmac_suspend);
  3178. +/**
  3179. + * stmmac_resume - resume callback
  3180. + * @ndev: net device pointer
  3181. + * Description: when resume this function is invoked to setup the DMA and CORE
  3182. + * in a usable state.
  3183. + */
  3184. int stmmac_resume(struct net_device *ndev)
  3185. {
  3186. struct stmmac_priv *priv = netdev_priv(ndev);
  3187. @@ -2987,6 +3089,7 @@ int stmmac_resume(struct net_device *nde
  3188. pinctrl_pm_select_default_state(priv->device);
  3189. /* enable the clk prevously disabled */
  3190. clk_enable(priv->stmmac_clk);
  3191. + clk_enable(priv->pclk);
  3192. /* reset the phy so that it's ready */
  3193. if (priv->mii)
  3194. stmmac_mdio_reset(priv->mii);
  3195. @@ -2995,7 +3098,7 @@ int stmmac_resume(struct net_device *nde
  3196. netif_device_attach(ndev);
  3197. init_dma_desc_rings(ndev, GFP_ATOMIC);
  3198. - stmmac_hw_setup(ndev);
  3199. + stmmac_hw_setup(ndev, false);
  3200. stmmac_init_tx_coalesce(priv);
  3201. napi_enable(&priv->napi);
  3202. @@ -3009,37 +3112,7 @@ int stmmac_resume(struct net_device *nde
  3203. return 0;
  3204. }
  3205. -#endif /* CONFIG_PM */
  3206. -
  3207. -/* Driver can be configured w/ and w/ both PCI and Platf drivers
  3208. - * depending on the configuration selected.
  3209. - */
  3210. -static int __init stmmac_init(void)
  3211. -{
  3212. - int ret;
  3213. -
  3214. - ret = stmmac_register_platform();
  3215. - if (ret)
  3216. - goto err;
  3217. - ret = stmmac_register_pci();
  3218. - if (ret)
  3219. - goto err_pci;
  3220. - return 0;
  3221. -err_pci:
  3222. - stmmac_unregister_platform();
  3223. -err:
  3224. - pr_err("stmmac: driver registration failed\n");
  3225. - return ret;
  3226. -}
  3227. -
  3228. -static void __exit stmmac_exit(void)
  3229. -{
  3230. - stmmac_unregister_platform();
  3231. - stmmac_unregister_pci();
  3232. -}
  3233. -
  3234. -module_init(stmmac_init);
  3235. -module_exit(stmmac_exit);
  3236. +EXPORT_SYMBOL_GPL(stmmac_resume);
  3237. #ifndef MODULE
  3238. static int __init stmmac_cmdline_opt(char *str)
  3239. @@ -3094,6 +3167,35 @@ err:
  3240. __setup("stmmaceth=", stmmac_cmdline_opt);
  3241. #endif /* MODULE */
  3242. +static int __init stmmac_init(void)
  3243. +{
  3244. +#ifdef CONFIG_DEBUG_FS
  3245. + /* Create debugfs main directory if it doesn't exist yet */
  3246. + if (!stmmac_fs_dir) {
  3247. + stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
  3248. +
  3249. + if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
  3250. + pr_err("ERROR %s, debugfs create directory failed\n",
  3251. + STMMAC_RESOURCE_NAME);
  3252. +
  3253. + return -ENOMEM;
  3254. + }
  3255. + }
  3256. +#endif
  3257. +
  3258. + return 0;
  3259. +}
  3260. +
  3261. +static void __exit stmmac_exit(void)
  3262. +{
  3263. +#ifdef CONFIG_DEBUG_FS
  3264. + debugfs_remove_recursive(stmmac_fs_dir);
  3265. +#endif
  3266. +}
  3267. +
  3268. +module_init(stmmac_init)
  3269. +module_exit(stmmac_exit)
  3270. +
  3271. MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver");
  3272. MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
  3273. MODULE_LICENSE("GPL");
  3274. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
  3275. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
  3276. @@ -161,11 +161,16 @@ int stmmac_mdio_reset(struct mii_bus *bu
  3277. if (!gpio_request(reset_gpio, "mdio-reset")) {
  3278. gpio_direction_output(reset_gpio, active_low ? 1 : 0);
  3279. - udelay(data->delays[0]);
  3280. + if (data->delays[0])
  3281. + msleep(DIV_ROUND_UP(data->delays[0], 1000));
  3282. +
  3283. gpio_set_value(reset_gpio, active_low ? 0 : 1);
  3284. - udelay(data->delays[1]);
  3285. + if (data->delays[1])
  3286. + msleep(DIV_ROUND_UP(data->delays[1], 1000));
  3287. +
  3288. gpio_set_value(reset_gpio, active_low ? 1 : 0);
  3289. - udelay(data->delays[2]);
  3290. + if (data->delays[2])
  3291. + msleep(DIV_ROUND_UP(data->delays[2], 1000));
  3292. }
  3293. }
  3294. #endif
  3295. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
  3296. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
  3297. @@ -24,38 +24,128 @@
  3298. *******************************************************************************/
  3299. #include <linux/pci.h>
  3300. +#include <linux/dmi.h>
  3301. +
  3302. #include "stmmac.h"
  3303. -static struct plat_stmmacenet_data plat_dat;
  3304. -static struct stmmac_mdio_bus_data mdio_data;
  3305. -static struct stmmac_dma_cfg dma_cfg;
  3306. -
  3307. -static void stmmac_default_data(void)
  3308. -{
  3309. - memset(&plat_dat, 0, sizeof(struct plat_stmmacenet_data));
  3310. -
  3311. - plat_dat.bus_id = 1;
  3312. - plat_dat.phy_addr = 0;
  3313. - plat_dat.interface = PHY_INTERFACE_MODE_GMII;
  3314. - plat_dat.clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
  3315. - plat_dat.has_gmac = 1;
  3316. - plat_dat.force_sf_dma_mode = 1;
  3317. -
  3318. - mdio_data.phy_reset = NULL;
  3319. - mdio_data.phy_mask = 0;
  3320. - plat_dat.mdio_bus_data = &mdio_data;
  3321. -
  3322. - dma_cfg.pbl = 32;
  3323. - dma_cfg.burst_len = DMA_AXI_BLEN_256;
  3324. - plat_dat.dma_cfg = &dma_cfg;
  3325. +/*
  3326. + * This struct is used to associate PCI Function of MAC controller on a board,
  3327. + * discovered via DMI, with the address of PHY connected to the MAC. The
  3328. + * negative value of the address means that MAC controller is not connected
  3329. + * with PHY.
  3330. + */
  3331. +struct stmmac_pci_dmi_data {
  3332. + const char *name;
  3333. + unsigned int func;
  3334. + int phy_addr;
  3335. +};
  3336. +
  3337. +struct stmmac_pci_info {
  3338. + struct pci_dev *pdev;
  3339. + int (*setup)(struct plat_stmmacenet_data *plat,
  3340. + struct stmmac_pci_info *info);
  3341. + struct stmmac_pci_dmi_data *dmi;
  3342. +};
  3343. +
  3344. +static int stmmac_pci_find_phy_addr(struct stmmac_pci_info *info)
  3345. +{
  3346. + const char *name = dmi_get_system_info(DMI_BOARD_NAME);
  3347. + unsigned int func = PCI_FUNC(info->pdev->devfn);
  3348. + struct stmmac_pci_dmi_data *dmi;
  3349. +
  3350. + /*
  3351. + * Galileo boards with old firmware don't support DMI. We always return
  3352. + * 1 here, so at least first found MAC controller would be probed.
  3353. + */
  3354. + if (!name)
  3355. + return 1;
  3356. +
  3357. + for (dmi = info->dmi; dmi->name && *dmi->name; dmi++) {
  3358. + if (!strcmp(dmi->name, name) && dmi->func == func)
  3359. + return dmi->phy_addr;
  3360. + }
  3361. +
  3362. + return -ENODEV;
  3363. +}
  3364. +
  3365. +static void stmmac_default_data(struct plat_stmmacenet_data *plat)
  3366. +{
  3367. + plat->bus_id = 1;
  3368. + plat->phy_addr = 0;
  3369. + plat->interface = PHY_INTERFACE_MODE_GMII;
  3370. + plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
  3371. + plat->has_gmac = 1;
  3372. + plat->force_sf_dma_mode = 1;
  3373. +
  3374. + plat->mdio_bus_data->phy_reset = NULL;
  3375. + plat->mdio_bus_data->phy_mask = 0;
  3376. +
  3377. + plat->dma_cfg->pbl = 32;
  3378. + plat->dma_cfg->burst_len = DMA_AXI_BLEN_256;
  3379. +
  3380. + /* Set default value for multicast hash bins */
  3381. + plat->multicast_filter_bins = HASH_TABLE_SIZE;
  3382. +
  3383. + /* Set default value for unicast filter entries */
  3384. + plat->unicast_filter_entries = 1;
  3385. +}
  3386. +
  3387. +static int quark_default_data(struct plat_stmmacenet_data *plat,
  3388. + struct stmmac_pci_info *info)
  3389. +{
  3390. + struct pci_dev *pdev = info->pdev;
  3391. + int ret;
  3392. +
  3393. + /*
  3394. + * Refuse to load the driver and register net device if MAC controller
  3395. + * does not connect to any PHY interface.
  3396. + */
  3397. + ret = stmmac_pci_find_phy_addr(info);
  3398. + if (ret < 0)
  3399. + return ret;
  3400. +
  3401. + plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
  3402. + plat->phy_addr = ret;
  3403. + plat->interface = PHY_INTERFACE_MODE_RMII;
  3404. + plat->clk_csr = 2;
  3405. + plat->has_gmac = 1;
  3406. + plat->force_sf_dma_mode = 1;
  3407. +
  3408. + plat->mdio_bus_data->phy_reset = NULL;
  3409. + plat->mdio_bus_data->phy_mask = 0;
  3410. +
  3411. + plat->dma_cfg->pbl = 16;
  3412. + plat->dma_cfg->burst_len = DMA_AXI_BLEN_256;
  3413. + plat->dma_cfg->fixed_burst = 1;
  3414. /* Set default value for multicast hash bins */
  3415. - plat_dat.multicast_filter_bins = HASH_TABLE_SIZE;
  3416. + plat->multicast_filter_bins = HASH_TABLE_SIZE;
  3417. /* Set default value for unicast filter entries */
  3418. - plat_dat.unicast_filter_entries = 1;
  3419. + plat->unicast_filter_entries = 1;
  3420. +
  3421. + return 0;
  3422. }
  3423. +static struct stmmac_pci_dmi_data quark_pci_dmi_data[] = {
  3424. + {
  3425. + .name = "Galileo",
  3426. + .func = 6,
  3427. + .phy_addr = 1,
  3428. + },
  3429. + {
  3430. + .name = "GalileoGen2",
  3431. + .func = 6,
  3432. + .phy_addr = 1,
  3433. + },
  3434. + {}
  3435. +};
  3436. +
  3437. +static struct stmmac_pci_info quark_pci_info = {
  3438. + .setup = quark_default_data,
  3439. + .dmi = quark_pci_dmi_data,
  3440. +};
  3441. +
  3442. /**
  3443. * stmmac_pci_probe
  3444. *
  3445. @@ -71,64 +161,65 @@ static void stmmac_default_data(void)
  3446. static int stmmac_pci_probe(struct pci_dev *pdev,
  3447. const struct pci_device_id *id)
  3448. {
  3449. - int ret = 0;
  3450. - void __iomem *addr = NULL;
  3451. - struct stmmac_priv *priv = NULL;
  3452. + struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
  3453. + struct plat_stmmacenet_data *plat;
  3454. + struct stmmac_resources res;
  3455. int i;
  3456. + int ret;
  3457. +
  3458. + plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
  3459. + if (!plat)
  3460. + return -ENOMEM;
  3461. +
  3462. + plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
  3463. + sizeof(*plat->mdio_bus_data),
  3464. + GFP_KERNEL);
  3465. + if (!plat->mdio_bus_data)
  3466. + return -ENOMEM;
  3467. +
  3468. + plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
  3469. + GFP_KERNEL);
  3470. + if (!plat->dma_cfg)
  3471. + return -ENOMEM;
  3472. /* Enable pci device */
  3473. - ret = pci_enable_device(pdev);
  3474. + ret = pcim_enable_device(pdev);
  3475. if (ret) {
  3476. - pr_err("%s : ERROR: failed to enable %s device\n", __func__,
  3477. - pci_name(pdev));
  3478. + dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
  3479. + __func__);
  3480. return ret;
  3481. }
  3482. - if (pci_request_regions(pdev, STMMAC_RESOURCE_NAME)) {
  3483. - pr_err("%s: ERROR: failed to get PCI region\n", __func__);
  3484. - ret = -ENODEV;
  3485. - goto err_out_req_reg_failed;
  3486. - }
  3487. /* Get the base address of device */
  3488. - for (i = 0; i <= 5; i++) {
  3489. + for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
  3490. if (pci_resource_len(pdev, i) == 0)
  3491. continue;
  3492. - addr = pci_iomap(pdev, i, 0);
  3493. - if (addr == NULL) {
  3494. - pr_err("%s: ERROR: cannot map register memory aborting",
  3495. - __func__);
  3496. - ret = -EIO;
  3497. - goto err_out_map_failed;
  3498. - }
  3499. + ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
  3500. + if (ret)
  3501. + return ret;
  3502. break;
  3503. }
  3504. - pci_set_master(pdev);
  3505. -
  3506. - stmmac_default_data();
  3507. - priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat, addr);
  3508. - if (IS_ERR(priv)) {
  3509. - pr_err("%s: main driver probe failed", __func__);
  3510. - ret = PTR_ERR(priv);
  3511. - goto err_out;
  3512. - }
  3513. - priv->dev->irq = pdev->irq;
  3514. - priv->wol_irq = pdev->irq;
  3515. -
  3516. - pci_set_drvdata(pdev, priv->dev);
  3517. + pci_set_master(pdev);
  3518. - pr_debug("STMMAC platform driver registration completed");
  3519. + if (info) {
  3520. + info->pdev = pdev;
  3521. + if (info->setup) {
  3522. + ret = info->setup(plat, info);
  3523. + if (ret)
  3524. + return ret;
  3525. + }
  3526. + } else
  3527. + stmmac_default_data(plat);
  3528. - return 0;
  3529. + pci_enable_msi(pdev);
  3530. -err_out:
  3531. - pci_clear_master(pdev);
  3532. -err_out_map_failed:
  3533. - pci_release_regions(pdev);
  3534. -err_out_req_reg_failed:
  3535. - pci_disable_device(pdev);
  3536. + memset(&res, 0, sizeof(res));
  3537. + res.addr = pcim_iomap_table(pdev)[i];
  3538. + res.wol_irq = pdev->irq;
  3539. + res.irq = pdev->irq;
  3540. - return ret;
  3541. + return stmmac_dvr_probe(&pdev->dev, plat, &res);
  3542. }
  3543. /**
  3544. @@ -141,61 +232,55 @@ err_out_req_reg_failed:
  3545. static void stmmac_pci_remove(struct pci_dev *pdev)
  3546. {
  3547. struct net_device *ndev = pci_get_drvdata(pdev);
  3548. - struct stmmac_priv *priv = netdev_priv(ndev);
  3549. stmmac_dvr_remove(ndev);
  3550. -
  3551. - pci_iounmap(pdev, priv->ioaddr);
  3552. - pci_release_regions(pdev);
  3553. - pci_disable_device(pdev);
  3554. }
  3555. -#ifdef CONFIG_PM
  3556. -static int stmmac_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  3557. +#ifdef CONFIG_PM_SLEEP
  3558. +static int stmmac_pci_suspend(struct device *dev)
  3559. {
  3560. + struct pci_dev *pdev = to_pci_dev(dev);
  3561. struct net_device *ndev = pci_get_drvdata(pdev);
  3562. - int ret;
  3563. -
  3564. - ret = stmmac_suspend(ndev);
  3565. - pci_save_state(pdev);
  3566. - pci_set_power_state(pdev, pci_choose_state(pdev, state));
  3567. - return ret;
  3568. + return stmmac_suspend(ndev);
  3569. }
  3570. -static int stmmac_pci_resume(struct pci_dev *pdev)
  3571. +static int stmmac_pci_resume(struct device *dev)
  3572. {
  3573. + struct pci_dev *pdev = to_pci_dev(dev);
  3574. struct net_device *ndev = pci_get_drvdata(pdev);
  3575. - pci_set_power_state(pdev, PCI_D0);
  3576. - pci_restore_state(pdev);
  3577. -
  3578. return stmmac_resume(ndev);
  3579. }
  3580. #endif
  3581. +static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_pci_suspend, stmmac_pci_resume);
  3582. +
  3583. #define STMMAC_VENDOR_ID 0x700
  3584. +#define STMMAC_QUARK_ID 0x0937
  3585. #define STMMAC_DEVICE_ID 0x1108
  3586. static const struct pci_device_id stmmac_id_table[] = {
  3587. {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
  3588. {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
  3589. + {PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info},
  3590. {}
  3591. };
  3592. MODULE_DEVICE_TABLE(pci, stmmac_id_table);
  3593. -struct pci_driver stmmac_pci_driver = {
  3594. +static struct pci_driver stmmac_pci_driver = {
  3595. .name = STMMAC_RESOURCE_NAME,
  3596. .id_table = stmmac_id_table,
  3597. .probe = stmmac_pci_probe,
  3598. .remove = stmmac_pci_remove,
  3599. -#ifdef CONFIG_PM
  3600. - .suspend = stmmac_pci_suspend,
  3601. - .resume = stmmac_pci_resume,
  3602. -#endif
  3603. + .driver = {
  3604. + .pm = &stmmac_pm_ops,
  3605. + },
  3606. };
  3607. +module_pci_driver(stmmac_pci_driver);
  3608. +
  3609. MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
  3610. MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
  3611. MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
  3612. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
  3613. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
  3614. @@ -23,41 +23,23 @@
  3615. *******************************************************************************/
  3616. #include <linux/platform_device.h>
  3617. +#include <linux/module.h>
  3618. #include <linux/io.h>
  3619. #include <linux/of.h>
  3620. #include <linux/of_net.h>
  3621. #include <linux/of_device.h>
  3622. -#include "stmmac.h"
  3623. +#include <linux/of_mdio.h>
  3624. -static const struct of_device_id stmmac_dt_ids[] = {
  3625. -#ifdef CONFIG_DWMAC_MESON
  3626. - { .compatible = "amlogic,meson6-dwmac", .data = &meson6_dwmac_data},
  3627. -#endif
  3628. -#ifdef CONFIG_DWMAC_SUNXI
  3629. - { .compatible = "allwinner,sun7i-a20-gmac", .data = &sun7i_gmac_data},
  3630. -#endif
  3631. -#ifdef CONFIG_DWMAC_STI
  3632. - { .compatible = "st,stih415-dwmac", .data = &stih4xx_dwmac_data},
  3633. - { .compatible = "st,stih416-dwmac", .data = &stih4xx_dwmac_data},
  3634. - { .compatible = "st,stid127-dwmac", .data = &stid127_dwmac_data},
  3635. - { .compatible = "st,stih407-dwmac", .data = &stih4xx_dwmac_data},
  3636. -#endif
  3637. -#ifdef CONFIG_DWMAC_SOCFPGA
  3638. - { .compatible = "altr,socfpga-stmmac", .data = &socfpga_gmac_data },
  3639. -#endif
  3640. - /* SoC specific glue layers should come before generic bindings */
  3641. - { .compatible = "st,spear600-gmac"},
  3642. - { .compatible = "snps,dwmac-3.610"},
  3643. - { .compatible = "snps,dwmac-3.70a"},
  3644. - { .compatible = "snps,dwmac-3.710"},
  3645. - { .compatible = "snps,dwmac"},
  3646. - { /* sentinel */ }
  3647. -};
  3648. -MODULE_DEVICE_TABLE(of, stmmac_dt_ids);
  3649. +#include "stmmac.h"
  3650. +#include "stmmac_platform.h"
  3651. #ifdef CONFIG_OF
  3652. -/* This function validates the number of Multicast filtering bins specified
  3653. +/**
  3654. + * dwmac1000_validate_mcast_bins - validates the number of Multicast filter bins
  3655. + * @mcast_bins: Multicast filtering bins
  3656. + * Description:
  3657. + * this function validates the number of Multicast filtering bins specified
  3658. * by the configuration through the device tree. The Synopsys GMAC supports
  3659. * 64 bins, 128 bins, or 256 bins. "bins" refer to the division of CRC
  3660. * number space. 64 bins correspond to 6 bits of the CRC, 128 corresponds
  3661. @@ -83,7 +65,11 @@ static int dwmac1000_validate_mcast_bins
  3662. return x;
  3663. }
  3664. -/* This function validates the number of Unicast address entries supported
  3665. +/**
  3666. + * dwmac1000_validate_ucast_entries - validate the Unicast address entries
  3667. + * @ucast_entries: number of Unicast address entries
  3668. + * Description:
  3669. + * This function validates the number of Unicast address entries supported
  3670. * by a particular Synopsys 10/100/1000 controller. The Synopsys controller
  3671. * supports 1, 32, 64, or 128 Unicast filter entries for it's Unicast filter
  3672. * logic. This function validates a valid, supported configuration is
  3673. @@ -109,37 +95,25 @@ static int dwmac1000_validate_ucast_entr
  3674. return x;
  3675. }
  3676. -static int stmmac_probe_config_dt(struct platform_device *pdev,
  3677. - struct plat_stmmacenet_data *plat,
  3678. - const char **mac)
  3679. +/**
  3680. + * stmmac_probe_config_dt - parse device-tree driver parameters
  3681. + * @pdev: platform_device structure
  3682. + * @plat: driver data platform structure
  3683. + * @mac: MAC address to use
  3684. + * Description:
  3685. + * this function is to read the driver parameters from device-tree and
  3686. + * set some private fields that will be used by the main at runtime.
  3687. + */
  3688. +struct plat_stmmacenet_data *
  3689. +stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
  3690. {
  3691. struct device_node *np = pdev->dev.of_node;
  3692. + struct plat_stmmacenet_data *plat;
  3693. struct stmmac_dma_cfg *dma_cfg;
  3694. - const struct of_device_id *device;
  3695. - if (!np)
  3696. - return -ENODEV;
  3697. -
  3698. - device = of_match_device(stmmac_dt_ids, &pdev->dev);
  3699. - if (!device)
  3700. - return -ENODEV;
  3701. -
  3702. - if (device->data) {
  3703. - const struct stmmac_of_data *data = device->data;
  3704. - plat->has_gmac = data->has_gmac;
  3705. - plat->enh_desc = data->enh_desc;
  3706. - plat->tx_coe = data->tx_coe;
  3707. - plat->rx_coe = data->rx_coe;
  3708. - plat->bugged_jumbo = data->bugged_jumbo;
  3709. - plat->pmt = data->pmt;
  3710. - plat->riwt_off = data->riwt_off;
  3711. - plat->fix_mac_speed = data->fix_mac_speed;
  3712. - plat->bus_setup = data->bus_setup;
  3713. - plat->setup = data->setup;
  3714. - plat->free = data->free;
  3715. - plat->init = data->init;
  3716. - plat->exit = data->exit;
  3717. - }
  3718. + plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
  3719. + if (!plat)
  3720. + return ERR_PTR(-ENOMEM);
  3721. *mac = of_get_mac_address(np);
  3722. plat->interface = of_get_phy_mode(np);
  3723. @@ -155,13 +129,24 @@ static int stmmac_probe_config_dt(struct
  3724. /* Default to phy auto-detection */
  3725. plat->phy_addr = -1;
  3726. + /* If we find a phy-handle property, use it as the PHY */
  3727. + plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
  3728. +
  3729. + /* If phy-handle is not specified, check if we have a fixed-phy */
  3730. + if (!plat->phy_node && of_phy_is_fixed_link(np)) {
  3731. + if ((of_phy_register_fixed_link(np) < 0))
  3732. + return ERR_PTR(-ENODEV);
  3733. +
  3734. + plat->phy_node = of_node_get(np);
  3735. + }
  3736. +
  3737. /* "snps,phy-addr" is not a standard property. Mark it as deprecated
  3738. * and warn of its use. Remove this when phy node support is added.
  3739. */
  3740. if (of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr) == 0)
  3741. dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n");
  3742. - if (plat->phy_bus_name)
  3743. + if (plat->phy_node || plat->phy_bus_name)
  3744. plat->mdio_bus_data = NULL;
  3745. else
  3746. plat->mdio_bus_data =
  3747. @@ -169,6 +154,10 @@ static int stmmac_probe_config_dt(struct
  3748. sizeof(struct stmmac_mdio_bus_data),
  3749. GFP_KERNEL);
  3750. + of_property_read_u32(np, "tx-fifo-depth", &plat->tx_fifo_size);
  3751. +
  3752. + of_property_read_u32(np, "rx-fifo-depth", &plat->rx_fifo_size);
  3753. +
  3754. plat->force_sf_dma_mode =
  3755. of_property_read_bool(np, "snps,force_sf_dma_mode");
  3756. @@ -177,6 +166,12 @@ static int stmmac_probe_config_dt(struct
  3757. */
  3758. plat->maxmtu = JUMBO_LEN;
  3759. + /* Set default value for multicast hash bins */
  3760. + plat->multicast_filter_bins = HASH_TABLE_SIZE;
  3761. +
  3762. + /* Set default value for unicast filter entries */
  3763. + plat->unicast_filter_entries = 1;
  3764. +
  3765. /*
  3766. * Currently only the properties needed on SPEAr600
  3767. * are provided. All other properties should be added
  3768. @@ -215,14 +210,19 @@ static int stmmac_probe_config_dt(struct
  3769. if (of_find_property(np, "snps,pbl", NULL)) {
  3770. dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg),
  3771. GFP_KERNEL);
  3772. - if (!dma_cfg)
  3773. - return -ENOMEM;
  3774. + if (!dma_cfg) {
  3775. + of_node_put(np);
  3776. + return ERR_PTR(-ENOMEM);
  3777. + }
  3778. plat->dma_cfg = dma_cfg;
  3779. of_property_read_u32(np, "snps,pbl", &dma_cfg->pbl);
  3780. dma_cfg->fixed_burst =
  3781. of_property_read_bool(np, "snps,fixed-burst");
  3782. dma_cfg->mixed_burst =
  3783. of_property_read_bool(np, "snps,mixed-burst");
  3784. + of_property_read_u32(np, "snps,burst_len", &dma_cfg->burst_len);
  3785. + if (dma_cfg->burst_len < 0 || dma_cfg->burst_len > 256)
  3786. + dma_cfg->burst_len = 0;
  3787. }
  3788. plat->force_thresh_dma_mode = of_property_read_bool(np, "snps,force_thresh_dma_mode");
  3789. if (plat->force_thresh_dma_mode) {
  3790. @@ -230,123 +230,60 @@ static int stmmac_probe_config_dt(struct
  3791. pr_warn("force_sf_dma_mode is ignored if force_thresh_dma_mode is set.");
  3792. }
  3793. - return 0;
  3794. + return plat;
  3795. }
  3796. #else
  3797. -static int stmmac_probe_config_dt(struct platform_device *pdev,
  3798. - struct plat_stmmacenet_data *plat,
  3799. - const char **mac)
  3800. +struct plat_stmmacenet_data *
  3801. +stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
  3802. {
  3803. - return -ENOSYS;
  3804. + return ERR_PTR(-ENOSYS);
  3805. }
  3806. #endif /* CONFIG_OF */
  3807. +EXPORT_SYMBOL_GPL(stmmac_probe_config_dt);
  3808. -/**
  3809. - * stmmac_pltfr_probe
  3810. - * @pdev: platform device pointer
  3811. - * Description: platform_device probe function. It allocates
  3812. - * the necessary resources and invokes the main to init
  3813. - * the net device, register the mdio bus etc.
  3814. - */
  3815. -static int stmmac_pltfr_probe(struct platform_device *pdev)
  3816. +int stmmac_get_platform_resources(struct platform_device *pdev,
  3817. + struct stmmac_resources *stmmac_res)
  3818. {
  3819. - int ret = 0;
  3820. struct resource *res;
  3821. - struct device *dev = &pdev->dev;
  3822. - void __iomem *addr = NULL;
  3823. - struct stmmac_priv *priv = NULL;
  3824. - struct plat_stmmacenet_data *plat_dat = NULL;
  3825. - const char *mac = NULL;
  3826. -
  3827. - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  3828. - addr = devm_ioremap_resource(dev, res);
  3829. - if (IS_ERR(addr))
  3830. - return PTR_ERR(addr);
  3831. -
  3832. - plat_dat = dev_get_platdata(&pdev->dev);
  3833. -
  3834. - if (!plat_dat)
  3835. - plat_dat = devm_kzalloc(&pdev->dev,
  3836. - sizeof(struct plat_stmmacenet_data),
  3837. - GFP_KERNEL);
  3838. - if (!plat_dat) {
  3839. - pr_err("%s: ERROR: no memory", __func__);
  3840. - return -ENOMEM;
  3841. - }
  3842. -
  3843. - /* Set default value for multicast hash bins */
  3844. - plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
  3845. -
  3846. - /* Set default value for unicast filter entries */
  3847. - plat_dat->unicast_filter_entries = 1;
  3848. -
  3849. - if (pdev->dev.of_node) {
  3850. - ret = stmmac_probe_config_dt(pdev, plat_dat, &mac);
  3851. - if (ret) {
  3852. - pr_err("%s: main dt probe failed", __func__);
  3853. - return ret;
  3854. - }
  3855. - }
  3856. -
  3857. - /* Custom setup (if needed) */
  3858. - if (plat_dat->setup) {
  3859. - plat_dat->bsp_priv = plat_dat->setup(pdev);
  3860. - if (IS_ERR(plat_dat->bsp_priv))
  3861. - return PTR_ERR(plat_dat->bsp_priv);
  3862. - }
  3863. -
  3864. - /* Custom initialisation (if needed)*/
  3865. - if (plat_dat->init) {
  3866. - ret = plat_dat->init(pdev, plat_dat->bsp_priv);
  3867. - if (unlikely(ret))
  3868. - return ret;
  3869. - }
  3870. - priv = stmmac_dvr_probe(&(pdev->dev), plat_dat, addr);
  3871. - if (IS_ERR(priv)) {
  3872. - pr_err("%s: main driver probe failed", __func__);
  3873. - return PTR_ERR(priv);
  3874. - }
  3875. + memset(stmmac_res, 0, sizeof(*stmmac_res));
  3876. - /* Get MAC address if available (DT) */
  3877. - if (mac)
  3878. - memcpy(priv->dev->dev_addr, mac, ETH_ALEN);
  3879. -
  3880. - /* Get the MAC information */
  3881. - priv->dev->irq = platform_get_irq_byname(pdev, "macirq");
  3882. - if (priv->dev->irq < 0) {
  3883. - if (priv->dev->irq != -EPROBE_DEFER) {
  3884. - netdev_err(priv->dev,
  3885. - "MAC IRQ configuration information not found\n");
  3886. + /* Get IRQ information early to have an ability to ask for deferred
  3887. + * probe if needed before we went too far with resource allocation.
  3888. + */
  3889. + stmmac_res->irq = platform_get_irq_byname(pdev, "macirq");
  3890. + if (stmmac_res->irq < 0) {
  3891. + if (stmmac_res->irq != -EPROBE_DEFER) {
  3892. + dev_err(&pdev->dev,
  3893. + "MAC IRQ configuration information not found\n");
  3894. }
  3895. - return priv->dev->irq;
  3896. + return stmmac_res->irq;
  3897. }
  3898. - /*
  3899. - * On some platforms e.g. SPEAr the wake up irq differs from the mac irq
  3900. + /* On some platforms e.g. SPEAr the wake up irq differs from the mac irq
  3901. * The external wake up irq can be passed through the platform code
  3902. * named as "eth_wake_irq"
  3903. *
  3904. * In case the wake up interrupt is not passed from the platform
  3905. * so the driver will continue to use the mac irq (ndev->irq)
  3906. */
  3907. - priv->wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
  3908. - if (priv->wol_irq < 0) {
  3909. - if (priv->wol_irq == -EPROBE_DEFER)
  3910. + stmmac_res->wol_irq = platform_get_irq_byname(pdev, "eth_wake_irq");
  3911. + if (stmmac_res->wol_irq < 0) {
  3912. + if (stmmac_res->wol_irq == -EPROBE_DEFER)
  3913. return -EPROBE_DEFER;
  3914. - priv->wol_irq = priv->dev->irq;
  3915. + stmmac_res->wol_irq = stmmac_res->irq;
  3916. }
  3917. - priv->lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
  3918. - if (priv->lpi_irq == -EPROBE_DEFER)
  3919. + stmmac_res->lpi_irq = platform_get_irq_byname(pdev, "eth_lpi");
  3920. + if (stmmac_res->lpi_irq == -EPROBE_DEFER)
  3921. return -EPROBE_DEFER;
  3922. - platform_set_drvdata(pdev, priv->dev);
  3923. -
  3924. - pr_debug("STMMAC platform driver registration completed");
  3925. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  3926. + stmmac_res->addr = devm_ioremap_resource(&pdev->dev, res);
  3927. - return 0;
  3928. + return PTR_ERR_OR_ZERO(stmmac_res->addr);
  3929. }
  3930. +EXPORT_SYMBOL_GPL(stmmac_get_platform_resources);
  3931. /**
  3932. * stmmac_pltfr_remove
  3933. @@ -354,7 +291,7 @@ static int stmmac_pltfr_probe(struct pla
  3934. * Description: this function calls the main to free the net resources
  3935. * and calls the platforms hook and release the resources (e.g. mem).
  3936. */
  3937. -static int stmmac_pltfr_remove(struct platform_device *pdev)
  3938. +int stmmac_pltfr_remove(struct platform_device *pdev)
  3939. {
  3940. struct net_device *ndev = platform_get_drvdata(pdev);
  3941. struct stmmac_priv *priv = netdev_priv(ndev);
  3942. @@ -363,13 +300,18 @@ static int stmmac_pltfr_remove(struct pl
  3943. if (priv->plat->exit)
  3944. priv->plat->exit(pdev, priv->plat->bsp_priv);
  3945. - if (priv->plat->free)
  3946. - priv->plat->free(pdev, priv->plat->bsp_priv);
  3947. -
  3948. return ret;
  3949. }
  3950. +EXPORT_SYMBOL_GPL(stmmac_pltfr_remove);
  3951. -#ifdef CONFIG_PM
  3952. +#ifdef CONFIG_PM_SLEEP
  3953. +/**
  3954. + * stmmac_pltfr_suspend
  3955. + * @dev: device pointer
  3956. + * Description: this function is invoked when suspend the driver and it direcly
  3957. + * call the main suspend function and then, if required, on some platform, it
  3958. + * can call an exit helper.
  3959. + */
  3960. static int stmmac_pltfr_suspend(struct device *dev)
  3961. {
  3962. int ret;
  3963. @@ -384,6 +326,13 @@ static int stmmac_pltfr_suspend(struct d
  3964. return ret;
  3965. }
  3966. +/**
  3967. + * stmmac_pltfr_resume
  3968. + * @dev: device pointer
  3969. + * Description: this function is invoked when resume the driver before calling
  3970. + * the main resume function, on some platforms, it can call own init helper
  3971. + * if required.
  3972. + */
  3973. static int stmmac_pltfr_resume(struct device *dev)
  3974. {
  3975. struct net_device *ndev = dev_get_drvdata(dev);
  3976. @@ -395,23 +344,12 @@ static int stmmac_pltfr_resume(struct de
  3977. return stmmac_resume(ndev);
  3978. }
  3979. +#endif /* CONFIG_PM_SLEEP */
  3980. -#endif /* CONFIG_PM */
  3981. -
  3982. -static SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops,
  3983. - stmmac_pltfr_suspend, stmmac_pltfr_resume);
  3984. -
  3985. -struct platform_driver stmmac_pltfr_driver = {
  3986. - .probe = stmmac_pltfr_probe,
  3987. - .remove = stmmac_pltfr_remove,
  3988. - .driver = {
  3989. - .name = STMMAC_RESOURCE_NAME,
  3990. - .owner = THIS_MODULE,
  3991. - .pm = &stmmac_pltfr_pm_ops,
  3992. - .of_match_table = of_match_ptr(stmmac_dt_ids),
  3993. - },
  3994. -};
  3995. +SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops, stmmac_pltfr_suspend,
  3996. + stmmac_pltfr_resume);
  3997. +EXPORT_SYMBOL_GPL(stmmac_pltfr_pm_ops);
  3998. -MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PLATFORM driver");
  3999. +MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet platform support");
  4000. MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
  4001. MODULE_LICENSE("GPL");
  4002. --- /dev/null
  4003. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
  4004. @@ -0,0 +1,33 @@
  4005. +/*******************************************************************************
  4006. + Copyright (C) 2007-2009 STMicroelectronics Ltd
  4007. +
  4008. + This program is free software; you can redistribute it and/or modify it
  4009. + under the terms and conditions of the GNU General Public License,
  4010. + version 2, as published by the Free Software Foundation.
  4011. +
  4012. + This program is distributed in the hope it will be useful, but WITHOUT
  4013. + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4014. + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  4015. + more details.
  4016. +
  4017. + The full GNU General Public License is included in this distribution in
  4018. + the file called "COPYING".
  4019. +
  4020. + Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  4021. +*******************************************************************************/
  4022. +
  4023. +#ifndef __STMMAC_PLATFORM_H__
  4024. +#define __STMMAC_PLATFORM_H__
  4025. +
  4026. +#include "stmmac.h"
  4027. +
  4028. +struct plat_stmmacenet_data *
  4029. +stmmac_probe_config_dt(struct platform_device *pdev, const char **mac);
  4030. +
  4031. +int stmmac_get_platform_resources(struct platform_device *pdev,
  4032. + struct stmmac_resources *stmmac_res);
  4033. +
  4034. +int stmmac_pltfr_remove(struct platform_device *pdev);
  4035. +extern const struct dev_pm_ops stmmac_pltfr_pm_ops;
  4036. +
  4037. +#endif /* __STMMAC_PLATFORM_H__ */