fxmac.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: fxmac.c
  15. * Date: 2022-04-06 14:46:52
  16. * LastEditTime: 2022-04-06 14:46:58
  17. * Description:  This file is for
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. */
  23. #include "fxmac.h"
  24. #include "ftypes.h"
  25. #include "fxmac_hw.h"
  26. #include "stdio.h"
  27. #include "fdebug.h"
  28. #define FXMAC_DEBUG_TAG "FXMAC"
  29. #define FXMAC_PRINT_E(format, ...) FT_DEBUG_PRINT_E(FXMAC_DEBUG_TAG, format, ##__VA_ARGS__)
  30. #define FXMAC_PRINT_I(format, ...) FT_DEBUG_PRINT_I(FXMAC_DEBUG_TAG, format, ##__VA_ARGS__)
  31. #define FXMAC_PRINT_D(format, ...) FT_DEBUG_PRINT_D(FXMAC_DEBUG_TAG, format, ##__VA_ARGS__)
  32. #define FXMAC_PRINT_W(format, ...) FT_DEBUG_PRINT_W(FXMAC_DEBUG_TAG, format, ##__VA_ARGS__)
  33. static void FXmacReset(FXmac *instance_p);
  34. extern FError FXmacSetTypeIdCheck(FXmac *instance_p, u32 id_check, u8 index);
  35. /**
  36. * @name: FXmacSelectClk
  37. * @msg: Determine the driver clock configuration based on the media independent interface
  38. * @param {FXmac} *instance_p is a pointer to the instance to be worked on.
  39. * @param {u32} speed interface speed
  40. * @return {*}
  41. */
  42. void FXmacSelectClk(FXmac *instance_p)
  43. {
  44. u32 reg_value;
  45. s32 set_speed = 0;
  46. u32 speed = instance_p->config.speed;
  47. FASSERT(instance_p != NULL);
  48. FASSERT((speed == FXMAC_SPEED_10) || (speed == FXMAC_SPEED_100) || (speed == FXMAC_SPEED_1000) || (speed == FXMAC_SPEED_2500) || (speed == FXMAC_SPEED_10000));
  49. if ((instance_p->config.interface == FXMAC_PHY_INTERFACE_MODE_USXGMII) || (instance_p->config.interface == FXMAC_PHY_INTERFACE_MODE_XGMII))
  50. {
  51. if (speed == FXMAC_SPEED_10000)
  52. {
  53. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_SRC_SEL_LN, 0x1);
  54. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_DIV_SEL0_LN, 0x4);
  55. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_DIV_SEL1_LN, 0x1);
  56. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_PMA_XCVR_POWER_STATE, 0x1);
  57. }
  58. }
  59. else if (instance_p->config.interface == FXMAC_PHY_INTERFACE_MODE_SGMII)
  60. {
  61. FXMAC_PRINT_I("FXMAC_PHY_INTERFACE_MODE_SGMII init");
  62. if (speed == FXMAC_SPEED_2500)
  63. {
  64. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_SRC_SEL_LN, 0);
  65. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_DIV_SEL0_LN, 0x1);
  66. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_DIV_SEL1_LN, 0x2);
  67. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_PMA_XCVR_POWER_STATE, 0x1);
  68. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL0, 0);
  69. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL1, 0x1);
  70. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL2, 0x1);
  71. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL3, 0x1);
  72. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL0, 0x1);
  73. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL1, 0x0);
  74. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL3_0, 0x0); /*0x1c70*/
  75. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL4_0, 0x0); /*0x1c74*/
  76. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL3_0, 0x0); /*0x1c78*/
  77. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL4_0, 0x0); /*0x1c7c*/
  78. }
  79. else if (speed == FXMAC_SPEED_1000)
  80. {
  81. FXMAC_PRINT_I("sgmii FXMAC_SPEED_1000 \r\n ");
  82. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_SRC_SEL_LN, 1);
  83. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_DIV_SEL0_LN, 0x4);
  84. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_DIV_SEL1_LN, 0x8);
  85. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_PMA_XCVR_POWER_STATE, 0x1);
  86. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL0, 0x0);
  87. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL1, 0x0);
  88. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL2, 0x0);
  89. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL3, 0x1);
  90. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL0, 0x1);
  91. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL1, 0x0);
  92. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL3_0, 0x0); /*0x1c70*/
  93. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL4_0, 0x0); /*0x1c74*/
  94. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL3_0, 0x0); /*0x1c78*/
  95. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL4_0, 0x0); /*0x1c7c*/
  96. }
  97. else if ((speed == FXMAC_SPEED_100) || (speed == FXMAC_SPEED_10))
  98. {
  99. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_DIV_SEL0_LN, 0x4);
  100. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_DIV_SEL1_LN, 0x8);
  101. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_PMA_XCVR_POWER_STATE, 0x1);
  102. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL0, 0x0);
  103. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL1, 0x0);
  104. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL2, 0x1);
  105. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL3, 0x1);
  106. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL0, 0x1);
  107. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL1, 0x0);
  108. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL3_0, 0x1); /*0x1c70*/
  109. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL4_0, 0x0); /*0x1c74*/
  110. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL3_0, 0x0); /*0x1c78*/
  111. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL4_0, 0x1); /*0x1c7c*/
  112. }
  113. }
  114. else if (instance_p->config.interface == FXMAC_PHY_INTERFACE_MODE_RGMII)
  115. {
  116. FXMAC_PRINT_I("FXMAC_PHY_INTERFACE_MODE_RGMII init");
  117. if (speed == FXMAC_SPEED_1000)
  118. {
  119. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_MII_SELECT, 0x1); /*0x1c18*/
  120. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_SEL_MII_ON_RGMII, 0x0); /*0x1c1c*/
  121. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL0, 0x0); /*0x1c20*/
  122. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL1, 0x1); /*0x1c24*/
  123. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL2, 0x0); /*0x1c28*/
  124. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL3, 0x0); /*0x1c2c*/
  125. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL0, 0x0); /*0x1c30*/
  126. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL1, 0x1); /*0x1c34*/
  127. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_CLK_250M_DIV10_DIV100_SEL,
  128. 0x0); /*0x1c38*/
  129. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL5, 0x1); /*0x1c48*/
  130. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RGMII_TX_CLK_SEL0, 0x1); /*0x1c80*/
  131. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RGMII_TX_CLK_SEL1, 0x0); /*0x1c84*/
  132. }
  133. else if (speed == FXMAC_SPEED_100)
  134. {
  135. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_SEL_MII_ON_RGMII, 0x0); /*0x1c1c*/
  136. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL0, 0x0); /*0x1c20*/
  137. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL1, 0x1); /*0x1c24*/
  138. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL2, 0x0); /*0x1c28*/
  139. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL3, 0x0); /*0x1c2c*/
  140. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL0, 0x0); /*0x1c30*/
  141. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL1, 0x1); /*0x1c34*/
  142. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_CLK_250M_DIV10_DIV100_SEL,
  143. 0x0); /*0x1c38*/
  144. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL5, 0x1); /*0x1c48*/
  145. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RGMII_TX_CLK_SEL0, 0x0); /*0x1c80*/
  146. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RGMII_TX_CLK_SEL1, 0x0); /*0x1c84*/
  147. }
  148. else
  149. {
  150. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_SEL_MII_ON_RGMII, 0x0); /*0x1c1c*/
  151. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL0, 0x0); /*0x1c20*/
  152. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL1, 0x1); /*0x1c24*/
  153. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL2, 0x0); /*0x1c28*/
  154. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_TX_CLK_SEL3, 0x0); /*0x1c2c*/
  155. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL0, 0x0); /*0x1c30*/
  156. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL1, 0x1); /*0x1c34*/
  157. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_CLK_250M_DIV10_DIV100_SEL,
  158. 0x1); /*0x1c38*/
  159. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL5, 0x1); /*0x1c48*/
  160. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RGMII_TX_CLK_SEL0, 0x0); /*0x1c80*/
  161. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RGMII_TX_CLK_SEL1, 0x0); /*0x1c84*/
  162. }
  163. }
  164. else if (instance_p->config.interface == FXMAC_PHY_INTERFACE_MODE_RMII)
  165. {
  166. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_RX_CLK_SEL5, 0x1); /*0x1c48*/
  167. }
  168. switch (speed)
  169. {
  170. case FXMAC_SPEED_25000:
  171. set_speed = 2;
  172. break;
  173. case FXMAC_SPEED_10000:
  174. set_speed = 4;
  175. break;
  176. case FXMAC_SPEED_5000:
  177. set_speed = 3;
  178. break;
  179. case FXMAC_SPEED_2500:
  180. set_speed = 2;
  181. break;
  182. case FXMAC_SPEED_1000:
  183. set_speed = 1;
  184. break;
  185. default:
  186. set_speed = 0;
  187. break;
  188. }
  189. /*GEM_HSMAC(0x0050) provide rate to the external*/
  190. reg_value = FXMAC_READREG32(instance_p->config.base_address, FXMAC_GEM_HSMAC);
  191. reg_value &= ~FXMAC_GEM_HSMACSPEED_MASK;
  192. reg_value |= (set_speed) &FXMAC_GEM_HSMACSPEED_MASK;
  193. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_GEM_HSMAC, reg_value);
  194. reg_value = FXMAC_READREG32(instance_p->config.base_address, FXMAC_GEM_HSMAC);
  195. FXMAC_PRINT_I("FXMAC_GEM_HSMAC is %x \r\n ", reg_value);
  196. }
  197. /**
  198. * Start the Ethernet controller as follows:
  199. * - Enable transmitter if FXMAC_TRANSMIT_ENABLE_OPTION is set
  200. * - Enable receiver if FXMAC_RECEIVER_ENABLE_OPTION is set
  201. * - Start the SG DMA send and receive channels and enable the device
  202. * interrupt
  203. *
  204. * @param instance_p is a pointer to the instance to be worked on.
  205. *
  206. * @return N/A
  207. *
  208. * @note
  209. * Hardware is configured with scatter-gather DMA, the driver expects to start
  210. * the scatter-gather channels and expects that the user has previously set up
  211. * the buffer descriptor lists.
  212. *
  213. * This function makes use of internal resources that are shared between the
  214. * Start, Stop, and Set/ClearOptions functions. So if one task might be setting
  215. * device options while another is trying to start the device, the user is
  216. * required to provide protection of this shared data (typically using a
  217. * semaphore).
  218. *
  219. * This function must not be preempted by an interrupt that may service the
  220. * device.
  221. *
  222. */
  223. void FXmacStart(FXmac *instance_p)
  224. {
  225. u32 reg_val;
  226. u32 reg = 0;
  227. /* Assert bad arguments and conditions */
  228. FASSERT(instance_p != NULL);
  229. FASSERT(instance_p->is_ready == (u32)FT_COMPONENT_IS_READY);
  230. /* Start DMA */
  231. /* When starting the DMA channels, both transmit and receive sides
  232. * need an initialized BD list.
  233. */
  234. FASSERT(instance_p->rx_bd_queue.bdring.base_bd_addr != 0);
  235. reg = FXMAC_READREG32(instance_p->config.base_address, FXMAC_RXQBASE_OFFSET);
  236. reg = FXMAC_READREG32(instance_p->config.base_address, FXMAC_TXQBASE_OFFSET);
  237. FXMAC_WRITEREG32(instance_p->config.base_address,
  238. FXMAC_RXQBASE_OFFSET,
  239. instance_p->rx_bd_queue.bdring.base_bd_addr);
  240. FXMAC_WRITEREG32(instance_p->config.base_address,
  241. FXMAC_TXQBASE_OFFSET,
  242. instance_p->tx_bd_queue.bdring.base_bd_addr);
  243. reg = FXMAC_READREG32(instance_p->config.base_address, FXMAC_RXQBASE_OFFSET);
  244. reg = FXMAC_READREG32(instance_p->config.base_address, FXMAC_TXQBASE_OFFSET);
  245. /* clear any existed int status */
  246. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_ISR_OFFSET,
  247. FXMAC_IXR_ALL_MASK);
  248. /* Enable transmitter if not already enabled */
  249. if ((instance_p->config.network_default_config & (u32)FXMAC_TRANSMITTER_ENABLE_OPTION) != 0x00000000U)
  250. {
  251. reg_val = FXMAC_READREG32(instance_p->config.base_address,
  252. FXMAC_NWCTRL_OFFSET);
  253. if ((!(reg_val & FXMAC_NWCTRL_TXEN_MASK)) == TRUE)
  254. {
  255. FXMAC_WRITEREG32(instance_p->config.base_address,
  256. FXMAC_NWCTRL_OFFSET,
  257. reg_val | (u32)FXMAC_NWCTRL_TXEN_MASK);
  258. }
  259. }
  260. /* Enable receiver if not already enabled */
  261. if ((instance_p->config.network_default_config & FXMAC_RECEIVER_ENABLE_OPTION) != 0x00000000U)
  262. {
  263. reg_val = FXMAC_READREG32(instance_p->config.base_address,
  264. FXMAC_NWCTRL_OFFSET);
  265. FXMAC_PRINT_I("endable receiver 0x%x \r\n ", reg_val);
  266. if ((!(reg_val & FXMAC_NWCTRL_RXEN_MASK)) == TRUE)
  267. {
  268. FXMAC_WRITEREG32(instance_p->config.base_address,
  269. FXMAC_NWCTRL_OFFSET,
  270. reg_val | (u32)FXMAC_NWCTRL_RXEN_MASK);
  271. }
  272. }
  273. FXMAC_PRINT_I("FXMAC_NWCTRL_OFFSET is 0x%x \r\n", FXMAC_READREG32(instance_p->config.base_address,
  274. FXMAC_NWCTRL_OFFSET));
  275. /* Enable TX and RX interrupt */
  276. FXMAC_INT_ENABLE(instance_p, FXMAC_IXR_LINKCHANGE_MASK | FXMAC_IXR_TX_ERR_MASK | FXMAC_IXR_RX_ERR_MASK | FXMAC_IXR_RXCOMPL_MASK | FXMAC_IXR_TXCOMPL_MASK);
  277. /* Mark as started */
  278. instance_p->is_started = FT_COMPONENT_IS_STARTED;
  279. return;
  280. }
  281. /**
  282. * Gracefully stop the Ethernet MAC as follows:
  283. * - Disable all interrupts from this device
  284. * - Stop DMA channels
  285. * - Disable the tansmitter and receiver
  286. *
  287. * Device options currently in effect are not changed.
  288. *
  289. * This function will disable all interrupts. Default interrupts settings that
  290. * had been enabled will be restored when FXmacStart() is called.
  291. *
  292. * @param instance_p is a pointer to the instance to be worked on.
  293. *
  294. * @note
  295. * This function makes use of internal resources that are shared between the
  296. * Start, Stop, Setoptions, and Clearoptions functions. So if one task might be
  297. * setting device options while another is trying to start the device, the user
  298. * is required to provide protection of this shared data (typically using a
  299. * semaphore).
  300. *
  301. * Stopping the DMA channels causes this function to block until the DMA
  302. * operation is complete.
  303. *
  304. */
  305. void FXmacStop(FXmac *instance_p)
  306. {
  307. u32 reg_val;
  308. FASSERT(instance_p != NULL);
  309. FASSERT(instance_p->is_ready == (u32)FT_COMPONENT_IS_READY);
  310. /* Disable all interrupts */
  311. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_IDR_OFFSET,
  312. FXMAC_IXR_ALL_MASK);
  313. /* Disable the receiver & transmitter */
  314. reg_val = FXMAC_READREG32(instance_p->config.base_address,
  315. FXMAC_NWCTRL_OFFSET);
  316. reg_val &= (u32)(~FXMAC_NWCTRL_RXEN_MASK);
  317. reg_val &= (u32)(~FXMAC_NWCTRL_TXEN_MASK);
  318. FXMAC_WRITEREG32(instance_p->config.base_address,
  319. FXMAC_NWCTRL_OFFSET, reg_val);
  320. /* Mark as stopped */
  321. instance_p->is_started = 0U;
  322. }
  323. static u32 FXmacClkDivGet(FXmac *instance_p)
  324. {
  325. FXmacConfig *config_p;
  326. config_p = &instance_p->config;
  327. if (config_p->pclk_hz <= 20000000)
  328. {
  329. return FXMAC_NWCFG_CLOCK_DIV8_MASK;
  330. }
  331. else if (config_p->pclk_hz <= 40000000)
  332. {
  333. return FXMAC_NWCFG_CLOCK_DIV16_MASK;
  334. }
  335. else if (config_p->pclk_hz <= 80000000)
  336. {
  337. return FXMAC_NWCFG_CLOCK_DIV32_MASK;
  338. }
  339. else if (instance_p->moudle_id >= 2)
  340. {
  341. if (config_p->pclk_hz <= 120000000)
  342. {
  343. return FXMAC_NWCFG_CLOCK_DIV48_MASK;
  344. }
  345. else if (config_p->pclk_hz <= 160000000)
  346. {
  347. return FXMAC_NWCFG_CLOCK_DIV64_MASK;
  348. }
  349. else if (config_p->pclk_hz <= 240000000)
  350. {
  351. return FXMAC_NWCFG_CLOCK_DIV96_MASK;
  352. }
  353. else if (config_p->pclk_hz <= 320000000)
  354. {
  355. return FXMAC_NWCFG_CLOCK_DIV128_MASK;
  356. }
  357. else
  358. {
  359. return FXMAC_NWCFG_CLOCK_DIV224_MASK;
  360. }
  361. }
  362. else
  363. {
  364. return FXMAC_NWCFG_CLOCK_DIV64_MASK;
  365. }
  366. }
  367. static u32 FXmacDmaWidth(FXmac *instance_p)
  368. {
  369. u32 read_regs = 0;
  370. FXmacConfig *config_p;
  371. config_p = &instance_p->config;
  372. if (instance_p->moudle_id < 2)
  373. {
  374. return FXMAC_NWCFG_BUS_WIDTH_32_MASK;
  375. }
  376. read_regs = FXMAC_READREG32(config_p->base_address, FXMAC_DESIGNCFG_DEBUG1_OFFSET);
  377. switch ((read_regs & FXMAC_DESIGNCFG_DEBUG1_BUS_WIDTH_MASK) >> 25)
  378. {
  379. case 4:
  380. FXMAC_PRINT_I("bus width is 128");
  381. return FXMAC_NWCFG_BUS_WIDTH_128_MASK;
  382. case 2:
  383. FXMAC_PRINT_I("bus width is 64");
  384. return FXMAC_NWCFG_BUS_WIDTH_64_MASK;
  385. default:
  386. FXMAC_PRINT_I("bus width is 32");
  387. return FXMAC_NWCFG_BUS_WIDTH_32_MASK;
  388. }
  389. }
  390. static void FXmacDmaReset(FXmac *instance_p)
  391. {
  392. u32 queue = 0;
  393. FXmacConfig *config_p;
  394. config_p = &instance_p->config;
  395. u32 dmacfg = 0;
  396. u32 rx_buf_size = 0;
  397. rx_buf_size = instance_p->max_frame_size / FXMAC_RX_BUF_UNIT;
  398. rx_buf_size += ((instance_p->max_frame_size % FXMAC_RX_BUF_UNIT) != 0) ? 1 : 0; /* roundup */
  399. if (instance_p->moudle_id >= 2)
  400. {
  401. for (queue = 0; queue < config_p->max_queue_num; queue++)
  402. {
  403. dmacfg = 0;
  404. FXmacSetQueuePtr(instance_p, (uintptr)NULL, queue, (u16)FXMAC_SEND);
  405. FXmacSetQueuePtr(instance_p, (uintptr)NULL, queue, (u16)FXMAC_RECV);
  406. if (queue)
  407. {
  408. FXMAC_WRITEREG32(config_p->base_address, FXMAC_RXBUFQX_SIZE_OFFSET(queue), rx_buf_size);
  409. }
  410. else /* queue is 0 */
  411. {
  412. dmacfg |= ((u32)FXMAC_DMACR_RXBUF_MASK & (rx_buf_size << FXMAC_DMACR_RXBUF_SHIFT));
  413. }
  414. }
  415. dmacfg |= (config_p->dma_brust_length & FXMAC_DMACR_BLENGTH_MASK);
  416. dmacfg &= ~FXMAC_DMACR_ENDIAN_MASK;
  417. dmacfg &= ~FXMAC_DMACR_SWAP_MANAGEMENT_MASK; /* 选择小端 */
  418. dmacfg &= ~FXMAC_DMACR_TCPCKSUM_MASK; /* close transmitter checksum generation engine */
  419. dmacfg &= ~FXMAC_DMACR_ADDR_WIDTH_64;
  420. dmacfg |= FXMAC_DMACR_RXSIZE_MASK | FXMAC_DMACR_TXSIZE_MASK;
  421. #if defined(__aarch64__) || defined(__arch64__)
  422. dmacfg |= FXMAC_DMACR_ADDR_WIDTH_64;
  423. #endif
  424. }
  425. else
  426. {
  427. FXmacSetQueuePtr(instance_p, (uintptr)NULL, 0, (u16)FXMAC_SEND);
  428. FXmacSetQueuePtr(instance_p, (uintptr)NULL, 0, (u16)FXMAC_RECV);
  429. dmacfg |= ((u32)FXMAC_DMACR_RXBUF_MASK & (rx_buf_size << FXMAC_DMACR_RXBUF_SHIFT));
  430. dmacfg |= (config_p->dma_brust_length & FXMAC_DMACR_BLENGTH_MASK);
  431. dmacfg &= ~FXMAC_DMACR_ENDIAN_MASK;
  432. dmacfg &= ~FXMAC_DMACR_SWAP_MANAGEMENT_MASK; /* 选择小端 */
  433. dmacfg &= ~FXMAC_DMACR_TCPCKSUM_MASK; /* close transmitter checksum generation engine */
  434. dmacfg &= ~FXMAC_DMACR_ADDR_WIDTH_64;
  435. dmacfg |= FXMAC_DMACR_RXSIZE_MASK | FXMAC_DMACR_TXSIZE_MASK;
  436. #if defined(__aarch64__) || defined(__arch64__)
  437. dmacfg |= FXMAC_DMACR_ADDR_WIDTH_64;
  438. #endif
  439. }
  440. FXMAC_WRITEREG32(config_p->base_address, FXMAC_DMACR_OFFSET, dmacfg);
  441. }
  442. /**
  443. * Perform a graceful reset of the Ethernet MAC. Resets the DMA channels, the
  444. * transmitter, and the receiver.
  445. *
  446. * Steps to reset
  447. * - Stops transmit and receive channels
  448. * - Stops DMA
  449. * - Configure transmit and receive buffer size to default
  450. * - Clear transmit and receive status register and counters
  451. * - Clear all interrupt sources
  452. * - Clear phy (if there is any previously detected) address
  453. * - Clear MAC addresses (1-4) as well as Type IDs and hash value
  454. *
  455. * All options are placed in their default state. Any frames in the
  456. * descriptor lists will remain in the lists. The side effect of doing
  457. * this is that after a reset and following a restart of the device, frames
  458. * were in the list before the reset may be transmitted or received.
  459. *
  460. * The upper layer software is responsible for re-configuring (if necessary)
  461. * and restarting the MAC after the reset. Note also that driver statistics
  462. * are not cleared on reset. It is up to the upper layer software to clear the
  463. * statistics if needed.
  464. *
  465. * When a reset is required, the driver notifies the upper layer software of
  466. * this need through the ErrorHandler callback and specific status codes.
  467. * The upper layer software is responsible for calling this Reset function
  468. * and then re-configuring the device.
  469. *
  470. * @param instance_p is a pointer to the instance to be worked on.
  471. *
  472. */
  473. static void FXmacReset(FXmac *instance_p)
  474. {
  475. u32 reg_val, write_reg = 0;
  476. u8 i;
  477. s8 mac_addr[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
  478. u32 rx_buf_num;
  479. FASSERT(instance_p != NULL);
  480. /* Stop the device and reset hardware */
  481. FXmacStop(instance_p);
  482. instance_p->moudle_id = (FXMAC_READREG32(instance_p->config.base_address, FXMAC_REVISION_REG_OFFSET) & FXMAC_IDENTIFICATION_MASK) >> 16;
  483. FXMAC_PRINT_I("instance_p->moudle_id is %d \r\n", instance_p->moudle_id);
  484. instance_p->max_mtu_size = FXMAC_MTU;
  485. instance_p->max_frame_size = FXMAC_MTU + FXMAC_HDR_SIZE + FXMAC_TRL_SIZE;
  486. FXMAC_WRITEREG32(instance_p->config.base_address,
  487. FXMAC_NWCTRL_OFFSET,
  488. ((FXMAC_NWCTRL_STATCLR_MASK) & (u32)(~FXMAC_NWCTRL_LOOPEN_MASK)) | FXMAC_NWCTRL_MDEN_MASK);
  489. write_reg = FXmacClkDivGet(instance_p); /* mdio clock division */
  490. write_reg |= FXmacDmaWidth(instance_p); /* 位宽 */
  491. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_NWCFG_OFFSET, write_reg);
  492. FXmacDmaReset(instance_p);
  493. /* This register, when read provides details of the status of the receive path. */
  494. FXMAC_WRITEREG32(instance_p->config.base_address,
  495. FXMAC_RXSR_OFFSET, FXMAC_SR_ALL_MASK);
  496. /* write 1 ro the relavant bit location disable that particular interrupt */
  497. FXMAC_WRITEREG32(instance_p->config.base_address,
  498. FXMAC_IDR_OFFSET, FXMAC_IXR_ALL_MASK);
  499. reg_val = FXMAC_READREG32(instance_p->config.base_address,
  500. FXMAC_ISR_OFFSET);
  501. FXMAC_WRITEREG32(instance_p->config.base_address, FXMAC_ISR_OFFSET,
  502. reg_val);
  503. FXMAC_WRITEREG32(instance_p->config.base_address,
  504. FXMAC_TXSR_OFFSET, FXMAC_SR_ALL_MASK);
  505. FXmacClearHash(instance_p);
  506. /* set default mac address */
  507. for (i = 0U; i < 4U; i++)
  508. {
  509. (void)FXmacSetMacAddress(instance_p, mac_addr, i);
  510. (void)FXmacGetMacAddress(instance_p, mac_addr, i);
  511. (void)FXmacSetTypeIdCheck(instance_p, 0x00000000U, i);
  512. }
  513. /* clear all counters */
  514. for (i = 0U; i < (u8)((FXMAC_LAST_OFFSET - FXMAC_OCTTXL_OFFSET) / 4U);
  515. i++)
  516. {
  517. (void)FXMAC_READREG32(instance_p->config.base_address,
  518. FXMAC_OCTTXL_OFFSET + (u32)(((u32)i) * ((u32)4)));
  519. }
  520. /* Sync default options with hardware but leave receiver and
  521. * transmitter disabled. They get enabled with FXmacStart() if
  522. * FXMAC_TRANSMITTER_ENABLE_OPTION and
  523. * FXMAC_RECEIVER_ENABLE_OPTION are set.
  524. */
  525. FXmacSetOptions(instance_p, instance_p->config.network_default_config & ~((u32)FXMAC_TRANSMITTER_ENABLE_OPTION | (u32)FXMAC_RECEIVER_ENABLE_OPTION), 0);
  526. FXmacClearOptions(instance_p, ~instance_p->config.network_default_config, 0);
  527. }
  528. /**
  529. * @name: FXmacInitInterface
  530. * @msg: Initialize the MAC controller configuration based on the PHY interface type
  531. * @note:
  532. * @param {FXmac} *instance_p is a pointer to the instance to be worked on.
  533. */
  534. void FXmacInitInterface(FXmac *instance_p)
  535. {
  536. u32 config, control;
  537. FXmacConfig *config_p;
  538. config_p = &instance_p->config;
  539. if (config_p->interface == FXMAC_PHY_INTERFACE_MODE_XGMII)
  540. {
  541. config = FXMAC_READREG32(config_p->base_address, FXMAC_NWCFG_OFFSET);
  542. config &= ~FXMAC_NWCFG_PCSSEL_MASK;
  543. FXMAC_WRITEREG32(config_p->base_address, FXMAC_NWCFG_OFFSET, config);
  544. control = FXMAC_READREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET);
  545. control |= FXMAC_NWCTRL_ENABLE_HS_MAC_MASK; /* Use high speed MAC */
  546. FXMAC_WRITEREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET, control);
  547. config_p->duplex = 1;
  548. }
  549. else if (config_p->interface == FXMAC_PHY_INTERFACE_MODE_USXGMII)
  550. {
  551. config = FXMAC_READREG32(config_p->base_address, FXMAC_NWCFG_OFFSET);
  552. config |= FXMAC_NWCFG_PCSSEL_MASK;
  553. FXMAC_WRITEREG32(config_p->base_address, FXMAC_NWCFG_OFFSET, config);
  554. control = FXMAC_READREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET);
  555. control |= FXMAC_NWCTRL_ENABLE_HS_MAC_MASK; /* Use high speed MAC */
  556. FXMAC_WRITEREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET, control);
  557. control = FXMAC_READREG32(config_p->base_address, FXMAC_GEM_USX_CONTROL_OFFSET);
  558. control &= ~(FXMAC_GEM_USX_TX_SCR_BYPASS | FXMAC_GEM_USX_RX_SCR_BYPASS);
  559. control |= FXMAC_GEM_USX_RX_SYNC_RESET;
  560. FXMAC_WRITEREG32(config_p->base_address, FXMAC_GEM_USX_CONTROL_OFFSET, control);
  561. control = FXMAC_READREG32(config_p->base_address, FXMAC_GEM_USX_CONTROL_OFFSET);
  562. control &= ~FXMAC_GEM_USX_RX_SYNC_RESET;
  563. control |= FXMAC_GEM_USX_TX_DATAPATH_EN;
  564. control |= FXMAC_GEM_USX_SIGNAL_OK;
  565. if (config_p->speed == FXMAC_SPEED_10000)
  566. {
  567. control |= FXMAC_GEM_USX_HS_MAC_SPEED_10G;
  568. }
  569. else if (config_p->speed == FXMAC_SPEED_25000)
  570. {
  571. control |= FXMAC_GEM_USX_HS_MAC_SPEED_2_5G;
  572. }
  573. else if (config_p->speed == FXMAC_SPEED_1000)
  574. {
  575. control |= FXMAC_GEM_USX_HS_MAC_SPEED_1G;
  576. }
  577. else if (config_p->speed == FXMAC_SPEED_100)
  578. {
  579. control |= FXMAC_GEM_USX_HS_MAC_SPEED_100M;
  580. }
  581. FXMAC_WRITEREG32(config_p->base_address, FXMAC_GEM_USX_CONTROL_OFFSET, control);
  582. config_p->duplex = 1;
  583. }
  584. else if (config_p->interface == FXMAC_PHY_INTERFACE_MODE_SGMII)
  585. {
  586. config = FXMAC_READREG32(config_p->base_address, FXMAC_NWCFG_OFFSET);
  587. config |= FXMAC_NWCFG_PCSSEL_MASK | FXMAC_NWCFG_SGMII_MODE_ENABLE_MASK;
  588. config &= ~(FXMAC_NWCFG_100_MASK | FXMAC_NWCFG_FDEN_MASK);
  589. if (instance_p->moudle_id >= 2)
  590. {
  591. config &= ~FXMAC_NWCFG_1000_MASK;
  592. }
  593. if (config_p->duplex)
  594. {
  595. config |= FXMAC_NWCFG_FDEN_MASK;
  596. }
  597. if (config_p->speed == FXMAC_SPEED_100)
  598. {
  599. config |= FXMAC_NWCFG_100_MASK;
  600. }
  601. else if (config_p->speed == FXMAC_SPEED_1000)
  602. {
  603. config |= FXMAC_NWCFG_1000_MASK;
  604. }
  605. FXMAC_WRITEREG32(config_p->base_address, FXMAC_NWCFG_OFFSET, config);
  606. if (config_p->speed == FXMAC_SPEED_2500)
  607. {
  608. control = FXMAC_READREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET);
  609. control |= FXMAC_NWCTRL_TWO_PT_FIVE_GIG_MASK;
  610. FXMAC_WRITEREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET, control);
  611. }
  612. else
  613. {
  614. control = FXMAC_READREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET);
  615. control &= ~FXMAC_NWCTRL_TWO_PT_FIVE_GIG_MASK;
  616. FXMAC_WRITEREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET, control);
  617. }
  618. control = FXMAC_READREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET);
  619. control &= ~FXMAC_NWCTRL_ENABLE_HS_MAC_MASK;
  620. FXMAC_WRITEREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET, control);
  621. control = FXMAC_READREG32(config_p->base_address, FXMAC_PCS_CONTROL_OFFSET);
  622. control |= FXMAC_PCS_CONTROL_ENABLE_AUTO_NEG;
  623. FXMAC_WRITEREG32(config_p->base_address, FXMAC_PCS_CONTROL_OFFSET, control);
  624. }
  625. else
  626. {
  627. config = FXMAC_READREG32(config_p->base_address, FXMAC_NWCFG_OFFSET);
  628. FXMAC_PRINT_I("select rgmii \r\n");
  629. config &= ~FXMAC_NWCFG_PCSSEL_MASK;
  630. config &= ~(FXMAC_NWCFG_100_MASK | FXMAC_NWCFG_FDEN_MASK);
  631. if (instance_p->moudle_id >= 2)
  632. {
  633. config &= ~FXMAC_NWCFG_1000_MASK;
  634. }
  635. if (config_p->duplex)
  636. {
  637. config |= FXMAC_NWCFG_FDEN_MASK;
  638. }
  639. if (config_p->speed == FXMAC_SPEED_100)
  640. {
  641. config |= FXMAC_NWCFG_100_MASK;
  642. }
  643. else if (config_p->speed == FXMAC_SPEED_1000)
  644. {
  645. config |= FXMAC_NWCFG_1000_MASK;
  646. }
  647. if (config_p->duplex)
  648. {
  649. config |= FXMAC_NWCFG_FDEN_MASK;
  650. }
  651. FXMAC_WRITEREG32(config_p->base_address, FXMAC_NWCFG_OFFSET, config);
  652. control = FXMAC_READREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET);
  653. control &= ~FXMAC_NWCTRL_ENABLE_HS_MAC_MASK; /* Use high speed MAC */
  654. FXMAC_WRITEREG32(config_p->base_address, FXMAC_NWCTRL_OFFSET, control);
  655. }
  656. }
  657. static void FXmacIrqStubHandler(void)
  658. {
  659. FASSERT_MSG(0, "Please register the interrupt callback function");
  660. }
  661. /**
  662. * @name: FXmacCfgInitialize
  663. * @msg: Initialize a specific fxmac instance/driver.
  664. * @note:
  665. * @param {FXmac} *instance_p is a pointer to the instance to be worked on.
  666. * @param {FXmacConfig} *config_p is the device configuration structure containing required
  667. * hardware build data.
  668. * @return {FT_SUCCESS} if initialization was successful
  669. */
  670. FError FXmacCfgInitialize(FXmac *instance_p, const FXmacConfig *config_p)
  671. {
  672. /* Verify arguments */
  673. FASSERT(instance_p != NULL);
  674. FASSERT(config_p != NULL);
  675. instance_p->config = *config_p;
  676. instance_p->link_status = FXMAC_LINKDOWN;
  677. /* Reset the hardware and set default options */
  678. instance_p->is_ready = FT_COMPONENT_IS_READY;
  679. FXmacReset(instance_p);
  680. instance_p->send_irq_handler = (FXmacIrqHandler)FXmacIrqStubHandler;
  681. instance_p->send_args = NULL;
  682. instance_p->recv_irq_handler = (FXmacIrqHandler)FXmacIrqStubHandler;
  683. instance_p->recv_args = NULL;
  684. instance_p->error_irq_handler = (FXmacErrorIrqHandler)FXmacIrqStubHandler;
  685. instance_p->error_args = NULL;
  686. instance_p->link_change_handler = (FXmacIrqHandler)FXmacIrqStubHandler;
  687. instance_p->link_change_args = NULL;
  688. instance_p->restart_handler = (FXmacIrqHandler)FXmacIrqStubHandler;
  689. instance_p->restart_args = NULL;
  690. return FT_SUCCESS;
  691. }
  692. /**
  693. * This function sets the start address of the transmit/receive buffer queue.
  694. *
  695. * @param instance_p is a pointer to the instance to be worked on.
  696. * @param queue_p is the address of the Queue to be written
  697. * @param queue_num is the Buffer Queue Index
  698. * @param direction indicates Transmit/Receive
  699. *
  700. * @note
  701. * The buffer queue addresses has to be set before starting the transfer, so
  702. * this function has to be called in prior to FXmacStart()
  703. *
  704. */
  705. void FXmacSetQueuePtr(FXmac *instance_p, uintptr queue_p, u8 queue_num,
  706. u32 direction)
  707. {
  708. /* Assert bad arguments and conditions */
  709. FASSERT(instance_p != NULL);
  710. FASSERT(instance_p->is_ready == (u32)FT_COMPONENT_IS_READY);
  711. /* If already started, then there is nothing to do */
  712. if (instance_p->is_started == (u32)FT_COMPONENT_IS_STARTED)
  713. {
  714. return;
  715. }
  716. if (queue_num == 0x00U)
  717. {
  718. if (direction == FXMAC_SEND)
  719. {
  720. /* set base start address of TX buffer queue (tx buffer descriptor list) */
  721. FXMAC_WRITEREG32(instance_p->config.base_address,
  722. FXMAC_TXQBASE_OFFSET,
  723. (queue_p & ULONG64_LO_MASK) | (((queue_p == (uintptr)0)) ? 1 : 0));
  724. }
  725. else
  726. {
  727. /* set base start address of RX buffer queue (rx buffer descriptor list) */
  728. FXMAC_WRITEREG32(instance_p->config.base_address,
  729. FXMAC_RXQBASE_OFFSET,
  730. (queue_p & ULONG64_LO_MASK) | (((queue_p == (uintptr)0)) ? 1 : 0));
  731. }
  732. }
  733. else
  734. {
  735. if (direction == FXMAC_SEND)
  736. {
  737. FXMAC_WRITEREG32(instance_p->config.base_address,
  738. FXMAC_QUEUE_REGISTER_OFFSET(FXMAC_TXQ1BASE_OFFSET, queue_num),
  739. (queue_p & ULONG64_LO_MASK) | (((queue_p == (uintptr)0)) ? 1 : 0));
  740. }
  741. else
  742. {
  743. FXMAC_WRITEREG32(instance_p->config.base_address,
  744. FXMAC_QUEUE_REGISTER_OFFSET(FXMAC_TXQ1BASE_OFFSET, queue_num),
  745. (queue_p & ULONG64_LO_MASK) | (((queue_p == (uintptr)0)) ? 1 : 0));
  746. }
  747. }
  748. #ifdef __aarch64__
  749. if (direction == FXMAC_SEND)
  750. {
  751. /* Set the MSB of TX Queue start address */
  752. FXMAC_WRITEREG32(instance_p->config.base_address,
  753. FXMAC_MSBBUF_TXQBASE_OFFSET,
  754. (u32)((queue_p & ULONG64_HI_MASK) >> 32U));
  755. }
  756. else
  757. {
  758. /* Set the MSB of RX Queue start address */
  759. FXMAC_WRITEREG32(instance_p->config.base_address,
  760. FXMAC_MSBBUF_RXQBASE_OFFSET,
  761. (u32)((queue_p & ULONG64_HI_MASK) >> 32U));
  762. }
  763. #endif
  764. }