mvneta.c 116 KB

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