eth_p4080.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /*
  2. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <netdev.h>
  9. #include <asm/mmu.h>
  10. #include <asm/processor.h>
  11. #include <asm/cache.h>
  12. #include <asm/immap_85xx.h>
  13. #include <asm/fsl_law.h>
  14. #include <fsl_ddr_sdram.h>
  15. #include <asm/fsl_serdes.h>
  16. #include <asm/fsl_portals.h>
  17. #include <asm/fsl_liodn.h>
  18. #include <malloc.h>
  19. #include <fm_eth.h>
  20. #include <fsl_mdio.h>
  21. #include <miiphy.h>
  22. #include <phy.h>
  23. #include "../common/ngpixis.h"
  24. #include "../common/fman.h"
  25. #include <fsl_dtsec.h>
  26. #define EMI_NONE 0xffffffff
  27. #define EMI_MASK 0xf0000000
  28. #define EMI1_RGMII 0x0
  29. #define EMI1_SLOT3 0x80000000 /* bank1 EFGH */
  30. #define EMI1_SLOT4 0x40000000 /* bank2 ABCD */
  31. #define EMI1_SLOT5 0xc0000000 /* bank3 ABCD */
  32. #define EMI2_SLOT4 0x10000000 /* bank2 ABCD */
  33. #define EMI2_SLOT5 0x30000000 /* bank3 ABCD */
  34. #define EMI1_MASK 0xc0000000
  35. #define EMI2_MASK 0x30000000
  36. #define PHY_BASE_ADDR 0x00
  37. #define PHY_BASE_ADDR_SLOT5 0x10
  38. static int mdio_mux[NUM_FM_PORTS];
  39. static char *mdio_names[16] = {
  40. "P4080DS_MDIO0",
  41. "P4080DS_MDIO1",
  42. NULL,
  43. "P4080DS_MDIO3",
  44. "P4080DS_MDIO4",
  45. NULL, NULL, NULL,
  46. "P4080DS_MDIO8",
  47. NULL, NULL, NULL,
  48. "P4080DS_MDIO12",
  49. NULL, NULL, NULL,
  50. };
  51. /*
  52. * Mapping of all 18 SERDES lanes to board slots. A value of '0' here means
  53. * that the mapping must be determined dynamically, or that the lane maps to
  54. * something other than a board slot.
  55. */
  56. static u8 lane_to_slot[] = {
  57. 1, 1, 2, 2, 3, 3, 3, 3, 6, 6, 4, 4, 4, 4, 5, 5, 5, 5
  58. };
  59. static char *p4080ds_mdio_name_for_muxval(u32 muxval)
  60. {
  61. return mdio_names[(muxval & EMI_MASK) >> 28];
  62. }
  63. struct mii_dev *mii_dev_for_muxval(u32 muxval)
  64. {
  65. struct mii_dev *bus;
  66. char *name = p4080ds_mdio_name_for_muxval(muxval);
  67. if (!name) {
  68. printf("No bus for muxval %x\n", muxval);
  69. return NULL;
  70. }
  71. bus = miiphy_get_dev_by_name(name);
  72. if (!bus) {
  73. printf("No bus by name %s\n", name);
  74. return NULL;
  75. }
  76. return bus;
  77. }
  78. #if defined(CONFIG_SYS_P4080_ERRATUM_SERDES9) && defined(CONFIG_PHY_TERANETICS)
  79. int board_phy_config(struct phy_device *phydev)
  80. {
  81. if (phydev->drv->config)
  82. phydev->drv->config(phydev);
  83. if (phydev->drv->uid == PHY_UID_TN2020) {
  84. unsigned long timeout = 1 * 1000; /* 1 seconds */
  85. enum srds_prtcl device;
  86. /*
  87. * Wait for the XAUI to come out of reset. This is when it
  88. * starts transmitting alignment signals.
  89. */
  90. while (--timeout) {
  91. int reg = phy_read(phydev, MDIO_MMD_PHYXS, MDIO_CTRL1);
  92. if (reg < 0) {
  93. printf("TN2020: Error reading from PHY at "
  94. "address %u\n", phydev->addr);
  95. break;
  96. }
  97. /*
  98. * Note that we've never actually seen
  99. * MDIO_CTRL1_RESET set to 1.
  100. */
  101. if ((reg & MDIO_CTRL1_RESET) == 0)
  102. break;
  103. udelay(1000);
  104. }
  105. if (!timeout) {
  106. printf("TN2020: Timeout waiting for PHY at address %u "
  107. " to reset.\n", phydev->addr);
  108. }
  109. switch (phydev->addr) {
  110. case CONFIG_SYS_FM1_10GEC1_PHY_ADDR:
  111. device = XAUI_FM1;
  112. break;
  113. case CONFIG_SYS_FM2_10GEC1_PHY_ADDR:
  114. device = XAUI_FM2;
  115. break;
  116. default:
  117. device = NONE;
  118. }
  119. serdes_reset_rx(device);
  120. }
  121. return 0;
  122. }
  123. #endif
  124. struct p4080ds_mdio {
  125. u32 muxval;
  126. struct mii_dev *realbus;
  127. };
  128. static void p4080ds_mux_mdio(u32 muxval)
  129. {
  130. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
  131. uint gpioval = in_be32(&pgpio->gpdat) & ~(EMI_MASK);
  132. gpioval |= muxval;
  133. out_be32(&pgpio->gpdat, gpioval);
  134. }
  135. static int p4080ds_mdio_read(struct mii_dev *bus, int addr, int devad,
  136. int regnum)
  137. {
  138. struct p4080ds_mdio *priv = bus->priv;
  139. p4080ds_mux_mdio(priv->muxval);
  140. return priv->realbus->read(priv->realbus, addr, devad, regnum);
  141. }
  142. static int p4080ds_mdio_write(struct mii_dev *bus, int addr, int devad,
  143. int regnum, u16 value)
  144. {
  145. struct p4080ds_mdio *priv = bus->priv;
  146. p4080ds_mux_mdio(priv->muxval);
  147. return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
  148. }
  149. static int p4080ds_mdio_reset(struct mii_dev *bus)
  150. {
  151. struct p4080ds_mdio *priv = bus->priv;
  152. return priv->realbus->reset(priv->realbus);
  153. }
  154. static int p4080ds_mdio_init(char *realbusname, u32 muxval)
  155. {
  156. struct p4080ds_mdio *pmdio;
  157. struct mii_dev *bus = mdio_alloc();
  158. if (!bus) {
  159. printf("Failed to allocate P4080DS MDIO bus\n");
  160. return -1;
  161. }
  162. pmdio = malloc(sizeof(*pmdio));
  163. if (!pmdio) {
  164. printf("Failed to allocate P4080DS private data\n");
  165. free(bus);
  166. return -1;
  167. }
  168. bus->read = p4080ds_mdio_read;
  169. bus->write = p4080ds_mdio_write;
  170. bus->reset = p4080ds_mdio_reset;
  171. sprintf(bus->name, p4080ds_mdio_name_for_muxval(muxval));
  172. pmdio->realbus = miiphy_get_dev_by_name(realbusname);
  173. if (!pmdio->realbus) {
  174. printf("No bus with name %s\n", realbusname);
  175. free(bus);
  176. free(pmdio);
  177. return -1;
  178. }
  179. pmdio->muxval = muxval;
  180. bus->priv = pmdio;
  181. return mdio_register(bus);
  182. }
  183. void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa,
  184. enum fm_port port, int offset)
  185. {
  186. if (mdio_mux[port] == EMI1_RGMII)
  187. fdt_set_phy_handle(blob, prop, pa, "phy_rgmii");
  188. if (mdio_mux[port] == EMI1_SLOT3) {
  189. int idx = port - FM2_DTSEC1 + 5;
  190. char phy[16];
  191. sprintf(phy, "phy%d_slot3", idx);
  192. fdt_set_phy_handle(blob, prop, pa, phy);
  193. }
  194. }
  195. void fdt_fixup_board_enet(void *fdt)
  196. {
  197. int i;
  198. /*
  199. * P4080DS can be configured in many different ways, supporting a number
  200. * of combinations of ethernet devices and phy types. In order to
  201. * have just one device tree for all of those configurations, we fix up
  202. * the tree here. By default, the device tree configures FM1 and FM2
  203. * for SGMII, and configures XAUI on both 10G interfaces. So we have
  204. * a number of different variables to track:
  205. *
  206. * 1) Whether the device is configured at all. Whichever devices are
  207. * not enabled should be disabled by setting the "status" property
  208. * to "disabled".
  209. * 2) What the PHY interface is. If this is an RGMII connection,
  210. * we should change the "phy-connection-type" property to
  211. * "rgmii"
  212. * 3) Which PHY is being used. Because the MDIO buses are muxed,
  213. * we need to redirect the "phy-handle" property to point at the
  214. * PHY on the right slot/bus.
  215. */
  216. /* We've got six MDIO nodes that may or may not need to exist */
  217. fdt_status_disabled_by_alias(fdt, "emi1_slot3");
  218. fdt_status_disabled_by_alias(fdt, "emi1_slot4");
  219. fdt_status_disabled_by_alias(fdt, "emi1_slot5");
  220. fdt_status_disabled_by_alias(fdt, "emi2_slot4");
  221. fdt_status_disabled_by_alias(fdt, "emi2_slot5");
  222. for (i = 0; i < NUM_FM_PORTS; i++) {
  223. switch (mdio_mux[i]) {
  224. case EMI1_SLOT3:
  225. fdt_status_okay_by_alias(fdt, "emi1_slot3");
  226. break;
  227. case EMI1_SLOT4:
  228. fdt_status_okay_by_alias(fdt, "emi1_slot4");
  229. break;
  230. case EMI1_SLOT5:
  231. fdt_status_okay_by_alias(fdt, "emi1_slot5");
  232. break;
  233. case EMI2_SLOT4:
  234. fdt_status_okay_by_alias(fdt, "emi2_slot4");
  235. break;
  236. case EMI2_SLOT5:
  237. fdt_status_okay_by_alias(fdt, "emi2_slot5");
  238. break;
  239. }
  240. }
  241. }
  242. int board_eth_init(bd_t *bis)
  243. {
  244. #ifdef CONFIG_FMAN_ENET
  245. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
  246. int i;
  247. struct fsl_pq_mdio_info dtsec_mdio_info;
  248. struct tgec_mdio_info tgec_mdio_info;
  249. struct mii_dev *bus;
  250. /* Initialize the mdio_mux array so we can recognize empty elements */
  251. for (i = 0; i < NUM_FM_PORTS; i++)
  252. mdio_mux[i] = EMI_NONE;
  253. /* The first 4 GPIOs are outputs to control MDIO bus muxing */
  254. out_be32(&pgpio->gpdir, EMI_MASK);
  255. dtsec_mdio_info.regs =
  256. (struct tsec_mii_mng *)CONFIG_SYS_FM1_DTSEC1_MDIO_ADDR;
  257. dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
  258. /* Register the 1G MDIO bus */
  259. fsl_pq_mdio_init(bis, &dtsec_mdio_info);
  260. tgec_mdio_info.regs =
  261. (struct tgec_mdio_controller *)CONFIG_SYS_FM1_TGEC_MDIO_ADDR;
  262. tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
  263. /* Register the 10G MDIO bus */
  264. fm_tgec_mdio_init(bis, &tgec_mdio_info);
  265. /* Register the 6 muxing front-ends to the MDIO buses */
  266. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII);
  267. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT3);
  268. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT4);
  269. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT5);
  270. p4080ds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2_SLOT4);
  271. p4080ds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2_SLOT5);
  272. fm_info_set_phy_address(FM1_DTSEC1, CONFIG_SYS_FM1_DTSEC1_PHY_ADDR);
  273. fm_info_set_phy_address(FM1_DTSEC2, CONFIG_SYS_FM1_DTSEC2_PHY_ADDR);
  274. fm_info_set_phy_address(FM1_DTSEC3, CONFIG_SYS_FM1_DTSEC3_PHY_ADDR);
  275. fm_info_set_phy_address(FM1_DTSEC4, CONFIG_SYS_FM1_DTSEC4_PHY_ADDR);
  276. fm_info_set_phy_address(FM1_10GEC1, CONFIG_SYS_FM1_10GEC1_PHY_ADDR);
  277. #if (CONFIG_SYS_NUM_FMAN == 2)
  278. fm_info_set_phy_address(FM2_DTSEC1, CONFIG_SYS_FM2_DTSEC1_PHY_ADDR);
  279. fm_info_set_phy_address(FM2_DTSEC2, CONFIG_SYS_FM2_DTSEC2_PHY_ADDR);
  280. fm_info_set_phy_address(FM2_DTSEC3, CONFIG_SYS_FM2_DTSEC3_PHY_ADDR);
  281. fm_info_set_phy_address(FM2_DTSEC4, CONFIG_SYS_FM2_DTSEC4_PHY_ADDR);
  282. fm_info_set_phy_address(FM2_10GEC1, CONFIG_SYS_FM2_10GEC1_PHY_ADDR);
  283. #endif
  284. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  285. int idx = i - FM1_DTSEC1, lane, slot;
  286. switch (fm_info_get_enet_if(i)) {
  287. case PHY_INTERFACE_MODE_SGMII:
  288. lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
  289. if (lane < 0)
  290. break;
  291. slot = lane_to_slot[lane];
  292. switch (slot) {
  293. case 3:
  294. mdio_mux[i] = EMI1_SLOT3;
  295. fm_info_set_mdio(i,
  296. mii_dev_for_muxval(mdio_mux[i]));
  297. break;
  298. case 4:
  299. mdio_mux[i] = EMI1_SLOT4;
  300. fm_info_set_mdio(i,
  301. mii_dev_for_muxval(mdio_mux[i]));
  302. break;
  303. case 5:
  304. mdio_mux[i] = EMI1_SLOT5;
  305. fm_info_set_mdio(i,
  306. mii_dev_for_muxval(mdio_mux[i]));
  307. break;
  308. };
  309. break;
  310. case PHY_INTERFACE_MODE_RGMII:
  311. fm_info_set_phy_address(i, 0);
  312. mdio_mux[i] = EMI1_RGMII;
  313. fm_info_set_mdio(i,
  314. mii_dev_for_muxval(mdio_mux[i]));
  315. break;
  316. default:
  317. break;
  318. }
  319. }
  320. bus = mii_dev_for_muxval(EMI1_SLOT5);
  321. set_sgmii_phy(bus, FM1_DTSEC1,
  322. CONFIG_SYS_NUM_FM1_DTSEC, PHY_BASE_ADDR_SLOT5);
  323. for (i = FM1_10GEC1; i < FM1_10GEC1 + CONFIG_SYS_NUM_FM1_10GEC; i++) {
  324. int idx = i - FM1_10GEC1, lane, slot;
  325. switch (fm_info_get_enet_if(i)) {
  326. case PHY_INTERFACE_MODE_XGMII:
  327. lane = serdes_get_first_lane(XAUI_FM1 + idx);
  328. if (lane < 0)
  329. break;
  330. slot = lane_to_slot[lane];
  331. switch (slot) {
  332. case 4:
  333. mdio_mux[i] = EMI2_SLOT4;
  334. fm_info_set_mdio(i,
  335. mii_dev_for_muxval(mdio_mux[i]));
  336. break;
  337. case 5:
  338. mdio_mux[i] = EMI2_SLOT5;
  339. fm_info_set_mdio(i,
  340. mii_dev_for_muxval(mdio_mux[i]));
  341. break;
  342. };
  343. break;
  344. default:
  345. break;
  346. }
  347. }
  348. #if (CONFIG_SYS_NUM_FMAN == 2)
  349. for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
  350. int idx = i - FM2_DTSEC1, lane, slot;
  351. switch (fm_info_get_enet_if(i)) {
  352. case PHY_INTERFACE_MODE_SGMII:
  353. lane = serdes_get_first_lane(SGMII_FM2_DTSEC1 + idx);
  354. if (lane < 0)
  355. break;
  356. slot = lane_to_slot[lane];
  357. switch (slot) {
  358. case 3:
  359. mdio_mux[i] = EMI1_SLOT3;
  360. fm_info_set_mdio(i,
  361. mii_dev_for_muxval(mdio_mux[i]));
  362. break;
  363. case 4:
  364. mdio_mux[i] = EMI1_SLOT4;
  365. fm_info_set_mdio(i,
  366. mii_dev_for_muxval(mdio_mux[i]));
  367. break;
  368. case 5:
  369. mdio_mux[i] = EMI1_SLOT5;
  370. fm_info_set_mdio(i,
  371. mii_dev_for_muxval(mdio_mux[i]));
  372. break;
  373. };
  374. break;
  375. case PHY_INTERFACE_MODE_RGMII:
  376. fm_info_set_phy_address(i, 0);
  377. mdio_mux[i] = EMI1_RGMII;
  378. fm_info_set_mdio(i,
  379. mii_dev_for_muxval(mdio_mux[i]));
  380. break;
  381. default:
  382. break;
  383. }
  384. }
  385. bus = mii_dev_for_muxval(EMI1_SLOT3);
  386. set_sgmii_phy(bus, FM2_DTSEC1, CONFIG_SYS_NUM_FM2_DTSEC, PHY_BASE_ADDR);
  387. bus = mii_dev_for_muxval(EMI1_SLOT4);
  388. set_sgmii_phy(bus, FM2_DTSEC1, CONFIG_SYS_NUM_FM2_DTSEC, PHY_BASE_ADDR);
  389. for (i = FM2_10GEC1; i < FM2_10GEC1 + CONFIG_SYS_NUM_FM2_10GEC; i++) {
  390. int idx = i - FM2_10GEC1, lane, slot;
  391. switch (fm_info_get_enet_if(i)) {
  392. case PHY_INTERFACE_MODE_XGMII:
  393. lane = serdes_get_first_lane(XAUI_FM2 + idx);
  394. if (lane < 0)
  395. break;
  396. slot = lane_to_slot[lane];
  397. switch (slot) {
  398. case 4:
  399. mdio_mux[i] = EMI2_SLOT4;
  400. fm_info_set_mdio(i,
  401. mii_dev_for_muxval(mdio_mux[i]));
  402. break;
  403. case 5:
  404. mdio_mux[i] = EMI2_SLOT5;
  405. fm_info_set_mdio(i,
  406. mii_dev_for_muxval(mdio_mux[i]));
  407. break;
  408. };
  409. break;
  410. default:
  411. break;
  412. }
  413. }
  414. #endif
  415. cpu_eth_init(bis);
  416. #endif /* CONFIG_FMAN_ENET */
  417. return pci_eth_init(bis);
  418. }