xgbe-dev.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182
  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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 &= 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 &= ~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, DMA_ARCACHE_SETTING);
  1097. XGMAC_SET_BITS(arcache, DMA_AXIARCR, DRD, DMA_ARDOMAIN_SETTING);
  1098. XGMAC_SET_BITS(arcache, DMA_AXIARCR, TEC, DMA_ARCACHE_SETTING);
  1099. XGMAC_SET_BITS(arcache, DMA_AXIARCR, TED, DMA_ARDOMAIN_SETTING);
  1100. XGMAC_SET_BITS(arcache, DMA_AXIARCR, THC, DMA_ARCACHE_SETTING);
  1101. XGMAC_SET_BITS(arcache, DMA_AXIARCR, THD, DMA_ARDOMAIN_SETTING);
  1102. XGMAC_IOWRITE(pdata, DMA_AXIARCR, arcache);
  1103. awcache = 0;
  1104. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWC, DMA_AWCACHE_SETTING);
  1105. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, DWD, DMA_AWDOMAIN_SETTING);
  1106. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPC, DMA_AWCACHE_SETTING);
  1107. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RPD, DMA_AWDOMAIN_SETTING);
  1108. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHC, DMA_AWCACHE_SETTING);
  1109. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, RHD, DMA_AWDOMAIN_SETTING);
  1110. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDC, DMA_AWCACHE_SETTING);
  1111. XGMAC_SET_BITS(awcache, DMA_AXIAWCR, TDD, DMA_AWDOMAIN_SETTING);
  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 = FIFO_SIZE_B(128);
  1136. break;
  1137. case 1:
  1138. q_fifo_size = FIFO_SIZE_B(256);
  1139. break;
  1140. case 2:
  1141. q_fifo_size = FIFO_SIZE_B(512);
  1142. break;
  1143. case 3:
  1144. q_fifo_size = FIFO_SIZE_KB(1);
  1145. break;
  1146. case 4:
  1147. q_fifo_size = FIFO_SIZE_KB(2);
  1148. break;
  1149. case 5:
  1150. q_fifo_size = FIFO_SIZE_KB(4);
  1151. break;
  1152. case 6:
  1153. q_fifo_size = FIFO_SIZE_KB(8);
  1154. break;
  1155. case 7:
  1156. q_fifo_size = FIFO_SIZE_KB(16);
  1157. break;
  1158. case 8:
  1159. q_fifo_size = FIFO_SIZE_KB(32);
  1160. break;
  1161. case 9:
  1162. q_fifo_size = FIFO_SIZE_KB(64);
  1163. break;
  1164. case 10:
  1165. q_fifo_size = FIFO_SIZE_KB(128);
  1166. break;
  1167. case 11:
  1168. q_fifo_size = 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 >= FIFO_SIZE_KB(256))
  1174. p_fifo = XGMAC_MTL_FIFO_SIZE_256K;
  1175. else if (q_fifo_size >= FIFO_SIZE_KB(128))
  1176. p_fifo = XGMAC_MTL_FIFO_SIZE_128K;
  1177. else if (q_fifo_size >= FIFO_SIZE_KB(64))
  1178. p_fifo = XGMAC_MTL_FIFO_SIZE_64K;
  1179. else if (q_fifo_size >= FIFO_SIZE_KB(32))
  1180. p_fifo = XGMAC_MTL_FIFO_SIZE_32K;
  1181. else if (q_fifo_size >= FIFO_SIZE_KB(16))
  1182. p_fifo = XGMAC_MTL_FIFO_SIZE_16K;
  1183. else if (q_fifo_size >= FIFO_SIZE_KB(8))
  1184. p_fifo = XGMAC_MTL_FIFO_SIZE_8K;
  1185. else if (q_fifo_size >= FIFO_SIZE_KB(4))
  1186. p_fifo = XGMAC_MTL_FIFO_SIZE_4K;
  1187. else if (q_fifo_size >= FIFO_SIZE_KB(2))
  1188. p_fifo = XGMAC_MTL_FIFO_SIZE_2K;
  1189. else if (q_fifo_size >= FIFO_SIZE_KB(1))
  1190. p_fifo = XGMAC_MTL_FIFO_SIZE_1K;
  1191. else if (q_fifo_size >= FIFO_SIZE_B(512))
  1192. p_fifo = XGMAC_MTL_FIFO_SIZE_512;
  1193. else if (q_fifo_size >= 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. if (pdata->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  1265. xgbe_enable_rx_vlan_stripping(pdata);
  1266. else
  1267. xgbe_disable_rx_vlan_stripping(pdata);
  1268. }
  1269. static void xgbe_tx_mmc_int(struct xgbe_prv_data *pdata)
  1270. {
  1271. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  1272. unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_TISR);
  1273. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_GB))
  1274. stats->txoctetcount_gb +=
  1275. XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
  1276. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_GB))
  1277. stats->txframecount_gb +=
  1278. XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
  1279. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_G))
  1280. stats->txbroadcastframes_g +=
  1281. XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
  1282. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_G))
  1283. stats->txmulticastframes_g +=
  1284. XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
  1285. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX64OCTETS_GB))
  1286. stats->tx64octets_gb +=
  1287. XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
  1288. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX65TO127OCTETS_GB))
  1289. stats->tx65to127octets_gb +=
  1290. XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
  1291. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX128TO255OCTETS_GB))
  1292. stats->tx128to255octets_gb +=
  1293. XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
  1294. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX256TO511OCTETS_GB))
  1295. stats->tx256to511octets_gb +=
  1296. XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
  1297. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX512TO1023OCTETS_GB))
  1298. stats->tx512to1023octets_gb +=
  1299. XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
  1300. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TX1024TOMAXOCTETS_GB))
  1301. stats->tx1024tomaxoctets_gb +=
  1302. XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
  1303. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNICASTFRAMES_GB))
  1304. stats->txunicastframes_gb +=
  1305. XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
  1306. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXMULTICASTFRAMES_GB))
  1307. stats->txmulticastframes_gb +=
  1308. XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
  1309. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXBROADCASTFRAMES_GB))
  1310. stats->txbroadcastframes_g +=
  1311. XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
  1312. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXUNDERFLOWERROR))
  1313. stats->txunderflowerror +=
  1314. XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
  1315. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXOCTETCOUNT_G))
  1316. stats->txoctetcount_g +=
  1317. XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
  1318. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXFRAMECOUNT_G))
  1319. stats->txframecount_g +=
  1320. XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
  1321. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXPAUSEFRAMES))
  1322. stats->txpauseframes +=
  1323. XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
  1324. if (XGMAC_GET_BITS(mmc_isr, MMC_TISR, TXVLANFRAMES_G))
  1325. stats->txvlanframes_g +=
  1326. XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
  1327. }
  1328. static void xgbe_rx_mmc_int(struct xgbe_prv_data *pdata)
  1329. {
  1330. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  1331. unsigned int mmc_isr = XGMAC_IOREAD(pdata, MMC_RISR);
  1332. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFRAMECOUNT_GB))
  1333. stats->rxframecount_gb +=
  1334. XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
  1335. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_GB))
  1336. stats->rxoctetcount_gb +=
  1337. XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
  1338. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOCTETCOUNT_G))
  1339. stats->rxoctetcount_g +=
  1340. XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
  1341. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXBROADCASTFRAMES_G))
  1342. stats->rxbroadcastframes_g +=
  1343. XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
  1344. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXMULTICASTFRAMES_G))
  1345. stats->rxmulticastframes_g +=
  1346. XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
  1347. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXCRCERROR))
  1348. stats->rxcrcerror +=
  1349. XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
  1350. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXRUNTERROR))
  1351. stats->rxrunterror +=
  1352. XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
  1353. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXJABBERERROR))
  1354. stats->rxjabbererror +=
  1355. XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
  1356. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNDERSIZE_G))
  1357. stats->rxundersize_g +=
  1358. XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
  1359. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOVERSIZE_G))
  1360. stats->rxoversize_g +=
  1361. XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
  1362. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX64OCTETS_GB))
  1363. stats->rx64octets_gb +=
  1364. XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
  1365. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX65TO127OCTETS_GB))
  1366. stats->rx65to127octets_gb +=
  1367. XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
  1368. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX128TO255OCTETS_GB))
  1369. stats->rx128to255octets_gb +=
  1370. XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
  1371. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX256TO511OCTETS_GB))
  1372. stats->rx256to511octets_gb +=
  1373. XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
  1374. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX512TO1023OCTETS_GB))
  1375. stats->rx512to1023octets_gb +=
  1376. XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
  1377. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RX1024TOMAXOCTETS_GB))
  1378. stats->rx1024tomaxoctets_gb +=
  1379. XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
  1380. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXUNICASTFRAMES_G))
  1381. stats->rxunicastframes_g +=
  1382. XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
  1383. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXLENGTHERROR))
  1384. stats->rxlengtherror +=
  1385. XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
  1386. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXOUTOFRANGETYPE))
  1387. stats->rxoutofrangetype +=
  1388. XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
  1389. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXPAUSEFRAMES))
  1390. stats->rxpauseframes +=
  1391. XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
  1392. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXFIFOOVERFLOW))
  1393. stats->rxfifooverflow +=
  1394. XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
  1395. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXVLANFRAMES_GB))
  1396. stats->rxvlanframes_gb +=
  1397. XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
  1398. if (XGMAC_GET_BITS(mmc_isr, MMC_RISR, RXWATCHDOGERROR))
  1399. stats->rxwatchdogerror +=
  1400. XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
  1401. }
  1402. static void xgbe_read_mmc_stats(struct xgbe_prv_data *pdata)
  1403. {
  1404. struct xgbe_mmc_stats *stats = &pdata->mmc_stats;
  1405. /* Freeze counters */
  1406. XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
  1407. stats->txoctetcount_gb +=
  1408. XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
  1409. stats->txframecount_gb +=
  1410. XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
  1411. stats->txbroadcastframes_g +=
  1412. XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
  1413. stats->txmulticastframes_g +=
  1414. XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
  1415. stats->tx64octets_gb +=
  1416. XGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
  1417. stats->tx65to127octets_gb +=
  1418. XGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
  1419. stats->tx128to255octets_gb +=
  1420. XGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
  1421. stats->tx256to511octets_gb +=
  1422. XGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
  1423. stats->tx512to1023octets_gb +=
  1424. XGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
  1425. stats->tx1024tomaxoctets_gb +=
  1426. XGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
  1427. stats->txunicastframes_gb +=
  1428. XGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
  1429. stats->txmulticastframes_gb +=
  1430. XGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
  1431. stats->txbroadcastframes_g +=
  1432. XGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
  1433. stats->txunderflowerror +=
  1434. XGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
  1435. stats->txoctetcount_g +=
  1436. XGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
  1437. stats->txframecount_g +=
  1438. XGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
  1439. stats->txpauseframes +=
  1440. XGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
  1441. stats->txvlanframes_g +=
  1442. XGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
  1443. stats->rxframecount_gb +=
  1444. XGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
  1445. stats->rxoctetcount_gb +=
  1446. XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
  1447. stats->rxoctetcount_g +=
  1448. XGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
  1449. stats->rxbroadcastframes_g +=
  1450. XGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
  1451. stats->rxmulticastframes_g +=
  1452. XGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
  1453. stats->rxcrcerror +=
  1454. XGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
  1455. stats->rxrunterror +=
  1456. XGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
  1457. stats->rxjabbererror +=
  1458. XGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
  1459. stats->rxundersize_g +=
  1460. XGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
  1461. stats->rxoversize_g +=
  1462. XGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
  1463. stats->rx64octets_gb +=
  1464. XGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
  1465. stats->rx65to127octets_gb +=
  1466. XGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
  1467. stats->rx128to255octets_gb +=
  1468. XGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
  1469. stats->rx256to511octets_gb +=
  1470. XGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
  1471. stats->rx512to1023octets_gb +=
  1472. XGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
  1473. stats->rx1024tomaxoctets_gb +=
  1474. XGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
  1475. stats->rxunicastframes_g +=
  1476. XGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
  1477. stats->rxlengtherror +=
  1478. XGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
  1479. stats->rxoutofrangetype +=
  1480. XGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
  1481. stats->rxpauseframes +=
  1482. XGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
  1483. stats->rxfifooverflow +=
  1484. XGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
  1485. stats->rxvlanframes_gb +=
  1486. XGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
  1487. stats->rxwatchdogerror +=
  1488. XGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
  1489. /* Un-freeze counters */
  1490. XGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
  1491. }
  1492. static void xgbe_config_mmc(struct xgbe_prv_data *pdata)
  1493. {
  1494. /* Set counters to reset on read */
  1495. XGMAC_IOWRITE_BITS(pdata, MMC_CR, ROR, 1);
  1496. /* Reset the counters */
  1497. XGMAC_IOWRITE_BITS(pdata, MMC_CR, CR, 1);
  1498. }
  1499. static void xgbe_enable_tx(struct xgbe_prv_data *pdata)
  1500. {
  1501. struct xgbe_channel *channel;
  1502. unsigned int i;
  1503. /* Enable each Tx DMA channel */
  1504. channel = pdata->channel;
  1505. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1506. if (!channel->tx_ring)
  1507. break;
  1508. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
  1509. }
  1510. /* Enable each Tx queue */
  1511. for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
  1512. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN,
  1513. MTL_Q_ENABLED);
  1514. /* Enable MAC Tx */
  1515. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
  1516. }
  1517. static void xgbe_disable_tx(struct xgbe_prv_data *pdata)
  1518. {
  1519. struct xgbe_channel *channel;
  1520. unsigned int i;
  1521. /* Disable MAC Tx */
  1522. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
  1523. /* Disable each Tx queue */
  1524. for (i = 0; i < pdata->hw_feat.tx_q_cnt; i++)
  1525. XGMAC_MTL_IOWRITE_BITS(pdata, i, MTL_Q_TQOMR, TXQEN, 0);
  1526. /* Disable each Tx DMA channel */
  1527. channel = pdata->channel;
  1528. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1529. if (!channel->tx_ring)
  1530. break;
  1531. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
  1532. }
  1533. }
  1534. static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
  1535. {
  1536. struct xgbe_channel *channel;
  1537. unsigned int reg_val, i;
  1538. /* Enable each Rx DMA channel */
  1539. channel = pdata->channel;
  1540. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1541. if (!channel->rx_ring)
  1542. break;
  1543. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
  1544. }
  1545. /* Enable each Rx queue */
  1546. reg_val = 0;
  1547. for (i = 0; i < pdata->hw_feat.rx_q_cnt; i++)
  1548. reg_val |= (0x02 << (i << 1));
  1549. XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
  1550. /* Enable MAC Rx */
  1551. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
  1552. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
  1553. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
  1554. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
  1555. }
  1556. static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
  1557. {
  1558. struct xgbe_channel *channel;
  1559. unsigned int i;
  1560. /* Disable MAC Rx */
  1561. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
  1562. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
  1563. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
  1564. XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
  1565. /* Disable each Rx queue */
  1566. XGMAC_IOWRITE(pdata, MAC_RQC0R, 0);
  1567. /* Disable each Rx DMA channel */
  1568. channel = pdata->channel;
  1569. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1570. if (!channel->rx_ring)
  1571. break;
  1572. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
  1573. }
  1574. }
  1575. static void xgbe_powerup_tx(struct xgbe_prv_data *pdata)
  1576. {
  1577. struct xgbe_channel *channel;
  1578. unsigned int i;
  1579. /* Enable each Tx DMA channel */
  1580. channel = pdata->channel;
  1581. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1582. if (!channel->tx_ring)
  1583. break;
  1584. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 1);
  1585. }
  1586. /* Enable MAC Tx */
  1587. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 1);
  1588. }
  1589. static void xgbe_powerdown_tx(struct xgbe_prv_data *pdata)
  1590. {
  1591. struct xgbe_channel *channel;
  1592. unsigned int i;
  1593. /* Disable MAC Tx */
  1594. XGMAC_IOWRITE_BITS(pdata, MAC_TCR, TE, 0);
  1595. /* Disable each Tx DMA channel */
  1596. channel = pdata->channel;
  1597. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1598. if (!channel->tx_ring)
  1599. break;
  1600. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_TCR, ST, 0);
  1601. }
  1602. }
  1603. static void xgbe_powerup_rx(struct xgbe_prv_data *pdata)
  1604. {
  1605. struct xgbe_channel *channel;
  1606. unsigned int i;
  1607. /* Enable each Rx DMA channel */
  1608. channel = pdata->channel;
  1609. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1610. if (!channel->rx_ring)
  1611. break;
  1612. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 1);
  1613. }
  1614. }
  1615. static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
  1616. {
  1617. struct xgbe_channel *channel;
  1618. unsigned int i;
  1619. /* Disable each Rx DMA channel */
  1620. channel = pdata->channel;
  1621. for (i = 0; i < pdata->channel_count; i++, channel++) {
  1622. if (!channel->rx_ring)
  1623. break;
  1624. XGMAC_DMA_IOWRITE_BITS(channel, DMA_CH_RCR, SR, 0);
  1625. }
  1626. }
  1627. static int xgbe_init(struct xgbe_prv_data *pdata)
  1628. {
  1629. struct xgbe_desc_if *desc_if = &pdata->desc_if;
  1630. int ret;
  1631. DBGPR("-->xgbe_init\n");
  1632. /* Flush Tx queues */
  1633. ret = xgbe_flush_tx_queues(pdata);
  1634. if (ret)
  1635. return ret;
  1636. /*
  1637. * Initialize DMA related features
  1638. */
  1639. xgbe_config_dma_bus(pdata);
  1640. xgbe_config_dma_cache(pdata);
  1641. xgbe_config_osp_mode(pdata);
  1642. xgbe_config_pblx8(pdata);
  1643. xgbe_config_tx_pbl_val(pdata);
  1644. xgbe_config_rx_pbl_val(pdata);
  1645. xgbe_config_rx_coalesce(pdata);
  1646. xgbe_config_tx_coalesce(pdata);
  1647. xgbe_config_rx_buffer_size(pdata);
  1648. xgbe_config_tso_mode(pdata);
  1649. desc_if->wrapper_tx_desc_init(pdata);
  1650. desc_if->wrapper_rx_desc_init(pdata);
  1651. xgbe_enable_dma_interrupts(pdata);
  1652. /*
  1653. * Initialize MTL related features
  1654. */
  1655. xgbe_config_mtl_mode(pdata);
  1656. xgbe_config_rx_queue_mapping(pdata);
  1657. /*TODO: Program the priorities mapped to the Selected Traffic Classes
  1658. in MTL_TC_Prty_Map0-3 registers */
  1659. xgbe_config_tsf_mode(pdata, pdata->tx_sf_mode);
  1660. xgbe_config_rsf_mode(pdata, pdata->rx_sf_mode);
  1661. xgbe_config_tx_threshold(pdata, pdata->tx_threshold);
  1662. xgbe_config_rx_threshold(pdata, pdata->rx_threshold);
  1663. xgbe_config_tx_fifo_size(pdata);
  1664. xgbe_config_rx_fifo_size(pdata);
  1665. xgbe_config_flow_control_threshold(pdata);
  1666. /*TODO: Queue to Traffic Class Mapping (Q2TCMAP) */
  1667. /*TODO: Error Packet and undersized good Packet forwarding enable
  1668. (FEP and FUP)
  1669. */
  1670. xgbe_enable_mtl_interrupts(pdata);
  1671. /* Transmit Class Weight */
  1672. XGMAC_IOWRITE_BITS(pdata, MTL_Q_TCQWR, QW, 0x10);
  1673. /*
  1674. * Initialize MAC related features
  1675. */
  1676. xgbe_config_mac_address(pdata);
  1677. xgbe_config_jumbo_enable(pdata);
  1678. xgbe_config_flow_control(pdata);
  1679. xgbe_config_checksum_offload(pdata);
  1680. xgbe_config_vlan_support(pdata);
  1681. xgbe_config_mmc(pdata);
  1682. xgbe_enable_mac_interrupts(pdata);
  1683. DBGPR("<--xgbe_init\n");
  1684. return 0;
  1685. }
  1686. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
  1687. {
  1688. DBGPR("-->xgbe_init_function_ptrs\n");
  1689. hw_if->tx_complete = xgbe_tx_complete;
  1690. hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
  1691. hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
  1692. hw_if->set_addn_mac_addrs = xgbe_set_addn_mac_addrs;
  1693. hw_if->set_mac_address = xgbe_set_mac_address;
  1694. hw_if->enable_rx_csum = xgbe_enable_rx_csum;
  1695. hw_if->disable_rx_csum = xgbe_disable_rx_csum;
  1696. hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
  1697. hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
  1698. hw_if->read_mmd_regs = xgbe_read_mmd_regs;
  1699. hw_if->write_mmd_regs = xgbe_write_mmd_regs;
  1700. hw_if->set_gmii_speed = xgbe_set_gmii_speed;
  1701. hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
  1702. hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
  1703. hw_if->enable_tx = xgbe_enable_tx;
  1704. hw_if->disable_tx = xgbe_disable_tx;
  1705. hw_if->enable_rx = xgbe_enable_rx;
  1706. hw_if->disable_rx = xgbe_disable_rx;
  1707. hw_if->powerup_tx = xgbe_powerup_tx;
  1708. hw_if->powerdown_tx = xgbe_powerdown_tx;
  1709. hw_if->powerup_rx = xgbe_powerup_rx;
  1710. hw_if->powerdown_rx = xgbe_powerdown_rx;
  1711. hw_if->pre_xmit = xgbe_pre_xmit;
  1712. hw_if->dev_read = xgbe_dev_read;
  1713. hw_if->enable_int = xgbe_enable_int;
  1714. hw_if->disable_int = xgbe_disable_int;
  1715. hw_if->init = xgbe_init;
  1716. hw_if->exit = xgbe_exit;
  1717. /* Descriptor related Sequences have to be initialized here */
  1718. hw_if->tx_desc_init = xgbe_tx_desc_init;
  1719. hw_if->rx_desc_init = xgbe_rx_desc_init;
  1720. hw_if->tx_desc_reset = xgbe_tx_desc_reset;
  1721. hw_if->rx_desc_reset = xgbe_rx_desc_reset;
  1722. hw_if->is_last_desc = xgbe_is_last_desc;
  1723. hw_if->is_context_desc = xgbe_is_context_desc;
  1724. /* For FLOW ctrl */
  1725. hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
  1726. hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
  1727. /* For RX coalescing */
  1728. hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
  1729. hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
  1730. hw_if->usec_to_riwt = xgbe_usec_to_riwt;
  1731. hw_if->riwt_to_usec = xgbe_riwt_to_usec;
  1732. /* For RX and TX threshold config */
  1733. hw_if->config_rx_threshold = xgbe_config_rx_threshold;
  1734. hw_if->config_tx_threshold = xgbe_config_tx_threshold;
  1735. /* For RX and TX Store and Forward Mode config */
  1736. hw_if->config_rsf_mode = xgbe_config_rsf_mode;
  1737. hw_if->config_tsf_mode = xgbe_config_tsf_mode;
  1738. /* For TX DMA Operating on Second Frame config */
  1739. hw_if->config_osp_mode = xgbe_config_osp_mode;
  1740. /* For RX and TX PBL config */
  1741. hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
  1742. hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
  1743. hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
  1744. hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
  1745. hw_if->config_pblx8 = xgbe_config_pblx8;
  1746. /* For MMC statistics support */
  1747. hw_if->tx_mmc_int = xgbe_tx_mmc_int;
  1748. hw_if->rx_mmc_int = xgbe_rx_mmc_int;
  1749. hw_if->read_mmc_stats = xgbe_read_mmc_stats;
  1750. DBGPR("<--xgbe_init_function_ptrs\n");
  1751. }