xgbe-dev.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624
  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 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 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/clk.h>
  118. #include <linux/bitrev.h>
  119. #include <linux/crc32.h>
  120. #include "xgbe.h"
  121. #include "xgbe-common.h"
  122. static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
  123. unsigned int usec)
  124. {
  125. unsigned long rate;
  126. unsigned int ret;
  127. DBGPR("-->xgbe_usec_to_riwt\n");
  128. rate = clk_get_rate(pdata->sysclk);
  129. /*
  130. * Convert the input usec value to the watchdog timer value. Each
  131. * watchdog timer value is equivalent to 256 clock cycles.
  132. * Calculate the required value as:
  133. * ( usec * ( system_clock_mhz / 10^6 ) / 256
  134. */
  135. ret = (usec * (rate / 1000000)) / 256;
  136. DBGPR("<--xgbe_usec_to_riwt\n");
  137. return ret;
  138. }
  139. static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
  140. unsigned int riwt)
  141. {
  142. unsigned long rate;
  143. unsigned int ret;
  144. DBGPR("-->xgbe_riwt_to_usec\n");
  145. rate = clk_get_rate(pdata->sysclk);
  146. /*
  147. * Convert the input watchdog timer value to the usec value. Each
  148. * watchdog timer value is equivalent to 256 clock cycles.
  149. * Calculate the required value as:
  150. * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
  151. */
  152. ret = (riwt * 256) / (rate / 1000000);
  153. DBGPR("<--xgbe_riwt_to_usec\n");
  154. return ret;
  155. }
  156. static int xgbe_config_pblx8(struct xgbe_prv_data *pdata)
  157. {
  158. struct xgbe_channel *channel;
  159. unsigned int i;
  160. channel = pdata->channel;
  161. for (i = 0; i < pdata->channel_count; i++, channel++)
  162. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, PBLX8,
  163. pdata->pblx8);
  164. return 0;
  165. }
  166. static int xgbe_get_tx_pbl_val(struct xgbe_prv_data *pdata)
  167. {
  168. return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_TCR, PBL);
  169. }
  170. static int xgbe_config_tx_pbl_val(struct xgbe_prv_data *pdata)
  171. {
  172. struct xgbe_channel *channel;
  173. unsigned int i;
  174. channel = pdata->channel;
  175. for (i = 0; i < pdata->channel_count; i++, channel++) {
  176. if (!channel->tx_ring)
  177. break;
  178. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, PBL,
  179. pdata->tx_pbl);
  180. }
  181. return 0;
  182. }
  183. static int xgbe_get_rx_pbl_val(struct xgbe_prv_data *pdata)
  184. {
  185. return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_RCR, PBL);
  186. }
  187. static int xgbe_config_rx_pbl_val(struct xgbe_prv_data *pdata)
  188. {
  189. struct xgbe_channel *channel;
  190. unsigned int i;
  191. channel = pdata->channel;
  192. for (i = 0; i < pdata->channel_count; i++, channel++) {
  193. if (!channel->rx_ring)
  194. break;
  195. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, PBL,
  196. pdata->rx_pbl);
  197. }
  198. return 0;
  199. }
  200. static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
  201. {
  202. struct xgbe_channel *channel;
  203. unsigned int i;
  204. channel = pdata->channel;
  205. for (i = 0; i < pdata->channel_count; i++, channel++) {
  206. if (!channel->tx_ring)
  207. break;
  208. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, OSP,
  209. pdata->tx_osp_mode);
  210. }
  211. return 0;
  212. }
  213. static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
  214. {
  215. unsigned int i;
  216. for (i = 0; i < pdata->rx_q_count; i++)
  217. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
  218. return 0;
  219. }
  220. static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
  221. {
  222. unsigned int i;
  223. for (i = 0; i < pdata->tx_q_count; i++)
  224. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
  225. return 0;
  226. }
  227. static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
  228. unsigned int val)
  229. {
  230. unsigned int i;
  231. for (i = 0; i < pdata->rx_q_count; i++)
  232. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
  233. return 0;
  234. }
  235. static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
  236. unsigned int val)
  237. {
  238. unsigned int i;
  239. for (i = 0; i < pdata->tx_q_count; i++)
  240. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
  241. return 0;
  242. }
  243. static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
  244. {
  245. struct xgbe_channel *channel;
  246. unsigned int i;
  247. channel = pdata->channel;
  248. for (i = 0; i < pdata->channel_count; i++, channel++) {
  249. if (!channel->rx_ring)
  250. break;
  251. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RIWT, RWT,
  252. pdata->rx_riwt);
  253. }
  254. return 0;
  255. }
  256. static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
  257. {
  258. return 0;
  259. }
  260. static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
  261. {
  262. struct xgbe_channel *channel;
  263. unsigned int i;
  264. channel = pdata->channel;
  265. for (i = 0; i < pdata->channel_count; i++, channel++) {
  266. if (!channel->rx_ring)
  267. break;
  268. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, RBSZ,
  269. pdata->rx_buf_size);
  270. }
  271. }
  272. static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
  273. {
  274. struct xgbe_channel *channel;
  275. unsigned int i;
  276. channel = pdata->channel;
  277. for (i = 0; i < pdata->channel_count; i++, channel++) {
  278. if (!channel->tx_ring)
  279. break;
  280. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, TSE, 1);
  281. }
  282. }
  283. static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
  284. {
  285. unsigned int max_q_count, q_count;
  286. unsigned int reg, reg_val;
  287. unsigned int i;
  288. /* Clear MTL flow control */
  289. for (i = 0; i < pdata->rx_q_count; i++)
  290. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
  291. /* Clear MAC flow control */
  292. max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
  293. q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
  294. reg = MAC_Q0TFCR;
  295. for (i = 0; i < q_count; i++) {
  296. reg_val = XGMAC_IOREAD(pdata, reg);
  297. XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
  298. XGMAC_IOWRITE(pdata, reg, reg_val);
  299. reg += MAC_QTFCR_INC;
  300. }
  301. return 0;
  302. }
  303. static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
  304. {
  305. unsigned int max_q_count, q_count;
  306. unsigned int reg, reg_val;
  307. unsigned int i;
  308. /* Set MTL flow control */
  309. for (i = 0; i < pdata->rx_q_count; i++)
  310. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 1);
  311. /* Set MAC flow control */
  312. max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
  313. q_count = min_t(unsigned int, pdata->tx_q_count, max_q_count);
  314. reg = MAC_Q0TFCR;
  315. for (i = 0; i < q_count; i++) {
  316. reg_val = XGMAC_IOREAD(pdata, reg);
  317. /* Enable transmit flow control */
  318. XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
  319. /* Set pause time */
  320. XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
  321. XGMAC_IOWRITE(pdata, reg, reg_val);
  322. reg += MAC_QTFCR_INC;
  323. }
  324. return 0;
  325. }
  326. static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
  327. {
  328. XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
  329. return 0;
  330. }
  331. static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
  332. {
  333. XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
  334. return 0;
  335. }
  336. static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
  337. {
  338. struct ieee_pfc *pfc = pdata->pfc;
  339. if (pdata->tx_pause || (pfc && pfc->pfc_en))
  340. xgbe_enable_tx_flow_control(pdata);
  341. else
  342. xgbe_disable_tx_flow_control(pdata);
  343. return 0;
  344. }
  345. static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
  346. {
  347. struct ieee_pfc *pfc = pdata->pfc;
  348. if (pdata->rx_pause || (pfc && pfc->pfc_en))
  349. xgbe_enable_rx_flow_control(pdata);
  350. else
  351. xgbe_disable_rx_flow_control(pdata);
  352. return 0;
  353. }
  354. static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
  355. {
  356. struct ieee_pfc *pfc = pdata->pfc;
  357. xgbe_config_tx_flow_control(pdata);
  358. xgbe_config_rx_flow_control(pdata);
  359. XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE,
  360. (pfc && pfc->pfc_en) ? 1 : 0);
  361. }
  362. static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
  363. {
  364. struct xgbe_channel *channel;
  365. unsigned int dma_ch_isr, dma_ch_ier;
  366. unsigned int i;
  367. channel = pdata->channel;
  368. for (i = 0; i < pdata->channel_count; i++, channel++) {
  369. /* Clear all the interrupts which are set */
  370. dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
  371. XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
  372. /* Clear all interrupt enable bits */
  373. dma_ch_ier = 0;
  374. /* Enable following interrupts
  375. * NIE - Normal Interrupt Summary Enable
  376. * AIE - Abnormal Interrupt Summary Enable
  377. * FBEE - Fatal Bus Error Enable
  378. */
  379. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
  380. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
  381. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
  382. if (channel->tx_ring) {
  383. /* Enable the following Tx interrupts
  384. * TIE - Transmit Interrupt Enable (unless polling)
  385. */
  386. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
  387. }
  388. if (channel->rx_ring) {
  389. /* Enable following Rx interrupts
  390. * RBUE - Receive Buffer Unavailable Enable
  391. * RIE - Receive Interrupt Enable
  392. */
  393. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
  394. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
  395. }
  396. XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
  397. }
  398. }
  399. static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
  400. {
  401. unsigned int mtl_q_isr;
  402. unsigned int q_count, i;
  403. q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
  404. for (i = 0; i < q_count; i++) {
  405. /* Clear all the interrupts which are set */
  406. mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
  407. XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
  408. /* No MTL interrupts to be enabled */
  409. XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_IER, 0);
  410. }
  411. }
  412. static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
  413. {
  414. unsigned int mac_ier = 0;
  415. /* Enable Timestamp interrupt */
  416. XGMAC_SET_BITS(mac_ier, MAC_IER, TSIE, 1);
  417. XGMAC_IOWRITE(pdata, MAC_IER, mac_ier);
  418. /* Enable all counter interrupts */
  419. XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xffffffff);
  420. XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xffffffff);
  421. }
  422. static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
  423. {
  424. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
  425. return 0;
  426. }
  427. static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
  428. {
  429. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
  430. return 0;
  431. }
  432. static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
  433. {
  434. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
  435. return 0;
  436. }
  437. static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
  438. unsigned int enable)
  439. {
  440. unsigned int val = enable ? 1 : 0;
  441. if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
  442. return 0;
  443. DBGPR(" %s promiscuous mode\n", enable ? "entering" : "leaving");
  444. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
  445. return 0;
  446. }
  447. static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
  448. unsigned int enable)
  449. {
  450. unsigned int val = enable ? 1 : 0;
  451. if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
  452. return 0;
  453. DBGPR(" %s allmulti mode\n", enable ? "entering" : "leaving");
  454. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
  455. return 0;
  456. }
  457. static void xgbe_set_mac_reg(struct xgbe_prv_data *pdata,
  458. struct netdev_hw_addr *ha, unsigned int *mac_reg)
  459. {
  460. unsigned int mac_addr_hi, mac_addr_lo;
  461. u8 *mac_addr;
  462. mac_addr_lo = 0;
  463. mac_addr_hi = 0;
  464. if (ha) {
  465. mac_addr = (u8 *)&mac_addr_lo;
  466. mac_addr[0] = ha->addr[0];
  467. mac_addr[1] = ha->addr[1];
  468. mac_addr[2] = ha->addr[2];
  469. mac_addr[3] = ha->addr[3];
  470. mac_addr = (u8 *)&mac_addr_hi;
  471. mac_addr[0] = ha->addr[4];
  472. mac_addr[1] = ha->addr[5];
  473. DBGPR(" adding mac address %pM at 0x%04x\n", ha->addr,
  474. *mac_reg);
  475. XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
  476. }
  477. XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_hi);
  478. *mac_reg += MAC_MACA_INC;
  479. XGMAC_IOWRITE(pdata, *mac_reg, mac_addr_lo);
  480. *mac_reg += MAC_MACA_INC;
  481. }
  482. static void xgbe_set_mac_addn_addrs(struct xgbe_prv_data *pdata)
  483. {
  484. struct net_device *netdev = pdata->netdev;
  485. struct netdev_hw_addr *ha;
  486. unsigned int mac_reg;
  487. unsigned int addn_macs;
  488. mac_reg = MAC_MACA1HR;
  489. addn_macs = pdata->hw_feat.addn_mac;
  490. if (netdev_uc_count(netdev) > addn_macs) {
  491. xgbe_set_promiscuous_mode(pdata, 1);
  492. } else {
  493. netdev_for_each_uc_addr(ha, netdev) {
  494. xgbe_set_mac_reg(pdata, ha, &mac_reg);
  495. addn_macs--;
  496. }
  497. if (netdev_mc_count(netdev) > addn_macs) {
  498. xgbe_set_all_multicast_mode(pdata, 1);
  499. } else {
  500. netdev_for_each_mc_addr(ha, netdev) {
  501. xgbe_set_mac_reg(pdata, ha, &mac_reg);
  502. addn_macs--;
  503. }
  504. }
  505. }
  506. /* Clear remaining additional MAC address entries */
  507. while (addn_macs--)
  508. xgbe_set_mac_reg(pdata, NULL, &mac_reg);
  509. }
  510. static void xgbe_set_mac_hash_table(struct xgbe_prv_data *pdata)
  511. {
  512. struct net_device *netdev = pdata->netdev;
  513. struct netdev_hw_addr *ha;
  514. unsigned int hash_reg;
  515. unsigned int hash_table_shift, hash_table_count;
  516. u32 hash_table[XGBE_MAC_HASH_TABLE_SIZE];
  517. u32 crc;
  518. unsigned int i;
  519. hash_table_shift = 26 - (pdata->hw_feat.hash_table_size >> 7);
  520. hash_table_count = pdata->hw_feat.hash_table_size / 32;
  521. memset(hash_table, 0, sizeof(hash_table));
  522. /* Build the MAC Hash Table register values */
  523. netdev_for_each_uc_addr(ha, netdev) {
  524. crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
  525. crc >>= hash_table_shift;
  526. hash_table[crc >> 5] |= (1 << (crc & 0x1f));
  527. }
  528. netdev_for_each_mc_addr(ha, netdev) {
  529. crc = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN));
  530. crc >>= hash_table_shift;
  531. hash_table[crc >> 5] |= (1 << (crc & 0x1f));
  532. }
  533. /* Set the MAC Hash Table registers */
  534. hash_reg = MAC_HTR0;
  535. for (i = 0; i < hash_table_count; i++) {
  536. XGMAC_IOWRITE(pdata, hash_reg, hash_table[i]);
  537. hash_reg += MAC_HTR_INC;
  538. }
  539. }
  540. static int xgbe_add_mac_addresses(struct xgbe_prv_data *pdata)
  541. {
  542. if (pdata->hw_feat.hash_table_size)
  543. xgbe_set_mac_hash_table(pdata);
  544. else
  545. xgbe_set_mac_addn_addrs(pdata);
  546. return 0;
  547. }
  548. static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
  549. {
  550. unsigned int mac_addr_hi, mac_addr_lo;
  551. mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
  552. mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
  553. (addr[1] << 8) | (addr[0] << 0);
  554. XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
  555. XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
  556. return 0;
  557. }
  558. static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
  559. int mmd_reg)
  560. {
  561. unsigned int mmd_address;
  562. int mmd_data;
  563. if (mmd_reg & MII_ADDR_C45)
  564. mmd_address = mmd_reg & ~MII_ADDR_C45;
  565. else
  566. mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
  567. /* The PCS registers are accessed using mmio. The underlying APB3
  568. * management interface uses indirect addressing to access the MMD
  569. * register sets. This requires accessing of the PCS register in two
  570. * phases, an address phase and a data phase.
  571. *
  572. * The mmio interface is based on 32-bit offsets and values. All
  573. * register offsets must therefore be adjusted by left shifting the
  574. * offset 2 bits and reading 32 bits of data.
  575. */
  576. mutex_lock(&pdata->xpcs_mutex);
  577. XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
  578. mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
  579. mutex_unlock(&pdata->xpcs_mutex);
  580. return mmd_data;
  581. }
  582. static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
  583. int mmd_reg, int mmd_data)
  584. {
  585. unsigned int mmd_address;
  586. if (mmd_reg & MII_ADDR_C45)
  587. mmd_address = mmd_reg & ~MII_ADDR_C45;
  588. else
  589. mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
  590. /* The PCS registers are accessed using mmio. The underlying APB3
  591. * management interface uses indirect addressing to access the MMD
  592. * register sets. This requires accessing of the PCS register in two
  593. * phases, an address phase and a data phase.
  594. *
  595. * The mmio interface is based on 32-bit offsets and values. All
  596. * register offsets must therefore be adjusted by left shifting the
  597. * offset 2 bits and reading 32 bits of data.
  598. */
  599. mutex_lock(&pdata->xpcs_mutex);
  600. XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
  601. XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
  602. mutex_unlock(&pdata->xpcs_mutex);
  603. }
  604. static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
  605. {
  606. return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
  607. }
  608. static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
  609. {
  610. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
  611. return 0;
  612. }
  613. static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
  614. {
  615. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
  616. return 0;
  617. }
  618. static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
  619. {
  620. /* Put the VLAN tag in the Rx descriptor */
  621. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
  622. /* Don't check the VLAN type */
  623. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
  624. /* Check only C-TAG (0x8100) packets */
  625. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
  626. /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
  627. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
  628. /* Enable VLAN tag stripping */
  629. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
  630. return 0;
  631. }
  632. static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
  633. {
  634. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
  635. return 0;
  636. }
  637. static int xgbe_enable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
  638. {
  639. /* Enable VLAN filtering */
  640. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 1);
  641. /* Enable VLAN Hash Table filtering */
  642. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTHM, 1);
  643. /* Disable VLAN tag inverse matching */
  644. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VTIM, 0);
  645. /* Only filter on the lower 12-bits of the VLAN tag */
  646. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ETV, 1);
  647. /* In order for the VLAN Hash Table filtering to be effective,
  648. * the VLAN tag identifier in the VLAN Tag Register must not
  649. * be zero. Set the VLAN tag identifier to "1" to enable the
  650. * VLAN Hash Table filtering. This implies that a VLAN tag of
  651. * 1 will always pass filtering.
  652. */
  653. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, VL, 1);
  654. return 0;
  655. }
  656. static int xgbe_disable_rx_vlan_filtering(struct xgbe_prv_data *pdata)
  657. {
  658. /* Disable VLAN filtering */
  659. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, VTFE, 0);
  660. return 0;
  661. }
  662. #ifndef CRCPOLY_LE
  663. #define CRCPOLY_LE 0xedb88320
  664. #endif
  665. static u32 xgbe_vid_crc32_le(__le16 vid_le)
  666. {
  667. u32 poly = CRCPOLY_LE;
  668. u32 crc = ~0;
  669. u32 temp = 0;
  670. unsigned char *data = (unsigned char *)&vid_le;
  671. unsigned char data_byte = 0;
  672. int i, bits;
  673. bits = get_bitmask_order(VLAN_VID_MASK);
  674. for (i = 0; i < bits; i++) {
  675. if ((i % 8) == 0)
  676. data_byte = data[i / 8];
  677. temp = ((crc & 1) ^ data_byte) & 1;
  678. crc >>= 1;
  679. data_byte >>= 1;
  680. if (temp)
  681. crc ^= poly;
  682. }
  683. return crc;
  684. }
  685. static int xgbe_update_vlan_hash_table(struct xgbe_prv_data *pdata)
  686. {
  687. u32 crc;
  688. u16 vid;
  689. __le16 vid_le;
  690. u16 vlan_hash_table = 0;
  691. /* Generate the VLAN Hash Table value */
  692. for_each_set_bit(vid, pdata->active_vlans, VLAN_N_VID) {
  693. /* Get the CRC32 value of the VLAN ID */
  694. vid_le = cpu_to_le16(vid);
  695. crc = bitrev32(~xgbe_vid_crc32_le(vid_le)) >> 28;
  696. vlan_hash_table |= (1 << crc);
  697. }
  698. /* Set the VLAN Hash Table filtering register */
  699. XGMAC_IOWRITE_BITS(pdata, MAC_VLANHTR, VLHT, vlan_hash_table);
  700. return 0;
  701. }
  702. static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
  703. {
  704. struct xgbe_ring_desc *rdesc = rdata->rdesc;
  705. /* Reset the Tx descriptor
  706. * Set buffer 1 (lo) address to zero
  707. * Set buffer 1 (hi) address to zero
  708. * Reset all other control bits (IC, TTSE, B2L & B1L)
  709. * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
  710. */
  711. rdesc->desc0 = 0;
  712. rdesc->desc1 = 0;
  713. rdesc->desc2 = 0;
  714. rdesc->desc3 = 0;
  715. }
  716. static void xgbe_tx_desc_init(struct xgbe_channel *channel)
  717. {
  718. struct xgbe_ring *ring = channel->tx_ring;
  719. struct xgbe_ring_data *rdata;
  720. struct xgbe_ring_desc *rdesc;
  721. int i;
  722. int start_index = ring->cur;
  723. DBGPR("-->tx_desc_init\n");
  724. /* Initialze all descriptors */
  725. for (i = 0; i < ring->rdesc_count; i++) {
  726. rdata = XGBE_GET_DESC_DATA(ring, i);
  727. rdesc = rdata->rdesc;
  728. /* Initialize Tx descriptor
  729. * Set buffer 1 (lo) address to zero
  730. * Set buffer 1 (hi) address to zero
  731. * Reset all other control bits (IC, TTSE, B2L & B1L)
  732. * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC,
  733. * etc)
  734. */
  735. rdesc->desc0 = 0;
  736. rdesc->desc1 = 0;
  737. rdesc->desc2 = 0;
  738. rdesc->desc3 = 0;
  739. }
  740. /* Make sure everything is written to the descriptor(s) before
  741. * telling the device about them
  742. */
  743. wmb();
  744. /* Update the total number of Tx descriptors */
  745. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
  746. /* Update the starting address of descriptor ring */
  747. rdata = XGBE_GET_DESC_DATA(ring, start_index);
  748. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
  749. upper_32_bits(rdata->rdesc_dma));
  750. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
  751. lower_32_bits(rdata->rdesc_dma));
  752. DBGPR("<--tx_desc_init\n");
  753. }
  754. static void xgbe_rx_desc_reset(struct xgbe_ring_data *rdata)
  755. {
  756. struct xgbe_ring_desc *rdesc = rdata->rdesc;
  757. /* Reset the Rx descriptor
  758. * Set buffer 1 (lo) address to dma address (lo)
  759. * Set buffer 1 (hi) address to dma address (hi)
  760. * Set buffer 2 (lo) address to zero
  761. * Set buffer 2 (hi) address to zero and set control bits
  762. * OWN and INTE
  763. */
  764. rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
  765. rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
  766. rdesc->desc2 = 0;
  767. rdesc->desc3 = 0;
  768. if (rdata->interrupt)
  769. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
  770. /* Since the Rx DMA engine is likely running, make sure everything
  771. * is written to the descriptor(s) before setting the OWN bit
  772. * for the descriptor
  773. */
  774. wmb();
  775. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
  776. /* Make sure ownership is written to the descriptor */
  777. wmb();
  778. }
  779. static void xgbe_rx_desc_init(struct xgbe_channel *channel)
  780. {
  781. struct xgbe_prv_data *pdata = channel->pdata;
  782. struct xgbe_ring *ring = channel->rx_ring;
  783. struct xgbe_ring_data *rdata;
  784. struct xgbe_ring_desc *rdesc;
  785. unsigned int start_index = ring->cur;
  786. unsigned int rx_coalesce, rx_frames;
  787. unsigned int i;
  788. DBGPR("-->rx_desc_init\n");
  789. rx_coalesce = (pdata->rx_riwt || pdata->rx_frames) ? 1 : 0;
  790. rx_frames = pdata->rx_frames;
  791. /* Initialize all descriptors */
  792. for (i = 0; i < ring->rdesc_count; i++) {
  793. rdata = XGBE_GET_DESC_DATA(ring, i);
  794. rdesc = rdata->rdesc;
  795. /* Initialize Rx descriptor
  796. * Set buffer 1 (lo) address to dma address (lo)
  797. * Set buffer 1 (hi) address to dma address (hi)
  798. * Set buffer 2 (lo) address to zero
  799. * Set buffer 2 (hi) address to zero and set control
  800. * bits OWN and INTE appropriateley
  801. */
  802. rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
  803. rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
  804. rdesc->desc2 = 0;
  805. rdesc->desc3 = 0;
  806. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
  807. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
  808. rdata->interrupt = 1;
  809. if (rx_coalesce && (!rx_frames || ((i + 1) % rx_frames))) {
  810. /* Clear interrupt on completion bit */
  811. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE,
  812. 0);
  813. rdata->interrupt = 0;
  814. }
  815. }
  816. /* Make sure everything is written to the descriptors before
  817. * telling the device about them
  818. */
  819. wmb();
  820. /* Update the total number of Rx descriptors */
  821. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
  822. /* Update the starting address of descriptor ring */
  823. rdata = XGBE_GET_DESC_DATA(ring, start_index);
  824. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
  825. upper_32_bits(rdata->rdesc_dma));
  826. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
  827. lower_32_bits(rdata->rdesc_dma));
  828. /* Update the Rx Descriptor Tail Pointer */
  829. rdata = XGBE_GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
  830. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
  831. lower_32_bits(rdata->rdesc_dma));
  832. DBGPR("<--rx_desc_init\n");
  833. }
  834. static void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
  835. unsigned int addend)
  836. {
  837. /* Set the addend register value and tell the device */
  838. XGMAC_IOWRITE(pdata, MAC_TSAR, addend);
  839. XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
  840. /* Wait for addend update to complete */
  841. while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
  842. udelay(5);
  843. }
  844. static void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
  845. unsigned int nsec)
  846. {
  847. /* Set the time values and tell the device */
  848. XGMAC_IOWRITE(pdata, MAC_STSUR, sec);
  849. XGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
  850. XGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
  851. /* Wait for time update to complete */
  852. while (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
  853. udelay(5);
  854. }
  855. static u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata)
  856. {
  857. u64 nsec;
  858. nsec = XGMAC_IOREAD(pdata, MAC_STSR);
  859. nsec *= NSEC_PER_SEC;
  860. nsec += XGMAC_IOREAD(pdata, MAC_STNR);
  861. return nsec;
  862. }
  863. static u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata)
  864. {
  865. unsigned int tx_snr;
  866. u64 nsec;
  867. tx_snr = XGMAC_IOREAD(pdata, MAC_TXSNR);
  868. if (XGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS))
  869. return 0;
  870. nsec = XGMAC_IOREAD(pdata, MAC_TXSSR);
  871. nsec *= NSEC_PER_SEC;
  872. nsec += tx_snr;
  873. return nsec;
  874. }
  875. static void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
  876. struct xgbe_ring_desc *rdesc)
  877. {
  878. u64 nsec;
  879. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSA) &&
  880. !XGMAC_GET_BITS_LE(rdesc->desc3, RX_CONTEXT_DESC3, TSD)) {
  881. nsec = le32_to_cpu(rdesc->desc1);
  882. nsec <<= 32;
  883. nsec |= le32_to_cpu(rdesc->desc0);
  884. if (nsec != 0xffffffffffffffffULL) {
  885. packet->rx_tstamp = nsec;
  886. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  887. RX_TSTAMP, 1);
  888. }
  889. }
  890. }
  891. static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
  892. unsigned int mac_tscr)
  893. {
  894. /* Set one nano-second accuracy */
  895. XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
  896. /* Set fine timestamp update */
  897. XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
  898. /* Overwrite earlier timestamps */
  899. XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
  900. XGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
  901. /* Exit if timestamping is not enabled */
  902. if (!XGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA))
  903. return 0;
  904. /* Initialize time registers */
  905. XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, XGBE_TSTAMP_SSINC);
  906. XGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, XGBE_TSTAMP_SNSINC);
  907. xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
  908. xgbe_set_tstamp_time(pdata, 0, 0);
  909. /* Initialize the timecounter */
  910. timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
  911. ktime_to_ns(ktime_get_real()));
  912. return 0;
  913. }
  914. static void xgbe_config_dcb_tc(struct xgbe_prv_data *pdata)
  915. {
  916. struct ieee_ets *ets = pdata->ets;
  917. unsigned int total_weight, min_weight, weight;
  918. unsigned int i;
  919. if (!ets)
  920. return;
  921. /* Set Tx to deficit weighted round robin scheduling algorithm (when
  922. * traffic class is using ETS algorithm)
  923. */
  924. XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_DWRR);
  925. /* Set Traffic Class algorithms */
  926. total_weight = pdata->netdev->mtu * pdata->hw_feat.tc_cnt;
  927. min_weight = total_weight / 100;
  928. if (!min_weight)
  929. min_weight = 1;
  930. for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
  931. switch (ets->tc_tsa[i]) {
  932. case IEEE_8021QAZ_TSA_STRICT:
  933. DBGPR(" TC%u using SP\n", i);
  934. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
  935. MTL_TSA_SP);
  936. break;
  937. case IEEE_8021QAZ_TSA_ETS:
  938. weight = total_weight * ets->tc_tx_bw[i] / 100;
  939. weight = clamp(weight, min_weight, total_weight);
  940. DBGPR(" TC%u using DWRR (weight %u)\n", i, weight);
  941. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
  942. MTL_TSA_ETS);
  943. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW,
  944. weight);
  945. break;
  946. }
  947. }
  948. }
  949. static void xgbe_config_dcb_pfc(struct xgbe_prv_data *pdata)
  950. {
  951. struct ieee_pfc *pfc = pdata->pfc;
  952. struct ieee_ets *ets = pdata->ets;
  953. unsigned int mask, reg, reg_val;
  954. unsigned int tc, prio;
  955. if (!pfc || !ets)
  956. return;
  957. for (tc = 0; tc < pdata->hw_feat.tc_cnt; tc++) {
  958. mask = 0;
  959. for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++) {
  960. if ((pfc->pfc_en & (1 << prio)) &&
  961. (ets->prio_tc[prio] == tc))
  962. mask |= (1 << prio);
  963. }
  964. mask &= 0xff;
  965. DBGPR(" TC%u PFC mask=%#x\n", tc, mask);
  966. reg = MTL_TCPM0R + (MTL_TCPM_INC * (tc / MTL_TCPM_TC_PER_REG));
  967. reg_val = XGMAC_IOREAD(pdata, reg);
  968. reg_val &= ~(0xff << ((tc % MTL_TCPM_TC_PER_REG) << 3));
  969. reg_val |= (mask << ((tc % MTL_TCPM_TC_PER_REG) << 3));
  970. XGMAC_IOWRITE(pdata, reg, reg_val);
  971. }
  972. xgbe_config_flow_control(pdata);
  973. }
  974. static void xgbe_pre_xmit(struct xgbe_channel *channel)
  975. {
  976. struct xgbe_prv_data *pdata = channel->pdata;
  977. struct xgbe_ring *ring = channel->tx_ring;
  978. struct xgbe_ring_data *rdata;
  979. struct xgbe_ring_desc *rdesc;
  980. struct xgbe_packet_data *packet = &ring->packet_data;
  981. unsigned int csum, tso, vlan;
  982. unsigned int tso_context, vlan_context;
  983. unsigned int tx_coalesce, tx_frames;
  984. int start_index = ring->cur;
  985. int i;
  986. DBGPR("-->xgbe_pre_xmit\n");
  987. csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
  988. CSUM_ENABLE);
  989. tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
  990. TSO_ENABLE);
  991. vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
  992. VLAN_CTAG);
  993. if (tso && (packet->mss != ring->tx.cur_mss))
  994. tso_context = 1;
  995. else
  996. tso_context = 0;
  997. if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
  998. vlan_context = 1;
  999. else
  1000. vlan_context = 0;
  1001. tx_coalesce = (pdata->tx_usecs || pdata->tx_frames) ? 1 : 0;
  1002. tx_frames = pdata->tx_frames;
  1003. if (tx_coalesce && !channel->tx_timer_active)
  1004. ring->coalesce_count = 0;
  1005. rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
  1006. rdesc = rdata->rdesc;
  1007. /* Create a context descriptor if this is a TSO packet */
  1008. if (tso_context || vlan_context) {
  1009. if (tso_context) {
  1010. DBGPR(" TSO context descriptor, mss=%u\n",
  1011. packet->mss);
  1012. /* Set the MSS size */
  1013. XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
  1014. MSS, packet->mss);
  1015. /* Mark it as a CONTEXT descriptor */
  1016. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  1017. CTXT, 1);
  1018. /* Indicate this descriptor contains the MSS */
  1019. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  1020. TCMSSV, 1);
  1021. ring->tx.cur_mss = packet->mss;
  1022. }
  1023. if (vlan_context) {
  1024. DBGPR(" VLAN context descriptor, ctag=%u\n",
  1025. packet->vlan_ctag);
  1026. /* Mark it as a CONTEXT descriptor */
  1027. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  1028. CTXT, 1);
  1029. /* Set the VLAN tag */
  1030. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  1031. VT, packet->vlan_ctag);
  1032. /* Indicate this descriptor contains the VLAN tag */
  1033. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  1034. VLTV, 1);
  1035. ring->tx.cur_vlan_ctag = packet->vlan_ctag;
  1036. }
  1037. ring->cur++;
  1038. rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
  1039. rdesc = rdata->rdesc;
  1040. }
  1041. /* Update buffer address (for TSO this is the header) */
  1042. rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
  1043. rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
  1044. /* Update the buffer length */
  1045. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
  1046. rdata->skb_dma_len);
  1047. /* VLAN tag insertion check */
  1048. if (vlan)
  1049. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
  1050. TX_NORMAL_DESC2_VLAN_INSERT);
  1051. /* Timestamp enablement check */
  1052. if (XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES, PTP))
  1053. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, TTSE, 1);
  1054. /* Set IC bit based on Tx coalescing settings */
  1055. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
  1056. if (tx_coalesce && (!tx_frames ||
  1057. (++ring->coalesce_count % tx_frames)))
  1058. /* Clear IC bit */
  1059. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
  1060. /* Mark it as First Descriptor */
  1061. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
  1062. /* Mark it as a NORMAL descriptor */
  1063. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
  1064. /* Set OWN bit if not the first descriptor */
  1065. if (ring->cur != start_index)
  1066. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
  1067. if (tso) {
  1068. /* Enable TSO */
  1069. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
  1070. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
  1071. packet->tcp_payload_len);
  1072. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
  1073. packet->tcp_header_len / 4);
  1074. } else {
  1075. /* Enable CRC and Pad Insertion */
  1076. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
  1077. /* Enable HW CSUM */
  1078. if (csum)
  1079. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
  1080. CIC, 0x3);
  1081. /* Set the total length to be transmitted */
  1082. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
  1083. packet->length);
  1084. }
  1085. for (i = ring->cur - start_index + 1; i < packet->rdesc_count; i++) {
  1086. ring->cur++;
  1087. rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
  1088. rdesc = rdata->rdesc;
  1089. /* Update buffer address */
  1090. rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
  1091. rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
  1092. /* Update the buffer length */
  1093. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
  1094. rdata->skb_dma_len);
  1095. /* Set IC bit based on Tx coalescing settings */
  1096. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
  1097. if (tx_coalesce && (!tx_frames ||
  1098. (++ring->coalesce_count % tx_frames)))
  1099. /* Clear IC bit */
  1100. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
  1101. /* Set OWN bit */
  1102. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
  1103. /* Mark it as NORMAL descriptor */
  1104. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
  1105. /* Enable HW CSUM */
  1106. if (csum)
  1107. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
  1108. CIC, 0x3);
  1109. }
  1110. /* Set LAST bit for the last descriptor */
  1111. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
  1112. /* In case the Tx DMA engine is running, make sure everything
  1113. * is written to the descriptor(s) before setting the OWN bit
  1114. * for the first descriptor
  1115. */
  1116. wmb();
  1117. /* Set OWN bit for the first descriptor */
  1118. rdata = XGBE_GET_DESC_DATA(ring, start_index);
  1119. rdesc = rdata->rdesc;
  1120. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
  1121. #ifdef XGMAC_ENABLE_TX_DESC_DUMP
  1122. xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
  1123. #endif
  1124. /* Make sure ownership is written to the descriptor */
  1125. wmb();
  1126. /* Issue a poll command to Tx DMA by writing address
  1127. * of next immediate free descriptor */
  1128. ring->cur++;
  1129. rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
  1130. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
  1131. lower_32_bits(rdata->rdesc_dma));
  1132. /* Start the Tx coalescing timer */
  1133. if (tx_coalesce && !channel->tx_timer_active) {
  1134. channel->tx_timer_active = 1;
  1135. hrtimer_start(&channel->tx_timer,
  1136. ktime_set(0, pdata->tx_usecs * NSEC_PER_USEC),
  1137. HRTIMER_MODE_REL);
  1138. }
  1139. DBGPR(" %s: descriptors %u to %u written\n",
  1140. channel->name, start_index & (ring->rdesc_count - 1),
  1141. (ring->cur - 1) & (ring->rdesc_count - 1));
  1142. DBGPR("<--xgbe_pre_xmit\n");
  1143. }
  1144. static int xgbe_dev_read(struct xgbe_channel *channel)
  1145. {
  1146. struct xgbe_ring *ring = channel->rx_ring;
  1147. struct xgbe_ring_data *rdata;
  1148. struct xgbe_ring_desc *rdesc;
  1149. struct xgbe_packet_data *packet = &ring->packet_data;
  1150. struct net_device *netdev = channel->pdata->netdev;
  1151. unsigned int err, etlt;
  1152. DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
  1153. rdata = XGBE_GET_DESC_DATA(ring, ring->cur);
  1154. rdesc = rdata->rdesc;
  1155. /* Check for data availability */
  1156. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
  1157. return 1;
  1158. #ifdef XGMAC_ENABLE_RX_DESC_DUMP
  1159. xgbe_dump_rx_desc(ring, rdesc, ring->cur);
  1160. #endif
  1161. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CTXT)) {
  1162. /* Timestamp Context Descriptor */
  1163. xgbe_get_rx_tstamp(packet, rdesc);
  1164. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1165. CONTEXT, 1);
  1166. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1167. CONTEXT_NEXT, 0);
  1168. return 0;
  1169. }
  1170. /* Normal Descriptor, be sure Context Descriptor bit is off */
  1171. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT, 0);
  1172. /* Indicate if a Context Descriptor is next */
  1173. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, CDA))
  1174. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1175. CONTEXT_NEXT, 1);
  1176. /* Get the packet length */
  1177. rdata->len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
  1178. if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
  1179. /* Not all the data has been transferred for this packet */
  1180. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1181. INCOMPLETE, 1);
  1182. return 0;
  1183. }
  1184. /* This is the last of the data for this packet */
  1185. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1186. INCOMPLETE, 0);
  1187. /* Set checksum done indicator as appropriate */
  1188. if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
  1189. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1190. CSUM_DONE, 1);
  1191. /* Check for errors (only valid in last descriptor) */
  1192. err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
  1193. etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
  1194. DBGPR(" err=%u, etlt=%#x\n", err, etlt);
  1195. if (!err || (err && !etlt)) {
  1196. if ((etlt == 0x09) &&
  1197. (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
  1198. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1199. VLAN_CTAG, 1);
  1200. packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
  1201. RX_NORMAL_DESC0,
  1202. OVT);
  1203. DBGPR(" vlan-ctag=0x%04x\n", packet->vlan_ctag);
  1204. }
  1205. } else {
  1206. if ((etlt == 0x05) || (etlt == 0x06))
  1207. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  1208. CSUM_DONE, 0);
  1209. else
  1210. XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
  1211. FRAME, 1);
  1212. }
  1213. DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
  1214. ring->cur & (ring->rdesc_count - 1), ring->cur);
  1215. return 0;
  1216. }
  1217. static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
  1218. {
  1219. /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
  1220. return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
  1221. }
  1222. static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
  1223. {
  1224. /* Rx and Tx share LD bit, so check TDES3.LD bit */
  1225. return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
  1226. }
  1227. static int xgbe_enable_int(struct xgbe_channel *channel,
  1228. enum xgbe_int int_id)
  1229. {
  1230. unsigned int dma_ch_ier;
  1231. dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
  1232. switch (int_id) {
  1233. case XGMAC_INT_DMA_CH_SR_TI:
  1234. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
  1235. break;
  1236. case XGMAC_INT_DMA_CH_SR_TPS:
  1237. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 1);
  1238. break;
  1239. case XGMAC_INT_DMA_CH_SR_TBU:
  1240. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 1);
  1241. break;
  1242. case XGMAC_INT_DMA_CH_SR_RI:
  1243. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
  1244. break;
  1245. case XGMAC_INT_DMA_CH_SR_RBU:
  1246. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
  1247. break;
  1248. case XGMAC_INT_DMA_CH_SR_RPS:
  1249. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 1);
  1250. break;
  1251. case XGMAC_INT_DMA_CH_SR_TI_RI:
  1252. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
  1253. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
  1254. break;
  1255. case XGMAC_INT_DMA_CH_SR_FBE:
  1256. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
  1257. break;
  1258. case XGMAC_INT_DMA_ALL:
  1259. dma_ch_ier |= channel->saved_ier;
  1260. break;
  1261. default:
  1262. return -1;
  1263. }
  1264. XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
  1265. return 0;
  1266. }
  1267. static int xgbe_disable_int(struct xgbe_channel *channel,
  1268. enum xgbe_int int_id)
  1269. {
  1270. unsigned int dma_ch_ier;
  1271. dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
  1272. switch (int_id) {
  1273. case XGMAC_INT_DMA_CH_SR_TI:
  1274. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
  1275. break;
  1276. case XGMAC_INT_DMA_CH_SR_TPS:
  1277. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TXSE, 0);
  1278. break;
  1279. case XGMAC_INT_DMA_CH_SR_TBU:
  1280. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TBUE, 0);
  1281. break;
  1282. case XGMAC_INT_DMA_CH_SR_RI:
  1283. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
  1284. break;
  1285. case XGMAC_INT_DMA_CH_SR_RBU:
  1286. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 0);
  1287. break;
  1288. case XGMAC_INT_DMA_CH_SR_RPS:
  1289. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RSE, 0);
  1290. break;
  1291. case XGMAC_INT_DMA_CH_SR_TI_RI:
  1292. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 0);
  1293. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 0);
  1294. break;
  1295. case XGMAC_INT_DMA_CH_SR_FBE:
  1296. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 0);
  1297. break;
  1298. case XGMAC_INT_DMA_ALL:
  1299. channel->saved_ier = dma_ch_ier & XGBE_DMA_INTERRUPT_MASK;
  1300. dma_ch_ier &= ~XGBE_DMA_INTERRUPT_MASK;
  1301. break;
  1302. default:
  1303. return -1;
  1304. }
  1305. XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
  1306. return 0;
  1307. }
  1308. static int xgbe_exit(struct xgbe_prv_data *pdata)
  1309. {
  1310. unsigned int count = 2000;
  1311. DBGPR("-->xgbe_exit\n");
  1312. /* Issue a software reset */
  1313. XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
  1314. usleep_range(10, 15);
  1315. /* Poll Until Poll Condition */
  1316. while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
  1317. usleep_range(500, 600);
  1318. if (!count)
  1319. return -EBUSY;
  1320. DBGPR("<--xgbe_exit\n");
  1321. return 0;
  1322. }
  1323. static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
  1324. {
  1325. unsigned int i, count;
  1326. if (XGMAC_GET_BITS(pdata->hw_feat.version, MAC_VR, SNPSVER) < 0x21)
  1327. return 0;
  1328. for (i = 0; i < pdata->tx_q_count; i++)
  1329. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
  1330. /* Poll Until Poll Condition */
  1331. for (i = 0; i < pdata->tx_q_count; i++) {
  1332. count = 2000;
  1333. while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
  1334. MTL_Q_TQOMR, FTQ))
  1335. usleep_range(500, 600);
  1336. if (!count)
  1337. return -EBUSY;
  1338. }
  1339. return 0;
  1340. }
  1341. static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
  1342. {
  1343. /* Set enhanced addressing mode */
  1344. XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
  1345. /* Set the System Bus mode */
  1346. XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
  1347. XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, BLEN_256, 1);
  1348. }
  1349. static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
  1350. {
  1351. unsigned int arcache, awcache;
  1352. arcache = 0;
  1353. XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, pdata->arcache);
  1354. XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, pdata->axdomain);
  1355. XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, pdata->arcache);
  1356. XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, pdata->axdomain);
  1357. XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, pdata->arcache);
  1358. XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, pdata->axdomain);
  1359. XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
  1360. awcache = 0;
  1361. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, pdata->awcache);
  1362. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, pdata->axdomain);
  1363. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, pdata->awcache);
  1364. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, pdata->axdomain);
  1365. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, pdata->awcache);
  1366. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, pdata->axdomain);
  1367. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, pdata->awcache);
  1368. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, pdata->axdomain);
  1369. XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
  1370. }
  1371. static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
  1372. {
  1373. unsigned int i;
  1374. /* Set Tx to weighted round robin scheduling algorithm */
  1375. XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
  1376. /* Set Tx traffic classes to use WRR algorithm with equal weights */
  1377. for (i = 0; i < pdata->hw_feat.tc_cnt; i++) {
  1378. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA,
  1379. MTL_TSA_ETS);
  1380. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_QWR, QW, 1);
  1381. }
  1382. /* Set Rx to strict priority algorithm */
  1383. XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
  1384. }
  1385. static unsigned int xgbe_calculate_per_queue_fifo(unsigned int fifo_size,
  1386. unsigned int queue_count)
  1387. {
  1388. unsigned int q_fifo_size = 0;
  1389. enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
  1390. /* Calculate Tx/Rx fifo share per queue */
  1391. switch (fifo_size) {
  1392. case 0:
  1393. q_fifo_size = XGBE_FIFO_SIZE_B(128);
  1394. break;
  1395. case 1:
  1396. q_fifo_size = XGBE_FIFO_SIZE_B(256);
  1397. break;
  1398. case 2:
  1399. q_fifo_size = XGBE_FIFO_SIZE_B(512);
  1400. break;
  1401. case 3:
  1402. q_fifo_size = XGBE_FIFO_SIZE_KB(1);
  1403. break;
  1404. case 4:
  1405. q_fifo_size = XGBE_FIFO_SIZE_KB(2);
  1406. break;
  1407. case 5:
  1408. q_fifo_size = XGBE_FIFO_SIZE_KB(4);
  1409. break;
  1410. case 6:
  1411. q_fifo_size = XGBE_FIFO_SIZE_KB(8);
  1412. break;
  1413. case 7:
  1414. q_fifo_size = XGBE_FIFO_SIZE_KB(16);
  1415. break;
  1416. case 8:
  1417. q_fifo_size = XGBE_FIFO_SIZE_KB(32);
  1418. break;
  1419. case 9:
  1420. q_fifo_size = XGBE_FIFO_SIZE_KB(64);
  1421. break;
  1422. case 10:
  1423. q_fifo_size = XGBE_FIFO_SIZE_KB(128);
  1424. break;
  1425. case 11:
  1426. q_fifo_size = XGBE_FIFO_SIZE_KB(256);
  1427. break;
  1428. }
  1429. /* The configured value is not the actual amount of fifo RAM */
  1430. q_fifo_size = min_t(unsigned int, XGBE_FIFO_MAX, q_fifo_size);
  1431. q_fifo_size = q_fifo_size / queue_count;
  1432. /* Set the queue fifo size programmable value */
  1433. if (q_fifo_size >= XGBE_FIFO_SIZE_KB(256))
  1434. p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
  1435. else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(128))
  1436. p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
  1437. else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(64))
  1438. p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
  1439. else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(32))
  1440. p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
  1441. else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(16))
  1442. p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
  1443. else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(8))
  1444. p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
  1445. else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(4))
  1446. p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
  1447. else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(2))
  1448. p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
  1449. else if (q_fifo_size >= XGBE_FIFO_SIZE_KB(1))
  1450. p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
  1451. else if (q_fifo_size >= XGBE_FIFO_SIZE_B(512))
  1452. p_fifo = XGMAC_MTL_FIFO_SIZE_512;
  1453. else if (q_fifo_size >= XGBE_FIFO_SIZE_B(256))
  1454. p_fifo = XGMAC_MTL_FIFO_SIZE_256;
  1455. return p_fifo;
  1456. }
  1457. static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
  1458. {
  1459. enum xgbe_mtl_fifo_size fifo_size;
  1460. unsigned int i;
  1461. fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
  1462. pdata->tx_q_count);
  1463. for (i = 0; i < pdata->tx_q_count; i++)
  1464. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
  1465. netdev_notice(pdata->netdev, "%d Tx queues, %d byte fifo per queue\n",
  1466. pdata->tx_q_count, ((fifo_size + 1) * 256));
  1467. }
  1468. static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
  1469. {
  1470. enum xgbe_mtl_fifo_size fifo_size;
  1471. unsigned int i;
  1472. fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
  1473. pdata->rx_q_count);
  1474. for (i = 0; i < pdata->rx_q_count; i++)
  1475. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
  1476. netdev_notice(pdata->netdev, "%d Rx queues, %d byte fifo per queue\n",
  1477. pdata->rx_q_count, ((fifo_size + 1) * 256));
  1478. }
  1479. static void xgbe_config_queue_mapping(struct xgbe_prv_data *pdata)
  1480. {
  1481. unsigned int qptc, qptc_extra, queue;
  1482. unsigned int prio_queues;
  1483. unsigned int ppq, ppq_extra, prio;
  1484. unsigned int mask;
  1485. unsigned int i, j, reg, reg_val;
  1486. /* Map the MTL Tx Queues to Traffic Classes
  1487. * Note: Tx Queues >= Traffic Classes
  1488. */
  1489. qptc = pdata->tx_q_count / pdata->hw_feat.tc_cnt;
  1490. qptc_extra = pdata->tx_q_count % pdata->hw_feat.tc_cnt;
  1491. for (i = 0, queue = 0; i < pdata->hw_feat.tc_cnt; i++) {
  1492. for (j = 0; j < qptc; j++) {
  1493. DBGPR(" TXq%u mapped to TC%u\n", queue, i);
  1494. XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
  1495. Q2TCMAP, i);
  1496. pdata->q2tc_map[queue++] = i;
  1497. }
  1498. if (i < qptc_extra) {
  1499. DBGPR(" TXq%u mapped to TC%u\n", queue, i);
  1500. XGMAC_MTL_IOWRITE_BITS(pdata, queue, MTL_Q_TQOMR,
  1501. Q2TCMAP, i);
  1502. pdata->q2tc_map[queue++] = i;
  1503. }
  1504. }
  1505. /* Map the 8 VLAN priority values to available MTL Rx queues */
  1506. prio_queues = min_t(unsigned int, IEEE_8021QAZ_MAX_TCS,
  1507. pdata->rx_q_count);
  1508. ppq = IEEE_8021QAZ_MAX_TCS / prio_queues;
  1509. ppq_extra = IEEE_8021QAZ_MAX_TCS % prio_queues;
  1510. reg = MAC_RQC2R;
  1511. reg_val = 0;
  1512. for (i = 0, prio = 0; i < prio_queues;) {
  1513. mask = 0;
  1514. for (j = 0; j < ppq; j++) {
  1515. DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
  1516. mask |= (1 << prio);
  1517. pdata->prio2q_map[prio++] = i;
  1518. }
  1519. if (i < ppq_extra) {
  1520. DBGPR(" PRIO%u mapped to RXq%u\n", prio, i);
  1521. mask |= (1 << prio);
  1522. pdata->prio2q_map[prio++] = i;
  1523. }
  1524. reg_val |= (mask << ((i++ % MAC_RQC2_Q_PER_REG) << 3));
  1525. if ((i % MAC_RQC2_Q_PER_REG) && (i != prio_queues))
  1526. continue;
  1527. XGMAC_IOWRITE(pdata, reg, reg_val);
  1528. reg += MAC_RQC2_INC;
  1529. reg_val = 0;
  1530. }
  1531. /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
  1532. reg = MTL_RQDCM0R;
  1533. reg_val = 0;
  1534. for (i = 0; i < pdata->rx_q_count;) {
  1535. reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
  1536. if ((i % MTL_RQDCM_Q_PER_REG) && (i != pdata->rx_q_count))
  1537. continue;
  1538. XGMAC_IOWRITE(pdata, reg, reg_val);
  1539. reg += MTL_RQDCM_INC;
  1540. reg_val = 0;
  1541. }
  1542. }
  1543. static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
  1544. {
  1545. unsigned int i;
  1546. for (i = 0; i < pdata->rx_q_count; i++) {
  1547. /* Activate flow control when less than 4k left in fifo */
  1548. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFA, 2);
  1549. /* De-activate flow control when more than 6k left in fifo */
  1550. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFD, 4);
  1551. }
  1552. }
  1553. static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
  1554. {
  1555. xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
  1556. /* Filtering is done using perfect filtering and hash filtering */
  1557. if (pdata->hw_feat.hash_table_size) {
  1558. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
  1559. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
  1560. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 1);
  1561. }
  1562. }
  1563. static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
  1564. {
  1565. unsigned int val;
  1566. val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
  1567. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
  1568. }
  1569. static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
  1570. {
  1571. if (pdata->netdev->features & NETIF_F_RXCSUM)
  1572. xgbe_enable_rx_csum(pdata);
  1573. else
  1574. xgbe_disable_rx_csum(pdata);
  1575. }
  1576. static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
  1577. {
  1578. /* Indicate that VLAN Tx CTAGs come from context descriptors */
  1579. XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
  1580. XGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
  1581. /* Set the current VLAN Hash Table register value */
  1582. xgbe_update_vlan_hash_table(pdata);
  1583. if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
  1584. xgbe_enable_rx_vlan_filtering(pdata);
  1585. else
  1586. xgbe_disable_rx_vlan_filtering(pdata);
  1587. if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  1588. xgbe_enable_rx_vlan_stripping(pdata);
  1589. else
  1590. xgbe_disable_rx_vlan_stripping(pdata);
  1591. }
  1592. static u64 xgbe_mmc_read(struct xgbe_prv_data *pdata, unsigned int reg_lo)
  1593. {
  1594. bool read_hi;
  1595. u64 val;
  1596. switch (reg_lo) {
  1597. /* These registers are always 64 bit */
  1598. case MMC_TXOCTETCOUNT_GB_LO:
  1599. case MMC_TXOCTETCOUNT_G_LO:
  1600. case MMC_RXOCTETCOUNT_GB_LO:
  1601. case MMC_RXOCTETCOUNT_G_LO:
  1602. read_hi = true;
  1603. break;
  1604. default:
  1605. read_hi = false;
  1606. };
  1607. val = XGMAC_IOREAD(pdata, reg_lo);
  1608. if (read_hi)
  1609. val |= ((u64)XGMAC_IOREAD(pdata, reg_lo + 4) << 32);
  1610. return val;
  1611. }
  1612. static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
  1613. {
  1614. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  1615. unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
  1616. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
  1617. stats->txoctetcount_gb +=
  1618. xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
  1619. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
  1620. stats->txframecount_gb +=
  1621. xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
  1622. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
  1623. stats->txbroadcastframes_g +=
  1624. xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
  1625. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
  1626. stats->txmulticastframes_g +=
  1627. xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
  1628. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
  1629. stats->tx64octets_gb +=
  1630. xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
  1631. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
  1632. stats->tx65to127octets_gb +=
  1633. xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
  1634. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
  1635. stats->tx128to255octets_gb +=
  1636. xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
  1637. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
  1638. stats->tx256to511octets_gb +=
  1639. xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
  1640. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
  1641. stats->tx512to1023octets_gb +=
  1642. xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
  1643. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
  1644. stats->tx1024tomaxoctets_gb +=
  1645. xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
  1646. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
  1647. stats->txunicastframes_gb +=
  1648. xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
  1649. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
  1650. stats->txmulticastframes_gb +=
  1651. xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
  1652. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
  1653. stats->txbroadcastframes_g +=
  1654. xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
  1655. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
  1656. stats->txunderflowerror +=
  1657. xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
  1658. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
  1659. stats->txoctetcount_g +=
  1660. xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
  1661. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
  1662. stats->txframecount_g +=
  1663. xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
  1664. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
  1665. stats->txpauseframes +=
  1666. xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
  1667. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
  1668. stats->txvlanframes_g +=
  1669. xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
  1670. }
  1671. static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
  1672. {
  1673. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  1674. unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
  1675. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
  1676. stats->rxframecount_gb +=
  1677. xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
  1678. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
  1679. stats->rxoctetcount_gb +=
  1680. xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
  1681. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
  1682. stats->rxoctetcount_g +=
  1683. xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
  1684. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
  1685. stats->rxbroadcastframes_g +=
  1686. xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
  1687. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
  1688. stats->rxmulticastframes_g +=
  1689. xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
  1690. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
  1691. stats->rxcrcerror +=
  1692. xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
  1693. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
  1694. stats->rxrunterror +=
  1695. xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
  1696. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
  1697. stats->rxjabbererror +=
  1698. xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
  1699. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
  1700. stats->rxundersize_g +=
  1701. xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
  1702. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
  1703. stats->rxoversize_g +=
  1704. xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
  1705. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
  1706. stats->rx64octets_gb +=
  1707. xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
  1708. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
  1709. stats->rx65to127octets_gb +=
  1710. xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
  1711. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
  1712. stats->rx128to255octets_gb +=
  1713. xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
  1714. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
  1715. stats->rx256to511octets_gb +=
  1716. xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
  1717. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
  1718. stats->rx512to1023octets_gb +=
  1719. xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
  1720. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
  1721. stats->rx1024tomaxoctets_gb +=
  1722. xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
  1723. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
  1724. stats->rxunicastframes_g +=
  1725. xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
  1726. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
  1727. stats->rxlengtherror +=
  1728. xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
  1729. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
  1730. stats->rxoutofrangetype +=
  1731. xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
  1732. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
  1733. stats->rxpauseframes +=
  1734. xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
  1735. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
  1736. stats->rxfifooverflow +=
  1737. xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
  1738. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
  1739. stats->rxvlanframes_gb +=
  1740. xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
  1741. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
  1742. stats->rxwatchdogerror +=
  1743. xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
  1744. }
  1745. static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
  1746. {
  1747. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  1748. /* Freeze counters */
  1749. XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
  1750. stats->txoctetcount_gb +=
  1751. xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_GB_LO);
  1752. stats->txframecount_gb +=
  1753. xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_GB_LO);
  1754. stats->txbroadcastframes_g +=
  1755. xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_G_LO);
  1756. stats->txmulticastframes_g +=
  1757. xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_G_LO);
  1758. stats->tx64octets_gb +=
  1759. xgbe_mmc_read(pdata, MMC_TX64OCTETS_GB_LO);
  1760. stats->tx65to127octets_gb +=
  1761. xgbe_mmc_read(pdata, MMC_TX65TO127OCTETS_GB_LO);
  1762. stats->tx128to255octets_gb +=
  1763. xgbe_mmc_read(pdata, MMC_TX128TO255OCTETS_GB_LO);
  1764. stats->tx256to511octets_gb +=
  1765. xgbe_mmc_read(pdata, MMC_TX256TO511OCTETS_GB_LO);
  1766. stats->tx512to1023octets_gb +=
  1767. xgbe_mmc_read(pdata, MMC_TX512TO1023OCTETS_GB_LO);
  1768. stats->tx1024tomaxoctets_gb +=
  1769. xgbe_mmc_read(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
  1770. stats->txunicastframes_gb +=
  1771. xgbe_mmc_read(pdata, MMC_TXUNICASTFRAMES_GB_LO);
  1772. stats->txmulticastframes_gb +=
  1773. xgbe_mmc_read(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
  1774. stats->txbroadcastframes_g +=
  1775. xgbe_mmc_read(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
  1776. stats->txunderflowerror +=
  1777. xgbe_mmc_read(pdata, MMC_TXUNDERFLOWERROR_LO);
  1778. stats->txoctetcount_g +=
  1779. xgbe_mmc_read(pdata, MMC_TXOCTETCOUNT_G_LO);
  1780. stats->txframecount_g +=
  1781. xgbe_mmc_read(pdata, MMC_TXFRAMECOUNT_G_LO);
  1782. stats->txpauseframes +=
  1783. xgbe_mmc_read(pdata, MMC_TXPAUSEFRAMES_LO);
  1784. stats->txvlanframes_g +=
  1785. xgbe_mmc_read(pdata, MMC_TXVLANFRAMES_G_LO);
  1786. stats->rxframecount_gb +=
  1787. xgbe_mmc_read(pdata, MMC_RXFRAMECOUNT_GB_LO);
  1788. stats->rxoctetcount_gb +=
  1789. xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_GB_LO);
  1790. stats->rxoctetcount_g +=
  1791. xgbe_mmc_read(pdata, MMC_RXOCTETCOUNT_G_LO);
  1792. stats->rxbroadcastframes_g +=
  1793. xgbe_mmc_read(pdata, MMC_RXBROADCASTFRAMES_G_LO);
  1794. stats->rxmulticastframes_g +=
  1795. xgbe_mmc_read(pdata, MMC_RXMULTICASTFRAMES_G_LO);
  1796. stats->rxcrcerror +=
  1797. xgbe_mmc_read(pdata, MMC_RXCRCERROR_LO);
  1798. stats->rxrunterror +=
  1799. xgbe_mmc_read(pdata, MMC_RXRUNTERROR);
  1800. stats->rxjabbererror +=
  1801. xgbe_mmc_read(pdata, MMC_RXJABBERERROR);
  1802. stats->rxundersize_g +=
  1803. xgbe_mmc_read(pdata, MMC_RXUNDERSIZE_G);
  1804. stats->rxoversize_g +=
  1805. xgbe_mmc_read(pdata, MMC_RXOVERSIZE_G);
  1806. stats->rx64octets_gb +=
  1807. xgbe_mmc_read(pdata, MMC_RX64OCTETS_GB_LO);
  1808. stats->rx65to127octets_gb +=
  1809. xgbe_mmc_read(pdata, MMC_RX65TO127OCTETS_GB_LO);
  1810. stats->rx128to255octets_gb +=
  1811. xgbe_mmc_read(pdata, MMC_RX128TO255OCTETS_GB_LO);
  1812. stats->rx256to511octets_gb +=
  1813. xgbe_mmc_read(pdata, MMC_RX256TO511OCTETS_GB_LO);
  1814. stats->rx512to1023octets_gb +=
  1815. xgbe_mmc_read(pdata, MMC_RX512TO1023OCTETS_GB_LO);
  1816. stats->rx1024tomaxoctets_gb +=
  1817. xgbe_mmc_read(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
  1818. stats->rxunicastframes_g +=
  1819. xgbe_mmc_read(pdata, MMC_RXUNICASTFRAMES_G_LO);
  1820. stats->rxlengtherror +=
  1821. xgbe_mmc_read(pdata, MMC_RXLENGTHERROR_LO);
  1822. stats->rxoutofrangetype +=
  1823. xgbe_mmc_read(pdata, MMC_RXOUTOFRANGETYPE_LO);
  1824. stats->rxpauseframes +=
  1825. xgbe_mmc_read(pdata, MMC_RXPAUSEFRAMES_LO);
  1826. stats->rxfifooverflow +=
  1827. xgbe_mmc_read(pdata, MMC_RXFIFOOVERFLOW_LO);
  1828. stats->rxvlanframes_gb +=
  1829. xgbe_mmc_read(pdata, MMC_RXVLANFRAMES_GB_LO);
  1830. stats->rxwatchdogerror +=
  1831. xgbe_mmc_read(pdata, MMC_RXWATCHDOGERROR);
  1832. /* Un-freeze counters */
  1833. XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
  1834. }
  1835. static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
  1836. {
  1837. /* Set counters to reset on read */
  1838. XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
  1839. /* Reset the counters */
  1840. XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
  1841. }
  1842. static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
  1843. {
  1844. struct xgbe_channel *channel;
  1845. unsigned int i;
  1846. /* Enable each Tx DMA channel */
  1847. channel = pdata->channel;
  1848. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1849. if (!channel->tx_ring)
  1850. break;
  1851. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
  1852. }
  1853. /* Enable each Tx queue */
  1854. for (i = 0; i < pdata->tx_q_count; i++)
  1855. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
  1856. MTL_Q_ENABLED);
  1857. /* Enable MAC Tx */
  1858. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
  1859. }
  1860. static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
  1861. {
  1862. struct xgbe_channel *channel;
  1863. unsigned int i;
  1864. /* Disable MAC Tx */
  1865. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
  1866. /* Disable each Tx queue */
  1867. for (i = 0; i < pdata->tx_q_count; i++)
  1868. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
  1869. /* Disable each Tx DMA channel */
  1870. channel = pdata->channel;
  1871. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1872. if (!channel->tx_ring)
  1873. break;
  1874. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
  1875. }
  1876. }
  1877. static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
  1878. {
  1879. struct xgbe_channel *channel;
  1880. unsigned int reg_val, i;
  1881. /* Enable each Rx DMA channel */
  1882. channel = pdata->channel;
  1883. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1884. if (!channel->rx_ring)
  1885. break;
  1886. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
  1887. }
  1888. /* Enable each Rx queue */
  1889. reg_val = 0;
  1890. for (i = 0; i < pdata->rx_q_count; i++)
  1891. reg_val |= (0x02 << (i << 1));
  1892. XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
  1893. /* Enable MAC Rx */
  1894. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
  1895. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
  1896. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
  1897. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
  1898. }
  1899. static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
  1900. {
  1901. struct xgbe_channel *channel;
  1902. unsigned int i;
  1903. /* Disable MAC Rx */
  1904. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
  1905. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
  1906. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
  1907. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
  1908. /* Disable each Rx queue */
  1909. XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
  1910. /* Disable each Rx DMA channel */
  1911. channel = pdata->channel;
  1912. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1913. if (!channel->rx_ring)
  1914. break;
  1915. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
  1916. }
  1917. }
  1918. static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
  1919. {
  1920. struct xgbe_channel *channel;
  1921. unsigned int i;
  1922. /* Enable each Tx DMA channel */
  1923. channel = pdata->channel;
  1924. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1925. if (!channel->tx_ring)
  1926. break;
  1927. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
  1928. }
  1929. /* Enable MAC Tx */
  1930. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
  1931. }
  1932. static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
  1933. {
  1934. struct xgbe_channel *channel;
  1935. unsigned int i;
  1936. /* Disable MAC Tx */
  1937. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
  1938. /* Disable each Tx DMA channel */
  1939. channel = pdata->channel;
  1940. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1941. if (!channel->tx_ring)
  1942. break;
  1943. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
  1944. }
  1945. }
  1946. static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
  1947. {
  1948. struct xgbe_channel *channel;
  1949. unsigned int i;
  1950. /* Enable each Rx DMA channel */
  1951. channel = pdata->channel;
  1952. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1953. if (!channel->rx_ring)
  1954. break;
  1955. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
  1956. }
  1957. }
  1958. static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
  1959. {
  1960. struct xgbe_channel *channel;
  1961. unsigned int i;
  1962. /* Disable each Rx DMA channel */
  1963. channel = pdata->channel;
  1964. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1965. if (!channel->rx_ring)
  1966. break;
  1967. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
  1968. }
  1969. }
  1970. static int xgbe_init(struct xgbe_prv_data *pdata)
  1971. {
  1972. struct xgbe_desc_if *desc_if = &pdata->desc_if;
  1973. int ret;
  1974. DBGPR("-->xgbe_init\n");
  1975. /* Flush Tx queues */
  1976. ret = xgbe_flush_tx_queues(pdata);
  1977. if (ret)
  1978. return ret;
  1979. /*
  1980. * Initialize DMA related features
  1981. */
  1982. xgbe_config_dma_bus(pdata);
  1983. xgbe_config_dma_cache(pdata);
  1984. xgbe_config_osp_mode(pdata);
  1985. xgbe_config_pblx8(pdata);
  1986. xgbe_config_tx_pbl_val(pdata);
  1987. xgbe_config_rx_pbl_val(pdata);
  1988. xgbe_config_rx_coalesce(pdata);
  1989. xgbe_config_tx_coalesce(pdata);
  1990. xgbe_config_rx_buffer_size(pdata);
  1991. xgbe_config_tso_mode(pdata);
  1992. desc_if->wrapper_tx_desc_init(pdata);
  1993. desc_if->wrapper_rx_desc_init(pdata);
  1994. xgbe_enable_dma_interrupts(pdata);
  1995. /*
  1996. * Initialize MTL related features
  1997. */
  1998. xgbe_config_mtl_mode(pdata);
  1999. xgbe_config_queue_mapping(pdata);
  2000. xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
  2001. xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
  2002. xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
  2003. xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
  2004. xgbe_config_tx_fifo_size(pdata);
  2005. xgbe_config_rx_fifo_size(pdata);
  2006. xgbe_config_flow_control_threshold(pdata);
  2007. /*TODO: Error Packet and undersized good Packet forwarding enable
  2008. (FEP and FUP)
  2009. */
  2010. xgbe_config_dcb_tc(pdata);
  2011. xgbe_config_dcb_pfc(pdata);
  2012. xgbe_enable_mtl_interrupts(pdata);
  2013. /*
  2014. * Initialize MAC related features
  2015. */
  2016. xgbe_config_mac_address(pdata);
  2017. xgbe_config_jumbo_enable(pdata);
  2018. xgbe_config_flow_control(pdata);
  2019. xgbe_config_checksum_offload(pdata);
  2020. xgbe_config_vlan_support(pdata);
  2021. xgbe_config_mmc(pdata);
  2022. xgbe_enable_mac_interrupts(pdata);
  2023. DBGPR("<--xgbe_init\n");
  2024. return 0;
  2025. }
  2026. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
  2027. {
  2028. DBGPR("-->xgbe_init_function_ptrs\n");
  2029. hw_if->tx_complete = xgbe_tx_complete;
  2030. hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
  2031. hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
  2032. hw_if->add_mac_addresses = xgbe_add_mac_addresses;
  2033. hw_if->set_mac_address = xgbe_set_mac_address;
  2034. hw_if->enable_rx_csum = xgbe_enable_rx_csum;
  2035. hw_if->disable_rx_csum = xgbe_disable_rx_csum;
  2036. hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
  2037. hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
  2038. hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
  2039. hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
  2040. hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
  2041. hw_if->read_mmd_regs = xgbe_read_mmd_regs;
  2042. hw_if->write_mmd_regs = xgbe_write_mmd_regs;
  2043. hw_if->set_gmii_speed = xgbe_set_gmii_speed;
  2044. hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
  2045. hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
  2046. hw_if->enable_tx = xgbe_enable_tx;
  2047. hw_if->disable_tx = xgbe_disable_tx;
  2048. hw_if->enable_rx = xgbe_enable_rx;
  2049. hw_if->disable_rx = xgbe_disable_rx;
  2050. hw_if->powerup_tx = xgbe_powerup_tx;
  2051. hw_if->powerdown_tx = xgbe_powerdown_tx;
  2052. hw_if->powerup_rx = xgbe_powerup_rx;
  2053. hw_if->powerdown_rx = xgbe_powerdown_rx;
  2054. hw_if->pre_xmit = xgbe_pre_xmit;
  2055. hw_if->dev_read = xgbe_dev_read;
  2056. hw_if->enable_int = xgbe_enable_int;
  2057. hw_if->disable_int = xgbe_disable_int;
  2058. hw_if->init = xgbe_init;
  2059. hw_if->exit = xgbe_exit;
  2060. /* Descriptor related Sequences have to be initialized here */
  2061. hw_if->tx_desc_init = xgbe_tx_desc_init;
  2062. hw_if->rx_desc_init = xgbe_rx_desc_init;
  2063. hw_if->tx_desc_reset = xgbe_tx_desc_reset;
  2064. hw_if->rx_desc_reset = xgbe_rx_desc_reset;
  2065. hw_if->is_last_desc = xgbe_is_last_desc;
  2066. hw_if->is_context_desc = xgbe_is_context_desc;
  2067. /* For FLOW ctrl */
  2068. hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
  2069. hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
  2070. /* For RX coalescing */
  2071. hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
  2072. hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
  2073. hw_if->usec_to_riwt = xgbe_usec_to_riwt;
  2074. hw_if->riwt_to_usec = xgbe_riwt_to_usec;
  2075. /* For RX and TX threshold config */
  2076. hw_if->config_rx_threshold = xgbe_config_rx_threshold;
  2077. hw_if->config_tx_threshold = xgbe_config_tx_threshold;
  2078. /* For RX and TX Store and Forward Mode config */
  2079. hw_if->config_rsf_mode = xgbe_config_rsf_mode;
  2080. hw_if->config_tsf_mode = xgbe_config_tsf_mode;
  2081. /* For TX DMA Operating on Second Frame config */
  2082. hw_if->config_osp_mode = xgbe_config_osp_mode;
  2083. /* For RX and TX PBL config */
  2084. hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
  2085. hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
  2086. hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
  2087. hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
  2088. hw_if->config_pblx8 = xgbe_config_pblx8;
  2089. /* For MMC statistics support */
  2090. hw_if->tx_mmc_int = xgbe_tx_mmc_int;
  2091. hw_if->rx_mmc_int = xgbe_rx_mmc_int;
  2092. hw_if->read_mmc_stats = xgbe_read_mmc_stats;
  2093. /* For PTP config */
  2094. hw_if->config_tstamp = xgbe_config_tstamp;
  2095. hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
  2096. hw_if->set_tstamp_time = xgbe_set_tstamp_time;
  2097. hw_if->get_tstamp_time = xgbe_get_tstamp_time;
  2098. hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
  2099. /* For Data Center Bridging config */
  2100. hw_if->config_dcb_tc = xgbe_config_dcb_tc;
  2101. hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
  2102. DBGPR("<--xgbe_init_function_ptrs\n");
  2103. }