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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. From d5e337e7aecc2e1cc9e96768062610adb95f8f72 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 | 292 +++++++++++++++++--
  19. drivers/net/ethernet/mediatek/mtk_eth_soc.h | 107 ++++++-
  20. 3 files changed, 470 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. @@ -22,6 +22,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. @@ -261,12 +263,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. @@ -509,6 +507,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. @@ -517,6 +539,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. @@ -568,7 +605,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. @@ -615,8 +667,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. @@ -633,21 +683,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. @@ -660,6 +729,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. @@ -668,6 +749,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. @@ -692,10 +777,14 @@ 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 | MAC_MCR_FORCE_LINK);
  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 | MAC_MCR_FORCE_LINK, 0, MTK_MAC_MCR(mac->id));
  381. + if (mtk_is_netsys_v3_or_greater(mac->hw))
  382. + mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id), 0, MTK_XGMAC_STS(mac->id));
  383. + } else if (mtk_is_netsys_v3_or_greater(mac->hw) && mac->id != MTK_GMAC1_ID) {
  384. + mtk_m32(mac->hw, XMAC_MCR_TRX_DISABLE, XMAC_MCR_TRX_DISABLE, MTK_XMAC_MCR(mac->id));
  385. + }
  386. }
  387. static void mtk_set_queue_speed(struct mtk_eth *eth, unsigned int idx,
  388. @@ -767,13 +856,11 @@ static void mtk_set_queue_speed(struct m
  389. mtk_w32(eth, val, soc->reg_map->qdma.qtx_sch + ofs);
  390. }
  391. -static void mtk_mac_link_up(struct phylink_config *config,
  392. - struct phy_device *phy,
  393. - unsigned int mode, phy_interface_t interface,
  394. - int speed, int duplex, bool tx_pause, bool rx_pause)
  395. +static void mtk_gdm_mac_link_up(struct mtk_mac *mac,
  396. + struct phy_device *phy,
  397. + unsigned int mode, phy_interface_t interface,
  398. + int speed, int duplex, bool tx_pause, bool rx_pause)
  399. {
  400. - struct mtk_mac *mac = container_of(config, struct mtk_mac,
  401. - phylink_config);
  402. u32 mcr;
  403. mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
  404. @@ -807,9 +894,63 @@ static void mtk_mac_link_up(struct phyli
  405. mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
  406. }
  407. +static void mtk_xgdm_mac_link_up(struct mtk_mac *mac,
  408. + struct phy_device *phy,
  409. + unsigned int mode, phy_interface_t interface,
  410. + int speed, int duplex, bool tx_pause, bool rx_pause)
  411. +{
  412. + u32 mcr, force_link = 0;
  413. +
  414. + if (mac->id == MTK_GMAC1_ID)
  415. + return;
  416. +
  417. + /* Eliminate the interference(before link-up) caused by PHY noise */
  418. + mtk_m32(mac->hw, XMAC_LOGIC_RST, 0, MTK_XMAC_LOGIC_RST(mac->id));
  419. + mdelay(20);
  420. + mtk_m32(mac->hw, XMAC_GLB_CNTCLR, XMAC_GLB_CNTCLR, MTK_XMAC_CNT_CTRL(mac->id));
  421. +
  422. + if (mac->interface == PHY_INTERFACE_MODE_INTERNAL || mac->id == MTK_GMAC3_ID)
  423. + force_link = MTK_XGMAC_FORCE_LINK(mac->id);
  424. +
  425. + mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id), force_link, MTK_XGMAC_STS(mac->id));
  426. +
  427. + mcr = mtk_r32(mac->hw, MTK_XMAC_MCR(mac->id));
  428. + mcr &= ~(XMAC_MCR_FORCE_TX_FC | XMAC_MCR_FORCE_RX_FC | XMAC_MCR_TRX_DISABLE);
  429. + /* Configure pause modes -
  430. + * phylink will avoid these for half duplex
  431. + */
  432. + if (tx_pause)
  433. + mcr |= XMAC_MCR_FORCE_TX_FC;
  434. + if (rx_pause)
  435. + mcr |= XMAC_MCR_FORCE_RX_FC;
  436. +
  437. + mtk_w32(mac->hw, mcr, MTK_XMAC_MCR(mac->id));
  438. +}
  439. +
  440. +static void mtk_mac_link_up(struct phylink_config *config,
  441. + struct phy_device *phy,
  442. + unsigned int mode, phy_interface_t interface,
  443. + int speed, int duplex, bool tx_pause, bool rx_pause)
  444. +{
  445. + struct mtk_mac *mac = container_of(config, struct mtk_mac,
  446. + phylink_config);
  447. +
  448. + if (mtk_is_netsys_v3_or_greater(mac->hw) && mtk_interface_mode_is_xgmii(interface))
  449. + mtk_xgdm_mac_link_up(mac, phy, mode, interface, speed, duplex,
  450. + tx_pause, rx_pause);
  451. + else
  452. + mtk_gdm_mac_link_up(mac, phy, mode, interface, speed, duplex,
  453. + tx_pause, rx_pause);
  454. +
  455. + /* Repeat pextp setup to tune link */
  456. + if (mac->pextp)
  457. + phy_set_mode_ext(mac->pextp, PHY_MODE_ETHERNET, interface);
  458. +}
  459. +
  460. static const struct phylink_mac_ops mtk_phylink_ops = {
  461. .mac_select_pcs = mtk_mac_select_pcs,
  462. .mac_config = mtk_mac_config,
  463. + .mac_prepare = mtk_mac_prepare,
  464. .mac_finish = mtk_mac_finish,
  465. .mac_link_down = mtk_mac_link_down,
  466. .mac_link_up = mtk_mac_link_up,
  467. @@ -3390,6 +3531,9 @@ static int mtk_open(struct net_device *d
  468. struct mtk_eth *eth = mac->hw;
  469. int i, err;
  470. + if (mac->pextp)
  471. + phy_power_on(mac->pextp);
  472. +
  473. err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
  474. if (err) {
  475. netdev_err(dev, "%s: could not attach PHY: %d\n", __func__,
  476. @@ -3519,6 +3663,9 @@ static int mtk_stop(struct net_device *d
  477. for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
  478. mtk_ppe_stop(eth->ppe[i]);
  479. + if (mac->pextp)
  480. + phy_power_off(mac->pextp);
  481. +
  482. return 0;
  483. }
  484. @@ -4516,6 +4663,7 @@ static const struct net_device_ops mtk_n
  485. static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
  486. {
  487. const __be32 *_id = of_get_property(np, "reg", NULL);
  488. + struct device_node *pcs_np;
  489. phy_interface_t phy_mode;
  490. struct phylink *phylink;
  491. struct mtk_mac *mac;
  492. @@ -4552,16 +4700,41 @@ static int mtk_add_mac(struct mtk_eth *e
  493. mac->id = id;
  494. mac->hw = eth;
  495. mac->of_node = np;
  496. + pcs_np = of_parse_phandle(mac->of_node, "pcs-handle", 0);
  497. + if (pcs_np) {
  498. + mac->sgmii_pcs = mtk_pcs_lynxi_get(eth->dev, pcs_np);
  499. + if (IS_ERR(mac->sgmii_pcs)) {
  500. + if (PTR_ERR(mac->sgmii_pcs) == -EPROBE_DEFER)
  501. + return -EPROBE_DEFER;
  502. - err = of_get_ethdev_address(mac->of_node, eth->netdev[id]);
  503. - if (err == -EPROBE_DEFER)
  504. - return err;
  505. + dev_err(eth->dev, "cannot select SGMII PCS, error %ld\n",
  506. + PTR_ERR(mac->sgmii_pcs));
  507. + return PTR_ERR(mac->sgmii_pcs);
  508. + }
  509. + }
  510. - if (err) {
  511. - /* If the mac address is invalid, use random mac address */
  512. - eth_hw_addr_random(eth->netdev[id]);
  513. - dev_err(eth->dev, "generated random MAC address %pM\n",
  514. - eth->netdev[id]->dev_addr);
  515. + pcs_np = of_parse_phandle(mac->of_node, "pcs-handle", 1);
  516. + if (pcs_np) {
  517. + mac->usxgmii_pcs = mtk_usxgmii_pcs_get(eth->dev, pcs_np);
  518. + if (IS_ERR(mac->usxgmii_pcs)) {
  519. + if (PTR_ERR(mac->usxgmii_pcs) == -EPROBE_DEFER)
  520. + return -EPROBE_DEFER;
  521. +
  522. + dev_err(eth->dev, "cannot select USXGMII PCS, error %ld\n",
  523. + PTR_ERR(mac->usxgmii_pcs));
  524. + return PTR_ERR(mac->usxgmii_pcs);
  525. + }
  526. + }
  527. +
  528. + if (mtk_is_netsys_v3_or_greater(eth) && (mac->sgmii_pcs || mac->usxgmii_pcs)) {
  529. + mac->pextp = devm_of_phy_get(eth->dev, mac->of_node, NULL);
  530. + if (IS_ERR(mac->pextp)) {
  531. + if (PTR_ERR(mac->pextp) != -EPROBE_DEFER)
  532. + dev_err(eth->dev, "cannot get PHY, error %ld\n",
  533. + PTR_ERR(mac->pextp));
  534. +
  535. + return PTR_ERR(mac->pextp);
  536. + }
  537. }
  538. memset(mac->hwlro_ip, 0, sizeof(mac->hwlro_ip));
  539. @@ -4644,8 +4817,21 @@ static int mtk_add_mac(struct mtk_eth *e
  540. phy_interface_zero(mac->phylink_config.supported_interfaces);
  541. __set_bit(PHY_INTERFACE_MODE_INTERNAL,
  542. mac->phylink_config.supported_interfaces);
  543. + } else if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_USXGMII)) {
  544. + mac->phylink_config.mac_capabilities |= MAC_5000FD | MAC_10000FD;
  545. + __set_bit(PHY_INTERFACE_MODE_5GBASER,
  546. + mac->phylink_config.supported_interfaces);
  547. + __set_bit(PHY_INTERFACE_MODE_10GBASER,
  548. + mac->phylink_config.supported_interfaces);
  549. + __set_bit(PHY_INTERFACE_MODE_USXGMII,
  550. + mac->phylink_config.supported_interfaces);
  551. }
  552. + if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_2P5GPHY) &&
  553. + id == MTK_GMAC2_ID)
  554. + __set_bit(PHY_INTERFACE_MODE_INTERNAL,
  555. + mac->phylink_config.supported_interfaces);
  556. +
  557. phylink = phylink_create(&mac->phylink_config,
  558. of_fwnode_handle(mac->of_node),
  559. phy_mode, &mtk_phylink_ops);
  560. @@ -4696,6 +4882,26 @@ free_netdev:
  561. return err;
  562. }
  563. +static int mtk_mac_assign_address(struct mtk_eth *eth, int i, bool test_defer_only)
  564. +{
  565. + int err = of_get_ethdev_address(eth->mac[i]->of_node, eth->netdev[i]);
  566. +
  567. + if (err == -EPROBE_DEFER)
  568. + return err;
  569. +
  570. + if (test_defer_only)
  571. + return 0;
  572. +
  573. + if (err) {
  574. + /* If the mac address is invalid, use random mac address */
  575. + eth_hw_addr_random(eth->netdev[i]);
  576. + dev_err(eth->dev, "generated random MAC address %pM\n",
  577. + eth->netdev[i]);
  578. + }
  579. +
  580. + return 0;
  581. +}
  582. +
  583. void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev)
  584. {
  585. struct net_device *dev, *tmp;
  586. @@ -4842,7 +5048,8 @@ static int mtk_probe(struct platform_dev
  587. regmap_write(cci, 0, 3);
  588. }
  589. - if (MTK_HAS_CAPS(eth->soc->caps, MTK_SGMII)) {
  590. + if (MTK_HAS_CAPS(eth->soc->caps, MTK_SGMII) &&
  591. + !mtk_is_netsys_v3_or_greater(eth)) {
  592. err = mtk_sgmii_init(eth);
  593. if (err)
  594. @@ -4953,6 +5160,24 @@ static int mtk_probe(struct platform_dev
  595. }
  596. }
  597. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  598. + if (!eth->netdev[i])
  599. + continue;
  600. +
  601. + err = mtk_mac_assign_address(eth, i, true);
  602. + if (err)
  603. + goto err_deinit_hw;
  604. + }
  605. +
  606. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  607. + if (!eth->netdev[i])
  608. + continue;
  609. +
  610. + err = mtk_mac_assign_address(eth, i, false);
  611. + if (err)
  612. + goto err_deinit_hw;
  613. + }
  614. +
  615. if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT)) {
  616. err = devm_request_irq(eth->dev, eth->irq[0],
  617. mtk_handle_irq, 0,
  618. @@ -5055,6 +5280,11 @@ static int mtk_remove(struct platform_de
  619. mtk_stop(eth->netdev[i]);
  620. mac = netdev_priv(eth->netdev[i]);
  621. phylink_disconnect_phy(mac->phylink);
  622. + if (mac->sgmii_pcs)
  623. + mtk_pcs_lynxi_put(mac->sgmii_pcs);
  624. +
  625. + if (mac->usxgmii_pcs)
  626. + mtk_usxgmii_pcs_put(mac->usxgmii_pcs);
  627. }
  628. mtk_wed_exit();
  629. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  630. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  631. @@ -15,6 +15,7 @@
  632. #include <linux/u64_stats_sync.h>
  633. #include <linux/refcount.h>
  634. #include <linux/phylink.h>
  635. +#include <linux/reset.h>
  636. #include <linux/rhashtable.h>
  637. #include <linux/dim.h>
  638. #include <linux/bitfield.h>
  639. @@ -502,6 +503,21 @@
  640. #define INTF_MODE_RGMII_1000 (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED)
  641. #define INTF_MODE_RGMII_10_100 0
  642. +/* XFI Mac control registers */
  643. +#define MTK_XMAC_BASE(x) (0x12000 + (((x) - 1) * 0x1000))
  644. +#define MTK_XMAC_MCR(x) (MTK_XMAC_BASE(x))
  645. +#define XMAC_MCR_TRX_DISABLE 0xf
  646. +#define XMAC_MCR_FORCE_TX_FC BIT(5)
  647. +#define XMAC_MCR_FORCE_RX_FC BIT(4)
  648. +
  649. +/* XFI Mac logic reset registers */
  650. +#define MTK_XMAC_LOGIC_RST(x) (MTK_XMAC_BASE(x) + 0x10)
  651. +#define XMAC_LOGIC_RST BIT(0)
  652. +
  653. +/* XFI Mac count global control */
  654. +#define MTK_XMAC_CNT_CTRL(x) (MTK_XMAC_BASE(x) + 0x100)
  655. +#define XMAC_GLB_CNTCLR BIT(0)
  656. +
  657. /* GPIO port control registers for GMAC 2*/
  658. #define GPIO_OD33_CTRL8 0x4c0
  659. #define GPIO_BIAS_CTRL 0xed0
  660. @@ -527,6 +543,7 @@
  661. #define SYSCFG0_SGMII_GMAC2 ((3 << 8) & SYSCFG0_SGMII_MASK)
  662. #define SYSCFG0_SGMII_GMAC1_V2 BIT(9)
  663. #define SYSCFG0_SGMII_GMAC2_V2 BIT(8)
  664. +#define SYSCFG0_SGMII_GMAC3_V2 BIT(7)
  665. /* ethernet subsystem clock register */
  666. @@ -565,6 +582,11 @@
  667. #define GEPHY_MAC_SEL BIT(1)
  668. /* Top misc registers */
  669. +#define TOP_MISC_NETSYS_PCS_MUX 0x84
  670. +#define NETSYS_PCS_MUX_MASK GENMASK(1, 0)
  671. +#define MUX_G2_USXGMII_SEL BIT(1)
  672. +#define MUX_HSGMII1_G1_SEL BIT(0)
  673. +
  674. #define USB_PHY_SWITCH_REG 0x218
  675. #define QPHY_SEL_MASK GENMASK(1, 0)
  676. #define SGMII_QPHY_SEL 0x2
  677. @@ -589,6 +611,8 @@
  678. #define MT7628_SDM_RBCNT (MT7628_SDM_OFFSET + 0x10c)
  679. #define MT7628_SDM_CS_ERR (MT7628_SDM_OFFSET + 0x110)
  680. +/* Debug Purpose Register */
  681. +#define MTK_PSE_FQFC_CFG 0x100
  682. #define MTK_FE_CDM1_FSM 0x220
  683. #define MTK_FE_CDM2_FSM 0x224
  684. #define MTK_FE_CDM3_FSM 0x238
  685. @@ -597,6 +621,11 @@
  686. #define MTK_FE_CDM6_FSM 0x328
  687. #define MTK_FE_GDM1_FSM 0x228
  688. #define MTK_FE_GDM2_FSM 0x22C
  689. +#define MTK_FE_GDM3_FSM 0x23C
  690. +#define MTK_FE_PSE_FREE 0x240
  691. +#define MTK_FE_DROP_FQ 0x244
  692. +#define MTK_FE_DROP_FC 0x248
  693. +#define MTK_FE_DROP_PPE 0x24C
  694. #define MTK_MAC_FSM(x) (0x1010C + ((x) * 0x100))
  695. @@ -721,12 +750,8 @@ enum mtk_clks_map {
  696. MTK_CLK_ETHWARP_WOCPU2,
  697. MTK_CLK_ETHWARP_WOCPU1,
  698. MTK_CLK_ETHWARP_WOCPU0,
  699. - MTK_CLK_TOP_USXGMII_SBUS_0_SEL,
  700. - MTK_CLK_TOP_USXGMII_SBUS_1_SEL,
  701. MTK_CLK_TOP_SGM_0_SEL,
  702. MTK_CLK_TOP_SGM_1_SEL,
  703. - MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL,
  704. - MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL,
  705. MTK_CLK_TOP_ETH_GMII_SEL,
  706. MTK_CLK_TOP_ETH_REFCK_50M_SEL,
  707. MTK_CLK_TOP_ETH_SYS_200M_SEL,
  708. @@ -797,19 +822,9 @@ enum mtk_clks_map {
  709. BIT_ULL(MTK_CLK_GP3) | BIT_ULL(MTK_CLK_XGP1) | \
  710. BIT_ULL(MTK_CLK_XGP2) | BIT_ULL(MTK_CLK_XGP3) | \
  711. BIT_ULL(MTK_CLK_CRYPTO) | \
  712. - BIT_ULL(MTK_CLK_SGMII_TX_250M) | \
  713. - BIT_ULL(MTK_CLK_SGMII_RX_250M) | \
  714. - BIT_ULL(MTK_CLK_SGMII2_TX_250M) | \
  715. - BIT_ULL(MTK_CLK_SGMII2_RX_250M) | \
  716. BIT_ULL(MTK_CLK_ETHWARP_WOCPU2) | \
  717. BIT_ULL(MTK_CLK_ETHWARP_WOCPU1) | \
  718. BIT_ULL(MTK_CLK_ETHWARP_WOCPU0) | \
  719. - BIT_ULL(MTK_CLK_TOP_USXGMII_SBUS_0_SEL) | \
  720. - BIT_ULL(MTK_CLK_TOP_USXGMII_SBUS_1_SEL) | \
  721. - BIT_ULL(MTK_CLK_TOP_SGM_0_SEL) | \
  722. - BIT_ULL(MTK_CLK_TOP_SGM_1_SEL) | \
  723. - BIT_ULL(MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL) | \
  724. - BIT_ULL(MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL) | \
  725. BIT_ULL(MTK_CLK_TOP_ETH_GMII_SEL) | \
  726. BIT_ULL(MTK_CLK_TOP_ETH_REFCK_50M_SEL) | \
  727. BIT_ULL(MTK_CLK_TOP_ETH_SYS_200M_SEL) | \
  728. @@ -943,6 +958,8 @@ enum mkt_eth_capabilities {
  729. MTK_RGMII_BIT = 0,
  730. MTK_TRGMII_BIT,
  731. MTK_SGMII_BIT,
  732. + MTK_USXGMII_BIT,
  733. + MTK_2P5GPHY_BIT,
  734. MTK_ESW_BIT,
  735. MTK_GEPHY_BIT,
  736. MTK_MUX_BIT,
  737. @@ -963,8 +980,11 @@ enum mkt_eth_capabilities {
  738. MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
  739. MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT,
  740. MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT,
  741. + MTK_ETH_MUX_GMAC2_TO_2P5GPHY_BIT,
  742. MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT,
  743. MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT,
  744. + MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT,
  745. + MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT,
  746. /* PATH BITS */
  747. MTK_ETH_PATH_GMAC1_RGMII_BIT,
  748. @@ -972,14 +992,21 @@ enum mkt_eth_capabilities {
  749. MTK_ETH_PATH_GMAC1_SGMII_BIT,
  750. MTK_ETH_PATH_GMAC2_RGMII_BIT,
  751. MTK_ETH_PATH_GMAC2_SGMII_BIT,
  752. + MTK_ETH_PATH_GMAC2_2P5GPHY_BIT,
  753. MTK_ETH_PATH_GMAC2_GEPHY_BIT,
  754. + MTK_ETH_PATH_GMAC3_SGMII_BIT,
  755. MTK_ETH_PATH_GDM1_ESW_BIT,
  756. + MTK_ETH_PATH_GMAC1_USXGMII_BIT,
  757. + MTK_ETH_PATH_GMAC2_USXGMII_BIT,
  758. + MTK_ETH_PATH_GMAC3_USXGMII_BIT,
  759. };
  760. /* Supported hardware group on SoCs */
  761. #define MTK_RGMII BIT_ULL(MTK_RGMII_BIT)
  762. #define MTK_TRGMII BIT_ULL(MTK_TRGMII_BIT)
  763. #define MTK_SGMII BIT_ULL(MTK_SGMII_BIT)
  764. +#define MTK_USXGMII BIT_ULL(MTK_USXGMII_BIT)
  765. +#define MTK_2P5GPHY BIT_ULL(MTK_2P5GPHY_BIT)
  766. #define MTK_ESW BIT_ULL(MTK_ESW_BIT)
  767. #define MTK_GEPHY BIT_ULL(MTK_GEPHY_BIT)
  768. #define MTK_MUX BIT_ULL(MTK_MUX_BIT)
  769. @@ -1002,10 +1029,16 @@ enum mkt_eth_capabilities {
  770. BIT_ULL(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT)
  771. #define MTK_ETH_MUX_U3_GMAC2_TO_QPHY \
  772. BIT_ULL(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT)
  773. +#define MTK_ETH_MUX_GMAC2_TO_2P5GPHY \
  774. + BIT_ULL(MTK_ETH_MUX_GMAC2_TO_2P5GPHY_BIT)
  775. #define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
  776. BIT_ULL(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT)
  777. #define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII \
  778. BIT_ULL(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT)
  779. +#define MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII \
  780. + BIT_ULL(MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT)
  781. +#define MTK_ETH_MUX_GMAC123_TO_USXGMII \
  782. + BIT_ULL(MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT)
  783. /* Supported path present on SoCs */
  784. #define MTK_ETH_PATH_GMAC1_RGMII BIT_ULL(MTK_ETH_PATH_GMAC1_RGMII_BIT)
  785. @@ -1013,8 +1046,13 @@ enum mkt_eth_capabilities {
  786. #define MTK_ETH_PATH_GMAC1_SGMII BIT_ULL(MTK_ETH_PATH_GMAC1_SGMII_BIT)
  787. #define MTK_ETH_PATH_GMAC2_RGMII BIT_ULL(MTK_ETH_PATH_GMAC2_RGMII_BIT)
  788. #define MTK_ETH_PATH_GMAC2_SGMII BIT_ULL(MTK_ETH_PATH_GMAC2_SGMII_BIT)
  789. +#define MTK_ETH_PATH_GMAC2_2P5GPHY BIT_ULL(MTK_ETH_PATH_GMAC2_2P5GPHY_BIT)
  790. #define MTK_ETH_PATH_GMAC2_GEPHY BIT_ULL(MTK_ETH_PATH_GMAC2_GEPHY_BIT)
  791. +#define MTK_ETH_PATH_GMAC3_SGMII BIT_ULL(MTK_ETH_PATH_GMAC3_SGMII_BIT)
  792. #define MTK_ETH_PATH_GDM1_ESW BIT_ULL(MTK_ETH_PATH_GDM1_ESW_BIT)
  793. +#define MTK_ETH_PATH_GMAC1_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC1_USXGMII_BIT)
  794. +#define MTK_ETH_PATH_GMAC2_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC2_USXGMII_BIT)
  795. +#define MTK_ETH_PATH_GMAC3_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC3_USXGMII_BIT)
  796. #define MTK_GMAC1_RGMII (MTK_ETH_PATH_GMAC1_RGMII | MTK_RGMII)
  797. #define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
  798. @@ -1022,7 +1060,12 @@ enum mkt_eth_capabilities {
  799. #define MTK_GMAC2_RGMII (MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII)
  800. #define MTK_GMAC2_SGMII (MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII)
  801. #define MTK_GMAC2_GEPHY (MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY)
  802. +#define MTK_GMAC2_2P5GPHY (MTK_ETH_PATH_GMAC2_2P5GPHY | MTK_2P5GPHY)
  803. +#define MTK_GMAC3_SGMII (MTK_ETH_PATH_GMAC3_SGMII | MTK_SGMII)
  804. #define MTK_GDM1_ESW (MTK_ETH_PATH_GDM1_ESW | MTK_ESW)
  805. +#define MTK_GMAC1_USXGMII (MTK_ETH_PATH_GMAC1_USXGMII | MTK_USXGMII)
  806. +#define MTK_GMAC2_USXGMII (MTK_ETH_PATH_GMAC2_USXGMII | MTK_USXGMII)
  807. +#define MTK_GMAC3_USXGMII (MTK_ETH_PATH_GMAC3_USXGMII | MTK_USXGMII)
  808. /* MUXes present on SoCs */
  809. /* 0: GDM1 -> GMAC1, 1: GDM1 -> ESW */
  810. @@ -1041,10 +1084,20 @@ enum mkt_eth_capabilities {
  811. (MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \
  812. MTK_SHARED_SGMII)
  813. +/* 2: GMAC2 -> XGMII */
  814. +#define MTK_MUX_GMAC2_TO_2P5GPHY \
  815. + (MTK_ETH_MUX_GMAC2_TO_2P5GPHY | MTK_MUX | MTK_INFRA)
  816. +
  817. /* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */
  818. #define MTK_MUX_GMAC12_TO_GEPHY_SGMII \
  819. (MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX)
  820. +#define MTK_MUX_GMAC123_TO_GEPHY_SGMII \
  821. + (MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII | MTK_MUX)
  822. +
  823. +#define MTK_MUX_GMAC123_TO_USXGMII \
  824. + (MTK_ETH_MUX_GMAC123_TO_USXGMII | MTK_MUX | MTK_INFRA)
  825. +
  826. #define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
  827. #define MT7621_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \
  828. @@ -1076,8 +1129,12 @@ enum mkt_eth_capabilities {
  829. MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
  830. MTK_RSTCTRL_PPE1 | MTK_SRAM)
  831. -#define MT7988_CAPS (MTK_36BIT_DMA | MTK_GDM1_ESW | MTK_QDMA | \
  832. - MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | MTK_SRAM)
  833. +#define MT7988_CAPS (MTK_36BIT_DMA | MTK_GDM1_ESW | MTK_GMAC1_SGMII | \
  834. + MTK_GMAC2_2P5GPHY | MTK_GMAC2_SGMII | MTK_GMAC2_USXGMII | \
  835. + MTK_GMAC3_SGMII | MTK_GMAC3_USXGMII | \
  836. + MTK_MUX_GMAC123_TO_GEPHY_SGMII | \
  837. + MTK_MUX_GMAC123_TO_USXGMII | MTK_MUX_GMAC2_TO_2P5GPHY | \
  838. + MTK_QDMA | MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | MTK_SRAM)
  839. struct mtk_tx_dma_desc_info {
  840. dma_addr_t addr;
  841. @@ -1314,6 +1371,9 @@ struct mtk_mac {
  842. struct device_node *of_node;
  843. struct phylink *phylink;
  844. struct phylink_config phylink_config;
  845. + struct phylink_pcs *sgmii_pcs;
  846. + struct phylink_pcs *usxgmii_pcs;
  847. + struct phy *pextp;
  848. struct mtk_eth *hw;
  849. struct mtk_hw_stats *hw_stats;
  850. __be32 hwlro_ip[MTK_MAX_LRO_IP_CNT];
  851. @@ -1437,6 +1497,19 @@ static inline u32 mtk_get_ib2_multicast_
  852. return MTK_FOE_IB2_MULTICAST;
  853. }
  854. +static inline bool mtk_interface_mode_is_xgmii(phy_interface_t interface)
  855. +{
  856. + switch (interface) {
  857. + case PHY_INTERFACE_MODE_INTERNAL:
  858. + case PHY_INTERFACE_MODE_USXGMII:
  859. + case PHY_INTERFACE_MODE_10GBASER:
  860. + case PHY_INTERFACE_MODE_5GBASER:
  861. + return true;
  862. + default:
  863. + return false;
  864. + }
  865. +}
  866. +
  867. /* read the hardware status register */
  868. void mtk_stats_update_mac(struct mtk_mac *mac);
  869. @@ -1445,8 +1518,10 @@ u32 mtk_r32(struct mtk_eth *eth, unsigne
  870. u32 mtk_m32(struct mtk_eth *eth, u32 mask, u32 set, unsigned int reg);
  871. int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
  872. +int mtk_gmac_2p5gphy_path_setup(struct mtk_eth *eth, int mac_id);
  873. int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
  874. int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
  875. +int mtk_gmac_usxgmii_path_setup(struct mtk_eth *eth, int mac_id);
  876. int mtk_eth_offload_init(struct mtk_eth *eth);
  877. int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,