xgbe-dev.c 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726
  1. /*
  2. * AMD 10Gb Ethernet driver
  3. *
  4. * This file is available to you under your choice of the following two
  5. * licenses:
  6. *
  7. * License 1: GPLv2
  8. *
  9. * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
  10. *
  11. * This file is free software; you may copy, redistribute and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 2 of the License, or (at
  14. * your option) any later version.
  15. *
  16. * This file is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. * This file incorporates work covered by the following copyright and
  25. * permission notice:
  26. * The Synopsys DWC ETHER XGMAC Software Driver and documentation
  27. * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
  28. * Inc. unless otherwise expressly agreed to in writing between Synopsys
  29. * and you.
  30. *
  31. * The Software IS NOT an item of Licensed Software or Licensed Product
  32. * under any End User Software License Agreement or Agreement for Licensed
  33. * Product with Synopsys or any supplement thereto. Permission is hereby
  34. * granted, free of charge, to any person obtaining a copy of this software
  35. * annotated with this license and the Software, to deal in the Software
  36. * without restriction, including without limitation the rights to use,
  37. * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  38. * of the Software, and to permit persons to whom the Software is furnished
  39. * to do so, subject to the following conditions:
  40. *
  41. * The above copyright notice and this permission notice shall be included
  42. * in all copies or substantial portions of the Software.
  43. *
  44. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45. * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  46. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  47. * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
  48. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  49. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  50. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  51. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  52. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  53. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  54. * THE POSSIBILITY OF SUCH DAMAGE.
  55. *
  56. *
  57. * License 2: Modified BSD
  58. *
  59. * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
  60. * All rights reserved.
  61. *
  62. * Redistribution and use in source and binary forms, with or without
  63. * modification, are permitted provided that the following conditions are met:
  64. * * Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. * * Redistributions in binary form must reproduce the above copyright
  67. * notice, this list of conditions and the following disclaimer in the
  68. * documentation and/or other materials provided with the distribution.
  69. * * Neither the name of Advanced Micro Devices, Inc. nor the
  70. * names of its contributors may be used to endorse or promote products
  71. * derived from this software without specific prior written permission.
  72. *
  73. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  74. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  75. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76. * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  77. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  79. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  80. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  81. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  82. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  83. *
  84. * This file incorporates work covered by the following copyright and
  85. * permission notice:
  86. * The Synopsys DWC ETHER XGMAC Software Driver and documentation
  87. * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
  88. * Inc. unless otherwise expressly agreed to in writing between Synopsys
  89. * and you.
  90. *
  91. * The Software IS NOT an item of Licensed Software or Licensed Product
  92. * under any End User Software License Agreement or Agreement for Licensed
  93. * Product with Synopsys or any supplement thereto. Permission is hereby
  94. * granted, free of charge, to any person obtaining a copy of this software
  95. * annotated with this license and the Software, to deal in the Software
  96. * without restriction, including without limitation the rights to use,
  97. * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  98. * of the Software, and to permit persons to whom the Software is furnished
  99. * to do so, subject to the following conditions:
  100. *
  101. * The above copyright notice and this permission notice shall be included
  102. * in all copies or substantial portions of the Software.
  103. *
  104. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  105. * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  106. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  107. * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
  108. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  109. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  110. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  111. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  112. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  113. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  114. * THE POSSIBILITY OF SUCH DAMAGE.
  115. */
  116. #include <linux/phy.h>
  117. #include <linux/mdio.h>
  118. #include <linux/clk.h>
  119. #include <linux/bitrev.h>
  120. #include <linux/crc32.h>
  121. #include <linux/crc32poly.h>
  122. #include "xgbe.h"
  123. #include "xgbe-common.h"
  124. static inline unsigned int xgbe_get_max_frame(struct xgbe_prv_data *pdata)
  125. {
  126. return pdata->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  127. }
  128. static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
  129. unsigned int usec)
  130. {
  131. unsigned long rate;
  132. unsigned int ret;
  133. DBGPR("-->xgbe_usec_to_riwt\n");
  134. rate = pdata->sysclk_rate;
  135. /*
  136. * Convert the input usec value to the watchdog timer value. Each
  137. * watchdog timer value is equivalent to 256 clock cycles.
  138. * Calculate the required value as:
  139. * ( usec * ( system_clock_mhz / 10^6 ) / 256
  140. */
  141. ret = (usec * (rate / 1000000)) / 256;
  142. DBGPR("<--xgbe_usec_to_riwt\n");
  143. return ret;
  144. }
  145. static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
  146. unsigned int riwt)
  147. {
  148. unsigned long rate;
  149. unsigned int ret;
  150. DBGPR("-->xgbe_riwt_to_usec\n");
  151. rate = pdata->sysclk_rate;
  152. /*
  153. * Convert the input watchdog timer value to the usec value. Each
  154. * watchdog timer value is equivalent to 256 clock cycles.
  155. * Calculate the required value as:
  156. * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
  157. */
  158. ret = (riwt * 256) / (rate / 1000000);
  159. DBGPR("<--xgbe_riwt_to_usec\n");
  160. return ret;
  161. }
  162. static int xgbe_config_pbl_val(struct xgbe_prv_data *pdata)
  163. {
  164. unsigned int pblx8, pbl;
  165. unsigned int i;
  166. pblx8 = DMA_PBL_X8_DISABLE;
  167. pbl = pdata->pbl;
  168. if (pdata->pbl > 32) {
  169. pblx8 = DMA_PBL_X8_ENABLE;
  170. pbl >>= 3;
  171. }
  172. for (i = 0; i < pdata->channel_count; i++) {
  173. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_CR, PBLX8,
  174. pblx8);
  175. if (pdata->channel[i]->tx_ring)
  176. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR,
  177. PBL, pbl);
  178. if (pdata->channel[i]->rx_ring)
  179. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR,
  180. PBL, pbl);
  181. }
  182. return 0;
  183. }
  184. static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
  185. {
  186. unsigned int i;
  187. for (i = 0; i < pdata->channel_count; i++) {
  188. if (!pdata->channel[i]->tx_ring)
  189. break;
  190. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, OSP,
  191. pdata->tx_osp_mode);
  192. }
  193. return 0;
  194. }
  195. static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
  196. {
  197. unsigned int i;
  198. for (i = 0; i < pdata->rx_q_count; i++)
  199. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
  200. return 0;
  201. }
  202. static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
  203. {
  204. unsigned int i;
  205. for (i = 0; i < pdata->tx_q_count; i++)
  206. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
  207. return 0;
  208. }
  209. static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
  210. unsigned int val)
  211. {
  212. unsigned int i;
  213. for (i = 0; i < pdata->rx_q_count; i++)
  214. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
  215. return 0;
  216. }
  217. static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
  218. unsigned int val)
  219. {
  220. unsigned int i;
  221. for (i = 0; i < pdata->tx_q_count; i++)
  222. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
  223. return 0;
  224. }
  225. static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
  226. {
  227. unsigned int i;
  228. for (i = 0; i < pdata->channel_count; i++) {
  229. if (!pdata->channel[i]->rx_ring)
  230. break;
  231. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RIWT, RWT,
  232. pdata->rx_riwt);
  233. }
  234. return 0;
  235. }
  236. static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
  237. {
  238. return 0;
  239. }
  240. static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
  241. {
  242. unsigned int i;
  243. for (i = 0; i < pdata->channel_count; i++) {
  244. if (!pdata->channel[i]->rx_ring)
  245. break;
  246. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, RBSZ,
  247. pdata->rx_buf_size);
  248. }
  249. }
  250. static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
  251. {
  252. unsigned int i;
  253. for (i = 0; i < pdata->channel_count; i++) {
  254. if (!pdata->channel[i]->tx_ring)
  255. break;
  256. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, TSE, 1);
  257. }
  258. }
  259. static void xgbe_config_sph_mode(struct xgbe_prv_data *pdata)
  260. {
  261. unsigned int i;
  262. for (i = 0; i < pdata->channel_count; i++) {
  263. if (!pdata->channel[i]->rx_ring)
  264. break;
  265. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_CR, SPH, 1);
  266. }
  267. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, HDSMS, XGBE_SPH_HDSMS_SIZE);
  268. }
  269. static void xgbe_disable_sph_mode(struct xgbe_prv_data *pdata)
  270. {
  271. unsigned int i;
  272. for (i = 0; i < pdata->channel_count; i++) {
  273. if (!pdata->channel[i]->rx_ring)
  274. break;
  275. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_CR, SPH, 0);
  276. }
  277. }
  278. static int xgbe_write_rss_reg(struct xgbe_prv_data *pdata, unsigned int type,
  279. unsigned int index, unsigned int val)
  280. {
  281. unsigned int wait;
  282. int ret = 0;
  283. mutex_lock(&pdata->rss_mutex);
  284. if (XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB)) {
  285. ret = -EBUSY;
  286. goto unlock;
  287. }
  288. XGMAC_IOWRITE(pdata, MAC_RSSDR, val);
  289. XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, RSSIA, index);
  290. XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, ADDRT, type);
  291. XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, CT, 0);
  292. XGMAC_IOWRITE_BITS(pdata, MAC_RSSAR, OB, 1);
  293. wait = 1000;
  294. while (wait--) {
  295. if (!XGMAC_IOREAD_BITS(pdata, MAC_RSSAR, OB))
  296. goto unlock;
  297. usleep_range(1000, 1500);
  298. }
  299. ret = -EBUSY;
  300. unlock:
  301. mutex_unlock(&pdata->rss_mutex);
  302. return ret;
  303. }
  304. static int xgbe_write_rss_hash_key(struct xgbe_prv_data *pdata)
  305. {
  306. unsigned int key_regs = sizeof(pdata->rss_key) / sizeof(u32);
  307. unsigned int *key = (unsigned int *)&pdata->rss_key;
  308. int ret;
  309. while (key_regs--) {
  310. ret = xgbe_write_rss_reg(pdata, XGBE_RSS_HASH_KEY_TYPE,
  311. key_regs, *key++);
  312. if (ret)
  313. return ret;
  314. }
  315. return 0;
  316. }
  317. static int xgbe_write_rss_lookup_table(struct xgbe_prv_data *pdata)
  318. {
  319. unsigned int i;
  320. int ret;
  321. for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) {
  322. ret = xgbe_write_rss_reg(pdata,
  323. XGBE_RSS_LOOKUP_TABLE_TYPE, i,
  324. pdata->rss_table[i]);
  325. if (ret)
  326. return ret;
  327. }
  328. return 0;
  329. }
  330. static int xgbe_set_rss_hash_key(struct xgbe_prv_data *pdata, const u8 *key)
  331. {
  332. memcpy(pdata->rss_key, key, sizeof(pdata->rss_key));
  333. return xgbe_write_rss_hash_key(pdata);
  334. }
  335. static int xgbe_set_rss_lookup_table(struct xgbe_prv_data *pdata,
  336. const u32 *table)
  337. {
  338. unsigned int i;
  339. for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
  340. XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH, table[i]);
  341. return xgbe_write_rss_lookup_table(pdata);
  342. }
  343. static int xgbe_enable_rss(struct xgbe_prv_data *pdata)
  344. {
  345. int ret;
  346. if (!pdata->hw_feat.rss)
  347. return -EOPNOTSUPP;
  348. /* Program the hash key */
  349. ret = xgbe_write_rss_hash_key(pdata);
  350. if (ret)
  351. return ret;
  352. /* Program the lookup table */
  353. ret = xgbe_write_rss_lookup_table(pdata);
  354. if (ret)
  355. return ret;
  356. /* Set the RSS options */
  357. XGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options);
  358. /* Enable RSS */
  359. XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 1);
  360. return 0;
  361. }
  362. static int xgbe_disable_rss(struct xgbe_prv_data *pdata)
  363. {
  364. if (!pdata->hw_feat.rss)
  365. return -EOPNOTSUPP;
  366. XGMAC_IOWRITE_BITS(pdata, MAC_RSSCR, RSSE, 0);
  367. return 0;
  368. }
  369. static void xgbe_config_rss(struct xgbe_prv_data *pdata)
  370. {
  371. int ret;
  372. if (!pdata->hw_feat.rss)
  373. return;
  374. if (pdata->netdev->features & NETIF_F_RXHASH)
  375. ret = xgbe_enable_rss(pdata);
  376. else
  377. ret = xgbe_disable_rss(pdata);
  378. if (ret)
  379. netdev_err(pdata->netdev,
  380. "error configuring RSS, RSS disabled\n");
  381. }
  382. static bool xgbe_is_pfc_queue(struct xgbe_prv_data *pdata,
  383. unsigned int queue)
  384. {
  385. unsigned int prio, tc;
  386. for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
  387. /* Does this queue handle the priority? */
  388. if (pdata->prio2q_map[prio] != queue)
  389. continue;
  390. /* Get the Traffic Class for this priority */
  391. tc = pdata->ets->prio_tc[prio];
  392. /* Check if PFC is enabled for this traffic class */
  393. if (pdata->pfc->pfc_en & (1 << tc))
  394. return true;
  395. }
  396. return false;
  397. }
  398. static void xgbe_set_vxlan_id(struct xgbe_prv_data *pdata)
  399. {
  400. /* Program the VXLAN port */
  401. XGMAC_IOWRITE_BITS(pdata, MAC_TIR, TNID, pdata->vxlan_port);
  402. netif_dbg(pdata, drv, pdata->netdev, "VXLAN tunnel id set to %hx\n",
  403. pdata->vxlan_port);
  404. }
  405. static void xgbe_enable_vxlan(struct xgbe_prv_data *pdata)
  406. {
  407. if (!pdata->hw_feat.vxn)
  408. return;
  409. /* Program the VXLAN port */
  410. xgbe_set_vxlan_id(pdata);
  411. /* Allow for IPv6/UDP zero-checksum VXLAN packets */
  412. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VUCC, 1);
  413. /* Enable VXLAN tunneling mode */
  414. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, VNM, 0);
  415. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, VNE, 1);
  416. netif_dbg(pdata, drv, pdata->netdev, "VXLAN acceleration enabled\n");
  417. }
  418. static void xgbe_disable_vxlan(struct xgbe_prv_data *pdata)
  419. {
  420. if (!pdata->hw_feat.vxn)
  421. return;
  422. /* Disable tunneling mode */
  423. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, VNE, 0);
  424. /* Clear IPv6/UDP zero-checksum VXLAN packets setting */
  425. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VUCC, 0);
  426. /* Clear the VXLAN port */
  427. XGMAC_IOWRITE_BITS(pdata, MAC_TIR, TNID, 0);
  428. netif_dbg(pdata, drv, pdata->netdev, "VXLAN acceleration disabled\n");
  429. }
  430. static unsigned int xgbe_get_fc_queue_count(struct xgbe_prv_data *pdata)
  431. {
  432. unsigned int max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
  433. /* From MAC ver 30H the TFCR is per priority, instead of per queue */
  434. if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) >= 0x30)
  435. return max_q_count;
  436. else
  437. return min_t(unsigned int, pdata->tx_q_count, max_q_count);
  438. }
  439. static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
  440. {
  441. unsigned int reg, reg_val;
  442. unsigned int i, q_count;
  443. /* Clear MTL flow control */
  444. for (i = 0; i < pdata->rx_q_count; i++)
  445. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
  446. /* Clear MAC flow control */
  447. q_count = xgbe_get_fc_queue_count(pdata);
  448. reg = MAC_Q0TFCR;
  449. for (i = 0; i < q_count; i++) {
  450. reg_val = XGMAC_IOREAD(pdata, reg);
  451. XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
  452. XGMAC_IOWRITE(pdata, reg, reg_val);
  453. reg += MAC_QTFCR_INC;
  454. }
  455. return 0;
  456. }
  457. static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
  458. {
  459. struct ieee_pfc *pfc = pdata->pfc;
  460. struct ieee_ets *ets = pdata->ets;
  461. unsigned int reg, reg_val;
  462. unsigned int i, q_count;
  463. /* Set MTL flow control */
  464. for (i = 0; i < pdata->rx_q_count; i++) {
  465. unsigned int ehfc = 0;
  466. if (pdata->rx_rfd[i]) {
  467. /* Flow control thresholds are established */
  468. if (pfc && ets) {
  469. if (xgbe_is_pfc_queue(pdata, i))
  470. ehfc = 1;
  471. } else {
  472. ehfc = 1;
  473. }
  474. }
  475. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, ehfc);
  476. netif_dbg(pdata, drv, pdata->netdev,
  477. "flow control %s for RXq%u\n",
  478. ehfc ? "enabled" : "disabled", i);
  479. }
  480. /* Set MAC flow control */
  481. q_count = xgbe_get_fc_queue_count(pdata);
  482. reg = MAC_Q0TFCR;
  483. for (i = 0; i < q_count; i++) {
  484. reg_val = XGMAC_IOREAD(pdata, reg);
  485. /* Enable transmit flow control */
  486. XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
  487. /* Set pause time */
  488. XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
  489. XGMAC_IOWRITE(pdata, reg, reg_val);
  490. reg += MAC_QTFCR_INC;
  491. }
  492. return 0;
  493. }
  494. static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
  495. {
  496. XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
  497. return 0;
  498. }
  499. static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
  500. {
  501. XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
  502. return 0;
  503. }
  504. static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
  505. {
  506. struct ieee_pfc *pfc = pdata->pfc;
  507. if (pdata->tx_pause || (pfc && pfc->pfc_en))
  508. xgbe_enable_tx_flow_control(pdata);
  509. else
  510. xgbe_disable_tx_flow_control(pdata);
  511. return 0;
  512. }
  513. static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
  514. {
  515. struct ieee_pfc *pfc = pdata->pfc;
  516. if (pdata->rx_pause || (pfc && pfc->pfc_en))
  517. xgbe_enable_rx_flow_control(pdata);
  518. else
  519. xgbe_disable_rx_flow_control(pdata);
  520. return 0;
  521. }
  522. static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
  523. {
  524. struct ieee_pfc *pfc = pdata->pfc;
  525. xgbe_config_tx_flow_control(pdata);
  526. xgbe_config_rx_flow_control(pdata);
  527. XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE,
  528. (pfc && pfc->pfc_en) ? 1 : 0);
  529. }
  530. static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
  531. {
  532. struct xgbe_channel *channel;
  533. unsigned int i, ver;
  534. /* Set the interrupt mode if supported */
  535. if (pdata->channel_irq_mode)
  536. XGMAC_IOWRITE_BITS(pdata, DMA_MR, INTM,
  537. pdata->channel_irq_mode);
  538. ver = XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER);
  539. for (i = 0; i < pdata->channel_count; i++) {
  540. channel = pdata->channel[i];
  541. /* Clear all the interrupts which are set */
  542. XGMAC_DMA_IOWRITE(channel, DMA_CH_SR,
  543. XGMAC_DMA_IOREAD(channel, DMA_CH_SR));
  544. /* Clear all interrupt enable bits */
  545. channel->curr_ier = 0;
  546. /* Enable following interrupts
  547. * NIE - Normal Interrupt Summary Enable
  548. * AIE - Abnormal Interrupt Summary Enable
  549. * FBEE - Fatal Bus Error Enable
  550. */
  551. if (ver < 0x21) {
  552. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, NIE20, 1);
  553. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, AIE20, 1);
  554. } else {
  555. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, NIE, 1);
  556. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, AIE, 1);
  557. }
  558. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, FBEE, 1);
  559. if (channel->tx_ring) {
  560. /* Enable the following Tx interrupts
  561. * TIE - Transmit Interrupt Enable (unless using
  562. * per channel interrupts in edge triggered
  563. * mode)
  564. */
  565. if (!pdata->per_channel_irq || pdata->channel_irq_mode)
  566. XGMAC_SET_BITS(channel->curr_ier,
  567. DMA_CH_IER, TIE, 1);
  568. }
  569. if (channel->rx_ring) {
  570. /* Enable following Rx interrupts
  571. * RBUE - Receive Buffer Unavailable Enable
  572. * RIE - Receive Interrupt Enable (unless using
  573. * per channel interrupts in edge triggered
  574. * mode)
  575. */
  576. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RBUE, 1);
  577. if (!pdata->per_channel_irq || pdata->channel_irq_mode)
  578. XGMAC_SET_BITS(channel->curr_ier,
  579. DMA_CH_IER, RIE, 1);
  580. }
  581. XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, channel->curr_ier);
  582. }
  583. }
  584. static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
  585. {
  586. unsigned int mtl_q_isr;
  587. unsigned int q_count, i;
  588. q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
  589. for (i = 0; i < q_count; i++) {
  590. /* Clear all the interrupts which are set */
  591. mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
  592. XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
  593. /* No MTL interrupts to be enabled */
  594. XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
  595. }
  596. }
  597. static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
  598. {
  599. unsigned int mac_ier = 0;
  600. /* Enable Timestamp interrupt */
  601. XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
  602. XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
  603. /* Enable all counter interrupts */
  604. XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff);
  605. XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff);
  606. /* Enable MDIO single command completion interrupt */
  607. XGMAC_IOWRITE_BITS(pdata, MAC_MDIOIER, SNGLCOMPIE, 1);
  608. }
  609. static void xgbe_enable_ecc_interrupts(struct xgbe_prv_data *pdata)
  610. {
  611. unsigned int ecc_isr, ecc_ier = 0;
  612. if (!pdata->vdata->ecc_support)
  613. return;
  614. /* Clear all the interrupts which are set */
  615. ecc_isr = XP_IOREAD(pdata, XP_ECC_ISR);
  616. XP_IOWRITE(pdata, XP_ECC_ISR, ecc_isr);
  617. /* Enable ECC interrupts */
  618. XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_DED, 1);
  619. XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_SEC, 1);
  620. XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_DED, 1);
  621. XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_SEC, 1);
  622. XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_DED, 1);
  623. XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_SEC, 1);
  624. XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier);
  625. }
  626. static void xgbe_disable_ecc_ded(struct xgbe_prv_data *pdata)
  627. {
  628. unsigned int ecc_ier;
  629. ecc_ier = XP_IOREAD(pdata, XP_ECC_IER);
  630. /* Disable ECC DED interrupts */
  631. XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_DED, 0);
  632. XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_DED, 0);
  633. XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_DED, 0);
  634. XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier);
  635. }
  636. static void xgbe_disable_ecc_sec(struct xgbe_prv_data *pdata,
  637. enum xgbe_ecc_sec sec)
  638. {
  639. unsigned int ecc_ier;
  640. ecc_ier = XP_IOREAD(pdata, XP_ECC_IER);
  641. /* Disable ECC SEC interrupt */
  642. switch (sec) {
  643. case XGBE_ECC_SEC_TX:
  644. XP_SET_BITS(ecc_ier, XP_ECC_IER, TX_SEC, 0);
  645. break;
  646. case XGBE_ECC_SEC_RX:
  647. XP_SET_BITS(ecc_ier, XP_ECC_IER, RX_SEC, 0);
  648. break;
  649. case XGBE_ECC_SEC_DESC:
  650. XP_SET_BITS(ecc_ier, XP_ECC_IER, DESC_SEC, 0);
  651. break;
  652. }
  653. XP_IOWRITE(pdata, XP_ECC_IER, ecc_ier);
  654. }
  655. static int xgbe_set_speed(struct xgbe_prv_data *pdata, int speed)
  656. {
  657. unsigned int ss;
  658. switch (speed) {
  659. case SPEED_10:
  660. ss = 0x07;
  661. break;
  662. case SPEED_1000:
  663. ss = 0x03;
  664. break;
  665. case SPEED_2500:
  666. ss = 0x02;
  667. break;
  668. case SPEED_10000:
  669. ss = 0x00;
  670. break;
  671. default:
  672. return -EINVAL;
  673. }
  674. if (XGMAC_IOREAD_BITS(pdata, MAC_TCR, SS) != ss)
  675. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, ss);
  676. return 0;
  677. }
  678. static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
  679. {
  680. /* Put the VLAN tag in the Rx descriptor */
  681. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
  682. /* Don't check the VLAN type */
  683. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
  684. /* Check only C-TAG (0x8100) packets */
  685. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
  686. /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
  687. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
  688. /* Enable VLAN tag stripping */
  689. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
  690. return 0;
  691. }
  692. static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
  693. {
  694. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
  695. return 0;
  696. }
  697. static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
  698. {
  699. /* Enable VLAN filtering */
  700. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
  701. /* Enable VLAN Hash Table filtering */
  702. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
  703. /* Disable VLAN tag inverse matching */
  704. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
  705. /* Only filter on the lower 12-bits of the VLAN tag */
  706. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
  707. /* In order for the VLAN Hash Table filtering to be effective,
  708. * the VLAN tag identifier in the VLAN Tag Register must not
  709. * be zero. Set the VLAN tag identifier to "1" to enable the
  710. * VLAN Hash Table filtering. This implies that a VLAN tag of
  711. * 1 will always pass filtering.
  712. */
  713. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
  714. return 0;
  715. }
  716. static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
  717. {
  718. /* Disable VLAN filtering */
  719. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
  720. return 0;
  721. }
  722. static u32 xgbe_vid_crc32_le(__le16 vid_le)
  723. {
  724. u32 crc = ~0;
  725. u32 temp = 0;
  726. unsigned char *data = (unsigned char *)&vid_le;
  727. unsigned char data_byte = 0;
  728. int i, bits;
  729. bits = get_bitmask_order(VLAN_VID_MASK);
  730. for (i = 0; i < bits; i++) {
  731. if ((i % 8) == 0)
  732. data_byte = data[i / 8];
  733. temp = ((crc & 1) ^ data_byte) & 1;
  734. crc >>= 1;
  735. data_byte >>= 1;
  736. if (temp)
  737. crc ^= CRC32_POLY_LE;
  738. }
  739. return crc;
  740. }
  741. static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
  742. {
  743. u32 crc;
  744. u16 vid;
  745. __le16 vid_le;
  746. u16 vlan_hash_table = 0;
  747. /* Generate the VLAN Hash Table value */
  748. for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
  749. /* Get the CRC32 value of the VLAN ID */
  750. vid_le = cpu_to_le16(vid);
  751. crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
  752. vlan_hash_table |= (1 << crc);
  753. }
  754. /* Set the VLAN Hash Table filtering register */
  755. XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
  756. return 0;
  757. }
  758. static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
  759. unsigned int enable)
  760. {
  761. unsigned int val = enable ? 1 : 0;
  762. if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
  763. return 0;
  764. netif_dbg(pdata, drv, pdata->netdev, "%s promiscuous mode\n",
  765. enable ? "entering" : "leaving");
  766. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
  767. /* Hardware will still perform VLAN filtering in promiscuous mode */
  768. if (enable) {
  769. xgbe_disable_rx_vlan_filtering(pdata);
  770. } else {
  771. if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
  772. xgbe_enable_rx_vlan_filtering(pdata);
  773. }
  774. return 0;
  775. }
  776. static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
  777. unsigned int enable)
  778. {
  779. unsigned int val = enable ? 1 : 0;
  780. if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
  781. return 0;
  782. netif_dbg(pdata, drv, pdata->netdev, "%s allmulti mode\n",
  783. enable ? "entering" : "leaving");
  784. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
  785. return 0;
  786. }
  787. static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
  788. struct netdev_hw_addr *ha, unsigned int *mac_reg)
  789. {
  790. unsigned int mac_addr_hi, mac_addr_lo;
  791. u8 *mac_addr;
  792. mac_addr_lo = 0;
  793. mac_addr_hi = 0;
  794. if (ha) {
  795. mac_addr = (u8 *)&mac_addr_lo;
  796. mac_addr[0] = ha->addr[0];
  797. mac_addr[1] = ha->addr[1];
  798. mac_addr[2] = ha->addr[2];
  799. mac_addr[3] = ha->addr[3];
  800. mac_addr = (u8 *)&mac_addr_hi;
  801. mac_addr[0] = ha->addr[4];
  802. mac_addr[1] = ha->addr[5];
  803. netif_dbg(pdata, drv, pdata->netdev,
  804. "adding mac address %pM at %#x\n",
  805. ha->addr, *mac_reg);
  806. XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
  807. }
  808. XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
  809. *mac_reg += MAC_MACA_INC;
  810. XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
  811. *mac_reg += MAC_MACA_INC;
  812. }
  813. static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
  814. {
  815. struct net_device *netdev = pdata->netdev;
  816. struct netdev_hw_addr *ha;
  817. unsigned int mac_reg;
  818. unsigned int addn_macs;
  819. mac_reg = MAC_MACA1HR;
  820. addn_macs = pdata->hw_feat.addn_mac;
  821. if (netdev_uc_count(netdev) > addn_macs) {
  822. xgbe_set_promiscuous_mode(pdata, 1);
  823. } else {
  824. netdev_for_each_uc_addr(ha, netdev) {
  825. xgbe_set_mac_reg(pdata, ha, &mac_reg);
  826. addn_macs--;
  827. }
  828. if (netdev_mc_count(netdev) > addn_macs) {
  829. xgbe_set_all_multicast_mode(pdata, 1);
  830. } else {
  831. netdev_for_each_mc_addr(ha, netdev) {
  832. xgbe_set_mac_reg(pdata, ha, &mac_reg);
  833. addn_macs--;
  834. }
  835. }
  836. }
  837. /* Clear remaining additional MAC address entries */
  838. while (addn_macs--)
  839. xgbe_set_mac_reg(pdata, NULL, &mac_reg);
  840. }
  841. static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
  842. {
  843. struct net_device *netdev = pdata->netdev;
  844. struct netdev_hw_addr *ha;
  845. unsigned int hash_reg;
  846. unsigned int hash_table_shift, hash_table_count;
  847. u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
  848. u32 crc;
  849. unsigned int i;
  850. hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
  851. hash_table_count = pdata->hw_feat.hash_table_size / 32;
  852. memset(hash_table, 0, sizeof(hash_table));
  853. /* Build the MAC Hash Table register values */
  854. netdev_for_each_uc_addr(ha, netdev) {
  855. crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
  856. crc >>= hash_table_shift;
  857. hash_table[crc >> 5] |= (1 << (crc & 0x1f));
  858. }
  859. netdev_for_each_mc_addr(ha, netdev) {
  860. crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
  861. crc >>= hash_table_shift;
  862. hash_table[crc >> 5] |= (1 << (crc & 0x1f));
  863. }
  864. /* Set the MAC Hash Table registers */
  865. hash_reg = MAC_HTR0;
  866. for (i = 0; i < hash_table_count; i++) {
  867. XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
  868. hash_reg += MAC_HTR_INC;
  869. }
  870. }
  871. static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
  872. {
  873. if (pdata->hw_feat.hash_table_size)
  874. xgbe_set_mac_hash_table(pdata);
  875. else
  876. xgbe_set_mac_addn_addrs(pdata);
  877. return 0;
  878. }
  879. static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, const u8 *addr)
  880. {
  881. unsigned int mac_addr_hi, mac_addr_lo;
  882. mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
  883. mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
  884. (addr[1] << 8) | (addr[0] << 0);
  885. XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
  886. XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
  887. return 0;
  888. }
  889. static int xgbe_config_rx_mode(struct xgbe_prv_data *pdata)
  890. {
  891. struct net_device *netdev = pdata->netdev;
  892. unsigned int pr_mode, am_mode;
  893. pr_mode = ((netdev->flags & IFF_PROMISC) != 0);
  894. am_mode = ((netdev->flags & IFF_ALLMULTI) != 0);
  895. xgbe_set_promiscuous_mode(pdata, pr_mode);
  896. xgbe_set_all_multicast_mode(pdata, am_mode);
  897. xgbe_add_mac_addresses(pdata);
  898. return 0;
  899. }
  900. static int xgbe_clr_gpio(struct xgbe_prv_data *pdata, unsigned int gpio)
  901. {
  902. unsigned int reg;
  903. if (gpio > 15)
  904. return -EINVAL;
  905. reg = XGMAC_IOREAD(pdata, MAC_GPIOSR);
  906. reg &= ~(1 << (gpio + 16));
  907. XGMAC_IOWRITE(pdata, MAC_GPIOSR, reg);
  908. return 0;
  909. }
  910. static int xgbe_set_gpio(struct xgbe_prv_data *pdata, unsigned int gpio)
  911. {
  912. unsigned int reg;
  913. if (gpio > 15)
  914. return -EINVAL;
  915. reg = XGMAC_IOREAD(pdata, MAC_GPIOSR);
  916. reg |= (1 << (gpio + 16));
  917. XGMAC_IOWRITE(pdata, MAC_GPIOSR, reg);
  918. return 0;
  919. }
  920. static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,
  921. int mmd_reg)
  922. {
  923. unsigned long flags;
  924. unsigned int mmd_address, index, offset;
  925. int mmd_data;
  926. if (mmd_reg & XGBE_ADDR_C45)
  927. mmd_address = mmd_reg & ~XGBE_ADDR_C45;
  928. else
  929. mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
  930. /* The PCS registers are accessed using mmio. The underlying
  931. * management interface uses indirect addressing to access the MMD
  932. * register sets. This requires accessing of the PCS register in two
  933. * phases, an address phase and a data phase.
  934. *
  935. * The mmio interface is based on 16-bit offsets and values. All
  936. * register offsets must therefore be adjusted by left shifting the
  937. * offset 1 bit and reading 16 bits of data.
  938. */
  939. mmd_address <<= 1;
  940. index = mmd_address & ~pdata->xpcs_window_mask;
  941. offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask);
  942. spin_lock_irqsave(&pdata->xpcs_lock, flags);
  943. XPCS32_IOWRITE(pdata, pdata->xpcs_window_sel_reg, index);
  944. mmd_data = XPCS16_IOREAD(pdata, offset);
  945. spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
  946. return mmd_data;
  947. }
  948. static void xgbe_write_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,
  949. int mmd_reg, int mmd_data)
  950. {
  951. unsigned long flags;
  952. unsigned int mmd_address, index, offset;
  953. if (mmd_reg & XGBE_ADDR_C45)
  954. mmd_address = mmd_reg & ~XGBE_ADDR_C45;
  955. else
  956. mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
  957. /* The PCS registers are accessed using mmio. The underlying
  958. * management interface uses indirect addressing to access the MMD
  959. * register sets. This requires accessing of the PCS register in two
  960. * phases, an address phase and a data phase.
  961. *
  962. * The mmio interface is based on 16-bit offsets and values. All
  963. * register offsets must therefore be adjusted by left shifting the
  964. * offset 1 bit and writing 16 bits of data.
  965. */
  966. mmd_address <<= 1;
  967. index = mmd_address & ~pdata->xpcs_window_mask;
  968. offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask);
  969. spin_lock_irqsave(&pdata->xpcs_lock, flags);
  970. XPCS32_IOWRITE(pdata, pdata->xpcs_window_sel_reg, index);
  971. XPCS16_IOWRITE(pdata, offset, mmd_data);
  972. spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
  973. }
  974. static int xgbe_read_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,
  975. int mmd_reg)
  976. {
  977. unsigned long flags;
  978. unsigned int mmd_address;
  979. int mmd_data;
  980. if (mmd_reg & XGBE_ADDR_C45)
  981. mmd_address = mmd_reg & ~XGBE_ADDR_C45;
  982. else
  983. mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
  984. /* The PCS registers are accessed using mmio. The underlying APB3
  985. * management interface uses indirect addressing to access the MMD
  986. * register sets. This requires accessing of the PCS register in two
  987. * phases, an address phase and a data phase.
  988. *
  989. * The mmio interface is based on 32-bit offsets and values. All
  990. * register offsets must therefore be adjusted by left shifting the
  991. * offset 2 bits and reading 32 bits of data.
  992. */
  993. spin_lock_irqsave(&pdata->xpcs_lock, flags);
  994. XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8);
  995. mmd_data = XPCS32_IOREAD(pdata, (mmd_address & 0xff) << 2);
  996. spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
  997. return mmd_data;
  998. }
  999. static void xgbe_write_mmd_regs_v1(struct xgbe_prv_data *pdata, int prtad,
  1000. int mmd_reg, int mmd_data)
  1001. {
  1002. unsigned int mmd_address;
  1003. unsigned long flags;
  1004. if (mmd_reg & XGBE_ADDR_C45)
  1005. mmd_address = mmd_reg & ~XGBE_ADDR_C45;
  1006. else
  1007. mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
  1008. /* The PCS registers are accessed using mmio. The underlying APB3
  1009. * management interface uses indirect addressing to access the MMD
  1010. * register sets. This requires accessing of the PCS register in two
  1011. * phases, an address phase and a data phase.
  1012. *
  1013. * The mmio interface is based on 32-bit offsets and values. All
  1014. * register offsets must therefore be adjusted by left shifting the
  1015. * offset 2 bits and writing 32 bits of data.
  1016. */
  1017. spin_lock_irqsave(&pdata->xpcs_lock, flags);
  1018. XPCS32_IOWRITE(pdata, PCS_V1_WINDOW_SELECT, mmd_address >> 8);
  1019. XPCS32_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
  1020. spin_unlock_irqrestore(&pdata->xpcs_lock, flags);
  1021. }
  1022. static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
  1023. int mmd_reg)
  1024. {
  1025. switch (pdata->vdata->xpcs_access) {
  1026. case XGBE_XPCS_ACCESS_V1:
  1027. return xgbe_read_mmd_regs_v1(pdata, prtad, mmd_reg);
  1028. case XGBE_XPCS_ACCESS_V2:
  1029. default:
  1030. return xgbe_read_mmd_regs_v2(pdata, prtad, mmd_reg);
  1031. }
  1032. }
  1033. static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
  1034. int mmd_reg, int mmd_data)
  1035. {
  1036. switch (pdata->vdata->xpcs_access) {
  1037. case XGBE_XPCS_ACCESS_V1:
  1038. return xgbe_write_mmd_regs_v1(pdata, prtad, mmd_reg, mmd_data);
  1039. case XGBE_XPCS_ACCESS_V2:
  1040. default:
  1041. return xgbe_write_mmd_regs_v2(pdata, prtad, mmd_reg, mmd_data);
  1042. }
  1043. }
  1044. static unsigned int xgbe_create_mdio_sca_c22(int port, int reg)
  1045. {
  1046. unsigned int mdio_sca;
  1047. mdio_sca = 0;
  1048. XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, RA, reg);
  1049. XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, PA, port);
  1050. return mdio_sca;
  1051. }
  1052. static unsigned int xgbe_create_mdio_sca_c45(int port, unsigned int da, int reg)
  1053. {
  1054. unsigned int mdio_sca;
  1055. mdio_sca = 0;
  1056. XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, RA, reg);
  1057. XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, PA, port);
  1058. XGMAC_SET_BITS(mdio_sca, MAC_MDIOSCAR, DA, da);
  1059. return mdio_sca;
  1060. }
  1061. static int xgbe_write_ext_mii_regs(struct xgbe_prv_data *pdata,
  1062. unsigned int mdio_sca, u16 val)
  1063. {
  1064. unsigned int mdio_sccd;
  1065. reinit_completion(&pdata->mdio_complete);
  1066. XGMAC_IOWRITE(pdata, MAC_MDIOSCAR, mdio_sca);
  1067. mdio_sccd = 0;
  1068. XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, DATA, val);
  1069. XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, CMD, 1);
  1070. XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, BUSY, 1);
  1071. XGMAC_IOWRITE(pdata, MAC_MDIOSCCDR, mdio_sccd);
  1072. if (!wait_for_completion_timeout(&pdata->mdio_complete, HZ)) {
  1073. netdev_err(pdata->netdev, "mdio write operation timed out\n");
  1074. return -ETIMEDOUT;
  1075. }
  1076. return 0;
  1077. }
  1078. static int xgbe_write_ext_mii_regs_c22(struct xgbe_prv_data *pdata, int addr,
  1079. int reg, u16 val)
  1080. {
  1081. unsigned int mdio_sca;
  1082. mdio_sca = xgbe_create_mdio_sca_c22(addr, reg);
  1083. return xgbe_write_ext_mii_regs(pdata, mdio_sca, val);
  1084. }
  1085. static int xgbe_write_ext_mii_regs_c45(struct xgbe_prv_data *pdata, int addr,
  1086. int devad, int reg, u16 val)
  1087. {
  1088. unsigned int mdio_sca;
  1089. mdio_sca = xgbe_create_mdio_sca_c45(addr, devad, reg);
  1090. return xgbe_write_ext_mii_regs(pdata, mdio_sca, val);
  1091. }
  1092. static int xgbe_read_ext_mii_regs(struct xgbe_prv_data *pdata,
  1093. unsigned int mdio_sca)
  1094. {
  1095. unsigned int mdio_sccd;
  1096. reinit_completion(&pdata->mdio_complete);
  1097. XGMAC_IOWRITE(pdata, MAC_MDIOSCAR, mdio_sca);
  1098. mdio_sccd = 0;
  1099. XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, CMD, 3);
  1100. XGMAC_SET_BITS(mdio_sccd, MAC_MDIOSCCDR, BUSY, 1);
  1101. XGMAC_IOWRITE(pdata, MAC_MDIOSCCDR, mdio_sccd);
  1102. if (!wait_for_completion_timeout(&pdata->mdio_complete, HZ)) {
  1103. netdev_err(pdata->netdev, "mdio read operation timed out\n");
  1104. return -ETIMEDOUT;
  1105. }
  1106. return XGMAC_IOREAD_BITS(pdata, MAC_MDIOSCCDR, DATA);
  1107. }
  1108. static int xgbe_read_ext_mii_regs_c22(struct xgbe_prv_data *pdata, int addr,
  1109. int reg)
  1110. {
  1111. unsigned int mdio_sca;
  1112. mdio_sca = xgbe_create_mdio_sca_c22(addr, reg);
  1113. return xgbe_read_ext_mii_regs(pdata, mdio_sca);
  1114. }
  1115. static int xgbe_read_ext_mii_regs_c45(struct xgbe_prv_data *pdata, int addr,
  1116. int devad, int reg)
  1117. {
  1118. unsigned int mdio_sca;
  1119. mdio_sca = xgbe_create_mdio_sca_c45(addr, devad, reg);
  1120. return xgbe_read_ext_mii_regs(pdata, mdio_sca);
  1121. }
  1122. static int xgbe_set_ext_mii_mode(struct xgbe_prv_data *pdata, unsigned int port,
  1123. enum xgbe_mdio_mode mode)
  1124. {
  1125. unsigned int reg_val = XGMAC_IOREAD(pdata, MAC_MDIOCL22R);
  1126. switch (mode) {
  1127. case XGBE_MDIO_MODE_CL22:
  1128. if (port > XGMAC_MAX_C22_PORT)
  1129. return -EINVAL;
  1130. reg_val |= (1 << port);
  1131. break;
  1132. case XGBE_MDIO_MODE_CL45:
  1133. break;
  1134. default:
  1135. return -EINVAL;
  1136. }
  1137. XGMAC_IOWRITE(pdata, MAC_MDIOCL22R, reg_val);
  1138. return 0;
  1139. }
  1140. static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
  1141. {
  1142. return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
  1143. }
  1144. static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
  1145. {
  1146. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
  1147. return 0;
  1148. }
  1149. static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
  1150. {
  1151. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
  1152. return 0;
  1153. }
  1154. static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
  1155. {
  1156. struct xgbe_ring_desc *rdesc = rdata->rdesc;
  1157. /* Reset the Tx descriptor
  1158. * Set buffer 1 (lo) address to zero
  1159. * Set buffer 1 (hi) address to zero
  1160. * Reset all other control bits (IC, TTSE, B2L & B1L)
  1161. * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
  1162. */
  1163. rdesc->desc0 = 0;
  1164. rdesc->desc1 = 0;
  1165. rdesc->desc2 = 0;
  1166. rdesc->desc3 = 0;
  1167. /* Make sure ownership is written to the descriptor */
  1168. dma_wmb();
  1169. }
  1170. static void xgbe_tx_desc_init(struct xgbe_channel *channel)
  1171. {
  1172. struct xgbe_ring *ring = channel->tx_ring;
  1173. struct xgbe_ring_data *rdata;
  1174. int i;
  1175. int start_index = ring->cur;
  1176. DBGPR("-->tx_desc_init\n");
  1177. /* Initialze all descriptors */
  1178. for (i = 0; i < ring->rdesc_count; i++) {
  1179. rdata = XGBE_GET_DESC_DATA(ring, i);
  1180. /* Initialize Tx descriptor */
  1181. xgbe_tx_desc_reset(rdata);
  1182. }
  1183. /* Update the total number of Tx descriptors */
  1184. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
  1185. /* Update the starting address of descriptor ring */
  1186. rdata = XGBE_GET_DESC_DATA(ring, start_index);
  1187. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
  1188. upper_32_bits(rdata->rdesc_dma));
  1189. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
  1190. lower_32_bits(rdata->rdesc_dma));
  1191. DBGPR("<--tx_desc_init\n");
  1192. }
  1193. static void xgbe_rx_desc_reset(struct xgbe_prv_data *pdata,
  1194. struct xgbe_ring_data *rdata, unsigned int index)
  1195. {
  1196. struct xgbe_ring_desc *rdesc = rdata->rdesc;
  1197. unsigned int rx_usecs = pdata->rx_usecs;
  1198. unsigned int rx_frames = pdata->rx_frames;
  1199. unsigned int inte;
  1200. dma_addr_t hdr_dma, buf_dma;
  1201. if (!rx_usecs && !rx_frames) {
  1202. /* No coalescing, interrupt for every descriptor */
  1203. inte = 1;
  1204. } else {
  1205. /* Set interrupt based on Rx frame coalescing setting */
  1206. if (rx_frames && !((index + 1) % rx_frames))
  1207. inte = 1;
  1208. else
  1209. inte = 0;
  1210. }
  1211. /* Reset the Rx descriptor
  1212. * Set buffer 1 (lo) address to header dma address (lo)
  1213. * Set buffer 1 (hi) address to header dma address (hi)
  1214. * Set buffer 2 (lo) address to buffer dma address (lo)
  1215. * Set buffer 2 (hi) address to buffer dma address (hi) and
  1216. * set control bits OWN and INTE
  1217. */
  1218. hdr_dma = rdata->rx.hdr.dma_base + rdata->rx.hdr.dma_off;
  1219. buf_dma = rdata->rx.buf.dma_base + rdata->rx.buf.dma_off;
  1220. rdesc->desc0 = cpu_to_le32(lower_32_bits(hdr_dma));
  1221. rdesc->desc1 = cpu_to_le32(upper_32_bits(hdr_dma));
  1222. rdesc->desc2 = cpu_to_le32(lower_32_bits(buf_dma));
  1223. rdesc->desc3 = cpu_to_le32(upper_32_bits(buf_dma));
  1224. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, inte);
  1225. /* Since the Rx DMA engine is likely running, make sure everything
  1226. * is written to the descriptor(s) before setting the OWN bit
  1227. * for the descriptor
  1228. */
  1229. dma_wmb();
  1230. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
  1231. /* Make sure ownership is written to the descriptor */
  1232. dma_wmb();
  1233. }
  1234. static void xgbe_rx_desc_init(struct xgbe_channel *channel)
  1235. {
  1236. struct xgbe_prv_data *pdata = channel->pdata;
  1237. struct xgbe_ring *ring = channel->rx_ring;
  1238. struct xgbe_ring_data *rdata;
  1239. unsigned int start_index = ring->cur;
  1240. unsigned int i;
  1241. DBGPR("-->rx_desc_init\n");
  1242. /* Initialize all descriptors */
  1243. for (i = 0; i < ring->rdesc_count; i++) {
  1244. rdata = XGBE_GET_DESC_DATA(ring, i);
  1245. /* Initialize Rx descriptor */
  1246. xgbe_rx_desc_reset(pdata, rdata, i);
  1247. }
  1248. /* Update the total number of Rx descriptors */
  1249. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
  1250. /* Update the starting address of descriptor ring */
  1251. rdata = XGBE_GET_DESC_DATA(ring, start_index);
  1252. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
  1253. upper_32_bits(rdata->rdesc_dma));
  1254. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
  1255. lower_32_bits(rdata->rdesc_dma));
  1256. /* Update the Rx Descriptor Tail Pointer */
  1257. rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
  1258. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
  1259. lower_32_bits(rdata->rdesc_dma));
  1260. DBGPR("<--rx_desc_init\n");
  1261. }
  1262. static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
  1263. unsigned int addend)
  1264. {
  1265. unsigned int count = 10000;
  1266. /* Set the addend register value and tell the device */
  1267. XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
  1268. XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
  1269. /* Wait for addend update to complete */
  1270. while (--count && XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
  1271. udelay(5);
  1272. if (!count)
  1273. netdev_err(pdata->netdev,
  1274. "timed out updating timestamp addend register\n");
  1275. }
  1276. static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
  1277. unsigned int nsec)
  1278. {
  1279. unsigned int count = 10000;
  1280. /* Set the time values and tell the device */
  1281. XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
  1282. XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
  1283. XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
  1284. /* Wait for time update to complete */
  1285. while (--count && XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
  1286. udelay(5);
  1287. if (!count)
  1288. netdev_err(pdata->netdev, "timed out initializing timestamp\n");
  1289. }
  1290. static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
  1291. {
  1292. u64 nsec;
  1293. nsec = XGMAC_IOREAD(pdata, MAC_STSR);
  1294. nsec *= NSEC_PER_SEC;
  1295. nsec += XGMAC_IOREAD(pdata, MAC_STNR);
  1296. return nsec;
  1297. }
  1298. static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
  1299. {
  1300. unsigned int tx_snr, tx_ssr;
  1301. u64 nsec;
  1302. if (pdata->vdata->tx_tstamp_workaround) {
  1303. tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
  1304. tx_ssr = XGMAC_IOREAD(pdata, MAC_TXSSR);
  1305. } else {
  1306. tx_ssr = XGMAC_IOREAD(pdata, MAC_TXSSR);
  1307. tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
  1308. }
  1309. if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
  1310. return 0;
  1311. nsec = tx_ssr;
  1312. nsec *= NSEC_PER_SEC;
  1313. nsec += tx_snr;
  1314. return nsec;
  1315. }
  1316. static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
  1317. struct xgbe_ring_desc *rdesc)
  1318. {
  1319. u64 nsec;
  1320. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
  1321. !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
  1322. nsec = le32_to_cpu(rdesc->desc1);
  1323. nsec <<= 32;
  1324. nsec |= le32_to_cpu(rdesc->desc0);
  1325. if (nsec != 0xffffffffffffffffULL) {
  1326. packet->rx_tstamp = nsec;
  1327. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1328. RX_TSTAMP, 1);
  1329. }
  1330. }
  1331. }
  1332. static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
  1333. unsigned int mac_tscr)
  1334. {
  1335. /* Set one nano-second accuracy */
  1336. XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
  1337. /* Set fine timestamp update */
  1338. XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
  1339. /* Overwrite earlier timestamps */
  1340. XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
  1341. XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
  1342. /* Exit if timestamping is not enabled */
  1343. if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
  1344. return 0;
  1345. /* Initialize time registers */
  1346. XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
  1347. XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
  1348. xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
  1349. xgbe_set_tstamp_time(pdata, 0, 0);
  1350. /* Initialize the timecounter */
  1351. timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
  1352. ktime_to_ns(ktime_get_real()));
  1353. return 0;
  1354. }
  1355. static void xgbe_tx_start_xmit(struct xgbe_channel *channel,
  1356. struct xgbe_ring *ring)
  1357. {
  1358. struct xgbe_prv_data *pdata = channel->pdata;
  1359. struct xgbe_ring_data *rdata;
  1360. /* Make sure everything is written before the register write */
  1361. wmb();
  1362. /* Issue a poll command to Tx DMA by writing address
  1363. * of next immediate free descriptor */
  1364. rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
  1365. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
  1366. lower_32_bits(rdata->rdesc_dma));
  1367. /* Start the Tx timer */
  1368. if (pdata->tx_usecs && !channel->tx_timer_active) {
  1369. channel->tx_timer_active = 1;
  1370. mod_timer(&channel->tx_timer,
  1371. jiffies + usecs_to_jiffies(pdata->tx_usecs));
  1372. }
  1373. ring->tx.xmit_more = 0;
  1374. }
  1375. static void xgbe_dev_xmit(struct xgbe_channel *channel)
  1376. {
  1377. struct xgbe_prv_data *pdata = channel->pdata;
  1378. struct xgbe_ring *ring = channel->tx_ring;
  1379. struct xgbe_ring_data *rdata;
  1380. struct xgbe_ring_desc *rdesc;
  1381. struct xgbe_packet_data *packet = &ring->packet_data;
  1382. unsigned int tx_packets, tx_bytes;
  1383. unsigned int csum, tso, vlan, vxlan;
  1384. unsigned int tso_context, vlan_context;
  1385. unsigned int tx_set_ic;
  1386. int start_index = ring->cur;
  1387. int cur_index = ring->cur;
  1388. int i;
  1389. DBGPR("-->xgbe_dev_xmit\n");
  1390. tx_packets = packet->tx_packets;
  1391. tx_bytes = packet->tx_bytes;
  1392. csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
  1393. CSUM_ENABLE);
  1394. tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
  1395. TSO_ENABLE);
  1396. vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
  1397. VLAN_CTAG);
  1398. vxlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
  1399. VXLAN);
  1400. if (tso && (packet->mss != ring->tx.cur_mss))
  1401. tso_context = 1;
  1402. else
  1403. tso_context = 0;
  1404. if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
  1405. vlan_context = 1;
  1406. else
  1407. vlan_context = 0;
  1408. /* Determine if an interrupt should be generated for this Tx:
  1409. * Interrupt:
  1410. * - Tx frame count exceeds the frame count setting
  1411. * - Addition of Tx frame count to the frame count since the
  1412. * last interrupt was set exceeds the frame count setting
  1413. * No interrupt:
  1414. * - No frame count setting specified (ethtool -C ethX tx-frames 0)
  1415. * - Addition of Tx frame count to the frame count since the
  1416. * last interrupt was set does not exceed the frame count setting
  1417. */
  1418. ring->coalesce_count += tx_packets;
  1419. if (!pdata->tx_frames)
  1420. tx_set_ic = 0;
  1421. else if (tx_packets > pdata->tx_frames)
  1422. tx_set_ic = 1;
  1423. else if ((ring->coalesce_count % pdata->tx_frames) < tx_packets)
  1424. tx_set_ic = 1;
  1425. else
  1426. tx_set_ic = 0;
  1427. rdata = XGBE_GET_DESC_DATA(ring, cur_index);
  1428. rdesc = rdata->rdesc;
  1429. /* Create a context descriptor if this is a TSO packet */
  1430. if (tso_context || vlan_context) {
  1431. if (tso_context) {
  1432. netif_dbg(pdata, tx_queued, pdata->netdev,
  1433. "TSO context descriptor, mss=%u\n",
  1434. packet->mss);
  1435. /* Set the MSS size */
  1436. XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
  1437. MSS, packet->mss);
  1438. /* Mark it as a CONTEXT descriptor */
  1439. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  1440. CTXT, 1);
  1441. /* Indicate this descriptor contains the MSS */
  1442. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  1443. TCMSSV, 1);
  1444. ring->tx.cur_mss = packet->mss;
  1445. }
  1446. if (vlan_context) {
  1447. netif_dbg(pdata, tx_queued, pdata->netdev,
  1448. "VLAN context descriptor, ctag=%u\n",
  1449. packet->vlan_ctag);
  1450. /* Mark it as a CONTEXT descriptor */
  1451. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  1452. CTXT, 1);
  1453. /* Set the VLAN tag */
  1454. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  1455. VT, packet->vlan_ctag);
  1456. /* Indicate this descriptor contains the VLAN tag */
  1457. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  1458. VLTV, 1);
  1459. ring->tx.cur_vlan_ctag = packet->vlan_ctag;
  1460. }
  1461. cur_index++;
  1462. rdata = XGBE_GET_DESC_DATA(ring, cur_index);
  1463. rdesc = rdata->rdesc;
  1464. }
  1465. /* Update buffer address (for TSO this is the header) */
  1466. rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
  1467. rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
  1468. /* Update the buffer length */
  1469. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
  1470. rdata->skb_dma_len);
  1471. /* VLAN tag insertion check */
  1472. if (vlan)
  1473. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
  1474. TX_NORMAL_DESC2_VLAN_INSERT);
  1475. /* Timestamp enablement check */
  1476. if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
  1477. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
  1478. /* Mark it as First Descriptor */
  1479. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
  1480. /* Mark it as a NORMAL descriptor */
  1481. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
  1482. /* Set OWN bit if not the first descriptor */
  1483. if (cur_index != start_index)
  1484. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
  1485. if (tso) {
  1486. /* Enable TSO */
  1487. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
  1488. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
  1489. packet->tcp_payload_len);
  1490. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
  1491. packet->tcp_header_len / 4);
  1492. pdata->ext_stats.tx_tso_packets += tx_packets;
  1493. } else {
  1494. /* Enable CRC and Pad Insertion */
  1495. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
  1496. /* Enable HW CSUM */
  1497. if (csum)
  1498. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
  1499. CIC, 0x3);
  1500. /* Set the total length to be transmitted */
  1501. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
  1502. packet->length);
  1503. }
  1504. if (vxlan) {
  1505. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, VNP,
  1506. TX_NORMAL_DESC3_VXLAN_PACKET);
  1507. pdata->ext_stats.tx_vxlan_packets += packet->tx_packets;
  1508. }
  1509. for (i = cur_index - start_index + 1; i < packet->rdesc_count; i++) {
  1510. cur_index++;
  1511. rdata = XGBE_GET_DESC_DATA(ring, cur_index);
  1512. rdesc = rdata->rdesc;
  1513. /* Update buffer address */
  1514. rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
  1515. rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
  1516. /* Update the buffer length */
  1517. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
  1518. rdata->skb_dma_len);
  1519. /* Set OWN bit */
  1520. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
  1521. /* Mark it as NORMAL descriptor */
  1522. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
  1523. /* Enable HW CSUM */
  1524. if (csum)
  1525. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
  1526. CIC, 0x3);
  1527. }
  1528. /* Set LAST bit for the last descriptor */
  1529. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
  1530. /* Set IC bit based on Tx coalescing settings */
  1531. if (tx_set_ic)
  1532. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
  1533. /* Save the Tx info to report back during cleanup */
  1534. rdata->tx.packets = tx_packets;
  1535. rdata->tx.bytes = tx_bytes;
  1536. pdata->ext_stats.txq_packets[channel->queue_index] += tx_packets;
  1537. pdata->ext_stats.txq_bytes[channel->queue_index] += tx_bytes;
  1538. /* In case the Tx DMA engine is running, make sure everything
  1539. * is written to the descriptor(s) before setting the OWN bit
  1540. * for the first descriptor
  1541. */
  1542. dma_wmb();
  1543. /* Set OWN bit for the first descriptor */
  1544. rdata = XGBE_GET_DESC_DATA(ring, start_index);
  1545. rdesc = rdata->rdesc;
  1546. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
  1547. if (netif_msg_tx_queued(pdata))
  1548. xgbe_dump_tx_desc(pdata, ring, start_index,
  1549. packet->rdesc_count, 1);
  1550. /* Make sure ownership is written to the descriptor */
  1551. smp_wmb();
  1552. ring->cur = cur_index + 1;
  1553. if (!netdev_xmit_more() ||
  1554. netif_xmit_stopped(netdev_get_tx_queue(pdata->netdev,
  1555. channel->queue_index)))
  1556. xgbe_tx_start_xmit(channel, ring);
  1557. else
  1558. ring->tx.xmit_more = 1;
  1559. DBGPR(" %s: descriptors %u to %u written\n",
  1560. channel->name, start_index & (ring->rdesc_count - 1),
  1561. (ring->cur - 1) & (ring->rdesc_count - 1));
  1562. DBGPR("<--xgbe_dev_xmit\n");
  1563. }
  1564. static int xgbe_dev_read(struct xgbe_channel *channel)
  1565. {
  1566. struct xgbe_prv_data *pdata = channel->pdata;
  1567. struct xgbe_ring *ring = channel->rx_ring;
  1568. struct xgbe_ring_data *rdata;
  1569. struct xgbe_ring_desc *rdesc;
  1570. struct xgbe_packet_data *packet = &ring->packet_data;
  1571. struct net_device *netdev = pdata->netdev;
  1572. unsigned int err, etlt, l34t;
  1573. DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
  1574. rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
  1575. rdesc = rdata->rdesc;
  1576. /* Check for data availability */
  1577. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
  1578. return 1;
  1579. /* Make sure descriptor fields are read after reading the OWN bit */
  1580. dma_rmb();
  1581. if (netif_msg_rx_status(pdata))
  1582. xgbe_dump_rx_desc(pdata, ring, ring->cur);
  1583. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
  1584. /* Timestamp Context Descriptor */
  1585. xgbe_get_rx_tstamp(packet, rdesc);
  1586. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1587. CONTEXT, 1);
  1588. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1589. CONTEXT_NEXT, 0);
  1590. return 0;
  1591. }
  1592. /* Normal Descriptor, be sure Context Descriptor bit is off */
  1593. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
  1594. /* Indicate if a Context Descriptor is next */
  1595. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
  1596. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1597. CONTEXT_NEXT, 1);
  1598. /* Get the header length */
  1599. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, FD)) {
  1600. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1601. FIRST, 1);
  1602. rdata->rx.hdr_len = XGMAC_GET_BITS_LE(rdesc->desc2,
  1603. RX_NORMAL_DESC2, HL);
  1604. if (rdata->rx.hdr_len)
  1605. pdata->ext_stats.rx_split_header_packets++;
  1606. } else {
  1607. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1608. FIRST, 0);
  1609. }
  1610. /* Get the RSS hash */
  1611. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, RSV)) {
  1612. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1613. RSS_HASH, 1);
  1614. packet->rss_hash = le32_to_cpu(rdesc->desc1);
  1615. l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T);
  1616. switch (l34t) {
  1617. case RX_DESC3_L34T_IPV4_TCP:
  1618. case RX_DESC3_L34T_IPV4_UDP:
  1619. case RX_DESC3_L34T_IPV6_TCP:
  1620. case RX_DESC3_L34T_IPV6_UDP:
  1621. packet->rss_hash_type = PKT_HASH_TYPE_L4;
  1622. break;
  1623. default:
  1624. packet->rss_hash_type = PKT_HASH_TYPE_L3;
  1625. }
  1626. }
  1627. /* Not all the data has been transferred for this packet */
  1628. if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD))
  1629. return 0;
  1630. /* This is the last of the data for this packet */
  1631. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1632. LAST, 1);
  1633. /* Get the packet length */
  1634. rdata->rx.len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
  1635. /* Set checksum done indicator as appropriate */
  1636. if (netdev->features & NETIF_F_RXCSUM) {
  1637. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1638. CSUM_DONE, 1);
  1639. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1640. TNPCSUM_DONE, 1);
  1641. }
  1642. /* Set the tunneled packet indicator */
  1643. if (XGMAC_GET_BITS_LE(rdesc->desc2, RX_NORMAL_DESC2, TNP)) {
  1644. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1645. TNP, 1);
  1646. pdata->ext_stats.rx_vxlan_packets++;
  1647. l34t = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, L34T);
  1648. switch (l34t) {
  1649. case RX_DESC3_L34T_IPV4_UNKNOWN:
  1650. case RX_DESC3_L34T_IPV6_UNKNOWN:
  1651. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1652. TNPCSUM_DONE, 0);
  1653. break;
  1654. }
  1655. }
  1656. /* Check for errors (only valid in last descriptor) */
  1657. err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
  1658. etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
  1659. netif_dbg(pdata, rx_status, netdev, "err=%u, etlt=%#x\n", err, etlt);
  1660. if (!err || !etlt) {
  1661. /* No error if err is 0 or etlt is 0 */
  1662. if ((etlt == 0x09) &&
  1663. (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
  1664. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1665. VLAN_CTAG, 1);
  1666. packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
  1667. RX_NORMAL_DESC0,
  1668. OVT);
  1669. netif_dbg(pdata, rx_status, netdev, "vlan-ctag=%#06x\n",
  1670. packet->vlan_ctag);
  1671. }
  1672. } else {
  1673. unsigned int tnp = XGMAC_GET_BITS(packet->attributes,
  1674. RX_PACKET_ATTRIBUTES, TNP);
  1675. if ((etlt == 0x05) || (etlt == 0x06)) {
  1676. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1677. CSUM_DONE, 0);
  1678. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1679. TNPCSUM_DONE, 0);
  1680. pdata->ext_stats.rx_csum_errors++;
  1681. } else if (tnp && ((etlt == 0x09) || (etlt == 0x0a))) {
  1682. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1683. CSUM_DONE, 0);
  1684. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1685. TNPCSUM_DONE, 0);
  1686. pdata->ext_stats.rx_vxlan_csum_errors++;
  1687. } else {
  1688. XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
  1689. FRAME, 1);
  1690. }
  1691. }
  1692. pdata->ext_stats.rxq_packets[channel->queue_index]++;
  1693. pdata->ext_stats.rxq_bytes[channel->queue_index] += rdata->rx.len;
  1694. DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
  1695. ring->cur & (ring->rdesc_count - 1), ring->cur);
  1696. return 0;
  1697. }
  1698. static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
  1699. {
  1700. /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
  1701. return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
  1702. }
  1703. static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
  1704. {
  1705. /* Rx and Tx share LD bit, so check TDES3.LD bit */
  1706. return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
  1707. }
  1708. static int xgbe_enable_int(struct xgbe_channel *channel,
  1709. enum xgbe_int int_id)
  1710. {
  1711. switch (int_id) {
  1712. case XGMAC_INT_DMA_CH_SR_TI:
  1713. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 1);
  1714. break;
  1715. case XGMAC_INT_DMA_CH_SR_TPS:
  1716. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TXSE, 1);
  1717. break;
  1718. case XGMAC_INT_DMA_CH_SR_TBU:
  1719. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TBUE, 1);
  1720. break;
  1721. case XGMAC_INT_DMA_CH_SR_RI:
  1722. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 1);
  1723. break;
  1724. case XGMAC_INT_DMA_CH_SR_RBU:
  1725. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RBUE, 1);
  1726. break;
  1727. case XGMAC_INT_DMA_CH_SR_RPS:
  1728. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RSE, 1);
  1729. break;
  1730. case XGMAC_INT_DMA_CH_SR_TI_RI:
  1731. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 1);
  1732. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 1);
  1733. break;
  1734. case XGMAC_INT_DMA_CH_SR_FBE:
  1735. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, FBEE, 1);
  1736. break;
  1737. case XGMAC_INT_DMA_ALL:
  1738. channel->curr_ier |= channel->saved_ier;
  1739. break;
  1740. default:
  1741. return -1;
  1742. }
  1743. XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, channel->curr_ier);
  1744. return 0;
  1745. }
  1746. static int xgbe_disable_int(struct xgbe_channel *channel,
  1747. enum xgbe_int int_id)
  1748. {
  1749. switch (int_id) {
  1750. case XGMAC_INT_DMA_CH_SR_TI:
  1751. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 0);
  1752. break;
  1753. case XGMAC_INT_DMA_CH_SR_TPS:
  1754. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TXSE, 0);
  1755. break;
  1756. case XGMAC_INT_DMA_CH_SR_TBU:
  1757. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TBUE, 0);
  1758. break;
  1759. case XGMAC_INT_DMA_CH_SR_RI:
  1760. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 0);
  1761. break;
  1762. case XGMAC_INT_DMA_CH_SR_RBU:
  1763. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RBUE, 0);
  1764. break;
  1765. case XGMAC_INT_DMA_CH_SR_RPS:
  1766. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RSE, 0);
  1767. break;
  1768. case XGMAC_INT_DMA_CH_SR_TI_RI:
  1769. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, TIE, 0);
  1770. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, RIE, 0);
  1771. break;
  1772. case XGMAC_INT_DMA_CH_SR_FBE:
  1773. XGMAC_SET_BITS(channel->curr_ier, DMA_CH_IER, FBEE, 0);
  1774. break;
  1775. case XGMAC_INT_DMA_ALL:
  1776. channel->saved_ier = channel->curr_ier;
  1777. channel->curr_ier = 0;
  1778. break;
  1779. default:
  1780. return -1;
  1781. }
  1782. XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, channel->curr_ier);
  1783. return 0;
  1784. }
  1785. static int __xgbe_exit(struct xgbe_prv_data *pdata)
  1786. {
  1787. unsigned int count = 2000;
  1788. DBGPR("-->xgbe_exit\n");
  1789. /* Issue a software reset */
  1790. XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
  1791. usleep_range(10, 15);
  1792. /* Poll Until Poll Condition */
  1793. while (--count && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
  1794. usleep_range(500, 600);
  1795. if (!count)
  1796. return -EBUSY;
  1797. DBGPR("<--xgbe_exit\n");
  1798. return 0;
  1799. }
  1800. static int xgbe_exit(struct xgbe_prv_data *pdata)
  1801. {
  1802. int ret;
  1803. /* To guard against possible incorrectly generated interrupts,
  1804. * issue the software reset twice.
  1805. */
  1806. ret = __xgbe_exit(pdata);
  1807. if (ret)
  1808. return ret;
  1809. return __xgbe_exit(pdata);
  1810. }
  1811. static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
  1812. {
  1813. unsigned int i, count;
  1814. if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
  1815. return 0;
  1816. for (i = 0; i < pdata->tx_q_count; i++)
  1817. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
  1818. /* Poll Until Poll Condition */
  1819. for (i = 0; i < pdata->tx_q_count; i++) {
  1820. count = 2000;
  1821. while (--count && XGMAC_MTL_IOREAD_BITS(pdata, i,
  1822. MTL_Q_TQOMR, FTQ))
  1823. usleep_range(500, 600);
  1824. if (!count)
  1825. return -EBUSY;
  1826. }
  1827. return 0;
  1828. }
  1829. static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
  1830. {
  1831. unsigned int sbmr;
  1832. sbmr = XGMAC_IOREAD(pdata, DMA_SBMR);
  1833. /* Set enhanced addressing mode */
  1834. XGMAC_SET_BITS(sbmr, DMA_SBMR, EAME, 1);
  1835. /* Set the System Bus mode */
  1836. XGMAC_SET_BITS(sbmr, DMA_SBMR, UNDEF, 1);
  1837. XGMAC_SET_BITS(sbmr, DMA_SBMR, BLEN, pdata->blen >> 2);
  1838. XGMAC_SET_BITS(sbmr, DMA_SBMR, AAL, pdata->aal);
  1839. XGMAC_SET_BITS(sbmr, DMA_SBMR, RD_OSR_LMT, pdata->rd_osr_limit - 1);
  1840. XGMAC_SET_BITS(sbmr, DMA_SBMR, WR_OSR_LMT, pdata->wr_osr_limit - 1);
  1841. XGMAC_IOWRITE(pdata, DMA_SBMR, sbmr);
  1842. /* Set descriptor fetching threshold */
  1843. if (pdata->vdata->tx_desc_prefetch)
  1844. XGMAC_IOWRITE_BITS(pdata, DMA_TXEDMACR, TDPS,
  1845. pdata->vdata->tx_desc_prefetch);
  1846. if (pdata->vdata->rx_desc_prefetch)
  1847. XGMAC_IOWRITE_BITS(pdata, DMA_RXEDMACR, RDPS,
  1848. pdata->vdata->rx_desc_prefetch);
  1849. }
  1850. static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
  1851. {
  1852. XGMAC_IOWRITE(pdata, DMA_AXIARCR, pdata->arcr);
  1853. XGMAC_IOWRITE(pdata, DMA_AXIAWCR, pdata->awcr);
  1854. if (pdata->awarcr)
  1855. XGMAC_IOWRITE(pdata, DMA_AXIAWARCR, pdata->awarcr);
  1856. }
  1857. static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
  1858. {
  1859. unsigned int i;
  1860. /* Set Tx to weighted round robin scheduling algorithm */
  1861. XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
  1862. /* Set Tx traffic classes to use WRR algorithm with equal weights */
  1863. for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
  1864. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
  1865. MTL_TSA_ETS);
  1866. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
  1867. }
  1868. /* Set Rx to strict priority algorithm */
  1869. XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
  1870. }
  1871. static void xgbe_queue_flow_control_threshold(struct xgbe_prv_data *pdata,
  1872. unsigned int queue,
  1873. unsigned int q_fifo_size)
  1874. {
  1875. unsigned int frame_fifo_size;
  1876. unsigned int rfa, rfd;
  1877. frame_fifo_size = XGMAC_FLOW_CONTROL_ALIGN(xgbe_get_max_frame(pdata));
  1878. if (pdata->pfcq[queue] && (q_fifo_size > pdata->pfc_rfa)) {
  1879. /* PFC is active for this queue */
  1880. rfa = pdata->pfc_rfa;
  1881. rfd = rfa + frame_fifo_size;
  1882. if (rfd > XGMAC_FLOW_CONTROL_MAX)
  1883. rfd = XGMAC_FLOW_CONTROL_MAX;
  1884. if (rfa >= XGMAC_FLOW_CONTROL_MAX)
  1885. rfa = XGMAC_FLOW_CONTROL_MAX - XGMAC_FLOW_CONTROL_UNIT;
  1886. } else {
  1887. /* This path deals with just maximum frame sizes which are
  1888. * limited to a jumbo frame of 9,000 (plus headers, etc.)
  1889. * so we can never exceed the maximum allowable RFA/RFD
  1890. * values.
  1891. */
  1892. if (q_fifo_size <= 2048) {
  1893. /* rx_rfd to zero to signal no flow control */
  1894. pdata->rx_rfa[queue] = 0;
  1895. pdata->rx_rfd[queue] = 0;
  1896. return;
  1897. }
  1898. if (q_fifo_size <= 4096) {
  1899. /* Between 2048 and 4096 */
  1900. pdata->rx_rfa[queue] = 0; /* Full - 1024 bytes */
  1901. pdata->rx_rfd[queue] = 1; /* Full - 1536 bytes */
  1902. return;
  1903. }
  1904. if (q_fifo_size <= frame_fifo_size) {
  1905. /* Between 4096 and max-frame */
  1906. pdata->rx_rfa[queue] = 2; /* Full - 2048 bytes */
  1907. pdata->rx_rfd[queue] = 5; /* Full - 3584 bytes */
  1908. return;
  1909. }
  1910. if (q_fifo_size <= (frame_fifo_size * 3)) {
  1911. /* Between max-frame and 3 max-frames,
  1912. * trigger if we get just over a frame of data and
  1913. * resume when we have just under half a frame left.
  1914. */
  1915. rfa = q_fifo_size - frame_fifo_size;
  1916. rfd = rfa + (frame_fifo_size / 2);
  1917. } else {
  1918. /* Above 3 max-frames - trigger when just over
  1919. * 2 frames of space available
  1920. */
  1921. rfa = frame_fifo_size * 2;
  1922. rfa += XGMAC_FLOW_CONTROL_UNIT;
  1923. rfd = rfa + frame_fifo_size;
  1924. }
  1925. }
  1926. pdata->rx_rfa[queue] = XGMAC_FLOW_CONTROL_VALUE(rfa);
  1927. pdata->rx_rfd[queue] = XGMAC_FLOW_CONTROL_VALUE(rfd);
  1928. }
  1929. static void xgbe_calculate_flow_control_threshold(struct xgbe_prv_data *pdata,
  1930. unsigned int *fifo)
  1931. {
  1932. unsigned int q_fifo_size;
  1933. unsigned int i;
  1934. for (i = 0; i < pdata->rx_q_count; i++) {
  1935. q_fifo_size = (fifo[i] + 1) * XGMAC_FIFO_UNIT;
  1936. xgbe_queue_flow_control_threshold(pdata, i, q_fifo_size);
  1937. }
  1938. }
  1939. static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
  1940. {
  1941. unsigned int i;
  1942. for (i = 0; i < pdata->rx_q_count; i++) {
  1943. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFA,
  1944. pdata->rx_rfa[i]);
  1945. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQFCR, RFD,
  1946. pdata->rx_rfd[i]);
  1947. }
  1948. }
  1949. static unsigned int xgbe_get_tx_fifo_size(struct xgbe_prv_data *pdata)
  1950. {
  1951. /* The configured value may not be the actual amount of fifo RAM */
  1952. return min_t(unsigned int, pdata->tx_max_fifo_size,
  1953. pdata->hw_feat.tx_fifo_size);
  1954. }
  1955. static unsigned int xgbe_get_rx_fifo_size(struct xgbe_prv_data *pdata)
  1956. {
  1957. /* The configured value may not be the actual amount of fifo RAM */
  1958. return min_t(unsigned int, pdata->rx_max_fifo_size,
  1959. pdata->hw_feat.rx_fifo_size);
  1960. }
  1961. static void xgbe_calculate_equal_fifo(unsigned int fifo_size,
  1962. unsigned int queue_count,
  1963. unsigned int *fifo)
  1964. {
  1965. unsigned int q_fifo_size;
  1966. unsigned int p_fifo;
  1967. unsigned int i;
  1968. q_fifo_size = fifo_size / queue_count;
  1969. /* Calculate the fifo setting by dividing the queue's fifo size
  1970. * by the fifo allocation increment (with 0 representing the
  1971. * base allocation increment so decrement the result by 1).
  1972. */
  1973. p_fifo = q_fifo_size / XGMAC_FIFO_UNIT;
  1974. if (p_fifo)
  1975. p_fifo--;
  1976. /* Distribute the fifo equally amongst the queues */
  1977. for (i = 0; i < queue_count; i++)
  1978. fifo[i] = p_fifo;
  1979. }
  1980. static unsigned int xgbe_set_nonprio_fifos(unsigned int fifo_size,
  1981. unsigned int queue_count,
  1982. unsigned int *fifo)
  1983. {
  1984. unsigned int i;
  1985. BUILD_BUG_ON_NOT_POWER_OF_2(XGMAC_FIFO_MIN_ALLOC);
  1986. if (queue_count <= IEEE_8021QAZ_MAX_TCS)
  1987. return fifo_size;
  1988. /* Rx queues 9 and up are for specialized packets,
  1989. * such as PTP or DCB control packets, etc. and
  1990. * don't require a large fifo
  1991. */
  1992. for (i = IEEE_8021QAZ_MAX_TCS; i < queue_count; i++) {
  1993. fifo[i] = (XGMAC_FIFO_MIN_ALLOC / XGMAC_FIFO_UNIT) - 1;
  1994. fifo_size -= XGMAC_FIFO_MIN_ALLOC;
  1995. }
  1996. return fifo_size;
  1997. }
  1998. static unsigned int xgbe_get_pfc_delay(struct xgbe_prv_data *pdata)
  1999. {
  2000. unsigned int delay;
  2001. /* If a delay has been provided, use that */
  2002. if (pdata->pfc->delay)
  2003. return pdata->pfc->delay / 8;
  2004. /* Allow for two maximum size frames */
  2005. delay = xgbe_get_max_frame(pdata);
  2006. delay += XGMAC_ETH_PREAMBLE;
  2007. delay *= 2;
  2008. /* Allow for PFC frame */
  2009. delay += XGMAC_PFC_DATA_LEN;
  2010. delay += ETH_HLEN + ETH_FCS_LEN;
  2011. delay += XGMAC_ETH_PREAMBLE;
  2012. /* Allow for miscellaneous delays (LPI exit, cable, etc.) */
  2013. delay += XGMAC_PFC_DELAYS;
  2014. return delay;
  2015. }
  2016. static unsigned int xgbe_get_pfc_queues(struct xgbe_prv_data *pdata)
  2017. {
  2018. unsigned int count, prio_queues;
  2019. unsigned int i;
  2020. if (!pdata->pfc->pfc_en)
  2021. return 0;
  2022. count = 0;
  2023. prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
  2024. for (i = 0; i < prio_queues; i++) {
  2025. if (!xgbe_is_pfc_queue(pdata, i))
  2026. continue;
  2027. pdata->pfcq[i] = 1;
  2028. count++;
  2029. }
  2030. return count;
  2031. }
  2032. static void xgbe_calculate_dcb_fifo(struct xgbe_prv_data *pdata,
  2033. unsigned int fifo_size,
  2034. unsigned int *fifo)
  2035. {
  2036. unsigned int q_fifo_size, rem_fifo, addn_fifo;
  2037. unsigned int prio_queues;
  2038. unsigned int pfc_count;
  2039. unsigned int i;
  2040. q_fifo_size = XGMAC_FIFO_ALIGN(xgbe_get_max_frame(pdata));
  2041. prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
  2042. pfc_count = xgbe_get_pfc_queues(pdata);
  2043. if (!pfc_count || ((q_fifo_size * prio_queues) > fifo_size)) {
  2044. /* No traffic classes with PFC enabled or can't do lossless */
  2045. xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo);
  2046. return;
  2047. }
  2048. /* Calculate how much fifo we have to play with */
  2049. rem_fifo = fifo_size - (q_fifo_size * prio_queues);
  2050. /* Calculate how much more than base fifo PFC needs, which also
  2051. * becomes the threshold activation point (RFA)
  2052. */
  2053. pdata->pfc_rfa = xgbe_get_pfc_delay(pdata);
  2054. pdata->pfc_rfa = XGMAC_FLOW_CONTROL_ALIGN(pdata->pfc_rfa);
  2055. if (pdata->pfc_rfa > q_fifo_size) {
  2056. addn_fifo = pdata->pfc_rfa - q_fifo_size;
  2057. addn_fifo = XGMAC_FIFO_ALIGN(addn_fifo);
  2058. } else {
  2059. addn_fifo = 0;
  2060. }
  2061. /* Calculate DCB fifo settings:
  2062. * - distribute remaining fifo between the VLAN priority
  2063. * queues based on traffic class PFC enablement and overall
  2064. * priority (0 is lowest priority, so start at highest)
  2065. */
  2066. i = prio_queues;
  2067. while (i > 0) {
  2068. i--;
  2069. fifo[i] = (q_fifo_size / XGMAC_FIFO_UNIT) - 1;
  2070. if (!pdata->pfcq[i] || !addn_fifo)
  2071. continue;
  2072. if (addn_fifo > rem_fifo) {
  2073. netdev_warn(pdata->netdev,
  2074. "RXq%u cannot set needed fifo size\n", i);
  2075. if (!rem_fifo)
  2076. continue;
  2077. addn_fifo = rem_fifo;
  2078. }
  2079. fifo[i] += (addn_fifo / XGMAC_FIFO_UNIT);
  2080. rem_fifo -= addn_fifo;
  2081. }
  2082. if (rem_fifo) {
  2083. unsigned int inc_fifo = rem_fifo / prio_queues;
  2084. /* Distribute remaining fifo across queues */
  2085. for (i = 0; i < prio_queues; i++)
  2086. fifo[i] += (inc_fifo / XGMAC_FIFO_UNIT);
  2087. }
  2088. }
  2089. static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
  2090. {
  2091. unsigned int fifo_size;
  2092. unsigned int fifo[XGBE_MAX_QUEUES];
  2093. unsigned int i;
  2094. fifo_size = xgbe_get_tx_fifo_size(pdata);
  2095. xgbe_calculate_equal_fifo(fifo_size, pdata->tx_q_count, fifo);
  2096. for (i = 0; i < pdata->tx_q_count; i++)
  2097. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo[i]);
  2098. netif_info(pdata, drv, pdata->netdev,
  2099. "%d Tx hardware queues, %d byte fifo per queue\n",
  2100. pdata->tx_q_count, ((fifo[0] + 1) * XGMAC_FIFO_UNIT));
  2101. }
  2102. static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
  2103. {
  2104. unsigned int fifo_size;
  2105. unsigned int fifo[XGBE_MAX_QUEUES];
  2106. unsigned int prio_queues;
  2107. unsigned int i;
  2108. /* Clear any DCB related fifo/queue information */
  2109. memset(pdata->pfcq, 0, sizeof(pdata->pfcq));
  2110. pdata->pfc_rfa = 0;
  2111. fifo_size = xgbe_get_rx_fifo_size(pdata);
  2112. prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
  2113. /* Assign a minimum fifo to the non-VLAN priority queues */
  2114. fifo_size = xgbe_set_nonprio_fifos(fifo_size, pdata->rx_q_count, fifo);
  2115. if (pdata->pfc && pdata->ets)
  2116. xgbe_calculate_dcb_fifo(pdata, fifo_size, fifo);
  2117. else
  2118. xgbe_calculate_equal_fifo(fifo_size, prio_queues, fifo);
  2119. for (i = 0; i < pdata->rx_q_count; i++)
  2120. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo[i]);
  2121. xgbe_calculate_flow_control_threshold(pdata, fifo);
  2122. xgbe_config_flow_control_threshold(pdata);
  2123. if (pdata->pfc && pdata->ets && pdata->pfc->pfc_en) {
  2124. netif_info(pdata, drv, pdata->netdev,
  2125. "%u Rx hardware queues\n", pdata->rx_q_count);
  2126. for (i = 0; i < pdata->rx_q_count; i++)
  2127. netif_info(pdata, drv, pdata->netdev,
  2128. "RxQ%u, %u byte fifo queue\n", i,
  2129. ((fifo[i] + 1) * XGMAC_FIFO_UNIT));
  2130. } else {
  2131. netif_info(pdata, drv, pdata->netdev,
  2132. "%u Rx hardware queues, %u byte fifo per queue\n",
  2133. pdata->rx_q_count,
  2134. ((fifo[0] + 1) * XGMAC_FIFO_UNIT));
  2135. }
  2136. }
  2137. static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
  2138. {
  2139. unsigned int qptc, qptc_extra, queue;
  2140. unsigned int prio_queues;
  2141. unsigned int ppq, ppq_extra, prio;
  2142. unsigned int mask;
  2143. unsigned int i, j, reg, reg_val;
  2144. /* Map the MTL Tx Queues to Traffic Classes
  2145. * Note: Tx Queues >= Traffic Classes
  2146. */
  2147. qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
  2148. qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
  2149. for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
  2150. for (j = 0; j < qptc; j++) {
  2151. netif_dbg(pdata, drv, pdata->netdev,
  2152. "TXq%u mapped to TC%u\n", queue, i);
  2153. XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
  2154. Q2TCMAP, i);
  2155. pdata->q2tc_map[queue++] = i;
  2156. }
  2157. if (i < qptc_extra) {
  2158. netif_dbg(pdata, drv, pdata->netdev,
  2159. "TXq%u mapped to TC%u\n", queue, i);
  2160. XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
  2161. Q2TCMAP, i);
  2162. pdata->q2tc_map[queue++] = i;
  2163. }
  2164. }
  2165. /* Map the 8 VLAN priority values to available MTL Rx queues */
  2166. prio_queues = XGMAC_PRIO_QUEUES(pdata->rx_q_count);
  2167. ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
  2168. ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
  2169. reg = MAC_RQC2R;
  2170. reg_val = 0;
  2171. for (i = 0, prio = 0; i < prio_queues;) {
  2172. mask = 0;
  2173. for (j = 0; j < ppq; j++) {
  2174. netif_dbg(pdata, drv, pdata->netdev,
  2175. "PRIO%u mapped to RXq%u\n", prio, i);
  2176. mask |= (1 << prio);
  2177. pdata->prio2q_map[prio++] = i;
  2178. }
  2179. if (i < ppq_extra) {
  2180. netif_dbg(pdata, drv, pdata->netdev,
  2181. "PRIO%u mapped to RXq%u\n", prio, i);
  2182. mask |= (1 << prio);
  2183. pdata->prio2q_map[prio++] = i;
  2184. }
  2185. reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
  2186. if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
  2187. continue;
  2188. XGMAC_IOWRITE(pdata, reg, reg_val);
  2189. reg += MAC_RQC2_INC;
  2190. reg_val = 0;
  2191. }
  2192. /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
  2193. reg = MTL_RQDCM0R;
  2194. reg_val = 0;
  2195. for (i = 0; i < pdata->rx_q_count;) {
  2196. reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
  2197. if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
  2198. continue;
  2199. XGMAC_IOWRITE(pdata, reg, reg_val);
  2200. reg += MTL_RQDCM_INC;
  2201. reg_val = 0;
  2202. }
  2203. }
  2204. static void xgbe_config_tc(struct xgbe_prv_data *pdata)
  2205. {
  2206. unsigned int offset, queue, prio;
  2207. u8 i;
  2208. netdev_reset_tc(pdata->netdev);
  2209. if (!pdata->num_tcs)
  2210. return;
  2211. netdev_set_num_tc(pdata->netdev, pdata->num_tcs);
  2212. for (i = 0, queue = 0, offset = 0; i < pdata->num_tcs; i++) {
  2213. while ((queue < pdata->tx_q_count) &&
  2214. (pdata->q2tc_map[queue] == i))
  2215. queue++;
  2216. netif_dbg(pdata, drv, pdata->netdev, "TC%u using TXq%u-%u\n",
  2217. i, offset, queue - 1);
  2218. netdev_set_tc_queue(pdata->netdev, i, queue - offset, offset);
  2219. offset = queue;
  2220. }
  2221. if (!pdata->ets)
  2222. return;
  2223. for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++)
  2224. netdev_set_prio_tc_map(pdata->netdev, prio,
  2225. pdata->ets->prio_tc[prio]);
  2226. }
  2227. static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
  2228. {
  2229. struct ieee_ets *ets = pdata->ets;
  2230. unsigned int total_weight, min_weight, weight;
  2231. unsigned int mask, reg, reg_val;
  2232. unsigned int i, prio;
  2233. if (!ets)
  2234. return;
  2235. /* Set Tx to deficit weighted round robin scheduling algorithm (when
  2236. * traffic class is using ETS algorithm)
  2237. */
  2238. XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
  2239. /* Set Traffic Class algorithms */
  2240. total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
  2241. min_weight = total_weight / 100;
  2242. if (!min_weight)
  2243. min_weight = 1;
  2244. for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
  2245. /* Map the priorities to the traffic class */
  2246. mask = 0;
  2247. for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
  2248. if (ets->prio_tc[prio] == i)
  2249. mask |= (1 << prio);
  2250. }
  2251. mask &= 0xff;
  2252. netif_dbg(pdata, drv, pdata->netdev, "TC%u PRIO mask=%#x\n",
  2253. i, mask);
  2254. reg = MTL_TCPM0R + (MTL_TCPM_INC * (i / MTL_TCPM_TC_PER_REG));
  2255. reg_val = XGMAC_IOREAD(pdata, reg);
  2256. reg_val &= ~(0xff << ((i % MTL_TCPM_TC_PER_REG) << 3));
  2257. reg_val |= (mask << ((i % MTL_TCPM_TC_PER_REG) << 3));
  2258. XGMAC_IOWRITE(pdata, reg, reg_val);
  2259. /* Set the traffic class algorithm */
  2260. switch (ets->tc_tsa[i]) {
  2261. case IEEE_8021QAZ_TSA_STRICT:
  2262. netif_dbg(pdata, drv, pdata->netdev,
  2263. "TC%u using SP\n", i);
  2264. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
  2265. MTL_TSA_SP);
  2266. break;
  2267. case IEEE_8021QAZ_TSA_ETS:
  2268. weight = total_weight * ets->tc_tx_bw[i] / 100;
  2269. weight = clamp(weight, min_weight, total_weight);
  2270. netif_dbg(pdata, drv, pdata->netdev,
  2271. "TC%u using DWRR (weight %u)\n", i, weight);
  2272. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
  2273. MTL_TSA_ETS);
  2274. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
  2275. weight);
  2276. break;
  2277. }
  2278. }
  2279. xgbe_config_tc(pdata);
  2280. }
  2281. static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
  2282. {
  2283. if (!test_bit(XGBE_DOWN, &pdata->dev_state)) {
  2284. /* Just stop the Tx queues while Rx fifo is changed */
  2285. netif_tx_stop_all_queues(pdata->netdev);
  2286. /* Suspend Rx so that fifo's can be adjusted */
  2287. pdata->hw_if.disable_rx(pdata);
  2288. }
  2289. xgbe_config_rx_fifo_size(pdata);
  2290. xgbe_config_flow_control(pdata);
  2291. if (!test_bit(XGBE_DOWN, &pdata->dev_state)) {
  2292. /* Resume Rx */
  2293. pdata->hw_if.enable_rx(pdata);
  2294. /* Resume Tx queues */
  2295. netif_tx_start_all_queues(pdata->netdev);
  2296. }
  2297. }
  2298. static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
  2299. {
  2300. xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
  2301. /* Filtering is done using perfect filtering and hash filtering */
  2302. if (pdata->hw_feat.hash_table_size) {
  2303. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
  2304. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
  2305. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
  2306. }
  2307. }
  2308. static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
  2309. {
  2310. unsigned int val;
  2311. val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
  2312. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
  2313. }
  2314. static void xgbe_config_mac_speed(struct xgbe_prv_data *pdata)
  2315. {
  2316. xgbe_set_speed(pdata, pdata->phy_speed);
  2317. }
  2318. static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
  2319. {
  2320. if (pdata->netdev->features & NETIF_F_RXCSUM)
  2321. xgbe_enable_rx_csum(pdata);
  2322. else
  2323. xgbe_disable_rx_csum(pdata);
  2324. }
  2325. static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
  2326. {
  2327. /* Indicate that VLAN Tx CTAGs come from context descriptors */
  2328. XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
  2329. XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
  2330. /* Set the current VLAN Hash Table register value */
  2331. xgbe_update_vlan_hash_table(pdata);
  2332. if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
  2333. xgbe_enable_rx_vlan_filtering(pdata);
  2334. else
  2335. xgbe_disable_rx_vlan_filtering(pdata);
  2336. if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  2337. xgbe_enable_rx_vlan_stripping(pdata);
  2338. else
  2339. xgbe_disable_rx_vlan_stripping(pdata);
  2340. }
  2341. static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
  2342. {
  2343. bool read_hi;
  2344. u64 val;
  2345. if (pdata->vdata->mmc_64bit) {
  2346. switch (reg_lo) {
  2347. /* These registers are always 32 bit */
  2348. case MMC_RXRUNTERROR:
  2349. case MMC_RXJABBERERROR:
  2350. case MMC_RXUNDERSIZE_G:
  2351. case MMC_RXOVERSIZE_G:
  2352. case MMC_RXWATCHDOGERROR:
  2353. read_hi = false;
  2354. break;
  2355. default:
  2356. read_hi = true;
  2357. }
  2358. } else {
  2359. switch (reg_lo) {
  2360. /* These registers are always 64 bit */
  2361. case MMC_TXOCTETCOUNT_GB_LO:
  2362. case MMC_TXOCTETCOUNT_G_LO:
  2363. case MMC_RXOCTETCOUNT_GB_LO:
  2364. case MMC_RXOCTETCOUNT_G_LO:
  2365. read_hi = true;
  2366. break;
  2367. default:
  2368. read_hi = false;
  2369. }
  2370. }
  2371. val = XGMAC_IOREAD(pdata, reg_lo);
  2372. if (read_hi)
  2373. val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
  2374. return val;
  2375. }
  2376. static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
  2377. {
  2378. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  2379. unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
  2380. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
  2381. stats->txoctetcount_gb +=
  2382. xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
  2383. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
  2384. stats->txframecount_gb +=
  2385. xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
  2386. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
  2387. stats->txbroadcastframes_g +=
  2388. xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
  2389. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
  2390. stats->txmulticastframes_g +=
  2391. xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
  2392. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
  2393. stats->tx64octets_gb +=
  2394. xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
  2395. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
  2396. stats->tx65to127octets_gb +=
  2397. xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
  2398. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
  2399. stats->tx128to255octets_gb +=
  2400. xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
  2401. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
  2402. stats->tx256to511octets_gb +=
  2403. xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
  2404. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
  2405. stats->tx512to1023octets_gb +=
  2406. xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
  2407. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
  2408. stats->tx1024tomaxoctets_gb +=
  2409. xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
  2410. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
  2411. stats->txunicastframes_gb +=
  2412. xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
  2413. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
  2414. stats->txmulticastframes_gb +=
  2415. xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
  2416. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
  2417. stats->txbroadcastframes_g +=
  2418. xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
  2419. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
  2420. stats->txunderflowerror +=
  2421. xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
  2422. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
  2423. stats->txoctetcount_g +=
  2424. xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
  2425. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
  2426. stats->txframecount_g +=
  2427. xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
  2428. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
  2429. stats->txpauseframes +=
  2430. xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
  2431. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
  2432. stats->txvlanframes_g +=
  2433. xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
  2434. }
  2435. static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
  2436. {
  2437. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  2438. unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
  2439. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
  2440. stats->rxframecount_gb +=
  2441. xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
  2442. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
  2443. stats->rxoctetcount_gb +=
  2444. xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
  2445. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
  2446. stats->rxoctetcount_g +=
  2447. xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
  2448. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
  2449. stats->rxbroadcastframes_g +=
  2450. xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
  2451. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
  2452. stats->rxmulticastframes_g +=
  2453. xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
  2454. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
  2455. stats->rxcrcerror +=
  2456. xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
  2457. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
  2458. stats->rxrunterror +=
  2459. xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
  2460. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
  2461. stats->rxjabbererror +=
  2462. xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
  2463. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
  2464. stats->rxundersize_g +=
  2465. xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
  2466. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
  2467. stats->rxoversize_g +=
  2468. xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
  2469. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
  2470. stats->rx64octets_gb +=
  2471. xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
  2472. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
  2473. stats->rx65to127octets_gb +=
  2474. xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
  2475. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
  2476. stats->rx128to255octets_gb +=
  2477. xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
  2478. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
  2479. stats->rx256to511octets_gb +=
  2480. xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
  2481. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
  2482. stats->rx512to1023octets_gb +=
  2483. xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
  2484. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
  2485. stats->rx1024tomaxoctets_gb +=
  2486. xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
  2487. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
  2488. stats->rxunicastframes_g +=
  2489. xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
  2490. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
  2491. stats->rxlengtherror +=
  2492. xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
  2493. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
  2494. stats->rxoutofrangetype +=
  2495. xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
  2496. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
  2497. stats->rxpauseframes +=
  2498. xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
  2499. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
  2500. stats->rxfifooverflow +=
  2501. xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
  2502. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
  2503. stats->rxvlanframes_gb +=
  2504. xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
  2505. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
  2506. stats->rxwatchdogerror +=
  2507. xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
  2508. }
  2509. static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
  2510. {
  2511. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  2512. /* Freeze counters */
  2513. XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
  2514. stats->txoctetcount_gb +=
  2515. xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
  2516. stats->txframecount_gb +=
  2517. xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
  2518. stats->txbroadcastframes_g +=
  2519. xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
  2520. stats->txmulticastframes_g +=
  2521. xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
  2522. stats->tx64octets_gb +=
  2523. xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
  2524. stats->tx65to127octets_gb +=
  2525. xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
  2526. stats->tx128to255octets_gb +=
  2527. xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
  2528. stats->tx256to511octets_gb +=
  2529. xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
  2530. stats->tx512to1023octets_gb +=
  2531. xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
  2532. stats->tx1024tomaxoctets_gb +=
  2533. xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
  2534. stats->txunicastframes_gb +=
  2535. xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
  2536. stats->txmulticastframes_gb +=
  2537. xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
  2538. stats->txbroadcastframes_g +=
  2539. xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
  2540. stats->txunderflowerror +=
  2541. xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
  2542. stats->txoctetcount_g +=
  2543. xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
  2544. stats->txframecount_g +=
  2545. xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
  2546. stats->txpauseframes +=
  2547. xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
  2548. stats->txvlanframes_g +=
  2549. xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
  2550. stats->rxframecount_gb +=
  2551. xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
  2552. stats->rxoctetcount_gb +=
  2553. xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
  2554. stats->rxoctetcount_g +=
  2555. xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
  2556. stats->rxbroadcastframes_g +=
  2557. xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
  2558. stats->rxmulticastframes_g +=
  2559. xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
  2560. stats->rxcrcerror +=
  2561. xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
  2562. stats->rxrunterror +=
  2563. xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
  2564. stats->rxjabbererror +=
  2565. xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
  2566. stats->rxundersize_g +=
  2567. xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
  2568. stats->rxoversize_g +=
  2569. xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
  2570. stats->rx64octets_gb +=
  2571. xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
  2572. stats->rx65to127octets_gb +=
  2573. xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
  2574. stats->rx128to255octets_gb +=
  2575. xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
  2576. stats->rx256to511octets_gb +=
  2577. xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
  2578. stats->rx512to1023octets_gb +=
  2579. xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
  2580. stats->rx1024tomaxoctets_gb +=
  2581. xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
  2582. stats->rxunicastframes_g +=
  2583. xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
  2584. stats->rxlengtherror +=
  2585. xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
  2586. stats->rxoutofrangetype +=
  2587. xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
  2588. stats->rxpauseframes +=
  2589. xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
  2590. stats->rxfifooverflow +=
  2591. xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
  2592. stats->rxvlanframes_gb +=
  2593. xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
  2594. stats->rxwatchdogerror +=
  2595. xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
  2596. /* Un-freeze counters */
  2597. XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
  2598. }
  2599. static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
  2600. {
  2601. /* Set counters to reset on read */
  2602. XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
  2603. /* Reset the counters */
  2604. XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
  2605. }
  2606. static void xgbe_txq_prepare_tx_stop(struct xgbe_prv_data *pdata,
  2607. unsigned int queue)
  2608. {
  2609. unsigned int tx_status;
  2610. unsigned long tx_timeout;
  2611. /* The Tx engine cannot be stopped if it is actively processing
  2612. * packets. Wait for the Tx queue to empty the Tx fifo. Don't
  2613. * wait forever though...
  2614. */
  2615. tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
  2616. while (time_before(jiffies, tx_timeout)) {
  2617. tx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_TQDR);
  2618. if ((XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TRCSTS) != 1) &&
  2619. (XGMAC_GET_BITS(tx_status, MTL_Q_TQDR, TXQSTS) == 0))
  2620. break;
  2621. usleep_range(500, 1000);
  2622. }
  2623. if (!time_before(jiffies, tx_timeout))
  2624. netdev_info(pdata->netdev,
  2625. "timed out waiting for Tx queue %u to empty\n",
  2626. queue);
  2627. }
  2628. static void xgbe_prepare_tx_stop(struct xgbe_prv_data *pdata,
  2629. unsigned int queue)
  2630. {
  2631. unsigned int tx_dsr, tx_pos, tx_qidx;
  2632. unsigned int tx_status;
  2633. unsigned long tx_timeout;
  2634. if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) > 0x20)
  2635. return xgbe_txq_prepare_tx_stop(pdata, queue);
  2636. /* Calculate the status register to read and the position within */
  2637. if (queue < DMA_DSRX_FIRST_QUEUE) {
  2638. tx_dsr = DMA_DSR0;
  2639. tx_pos = (queue * DMA_DSR_Q_WIDTH) + DMA_DSR0_TPS_START;
  2640. } else {
  2641. tx_qidx = queue - DMA_DSRX_FIRST_QUEUE;
  2642. tx_dsr = DMA_DSR1 + ((tx_qidx / DMA_DSRX_QPR) * DMA_DSRX_INC);
  2643. tx_pos = ((tx_qidx % DMA_DSRX_QPR) * DMA_DSR_Q_WIDTH) +
  2644. DMA_DSRX_TPS_START;
  2645. }
  2646. /* The Tx engine cannot be stopped if it is actively processing
  2647. * descriptors. Wait for the Tx engine to enter the stopped or
  2648. * suspended state. Don't wait forever though...
  2649. */
  2650. tx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
  2651. while (time_before(jiffies, tx_timeout)) {
  2652. tx_status = XGMAC_IOREAD(pdata, tx_dsr);
  2653. tx_status = GET_BITS(tx_status, tx_pos, DMA_DSR_TPS_WIDTH);
  2654. if ((tx_status == DMA_TPS_STOPPED) ||
  2655. (tx_status == DMA_TPS_SUSPENDED))
  2656. break;
  2657. usleep_range(500, 1000);
  2658. }
  2659. if (!time_before(jiffies, tx_timeout))
  2660. netdev_info(pdata->netdev,
  2661. "timed out waiting for Tx DMA channel %u to stop\n",
  2662. queue);
  2663. }
  2664. static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
  2665. {
  2666. unsigned int i;
  2667. /* Enable each Tx DMA channel */
  2668. for (i = 0; i < pdata->channel_count; i++) {
  2669. if (!pdata->channel[i]->tx_ring)
  2670. break;
  2671. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 1);
  2672. }
  2673. /* Enable each Tx queue */
  2674. for (i = 0; i < pdata->tx_q_count; i++)
  2675. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
  2676. MTL_Q_ENABLED);
  2677. /* Enable MAC Tx */
  2678. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
  2679. }
  2680. static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
  2681. {
  2682. unsigned int i;
  2683. /* Prepare for Tx DMA channel stop */
  2684. for (i = 0; i < pdata->tx_q_count; i++)
  2685. xgbe_prepare_tx_stop(pdata, i);
  2686. /* Disable MAC Tx */
  2687. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
  2688. /* Disable each Tx queue */
  2689. for (i = 0; i < pdata->tx_q_count; i++)
  2690. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
  2691. /* Disable each Tx DMA channel */
  2692. for (i = 0; i < pdata->channel_count; i++) {
  2693. if (!pdata->channel[i]->tx_ring)
  2694. break;
  2695. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 0);
  2696. }
  2697. }
  2698. static void xgbe_prepare_rx_stop(struct xgbe_prv_data *pdata,
  2699. unsigned int queue)
  2700. {
  2701. unsigned int rx_status;
  2702. unsigned long rx_timeout;
  2703. /* The Rx engine cannot be stopped if it is actively processing
  2704. * packets. Wait for the Rx queue to empty the Rx fifo. Don't
  2705. * wait forever though...
  2706. */
  2707. rx_timeout = jiffies + (XGBE_DMA_STOP_TIMEOUT * HZ);
  2708. while (time_before(jiffies, rx_timeout)) {
  2709. rx_status = XGMAC_MTL_IOREAD(pdata, queue, MTL_Q_RQDR);
  2710. if ((XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, PRXQ) == 0) &&
  2711. (XGMAC_GET_BITS(rx_status, MTL_Q_RQDR, RXQSTS) == 0))
  2712. break;
  2713. usleep_range(500, 1000);
  2714. }
  2715. if (!time_before(jiffies, rx_timeout))
  2716. netdev_info(pdata->netdev,
  2717. "timed out waiting for Rx queue %u to empty\n",
  2718. queue);
  2719. }
  2720. static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
  2721. {
  2722. unsigned int reg_val, i;
  2723. /* Enable each Rx DMA channel */
  2724. for (i = 0; i < pdata->channel_count; i++) {
  2725. if (!pdata->channel[i]->rx_ring)
  2726. break;
  2727. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 1);
  2728. }
  2729. /* Enable each Rx queue */
  2730. reg_val = 0;
  2731. for (i = 0; i < pdata->rx_q_count; i++)
  2732. reg_val |= (0x02 << (i << 1));
  2733. XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
  2734. /* Enable MAC Rx */
  2735. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
  2736. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
  2737. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
  2738. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
  2739. }
  2740. static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
  2741. {
  2742. unsigned int i;
  2743. /* Disable MAC Rx */
  2744. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
  2745. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
  2746. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
  2747. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
  2748. /* Prepare for Rx DMA channel stop */
  2749. for (i = 0; i < pdata->rx_q_count; i++)
  2750. xgbe_prepare_rx_stop(pdata, i);
  2751. /* Disable each Rx queue */
  2752. XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
  2753. /* Disable each Rx DMA channel */
  2754. for (i = 0; i < pdata->channel_count; i++) {
  2755. if (!pdata->channel[i]->rx_ring)
  2756. break;
  2757. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 0);
  2758. }
  2759. }
  2760. static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
  2761. {
  2762. unsigned int i;
  2763. /* Enable each Tx DMA channel */
  2764. for (i = 0; i < pdata->channel_count; i++) {
  2765. if (!pdata->channel[i]->tx_ring)
  2766. break;
  2767. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 1);
  2768. }
  2769. /* Enable MAC Tx */
  2770. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
  2771. }
  2772. static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
  2773. {
  2774. unsigned int i;
  2775. /* Prepare for Tx DMA channel stop */
  2776. for (i = 0; i < pdata->tx_q_count; i++)
  2777. xgbe_prepare_tx_stop(pdata, i);
  2778. /* Disable MAC Tx */
  2779. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
  2780. /* Disable each Tx DMA channel */
  2781. for (i = 0; i < pdata->channel_count; i++) {
  2782. if (!pdata->channel[i]->tx_ring)
  2783. break;
  2784. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_TCR, ST, 0);
  2785. }
  2786. }
  2787. static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
  2788. {
  2789. unsigned int i;
  2790. /* Enable each Rx DMA channel */
  2791. for (i = 0; i < pdata->channel_count; i++) {
  2792. if (!pdata->channel[i]->rx_ring)
  2793. break;
  2794. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 1);
  2795. }
  2796. }
  2797. static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
  2798. {
  2799. unsigned int i;
  2800. /* Disable each Rx DMA channel */
  2801. for (i = 0; i < pdata->channel_count; i++) {
  2802. if (!pdata->channel[i]->rx_ring)
  2803. break;
  2804. XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_RCR, SR, 0);
  2805. }
  2806. }
  2807. static int xgbe_init(struct xgbe_prv_data *pdata)
  2808. {
  2809. struct xgbe_desc_if *desc_if = &pdata->desc_if;
  2810. int ret;
  2811. DBGPR("-->xgbe_init\n");
  2812. /* Flush Tx queues */
  2813. ret = xgbe_flush_tx_queues(pdata);
  2814. if (ret) {
  2815. netdev_err(pdata->netdev, "error flushing TX queues\n");
  2816. return ret;
  2817. }
  2818. /*
  2819. * Initialize DMA related features
  2820. */
  2821. xgbe_config_dma_bus(pdata);
  2822. xgbe_config_dma_cache(pdata);
  2823. xgbe_config_osp_mode(pdata);
  2824. xgbe_config_pbl_val(pdata);
  2825. xgbe_config_rx_coalesce(pdata);
  2826. xgbe_config_tx_coalesce(pdata);
  2827. xgbe_config_rx_buffer_size(pdata);
  2828. xgbe_config_tso_mode(pdata);
  2829. if (pdata->netdev->features & NETIF_F_RXCSUM) {
  2830. xgbe_config_sph_mode(pdata);
  2831. xgbe_config_rss(pdata);
  2832. }
  2833. desc_if->wrapper_tx_desc_init(pdata);
  2834. desc_if->wrapper_rx_desc_init(pdata);
  2835. xgbe_enable_dma_interrupts(pdata);
  2836. /*
  2837. * Initialize MTL related features
  2838. */
  2839. xgbe_config_mtl_mode(pdata);
  2840. xgbe_config_queue_mapping(pdata);
  2841. xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
  2842. xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
  2843. xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
  2844. xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
  2845. xgbe_config_tx_fifo_size(pdata);
  2846. xgbe_config_rx_fifo_size(pdata);
  2847. /*TODO: Error Packet and undersized good Packet forwarding enable
  2848. (FEP and FUP)
  2849. */
  2850. xgbe_config_dcb_tc(pdata);
  2851. xgbe_enable_mtl_interrupts(pdata);
  2852. /*
  2853. * Initialize MAC related features
  2854. */
  2855. xgbe_config_mac_address(pdata);
  2856. xgbe_config_rx_mode(pdata);
  2857. xgbe_config_jumbo_enable(pdata);
  2858. xgbe_config_flow_control(pdata);
  2859. xgbe_config_mac_speed(pdata);
  2860. xgbe_config_checksum_offload(pdata);
  2861. xgbe_config_vlan_support(pdata);
  2862. xgbe_config_mmc(pdata);
  2863. xgbe_enable_mac_interrupts(pdata);
  2864. /*
  2865. * Initialize ECC related features
  2866. */
  2867. xgbe_enable_ecc_interrupts(pdata);
  2868. DBGPR("<--xgbe_init\n");
  2869. return 0;
  2870. }
  2871. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
  2872. {
  2873. DBGPR("-->xgbe_init_function_ptrs\n");
  2874. hw_if->tx_complete = xgbe_tx_complete;
  2875. hw_if->set_mac_address = xgbe_set_mac_address;
  2876. hw_if->config_rx_mode = xgbe_config_rx_mode;
  2877. hw_if->enable_rx_csum = xgbe_enable_rx_csum;
  2878. hw_if->disable_rx_csum = xgbe_disable_rx_csum;
  2879. hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
  2880. hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
  2881. hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
  2882. hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
  2883. hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
  2884. hw_if->read_mmd_regs = xgbe_read_mmd_regs;
  2885. hw_if->write_mmd_regs = xgbe_write_mmd_regs;
  2886. hw_if->set_speed = xgbe_set_speed;
  2887. hw_if->set_ext_mii_mode = xgbe_set_ext_mii_mode;
  2888. hw_if->read_ext_mii_regs_c22 = xgbe_read_ext_mii_regs_c22;
  2889. hw_if->write_ext_mii_regs_c22 = xgbe_write_ext_mii_regs_c22;
  2890. hw_if->read_ext_mii_regs_c45 = xgbe_read_ext_mii_regs_c45;
  2891. hw_if->write_ext_mii_regs_c45 = xgbe_write_ext_mii_regs_c45;
  2892. hw_if->set_gpio = xgbe_set_gpio;
  2893. hw_if->clr_gpio = xgbe_clr_gpio;
  2894. hw_if->enable_tx = xgbe_enable_tx;
  2895. hw_if->disable_tx = xgbe_disable_tx;
  2896. hw_if->enable_rx = xgbe_enable_rx;
  2897. hw_if->disable_rx = xgbe_disable_rx;
  2898. hw_if->powerup_tx = xgbe_powerup_tx;
  2899. hw_if->powerdown_tx = xgbe_powerdown_tx;
  2900. hw_if->powerup_rx = xgbe_powerup_rx;
  2901. hw_if->powerdown_rx = xgbe_powerdown_rx;
  2902. hw_if->dev_xmit = xgbe_dev_xmit;
  2903. hw_if->dev_read = xgbe_dev_read;
  2904. hw_if->enable_int = xgbe_enable_int;
  2905. hw_if->disable_int = xgbe_disable_int;
  2906. hw_if->init = xgbe_init;
  2907. hw_if->exit = xgbe_exit;
  2908. /* Descriptor related Sequences have to be initialized here */
  2909. hw_if->tx_desc_init = xgbe_tx_desc_init;
  2910. hw_if->rx_desc_init = xgbe_rx_desc_init;
  2911. hw_if->tx_desc_reset = xgbe_tx_desc_reset;
  2912. hw_if->rx_desc_reset = xgbe_rx_desc_reset;
  2913. hw_if->is_last_desc = xgbe_is_last_desc;
  2914. hw_if->is_context_desc = xgbe_is_context_desc;
  2915. hw_if->tx_start_xmit = xgbe_tx_start_xmit;
  2916. /* For FLOW ctrl */
  2917. hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
  2918. hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
  2919. /* For RX coalescing */
  2920. hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
  2921. hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
  2922. hw_if->usec_to_riwt = xgbe_usec_to_riwt;
  2923. hw_if->riwt_to_usec = xgbe_riwt_to_usec;
  2924. /* For RX and TX threshold config */
  2925. hw_if->config_rx_threshold = xgbe_config_rx_threshold;
  2926. hw_if->config_tx_threshold = xgbe_config_tx_threshold;
  2927. /* For RX and TX Store and Forward Mode config */
  2928. hw_if->config_rsf_mode = xgbe_config_rsf_mode;
  2929. hw_if->config_tsf_mode = xgbe_config_tsf_mode;
  2930. /* For TX DMA Operating on Second Frame config */
  2931. hw_if->config_osp_mode = xgbe_config_osp_mode;
  2932. /* For MMC statistics support */
  2933. hw_if->tx_mmc_int = xgbe_tx_mmc_int;
  2934. hw_if->rx_mmc_int = xgbe_rx_mmc_int;
  2935. hw_if->read_mmc_stats = xgbe_read_mmc_stats;
  2936. /* For PTP config */
  2937. hw_if->config_tstamp = xgbe_config_tstamp;
  2938. hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
  2939. hw_if->set_tstamp_time = xgbe_set_tstamp_time;
  2940. hw_if->get_tstamp_time = xgbe_get_tstamp_time;
  2941. hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
  2942. /* For Data Center Bridging config */
  2943. hw_if->config_tc = xgbe_config_tc;
  2944. hw_if->config_dcb_tc = xgbe_config_dcb_tc;
  2945. hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
  2946. /* For Receive Side Scaling */
  2947. hw_if->enable_rss = xgbe_enable_rss;
  2948. hw_if->disable_rss = xgbe_disable_rss;
  2949. hw_if->set_rss_hash_key = xgbe_set_rss_hash_key;
  2950. hw_if->set_rss_lookup_table = xgbe_set_rss_lookup_table;
  2951. /* For ECC */
  2952. hw_if->disable_ecc_ded = xgbe_disable_ecc_ded;
  2953. hw_if->disable_ecc_sec = xgbe_disable_ecc_sec;
  2954. /* For VXLAN */
  2955. hw_if->enable_vxlan = xgbe_enable_vxlan;
  2956. hw_if->disable_vxlan = xgbe_disable_vxlan;
  2957. hw_if->set_vxlan_id = xgbe_set_vxlan_id;
  2958. /* For Split Header*/
  2959. hw_if->enable_sph = xgbe_config_sph_mode;
  2960. hw_if->disable_sph = xgbe_disable_sph_mode;
  2961. DBGPR("<--xgbe_init_function_ptrs\n");
  2962. }