mvneta.c 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298
  1. /*
  2. * Driver for Marvell NETA network card for Armada XP and Armada 370 SoCs.
  3. *
  4. * Copyright (C) 2012 Marvell
  5. *
  6. * Rami Rosen <rosenr@marvell.com>
  7. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/cpu.h>
  15. #include <linux/etherdevice.h>
  16. #include <linux/if_vlan.h>
  17. #include <linux/inetdevice.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/io.h>
  20. #include <linux/kernel.h>
  21. #include <linux/mbus.h>
  22. #include <linux/module.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/of.h>
  25. #include <linux/of_address.h>
  26. #include <linux/of_irq.h>
  27. #include <linux/of_mdio.h>
  28. #include <linux/of_net.h>
  29. #include <linux/phy.h>
  30. #include <linux/phy_fixed.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/skbuff.h>
  33. #include <net/hwbm.h>
  34. #include "mvneta_bm.h"
  35. #include <net/ip.h>
  36. #include <net/ipv6.h>
  37. #include <net/tso.h>
  38. /* Registers */
  39. #define MVNETA_RXQ_CONFIG_REG(q) (0x1400 + ((q) << 2))
  40. #define MVNETA_RXQ_HW_BUF_ALLOC BIT(0)
  41. #define MVNETA_RXQ_SHORT_POOL_ID_SHIFT 4
  42. #define MVNETA_RXQ_SHORT_POOL_ID_MASK 0x30
  43. #define MVNETA_RXQ_LONG_POOL_ID_SHIFT 6
  44. #define MVNETA_RXQ_LONG_POOL_ID_MASK 0xc0
  45. #define MVNETA_RXQ_PKT_OFFSET_ALL_MASK (0xf << 8)
  46. #define MVNETA_RXQ_PKT_OFFSET_MASK(offs) ((offs) << 8)
  47. #define MVNETA_RXQ_THRESHOLD_REG(q) (0x14c0 + ((q) << 2))
  48. #define MVNETA_RXQ_NON_OCCUPIED(v) ((v) << 16)
  49. #define MVNETA_RXQ_BASE_ADDR_REG(q) (0x1480 + ((q) << 2))
  50. #define MVNETA_RXQ_SIZE_REG(q) (0x14a0 + ((q) << 2))
  51. #define MVNETA_RXQ_BUF_SIZE_SHIFT 19
  52. #define MVNETA_RXQ_BUF_SIZE_MASK (0x1fff << 19)
  53. #define MVNETA_RXQ_STATUS_REG(q) (0x14e0 + ((q) << 2))
  54. #define MVNETA_RXQ_OCCUPIED_ALL_MASK 0x3fff
  55. #define MVNETA_RXQ_STATUS_UPDATE_REG(q) (0x1500 + ((q) << 2))
  56. #define MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT 16
  57. #define MVNETA_RXQ_ADD_NON_OCCUPIED_MAX 255
  58. #define MVNETA_PORT_POOL_BUFFER_SZ_REG(pool) (0x1700 + ((pool) << 2))
  59. #define MVNETA_PORT_POOL_BUFFER_SZ_SHIFT 3
  60. #define MVNETA_PORT_POOL_BUFFER_SZ_MASK 0xfff8
  61. #define MVNETA_PORT_RX_RESET 0x1cc0
  62. #define MVNETA_PORT_RX_DMA_RESET BIT(0)
  63. #define MVNETA_PHY_ADDR 0x2000
  64. #define MVNETA_PHY_ADDR_MASK 0x1f
  65. #define MVNETA_MBUS_RETRY 0x2010
  66. #define MVNETA_UNIT_INTR_CAUSE 0x2080
  67. #define MVNETA_UNIT_CONTROL 0x20B0
  68. #define MVNETA_PHY_POLLING_ENABLE BIT(1)
  69. #define MVNETA_WIN_BASE(w) (0x2200 + ((w) << 3))
  70. #define MVNETA_WIN_SIZE(w) (0x2204 + ((w) << 3))
  71. #define MVNETA_WIN_REMAP(w) (0x2280 + ((w) << 2))
  72. #define MVNETA_BASE_ADDR_ENABLE 0x2290
  73. #define MVNETA_ACCESS_PROTECT_ENABLE 0x2294
  74. #define MVNETA_PORT_CONFIG 0x2400
  75. #define MVNETA_UNI_PROMISC_MODE BIT(0)
  76. #define MVNETA_DEF_RXQ(q) ((q) << 1)
  77. #define MVNETA_DEF_RXQ_ARP(q) ((q) << 4)
  78. #define MVNETA_TX_UNSET_ERR_SUM BIT(12)
  79. #define MVNETA_DEF_RXQ_TCP(q) ((q) << 16)
  80. #define MVNETA_DEF_RXQ_UDP(q) ((q) << 19)
  81. #define MVNETA_DEF_RXQ_BPDU(q) ((q) << 22)
  82. #define MVNETA_RX_CSUM_WITH_PSEUDO_HDR BIT(25)
  83. #define MVNETA_PORT_CONFIG_DEFL_VALUE(q) (MVNETA_DEF_RXQ(q) | \
  84. MVNETA_DEF_RXQ_ARP(q) | \
  85. MVNETA_DEF_RXQ_TCP(q) | \
  86. MVNETA_DEF_RXQ_UDP(q) | \
  87. MVNETA_DEF_RXQ_BPDU(q) | \
  88. MVNETA_TX_UNSET_ERR_SUM | \
  89. MVNETA_RX_CSUM_WITH_PSEUDO_HDR)
  90. #define MVNETA_PORT_CONFIG_EXTEND 0x2404
  91. #define MVNETA_MAC_ADDR_LOW 0x2414
  92. #define MVNETA_MAC_ADDR_HIGH 0x2418
  93. #define MVNETA_SDMA_CONFIG 0x241c
  94. #define MVNETA_SDMA_BRST_SIZE_16 4
  95. #define MVNETA_RX_BRST_SZ_MASK(burst) ((burst) << 1)
  96. #define MVNETA_RX_NO_DATA_SWAP BIT(4)
  97. #define MVNETA_TX_NO_DATA_SWAP BIT(5)
  98. #define MVNETA_DESC_SWAP BIT(6)
  99. #define MVNETA_TX_BRST_SZ_MASK(burst) ((burst) << 22)
  100. #define MVNETA_PORT_STATUS 0x2444
  101. #define MVNETA_TX_IN_PRGRS BIT(1)
  102. #define MVNETA_TX_FIFO_EMPTY BIT(8)
  103. #define MVNETA_RX_MIN_FRAME_SIZE 0x247c
  104. #define MVNETA_SERDES_CFG 0x24A0
  105. #define MVNETA_SGMII_SERDES_PROTO 0x0cc7
  106. #define MVNETA_QSGMII_SERDES_PROTO 0x0667
  107. #define MVNETA_TYPE_PRIO 0x24bc
  108. #define MVNETA_FORCE_UNI BIT(21)
  109. #define MVNETA_TXQ_CMD_1 0x24e4
  110. #define MVNETA_TXQ_CMD 0x2448
  111. #define MVNETA_TXQ_DISABLE_SHIFT 8
  112. #define MVNETA_TXQ_ENABLE_MASK 0x000000ff
  113. #define MVNETA_RX_DISCARD_FRAME_COUNT 0x2484
  114. #define MVNETA_OVERRUN_FRAME_COUNT 0x2488
  115. #define MVNETA_GMAC_CLOCK_DIVIDER 0x24f4
  116. #define MVNETA_GMAC_1MS_CLOCK_ENABLE BIT(31)
  117. #define MVNETA_ACC_MODE 0x2500
  118. #define MVNETA_BM_ADDRESS 0x2504
  119. #define MVNETA_CPU_MAP(cpu) (0x2540 + ((cpu) << 2))
  120. #define MVNETA_CPU_RXQ_ACCESS_ALL_MASK 0x000000ff
  121. #define MVNETA_CPU_TXQ_ACCESS_ALL_MASK 0x0000ff00
  122. #define MVNETA_CPU_RXQ_ACCESS(rxq) BIT(rxq)
  123. #define MVNETA_CPU_TXQ_ACCESS(txq) BIT(txq + 8)
  124. #define MVNETA_RXQ_TIME_COAL_REG(q) (0x2580 + ((q) << 2))
  125. /* Exception Interrupt Port/Queue Cause register
  126. *
  127. * Their behavior depend of the mapping done using the PCPX2Q
  128. * registers. For a given CPU if the bit associated to a queue is not
  129. * set, then for the register a read from this CPU will always return
  130. * 0 and a write won't do anything
  131. */
  132. #define MVNETA_INTR_NEW_CAUSE 0x25a0
  133. #define MVNETA_INTR_NEW_MASK 0x25a4
  134. /* bits 0..7 = TXQ SENT, one bit per queue.
  135. * bits 8..15 = RXQ OCCUP, one bit per queue.
  136. * bits 16..23 = RXQ FREE, one bit per queue.
  137. * bit 29 = OLD_REG_SUM, see old reg ?
  138. * bit 30 = TX_ERR_SUM, one bit for 4 ports
  139. * bit 31 = MISC_SUM, one bit for 4 ports
  140. */
  141. #define MVNETA_TX_INTR_MASK(nr_txqs) (((1 << nr_txqs) - 1) << 0)
  142. #define MVNETA_TX_INTR_MASK_ALL (0xff << 0)
  143. #define MVNETA_RX_INTR_MASK(nr_rxqs) (((1 << nr_rxqs) - 1) << 8)
  144. #define MVNETA_RX_INTR_MASK_ALL (0xff << 8)
  145. #define MVNETA_MISCINTR_INTR_MASK BIT(31)
  146. #define MVNETA_INTR_OLD_CAUSE 0x25a8
  147. #define MVNETA_INTR_OLD_MASK 0x25ac
  148. /* Data Path Port/Queue Cause Register */
  149. #define MVNETA_INTR_MISC_CAUSE 0x25b0
  150. #define MVNETA_INTR_MISC_MASK 0x25b4
  151. #define MVNETA_CAUSE_PHY_STATUS_CHANGE BIT(0)
  152. #define MVNETA_CAUSE_LINK_CHANGE BIT(1)
  153. #define MVNETA_CAUSE_PTP BIT(4)
  154. #define MVNETA_CAUSE_INTERNAL_ADDR_ERR BIT(7)
  155. #define MVNETA_CAUSE_RX_OVERRUN BIT(8)
  156. #define MVNETA_CAUSE_RX_CRC_ERROR BIT(9)
  157. #define MVNETA_CAUSE_RX_LARGE_PKT BIT(10)
  158. #define MVNETA_CAUSE_TX_UNDERUN BIT(11)
  159. #define MVNETA_CAUSE_PRBS_ERR BIT(12)
  160. #define MVNETA_CAUSE_PSC_SYNC_CHANGE BIT(13)
  161. #define MVNETA_CAUSE_SERDES_SYNC_ERR BIT(14)
  162. #define MVNETA_CAUSE_BMU_ALLOC_ERR_SHIFT 16
  163. #define MVNETA_CAUSE_BMU_ALLOC_ERR_ALL_MASK (0xF << MVNETA_CAUSE_BMU_ALLOC_ERR_SHIFT)
  164. #define MVNETA_CAUSE_BMU_ALLOC_ERR_MASK(pool) (1 << (MVNETA_CAUSE_BMU_ALLOC_ERR_SHIFT + (pool)))
  165. #define MVNETA_CAUSE_TXQ_ERROR_SHIFT 24
  166. #define MVNETA_CAUSE_TXQ_ERROR_ALL_MASK (0xFF << MVNETA_CAUSE_TXQ_ERROR_SHIFT)
  167. #define MVNETA_CAUSE_TXQ_ERROR_MASK(q) (1 << (MVNETA_CAUSE_TXQ_ERROR_SHIFT + (q)))
  168. #define MVNETA_INTR_ENABLE 0x25b8
  169. #define MVNETA_TXQ_INTR_ENABLE_ALL_MASK 0x0000ff00
  170. #define MVNETA_RXQ_INTR_ENABLE_ALL_MASK 0x000000ff
  171. #define MVNETA_RXQ_CMD 0x2680
  172. #define MVNETA_RXQ_DISABLE_SHIFT 8
  173. #define MVNETA_RXQ_ENABLE_MASK 0x000000ff
  174. #define MVETH_TXQ_TOKEN_COUNT_REG(q) (0x2700 + ((q) << 4))
  175. #define MVETH_TXQ_TOKEN_CFG_REG(q) (0x2704 + ((q) << 4))
  176. #define MVNETA_GMAC_CTRL_0 0x2c00
  177. #define MVNETA_GMAC_MAX_RX_SIZE_SHIFT 2
  178. #define MVNETA_GMAC_MAX_RX_SIZE_MASK 0x7ffc
  179. #define MVNETA_GMAC0_PORT_ENABLE BIT(0)
  180. #define MVNETA_GMAC_CTRL_2 0x2c08
  181. #define MVNETA_GMAC2_INBAND_AN_ENABLE BIT(0)
  182. #define MVNETA_GMAC2_PCS_ENABLE BIT(3)
  183. #define MVNETA_GMAC2_PORT_RGMII BIT(4)
  184. #define MVNETA_GMAC2_PORT_RESET BIT(6)
  185. #define MVNETA_GMAC_STATUS 0x2c10
  186. #define MVNETA_GMAC_LINK_UP BIT(0)
  187. #define MVNETA_GMAC_SPEED_1000 BIT(1)
  188. #define MVNETA_GMAC_SPEED_100 BIT(2)
  189. #define MVNETA_GMAC_FULL_DUPLEX BIT(3)
  190. #define MVNETA_GMAC_RX_FLOW_CTRL_ENABLE BIT(4)
  191. #define MVNETA_GMAC_TX_FLOW_CTRL_ENABLE BIT(5)
  192. #define MVNETA_GMAC_RX_FLOW_CTRL_ACTIVE BIT(6)
  193. #define MVNETA_GMAC_TX_FLOW_CTRL_ACTIVE BIT(7)
  194. #define MVNETA_GMAC_AUTONEG_CONFIG 0x2c0c
  195. #define MVNETA_GMAC_FORCE_LINK_DOWN BIT(0)
  196. #define MVNETA_GMAC_FORCE_LINK_PASS BIT(1)
  197. #define MVNETA_GMAC_INBAND_AN_ENABLE BIT(2)
  198. #define MVNETA_GMAC_CONFIG_MII_SPEED BIT(5)
  199. #define MVNETA_GMAC_CONFIG_GMII_SPEED BIT(6)
  200. #define MVNETA_GMAC_AN_SPEED_EN BIT(7)
  201. #define MVNETA_GMAC_AN_FLOW_CTRL_EN BIT(11)
  202. #define MVNETA_GMAC_CONFIG_FULL_DUPLEX BIT(12)
  203. #define MVNETA_GMAC_AN_DUPLEX_EN BIT(13)
  204. #define MVNETA_MIB_COUNTERS_BASE 0x3000
  205. #define MVNETA_MIB_LATE_COLLISION 0x7c
  206. #define MVNETA_DA_FILT_SPEC_MCAST 0x3400
  207. #define MVNETA_DA_FILT_OTH_MCAST 0x3500
  208. #define MVNETA_DA_FILT_UCAST_BASE 0x3600
  209. #define MVNETA_TXQ_BASE_ADDR_REG(q) (0x3c00 + ((q) << 2))
  210. #define MVNETA_TXQ_SIZE_REG(q) (0x3c20 + ((q) << 2))
  211. #define MVNETA_TXQ_SENT_THRESH_ALL_MASK 0x3fff0000
  212. #define MVNETA_TXQ_SENT_THRESH_MASK(coal) ((coal) << 16)
  213. #define MVNETA_TXQ_UPDATE_REG(q) (0x3c60 + ((q) << 2))
  214. #define MVNETA_TXQ_DEC_SENT_SHIFT 16
  215. #define MVNETA_TXQ_STATUS_REG(q) (0x3c40 + ((q) << 2))
  216. #define MVNETA_TXQ_SENT_DESC_SHIFT 16
  217. #define MVNETA_TXQ_SENT_DESC_MASK 0x3fff0000
  218. #define MVNETA_PORT_TX_RESET 0x3cf0
  219. #define MVNETA_PORT_TX_DMA_RESET BIT(0)
  220. #define MVNETA_TX_MTU 0x3e0c
  221. #define MVNETA_TX_TOKEN_SIZE 0x3e14
  222. #define MVNETA_TX_TOKEN_SIZE_MAX 0xffffffff
  223. #define MVNETA_TXQ_TOKEN_SIZE_REG(q) (0x3e40 + ((q) << 2))
  224. #define MVNETA_TXQ_TOKEN_SIZE_MAX 0x7fffffff
  225. #define MVNETA_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff
  226. /* Descriptor ring Macros */
  227. #define MVNETA_QUEUE_NEXT_DESC(q, index) \
  228. (((index) < (q)->last_desc) ? ((index) + 1) : 0)
  229. /* Various constants */
  230. /* Coalescing */
  231. #define MVNETA_TXDONE_COAL_PKTS 0 /* interrupt per packet */
  232. #define MVNETA_RX_COAL_PKTS 32
  233. #define MVNETA_RX_COAL_USEC 100
  234. /* The two bytes Marvell header. Either contains a special value used
  235. * by Marvell switches when a specific hardware mode is enabled (not
  236. * supported by this driver) or is filled automatically by zeroes on
  237. * the RX side. Those two bytes being at the front of the Ethernet
  238. * header, they allow to have the IP header aligned on a 4 bytes
  239. * boundary automatically: the hardware skips those two bytes on its
  240. * own.
  241. */
  242. #define MVNETA_MH_SIZE 2
  243. #define MVNETA_VLAN_TAG_LEN 4
  244. #define MVNETA_TX_CSUM_DEF_SIZE 1600
  245. #define MVNETA_TX_CSUM_MAX_SIZE 9800
  246. #define MVNETA_ACC_MODE_EXT1 1
  247. #define MVNETA_ACC_MODE_EXT2 2
  248. #define MVNETA_MAX_DECODE_WIN 6
  249. /* Timeout constants */
  250. #define MVNETA_TX_DISABLE_TIMEOUT_MSEC 1000
  251. #define MVNETA_RX_DISABLE_TIMEOUT_MSEC 1000
  252. #define MVNETA_TX_FIFO_EMPTY_TIMEOUT 10000
  253. #define MVNETA_TX_MTU_MAX 0x3ffff
  254. /* The RSS lookup table actually has 256 entries but we do not use
  255. * them yet
  256. */
  257. #define MVNETA_RSS_LU_TABLE_SIZE 1
  258. /* TSO header size */
  259. #define TSO_HEADER_SIZE 128
  260. /* Max number of Rx descriptors */
  261. #define MVNETA_MAX_RXD 128
  262. /* Max number of Tx descriptors */
  263. #define MVNETA_MAX_TXD 532
  264. /* Max number of allowed TCP segments for software TSO */
  265. #define MVNETA_MAX_TSO_SEGS 100
  266. #define MVNETA_MAX_SKB_DESCS (MVNETA_MAX_TSO_SEGS * 2 + MAX_SKB_FRAGS)
  267. /* descriptor aligned size */
  268. #define MVNETA_DESC_ALIGNED_SIZE 32
  269. #define MVNETA_RX_PKT_SIZE(mtu) \
  270. ALIGN((mtu) + MVNETA_MH_SIZE + MVNETA_VLAN_TAG_LEN + \
  271. ETH_HLEN + ETH_FCS_LEN, \
  272. cache_line_size())
  273. #define IS_TSO_HEADER(txq, addr) \
  274. ((addr >= txq->tso_hdrs_phys) && \
  275. (addr < txq->tso_hdrs_phys + txq->size * TSO_HEADER_SIZE))
  276. #define MVNETA_RX_GET_BM_POOL_ID(rxd) \
  277. (((rxd)->status & MVNETA_RXD_BM_POOL_MASK) >> MVNETA_RXD_BM_POOL_SHIFT)
  278. struct mvneta_statistic {
  279. unsigned short offset;
  280. unsigned short type;
  281. const char name[ETH_GSTRING_LEN];
  282. };
  283. #define T_REG_32 32
  284. #define T_REG_64 64
  285. static const struct mvneta_statistic mvneta_statistics[] = {
  286. { 0x3000, T_REG_64, "good_octets_received", },
  287. { 0x3010, T_REG_32, "good_frames_received", },
  288. { 0x3008, T_REG_32, "bad_octets_received", },
  289. { 0x3014, T_REG_32, "bad_frames_received", },
  290. { 0x3018, T_REG_32, "broadcast_frames_received", },
  291. { 0x301c, T_REG_32, "multicast_frames_received", },
  292. { 0x3050, T_REG_32, "unrec_mac_control_received", },
  293. { 0x3058, T_REG_32, "good_fc_received", },
  294. { 0x305c, T_REG_32, "bad_fc_received", },
  295. { 0x3060, T_REG_32, "undersize_received", },
  296. { 0x3064, T_REG_32, "fragments_received", },
  297. { 0x3068, T_REG_32, "oversize_received", },
  298. { 0x306c, T_REG_32, "jabber_received", },
  299. { 0x3070, T_REG_32, "mac_receive_error", },
  300. { 0x3074, T_REG_32, "bad_crc_event", },
  301. { 0x3078, T_REG_32, "collision", },
  302. { 0x307c, T_REG_32, "late_collision", },
  303. { 0x2484, T_REG_32, "rx_discard", },
  304. { 0x2488, T_REG_32, "rx_overrun", },
  305. { 0x3020, T_REG_32, "frames_64_octets", },
  306. { 0x3024, T_REG_32, "frames_65_to_127_octets", },
  307. { 0x3028, T_REG_32, "frames_128_to_255_octets", },
  308. { 0x302c, T_REG_32, "frames_256_to_511_octets", },
  309. { 0x3030, T_REG_32, "frames_512_to_1023_octets", },
  310. { 0x3034, T_REG_32, "frames_1024_to_max_octets", },
  311. { 0x3038, T_REG_64, "good_octets_sent", },
  312. { 0x3040, T_REG_32, "good_frames_sent", },
  313. { 0x3044, T_REG_32, "excessive_collision", },
  314. { 0x3048, T_REG_32, "multicast_frames_sent", },
  315. { 0x304c, T_REG_32, "broadcast_frames_sent", },
  316. { 0x3054, T_REG_32, "fc_sent", },
  317. { 0x300c, T_REG_32, "internal_mac_transmit_err", },
  318. };
  319. struct mvneta_pcpu_stats {
  320. struct u64_stats_sync syncp;
  321. u64 rx_packets;
  322. u64 rx_bytes;
  323. u64 tx_packets;
  324. u64 tx_bytes;
  325. };
  326. struct mvneta_pcpu_port {
  327. /* Pointer to the shared port */
  328. struct mvneta_port *pp;
  329. /* Pointer to the CPU-local NAPI struct */
  330. struct napi_struct napi;
  331. /* Cause of the previous interrupt */
  332. u32 cause_rx_tx;
  333. };
  334. struct mvneta_port {
  335. u8 id;
  336. struct mvneta_pcpu_port __percpu *ports;
  337. struct mvneta_pcpu_stats __percpu *stats;
  338. int pkt_size;
  339. unsigned int frag_size;
  340. void __iomem *base;
  341. struct mvneta_rx_queue *rxqs;
  342. struct mvneta_tx_queue *txqs;
  343. struct net_device *dev;
  344. struct hlist_node node_online;
  345. struct hlist_node node_dead;
  346. int rxq_def;
  347. /* Protect the access to the percpu interrupt registers,
  348. * ensuring that the configuration remains coherent.
  349. */
  350. spinlock_t lock;
  351. bool is_stopped;
  352. /* Core clock */
  353. struct clk *clk;
  354. /* AXI clock */
  355. struct clk *clk_bus;
  356. u8 mcast_count[256];
  357. u16 tx_ring_size;
  358. u16 rx_ring_size;
  359. struct mii_bus *mii_bus;
  360. phy_interface_t phy_interface;
  361. struct device_node *phy_node;
  362. unsigned int link;
  363. unsigned int duplex;
  364. unsigned int speed;
  365. unsigned int tx_csum_limit;
  366. unsigned int use_inband_status:1;
  367. struct mvneta_bm *bm_priv;
  368. struct mvneta_bm_pool *pool_long;
  369. struct mvneta_bm_pool *pool_short;
  370. int bm_win_id;
  371. u64 ethtool_stats[ARRAY_SIZE(mvneta_statistics)];
  372. u32 indir[MVNETA_RSS_LU_TABLE_SIZE];
  373. };
  374. /* The mvneta_tx_desc and mvneta_rx_desc structures describe the
  375. * layout of the transmit and reception DMA descriptors, and their
  376. * layout is therefore defined by the hardware design
  377. */
  378. #define MVNETA_TX_L3_OFF_SHIFT 0
  379. #define MVNETA_TX_IP_HLEN_SHIFT 8
  380. #define MVNETA_TX_L4_UDP BIT(16)
  381. #define MVNETA_TX_L3_IP6 BIT(17)
  382. #define MVNETA_TXD_IP_CSUM BIT(18)
  383. #define MVNETA_TXD_Z_PAD BIT(19)
  384. #define MVNETA_TXD_L_DESC BIT(20)
  385. #define MVNETA_TXD_F_DESC BIT(21)
  386. #define MVNETA_TXD_FLZ_DESC (MVNETA_TXD_Z_PAD | \
  387. MVNETA_TXD_L_DESC | \
  388. MVNETA_TXD_F_DESC)
  389. #define MVNETA_TX_L4_CSUM_FULL BIT(30)
  390. #define MVNETA_TX_L4_CSUM_NOT BIT(31)
  391. #define MVNETA_RXD_ERR_CRC 0x0
  392. #define MVNETA_RXD_BM_POOL_SHIFT 13
  393. #define MVNETA_RXD_BM_POOL_MASK (BIT(13) | BIT(14))
  394. #define MVNETA_RXD_ERR_SUMMARY BIT(16)
  395. #define MVNETA_RXD_ERR_OVERRUN BIT(17)
  396. #define MVNETA_RXD_ERR_LEN BIT(18)
  397. #define MVNETA_RXD_ERR_RESOURCE (BIT(17) | BIT(18))
  398. #define MVNETA_RXD_ERR_CODE_MASK (BIT(17) | BIT(18))
  399. #define MVNETA_RXD_L3_IP4 BIT(25)
  400. #define MVNETA_RXD_FIRST_LAST_DESC (BIT(26) | BIT(27))
  401. #define MVNETA_RXD_L4_CSUM_OK BIT(30)
  402. #if defined(__LITTLE_ENDIAN)
  403. struct mvneta_tx_desc {
  404. u32 command; /* Options used by HW for packet transmitting.*/
  405. u16 reserverd1; /* csum_l4 (for future use) */
  406. u16 data_size; /* Data size of transmitted packet in bytes */
  407. u32 buf_phys_addr; /* Physical addr of transmitted buffer */
  408. u32 reserved2; /* hw_cmd - (for future use, PMT) */
  409. u32 reserved3[4]; /* Reserved - (for future use) */
  410. };
  411. struct mvneta_rx_desc {
  412. u32 status; /* Info about received packet */
  413. u16 reserved1; /* pnc_info - (for future use, PnC) */
  414. u16 data_size; /* Size of received packet in bytes */
  415. u32 buf_phys_addr; /* Physical address of the buffer */
  416. u32 reserved2; /* pnc_flow_id (for future use, PnC) */
  417. u32 buf_cookie; /* cookie for access to RX buffer in rx path */
  418. u16 reserved3; /* prefetch_cmd, for future use */
  419. u16 reserved4; /* csum_l4 - (for future use, PnC) */
  420. u32 reserved5; /* pnc_extra PnC (for future use, PnC) */
  421. u32 reserved6; /* hw_cmd (for future use, PnC and HWF) */
  422. };
  423. #else
  424. struct mvneta_tx_desc {
  425. u16 data_size; /* Data size of transmitted packet in bytes */
  426. u16 reserverd1; /* csum_l4 (for future use) */
  427. u32 command; /* Options used by HW for packet transmitting.*/
  428. u32 reserved2; /* hw_cmd - (for future use, PMT) */
  429. u32 buf_phys_addr; /* Physical addr of transmitted buffer */
  430. u32 reserved3[4]; /* Reserved - (for future use) */
  431. };
  432. struct mvneta_rx_desc {
  433. u16 data_size; /* Size of received packet in bytes */
  434. u16 reserved1; /* pnc_info - (for future use, PnC) */
  435. u32 status; /* Info about received packet */
  436. u32 reserved2; /* pnc_flow_id (for future use, PnC) */
  437. u32 buf_phys_addr; /* Physical address of the buffer */
  438. u16 reserved4; /* csum_l4 - (for future use, PnC) */
  439. u16 reserved3; /* prefetch_cmd, for future use */
  440. u32 buf_cookie; /* cookie for access to RX buffer in rx path */
  441. u32 reserved5; /* pnc_extra PnC (for future use, PnC) */
  442. u32 reserved6; /* hw_cmd (for future use, PnC and HWF) */
  443. };
  444. #endif
  445. struct mvneta_tx_queue {
  446. /* Number of this TX queue, in the range 0-7 */
  447. u8 id;
  448. /* Number of TX DMA descriptors in the descriptor ring */
  449. int size;
  450. /* Number of currently used TX DMA descriptor in the
  451. * descriptor ring
  452. */
  453. int count;
  454. int tx_stop_threshold;
  455. int tx_wake_threshold;
  456. /* Array of transmitted skb */
  457. struct sk_buff **tx_skb;
  458. /* Index of last TX DMA descriptor that was inserted */
  459. int txq_put_index;
  460. /* Index of the TX DMA descriptor to be cleaned up */
  461. int txq_get_index;
  462. u32 done_pkts_coal;
  463. /* Virtual address of the TX DMA descriptors array */
  464. struct mvneta_tx_desc *descs;
  465. /* DMA address of the TX DMA descriptors array */
  466. dma_addr_t descs_phys;
  467. /* Index of the last TX DMA descriptor */
  468. int last_desc;
  469. /* Index of the next TX DMA descriptor to process */
  470. int next_desc_to_proc;
  471. /* DMA buffers for TSO headers */
  472. char *tso_hdrs;
  473. /* DMA address of TSO headers */
  474. dma_addr_t tso_hdrs_phys;
  475. /* Affinity mask for CPUs*/
  476. cpumask_t affinity_mask;
  477. };
  478. struct mvneta_rx_queue {
  479. /* rx queue number, in the range 0-7 */
  480. u8 id;
  481. /* num of rx descriptors in the rx descriptor ring */
  482. int size;
  483. /* counter of times when mvneta_refill() failed */
  484. int missed;
  485. u32 pkts_coal;
  486. u32 time_coal;
  487. /* Virtual address of the RX DMA descriptors array */
  488. struct mvneta_rx_desc *descs;
  489. /* DMA address of the RX DMA descriptors array */
  490. dma_addr_t descs_phys;
  491. /* Index of the last RX DMA descriptor */
  492. int last_desc;
  493. /* Index of the next RX DMA descriptor to process */
  494. int next_desc_to_proc;
  495. };
  496. static enum cpuhp_state online_hpstate;
  497. /* The hardware supports eight (8) rx queues, but we are only allowing
  498. * the first one to be used. Therefore, let's just allocate one queue.
  499. */
  500. static int rxq_number = 8;
  501. static int txq_number = 8;
  502. static int rxq_def;
  503. static int rx_copybreak __read_mostly = 256;
  504. /* HW BM need that each port be identify by a unique ID */
  505. static int global_port_id;
  506. #define MVNETA_DRIVER_NAME "mvneta"
  507. #define MVNETA_DRIVER_VERSION "1.0"
  508. /* Utility/helper methods */
  509. /* Write helper method */
  510. static void mvreg_write(struct mvneta_port *pp, u32 offset, u32 data)
  511. {
  512. writel(data, pp->base + offset);
  513. }
  514. /* Read helper method */
  515. static u32 mvreg_read(struct mvneta_port *pp, u32 offset)
  516. {
  517. return readl(pp->base + offset);
  518. }
  519. /* Increment txq get counter */
  520. static void mvneta_txq_inc_get(struct mvneta_tx_queue *txq)
  521. {
  522. txq->txq_get_index++;
  523. if (txq->txq_get_index == txq->size)
  524. txq->txq_get_index = 0;
  525. }
  526. /* Increment txq put counter */
  527. static void mvneta_txq_inc_put(struct mvneta_tx_queue *txq)
  528. {
  529. txq->txq_put_index++;
  530. if (txq->txq_put_index == txq->size)
  531. txq->txq_put_index = 0;
  532. }
  533. /* Clear all MIB counters */
  534. static void mvneta_mib_counters_clear(struct mvneta_port *pp)
  535. {
  536. int i;
  537. u32 dummy;
  538. /* Perform dummy reads from MIB counters */
  539. for (i = 0; i < MVNETA_MIB_LATE_COLLISION; i += 4)
  540. dummy = mvreg_read(pp, (MVNETA_MIB_COUNTERS_BASE + i));
  541. dummy = mvreg_read(pp, MVNETA_RX_DISCARD_FRAME_COUNT);
  542. dummy = mvreg_read(pp, MVNETA_OVERRUN_FRAME_COUNT);
  543. }
  544. /* Get System Network Statistics */
  545. static struct rtnl_link_stats64 *
  546. mvneta_get_stats64(struct net_device *dev,
  547. struct rtnl_link_stats64 *stats)
  548. {
  549. struct mvneta_port *pp = netdev_priv(dev);
  550. unsigned int start;
  551. int cpu;
  552. for_each_possible_cpu(cpu) {
  553. struct mvneta_pcpu_stats *cpu_stats;
  554. u64 rx_packets;
  555. u64 rx_bytes;
  556. u64 tx_packets;
  557. u64 tx_bytes;
  558. cpu_stats = per_cpu_ptr(pp->stats, cpu);
  559. do {
  560. start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
  561. rx_packets = cpu_stats->rx_packets;
  562. rx_bytes = cpu_stats->rx_bytes;
  563. tx_packets = cpu_stats->tx_packets;
  564. tx_bytes = cpu_stats->tx_bytes;
  565. } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
  566. stats->rx_packets += rx_packets;
  567. stats->rx_bytes += rx_bytes;
  568. stats->tx_packets += tx_packets;
  569. stats->tx_bytes += tx_bytes;
  570. }
  571. stats->rx_errors = dev->stats.rx_errors;
  572. stats->rx_dropped = dev->stats.rx_dropped;
  573. stats->tx_dropped = dev->stats.tx_dropped;
  574. return stats;
  575. }
  576. /* Rx descriptors helper methods */
  577. /* Checks whether the RX descriptor having this status is both the first
  578. * and the last descriptor for the RX packet. Each RX packet is currently
  579. * received through a single RX descriptor, so not having each RX
  580. * descriptor with its first and last bits set is an error
  581. */
  582. static int mvneta_rxq_desc_is_first_last(u32 status)
  583. {
  584. return (status & MVNETA_RXD_FIRST_LAST_DESC) ==
  585. MVNETA_RXD_FIRST_LAST_DESC;
  586. }
  587. /* Add number of descriptors ready to receive new packets */
  588. static void mvneta_rxq_non_occup_desc_add(struct mvneta_port *pp,
  589. struct mvneta_rx_queue *rxq,
  590. int ndescs)
  591. {
  592. /* Only MVNETA_RXQ_ADD_NON_OCCUPIED_MAX (255) descriptors can
  593. * be added at once
  594. */
  595. while (ndescs > MVNETA_RXQ_ADD_NON_OCCUPIED_MAX) {
  596. mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id),
  597. (MVNETA_RXQ_ADD_NON_OCCUPIED_MAX <<
  598. MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT));
  599. ndescs -= MVNETA_RXQ_ADD_NON_OCCUPIED_MAX;
  600. }
  601. mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id),
  602. (ndescs << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT));
  603. }
  604. /* Get number of RX descriptors occupied by received packets */
  605. static int mvneta_rxq_busy_desc_num_get(struct mvneta_port *pp,
  606. struct mvneta_rx_queue *rxq)
  607. {
  608. u32 val;
  609. val = mvreg_read(pp, MVNETA_RXQ_STATUS_REG(rxq->id));
  610. return val & MVNETA_RXQ_OCCUPIED_ALL_MASK;
  611. }
  612. /* Update num of rx desc called upon return from rx path or
  613. * from mvneta_rxq_drop_pkts().
  614. */
  615. static void mvneta_rxq_desc_num_update(struct mvneta_port *pp,
  616. struct mvneta_rx_queue *rxq,
  617. int rx_done, int rx_filled)
  618. {
  619. u32 val;
  620. if ((rx_done <= 0xff) && (rx_filled <= 0xff)) {
  621. val = rx_done |
  622. (rx_filled << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT);
  623. mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id), val);
  624. return;
  625. }
  626. /* Only 255 descriptors can be added at once */
  627. while ((rx_done > 0) || (rx_filled > 0)) {
  628. if (rx_done <= 0xff) {
  629. val = rx_done;
  630. rx_done = 0;
  631. } else {
  632. val = 0xff;
  633. rx_done -= 0xff;
  634. }
  635. if (rx_filled <= 0xff) {
  636. val |= rx_filled << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT;
  637. rx_filled = 0;
  638. } else {
  639. val |= 0xff << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT;
  640. rx_filled -= 0xff;
  641. }
  642. mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id), val);
  643. }
  644. }
  645. /* Get pointer to next RX descriptor to be processed by SW */
  646. static struct mvneta_rx_desc *
  647. mvneta_rxq_next_desc_get(struct mvneta_rx_queue *rxq)
  648. {
  649. int rx_desc = rxq->next_desc_to_proc;
  650. rxq->next_desc_to_proc = MVNETA_QUEUE_NEXT_DESC(rxq, rx_desc);
  651. prefetch(rxq->descs + rxq->next_desc_to_proc);
  652. return rxq->descs + rx_desc;
  653. }
  654. /* Change maximum receive size of the port. */
  655. static void mvneta_max_rx_size_set(struct mvneta_port *pp, int max_rx_size)
  656. {
  657. u32 val;
  658. val = mvreg_read(pp, MVNETA_GMAC_CTRL_0);
  659. val &= ~MVNETA_GMAC_MAX_RX_SIZE_MASK;
  660. val |= ((max_rx_size - MVNETA_MH_SIZE) / 2) <<
  661. MVNETA_GMAC_MAX_RX_SIZE_SHIFT;
  662. mvreg_write(pp, MVNETA_GMAC_CTRL_0, val);
  663. }
  664. /* Set rx queue offset */
  665. static void mvneta_rxq_offset_set(struct mvneta_port *pp,
  666. struct mvneta_rx_queue *rxq,
  667. int offset)
  668. {
  669. u32 val;
  670. val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
  671. val &= ~MVNETA_RXQ_PKT_OFFSET_ALL_MASK;
  672. /* Offset is in */
  673. val |= MVNETA_RXQ_PKT_OFFSET_MASK(offset >> 3);
  674. mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
  675. }
  676. /* Tx descriptors helper methods */
  677. /* Update HW with number of TX descriptors to be sent */
  678. static void mvneta_txq_pend_desc_add(struct mvneta_port *pp,
  679. struct mvneta_tx_queue *txq,
  680. int pend_desc)
  681. {
  682. u32 val;
  683. /* Only 255 descriptors can be added at once ; Assume caller
  684. * process TX desriptors in quanta less than 256
  685. */
  686. val = pend_desc;
  687. mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val);
  688. }
  689. /* Get pointer to next TX descriptor to be processed (send) by HW */
  690. static struct mvneta_tx_desc *
  691. mvneta_txq_next_desc_get(struct mvneta_tx_queue *txq)
  692. {
  693. int tx_desc = txq->next_desc_to_proc;
  694. txq->next_desc_to_proc = MVNETA_QUEUE_NEXT_DESC(txq, tx_desc);
  695. return txq->descs + tx_desc;
  696. }
  697. /* Release the last allocated TX descriptor. Useful to handle DMA
  698. * mapping failures in the TX path.
  699. */
  700. static void mvneta_txq_desc_put(struct mvneta_tx_queue *txq)
  701. {
  702. if (txq->next_desc_to_proc == 0)
  703. txq->next_desc_to_proc = txq->last_desc - 1;
  704. else
  705. txq->next_desc_to_proc--;
  706. }
  707. /* Set rxq buf size */
  708. static void mvneta_rxq_buf_size_set(struct mvneta_port *pp,
  709. struct mvneta_rx_queue *rxq,
  710. int buf_size)
  711. {
  712. u32 val;
  713. val = mvreg_read(pp, MVNETA_RXQ_SIZE_REG(rxq->id));
  714. val &= ~MVNETA_RXQ_BUF_SIZE_MASK;
  715. val |= ((buf_size >> 3) << MVNETA_RXQ_BUF_SIZE_SHIFT);
  716. mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), val);
  717. }
  718. /* Disable buffer management (BM) */
  719. static void mvneta_rxq_bm_disable(struct mvneta_port *pp,
  720. struct mvneta_rx_queue *rxq)
  721. {
  722. u32 val;
  723. val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
  724. val &= ~MVNETA_RXQ_HW_BUF_ALLOC;
  725. mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
  726. }
  727. /* Enable buffer management (BM) */
  728. static void mvneta_rxq_bm_enable(struct mvneta_port *pp,
  729. struct mvneta_rx_queue *rxq)
  730. {
  731. u32 val;
  732. val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
  733. val |= MVNETA_RXQ_HW_BUF_ALLOC;
  734. mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
  735. }
  736. /* Notify HW about port's assignment of pool for bigger packets */
  737. static void mvneta_rxq_long_pool_set(struct mvneta_port *pp,
  738. struct mvneta_rx_queue *rxq)
  739. {
  740. u32 val;
  741. val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
  742. val &= ~MVNETA_RXQ_LONG_POOL_ID_MASK;
  743. val |= (pp->pool_long->id << MVNETA_RXQ_LONG_POOL_ID_SHIFT);
  744. mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
  745. }
  746. /* Notify HW about port's assignment of pool for smaller packets */
  747. static void mvneta_rxq_short_pool_set(struct mvneta_port *pp,
  748. struct mvneta_rx_queue *rxq)
  749. {
  750. u32 val;
  751. val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
  752. val &= ~MVNETA_RXQ_SHORT_POOL_ID_MASK;
  753. val |= (pp->pool_short->id << MVNETA_RXQ_SHORT_POOL_ID_SHIFT);
  754. mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
  755. }
  756. /* Set port's receive buffer size for assigned BM pool */
  757. static inline void mvneta_bm_pool_bufsize_set(struct mvneta_port *pp,
  758. int buf_size,
  759. u8 pool_id)
  760. {
  761. u32 val;
  762. if (!IS_ALIGNED(buf_size, 8)) {
  763. dev_warn(pp->dev->dev.parent,
  764. "illegal buf_size value %d, round to %d\n",
  765. buf_size, ALIGN(buf_size, 8));
  766. buf_size = ALIGN(buf_size, 8);
  767. }
  768. val = mvreg_read(pp, MVNETA_PORT_POOL_BUFFER_SZ_REG(pool_id));
  769. val |= buf_size & MVNETA_PORT_POOL_BUFFER_SZ_MASK;
  770. mvreg_write(pp, MVNETA_PORT_POOL_BUFFER_SZ_REG(pool_id), val);
  771. }
  772. /* Configure MBUS window in order to enable access BM internal SRAM */
  773. static int mvneta_mbus_io_win_set(struct mvneta_port *pp, u32 base, u32 wsize,
  774. u8 target, u8 attr)
  775. {
  776. u32 win_enable, win_protect;
  777. int i;
  778. win_enable = mvreg_read(pp, MVNETA_BASE_ADDR_ENABLE);
  779. if (pp->bm_win_id < 0) {
  780. /* Find first not occupied window */
  781. for (i = 0; i < MVNETA_MAX_DECODE_WIN; i++) {
  782. if (win_enable & (1 << i)) {
  783. pp->bm_win_id = i;
  784. break;
  785. }
  786. }
  787. if (i == MVNETA_MAX_DECODE_WIN)
  788. return -ENOMEM;
  789. } else {
  790. i = pp->bm_win_id;
  791. }
  792. mvreg_write(pp, MVNETA_WIN_BASE(i), 0);
  793. mvreg_write(pp, MVNETA_WIN_SIZE(i), 0);
  794. if (i < 4)
  795. mvreg_write(pp, MVNETA_WIN_REMAP(i), 0);
  796. mvreg_write(pp, MVNETA_WIN_BASE(i), (base & 0xffff0000) |
  797. (attr << 8) | target);
  798. mvreg_write(pp, MVNETA_WIN_SIZE(i), (wsize - 1) & 0xffff0000);
  799. win_protect = mvreg_read(pp, MVNETA_ACCESS_PROTECT_ENABLE);
  800. win_protect |= 3 << (2 * i);
  801. mvreg_write(pp, MVNETA_ACCESS_PROTECT_ENABLE, win_protect);
  802. win_enable &= ~(1 << i);
  803. mvreg_write(pp, MVNETA_BASE_ADDR_ENABLE, win_enable);
  804. return 0;
  805. }
  806. /* Assign and initialize pools for port. In case of fail
  807. * buffer manager will remain disabled for current port.
  808. */
  809. static int mvneta_bm_port_init(struct platform_device *pdev,
  810. struct mvneta_port *pp)
  811. {
  812. struct device_node *dn = pdev->dev.of_node;
  813. u32 long_pool_id, short_pool_id, wsize;
  814. u8 target, attr;
  815. int err;
  816. /* Get BM window information */
  817. err = mvebu_mbus_get_io_win_info(pp->bm_priv->bppi_phys_addr, &wsize,
  818. &target, &attr);
  819. if (err < 0)
  820. return err;
  821. pp->bm_win_id = -1;
  822. /* Open NETA -> BM window */
  823. err = mvneta_mbus_io_win_set(pp, pp->bm_priv->bppi_phys_addr, wsize,
  824. target, attr);
  825. if (err < 0) {
  826. netdev_info(pp->dev, "fail to configure mbus window to BM\n");
  827. return err;
  828. }
  829. if (of_property_read_u32(dn, "bm,pool-long", &long_pool_id)) {
  830. netdev_info(pp->dev, "missing long pool id\n");
  831. return -EINVAL;
  832. }
  833. /* Create port's long pool depending on mtu */
  834. pp->pool_long = mvneta_bm_pool_use(pp->bm_priv, long_pool_id,
  835. MVNETA_BM_LONG, pp->id,
  836. MVNETA_RX_PKT_SIZE(pp->dev->mtu));
  837. if (!pp->pool_long) {
  838. netdev_info(pp->dev, "fail to obtain long pool for port\n");
  839. return -ENOMEM;
  840. }
  841. pp->pool_long->port_map |= 1 << pp->id;
  842. mvneta_bm_pool_bufsize_set(pp, pp->pool_long->buf_size,
  843. pp->pool_long->id);
  844. /* If short pool id is not defined, assume using single pool */
  845. if (of_property_read_u32(dn, "bm,pool-short", &short_pool_id))
  846. short_pool_id = long_pool_id;
  847. /* Create port's short pool */
  848. pp->pool_short = mvneta_bm_pool_use(pp->bm_priv, short_pool_id,
  849. MVNETA_BM_SHORT, pp->id,
  850. MVNETA_BM_SHORT_PKT_SIZE);
  851. if (!pp->pool_short) {
  852. netdev_info(pp->dev, "fail to obtain short pool for port\n");
  853. mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id);
  854. return -ENOMEM;
  855. }
  856. if (short_pool_id != long_pool_id) {
  857. pp->pool_short->port_map |= 1 << pp->id;
  858. mvneta_bm_pool_bufsize_set(pp, pp->pool_short->buf_size,
  859. pp->pool_short->id);
  860. }
  861. return 0;
  862. }
  863. /* Update settings of a pool for bigger packets */
  864. static void mvneta_bm_update_mtu(struct mvneta_port *pp, int mtu)
  865. {
  866. struct mvneta_bm_pool *bm_pool = pp->pool_long;
  867. struct hwbm_pool *hwbm_pool = &bm_pool->hwbm_pool;
  868. int num;
  869. /* Release all buffers from long pool */
  870. mvneta_bm_bufs_free(pp->bm_priv, bm_pool, 1 << pp->id);
  871. if (hwbm_pool->buf_num) {
  872. WARN(1, "cannot free all buffers in pool %d\n",
  873. bm_pool->id);
  874. goto bm_mtu_err;
  875. }
  876. bm_pool->pkt_size = MVNETA_RX_PKT_SIZE(mtu);
  877. bm_pool->buf_size = MVNETA_RX_BUF_SIZE(bm_pool->pkt_size);
  878. hwbm_pool->frag_size = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
  879. SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(bm_pool->pkt_size));
  880. /* Fill entire long pool */
  881. num = hwbm_pool_add(hwbm_pool, hwbm_pool->size, GFP_ATOMIC);
  882. if (num != hwbm_pool->size) {
  883. WARN(1, "pool %d: %d of %d allocated\n",
  884. bm_pool->id, num, hwbm_pool->size);
  885. goto bm_mtu_err;
  886. }
  887. mvneta_bm_pool_bufsize_set(pp, bm_pool->buf_size, bm_pool->id);
  888. return;
  889. bm_mtu_err:
  890. mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id);
  891. mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short, 1 << pp->id);
  892. pp->bm_priv = NULL;
  893. mvreg_write(pp, MVNETA_ACC_MODE, MVNETA_ACC_MODE_EXT1);
  894. netdev_info(pp->dev, "fail to update MTU, fall back to software BM\n");
  895. }
  896. /* Start the Ethernet port RX and TX activity */
  897. static void mvneta_port_up(struct mvneta_port *pp)
  898. {
  899. int queue;
  900. u32 q_map;
  901. /* Enable all initialized TXs. */
  902. q_map = 0;
  903. for (queue = 0; queue < txq_number; queue++) {
  904. struct mvneta_tx_queue *txq = &pp->txqs[queue];
  905. if (txq->descs != NULL)
  906. q_map |= (1 << queue);
  907. }
  908. mvreg_write(pp, MVNETA_TXQ_CMD, q_map);
  909. q_map = 0;
  910. /* Enable all initialized RXQs. */
  911. for (queue = 0; queue < rxq_number; queue++) {
  912. struct mvneta_rx_queue *rxq = &pp->rxqs[queue];
  913. if (rxq->descs != NULL)
  914. q_map |= (1 << queue);
  915. }
  916. mvreg_write(pp, MVNETA_RXQ_CMD, q_map);
  917. }
  918. /* Stop the Ethernet port activity */
  919. static void mvneta_port_down(struct mvneta_port *pp)
  920. {
  921. u32 val;
  922. int count;
  923. /* Stop Rx port activity. Check port Rx activity. */
  924. val = mvreg_read(pp, MVNETA_RXQ_CMD) & MVNETA_RXQ_ENABLE_MASK;
  925. /* Issue stop command for active channels only */
  926. if (val != 0)
  927. mvreg_write(pp, MVNETA_RXQ_CMD,
  928. val << MVNETA_RXQ_DISABLE_SHIFT);
  929. /* Wait for all Rx activity to terminate. */
  930. count = 0;
  931. do {
  932. if (count++ >= MVNETA_RX_DISABLE_TIMEOUT_MSEC) {
  933. netdev_warn(pp->dev,
  934. "TIMEOUT for RX stopped ! rx_queue_cmd: 0x%08x\n",
  935. val);
  936. break;
  937. }
  938. mdelay(1);
  939. val = mvreg_read(pp, MVNETA_RXQ_CMD);
  940. } while (val & MVNETA_RXQ_ENABLE_MASK);
  941. /* Stop Tx port activity. Check port Tx activity. Issue stop
  942. * command for active channels only
  943. */
  944. val = (mvreg_read(pp, MVNETA_TXQ_CMD)) & MVNETA_TXQ_ENABLE_MASK;
  945. if (val != 0)
  946. mvreg_write(pp, MVNETA_TXQ_CMD,
  947. (val << MVNETA_TXQ_DISABLE_SHIFT));
  948. /* Wait for all Tx activity to terminate. */
  949. count = 0;
  950. do {
  951. if (count++ >= MVNETA_TX_DISABLE_TIMEOUT_MSEC) {
  952. netdev_warn(pp->dev,
  953. "TIMEOUT for TX stopped status=0x%08x\n",
  954. val);
  955. break;
  956. }
  957. mdelay(1);
  958. /* Check TX Command reg that all Txqs are stopped */
  959. val = mvreg_read(pp, MVNETA_TXQ_CMD);
  960. } while (val & MVNETA_TXQ_ENABLE_MASK);
  961. /* Double check to verify that TX FIFO is empty */
  962. count = 0;
  963. do {
  964. if (count++ >= MVNETA_TX_FIFO_EMPTY_TIMEOUT) {
  965. netdev_warn(pp->dev,
  966. "TX FIFO empty timeout status=0x%08x\n",
  967. val);
  968. break;
  969. }
  970. mdelay(1);
  971. val = mvreg_read(pp, MVNETA_PORT_STATUS);
  972. } while (!(val & MVNETA_TX_FIFO_EMPTY) &&
  973. (val & MVNETA_TX_IN_PRGRS));
  974. udelay(200);
  975. }
  976. /* Enable the port by setting the port enable bit of the MAC control register */
  977. static void mvneta_port_enable(struct mvneta_port *pp)
  978. {
  979. u32 val;
  980. /* Enable port */
  981. val = mvreg_read(pp, MVNETA_GMAC_CTRL_0);
  982. val |= MVNETA_GMAC0_PORT_ENABLE;
  983. mvreg_write(pp, MVNETA_GMAC_CTRL_0, val);
  984. }
  985. /* Disable the port and wait for about 200 usec before retuning */
  986. static void mvneta_port_disable(struct mvneta_port *pp)
  987. {
  988. u32 val;
  989. /* Reset the Enable bit in the Serial Control Register */
  990. val = mvreg_read(pp, MVNETA_GMAC_CTRL_0);
  991. val &= ~MVNETA_GMAC0_PORT_ENABLE;
  992. mvreg_write(pp, MVNETA_GMAC_CTRL_0, val);
  993. pp->link = 0;
  994. pp->duplex = -1;
  995. pp->speed = 0;
  996. udelay(200);
  997. }
  998. /* Multicast tables methods */
  999. /* Set all entries in Unicast MAC Table; queue==-1 means reject all */
  1000. static void mvneta_set_ucast_table(struct mvneta_port *pp, int queue)
  1001. {
  1002. int offset;
  1003. u32 val;
  1004. if (queue == -1) {
  1005. val = 0;
  1006. } else {
  1007. val = 0x1 | (queue << 1);
  1008. val |= (val << 24) | (val << 16) | (val << 8);
  1009. }
  1010. for (offset = 0; offset <= 0xc; offset += 4)
  1011. mvreg_write(pp, MVNETA_DA_FILT_UCAST_BASE + offset, val);
  1012. }
  1013. /* Set all entries in Special Multicast MAC Table; queue==-1 means reject all */
  1014. static void mvneta_set_special_mcast_table(struct mvneta_port *pp, int queue)
  1015. {
  1016. int offset;
  1017. u32 val;
  1018. if (queue == -1) {
  1019. val = 0;
  1020. } else {
  1021. val = 0x1 | (queue << 1);
  1022. val |= (val << 24) | (val << 16) | (val << 8);
  1023. }
  1024. for (offset = 0; offset <= 0xfc; offset += 4)
  1025. mvreg_write(pp, MVNETA_DA_FILT_SPEC_MCAST + offset, val);
  1026. }
  1027. /* Set all entries in Other Multicast MAC Table. queue==-1 means reject all */
  1028. static void mvneta_set_other_mcast_table(struct mvneta_port *pp, int queue)
  1029. {
  1030. int offset;
  1031. u32 val;
  1032. if (queue == -1) {
  1033. memset(pp->mcast_count, 0, sizeof(pp->mcast_count));
  1034. val = 0;
  1035. } else {
  1036. memset(pp->mcast_count, 1, sizeof(pp->mcast_count));
  1037. val = 0x1 | (queue << 1);
  1038. val |= (val << 24) | (val << 16) | (val << 8);
  1039. }
  1040. for (offset = 0; offset <= 0xfc; offset += 4)
  1041. mvreg_write(pp, MVNETA_DA_FILT_OTH_MCAST + offset, val);
  1042. }
  1043. static void mvneta_set_autoneg(struct mvneta_port *pp, int enable)
  1044. {
  1045. u32 val;
  1046. if (enable) {
  1047. val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
  1048. val &= ~(MVNETA_GMAC_FORCE_LINK_PASS |
  1049. MVNETA_GMAC_FORCE_LINK_DOWN |
  1050. MVNETA_GMAC_AN_FLOW_CTRL_EN);
  1051. val |= MVNETA_GMAC_INBAND_AN_ENABLE |
  1052. MVNETA_GMAC_AN_SPEED_EN |
  1053. MVNETA_GMAC_AN_DUPLEX_EN;
  1054. mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
  1055. val = mvreg_read(pp, MVNETA_GMAC_CLOCK_DIVIDER);
  1056. val |= MVNETA_GMAC_1MS_CLOCK_ENABLE;
  1057. mvreg_write(pp, MVNETA_GMAC_CLOCK_DIVIDER, val);
  1058. val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
  1059. val |= MVNETA_GMAC2_INBAND_AN_ENABLE;
  1060. mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
  1061. } else {
  1062. val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
  1063. val &= ~(MVNETA_GMAC_INBAND_AN_ENABLE |
  1064. MVNETA_GMAC_AN_SPEED_EN |
  1065. MVNETA_GMAC_AN_DUPLEX_EN);
  1066. mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
  1067. val = mvreg_read(pp, MVNETA_GMAC_CLOCK_DIVIDER);
  1068. val &= ~MVNETA_GMAC_1MS_CLOCK_ENABLE;
  1069. mvreg_write(pp, MVNETA_GMAC_CLOCK_DIVIDER, val);
  1070. val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
  1071. val &= ~MVNETA_GMAC2_INBAND_AN_ENABLE;
  1072. mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
  1073. }
  1074. }
  1075. static void mvneta_percpu_unmask_interrupt(void *arg)
  1076. {
  1077. struct mvneta_port *pp = arg;
  1078. /* All the queue are unmasked, but actually only the ones
  1079. * mapped to this CPU will be unmasked
  1080. */
  1081. mvreg_write(pp, MVNETA_INTR_NEW_MASK,
  1082. MVNETA_RX_INTR_MASK_ALL |
  1083. MVNETA_TX_INTR_MASK_ALL |
  1084. MVNETA_MISCINTR_INTR_MASK);
  1085. }
  1086. static void mvneta_percpu_mask_interrupt(void *arg)
  1087. {
  1088. struct mvneta_port *pp = arg;
  1089. /* All the queue are masked, but actually only the ones
  1090. * mapped to this CPU will be masked
  1091. */
  1092. mvreg_write(pp, MVNETA_INTR_NEW_MASK, 0);
  1093. mvreg_write(pp, MVNETA_INTR_OLD_MASK, 0);
  1094. mvreg_write(pp, MVNETA_INTR_MISC_MASK, 0);
  1095. }
  1096. static void mvneta_percpu_clear_intr_cause(void *arg)
  1097. {
  1098. struct mvneta_port *pp = arg;
  1099. /* All the queue are cleared, but actually only the ones
  1100. * mapped to this CPU will be cleared
  1101. */
  1102. mvreg_write(pp, MVNETA_INTR_NEW_CAUSE, 0);
  1103. mvreg_write(pp, MVNETA_INTR_MISC_CAUSE, 0);
  1104. mvreg_write(pp, MVNETA_INTR_OLD_CAUSE, 0);
  1105. }
  1106. /* This method sets defaults to the NETA port:
  1107. * Clears interrupt Cause and Mask registers.
  1108. * Clears all MAC tables.
  1109. * Sets defaults to all registers.
  1110. * Resets RX and TX descriptor rings.
  1111. * Resets PHY.
  1112. * This method can be called after mvneta_port_down() to return the port
  1113. * settings to defaults.
  1114. */
  1115. static void mvneta_defaults_set(struct mvneta_port *pp)
  1116. {
  1117. int cpu;
  1118. int queue;
  1119. u32 val;
  1120. int max_cpu = num_present_cpus();
  1121. /* Clear all Cause registers */
  1122. on_each_cpu(mvneta_percpu_clear_intr_cause, pp, true);
  1123. /* Mask all interrupts */
  1124. on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
  1125. mvreg_write(pp, MVNETA_INTR_ENABLE, 0);
  1126. /* Enable MBUS Retry bit16 */
  1127. mvreg_write(pp, MVNETA_MBUS_RETRY, 0x20);
  1128. /* Set CPU queue access map. CPUs are assigned to the RX and
  1129. * TX queues modulo their number. If there is only one TX
  1130. * queue then it is assigned to the CPU associated to the
  1131. * default RX queue.
  1132. */
  1133. for_each_present_cpu(cpu) {
  1134. int rxq_map = 0, txq_map = 0;
  1135. int rxq, txq;
  1136. for (rxq = 0; rxq < rxq_number; rxq++)
  1137. if ((rxq % max_cpu) == cpu)
  1138. rxq_map |= MVNETA_CPU_RXQ_ACCESS(rxq);
  1139. for (txq = 0; txq < txq_number; txq++)
  1140. if ((txq % max_cpu) == cpu)
  1141. txq_map |= MVNETA_CPU_TXQ_ACCESS(txq);
  1142. /* With only one TX queue we configure a special case
  1143. * which will allow to get all the irq on a single
  1144. * CPU
  1145. */
  1146. if (txq_number == 1)
  1147. txq_map = (cpu == pp->rxq_def) ?
  1148. MVNETA_CPU_TXQ_ACCESS(1) : 0;
  1149. mvreg_write(pp, MVNETA_CPU_MAP(cpu), rxq_map | txq_map);
  1150. }
  1151. /* Reset RX and TX DMAs */
  1152. mvreg_write(pp, MVNETA_PORT_RX_RESET, MVNETA_PORT_RX_DMA_RESET);
  1153. mvreg_write(pp, MVNETA_PORT_TX_RESET, MVNETA_PORT_TX_DMA_RESET);
  1154. /* Disable Legacy WRR, Disable EJP, Release from reset */
  1155. mvreg_write(pp, MVNETA_TXQ_CMD_1, 0);
  1156. for (queue = 0; queue < txq_number; queue++) {
  1157. mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(queue), 0);
  1158. mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(queue), 0);
  1159. }
  1160. mvreg_write(pp, MVNETA_PORT_TX_RESET, 0);
  1161. mvreg_write(pp, MVNETA_PORT_RX_RESET, 0);
  1162. /* Set Port Acceleration Mode */
  1163. if (pp->bm_priv)
  1164. /* HW buffer management + legacy parser */
  1165. val = MVNETA_ACC_MODE_EXT2;
  1166. else
  1167. /* SW buffer management + legacy parser */
  1168. val = MVNETA_ACC_MODE_EXT1;
  1169. mvreg_write(pp, MVNETA_ACC_MODE, val);
  1170. if (pp->bm_priv)
  1171. mvreg_write(pp, MVNETA_BM_ADDRESS, pp->bm_priv->bppi_phys_addr);
  1172. /* Update val of portCfg register accordingly with all RxQueue types */
  1173. val = MVNETA_PORT_CONFIG_DEFL_VALUE(pp->rxq_def);
  1174. mvreg_write(pp, MVNETA_PORT_CONFIG, val);
  1175. val = 0;
  1176. mvreg_write(pp, MVNETA_PORT_CONFIG_EXTEND, val);
  1177. mvreg_write(pp, MVNETA_RX_MIN_FRAME_SIZE, 64);
  1178. /* Build PORT_SDMA_CONFIG_REG */
  1179. val = 0;
  1180. /* Default burst size */
  1181. val |= MVNETA_TX_BRST_SZ_MASK(MVNETA_SDMA_BRST_SIZE_16);
  1182. val |= MVNETA_RX_BRST_SZ_MASK(MVNETA_SDMA_BRST_SIZE_16);
  1183. val |= MVNETA_RX_NO_DATA_SWAP | MVNETA_TX_NO_DATA_SWAP;
  1184. #if defined(__BIG_ENDIAN)
  1185. val |= MVNETA_DESC_SWAP;
  1186. #endif
  1187. /* Assign port SDMA configuration */
  1188. mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
  1189. /* Disable PHY polling in hardware, since we're using the
  1190. * kernel phylib to do this.
  1191. */
  1192. val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
  1193. val &= ~MVNETA_PHY_POLLING_ENABLE;
  1194. mvreg_write(pp, MVNETA_UNIT_CONTROL, val);
  1195. mvneta_set_autoneg(pp, pp->use_inband_status);
  1196. mvneta_set_ucast_table(pp, -1);
  1197. mvneta_set_special_mcast_table(pp, -1);
  1198. mvneta_set_other_mcast_table(pp, -1);
  1199. /* Set port interrupt enable register - default enable all */
  1200. mvreg_write(pp, MVNETA_INTR_ENABLE,
  1201. (MVNETA_RXQ_INTR_ENABLE_ALL_MASK
  1202. | MVNETA_TXQ_INTR_ENABLE_ALL_MASK));
  1203. mvneta_mib_counters_clear(pp);
  1204. }
  1205. /* Set max sizes for tx queues */
  1206. static void mvneta_txq_max_tx_size_set(struct mvneta_port *pp, int max_tx_size)
  1207. {
  1208. u32 val, size, mtu;
  1209. int queue;
  1210. mtu = max_tx_size * 8;
  1211. if (mtu > MVNETA_TX_MTU_MAX)
  1212. mtu = MVNETA_TX_MTU_MAX;
  1213. /* Set MTU */
  1214. val = mvreg_read(pp, MVNETA_TX_MTU);
  1215. val &= ~MVNETA_TX_MTU_MAX;
  1216. val |= mtu;
  1217. mvreg_write(pp, MVNETA_TX_MTU, val);
  1218. /* TX token size and all TXQs token size must be larger that MTU */
  1219. val = mvreg_read(pp, MVNETA_TX_TOKEN_SIZE);
  1220. size = val & MVNETA_TX_TOKEN_SIZE_MAX;
  1221. if (size < mtu) {
  1222. size = mtu;
  1223. val &= ~MVNETA_TX_TOKEN_SIZE_MAX;
  1224. val |= size;
  1225. mvreg_write(pp, MVNETA_TX_TOKEN_SIZE, val);
  1226. }
  1227. for (queue = 0; queue < txq_number; queue++) {
  1228. val = mvreg_read(pp, MVNETA_TXQ_TOKEN_SIZE_REG(queue));
  1229. size = val & MVNETA_TXQ_TOKEN_SIZE_MAX;
  1230. if (size < mtu) {
  1231. size = mtu;
  1232. val &= ~MVNETA_TXQ_TOKEN_SIZE_MAX;
  1233. val |= size;
  1234. mvreg_write(pp, MVNETA_TXQ_TOKEN_SIZE_REG(queue), val);
  1235. }
  1236. }
  1237. }
  1238. /* Set unicast address */
  1239. static void mvneta_set_ucast_addr(struct mvneta_port *pp, u8 last_nibble,
  1240. int queue)
  1241. {
  1242. unsigned int unicast_reg;
  1243. unsigned int tbl_offset;
  1244. unsigned int reg_offset;
  1245. /* Locate the Unicast table entry */
  1246. last_nibble = (0xf & last_nibble);
  1247. /* offset from unicast tbl base */
  1248. tbl_offset = (last_nibble / 4) * 4;
  1249. /* offset within the above reg */
  1250. reg_offset = last_nibble % 4;
  1251. unicast_reg = mvreg_read(pp, (MVNETA_DA_FILT_UCAST_BASE + tbl_offset));
  1252. if (queue == -1) {
  1253. /* Clear accepts frame bit at specified unicast DA tbl entry */
  1254. unicast_reg &= ~(0xff << (8 * reg_offset));
  1255. } else {
  1256. unicast_reg &= ~(0xff << (8 * reg_offset));
  1257. unicast_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset));
  1258. }
  1259. mvreg_write(pp, (MVNETA_DA_FILT_UCAST_BASE + tbl_offset), unicast_reg);
  1260. }
  1261. /* Set mac address */
  1262. static void mvneta_mac_addr_set(struct mvneta_port *pp, unsigned char *addr,
  1263. int queue)
  1264. {
  1265. unsigned int mac_h;
  1266. unsigned int mac_l;
  1267. if (queue != -1) {
  1268. mac_l = (addr[4] << 8) | (addr[5]);
  1269. mac_h = (addr[0] << 24) | (addr[1] << 16) |
  1270. (addr[2] << 8) | (addr[3] << 0);
  1271. mvreg_write(pp, MVNETA_MAC_ADDR_LOW, mac_l);
  1272. mvreg_write(pp, MVNETA_MAC_ADDR_HIGH, mac_h);
  1273. }
  1274. /* Accept frames of this address */
  1275. mvneta_set_ucast_addr(pp, addr[5], queue);
  1276. }
  1277. /* Set the number of packets that will be received before RX interrupt
  1278. * will be generated by HW.
  1279. */
  1280. static void mvneta_rx_pkts_coal_set(struct mvneta_port *pp,
  1281. struct mvneta_rx_queue *rxq, u32 value)
  1282. {
  1283. mvreg_write(pp, MVNETA_RXQ_THRESHOLD_REG(rxq->id),
  1284. value | MVNETA_RXQ_NON_OCCUPIED(0));
  1285. rxq->pkts_coal = value;
  1286. }
  1287. /* Set the time delay in usec before RX interrupt will be generated by
  1288. * HW.
  1289. */
  1290. static void mvneta_rx_time_coal_set(struct mvneta_port *pp,
  1291. struct mvneta_rx_queue *rxq, u32 value)
  1292. {
  1293. u32 val;
  1294. unsigned long clk_rate;
  1295. clk_rate = clk_get_rate(pp->clk);
  1296. val = (clk_rate / 1000000) * value;
  1297. mvreg_write(pp, MVNETA_RXQ_TIME_COAL_REG(rxq->id), val);
  1298. rxq->time_coal = value;
  1299. }
  1300. /* Set threshold for TX_DONE pkts coalescing */
  1301. static void mvneta_tx_done_pkts_coal_set(struct mvneta_port *pp,
  1302. struct mvneta_tx_queue *txq, u32 value)
  1303. {
  1304. u32 val;
  1305. val = mvreg_read(pp, MVNETA_TXQ_SIZE_REG(txq->id));
  1306. val &= ~MVNETA_TXQ_SENT_THRESH_ALL_MASK;
  1307. val |= MVNETA_TXQ_SENT_THRESH_MASK(value);
  1308. mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), val);
  1309. txq->done_pkts_coal = value;
  1310. }
  1311. /* Handle rx descriptor fill by setting buf_cookie and buf_phys_addr */
  1312. static void mvneta_rx_desc_fill(struct mvneta_rx_desc *rx_desc,
  1313. u32 phys_addr, u32 cookie)
  1314. {
  1315. rx_desc->buf_cookie = cookie;
  1316. rx_desc->buf_phys_addr = phys_addr;
  1317. }
  1318. /* Decrement sent descriptors counter */
  1319. static void mvneta_txq_sent_desc_dec(struct mvneta_port *pp,
  1320. struct mvneta_tx_queue *txq,
  1321. int sent_desc)
  1322. {
  1323. u32 val;
  1324. /* Only 255 TX descriptors can be updated at once */
  1325. while (sent_desc > 0xff) {
  1326. val = 0xff << MVNETA_TXQ_DEC_SENT_SHIFT;
  1327. mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val);
  1328. sent_desc = sent_desc - 0xff;
  1329. }
  1330. val = sent_desc << MVNETA_TXQ_DEC_SENT_SHIFT;
  1331. mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val);
  1332. }
  1333. /* Get number of TX descriptors already sent by HW */
  1334. static int mvneta_txq_sent_desc_num_get(struct mvneta_port *pp,
  1335. struct mvneta_tx_queue *txq)
  1336. {
  1337. u32 val;
  1338. int sent_desc;
  1339. val = mvreg_read(pp, MVNETA_TXQ_STATUS_REG(txq->id));
  1340. sent_desc = (val & MVNETA_TXQ_SENT_DESC_MASK) >>
  1341. MVNETA_TXQ_SENT_DESC_SHIFT;
  1342. return sent_desc;
  1343. }
  1344. /* Get number of sent descriptors and decrement counter.
  1345. * The number of sent descriptors is returned.
  1346. */
  1347. static int mvneta_txq_sent_desc_proc(struct mvneta_port *pp,
  1348. struct mvneta_tx_queue *txq)
  1349. {
  1350. int sent_desc;
  1351. /* Get number of sent descriptors */
  1352. sent_desc = mvneta_txq_sent_desc_num_get(pp, txq);
  1353. /* Decrement sent descriptors counter */
  1354. if (sent_desc)
  1355. mvneta_txq_sent_desc_dec(pp, txq, sent_desc);
  1356. return sent_desc;
  1357. }
  1358. /* Set TXQ descriptors fields relevant for CSUM calculation */
  1359. static u32 mvneta_txq_desc_csum(int l3_offs, int l3_proto,
  1360. int ip_hdr_len, int l4_proto)
  1361. {
  1362. u32 command;
  1363. /* Fields: L3_offset, IP_hdrlen, L3_type, G_IPv4_chk,
  1364. * G_L4_chk, L4_type; required only for checksum
  1365. * calculation
  1366. */
  1367. command = l3_offs << MVNETA_TX_L3_OFF_SHIFT;
  1368. command |= ip_hdr_len << MVNETA_TX_IP_HLEN_SHIFT;
  1369. if (l3_proto == htons(ETH_P_IP))
  1370. command |= MVNETA_TXD_IP_CSUM;
  1371. else
  1372. command |= MVNETA_TX_L3_IP6;
  1373. if (l4_proto == IPPROTO_TCP)
  1374. command |= MVNETA_TX_L4_CSUM_FULL;
  1375. else if (l4_proto == IPPROTO_UDP)
  1376. command |= MVNETA_TX_L4_UDP | MVNETA_TX_L4_CSUM_FULL;
  1377. else
  1378. command |= MVNETA_TX_L4_CSUM_NOT;
  1379. return command;
  1380. }
  1381. /* Display more error info */
  1382. static void mvneta_rx_error(struct mvneta_port *pp,
  1383. struct mvneta_rx_desc *rx_desc)
  1384. {
  1385. u32 status = rx_desc->status;
  1386. if (!mvneta_rxq_desc_is_first_last(status)) {
  1387. netdev_err(pp->dev,
  1388. "bad rx status %08x (buffer oversize), size=%d\n",
  1389. status, rx_desc->data_size);
  1390. return;
  1391. }
  1392. switch (status & MVNETA_RXD_ERR_CODE_MASK) {
  1393. case MVNETA_RXD_ERR_CRC:
  1394. netdev_err(pp->dev, "bad rx status %08x (crc error), size=%d\n",
  1395. status, rx_desc->data_size);
  1396. break;
  1397. case MVNETA_RXD_ERR_OVERRUN:
  1398. netdev_err(pp->dev, "bad rx status %08x (overrun error), size=%d\n",
  1399. status, rx_desc->data_size);
  1400. break;
  1401. case MVNETA_RXD_ERR_LEN:
  1402. netdev_err(pp->dev, "bad rx status %08x (max frame length error), size=%d\n",
  1403. status, rx_desc->data_size);
  1404. break;
  1405. case MVNETA_RXD_ERR_RESOURCE:
  1406. netdev_err(pp->dev, "bad rx status %08x (resource error), size=%d\n",
  1407. status, rx_desc->data_size);
  1408. break;
  1409. }
  1410. }
  1411. /* Handle RX checksum offload based on the descriptor's status */
  1412. static void mvneta_rx_csum(struct mvneta_port *pp, u32 status,
  1413. struct sk_buff *skb)
  1414. {
  1415. if ((status & MVNETA_RXD_L3_IP4) &&
  1416. (status & MVNETA_RXD_L4_CSUM_OK)) {
  1417. skb->csum = 0;
  1418. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1419. return;
  1420. }
  1421. skb->ip_summed = CHECKSUM_NONE;
  1422. }
  1423. /* Return tx queue pointer (find last set bit) according to <cause> returned
  1424. * form tx_done reg. <cause> must not be null. The return value is always a
  1425. * valid queue for matching the first one found in <cause>.
  1426. */
  1427. static struct mvneta_tx_queue *mvneta_tx_done_policy(struct mvneta_port *pp,
  1428. u32 cause)
  1429. {
  1430. int queue = fls(cause) - 1;
  1431. return &pp->txqs[queue];
  1432. }
  1433. /* Free tx queue skbuffs */
  1434. static void mvneta_txq_bufs_free(struct mvneta_port *pp,
  1435. struct mvneta_tx_queue *txq, int num)
  1436. {
  1437. int i;
  1438. for (i = 0; i < num; i++) {
  1439. struct mvneta_tx_desc *tx_desc = txq->descs +
  1440. txq->txq_get_index;
  1441. struct sk_buff *skb = txq->tx_skb[txq->txq_get_index];
  1442. mvneta_txq_inc_get(txq);
  1443. if (!IS_TSO_HEADER(txq, tx_desc->buf_phys_addr))
  1444. dma_unmap_single(pp->dev->dev.parent,
  1445. tx_desc->buf_phys_addr,
  1446. tx_desc->data_size, DMA_TO_DEVICE);
  1447. if (!skb)
  1448. continue;
  1449. dev_kfree_skb_any(skb);
  1450. }
  1451. }
  1452. /* Handle end of transmission */
  1453. static void mvneta_txq_done(struct mvneta_port *pp,
  1454. struct mvneta_tx_queue *txq)
  1455. {
  1456. struct netdev_queue *nq = netdev_get_tx_queue(pp->dev, txq->id);
  1457. int tx_done;
  1458. tx_done = mvneta_txq_sent_desc_proc(pp, txq);
  1459. if (!tx_done)
  1460. return;
  1461. mvneta_txq_bufs_free(pp, txq, tx_done);
  1462. txq->count -= tx_done;
  1463. if (netif_tx_queue_stopped(nq)) {
  1464. if (txq->count <= txq->tx_wake_threshold)
  1465. netif_tx_wake_queue(nq);
  1466. }
  1467. }
  1468. void *mvneta_frag_alloc(unsigned int frag_size)
  1469. {
  1470. if (likely(frag_size <= PAGE_SIZE))
  1471. return netdev_alloc_frag(frag_size);
  1472. else
  1473. return kmalloc(frag_size, GFP_ATOMIC);
  1474. }
  1475. EXPORT_SYMBOL_GPL(mvneta_frag_alloc);
  1476. void mvneta_frag_free(unsigned int frag_size, void *data)
  1477. {
  1478. if (likely(frag_size <= PAGE_SIZE))
  1479. skb_free_frag(data);
  1480. else
  1481. kfree(data);
  1482. }
  1483. EXPORT_SYMBOL_GPL(mvneta_frag_free);
  1484. /* Refill processing for SW buffer management */
  1485. static int mvneta_rx_refill(struct mvneta_port *pp,
  1486. struct mvneta_rx_desc *rx_desc)
  1487. {
  1488. dma_addr_t phys_addr;
  1489. void *data;
  1490. data = mvneta_frag_alloc(pp->frag_size);
  1491. if (!data)
  1492. return -ENOMEM;
  1493. phys_addr = dma_map_single(pp->dev->dev.parent, data,
  1494. MVNETA_RX_BUF_SIZE(pp->pkt_size),
  1495. DMA_FROM_DEVICE);
  1496. if (unlikely(dma_mapping_error(pp->dev->dev.parent, phys_addr))) {
  1497. mvneta_frag_free(pp->frag_size, data);
  1498. return -ENOMEM;
  1499. }
  1500. mvneta_rx_desc_fill(rx_desc, phys_addr, (u32)data);
  1501. return 0;
  1502. }
  1503. /* Handle tx checksum */
  1504. static u32 mvneta_skb_tx_csum(struct mvneta_port *pp, struct sk_buff *skb)
  1505. {
  1506. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  1507. int ip_hdr_len = 0;
  1508. __be16 l3_proto = vlan_get_protocol(skb);
  1509. u8 l4_proto;
  1510. if (l3_proto == htons(ETH_P_IP)) {
  1511. struct iphdr *ip4h = ip_hdr(skb);
  1512. /* Calculate IPv4 checksum and L4 checksum */
  1513. ip_hdr_len = ip4h->ihl;
  1514. l4_proto = ip4h->protocol;
  1515. } else if (l3_proto == htons(ETH_P_IPV6)) {
  1516. struct ipv6hdr *ip6h = ipv6_hdr(skb);
  1517. /* Read l4_protocol from one of IPv6 extra headers */
  1518. if (skb_network_header_len(skb) > 0)
  1519. ip_hdr_len = (skb_network_header_len(skb) >> 2);
  1520. l4_proto = ip6h->nexthdr;
  1521. } else
  1522. return MVNETA_TX_L4_CSUM_NOT;
  1523. return mvneta_txq_desc_csum(skb_network_offset(skb),
  1524. l3_proto, ip_hdr_len, l4_proto);
  1525. }
  1526. return MVNETA_TX_L4_CSUM_NOT;
  1527. }
  1528. /* Drop packets received by the RXQ and free buffers */
  1529. static void mvneta_rxq_drop_pkts(struct mvneta_port *pp,
  1530. struct mvneta_rx_queue *rxq)
  1531. {
  1532. int rx_done, i;
  1533. rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq);
  1534. if (rx_done)
  1535. mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done);
  1536. if (pp->bm_priv) {
  1537. for (i = 0; i < rx_done; i++) {
  1538. struct mvneta_rx_desc *rx_desc =
  1539. mvneta_rxq_next_desc_get(rxq);
  1540. u8 pool_id = MVNETA_RX_GET_BM_POOL_ID(rx_desc);
  1541. struct mvneta_bm_pool *bm_pool;
  1542. bm_pool = &pp->bm_priv->bm_pools[pool_id];
  1543. /* Return dropped buffer to the pool */
  1544. mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool,
  1545. rx_desc->buf_phys_addr);
  1546. }
  1547. return;
  1548. }
  1549. for (i = 0; i < rxq->size; i++) {
  1550. struct mvneta_rx_desc *rx_desc = rxq->descs + i;
  1551. void *data = (void *)rx_desc->buf_cookie;
  1552. dma_unmap_single(pp->dev->dev.parent, rx_desc->buf_phys_addr,
  1553. MVNETA_RX_BUF_SIZE(pp->pkt_size), DMA_FROM_DEVICE);
  1554. mvneta_frag_free(pp->frag_size, data);
  1555. }
  1556. }
  1557. /* Main rx processing when using software buffer management */
  1558. static int mvneta_rx_swbm(struct mvneta_port *pp, int rx_todo,
  1559. struct mvneta_rx_queue *rxq)
  1560. {
  1561. struct mvneta_pcpu_port *port = this_cpu_ptr(pp->ports);
  1562. struct net_device *dev = pp->dev;
  1563. int rx_done;
  1564. u32 rcvd_pkts = 0;
  1565. u32 rcvd_bytes = 0;
  1566. /* Get number of received packets */
  1567. rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq);
  1568. if (rx_todo > rx_done)
  1569. rx_todo = rx_done;
  1570. rx_done = 0;
  1571. /* Fairness NAPI loop */
  1572. while (rx_done < rx_todo) {
  1573. struct mvneta_rx_desc *rx_desc = mvneta_rxq_next_desc_get(rxq);
  1574. struct sk_buff *skb;
  1575. unsigned char *data;
  1576. dma_addr_t phys_addr;
  1577. u32 rx_status, frag_size;
  1578. int rx_bytes, err;
  1579. rx_done++;
  1580. rx_status = rx_desc->status;
  1581. rx_bytes = rx_desc->data_size - (ETH_FCS_LEN + MVNETA_MH_SIZE);
  1582. data = (unsigned char *)rx_desc->buf_cookie;
  1583. phys_addr = rx_desc->buf_phys_addr;
  1584. if (!mvneta_rxq_desc_is_first_last(rx_status) ||
  1585. (rx_status & MVNETA_RXD_ERR_SUMMARY)) {
  1586. mvneta_rx_error(pp, rx_desc);
  1587. err_drop_frame:
  1588. dev->stats.rx_errors++;
  1589. /* leave the descriptor untouched */
  1590. continue;
  1591. }
  1592. if (rx_bytes <= rx_copybreak) {
  1593. /* better copy a small frame and not unmap the DMA region */
  1594. skb = netdev_alloc_skb_ip_align(dev, rx_bytes);
  1595. if (unlikely(!skb))
  1596. goto err_drop_frame;
  1597. dma_sync_single_range_for_cpu(dev->dev.parent,
  1598. rx_desc->buf_phys_addr,
  1599. MVNETA_MH_SIZE + NET_SKB_PAD,
  1600. rx_bytes,
  1601. DMA_FROM_DEVICE);
  1602. memcpy(skb_put(skb, rx_bytes),
  1603. data + MVNETA_MH_SIZE + NET_SKB_PAD,
  1604. rx_bytes);
  1605. skb->protocol = eth_type_trans(skb, dev);
  1606. mvneta_rx_csum(pp, rx_status, skb);
  1607. napi_gro_receive(&port->napi, skb);
  1608. rcvd_pkts++;
  1609. rcvd_bytes += rx_bytes;
  1610. /* leave the descriptor and buffer untouched */
  1611. continue;
  1612. }
  1613. /* Refill processing */
  1614. err = mvneta_rx_refill(pp, rx_desc);
  1615. if (err) {
  1616. netdev_err(dev, "Linux processing - Can't refill\n");
  1617. rxq->missed++;
  1618. goto err_drop_frame;
  1619. }
  1620. frag_size = pp->frag_size;
  1621. skb = build_skb(data, frag_size > PAGE_SIZE ? 0 : frag_size);
  1622. /* After refill old buffer has to be unmapped regardless
  1623. * the skb is successfully built or not.
  1624. */
  1625. dma_unmap_single(dev->dev.parent, phys_addr,
  1626. MVNETA_RX_BUF_SIZE(pp->pkt_size),
  1627. DMA_FROM_DEVICE);
  1628. if (!skb)
  1629. goto err_drop_frame;
  1630. rcvd_pkts++;
  1631. rcvd_bytes += rx_bytes;
  1632. /* Linux processing */
  1633. skb_reserve(skb, MVNETA_MH_SIZE + NET_SKB_PAD);
  1634. skb_put(skb, rx_bytes);
  1635. skb->protocol = eth_type_trans(skb, dev);
  1636. mvneta_rx_csum(pp, rx_status, skb);
  1637. napi_gro_receive(&port->napi, skb);
  1638. }
  1639. if (rcvd_pkts) {
  1640. struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
  1641. u64_stats_update_begin(&stats->syncp);
  1642. stats->rx_packets += rcvd_pkts;
  1643. stats->rx_bytes += rcvd_bytes;
  1644. u64_stats_update_end(&stats->syncp);
  1645. }
  1646. /* Update rxq management counters */
  1647. mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done);
  1648. return rx_done;
  1649. }
  1650. /* Main rx processing when using hardware buffer management */
  1651. static int mvneta_rx_hwbm(struct mvneta_port *pp, int rx_todo,
  1652. struct mvneta_rx_queue *rxq)
  1653. {
  1654. struct mvneta_pcpu_port *port = this_cpu_ptr(pp->ports);
  1655. struct net_device *dev = pp->dev;
  1656. int rx_done;
  1657. u32 rcvd_pkts = 0;
  1658. u32 rcvd_bytes = 0;
  1659. /* Get number of received packets */
  1660. rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq);
  1661. if (rx_todo > rx_done)
  1662. rx_todo = rx_done;
  1663. rx_done = 0;
  1664. /* Fairness NAPI loop */
  1665. while (rx_done < rx_todo) {
  1666. struct mvneta_rx_desc *rx_desc = mvneta_rxq_next_desc_get(rxq);
  1667. struct mvneta_bm_pool *bm_pool = NULL;
  1668. struct sk_buff *skb;
  1669. unsigned char *data;
  1670. dma_addr_t phys_addr;
  1671. u32 rx_status, frag_size;
  1672. int rx_bytes, err;
  1673. u8 pool_id;
  1674. rx_done++;
  1675. rx_status = rx_desc->status;
  1676. rx_bytes = rx_desc->data_size - (ETH_FCS_LEN + MVNETA_MH_SIZE);
  1677. data = (unsigned char *)rx_desc->buf_cookie;
  1678. phys_addr = rx_desc->buf_phys_addr;
  1679. pool_id = MVNETA_RX_GET_BM_POOL_ID(rx_desc);
  1680. bm_pool = &pp->bm_priv->bm_pools[pool_id];
  1681. if (!mvneta_rxq_desc_is_first_last(rx_status) ||
  1682. (rx_status & MVNETA_RXD_ERR_SUMMARY)) {
  1683. err_drop_frame_ret_pool:
  1684. /* Return the buffer to the pool */
  1685. mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool,
  1686. rx_desc->buf_phys_addr);
  1687. err_drop_frame:
  1688. dev->stats.rx_errors++;
  1689. mvneta_rx_error(pp, rx_desc);
  1690. /* leave the descriptor untouched */
  1691. continue;
  1692. }
  1693. if (rx_bytes <= rx_copybreak) {
  1694. /* better copy a small frame and not unmap the DMA region */
  1695. skb = netdev_alloc_skb_ip_align(dev, rx_bytes);
  1696. if (unlikely(!skb))
  1697. goto err_drop_frame_ret_pool;
  1698. dma_sync_single_range_for_cpu(dev->dev.parent,
  1699. rx_desc->buf_phys_addr,
  1700. MVNETA_MH_SIZE + NET_SKB_PAD,
  1701. rx_bytes,
  1702. DMA_FROM_DEVICE);
  1703. memcpy(skb_put(skb, rx_bytes),
  1704. data + MVNETA_MH_SIZE + NET_SKB_PAD,
  1705. rx_bytes);
  1706. skb->protocol = eth_type_trans(skb, dev);
  1707. mvneta_rx_csum(pp, rx_status, skb);
  1708. napi_gro_receive(&port->napi, skb);
  1709. rcvd_pkts++;
  1710. rcvd_bytes += rx_bytes;
  1711. /* Return the buffer to the pool */
  1712. mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool,
  1713. rx_desc->buf_phys_addr);
  1714. /* leave the descriptor and buffer untouched */
  1715. continue;
  1716. }
  1717. /* Refill processing */
  1718. err = hwbm_pool_refill(&bm_pool->hwbm_pool, GFP_ATOMIC);
  1719. if (err) {
  1720. netdev_err(dev, "Linux processing - Can't refill\n");
  1721. rxq->missed++;
  1722. goto err_drop_frame_ret_pool;
  1723. }
  1724. frag_size = bm_pool->hwbm_pool.frag_size;
  1725. skb = build_skb(data, frag_size > PAGE_SIZE ? 0 : frag_size);
  1726. /* After refill old buffer has to be unmapped regardless
  1727. * the skb is successfully built or not.
  1728. */
  1729. dma_unmap_single(&pp->bm_priv->pdev->dev, phys_addr,
  1730. bm_pool->buf_size, DMA_FROM_DEVICE);
  1731. if (!skb)
  1732. goto err_drop_frame;
  1733. rcvd_pkts++;
  1734. rcvd_bytes += rx_bytes;
  1735. /* Linux processing */
  1736. skb_reserve(skb, MVNETA_MH_SIZE + NET_SKB_PAD);
  1737. skb_put(skb, rx_bytes);
  1738. skb->protocol = eth_type_trans(skb, dev);
  1739. mvneta_rx_csum(pp, rx_status, skb);
  1740. napi_gro_receive(&port->napi, skb);
  1741. }
  1742. if (rcvd_pkts) {
  1743. struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
  1744. u64_stats_update_begin(&stats->syncp);
  1745. stats->rx_packets += rcvd_pkts;
  1746. stats->rx_bytes += rcvd_bytes;
  1747. u64_stats_update_end(&stats->syncp);
  1748. }
  1749. /* Update rxq management counters */
  1750. mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done);
  1751. return rx_done;
  1752. }
  1753. static inline void
  1754. mvneta_tso_put_hdr(struct sk_buff *skb,
  1755. struct mvneta_port *pp, struct mvneta_tx_queue *txq)
  1756. {
  1757. struct mvneta_tx_desc *tx_desc;
  1758. int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  1759. txq->tx_skb[txq->txq_put_index] = NULL;
  1760. tx_desc = mvneta_txq_next_desc_get(txq);
  1761. tx_desc->data_size = hdr_len;
  1762. tx_desc->command = mvneta_skb_tx_csum(pp, skb);
  1763. tx_desc->command |= MVNETA_TXD_F_DESC;
  1764. tx_desc->buf_phys_addr = txq->tso_hdrs_phys +
  1765. txq->txq_put_index * TSO_HEADER_SIZE;
  1766. mvneta_txq_inc_put(txq);
  1767. }
  1768. static inline int
  1769. mvneta_tso_put_data(struct net_device *dev, struct mvneta_tx_queue *txq,
  1770. struct sk_buff *skb, char *data, int size,
  1771. bool last_tcp, bool is_last)
  1772. {
  1773. struct mvneta_tx_desc *tx_desc;
  1774. tx_desc = mvneta_txq_next_desc_get(txq);
  1775. tx_desc->data_size = size;
  1776. tx_desc->buf_phys_addr = dma_map_single(dev->dev.parent, data,
  1777. size, DMA_TO_DEVICE);
  1778. if (unlikely(dma_mapping_error(dev->dev.parent,
  1779. tx_desc->buf_phys_addr))) {
  1780. mvneta_txq_desc_put(txq);
  1781. return -ENOMEM;
  1782. }
  1783. tx_desc->command = 0;
  1784. txq->tx_skb[txq->txq_put_index] = NULL;
  1785. if (last_tcp) {
  1786. /* last descriptor in the TCP packet */
  1787. tx_desc->command = MVNETA_TXD_L_DESC;
  1788. /* last descriptor in SKB */
  1789. if (is_last)
  1790. txq->tx_skb[txq->txq_put_index] = skb;
  1791. }
  1792. mvneta_txq_inc_put(txq);
  1793. return 0;
  1794. }
  1795. static int mvneta_tx_tso(struct sk_buff *skb, struct net_device *dev,
  1796. struct mvneta_tx_queue *txq)
  1797. {
  1798. int total_len, data_left;
  1799. int desc_count = 0;
  1800. struct mvneta_port *pp = netdev_priv(dev);
  1801. struct tso_t tso;
  1802. int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  1803. int i;
  1804. /* Count needed descriptors */
  1805. if ((txq->count + tso_count_descs(skb)) >= txq->size)
  1806. return 0;
  1807. if (skb_headlen(skb) < (skb_transport_offset(skb) + tcp_hdrlen(skb))) {
  1808. pr_info("*** Is this even possible???!?!?\n");
  1809. return 0;
  1810. }
  1811. /* Initialize the TSO handler, and prepare the first payload */
  1812. tso_start(skb, &tso);
  1813. total_len = skb->len - hdr_len;
  1814. while (total_len > 0) {
  1815. char *hdr;
  1816. data_left = min_t(int, skb_shinfo(skb)->gso_size, total_len);
  1817. total_len -= data_left;
  1818. desc_count++;
  1819. /* prepare packet headers: MAC + IP + TCP */
  1820. hdr = txq->tso_hdrs + txq->txq_put_index * TSO_HEADER_SIZE;
  1821. tso_build_hdr(skb, hdr, &tso, data_left, total_len == 0);
  1822. mvneta_tso_put_hdr(skb, pp, txq);
  1823. while (data_left > 0) {
  1824. int size;
  1825. desc_count++;
  1826. size = min_t(int, tso.size, data_left);
  1827. if (mvneta_tso_put_data(dev, txq, skb,
  1828. tso.data, size,
  1829. size == data_left,
  1830. total_len == 0))
  1831. goto err_release;
  1832. data_left -= size;
  1833. tso_build_data(skb, &tso, size);
  1834. }
  1835. }
  1836. return desc_count;
  1837. err_release:
  1838. /* Release all used data descriptors; header descriptors must not
  1839. * be DMA-unmapped.
  1840. */
  1841. for (i = desc_count - 1; i >= 0; i--) {
  1842. struct mvneta_tx_desc *tx_desc = txq->descs + i;
  1843. if (!IS_TSO_HEADER(txq, tx_desc->buf_phys_addr))
  1844. dma_unmap_single(pp->dev->dev.parent,
  1845. tx_desc->buf_phys_addr,
  1846. tx_desc->data_size,
  1847. DMA_TO_DEVICE);
  1848. mvneta_txq_desc_put(txq);
  1849. }
  1850. return 0;
  1851. }
  1852. /* Handle tx fragmentation processing */
  1853. static int mvneta_tx_frag_process(struct mvneta_port *pp, struct sk_buff *skb,
  1854. struct mvneta_tx_queue *txq)
  1855. {
  1856. struct mvneta_tx_desc *tx_desc;
  1857. int i, nr_frags = skb_shinfo(skb)->nr_frags;
  1858. for (i = 0; i < nr_frags; i++) {
  1859. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1860. void *addr = page_address(frag->page.p) + frag->page_offset;
  1861. tx_desc = mvneta_txq_next_desc_get(txq);
  1862. tx_desc->data_size = frag->size;
  1863. tx_desc->buf_phys_addr =
  1864. dma_map_single(pp->dev->dev.parent, addr,
  1865. tx_desc->data_size, DMA_TO_DEVICE);
  1866. if (dma_mapping_error(pp->dev->dev.parent,
  1867. tx_desc->buf_phys_addr)) {
  1868. mvneta_txq_desc_put(txq);
  1869. goto error;
  1870. }
  1871. if (i == nr_frags - 1) {
  1872. /* Last descriptor */
  1873. tx_desc->command = MVNETA_TXD_L_DESC | MVNETA_TXD_Z_PAD;
  1874. txq->tx_skb[txq->txq_put_index] = skb;
  1875. } else {
  1876. /* Descriptor in the middle: Not First, Not Last */
  1877. tx_desc->command = 0;
  1878. txq->tx_skb[txq->txq_put_index] = NULL;
  1879. }
  1880. mvneta_txq_inc_put(txq);
  1881. }
  1882. return 0;
  1883. error:
  1884. /* Release all descriptors that were used to map fragments of
  1885. * this packet, as well as the corresponding DMA mappings
  1886. */
  1887. for (i = i - 1; i >= 0; i--) {
  1888. tx_desc = txq->descs + i;
  1889. dma_unmap_single(pp->dev->dev.parent,
  1890. tx_desc->buf_phys_addr,
  1891. tx_desc->data_size,
  1892. DMA_TO_DEVICE);
  1893. mvneta_txq_desc_put(txq);
  1894. }
  1895. return -ENOMEM;
  1896. }
  1897. /* Main tx processing */
  1898. static int mvneta_tx(struct sk_buff *skb, struct net_device *dev)
  1899. {
  1900. struct mvneta_port *pp = netdev_priv(dev);
  1901. u16 txq_id = skb_get_queue_mapping(skb);
  1902. struct mvneta_tx_queue *txq = &pp->txqs[txq_id];
  1903. struct mvneta_tx_desc *tx_desc;
  1904. int len = skb->len;
  1905. int frags = 0;
  1906. u32 tx_cmd;
  1907. if (!netif_running(dev))
  1908. goto out;
  1909. if (skb_is_gso(skb)) {
  1910. frags = mvneta_tx_tso(skb, dev, txq);
  1911. goto out;
  1912. }
  1913. frags = skb_shinfo(skb)->nr_frags + 1;
  1914. /* Get a descriptor for the first part of the packet */
  1915. tx_desc = mvneta_txq_next_desc_get(txq);
  1916. tx_cmd = mvneta_skb_tx_csum(pp, skb);
  1917. tx_desc->data_size = skb_headlen(skb);
  1918. tx_desc->buf_phys_addr = dma_map_single(dev->dev.parent, skb->data,
  1919. tx_desc->data_size,
  1920. DMA_TO_DEVICE);
  1921. if (unlikely(dma_mapping_error(dev->dev.parent,
  1922. tx_desc->buf_phys_addr))) {
  1923. mvneta_txq_desc_put(txq);
  1924. frags = 0;
  1925. goto out;
  1926. }
  1927. if (frags == 1) {
  1928. /* First and Last descriptor */
  1929. tx_cmd |= MVNETA_TXD_FLZ_DESC;
  1930. tx_desc->command = tx_cmd;
  1931. txq->tx_skb[txq->txq_put_index] = skb;
  1932. mvneta_txq_inc_put(txq);
  1933. } else {
  1934. /* First but not Last */
  1935. tx_cmd |= MVNETA_TXD_F_DESC;
  1936. txq->tx_skb[txq->txq_put_index] = NULL;
  1937. mvneta_txq_inc_put(txq);
  1938. tx_desc->command = tx_cmd;
  1939. /* Continue with other skb fragments */
  1940. if (mvneta_tx_frag_process(pp, skb, txq)) {
  1941. dma_unmap_single(dev->dev.parent,
  1942. tx_desc->buf_phys_addr,
  1943. tx_desc->data_size,
  1944. DMA_TO_DEVICE);
  1945. mvneta_txq_desc_put(txq);
  1946. frags = 0;
  1947. goto out;
  1948. }
  1949. }
  1950. out:
  1951. if (frags > 0) {
  1952. struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
  1953. struct netdev_queue *nq = netdev_get_tx_queue(dev, txq_id);
  1954. txq->count += frags;
  1955. mvneta_txq_pend_desc_add(pp, txq, frags);
  1956. if (txq->count >= txq->tx_stop_threshold)
  1957. netif_tx_stop_queue(nq);
  1958. u64_stats_update_begin(&stats->syncp);
  1959. stats->tx_packets++;
  1960. stats->tx_bytes += len;
  1961. u64_stats_update_end(&stats->syncp);
  1962. } else {
  1963. dev->stats.tx_dropped++;
  1964. dev_kfree_skb_any(skb);
  1965. }
  1966. return NETDEV_TX_OK;
  1967. }
  1968. /* Free tx resources, when resetting a port */
  1969. static void mvneta_txq_done_force(struct mvneta_port *pp,
  1970. struct mvneta_tx_queue *txq)
  1971. {
  1972. int tx_done = txq->count;
  1973. mvneta_txq_bufs_free(pp, txq, tx_done);
  1974. /* reset txq */
  1975. txq->count = 0;
  1976. txq->txq_put_index = 0;
  1977. txq->txq_get_index = 0;
  1978. }
  1979. /* Handle tx done - called in softirq context. The <cause_tx_done> argument
  1980. * must be a valid cause according to MVNETA_TXQ_INTR_MASK_ALL.
  1981. */
  1982. static void mvneta_tx_done_gbe(struct mvneta_port *pp, u32 cause_tx_done)
  1983. {
  1984. struct mvneta_tx_queue *txq;
  1985. struct netdev_queue *nq;
  1986. while (cause_tx_done) {
  1987. txq = mvneta_tx_done_policy(pp, cause_tx_done);
  1988. nq = netdev_get_tx_queue(pp->dev, txq->id);
  1989. __netif_tx_lock(nq, smp_processor_id());
  1990. if (txq->count)
  1991. mvneta_txq_done(pp, txq);
  1992. __netif_tx_unlock(nq);
  1993. cause_tx_done &= ~((1 << txq->id));
  1994. }
  1995. }
  1996. /* Compute crc8 of the specified address, using a unique algorithm ,
  1997. * according to hw spec, different than generic crc8 algorithm
  1998. */
  1999. static int mvneta_addr_crc(unsigned char *addr)
  2000. {
  2001. int crc = 0;
  2002. int i;
  2003. for (i = 0; i < ETH_ALEN; i++) {
  2004. int j;
  2005. crc = (crc ^ addr[i]) << 8;
  2006. for (j = 7; j >= 0; j--) {
  2007. if (crc & (0x100 << j))
  2008. crc ^= 0x107 << j;
  2009. }
  2010. }
  2011. return crc;
  2012. }
  2013. /* This method controls the net device special MAC multicast support.
  2014. * The Special Multicast Table for MAC addresses supports MAC of the form
  2015. * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0xFF).
  2016. * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
  2017. * Table entries in the DA-Filter table. This method set the Special
  2018. * Multicast Table appropriate entry.
  2019. */
  2020. static void mvneta_set_special_mcast_addr(struct mvneta_port *pp,
  2021. unsigned char last_byte,
  2022. int queue)
  2023. {
  2024. unsigned int smc_table_reg;
  2025. unsigned int tbl_offset;
  2026. unsigned int reg_offset;
  2027. /* Register offset from SMC table base */
  2028. tbl_offset = (last_byte / 4);
  2029. /* Entry offset within the above reg */
  2030. reg_offset = last_byte % 4;
  2031. smc_table_reg = mvreg_read(pp, (MVNETA_DA_FILT_SPEC_MCAST
  2032. + tbl_offset * 4));
  2033. if (queue == -1)
  2034. smc_table_reg &= ~(0xff << (8 * reg_offset));
  2035. else {
  2036. smc_table_reg &= ~(0xff << (8 * reg_offset));
  2037. smc_table_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset));
  2038. }
  2039. mvreg_write(pp, MVNETA_DA_FILT_SPEC_MCAST + tbl_offset * 4,
  2040. smc_table_reg);
  2041. }
  2042. /* This method controls the network device Other MAC multicast support.
  2043. * The Other Multicast Table is used for multicast of another type.
  2044. * A CRC-8 is used as an index to the Other Multicast Table entries
  2045. * in the DA-Filter table.
  2046. * The method gets the CRC-8 value from the calling routine and
  2047. * sets the Other Multicast Table appropriate entry according to the
  2048. * specified CRC-8 .
  2049. */
  2050. static void mvneta_set_other_mcast_addr(struct mvneta_port *pp,
  2051. unsigned char crc8,
  2052. int queue)
  2053. {
  2054. unsigned int omc_table_reg;
  2055. unsigned int tbl_offset;
  2056. unsigned int reg_offset;
  2057. tbl_offset = (crc8 / 4) * 4; /* Register offset from OMC table base */
  2058. reg_offset = crc8 % 4; /* Entry offset within the above reg */
  2059. omc_table_reg = mvreg_read(pp, MVNETA_DA_FILT_OTH_MCAST + tbl_offset);
  2060. if (queue == -1) {
  2061. /* Clear accepts frame bit at specified Other DA table entry */
  2062. omc_table_reg &= ~(0xff << (8 * reg_offset));
  2063. } else {
  2064. omc_table_reg &= ~(0xff << (8 * reg_offset));
  2065. omc_table_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset));
  2066. }
  2067. mvreg_write(pp, MVNETA_DA_FILT_OTH_MCAST + tbl_offset, omc_table_reg);
  2068. }
  2069. /* The network device supports multicast using two tables:
  2070. * 1) Special Multicast Table for MAC addresses of the form
  2071. * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0xFF).
  2072. * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
  2073. * Table entries in the DA-Filter table.
  2074. * 2) Other Multicast Table for multicast of another type. A CRC-8 value
  2075. * is used as an index to the Other Multicast Table entries in the
  2076. * DA-Filter table.
  2077. */
  2078. static int mvneta_mcast_addr_set(struct mvneta_port *pp, unsigned char *p_addr,
  2079. int queue)
  2080. {
  2081. unsigned char crc_result = 0;
  2082. if (memcmp(p_addr, "\x01\x00\x5e\x00\x00", 5) == 0) {
  2083. mvneta_set_special_mcast_addr(pp, p_addr[5], queue);
  2084. return 0;
  2085. }
  2086. crc_result = mvneta_addr_crc(p_addr);
  2087. if (queue == -1) {
  2088. if (pp->mcast_count[crc_result] == 0) {
  2089. netdev_info(pp->dev, "No valid Mcast for crc8=0x%02x\n",
  2090. crc_result);
  2091. return -EINVAL;
  2092. }
  2093. pp->mcast_count[crc_result]--;
  2094. if (pp->mcast_count[crc_result] != 0) {
  2095. netdev_info(pp->dev,
  2096. "After delete there are %d valid Mcast for crc8=0x%02x\n",
  2097. pp->mcast_count[crc_result], crc_result);
  2098. return -EINVAL;
  2099. }
  2100. } else
  2101. pp->mcast_count[crc_result]++;
  2102. mvneta_set_other_mcast_addr(pp, crc_result, queue);
  2103. return 0;
  2104. }
  2105. /* Configure Fitering mode of Ethernet port */
  2106. static void mvneta_rx_unicast_promisc_set(struct mvneta_port *pp,
  2107. int is_promisc)
  2108. {
  2109. u32 port_cfg_reg, val;
  2110. port_cfg_reg = mvreg_read(pp, MVNETA_PORT_CONFIG);
  2111. val = mvreg_read(pp, MVNETA_TYPE_PRIO);
  2112. /* Set / Clear UPM bit in port configuration register */
  2113. if (is_promisc) {
  2114. /* Accept all Unicast addresses */
  2115. port_cfg_reg |= MVNETA_UNI_PROMISC_MODE;
  2116. val |= MVNETA_FORCE_UNI;
  2117. mvreg_write(pp, MVNETA_MAC_ADDR_LOW, 0xffff);
  2118. mvreg_write(pp, MVNETA_MAC_ADDR_HIGH, 0xffffffff);
  2119. } else {
  2120. /* Reject all Unicast addresses */
  2121. port_cfg_reg &= ~MVNETA_UNI_PROMISC_MODE;
  2122. val &= ~MVNETA_FORCE_UNI;
  2123. }
  2124. mvreg_write(pp, MVNETA_PORT_CONFIG, port_cfg_reg);
  2125. mvreg_write(pp, MVNETA_TYPE_PRIO, val);
  2126. }
  2127. /* register unicast and multicast addresses */
  2128. static void mvneta_set_rx_mode(struct net_device *dev)
  2129. {
  2130. struct mvneta_port *pp = netdev_priv(dev);
  2131. struct netdev_hw_addr *ha;
  2132. if (dev->flags & IFF_PROMISC) {
  2133. /* Accept all: Multicast + Unicast */
  2134. mvneta_rx_unicast_promisc_set(pp, 1);
  2135. mvneta_set_ucast_table(pp, pp->rxq_def);
  2136. mvneta_set_special_mcast_table(pp, pp->rxq_def);
  2137. mvneta_set_other_mcast_table(pp, pp->rxq_def);
  2138. } else {
  2139. /* Accept single Unicast */
  2140. mvneta_rx_unicast_promisc_set(pp, 0);
  2141. mvneta_set_ucast_table(pp, -1);
  2142. mvneta_mac_addr_set(pp, dev->dev_addr, pp->rxq_def);
  2143. if (dev->flags & IFF_ALLMULTI) {
  2144. /* Accept all multicast */
  2145. mvneta_set_special_mcast_table(pp, pp->rxq_def);
  2146. mvneta_set_other_mcast_table(pp, pp->rxq_def);
  2147. } else {
  2148. /* Accept only initialized multicast */
  2149. mvneta_set_special_mcast_table(pp, -1);
  2150. mvneta_set_other_mcast_table(pp, -1);
  2151. if (!netdev_mc_empty(dev)) {
  2152. netdev_for_each_mc_addr(ha, dev) {
  2153. mvneta_mcast_addr_set(pp, ha->addr,
  2154. pp->rxq_def);
  2155. }
  2156. }
  2157. }
  2158. }
  2159. }
  2160. /* Interrupt handling - the callback for request_irq() */
  2161. static irqreturn_t mvneta_isr(int irq, void *dev_id)
  2162. {
  2163. struct mvneta_pcpu_port *port = (struct mvneta_pcpu_port *)dev_id;
  2164. disable_percpu_irq(port->pp->dev->irq);
  2165. napi_schedule(&port->napi);
  2166. return IRQ_HANDLED;
  2167. }
  2168. static int mvneta_fixed_link_update(struct mvneta_port *pp,
  2169. struct phy_device *phy)
  2170. {
  2171. struct fixed_phy_status status;
  2172. struct fixed_phy_status changed = {};
  2173. u32 gmac_stat = mvreg_read(pp, MVNETA_GMAC_STATUS);
  2174. status.link = !!(gmac_stat & MVNETA_GMAC_LINK_UP);
  2175. if (gmac_stat & MVNETA_GMAC_SPEED_1000)
  2176. status.speed = SPEED_1000;
  2177. else if (gmac_stat & MVNETA_GMAC_SPEED_100)
  2178. status.speed = SPEED_100;
  2179. else
  2180. status.speed = SPEED_10;
  2181. status.duplex = !!(gmac_stat & MVNETA_GMAC_FULL_DUPLEX);
  2182. changed.link = 1;
  2183. changed.speed = 1;
  2184. changed.duplex = 1;
  2185. fixed_phy_update_state(phy, &status, &changed);
  2186. return 0;
  2187. }
  2188. /* NAPI handler
  2189. * Bits 0 - 7 of the causeRxTx register indicate that are transmitted
  2190. * packets on the corresponding TXQ (Bit 0 is for TX queue 1).
  2191. * Bits 8 -15 of the cause Rx Tx register indicate that are received
  2192. * packets on the corresponding RXQ (Bit 8 is for RX queue 0).
  2193. * Each CPU has its own causeRxTx register
  2194. */
  2195. static int mvneta_poll(struct napi_struct *napi, int budget)
  2196. {
  2197. int rx_done = 0;
  2198. u32 cause_rx_tx;
  2199. int rx_queue;
  2200. struct mvneta_port *pp = netdev_priv(napi->dev);
  2201. struct net_device *ndev = pp->dev;
  2202. struct mvneta_pcpu_port *port = this_cpu_ptr(pp->ports);
  2203. if (!netif_running(pp->dev)) {
  2204. napi_complete(&port->napi);
  2205. return rx_done;
  2206. }
  2207. /* Read cause register */
  2208. cause_rx_tx = mvreg_read(pp, MVNETA_INTR_NEW_CAUSE);
  2209. if (cause_rx_tx & MVNETA_MISCINTR_INTR_MASK) {
  2210. u32 cause_misc = mvreg_read(pp, MVNETA_INTR_MISC_CAUSE);
  2211. mvreg_write(pp, MVNETA_INTR_MISC_CAUSE, 0);
  2212. if (pp->use_inband_status && (cause_misc &
  2213. (MVNETA_CAUSE_PHY_STATUS_CHANGE |
  2214. MVNETA_CAUSE_LINK_CHANGE |
  2215. MVNETA_CAUSE_PSC_SYNC_CHANGE))) {
  2216. mvneta_fixed_link_update(pp, ndev->phydev);
  2217. }
  2218. }
  2219. /* Release Tx descriptors */
  2220. if (cause_rx_tx & MVNETA_TX_INTR_MASK_ALL) {
  2221. mvneta_tx_done_gbe(pp, (cause_rx_tx & MVNETA_TX_INTR_MASK_ALL));
  2222. cause_rx_tx &= ~MVNETA_TX_INTR_MASK_ALL;
  2223. }
  2224. /* For the case where the last mvneta_poll did not process all
  2225. * RX packets
  2226. */
  2227. rx_queue = fls(((cause_rx_tx >> 8) & 0xff));
  2228. cause_rx_tx |= port->cause_rx_tx;
  2229. if (rx_queue) {
  2230. rx_queue = rx_queue - 1;
  2231. if (pp->bm_priv)
  2232. rx_done = mvneta_rx_hwbm(pp, budget, &pp->rxqs[rx_queue]);
  2233. else
  2234. rx_done = mvneta_rx_swbm(pp, budget, &pp->rxqs[rx_queue]);
  2235. }
  2236. budget -= rx_done;
  2237. if (budget > 0) {
  2238. cause_rx_tx = 0;
  2239. napi_complete(&port->napi);
  2240. enable_percpu_irq(pp->dev->irq, 0);
  2241. }
  2242. port->cause_rx_tx = cause_rx_tx;
  2243. return rx_done;
  2244. }
  2245. /* Handle rxq fill: allocates rxq skbs; called when initializing a port */
  2246. static int mvneta_rxq_fill(struct mvneta_port *pp, struct mvneta_rx_queue *rxq,
  2247. int num)
  2248. {
  2249. int i;
  2250. for (i = 0; i < num; i++) {
  2251. memset(rxq->descs + i, 0, sizeof(struct mvneta_rx_desc));
  2252. if (mvneta_rx_refill(pp, rxq->descs + i) != 0) {
  2253. netdev_err(pp->dev, "%s:rxq %d, %d of %d buffs filled\n",
  2254. __func__, rxq->id, i, num);
  2255. break;
  2256. }
  2257. }
  2258. /* Add this number of RX descriptors as non occupied (ready to
  2259. * get packets)
  2260. */
  2261. mvneta_rxq_non_occup_desc_add(pp, rxq, i);
  2262. return i;
  2263. }
  2264. /* Free all packets pending transmit from all TXQs and reset TX port */
  2265. static void mvneta_tx_reset(struct mvneta_port *pp)
  2266. {
  2267. int queue;
  2268. /* free the skb's in the tx ring */
  2269. for (queue = 0; queue < txq_number; queue++)
  2270. mvneta_txq_done_force(pp, &pp->txqs[queue]);
  2271. mvreg_write(pp, MVNETA_PORT_TX_RESET, MVNETA_PORT_TX_DMA_RESET);
  2272. mvreg_write(pp, MVNETA_PORT_TX_RESET, 0);
  2273. }
  2274. static void mvneta_rx_reset(struct mvneta_port *pp)
  2275. {
  2276. mvreg_write(pp, MVNETA_PORT_RX_RESET, MVNETA_PORT_RX_DMA_RESET);
  2277. mvreg_write(pp, MVNETA_PORT_RX_RESET, 0);
  2278. }
  2279. /* Rx/Tx queue initialization/cleanup methods */
  2280. /* Create a specified RX queue */
  2281. static int mvneta_rxq_init(struct mvneta_port *pp,
  2282. struct mvneta_rx_queue *rxq)
  2283. {
  2284. rxq->size = pp->rx_ring_size;
  2285. /* Allocate memory for RX descriptors */
  2286. rxq->descs = dma_alloc_coherent(pp->dev->dev.parent,
  2287. rxq->size * MVNETA_DESC_ALIGNED_SIZE,
  2288. &rxq->descs_phys, GFP_KERNEL);
  2289. if (rxq->descs == NULL)
  2290. return -ENOMEM;
  2291. rxq->last_desc = rxq->size - 1;
  2292. /* Set Rx descriptors queue starting address */
  2293. mvreg_write(pp, MVNETA_RXQ_BASE_ADDR_REG(rxq->id), rxq->descs_phys);
  2294. mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), rxq->size);
  2295. /* Set Offset */
  2296. mvneta_rxq_offset_set(pp, rxq, NET_SKB_PAD);
  2297. /* Set coalescing pkts and time */
  2298. mvneta_rx_pkts_coal_set(pp, rxq, rxq->pkts_coal);
  2299. mvneta_rx_time_coal_set(pp, rxq, rxq->time_coal);
  2300. if (!pp->bm_priv) {
  2301. /* Fill RXQ with buffers from RX pool */
  2302. mvneta_rxq_buf_size_set(pp, rxq,
  2303. MVNETA_RX_BUF_SIZE(pp->pkt_size));
  2304. mvneta_rxq_bm_disable(pp, rxq);
  2305. } else {
  2306. mvneta_rxq_bm_enable(pp, rxq);
  2307. mvneta_rxq_long_pool_set(pp, rxq);
  2308. mvneta_rxq_short_pool_set(pp, rxq);
  2309. }
  2310. mvneta_rxq_fill(pp, rxq, rxq->size);
  2311. return 0;
  2312. }
  2313. /* Cleanup Rx queue */
  2314. static void mvneta_rxq_deinit(struct mvneta_port *pp,
  2315. struct mvneta_rx_queue *rxq)
  2316. {
  2317. mvneta_rxq_drop_pkts(pp, rxq);
  2318. if (rxq->descs)
  2319. dma_free_coherent(pp->dev->dev.parent,
  2320. rxq->size * MVNETA_DESC_ALIGNED_SIZE,
  2321. rxq->descs,
  2322. rxq->descs_phys);
  2323. rxq->descs = NULL;
  2324. rxq->last_desc = 0;
  2325. rxq->next_desc_to_proc = 0;
  2326. rxq->descs_phys = 0;
  2327. }
  2328. /* Create and initialize a tx queue */
  2329. static int mvneta_txq_init(struct mvneta_port *pp,
  2330. struct mvneta_tx_queue *txq)
  2331. {
  2332. int cpu;
  2333. txq->size = pp->tx_ring_size;
  2334. /* A queue must always have room for at least one skb.
  2335. * Therefore, stop the queue when the free entries reaches
  2336. * the maximum number of descriptors per skb.
  2337. */
  2338. txq->tx_stop_threshold = txq->size - MVNETA_MAX_SKB_DESCS;
  2339. txq->tx_wake_threshold = txq->tx_stop_threshold / 2;
  2340. /* Allocate memory for TX descriptors */
  2341. txq->descs = dma_alloc_coherent(pp->dev->dev.parent,
  2342. txq->size * MVNETA_DESC_ALIGNED_SIZE,
  2343. &txq->descs_phys, GFP_KERNEL);
  2344. if (txq->descs == NULL)
  2345. return -ENOMEM;
  2346. txq->last_desc = txq->size - 1;
  2347. /* Set maximum bandwidth for enabled TXQs */
  2348. mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(txq->id), 0x03ffffff);
  2349. mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(txq->id), 0x3fffffff);
  2350. /* Set Tx descriptors queue starting address */
  2351. mvreg_write(pp, MVNETA_TXQ_BASE_ADDR_REG(txq->id), txq->descs_phys);
  2352. mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), txq->size);
  2353. txq->tx_skb = kmalloc(txq->size * sizeof(*txq->tx_skb), GFP_KERNEL);
  2354. if (txq->tx_skb == NULL) {
  2355. dma_free_coherent(pp->dev->dev.parent,
  2356. txq->size * MVNETA_DESC_ALIGNED_SIZE,
  2357. txq->descs, txq->descs_phys);
  2358. return -ENOMEM;
  2359. }
  2360. /* Allocate DMA buffers for TSO MAC/IP/TCP headers */
  2361. txq->tso_hdrs = dma_alloc_coherent(pp->dev->dev.parent,
  2362. txq->size * TSO_HEADER_SIZE,
  2363. &txq->tso_hdrs_phys, GFP_KERNEL);
  2364. if (txq->tso_hdrs == NULL) {
  2365. kfree(txq->tx_skb);
  2366. dma_free_coherent(pp->dev->dev.parent,
  2367. txq->size * MVNETA_DESC_ALIGNED_SIZE,
  2368. txq->descs, txq->descs_phys);
  2369. return -ENOMEM;
  2370. }
  2371. mvneta_tx_done_pkts_coal_set(pp, txq, txq->done_pkts_coal);
  2372. /* Setup XPS mapping */
  2373. if (txq_number > 1)
  2374. cpu = txq->id % num_present_cpus();
  2375. else
  2376. cpu = pp->rxq_def % num_present_cpus();
  2377. cpumask_set_cpu(cpu, &txq->affinity_mask);
  2378. netif_set_xps_queue(pp->dev, &txq->affinity_mask, txq->id);
  2379. return 0;
  2380. }
  2381. /* Free allocated resources when mvneta_txq_init() fails to allocate memory*/
  2382. static void mvneta_txq_deinit(struct mvneta_port *pp,
  2383. struct mvneta_tx_queue *txq)
  2384. {
  2385. kfree(txq->tx_skb);
  2386. if (txq->tso_hdrs)
  2387. dma_free_coherent(pp->dev->dev.parent,
  2388. txq->size * TSO_HEADER_SIZE,
  2389. txq->tso_hdrs, txq->tso_hdrs_phys);
  2390. if (txq->descs)
  2391. dma_free_coherent(pp->dev->dev.parent,
  2392. txq->size * MVNETA_DESC_ALIGNED_SIZE,
  2393. txq->descs, txq->descs_phys);
  2394. txq->descs = NULL;
  2395. txq->last_desc = 0;
  2396. txq->next_desc_to_proc = 0;
  2397. txq->descs_phys = 0;
  2398. /* Set minimum bandwidth for disabled TXQs */
  2399. mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(txq->id), 0);
  2400. mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(txq->id), 0);
  2401. /* Set Tx descriptors queue starting address and size */
  2402. mvreg_write(pp, MVNETA_TXQ_BASE_ADDR_REG(txq->id), 0);
  2403. mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), 0);
  2404. }
  2405. /* Cleanup all Tx queues */
  2406. static void mvneta_cleanup_txqs(struct mvneta_port *pp)
  2407. {
  2408. int queue;
  2409. for (queue = 0; queue < txq_number; queue++)
  2410. mvneta_txq_deinit(pp, &pp->txqs[queue]);
  2411. }
  2412. /* Cleanup all Rx queues */
  2413. static void mvneta_cleanup_rxqs(struct mvneta_port *pp)
  2414. {
  2415. int queue;
  2416. for (queue = 0; queue < rxq_number; queue++)
  2417. mvneta_rxq_deinit(pp, &pp->rxqs[queue]);
  2418. }
  2419. /* Init all Rx queues */
  2420. static int mvneta_setup_rxqs(struct mvneta_port *pp)
  2421. {
  2422. int queue;
  2423. for (queue = 0; queue < rxq_number; queue++) {
  2424. int err = mvneta_rxq_init(pp, &pp->rxqs[queue]);
  2425. if (err) {
  2426. netdev_err(pp->dev, "%s: can't create rxq=%d\n",
  2427. __func__, queue);
  2428. mvneta_cleanup_rxqs(pp);
  2429. return err;
  2430. }
  2431. }
  2432. return 0;
  2433. }
  2434. /* Init all tx queues */
  2435. static int mvneta_setup_txqs(struct mvneta_port *pp)
  2436. {
  2437. int queue;
  2438. for (queue = 0; queue < txq_number; queue++) {
  2439. int err = mvneta_txq_init(pp, &pp->txqs[queue]);
  2440. if (err) {
  2441. netdev_err(pp->dev, "%s: can't create txq=%d\n",
  2442. __func__, queue);
  2443. mvneta_cleanup_txqs(pp);
  2444. return err;
  2445. }
  2446. }
  2447. return 0;
  2448. }
  2449. static void mvneta_start_dev(struct mvneta_port *pp)
  2450. {
  2451. int cpu;
  2452. struct net_device *ndev = pp->dev;
  2453. mvneta_max_rx_size_set(pp, pp->pkt_size);
  2454. mvneta_txq_max_tx_size_set(pp, pp->pkt_size);
  2455. /* start the Rx/Tx activity */
  2456. mvneta_port_enable(pp);
  2457. /* Enable polling on the port */
  2458. for_each_online_cpu(cpu) {
  2459. struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu);
  2460. napi_enable(&port->napi);
  2461. }
  2462. /* Unmask interrupts. It has to be done from each CPU */
  2463. on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true);
  2464. mvreg_write(pp, MVNETA_INTR_MISC_MASK,
  2465. MVNETA_CAUSE_PHY_STATUS_CHANGE |
  2466. MVNETA_CAUSE_LINK_CHANGE |
  2467. MVNETA_CAUSE_PSC_SYNC_CHANGE);
  2468. phy_start(ndev->phydev);
  2469. netif_tx_start_all_queues(pp->dev);
  2470. }
  2471. static void mvneta_stop_dev(struct mvneta_port *pp)
  2472. {
  2473. unsigned int cpu;
  2474. struct net_device *ndev = pp->dev;
  2475. phy_stop(ndev->phydev);
  2476. for_each_online_cpu(cpu) {
  2477. struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu);
  2478. napi_disable(&port->napi);
  2479. }
  2480. netif_carrier_off(pp->dev);
  2481. mvneta_port_down(pp);
  2482. netif_tx_stop_all_queues(pp->dev);
  2483. /* Stop the port activity */
  2484. mvneta_port_disable(pp);
  2485. /* Clear all ethernet port interrupts */
  2486. on_each_cpu(mvneta_percpu_clear_intr_cause, pp, true);
  2487. /* Mask all ethernet port interrupts */
  2488. on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
  2489. mvneta_tx_reset(pp);
  2490. mvneta_rx_reset(pp);
  2491. }
  2492. /* Return positive if MTU is valid */
  2493. static int mvneta_check_mtu_valid(struct net_device *dev, int mtu)
  2494. {
  2495. if (mtu < 68) {
  2496. netdev_err(dev, "cannot change mtu to less than 68\n");
  2497. return -EINVAL;
  2498. }
  2499. /* 9676 == 9700 - 20 and rounding to 8 */
  2500. if (mtu > 9676) {
  2501. netdev_info(dev, "Illegal MTU value %d, round to 9676\n", mtu);
  2502. mtu = 9676;
  2503. }
  2504. if (!IS_ALIGNED(MVNETA_RX_PKT_SIZE(mtu), 8)) {
  2505. netdev_info(dev, "Illegal MTU value %d, rounding to %d\n",
  2506. mtu, ALIGN(MVNETA_RX_PKT_SIZE(mtu), 8));
  2507. mtu = ALIGN(MVNETA_RX_PKT_SIZE(mtu), 8);
  2508. }
  2509. return mtu;
  2510. }
  2511. static void mvneta_percpu_enable(void *arg)
  2512. {
  2513. struct mvneta_port *pp = arg;
  2514. enable_percpu_irq(pp->dev->irq, IRQ_TYPE_NONE);
  2515. }
  2516. static void mvneta_percpu_disable(void *arg)
  2517. {
  2518. struct mvneta_port *pp = arg;
  2519. disable_percpu_irq(pp->dev->irq);
  2520. }
  2521. /* Change the device mtu */
  2522. static int mvneta_change_mtu(struct net_device *dev, int mtu)
  2523. {
  2524. struct mvneta_port *pp = netdev_priv(dev);
  2525. int ret;
  2526. mtu = mvneta_check_mtu_valid(dev, mtu);
  2527. if (mtu < 0)
  2528. return -EINVAL;
  2529. dev->mtu = mtu;
  2530. if (!netif_running(dev)) {
  2531. if (pp->bm_priv)
  2532. mvneta_bm_update_mtu(pp, mtu);
  2533. netdev_update_features(dev);
  2534. return 0;
  2535. }
  2536. /* The interface is running, so we have to force a
  2537. * reallocation of the queues
  2538. */
  2539. mvneta_stop_dev(pp);
  2540. on_each_cpu(mvneta_percpu_disable, pp, true);
  2541. mvneta_cleanup_txqs(pp);
  2542. mvneta_cleanup_rxqs(pp);
  2543. if (pp->bm_priv)
  2544. mvneta_bm_update_mtu(pp, mtu);
  2545. pp->pkt_size = MVNETA_RX_PKT_SIZE(dev->mtu);
  2546. pp->frag_size = SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(pp->pkt_size)) +
  2547. SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
  2548. ret = mvneta_setup_rxqs(pp);
  2549. if (ret) {
  2550. netdev_err(dev, "unable to setup rxqs after MTU change\n");
  2551. return ret;
  2552. }
  2553. ret = mvneta_setup_txqs(pp);
  2554. if (ret) {
  2555. netdev_err(dev, "unable to setup txqs after MTU change\n");
  2556. return ret;
  2557. }
  2558. on_each_cpu(mvneta_percpu_enable, pp, true);
  2559. mvneta_start_dev(pp);
  2560. mvneta_port_up(pp);
  2561. netdev_update_features(dev);
  2562. return 0;
  2563. }
  2564. static netdev_features_t mvneta_fix_features(struct net_device *dev,
  2565. netdev_features_t features)
  2566. {
  2567. struct mvneta_port *pp = netdev_priv(dev);
  2568. if (pp->tx_csum_limit && dev->mtu > pp->tx_csum_limit) {
  2569. features &= ~(NETIF_F_IP_CSUM | NETIF_F_TSO);
  2570. netdev_info(dev,
  2571. "Disable IP checksum for MTU greater than %dB\n",
  2572. pp->tx_csum_limit);
  2573. }
  2574. return features;
  2575. }
  2576. /* Get mac address */
  2577. static void mvneta_get_mac_addr(struct mvneta_port *pp, unsigned char *addr)
  2578. {
  2579. u32 mac_addr_l, mac_addr_h;
  2580. mac_addr_l = mvreg_read(pp, MVNETA_MAC_ADDR_LOW);
  2581. mac_addr_h = mvreg_read(pp, MVNETA_MAC_ADDR_HIGH);
  2582. addr[0] = (mac_addr_h >> 24) & 0xFF;
  2583. addr[1] = (mac_addr_h >> 16) & 0xFF;
  2584. addr[2] = (mac_addr_h >> 8) & 0xFF;
  2585. addr[3] = mac_addr_h & 0xFF;
  2586. addr[4] = (mac_addr_l >> 8) & 0xFF;
  2587. addr[5] = mac_addr_l & 0xFF;
  2588. }
  2589. /* Handle setting mac address */
  2590. static int mvneta_set_mac_addr(struct net_device *dev, void *addr)
  2591. {
  2592. struct mvneta_port *pp = netdev_priv(dev);
  2593. struct sockaddr *sockaddr = addr;
  2594. int ret;
  2595. ret = eth_prepare_mac_addr_change(dev, addr);
  2596. if (ret < 0)
  2597. return ret;
  2598. /* Remove previous address table entry */
  2599. mvneta_mac_addr_set(pp, dev->dev_addr, -1);
  2600. /* Set new addr in hw */
  2601. mvneta_mac_addr_set(pp, sockaddr->sa_data, pp->rxq_def);
  2602. eth_commit_mac_addr_change(dev, addr);
  2603. return 0;
  2604. }
  2605. static void mvneta_adjust_link(struct net_device *ndev)
  2606. {
  2607. struct mvneta_port *pp = netdev_priv(ndev);
  2608. struct phy_device *phydev = ndev->phydev;
  2609. int status_change = 0;
  2610. if (phydev->link) {
  2611. if ((pp->speed != phydev->speed) ||
  2612. (pp->duplex != phydev->duplex)) {
  2613. u32 val;
  2614. val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
  2615. val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
  2616. MVNETA_GMAC_CONFIG_GMII_SPEED |
  2617. MVNETA_GMAC_CONFIG_FULL_DUPLEX);
  2618. if (phydev->duplex)
  2619. val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
  2620. if (phydev->speed == SPEED_1000)
  2621. val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
  2622. else if (phydev->speed == SPEED_100)
  2623. val |= MVNETA_GMAC_CONFIG_MII_SPEED;
  2624. mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
  2625. pp->duplex = phydev->duplex;
  2626. pp->speed = phydev->speed;
  2627. }
  2628. }
  2629. if (phydev->link != pp->link) {
  2630. if (!phydev->link) {
  2631. pp->duplex = -1;
  2632. pp->speed = 0;
  2633. }
  2634. pp->link = phydev->link;
  2635. status_change = 1;
  2636. }
  2637. if (status_change) {
  2638. if (phydev->link) {
  2639. if (!pp->use_inband_status) {
  2640. u32 val = mvreg_read(pp,
  2641. MVNETA_GMAC_AUTONEG_CONFIG);
  2642. val &= ~MVNETA_GMAC_FORCE_LINK_DOWN;
  2643. val |= MVNETA_GMAC_FORCE_LINK_PASS;
  2644. mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG,
  2645. val);
  2646. }
  2647. mvneta_port_up(pp);
  2648. } else {
  2649. if (!pp->use_inband_status) {
  2650. u32 val = mvreg_read(pp,
  2651. MVNETA_GMAC_AUTONEG_CONFIG);
  2652. val &= ~MVNETA_GMAC_FORCE_LINK_PASS;
  2653. val |= MVNETA_GMAC_FORCE_LINK_DOWN;
  2654. mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG,
  2655. val);
  2656. }
  2657. mvneta_port_down(pp);
  2658. }
  2659. phy_print_status(phydev);
  2660. }
  2661. }
  2662. static int mvneta_mdio_probe(struct mvneta_port *pp)
  2663. {
  2664. struct phy_device *phy_dev;
  2665. phy_dev = of_phy_connect(pp->dev, pp->phy_node, mvneta_adjust_link, 0,
  2666. pp->phy_interface);
  2667. if (!phy_dev) {
  2668. netdev_err(pp->dev, "could not find the PHY\n");
  2669. return -ENODEV;
  2670. }
  2671. phy_dev->supported &= PHY_GBIT_FEATURES;
  2672. phy_dev->advertising = phy_dev->supported;
  2673. pp->link = 0;
  2674. pp->duplex = 0;
  2675. pp->speed = 0;
  2676. return 0;
  2677. }
  2678. static void mvneta_mdio_remove(struct mvneta_port *pp)
  2679. {
  2680. struct net_device *ndev = pp->dev;
  2681. phy_disconnect(ndev->phydev);
  2682. }
  2683. /* Electing a CPU must be done in an atomic way: it should be done
  2684. * after or before the removal/insertion of a CPU and this function is
  2685. * not reentrant.
  2686. */
  2687. static void mvneta_percpu_elect(struct mvneta_port *pp)
  2688. {
  2689. int elected_cpu = 0, max_cpu, cpu, i = 0;
  2690. /* Use the cpu associated to the rxq when it is online, in all
  2691. * the other cases, use the cpu 0 which can't be offline.
  2692. */
  2693. if (cpu_online(pp->rxq_def))
  2694. elected_cpu = pp->rxq_def;
  2695. max_cpu = num_present_cpus();
  2696. for_each_online_cpu(cpu) {
  2697. int rxq_map = 0, txq_map = 0;
  2698. int rxq;
  2699. for (rxq = 0; rxq < rxq_number; rxq++)
  2700. if ((rxq % max_cpu) == cpu)
  2701. rxq_map |= MVNETA_CPU_RXQ_ACCESS(rxq);
  2702. if (cpu == elected_cpu)
  2703. /* Map the default receive queue queue to the
  2704. * elected CPU
  2705. */
  2706. rxq_map |= MVNETA_CPU_RXQ_ACCESS(pp->rxq_def);
  2707. /* We update the TX queue map only if we have one
  2708. * queue. In this case we associate the TX queue to
  2709. * the CPU bound to the default RX queue
  2710. */
  2711. if (txq_number == 1)
  2712. txq_map = (cpu == elected_cpu) ?
  2713. MVNETA_CPU_TXQ_ACCESS(1) : 0;
  2714. else
  2715. txq_map = mvreg_read(pp, MVNETA_CPU_MAP(cpu)) &
  2716. MVNETA_CPU_TXQ_ACCESS_ALL_MASK;
  2717. mvreg_write(pp, MVNETA_CPU_MAP(cpu), rxq_map | txq_map);
  2718. /* Update the interrupt mask on each CPU according the
  2719. * new mapping
  2720. */
  2721. smp_call_function_single(cpu, mvneta_percpu_unmask_interrupt,
  2722. pp, true);
  2723. i++;
  2724. }
  2725. };
  2726. static int mvneta_cpu_online(unsigned int cpu, struct hlist_node *node)
  2727. {
  2728. int other_cpu;
  2729. struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port,
  2730. node_online);
  2731. struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu);
  2732. spin_lock(&pp->lock);
  2733. /*
  2734. * Configuring the driver for a new CPU while the driver is
  2735. * stopping is racy, so just avoid it.
  2736. */
  2737. if (pp->is_stopped) {
  2738. spin_unlock(&pp->lock);
  2739. return 0;
  2740. }
  2741. netif_tx_stop_all_queues(pp->dev);
  2742. /*
  2743. * We have to synchronise on tha napi of each CPU except the one
  2744. * just being woken up
  2745. */
  2746. for_each_online_cpu(other_cpu) {
  2747. if (other_cpu != cpu) {
  2748. struct mvneta_pcpu_port *other_port =
  2749. per_cpu_ptr(pp->ports, other_cpu);
  2750. napi_synchronize(&other_port->napi);
  2751. }
  2752. }
  2753. /* Mask all ethernet port interrupts */
  2754. on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
  2755. napi_enable(&port->napi);
  2756. /*
  2757. * Enable per-CPU interrupts on the CPU that is
  2758. * brought up.
  2759. */
  2760. mvneta_percpu_enable(pp);
  2761. /*
  2762. * Enable per-CPU interrupt on the one CPU we care
  2763. * about.
  2764. */
  2765. mvneta_percpu_elect(pp);
  2766. /* Unmask all ethernet port interrupts */
  2767. on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true);
  2768. mvreg_write(pp, MVNETA_INTR_MISC_MASK,
  2769. MVNETA_CAUSE_PHY_STATUS_CHANGE |
  2770. MVNETA_CAUSE_LINK_CHANGE |
  2771. MVNETA_CAUSE_PSC_SYNC_CHANGE);
  2772. netif_tx_start_all_queues(pp->dev);
  2773. spin_unlock(&pp->lock);
  2774. return 0;
  2775. }
  2776. static int mvneta_cpu_down_prepare(unsigned int cpu, struct hlist_node *node)
  2777. {
  2778. struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port,
  2779. node_online);
  2780. struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu);
  2781. /*
  2782. * Thanks to this lock we are sure that any pending cpu election is
  2783. * done.
  2784. */
  2785. spin_lock(&pp->lock);
  2786. /* Mask all ethernet port interrupts */
  2787. on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
  2788. spin_unlock(&pp->lock);
  2789. napi_synchronize(&port->napi);
  2790. napi_disable(&port->napi);
  2791. /* Disable per-CPU interrupts on the CPU that is brought down. */
  2792. mvneta_percpu_disable(pp);
  2793. return 0;
  2794. }
  2795. static int mvneta_cpu_dead(unsigned int cpu, struct hlist_node *node)
  2796. {
  2797. struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port,
  2798. node_dead);
  2799. /* Check if a new CPU must be elected now this on is down */
  2800. spin_lock(&pp->lock);
  2801. mvneta_percpu_elect(pp);
  2802. spin_unlock(&pp->lock);
  2803. /* Unmask all ethernet port interrupts */
  2804. on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true);
  2805. mvreg_write(pp, MVNETA_INTR_MISC_MASK,
  2806. MVNETA_CAUSE_PHY_STATUS_CHANGE |
  2807. MVNETA_CAUSE_LINK_CHANGE |
  2808. MVNETA_CAUSE_PSC_SYNC_CHANGE);
  2809. netif_tx_start_all_queues(pp->dev);
  2810. return 0;
  2811. }
  2812. static int mvneta_open(struct net_device *dev)
  2813. {
  2814. struct mvneta_port *pp = netdev_priv(dev);
  2815. int ret;
  2816. pp->pkt_size = MVNETA_RX_PKT_SIZE(pp->dev->mtu);
  2817. pp->frag_size = SKB_DATA_ALIGN(MVNETA_RX_BUF_SIZE(pp->pkt_size)) +
  2818. SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
  2819. ret = mvneta_setup_rxqs(pp);
  2820. if (ret)
  2821. return ret;
  2822. ret = mvneta_setup_txqs(pp);
  2823. if (ret)
  2824. goto err_cleanup_rxqs;
  2825. /* Connect to port interrupt line */
  2826. ret = request_percpu_irq(pp->dev->irq, mvneta_isr,
  2827. MVNETA_DRIVER_NAME, pp->ports);
  2828. if (ret) {
  2829. netdev_err(pp->dev, "cannot request irq %d\n", pp->dev->irq);
  2830. goto err_cleanup_txqs;
  2831. }
  2832. /* Enable per-CPU interrupt on all the CPU to handle our RX
  2833. * queue interrupts
  2834. */
  2835. on_each_cpu(mvneta_percpu_enable, pp, true);
  2836. pp->is_stopped = false;
  2837. /* Register a CPU notifier to handle the case where our CPU
  2838. * might be taken offline.
  2839. */
  2840. ret = cpuhp_state_add_instance_nocalls(online_hpstate,
  2841. &pp->node_online);
  2842. if (ret)
  2843. goto err_free_irq;
  2844. ret = cpuhp_state_add_instance_nocalls(CPUHP_NET_MVNETA_DEAD,
  2845. &pp->node_dead);
  2846. if (ret)
  2847. goto err_free_online_hp;
  2848. /* In default link is down */
  2849. netif_carrier_off(pp->dev);
  2850. ret = mvneta_mdio_probe(pp);
  2851. if (ret < 0) {
  2852. netdev_err(dev, "cannot probe MDIO bus\n");
  2853. goto err_free_dead_hp;
  2854. }
  2855. mvneta_start_dev(pp);
  2856. return 0;
  2857. err_free_dead_hp:
  2858. cpuhp_state_remove_instance_nocalls(CPUHP_NET_MVNETA_DEAD,
  2859. &pp->node_dead);
  2860. err_free_online_hp:
  2861. cpuhp_state_remove_instance_nocalls(online_hpstate, &pp->node_online);
  2862. err_free_irq:
  2863. on_each_cpu(mvneta_percpu_disable, pp, true);
  2864. free_percpu_irq(pp->dev->irq, pp->ports);
  2865. err_cleanup_txqs:
  2866. mvneta_cleanup_txqs(pp);
  2867. err_cleanup_rxqs:
  2868. mvneta_cleanup_rxqs(pp);
  2869. return ret;
  2870. }
  2871. /* Stop the port, free port interrupt line */
  2872. static int mvneta_stop(struct net_device *dev)
  2873. {
  2874. struct mvneta_port *pp = netdev_priv(dev);
  2875. /* Inform that we are stopping so we don't want to setup the
  2876. * driver for new CPUs in the notifiers. The code of the
  2877. * notifier for CPU online is protected by the same spinlock,
  2878. * so when we get the lock, the notifer work is done.
  2879. */
  2880. spin_lock(&pp->lock);
  2881. pp->is_stopped = true;
  2882. spin_unlock(&pp->lock);
  2883. mvneta_stop_dev(pp);
  2884. mvneta_mdio_remove(pp);
  2885. cpuhp_state_remove_instance_nocalls(online_hpstate, &pp->node_online);
  2886. cpuhp_state_remove_instance_nocalls(CPUHP_NET_MVNETA_DEAD,
  2887. &pp->node_dead);
  2888. on_each_cpu(mvneta_percpu_disable, pp, true);
  2889. free_percpu_irq(dev->irq, pp->ports);
  2890. mvneta_cleanup_rxqs(pp);
  2891. mvneta_cleanup_txqs(pp);
  2892. return 0;
  2893. }
  2894. static int mvneta_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  2895. {
  2896. if (!dev->phydev)
  2897. return -ENOTSUPP;
  2898. return phy_mii_ioctl(dev->phydev, ifr, cmd);
  2899. }
  2900. /* Ethtool methods */
  2901. /* Set link ksettings (phy address, speed) for ethtools */
  2902. static int
  2903. mvneta_ethtool_set_link_ksettings(struct net_device *ndev,
  2904. const struct ethtool_link_ksettings *cmd)
  2905. {
  2906. struct mvneta_port *pp = netdev_priv(ndev);
  2907. struct phy_device *phydev = ndev->phydev;
  2908. if (!phydev)
  2909. return -ENODEV;
  2910. if ((cmd->base.autoneg == AUTONEG_ENABLE) != pp->use_inband_status) {
  2911. u32 val;
  2912. mvneta_set_autoneg(pp, cmd->base.autoneg == AUTONEG_ENABLE);
  2913. if (cmd->base.autoneg == AUTONEG_DISABLE) {
  2914. val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
  2915. val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
  2916. MVNETA_GMAC_CONFIG_GMII_SPEED |
  2917. MVNETA_GMAC_CONFIG_FULL_DUPLEX);
  2918. if (phydev->duplex)
  2919. val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
  2920. if (phydev->speed == SPEED_1000)
  2921. val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
  2922. else if (phydev->speed == SPEED_100)
  2923. val |= MVNETA_GMAC_CONFIG_MII_SPEED;
  2924. mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
  2925. }
  2926. pp->use_inband_status = (cmd->base.autoneg == AUTONEG_ENABLE);
  2927. netdev_info(pp->dev, "autoneg status set to %i\n",
  2928. pp->use_inband_status);
  2929. if (netif_running(ndev)) {
  2930. mvneta_port_down(pp);
  2931. mvneta_port_up(pp);
  2932. }
  2933. }
  2934. return phy_ethtool_ksettings_set(ndev->phydev, cmd);
  2935. }
  2936. /* Set interrupt coalescing for ethtools */
  2937. static int mvneta_ethtool_set_coalesce(struct net_device *dev,
  2938. struct ethtool_coalesce *c)
  2939. {
  2940. struct mvneta_port *pp = netdev_priv(dev);
  2941. int queue;
  2942. for (queue = 0; queue < rxq_number; queue++) {
  2943. struct mvneta_rx_queue *rxq = &pp->rxqs[queue];
  2944. rxq->time_coal = c->rx_coalesce_usecs;
  2945. rxq->pkts_coal = c->rx_max_coalesced_frames;
  2946. mvneta_rx_pkts_coal_set(pp, rxq, rxq->pkts_coal);
  2947. mvneta_rx_time_coal_set(pp, rxq, rxq->time_coal);
  2948. }
  2949. for (queue = 0; queue < txq_number; queue++) {
  2950. struct mvneta_tx_queue *txq = &pp->txqs[queue];
  2951. txq->done_pkts_coal = c->tx_max_coalesced_frames;
  2952. mvneta_tx_done_pkts_coal_set(pp, txq, txq->done_pkts_coal);
  2953. }
  2954. return 0;
  2955. }
  2956. /* get coalescing for ethtools */
  2957. static int mvneta_ethtool_get_coalesce(struct net_device *dev,
  2958. struct ethtool_coalesce *c)
  2959. {
  2960. struct mvneta_port *pp = netdev_priv(dev);
  2961. c->rx_coalesce_usecs = pp->rxqs[0].time_coal;
  2962. c->rx_max_coalesced_frames = pp->rxqs[0].pkts_coal;
  2963. c->tx_max_coalesced_frames = pp->txqs[0].done_pkts_coal;
  2964. return 0;
  2965. }
  2966. static void mvneta_ethtool_get_drvinfo(struct net_device *dev,
  2967. struct ethtool_drvinfo *drvinfo)
  2968. {
  2969. strlcpy(drvinfo->driver, MVNETA_DRIVER_NAME,
  2970. sizeof(drvinfo->driver));
  2971. strlcpy(drvinfo->version, MVNETA_DRIVER_VERSION,
  2972. sizeof(drvinfo->version));
  2973. strlcpy(drvinfo->bus_info, dev_name(&dev->dev),
  2974. sizeof(drvinfo->bus_info));
  2975. }
  2976. static void mvneta_ethtool_get_ringparam(struct net_device *netdev,
  2977. struct ethtool_ringparam *ring)
  2978. {
  2979. struct mvneta_port *pp = netdev_priv(netdev);
  2980. ring->rx_max_pending = MVNETA_MAX_RXD;
  2981. ring->tx_max_pending = MVNETA_MAX_TXD;
  2982. ring->rx_pending = pp->rx_ring_size;
  2983. ring->tx_pending = pp->tx_ring_size;
  2984. }
  2985. static int mvneta_ethtool_set_ringparam(struct net_device *dev,
  2986. struct ethtool_ringparam *ring)
  2987. {
  2988. struct mvneta_port *pp = netdev_priv(dev);
  2989. if ((ring->rx_pending == 0) || (ring->tx_pending == 0))
  2990. return -EINVAL;
  2991. pp->rx_ring_size = ring->rx_pending < MVNETA_MAX_RXD ?
  2992. ring->rx_pending : MVNETA_MAX_RXD;
  2993. pp->tx_ring_size = clamp_t(u16, ring->tx_pending,
  2994. MVNETA_MAX_SKB_DESCS * 2, MVNETA_MAX_TXD);
  2995. if (pp->tx_ring_size != ring->tx_pending)
  2996. netdev_warn(dev, "TX queue size set to %u (requested %u)\n",
  2997. pp->tx_ring_size, ring->tx_pending);
  2998. if (netif_running(dev)) {
  2999. mvneta_stop(dev);
  3000. if (mvneta_open(dev)) {
  3001. netdev_err(dev,
  3002. "error on opening device after ring param change\n");
  3003. return -ENOMEM;
  3004. }
  3005. }
  3006. return 0;
  3007. }
  3008. static void mvneta_ethtool_get_strings(struct net_device *netdev, u32 sset,
  3009. u8 *data)
  3010. {
  3011. if (sset == ETH_SS_STATS) {
  3012. int i;
  3013. for (i = 0; i < ARRAY_SIZE(mvneta_statistics); i++)
  3014. memcpy(data + i * ETH_GSTRING_LEN,
  3015. mvneta_statistics[i].name, ETH_GSTRING_LEN);
  3016. }
  3017. }
  3018. static void mvneta_ethtool_update_stats(struct mvneta_port *pp)
  3019. {
  3020. const struct mvneta_statistic *s;
  3021. void __iomem *base = pp->base;
  3022. u32 high, low, val;
  3023. u64 val64;
  3024. int i;
  3025. for (i = 0, s = mvneta_statistics;
  3026. s < mvneta_statistics + ARRAY_SIZE(mvneta_statistics);
  3027. s++, i++) {
  3028. switch (s->type) {
  3029. case T_REG_32:
  3030. val = readl_relaxed(base + s->offset);
  3031. pp->ethtool_stats[i] += val;
  3032. break;
  3033. case T_REG_64:
  3034. /* Docs say to read low 32-bit then high */
  3035. low = readl_relaxed(base + s->offset);
  3036. high = readl_relaxed(base + s->offset + 4);
  3037. val64 = (u64)high << 32 | low;
  3038. pp->ethtool_stats[i] += val64;
  3039. break;
  3040. }
  3041. }
  3042. }
  3043. static void mvneta_ethtool_get_stats(struct net_device *dev,
  3044. struct ethtool_stats *stats, u64 *data)
  3045. {
  3046. struct mvneta_port *pp = netdev_priv(dev);
  3047. int i;
  3048. mvneta_ethtool_update_stats(pp);
  3049. for (i = 0; i < ARRAY_SIZE(mvneta_statistics); i++)
  3050. *data++ = pp->ethtool_stats[i];
  3051. }
  3052. static int mvneta_ethtool_get_sset_count(struct net_device *dev, int sset)
  3053. {
  3054. if (sset == ETH_SS_STATS)
  3055. return ARRAY_SIZE(mvneta_statistics);
  3056. return -EOPNOTSUPP;
  3057. }
  3058. static u32 mvneta_ethtool_get_rxfh_indir_size(struct net_device *dev)
  3059. {
  3060. return MVNETA_RSS_LU_TABLE_SIZE;
  3061. }
  3062. static int mvneta_ethtool_get_rxnfc(struct net_device *dev,
  3063. struct ethtool_rxnfc *info,
  3064. u32 *rules __always_unused)
  3065. {
  3066. switch (info->cmd) {
  3067. case ETHTOOL_GRXRINGS:
  3068. info->data = rxq_number;
  3069. return 0;
  3070. case ETHTOOL_GRXFH:
  3071. return -EOPNOTSUPP;
  3072. default:
  3073. return -EOPNOTSUPP;
  3074. }
  3075. }
  3076. static int mvneta_config_rss(struct mvneta_port *pp)
  3077. {
  3078. int cpu;
  3079. u32 val;
  3080. netif_tx_stop_all_queues(pp->dev);
  3081. on_each_cpu(mvneta_percpu_mask_interrupt, pp, true);
  3082. /* We have to synchronise on the napi of each CPU */
  3083. for_each_online_cpu(cpu) {
  3084. struct mvneta_pcpu_port *pcpu_port =
  3085. per_cpu_ptr(pp->ports, cpu);
  3086. napi_synchronize(&pcpu_port->napi);
  3087. napi_disable(&pcpu_port->napi);
  3088. }
  3089. pp->rxq_def = pp->indir[0];
  3090. /* Update unicast mapping */
  3091. mvneta_set_rx_mode(pp->dev);
  3092. /* Update val of portCfg register accordingly with all RxQueue types */
  3093. val = MVNETA_PORT_CONFIG_DEFL_VALUE(pp->rxq_def);
  3094. mvreg_write(pp, MVNETA_PORT_CONFIG, val);
  3095. /* Update the elected CPU matching the new rxq_def */
  3096. spin_lock(&pp->lock);
  3097. mvneta_percpu_elect(pp);
  3098. spin_unlock(&pp->lock);
  3099. /* We have to synchronise on the napi of each CPU */
  3100. for_each_online_cpu(cpu) {
  3101. struct mvneta_pcpu_port *pcpu_port =
  3102. per_cpu_ptr(pp->ports, cpu);
  3103. napi_enable(&pcpu_port->napi);
  3104. }
  3105. netif_tx_start_all_queues(pp->dev);
  3106. return 0;
  3107. }
  3108. static int mvneta_ethtool_set_rxfh(struct net_device *dev, const u32 *indir,
  3109. const u8 *key, const u8 hfunc)
  3110. {
  3111. struct mvneta_port *pp = netdev_priv(dev);
  3112. /* We require at least one supported parameter to be changed
  3113. * and no change in any of the unsupported parameters
  3114. */
  3115. if (key ||
  3116. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  3117. return -EOPNOTSUPP;
  3118. if (!indir)
  3119. return 0;
  3120. memcpy(pp->indir, indir, MVNETA_RSS_LU_TABLE_SIZE);
  3121. return mvneta_config_rss(pp);
  3122. }
  3123. static int mvneta_ethtool_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
  3124. u8 *hfunc)
  3125. {
  3126. struct mvneta_port *pp = netdev_priv(dev);
  3127. if (hfunc)
  3128. *hfunc = ETH_RSS_HASH_TOP;
  3129. if (!indir)
  3130. return 0;
  3131. memcpy(indir, pp->indir, MVNETA_RSS_LU_TABLE_SIZE);
  3132. return 0;
  3133. }
  3134. static const struct net_device_ops mvneta_netdev_ops = {
  3135. .ndo_open = mvneta_open,
  3136. .ndo_stop = mvneta_stop,
  3137. .ndo_start_xmit = mvneta_tx,
  3138. .ndo_set_rx_mode = mvneta_set_rx_mode,
  3139. .ndo_set_mac_address = mvneta_set_mac_addr,
  3140. .ndo_change_mtu = mvneta_change_mtu,
  3141. .ndo_fix_features = mvneta_fix_features,
  3142. .ndo_get_stats64 = mvneta_get_stats64,
  3143. .ndo_do_ioctl = mvneta_ioctl,
  3144. };
  3145. const struct ethtool_ops mvneta_eth_tool_ops = {
  3146. .get_link = ethtool_op_get_link,
  3147. .set_coalesce = mvneta_ethtool_set_coalesce,
  3148. .get_coalesce = mvneta_ethtool_get_coalesce,
  3149. .get_drvinfo = mvneta_ethtool_get_drvinfo,
  3150. .get_ringparam = mvneta_ethtool_get_ringparam,
  3151. .set_ringparam = mvneta_ethtool_set_ringparam,
  3152. .get_strings = mvneta_ethtool_get_strings,
  3153. .get_ethtool_stats = mvneta_ethtool_get_stats,
  3154. .get_sset_count = mvneta_ethtool_get_sset_count,
  3155. .get_rxfh_indir_size = mvneta_ethtool_get_rxfh_indir_size,
  3156. .get_rxnfc = mvneta_ethtool_get_rxnfc,
  3157. .get_rxfh = mvneta_ethtool_get_rxfh,
  3158. .set_rxfh = mvneta_ethtool_set_rxfh,
  3159. .get_link_ksettings = phy_ethtool_get_link_ksettings,
  3160. .set_link_ksettings = mvneta_ethtool_set_link_ksettings,
  3161. };
  3162. /* Initialize hw */
  3163. static int mvneta_init(struct device *dev, struct mvneta_port *pp)
  3164. {
  3165. int queue;
  3166. /* Disable port */
  3167. mvneta_port_disable(pp);
  3168. /* Set port default values */
  3169. mvneta_defaults_set(pp);
  3170. pp->txqs = devm_kcalloc(dev, txq_number, sizeof(struct mvneta_tx_queue),
  3171. GFP_KERNEL);
  3172. if (!pp->txqs)
  3173. return -ENOMEM;
  3174. /* Initialize TX descriptor rings */
  3175. for (queue = 0; queue < txq_number; queue++) {
  3176. struct mvneta_tx_queue *txq = &pp->txqs[queue];
  3177. txq->id = queue;
  3178. txq->size = pp->tx_ring_size;
  3179. txq->done_pkts_coal = MVNETA_TXDONE_COAL_PKTS;
  3180. }
  3181. pp->rxqs = devm_kcalloc(dev, rxq_number, sizeof(struct mvneta_rx_queue),
  3182. GFP_KERNEL);
  3183. if (!pp->rxqs)
  3184. return -ENOMEM;
  3185. /* Create Rx descriptor rings */
  3186. for (queue = 0; queue < rxq_number; queue++) {
  3187. struct mvneta_rx_queue *rxq = &pp->rxqs[queue];
  3188. rxq->id = queue;
  3189. rxq->size = pp->rx_ring_size;
  3190. rxq->pkts_coal = MVNETA_RX_COAL_PKTS;
  3191. rxq->time_coal = MVNETA_RX_COAL_USEC;
  3192. }
  3193. return 0;
  3194. }
  3195. /* platform glue : initialize decoding windows */
  3196. static void mvneta_conf_mbus_windows(struct mvneta_port *pp,
  3197. const struct mbus_dram_target_info *dram)
  3198. {
  3199. u32 win_enable;
  3200. u32 win_protect;
  3201. int i;
  3202. for (i = 0; i < 6; i++) {
  3203. mvreg_write(pp, MVNETA_WIN_BASE(i), 0);
  3204. mvreg_write(pp, MVNETA_WIN_SIZE(i), 0);
  3205. if (i < 4)
  3206. mvreg_write(pp, MVNETA_WIN_REMAP(i), 0);
  3207. }
  3208. win_enable = 0x3f;
  3209. win_protect = 0;
  3210. for (i = 0; i < dram->num_cs; i++) {
  3211. const struct mbus_dram_window *cs = dram->cs + i;
  3212. mvreg_write(pp, MVNETA_WIN_BASE(i), (cs->base & 0xffff0000) |
  3213. (cs->mbus_attr << 8) | dram->mbus_dram_target_id);
  3214. mvreg_write(pp, MVNETA_WIN_SIZE(i),
  3215. (cs->size - 1) & 0xffff0000);
  3216. win_enable &= ~(1 << i);
  3217. win_protect |= 3 << (2 * i);
  3218. }
  3219. mvreg_write(pp, MVNETA_BASE_ADDR_ENABLE, win_enable);
  3220. mvreg_write(pp, MVNETA_ACCESS_PROTECT_ENABLE, win_protect);
  3221. }
  3222. /* Power up the port */
  3223. static int mvneta_port_power_up(struct mvneta_port *pp, int phy_mode)
  3224. {
  3225. u32 ctrl;
  3226. /* MAC Cause register should be cleared */
  3227. mvreg_write(pp, MVNETA_UNIT_INTR_CAUSE, 0);
  3228. ctrl = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
  3229. /* Even though it might look weird, when we're configured in
  3230. * SGMII or QSGMII mode, the RGMII bit needs to be set.
  3231. */
  3232. switch(phy_mode) {
  3233. case PHY_INTERFACE_MODE_QSGMII:
  3234. mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_QSGMII_SERDES_PROTO);
  3235. ctrl |= MVNETA_GMAC2_PCS_ENABLE | MVNETA_GMAC2_PORT_RGMII;
  3236. break;
  3237. case PHY_INTERFACE_MODE_SGMII:
  3238. mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_SGMII_SERDES_PROTO);
  3239. ctrl |= MVNETA_GMAC2_PCS_ENABLE | MVNETA_GMAC2_PORT_RGMII;
  3240. break;
  3241. case PHY_INTERFACE_MODE_RGMII:
  3242. case PHY_INTERFACE_MODE_RGMII_ID:
  3243. ctrl |= MVNETA_GMAC2_PORT_RGMII;
  3244. break;
  3245. default:
  3246. return -EINVAL;
  3247. }
  3248. /* Cancel Port Reset */
  3249. ctrl &= ~MVNETA_GMAC2_PORT_RESET;
  3250. mvreg_write(pp, MVNETA_GMAC_CTRL_2, ctrl);
  3251. while ((mvreg_read(pp, MVNETA_GMAC_CTRL_2) &
  3252. MVNETA_GMAC2_PORT_RESET) != 0)
  3253. continue;
  3254. return 0;
  3255. }
  3256. /* Device initialization routine */
  3257. static int mvneta_probe(struct platform_device *pdev)
  3258. {
  3259. const struct mbus_dram_target_info *dram_target_info;
  3260. struct resource *res;
  3261. struct device_node *dn = pdev->dev.of_node;
  3262. struct device_node *phy_node;
  3263. struct device_node *bm_node;
  3264. struct mvneta_port *pp;
  3265. struct net_device *dev;
  3266. const char *dt_mac_addr;
  3267. char hw_mac_addr[ETH_ALEN];
  3268. const char *mac_from;
  3269. const char *managed;
  3270. int tx_csum_limit;
  3271. int phy_mode;
  3272. int err;
  3273. int cpu;
  3274. dev = alloc_etherdev_mqs(sizeof(struct mvneta_port), txq_number, rxq_number);
  3275. if (!dev)
  3276. return -ENOMEM;
  3277. dev->irq = irq_of_parse_and_map(dn, 0);
  3278. if (dev->irq == 0) {
  3279. err = -EINVAL;
  3280. goto err_free_netdev;
  3281. }
  3282. phy_node = of_parse_phandle(dn, "phy", 0);
  3283. if (!phy_node) {
  3284. if (!of_phy_is_fixed_link(dn)) {
  3285. dev_err(&pdev->dev, "no PHY specified\n");
  3286. err = -ENODEV;
  3287. goto err_free_irq;
  3288. }
  3289. err = of_phy_register_fixed_link(dn);
  3290. if (err < 0) {
  3291. dev_err(&pdev->dev, "cannot register fixed PHY\n");
  3292. goto err_free_irq;
  3293. }
  3294. /* In the case of a fixed PHY, the DT node associated
  3295. * to the PHY is the Ethernet MAC DT node.
  3296. */
  3297. phy_node = of_node_get(dn);
  3298. }
  3299. phy_mode = of_get_phy_mode(dn);
  3300. if (phy_mode < 0) {
  3301. dev_err(&pdev->dev, "incorrect phy-mode\n");
  3302. err = -EINVAL;
  3303. goto err_put_phy_node;
  3304. }
  3305. dev->tx_queue_len = MVNETA_MAX_TXD;
  3306. dev->watchdog_timeo = 5 * HZ;
  3307. dev->netdev_ops = &mvneta_netdev_ops;
  3308. dev->ethtool_ops = &mvneta_eth_tool_ops;
  3309. pp = netdev_priv(dev);
  3310. spin_lock_init(&pp->lock);
  3311. pp->phy_node = phy_node;
  3312. pp->phy_interface = phy_mode;
  3313. err = of_property_read_string(dn, "managed", &managed);
  3314. pp->use_inband_status = (err == 0 &&
  3315. strcmp(managed, "in-band-status") == 0);
  3316. pp->rxq_def = rxq_def;
  3317. pp->indir[0] = rxq_def;
  3318. pp->clk = devm_clk_get(&pdev->dev, "core");
  3319. if (IS_ERR(pp->clk))
  3320. pp->clk = devm_clk_get(&pdev->dev, NULL);
  3321. if (IS_ERR(pp->clk)) {
  3322. err = PTR_ERR(pp->clk);
  3323. goto err_put_phy_node;
  3324. }
  3325. clk_prepare_enable(pp->clk);
  3326. pp->clk_bus = devm_clk_get(&pdev->dev, "bus");
  3327. if (!IS_ERR(pp->clk_bus))
  3328. clk_prepare_enable(pp->clk_bus);
  3329. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  3330. pp->base = devm_ioremap_resource(&pdev->dev, res);
  3331. if (IS_ERR(pp->base)) {
  3332. err = PTR_ERR(pp->base);
  3333. goto err_clk;
  3334. }
  3335. /* Alloc per-cpu port structure */
  3336. pp->ports = alloc_percpu(struct mvneta_pcpu_port);
  3337. if (!pp->ports) {
  3338. err = -ENOMEM;
  3339. goto err_clk;
  3340. }
  3341. /* Alloc per-cpu stats */
  3342. pp->stats = netdev_alloc_pcpu_stats(struct mvneta_pcpu_stats);
  3343. if (!pp->stats) {
  3344. err = -ENOMEM;
  3345. goto err_free_ports;
  3346. }
  3347. dt_mac_addr = of_get_mac_address(dn);
  3348. if (dt_mac_addr) {
  3349. mac_from = "device tree";
  3350. memcpy(dev->dev_addr, dt_mac_addr, ETH_ALEN);
  3351. } else {
  3352. mvneta_get_mac_addr(pp, hw_mac_addr);
  3353. if (is_valid_ether_addr(hw_mac_addr)) {
  3354. mac_from = "hardware";
  3355. memcpy(dev->dev_addr, hw_mac_addr, ETH_ALEN);
  3356. } else {
  3357. mac_from = "random";
  3358. eth_hw_addr_random(dev);
  3359. }
  3360. }
  3361. if (!of_property_read_u32(dn, "tx-csum-limit", &tx_csum_limit)) {
  3362. if (tx_csum_limit < 0 ||
  3363. tx_csum_limit > MVNETA_TX_CSUM_MAX_SIZE) {
  3364. tx_csum_limit = MVNETA_TX_CSUM_DEF_SIZE;
  3365. dev_info(&pdev->dev,
  3366. "Wrong TX csum limit in DT, set to %dB\n",
  3367. MVNETA_TX_CSUM_DEF_SIZE);
  3368. }
  3369. } else if (of_device_is_compatible(dn, "marvell,armada-370-neta")) {
  3370. tx_csum_limit = MVNETA_TX_CSUM_DEF_SIZE;
  3371. } else {
  3372. tx_csum_limit = MVNETA_TX_CSUM_MAX_SIZE;
  3373. }
  3374. pp->tx_csum_limit = tx_csum_limit;
  3375. dram_target_info = mv_mbus_dram_info();
  3376. if (dram_target_info)
  3377. mvneta_conf_mbus_windows(pp, dram_target_info);
  3378. pp->tx_ring_size = MVNETA_MAX_TXD;
  3379. pp->rx_ring_size = MVNETA_MAX_RXD;
  3380. pp->dev = dev;
  3381. SET_NETDEV_DEV(dev, &pdev->dev);
  3382. pp->id = global_port_id++;
  3383. /* Obtain access to BM resources if enabled and already initialized */
  3384. bm_node = of_parse_phandle(dn, "buffer-manager", 0);
  3385. if (bm_node && bm_node->data) {
  3386. pp->bm_priv = bm_node->data;
  3387. err = mvneta_bm_port_init(pdev, pp);
  3388. if (err < 0) {
  3389. dev_info(&pdev->dev, "use SW buffer management\n");
  3390. pp->bm_priv = NULL;
  3391. }
  3392. }
  3393. of_node_put(bm_node);
  3394. err = mvneta_init(&pdev->dev, pp);
  3395. if (err < 0)
  3396. goto err_netdev;
  3397. err = mvneta_port_power_up(pp, phy_mode);
  3398. if (err < 0) {
  3399. dev_err(&pdev->dev, "can't power up port\n");
  3400. goto err_netdev;
  3401. }
  3402. for_each_present_cpu(cpu) {
  3403. struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu);
  3404. netif_napi_add(dev, &port->napi, mvneta_poll, NAPI_POLL_WEIGHT);
  3405. port->pp = pp;
  3406. }
  3407. dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO;
  3408. dev->hw_features |= dev->features;
  3409. dev->vlan_features |= dev->features;
  3410. dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
  3411. dev->gso_max_segs = MVNETA_MAX_TSO_SEGS;
  3412. err = register_netdev(dev);
  3413. if (err < 0) {
  3414. dev_err(&pdev->dev, "failed to register\n");
  3415. goto err_free_stats;
  3416. }
  3417. netdev_info(dev, "Using %s mac address %pM\n", mac_from,
  3418. dev->dev_addr);
  3419. platform_set_drvdata(pdev, pp->dev);
  3420. if (pp->use_inband_status) {
  3421. struct phy_device *phy = of_phy_find_device(dn);
  3422. mvneta_fixed_link_update(pp, phy);
  3423. put_device(&phy->mdio.dev);
  3424. }
  3425. return 0;
  3426. err_netdev:
  3427. unregister_netdev(dev);
  3428. if (pp->bm_priv) {
  3429. mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id);
  3430. mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short,
  3431. 1 << pp->id);
  3432. }
  3433. err_free_stats:
  3434. free_percpu(pp->stats);
  3435. err_free_ports:
  3436. free_percpu(pp->ports);
  3437. err_clk:
  3438. clk_disable_unprepare(pp->clk_bus);
  3439. clk_disable_unprepare(pp->clk);
  3440. err_put_phy_node:
  3441. of_node_put(phy_node);
  3442. if (of_phy_is_fixed_link(dn))
  3443. of_phy_deregister_fixed_link(dn);
  3444. err_free_irq:
  3445. irq_dispose_mapping(dev->irq);
  3446. err_free_netdev:
  3447. free_netdev(dev);
  3448. return err;
  3449. }
  3450. /* Device removal routine */
  3451. static int mvneta_remove(struct platform_device *pdev)
  3452. {
  3453. struct net_device *dev = platform_get_drvdata(pdev);
  3454. struct device_node *dn = pdev->dev.of_node;
  3455. struct mvneta_port *pp = netdev_priv(dev);
  3456. unregister_netdev(dev);
  3457. clk_disable_unprepare(pp->clk_bus);
  3458. clk_disable_unprepare(pp->clk);
  3459. free_percpu(pp->ports);
  3460. free_percpu(pp->stats);
  3461. if (of_phy_is_fixed_link(dn))
  3462. of_phy_deregister_fixed_link(dn);
  3463. irq_dispose_mapping(dev->irq);
  3464. of_node_put(pp->phy_node);
  3465. free_netdev(dev);
  3466. if (pp->bm_priv) {
  3467. mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id);
  3468. mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short,
  3469. 1 << pp->id);
  3470. }
  3471. return 0;
  3472. }
  3473. static const struct of_device_id mvneta_match[] = {
  3474. { .compatible = "marvell,armada-370-neta" },
  3475. { .compatible = "marvell,armada-xp-neta" },
  3476. { }
  3477. };
  3478. MODULE_DEVICE_TABLE(of, mvneta_match);
  3479. static struct platform_driver mvneta_driver = {
  3480. .probe = mvneta_probe,
  3481. .remove = mvneta_remove,
  3482. .driver = {
  3483. .name = MVNETA_DRIVER_NAME,
  3484. .of_match_table = mvneta_match,
  3485. },
  3486. };
  3487. static int __init mvneta_driver_init(void)
  3488. {
  3489. int ret;
  3490. ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "net/mvmeta:online",
  3491. mvneta_cpu_online,
  3492. mvneta_cpu_down_prepare);
  3493. if (ret < 0)
  3494. goto out;
  3495. online_hpstate = ret;
  3496. ret = cpuhp_setup_state_multi(CPUHP_NET_MVNETA_DEAD, "net/mvneta:dead",
  3497. NULL, mvneta_cpu_dead);
  3498. if (ret)
  3499. goto err_dead;
  3500. ret = platform_driver_register(&mvneta_driver);
  3501. if (ret)
  3502. goto err;
  3503. return 0;
  3504. err:
  3505. cpuhp_remove_multi_state(CPUHP_NET_MVNETA_DEAD);
  3506. err_dead:
  3507. cpuhp_remove_multi_state(online_hpstate);
  3508. out:
  3509. return ret;
  3510. }
  3511. module_init(mvneta_driver_init);
  3512. static void __exit mvneta_driver_exit(void)
  3513. {
  3514. platform_driver_unregister(&mvneta_driver);
  3515. cpuhp_remove_multi_state(CPUHP_NET_MVNETA_DEAD);
  3516. cpuhp_remove_multi_state(online_hpstate);
  3517. }
  3518. module_exit(mvneta_driver_exit);
  3519. MODULE_DESCRIPTION("Marvell NETA Ethernet Driver - www.marvell.com");
  3520. MODULE_AUTHOR("Rami Rosen <rosenr@marvell.com>, Thomas Petazzoni <thomas.petazzoni@free-electrons.com>");
  3521. MODULE_LICENSE("GPL");
  3522. module_param(rxq_number, int, S_IRUGO);
  3523. module_param(txq_number, int, S_IRUGO);
  3524. module_param(rxq_def, int, S_IRUGO);
  3525. module_param(rx_copybreak, int, S_IRUGO | S_IWUSR);