xgbe-dev.c 97 KB

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