737-net-ethernet-mtk_eth_soc-add-paths-and-SerDes-modes-.patch 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. From 91bda2f441f9e37273922028ffc48ce8e91bf5bd Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Tue, 12 Dec 2023 03:51:14 +0000
  4. Subject: [PATCH] net: ethernet: mtk_eth_soc: add paths and SerDes modes for
  5. MT7988
  6. MT7988 comes with a built-in 2.5G PHY as well as SerDes lanes to
  7. connect external PHYs or transceivers in USXGMII, 10GBase-R, 5GBase-R,
  8. 2500Base-X, 1000Base-X and Cisco SGMII interface modes.
  9. Implement support for configuring for the new paths to SerDes interfaces
  10. and the internal 2.5G PHY.
  11. Add USXGMII PCS driver for 10GBase-R, 5GBase-R and USXGMII mode, and
  12. setup the new PHYA on MT7988 to access the also still existing old
  13. LynxI PCS for 1000Base-X, 2500Base-X and Cisco SGMII PCS interface
  14. modes.
  15. Signed-off-by: Daniel Golle <[email protected]>
  16. ---
  17. drivers/net/ethernet/mediatek/mtk_eth_path.c | 122 +++++++-
  18. drivers/net/ethernet/mediatek/mtk_eth_soc.c | 291 +++++++++++++++++--
  19. drivers/net/ethernet/mediatek/mtk_eth_soc.h | 107 ++++++-
  20. 3 files changed, 469 insertions(+), 51 deletions(-)
  21. --- a/drivers/net/ethernet/mediatek/mtk_eth_path.c
  22. +++ b/drivers/net/ethernet/mediatek/mtk_eth_path.c
  23. @@ -31,10 +31,20 @@ static const char *mtk_eth_path_name(u64
  24. return "gmac2_rgmii";
  25. case MTK_ETH_PATH_GMAC2_SGMII:
  26. return "gmac2_sgmii";
  27. + case MTK_ETH_PATH_GMAC2_2P5GPHY:
  28. + return "gmac2_2p5gphy";
  29. case MTK_ETH_PATH_GMAC2_GEPHY:
  30. return "gmac2_gephy";
  31. + case MTK_ETH_PATH_GMAC3_SGMII:
  32. + return "gmac3_sgmii";
  33. case MTK_ETH_PATH_GDM1_ESW:
  34. return "gdm1_esw";
  35. + case MTK_ETH_PATH_GMAC1_USXGMII:
  36. + return "gmac1_usxgmii";
  37. + case MTK_ETH_PATH_GMAC2_USXGMII:
  38. + return "gmac2_usxgmii";
  39. + case MTK_ETH_PATH_GMAC3_USXGMII:
  40. + return "gmac3_usxgmii";
  41. default:
  42. return "unknown path";
  43. }
  44. @@ -127,6 +137,27 @@ static int set_mux_u3_gmac2_to_qphy(stru
  45. return 0;
  46. }
  47. +static int set_mux_gmac2_to_2p5gphy(struct mtk_eth *eth, u64 path)
  48. +{
  49. + int ret;
  50. +
  51. + if (path == MTK_ETH_PATH_GMAC2_2P5GPHY) {
  52. + ret = regmap_clear_bits(eth->ethsys, ETHSYS_SYSCFG0, SYSCFG0_SGMII_GMAC2_V2);
  53. + if (ret)
  54. + return ret;
  55. +
  56. + /* Setup mux to 2p5g PHY */
  57. + ret = regmap_clear_bits(eth->infra, TOP_MISC_NETSYS_PCS_MUX, MUX_G2_USXGMII_SEL);
  58. + if (ret)
  59. + return ret;
  60. +
  61. + dev_dbg(eth->dev, "path %s in %s updated\n",
  62. + mtk_eth_path_name(path), __func__);
  63. + }
  64. +
  65. + return 0;
  66. +}
  67. +
  68. static int set_mux_gmac1_gmac2_to_sgmii_rgmii(struct mtk_eth *eth, u64 path)
  69. {
  70. unsigned int val = 0;
  71. @@ -165,7 +196,48 @@ static int set_mux_gmac1_gmac2_to_sgmii_
  72. return 0;
  73. }
  74. -static int set_mux_gmac12_to_gephy_sgmii(struct mtk_eth *eth, u64 path)
  75. +static int set_mux_gmac123_to_usxgmii(struct mtk_eth *eth, u64 path)
  76. +{
  77. + unsigned int val = 0;
  78. + bool updated = true;
  79. + int mac_id = 0;
  80. +
  81. + /* Disable SYSCFG1 SGMII */
  82. + regmap_read(eth->ethsys, ETHSYS_SYSCFG0, &val);
  83. +
  84. + switch (path) {
  85. + case MTK_ETH_PATH_GMAC1_USXGMII:
  86. + val &= ~(u32)SYSCFG0_SGMII_GMAC1_V2;
  87. + mac_id = MTK_GMAC1_ID;
  88. + break;
  89. + case MTK_ETH_PATH_GMAC2_USXGMII:
  90. + val &= ~(u32)SYSCFG0_SGMII_GMAC2_V2;
  91. + mac_id = MTK_GMAC2_ID;
  92. + break;
  93. + case MTK_ETH_PATH_GMAC3_USXGMII:
  94. + val &= ~(u32)SYSCFG0_SGMII_GMAC3_V2;
  95. + mac_id = MTK_GMAC3_ID;
  96. + break;
  97. + default:
  98. + updated = false;
  99. + };
  100. +
  101. + if (updated) {
  102. + regmap_update_bits(eth->ethsys, ETHSYS_SYSCFG0,
  103. + SYSCFG0_SGMII_MASK, val);
  104. +
  105. + if (mac_id == MTK_GMAC2_ID)
  106. + regmap_set_bits(eth->infra, TOP_MISC_NETSYS_PCS_MUX,
  107. + MUX_G2_USXGMII_SEL);
  108. + }
  109. +
  110. + dev_dbg(eth->dev, "path %s in %s updated = %d\n",
  111. + mtk_eth_path_name(path), __func__, updated);
  112. +
  113. + return 0;
  114. +}
  115. +
  116. +static int set_mux_gmac123_to_gephy_sgmii(struct mtk_eth *eth, u64 path)
  117. {
  118. unsigned int val = 0;
  119. bool updated = true;
  120. @@ -182,6 +254,9 @@ static int set_mux_gmac12_to_gephy_sgmii
  121. case MTK_ETH_PATH_GMAC2_SGMII:
  122. val |= SYSCFG0_SGMII_GMAC2_V2;
  123. break;
  124. + case MTK_ETH_PATH_GMAC3_SGMII:
  125. + val |= SYSCFG0_SGMII_GMAC3_V2;
  126. + break;
  127. default:
  128. updated = false;
  129. }
  130. @@ -210,13 +285,25 @@ static const struct mtk_eth_muxc mtk_eth
  131. .cap_bit = MTK_ETH_MUX_U3_GMAC2_TO_QPHY,
  132. .set_path = set_mux_u3_gmac2_to_qphy,
  133. }, {
  134. + .name = "mux_gmac2_to_2p5gphy",
  135. + .cap_bit = MTK_ETH_MUX_GMAC2_TO_2P5GPHY,
  136. + .set_path = set_mux_gmac2_to_2p5gphy,
  137. + }, {
  138. .name = "mux_gmac1_gmac2_to_sgmii_rgmii",
  139. .cap_bit = MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII,
  140. .set_path = set_mux_gmac1_gmac2_to_sgmii_rgmii,
  141. }, {
  142. .name = "mux_gmac12_to_gephy_sgmii",
  143. .cap_bit = MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII,
  144. - .set_path = set_mux_gmac12_to_gephy_sgmii,
  145. + .set_path = set_mux_gmac123_to_gephy_sgmii,
  146. + }, {
  147. + .name = "mux_gmac123_to_gephy_sgmii",
  148. + .cap_bit = MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII,
  149. + .set_path = set_mux_gmac123_to_gephy_sgmii,
  150. + }, {
  151. + .name = "mux_gmac123_to_usxgmii",
  152. + .cap_bit = MTK_ETH_MUX_GMAC123_TO_USXGMII,
  153. + .set_path = set_mux_gmac123_to_usxgmii,
  154. },
  155. };
  156. @@ -249,12 +336,39 @@ out:
  157. return err;
  158. }
  159. +int mtk_gmac_usxgmii_path_setup(struct mtk_eth *eth, int mac_id)
  160. +{
  161. + u64 path;
  162. +
  163. + path = (mac_id == MTK_GMAC1_ID) ? MTK_ETH_PATH_GMAC1_USXGMII :
  164. + (mac_id == MTK_GMAC2_ID) ? MTK_ETH_PATH_GMAC2_USXGMII :
  165. + MTK_ETH_PATH_GMAC3_USXGMII;
  166. +
  167. + /* Setup proper MUXes along the path */
  168. + return mtk_eth_mux_setup(eth, path);
  169. +}
  170. +
  171. int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id)
  172. {
  173. u64 path;
  174. - path = (mac_id == 0) ? MTK_ETH_PATH_GMAC1_SGMII :
  175. - MTK_ETH_PATH_GMAC2_SGMII;
  176. + path = (mac_id == MTK_GMAC1_ID) ? MTK_ETH_PATH_GMAC1_SGMII :
  177. + (mac_id == MTK_GMAC2_ID) ? MTK_ETH_PATH_GMAC2_SGMII :
  178. + MTK_ETH_PATH_GMAC3_SGMII;
  179. +
  180. + /* Setup proper MUXes along the path */
  181. + return mtk_eth_mux_setup(eth, path);
  182. +}
  183. +
  184. +int mtk_gmac_2p5gphy_path_setup(struct mtk_eth *eth, int mac_id)
  185. +{
  186. + u64 path = 0;
  187. +
  188. + if (mac_id == MTK_GMAC2_ID)
  189. + path = MTK_ETH_PATH_GMAC2_2P5GPHY;
  190. +
  191. + if (!path)
  192. + return -EINVAL;
  193. /* Setup proper MUXes along the path */
  194. return mtk_eth_mux_setup(eth, path);
  195. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  196. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  197. @@ -21,6 +21,8 @@
  198. #include <linux/pinctrl/devinfo.h>
  199. #include <linux/phylink.h>
  200. #include <linux/pcs/pcs-mtk-lynxi.h>
  201. +#include <linux/pcs/pcs-mtk-usxgmii.h>
  202. +#include <linux/phy/phy.h>
  203. #include <linux/jhash.h>
  204. #include <linux/bitfield.h>
  205. #include <net/dsa.h>
  206. @@ -258,12 +260,8 @@ static const char * const mtk_clks_sourc
  207. "ethwarp_wocpu2",
  208. "ethwarp_wocpu1",
  209. "ethwarp_wocpu0",
  210. - "top_usxgmii0_sel",
  211. - "top_usxgmii1_sel",
  212. "top_sgm0_sel",
  213. "top_sgm1_sel",
  214. - "top_xfi_phy0_xtal_sel",
  215. - "top_xfi_phy1_xtal_sel",
  216. "top_eth_gmii_sel",
  217. "top_eth_refck_50m_sel",
  218. "top_eth_sys_200m_sel",
  219. @@ -475,6 +473,30 @@ static void mtk_setup_bridge_switch(stru
  220. MTK_GSW_CFG);
  221. }
  222. +static bool mtk_check_gmac23_idle(struct mtk_mac *mac)
  223. +{
  224. + u32 mac_fsm, gdm_fsm;
  225. +
  226. + mac_fsm = mtk_r32(mac->hw, MTK_MAC_FSM(mac->id));
  227. +
  228. + switch (mac->id) {
  229. + case MTK_GMAC2_ID:
  230. + gdm_fsm = mtk_r32(mac->hw, MTK_FE_GDM2_FSM);
  231. + break;
  232. + case MTK_GMAC3_ID:
  233. + gdm_fsm = mtk_r32(mac->hw, MTK_FE_GDM3_FSM);
  234. + break;
  235. + default:
  236. + return true;
  237. + };
  238. +
  239. + if ((mac_fsm & 0xFFFF0000) == 0x01010000 &&
  240. + (gdm_fsm & 0xFFFF0000) == 0x00000000)
  241. + return true;
  242. +
  243. + return false;
  244. +}
  245. +
  246. static struct phylink_pcs *mtk_mac_select_pcs(struct phylink_config *config,
  247. phy_interface_t interface)
  248. {
  249. @@ -483,6 +505,21 @@ static struct phylink_pcs *mtk_mac_selec
  250. struct mtk_eth *eth = mac->hw;
  251. unsigned int sid;
  252. + if (mtk_is_netsys_v3_or_greater(eth)) {
  253. + switch (interface) {
  254. + case PHY_INTERFACE_MODE_1000BASEX:
  255. + case PHY_INTERFACE_MODE_2500BASEX:
  256. + case PHY_INTERFACE_MODE_SGMII:
  257. + return mac->sgmii_pcs;
  258. + case PHY_INTERFACE_MODE_5GBASER:
  259. + case PHY_INTERFACE_MODE_10GBASER:
  260. + case PHY_INTERFACE_MODE_USXGMII:
  261. + return mac->usxgmii_pcs;
  262. + default:
  263. + return NULL;
  264. + }
  265. + }
  266. +
  267. if (interface == PHY_INTERFACE_MODE_SGMII ||
  268. phy_interface_mode_is_8023z(interface)) {
  269. sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ?
  270. @@ -544,7 +581,22 @@ static void mtk_mac_config(struct phylin
  271. goto init_err;
  272. }
  273. break;
  274. + case PHY_INTERFACE_MODE_USXGMII:
  275. + case PHY_INTERFACE_MODE_10GBASER:
  276. + case PHY_INTERFACE_MODE_5GBASER:
  277. + if (MTK_HAS_CAPS(eth->soc->caps, MTK_USXGMII)) {
  278. + err = mtk_gmac_usxgmii_path_setup(eth, mac->id);
  279. + if (err)
  280. + goto init_err;
  281. + }
  282. + break;
  283. case PHY_INTERFACE_MODE_INTERNAL:
  284. + if (mac->id == MTK_GMAC2_ID &&
  285. + MTK_HAS_CAPS(eth->soc->caps, MTK_2P5GPHY)) {
  286. + err = mtk_gmac_2p5gphy_path_setup(eth, mac->id);
  287. + if (err)
  288. + goto init_err;
  289. + }
  290. break;
  291. default:
  292. goto err_phy;
  293. @@ -599,8 +651,6 @@ static void mtk_mac_config(struct phylin
  294. val &= ~SYSCFG0_GE_MODE(SYSCFG0_GE_MASK, mac->id);
  295. val |= SYSCFG0_GE_MODE(ge_mode, mac->id);
  296. regmap_write(eth->ethsys, ETHSYS_SYSCFG0, val);
  297. -
  298. - mac->interface = state->interface;
  299. }
  300. /* SGMII */
  301. @@ -617,21 +667,40 @@ static void mtk_mac_config(struct phylin
  302. /* Save the syscfg0 value for mac_finish */
  303. mac->syscfg0 = val;
  304. - } else if (phylink_autoneg_inband(mode)) {
  305. + } else if (state->interface != PHY_INTERFACE_MODE_USXGMII &&
  306. + state->interface != PHY_INTERFACE_MODE_10GBASER &&
  307. + state->interface != PHY_INTERFACE_MODE_5GBASER &&
  308. + phylink_autoneg_inband(mode)) {
  309. dev_err(eth->dev,
  310. - "In-band mode not supported in non SGMII mode!\n");
  311. + "In-band mode not supported in non-SerDes modes!\n");
  312. return;
  313. }
  314. /* Setup gmac */
  315. - if (mtk_is_netsys_v3_or_greater(eth) &&
  316. - mac->interface == PHY_INTERFACE_MODE_INTERNAL) {
  317. - mtk_w32(mac->hw, MTK_GDMA_XGDM_SEL, MTK_GDMA_EG_CTRL(mac->id));
  318. - mtk_w32(mac->hw, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(mac->id));
  319. + if (mtk_is_netsys_v3_or_greater(eth)) {
  320. + if (mtk_interface_mode_is_xgmii(state->interface)) {
  321. + mtk_w32(mac->hw, MTK_GDMA_XGDM_SEL, MTK_GDMA_EG_CTRL(mac->id));
  322. + mtk_w32(mac->hw, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(mac->id));
  323. +
  324. + if (mac->id == MTK_GMAC1_ID)
  325. + mtk_setup_bridge_switch(eth);
  326. + } else {
  327. + mtk_w32(eth, 0, MTK_GDMA_EG_CTRL(mac->id));
  328. - mtk_setup_bridge_switch(eth);
  329. + /* FIXME: In current hardware design, we have to reset FE
  330. + * when swtiching XGDM to GDM. Therefore, here trigger an SER
  331. + * to let GDM go back to the initial state.
  332. + */
  333. + if ((mtk_interface_mode_is_xgmii(mac->interface) ||
  334. + mac->interface == PHY_INTERFACE_MODE_NA) &&
  335. + !mtk_check_gmac23_idle(mac) &&
  336. + !test_bit(MTK_RESETTING, &eth->state))
  337. + schedule_work(&eth->pending_work);
  338. + }
  339. }
  340. + mac->interface = state->interface;
  341. +
  342. return;
  343. err_phy:
  344. @@ -644,6 +713,18 @@ init_err:
  345. mac->id, phy_modes(state->interface), err);
  346. }
  347. +static int mtk_mac_prepare(struct phylink_config *config, unsigned int mode,
  348. + phy_interface_t interface)
  349. +{
  350. + struct mtk_mac *mac = container_of(config, struct mtk_mac,
  351. + phylink_config);
  352. +
  353. + if (mac->pextp && mac->interface != interface)
  354. + phy_reset(mac->pextp);
  355. +
  356. + return 0;
  357. +}
  358. +
  359. static int mtk_mac_finish(struct phylink_config *config, unsigned int mode,
  360. phy_interface_t interface)
  361. {
  362. @@ -652,6 +733,10 @@ static int mtk_mac_finish(struct phylink
  363. struct mtk_eth *eth = mac->hw;
  364. u32 mcr_cur, mcr_new;
  365. + /* Setup PMA/PMD */
  366. + if (mac->pextp)
  367. + phy_set_mode_ext(mac->pextp, PHY_MODE_ETHERNET, interface);
  368. +
  369. /* Enable SGMII */
  370. if (interface == PHY_INTERFACE_MODE_SGMII ||
  371. phy_interface_mode_is_8023z(interface))
  372. @@ -677,10 +762,13 @@ static void mtk_mac_link_down(struct phy
  373. {
  374. struct mtk_mac *mac = container_of(config, struct mtk_mac,
  375. phylink_config);
  376. - u32 mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
  377. - mcr &= ~(MAC_MCR_TX_EN | MAC_MCR_RX_EN);
  378. - mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
  379. + if (!mtk_interface_mode_is_xgmii(interface)) {
  380. + mtk_m32(mac->hw, MAC_MCR_TX_EN | MAC_MCR_RX_EN, 0, MTK_MAC_MCR(mac->id));
  381. + mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id), 0, MTK_XGMAC_STS(mac->id));
  382. + } else if (mac->id != MTK_GMAC1_ID) {
  383. + mtk_m32(mac->hw, XMAC_MCR_TRX_DISABLE, XMAC_MCR_TRX_DISABLE, MTK_XMAC_MCR(mac->id));
  384. + }
  385. }
  386. static void mtk_set_queue_speed(struct mtk_eth *eth, unsigned int idx,
  387. @@ -752,13 +840,11 @@ static void mtk_set_queue_speed(struct m
  388. mtk_w32(eth, val, soc->reg_map->qdma.qtx_sch + ofs);
  389. }
  390. -static void mtk_mac_link_up(struct phylink_config *config,
  391. - struct phy_device *phy,
  392. - unsigned int mode, phy_interface_t interface,
  393. - int speed, int duplex, bool tx_pause, bool rx_pause)
  394. +static void mtk_gdm_mac_link_up(struct mtk_mac *mac,
  395. + struct phy_device *phy,
  396. + unsigned int mode, phy_interface_t interface,
  397. + int speed, int duplex, bool tx_pause, bool rx_pause)
  398. {
  399. - struct mtk_mac *mac = container_of(config, struct mtk_mac,
  400. - phylink_config);
  401. u32 mcr;
  402. mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
  403. @@ -792,9 +878,63 @@ static void mtk_mac_link_up(struct phyli
  404. mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
  405. }
  406. +static void mtk_xgdm_mac_link_up(struct mtk_mac *mac,
  407. + struct phy_device *phy,
  408. + unsigned int mode, phy_interface_t interface,
  409. + int speed, int duplex, bool tx_pause, bool rx_pause)
  410. +{
  411. + u32 mcr, force_link = 0;
  412. +
  413. + if (mac->id == MTK_GMAC1_ID)
  414. + return;
  415. +
  416. + /* Eliminate the interference(before link-up) caused by PHY noise */
  417. + mtk_m32(mac->hw, XMAC_LOGIC_RST, 0, MTK_XMAC_LOGIC_RST(mac->id));
  418. + mdelay(20);
  419. + mtk_m32(mac->hw, XMAC_GLB_CNTCLR, XMAC_GLB_CNTCLR, MTK_XMAC_CNT_CTRL(mac->id));
  420. +
  421. + if (mac->interface == PHY_INTERFACE_MODE_INTERNAL || mac->id == MTK_GMAC3_ID)
  422. + force_link = MTK_XGMAC_FORCE_LINK(mac->id);
  423. +
  424. + mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id), force_link, MTK_XGMAC_STS(mac->id));
  425. +
  426. + mcr = mtk_r32(mac->hw, MTK_XMAC_MCR(mac->id));
  427. + mcr &= ~(XMAC_MCR_FORCE_TX_FC | XMAC_MCR_FORCE_RX_FC | XMAC_MCR_TRX_DISABLE);
  428. + /* Configure pause modes -
  429. + * phylink will avoid these for half duplex
  430. + */
  431. + if (tx_pause)
  432. + mcr |= XMAC_MCR_FORCE_TX_FC;
  433. + if (rx_pause)
  434. + mcr |= XMAC_MCR_FORCE_RX_FC;
  435. +
  436. + mtk_w32(mac->hw, mcr, MTK_XMAC_MCR(mac->id));
  437. +}
  438. +
  439. +static void mtk_mac_link_up(struct phylink_config *config,
  440. + struct phy_device *phy,
  441. + unsigned int mode, phy_interface_t interface,
  442. + int speed, int duplex, bool tx_pause, bool rx_pause)
  443. +{
  444. + struct mtk_mac *mac = container_of(config, struct mtk_mac,
  445. + phylink_config);
  446. +
  447. + if (mtk_interface_mode_is_xgmii(interface))
  448. + mtk_xgdm_mac_link_up(mac, phy, mode, interface, speed, duplex,
  449. + tx_pause, rx_pause);
  450. + else
  451. + mtk_gdm_mac_link_up(mac, phy, mode, interface, speed, duplex,
  452. + tx_pause, rx_pause);
  453. +
  454. + /* Repeat pextp setup to tune link */
  455. + if (mac->pextp)
  456. + phy_set_mode_ext(mac->pextp, PHY_MODE_ETHERNET, interface);
  457. +}
  458. +
  459. static const struct phylink_mac_ops mtk_phylink_ops = {
  460. .mac_select_pcs = mtk_mac_select_pcs,
  461. .mac_config = mtk_mac_config,
  462. + .mac_prepare = mtk_mac_prepare,
  463. .mac_finish = mtk_mac_finish,
  464. .mac_link_down = mtk_mac_link_down,
  465. .mac_link_up = mtk_mac_link_up,
  466. @@ -3373,6 +3513,9 @@ static int mtk_open(struct net_device *d
  467. struct mtk_eth *eth = mac->hw;
  468. int i, err;
  469. + if (mac->pextp)
  470. + phy_power_on(mac->pextp);
  471. +
  472. err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
  473. if (err) {
  474. netdev_err(dev, "%s: could not attach PHY: %d\n", __func__,
  475. @@ -3501,6 +3644,9 @@ static int mtk_stop(struct net_device *d
  476. for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
  477. mtk_ppe_stop(eth->ppe[i]);
  478. + if (mac->pextp)
  479. + phy_power_off(mac->pextp);
  480. +
  481. return 0;
  482. }
  483. @@ -4498,6 +4644,7 @@ static const struct net_device_ops mtk_n
  484. static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
  485. {
  486. const __be32 *_id = of_get_property(np, "reg", NULL);
  487. + struct device_node *pcs_np;
  488. phy_interface_t phy_mode;
  489. struct phylink *phylink;
  490. struct mtk_mac *mac;
  491. @@ -4533,16 +4680,41 @@ static int mtk_add_mac(struct mtk_eth *e
  492. mac->id = id;
  493. mac->hw = eth;
  494. mac->of_node = np;
  495. + pcs_np = of_parse_phandle(mac->of_node, "pcs-handle", 0);
  496. + if (pcs_np) {
  497. + mac->sgmii_pcs = mtk_pcs_lynxi_get(eth->dev, pcs_np);
  498. + if (IS_ERR(mac->sgmii_pcs)) {
  499. + if (PTR_ERR(mac->sgmii_pcs) == -EPROBE_DEFER)
  500. + return -EPROBE_DEFER;
  501. - err = of_get_ethdev_address(mac->of_node, eth->netdev[id]);
  502. - if (err == -EPROBE_DEFER)
  503. - return err;
  504. + dev_err(eth->dev, "cannot select SGMII PCS, error %ld\n",
  505. + PTR_ERR(mac->sgmii_pcs));
  506. + return PTR_ERR(mac->sgmii_pcs);
  507. + }
  508. + }
  509. - if (err) {
  510. - /* If the mac address is invalid, use random mac address */
  511. - eth_hw_addr_random(eth->netdev[id]);
  512. - dev_err(eth->dev, "generated random MAC address %pM\n",
  513. - eth->netdev[id]->dev_addr);
  514. + pcs_np = of_parse_phandle(mac->of_node, "pcs-handle", 1);
  515. + if (pcs_np) {
  516. + mac->usxgmii_pcs = mtk_usxgmii_pcs_get(eth->dev, pcs_np);
  517. + if (IS_ERR(mac->usxgmii_pcs)) {
  518. + if (PTR_ERR(mac->usxgmii_pcs) == -EPROBE_DEFER)
  519. + return -EPROBE_DEFER;
  520. +
  521. + dev_err(eth->dev, "cannot select USXGMII PCS, error %ld\n",
  522. + PTR_ERR(mac->usxgmii_pcs));
  523. + return PTR_ERR(mac->usxgmii_pcs);
  524. + }
  525. + }
  526. +
  527. + if (mtk_is_netsys_v3_or_greater(eth) && (mac->sgmii_pcs || mac->usxgmii_pcs)) {
  528. + mac->pextp = devm_of_phy_get(eth->dev, mac->of_node, NULL);
  529. + if (IS_ERR(mac->pextp)) {
  530. + if (PTR_ERR(mac->pextp) != -EPROBE_DEFER)
  531. + dev_err(eth->dev, "cannot get PHY, error %ld\n",
  532. + PTR_ERR(mac->pextp));
  533. +
  534. + return PTR_ERR(mac->pextp);
  535. + }
  536. }
  537. memset(mac->hwlro_ip, 0, sizeof(mac->hwlro_ip));
  538. @@ -4616,8 +4788,21 @@ static int mtk_add_mac(struct mtk_eth *e
  539. phy_interface_zero(mac->phylink_config.supported_interfaces);
  540. __set_bit(PHY_INTERFACE_MODE_INTERNAL,
  541. mac->phylink_config.supported_interfaces);
  542. + } else if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_USXGMII)) {
  543. + mac->phylink_config.mac_capabilities |= MAC_5000FD | MAC_10000FD;
  544. + __set_bit(PHY_INTERFACE_MODE_5GBASER,
  545. + mac->phylink_config.supported_interfaces);
  546. + __set_bit(PHY_INTERFACE_MODE_10GBASER,
  547. + mac->phylink_config.supported_interfaces);
  548. + __set_bit(PHY_INTERFACE_MODE_USXGMII,
  549. + mac->phylink_config.supported_interfaces);
  550. }
  551. + if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_2P5GPHY) &&
  552. + id == MTK_GMAC2_ID)
  553. + __set_bit(PHY_INTERFACE_MODE_INTERNAL,
  554. + mac->phylink_config.supported_interfaces);
  555. +
  556. phylink = phylink_create(&mac->phylink_config,
  557. of_fwnode_handle(mac->of_node),
  558. phy_mode, &mtk_phylink_ops);
  559. @@ -4662,6 +4847,26 @@ free_netdev:
  560. return err;
  561. }
  562. +static int mtk_mac_assign_address(struct mtk_eth *eth, int i, bool test_defer_only)
  563. +{
  564. + int err = of_get_ethdev_address(eth->mac[i]->of_node, eth->netdev[i]);
  565. +
  566. + if (err == -EPROBE_DEFER)
  567. + return err;
  568. +
  569. + if (test_defer_only)
  570. + return 0;
  571. +
  572. + if (err) {
  573. + /* If the mac address is invalid, use random mac address */
  574. + eth_hw_addr_random(eth->netdev[i]);
  575. + dev_err(eth->dev, "generated random MAC address %pM\n",
  576. + eth->netdev[i]);
  577. + }
  578. +
  579. + return 0;
  580. +}
  581. +
  582. void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev)
  583. {
  584. struct net_device *dev, *tmp;
  585. @@ -4805,7 +5010,8 @@ static int mtk_probe(struct platform_dev
  586. regmap_write(cci, 0, 3);
  587. }
  588. - if (MTK_HAS_CAPS(eth->soc->caps, MTK_SGMII)) {
  589. + if (MTK_HAS_CAPS(eth->soc->caps, MTK_SGMII) &&
  590. + !mtk_is_netsys_v3_or_greater(eth)) {
  591. err = mtk_sgmii_init(eth);
  592. if (err)
  593. @@ -4916,6 +5122,24 @@ static int mtk_probe(struct platform_dev
  594. }
  595. }
  596. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  597. + if (!eth->netdev[i])
  598. + continue;
  599. +
  600. + err = mtk_mac_assign_address(eth, i, true);
  601. + if (err)
  602. + goto err_deinit_hw;
  603. + }
  604. +
  605. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  606. + if (!eth->netdev[i])
  607. + continue;
  608. +
  609. + err = mtk_mac_assign_address(eth, i, false);
  610. + if (err)
  611. + goto err_deinit_hw;
  612. + }
  613. +
  614. if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT)) {
  615. err = devm_request_irq(eth->dev, eth->irq[0],
  616. mtk_handle_irq, 0,
  617. @@ -5018,6 +5242,11 @@ static int mtk_remove(struct platform_de
  618. mtk_stop(eth->netdev[i]);
  619. mac = netdev_priv(eth->netdev[i]);
  620. phylink_disconnect_phy(mac->phylink);
  621. + if (mac->sgmii_pcs)
  622. + mtk_pcs_lynxi_put(mac->sgmii_pcs);
  623. +
  624. + if (mac->usxgmii_pcs)
  625. + mtk_usxgmii_pcs_put(mac->usxgmii_pcs);
  626. }
  627. mtk_wed_exit();
  628. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  629. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  630. @@ -15,6 +15,7 @@
  631. #include <linux/u64_stats_sync.h>
  632. #include <linux/refcount.h>
  633. #include <linux/phylink.h>
  634. +#include <linux/reset.h>
  635. #include <linux/rhashtable.h>
  636. #include <linux/dim.h>
  637. #include <linux/bitfield.h>
  638. @@ -502,6 +503,21 @@
  639. #define INTF_MODE_RGMII_1000 (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED)
  640. #define INTF_MODE_RGMII_10_100 0
  641. +/* XFI Mac control registers */
  642. +#define MTK_XMAC_BASE(x) (0x12000 + (((x) - 1) * 0x1000))
  643. +#define MTK_XMAC_MCR(x) (MTK_XMAC_BASE(x))
  644. +#define XMAC_MCR_TRX_DISABLE 0xf
  645. +#define XMAC_MCR_FORCE_TX_FC BIT(5)
  646. +#define XMAC_MCR_FORCE_RX_FC BIT(4)
  647. +
  648. +/* XFI Mac logic reset registers */
  649. +#define MTK_XMAC_LOGIC_RST(x) (MTK_XMAC_BASE(x) + 0x10)
  650. +#define XMAC_LOGIC_RST BIT(0)
  651. +
  652. +/* XFI Mac count global control */
  653. +#define MTK_XMAC_CNT_CTRL(x) (MTK_XMAC_BASE(x) + 0x100)
  654. +#define XMAC_GLB_CNTCLR BIT(0)
  655. +
  656. /* GPIO port control registers for GMAC 2*/
  657. #define GPIO_OD33_CTRL8 0x4c0
  658. #define GPIO_BIAS_CTRL 0xed0
  659. @@ -527,6 +543,7 @@
  660. #define SYSCFG0_SGMII_GMAC2 ((3 << 8) & SYSCFG0_SGMII_MASK)
  661. #define SYSCFG0_SGMII_GMAC1_V2 BIT(9)
  662. #define SYSCFG0_SGMII_GMAC2_V2 BIT(8)
  663. +#define SYSCFG0_SGMII_GMAC3_V2 BIT(7)
  664. /* ethernet subsystem clock register */
  665. @@ -565,6 +582,11 @@
  666. #define GEPHY_MAC_SEL BIT(1)
  667. /* Top misc registers */
  668. +#define TOP_MISC_NETSYS_PCS_MUX 0x84
  669. +#define NETSYS_PCS_MUX_MASK GENMASK(1, 0)
  670. +#define MUX_G2_USXGMII_SEL BIT(1)
  671. +#define MUX_HSGMII1_G1_SEL BIT(0)
  672. +
  673. #define USB_PHY_SWITCH_REG 0x218
  674. #define QPHY_SEL_MASK GENMASK(1, 0)
  675. #define SGMII_QPHY_SEL 0x2
  676. @@ -589,6 +611,8 @@
  677. #define MT7628_SDM_RBCNT (MT7628_SDM_OFFSET + 0x10c)
  678. #define MT7628_SDM_CS_ERR (MT7628_SDM_OFFSET + 0x110)
  679. +/* Debug Purpose Register */
  680. +#define MTK_PSE_FQFC_CFG 0x100
  681. #define MTK_FE_CDM1_FSM 0x220
  682. #define MTK_FE_CDM2_FSM 0x224
  683. #define MTK_FE_CDM3_FSM 0x238
  684. @@ -597,6 +621,11 @@
  685. #define MTK_FE_CDM6_FSM 0x328
  686. #define MTK_FE_GDM1_FSM 0x228
  687. #define MTK_FE_GDM2_FSM 0x22C
  688. +#define MTK_FE_GDM3_FSM 0x23C
  689. +#define MTK_FE_PSE_FREE 0x240
  690. +#define MTK_FE_DROP_FQ 0x244
  691. +#define MTK_FE_DROP_FC 0x248
  692. +#define MTK_FE_DROP_PPE 0x24C
  693. #define MTK_MAC_FSM(x) (0x1010C + ((x) * 0x100))
  694. @@ -721,12 +750,8 @@ enum mtk_clks_map {
  695. MTK_CLK_ETHWARP_WOCPU2,
  696. MTK_CLK_ETHWARP_WOCPU1,
  697. MTK_CLK_ETHWARP_WOCPU0,
  698. - MTK_CLK_TOP_USXGMII_SBUS_0_SEL,
  699. - MTK_CLK_TOP_USXGMII_SBUS_1_SEL,
  700. MTK_CLK_TOP_SGM_0_SEL,
  701. MTK_CLK_TOP_SGM_1_SEL,
  702. - MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL,
  703. - MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL,
  704. MTK_CLK_TOP_ETH_GMII_SEL,
  705. MTK_CLK_TOP_ETH_REFCK_50M_SEL,
  706. MTK_CLK_TOP_ETH_SYS_200M_SEL,
  707. @@ -797,19 +822,9 @@ enum mtk_clks_map {
  708. BIT_ULL(MTK_CLK_GP3) | BIT_ULL(MTK_CLK_XGP1) | \
  709. BIT_ULL(MTK_CLK_XGP2) | BIT_ULL(MTK_CLK_XGP3) | \
  710. BIT_ULL(MTK_CLK_CRYPTO) | \
  711. - BIT_ULL(MTK_CLK_SGMII_TX_250M) | \
  712. - BIT_ULL(MTK_CLK_SGMII_RX_250M) | \
  713. - BIT_ULL(MTK_CLK_SGMII2_TX_250M) | \
  714. - BIT_ULL(MTK_CLK_SGMII2_RX_250M) | \
  715. BIT_ULL(MTK_CLK_ETHWARP_WOCPU2) | \
  716. BIT_ULL(MTK_CLK_ETHWARP_WOCPU1) | \
  717. BIT_ULL(MTK_CLK_ETHWARP_WOCPU0) | \
  718. - BIT_ULL(MTK_CLK_TOP_USXGMII_SBUS_0_SEL) | \
  719. - BIT_ULL(MTK_CLK_TOP_USXGMII_SBUS_1_SEL) | \
  720. - BIT_ULL(MTK_CLK_TOP_SGM_0_SEL) | \
  721. - BIT_ULL(MTK_CLK_TOP_SGM_1_SEL) | \
  722. - BIT_ULL(MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL) | \
  723. - BIT_ULL(MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL) | \
  724. BIT_ULL(MTK_CLK_TOP_ETH_GMII_SEL) | \
  725. BIT_ULL(MTK_CLK_TOP_ETH_REFCK_50M_SEL) | \
  726. BIT_ULL(MTK_CLK_TOP_ETH_SYS_200M_SEL) | \
  727. @@ -943,6 +958,8 @@ enum mkt_eth_capabilities {
  728. MTK_RGMII_BIT = 0,
  729. MTK_TRGMII_BIT,
  730. MTK_SGMII_BIT,
  731. + MTK_USXGMII_BIT,
  732. + MTK_2P5GPHY_BIT,
  733. MTK_ESW_BIT,
  734. MTK_GEPHY_BIT,
  735. MTK_MUX_BIT,
  736. @@ -963,8 +980,11 @@ enum mkt_eth_capabilities {
  737. MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
  738. MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT,
  739. MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT,
  740. + MTK_ETH_MUX_GMAC2_TO_2P5GPHY_BIT,
  741. MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT,
  742. MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT,
  743. + MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT,
  744. + MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT,
  745. /* PATH BITS */
  746. MTK_ETH_PATH_GMAC1_RGMII_BIT,
  747. @@ -972,14 +992,21 @@ enum mkt_eth_capabilities {
  748. MTK_ETH_PATH_GMAC1_SGMII_BIT,
  749. MTK_ETH_PATH_GMAC2_RGMII_BIT,
  750. MTK_ETH_PATH_GMAC2_SGMII_BIT,
  751. + MTK_ETH_PATH_GMAC2_2P5GPHY_BIT,
  752. MTK_ETH_PATH_GMAC2_GEPHY_BIT,
  753. + MTK_ETH_PATH_GMAC3_SGMII_BIT,
  754. MTK_ETH_PATH_GDM1_ESW_BIT,
  755. + MTK_ETH_PATH_GMAC1_USXGMII_BIT,
  756. + MTK_ETH_PATH_GMAC2_USXGMII_BIT,
  757. + MTK_ETH_PATH_GMAC3_USXGMII_BIT,
  758. };
  759. /* Supported hardware group on SoCs */
  760. #define MTK_RGMII BIT_ULL(MTK_RGMII_BIT)
  761. #define MTK_TRGMII BIT_ULL(MTK_TRGMII_BIT)
  762. #define MTK_SGMII BIT_ULL(MTK_SGMII_BIT)
  763. +#define MTK_USXGMII BIT_ULL(MTK_USXGMII_BIT)
  764. +#define MTK_2P5GPHY BIT_ULL(MTK_2P5GPHY_BIT)
  765. #define MTK_ESW BIT_ULL(MTK_ESW_BIT)
  766. #define MTK_GEPHY BIT_ULL(MTK_GEPHY_BIT)
  767. #define MTK_MUX BIT_ULL(MTK_MUX_BIT)
  768. @@ -1002,10 +1029,16 @@ enum mkt_eth_capabilities {
  769. BIT_ULL(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT)
  770. #define MTK_ETH_MUX_U3_GMAC2_TO_QPHY \
  771. BIT_ULL(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT)
  772. +#define MTK_ETH_MUX_GMAC2_TO_2P5GPHY \
  773. + BIT_ULL(MTK_ETH_MUX_GMAC2_TO_2P5GPHY_BIT)
  774. #define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
  775. BIT_ULL(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT)
  776. #define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII \
  777. BIT_ULL(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT)
  778. +#define MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII \
  779. + BIT_ULL(MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT)
  780. +#define MTK_ETH_MUX_GMAC123_TO_USXGMII \
  781. + BIT_ULL(MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT)
  782. /* Supported path present on SoCs */
  783. #define MTK_ETH_PATH_GMAC1_RGMII BIT_ULL(MTK_ETH_PATH_GMAC1_RGMII_BIT)
  784. @@ -1013,8 +1046,13 @@ enum mkt_eth_capabilities {
  785. #define MTK_ETH_PATH_GMAC1_SGMII BIT_ULL(MTK_ETH_PATH_GMAC1_SGMII_BIT)
  786. #define MTK_ETH_PATH_GMAC2_RGMII BIT_ULL(MTK_ETH_PATH_GMAC2_RGMII_BIT)
  787. #define MTK_ETH_PATH_GMAC2_SGMII BIT_ULL(MTK_ETH_PATH_GMAC2_SGMII_BIT)
  788. +#define MTK_ETH_PATH_GMAC2_2P5GPHY BIT_ULL(MTK_ETH_PATH_GMAC2_2P5GPHY_BIT)
  789. #define MTK_ETH_PATH_GMAC2_GEPHY BIT_ULL(MTK_ETH_PATH_GMAC2_GEPHY_BIT)
  790. +#define MTK_ETH_PATH_GMAC3_SGMII BIT_ULL(MTK_ETH_PATH_GMAC3_SGMII_BIT)
  791. #define MTK_ETH_PATH_GDM1_ESW BIT_ULL(MTK_ETH_PATH_GDM1_ESW_BIT)
  792. +#define MTK_ETH_PATH_GMAC1_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC1_USXGMII_BIT)
  793. +#define MTK_ETH_PATH_GMAC2_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC2_USXGMII_BIT)
  794. +#define MTK_ETH_PATH_GMAC3_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC3_USXGMII_BIT)
  795. #define MTK_GMAC1_RGMII (MTK_ETH_PATH_GMAC1_RGMII | MTK_RGMII)
  796. #define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
  797. @@ -1022,7 +1060,12 @@ enum mkt_eth_capabilities {
  798. #define MTK_GMAC2_RGMII (MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII)
  799. #define MTK_GMAC2_SGMII (MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII)
  800. #define MTK_GMAC2_GEPHY (MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY)
  801. +#define MTK_GMAC2_2P5GPHY (MTK_ETH_PATH_GMAC2_2P5GPHY | MTK_2P5GPHY)
  802. +#define MTK_GMAC3_SGMII (MTK_ETH_PATH_GMAC3_SGMII | MTK_SGMII)
  803. #define MTK_GDM1_ESW (MTK_ETH_PATH_GDM1_ESW | MTK_ESW)
  804. +#define MTK_GMAC1_USXGMII (MTK_ETH_PATH_GMAC1_USXGMII | MTK_USXGMII)
  805. +#define MTK_GMAC2_USXGMII (MTK_ETH_PATH_GMAC2_USXGMII | MTK_USXGMII)
  806. +#define MTK_GMAC3_USXGMII (MTK_ETH_PATH_GMAC3_USXGMII | MTK_USXGMII)
  807. /* MUXes present on SoCs */
  808. /* 0: GDM1 -> GMAC1, 1: GDM1 -> ESW */
  809. @@ -1041,10 +1084,20 @@ enum mkt_eth_capabilities {
  810. (MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \
  811. MTK_SHARED_SGMII)
  812. +/* 2: GMAC2 -> XGMII */
  813. +#define MTK_MUX_GMAC2_TO_2P5GPHY \
  814. + (MTK_ETH_MUX_GMAC2_TO_2P5GPHY | MTK_MUX | MTK_INFRA)
  815. +
  816. /* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */
  817. #define MTK_MUX_GMAC12_TO_GEPHY_SGMII \
  818. (MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX)
  819. +#define MTK_MUX_GMAC123_TO_GEPHY_SGMII \
  820. + (MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII | MTK_MUX)
  821. +
  822. +#define MTK_MUX_GMAC123_TO_USXGMII \
  823. + (MTK_ETH_MUX_GMAC123_TO_USXGMII | MTK_MUX | MTK_INFRA)
  824. +
  825. #define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
  826. #define MT7621_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \
  827. @@ -1076,8 +1129,12 @@ enum mkt_eth_capabilities {
  828. MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
  829. MTK_RSTCTRL_PPE1 | MTK_SRAM)
  830. -#define MT7988_CAPS (MTK_36BIT_DMA | MTK_GDM1_ESW | MTK_QDMA | \
  831. - MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | MTK_SRAM)
  832. +#define MT7988_CAPS (MTK_36BIT_DMA | MTK_GDM1_ESW | MTK_GMAC1_SGMII | \
  833. + MTK_GMAC2_2P5GPHY | MTK_GMAC2_SGMII | MTK_GMAC2_USXGMII | \
  834. + MTK_GMAC3_SGMII | MTK_GMAC3_USXGMII | \
  835. + MTK_MUX_GMAC123_TO_GEPHY_SGMII | \
  836. + MTK_MUX_GMAC123_TO_USXGMII | MTK_MUX_GMAC2_TO_2P5GPHY | \
  837. + MTK_QDMA | MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | MTK_SRAM)
  838. struct mtk_tx_dma_desc_info {
  839. dma_addr_t addr;
  840. @@ -1314,6 +1371,9 @@ struct mtk_mac {
  841. struct device_node *of_node;
  842. struct phylink *phylink;
  843. struct phylink_config phylink_config;
  844. + struct phylink_pcs *sgmii_pcs;
  845. + struct phylink_pcs *usxgmii_pcs;
  846. + struct phy *pextp;
  847. struct mtk_eth *hw;
  848. struct mtk_hw_stats *hw_stats;
  849. __be32 hwlro_ip[MTK_MAX_LRO_IP_CNT];
  850. @@ -1437,6 +1497,19 @@ static inline u32 mtk_get_ib2_multicast_
  851. return MTK_FOE_IB2_MULTICAST;
  852. }
  853. +static inline bool mtk_interface_mode_is_xgmii(phy_interface_t interface)
  854. +{
  855. + switch (interface) {
  856. + case PHY_INTERFACE_MODE_INTERNAL:
  857. + case PHY_INTERFACE_MODE_USXGMII:
  858. + case PHY_INTERFACE_MODE_10GBASER:
  859. + case PHY_INTERFACE_MODE_5GBASER:
  860. + return true;
  861. + default:
  862. + return false;
  863. + }
  864. +}
  865. +
  866. /* read the hardware status register */
  867. void mtk_stats_update_mac(struct mtk_mac *mac);
  868. @@ -1445,8 +1518,10 @@ u32 mtk_r32(struct mtk_eth *eth, unsigne
  869. u32 mtk_m32(struct mtk_eth *eth, u32 mask, u32 set, unsigned int reg);
  870. int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
  871. +int mtk_gmac_2p5gphy_path_setup(struct mtk_eth *eth, int mac_id);
  872. int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
  873. int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
  874. +int mtk_gmac_usxgmii_path_setup(struct mtk_eth *eth, int mac_id);
  875. int mtk_eth_offload_init(struct mtk_eth *eth);
  876. int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,