xgbe-dev.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183
  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 <asm/cputype.h>
  119. #include "xgbe.h"
  120. #include "xgbe-common.h"
  121. static unsigned int xgbe_usec_to_riwt(struct xgbe_prv_data *pdata,
  122. unsigned int usec)
  123. {
  124. unsigned long rate;
  125. unsigned int ret;
  126. DBGPR("-->xgbe_usec_to_riwt\n");
  127. rate = clk_get_rate(pdata->sysclock);
  128. /*
  129. * Convert the input usec value to the watchdog timer value. Each
  130. * watchdog timer value is equivalent to 256 clock cycles.
  131. * Calculate the required value as:
  132. * ( usec * ( system_clock_mhz / 10^6 ) / 256
  133. */
  134. ret = (usec * (rate / 1000000)) / 256;
  135. DBGPR("<--xgbe_usec_to_riwt\n");
  136. return ret;
  137. }
  138. static unsigned int xgbe_riwt_to_usec(struct xgbe_prv_data *pdata,
  139. unsigned int riwt)
  140. {
  141. unsigned long rate;
  142. unsigned int ret;
  143. DBGPR("-->xgbe_riwt_to_usec\n");
  144. rate = clk_get_rate(pdata->sysclock);
  145. /*
  146. * Convert the input watchdog timer value to the usec value. Each
  147. * watchdog timer value is equivalent to 256 clock cycles.
  148. * Calculate the required value as:
  149. * ( riwt * 256 ) / ( system_clock_mhz / 10^6 )
  150. */
  151. ret = (riwt * 256) / (rate / 1000000);
  152. DBGPR("<--xgbe_riwt_to_usec\n");
  153. return ret;
  154. }
  155. static int xgbe_config_pblx8(struct xgbe_prv_data *pdata)
  156. {
  157. struct xgbe_channel *channel;
  158. unsigned int i;
  159. channel = pdata->channel;
  160. for (i = 0; i < pdata->channel_count; i++, channel++)
  161. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_CR, PBLX8,
  162. pdata->pblx8);
  163. return 0;
  164. }
  165. static int xgbe_get_tx_pbl_val(struct xgbe_prv_data *pdata)
  166. {
  167. return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_TCR, PBL);
  168. }
  169. static int xgbe_config_tx_pbl_val(struct xgbe_prv_data *pdata)
  170. {
  171. struct xgbe_channel *channel;
  172. unsigned int i;
  173. channel = pdata->channel;
  174. for (i = 0; i < pdata->channel_count; i++, channel++) {
  175. if (!channel->tx_ring)
  176. break;
  177. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, PBL,
  178. pdata->tx_pbl);
  179. }
  180. return 0;
  181. }
  182. static int xgbe_get_rx_pbl_val(struct xgbe_prv_data *pdata)
  183. {
  184. return XGMAC_DMA_IOREAD_BITS(pdata->channel, DMA_CH_RCR, PBL);
  185. }
  186. static int xgbe_config_rx_pbl_val(struct xgbe_prv_data *pdata)
  187. {
  188. struct xgbe_channel *channel;
  189. unsigned int i;
  190. channel = pdata->channel;
  191. for (i = 0; i < pdata->channel_count; i++, channel++) {
  192. if (!channel->rx_ring)
  193. break;
  194. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, PBL,
  195. pdata->rx_pbl);
  196. }
  197. return 0;
  198. }
  199. static int xgbe_config_osp_mode(struct xgbe_prv_data *pdata)
  200. {
  201. struct xgbe_channel *channel;
  202. unsigned int i;
  203. channel = pdata->channel;
  204. for (i = 0; i < pdata->channel_count; i++, channel++) {
  205. if (!channel->tx_ring)
  206. break;
  207. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, OSP,
  208. pdata->tx_osp_mode);
  209. }
  210. return 0;
  211. }
  212. static int xgbe_config_rsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
  213. {
  214. unsigned int i;
  215. for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
  216. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RSF, val);
  217. return 0;
  218. }
  219. static int xgbe_config_tsf_mode(struct xgbe_prv_data *pdata, unsigned int val)
  220. {
  221. unsigned int i;
  222. for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
  223. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TSF, val);
  224. return 0;
  225. }
  226. static int xgbe_config_rx_threshold(struct xgbe_prv_data *pdata,
  227. unsigned int val)
  228. {
  229. unsigned int i;
  230. for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
  231. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RTC, val);
  232. return 0;
  233. }
  234. static int xgbe_config_tx_threshold(struct xgbe_prv_data *pdata,
  235. unsigned int val)
  236. {
  237. unsigned int i;
  238. for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
  239. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TTC, val);
  240. return 0;
  241. }
  242. static int xgbe_config_rx_coalesce(struct xgbe_prv_data *pdata)
  243. {
  244. struct xgbe_channel *channel;
  245. unsigned int i;
  246. channel = pdata->channel;
  247. for (i = 0; i < pdata->channel_count; i++, channel++) {
  248. if (!channel->rx_ring)
  249. break;
  250. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RIWT, RWT,
  251. pdata->rx_riwt);
  252. }
  253. return 0;
  254. }
  255. static int xgbe_config_tx_coalesce(struct xgbe_prv_data *pdata)
  256. {
  257. return 0;
  258. }
  259. static void xgbe_config_rx_buffer_size(struct xgbe_prv_data *pdata)
  260. {
  261. struct xgbe_channel *channel;
  262. unsigned int i;
  263. channel = pdata->channel;
  264. for (i = 0; i < pdata->channel_count; i++, channel++) {
  265. if (!channel->rx_ring)
  266. break;
  267. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, RBSZ,
  268. pdata->rx_buf_size);
  269. }
  270. }
  271. static void xgbe_config_tso_mode(struct xgbe_prv_data *pdata)
  272. {
  273. struct xgbe_channel *channel;
  274. unsigned int i;
  275. channel = pdata->channel;
  276. for (i = 0; i < pdata->channel_count; i++, channel++) {
  277. if (!channel->tx_ring)
  278. break;
  279. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, TSE, 1);
  280. }
  281. }
  282. static int xgbe_disable_tx_flow_control(struct xgbe_prv_data *pdata)
  283. {
  284. unsigned int max_q_count, q_count;
  285. unsigned int reg, reg_val;
  286. unsigned int i;
  287. /* Clear MTL flow control */
  288. for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
  289. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 0);
  290. /* Clear MAC flow control */
  291. max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
  292. q_count = min_t(unsigned int, pdata->hw_feat.rx_q_cnt, max_q_count);
  293. reg = MAC_Q0TFCR;
  294. for (i = 0; i < q_count; i++) {
  295. reg_val = XGMAC_IOREAD(pdata, reg);
  296. XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 0);
  297. XGMAC_IOWRITE(pdata, reg, reg_val);
  298. reg += MAC_QTFCR_INC;
  299. }
  300. return 0;
  301. }
  302. static int xgbe_enable_tx_flow_control(struct xgbe_prv_data *pdata)
  303. {
  304. unsigned int max_q_count, q_count;
  305. unsigned int reg, reg_val;
  306. unsigned int i;
  307. /* Set MTL flow control */
  308. for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
  309. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, EHFC, 1);
  310. /* Set MAC flow control */
  311. max_q_count = XGMAC_MAX_FLOW_CONTROL_QUEUES;
  312. q_count = min_t(unsigned int, pdata->hw_feat.rx_q_cnt, max_q_count);
  313. reg = MAC_Q0TFCR;
  314. for (i = 0; i < q_count; i++) {
  315. reg_val = XGMAC_IOREAD(pdata, reg);
  316. /* Enable transmit flow control */
  317. XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, TFE, 1);
  318. /* Set pause time */
  319. XGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, 0xffff);
  320. XGMAC_IOWRITE(pdata, reg, reg_val);
  321. reg += MAC_QTFCR_INC;
  322. }
  323. return 0;
  324. }
  325. static int xgbe_disable_rx_flow_control(struct xgbe_prv_data *pdata)
  326. {
  327. XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 0);
  328. return 0;
  329. }
  330. static int xgbe_enable_rx_flow_control(struct xgbe_prv_data *pdata)
  331. {
  332. XGMAC_IOWRITE_BITS(pdata, MAC_RFCR, RFE, 1);
  333. return 0;
  334. }
  335. static int xgbe_config_tx_flow_control(struct xgbe_prv_data *pdata)
  336. {
  337. if (pdata->tx_pause)
  338. xgbe_enable_tx_flow_control(pdata);
  339. else
  340. xgbe_disable_tx_flow_control(pdata);
  341. return 0;
  342. }
  343. static int xgbe_config_rx_flow_control(struct xgbe_prv_data *pdata)
  344. {
  345. if (pdata->rx_pause)
  346. xgbe_enable_rx_flow_control(pdata);
  347. else
  348. xgbe_disable_rx_flow_control(pdata);
  349. return 0;
  350. }
  351. static void xgbe_config_flow_control(struct xgbe_prv_data *pdata)
  352. {
  353. xgbe_config_tx_flow_control(pdata);
  354. xgbe_config_rx_flow_control(pdata);
  355. }
  356. static void xgbe_enable_dma_interrupts(struct xgbe_prv_data *pdata)
  357. {
  358. struct xgbe_channel *channel;
  359. unsigned int dma_ch_isr, dma_ch_ier;
  360. unsigned int i;
  361. channel = pdata->channel;
  362. for (i = 0; i < pdata->channel_count; i++, channel++) {
  363. /* Clear all the interrupts which are set */
  364. dma_ch_isr = XGMAC_DMA_IOREAD(channel, DMA_CH_SR);
  365. XGMAC_DMA_IOWRITE(channel, DMA_CH_SR, dma_ch_isr);
  366. /* Clear all interrupt enable bits */
  367. dma_ch_ier = 0;
  368. /* Enable following interrupts
  369. * NIE - Normal Interrupt Summary Enable
  370. * AIE - Abnormal Interrupt Summary Enable
  371. * FBEE - Fatal Bus Error Enable
  372. */
  373. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, NIE, 1);
  374. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, AIE, 1);
  375. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, FBEE, 1);
  376. if (channel->tx_ring) {
  377. /* Enable the following Tx interrupts
  378. * TIE - Transmit Interrupt Enable (unless polling)
  379. */
  380. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, TIE, 1);
  381. }
  382. if (channel->rx_ring) {
  383. /* Enable following Rx interrupts
  384. * RBUE - Receive Buffer Unavailable Enable
  385. * RIE - Receive Interrupt Enable
  386. */
  387. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RBUE, 1);
  388. XGMAC_SET_BITS(dma_ch_ier, DMA_CH_IER, RIE, 1);
  389. }
  390. XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
  391. }
  392. }
  393. static void xgbe_enable_mtl_interrupts(struct xgbe_prv_data *pdata)
  394. {
  395. unsigned int mtl_q_isr;
  396. unsigned int q_count, i;
  397. q_count = max(pdata->hw_feat.tx_q_cnt, pdata->hw_feat.rx_q_cnt);
  398. for (i = 0; i < q_count; i++) {
  399. /* Clear all the interrupts which are set */
  400. mtl_q_isr = XGMAC_MTL_IOREAD(pdata, i, MTL_Q_ISR);
  401. XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, mtl_q_isr);
  402. /* No MTL interrupts to be enabled */
  403. XGMAC_MTL_IOWRITE(pdata, i, MTL_Q_ISR, 0);
  404. }
  405. }
  406. static void xgbe_enable_mac_interrupts(struct xgbe_prv_data *pdata)
  407. {
  408. /* No MAC interrupts to be enabled */
  409. XGMAC_IOWRITE(pdata, MAC_IER, 0);
  410. /* Enable all counter interrupts */
  411. XGMAC_IOWRITE_BITS(pdata, MMC_RIER, ALL_INTERRUPTS, 0xff);
  412. XGMAC_IOWRITE_BITS(pdata, MMC_TIER, ALL_INTERRUPTS, 0xff);
  413. }
  414. static int xgbe_set_gmii_speed(struct xgbe_prv_data *pdata)
  415. {
  416. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x3);
  417. return 0;
  418. }
  419. static int xgbe_set_gmii_2500_speed(struct xgbe_prv_data *pdata)
  420. {
  421. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0x2);
  422. return 0;
  423. }
  424. static int xgbe_set_xgmii_speed(struct xgbe_prv_data *pdata)
  425. {
  426. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, SS, 0);
  427. return 0;
  428. }
  429. static int xgbe_set_promiscuous_mode(struct xgbe_prv_data *pdata,
  430. unsigned int enable)
  431. {
  432. unsigned int val = enable ? 1 : 0;
  433. if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PR) == val)
  434. return 0;
  435. DBGPR(" %s promiscuous mode\n", enable ? "entering" : "leaving");
  436. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, val);
  437. return 0;
  438. }
  439. static int xgbe_set_all_multicast_mode(struct xgbe_prv_data *pdata,
  440. unsigned int enable)
  441. {
  442. unsigned int val = enable ? 1 : 0;
  443. if (XGMAC_IOREAD_BITS(pdata, MAC_PFR, PM) == val)
  444. return 0;
  445. DBGPR(" %s allmulti mode\n", enable ? "entering" : "leaving");
  446. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, val);
  447. return 0;
  448. }
  449. static int xgbe_set_addn_mac_addrs(struct xgbe_prv_data *pdata,
  450. unsigned int am_mode)
  451. {
  452. struct netdev_hw_addr *ha;
  453. unsigned int mac_reg;
  454. unsigned int mac_addr_hi, mac_addr_lo;
  455. u8 *mac_addr;
  456. unsigned int i;
  457. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0);
  458. XGMAC_IOWRITE_BITS(pdata, MAC_PFR, HMC, 0);
  459. i = 0;
  460. mac_reg = MAC_MACA1HR;
  461. netdev_for_each_uc_addr(ha, pdata->netdev) {
  462. mac_addr_lo = 0;
  463. mac_addr_hi = 0;
  464. mac_addr = (u8 *)&mac_addr_lo;
  465. mac_addr[0] = ha->addr[0];
  466. mac_addr[1] = ha->addr[1];
  467. mac_addr[2] = ha->addr[2];
  468. mac_addr[3] = ha->addr[3];
  469. mac_addr = (u8 *)&mac_addr_hi;
  470. mac_addr[0] = ha->addr[4];
  471. mac_addr[1] = ha->addr[5];
  472. DBGPR(" adding unicast address %pM at 0x%04x\n",
  473. ha->addr, mac_reg);
  474. XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
  475. XGMAC_IOWRITE(pdata, mac_reg, mac_addr_hi);
  476. mac_reg += MAC_MACA_INC;
  477. XGMAC_IOWRITE(pdata, mac_reg, mac_addr_lo);
  478. mac_reg += MAC_MACA_INC;
  479. i++;
  480. }
  481. if (!am_mode) {
  482. netdev_for_each_mc_addr(ha, pdata->netdev) {
  483. mac_addr_lo = 0;
  484. mac_addr_hi = 0;
  485. mac_addr = (u8 *)&mac_addr_lo;
  486. mac_addr[0] = ha->addr[0];
  487. mac_addr[1] = ha->addr[1];
  488. mac_addr[2] = ha->addr[2];
  489. mac_addr[3] = ha->addr[3];
  490. mac_addr = (u8 *)&mac_addr_hi;
  491. mac_addr[0] = ha->addr[4];
  492. mac_addr[1] = ha->addr[5];
  493. DBGPR(" adding multicast address %pM at 0x%04x\n",
  494. ha->addr, mac_reg);
  495. XGMAC_SET_BITS(mac_addr_hi, MAC_MACA1HR, AE, 1);
  496. XGMAC_IOWRITE(pdata, mac_reg, mac_addr_hi);
  497. mac_reg += MAC_MACA_INC;
  498. XGMAC_IOWRITE(pdata, mac_reg, mac_addr_lo);
  499. mac_reg += MAC_MACA_INC;
  500. i++;
  501. }
  502. }
  503. /* Clear remaining additional MAC address entries */
  504. for (; i < pdata->hw_feat.addn_mac; i++) {
  505. XGMAC_IOWRITE(pdata, mac_reg, 0);
  506. mac_reg += MAC_MACA_INC;
  507. XGMAC_IOWRITE(pdata, mac_reg, 0);
  508. mac_reg += MAC_MACA_INC;
  509. }
  510. return 0;
  511. }
  512. static int xgbe_set_mac_address(struct xgbe_prv_data *pdata, u8 *addr)
  513. {
  514. unsigned int mac_addr_hi, mac_addr_lo;
  515. mac_addr_hi = (addr[5] << 8) | (addr[4] << 0);
  516. mac_addr_lo = (addr[3] << 24) | (addr[2] << 16) |
  517. (addr[1] << 8) | (addr[0] << 0);
  518. XGMAC_IOWRITE(pdata, MAC_MACA0HR, mac_addr_hi);
  519. XGMAC_IOWRITE(pdata, MAC_MACA0LR, mac_addr_lo);
  520. return 0;
  521. }
  522. static int xgbe_read_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
  523. int mmd_reg)
  524. {
  525. unsigned int mmd_address;
  526. int mmd_data;
  527. if (mmd_reg & MII_ADDR_C45)
  528. mmd_address = mmd_reg & ~MII_ADDR_C45;
  529. else
  530. mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
  531. /* The PCS registers are accessed using mmio. The underlying APB3
  532. * management interface uses indirect addressing to access the MMD
  533. * register sets. This requires accessing of the PCS register in two
  534. * phases, an address phase and a data phase.
  535. *
  536. * The mmio interface is based on 32-bit offsets and values. All
  537. * register offsets must therefore be adjusted by left shifting the
  538. * offset 2 bits and reading 32 bits of data.
  539. */
  540. mutex_lock(&pdata->xpcs_mutex);
  541. XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
  542. mmd_data = XPCS_IOREAD(pdata, (mmd_address & 0xff) << 2);
  543. mutex_unlock(&pdata->xpcs_mutex);
  544. return mmd_data;
  545. }
  546. static void xgbe_write_mmd_regs(struct xgbe_prv_data *pdata, int prtad,
  547. int mmd_reg, int mmd_data)
  548. {
  549. unsigned int mmd_address;
  550. if (mmd_reg & MII_ADDR_C45)
  551. mmd_address = mmd_reg & ~MII_ADDR_C45;
  552. else
  553. mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
  554. /* The PCS registers are accessed using mmio. The underlying APB3
  555. * management interface uses indirect addressing to access the MMD
  556. * register sets. This requires accessing of the PCS register in two
  557. * phases, an address phase and a data phase.
  558. *
  559. * The mmio interface is based on 32-bit offsets and values. All
  560. * register offsets must therefore be adjusted by left shifting the
  561. * offset 2 bits and reading 32 bits of data.
  562. */
  563. mutex_lock(&pdata->xpcs_mutex);
  564. XPCS_IOWRITE(pdata, PCS_MMD_SELECT << 2, mmd_address >> 8);
  565. XPCS_IOWRITE(pdata, (mmd_address & 0xff) << 2, mmd_data);
  566. mutex_unlock(&pdata->xpcs_mutex);
  567. }
  568. static int xgbe_tx_complete(struct xgbe_ring_desc *rdesc)
  569. {
  570. return !XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN);
  571. }
  572. static int xgbe_disable_rx_csum(struct xgbe_prv_data *pdata)
  573. {
  574. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 0);
  575. return 0;
  576. }
  577. static int xgbe_enable_rx_csum(struct xgbe_prv_data *pdata)
  578. {
  579. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, IPC, 1);
  580. return 0;
  581. }
  582. static int xgbe_enable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
  583. {
  584. /* Put the VLAN tag in the Rx descriptor */
  585. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLRXS, 1);
  586. /* Don't check the VLAN type */
  587. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, DOVLTC, 1);
  588. /* Check only C-TAG (0x8100) packets */
  589. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERSVLM, 0);
  590. /* Don't consider an S-TAG (0x88A8) packet as a VLAN packet */
  591. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ESVL, 0);
  592. /* Enable VLAN tag stripping */
  593. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0x3);
  594. return 0;
  595. }
  596. static int xgbe_disable_rx_vlan_stripping(struct xgbe_prv_data *pdata)
  597. {
  598. XGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EVLS, 0);
  599. return 0;
  600. }
  601. static void xgbe_tx_desc_reset(struct xgbe_ring_data *rdata)
  602. {
  603. struct xgbe_ring_desc *rdesc = rdata->rdesc;
  604. /* Reset the Tx descriptor
  605. * Set buffer 1 (lo) address to zero
  606. * Set buffer 1 (hi) address to zero
  607. * Reset all other control bits (IC, TTSE, B2L & B1L)
  608. * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC, etc)
  609. */
  610. rdesc->desc0 = 0;
  611. rdesc->desc1 = 0;
  612. rdesc->desc2 = 0;
  613. rdesc->desc3 = 0;
  614. }
  615. static void xgbe_tx_desc_init(struct xgbe_channel *channel)
  616. {
  617. struct xgbe_ring *ring = channel->tx_ring;
  618. struct xgbe_ring_data *rdata;
  619. struct xgbe_ring_desc *rdesc;
  620. int i;
  621. int start_index = ring->cur;
  622. DBGPR("-->tx_desc_init\n");
  623. /* Initialze all descriptors */
  624. for (i = 0; i < ring->rdesc_count; i++) {
  625. rdata = GET_DESC_DATA(ring, i);
  626. rdesc = rdata->rdesc;
  627. /* Initialize Tx descriptor
  628. * Set buffer 1 (lo) address to zero
  629. * Set buffer 1 (hi) address to zero
  630. * Reset all other control bits (IC, TTSE, B2L & B1L)
  631. * Reset all other control bits (OWN, CTXT, FD, LD, CPC, CIC,
  632. * etc)
  633. */
  634. rdesc->desc0 = 0;
  635. rdesc->desc1 = 0;
  636. rdesc->desc2 = 0;
  637. rdesc->desc3 = 0;
  638. }
  639. /* Make sure everything is written to the descriptor(s) before
  640. * telling the device about them
  641. */
  642. wmb();
  643. /* Update the total number of Tx descriptors */
  644. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDRLR, ring->rdesc_count - 1);
  645. /* Update the starting address of descriptor ring */
  646. rdata = GET_DESC_DATA(ring, start_index);
  647. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_HI,
  648. upper_32_bits(rdata->rdesc_dma));
  649. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDLR_LO,
  650. lower_32_bits(rdata->rdesc_dma));
  651. DBGPR("<--tx_desc_init\n");
  652. }
  653. static void xgbe_rx_desc_reset(struct xgbe_ring_data *rdata)
  654. {
  655. struct xgbe_ring_desc *rdesc = rdata->rdesc;
  656. /* Reset the Rx descriptor
  657. * Set buffer 1 (lo) address to dma address (lo)
  658. * Set buffer 1 (hi) address to dma address (hi)
  659. * Set buffer 2 (lo) address to zero
  660. * Set buffer 2 (hi) address to zero and set control bits
  661. * OWN and INTE
  662. */
  663. rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
  664. rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
  665. rdesc->desc2 = 0;
  666. rdesc->desc3 = 0;
  667. if (rdata->interrupt)
  668. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
  669. /* Since the Rx DMA engine is likely running, make sure everything
  670. * is written to the descriptor(s) before setting the OWN bit
  671. * for the descriptor
  672. */
  673. wmb();
  674. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
  675. /* Make sure ownership is written to the descriptor */
  676. wmb();
  677. }
  678. static void xgbe_rx_desc_init(struct xgbe_channel *channel)
  679. {
  680. struct xgbe_prv_data *pdata = channel->pdata;
  681. struct xgbe_ring *ring = channel->rx_ring;
  682. struct xgbe_ring_data *rdata;
  683. struct xgbe_ring_desc *rdesc;
  684. unsigned int start_index = ring->cur;
  685. unsigned int rx_coalesce, rx_frames;
  686. unsigned int i;
  687. DBGPR("-->rx_desc_init\n");
  688. rx_coalesce = (pdata->rx_riwt || pdata->rx_frames) ? 1 : 0;
  689. rx_frames = pdata->rx_frames;
  690. /* Initialize all descriptors */
  691. for (i = 0; i < ring->rdesc_count; i++) {
  692. rdata = GET_DESC_DATA(ring, i);
  693. rdesc = rdata->rdesc;
  694. /* Initialize Rx descriptor
  695. * Set buffer 1 (lo) address to dma address (lo)
  696. * Set buffer 1 (hi) address to dma address (hi)
  697. * Set buffer 2 (lo) address to zero
  698. * Set buffer 2 (hi) address to zero and set control
  699. * bits OWN and INTE appropriateley
  700. */
  701. rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
  702. rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
  703. rdesc->desc2 = 0;
  704. rdesc->desc3 = 0;
  705. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN, 1);
  706. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE, 1);
  707. rdata->interrupt = 1;
  708. if (rx_coalesce && (!rx_frames || ((i + 1) % rx_frames))) {
  709. /* Clear interrupt on completion bit */
  710. XGMAC_SET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, INTE,
  711. 0);
  712. rdata->interrupt = 0;
  713. }
  714. }
  715. /* Make sure everything is written to the descriptors before
  716. * telling the device about them
  717. */
  718. wmb();
  719. /* Update the total number of Rx descriptors */
  720. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDRLR, ring->rdesc_count - 1);
  721. /* Update the starting address of descriptor ring */
  722. rdata = GET_DESC_DATA(ring, start_index);
  723. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_HI,
  724. upper_32_bits(rdata->rdesc_dma));
  725. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDLR_LO,
  726. lower_32_bits(rdata->rdesc_dma));
  727. /* Update the Rx Descriptor Tail Pointer */
  728. rdata = GET_DESC_DATA(ring, start_index + ring->rdesc_count - 1);
  729. XGMAC_DMA_IOWRITE(channel, DMA_CH_RDTR_LO,
  730. lower_32_bits(rdata->rdesc_dma));
  731. DBGPR("<--rx_desc_init\n");
  732. }
  733. static void xgbe_pre_xmit(struct xgbe_channel *channel)
  734. {
  735. struct xgbe_prv_data *pdata = channel->pdata;
  736. struct xgbe_ring *ring = channel->tx_ring;
  737. struct xgbe_ring_data *rdata;
  738. struct xgbe_ring_desc *rdesc;
  739. struct xgbe_packet_data *packet = &ring->packet_data;
  740. unsigned int csum, tso, vlan;
  741. unsigned int tso_context, vlan_context;
  742. unsigned int tx_coalesce, tx_frames;
  743. int start_index = ring->cur;
  744. int i;
  745. DBGPR("-->xgbe_pre_xmit\n");
  746. csum = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
  747. CSUM_ENABLE);
  748. tso = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
  749. TSO_ENABLE);
  750. vlan = XGMAC_GET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
  751. VLAN_CTAG);
  752. if (tso && (packet->mss != ring->tx.cur_mss))
  753. tso_context = 1;
  754. else
  755. tso_context = 0;
  756. if (vlan && (packet->vlan_ctag != ring->tx.cur_vlan_ctag))
  757. vlan_context = 1;
  758. else
  759. vlan_context = 0;
  760. tx_coalesce = (pdata->tx_usecs || pdata->tx_frames) ? 1 : 0;
  761. tx_frames = pdata->tx_frames;
  762. if (tx_coalesce && !channel->tx_timer_active)
  763. ring->coalesce_count = 0;
  764. rdata = GET_DESC_DATA(ring, ring->cur);
  765. rdesc = rdata->rdesc;
  766. /* Create a context descriptor if this is a TSO packet */
  767. if (tso_context || vlan_context) {
  768. if (tso_context) {
  769. DBGPR(" TSO context descriptor, mss=%u\n",
  770. packet->mss);
  771. /* Set the MSS size */
  772. XGMAC_SET_BITS_LE(rdesc->desc2, TX_CONTEXT_DESC2,
  773. MSS, packet->mss);
  774. /* Mark it as a CONTEXT descriptor */
  775. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  776. CTXT, 1);
  777. /* Indicate this descriptor contains the MSS */
  778. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  779. TCMSSV, 1);
  780. ring->tx.cur_mss = packet->mss;
  781. }
  782. if (vlan_context) {
  783. DBGPR(" VLAN context descriptor, ctag=%u\n",
  784. packet->vlan_ctag);
  785. /* Mark it as a CONTEXT descriptor */
  786. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  787. CTXT, 1);
  788. /* Set the VLAN tag */
  789. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  790. VT, packet->vlan_ctag);
  791. /* Indicate this descriptor contains the VLAN tag */
  792. XGMAC_SET_BITS_LE(rdesc->desc3, TX_CONTEXT_DESC3,
  793. VLTV, 1);
  794. ring->tx.cur_vlan_ctag = packet->vlan_ctag;
  795. }
  796. ring->cur++;
  797. rdata = GET_DESC_DATA(ring, ring->cur);
  798. rdesc = rdata->rdesc;
  799. }
  800. /* Update buffer address (for TSO this is the header) */
  801. rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
  802. rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
  803. /* Update the buffer length */
  804. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
  805. rdata->skb_dma_len);
  806. /* VLAN tag insertion check */
  807. if (vlan)
  808. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, VTIR,
  809. TX_NORMAL_DESC2_VLAN_INSERT);
  810. /* Set IC bit based on Tx coalescing settings */
  811. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
  812. if (tx_coalesce && (!tx_frames ||
  813. (++ring->coalesce_count % tx_frames)))
  814. /* Clear IC bit */
  815. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
  816. /* Mark it as First Descriptor */
  817. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FD, 1);
  818. /* Mark it as a NORMAL descriptor */
  819. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
  820. /* Set OWN bit if not the first descriptor */
  821. if (ring->cur != start_index)
  822. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
  823. if (tso) {
  824. /* Enable TSO */
  825. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TSE, 1);
  826. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPPL,
  827. packet->tcp_payload_len);
  828. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, TCPHDRLEN,
  829. packet->tcp_header_len / 4);
  830. } else {
  831. /* Enable CRC and Pad Insertion */
  832. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CPC, 0);
  833. /* Enable HW CSUM */
  834. if (csum)
  835. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
  836. CIC, 0x3);
  837. /* Set the total length to be transmitted */
  838. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, FL,
  839. packet->length);
  840. }
  841. for (i = ring->cur - start_index + 1; i < packet->rdesc_count; i++) {
  842. ring->cur++;
  843. rdata = GET_DESC_DATA(ring, ring->cur);
  844. rdesc = rdata->rdesc;
  845. /* Update buffer address */
  846. rdesc->desc0 = cpu_to_le32(lower_32_bits(rdata->skb_dma));
  847. rdesc->desc1 = cpu_to_le32(upper_32_bits(rdata->skb_dma));
  848. /* Update the buffer length */
  849. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, HL_B1L,
  850. rdata->skb_dma_len);
  851. /* Set IC bit based on Tx coalescing settings */
  852. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 1);
  853. if (tx_coalesce && (!tx_frames ||
  854. (++ring->coalesce_count % tx_frames)))
  855. /* Clear IC bit */
  856. XGMAC_SET_BITS_LE(rdesc->desc2, TX_NORMAL_DESC2, IC, 0);
  857. /* Set OWN bit */
  858. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
  859. /* Mark it as NORMAL descriptor */
  860. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT, 0);
  861. /* Enable HW CSUM */
  862. if (csum)
  863. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3,
  864. CIC, 0x3);
  865. }
  866. /* Set LAST bit for the last descriptor */
  867. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD, 1);
  868. /* In case the Tx DMA engine is running, make sure everything
  869. * is written to the descriptor(s) before setting the OWN bit
  870. * for the first descriptor
  871. */
  872. wmb();
  873. /* Set OWN bit for the first descriptor */
  874. rdata = GET_DESC_DATA(ring, start_index);
  875. rdesc = rdata->rdesc;
  876. XGMAC_SET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, OWN, 1);
  877. #ifdef XGMAC_ENABLE_TX_DESC_DUMP
  878. xgbe_dump_tx_desc(ring, start_index, packet->rdesc_count, 1);
  879. #endif
  880. /* Make sure ownership is written to the descriptor */
  881. wmb();
  882. /* Issue a poll command to Tx DMA by writing address
  883. * of next immediate free descriptor */
  884. ring->cur++;
  885. rdata = GET_DESC_DATA(ring, ring->cur);
  886. XGMAC_DMA_IOWRITE(channel, DMA_CH_TDTR_LO,
  887. lower_32_bits(rdata->rdesc_dma));
  888. /* Start the Tx coalescing timer */
  889. if (tx_coalesce && !channel->tx_timer_active) {
  890. channel->tx_timer_active = 1;
  891. hrtimer_start(&channel->tx_timer,
  892. ktime_set(0, pdata->tx_usecs * NSEC_PER_USEC),
  893. HRTIMER_MODE_REL);
  894. }
  895. DBGPR(" %s: descriptors %u to %u written\n",
  896. channel->name, start_index & (ring->rdesc_count - 1),
  897. (ring->cur - 1) & (ring->rdesc_count - 1));
  898. DBGPR("<--xgbe_pre_xmit\n");
  899. }
  900. static int xgbe_dev_read(struct xgbe_channel *channel)
  901. {
  902. struct xgbe_ring *ring = channel->rx_ring;
  903. struct xgbe_ring_data *rdata;
  904. struct xgbe_ring_desc *rdesc;
  905. struct xgbe_packet_data *packet = &ring->packet_data;
  906. unsigned int err, etlt;
  907. DBGPR("-->xgbe_dev_read: cur = %d\n", ring->cur);
  908. rdata = GET_DESC_DATA(ring, ring->cur);
  909. rdesc = rdata->rdesc;
  910. /* Check for data availability */
  911. if (XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, OWN))
  912. return 1;
  913. #ifdef XGMAC_ENABLE_RX_DESC_DUMP
  914. xgbe_dump_rx_desc(ring, rdesc, ring->cur);
  915. #endif
  916. /* Get the packet length */
  917. rdata->len = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, PL);
  918. if (!XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, LD)) {
  919. /* Not all the data has been transferred for this packet */
  920. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  921. INCOMPLETE, 1);
  922. return 0;
  923. }
  924. /* This is the last of the data for this packet */
  925. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  926. INCOMPLETE, 0);
  927. /* Set checksum done indicator as appropriate */
  928. if (channel->pdata->netdev->features & NETIF_F_RXCSUM)
  929. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  930. CSUM_DONE, 1);
  931. /* Check for errors (only valid in last descriptor) */
  932. err = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ES);
  933. etlt = XGMAC_GET_BITS_LE(rdesc->desc3, RX_NORMAL_DESC3, ETLT);
  934. DBGPR(" err=%u, etlt=%#x\n", err, etlt);
  935. if (!err || (err && !etlt)) {
  936. if (etlt == 0x09) {
  937. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  938. VLAN_CTAG, 1);
  939. packet->vlan_ctag = XGMAC_GET_BITS_LE(rdesc->desc0,
  940. RX_NORMAL_DESC0,
  941. OVT);
  942. DBGPR(" vlan-ctag=0x%04x\n", packet->vlan_ctag);
  943. }
  944. } else {
  945. if ((etlt == 0x05) || (etlt == 0x06))
  946. XGMAC_SET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES,
  947. CSUM_DONE, 0);
  948. else
  949. XGMAC_SET_BITS(packet->errors, RX_PACKET_ERRORS,
  950. FRAME, 1);
  951. }
  952. DBGPR("<--xgbe_dev_read: %s - descriptor=%u (cur=%d)\n", channel->name,
  953. ring->cur & (ring->rdesc_count - 1), ring->cur);
  954. return 0;
  955. }
  956. static int xgbe_is_context_desc(struct xgbe_ring_desc *rdesc)
  957. {
  958. /* Rx and Tx share CTXT bit, so check TDES3.CTXT bit */
  959. return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, CTXT);
  960. }
  961. static int xgbe_is_last_desc(struct xgbe_ring_desc *rdesc)
  962. {
  963. /* Rx and Tx share LD bit, so check TDES3.LD bit */
  964. return XGMAC_GET_BITS_LE(rdesc->desc3, TX_NORMAL_DESC3, LD);
  965. }
  966. static void xgbe_save_interrupt_status(struct xgbe_channel *channel,
  967. enum xgbe_int_state int_state)
  968. {
  969. unsigned int dma_ch_ier;
  970. if (int_state == XGMAC_INT_STATE_SAVE) {
  971. channel->saved_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
  972. channel->saved_ier &= DMA_INTERRUPT_MASK;
  973. } else {
  974. dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
  975. dma_ch_ier |= channel->saved_ier;
  976. XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
  977. }
  978. }
  979. static int xgbe_enable_int(struct xgbe_channel *channel,
  980. enum xgbe_int int_id)
  981. {
  982. switch (int_id) {
  983. case XGMAC_INT_DMA_ISR_DC0IS:
  984. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 1);
  985. break;
  986. case XGMAC_INT_DMA_CH_SR_TI:
  987. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 1);
  988. break;
  989. case XGMAC_INT_DMA_CH_SR_TPS:
  990. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TXSE, 1);
  991. break;
  992. case XGMAC_INT_DMA_CH_SR_TBU:
  993. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TBUE, 1);
  994. break;
  995. case XGMAC_INT_DMA_CH_SR_RI:
  996. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RIE, 1);
  997. break;
  998. case XGMAC_INT_DMA_CH_SR_RBU:
  999. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RBUE, 1);
  1000. break;
  1001. case XGMAC_INT_DMA_CH_SR_RPS:
  1002. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RSE, 1);
  1003. break;
  1004. case XGMAC_INT_DMA_CH_SR_FBE:
  1005. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, FBEE, 1);
  1006. break;
  1007. case XGMAC_INT_DMA_ALL:
  1008. xgbe_save_interrupt_status(channel, XGMAC_INT_STATE_RESTORE);
  1009. break;
  1010. default:
  1011. return -1;
  1012. }
  1013. return 0;
  1014. }
  1015. static int xgbe_disable_int(struct xgbe_channel *channel,
  1016. enum xgbe_int int_id)
  1017. {
  1018. unsigned int dma_ch_ier;
  1019. switch (int_id) {
  1020. case XGMAC_INT_DMA_ISR_DC0IS:
  1021. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 0);
  1022. break;
  1023. case XGMAC_INT_DMA_CH_SR_TI:
  1024. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TIE, 0);
  1025. break;
  1026. case XGMAC_INT_DMA_CH_SR_TPS:
  1027. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TXSE, 0);
  1028. break;
  1029. case XGMAC_INT_DMA_CH_SR_TBU:
  1030. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, TBUE, 0);
  1031. break;
  1032. case XGMAC_INT_DMA_CH_SR_RI:
  1033. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RIE, 0);
  1034. break;
  1035. case XGMAC_INT_DMA_CH_SR_RBU:
  1036. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RBUE, 0);
  1037. break;
  1038. case XGMAC_INT_DMA_CH_SR_RPS:
  1039. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, RSE, 0);
  1040. break;
  1041. case XGMAC_INT_DMA_CH_SR_FBE:
  1042. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_IER, FBEE, 0);
  1043. break;
  1044. case XGMAC_INT_DMA_ALL:
  1045. xgbe_save_interrupt_status(channel, XGMAC_INT_STATE_SAVE);
  1046. dma_ch_ier = XGMAC_DMA_IOREAD(channel, DMA_CH_IER);
  1047. dma_ch_ier &= ~DMA_INTERRUPT_MASK;
  1048. XGMAC_DMA_IOWRITE(channel, DMA_CH_IER, dma_ch_ier);
  1049. break;
  1050. default:
  1051. return -1;
  1052. }
  1053. return 0;
  1054. }
  1055. static int xgbe_exit(struct xgbe_prv_data *pdata)
  1056. {
  1057. unsigned int count = 2000;
  1058. DBGPR("-->xgbe_exit\n");
  1059. /* Issue a software reset */
  1060. XGMAC_IOWRITE_BITS(pdata, DMA_MR, SWR, 1);
  1061. usleep_range(10, 15);
  1062. /* Poll Until Poll Condition */
  1063. while (count-- && XGMAC_IOREAD_BITS(pdata, DMA_MR, SWR))
  1064. usleep_range(500, 600);
  1065. if (!count)
  1066. return -EBUSY;
  1067. DBGPR("<--xgbe_exit\n");
  1068. return 0;
  1069. }
  1070. static int xgbe_flush_tx_queues(struct xgbe_prv_data *pdata)
  1071. {
  1072. unsigned int i, count;
  1073. for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
  1074. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, FTQ, 1);
  1075. /* Poll Until Poll Condition */
  1076. for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++) {
  1077. count = 2000;
  1078. while (count-- && XGMAC_MTL_IOREAD_BITS(pdata, i,
  1079. MTL_Q_TQOMR, FTQ))
  1080. usleep_range(500, 600);
  1081. if (!count)
  1082. return -EBUSY;
  1083. }
  1084. return 0;
  1085. }
  1086. static void xgbe_config_dma_bus(struct xgbe_prv_data *pdata)
  1087. {
  1088. /* Set enhanced addressing mode */
  1089. XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, EAME, 1);
  1090. /* Set the System Bus mode */
  1091. XGMAC_IOWRITE_BITS(pdata, DMA_SBMR, UNDEF, 1);
  1092. }
  1093. static void xgbe_config_dma_cache(struct xgbe_prv_data *pdata)
  1094. {
  1095. unsigned int arcache, awcache;
  1096. arcache = 0;
  1097. XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRC, DMA_ARCACHE_SETTING);
  1098. XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, DMA_ARDOMAIN_SETTING);
  1099. XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, DMA_ARCACHE_SETTING);
  1100. XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, DMA_ARDOMAIN_SETTING);
  1101. XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, DMA_ARCACHE_SETTING);
  1102. XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, DMA_ARDOMAIN_SETTING);
  1103. XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
  1104. awcache = 0;
  1105. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, DMA_AWCACHE_SETTING);
  1106. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, DMA_AWDOMAIN_SETTING);
  1107. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, DMA_AWCACHE_SETTING);
  1108. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, DMA_AWDOMAIN_SETTING);
  1109. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, DMA_AWCACHE_SETTING);
  1110. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, DMA_AWDOMAIN_SETTING);
  1111. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, DMA_AWCACHE_SETTING);
  1112. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, DMA_AWDOMAIN_SETTING);
  1113. XGMAC_IOWRITE(pdata, DMA_AXIAWCR, awcache);
  1114. }
  1115. static void xgbe_config_mtl_mode(struct xgbe_prv_data *pdata)
  1116. {
  1117. unsigned int i;
  1118. /* Set Tx to weighted round robin scheduling algorithm (when
  1119. * traffic class is using ETS algorithm)
  1120. */
  1121. XGMAC_IOWRITE_BITS(pdata, MTL_OMR, ETSALG, MTL_ETSALG_WRR);
  1122. /* Set Tx traffic classes to strict priority algorithm */
  1123. for (i = 0; i < XGBE_TC_CNT; i++)
  1124. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_TC_ETSCR, TSA, MTL_TSA_SP);
  1125. /* Set Rx to strict priority algorithm */
  1126. XGMAC_IOWRITE_BITS(pdata, MTL_OMR, RAA, MTL_RAA_SP);
  1127. }
  1128. static unsigned int xgbe_calculate_per_queue_fifo(unsigned long fifo_size,
  1129. unsigned char queue_count)
  1130. {
  1131. unsigned int q_fifo_size = 0;
  1132. enum xgbe_mtl_fifo_size p_fifo = XGMAC_MTL_FIFO_SIZE_256;
  1133. /* Calculate Tx/Rx fifo share per queue */
  1134. switch (fifo_size) {
  1135. case 0:
  1136. q_fifo_size = FIFO_SIZE_B(128);
  1137. break;
  1138. case 1:
  1139. q_fifo_size = FIFO_SIZE_B(256);
  1140. break;
  1141. case 2:
  1142. q_fifo_size = FIFO_SIZE_B(512);
  1143. break;
  1144. case 3:
  1145. q_fifo_size = FIFO_SIZE_KB(1);
  1146. break;
  1147. case 4:
  1148. q_fifo_size = FIFO_SIZE_KB(2);
  1149. break;
  1150. case 5:
  1151. q_fifo_size = FIFO_SIZE_KB(4);
  1152. break;
  1153. case 6:
  1154. q_fifo_size = FIFO_SIZE_KB(8);
  1155. break;
  1156. case 7:
  1157. q_fifo_size = FIFO_SIZE_KB(16);
  1158. break;
  1159. case 8:
  1160. q_fifo_size = FIFO_SIZE_KB(32);
  1161. break;
  1162. case 9:
  1163. q_fifo_size = FIFO_SIZE_KB(64);
  1164. break;
  1165. case 10:
  1166. q_fifo_size = FIFO_SIZE_KB(128);
  1167. break;
  1168. case 11:
  1169. q_fifo_size = FIFO_SIZE_KB(256);
  1170. break;
  1171. }
  1172. q_fifo_size = q_fifo_size / queue_count;
  1173. /* Set the queue fifo size programmable value */
  1174. if (q_fifo_size >= FIFO_SIZE_KB(256))
  1175. p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
  1176. else if (q_fifo_size >= FIFO_SIZE_KB(128))
  1177. p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
  1178. else if (q_fifo_size >= FIFO_SIZE_KB(64))
  1179. p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
  1180. else if (q_fifo_size >= FIFO_SIZE_KB(32))
  1181. p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
  1182. else if (q_fifo_size >= FIFO_SIZE_KB(16))
  1183. p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
  1184. else if (q_fifo_size >= FIFO_SIZE_KB(8))
  1185. p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
  1186. else if (q_fifo_size >= FIFO_SIZE_KB(4))
  1187. p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
  1188. else if (q_fifo_size >= FIFO_SIZE_KB(2))
  1189. p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
  1190. else if (q_fifo_size >= FIFO_SIZE_KB(1))
  1191. p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
  1192. else if (q_fifo_size >= FIFO_SIZE_B(512))
  1193. p_fifo = XGMAC_MTL_FIFO_SIZE_512;
  1194. else if (q_fifo_size >= FIFO_SIZE_B(256))
  1195. p_fifo = XGMAC_MTL_FIFO_SIZE_256;
  1196. return p_fifo;
  1197. }
  1198. static void xgbe_config_tx_fifo_size(struct xgbe_prv_data *pdata)
  1199. {
  1200. enum xgbe_mtl_fifo_size fifo_size;
  1201. unsigned int i;
  1202. fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.tx_fifo_size,
  1203. pdata->hw_feat.tx_q_cnt);
  1204. for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
  1205. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TQS, fifo_size);
  1206. netdev_notice(pdata->netdev, "%d Tx queues, %d byte fifo per queue\n",
  1207. pdata->hw_feat.tx_q_cnt, ((fifo_size + 1) * 256));
  1208. }
  1209. static void xgbe_config_rx_fifo_size(struct xgbe_prv_data *pdata)
  1210. {
  1211. enum xgbe_mtl_fifo_size fifo_size;
  1212. unsigned int i;
  1213. fifo_size = xgbe_calculate_per_queue_fifo(pdata->hw_feat.rx_fifo_size,
  1214. pdata->hw_feat.rx_q_cnt);
  1215. for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
  1216. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RQS, fifo_size);
  1217. netdev_notice(pdata->netdev, "%d Rx queues, %d byte fifo per queue\n",
  1218. pdata->hw_feat.rx_q_cnt, ((fifo_size + 1) * 256));
  1219. }
  1220. static void xgbe_config_rx_queue_mapping(struct xgbe_prv_data *pdata)
  1221. {
  1222. unsigned int i, reg, reg_val;
  1223. unsigned int q_count = pdata->hw_feat.rx_q_cnt;
  1224. /* Select dynamic mapping of MTL Rx queue to DMA Rx channel */
  1225. reg = MTL_RQDCM0R;
  1226. reg_val = 0;
  1227. for (i = 0; i < q_count;) {
  1228. reg_val |= (0x80 << ((i++ % MTL_RQDCM_Q_PER_REG) << 3));
  1229. if ((i % MTL_RQDCM_Q_PER_REG) && (i != q_count))
  1230. continue;
  1231. XGMAC_IOWRITE(pdata, reg, reg_val);
  1232. reg += MTL_RQDCM_INC;
  1233. reg_val = 0;
  1234. }
  1235. }
  1236. static void xgbe_config_flow_control_threshold(struct xgbe_prv_data *pdata)
  1237. {
  1238. unsigned int i;
  1239. for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++) {
  1240. /* Activate flow control when less than 4k left in fifo */
  1241. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFA, 2);
  1242. /* De-activate flow control when more than 6k left in fifo */
  1243. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_RQOMR, RFD, 4);
  1244. }
  1245. }
  1246. static void xgbe_config_mac_address(struct xgbe_prv_data *pdata)
  1247. {
  1248. xgbe_set_mac_address(pdata, pdata->netdev->dev_addr);
  1249. }
  1250. static void xgbe_config_jumbo_enable(struct xgbe_prv_data *pdata)
  1251. {
  1252. unsigned int val;
  1253. val = (pdata->netdev->mtu > XGMAC_STD_PACKET_MTU) ? 1 : 0;
  1254. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
  1255. }
  1256. static void xgbe_config_checksum_offload(struct xgbe_prv_data *pdata)
  1257. {
  1258. if (pdata->netdev->features & NETIF_F_RXCSUM)
  1259. xgbe_enable_rx_csum(pdata);
  1260. else
  1261. xgbe_disable_rx_csum(pdata);
  1262. }
  1263. static void xgbe_config_vlan_support(struct xgbe_prv_data *pdata)
  1264. {
  1265. if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  1266. xgbe_enable_rx_vlan_stripping(pdata);
  1267. else
  1268. xgbe_disable_rx_vlan_stripping(pdata);
  1269. }
  1270. static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
  1271. {
  1272. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  1273. unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
  1274. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
  1275. stats->txoctetcount_gb +=
  1276. XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
  1277. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
  1278. stats->txframecount_gb +=
  1279. XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
  1280. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
  1281. stats->txbroadcastframes_g +=
  1282. XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
  1283. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
  1284. stats->txmulticastframes_g +=
  1285. XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
  1286. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
  1287. stats->tx64octets_gb +=
  1288. XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
  1289. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
  1290. stats->tx65to127octets_gb +=
  1291. XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
  1292. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
  1293. stats->tx128to255octets_gb +=
  1294. XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
  1295. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
  1296. stats->tx256to511octets_gb +=
  1297. XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
  1298. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
  1299. stats->tx512to1023octets_gb +=
  1300. XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
  1301. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
  1302. stats->tx1024tomaxoctets_gb +=
  1303. XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
  1304. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
  1305. stats->txunicastframes_gb +=
  1306. XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
  1307. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
  1308. stats->txmulticastframes_gb +=
  1309. XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
  1310. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
  1311. stats->txbroadcastframes_g +=
  1312. XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
  1313. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
  1314. stats->txunderflowerror +=
  1315. XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
  1316. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
  1317. stats->txoctetcount_g +=
  1318. XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
  1319. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
  1320. stats->txframecount_g +=
  1321. XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
  1322. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
  1323. stats->txpauseframes +=
  1324. XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
  1325. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
  1326. stats->txvlanframes_g +=
  1327. XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
  1328. }
  1329. static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
  1330. {
  1331. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  1332. unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
  1333. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
  1334. stats->rxframecount_gb +=
  1335. XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
  1336. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
  1337. stats->rxoctetcount_gb +=
  1338. XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
  1339. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
  1340. stats->rxoctetcount_g +=
  1341. XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
  1342. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
  1343. stats->rxbroadcastframes_g +=
  1344. XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
  1345. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
  1346. stats->rxmulticastframes_g +=
  1347. XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
  1348. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
  1349. stats->rxcrcerror +=
  1350. XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
  1351. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
  1352. stats->rxrunterror +=
  1353. XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
  1354. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
  1355. stats->rxjabbererror +=
  1356. XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
  1357. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
  1358. stats->rxundersize_g +=
  1359. XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
  1360. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
  1361. stats->rxoversize_g +=
  1362. XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
  1363. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
  1364. stats->rx64octets_gb +=
  1365. XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
  1366. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
  1367. stats->rx65to127octets_gb +=
  1368. XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
  1369. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
  1370. stats->rx128to255octets_gb +=
  1371. XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
  1372. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
  1373. stats->rx256to511octets_gb +=
  1374. XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
  1375. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
  1376. stats->rx512to1023octets_gb +=
  1377. XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
  1378. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
  1379. stats->rx1024tomaxoctets_gb +=
  1380. XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
  1381. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
  1382. stats->rxunicastframes_g +=
  1383. XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
  1384. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
  1385. stats->rxlengtherror +=
  1386. XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
  1387. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
  1388. stats->rxoutofrangetype +=
  1389. XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
  1390. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
  1391. stats->rxpauseframes +=
  1392. XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
  1393. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
  1394. stats->rxfifooverflow +=
  1395. XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
  1396. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
  1397. stats->rxvlanframes_gb +=
  1398. XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
  1399. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
  1400. stats->rxwatchdogerror +=
  1401. XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
  1402. }
  1403. static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
  1404. {
  1405. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  1406. /* Freeze counters */
  1407. XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
  1408. stats->txoctetcount_gb +=
  1409. XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
  1410. stats->txframecount_gb +=
  1411. XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
  1412. stats->txbroadcastframes_g +=
  1413. XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
  1414. stats->txmulticastframes_g +=
  1415. XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
  1416. stats->tx64octets_gb +=
  1417. XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
  1418. stats->tx65to127octets_gb +=
  1419. XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
  1420. stats->tx128to255octets_gb +=
  1421. XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
  1422. stats->tx256to511octets_gb +=
  1423. XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
  1424. stats->tx512to1023octets_gb +=
  1425. XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
  1426. stats->tx1024tomaxoctets_gb +=
  1427. XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
  1428. stats->txunicastframes_gb +=
  1429. XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
  1430. stats->txmulticastframes_gb +=
  1431. XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
  1432. stats->txbroadcastframes_g +=
  1433. XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
  1434. stats->txunderflowerror +=
  1435. XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
  1436. stats->txoctetcount_g +=
  1437. XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
  1438. stats->txframecount_g +=
  1439. XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
  1440. stats->txpauseframes +=
  1441. XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
  1442. stats->txvlanframes_g +=
  1443. XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
  1444. stats->rxframecount_gb +=
  1445. XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
  1446. stats->rxoctetcount_gb +=
  1447. XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
  1448. stats->rxoctetcount_g +=
  1449. XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
  1450. stats->rxbroadcastframes_g +=
  1451. XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
  1452. stats->rxmulticastframes_g +=
  1453. XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
  1454. stats->rxcrcerror +=
  1455. XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
  1456. stats->rxrunterror +=
  1457. XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
  1458. stats->rxjabbererror +=
  1459. XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
  1460. stats->rxundersize_g +=
  1461. XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
  1462. stats->rxoversize_g +=
  1463. XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
  1464. stats->rx64octets_gb +=
  1465. XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
  1466. stats->rx65to127octets_gb +=
  1467. XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
  1468. stats->rx128to255octets_gb +=
  1469. XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
  1470. stats->rx256to511octets_gb +=
  1471. XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
  1472. stats->rx512to1023octets_gb +=
  1473. XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
  1474. stats->rx1024tomaxoctets_gb +=
  1475. XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
  1476. stats->rxunicastframes_g +=
  1477. XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
  1478. stats->rxlengtherror +=
  1479. XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
  1480. stats->rxoutofrangetype +=
  1481. XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
  1482. stats->rxpauseframes +=
  1483. XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
  1484. stats->rxfifooverflow +=
  1485. XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
  1486. stats->rxvlanframes_gb +=
  1487. XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
  1488. stats->rxwatchdogerror +=
  1489. XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
  1490. /* Un-freeze counters */
  1491. XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
  1492. }
  1493. static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
  1494. {
  1495. /* Set counters to reset on read */
  1496. XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
  1497. /* Reset the counters */
  1498. XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
  1499. }
  1500. static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
  1501. {
  1502. struct xgbe_channel *channel;
  1503. unsigned int i;
  1504. /* Enable each Tx DMA channel */
  1505. channel = pdata->channel;
  1506. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1507. if (!channel->tx_ring)
  1508. break;
  1509. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
  1510. }
  1511. /* Enable each Tx queue */
  1512. for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
  1513. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
  1514. MTL_Q_ENABLED);
  1515. /* Enable MAC Tx */
  1516. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
  1517. }
  1518. static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
  1519. {
  1520. struct xgbe_channel *channel;
  1521. unsigned int i;
  1522. /* Disable MAC Tx */
  1523. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
  1524. /* Disable each Tx queue */
  1525. for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
  1526. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
  1527. /* Disable each Tx DMA channel */
  1528. channel = pdata->channel;
  1529. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1530. if (!channel->tx_ring)
  1531. break;
  1532. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
  1533. }
  1534. }
  1535. static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
  1536. {
  1537. struct xgbe_channel *channel;
  1538. unsigned int reg_val, i;
  1539. /* Enable each Rx DMA channel */
  1540. channel = pdata->channel;
  1541. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1542. if (!channel->rx_ring)
  1543. break;
  1544. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
  1545. }
  1546. /* Enable each Rx queue */
  1547. reg_val = 0;
  1548. for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
  1549. reg_val |= (0x02 << (i << 1));
  1550. XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
  1551. /* Enable MAC Rx */
  1552. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
  1553. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
  1554. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
  1555. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
  1556. }
  1557. static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
  1558. {
  1559. struct xgbe_channel *channel;
  1560. unsigned int i;
  1561. /* Disable MAC Rx */
  1562. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
  1563. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
  1564. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
  1565. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
  1566. /* Disable each Rx queue */
  1567. XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
  1568. /* Disable each Rx DMA channel */
  1569. channel = pdata->channel;
  1570. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1571. if (!channel->rx_ring)
  1572. break;
  1573. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
  1574. }
  1575. }
  1576. static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
  1577. {
  1578. struct xgbe_channel *channel;
  1579. unsigned int i;
  1580. /* Enable each Tx DMA channel */
  1581. channel = pdata->channel;
  1582. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1583. if (!channel->tx_ring)
  1584. break;
  1585. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
  1586. }
  1587. /* Enable MAC Tx */
  1588. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
  1589. }
  1590. static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
  1591. {
  1592. struct xgbe_channel *channel;
  1593. unsigned int i;
  1594. /* Disable MAC Tx */
  1595. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
  1596. /* Disable each Tx DMA channel */
  1597. channel = pdata->channel;
  1598. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1599. if (!channel->tx_ring)
  1600. break;
  1601. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
  1602. }
  1603. }
  1604. static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
  1605. {
  1606. struct xgbe_channel *channel;
  1607. unsigned int i;
  1608. /* Enable each Rx DMA channel */
  1609. channel = pdata->channel;
  1610. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1611. if (!channel->rx_ring)
  1612. break;
  1613. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
  1614. }
  1615. }
  1616. static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
  1617. {
  1618. struct xgbe_channel *channel;
  1619. unsigned int i;
  1620. /* Disable each Rx DMA channel */
  1621. channel = pdata->channel;
  1622. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1623. if (!channel->rx_ring)
  1624. break;
  1625. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
  1626. }
  1627. }
  1628. static int xgbe_init(struct xgbe_prv_data *pdata)
  1629. {
  1630. struct xgbe_desc_if *desc_if = &pdata->desc_if;
  1631. int ret;
  1632. DBGPR("-->xgbe_init\n");
  1633. /* Flush Tx queues */
  1634. ret = xgbe_flush_tx_queues(pdata);
  1635. if (ret)
  1636. return ret;
  1637. /*
  1638. * Initialize DMA related features
  1639. */
  1640. xgbe_config_dma_bus(pdata);
  1641. xgbe_config_dma_cache(pdata);
  1642. xgbe_config_osp_mode(pdata);
  1643. xgbe_config_pblx8(pdata);
  1644. xgbe_config_tx_pbl_val(pdata);
  1645. xgbe_config_rx_pbl_val(pdata);
  1646. xgbe_config_rx_coalesce(pdata);
  1647. xgbe_config_tx_coalesce(pdata);
  1648. xgbe_config_rx_buffer_size(pdata);
  1649. xgbe_config_tso_mode(pdata);
  1650. desc_if->wrapper_tx_desc_init(pdata);
  1651. desc_if->wrapper_rx_desc_init(pdata);
  1652. xgbe_enable_dma_interrupts(pdata);
  1653. /*
  1654. * Initialize MTL related features
  1655. */
  1656. xgbe_config_mtl_mode(pdata);
  1657. xgbe_config_rx_queue_mapping(pdata);
  1658. /*TODO: Program the priorities mapped to the Selected Traffic Classes
  1659. in MTL_TC_Prty_Map0-3 registers */
  1660. xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
  1661. xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
  1662. xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
  1663. xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
  1664. xgbe_config_tx_fifo_size(pdata);
  1665. xgbe_config_rx_fifo_size(pdata);
  1666. xgbe_config_flow_control_threshold(pdata);
  1667. /*TODO: Queue to Traffic Class Mapping (Q2TCMAP) */
  1668. /*TODO: Error Packet and undersized good Packet forwarding enable
  1669. (FEP and FUP)
  1670. */
  1671. xgbe_enable_mtl_interrupts(pdata);
  1672. /* Transmit Class Weight */
  1673. XGMAC_IOWRITE_BITS(pdata, MTL_Q_TCQWR, QW, 0x10);
  1674. /*
  1675. * Initialize MAC related features
  1676. */
  1677. xgbe_config_mac_address(pdata);
  1678. xgbe_config_jumbo_enable(pdata);
  1679. xgbe_config_flow_control(pdata);
  1680. xgbe_config_checksum_offload(pdata);
  1681. xgbe_config_vlan_support(pdata);
  1682. xgbe_config_mmc(pdata);
  1683. xgbe_enable_mac_interrupts(pdata);
  1684. DBGPR("<--xgbe_init\n");
  1685. return 0;
  1686. }
  1687. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
  1688. {
  1689. DBGPR("-->xgbe_init_function_ptrs\n");
  1690. hw_if->tx_complete = xgbe_tx_complete;
  1691. hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
  1692. hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
  1693. hw_if->set_addn_mac_addrs = xgbe_set_addn_mac_addrs;
  1694. hw_if->set_mac_address = xgbe_set_mac_address;
  1695. hw_if->enable_rx_csum = xgbe_enable_rx_csum;
  1696. hw_if->disable_rx_csum = xgbe_disable_rx_csum;
  1697. hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
  1698. hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
  1699. hw_if->read_mmd_regs = xgbe_read_mmd_regs;
  1700. hw_if->write_mmd_regs = xgbe_write_mmd_regs;
  1701. hw_if->set_gmii_speed = xgbe_set_gmii_speed;
  1702. hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
  1703. hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
  1704. hw_if->enable_tx = xgbe_enable_tx;
  1705. hw_if->disable_tx = xgbe_disable_tx;
  1706. hw_if->enable_rx = xgbe_enable_rx;
  1707. hw_if->disable_rx = xgbe_disable_rx;
  1708. hw_if->powerup_tx = xgbe_powerup_tx;
  1709. hw_if->powerdown_tx = xgbe_powerdown_tx;
  1710. hw_if->powerup_rx = xgbe_powerup_rx;
  1711. hw_if->powerdown_rx = xgbe_powerdown_rx;
  1712. hw_if->pre_xmit = xgbe_pre_xmit;
  1713. hw_if->dev_read = xgbe_dev_read;
  1714. hw_if->enable_int = xgbe_enable_int;
  1715. hw_if->disable_int = xgbe_disable_int;
  1716. hw_if->init = xgbe_init;
  1717. hw_if->exit = xgbe_exit;
  1718. /* Descriptor related Sequences have to be initialized here */
  1719. hw_if->tx_desc_init = xgbe_tx_desc_init;
  1720. hw_if->rx_desc_init = xgbe_rx_desc_init;
  1721. hw_if->tx_desc_reset = xgbe_tx_desc_reset;
  1722. hw_if->rx_desc_reset = xgbe_rx_desc_reset;
  1723. hw_if->is_last_desc = xgbe_is_last_desc;
  1724. hw_if->is_context_desc = xgbe_is_context_desc;
  1725. /* For FLOW ctrl */
  1726. hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
  1727. hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
  1728. /* For RX coalescing */
  1729. hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
  1730. hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
  1731. hw_if->usec_to_riwt = xgbe_usec_to_riwt;
  1732. hw_if->riwt_to_usec = xgbe_riwt_to_usec;
  1733. /* For RX and TX threshold config */
  1734. hw_if->config_rx_threshold = xgbe_config_rx_threshold;
  1735. hw_if->config_tx_threshold = xgbe_config_tx_threshold;
  1736. /* For RX and TX Store and Forward Mode config */
  1737. hw_if->config_rsf_mode = xgbe_config_rsf_mode;
  1738. hw_if->config_tsf_mode = xgbe_config_tsf_mode;
  1739. /* For TX DMA Operating on Second Frame config */
  1740. hw_if->config_osp_mode = xgbe_config_osp_mode;
  1741. /* For RX and TX PBL config */
  1742. hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
  1743. hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
  1744. hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
  1745. hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
  1746. hw_if->config_pblx8 = xgbe_config_pblx8;
  1747. /* For MMC statistics support */
  1748. hw_if->tx_mmc_int = xgbe_tx_mmc_int;
  1749. hw_if->rx_mmc_int = xgbe_rx_mmc_int;
  1750. hw_if->read_mmc_stats = xgbe_read_mmc_stats;
  1751. DBGPR("<--xgbe_init_function_ptrs\n");
  1752. }