xgbe-dev.c 62 KB

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