710-net-add-qualcomm-essedma-ethernet-driver.patch 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578
  1. From 12e9319da1adacac92930c899c99f0e1970cac11 Mon Sep 17 00:00:00 2001
  2. From: Christian Lamparter <[email protected]>
  3. Date: Thu, 19 Jan 2017 02:01:31 +0100
  4. Subject: [PATCH 33/38] NET: add qualcomm essedma ethernet driver
  5. Signed-off-by: Christian Lamparter <[email protected]>
  6. ---
  7. drivers/net/ethernet/qualcomm/Kconfig | 9 +++++++++
  8. drivers/net/ethernet/qualcomm/Makefile | 1 +
  9. 2 files changed, 10 insertions(+)
  10. --- a/drivers/net/ethernet/qualcomm/Kconfig
  11. +++ b/drivers/net/ethernet/qualcomm/Kconfig
  12. @@ -61,4 +61,13 @@ config QCOM_EMAC
  13. source "drivers/net/ethernet/qualcomm/rmnet/Kconfig"
  14. +config ESSEDMA
  15. + tristate "Qualcomm Atheros ESS Edma support"
  16. + ---help---
  17. + This driver supports ethernet edma adapter.
  18. + Say Y to build this driver.
  19. +
  20. + To compile this driver as a module, choose M here. The module
  21. + will be called essedma.ko.
  22. +
  23. endif # NET_VENDOR_QUALCOMM
  24. --- a/drivers/net/ethernet/qualcomm/Makefile
  25. +++ b/drivers/net/ethernet/qualcomm/Makefile
  26. @@ -10,5 +10,6 @@ obj-$(CONFIG_QCA7000_UART) += qcauart.o
  27. qcauart-objs := qca_uart.o
  28. obj-y += emac/
  29. +obj-$(CONFIG_ESSEDMA) += essedma/
  30. obj-$(CONFIG_RMNET) += rmnet/
  31. --- /dev/null
  32. +++ b/drivers/net/ethernet/qualcomm/essedma/Makefile
  33. @@ -0,0 +1,9 @@
  34. +#
  35. +## Makefile for the Qualcomm Atheros ethernet edma driver
  36. +#
  37. +
  38. +
  39. +obj-$(CONFIG_ESSEDMA) += essedma.o
  40. +
  41. +essedma-objs := edma_axi.o edma.o edma_ethtool.o
  42. +
  43. --- /dev/null
  44. +++ b/drivers/net/ethernet/qualcomm/essedma/edma.c
  45. @@ -0,0 +1,2143 @@
  46. +/*
  47. + * Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
  48. + *
  49. + * Permission to use, copy, modify, and/or distribute this software for
  50. + * any purpose with or without fee is hereby granted, provided that the
  51. + * above copyright notice and this permission notice appear in all copies.
  52. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  53. + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  54. + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  55. + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  56. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  57. + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  58. + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  59. + */
  60. +
  61. +#include <linux/platform_device.h>
  62. +#include <linux/if_vlan.h>
  63. +#include "ess_edma.h"
  64. +#include "edma.h"
  65. +
  66. +extern struct net_device *edma_netdev[EDMA_MAX_PORTID_SUPPORTED];
  67. +bool edma_stp_rstp;
  68. +u16 edma_ath_eth_type;
  69. +
  70. +/* edma_skb_priority_offset()
  71. + * get edma skb priority
  72. + */
  73. +static unsigned int edma_skb_priority_offset(struct sk_buff *skb)
  74. +{
  75. + return (skb->priority >> 2) & 1;
  76. +}
  77. +
  78. +/* edma_alloc_tx_ring()
  79. + * Allocate Tx descriptors ring
  80. + */
  81. +static int edma_alloc_tx_ring(struct edma_common_info *edma_cinfo,
  82. + struct edma_tx_desc_ring *etdr)
  83. +{
  84. + struct platform_device *pdev = edma_cinfo->pdev;
  85. +
  86. + /* Initialize ring */
  87. + etdr->size = sizeof(struct edma_sw_desc) * etdr->count;
  88. + etdr->sw_next_to_fill = 0;
  89. + etdr->sw_next_to_clean = 0;
  90. +
  91. + /* Allocate SW descriptors */
  92. + etdr->sw_desc = vzalloc(etdr->size);
  93. + if (!etdr->sw_desc) {
  94. + dev_err(&pdev->dev, "buffer alloc of tx ring failed=%p", etdr);
  95. + return -ENOMEM;
  96. + }
  97. +
  98. + /* Allocate HW descriptors */
  99. + etdr->hw_desc = dma_alloc_coherent(&pdev->dev, etdr->size, &etdr->dma,
  100. + GFP_KERNEL);
  101. + if (!etdr->hw_desc) {
  102. + dev_err(&pdev->dev, "descriptor allocation for tx ring failed");
  103. + vfree(etdr->sw_desc);
  104. + return -ENOMEM;
  105. + }
  106. +
  107. + return 0;
  108. +}
  109. +
  110. +/* edma_free_tx_ring()
  111. + * Free tx rings allocated by edma_alloc_tx_rings
  112. + */
  113. +static void edma_free_tx_ring(struct edma_common_info *edma_cinfo,
  114. + struct edma_tx_desc_ring *etdr)
  115. +{
  116. + struct platform_device *pdev = edma_cinfo->pdev;
  117. +
  118. + if (likely(etdr->dma))
  119. + dma_free_coherent(&pdev->dev, etdr->size, etdr->hw_desc,
  120. + etdr->dma);
  121. +
  122. + vfree(etdr->sw_desc);
  123. + etdr->sw_desc = NULL;
  124. +}
  125. +
  126. +/* edma_alloc_rx_ring()
  127. + * allocate rx descriptor ring
  128. + */
  129. +static int edma_alloc_rx_ring(struct edma_common_info *edma_cinfo,
  130. + struct edma_rfd_desc_ring *erxd)
  131. +{
  132. + struct platform_device *pdev = edma_cinfo->pdev;
  133. +
  134. + erxd->size = sizeof(struct edma_sw_desc) * erxd->count;
  135. + erxd->sw_next_to_fill = 0;
  136. + erxd->sw_next_to_clean = 0;
  137. +
  138. + /* Allocate SW descriptors */
  139. + erxd->sw_desc = vzalloc(erxd->size);
  140. + if (!erxd->sw_desc)
  141. + return -ENOMEM;
  142. +
  143. + /* Alloc HW descriptors */
  144. + erxd->hw_desc = dma_alloc_coherent(&pdev->dev, erxd->size, &erxd->dma,
  145. + GFP_KERNEL);
  146. + if (!erxd->hw_desc) {
  147. + vfree(erxd->sw_desc);
  148. + return -ENOMEM;
  149. + }
  150. +
  151. + return 0;
  152. +}
  153. +
  154. +/* edma_free_rx_ring()
  155. + * Free rx ring allocated by alloc_rx_ring
  156. + */
  157. +static void edma_free_rx_ring(struct edma_common_info *edma_cinfo,
  158. + struct edma_rfd_desc_ring *rxdr)
  159. +{
  160. + struct platform_device *pdev = edma_cinfo->pdev;
  161. +
  162. + if (likely(rxdr->dma))
  163. + dma_free_coherent(&pdev->dev, rxdr->size, rxdr->hw_desc,
  164. + rxdr->dma);
  165. +
  166. + vfree(rxdr->sw_desc);
  167. + rxdr->sw_desc = NULL;
  168. +}
  169. +
  170. +/* edma_configure_tx()
  171. + * Configure transmission control data
  172. + */
  173. +static void edma_configure_tx(struct edma_common_info *edma_cinfo)
  174. +{
  175. + u32 txq_ctrl_data;
  176. +
  177. + txq_ctrl_data = (EDMA_TPD_BURST << EDMA_TXQ_NUM_TPD_BURST_SHIFT);
  178. + txq_ctrl_data |= EDMA_TXQ_CTRL_TPD_BURST_EN;
  179. + txq_ctrl_data |= (EDMA_TXF_BURST << EDMA_TXQ_TXF_BURST_NUM_SHIFT);
  180. + edma_write_reg(EDMA_REG_TXQ_CTRL, txq_ctrl_data);
  181. +}
  182. +
  183. +
  184. +/* edma_configure_rx()
  185. + * configure reception control data
  186. + */
  187. +static void edma_configure_rx(struct edma_common_info *edma_cinfo)
  188. +{
  189. + struct edma_hw *hw = &edma_cinfo->hw;
  190. + u32 rss_type, rx_desc1, rxq_ctrl_data;
  191. +
  192. + /* Set RSS type */
  193. + rss_type = hw->rss_type;
  194. + edma_write_reg(EDMA_REG_RSS_TYPE, rss_type);
  195. +
  196. + /* Set RFD burst number */
  197. + rx_desc1 = (EDMA_RFD_BURST << EDMA_RXQ_RFD_BURST_NUM_SHIFT);
  198. +
  199. + /* Set RFD prefetch threshold */
  200. + rx_desc1 |= (EDMA_RFD_THR << EDMA_RXQ_RFD_PF_THRESH_SHIFT);
  201. +
  202. + /* Set RFD in host ring low threshold to generte interrupt */
  203. + rx_desc1 |= (EDMA_RFD_LTHR << EDMA_RXQ_RFD_LOW_THRESH_SHIFT);
  204. + edma_write_reg(EDMA_REG_RX_DESC1, rx_desc1);
  205. +
  206. + /* Set Rx FIFO threshold to start to DMA data to host */
  207. + rxq_ctrl_data = EDMA_FIFO_THRESH_128_BYTE;
  208. +
  209. + /* Set RX remove vlan bit */
  210. + rxq_ctrl_data |= EDMA_RXQ_CTRL_RMV_VLAN;
  211. +
  212. + edma_write_reg(EDMA_REG_RXQ_CTRL, rxq_ctrl_data);
  213. +}
  214. +
  215. +/* edma_alloc_rx_buf()
  216. + * does skb allocation for the received packets.
  217. + */
  218. +static int edma_alloc_rx_buf(struct edma_common_info
  219. + *edma_cinfo,
  220. + struct edma_rfd_desc_ring *erdr,
  221. + int cleaned_count, int queue_id)
  222. +{
  223. + struct platform_device *pdev = edma_cinfo->pdev;
  224. + struct edma_rx_free_desc *rx_desc;
  225. + struct edma_sw_desc *sw_desc;
  226. + struct sk_buff *skb;
  227. + unsigned int i;
  228. + u16 prod_idx, length;
  229. + u32 reg_data;
  230. +
  231. + if (cleaned_count > erdr->count) {
  232. + dev_err(&pdev->dev, "Incorrect cleaned_count %d",
  233. + cleaned_count);
  234. + return -1;
  235. + }
  236. +
  237. + i = erdr->sw_next_to_fill;
  238. +
  239. + while (cleaned_count) {
  240. + sw_desc = &erdr->sw_desc[i];
  241. + length = edma_cinfo->rx_head_buffer_len;
  242. +
  243. + if (sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_REUSE) {
  244. + skb = sw_desc->skb;
  245. + } else {
  246. + /* alloc skb */
  247. + skb = netdev_alloc_skb(edma_netdev[0], length);
  248. + if (!skb) {
  249. + /* Better luck next round */
  250. + break;
  251. + }
  252. + }
  253. +
  254. + if (edma_cinfo->page_mode) {
  255. + struct page *pg = alloc_page(GFP_ATOMIC);
  256. +
  257. + if (!pg) {
  258. + dev_kfree_skb_any(skb);
  259. + break;
  260. + }
  261. +
  262. + sw_desc->dma = dma_map_page(&pdev->dev, pg, 0,
  263. + edma_cinfo->rx_page_buffer_len,
  264. + DMA_FROM_DEVICE);
  265. + if (dma_mapping_error(&pdev->dev,
  266. + sw_desc->dma)) {
  267. + __free_page(pg);
  268. + dev_kfree_skb_any(skb);
  269. + break;
  270. + }
  271. +
  272. + skb_fill_page_desc(skb, 0, pg, 0,
  273. + edma_cinfo->rx_page_buffer_len);
  274. + sw_desc->flags = EDMA_SW_DESC_FLAG_SKB_FRAG;
  275. + sw_desc->length = edma_cinfo->rx_page_buffer_len;
  276. + } else {
  277. + sw_desc->dma = dma_map_single(&pdev->dev, skb->data,
  278. + length, DMA_FROM_DEVICE);
  279. + if (dma_mapping_error(&pdev->dev,
  280. + sw_desc->dma)) {
  281. + dev_kfree_skb_any(skb);
  282. + break;
  283. + }
  284. +
  285. + sw_desc->flags = EDMA_SW_DESC_FLAG_SKB_HEAD;
  286. + sw_desc->length = length;
  287. + }
  288. +
  289. + /* Update the buffer info */
  290. + sw_desc->skb = skb;
  291. + rx_desc = (&((struct edma_rx_free_desc *)(erdr->hw_desc))[i]);
  292. + rx_desc->buffer_addr = cpu_to_le64(sw_desc->dma);
  293. + if (++i == erdr->count)
  294. + i = 0;
  295. + cleaned_count--;
  296. + }
  297. +
  298. + erdr->sw_next_to_fill = i;
  299. +
  300. + if (i == 0)
  301. + prod_idx = erdr->count - 1;
  302. + else
  303. + prod_idx = i - 1;
  304. +
  305. + /* Update the producer index */
  306. + edma_read_reg(EDMA_REG_RFD_IDX_Q(queue_id), &reg_data);
  307. + reg_data &= ~EDMA_RFD_PROD_IDX_BITS;
  308. + reg_data |= prod_idx;
  309. + edma_write_reg(EDMA_REG_RFD_IDX_Q(queue_id), reg_data);
  310. + return cleaned_count;
  311. +}
  312. +
  313. +/* edma_init_desc()
  314. + * update descriptor ring size, buffer and producer/consumer index
  315. + */
  316. +static void edma_init_desc(struct edma_common_info *edma_cinfo)
  317. +{
  318. + struct edma_rfd_desc_ring *rfd_ring;
  319. + struct edma_tx_desc_ring *etdr;
  320. + int i = 0, j = 0;
  321. + u32 data = 0;
  322. + u16 hw_cons_idx = 0;
  323. +
  324. + /* Set the base address of every TPD ring. */
  325. + for (i = 0; i < edma_cinfo->num_tx_queues; i++) {
  326. + etdr = edma_cinfo->tpd_ring[i];
  327. +
  328. + /* Update descriptor ring base address */
  329. + edma_write_reg(EDMA_REG_TPD_BASE_ADDR_Q(i), (u32)etdr->dma);
  330. + edma_read_reg(EDMA_REG_TPD_IDX_Q(i), &data);
  331. +
  332. + /* Calculate hardware consumer index */
  333. + hw_cons_idx = (data >> EDMA_TPD_CONS_IDX_SHIFT) & 0xffff;
  334. + etdr->sw_next_to_fill = hw_cons_idx;
  335. + etdr->sw_next_to_clean = hw_cons_idx;
  336. + data &= ~(EDMA_TPD_PROD_IDX_MASK << EDMA_TPD_PROD_IDX_SHIFT);
  337. + data |= hw_cons_idx;
  338. +
  339. + /* update producer index */
  340. + edma_write_reg(EDMA_REG_TPD_IDX_Q(i), data);
  341. +
  342. + /* update SW consumer index register */
  343. + edma_write_reg(EDMA_REG_TX_SW_CONS_IDX_Q(i), hw_cons_idx);
  344. +
  345. + /* Set TPD ring size */
  346. + edma_write_reg(EDMA_REG_TPD_RING_SIZE,
  347. + edma_cinfo->tx_ring_count &
  348. + EDMA_TPD_RING_SIZE_MASK);
  349. + }
  350. +
  351. + for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) {
  352. + rfd_ring = edma_cinfo->rfd_ring[j];
  353. + /* Update Receive Free descriptor ring base address */
  354. + edma_write_reg(EDMA_REG_RFD_BASE_ADDR_Q(j),
  355. + (u32)(rfd_ring->dma));
  356. + j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1);
  357. + }
  358. +
  359. + data = edma_cinfo->rx_head_buffer_len;
  360. + if (edma_cinfo->page_mode)
  361. + data = edma_cinfo->rx_page_buffer_len;
  362. +
  363. + data &= EDMA_RX_BUF_SIZE_MASK;
  364. + data <<= EDMA_RX_BUF_SIZE_SHIFT;
  365. +
  366. + /* Update RFD ring size and RX buffer size */
  367. + data |= (edma_cinfo->rx_ring_count & EDMA_RFD_RING_SIZE_MASK)
  368. + << EDMA_RFD_RING_SIZE_SHIFT;
  369. +
  370. + edma_write_reg(EDMA_REG_RX_DESC0, data);
  371. +
  372. + /* Disable TX FIFO low watermark and high watermark */
  373. + edma_write_reg(EDMA_REG_TXF_WATER_MARK, 0);
  374. +
  375. + /* Load all of base address above */
  376. + edma_read_reg(EDMA_REG_TX_SRAM_PART, &data);
  377. + data |= 1 << EDMA_LOAD_PTR_SHIFT;
  378. + edma_write_reg(EDMA_REG_TX_SRAM_PART, data);
  379. +}
  380. +
  381. +/* edma_receive_checksum
  382. + * Api to check checksum on receive packets
  383. + */
  384. +static void edma_receive_checksum(struct edma_rx_return_desc *rd,
  385. + struct sk_buff *skb)
  386. +{
  387. + skb_checksum_none_assert(skb);
  388. +
  389. + /* check the RRD IP/L4 checksum bit to see if
  390. + * its set, which in turn indicates checksum
  391. + * failure.
  392. + */
  393. + if (rd->rrd6 & EDMA_RRD_CSUM_FAIL_MASK)
  394. + return;
  395. +
  396. + skb->ip_summed = CHECKSUM_UNNECESSARY;
  397. +}
  398. +
  399. +/* edma_clean_rfd()
  400. + * clean up rx resourcers on error
  401. + */
  402. +static void edma_clean_rfd(struct edma_rfd_desc_ring *erdr, u16 index)
  403. +{
  404. + struct edma_rx_free_desc *rx_desc;
  405. + struct edma_sw_desc *sw_desc;
  406. +
  407. + rx_desc = (&((struct edma_rx_free_desc *)(erdr->hw_desc))[index]);
  408. + sw_desc = &erdr->sw_desc[index];
  409. + if (sw_desc->skb) {
  410. + dev_kfree_skb_any(sw_desc->skb);
  411. + sw_desc->skb = NULL;
  412. + }
  413. +
  414. + memset(rx_desc, 0, sizeof(struct edma_rx_free_desc));
  415. +}
  416. +
  417. +/* edma_rx_complete_fraglist()
  418. + * Complete Rx processing for fraglist skbs
  419. + */
  420. +static void edma_rx_complete_stp_rstp(struct sk_buff *skb, int port_id, struct edma_rx_return_desc *rd)
  421. +{
  422. + int i;
  423. + u32 priority;
  424. + u16 port_type;
  425. + u8 mac_addr[EDMA_ETH_HDR_LEN];
  426. +
  427. + port_type = (rd->rrd1 >> EDMA_RRD_PORT_TYPE_SHIFT)
  428. + & EDMA_RRD_PORT_TYPE_MASK;
  429. + /* if port type is 0x4, then only proceed with
  430. + * other stp/rstp calculation
  431. + */
  432. + if (port_type == EDMA_RX_ATH_HDR_RSTP_PORT_TYPE) {
  433. + u8 bpdu_mac[6] = {0x01, 0x80, 0xc2, 0x00, 0x00, 0x00};
  434. +
  435. + /* calculate the frame priority */
  436. + priority = (rd->rrd1 >> EDMA_RRD_PRIORITY_SHIFT)
  437. + & EDMA_RRD_PRIORITY_MASK;
  438. +
  439. + for (i = 0; i < EDMA_ETH_HDR_LEN; i++)
  440. + mac_addr[i] = skb->data[i];
  441. +
  442. + /* Check if destination mac addr is bpdu addr */
  443. + if (!memcmp(mac_addr, bpdu_mac, 6)) {
  444. + /* destination mac address is BPDU
  445. + * destination mac address, then add
  446. + * atheros header to the packet.
  447. + */
  448. + u16 athr_hdr = (EDMA_RX_ATH_HDR_VERSION << EDMA_RX_ATH_HDR_VERSION_SHIFT) |
  449. + (priority << EDMA_RX_ATH_HDR_PRIORITY_SHIFT) |
  450. + (EDMA_RX_ATH_HDR_RSTP_PORT_TYPE << EDMA_RX_ATH_PORT_TYPE_SHIFT) | port_id;
  451. + skb_push(skb, 4);
  452. + memcpy(skb->data, mac_addr, EDMA_ETH_HDR_LEN);
  453. + *(uint16_t *)&skb->data[12] = htons(edma_ath_eth_type);
  454. + *(uint16_t *)&skb->data[14] = htons(athr_hdr);
  455. + }
  456. + }
  457. +}
  458. +
  459. +/*
  460. + * edma_rx_complete_fraglist()
  461. + * Complete Rx processing for fraglist skbs
  462. + */
  463. +static int edma_rx_complete_fraglist(struct sk_buff *skb, u16 num_rfds, u16 length, u32 sw_next_to_clean,
  464. + u16 *cleaned_count, struct edma_rfd_desc_ring *erdr, struct edma_common_info *edma_cinfo)
  465. +{
  466. + struct platform_device *pdev = edma_cinfo->pdev;
  467. + struct edma_hw *hw = &edma_cinfo->hw;
  468. + struct sk_buff *skb_temp;
  469. + struct edma_sw_desc *sw_desc;
  470. + int i;
  471. + u16 size_remaining;
  472. +
  473. + skb->data_len = 0;
  474. + skb->tail += (hw->rx_head_buff_size - 16);
  475. + skb->len = skb->truesize = length;
  476. + size_remaining = length - (hw->rx_head_buff_size - 16);
  477. +
  478. + /* clean-up all related sw_descs */
  479. + for (i = 1; i < num_rfds; i++) {
  480. + struct sk_buff *skb_prev;
  481. + sw_desc = &erdr->sw_desc[sw_next_to_clean];
  482. + skb_temp = sw_desc->skb;
  483. +
  484. + dma_unmap_single(&pdev->dev, sw_desc->dma,
  485. + sw_desc->length, DMA_FROM_DEVICE);
  486. +
  487. + if (size_remaining < hw->rx_head_buff_size)
  488. + skb_put(skb_temp, size_remaining);
  489. + else
  490. + skb_put(skb_temp, hw->rx_head_buff_size);
  491. +
  492. + /*
  493. + * If we are processing the first rfd, we link
  494. + * skb->frag_list to the skb corresponding to the
  495. + * first RFD
  496. + */
  497. + if (i == 1)
  498. + skb_shinfo(skb)->frag_list = skb_temp;
  499. + else
  500. + skb_prev->next = skb_temp;
  501. + skb_prev = skb_temp;
  502. + skb_temp->next = NULL;
  503. +
  504. + skb->data_len += skb_temp->len;
  505. + size_remaining -= skb_temp->len;
  506. +
  507. + /* Increment SW index */
  508. + sw_next_to_clean = (sw_next_to_clean + 1) & (erdr->count - 1);
  509. + (*cleaned_count)++;
  510. + }
  511. +
  512. + return sw_next_to_clean;
  513. +}
  514. +
  515. +/* edma_rx_complete_paged()
  516. + * Complete Rx processing for paged skbs
  517. + */
  518. +static int edma_rx_complete_paged(struct sk_buff *skb, u16 num_rfds, u16 length, u32 sw_next_to_clean,
  519. + u16 *cleaned_count, struct edma_rfd_desc_ring *erdr, struct edma_common_info *edma_cinfo)
  520. +{
  521. + struct platform_device *pdev = edma_cinfo->pdev;
  522. + struct sk_buff *skb_temp;
  523. + struct edma_sw_desc *sw_desc;
  524. + int i;
  525. + u16 size_remaining;
  526. +
  527. + skb_frag_t *frag = &skb_shinfo(skb)->frags[0];
  528. +
  529. + /* Setup skbuff fields */
  530. + skb->len = length;
  531. +
  532. + if (likely(num_rfds <= 1)) {
  533. + skb->data_len = length;
  534. + skb->truesize += edma_cinfo->rx_page_buffer_len;
  535. + skb_fill_page_desc(skb, 0, skb_frag_page(frag),
  536. + 16, length);
  537. + } else {
  538. + frag->size -= 16;
  539. + skb->data_len = frag->size;
  540. + skb->truesize += edma_cinfo->rx_page_buffer_len;
  541. + size_remaining = length - frag->size;
  542. +
  543. + skb_fill_page_desc(skb, 0, skb_frag_page(frag),
  544. + 16, frag->size);
  545. +
  546. + /* clean-up all related sw_descs */
  547. + for (i = 1; i < num_rfds; i++) {
  548. + sw_desc = &erdr->sw_desc[sw_next_to_clean];
  549. + skb_temp = sw_desc->skb;
  550. + frag = &skb_shinfo(skb_temp)->frags[0];
  551. + dma_unmap_page(&pdev->dev, sw_desc->dma,
  552. + sw_desc->length, DMA_FROM_DEVICE);
  553. +
  554. + if (size_remaining < edma_cinfo->rx_page_buffer_len)
  555. + frag->size = size_remaining;
  556. +
  557. + skb_fill_page_desc(skb, i, skb_frag_page(frag),
  558. + 0, frag->size);
  559. +
  560. + skb_shinfo(skb_temp)->nr_frags = 0;
  561. + dev_kfree_skb_any(skb_temp);
  562. +
  563. + skb->data_len += frag->size;
  564. + skb->truesize += edma_cinfo->rx_page_buffer_len;
  565. + size_remaining -= frag->size;
  566. +
  567. + /* Increment SW index */
  568. + sw_next_to_clean = (sw_next_to_clean + 1) & (erdr->count - 1);
  569. + (*cleaned_count)++;
  570. + }
  571. + }
  572. +
  573. + return sw_next_to_clean;
  574. +}
  575. +
  576. +/*
  577. + * edma_rx_complete()
  578. + * Main api called from the poll function to process rx packets.
  579. + */
  580. +static void edma_rx_complete(struct edma_common_info *edma_cinfo,
  581. + int *work_done, int work_to_do, int queue_id,
  582. + struct napi_struct *napi)
  583. +{
  584. + struct platform_device *pdev = edma_cinfo->pdev;
  585. + struct edma_rfd_desc_ring *erdr = edma_cinfo->rfd_ring[queue_id];
  586. + struct net_device *netdev;
  587. + struct edma_adapter *adapter;
  588. + struct edma_sw_desc *sw_desc;
  589. + struct sk_buff *skb;
  590. + struct edma_rx_return_desc *rd;
  591. + u16 hash_type, rrd[8], cleaned_count = 0, length = 0, num_rfds = 1,
  592. + sw_next_to_clean, hw_next_to_clean = 0, vlan = 0, ret_count = 0;
  593. + u32 data = 0;
  594. + u8 *vaddr;
  595. + int port_id, i, drop_count = 0;
  596. + u32 priority;
  597. + u16 count = erdr->count, rfd_avail;
  598. + u8 queue_to_rxid[8] = {0, 0, 1, 1, 2, 2, 3, 3};
  599. +
  600. + sw_next_to_clean = erdr->sw_next_to_clean;
  601. +
  602. + edma_read_reg(EDMA_REG_RFD_IDX_Q(queue_id), &data);
  603. + hw_next_to_clean = (data >> EDMA_RFD_CONS_IDX_SHIFT) &
  604. + EDMA_RFD_CONS_IDX_MASK;
  605. +
  606. + do {
  607. + while (sw_next_to_clean != hw_next_to_clean) {
  608. + if (!work_to_do)
  609. + break;
  610. +
  611. + sw_desc = &erdr->sw_desc[sw_next_to_clean];
  612. + skb = sw_desc->skb;
  613. +
  614. + /* Unmap the allocated buffer */
  615. + if (likely(sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_HEAD))
  616. + dma_unmap_single(&pdev->dev, sw_desc->dma,
  617. + sw_desc->length, DMA_FROM_DEVICE);
  618. + else
  619. + dma_unmap_page(&pdev->dev, sw_desc->dma,
  620. + sw_desc->length, DMA_FROM_DEVICE);
  621. +
  622. + /* Get RRD */
  623. + if (edma_cinfo->page_mode) {
  624. + vaddr = kmap_atomic(skb_frag_page(&skb_shinfo(skb)->frags[0]));
  625. + memcpy((uint8_t *)&rrd[0], vaddr, 16);
  626. + rd = (struct edma_rx_return_desc *)rrd;
  627. + kunmap_atomic(vaddr);
  628. + } else {
  629. + rd = (struct edma_rx_return_desc *)skb->data;
  630. + }
  631. +
  632. + /* Check if RRD is valid */
  633. + if (!(rd->rrd7 & EDMA_RRD_DESC_VALID)) {
  634. + edma_clean_rfd(erdr, sw_next_to_clean);
  635. + sw_next_to_clean = (sw_next_to_clean + 1) &
  636. + (erdr->count - 1);
  637. + cleaned_count++;
  638. + continue;
  639. + }
  640. +
  641. + /* Get the number of RFDs from RRD */
  642. + num_rfds = rd->rrd1 & EDMA_RRD_NUM_RFD_MASK;
  643. +
  644. + /* Get Rx port ID from switch */
  645. + port_id = (rd->rrd1 >> EDMA_PORT_ID_SHIFT) & EDMA_PORT_ID_MASK;
  646. + if ((!port_id) || (port_id > EDMA_MAX_PORTID_SUPPORTED)) {
  647. + dev_err(&pdev->dev, "Invalid RRD source port bit set");
  648. + for (i = 0; i < num_rfds; i++) {
  649. + edma_clean_rfd(erdr, sw_next_to_clean);
  650. + sw_next_to_clean = (sw_next_to_clean + 1) & (erdr->count - 1);
  651. + cleaned_count++;
  652. + }
  653. + continue;
  654. + }
  655. +
  656. + /* check if we have a sink for the data we receive.
  657. + * If the interface isn't setup, we have to drop the
  658. + * incoming data for now.
  659. + */
  660. + netdev = edma_cinfo->portid_netdev_lookup_tbl[port_id];
  661. + if (!netdev) {
  662. + edma_clean_rfd(erdr, sw_next_to_clean);
  663. + sw_next_to_clean = (sw_next_to_clean + 1) &
  664. + (erdr->count - 1);
  665. + cleaned_count++;
  666. + continue;
  667. + }
  668. + adapter = netdev_priv(netdev);
  669. +
  670. + /* This code is added to handle a usecase where high
  671. + * priority stream and a low priority stream are
  672. + * received simultaneously on DUT. The problem occurs
  673. + * if one of the Rx rings is full and the corresponding
  674. + * core is busy with other stuff. This causes ESS CPU
  675. + * port to backpressure all incoming traffic including
  676. + * high priority one. We monitor free descriptor count
  677. + * on each CPU and whenever it reaches threshold (< 80),
  678. + * we drop all low priority traffic and let only high
  679. + * priotiy traffic pass through. We can hence avoid
  680. + * ESS CPU port to send backpressure on high priroity
  681. + * stream.
  682. + */
  683. + priority = (rd->rrd1 >> EDMA_RRD_PRIORITY_SHIFT)
  684. + & EDMA_RRD_PRIORITY_MASK;
  685. + if (likely(!priority && !edma_cinfo->page_mode && (num_rfds <= 1))) {
  686. + rfd_avail = (count + sw_next_to_clean - hw_next_to_clean - 1) & (count - 1);
  687. + if (rfd_avail < EDMA_RFD_AVAIL_THR) {
  688. + sw_desc->flags = EDMA_SW_DESC_FLAG_SKB_REUSE;
  689. + sw_next_to_clean = (sw_next_to_clean + 1) & (erdr->count - 1);
  690. + adapter->stats.rx_dropped++;
  691. + cleaned_count++;
  692. + drop_count++;
  693. + if (drop_count == 3) {
  694. + work_to_do--;
  695. + (*work_done)++;
  696. + drop_count = 0;
  697. + }
  698. + if (cleaned_count == EDMA_RX_BUFFER_WRITE) {
  699. + /* If buffer clean count reaches 16, we replenish HW buffers. */
  700. + ret_count = edma_alloc_rx_buf(edma_cinfo, erdr, cleaned_count, queue_id);
  701. + edma_write_reg(EDMA_REG_RX_SW_CONS_IDX_Q(queue_id),
  702. + sw_next_to_clean);
  703. + cleaned_count = ret_count;
  704. + }
  705. + continue;
  706. + }
  707. + }
  708. +
  709. + work_to_do--;
  710. + (*work_done)++;
  711. +
  712. + /* Increment SW index */
  713. + sw_next_to_clean = (sw_next_to_clean + 1) &
  714. + (erdr->count - 1);
  715. +
  716. + cleaned_count++;
  717. +
  718. + /* Get the packet size and allocate buffer */
  719. + length = rd->rrd6 & EDMA_RRD_PKT_SIZE_MASK;
  720. +
  721. + if (edma_cinfo->page_mode) {
  722. + /* paged skb */
  723. + sw_next_to_clean = edma_rx_complete_paged(skb, num_rfds, length, sw_next_to_clean, &cleaned_count, erdr, edma_cinfo);
  724. + if (!pskb_may_pull(skb, ETH_HLEN)) {
  725. + dev_kfree_skb_any(skb);
  726. + continue;
  727. + }
  728. + } else {
  729. + /* single or fraglist skb */
  730. +
  731. + /* Addition of 16 bytes is required, as in the packet
  732. + * first 16 bytes are rrd descriptors, so actual data
  733. + * starts from an offset of 16.
  734. + */
  735. + skb_reserve(skb, 16);
  736. + if (likely((num_rfds <= 1) || !edma_cinfo->fraglist_mode)) {
  737. + skb_put(skb, length);
  738. + } else {
  739. + sw_next_to_clean = edma_rx_complete_fraglist(skb, num_rfds, length, sw_next_to_clean, &cleaned_count, erdr, edma_cinfo);
  740. + }
  741. + }
  742. +
  743. + if (edma_stp_rstp) {
  744. + edma_rx_complete_stp_rstp(skb, port_id, rd);
  745. + }
  746. +
  747. + skb->protocol = eth_type_trans(skb, netdev);
  748. +
  749. + /* Record Rx queue for RFS/RPS and fill flow hash from HW */
  750. + skb_record_rx_queue(skb, queue_to_rxid[queue_id]);
  751. + if (netdev->features & NETIF_F_RXHASH) {
  752. + hash_type = (rd->rrd5 >> EDMA_HASH_TYPE_SHIFT);
  753. + if ((hash_type > EDMA_HASH_TYPE_START) && (hash_type < EDMA_HASH_TYPE_END))
  754. + skb_set_hash(skb, rd->rrd2, PKT_HASH_TYPE_L4);
  755. + }
  756. +
  757. +#ifdef CONFIG_NF_FLOW_COOKIE
  758. + skb->flow_cookie = rd->rrd3 & EDMA_RRD_FLOW_COOKIE_MASK;
  759. +#endif
  760. + edma_receive_checksum(rd, skb);
  761. +
  762. + /* Process VLAN HW acceleration indication provided by HW */
  763. + if (unlikely(adapter->default_vlan_tag != rd->rrd4)) {
  764. + vlan = rd->rrd4;
  765. + if (likely(rd->rrd7 & EDMA_RRD_CVLAN))
  766. + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan);
  767. + else if (rd->rrd1 & EDMA_RRD_SVLAN)
  768. + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021AD), vlan);
  769. + }
  770. +
  771. + /* Update rx statistics */
  772. + adapter->stats.rx_packets++;
  773. + adapter->stats.rx_bytes += length;
  774. +
  775. + /* Check if we reached refill threshold */
  776. + if (cleaned_count == EDMA_RX_BUFFER_WRITE) {
  777. + ret_count = edma_alloc_rx_buf(edma_cinfo, erdr, cleaned_count, queue_id);
  778. + edma_write_reg(EDMA_REG_RX_SW_CONS_IDX_Q(queue_id),
  779. + sw_next_to_clean);
  780. + cleaned_count = ret_count;
  781. + }
  782. +
  783. + /* At this point skb should go to stack */
  784. + napi_gro_receive(napi, skb);
  785. + }
  786. +
  787. + /* Check if we still have NAPI budget */
  788. + if (!work_to_do)
  789. + break;
  790. +
  791. + /* Read index once again since we still have NAPI budget */
  792. + edma_read_reg(EDMA_REG_RFD_IDX_Q(queue_id), &data);
  793. + hw_next_to_clean = (data >> EDMA_RFD_CONS_IDX_SHIFT) &
  794. + EDMA_RFD_CONS_IDX_MASK;
  795. + } while (hw_next_to_clean != sw_next_to_clean);
  796. +
  797. + erdr->sw_next_to_clean = sw_next_to_clean;
  798. +
  799. + /* Refill here in case refill threshold wasn't reached */
  800. + if (likely(cleaned_count)) {
  801. + ret_count = edma_alloc_rx_buf(edma_cinfo, erdr, cleaned_count, queue_id);
  802. + if (ret_count)
  803. + dev_dbg(&pdev->dev, "Not all buffers was reallocated");
  804. + edma_write_reg(EDMA_REG_RX_SW_CONS_IDX_Q(queue_id),
  805. + erdr->sw_next_to_clean);
  806. + }
  807. +}
  808. +
  809. +/* edma_delete_rfs_filter()
  810. + * Remove RFS filter from switch
  811. + */
  812. +static int edma_delete_rfs_filter(struct edma_adapter *adapter,
  813. + struct edma_rfs_filter_node *filter_node)
  814. +{
  815. + int res = -1;
  816. +
  817. + struct flow_keys *keys = &filter_node->keys;
  818. +
  819. + if (likely(adapter->set_rfs_rule))
  820. + res = (*adapter->set_rfs_rule)(adapter->netdev,
  821. + flow_get_u32_src(keys), flow_get_u32_dst(keys),
  822. + keys->ports.src, keys->ports.dst,
  823. + keys->basic.ip_proto, filter_node->rq_id, 0);
  824. +
  825. + return res;
  826. +}
  827. +
  828. +/* edma_add_rfs_filter()
  829. + * Add RFS filter to switch
  830. + */
  831. +static int edma_add_rfs_filter(struct edma_adapter *adapter,
  832. + struct flow_keys *keys, u16 rq,
  833. + struct edma_rfs_filter_node *filter_node)
  834. +{
  835. + int res = -1;
  836. +
  837. + struct flow_keys *dest_keys = &filter_node->keys;
  838. +
  839. + memcpy(dest_keys, &filter_node->keys, sizeof(*dest_keys));
  840. +/*
  841. + dest_keys->control = keys->control;
  842. + dest_keys->basic = keys->basic;
  843. + dest_keys->addrs = keys->addrs;
  844. + dest_keys->ports = keys->ports;
  845. + dest_keys.ip_proto = keys->ip_proto;
  846. +*/
  847. + /* Call callback registered by ESS driver */
  848. + if (likely(adapter->set_rfs_rule))
  849. + res = (*adapter->set_rfs_rule)(adapter->netdev, flow_get_u32_src(keys),
  850. + flow_get_u32_dst(keys), keys->ports.src, keys->ports.dst,
  851. + keys->basic.ip_proto, rq, 1);
  852. +
  853. + return res;
  854. +}
  855. +
  856. +/* edma_rfs_key_search()
  857. + * Look for existing RFS entry
  858. + */
  859. +static struct edma_rfs_filter_node *edma_rfs_key_search(struct hlist_head *h,
  860. + struct flow_keys *key)
  861. +{
  862. + struct edma_rfs_filter_node *p;
  863. +
  864. + hlist_for_each_entry(p, h, node)
  865. + if (flow_get_u32_src(&p->keys) == flow_get_u32_src(key) &&
  866. + flow_get_u32_dst(&p->keys) == flow_get_u32_dst(key) &&
  867. + p->keys.ports.src == key->ports.src &&
  868. + p->keys.ports.dst == key->ports.dst &&
  869. + p->keys.basic.ip_proto == key->basic.ip_proto)
  870. + return p;
  871. + return NULL;
  872. +}
  873. +
  874. +/* edma_initialise_rfs_flow_table()
  875. + * Initialise EDMA RFS flow table
  876. + */
  877. +static void edma_initialise_rfs_flow_table(struct edma_adapter *adapter)
  878. +{
  879. + int i;
  880. +
  881. + spin_lock_init(&adapter->rfs.rfs_ftab_lock);
  882. +
  883. + /* Initialize EDMA flow hash table */
  884. + for (i = 0; i < EDMA_RFS_FLOW_ENTRIES; i++)
  885. + INIT_HLIST_HEAD(&adapter->rfs.hlist_head[i]);
  886. +
  887. + adapter->rfs.max_num_filter = EDMA_RFS_FLOW_ENTRIES;
  888. + adapter->rfs.filter_available = adapter->rfs.max_num_filter;
  889. + adapter->rfs.hashtoclean = 0;
  890. +
  891. + /* Add timer to get periodic RFS updates from OS */
  892. + init_timer(&adapter->rfs.expire_rfs);
  893. + adapter->rfs.expire_rfs.function = edma_flow_may_expire;
  894. + adapter->rfs.expire_rfs.data = (unsigned long)adapter;
  895. + mod_timer(&adapter->rfs.expire_rfs, jiffies + HZ / 4);
  896. +}
  897. +
  898. +/* edma_free_rfs_flow_table()
  899. + * Free EDMA RFS flow table
  900. + */
  901. +static void edma_free_rfs_flow_table(struct edma_adapter *adapter)
  902. +{
  903. + int i;
  904. +
  905. + /* Remove sync timer */
  906. + del_timer_sync(&adapter->rfs.expire_rfs);
  907. + spin_lock_bh(&adapter->rfs.rfs_ftab_lock);
  908. +
  909. + /* Free EDMA RFS table entries */
  910. + adapter->rfs.filter_available = 0;
  911. +
  912. + /* Clean-up EDMA flow hash table */
  913. + for (i = 0; i < EDMA_RFS_FLOW_ENTRIES; i++) {
  914. + struct hlist_head *hhead;
  915. + struct hlist_node *tmp;
  916. + struct edma_rfs_filter_node *filter_node;
  917. + int res;
  918. +
  919. + hhead = &adapter->rfs.hlist_head[i];
  920. + hlist_for_each_entry_safe(filter_node, tmp, hhead, node) {
  921. + res = edma_delete_rfs_filter(adapter, filter_node);
  922. + if (res < 0)
  923. + dev_warn(&adapter->netdev->dev,
  924. + "EDMA going down but RFS entry %d not allowed to be flushed by Switch",
  925. + filter_node->flow_id);
  926. + hlist_del(&filter_node->node);
  927. + kfree(filter_node);
  928. + }
  929. + }
  930. + spin_unlock_bh(&adapter->rfs.rfs_ftab_lock);
  931. +}
  932. +
  933. +/* edma_tx_unmap_and_free()
  934. + * clean TX buffer
  935. + */
  936. +static inline void edma_tx_unmap_and_free(struct platform_device *pdev,
  937. + struct edma_sw_desc *sw_desc)
  938. +{
  939. + struct sk_buff *skb = sw_desc->skb;
  940. +
  941. + if (likely((sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_HEAD) ||
  942. + (sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_FRAGLIST)))
  943. + /* unmap_single for skb head area */
  944. + dma_unmap_single(&pdev->dev, sw_desc->dma,
  945. + sw_desc->length, DMA_TO_DEVICE);
  946. + else if (sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_FRAG)
  947. + /* unmap page for paged fragments */
  948. + dma_unmap_page(&pdev->dev, sw_desc->dma,
  949. + sw_desc->length, DMA_TO_DEVICE);
  950. +
  951. + if (likely(sw_desc->flags & EDMA_SW_DESC_FLAG_LAST))
  952. + dev_kfree_skb_any(skb);
  953. +
  954. + sw_desc->flags = 0;
  955. +}
  956. +
  957. +/* edma_tx_complete()
  958. + * Used to clean tx queues and update hardware and consumer index
  959. + */
  960. +static void edma_tx_complete(struct edma_common_info *edma_cinfo, int queue_id)
  961. +{
  962. + struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[queue_id];
  963. + struct edma_sw_desc *sw_desc;
  964. + struct platform_device *pdev = edma_cinfo->pdev;
  965. + int i;
  966. +
  967. + u16 sw_next_to_clean = etdr->sw_next_to_clean;
  968. + u16 hw_next_to_clean;
  969. + u32 data = 0;
  970. +
  971. + edma_read_reg(EDMA_REG_TPD_IDX_Q(queue_id), &data);
  972. + hw_next_to_clean = (data >> EDMA_TPD_CONS_IDX_SHIFT) & EDMA_TPD_CONS_IDX_MASK;
  973. +
  974. + /* clean the buffer here */
  975. + while (sw_next_to_clean != hw_next_to_clean) {
  976. + sw_desc = &etdr->sw_desc[sw_next_to_clean];
  977. + edma_tx_unmap_and_free(pdev, sw_desc);
  978. + sw_next_to_clean = (sw_next_to_clean + 1) & (etdr->count - 1);
  979. + }
  980. +
  981. + etdr->sw_next_to_clean = sw_next_to_clean;
  982. +
  983. + /* update the TPD consumer index register */
  984. + edma_write_reg(EDMA_REG_TX_SW_CONS_IDX_Q(queue_id), sw_next_to_clean);
  985. +
  986. + /* Wake the queue if queue is stopped and netdev link is up */
  987. + for (i = 0; i < EDMA_MAX_NETDEV_PER_QUEUE && etdr->nq[i] ; i++) {
  988. + if (netif_tx_queue_stopped(etdr->nq[i])) {
  989. + if ((etdr->netdev[i]) && netif_carrier_ok(etdr->netdev[i]))
  990. + netif_tx_wake_queue(etdr->nq[i]);
  991. + }
  992. + }
  993. +}
  994. +
  995. +/* edma_get_tx_buffer()
  996. + * Get sw_desc corresponding to the TPD
  997. + */
  998. +static struct edma_sw_desc *edma_get_tx_buffer(struct edma_common_info *edma_cinfo,
  999. + struct edma_tx_desc *tpd, int queue_id)
  1000. +{
  1001. + struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[queue_id];
  1002. + return &etdr->sw_desc[tpd - (struct edma_tx_desc *)etdr->hw_desc];
  1003. +}
  1004. +
  1005. +/* edma_get_next_tpd()
  1006. + * Return a TPD descriptor for transfer
  1007. + */
  1008. +static struct edma_tx_desc *edma_get_next_tpd(struct edma_common_info *edma_cinfo,
  1009. + int queue_id)
  1010. +{
  1011. + struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[queue_id];
  1012. + u16 sw_next_to_fill = etdr->sw_next_to_fill;
  1013. + struct edma_tx_desc *tpd_desc =
  1014. + (&((struct edma_tx_desc *)(etdr->hw_desc))[sw_next_to_fill]);
  1015. +
  1016. + etdr->sw_next_to_fill = (etdr->sw_next_to_fill + 1) & (etdr->count - 1);
  1017. +
  1018. + return tpd_desc;
  1019. +}
  1020. +
  1021. +/* edma_tpd_available()
  1022. + * Check number of free TPDs
  1023. + */
  1024. +static inline u16 edma_tpd_available(struct edma_common_info *edma_cinfo,
  1025. + int queue_id)
  1026. +{
  1027. + struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[queue_id];
  1028. +
  1029. + u16 sw_next_to_fill;
  1030. + u16 sw_next_to_clean;
  1031. + u16 count = 0;
  1032. +
  1033. + sw_next_to_clean = etdr->sw_next_to_clean;
  1034. + sw_next_to_fill = etdr->sw_next_to_fill;
  1035. +
  1036. + if (likely(sw_next_to_clean <= sw_next_to_fill))
  1037. + count = etdr->count;
  1038. +
  1039. + return count + sw_next_to_clean - sw_next_to_fill - 1;
  1040. +}
  1041. +
  1042. +/* edma_tx_queue_get()
  1043. + * Get the starting number of the queue
  1044. + */
  1045. +static inline int edma_tx_queue_get(struct edma_adapter *adapter,
  1046. + struct sk_buff *skb, int txq_id)
  1047. +{
  1048. + /* skb->priority is used as an index to skb priority table
  1049. + * and based on packet priority, correspong queue is assigned.
  1050. + */
  1051. + return adapter->tx_start_offset[txq_id] + edma_skb_priority_offset(skb);
  1052. +}
  1053. +
  1054. +/* edma_tx_update_hw_idx()
  1055. + * update the producer index for the ring transmitted
  1056. + */
  1057. +static void edma_tx_update_hw_idx(struct edma_common_info *edma_cinfo,
  1058. + struct sk_buff *skb, int queue_id)
  1059. +{
  1060. + struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[queue_id];
  1061. + u32 tpd_idx_data;
  1062. +
  1063. + /* Read and update the producer index */
  1064. + edma_read_reg(EDMA_REG_TPD_IDX_Q(queue_id), &tpd_idx_data);
  1065. + tpd_idx_data &= ~EDMA_TPD_PROD_IDX_BITS;
  1066. + tpd_idx_data |= (etdr->sw_next_to_fill & EDMA_TPD_PROD_IDX_MASK)
  1067. + << EDMA_TPD_PROD_IDX_SHIFT;
  1068. +
  1069. + edma_write_reg(EDMA_REG_TPD_IDX_Q(queue_id), tpd_idx_data);
  1070. +}
  1071. +
  1072. +/* edma_rollback_tx()
  1073. + * Function to retrieve tx resources in case of error
  1074. + */
  1075. +static void edma_rollback_tx(struct edma_adapter *adapter,
  1076. + struct edma_tx_desc *start_tpd, int queue_id)
  1077. +{
  1078. + struct edma_tx_desc_ring *etdr = adapter->edma_cinfo->tpd_ring[queue_id];
  1079. + struct edma_sw_desc *sw_desc;
  1080. + struct edma_tx_desc *tpd = NULL;
  1081. + u16 start_index, index;
  1082. +
  1083. + start_index = start_tpd - (struct edma_tx_desc *)(etdr->hw_desc);
  1084. +
  1085. + index = start_index;
  1086. + while (index != etdr->sw_next_to_fill) {
  1087. + tpd = (&((struct edma_tx_desc *)(etdr->hw_desc))[index]);
  1088. + sw_desc = &etdr->sw_desc[index];
  1089. + edma_tx_unmap_and_free(adapter->pdev, sw_desc);
  1090. + memset(tpd, 0, sizeof(struct edma_tx_desc));
  1091. + if (++index == etdr->count)
  1092. + index = 0;
  1093. + }
  1094. + etdr->sw_next_to_fill = start_index;
  1095. +}
  1096. +
  1097. +/* edma_tx_map_and_fill()
  1098. + * gets called from edma_xmit_frame
  1099. + *
  1100. + * This is where the dma of the buffer to be transmitted
  1101. + * gets mapped
  1102. + */
  1103. +static int edma_tx_map_and_fill(struct edma_common_info *edma_cinfo,
  1104. + struct edma_adapter *adapter, struct sk_buff *skb, int queue_id,
  1105. + unsigned int flags_transmit, u16 from_cpu, u16 dp_bitmap,
  1106. + bool packet_is_rstp, int nr_frags)
  1107. +{
  1108. + struct edma_sw_desc *sw_desc = NULL;
  1109. + struct platform_device *pdev = edma_cinfo->pdev;
  1110. + struct edma_tx_desc *tpd = NULL, *start_tpd = NULL;
  1111. + struct sk_buff *iter_skb;
  1112. + int i = 0;
  1113. + u32 word1 = 0, word3 = 0, lso_word1 = 0, svlan_tag = 0;
  1114. + u16 buf_len, lso_desc_len = 0;
  1115. +
  1116. + /* It should either be a nr_frags skb or fraglist skb but not both */
  1117. + BUG_ON(nr_frags && skb_has_frag_list(skb));
  1118. +
  1119. + if (skb_is_gso(skb)) {
  1120. + /* TODO: What additional checks need to be performed here */
  1121. + if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) {
  1122. + lso_word1 |= EDMA_TPD_IPV4_EN;
  1123. + ip_hdr(skb)->check = 0;
  1124. + tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  1125. + ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  1126. + } else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) {
  1127. + lso_word1 |= EDMA_TPD_LSO_V2_EN;
  1128. + ipv6_hdr(skb)->payload_len = 0;
  1129. + tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  1130. + &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  1131. + } else
  1132. + return -EINVAL;
  1133. +
  1134. + lso_word1 |= EDMA_TPD_LSO_EN | ((skb_shinfo(skb)->gso_size & EDMA_TPD_MSS_MASK) << EDMA_TPD_MSS_SHIFT) |
  1135. + (skb_transport_offset(skb) << EDMA_TPD_HDR_SHIFT);
  1136. + } else if (flags_transmit & EDMA_HW_CHECKSUM) {
  1137. + u8 css, cso;
  1138. + cso = skb_checksum_start_offset(skb);
  1139. + css = cso + skb->csum_offset;
  1140. +
  1141. + word1 |= (EDMA_TPD_CUSTOM_CSUM_EN);
  1142. + word1 |= (cso >> 1) << EDMA_TPD_HDR_SHIFT;
  1143. + word1 |= ((css >> 1) << EDMA_TPD_CUSTOM_CSUM_SHIFT);
  1144. + }
  1145. +
  1146. + if (skb->protocol == htons(ETH_P_PPP_SES))
  1147. + word1 |= EDMA_TPD_PPPOE_EN;
  1148. +
  1149. + if (flags_transmit & EDMA_VLAN_TX_TAG_INSERT_FLAG) {
  1150. + switch(skb->vlan_proto) {
  1151. + case htons(ETH_P_8021Q):
  1152. + word3 |= (1 << EDMA_TX_INS_CVLAN);
  1153. + word3 |= skb_vlan_tag_get(skb) << EDMA_TX_CVLAN_TAG_SHIFT;
  1154. + break;
  1155. + case htons(ETH_P_8021AD):
  1156. + word1 |= (1 << EDMA_TX_INS_SVLAN);
  1157. + svlan_tag = skb_vlan_tag_get(skb) << EDMA_TX_SVLAN_TAG_SHIFT;
  1158. + break;
  1159. + default:
  1160. + dev_err(&pdev->dev, "no ctag or stag present\n");
  1161. + goto vlan_tag_error;
  1162. + }
  1163. + } else if (flags_transmit & EDMA_VLAN_TX_TAG_INSERT_DEFAULT_FLAG) {
  1164. + word3 |= (1 << EDMA_TX_INS_CVLAN);
  1165. + word3 |= (adapter->default_vlan_tag) << EDMA_TX_CVLAN_TAG_SHIFT;
  1166. + }
  1167. +
  1168. + if (packet_is_rstp) {
  1169. + word3 |= dp_bitmap << EDMA_TPD_PORT_BITMAP_SHIFT;
  1170. + word3 |= from_cpu << EDMA_TPD_FROM_CPU_SHIFT;
  1171. + } else {
  1172. + word3 |= adapter->dp_bitmap << EDMA_TPD_PORT_BITMAP_SHIFT;
  1173. + }
  1174. +
  1175. + buf_len = skb_headlen(skb);
  1176. +
  1177. + if (lso_word1) {
  1178. + if (lso_word1 & EDMA_TPD_LSO_V2_EN) {
  1179. +
  1180. + /* IPv6 LSOv2 descriptor */
  1181. + start_tpd = tpd = edma_get_next_tpd(edma_cinfo, queue_id);
  1182. + sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id);
  1183. + sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_NONE;
  1184. +
  1185. + /* LSOv2 descriptor overrides addr field to pass length */
  1186. + tpd->addr = cpu_to_le16(skb->len);
  1187. + tpd->svlan_tag = svlan_tag;
  1188. + tpd->word1 = word1 | lso_word1;
  1189. + tpd->word3 = word3;
  1190. + }
  1191. +
  1192. + tpd = edma_get_next_tpd(edma_cinfo, queue_id);
  1193. + if (!start_tpd)
  1194. + start_tpd = tpd;
  1195. + sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id);
  1196. +
  1197. + /* The last buffer info contain the skb address,
  1198. + * so skb will be freed after unmap
  1199. + */
  1200. + sw_desc->length = lso_desc_len;
  1201. + sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_HEAD;
  1202. +
  1203. + sw_desc->dma = dma_map_single(&adapter->pdev->dev,
  1204. + skb->data, buf_len, DMA_TO_DEVICE);
  1205. + if (dma_mapping_error(&pdev->dev, sw_desc->dma))
  1206. + goto dma_error;
  1207. +
  1208. + tpd->addr = cpu_to_le32(sw_desc->dma);
  1209. + tpd->len = cpu_to_le16(buf_len);
  1210. +
  1211. + tpd->svlan_tag = svlan_tag;
  1212. + tpd->word1 = word1 | lso_word1;
  1213. + tpd->word3 = word3;
  1214. +
  1215. + /* The last buffer info contain the skb address,
  1216. + * so it will be freed after unmap
  1217. + */
  1218. + sw_desc->length = lso_desc_len;
  1219. + sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_HEAD;
  1220. +
  1221. + buf_len = 0;
  1222. + }
  1223. +
  1224. + if (likely(buf_len)) {
  1225. +
  1226. + /* TODO Do not dequeue descriptor if there is a potential error */
  1227. + tpd = edma_get_next_tpd(edma_cinfo, queue_id);
  1228. +
  1229. + if (!start_tpd)
  1230. + start_tpd = tpd;
  1231. +
  1232. + sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id);
  1233. +
  1234. + /* The last buffer info contain the skb address,
  1235. + * so it will be free after unmap
  1236. + */
  1237. + sw_desc->length = buf_len;
  1238. + sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_HEAD;
  1239. + sw_desc->dma = dma_map_single(&adapter->pdev->dev,
  1240. + skb->data, buf_len, DMA_TO_DEVICE);
  1241. + if (dma_mapping_error(&pdev->dev, sw_desc->dma))
  1242. + goto dma_error;
  1243. +
  1244. + tpd->addr = cpu_to_le32(sw_desc->dma);
  1245. + tpd->len = cpu_to_le16(buf_len);
  1246. +
  1247. + tpd->svlan_tag = svlan_tag;
  1248. + tpd->word1 = word1 | lso_word1;
  1249. + tpd->word3 = word3;
  1250. + }
  1251. +
  1252. + /* Walk through all paged fragments */
  1253. + while (nr_frags--) {
  1254. + skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1255. + buf_len = skb_frag_size(frag);
  1256. + tpd = edma_get_next_tpd(edma_cinfo, queue_id);
  1257. + sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id);
  1258. + sw_desc->length = buf_len;
  1259. + sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_FRAG;
  1260. +
  1261. + sw_desc->dma = skb_frag_dma_map(&pdev->dev, frag, 0, buf_len, DMA_TO_DEVICE);
  1262. +
  1263. + if (dma_mapping_error(NULL, sw_desc->dma))
  1264. + goto dma_error;
  1265. +
  1266. + tpd->addr = cpu_to_le32(sw_desc->dma);
  1267. + tpd->len = cpu_to_le16(buf_len);
  1268. +
  1269. + tpd->svlan_tag = svlan_tag;
  1270. + tpd->word1 = word1 | lso_word1;
  1271. + tpd->word3 = word3;
  1272. + i++;
  1273. + }
  1274. +
  1275. + /* Walk through all fraglist skbs */
  1276. + skb_walk_frags(skb, iter_skb) {
  1277. + buf_len = iter_skb->len;
  1278. + tpd = edma_get_next_tpd(edma_cinfo, queue_id);
  1279. + sw_desc = edma_get_tx_buffer(edma_cinfo, tpd, queue_id);
  1280. + sw_desc->length = buf_len;
  1281. + sw_desc->dma = dma_map_single(&adapter->pdev->dev,
  1282. + iter_skb->data, buf_len, DMA_TO_DEVICE);
  1283. +
  1284. + if (dma_mapping_error(NULL, sw_desc->dma))
  1285. + goto dma_error;
  1286. +
  1287. + tpd->addr = cpu_to_le32(sw_desc->dma);
  1288. + tpd->len = cpu_to_le16(buf_len);
  1289. + tpd->svlan_tag = svlan_tag;
  1290. + tpd->word1 = word1 | lso_word1;
  1291. + tpd->word3 = word3;
  1292. + sw_desc->flags |= EDMA_SW_DESC_FLAG_SKB_FRAGLIST;
  1293. + }
  1294. +
  1295. + if (tpd)
  1296. + tpd->word1 |= 1 << EDMA_TPD_EOP_SHIFT;
  1297. +
  1298. + sw_desc->skb = skb;
  1299. + sw_desc->flags |= EDMA_SW_DESC_FLAG_LAST;
  1300. +
  1301. + return 0;
  1302. +
  1303. +dma_error:
  1304. + edma_rollback_tx(adapter, start_tpd, queue_id);
  1305. + dev_err(&pdev->dev, "TX DMA map failed\n");
  1306. +vlan_tag_error:
  1307. + return -ENOMEM;
  1308. +}
  1309. +
  1310. +/* edma_check_link()
  1311. + * check Link status
  1312. + */
  1313. +static int edma_check_link(struct edma_adapter *adapter)
  1314. +{
  1315. + struct phy_device *phydev = adapter->phydev;
  1316. +
  1317. + if (!(adapter->poll_required))
  1318. + return __EDMA_LINKUP;
  1319. +
  1320. + if (phydev->link)
  1321. + return __EDMA_LINKUP;
  1322. +
  1323. + return __EDMA_LINKDOWN;
  1324. +}
  1325. +
  1326. +/* edma_adjust_link()
  1327. + * check for edma link status
  1328. + */
  1329. +void edma_adjust_link(struct net_device *netdev)
  1330. +{
  1331. + int status;
  1332. + struct edma_adapter *adapter = netdev_priv(netdev);
  1333. + struct phy_device *phydev = adapter->phydev;
  1334. +
  1335. + if (!test_bit(__EDMA_UP, &adapter->state_flags))
  1336. + return;
  1337. +
  1338. + status = edma_check_link(adapter);
  1339. +
  1340. + if (status == __EDMA_LINKUP && adapter->link_state == __EDMA_LINKDOWN) {
  1341. + dev_info(&adapter->pdev->dev, "%s: GMAC Link is up with phy_speed=%d\n", netdev->name, phydev->speed);
  1342. + adapter->link_state = __EDMA_LINKUP;
  1343. + netif_carrier_on(netdev);
  1344. + if (netif_running(netdev))
  1345. + netif_tx_wake_all_queues(netdev);
  1346. + } else if (status == __EDMA_LINKDOWN && adapter->link_state == __EDMA_LINKUP) {
  1347. + dev_info(&adapter->pdev->dev, "%s: GMAC Link is down\n", netdev->name);
  1348. + adapter->link_state = __EDMA_LINKDOWN;
  1349. + netif_carrier_off(netdev);
  1350. + netif_tx_stop_all_queues(netdev);
  1351. + }
  1352. +}
  1353. +
  1354. +/* edma_get_stats()
  1355. + * Statistics api used to retreive the tx/rx statistics
  1356. + */
  1357. +struct net_device_stats *edma_get_stats(struct net_device *netdev)
  1358. +{
  1359. + struct edma_adapter *adapter = netdev_priv(netdev);
  1360. +
  1361. + return &adapter->stats;
  1362. +}
  1363. +
  1364. +/* edma_xmit()
  1365. + * Main api to be called by the core for packet transmission
  1366. + */
  1367. +netdev_tx_t edma_xmit(struct sk_buff *skb,
  1368. + struct net_device *net_dev)
  1369. +{
  1370. + struct edma_adapter *adapter = netdev_priv(net_dev);
  1371. + struct edma_common_info *edma_cinfo = adapter->edma_cinfo;
  1372. + struct edma_tx_desc_ring *etdr;
  1373. + u16 from_cpu, dp_bitmap, txq_id;
  1374. + int ret, nr_frags = 0, num_tpds_needed = 1, queue_id;
  1375. + unsigned int flags_transmit = 0;
  1376. + bool packet_is_rstp = false;
  1377. + struct netdev_queue *nq = NULL;
  1378. +
  1379. + if (skb_shinfo(skb)->nr_frags) {
  1380. + nr_frags = skb_shinfo(skb)->nr_frags;
  1381. + num_tpds_needed += nr_frags;
  1382. + } else if (skb_has_frag_list(skb)) {
  1383. + struct sk_buff *iter_skb;
  1384. +
  1385. + skb_walk_frags(skb, iter_skb)
  1386. + num_tpds_needed++;
  1387. + }
  1388. +
  1389. + if (num_tpds_needed > EDMA_MAX_SKB_FRAGS) {
  1390. + dev_err(&net_dev->dev,
  1391. + "skb received with fragments %d which is more than %lu",
  1392. + num_tpds_needed, EDMA_MAX_SKB_FRAGS);
  1393. + dev_kfree_skb_any(skb);
  1394. + adapter->stats.tx_errors++;
  1395. + return NETDEV_TX_OK;
  1396. + }
  1397. +
  1398. + if (edma_stp_rstp) {
  1399. + u16 ath_hdr, ath_eth_type;
  1400. + u8 mac_addr[EDMA_ETH_HDR_LEN];
  1401. + ath_eth_type = ntohs(*(uint16_t *)&skb->data[12]);
  1402. + if (ath_eth_type == edma_ath_eth_type) {
  1403. + packet_is_rstp = true;
  1404. + ath_hdr = htons(*(uint16_t *)&skb->data[14]);
  1405. + dp_bitmap = ath_hdr & EDMA_TX_ATH_HDR_PORT_BITMAP_MASK;
  1406. + from_cpu = (ath_hdr & EDMA_TX_ATH_HDR_FROM_CPU_MASK) >> EDMA_TX_ATH_HDR_FROM_CPU_SHIFT;
  1407. + memcpy(mac_addr, skb->data, EDMA_ETH_HDR_LEN);
  1408. +
  1409. + skb_pull(skb, 4);
  1410. +
  1411. + memcpy(skb->data, mac_addr, EDMA_ETH_HDR_LEN);
  1412. + }
  1413. + }
  1414. +
  1415. + /* this will be one of the 4 TX queues exposed to linux kernel */
  1416. + txq_id = skb_get_queue_mapping(skb);
  1417. + queue_id = edma_tx_queue_get(adapter, skb, txq_id);
  1418. + etdr = edma_cinfo->tpd_ring[queue_id];
  1419. + nq = netdev_get_tx_queue(net_dev, txq_id);
  1420. +
  1421. + local_bh_disable();
  1422. + /* Tx is not handled in bottom half context. Hence, we need to protect
  1423. + * Tx from tasks and bottom half
  1424. + */
  1425. +
  1426. + if (num_tpds_needed > edma_tpd_available(edma_cinfo, queue_id)) {
  1427. + /* not enough descriptor, just stop queue */
  1428. + netif_tx_stop_queue(nq);
  1429. + local_bh_enable();
  1430. + dev_dbg(&net_dev->dev, "Not enough descriptors available");
  1431. + edma_cinfo->edma_ethstats.tx_desc_error++;
  1432. + return NETDEV_TX_BUSY;
  1433. + }
  1434. +
  1435. + /* Check and mark VLAN tag offload */
  1436. + if (skb_vlan_tag_present(skb))
  1437. + flags_transmit |= EDMA_VLAN_TX_TAG_INSERT_FLAG;
  1438. + else if (adapter->default_vlan_tag)
  1439. + flags_transmit |= EDMA_VLAN_TX_TAG_INSERT_DEFAULT_FLAG;
  1440. +
  1441. + /* Check and mark checksum offload */
  1442. + if (likely(skb->ip_summed == CHECKSUM_PARTIAL))
  1443. + flags_transmit |= EDMA_HW_CHECKSUM;
  1444. +
  1445. + /* Map and fill descriptor for Tx */
  1446. + ret = edma_tx_map_and_fill(edma_cinfo, adapter, skb, queue_id,
  1447. + flags_transmit, from_cpu, dp_bitmap, packet_is_rstp, nr_frags);
  1448. + if (ret) {
  1449. + dev_kfree_skb_any(skb);
  1450. + adapter->stats.tx_errors++;
  1451. + goto netdev_okay;
  1452. + }
  1453. +
  1454. + /* Update SW producer index */
  1455. + edma_tx_update_hw_idx(edma_cinfo, skb, queue_id);
  1456. +
  1457. + /* update tx statistics */
  1458. + adapter->stats.tx_packets++;
  1459. + adapter->stats.tx_bytes += skb->len;
  1460. +
  1461. +netdev_okay:
  1462. + local_bh_enable();
  1463. + return NETDEV_TX_OK;
  1464. +}
  1465. +
  1466. +/*
  1467. + * edma_flow_may_expire()
  1468. + * Timer function called periodically to delete the node
  1469. + */
  1470. +void edma_flow_may_expire(unsigned long data)
  1471. +{
  1472. + struct edma_adapter *adapter = (struct edma_adapter *)data;
  1473. + int j;
  1474. +
  1475. + spin_lock_bh(&adapter->rfs.rfs_ftab_lock);
  1476. + for (j = 0; j < EDMA_RFS_EXPIRE_COUNT_PER_CALL; j++) {
  1477. + struct hlist_head *hhead;
  1478. + struct hlist_node *tmp;
  1479. + struct edma_rfs_filter_node *n;
  1480. + bool res;
  1481. +
  1482. + hhead = &adapter->rfs.hlist_head[adapter->rfs.hashtoclean++];
  1483. + hlist_for_each_entry_safe(n, tmp, hhead, node) {
  1484. + res = rps_may_expire_flow(adapter->netdev, n->rq_id,
  1485. + n->flow_id, n->filter_id);
  1486. + if (res) {
  1487. + int ret;
  1488. + ret = edma_delete_rfs_filter(adapter, n);
  1489. + if (ret < 0)
  1490. + dev_dbg(&adapter->netdev->dev,
  1491. + "RFS entry %d not allowed to be flushed by Switch",
  1492. + n->flow_id);
  1493. + else {
  1494. + hlist_del(&n->node);
  1495. + kfree(n);
  1496. + adapter->rfs.filter_available++;
  1497. + }
  1498. + }
  1499. + }
  1500. + }
  1501. +
  1502. + adapter->rfs.hashtoclean = adapter->rfs.hashtoclean & (EDMA_RFS_FLOW_ENTRIES - 1);
  1503. + spin_unlock_bh(&adapter->rfs.rfs_ftab_lock);
  1504. + mod_timer(&adapter->rfs.expire_rfs, jiffies + HZ / 4);
  1505. +}
  1506. +
  1507. +/* edma_rx_flow_steer()
  1508. + * Called by core to to steer the flow to CPU
  1509. + */
  1510. +int edma_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
  1511. + u16 rxq, u32 flow_id)
  1512. +{
  1513. + struct flow_keys keys;
  1514. + struct edma_rfs_filter_node *filter_node;
  1515. + struct edma_adapter *adapter = netdev_priv(dev);
  1516. + u16 hash_tblid;
  1517. + int res;
  1518. +
  1519. + if (skb->protocol == htons(ETH_P_IPV6)) {
  1520. + dev_err(&adapter->pdev->dev, "IPv6 not supported\n");
  1521. + res = -EINVAL;
  1522. + goto no_protocol_err;
  1523. + }
  1524. +
  1525. + /* Dissect flow parameters
  1526. + * We only support IPv4 + TCP/UDP
  1527. + */
  1528. + res = skb_flow_dissect_flow_keys(skb, &keys, 0);
  1529. + if (!((keys.basic.ip_proto == IPPROTO_TCP) || (keys.basic.ip_proto == IPPROTO_UDP))) {
  1530. + res = -EPROTONOSUPPORT;
  1531. + goto no_protocol_err;
  1532. + }
  1533. +
  1534. + /* Check if table entry exists */
  1535. + hash_tblid = skb_get_hash_raw(skb) & EDMA_RFS_FLOW_ENTRIES_MASK;
  1536. +
  1537. + spin_lock_bh(&adapter->rfs.rfs_ftab_lock);
  1538. + filter_node = edma_rfs_key_search(&adapter->rfs.hlist_head[hash_tblid], &keys);
  1539. +
  1540. + if (filter_node) {
  1541. + if (rxq == filter_node->rq_id) {
  1542. + res = -EEXIST;
  1543. + goto out;
  1544. + } else {
  1545. + res = edma_delete_rfs_filter(adapter, filter_node);
  1546. + if (res < 0)
  1547. + dev_warn(&adapter->netdev->dev,
  1548. + "Cannot steer flow %d to different queue",
  1549. + filter_node->flow_id);
  1550. + else {
  1551. + adapter->rfs.filter_available++;
  1552. + res = edma_add_rfs_filter(adapter, &keys, rxq, filter_node);
  1553. + if (res < 0) {
  1554. + dev_warn(&adapter->netdev->dev,
  1555. + "Cannot steer flow %d to different queue",
  1556. + filter_node->flow_id);
  1557. + } else {
  1558. + adapter->rfs.filter_available--;
  1559. + filter_node->rq_id = rxq;
  1560. + filter_node->filter_id = res;
  1561. + }
  1562. + }
  1563. + }
  1564. + } else {
  1565. + if (adapter->rfs.filter_available == 0) {
  1566. + res = -EBUSY;
  1567. + goto out;
  1568. + }
  1569. +
  1570. + filter_node = kmalloc(sizeof(*filter_node), GFP_ATOMIC);
  1571. + if (!filter_node) {
  1572. + res = -ENOMEM;
  1573. + goto out;
  1574. + }
  1575. +
  1576. + res = edma_add_rfs_filter(adapter, &keys, rxq, filter_node);
  1577. + if (res < 0) {
  1578. + kfree(filter_node);
  1579. + goto out;
  1580. + }
  1581. +
  1582. + adapter->rfs.filter_available--;
  1583. + filter_node->rq_id = rxq;
  1584. + filter_node->filter_id = res;
  1585. + filter_node->flow_id = flow_id;
  1586. + filter_node->keys = keys;
  1587. + INIT_HLIST_NODE(&filter_node->node);
  1588. + hlist_add_head(&filter_node->node, &adapter->rfs.hlist_head[hash_tblid]);
  1589. + }
  1590. +
  1591. +out:
  1592. + spin_unlock_bh(&adapter->rfs.rfs_ftab_lock);
  1593. +no_protocol_err:
  1594. + return res;
  1595. +}
  1596. +
  1597. +/* edma_register_rfs_filter()
  1598. + * Add RFS filter callback
  1599. + */
  1600. +int edma_register_rfs_filter(struct net_device *netdev,
  1601. + set_rfs_filter_callback_t set_filter)
  1602. +{
  1603. + struct edma_adapter *adapter = netdev_priv(netdev);
  1604. +
  1605. + spin_lock_bh(&adapter->rfs.rfs_ftab_lock);
  1606. +
  1607. + if (adapter->set_rfs_rule) {
  1608. + spin_unlock_bh(&adapter->rfs.rfs_ftab_lock);
  1609. + return -1;
  1610. + }
  1611. +
  1612. + adapter->set_rfs_rule = set_filter;
  1613. + spin_unlock_bh(&adapter->rfs.rfs_ftab_lock);
  1614. +
  1615. + return 0;
  1616. +}
  1617. +
  1618. +/* edma_alloc_tx_rings()
  1619. + * Allocate rx rings
  1620. + */
  1621. +int edma_alloc_tx_rings(struct edma_common_info *edma_cinfo)
  1622. +{
  1623. + struct platform_device *pdev = edma_cinfo->pdev;
  1624. + int i, err = 0;
  1625. +
  1626. + for (i = 0; i < edma_cinfo->num_tx_queues; i++) {
  1627. + err = edma_alloc_tx_ring(edma_cinfo, edma_cinfo->tpd_ring[i]);
  1628. + if (err) {
  1629. + dev_err(&pdev->dev, "Tx Queue alloc %u failed\n", i);
  1630. + return err;
  1631. + }
  1632. + }
  1633. +
  1634. + return 0;
  1635. +}
  1636. +
  1637. +/* edma_free_tx_rings()
  1638. + * Free tx rings
  1639. + */
  1640. +void edma_free_tx_rings(struct edma_common_info *edma_cinfo)
  1641. +{
  1642. + int i;
  1643. +
  1644. + for (i = 0; i < edma_cinfo->num_tx_queues; i++)
  1645. + edma_free_tx_ring(edma_cinfo, edma_cinfo->tpd_ring[i]);
  1646. +}
  1647. +
  1648. +/* edma_free_tx_resources()
  1649. + * Free buffers associated with tx rings
  1650. + */
  1651. +void edma_free_tx_resources(struct edma_common_info *edma_cinfo)
  1652. +{
  1653. + struct edma_tx_desc_ring *etdr;
  1654. + struct edma_sw_desc *sw_desc;
  1655. + struct platform_device *pdev = edma_cinfo->pdev;
  1656. + int i, j;
  1657. +
  1658. + for (i = 0; i < edma_cinfo->num_tx_queues; i++) {
  1659. + etdr = edma_cinfo->tpd_ring[i];
  1660. + for (j = 0; j < EDMA_TX_RING_SIZE; j++) {
  1661. + sw_desc = &etdr->sw_desc[j];
  1662. + if (sw_desc->flags & (EDMA_SW_DESC_FLAG_SKB_HEAD |
  1663. + EDMA_SW_DESC_FLAG_SKB_FRAG | EDMA_SW_DESC_FLAG_SKB_FRAGLIST))
  1664. + edma_tx_unmap_and_free(pdev, sw_desc);
  1665. + }
  1666. + }
  1667. +}
  1668. +
  1669. +/* edma_alloc_rx_rings()
  1670. + * Allocate rx rings
  1671. + */
  1672. +int edma_alloc_rx_rings(struct edma_common_info *edma_cinfo)
  1673. +{
  1674. + struct platform_device *pdev = edma_cinfo->pdev;
  1675. + int i, j, err = 0;
  1676. +
  1677. + for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) {
  1678. + err = edma_alloc_rx_ring(edma_cinfo, edma_cinfo->rfd_ring[j]);
  1679. + if (err) {
  1680. + dev_err(&pdev->dev, "Rx Queue alloc%u failed\n", i);
  1681. + return err;
  1682. + }
  1683. + j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1);
  1684. + }
  1685. +
  1686. + return 0;
  1687. +}
  1688. +
  1689. +/* edma_free_rx_rings()
  1690. + * free rx rings
  1691. + */
  1692. +void edma_free_rx_rings(struct edma_common_info *edma_cinfo)
  1693. +{
  1694. + int i, j;
  1695. +
  1696. + for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) {
  1697. + edma_free_rx_ring(edma_cinfo, edma_cinfo->rfd_ring[j]);
  1698. + j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1);
  1699. + }
  1700. +}
  1701. +
  1702. +/* edma_free_queues()
  1703. + * Free the queues allocaated
  1704. + */
  1705. +void edma_free_queues(struct edma_common_info *edma_cinfo)
  1706. +{
  1707. + int i , j;
  1708. +
  1709. + for (i = 0; i < edma_cinfo->num_tx_queues; i++) {
  1710. + if (edma_cinfo->tpd_ring[i])
  1711. + kfree(edma_cinfo->tpd_ring[i]);
  1712. + edma_cinfo->tpd_ring[i] = NULL;
  1713. + }
  1714. +
  1715. + for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) {
  1716. + if (edma_cinfo->rfd_ring[j])
  1717. + kfree(edma_cinfo->rfd_ring[j]);
  1718. + edma_cinfo->rfd_ring[j] = NULL;
  1719. + j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1);
  1720. + }
  1721. +
  1722. + edma_cinfo->num_rx_queues = 0;
  1723. + edma_cinfo->num_tx_queues = 0;
  1724. +
  1725. + return;
  1726. +}
  1727. +
  1728. +/* edma_free_rx_resources()
  1729. + * Free buffers associated with tx rings
  1730. + */
  1731. +void edma_free_rx_resources(struct edma_common_info *edma_cinfo)
  1732. +{
  1733. + struct edma_rfd_desc_ring *erdr;
  1734. + struct edma_sw_desc *sw_desc;
  1735. + struct platform_device *pdev = edma_cinfo->pdev;
  1736. + int i, j, k;
  1737. +
  1738. + for (i = 0, k = 0; i < edma_cinfo->num_rx_queues; i++) {
  1739. + erdr = edma_cinfo->rfd_ring[k];
  1740. + for (j = 0; j < EDMA_RX_RING_SIZE; j++) {
  1741. + sw_desc = &erdr->sw_desc[j];
  1742. + if (likely(sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_HEAD)) {
  1743. + dma_unmap_single(&pdev->dev, sw_desc->dma,
  1744. + sw_desc->length, DMA_FROM_DEVICE);
  1745. + edma_clean_rfd(erdr, j);
  1746. + } else if ((sw_desc->flags & EDMA_SW_DESC_FLAG_SKB_FRAG)) {
  1747. + dma_unmap_page(&pdev->dev, sw_desc->dma,
  1748. + sw_desc->length, DMA_FROM_DEVICE);
  1749. + edma_clean_rfd(erdr, j);
  1750. + }
  1751. + }
  1752. + k += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1);
  1753. +
  1754. + }
  1755. +}
  1756. +
  1757. +/* edma_alloc_queues_tx()
  1758. + * Allocate memory for all rings
  1759. + */
  1760. +int edma_alloc_queues_tx(struct edma_common_info *edma_cinfo)
  1761. +{
  1762. + int i;
  1763. +
  1764. + for (i = 0; i < edma_cinfo->num_tx_queues; i++) {
  1765. + struct edma_tx_desc_ring *etdr;
  1766. + etdr = kzalloc(sizeof(struct edma_tx_desc_ring), GFP_KERNEL);
  1767. + if (!etdr)
  1768. + goto err;
  1769. + etdr->count = edma_cinfo->tx_ring_count;
  1770. + edma_cinfo->tpd_ring[i] = etdr;
  1771. + }
  1772. +
  1773. + return 0;
  1774. +err:
  1775. + edma_free_queues(edma_cinfo);
  1776. + return -1;
  1777. +}
  1778. +
  1779. +/* edma_alloc_queues_rx()
  1780. + * Allocate memory for all rings
  1781. + */
  1782. +int edma_alloc_queues_rx(struct edma_common_info *edma_cinfo)
  1783. +{
  1784. + int i, j;
  1785. +
  1786. + for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) {
  1787. + struct edma_rfd_desc_ring *rfd_ring;
  1788. + rfd_ring = kzalloc(sizeof(struct edma_rfd_desc_ring),
  1789. + GFP_KERNEL);
  1790. + if (!rfd_ring)
  1791. + goto err;
  1792. + rfd_ring->count = edma_cinfo->rx_ring_count;
  1793. + edma_cinfo->rfd_ring[j] = rfd_ring;
  1794. + j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1);
  1795. + }
  1796. + return 0;
  1797. +err:
  1798. + edma_free_queues(edma_cinfo);
  1799. + return -1;
  1800. +}
  1801. +
  1802. +/* edma_clear_irq_status()
  1803. + * Clear interrupt status
  1804. + */
  1805. +void edma_clear_irq_status()
  1806. +{
  1807. + edma_write_reg(EDMA_REG_RX_ISR, 0xff);
  1808. + edma_write_reg(EDMA_REG_TX_ISR, 0xffff);
  1809. + edma_write_reg(EDMA_REG_MISC_ISR, 0x1fff);
  1810. + edma_write_reg(EDMA_REG_WOL_ISR, 0x1);
  1811. +};
  1812. +
  1813. +/* edma_configure()
  1814. + * Configure skb, edma interrupts and control register.
  1815. + */
  1816. +int edma_configure(struct edma_common_info *edma_cinfo)
  1817. +{
  1818. + struct edma_hw *hw = &edma_cinfo->hw;
  1819. + u32 intr_modrt_data;
  1820. + u32 intr_ctrl_data = 0;
  1821. + int i, j, ret_count;
  1822. +
  1823. + edma_read_reg(EDMA_REG_INTR_CTRL, &intr_ctrl_data);
  1824. + intr_ctrl_data &= ~(1 << EDMA_INTR_SW_IDX_W_TYP_SHIFT);
  1825. + intr_ctrl_data |= hw->intr_sw_idx_w << EDMA_INTR_SW_IDX_W_TYP_SHIFT;
  1826. + edma_write_reg(EDMA_REG_INTR_CTRL, intr_ctrl_data);
  1827. +
  1828. + edma_clear_irq_status();
  1829. +
  1830. + /* Clear any WOL status */
  1831. + edma_write_reg(EDMA_REG_WOL_CTRL, 0);
  1832. + intr_modrt_data = (EDMA_TX_IMT << EDMA_IRQ_MODRT_TX_TIMER_SHIFT);
  1833. + intr_modrt_data |= (EDMA_RX_IMT << EDMA_IRQ_MODRT_RX_TIMER_SHIFT);
  1834. + edma_write_reg(EDMA_REG_IRQ_MODRT_TIMER_INIT, intr_modrt_data);
  1835. + edma_configure_tx(edma_cinfo);
  1836. + edma_configure_rx(edma_cinfo);
  1837. +
  1838. + /* Allocate the RX buffer */
  1839. + for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) {
  1840. + struct edma_rfd_desc_ring *ring = edma_cinfo->rfd_ring[j];
  1841. + ret_count = edma_alloc_rx_buf(edma_cinfo, ring, ring->count, j);
  1842. + if (ret_count) {
  1843. + dev_dbg(&edma_cinfo->pdev->dev, "not all rx buffers allocated\n");
  1844. + }
  1845. + j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1);
  1846. + }
  1847. +
  1848. + /* Configure descriptor Ring */
  1849. + edma_init_desc(edma_cinfo);
  1850. + return 0;
  1851. +}
  1852. +
  1853. +/* edma_irq_enable()
  1854. + * Enable default interrupt generation settings
  1855. + */
  1856. +void edma_irq_enable(struct edma_common_info *edma_cinfo)
  1857. +{
  1858. + struct edma_hw *hw = &edma_cinfo->hw;
  1859. + int i, j;
  1860. +
  1861. + edma_write_reg(EDMA_REG_RX_ISR, 0xff);
  1862. + for (i = 0, j = 0; i < edma_cinfo->num_rx_queues; i++) {
  1863. + edma_write_reg(EDMA_REG_RX_INT_MASK_Q(j), hw->rx_intr_mask);
  1864. + j += ((edma_cinfo->num_rx_queues == 4) ? 2 : 1);
  1865. + }
  1866. + edma_write_reg(EDMA_REG_TX_ISR, 0xffff);
  1867. + for (i = 0; i < edma_cinfo->num_tx_queues; i++)
  1868. + edma_write_reg(EDMA_REG_TX_INT_MASK_Q(i), hw->tx_intr_mask);
  1869. +}
  1870. +
  1871. +/* edma_irq_disable()
  1872. + * Disable Interrupt
  1873. + */
  1874. +void edma_irq_disable(struct edma_common_info *edma_cinfo)
  1875. +{
  1876. + int i;
  1877. +
  1878. + for (i = 0; i < EDMA_MAX_RECEIVE_QUEUE; i++)
  1879. + edma_write_reg(EDMA_REG_RX_INT_MASK_Q(i), 0x0);
  1880. +
  1881. + for (i = 0; i < EDMA_MAX_TRANSMIT_QUEUE; i++)
  1882. + edma_write_reg(EDMA_REG_TX_INT_MASK_Q(i), 0x0);
  1883. + edma_write_reg(EDMA_REG_MISC_IMR, 0);
  1884. + edma_write_reg(EDMA_REG_WOL_IMR, 0);
  1885. +}
  1886. +
  1887. +/* edma_free_irqs()
  1888. + * Free All IRQs
  1889. + */
  1890. +void edma_free_irqs(struct edma_adapter *adapter)
  1891. +{
  1892. + struct edma_common_info *edma_cinfo = adapter->edma_cinfo;
  1893. + int i, j;
  1894. + int k = ((edma_cinfo->num_rx_queues == 4) ? 1 : 2);
  1895. +
  1896. + for (i = 0; i < CONFIG_NR_CPUS; i++) {
  1897. + for (j = edma_cinfo->edma_percpu_info[i].tx_start; j < (edma_cinfo->edma_percpu_info[i].tx_start + 4); j++)
  1898. + free_irq(edma_cinfo->tx_irq[j], &edma_cinfo->edma_percpu_info[i]);
  1899. +
  1900. + for (j = edma_cinfo->edma_percpu_info[i].rx_start; j < (edma_cinfo->edma_percpu_info[i].rx_start + k); j++)
  1901. + free_irq(edma_cinfo->rx_irq[j], &edma_cinfo->edma_percpu_info[i]);
  1902. + }
  1903. +}
  1904. +
  1905. +/* edma_enable_rx_ctrl()
  1906. + * Enable RX queue control
  1907. + */
  1908. +void edma_enable_rx_ctrl(struct edma_hw *hw)
  1909. +{
  1910. + u32 data;
  1911. +
  1912. + edma_read_reg(EDMA_REG_RXQ_CTRL, &data);
  1913. + data |= EDMA_RXQ_CTRL_EN;
  1914. + edma_write_reg(EDMA_REG_RXQ_CTRL, data);
  1915. +}
  1916. +
  1917. +
  1918. +/* edma_enable_tx_ctrl()
  1919. + * Enable TX queue control
  1920. + */
  1921. +void edma_enable_tx_ctrl(struct edma_hw *hw)
  1922. +{
  1923. + u32 data;
  1924. +
  1925. + edma_read_reg(EDMA_REG_TXQ_CTRL, &data);
  1926. + data |= EDMA_TXQ_CTRL_TXQ_EN;
  1927. + edma_write_reg(EDMA_REG_TXQ_CTRL, data);
  1928. +}
  1929. +
  1930. +/* edma_stop_rx_tx()
  1931. + * Disable RX/TQ Queue control
  1932. + */
  1933. +void edma_stop_rx_tx(struct edma_hw *hw)
  1934. +{
  1935. + u32 data;
  1936. +
  1937. + edma_read_reg(EDMA_REG_RXQ_CTRL, &data);
  1938. + data &= ~EDMA_RXQ_CTRL_EN;
  1939. + edma_write_reg(EDMA_REG_RXQ_CTRL, data);
  1940. + edma_read_reg(EDMA_REG_TXQ_CTRL, &data);
  1941. + data &= ~EDMA_TXQ_CTRL_TXQ_EN;
  1942. + edma_write_reg(EDMA_REG_TXQ_CTRL, data);
  1943. +}
  1944. +
  1945. +/* edma_reset()
  1946. + * Reset the EDMA
  1947. + */
  1948. +int edma_reset(struct edma_common_info *edma_cinfo)
  1949. +{
  1950. + struct edma_hw *hw = &edma_cinfo->hw;
  1951. +
  1952. + edma_irq_disable(edma_cinfo);
  1953. +
  1954. + edma_clear_irq_status();
  1955. +
  1956. + edma_stop_rx_tx(hw);
  1957. +
  1958. + return 0;
  1959. +}
  1960. +
  1961. +/* edma_fill_netdev()
  1962. + * Fill netdev for each etdr
  1963. + */
  1964. +int edma_fill_netdev(struct edma_common_info *edma_cinfo, int queue_id,
  1965. + int dev, int txq_id)
  1966. +{
  1967. + struct edma_tx_desc_ring *etdr;
  1968. + int i = 0;
  1969. +
  1970. + etdr = edma_cinfo->tpd_ring[queue_id];
  1971. +
  1972. + while (etdr->netdev[i])
  1973. + i++;
  1974. +
  1975. + if (i >= EDMA_MAX_NETDEV_PER_QUEUE)
  1976. + return -1;
  1977. +
  1978. + /* Populate the netdev associated with the tpd ring */
  1979. + etdr->netdev[i] = edma_netdev[dev];
  1980. + etdr->nq[i] = netdev_get_tx_queue(edma_netdev[dev], txq_id);
  1981. +
  1982. + return 0;
  1983. +}
  1984. +
  1985. +/* edma_set_mac()
  1986. + * Change the Ethernet Address of the NIC
  1987. + */
  1988. +int edma_set_mac_addr(struct net_device *netdev, void *p)
  1989. +{
  1990. + struct sockaddr *addr = p;
  1991. +
  1992. + if (!is_valid_ether_addr(addr->sa_data))
  1993. + return -EINVAL;
  1994. +
  1995. + if (netif_running(netdev))
  1996. + return -EBUSY;
  1997. +
  1998. + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1999. + return 0;
  2000. +}
  2001. +
  2002. +/* edma_set_stp_rstp()
  2003. + * set stp/rstp
  2004. + */
  2005. +void edma_set_stp_rstp(bool rstp)
  2006. +{
  2007. + edma_stp_rstp = rstp;
  2008. +}
  2009. +
  2010. +/* edma_assign_ath_hdr_type()
  2011. + * assign atheros header eth type
  2012. + */
  2013. +void edma_assign_ath_hdr_type(int eth_type)
  2014. +{
  2015. + edma_ath_eth_type = eth_type & EDMA_ETH_TYPE_MASK;
  2016. +}
  2017. +
  2018. +/* edma_get_default_vlan_tag()
  2019. + * Used by other modules to get the default vlan tag
  2020. + */
  2021. +int edma_get_default_vlan_tag(struct net_device *netdev)
  2022. +{
  2023. + struct edma_adapter *adapter = netdev_priv(netdev);
  2024. +
  2025. + if (adapter->default_vlan_tag)
  2026. + return adapter->default_vlan_tag;
  2027. +
  2028. + return 0;
  2029. +}
  2030. +
  2031. +/* edma_open()
  2032. + * gets called when netdevice is up, start the queue.
  2033. + */
  2034. +int edma_open(struct net_device *netdev)
  2035. +{
  2036. + struct edma_adapter *adapter = netdev_priv(netdev);
  2037. + struct platform_device *pdev = adapter->edma_cinfo->pdev;
  2038. +
  2039. + netif_tx_start_all_queues(netdev);
  2040. + edma_initialise_rfs_flow_table(adapter);
  2041. + set_bit(__EDMA_UP, &adapter->state_flags);
  2042. +
  2043. + /* if Link polling is enabled, in our case enabled for WAN, then
  2044. + * do a phy start, else always set link as UP
  2045. + */
  2046. + if (adapter->poll_required) {
  2047. + if (!IS_ERR(adapter->phydev)) {
  2048. + phy_start(adapter->phydev);
  2049. + phy_start_aneg(adapter->phydev);
  2050. + adapter->link_state = __EDMA_LINKDOWN;
  2051. + } else {
  2052. + dev_dbg(&pdev->dev, "Invalid PHY device for a link polled interface\n");
  2053. + }
  2054. + } else {
  2055. + adapter->link_state = __EDMA_LINKUP;
  2056. + netif_carrier_on(netdev);
  2057. + }
  2058. +
  2059. + return 0;
  2060. +}
  2061. +
  2062. +
  2063. +/* edma_close()
  2064. + * gets called when netdevice is down, stops the queue.
  2065. + */
  2066. +int edma_close(struct net_device *netdev)
  2067. +{
  2068. + struct edma_adapter *adapter = netdev_priv(netdev);
  2069. +
  2070. + edma_free_rfs_flow_table(adapter);
  2071. + netif_carrier_off(netdev);
  2072. + netif_tx_stop_all_queues(netdev);
  2073. +
  2074. + if (adapter->poll_required) {
  2075. + if (!IS_ERR(adapter->phydev))
  2076. + phy_stop(adapter->phydev);
  2077. + }
  2078. +
  2079. + adapter->link_state = __EDMA_LINKDOWN;
  2080. +
  2081. + /* Set GMAC state to UP before link state is checked
  2082. + */
  2083. + clear_bit(__EDMA_UP, &adapter->state_flags);
  2084. +
  2085. + return 0;
  2086. +}
  2087. +
  2088. +/* edma_poll
  2089. + * polling function that gets called when the napi gets scheduled.
  2090. + *
  2091. + * Main sequence of task performed in this api
  2092. + * is clear irq status -> clear_tx_irq -> clean_rx_irq->
  2093. + * enable interrupts.
  2094. + */
  2095. +int edma_poll(struct napi_struct *napi, int budget)
  2096. +{
  2097. + struct edma_per_cpu_queues_info *edma_percpu_info = container_of(napi,
  2098. + struct edma_per_cpu_queues_info, napi);
  2099. + struct edma_common_info *edma_cinfo = edma_percpu_info->edma_cinfo;
  2100. + u32 reg_data;
  2101. + u32 shadow_rx_status, shadow_tx_status;
  2102. + int queue_id;
  2103. + int i, work_done = 0;
  2104. +
  2105. + /* Store the Rx/Tx status by ANDing it with
  2106. + * appropriate CPU RX?TX mask
  2107. + */
  2108. + edma_read_reg(EDMA_REG_RX_ISR, &reg_data);
  2109. + edma_percpu_info->rx_status |= reg_data & edma_percpu_info->rx_mask;
  2110. + shadow_rx_status = edma_percpu_info->rx_status;
  2111. + edma_read_reg(EDMA_REG_TX_ISR, &reg_data);
  2112. + edma_percpu_info->tx_status |= reg_data & edma_percpu_info->tx_mask;
  2113. + shadow_tx_status = edma_percpu_info->tx_status;
  2114. +
  2115. + /* Every core will have a start, which will be computed
  2116. + * in probe and stored in edma_percpu_info->tx_start variable.
  2117. + * We will shift the status bit by tx_start to obtain
  2118. + * status bits for the core on which the current processing
  2119. + * is happening. Since, there are 4 tx queues per core,
  2120. + * we will run the loop till we get the correct queue to clear.
  2121. + */
  2122. + while (edma_percpu_info->tx_status) {
  2123. + queue_id = ffs(edma_percpu_info->tx_status) - 1;
  2124. + edma_tx_complete(edma_cinfo, queue_id);
  2125. + edma_percpu_info->tx_status &= ~(1 << queue_id);
  2126. + }
  2127. +
  2128. + /* Every core will have a start, which will be computed
  2129. + * in probe and stored in edma_percpu_info->tx_start variable.
  2130. + * We will shift the status bit by tx_start to obtain
  2131. + * status bits for the core on which the current processing
  2132. + * is happening. Since, there are 4 tx queues per core, we
  2133. + * will run the loop till we get the correct queue to clear.
  2134. + */
  2135. + while (edma_percpu_info->rx_status) {
  2136. + queue_id = ffs(edma_percpu_info->rx_status) - 1;
  2137. + edma_rx_complete(edma_cinfo, &work_done,
  2138. + budget, queue_id, napi);
  2139. +
  2140. + if (likely(work_done < budget))
  2141. + edma_percpu_info->rx_status &= ~(1 << queue_id);
  2142. + else
  2143. + break;
  2144. + }
  2145. +
  2146. + /* Clear the status register, to avoid the interrupts to
  2147. + * reoccur.This clearing of interrupt status register is
  2148. + * done here as writing to status register only takes place
  2149. + * once the producer/consumer index has been updated to
  2150. + * reflect that the packet transmission/reception went fine.
  2151. + */
  2152. + edma_write_reg(EDMA_REG_RX_ISR, shadow_rx_status);
  2153. + edma_write_reg(EDMA_REG_TX_ISR, shadow_tx_status);
  2154. +
  2155. + /* If budget not fully consumed, exit the polling mode */
  2156. + if (likely(work_done < budget)) {
  2157. + napi_complete(napi);
  2158. +
  2159. + /* re-enable the interrupts */
  2160. + for (i = 0; i < edma_cinfo->num_rxq_per_core; i++)
  2161. + edma_write_reg(EDMA_REG_RX_INT_MASK_Q(edma_percpu_info->rx_start + i), 0x1);
  2162. + for (i = 0; i < edma_cinfo->num_txq_per_core; i++)
  2163. + edma_write_reg(EDMA_REG_TX_INT_MASK_Q(edma_percpu_info->tx_start + i), 0x1);
  2164. + }
  2165. +
  2166. + return work_done;
  2167. +}
  2168. +
  2169. +/* edma interrupt()
  2170. + * interrupt handler
  2171. + */
  2172. +irqreturn_t edma_interrupt(int irq, void *dev)
  2173. +{
  2174. + struct edma_per_cpu_queues_info *edma_percpu_info = (struct edma_per_cpu_queues_info *) dev;
  2175. + struct edma_common_info *edma_cinfo = edma_percpu_info->edma_cinfo;
  2176. + int i;
  2177. +
  2178. + /* Unmask the TX/RX interrupt register */
  2179. + for (i = 0; i < edma_cinfo->num_rxq_per_core; i++)
  2180. + edma_write_reg(EDMA_REG_RX_INT_MASK_Q(edma_percpu_info->rx_start + i), 0x0);
  2181. +
  2182. + for (i = 0; i < edma_cinfo->num_txq_per_core; i++)
  2183. + edma_write_reg(EDMA_REG_TX_INT_MASK_Q(edma_percpu_info->tx_start + i), 0x0);
  2184. +
  2185. + napi_schedule(&edma_percpu_info->napi);
  2186. +
  2187. + return IRQ_HANDLED;
  2188. +}
  2189. --- /dev/null
  2190. +++ b/drivers/net/ethernet/qualcomm/essedma/edma.h
  2191. @@ -0,0 +1,446 @@
  2192. +/*
  2193. + * Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
  2194. + *
  2195. + * Permission to use, copy, modify, and/or distribute this software for
  2196. + * any purpose with or without fee is hereby granted, provided that the
  2197. + * above copyright notice and this permission notice appear in all copies.
  2198. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  2199. + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  2200. + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  2201. + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  2202. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  2203. + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  2204. + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  2205. + */
  2206. +
  2207. +#ifndef _EDMA_H_
  2208. +#define _EDMA_H_
  2209. +
  2210. +#include <linux/init.h>
  2211. +#include <linux/interrupt.h>
  2212. +#include <linux/types.h>
  2213. +#include <linux/errno.h>
  2214. +#include <linux/module.h>
  2215. +#include <linux/netdevice.h>
  2216. +#include <linux/etherdevice.h>
  2217. +#include <linux/skbuff.h>
  2218. +#include <linux/io.h>
  2219. +#include <linux/vmalloc.h>
  2220. +#include <linux/pagemap.h>
  2221. +#include <linux/smp.h>
  2222. +#include <linux/platform_device.h>
  2223. +#include <linux/of.h>
  2224. +#include <linux/of_device.h>
  2225. +#include <linux/kernel.h>
  2226. +#include <linux/device.h>
  2227. +#include <linux/sysctl.h>
  2228. +#include <linux/phy.h>
  2229. +#include <linux/of_net.h>
  2230. +#include <net/checksum.h>
  2231. +#include <net/ip6_checksum.h>
  2232. +#include <asm-generic/bug.h>
  2233. +#include "ess_edma.h"
  2234. +
  2235. +#define EDMA_CPU_CORES_SUPPORTED 4
  2236. +#define EDMA_MAX_PORTID_SUPPORTED 5
  2237. +#define EDMA_MAX_VLAN_SUPPORTED EDMA_MAX_PORTID_SUPPORTED
  2238. +#define EDMA_MAX_PORTID_BITMAP_INDEX (EDMA_MAX_PORTID_SUPPORTED + 1)
  2239. +#define EDMA_MAX_PORTID_BITMAP_SUPPORTED 0x1f /* 0001_1111 = 0x1f */
  2240. +#define EDMA_MAX_NETDEV_PER_QUEUE 4 /* 3 Netdev per queue, 1 space for indexing */
  2241. +
  2242. +#define EDMA_MAX_RECEIVE_QUEUE 8
  2243. +#define EDMA_MAX_TRANSMIT_QUEUE 16
  2244. +
  2245. +/* WAN/LAN adapter number */
  2246. +#define EDMA_WAN 0
  2247. +#define EDMA_LAN 1
  2248. +
  2249. +/* VLAN tag */
  2250. +#define EDMA_LAN_DEFAULT_VLAN 1
  2251. +#define EDMA_WAN_DEFAULT_VLAN 2
  2252. +
  2253. +#define EDMA_DEFAULT_GROUP1_VLAN 1
  2254. +#define EDMA_DEFAULT_GROUP2_VLAN 2
  2255. +#define EDMA_DEFAULT_GROUP3_VLAN 3
  2256. +#define EDMA_DEFAULT_GROUP4_VLAN 4
  2257. +#define EDMA_DEFAULT_GROUP5_VLAN 5
  2258. +
  2259. +/* Queues exposed to linux kernel */
  2260. +#define EDMA_NETDEV_TX_QUEUE 4
  2261. +#define EDMA_NETDEV_RX_QUEUE 4
  2262. +
  2263. +/* Number of queues per core */
  2264. +#define EDMA_NUM_TXQ_PER_CORE 4
  2265. +#define EDMA_NUM_RXQ_PER_CORE 2
  2266. +
  2267. +#define EDMA_TPD_EOP_SHIFT 31
  2268. +
  2269. +#define EDMA_PORT_ID_SHIFT 12
  2270. +#define EDMA_PORT_ID_MASK 0x7
  2271. +
  2272. +/* tpd word 3 bit 18-28 */
  2273. +#define EDMA_TPD_PORT_BITMAP_SHIFT 18
  2274. +
  2275. +#define EDMA_TPD_FROM_CPU_SHIFT 25
  2276. +
  2277. +#define EDMA_FROM_CPU_MASK 0x80
  2278. +#define EDMA_SKB_PRIORITY_MASK 0x38
  2279. +
  2280. +/* TX/RX descriptor ring count */
  2281. +/* should be a power of 2 */
  2282. +#define EDMA_RX_RING_SIZE 128
  2283. +#define EDMA_TX_RING_SIZE 128
  2284. +
  2285. +/* Flags used in paged/non paged mode */
  2286. +#define EDMA_RX_HEAD_BUFF_SIZE_JUMBO 256
  2287. +#define EDMA_RX_HEAD_BUFF_SIZE 1540
  2288. +
  2289. +/* MAX frame size supported by switch */
  2290. +#define EDMA_MAX_JUMBO_FRAME_SIZE 9216
  2291. +
  2292. +/* Configurations */
  2293. +#define EDMA_INTR_CLEAR_TYPE 0
  2294. +#define EDMA_INTR_SW_IDX_W_TYPE 0
  2295. +#define EDMA_FIFO_THRESH_TYPE 0
  2296. +#define EDMA_RSS_TYPE 0
  2297. +#define EDMA_RX_IMT 0x0020
  2298. +#define EDMA_TX_IMT 0x0050
  2299. +#define EDMA_TPD_BURST 5
  2300. +#define EDMA_TXF_BURST 0x100
  2301. +#define EDMA_RFD_BURST 8
  2302. +#define EDMA_RFD_THR 16
  2303. +#define EDMA_RFD_LTHR 0
  2304. +
  2305. +/* RX/TX per CPU based mask/shift */
  2306. +#define EDMA_TX_PER_CPU_MASK 0xF
  2307. +#define EDMA_RX_PER_CPU_MASK 0x3
  2308. +#define EDMA_TX_PER_CPU_MASK_SHIFT 0x2
  2309. +#define EDMA_RX_PER_CPU_MASK_SHIFT 0x1
  2310. +#define EDMA_TX_CPU_START_SHIFT 0x2
  2311. +#define EDMA_RX_CPU_START_SHIFT 0x1
  2312. +
  2313. +/* FLags used in transmit direction */
  2314. +#define EDMA_HW_CHECKSUM 0x00000001
  2315. +#define EDMA_VLAN_TX_TAG_INSERT_FLAG 0x00000002
  2316. +#define EDMA_VLAN_TX_TAG_INSERT_DEFAULT_FLAG 0x00000004
  2317. +
  2318. +#define EDMA_SW_DESC_FLAG_LAST 0x1
  2319. +#define EDMA_SW_DESC_FLAG_SKB_HEAD 0x2
  2320. +#define EDMA_SW_DESC_FLAG_SKB_FRAG 0x4
  2321. +#define EDMA_SW_DESC_FLAG_SKB_FRAGLIST 0x8
  2322. +#define EDMA_SW_DESC_FLAG_SKB_NONE 0x10
  2323. +#define EDMA_SW_DESC_FLAG_SKB_REUSE 0x20
  2324. +
  2325. +
  2326. +#define EDMA_MAX_SKB_FRAGS (MAX_SKB_FRAGS + 1)
  2327. +
  2328. +/* Ethtool specific list of EDMA supported features */
  2329. +#define EDMA_SUPPORTED_FEATURES (SUPPORTED_10baseT_Half \
  2330. + | SUPPORTED_10baseT_Full \
  2331. + | SUPPORTED_100baseT_Half \
  2332. + | SUPPORTED_100baseT_Full \
  2333. + | SUPPORTED_1000baseT_Full)
  2334. +
  2335. +/* Recevie side atheros Header */
  2336. +#define EDMA_RX_ATH_HDR_VERSION 0x2
  2337. +#define EDMA_RX_ATH_HDR_VERSION_SHIFT 14
  2338. +#define EDMA_RX_ATH_HDR_PRIORITY_SHIFT 11
  2339. +#define EDMA_RX_ATH_PORT_TYPE_SHIFT 6
  2340. +#define EDMA_RX_ATH_HDR_RSTP_PORT_TYPE 0x4
  2341. +
  2342. +/* Transmit side atheros Header */
  2343. +#define EDMA_TX_ATH_HDR_PORT_BITMAP_MASK 0x7F
  2344. +#define EDMA_TX_ATH_HDR_FROM_CPU_MASK 0x80
  2345. +#define EDMA_TX_ATH_HDR_FROM_CPU_SHIFT 7
  2346. +
  2347. +#define EDMA_TXQ_START_CORE0 8
  2348. +#define EDMA_TXQ_START_CORE1 12
  2349. +#define EDMA_TXQ_START_CORE2 0
  2350. +#define EDMA_TXQ_START_CORE3 4
  2351. +
  2352. +#define EDMA_TXQ_IRQ_MASK_CORE0 0x0F00
  2353. +#define EDMA_TXQ_IRQ_MASK_CORE1 0xF000
  2354. +#define EDMA_TXQ_IRQ_MASK_CORE2 0x000F
  2355. +#define EDMA_TXQ_IRQ_MASK_CORE3 0x00F0
  2356. +
  2357. +#define EDMA_ETH_HDR_LEN 12
  2358. +#define EDMA_ETH_TYPE_MASK 0xFFFF
  2359. +
  2360. +#define EDMA_RX_BUFFER_WRITE 16
  2361. +#define EDMA_RFD_AVAIL_THR 80
  2362. +
  2363. +#define EDMA_GMAC_NO_MDIO_PHY PHY_MAX_ADDR
  2364. +
  2365. +extern int ssdk_rfs_ipct_rule_set(__be32 ip_src, __be32 ip_dst,
  2366. + __be16 sport, __be16 dport,
  2367. + uint8_t proto, u16 loadbalance, bool action);
  2368. +struct edma_ethtool_statistics {
  2369. + u32 tx_q0_pkt;
  2370. + u32 tx_q1_pkt;
  2371. + u32 tx_q2_pkt;
  2372. + u32 tx_q3_pkt;
  2373. + u32 tx_q4_pkt;
  2374. + u32 tx_q5_pkt;
  2375. + u32 tx_q6_pkt;
  2376. + u32 tx_q7_pkt;
  2377. + u32 tx_q8_pkt;
  2378. + u32 tx_q9_pkt;
  2379. + u32 tx_q10_pkt;
  2380. + u32 tx_q11_pkt;
  2381. + u32 tx_q12_pkt;
  2382. + u32 tx_q13_pkt;
  2383. + u32 tx_q14_pkt;
  2384. + u32 tx_q15_pkt;
  2385. + u32 tx_q0_byte;
  2386. + u32 tx_q1_byte;
  2387. + u32 tx_q2_byte;
  2388. + u32 tx_q3_byte;
  2389. + u32 tx_q4_byte;
  2390. + u32 tx_q5_byte;
  2391. + u32 tx_q6_byte;
  2392. + u32 tx_q7_byte;
  2393. + u32 tx_q8_byte;
  2394. + u32 tx_q9_byte;
  2395. + u32 tx_q10_byte;
  2396. + u32 tx_q11_byte;
  2397. + u32 tx_q12_byte;
  2398. + u32 tx_q13_byte;
  2399. + u32 tx_q14_byte;
  2400. + u32 tx_q15_byte;
  2401. + u32 rx_q0_pkt;
  2402. + u32 rx_q1_pkt;
  2403. + u32 rx_q2_pkt;
  2404. + u32 rx_q3_pkt;
  2405. + u32 rx_q4_pkt;
  2406. + u32 rx_q5_pkt;
  2407. + u32 rx_q6_pkt;
  2408. + u32 rx_q7_pkt;
  2409. + u32 rx_q0_byte;
  2410. + u32 rx_q1_byte;
  2411. + u32 rx_q2_byte;
  2412. + u32 rx_q3_byte;
  2413. + u32 rx_q4_byte;
  2414. + u32 rx_q5_byte;
  2415. + u32 rx_q6_byte;
  2416. + u32 rx_q7_byte;
  2417. + u32 tx_desc_error;
  2418. +};
  2419. +
  2420. +struct edma_mdio_data {
  2421. + struct mii_bus *mii_bus;
  2422. + void __iomem *membase;
  2423. + int phy_irq[PHY_MAX_ADDR];
  2424. +};
  2425. +
  2426. +/* EDMA LINK state */
  2427. +enum edma_link_state {
  2428. + __EDMA_LINKUP, /* Indicate link is UP */
  2429. + __EDMA_LINKDOWN /* Indicate link is down */
  2430. +};
  2431. +
  2432. +/* EDMA GMAC state */
  2433. +enum edma_gmac_state {
  2434. + __EDMA_UP /* use to indicate GMAC is up */
  2435. +};
  2436. +
  2437. +/* edma transmit descriptor */
  2438. +struct edma_tx_desc {
  2439. + __le16 len; /* full packet including CRC */
  2440. + __le16 svlan_tag; /* vlan tag */
  2441. + __le32 word1; /* byte 4-7 */
  2442. + __le32 addr; /* address of buffer */
  2443. + __le32 word3; /* byte 12 */
  2444. +};
  2445. +
  2446. +/* edma receive return descriptor */
  2447. +struct edma_rx_return_desc {
  2448. + u16 rrd0;
  2449. + u16 rrd1;
  2450. + u16 rrd2;
  2451. + u16 rrd3;
  2452. + u16 rrd4;
  2453. + u16 rrd5;
  2454. + u16 rrd6;
  2455. + u16 rrd7;
  2456. +};
  2457. +
  2458. +/* RFD descriptor */
  2459. +struct edma_rx_free_desc {
  2460. + __le32 buffer_addr; /* buffer address */
  2461. +};
  2462. +
  2463. +/* edma hw specific data */
  2464. +struct edma_hw {
  2465. + u32 __iomem *hw_addr; /* inner register address */
  2466. + struct edma_adapter *adapter; /* netdevice adapter */
  2467. + u32 rx_intr_mask; /*rx interrupt mask */
  2468. + u32 tx_intr_mask; /* tx interrupt nask */
  2469. + u32 misc_intr_mask; /* misc interrupt mask */
  2470. + u32 wol_intr_mask; /* wake on lan interrupt mask */
  2471. + bool intr_clear_type; /* interrupt clear */
  2472. + bool intr_sw_idx_w; /* interrupt software index */
  2473. + u32 rx_head_buff_size; /* Rx buffer size */
  2474. + u8 rss_type; /* rss protocol type */
  2475. +};
  2476. +
  2477. +/* edma_sw_desc stores software descriptor
  2478. + * SW descriptor has 1:1 map with HW descriptor
  2479. + */
  2480. +struct edma_sw_desc {
  2481. + struct sk_buff *skb;
  2482. + dma_addr_t dma; /* dma address */
  2483. + u16 length; /* Tx/Rx buffer length */
  2484. + u32 flags;
  2485. +};
  2486. +
  2487. +/* per core related information */
  2488. +struct edma_per_cpu_queues_info {
  2489. + struct napi_struct napi; /* napi associated with the core */
  2490. + u32 tx_mask; /* tx interrupt mask */
  2491. + u32 rx_mask; /* rx interrupt mask */
  2492. + u32 tx_status; /* tx interrupt status */
  2493. + u32 rx_status; /* rx interrupt status */
  2494. + u32 tx_start; /* tx queue start */
  2495. + u32 rx_start; /* rx queue start */
  2496. + struct edma_common_info *edma_cinfo; /* edma common info */
  2497. +};
  2498. +
  2499. +/* edma specific common info */
  2500. +struct edma_common_info {
  2501. + struct edma_tx_desc_ring *tpd_ring[16]; /* 16 Tx queues */
  2502. + struct edma_rfd_desc_ring *rfd_ring[8]; /* 8 Rx queues */
  2503. + struct platform_device *pdev; /* device structure */
  2504. + struct net_device *netdev[EDMA_MAX_PORTID_SUPPORTED];
  2505. + struct net_device *portid_netdev_lookup_tbl[EDMA_MAX_PORTID_BITMAP_INDEX];
  2506. + struct ctl_table_header *edma_ctl_table_hdr;
  2507. + int num_gmac;
  2508. + struct edma_ethtool_statistics edma_ethstats; /* ethtool stats */
  2509. + int num_rx_queues; /* number of rx queue */
  2510. + u32 num_tx_queues; /* number of tx queue */
  2511. + u32 tx_irq[16]; /* number of tx irq */
  2512. + u32 rx_irq[8]; /* number of rx irq */
  2513. + u32 from_cpu; /* from CPU TPD field */
  2514. + u32 num_rxq_per_core; /* Rx queues per core */
  2515. + u32 num_txq_per_core; /* Tx queues per core */
  2516. + u16 tx_ring_count; /* Tx ring count */
  2517. + u16 rx_ring_count; /* Rx ring*/
  2518. + u16 rx_head_buffer_len; /* rx buffer length */
  2519. + u16 rx_page_buffer_len; /* rx buffer length */
  2520. + u32 page_mode; /* Jumbo frame supported flag */
  2521. + u32 fraglist_mode; /* fraglist supported flag */
  2522. + struct edma_hw hw; /* edma hw specific structure */
  2523. + struct edma_per_cpu_queues_info edma_percpu_info[CONFIG_NR_CPUS]; /* per cpu information */
  2524. + spinlock_t stats_lock; /* protect edma stats area for updation */
  2525. +};
  2526. +
  2527. +/* transimit packet descriptor (tpd) ring */
  2528. +struct edma_tx_desc_ring {
  2529. + struct netdev_queue *nq[EDMA_MAX_NETDEV_PER_QUEUE]; /* Linux queue index */
  2530. + struct net_device *netdev[EDMA_MAX_NETDEV_PER_QUEUE];
  2531. + /* Array of netdevs associated with the tpd ring */
  2532. + void *hw_desc; /* descriptor ring virtual address */
  2533. + struct edma_sw_desc *sw_desc; /* buffer associated with ring */
  2534. + int netdev_bmp; /* Bitmap for per-ring netdevs */
  2535. + u32 size; /* descriptor ring length in bytes */
  2536. + u16 count; /* number of descriptors in the ring */
  2537. + dma_addr_t dma; /* descriptor ring physical address */
  2538. + u16 sw_next_to_fill; /* next Tx descriptor to fill */
  2539. + u16 sw_next_to_clean; /* next Tx descriptor to clean */
  2540. +};
  2541. +
  2542. +/* receive free descriptor (rfd) ring */
  2543. +struct edma_rfd_desc_ring {
  2544. + void *hw_desc; /* descriptor ring virtual address */
  2545. + struct edma_sw_desc *sw_desc; /* buffer associated with ring */
  2546. + u16 size; /* bytes allocated to sw_desc */
  2547. + u16 count; /* number of descriptors in the ring */
  2548. + dma_addr_t dma; /* descriptor ring physical address */
  2549. + u16 sw_next_to_fill; /* next descriptor to fill */
  2550. + u16 sw_next_to_clean; /* next descriptor to clean */
  2551. +};
  2552. +
  2553. +/* edma_rfs_flter_node - rfs filter node in hash table */
  2554. +struct edma_rfs_filter_node {
  2555. + struct flow_keys keys;
  2556. + u32 flow_id; /* flow_id of filter provided by kernel */
  2557. + u16 filter_id; /* filter id of filter returned by adaptor */
  2558. + u16 rq_id; /* desired rq index */
  2559. + struct hlist_node node; /* edma rfs list node */
  2560. +};
  2561. +
  2562. +/* edma_rfs_flow_tbl - rfs flow table */
  2563. +struct edma_rfs_flow_table {
  2564. + u16 max_num_filter; /* Maximum number of filters edma supports */
  2565. + u16 hashtoclean; /* hash table index to clean next */
  2566. + int filter_available; /* Number of free filters available */
  2567. + struct hlist_head hlist_head[EDMA_RFS_FLOW_ENTRIES];
  2568. + spinlock_t rfs_ftab_lock;
  2569. + struct timer_list expire_rfs; /* timer function for edma_rps_may_expire_flow */
  2570. +};
  2571. +
  2572. +/* EDMA net device structure */
  2573. +struct edma_adapter {
  2574. + struct net_device *netdev; /* netdevice */
  2575. + struct platform_device *pdev; /* platform device */
  2576. + struct edma_common_info *edma_cinfo; /* edma common info */
  2577. + struct phy_device *phydev; /* Phy device */
  2578. + struct edma_rfs_flow_table rfs; /* edma rfs flow table */
  2579. + struct net_device_stats stats; /* netdev statistics */
  2580. + set_rfs_filter_callback_t set_rfs_rule;
  2581. + u32 flags;/* status flags */
  2582. + unsigned long state_flags; /* GMAC up/down flags */
  2583. + u32 forced_speed; /* link force speed */
  2584. + u32 forced_duplex; /* link force duplex */
  2585. + u32 link_state; /* phy link state */
  2586. + u32 phy_mdio_addr; /* PHY device address on MII interface */
  2587. + u32 poll_required; /* check if link polling is required */
  2588. + u32 tx_start_offset[CONFIG_NR_CPUS]; /* tx queue start */
  2589. + u32 default_vlan_tag; /* vlan tag */
  2590. + u32 dp_bitmap;
  2591. + uint8_t phy_id[MII_BUS_ID_SIZE + 3];
  2592. +};
  2593. +
  2594. +int edma_alloc_queues_tx(struct edma_common_info *edma_cinfo);
  2595. +int edma_alloc_queues_rx(struct edma_common_info *edma_cinfo);
  2596. +int edma_open(struct net_device *netdev);
  2597. +int edma_close(struct net_device *netdev);
  2598. +void edma_free_tx_resources(struct edma_common_info *edma_c_info);
  2599. +void edma_free_rx_resources(struct edma_common_info *edma_c_info);
  2600. +int edma_alloc_tx_rings(struct edma_common_info *edma_cinfo);
  2601. +int edma_alloc_rx_rings(struct edma_common_info *edma_cinfo);
  2602. +void edma_free_tx_rings(struct edma_common_info *edma_cinfo);
  2603. +void edma_free_rx_rings(struct edma_common_info *edma_cinfo);
  2604. +void edma_free_queues(struct edma_common_info *edma_cinfo);
  2605. +void edma_irq_disable(struct edma_common_info *edma_cinfo);
  2606. +int edma_reset(struct edma_common_info *edma_cinfo);
  2607. +int edma_poll(struct napi_struct *napi, int budget);
  2608. +netdev_tx_t edma_xmit(struct sk_buff *skb,
  2609. + struct net_device *netdev);
  2610. +int edma_configure(struct edma_common_info *edma_cinfo);
  2611. +void edma_irq_enable(struct edma_common_info *edma_cinfo);
  2612. +void edma_enable_tx_ctrl(struct edma_hw *hw);
  2613. +void edma_enable_rx_ctrl(struct edma_hw *hw);
  2614. +void edma_stop_rx_tx(struct edma_hw *hw);
  2615. +void edma_free_irqs(struct edma_adapter *adapter);
  2616. +irqreturn_t edma_interrupt(int irq, void *dev);
  2617. +void edma_write_reg(u16 reg_addr, u32 reg_value);
  2618. +void edma_read_reg(u16 reg_addr, volatile u32 *reg_value);
  2619. +struct net_device_stats *edma_get_stats(struct net_device *netdev);
  2620. +int edma_set_mac_addr(struct net_device *netdev, void *p);
  2621. +int edma_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
  2622. + u16 rxq, u32 flow_id);
  2623. +int edma_register_rfs_filter(struct net_device *netdev,
  2624. + set_rfs_filter_callback_t set_filter);
  2625. +void edma_flow_may_expire(unsigned long data);
  2626. +void edma_set_ethtool_ops(struct net_device *netdev);
  2627. +void edma_set_stp_rstp(bool tag);
  2628. +void edma_assign_ath_hdr_type(int tag);
  2629. +int edma_get_default_vlan_tag(struct net_device *netdev);
  2630. +void edma_adjust_link(struct net_device *netdev);
  2631. +int edma_fill_netdev(struct edma_common_info *edma_cinfo, int qid, int num, int txq_id);
  2632. +void edma_read_append_stats(struct edma_common_info *edma_cinfo);
  2633. +void edma_change_tx_coalesce(int usecs);
  2634. +void edma_change_rx_coalesce(int usecs);
  2635. +void edma_get_tx_rx_coalesce(u32 *reg_val);
  2636. +void edma_clear_irq_status(void);
  2637. +#endif /* _EDMA_H_ */
  2638. --- /dev/null
  2639. +++ b/drivers/net/ethernet/qualcomm/essedma/edma_axi.c
  2640. @@ -0,0 +1,1220 @@
  2641. +/*
  2642. + * Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
  2643. + *
  2644. + * Permission to use, copy, modify, and/or distribute this software for
  2645. + * any purpose with or without fee is hereby granted, provided that the
  2646. + * above copyright notice and this permission notice appear in all copies.
  2647. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  2648. + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  2649. + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  2650. + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  2651. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  2652. + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  2653. + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  2654. + */
  2655. +
  2656. +#include <linux/cpu_rmap.h>
  2657. +#include <linux/of.h>
  2658. +#include <linux/of_net.h>
  2659. +#include <linux/timer.h>
  2660. +#include "edma.h"
  2661. +#include "ess_edma.h"
  2662. +
  2663. +/* Weight round robin and virtual QID mask */
  2664. +#define EDMA_WRR_VID_SCTL_MASK 0xffff
  2665. +
  2666. +/* Weight round robin and virtual QID shift */
  2667. +#define EDMA_WRR_VID_SCTL_SHIFT 16
  2668. +
  2669. +char edma_axi_driver_name[] = "ess_edma";
  2670. +static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE |
  2671. + NETIF_MSG_LINK | NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP;
  2672. +
  2673. +static u32 edma_hw_addr;
  2674. +
  2675. +struct timer_list edma_stats_timer;
  2676. +
  2677. +char edma_tx_irq[16][64];
  2678. +char edma_rx_irq[8][64];
  2679. +struct net_device *edma_netdev[EDMA_MAX_PORTID_SUPPORTED];
  2680. +static u16 tx_start[4] = {EDMA_TXQ_START_CORE0, EDMA_TXQ_START_CORE1,
  2681. + EDMA_TXQ_START_CORE2, EDMA_TXQ_START_CORE3};
  2682. +static u32 tx_mask[4] = {EDMA_TXQ_IRQ_MASK_CORE0, EDMA_TXQ_IRQ_MASK_CORE1,
  2683. + EDMA_TXQ_IRQ_MASK_CORE2, EDMA_TXQ_IRQ_MASK_CORE3};
  2684. +
  2685. +static u32 edma_default_ltag __read_mostly = EDMA_LAN_DEFAULT_VLAN;
  2686. +static u32 edma_default_wtag __read_mostly = EDMA_WAN_DEFAULT_VLAN;
  2687. +static u32 edma_default_group1_vtag __read_mostly = EDMA_DEFAULT_GROUP1_VLAN;
  2688. +static u32 edma_default_group2_vtag __read_mostly = EDMA_DEFAULT_GROUP2_VLAN;
  2689. +static u32 edma_default_group3_vtag __read_mostly = EDMA_DEFAULT_GROUP3_VLAN;
  2690. +static u32 edma_default_group4_vtag __read_mostly = EDMA_DEFAULT_GROUP4_VLAN;
  2691. +static u32 edma_default_group5_vtag __read_mostly = EDMA_DEFAULT_GROUP5_VLAN;
  2692. +static u32 edma_rss_idt_val = EDMA_RSS_IDT_VALUE;
  2693. +static u32 edma_rss_idt_idx;
  2694. +
  2695. +static int edma_weight_assigned_to_q __read_mostly;
  2696. +static int edma_queue_to_virtual_q __read_mostly;
  2697. +static bool edma_enable_rstp __read_mostly;
  2698. +static int edma_athr_hdr_eth_type __read_mostly;
  2699. +
  2700. +static int page_mode;
  2701. +module_param(page_mode, int, 0);
  2702. +MODULE_PARM_DESC(page_mode, "enable page mode");
  2703. +
  2704. +static int overwrite_mode;
  2705. +module_param(overwrite_mode, int, 0);
  2706. +MODULE_PARM_DESC(overwrite_mode, "overwrite default page_mode setting");
  2707. +
  2708. +static int jumbo_mru = EDMA_RX_HEAD_BUFF_SIZE;
  2709. +module_param(jumbo_mru, int, 0);
  2710. +MODULE_PARM_DESC(jumbo_mru, "enable fraglist support");
  2711. +
  2712. +static int num_rxq = 4;
  2713. +module_param(num_rxq, int, 0);
  2714. +MODULE_PARM_DESC(num_rxq, "change the number of rx queues");
  2715. +
  2716. +void edma_write_reg(u16 reg_addr, u32 reg_value)
  2717. +{
  2718. + writel(reg_value, ((void __iomem *)(edma_hw_addr + reg_addr)));
  2719. +}
  2720. +
  2721. +void edma_read_reg(u16 reg_addr, volatile u32 *reg_value)
  2722. +{
  2723. + *reg_value = readl((void __iomem *)(edma_hw_addr + reg_addr));
  2724. +}
  2725. +
  2726. +/* edma_change_tx_coalesce()
  2727. + * change tx interrupt moderation timer
  2728. + */
  2729. +void edma_change_tx_coalesce(int usecs)
  2730. +{
  2731. + u32 reg_value;
  2732. +
  2733. + /* Here, we right shift the value from the user by 1, this is
  2734. + * done because IMT resolution timer is 2usecs. 1 count
  2735. + * of this register corresponds to 2 usecs.
  2736. + */
  2737. + edma_read_reg(EDMA_REG_IRQ_MODRT_TIMER_INIT, &reg_value);
  2738. + reg_value = ((reg_value & 0xffff) | ((usecs >> 1) << 16));
  2739. + edma_write_reg(EDMA_REG_IRQ_MODRT_TIMER_INIT, reg_value);
  2740. +}
  2741. +
  2742. +/* edma_change_rx_coalesce()
  2743. + * change rx interrupt moderation timer
  2744. + */
  2745. +void edma_change_rx_coalesce(int usecs)
  2746. +{
  2747. + u32 reg_value;
  2748. +
  2749. + /* Here, we right shift the value from the user by 1, this is
  2750. + * done because IMT resolution timer is 2usecs. 1 count
  2751. + * of this register corresponds to 2 usecs.
  2752. + */
  2753. + edma_read_reg(EDMA_REG_IRQ_MODRT_TIMER_INIT, &reg_value);
  2754. + reg_value = ((reg_value & 0xffff0000) | (usecs >> 1));
  2755. + edma_write_reg(EDMA_REG_IRQ_MODRT_TIMER_INIT, reg_value);
  2756. +}
  2757. +
  2758. +/* edma_get_tx_rx_coalesce()
  2759. + * Get tx/rx interrupt moderation value
  2760. + */
  2761. +void edma_get_tx_rx_coalesce(u32 *reg_val)
  2762. +{
  2763. + edma_read_reg(EDMA_REG_IRQ_MODRT_TIMER_INIT, reg_val);
  2764. +}
  2765. +
  2766. +void edma_read_append_stats(struct edma_common_info *edma_cinfo)
  2767. +{
  2768. + uint32_t *p;
  2769. + int i;
  2770. + u32 stat;
  2771. +
  2772. + spin_lock(&edma_cinfo->stats_lock);
  2773. + p = (uint32_t *)&(edma_cinfo->edma_ethstats);
  2774. +
  2775. + for (i = 0; i < EDMA_MAX_TRANSMIT_QUEUE; i++) {
  2776. + edma_read_reg(EDMA_REG_TX_STAT_PKT_Q(i), &stat);
  2777. + *p += stat;
  2778. + p++;
  2779. + }
  2780. +
  2781. + for (i = 0; i < EDMA_MAX_TRANSMIT_QUEUE; i++) {
  2782. + edma_read_reg(EDMA_REG_TX_STAT_BYTE_Q(i), &stat);
  2783. + *p += stat;
  2784. + p++;
  2785. + }
  2786. +
  2787. + for (i = 0; i < EDMA_MAX_RECEIVE_QUEUE; i++) {
  2788. + edma_read_reg(EDMA_REG_RX_STAT_PKT_Q(i), &stat);
  2789. + *p += stat;
  2790. + p++;
  2791. + }
  2792. +
  2793. + for (i = 0; i < EDMA_MAX_RECEIVE_QUEUE; i++) {
  2794. + edma_read_reg(EDMA_REG_RX_STAT_BYTE_Q(i), &stat);
  2795. + *p += stat;
  2796. + p++;
  2797. + }
  2798. +
  2799. + spin_unlock(&edma_cinfo->stats_lock);
  2800. +}
  2801. +
  2802. +static void edma_statistics_timer(unsigned long data)
  2803. +{
  2804. + struct edma_common_info *edma_cinfo = (struct edma_common_info *)data;
  2805. +
  2806. + edma_read_append_stats(edma_cinfo);
  2807. +
  2808. + mod_timer(&edma_stats_timer, jiffies + 1*HZ);
  2809. +}
  2810. +
  2811. +static int edma_enable_stp_rstp(struct ctl_table *table, int write,
  2812. + void __user *buffer, size_t *lenp,
  2813. + loff_t *ppos)
  2814. +{
  2815. + int ret;
  2816. +
  2817. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  2818. + if (write)
  2819. + edma_set_stp_rstp(edma_enable_rstp);
  2820. +
  2821. + return ret;
  2822. +}
  2823. +
  2824. +static int edma_ath_hdr_eth_type(struct ctl_table *table, int write,
  2825. + void __user *buffer, size_t *lenp,
  2826. + loff_t *ppos)
  2827. +{
  2828. + int ret;
  2829. +
  2830. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  2831. + if (write)
  2832. + edma_assign_ath_hdr_type(edma_athr_hdr_eth_type);
  2833. +
  2834. + return ret;
  2835. +}
  2836. +
  2837. +static int edma_change_default_lan_vlan(struct ctl_table *table, int write,
  2838. + void __user *buffer, size_t *lenp,
  2839. + loff_t *ppos)
  2840. +{
  2841. + struct edma_adapter *adapter;
  2842. + int ret;
  2843. +
  2844. + if (!edma_netdev[1]) {
  2845. + pr_err("Netdevice for default_lan does not exist\n");
  2846. + return -1;
  2847. + }
  2848. +
  2849. + adapter = netdev_priv(edma_netdev[1]);
  2850. +
  2851. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  2852. +
  2853. + if (write)
  2854. + adapter->default_vlan_tag = edma_default_ltag;
  2855. +
  2856. + return ret;
  2857. +}
  2858. +
  2859. +static int edma_change_default_wan_vlan(struct ctl_table *table, int write,
  2860. + void __user *buffer, size_t *lenp,
  2861. + loff_t *ppos)
  2862. +{
  2863. + struct edma_adapter *adapter;
  2864. + int ret;
  2865. +
  2866. + if (!edma_netdev[0]) {
  2867. + pr_err("Netdevice for default_wan does not exist\n");
  2868. + return -1;
  2869. + }
  2870. +
  2871. + adapter = netdev_priv(edma_netdev[0]);
  2872. +
  2873. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  2874. +
  2875. + if (write)
  2876. + adapter->default_vlan_tag = edma_default_wtag;
  2877. +
  2878. + return ret;
  2879. +}
  2880. +
  2881. +static int edma_change_group1_vtag(struct ctl_table *table, int write,
  2882. + void __user *buffer, size_t *lenp,
  2883. + loff_t *ppos)
  2884. +{
  2885. + struct edma_adapter *adapter;
  2886. + struct edma_common_info *edma_cinfo;
  2887. + int ret;
  2888. +
  2889. + if (!edma_netdev[0]) {
  2890. + pr_err("Netdevice for Group 1 does not exist\n");
  2891. + return -1;
  2892. + }
  2893. +
  2894. + adapter = netdev_priv(edma_netdev[0]);
  2895. + edma_cinfo = adapter->edma_cinfo;
  2896. +
  2897. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  2898. +
  2899. + if (write)
  2900. + adapter->default_vlan_tag = edma_default_group1_vtag;
  2901. +
  2902. + return ret;
  2903. +}
  2904. +
  2905. +static int edma_change_group2_vtag(struct ctl_table *table, int write,
  2906. + void __user *buffer, size_t *lenp,
  2907. + loff_t *ppos)
  2908. +{
  2909. + struct edma_adapter *adapter;
  2910. + struct edma_common_info *edma_cinfo;
  2911. + int ret;
  2912. +
  2913. + if (!edma_netdev[1]) {
  2914. + pr_err("Netdevice for Group 2 does not exist\n");
  2915. + return -1;
  2916. + }
  2917. +
  2918. + adapter = netdev_priv(edma_netdev[1]);
  2919. + edma_cinfo = adapter->edma_cinfo;
  2920. +
  2921. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  2922. +
  2923. + if (write)
  2924. + adapter->default_vlan_tag = edma_default_group2_vtag;
  2925. +
  2926. + return ret;
  2927. +}
  2928. +
  2929. +static int edma_change_group3_vtag(struct ctl_table *table, int write,
  2930. + void __user *buffer, size_t *lenp,
  2931. + loff_t *ppos)
  2932. +{
  2933. + struct edma_adapter *adapter;
  2934. + struct edma_common_info *edma_cinfo;
  2935. + int ret;
  2936. +
  2937. + if (!edma_netdev[2]) {
  2938. + pr_err("Netdevice for Group 3 does not exist\n");
  2939. + return -1;
  2940. + }
  2941. +
  2942. + adapter = netdev_priv(edma_netdev[2]);
  2943. + edma_cinfo = adapter->edma_cinfo;
  2944. +
  2945. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  2946. +
  2947. + if (write)
  2948. + adapter->default_vlan_tag = edma_default_group3_vtag;
  2949. +
  2950. + return ret;
  2951. +}
  2952. +
  2953. +static int edma_change_group4_vtag(struct ctl_table *table, int write,
  2954. + void __user *buffer, size_t *lenp,
  2955. + loff_t *ppos)
  2956. +{
  2957. + struct edma_adapter *adapter;
  2958. + struct edma_common_info *edma_cinfo;
  2959. + int ret;
  2960. +
  2961. + if (!edma_netdev[3]) {
  2962. + pr_err("Netdevice for Group 4 does not exist\n");
  2963. + return -1;
  2964. + }
  2965. +
  2966. + adapter = netdev_priv(edma_netdev[3]);
  2967. + edma_cinfo = adapter->edma_cinfo;
  2968. +
  2969. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  2970. +
  2971. + if (write)
  2972. + adapter->default_vlan_tag = edma_default_group4_vtag;
  2973. +
  2974. + return ret;
  2975. +}
  2976. +
  2977. +static int edma_change_group5_vtag(struct ctl_table *table, int write,
  2978. + void __user *buffer, size_t *lenp,
  2979. + loff_t *ppos)
  2980. +{
  2981. + struct edma_adapter *adapter;
  2982. + struct edma_common_info *edma_cinfo;
  2983. + int ret;
  2984. +
  2985. + if (!edma_netdev[4]) {
  2986. + pr_err("Netdevice for Group 5 does not exist\n");
  2987. + return -1;
  2988. + }
  2989. +
  2990. + adapter = netdev_priv(edma_netdev[4]);
  2991. + edma_cinfo = adapter->edma_cinfo;
  2992. +
  2993. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  2994. +
  2995. + if (write)
  2996. + adapter->default_vlan_tag = edma_default_group5_vtag;
  2997. +
  2998. + return ret;
  2999. +}
  3000. +
  3001. +static int edma_set_rss_idt_value(struct ctl_table *table, int write,
  3002. + void __user *buffer, size_t *lenp,
  3003. + loff_t *ppos)
  3004. +{
  3005. + int ret;
  3006. +
  3007. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  3008. + if (write && !ret)
  3009. + edma_write_reg(EDMA_REG_RSS_IDT(edma_rss_idt_idx),
  3010. + edma_rss_idt_val);
  3011. + return ret;
  3012. +}
  3013. +
  3014. +static int edma_set_rss_idt_idx(struct ctl_table *table, int write,
  3015. + void __user *buffer, size_t *lenp,
  3016. + loff_t *ppos)
  3017. +{
  3018. + int ret;
  3019. + u32 old_value = edma_rss_idt_idx;
  3020. +
  3021. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  3022. + if (!write || ret)
  3023. + return ret;
  3024. +
  3025. + if (edma_rss_idt_idx >= EDMA_NUM_IDT) {
  3026. + pr_err("Invalid RSS indirection table index %d\n",
  3027. + edma_rss_idt_idx);
  3028. + edma_rss_idt_idx = old_value;
  3029. + return -EINVAL;
  3030. + }
  3031. + return ret;
  3032. +}
  3033. +
  3034. +static int edma_weight_assigned_to_queues(struct ctl_table *table, int write,
  3035. + void __user *buffer, size_t *lenp,
  3036. + loff_t *ppos)
  3037. +{
  3038. + int ret, queue_id, weight;
  3039. + u32 reg_data, data, reg_addr;
  3040. +
  3041. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  3042. + if (write) {
  3043. + queue_id = edma_weight_assigned_to_q & EDMA_WRR_VID_SCTL_MASK;
  3044. + if (queue_id < 0 || queue_id > 15) {
  3045. + pr_err("queue_id not within desired range\n");
  3046. + return -EINVAL;
  3047. + }
  3048. +
  3049. + weight = edma_weight_assigned_to_q >> EDMA_WRR_VID_SCTL_SHIFT;
  3050. + if (weight < 0 || weight > 0xF) {
  3051. + pr_err("queue_id not within desired range\n");
  3052. + return -EINVAL;
  3053. + }
  3054. +
  3055. + data = weight << EDMA_WRR_SHIFT(queue_id);
  3056. +
  3057. + reg_addr = EDMA_REG_WRR_CTRL_Q0_Q3 + (queue_id & ~0x3);
  3058. + edma_read_reg(reg_addr, &reg_data);
  3059. + reg_data &= ~(1 << EDMA_WRR_SHIFT(queue_id));
  3060. + edma_write_reg(reg_addr, data | reg_data);
  3061. + }
  3062. +
  3063. + return ret;
  3064. +}
  3065. +
  3066. +static int edma_queue_to_virtual_queue_map(struct ctl_table *table, int write,
  3067. + void __user *buffer, size_t *lenp,
  3068. + loff_t *ppos)
  3069. +{
  3070. + int ret, queue_id, virtual_qid;
  3071. + u32 reg_data, data, reg_addr;
  3072. +
  3073. + ret = proc_dointvec(table, write, buffer, lenp, ppos);
  3074. + if (write) {
  3075. + queue_id = edma_queue_to_virtual_q & EDMA_WRR_VID_SCTL_MASK;
  3076. + if (queue_id < 0 || queue_id > 15) {
  3077. + pr_err("queue_id not within desired range\n");
  3078. + return -EINVAL;
  3079. + }
  3080. +
  3081. + virtual_qid = edma_queue_to_virtual_q >>
  3082. + EDMA_WRR_VID_SCTL_SHIFT;
  3083. + if (virtual_qid < 0 || virtual_qid > 8) {
  3084. + pr_err("queue_id not within desired range\n");
  3085. + return -EINVAL;
  3086. + }
  3087. +
  3088. + data = virtual_qid << EDMA_VQ_ID_SHIFT(queue_id);
  3089. +
  3090. + reg_addr = EDMA_REG_VQ_CTRL0 + (queue_id & ~0x3);
  3091. + edma_read_reg(reg_addr, &reg_data);
  3092. + reg_data &= ~(1 << EDMA_VQ_ID_SHIFT(queue_id));
  3093. + edma_write_reg(reg_addr, data | reg_data);
  3094. + }
  3095. +
  3096. + return ret;
  3097. +}
  3098. +
  3099. +static struct ctl_table edma_table[] = {
  3100. + {
  3101. + .procname = "default_lan_tag",
  3102. + .data = &edma_default_ltag,
  3103. + .maxlen = sizeof(int),
  3104. + .mode = 0644,
  3105. + .proc_handler = edma_change_default_lan_vlan
  3106. + },
  3107. + {
  3108. + .procname = "default_wan_tag",
  3109. + .data = &edma_default_wtag,
  3110. + .maxlen = sizeof(int),
  3111. + .mode = 0644,
  3112. + .proc_handler = edma_change_default_wan_vlan
  3113. + },
  3114. + {
  3115. + .procname = "weight_assigned_to_queues",
  3116. + .data = &edma_weight_assigned_to_q,
  3117. + .maxlen = sizeof(int),
  3118. + .mode = 0644,
  3119. + .proc_handler = edma_weight_assigned_to_queues
  3120. + },
  3121. + {
  3122. + .procname = "queue_to_virtual_queue_map",
  3123. + .data = &edma_queue_to_virtual_q,
  3124. + .maxlen = sizeof(int),
  3125. + .mode = 0644,
  3126. + .proc_handler = edma_queue_to_virtual_queue_map
  3127. + },
  3128. + {
  3129. + .procname = "enable_stp_rstp",
  3130. + .data = &edma_enable_rstp,
  3131. + .maxlen = sizeof(int),
  3132. + .mode = 0644,
  3133. + .proc_handler = edma_enable_stp_rstp
  3134. + },
  3135. + {
  3136. + .procname = "athr_hdr_eth_type",
  3137. + .data = &edma_athr_hdr_eth_type,
  3138. + .maxlen = sizeof(int),
  3139. + .mode = 0644,
  3140. + .proc_handler = edma_ath_hdr_eth_type
  3141. + },
  3142. + {
  3143. + .procname = "default_group1_vlan_tag",
  3144. + .data = &edma_default_group1_vtag,
  3145. + .maxlen = sizeof(int),
  3146. + .mode = 0644,
  3147. + .proc_handler = edma_change_group1_vtag
  3148. + },
  3149. + {
  3150. + .procname = "default_group2_vlan_tag",
  3151. + .data = &edma_default_group2_vtag,
  3152. + .maxlen = sizeof(int),
  3153. + .mode = 0644,
  3154. + .proc_handler = edma_change_group2_vtag
  3155. + },
  3156. + {
  3157. + .procname = "default_group3_vlan_tag",
  3158. + .data = &edma_default_group3_vtag,
  3159. + .maxlen = sizeof(int),
  3160. + .mode = 0644,
  3161. + .proc_handler = edma_change_group3_vtag
  3162. + },
  3163. + {
  3164. + .procname = "default_group4_vlan_tag",
  3165. + .data = &edma_default_group4_vtag,
  3166. + .maxlen = sizeof(int),
  3167. + .mode = 0644,
  3168. + .proc_handler = edma_change_group4_vtag
  3169. + },
  3170. + {
  3171. + .procname = "default_group5_vlan_tag",
  3172. + .data = &edma_default_group5_vtag,
  3173. + .maxlen = sizeof(int),
  3174. + .mode = 0644,
  3175. + .proc_handler = edma_change_group5_vtag
  3176. + },
  3177. + {
  3178. + .procname = "edma_rss_idt_value",
  3179. + .data = &edma_rss_idt_val,
  3180. + .maxlen = sizeof(int),
  3181. + .mode = 0644,
  3182. + .proc_handler = edma_set_rss_idt_value
  3183. + },
  3184. + {
  3185. + .procname = "edma_rss_idt_idx",
  3186. + .data = &edma_rss_idt_idx,
  3187. + .maxlen = sizeof(int),
  3188. + .mode = 0644,
  3189. + .proc_handler = edma_set_rss_idt_idx
  3190. + },
  3191. + {}
  3192. +};
  3193. +
  3194. +/* edma_axi_netdev_ops
  3195. + * Describe the operations supported by registered netdevices
  3196. + *
  3197. + * static const struct net_device_ops edma_axi_netdev_ops = {
  3198. + * .ndo_open = edma_open,
  3199. + * .ndo_stop = edma_close,
  3200. + * .ndo_start_xmit = edma_xmit_frame,
  3201. + * .ndo_set_mac_address = edma_set_mac_addr,
  3202. + * }
  3203. + */
  3204. +static const struct net_device_ops edma_axi_netdev_ops = {
  3205. + .ndo_open = edma_open,
  3206. + .ndo_stop = edma_close,
  3207. + .ndo_start_xmit = edma_xmit,
  3208. + .ndo_set_mac_address = edma_set_mac_addr,
  3209. +#ifdef CONFIG_RFS_ACCEL
  3210. + .ndo_rx_flow_steer = edma_rx_flow_steer,
  3211. + .ndo_register_rfs_filter = edma_register_rfs_filter,
  3212. + .ndo_get_default_vlan_tag = edma_get_default_vlan_tag,
  3213. +#endif
  3214. + .ndo_get_stats = edma_get_stats,
  3215. +};
  3216. +
  3217. +/* edma_axi_probe()
  3218. + * Initialise an adapter identified by a platform_device structure.
  3219. + *
  3220. + * The OS initialization, configuring of the adapter private structure,
  3221. + * and a hardware reset occur in the probe.
  3222. + */
  3223. +static int edma_axi_probe(struct platform_device *pdev)
  3224. +{
  3225. + struct edma_common_info *edma_cinfo;
  3226. + struct edma_hw *hw;
  3227. + struct edma_adapter *adapter[EDMA_MAX_PORTID_SUPPORTED];
  3228. + struct resource *res;
  3229. + struct device_node *np = pdev->dev.of_node;
  3230. + struct device_node *pnp;
  3231. + struct device_node *mdio_node = NULL;
  3232. + struct platform_device *mdio_plat = NULL;
  3233. + struct mii_bus *miibus = NULL;
  3234. + struct edma_mdio_data *mdio_data = NULL;
  3235. + int i, j, k, err = 0;
  3236. + int portid_bmp;
  3237. + int idx = 0, idx_mac = 0;
  3238. +
  3239. + if (CONFIG_NR_CPUS != EDMA_CPU_CORES_SUPPORTED) {
  3240. + dev_err(&pdev->dev, "Invalid CPU Cores\n");
  3241. + return -EINVAL;
  3242. + }
  3243. +
  3244. + if ((num_rxq != 4) && (num_rxq != 8)) {
  3245. + dev_err(&pdev->dev, "Invalid RX queue, edma probe failed\n");
  3246. + return -EINVAL;
  3247. + }
  3248. + edma_cinfo = kzalloc(sizeof(struct edma_common_info), GFP_KERNEL);
  3249. + if (!edma_cinfo) {
  3250. + err = -ENOMEM;
  3251. + goto err_alloc;
  3252. + }
  3253. +
  3254. + edma_cinfo->pdev = pdev;
  3255. +
  3256. + of_property_read_u32(np, "qcom,num_gmac", &edma_cinfo->num_gmac);
  3257. + if (edma_cinfo->num_gmac > EDMA_MAX_PORTID_SUPPORTED) {
  3258. + pr_err("Invalid DTSI Entry for qcom,num_gmac\n");
  3259. + err = -EINVAL;
  3260. + goto err_cinfo;
  3261. + }
  3262. +
  3263. + /* Initialize the netdev array before allocation
  3264. + * to avoid double free
  3265. + */
  3266. + for (i = 0 ; i < edma_cinfo->num_gmac ; i++)
  3267. + edma_netdev[i] = NULL;
  3268. +
  3269. + for (i = 0 ; i < edma_cinfo->num_gmac ; i++) {
  3270. + edma_netdev[i] = alloc_etherdev_mqs(sizeof(struct edma_adapter),
  3271. + EDMA_NETDEV_TX_QUEUE, EDMA_NETDEV_RX_QUEUE);
  3272. +
  3273. + if (!edma_netdev[i]) {
  3274. + dev_err(&pdev->dev,
  3275. + "net device alloc fails for index=%d\n", i);
  3276. + err = -ENODEV;
  3277. + goto err_ioremap;
  3278. + }
  3279. +
  3280. + SET_NETDEV_DEV(edma_netdev[i], &pdev->dev);
  3281. + platform_set_drvdata(pdev, edma_netdev[i]);
  3282. + edma_cinfo->netdev[i] = edma_netdev[i];
  3283. + }
  3284. +
  3285. + /* Fill ring details */
  3286. + edma_cinfo->num_tx_queues = EDMA_MAX_TRANSMIT_QUEUE;
  3287. + edma_cinfo->num_txq_per_core = (EDMA_MAX_TRANSMIT_QUEUE / 4);
  3288. + edma_cinfo->tx_ring_count = EDMA_TX_RING_SIZE;
  3289. +
  3290. + /* Update num rx queues based on module parameter */
  3291. + edma_cinfo->num_rx_queues = num_rxq;
  3292. + edma_cinfo->num_rxq_per_core = ((num_rxq == 4) ? 1 : 2);
  3293. +
  3294. + edma_cinfo->rx_ring_count = EDMA_RX_RING_SIZE;
  3295. +
  3296. + hw = &edma_cinfo->hw;
  3297. +
  3298. + /* Fill HW defaults */
  3299. + hw->tx_intr_mask = EDMA_TX_IMR_NORMAL_MASK;
  3300. + hw->rx_intr_mask = EDMA_RX_IMR_NORMAL_MASK;
  3301. +
  3302. + of_property_read_u32(np, "qcom,page-mode", &edma_cinfo->page_mode);
  3303. + of_property_read_u32(np, "qcom,rx_head_buf_size",
  3304. + &hw->rx_head_buff_size);
  3305. +
  3306. + if (overwrite_mode) {
  3307. + dev_info(&pdev->dev, "page mode overwritten");
  3308. + edma_cinfo->page_mode = page_mode;
  3309. + }
  3310. +
  3311. + if (jumbo_mru)
  3312. + edma_cinfo->fraglist_mode = 1;
  3313. +
  3314. + if (edma_cinfo->page_mode)
  3315. + hw->rx_head_buff_size = EDMA_RX_HEAD_BUFF_SIZE_JUMBO;
  3316. + else if (edma_cinfo->fraglist_mode)
  3317. + hw->rx_head_buff_size = jumbo_mru;
  3318. + else if (!hw->rx_head_buff_size)
  3319. + hw->rx_head_buff_size = EDMA_RX_HEAD_BUFF_SIZE;
  3320. +
  3321. + hw->misc_intr_mask = 0;
  3322. + hw->wol_intr_mask = 0;
  3323. +
  3324. + hw->intr_clear_type = EDMA_INTR_CLEAR_TYPE;
  3325. + hw->intr_sw_idx_w = EDMA_INTR_SW_IDX_W_TYPE;
  3326. +
  3327. + /* configure RSS type to the different protocol that can be
  3328. + * supported
  3329. + */
  3330. + hw->rss_type = EDMA_RSS_TYPE_IPV4TCP | EDMA_RSS_TYPE_IPV6_TCP |
  3331. + EDMA_RSS_TYPE_IPV4_UDP | EDMA_RSS_TYPE_IPV6UDP |
  3332. + EDMA_RSS_TYPE_IPV4 | EDMA_RSS_TYPE_IPV6;
  3333. +
  3334. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  3335. +
  3336. + edma_cinfo->hw.hw_addr = devm_ioremap_resource(&pdev->dev, res);
  3337. + if (IS_ERR(edma_cinfo->hw.hw_addr)) {
  3338. + err = PTR_ERR(edma_cinfo->hw.hw_addr);
  3339. + goto err_ioremap;
  3340. + }
  3341. +
  3342. + edma_hw_addr = (u32)edma_cinfo->hw.hw_addr;
  3343. +
  3344. + /* Parse tx queue interrupt number from device tree */
  3345. + for (i = 0; i < edma_cinfo->num_tx_queues; i++)
  3346. + edma_cinfo->tx_irq[i] = platform_get_irq(pdev, i);
  3347. +
  3348. + /* Parse rx queue interrupt number from device tree
  3349. + * Here we are setting j to point to the point where we
  3350. + * left tx interrupt parsing(i.e 16) and run run the loop
  3351. + * from 0 to 7 to parse rx interrupt number.
  3352. + */
  3353. + for (i = 0, j = edma_cinfo->num_tx_queues, k = 0;
  3354. + i < edma_cinfo->num_rx_queues; i++) {
  3355. + edma_cinfo->rx_irq[k] = platform_get_irq(pdev, j);
  3356. + k += ((num_rxq == 4) ? 2 : 1);
  3357. + j += ((num_rxq == 4) ? 2 : 1);
  3358. + }
  3359. +
  3360. + edma_cinfo->rx_head_buffer_len = edma_cinfo->hw.rx_head_buff_size;
  3361. + edma_cinfo->rx_page_buffer_len = PAGE_SIZE;
  3362. +
  3363. + err = edma_alloc_queues_tx(edma_cinfo);
  3364. + if (err) {
  3365. + dev_err(&pdev->dev, "Allocation of TX queue failed\n");
  3366. + goto err_tx_qinit;
  3367. + }
  3368. +
  3369. + err = edma_alloc_queues_rx(edma_cinfo);
  3370. + if (err) {
  3371. + dev_err(&pdev->dev, "Allocation of RX queue failed\n");
  3372. + goto err_rx_qinit;
  3373. + }
  3374. +
  3375. + err = edma_alloc_tx_rings(edma_cinfo);
  3376. + if (err) {
  3377. + dev_err(&pdev->dev, "Allocation of TX resources failed\n");
  3378. + goto err_tx_rinit;
  3379. + }
  3380. +
  3381. + err = edma_alloc_rx_rings(edma_cinfo);
  3382. + if (err) {
  3383. + dev_err(&pdev->dev, "Allocation of RX resources failed\n");
  3384. + goto err_rx_rinit;
  3385. + }
  3386. +
  3387. + /* Initialize netdev and netdev bitmap for transmit descriptor rings */
  3388. + for (i = 0; i < edma_cinfo->num_tx_queues; i++) {
  3389. + struct edma_tx_desc_ring *etdr = edma_cinfo->tpd_ring[i];
  3390. + int j;
  3391. +
  3392. + etdr->netdev_bmp = 0;
  3393. + for (j = 0; j < EDMA_MAX_NETDEV_PER_QUEUE; j++) {
  3394. + etdr->netdev[j] = NULL;
  3395. + etdr->nq[j] = NULL;
  3396. + }
  3397. + }
  3398. +
  3399. + if (of_property_read_bool(np, "qcom,mdio_supported")) {
  3400. + mdio_node = of_find_compatible_node(NULL, NULL,
  3401. + "qcom,ipq4019-mdio");
  3402. + if (!mdio_node) {
  3403. + dev_err(&pdev->dev, "cannot find mdio node by phandle");
  3404. + err = -EIO;
  3405. + goto err_mdiobus_init_fail;
  3406. + }
  3407. +
  3408. + mdio_plat = of_find_device_by_node(mdio_node);
  3409. + if (!mdio_plat) {
  3410. + dev_err(&pdev->dev,
  3411. + "cannot find platform device from mdio node");
  3412. + of_node_put(mdio_node);
  3413. + err = -EIO;
  3414. + goto err_mdiobus_init_fail;
  3415. + }
  3416. +
  3417. + mdio_data = dev_get_drvdata(&mdio_plat->dev);
  3418. + if (!mdio_data) {
  3419. + dev_err(&pdev->dev,
  3420. + "cannot get mii bus reference from device data");
  3421. + of_node_put(mdio_node);
  3422. + err = -EIO;
  3423. + goto err_mdiobus_init_fail;
  3424. + }
  3425. +
  3426. + miibus = mdio_data->mii_bus;
  3427. + }
  3428. +
  3429. + for_each_available_child_of_node(np, pnp) {
  3430. + const char *mac_addr;
  3431. +
  3432. + /* this check is needed if parent and daughter dts have
  3433. + * different number of gmac nodes
  3434. + */
  3435. + if (idx_mac == edma_cinfo->num_gmac) {
  3436. + of_node_put(np);
  3437. + break;
  3438. + }
  3439. +
  3440. + mac_addr = of_get_mac_address(pnp);
  3441. + if (mac_addr)
  3442. + memcpy(edma_netdev[idx_mac]->dev_addr, mac_addr, ETH_ALEN);
  3443. +
  3444. + idx_mac++;
  3445. + }
  3446. +
  3447. + /* Populate the adapter structure register the netdevice */
  3448. + for (i = 0; i < edma_cinfo->num_gmac; i++) {
  3449. + int k, m;
  3450. +
  3451. + adapter[i] = netdev_priv(edma_netdev[i]);
  3452. + adapter[i]->netdev = edma_netdev[i];
  3453. + adapter[i]->pdev = pdev;
  3454. + for (j = 0; j < CONFIG_NR_CPUS; j++) {
  3455. + m = i % 2;
  3456. + adapter[i]->tx_start_offset[j] =
  3457. + ((j << EDMA_TX_CPU_START_SHIFT) + (m << 1));
  3458. + /* Share the queues with available net-devices.
  3459. + * For instance , with 5 net-devices
  3460. + * eth0/eth2/eth4 will share q0,q1,q4,q5,q8,q9,q12,q13
  3461. + * and eth1/eth3 will get the remaining.
  3462. + */
  3463. + for (k = adapter[i]->tx_start_offset[j]; k <
  3464. + (adapter[i]->tx_start_offset[j] + 2); k++) {
  3465. + if (edma_fill_netdev(edma_cinfo, k, i, j)) {
  3466. + pr_err("Netdev overflow Error\n");
  3467. + goto err_register;
  3468. + }
  3469. + }
  3470. + }
  3471. +
  3472. + adapter[i]->edma_cinfo = edma_cinfo;
  3473. + edma_netdev[i]->netdev_ops = &edma_axi_netdev_ops;
  3474. + edma_netdev[i]->max_mtu = 9000;
  3475. + edma_netdev[i]->features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM
  3476. + | NETIF_F_HW_VLAN_CTAG_TX
  3477. + | NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_SG |
  3478. + NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GRO;
  3479. + edma_netdev[i]->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM |
  3480. + NETIF_F_HW_VLAN_CTAG_RX
  3481. + | NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 |
  3482. + NETIF_F_GRO;
  3483. + edma_netdev[i]->vlan_features = NETIF_F_HW_CSUM | NETIF_F_SG |
  3484. + NETIF_F_TSO | NETIF_F_TSO6 |
  3485. + NETIF_F_GRO;
  3486. + edma_netdev[i]->wanted_features = NETIF_F_HW_CSUM | NETIF_F_SG |
  3487. + NETIF_F_TSO | NETIF_F_TSO6 |
  3488. + NETIF_F_GRO;
  3489. +
  3490. +#ifdef CONFIG_RFS_ACCEL
  3491. + edma_netdev[i]->features |= NETIF_F_RXHASH | NETIF_F_NTUPLE;
  3492. + edma_netdev[i]->hw_features |= NETIF_F_RXHASH | NETIF_F_NTUPLE;
  3493. + edma_netdev[i]->vlan_features |= NETIF_F_RXHASH | NETIF_F_NTUPLE;
  3494. + edma_netdev[i]->wanted_features |= NETIF_F_RXHASH | NETIF_F_NTUPLE;
  3495. +#endif
  3496. + edma_set_ethtool_ops(edma_netdev[i]);
  3497. +
  3498. + /* This just fill in some default MAC address
  3499. + */
  3500. + if (!is_valid_ether_addr(edma_netdev[i]->dev_addr)) {
  3501. + random_ether_addr(edma_netdev[i]->dev_addr);
  3502. + pr_info("EDMA using MAC@ - using");
  3503. + pr_info("%02x:%02x:%02x:%02x:%02x:%02x\n",
  3504. + *(edma_netdev[i]->dev_addr),
  3505. + *(edma_netdev[i]->dev_addr + 1),
  3506. + *(edma_netdev[i]->dev_addr + 2),
  3507. + *(edma_netdev[i]->dev_addr + 3),
  3508. + *(edma_netdev[i]->dev_addr + 4),
  3509. + *(edma_netdev[i]->dev_addr + 5));
  3510. + }
  3511. +
  3512. + err = register_netdev(edma_netdev[i]);
  3513. + if (err)
  3514. + goto err_register;
  3515. +
  3516. + /* carrier off reporting is important to
  3517. + * ethtool even BEFORE open
  3518. + */
  3519. + netif_carrier_off(edma_netdev[i]);
  3520. +
  3521. + /* Allocate reverse irq cpu mapping structure for
  3522. + * receive queues
  3523. + */
  3524. +#ifdef CONFIG_RFS_ACCEL
  3525. + edma_netdev[i]->rx_cpu_rmap =
  3526. + alloc_irq_cpu_rmap(EDMA_NETDEV_RX_QUEUE);
  3527. + if (!edma_netdev[i]->rx_cpu_rmap) {
  3528. + err = -ENOMEM;
  3529. + goto err_rmap_alloc_fail;
  3530. + }
  3531. +#endif
  3532. + }
  3533. +
  3534. + for (i = 0; i < EDMA_MAX_PORTID_BITMAP_INDEX; i++)
  3535. + edma_cinfo->portid_netdev_lookup_tbl[i] = NULL;
  3536. +
  3537. + for_each_available_child_of_node(np, pnp) {
  3538. + const uint32_t *vlan_tag = NULL;
  3539. + int len;
  3540. +
  3541. + /* this check is needed if parent and daughter dts have
  3542. + * different number of gmac nodes
  3543. + */
  3544. + if (idx == edma_cinfo->num_gmac)
  3545. + break;
  3546. +
  3547. + /* Populate port-id to netdev lookup table */
  3548. + vlan_tag = of_get_property(pnp, "vlan_tag", &len);
  3549. + if (!vlan_tag) {
  3550. + pr_err("Vlan tag parsing Failed.\n");
  3551. + goto err_rmap_alloc_fail;
  3552. + }
  3553. +
  3554. + adapter[idx]->default_vlan_tag = of_read_number(vlan_tag, 1);
  3555. + vlan_tag++;
  3556. + portid_bmp = of_read_number(vlan_tag, 1);
  3557. + adapter[idx]->dp_bitmap = portid_bmp;
  3558. +
  3559. + portid_bmp = portid_bmp >> 1; /* We ignore CPU Port bit 0 */
  3560. + while (portid_bmp) {
  3561. + int port_bit = ffs(portid_bmp);
  3562. +
  3563. + if (port_bit > EDMA_MAX_PORTID_SUPPORTED)
  3564. + goto err_rmap_alloc_fail;
  3565. + edma_cinfo->portid_netdev_lookup_tbl[port_bit] =
  3566. + edma_netdev[idx];
  3567. + portid_bmp &= ~(1 << (port_bit - 1));
  3568. + }
  3569. +
  3570. + if (!of_property_read_u32(pnp, "qcom,poll_required",
  3571. + &adapter[idx]->poll_required)) {
  3572. + if (adapter[idx]->poll_required) {
  3573. + of_property_read_u32(pnp, "qcom,phy_mdio_addr",
  3574. + &adapter[idx]->phy_mdio_addr);
  3575. + of_property_read_u32(pnp, "qcom,forced_speed",
  3576. + &adapter[idx]->forced_speed);
  3577. + of_property_read_u32(pnp, "qcom,forced_duplex",
  3578. + &adapter[idx]->forced_duplex);
  3579. +
  3580. + /* create a phyid using MDIO bus id
  3581. + * and MDIO bus address
  3582. + */
  3583. + snprintf(adapter[idx]->phy_id,
  3584. + MII_BUS_ID_SIZE + 3, PHY_ID_FMT,
  3585. + miibus->id,
  3586. + adapter[idx]->phy_mdio_addr);
  3587. + }
  3588. + } else {
  3589. + adapter[idx]->poll_required = 0;
  3590. + adapter[idx]->forced_speed = SPEED_1000;
  3591. + adapter[idx]->forced_duplex = DUPLEX_FULL;
  3592. + }
  3593. +
  3594. + idx++;
  3595. + }
  3596. +
  3597. + edma_cinfo->edma_ctl_table_hdr = register_net_sysctl(&init_net,
  3598. + "net/edma",
  3599. + edma_table);
  3600. + if (!edma_cinfo->edma_ctl_table_hdr) {
  3601. + dev_err(&pdev->dev, "edma sysctl table hdr not registered\n");
  3602. + goto err_unregister_sysctl_tbl;
  3603. + }
  3604. +
  3605. + /* Disable all 16 Tx and 8 rx irqs */
  3606. + edma_irq_disable(edma_cinfo);
  3607. +
  3608. + err = edma_reset(edma_cinfo);
  3609. + if (err) {
  3610. + err = -EIO;
  3611. + goto err_reset;
  3612. + }
  3613. +
  3614. + /* populate per_core_info, do a napi_Add, request 16 TX irqs,
  3615. + * 8 RX irqs, do a napi enable
  3616. + */
  3617. + for (i = 0; i < CONFIG_NR_CPUS; i++) {
  3618. + u8 rx_start;
  3619. +
  3620. + edma_cinfo->edma_percpu_info[i].napi.state = 0;
  3621. +
  3622. + netif_napi_add(edma_netdev[0],
  3623. + &edma_cinfo->edma_percpu_info[i].napi,
  3624. + edma_poll, 64);
  3625. + napi_enable(&edma_cinfo->edma_percpu_info[i].napi);
  3626. + edma_cinfo->edma_percpu_info[i].tx_mask = tx_mask[i];
  3627. + edma_cinfo->edma_percpu_info[i].rx_mask = EDMA_RX_PER_CPU_MASK
  3628. + << (i << EDMA_RX_PER_CPU_MASK_SHIFT);
  3629. + edma_cinfo->edma_percpu_info[i].tx_start = tx_start[i];
  3630. + edma_cinfo->edma_percpu_info[i].rx_start =
  3631. + i << EDMA_RX_CPU_START_SHIFT;
  3632. + rx_start = i << EDMA_RX_CPU_START_SHIFT;
  3633. + edma_cinfo->edma_percpu_info[i].tx_status = 0;
  3634. + edma_cinfo->edma_percpu_info[i].rx_status = 0;
  3635. + edma_cinfo->edma_percpu_info[i].edma_cinfo = edma_cinfo;
  3636. +
  3637. + /* Request irq per core */
  3638. + for (j = edma_cinfo->edma_percpu_info[i].tx_start;
  3639. + j < tx_start[i] + 4; j++) {
  3640. + sprintf(&edma_tx_irq[j][0], "edma_eth_tx%d", j);
  3641. + err = request_irq(edma_cinfo->tx_irq[j],
  3642. + edma_interrupt,
  3643. + 0,
  3644. + &edma_tx_irq[j][0],
  3645. + &edma_cinfo->edma_percpu_info[i]);
  3646. + if (err)
  3647. + goto err_reset;
  3648. + }
  3649. +
  3650. + for (j = edma_cinfo->edma_percpu_info[i].rx_start;
  3651. + j < (rx_start +
  3652. + ((edma_cinfo->num_rx_queues == 4) ? 1 : 2));
  3653. + j++) {
  3654. + sprintf(&edma_rx_irq[j][0], "edma_eth_rx%d", j);
  3655. + err = request_irq(edma_cinfo->rx_irq[j],
  3656. + edma_interrupt,
  3657. + 0,
  3658. + &edma_rx_irq[j][0],
  3659. + &edma_cinfo->edma_percpu_info[i]);
  3660. + if (err)
  3661. + goto err_reset;
  3662. + }
  3663. +
  3664. +#ifdef CONFIG_RFS_ACCEL
  3665. + for (j = edma_cinfo->edma_percpu_info[i].rx_start;
  3666. + j < rx_start + 2; j += 2) {
  3667. + err = irq_cpu_rmap_add(edma_netdev[0]->rx_cpu_rmap,
  3668. + edma_cinfo->rx_irq[j]);
  3669. + if (err)
  3670. + goto err_rmap_add_fail;
  3671. + }
  3672. +#endif
  3673. + }
  3674. +
  3675. + /* Used to clear interrupt status, allocate rx buffer,
  3676. + * configure edma descriptors registers
  3677. + */
  3678. + err = edma_configure(edma_cinfo);
  3679. + if (err) {
  3680. + err = -EIO;
  3681. + goto err_configure;
  3682. + }
  3683. +
  3684. + /* Configure RSS indirection table.
  3685. + * 128 hash will be configured in the following
  3686. + * pattern: hash{0,1,2,3} = {Q0,Q2,Q4,Q6} respectively
  3687. + * and so on
  3688. + */
  3689. + for (i = 0; i < EDMA_NUM_IDT; i++)
  3690. + edma_write_reg(EDMA_REG_RSS_IDT(i), EDMA_RSS_IDT_VALUE);
  3691. +
  3692. + /* Configure load balance mapping table.
  3693. + * 4 table entry will be configured according to the
  3694. + * following pattern: load_balance{0,1,2,3} = {Q0,Q1,Q3,Q4}
  3695. + * respectively.
  3696. + */
  3697. + edma_write_reg(EDMA_REG_LB_RING, EDMA_LB_REG_VALUE);
  3698. +
  3699. + /* Configure Virtual queue for Tx rings
  3700. + * User can also change this value runtime through
  3701. + * a sysctl
  3702. + */
  3703. + edma_write_reg(EDMA_REG_VQ_CTRL0, EDMA_VQ_REG_VALUE);
  3704. + edma_write_reg(EDMA_REG_VQ_CTRL1, EDMA_VQ_REG_VALUE);
  3705. +
  3706. + /* Configure Max AXI Burst write size to 128 bytes*/
  3707. + edma_write_reg(EDMA_REG_AXIW_CTRL_MAXWRSIZE,
  3708. + EDMA_AXIW_MAXWRSIZE_VALUE);
  3709. +
  3710. + /* Enable All 16 tx and 8 rx irq mask */
  3711. + edma_irq_enable(edma_cinfo);
  3712. + edma_enable_tx_ctrl(&edma_cinfo->hw);
  3713. + edma_enable_rx_ctrl(&edma_cinfo->hw);
  3714. +
  3715. + for (i = 0; i < edma_cinfo->num_gmac; i++) {
  3716. + if (adapter[i]->poll_required) {
  3717. + adapter[i]->phydev =
  3718. + phy_connect(edma_netdev[i],
  3719. + (const char *)adapter[i]->phy_id,
  3720. + &edma_adjust_link,
  3721. + PHY_INTERFACE_MODE_SGMII);
  3722. + if (IS_ERR(adapter[i]->phydev)) {
  3723. + dev_dbg(&pdev->dev, "PHY attach FAIL");
  3724. + err = -EIO;
  3725. + goto edma_phy_attach_fail;
  3726. + } else {
  3727. + adapter[i]->phydev->advertising |=
  3728. + ADVERTISED_Pause |
  3729. + ADVERTISED_Asym_Pause;
  3730. + adapter[i]->phydev->supported |=
  3731. + SUPPORTED_Pause |
  3732. + SUPPORTED_Asym_Pause;
  3733. + }
  3734. + } else {
  3735. + adapter[i]->phydev = NULL;
  3736. + }
  3737. + }
  3738. +
  3739. + spin_lock_init(&edma_cinfo->stats_lock);
  3740. +
  3741. + init_timer(&edma_stats_timer);
  3742. + edma_stats_timer.expires = jiffies + 1*HZ;
  3743. + edma_stats_timer.data = (unsigned long)edma_cinfo;
  3744. + edma_stats_timer.function = edma_statistics_timer; /* timer handler */
  3745. + add_timer(&edma_stats_timer);
  3746. +
  3747. + return 0;
  3748. +
  3749. +edma_phy_attach_fail:
  3750. + miibus = NULL;
  3751. +err_configure:
  3752. +#ifdef CONFIG_RFS_ACCEL
  3753. + for (i = 0; i < edma_cinfo->num_gmac; i++) {
  3754. + free_irq_cpu_rmap(adapter[i]->netdev->rx_cpu_rmap);
  3755. + adapter[i]->netdev->rx_cpu_rmap = NULL;
  3756. + }
  3757. +#endif
  3758. +err_rmap_add_fail:
  3759. + edma_free_irqs(adapter[0]);
  3760. + for (i = 0; i < CONFIG_NR_CPUS; i++)
  3761. + napi_disable(&edma_cinfo->edma_percpu_info[i].napi);
  3762. +err_reset:
  3763. +err_unregister_sysctl_tbl:
  3764. +err_rmap_alloc_fail:
  3765. + for (i = 0; i < edma_cinfo->num_gmac; i++)
  3766. + unregister_netdev(edma_netdev[i]);
  3767. +err_register:
  3768. +err_mdiobus_init_fail:
  3769. + edma_free_rx_rings(edma_cinfo);
  3770. +err_rx_rinit:
  3771. + edma_free_tx_rings(edma_cinfo);
  3772. +err_tx_rinit:
  3773. + edma_free_queues(edma_cinfo);
  3774. +err_rx_qinit:
  3775. +err_tx_qinit:
  3776. + iounmap(edma_cinfo->hw.hw_addr);
  3777. +err_ioremap:
  3778. + for (i = 0; i < edma_cinfo->num_gmac; i++) {
  3779. + if (edma_netdev[i])
  3780. + free_netdev(edma_netdev[i]);
  3781. + }
  3782. +err_cinfo:
  3783. + kfree(edma_cinfo);
  3784. +err_alloc:
  3785. + return err;
  3786. +}
  3787. +
  3788. +/* edma_axi_remove()
  3789. + * Device Removal Routine
  3790. + *
  3791. + * edma_axi_remove is called by the platform subsystem to alert the driver
  3792. + * that it should release a platform device.
  3793. + */
  3794. +static int edma_axi_remove(struct platform_device *pdev)
  3795. +{
  3796. + struct edma_adapter *adapter = netdev_priv(edma_netdev[0]);
  3797. + struct edma_common_info *edma_cinfo = adapter->edma_cinfo;
  3798. + struct edma_hw *hw = &edma_cinfo->hw;
  3799. + int i;
  3800. +
  3801. + for (i = 0; i < edma_cinfo->num_gmac; i++)
  3802. + unregister_netdev(edma_netdev[i]);
  3803. +
  3804. + edma_stop_rx_tx(hw);
  3805. + for (i = 0; i < CONFIG_NR_CPUS; i++)
  3806. + napi_disable(&edma_cinfo->edma_percpu_info[i].napi);
  3807. +
  3808. + edma_irq_disable(edma_cinfo);
  3809. + edma_write_reg(EDMA_REG_RX_ISR, 0xff);
  3810. + edma_write_reg(EDMA_REG_TX_ISR, 0xffff);
  3811. +#ifdef CONFIG_RFS_ACCEL
  3812. + for (i = 0; i < edma_cinfo->num_gmac; i++) {
  3813. + free_irq_cpu_rmap(edma_netdev[i]->rx_cpu_rmap);
  3814. + edma_netdev[i]->rx_cpu_rmap = NULL;
  3815. + }
  3816. +#endif
  3817. +
  3818. + for (i = 0; i < edma_cinfo->num_gmac; i++) {
  3819. + struct edma_adapter *adapter = netdev_priv(edma_netdev[i]);
  3820. +
  3821. + if (adapter->phydev)
  3822. + phy_disconnect(adapter->phydev);
  3823. + }
  3824. +
  3825. + del_timer_sync(&edma_stats_timer);
  3826. + edma_free_irqs(adapter);
  3827. + unregister_net_sysctl_table(edma_cinfo->edma_ctl_table_hdr);
  3828. + edma_free_tx_resources(edma_cinfo);
  3829. + edma_free_rx_resources(edma_cinfo);
  3830. + edma_free_tx_rings(edma_cinfo);
  3831. + edma_free_rx_rings(edma_cinfo);
  3832. + edma_free_queues(edma_cinfo);
  3833. + for (i = 0; i < edma_cinfo->num_gmac; i++)
  3834. + free_netdev(edma_netdev[i]);
  3835. +
  3836. + kfree(edma_cinfo);
  3837. +
  3838. + return 0;
  3839. +}
  3840. +
  3841. +static const struct of_device_id edma_of_mtable[] = {
  3842. + {.compatible = "qcom,ess-edma" },
  3843. + {}
  3844. +};
  3845. +MODULE_DEVICE_TABLE(of, edma_of_mtable);
  3846. +
  3847. +static struct platform_driver edma_axi_driver = {
  3848. + .driver = {
  3849. + .name = edma_axi_driver_name,
  3850. + .of_match_table = edma_of_mtable,
  3851. + },
  3852. + .probe = edma_axi_probe,
  3853. + .remove = edma_axi_remove,
  3854. +};
  3855. +
  3856. +module_platform_driver(edma_axi_driver);
  3857. +
  3858. +MODULE_AUTHOR("Qualcomm Atheros Inc");
  3859. +MODULE_DESCRIPTION("QCA ESS EDMA driver");
  3860. +MODULE_LICENSE("GPL");
  3861. --- /dev/null
  3862. +++ b/drivers/net/ethernet/qualcomm/essedma/edma_ethtool.c
  3863. @@ -0,0 +1,374 @@
  3864. +/*
  3865. + * Copyright (c) 2015 - 2016, The Linux Foundation. All rights reserved.
  3866. + *
  3867. + * Permission to use, copy, modify, and/or distribute this software for
  3868. + * any purpose with or without fee is hereby granted, provided that the
  3869. + * above copyright notice and this permission notice appear in all copies.
  3870. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  3871. + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  3872. + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  3873. + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  3874. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  3875. + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  3876. + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  3877. + */
  3878. +
  3879. +#include <linux/ethtool.h>
  3880. +#include <linux/netdevice.h>
  3881. +#include <linux/string.h>
  3882. +#include "edma.h"
  3883. +
  3884. +struct edma_ethtool_stats {
  3885. + uint8_t stat_string[ETH_GSTRING_LEN];
  3886. + uint32_t stat_offset;
  3887. +};
  3888. +
  3889. +#define EDMA_STAT(m) offsetof(struct edma_ethtool_statistics, m)
  3890. +#define DRVINFO_LEN 32
  3891. +
  3892. +/* Array of strings describing statistics
  3893. + */
  3894. +static const struct edma_ethtool_stats edma_gstrings_stats[] = {
  3895. + {"tx_q0_pkt", EDMA_STAT(tx_q0_pkt)},
  3896. + {"tx_q1_pkt", EDMA_STAT(tx_q1_pkt)},
  3897. + {"tx_q2_pkt", EDMA_STAT(tx_q2_pkt)},
  3898. + {"tx_q3_pkt", EDMA_STAT(tx_q3_pkt)},
  3899. + {"tx_q4_pkt", EDMA_STAT(tx_q4_pkt)},
  3900. + {"tx_q5_pkt", EDMA_STAT(tx_q5_pkt)},
  3901. + {"tx_q6_pkt", EDMA_STAT(tx_q6_pkt)},
  3902. + {"tx_q7_pkt", EDMA_STAT(tx_q7_pkt)},
  3903. + {"tx_q8_pkt", EDMA_STAT(tx_q8_pkt)},
  3904. + {"tx_q9_pkt", EDMA_STAT(tx_q9_pkt)},
  3905. + {"tx_q10_pkt", EDMA_STAT(tx_q10_pkt)},
  3906. + {"tx_q11_pkt", EDMA_STAT(tx_q11_pkt)},
  3907. + {"tx_q12_pkt", EDMA_STAT(tx_q12_pkt)},
  3908. + {"tx_q13_pkt", EDMA_STAT(tx_q13_pkt)},
  3909. + {"tx_q14_pkt", EDMA_STAT(tx_q14_pkt)},
  3910. + {"tx_q15_pkt", EDMA_STAT(tx_q15_pkt)},
  3911. + {"tx_q0_byte", EDMA_STAT(tx_q0_byte)},
  3912. + {"tx_q1_byte", EDMA_STAT(tx_q1_byte)},
  3913. + {"tx_q2_byte", EDMA_STAT(tx_q2_byte)},
  3914. + {"tx_q3_byte", EDMA_STAT(tx_q3_byte)},
  3915. + {"tx_q4_byte", EDMA_STAT(tx_q4_byte)},
  3916. + {"tx_q5_byte", EDMA_STAT(tx_q5_byte)},
  3917. + {"tx_q6_byte", EDMA_STAT(tx_q6_byte)},
  3918. + {"tx_q7_byte", EDMA_STAT(tx_q7_byte)},
  3919. + {"tx_q8_byte", EDMA_STAT(tx_q8_byte)},
  3920. + {"tx_q9_byte", EDMA_STAT(tx_q9_byte)},
  3921. + {"tx_q10_byte", EDMA_STAT(tx_q10_byte)},
  3922. + {"tx_q11_byte", EDMA_STAT(tx_q11_byte)},
  3923. + {"tx_q12_byte", EDMA_STAT(tx_q12_byte)},
  3924. + {"tx_q13_byte", EDMA_STAT(tx_q13_byte)},
  3925. + {"tx_q14_byte", EDMA_STAT(tx_q14_byte)},
  3926. + {"tx_q15_byte", EDMA_STAT(tx_q15_byte)},
  3927. + {"rx_q0_pkt", EDMA_STAT(rx_q0_pkt)},
  3928. + {"rx_q1_pkt", EDMA_STAT(rx_q1_pkt)},
  3929. + {"rx_q2_pkt", EDMA_STAT(rx_q2_pkt)},
  3930. + {"rx_q3_pkt", EDMA_STAT(rx_q3_pkt)},
  3931. + {"rx_q4_pkt", EDMA_STAT(rx_q4_pkt)},
  3932. + {"rx_q5_pkt", EDMA_STAT(rx_q5_pkt)},
  3933. + {"rx_q6_pkt", EDMA_STAT(rx_q6_pkt)},
  3934. + {"rx_q7_pkt", EDMA_STAT(rx_q7_pkt)},
  3935. + {"rx_q0_byte", EDMA_STAT(rx_q0_byte)},
  3936. + {"rx_q1_byte", EDMA_STAT(rx_q1_byte)},
  3937. + {"rx_q2_byte", EDMA_STAT(rx_q2_byte)},
  3938. + {"rx_q3_byte", EDMA_STAT(rx_q3_byte)},
  3939. + {"rx_q4_byte", EDMA_STAT(rx_q4_byte)},
  3940. + {"rx_q5_byte", EDMA_STAT(rx_q5_byte)},
  3941. + {"rx_q6_byte", EDMA_STAT(rx_q6_byte)},
  3942. + {"rx_q7_byte", EDMA_STAT(rx_q7_byte)},
  3943. + {"tx_desc_error", EDMA_STAT(tx_desc_error)},
  3944. +};
  3945. +
  3946. +#define EDMA_STATS_LEN ARRAY_SIZE(edma_gstrings_stats)
  3947. +
  3948. +/* edma_get_strset_count()
  3949. + * Get strset count
  3950. + */
  3951. +static int edma_get_strset_count(struct net_device *netdev,
  3952. + int sset)
  3953. +{
  3954. + switch (sset) {
  3955. + case ETH_SS_STATS:
  3956. + return EDMA_STATS_LEN;
  3957. + default:
  3958. + netdev_dbg(netdev, "%s: Invalid string set", __func__);
  3959. + return -EOPNOTSUPP;
  3960. + }
  3961. +}
  3962. +
  3963. +
  3964. +/* edma_get_strings()
  3965. + * get stats string
  3966. + */
  3967. +static void edma_get_strings(struct net_device *netdev, uint32_t stringset,
  3968. + uint8_t *data)
  3969. +{
  3970. + uint8_t *p = data;
  3971. + uint32_t i;
  3972. +
  3973. + switch (stringset) {
  3974. + case ETH_SS_STATS:
  3975. + for (i = 0; i < EDMA_STATS_LEN; i++) {
  3976. + memcpy(p, edma_gstrings_stats[i].stat_string,
  3977. + min((size_t)ETH_GSTRING_LEN,
  3978. + strlen(edma_gstrings_stats[i].stat_string)
  3979. + + 1));
  3980. + p += ETH_GSTRING_LEN;
  3981. + }
  3982. + break;
  3983. + }
  3984. +}
  3985. +
  3986. +/* edma_get_ethtool_stats()
  3987. + * Get ethtool statistics
  3988. + */
  3989. +static void edma_get_ethtool_stats(struct net_device *netdev,
  3990. + struct ethtool_stats *stats, uint64_t *data)
  3991. +{
  3992. + struct edma_adapter *adapter = netdev_priv(netdev);
  3993. + struct edma_common_info *edma_cinfo = adapter->edma_cinfo;
  3994. + int i;
  3995. + uint8_t *p = NULL;
  3996. +
  3997. + edma_read_append_stats(edma_cinfo);
  3998. +
  3999. + for(i = 0; i < EDMA_STATS_LEN; i++) {
  4000. + p = (uint8_t *)&(edma_cinfo->edma_ethstats) +
  4001. + edma_gstrings_stats[i].stat_offset;
  4002. + data[i] = *(uint32_t *)p;
  4003. + }
  4004. +}
  4005. +
  4006. +/* edma_get_drvinfo()
  4007. + * get edma driver info
  4008. + */
  4009. +static void edma_get_drvinfo(struct net_device *dev,
  4010. + struct ethtool_drvinfo *info)
  4011. +{
  4012. + strlcpy(info->driver, "ess_edma", DRVINFO_LEN);
  4013. + strlcpy(info->bus_info, "axi", ETHTOOL_BUSINFO_LEN);
  4014. +}
  4015. +
  4016. +/* edma_nway_reset()
  4017. + * Reset the phy, if available.
  4018. + */
  4019. +static int edma_nway_reset(struct net_device *netdev)
  4020. +{
  4021. + return -EINVAL;
  4022. +}
  4023. +
  4024. +/* edma_get_wol()
  4025. + * get wake on lan info
  4026. + */
  4027. +static void edma_get_wol(struct net_device *netdev,
  4028. + struct ethtool_wolinfo *wol)
  4029. +{
  4030. + wol->supported = 0;
  4031. + wol->wolopts = 0;
  4032. +}
  4033. +
  4034. +/* edma_get_msglevel()
  4035. + * get message level.
  4036. + */
  4037. +static uint32_t edma_get_msglevel(struct net_device *netdev)
  4038. +{
  4039. + return 0;
  4040. +}
  4041. +
  4042. +/* edma_get_settings()
  4043. + * Get edma settings
  4044. + */
  4045. +static int edma_get_settings(struct net_device *netdev,
  4046. + struct ethtool_cmd *ecmd)
  4047. +{
  4048. + struct edma_adapter *adapter = netdev_priv(netdev);
  4049. +
  4050. + if (adapter->poll_required) {
  4051. + struct phy_device *phydev = NULL;
  4052. + uint16_t phyreg;
  4053. +
  4054. + if ((adapter->forced_speed != SPEED_UNKNOWN)
  4055. + && !(adapter->poll_required))
  4056. + return -EPERM;
  4057. +
  4058. + phydev = adapter->phydev;
  4059. +
  4060. + ecmd->advertising = phydev->advertising;
  4061. + ecmd->autoneg = phydev->autoneg;
  4062. +
  4063. + if (adapter->link_state == __EDMA_LINKDOWN) {
  4064. + ecmd->speed = SPEED_UNKNOWN;
  4065. + ecmd->duplex = DUPLEX_UNKNOWN;
  4066. + } else {
  4067. + ecmd->speed = phydev->speed;
  4068. + ecmd->duplex = phydev->duplex;
  4069. + }
  4070. +
  4071. + ecmd->phy_address = adapter->phy_mdio_addr;
  4072. +
  4073. + phyreg = (uint16_t)phy_read(adapter->phydev, MII_LPA);
  4074. + if (phyreg & LPA_10HALF)
  4075. + ecmd->lp_advertising |= ADVERTISED_10baseT_Half;
  4076. +
  4077. + if (phyreg & LPA_10FULL)
  4078. + ecmd->lp_advertising |= ADVERTISED_10baseT_Full;
  4079. +
  4080. + if (phyreg & LPA_100HALF)
  4081. + ecmd->lp_advertising |= ADVERTISED_100baseT_Half;
  4082. +
  4083. + if (phyreg & LPA_100FULL)
  4084. + ecmd->lp_advertising |= ADVERTISED_100baseT_Full;
  4085. +
  4086. + phyreg = (uint16_t)phy_read(adapter->phydev, MII_STAT1000);
  4087. + if (phyreg & LPA_1000HALF)
  4088. + ecmd->lp_advertising |= ADVERTISED_1000baseT_Half;
  4089. +
  4090. + if (phyreg & LPA_1000FULL)
  4091. + ecmd->lp_advertising |= ADVERTISED_1000baseT_Full;
  4092. + } else {
  4093. + /* If the speed/duplex for this GMAC is forced and we
  4094. + * are not polling for link state changes, return the
  4095. + * values as specified by platform. This will be true
  4096. + * for GMACs connected to switch, and interfaces that
  4097. + * do not use a PHY.
  4098. + */
  4099. + if (!(adapter->poll_required)) {
  4100. + if (adapter->forced_speed != SPEED_UNKNOWN) {
  4101. + /* set speed and duplex */
  4102. + ethtool_cmd_speed_set(ecmd, SPEED_1000);
  4103. + ecmd->duplex = DUPLEX_FULL;
  4104. +
  4105. + /* Populate capabilities advertised by self */
  4106. + ecmd->advertising = 0;
  4107. + ecmd->autoneg = 0;
  4108. + ecmd->port = PORT_TP;
  4109. + ecmd->transceiver = XCVR_EXTERNAL;
  4110. + } else {
  4111. + /* non link polled and non
  4112. + * forced speed/duplex interface
  4113. + */
  4114. + return -EIO;
  4115. + }
  4116. + }
  4117. + }
  4118. +
  4119. + return 0;
  4120. +}
  4121. +
  4122. +/* edma_set_settings()
  4123. + * Set EDMA settings
  4124. + */
  4125. +static int edma_set_settings(struct net_device *netdev,
  4126. + struct ethtool_cmd *ecmd)
  4127. +{
  4128. + struct edma_adapter *adapter = netdev_priv(netdev);
  4129. + struct phy_device *phydev = NULL;
  4130. +
  4131. + if ((adapter->forced_speed != SPEED_UNKNOWN) &&
  4132. + !adapter->poll_required)
  4133. + return -EPERM;
  4134. +
  4135. + phydev = adapter->phydev;
  4136. + phydev->advertising = ecmd->advertising;
  4137. + phydev->autoneg = ecmd->autoneg;
  4138. + phydev->speed = ethtool_cmd_speed(ecmd);
  4139. + phydev->duplex = ecmd->duplex;
  4140. +
  4141. + genphy_config_aneg(phydev);
  4142. +
  4143. + return 0;
  4144. +}
  4145. +
  4146. +/* edma_get_coalesce
  4147. + * get interrupt mitigation
  4148. + */
  4149. +static int edma_get_coalesce(struct net_device *netdev,
  4150. + struct ethtool_coalesce *ec)
  4151. +{
  4152. + u32 reg_val;
  4153. +
  4154. + edma_get_tx_rx_coalesce(&reg_val);
  4155. +
  4156. + /* We read the Interrupt Moderation Timer(IMT) register value,
  4157. + * use lower 16 bit for rx and higher 16 bit for Tx. We do a
  4158. + * left shift by 1, because IMT resolution timer is 2usecs.
  4159. + * Hence the value given by the register is multiplied by 2 to
  4160. + * get the actual time in usecs.
  4161. + */
  4162. + ec->tx_coalesce_usecs = (((reg_val >> 16) & 0xffff) << 1);
  4163. + ec->rx_coalesce_usecs = ((reg_val & 0xffff) << 1);
  4164. +
  4165. + return 0;
  4166. +}
  4167. +
  4168. +/* edma_set_coalesce
  4169. + * set interrupt mitigation
  4170. + */
  4171. +static int edma_set_coalesce(struct net_device *netdev,
  4172. + struct ethtool_coalesce *ec)
  4173. +{
  4174. + if (ec->tx_coalesce_usecs)
  4175. + edma_change_tx_coalesce(ec->tx_coalesce_usecs);
  4176. + if (ec->rx_coalesce_usecs)
  4177. + edma_change_rx_coalesce(ec->rx_coalesce_usecs);
  4178. +
  4179. + return 0;
  4180. +}
  4181. +
  4182. +/* edma_set_priv_flags()
  4183. + * Set EDMA private flags
  4184. + */
  4185. +static int edma_set_priv_flags(struct net_device *netdev, u32 flags)
  4186. +{
  4187. + return 0;
  4188. +}
  4189. +
  4190. +/* edma_get_priv_flags()
  4191. + * get edma driver flags
  4192. + */
  4193. +static u32 edma_get_priv_flags(struct net_device *netdev)
  4194. +{
  4195. + return 0;
  4196. +}
  4197. +
  4198. +/* edma_get_ringparam()
  4199. + * get ring size
  4200. + */
  4201. +static void edma_get_ringparam(struct net_device *netdev,
  4202. + struct ethtool_ringparam *ring)
  4203. +{
  4204. + struct edma_adapter *adapter = netdev_priv(netdev);
  4205. + struct edma_common_info *edma_cinfo = adapter->edma_cinfo;
  4206. +
  4207. + ring->tx_max_pending = edma_cinfo->tx_ring_count;
  4208. + ring->rx_max_pending = edma_cinfo->rx_ring_count;
  4209. +}
  4210. +
  4211. +/* Ethtool operations
  4212. + */
  4213. +static const struct ethtool_ops edma_ethtool_ops = {
  4214. + .get_drvinfo = &edma_get_drvinfo,
  4215. + .get_link = &ethtool_op_get_link,
  4216. + .get_msglevel = &edma_get_msglevel,
  4217. + .nway_reset = &edma_nway_reset,
  4218. + .get_wol = &edma_get_wol,
  4219. + .get_settings = &edma_get_settings,
  4220. + .set_settings = &edma_set_settings,
  4221. + .get_strings = &edma_get_strings,
  4222. + .get_sset_count = &edma_get_strset_count,
  4223. + .get_ethtool_stats = &edma_get_ethtool_stats,
  4224. + .get_coalesce = &edma_get_coalesce,
  4225. + .set_coalesce = &edma_set_coalesce,
  4226. + .get_priv_flags = edma_get_priv_flags,
  4227. + .set_priv_flags = edma_set_priv_flags,
  4228. + .get_ringparam = edma_get_ringparam,
  4229. +};
  4230. +
  4231. +/* edma_set_ethtool_ops
  4232. + * Set ethtool operations
  4233. + */
  4234. +void edma_set_ethtool_ops(struct net_device *netdev)
  4235. +{
  4236. + netdev->ethtool_ops = &edma_ethtool_ops;
  4237. +}
  4238. --- /dev/null
  4239. +++ b/drivers/net/ethernet/qualcomm/essedma/ess_edma.h
  4240. @@ -0,0 +1,332 @@
  4241. +/*
  4242. + * Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
  4243. + *
  4244. + * Permission to use, copy, modify, and/or distribute this software for
  4245. + * any purpose with or without fee is hereby granted, provided that the
  4246. + * above copyright notice and this permission notice appear in all copies.
  4247. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  4248. + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  4249. + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  4250. + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  4251. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  4252. + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  4253. + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  4254. + */
  4255. +
  4256. +#ifndef _ESS_EDMA_H_
  4257. +#define _ESS_EDMA_H_
  4258. +
  4259. +#include <linux/types.h>
  4260. +
  4261. +struct edma_adapter;
  4262. +struct edma_hw;
  4263. +
  4264. +/* register definition */
  4265. +#define EDMA_REG_MAS_CTRL 0x0
  4266. +#define EDMA_REG_TIMEOUT_CTRL 0x004
  4267. +#define EDMA_REG_DBG0 0x008
  4268. +#define EDMA_REG_DBG1 0x00C
  4269. +#define EDMA_REG_SW_CTRL0 0x100
  4270. +#define EDMA_REG_SW_CTRL1 0x104
  4271. +
  4272. +/* Interrupt Status Register */
  4273. +#define EDMA_REG_RX_ISR 0x200
  4274. +#define EDMA_REG_TX_ISR 0x208
  4275. +#define EDMA_REG_MISC_ISR 0x210
  4276. +#define EDMA_REG_WOL_ISR 0x218
  4277. +
  4278. +#define EDMA_MISC_ISR_RX_URG_Q(x) (1 << x)
  4279. +
  4280. +#define EDMA_MISC_ISR_AXIR_TIMEOUT 0x00000100
  4281. +#define EDMA_MISC_ISR_AXIR_ERR 0x00000200
  4282. +#define EDMA_MISC_ISR_TXF_DEAD 0x00000400
  4283. +#define EDMA_MISC_ISR_AXIW_ERR 0x00000800
  4284. +#define EDMA_MISC_ISR_AXIW_TIMEOUT 0x00001000
  4285. +
  4286. +#define EDMA_WOL_ISR 0x00000001
  4287. +
  4288. +/* Interrupt Mask Register */
  4289. +#define EDMA_REG_MISC_IMR 0x214
  4290. +#define EDMA_REG_WOL_IMR 0x218
  4291. +
  4292. +#define EDMA_RX_IMR_NORMAL_MASK 0x1
  4293. +#define EDMA_TX_IMR_NORMAL_MASK 0x1
  4294. +#define EDMA_MISC_IMR_NORMAL_MASK 0x80001FFF
  4295. +#define EDMA_WOL_IMR_NORMAL_MASK 0x1
  4296. +
  4297. +/* Edma receive consumer index */
  4298. +#define EDMA_REG_RX_SW_CONS_IDX_Q(x) (0x220 + ((x) << 2)) /* x is the queue id */
  4299. +/* Edma transmit consumer index */
  4300. +#define EDMA_REG_TX_SW_CONS_IDX_Q(x) (0x240 + ((x) << 2)) /* x is the queue id */
  4301. +
  4302. +/* IRQ Moderator Initial Timer Register */
  4303. +#define EDMA_REG_IRQ_MODRT_TIMER_INIT 0x280
  4304. +#define EDMA_IRQ_MODRT_TIMER_MASK 0xFFFF
  4305. +#define EDMA_IRQ_MODRT_RX_TIMER_SHIFT 0
  4306. +#define EDMA_IRQ_MODRT_TX_TIMER_SHIFT 16
  4307. +
  4308. +/* Interrupt Control Register */
  4309. +#define EDMA_REG_INTR_CTRL 0x284
  4310. +#define EDMA_INTR_CLR_TYP_SHIFT 0
  4311. +#define EDMA_INTR_SW_IDX_W_TYP_SHIFT 1
  4312. +#define EDMA_INTR_CLEAR_TYPE_W1 0
  4313. +#define EDMA_INTR_CLEAR_TYPE_R 1
  4314. +
  4315. +/* RX Interrupt Mask Register */
  4316. +#define EDMA_REG_RX_INT_MASK_Q(x) (0x300 + ((x) << 2)) /* x = queue id */
  4317. +
  4318. +/* TX Interrupt mask register */
  4319. +#define EDMA_REG_TX_INT_MASK_Q(x) (0x340 + ((x) << 2)) /* x = queue id */
  4320. +
  4321. +/* Load Ptr Register
  4322. + * Software sets this bit after the initialization of the head and tail
  4323. + */
  4324. +#define EDMA_REG_TX_SRAM_PART 0x400
  4325. +#define EDMA_LOAD_PTR_SHIFT 16
  4326. +
  4327. +/* TXQ Control Register */
  4328. +#define EDMA_REG_TXQ_CTRL 0x404
  4329. +#define EDMA_TXQ_CTRL_IP_OPTION_EN 0x10
  4330. +#define EDMA_TXQ_CTRL_TXQ_EN 0x20
  4331. +#define EDMA_TXQ_CTRL_ENH_MODE 0x40
  4332. +#define EDMA_TXQ_CTRL_LS_8023_EN 0x80
  4333. +#define EDMA_TXQ_CTRL_TPD_BURST_EN 0x100
  4334. +#define EDMA_TXQ_CTRL_LSO_BREAK_EN 0x200
  4335. +#define EDMA_TXQ_NUM_TPD_BURST_MASK 0xF
  4336. +#define EDMA_TXQ_TXF_BURST_NUM_MASK 0xFFFF
  4337. +#define EDMA_TXQ_NUM_TPD_BURST_SHIFT 0
  4338. +#define EDMA_TXQ_TXF_BURST_NUM_SHIFT 16
  4339. +
  4340. +#define EDMA_REG_TXF_WATER_MARK 0x408 /* In 8-bytes */
  4341. +#define EDMA_TXF_WATER_MARK_MASK 0x0FFF
  4342. +#define EDMA_TXF_LOW_WATER_MARK_SHIFT 0
  4343. +#define EDMA_TXF_HIGH_WATER_MARK_SHIFT 16
  4344. +#define EDMA_TXQ_CTRL_BURST_MODE_EN 0x80000000
  4345. +
  4346. +/* WRR Control Register */
  4347. +#define EDMA_REG_WRR_CTRL_Q0_Q3 0x40c
  4348. +#define EDMA_REG_WRR_CTRL_Q4_Q7 0x410
  4349. +#define EDMA_REG_WRR_CTRL_Q8_Q11 0x414
  4350. +#define EDMA_REG_WRR_CTRL_Q12_Q15 0x418
  4351. +
  4352. +/* Weight round robin(WRR), it takes queue as input, and computes
  4353. + * starting bits where we need to write the weight for a particular
  4354. + * queue
  4355. + */
  4356. +#define EDMA_WRR_SHIFT(x) (((x) * 5) % 20)
  4357. +
  4358. +/* Tx Descriptor Control Register */
  4359. +#define EDMA_REG_TPD_RING_SIZE 0x41C
  4360. +#define EDMA_TPD_RING_SIZE_SHIFT 0
  4361. +#define EDMA_TPD_RING_SIZE_MASK 0xFFFF
  4362. +
  4363. +/* Transmit descriptor base address */
  4364. +#define EDMA_REG_TPD_BASE_ADDR_Q(x) (0x420 + ((x) << 2)) /* x = queue id */
  4365. +
  4366. +/* TPD Index Register */
  4367. +#define EDMA_REG_TPD_IDX_Q(x) (0x460 + ((x) << 2)) /* x = queue id */
  4368. +
  4369. +#define EDMA_TPD_PROD_IDX_BITS 0x0000FFFF
  4370. +#define EDMA_TPD_CONS_IDX_BITS 0xFFFF0000
  4371. +#define EDMA_TPD_PROD_IDX_MASK 0xFFFF
  4372. +#define EDMA_TPD_CONS_IDX_MASK 0xFFFF
  4373. +#define EDMA_TPD_PROD_IDX_SHIFT 0
  4374. +#define EDMA_TPD_CONS_IDX_SHIFT 16
  4375. +
  4376. +/* TX Virtual Queue Mapping Control Register */
  4377. +#define EDMA_REG_VQ_CTRL0 0x4A0
  4378. +#define EDMA_REG_VQ_CTRL1 0x4A4
  4379. +
  4380. +/* Virtual QID shift, it takes queue as input, and computes
  4381. + * Virtual QID position in virtual qid control register
  4382. + */
  4383. +#define EDMA_VQ_ID_SHIFT(i) (((i) * 3) % 24)
  4384. +
  4385. +/* Virtual Queue Default Value */
  4386. +#define EDMA_VQ_REG_VALUE 0x240240
  4387. +
  4388. +/* Tx side Port Interface Control Register */
  4389. +#define EDMA_REG_PORT_CTRL 0x4A8
  4390. +#define EDMA_PAD_EN_SHIFT 15
  4391. +
  4392. +/* Tx side VLAN Configuration Register */
  4393. +#define EDMA_REG_VLAN_CFG 0x4AC
  4394. +
  4395. +#define EDMA_TX_CVLAN 16
  4396. +#define EDMA_TX_INS_CVLAN 17
  4397. +#define EDMA_TX_CVLAN_TAG_SHIFT 0
  4398. +
  4399. +#define EDMA_TX_SVLAN 14
  4400. +#define EDMA_TX_INS_SVLAN 15
  4401. +#define EDMA_TX_SVLAN_TAG_SHIFT 16
  4402. +
  4403. +/* Tx Queue Packet Statistic Register */
  4404. +#define EDMA_REG_TX_STAT_PKT_Q(x) (0x700 + ((x) << 3)) /* x = queue id */
  4405. +
  4406. +#define EDMA_TX_STAT_PKT_MASK 0xFFFFFF
  4407. +
  4408. +/* Tx Queue Byte Statistic Register */
  4409. +#define EDMA_REG_TX_STAT_BYTE_Q(x) (0x704 + ((x) << 3)) /* x = queue id */
  4410. +
  4411. +/* Load Balance Based Ring Offset Register */
  4412. +#define EDMA_REG_LB_RING 0x800
  4413. +#define EDMA_LB_RING_ENTRY_MASK 0xff
  4414. +#define EDMA_LB_RING_ID_MASK 0x7
  4415. +#define EDMA_LB_RING_PROFILE_ID_MASK 0x3
  4416. +#define EDMA_LB_RING_ENTRY_BIT_OFFSET 8
  4417. +#define EDMA_LB_RING_ID_OFFSET 0
  4418. +#define EDMA_LB_RING_PROFILE_ID_OFFSET 3
  4419. +#define EDMA_LB_REG_VALUE 0x6040200
  4420. +
  4421. +/* Load Balance Priority Mapping Register */
  4422. +#define EDMA_REG_LB_PRI_START 0x804
  4423. +#define EDMA_REG_LB_PRI_END 0x810
  4424. +#define EDMA_LB_PRI_REG_INC 4
  4425. +#define EDMA_LB_PRI_ENTRY_BIT_OFFSET 4
  4426. +#define EDMA_LB_PRI_ENTRY_MASK 0xf
  4427. +
  4428. +/* RSS Priority Mapping Register */
  4429. +#define EDMA_REG_RSS_PRI 0x820
  4430. +#define EDMA_RSS_PRI_ENTRY_MASK 0xf
  4431. +#define EDMA_RSS_RING_ID_MASK 0x7
  4432. +#define EDMA_RSS_PRI_ENTRY_BIT_OFFSET 4
  4433. +
  4434. +/* RSS Indirection Register */
  4435. +#define EDMA_REG_RSS_IDT(x) (0x840 + ((x) << 2)) /* x = No. of indirection table */
  4436. +#define EDMA_NUM_IDT 16
  4437. +#define EDMA_RSS_IDT_VALUE 0x64206420
  4438. +
  4439. +/* Default RSS Ring Register */
  4440. +#define EDMA_REG_DEF_RSS 0x890
  4441. +#define EDMA_DEF_RSS_MASK 0x7
  4442. +
  4443. +/* RSS Hash Function Type Register */
  4444. +#define EDMA_REG_RSS_TYPE 0x894
  4445. +#define EDMA_RSS_TYPE_NONE 0x01
  4446. +#define EDMA_RSS_TYPE_IPV4TCP 0x02
  4447. +#define EDMA_RSS_TYPE_IPV6_TCP 0x04
  4448. +#define EDMA_RSS_TYPE_IPV4_UDP 0x08
  4449. +#define EDMA_RSS_TYPE_IPV6UDP 0x10
  4450. +#define EDMA_RSS_TYPE_IPV4 0x20
  4451. +#define EDMA_RSS_TYPE_IPV6 0x40
  4452. +#define EDMA_RSS_HASH_MODE_MASK 0x7f
  4453. +
  4454. +#define EDMA_REG_RSS_HASH_VALUE 0x8C0
  4455. +
  4456. +#define EDMA_REG_RSS_TYPE_RESULT 0x8C4
  4457. +
  4458. +#define EDMA_HASH_TYPE_START 0
  4459. +#define EDMA_HASH_TYPE_END 5
  4460. +#define EDMA_HASH_TYPE_SHIFT 12
  4461. +
  4462. +#define EDMA_RFS_FLOW_ENTRIES 1024
  4463. +#define EDMA_RFS_FLOW_ENTRIES_MASK (EDMA_RFS_FLOW_ENTRIES - 1)
  4464. +#define EDMA_RFS_EXPIRE_COUNT_PER_CALL 128
  4465. +
  4466. +/* RFD Base Address Register */
  4467. +#define EDMA_REG_RFD_BASE_ADDR_Q(x) (0x950 + ((x) << 2)) /* x = queue id */
  4468. +
  4469. +/* RFD Index Register */
  4470. +#define EDMA_REG_RFD_IDX_Q(x) (0x9B0 + ((x) << 2))
  4471. +
  4472. +#define EDMA_RFD_PROD_IDX_BITS 0x00000FFF
  4473. +#define EDMA_RFD_CONS_IDX_BITS 0x0FFF0000
  4474. +#define EDMA_RFD_PROD_IDX_MASK 0xFFF
  4475. +#define EDMA_RFD_CONS_IDX_MASK 0xFFF
  4476. +#define EDMA_RFD_PROD_IDX_SHIFT 0
  4477. +#define EDMA_RFD_CONS_IDX_SHIFT 16
  4478. +
  4479. +/* Rx Descriptor Control Register */
  4480. +#define EDMA_REG_RX_DESC0 0xA10
  4481. +#define EDMA_RFD_RING_SIZE_MASK 0xFFF
  4482. +#define EDMA_RX_BUF_SIZE_MASK 0xFFFF
  4483. +#define EDMA_RFD_RING_SIZE_SHIFT 0
  4484. +#define EDMA_RX_BUF_SIZE_SHIFT 16
  4485. +
  4486. +#define EDMA_REG_RX_DESC1 0xA14
  4487. +#define EDMA_RXQ_RFD_BURST_NUM_MASK 0x3F
  4488. +#define EDMA_RXQ_RFD_PF_THRESH_MASK 0x1F
  4489. +#define EDMA_RXQ_RFD_LOW_THRESH_MASK 0xFFF
  4490. +#define EDMA_RXQ_RFD_BURST_NUM_SHIFT 0
  4491. +#define EDMA_RXQ_RFD_PF_THRESH_SHIFT 8
  4492. +#define EDMA_RXQ_RFD_LOW_THRESH_SHIFT 16
  4493. +
  4494. +/* RXQ Control Register */
  4495. +#define EDMA_REG_RXQ_CTRL 0xA18
  4496. +#define EDMA_FIFO_THRESH_TYPE_SHIF 0
  4497. +#define EDMA_FIFO_THRESH_128_BYTE 0x0
  4498. +#define EDMA_FIFO_THRESH_64_BYTE 0x1
  4499. +#define EDMA_RXQ_CTRL_RMV_VLAN 0x00000002
  4500. +#define EDMA_RXQ_CTRL_EN 0x0000FF00
  4501. +
  4502. +/* AXI Burst Size Config */
  4503. +#define EDMA_REG_AXIW_CTRL_MAXWRSIZE 0xA1C
  4504. +#define EDMA_AXIW_MAXWRSIZE_VALUE 0x0
  4505. +
  4506. +/* Rx Statistics Register */
  4507. +#define EDMA_REG_RX_STAT_BYTE_Q(x) (0xA30 + ((x) << 2)) /* x = queue id */
  4508. +#define EDMA_REG_RX_STAT_PKT_Q(x) (0xA50 + ((x) << 2)) /* x = queue id */
  4509. +
  4510. +/* WoL Pattern Length Register */
  4511. +#define EDMA_REG_WOL_PATTERN_LEN0 0xC00
  4512. +#define EDMA_WOL_PT_LEN_MASK 0xFF
  4513. +#define EDMA_WOL_PT0_LEN_SHIFT 0
  4514. +#define EDMA_WOL_PT1_LEN_SHIFT 8
  4515. +#define EDMA_WOL_PT2_LEN_SHIFT 16
  4516. +#define EDMA_WOL_PT3_LEN_SHIFT 24
  4517. +
  4518. +#define EDMA_REG_WOL_PATTERN_LEN1 0xC04
  4519. +#define EDMA_WOL_PT4_LEN_SHIFT 0
  4520. +#define EDMA_WOL_PT5_LEN_SHIFT 8
  4521. +#define EDMA_WOL_PT6_LEN_SHIFT 16
  4522. +
  4523. +/* WoL Control Register */
  4524. +#define EDMA_REG_WOL_CTRL 0xC08
  4525. +#define EDMA_WOL_WK_EN 0x00000001
  4526. +#define EDMA_WOL_MG_EN 0x00000002
  4527. +#define EDMA_WOL_PT0_EN 0x00000004
  4528. +#define EDMA_WOL_PT1_EN 0x00000008
  4529. +#define EDMA_WOL_PT2_EN 0x00000010
  4530. +#define EDMA_WOL_PT3_EN 0x00000020
  4531. +#define EDMA_WOL_PT4_EN 0x00000040
  4532. +#define EDMA_WOL_PT5_EN 0x00000080
  4533. +#define EDMA_WOL_PT6_EN 0x00000100
  4534. +
  4535. +/* MAC Control Register */
  4536. +#define EDMA_REG_MAC_CTRL0 0xC20
  4537. +#define EDMA_REG_MAC_CTRL1 0xC24
  4538. +
  4539. +/* WoL Pattern Register */
  4540. +#define EDMA_REG_WOL_PATTERN_START 0x5000
  4541. +#define EDMA_PATTERN_PART_REG_OFFSET 0x40
  4542. +
  4543. +
  4544. +/* TX descriptor fields */
  4545. +#define EDMA_TPD_HDR_SHIFT 0
  4546. +#define EDMA_TPD_PPPOE_EN 0x00000100
  4547. +#define EDMA_TPD_IP_CSUM_EN 0x00000200
  4548. +#define EDMA_TPD_TCP_CSUM_EN 0x0000400
  4549. +#define EDMA_TPD_UDP_CSUM_EN 0x00000800
  4550. +#define EDMA_TPD_CUSTOM_CSUM_EN 0x00000C00
  4551. +#define EDMA_TPD_LSO_EN 0x00001000
  4552. +#define EDMA_TPD_LSO_V2_EN 0x00002000
  4553. +#define EDMA_TPD_IPV4_EN 0x00010000
  4554. +#define EDMA_TPD_MSS_MASK 0x1FFF
  4555. +#define EDMA_TPD_MSS_SHIFT 18
  4556. +#define EDMA_TPD_CUSTOM_CSUM_SHIFT 18
  4557. +
  4558. +/* RRD descriptor fields */
  4559. +#define EDMA_RRD_NUM_RFD_MASK 0x000F
  4560. +#define EDMA_RRD_SVLAN 0x8000
  4561. +#define EDMA_RRD_FLOW_COOKIE_MASK 0x07FF;
  4562. +
  4563. +#define EDMA_RRD_PKT_SIZE_MASK 0x3FFF
  4564. +#define EDMA_RRD_CSUM_FAIL_MASK 0xC000
  4565. +#define EDMA_RRD_CVLAN 0x0001
  4566. +#define EDMA_RRD_DESC_VALID 0x8000
  4567. +
  4568. +#define EDMA_RRD_PRIORITY_SHIFT 4
  4569. +#define EDMA_RRD_PRIORITY_MASK 0x7
  4570. +#define EDMA_RRD_PORT_TYPE_SHIFT 7
  4571. +#define EDMA_RRD_PORT_TYPE_MASK 0x1F
  4572. +#endif /* _ESS_EDMA_H_ */