xgbe-dev.c 99 KB

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