xgbe-dev.c 99 KB

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