eth_superhydra.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /*
  2. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  3. * Author: Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * This file handles the board muxing between the Fman Ethernet MACs and
  25. * the RGMII/SGMII/XGMII PHYs on a Freescale P5040 "Super Hydra" reference
  26. * board. The RGMII PHYs are the two on-board 1Gb ports. The SGMII PHYs are
  27. * provided by the standard Freescale four-port SGMII riser card. The 10Gb
  28. * XGMII PHYs are provided via the XAUI riser card. The P5040 has 2 FMans
  29. * and 5 1G interfaces and 10G interface per FMan. Based on the options in
  30. * the RCW, we could have upto 3 SGMII cards and 1 XAUI card at a time.
  31. *
  32. * Muxing is handled via the PIXIS BRDCFG1 register. The EMI1 bits control
  33. * muxing among the RGMII PHYs and the SGMII PHYs. The value for RGMII is
  34. * always the same (0). The value for SGMII depends on which slot the riser is
  35. * inserted in. The EMI2 bits control muxing for the the XGMII. Like SGMII,
  36. * the value is based on which slot the XAUI is inserted in.
  37. *
  38. * The SERDES configuration is used to determine where the SGMII and XAUI cards
  39. * exist, and also which Fman's MACs are routed to which PHYs. So for a given
  40. * Fman MAC, there is one and only PHY it connects to. MACs cannot be routed
  41. * to PHYs dynamically.
  42. *
  43. *
  44. * This file also updates the device tree in three ways:
  45. *
  46. * 1) The status of each virtual MDIO node that is referenced by an Ethernet
  47. * node is set to "okay".
  48. *
  49. * 2) The phy-handle property of each active Ethernet MAC node is set to the
  50. * appropriate PHY node.
  51. *
  52. * 3) The "mux value" for each virtual MDIO node is set to the correct value,
  53. * if necessary. Some virtual MDIO nodes do not have configurable mux
  54. * values, so those values are hard-coded in the DTS. On the HYDRA board,
  55. * the virtual MDIO node for the SGMII card needs to be updated.
  56. *
  57. * For all this to work, the device tree needs to have the following:
  58. *
  59. * 1) An alias for each PHY node that an Ethernet node could be routed to.
  60. *
  61. * 2) An alias for each real and virtual MDIO node that is disabled by default
  62. * and might need to be enabled, and also might need to have its mux-value
  63. * updated.
  64. */
  65. #include <common.h>
  66. #include <netdev.h>
  67. #include <asm/fsl_serdes.h>
  68. #include <fm_eth.h>
  69. #include <fsl_mdio.h>
  70. #include <malloc.h>
  71. #include <fdt_support.h>
  72. #include <asm/fsl_dtsec.h>
  73. #include "../common/ngpixis.h"
  74. #include "../common/fman.h"
  75. #ifdef CONFIG_FMAN_ENET
  76. #define BRDCFG1_EMI1_SEL_MASK 0x70
  77. #define BRDCFG1_EMI1_SEL_SLOT1 0x10
  78. #define BRDCFG1_EMI1_SEL_SLOT2 0x20
  79. #define BRDCFG1_EMI1_SEL_SLOT5 0x30
  80. #define BRDCFG1_EMI1_SEL_SLOT6 0x40
  81. #define BRDCFG1_EMI1_SEL_SLOT7 0x50
  82. #define BRDCFG1_EMI1_SEL_SLOT3 0x60
  83. #define BRDCFG1_EMI1_SEL_RGMII 0x00
  84. #define BRDCFG1_EMI1_EN 0x08
  85. #define BRDCFG1_EMI2_SEL_MASK 0x06
  86. #define BRDCFG1_EMI2_SEL_SLOT1 0x00
  87. #define BRDCFG1_EMI2_SEL_SLOT2 0x02
  88. #define BRDCFG2_REG_GPIO_SEL 0x20
  89. /*
  90. * BRDCFG1 mask and value for each MAC
  91. *
  92. * This array contains the BRDCFG1 values (in mask/val format) that route the
  93. * MDIO bus to a particular RGMII or SGMII PHY.
  94. */
  95. static struct {
  96. u8 mask;
  97. u8 val;
  98. } mdio_mux[NUM_FM_PORTS];
  99. /*
  100. * Mapping of all 18 SERDES lanes to board slots. A value of '0' here means
  101. * that the mapping must be determined dynamically, or that the lane maps to
  102. * something other than a board slot
  103. */
  104. static u8 lane_to_slot[] = {
  105. 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0
  106. };
  107. /*
  108. * Set the board muxing for a given MAC
  109. *
  110. * The MDIO layer calls this function every time it wants to talk to a PHY.
  111. */
  112. void super_hydra_mux_mdio(u8 mask, u8 val)
  113. {
  114. clrsetbits_8(&pixis->brdcfg1, mask, val);
  115. }
  116. struct super_hydra_mdio {
  117. u8 mask;
  118. u8 val;
  119. struct mii_dev *realbus;
  120. };
  121. static int super_hydra_mdio_read(struct mii_dev *bus, int addr, int devad,
  122. int regnum)
  123. {
  124. struct super_hydra_mdio *priv = bus->priv;
  125. super_hydra_mux_mdio(priv->mask, priv->val);
  126. return priv->realbus->read(priv->realbus, addr, devad, regnum);
  127. }
  128. static int super_hydra_mdio_write(struct mii_dev *bus, int addr, int devad,
  129. int regnum, u16 value)
  130. {
  131. struct super_hydra_mdio *priv = bus->priv;
  132. super_hydra_mux_mdio(priv->mask, priv->val);
  133. return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
  134. }
  135. static int super_hydra_mdio_reset(struct mii_dev *bus)
  136. {
  137. struct super_hydra_mdio *priv = bus->priv;
  138. return priv->realbus->reset(priv->realbus);
  139. }
  140. static void super_hydra_mdio_set_mux(char *name, u8 mask, u8 val)
  141. {
  142. struct mii_dev *bus = miiphy_get_dev_by_name(name);
  143. struct super_hydra_mdio *priv = bus->priv;
  144. priv->mask = mask;
  145. priv->val = val;
  146. }
  147. static int super_hydra_mdio_init(char *realbusname, char *fakebusname)
  148. {
  149. struct super_hydra_mdio *hmdio;
  150. struct mii_dev *bus = mdio_alloc();
  151. if (!bus) {
  152. printf("Failed to allocate Hydra MDIO bus\n");
  153. return -1;
  154. }
  155. hmdio = malloc(sizeof(*hmdio));
  156. if (!hmdio) {
  157. printf("Failed to allocate Hydra private data\n");
  158. free(bus);
  159. return -1;
  160. }
  161. bus->read = super_hydra_mdio_read;
  162. bus->write = super_hydra_mdio_write;
  163. bus->reset = super_hydra_mdio_reset;
  164. sprintf(bus->name, fakebusname);
  165. hmdio->realbus = miiphy_get_dev_by_name(realbusname);
  166. if (!hmdio->realbus) {
  167. printf("No bus with name %s\n", realbusname);
  168. free(bus);
  169. free(hmdio);
  170. return -1;
  171. }
  172. bus->priv = hmdio;
  173. return mdio_register(bus);
  174. }
  175. /*
  176. * Given the following ...
  177. *
  178. * 1) A pointer to an Fman Ethernet node (as identified by the 'compat'
  179. * compatible string and 'addr' physical address)
  180. *
  181. * 2) An Fman port
  182. *
  183. * ... update the phy-handle property of the Ethernet node to point to the
  184. * right PHY. This assumes that we already know the PHY for each port. That
  185. * information is stored in mdio_mux[].
  186. *
  187. * The offset of the Fman Ethernet node is also passed in for convenience, but
  188. * it is not used.
  189. *
  190. * Note that what we call "Fman ports" (enum fm_port) is really an Fman MAC.
  191. * Inside the Fman, "ports" are things that connect to MACs. We only call them
  192. * ports in U-Boot because on previous Ethernet devices (e.g. Gianfar), MACs
  193. * and ports are the same thing.
  194. */
  195. void board_ft_fman_fixup_port(void *fdt, char *compat, phys_addr_t addr,
  196. enum fm_port port, int offset)
  197. {
  198. enum srds_prtcl device;
  199. int lane, slot, phy;
  200. char alias[32];
  201. /* RGMII and XGMII are already mapped correctly in the DTS */
  202. if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_SGMII) {
  203. device = serdes_device_from_fm_port(port);
  204. lane = serdes_get_first_lane(device);
  205. slot = lane_to_slot[lane];
  206. phy = fm_info_get_phy_address(port);
  207. sprintf(alias, "phy_sgmii_slot%u_%x", slot, phy);
  208. fdt_set_phy_handle(fdt, compat, addr, alias);
  209. }
  210. }
  211. #define PIXIS_SW2_LANE_23_SEL 0x80
  212. #define PIXIS_SW2_LANE_45_SEL 0x40
  213. #define PIXIS_SW2_LANE_67_SEL_MASK 0x30
  214. #define PIXIS_SW2_LANE_67_SEL_5 0x00
  215. #define PIXIS_SW2_LANE_67_SEL_6 0x20
  216. #define PIXIS_SW2_LANE_67_SEL_7 0x10
  217. #define PIXIS_SW2_LANE_8_SEL 0x08
  218. #define PIXIS_SW2_LANE_1617_SEL 0x04
  219. #define PIXIS_SW11_LANE_9_SEL 0x04
  220. /*
  221. * Initialize the lane_to_slot[] array.
  222. *
  223. * On the P4080DS "Expedition" board, the mapping of SERDES lanes to board
  224. * slots is hard-coded. On the Hydra board, however, the mapping is controlled
  225. * by board switch SW2, so the lane_to_slot[] array needs to be dynamically
  226. * initialized.
  227. */
  228. static void initialize_lane_to_slot(void)
  229. {
  230. u8 sw2 = in_8(&PIXIS_SW(2));
  231. /* SW11 appears in the programming model as SW9 */
  232. u8 sw11 = in_8(&PIXIS_SW(9));
  233. lane_to_slot[2] = (sw2 & PIXIS_SW2_LANE_23_SEL) ? 7 : 4;
  234. lane_to_slot[3] = lane_to_slot[2];
  235. lane_to_slot[4] = (sw2 & PIXIS_SW2_LANE_45_SEL) ? 7 : 6;
  236. lane_to_slot[5] = lane_to_slot[4];
  237. switch (sw2 & PIXIS_SW2_LANE_67_SEL_MASK) {
  238. case PIXIS_SW2_LANE_67_SEL_5:
  239. lane_to_slot[6] = 5;
  240. break;
  241. case PIXIS_SW2_LANE_67_SEL_6:
  242. lane_to_slot[6] = 6;
  243. break;
  244. case PIXIS_SW2_LANE_67_SEL_7:
  245. lane_to_slot[6] = 7;
  246. break;
  247. }
  248. lane_to_slot[7] = lane_to_slot[6];
  249. lane_to_slot[8] = (sw2 & PIXIS_SW2_LANE_8_SEL) ? 3 : 0;
  250. lane_to_slot[9] = (sw11 & PIXIS_SW11_LANE_9_SEL) ? 0 : 3;
  251. lane_to_slot[16] = (sw2 & PIXIS_SW2_LANE_1617_SEL) ? 1 : 0;
  252. lane_to_slot[17] = lane_to_slot[16];
  253. }
  254. #endif /* #ifdef CONFIG_FMAN_ENET */
  255. /*
  256. * Configure the status for the virtual MDIO nodes
  257. *
  258. * Rather than create the virtual MDIO nodes from scratch for each active
  259. * virtual MDIO, we expect the DTS to have the nodes defined already, and we
  260. * only enable the ones that are actually active.
  261. *
  262. * We assume that the DTS already hard-codes the status for all the
  263. * virtual MDIO nodes to "disabled", so all we need to do is enable the
  264. * active ones.
  265. */
  266. void fdt_fixup_board_enet(void *fdt)
  267. {
  268. #ifdef CONFIG_FMAN_ENET
  269. enum fm_port i;
  270. int lane, slot;
  271. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  272. int idx = i - FM1_DTSEC1;
  273. switch (fm_info_get_enet_if(i)) {
  274. case PHY_INTERFACE_MODE_SGMII:
  275. lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
  276. if (lane >= 0) {
  277. char alias[32];
  278. slot = lane_to_slot[lane];
  279. sprintf(alias, "hydra_sg_slot%u", slot);
  280. fdt_status_okay_by_alias(fdt, alias);
  281. debug("Enabled MDIO node %s (slot %i)\n",
  282. alias, slot);
  283. }
  284. break;
  285. case PHY_INTERFACE_MODE_RGMII:
  286. fdt_status_okay_by_alias(fdt, "hydra_rg");
  287. debug("Enabled MDIO node hydra_rg\n");
  288. break;
  289. default:
  290. break;
  291. }
  292. }
  293. lane = serdes_get_first_lane(XAUI_FM1);
  294. if (lane >= 0) {
  295. char alias[32];
  296. slot = lane_to_slot[lane];
  297. sprintf(alias, "hydra_xg_slot%u", slot);
  298. fdt_status_okay_by_alias(fdt, alias);
  299. debug("Enabled MDIO node %s (slot %i)\n", alias, slot);
  300. }
  301. #if CONFIG_SYS_NUM_FMAN == 2
  302. for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
  303. int idx = i - FM2_DTSEC1;
  304. switch (fm_info_get_enet_if(i)) {
  305. case PHY_INTERFACE_MODE_SGMII:
  306. lane = serdes_get_first_lane(SGMII_FM2_DTSEC1 + idx);
  307. if (lane >= 0) {
  308. char alias[32];
  309. slot = lane_to_slot[lane];
  310. sprintf(alias, "hydra_sg_slot%u", slot);
  311. fdt_status_okay_by_alias(fdt, alias);
  312. debug("Enabled MDIO node %s (slot %i)\n",
  313. alias, slot);
  314. }
  315. break;
  316. case PHY_INTERFACE_MODE_RGMII:
  317. fdt_status_okay_by_alias(fdt, "hydra_rg");
  318. debug("Enabled MDIO node hydra_rg\n");
  319. break;
  320. default:
  321. break;
  322. }
  323. }
  324. lane = serdes_get_first_lane(XAUI_FM2);
  325. if (lane >= 0) {
  326. char alias[32];
  327. slot = lane_to_slot[lane];
  328. sprintf(alias, "hydra_xg_slot%u", slot);
  329. fdt_status_okay_by_alias(fdt, alias);
  330. debug("Enabled MDIO node %s (slot %i)\n", alias, slot);
  331. }
  332. #endif /* CONFIG_SYS_NUM_FMAN == 2 */
  333. #endif /* CONFIG_FMAN_ENET */
  334. }
  335. /*
  336. * Mapping of SerDes Protocol to MDIO MUX value and PHY address.
  337. *
  338. * Fman 1:
  339. * DTSEC1 | DTSEC2 | DTSEC3 | DTSEC4
  340. * Mux Phy | Mux Phy | Mux Phy | Mux Phy
  341. * Value Addr | Value Addr | Value Addr | Value Addr
  342. * 0x00 2 1c | 2 1d | 2 1e | 2 1f
  343. * 0x01 | | 6 1c |
  344. * 0x02 | | 3 1c | 3 1d
  345. * 0x03 2 1c | 2 1d | 2 1e | 2 1f
  346. * 0x04 2 1c | 2 1d | 2 1e | 2 1f
  347. * 0x05 | | 3 1c | 3 1d
  348. * 0x06 2 1c | 2 1d | 2 1e | 2 1f
  349. * 0x07 | | 6 1c |
  350. * 0x11 2 1c | 2 1d | 2 1e | 2 1f
  351. * 0x2a 2 | | 2 1e | 2 1f
  352. * 0x34 6 1c | 6 1d | 4 1e | 4 1f
  353. * 0x35 | | 3 1c | 3 1d
  354. * 0x36 6 1c | 6 1d | 4 1e | 4 1f
  355. * | | |
  356. * Fman 2: | | |
  357. * DTSEC1 | DTSEC2 | DTSEC3 | DTSEC4
  358. * EMI1 | EMI1 | EMI1 | EMI1
  359. * Mux Phy | Mux Phy | Mux Phy | Mux Phy
  360. * Value Addr | Value Addr | Value Addr | Value Addr
  361. * 0x00 | | 6 1c | 6 1d
  362. * 0x01 | | |
  363. * 0x02 | | 6 1c | 6 1d
  364. * 0x03 3 1c | 3 1d | 6 1c | 6 1d
  365. * 0x04 3 1c | 3 1d | 6 1c | 6 1d
  366. * 0x05 | | 6 1c | 6 1d
  367. * 0x06 | | 6 1c | 6 1d
  368. * 0x07 | | |
  369. * 0x11 | | |
  370. * 0x2a | | |
  371. * 0x34 | | |
  372. * 0x35 | | |
  373. * 0x36 | | |
  374. */
  375. int board_eth_init(bd_t *bis)
  376. {
  377. #ifdef CONFIG_FMAN_ENET
  378. struct fsl_pq_mdio_info dtsec_mdio_info;
  379. struct tgec_mdio_info tgec_mdio_info;
  380. unsigned int i, slot;
  381. int lane;
  382. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  383. int srds_prtcl = (in_be32(&gur->rcwsr[4]) &
  384. FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
  385. printf("Initializing Fman\n");
  386. initialize_lane_to_slot();
  387. /* We want to use the PIXIS to configure MUX routing, not GPIOs. */
  388. setbits_8(&pixis->brdcfg2, BRDCFG2_REG_GPIO_SEL);
  389. memset(mdio_mux, 0, sizeof(mdio_mux));
  390. dtsec_mdio_info.regs =
  391. (struct tsec_mii_mng *)CONFIG_SYS_FM1_DTSEC1_MDIO_ADDR;
  392. dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
  393. /* Register the real 1G MDIO bus */
  394. fsl_pq_mdio_init(bis, &dtsec_mdio_info);
  395. tgec_mdio_info.regs =
  396. (struct tgec_mdio_controller *)CONFIG_SYS_FM1_TGEC_MDIO_ADDR;
  397. tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
  398. /* Register the real 10G MDIO bus */
  399. fm_tgec_mdio_init(bis, &tgec_mdio_info);
  400. /* Register the three virtual MDIO front-ends */
  401. super_hydra_mdio_init(DEFAULT_FM_MDIO_NAME,
  402. "SUPER_HYDRA_RGMII_MDIO");
  403. super_hydra_mdio_init(DEFAULT_FM_MDIO_NAME,
  404. "SUPER_HYDRA_FM1_SGMII_MDIO");
  405. super_hydra_mdio_init(DEFAULT_FM_MDIO_NAME,
  406. "SUPER_HYDRA_FM2_SGMII_MDIO");
  407. super_hydra_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME,
  408. "SUPER_HYDRA_FM1_TGEC_MDIO");
  409. super_hydra_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME,
  410. "SUPER_HYDRA_FM2_TGEC_MDIO");
  411. /*
  412. * Program the DTSEC PHY addresses assuming that they are all SGMII.
  413. * For any DTSEC that's RGMII, we'll override its PHY address later.
  414. * We assume that DTSEC5 is only used for RGMII.
  415. */
  416. fm_info_set_phy_address(FM1_DTSEC1, CONFIG_SYS_FM1_DTSEC1_PHY_ADDR);
  417. fm_info_set_phy_address(FM1_DTSEC2, CONFIG_SYS_FM1_DTSEC2_PHY_ADDR);
  418. fm_info_set_phy_address(FM1_10GEC1, CONFIG_SYS_FM2_10GEC1_PHY_ADDR);
  419. #if (CONFIG_SYS_NUM_FMAN == 2)
  420. fm_info_set_phy_address(FM2_DTSEC1, CONFIG_SYS_FM2_DTSEC1_PHY_ADDR);
  421. fm_info_set_phy_address(FM2_DTSEC2, CONFIG_SYS_FM2_DTSEC2_PHY_ADDR);
  422. fm_info_set_phy_address(FM2_DTSEC3, CONFIG_SYS_FM2_DTSEC1_PHY_ADDR);
  423. fm_info_set_phy_address(FM2_DTSEC4, CONFIG_SYS_FM2_DTSEC2_PHY_ADDR);
  424. fm_info_set_phy_address(FM2_10GEC1, CONFIG_SYS_FM1_10GEC1_PHY_ADDR);
  425. #endif
  426. switch (srds_prtcl) {
  427. case 0:
  428. case 3:
  429. case 4:
  430. case 6:
  431. case 0x11:
  432. case 0x2a:
  433. case 0x34:
  434. case 0x36:
  435. fm_info_set_phy_address(FM1_DTSEC3,
  436. CONFIG_SYS_FM1_DTSEC3_PHY_ADDR);
  437. fm_info_set_phy_address(FM1_DTSEC4,
  438. CONFIG_SYS_FM1_DTSEC4_PHY_ADDR);
  439. break;
  440. case 1:
  441. case 2:
  442. case 5:
  443. case 7:
  444. case 0x35:
  445. fm_info_set_phy_address(FM1_DTSEC3,
  446. CONFIG_SYS_FM1_DTSEC1_PHY_ADDR);
  447. fm_info_set_phy_address(FM1_DTSEC4,
  448. CONFIG_SYS_FM1_DTSEC2_PHY_ADDR);
  449. break;
  450. default:
  451. printf("Fman: Unsupport SerDes Protocol 0x%02x\n", srds_prtcl);
  452. break;
  453. }
  454. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  455. int idx = i - FM1_DTSEC1;
  456. switch (fm_info_get_enet_if(i)) {
  457. case PHY_INTERFACE_MODE_SGMII:
  458. lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
  459. if (lane < 0)
  460. break;
  461. slot = lane_to_slot[lane];
  462. mdio_mux[i].mask = BRDCFG1_EMI1_SEL_MASK;
  463. debug("FM1@DTSEC%u expects SGMII in slot %u\n",
  464. idx + 1, slot);
  465. switch (slot) {
  466. case 1:
  467. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT1 |
  468. BRDCFG1_EMI1_EN;
  469. break;
  470. case 2:
  471. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT2 |
  472. BRDCFG1_EMI1_EN;
  473. break;
  474. case 3:
  475. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT3 |
  476. BRDCFG1_EMI1_EN;
  477. break;
  478. case 5:
  479. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT5 |
  480. BRDCFG1_EMI1_EN;
  481. break;
  482. case 6:
  483. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT6 |
  484. BRDCFG1_EMI1_EN;
  485. break;
  486. case 7:
  487. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT7 |
  488. BRDCFG1_EMI1_EN;
  489. break;
  490. };
  491. super_hydra_mdio_set_mux("SUPER_HYDRA_FM1_SGMII_MDIO",
  492. mdio_mux[i].mask, mdio_mux[i].val);
  493. fm_info_set_mdio(i,
  494. miiphy_get_dev_by_name("SUPER_HYDRA_FM1_SGMII_MDIO"));
  495. break;
  496. case PHY_INTERFACE_MODE_RGMII:
  497. /*
  498. * FM1 DTSEC5 is routed via EC1 to the first on-board
  499. * RGMII port. FM2 DTSEC5 is routed via EC2 to the
  500. * second on-board RGMII port. The other DTSECs cannot
  501. * be routed to RGMII.
  502. */
  503. debug("FM1@DTSEC%u is RGMII at address %u\n",
  504. idx + 1, 0);
  505. fm_info_set_phy_address(i, 0);
  506. mdio_mux[i].mask = BRDCFG1_EMI1_SEL_MASK;
  507. mdio_mux[i].val = BRDCFG1_EMI1_SEL_RGMII |
  508. BRDCFG1_EMI1_EN;
  509. super_hydra_mdio_set_mux("SUPER_HYDRA_RGMII_MDIO",
  510. mdio_mux[i].mask, mdio_mux[i].val);
  511. fm_info_set_mdio(i,
  512. miiphy_get_dev_by_name("SUPER_HYDRA_RGMII_MDIO"));
  513. break;
  514. case PHY_INTERFACE_MODE_NONE:
  515. fm_info_set_phy_address(i, 0);
  516. break;
  517. default:
  518. printf("Fman1: DTSEC%u set to unknown interface %i\n",
  519. idx + 1, fm_info_get_enet_if(i));
  520. fm_info_set_phy_address(i, 0);
  521. break;
  522. }
  523. }
  524. /*
  525. * For 10G, we only support one XAUI card per Fman. If present, then we
  526. * force its routing and never touch those bits again, which removes the
  527. * need for Linux to do any muxing. This works because of the way
  528. * BRDCFG1 is defined, but it's a bit hackish.
  529. *
  530. * The PHY address for the XAUI card depends on which slot it's in. The
  531. * macros we use imply that the PHY address is based on which FM, but
  532. * that's not true. On the P4080DS, FM1 could only use XAUI in slot 5,
  533. * and FM2 could only use a XAUI in slot 4. On the Hydra board, we
  534. * check the actual slot and just use the macros as-is, even though
  535. * the P3041 and P5020 only have one Fman.
  536. */
  537. lane = serdes_get_first_lane(XAUI_FM1);
  538. if (lane >= 0) {
  539. debug("FM1@TGEC1 expects XAUI in slot %u\n", lane_to_slot[lane]);
  540. mdio_mux[i].mask = BRDCFG1_EMI2_SEL_MASK;
  541. mdio_mux[i].val = BRDCFG1_EMI2_SEL_SLOT2;
  542. super_hydra_mdio_set_mux("SUPER_HYDRA_FM1_TGEC_MDIO",
  543. mdio_mux[i].mask, mdio_mux[i].val);
  544. }
  545. fm_info_set_mdio(FM1_10GEC1,
  546. miiphy_get_dev_by_name("SUPER_HYDRA_FM1_TGEC_MDIO"));
  547. #if (CONFIG_SYS_NUM_FMAN == 2)
  548. for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
  549. int idx = i - FM2_DTSEC1;
  550. switch (fm_info_get_enet_if(i)) {
  551. case PHY_INTERFACE_MODE_SGMII:
  552. lane = serdes_get_first_lane(SGMII_FM2_DTSEC1 + idx);
  553. if (lane < 0)
  554. break;
  555. slot = lane_to_slot[lane];
  556. mdio_mux[i].mask = BRDCFG1_EMI1_SEL_MASK;
  557. debug("FM2@DTSEC%u expects SGMII in slot %u\n",
  558. idx + 1, slot);
  559. switch (slot) {
  560. case 1:
  561. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT1 |
  562. BRDCFG1_EMI1_EN;
  563. break;
  564. case 2:
  565. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT2 |
  566. BRDCFG1_EMI1_EN;
  567. break;
  568. case 3:
  569. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT3 |
  570. BRDCFG1_EMI1_EN;
  571. break;
  572. case 5:
  573. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT5 |
  574. BRDCFG1_EMI1_EN;
  575. break;
  576. case 6:
  577. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT6 |
  578. BRDCFG1_EMI1_EN;
  579. break;
  580. case 7:
  581. mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT7 |
  582. BRDCFG1_EMI1_EN;
  583. break;
  584. };
  585. super_hydra_mdio_set_mux("SUPER_HYDRA_FM2_SGMII_MDIO",
  586. mdio_mux[i].mask, mdio_mux[i].val);
  587. fm_info_set_mdio(i,
  588. miiphy_get_dev_by_name("SUPER_HYDRA_FM2_SGMII_MDIO"));
  589. break;
  590. case PHY_INTERFACE_MODE_RGMII:
  591. /*
  592. * FM1 DTSEC5 is routed via EC1 to the first on-board
  593. * RGMII port. FM2 DTSEC5 is routed via EC2 to the
  594. * second on-board RGMII port. The other DTSECs cannot
  595. * be routed to RGMII.
  596. */
  597. debug("FM2@DTSEC%u is RGMII at address %u\n",
  598. idx + 1, 1);
  599. fm_info_set_phy_address(i, 1);
  600. mdio_mux[i].mask = BRDCFG1_EMI1_SEL_MASK;
  601. mdio_mux[i].val = BRDCFG1_EMI1_SEL_RGMII |
  602. BRDCFG1_EMI1_EN;
  603. super_hydra_mdio_set_mux("SUPER_HYDRA_RGMII_MDIO",
  604. mdio_mux[i].mask, mdio_mux[i].val);
  605. fm_info_set_mdio(i,
  606. miiphy_get_dev_by_name("SUPER_HYDRA_RGMII_MDIO"));
  607. break;
  608. case PHY_INTERFACE_MODE_NONE:
  609. fm_info_set_phy_address(i, 0);
  610. break;
  611. default:
  612. printf("Fman2: DTSEC%u set to unknown interface %i\n",
  613. idx + 1, fm_info_get_enet_if(i));
  614. fm_info_set_phy_address(i, 0);
  615. break;
  616. }
  617. }
  618. /*
  619. * For 10G, we only support one XAUI card per Fman. If present, then we
  620. * force its routing and never touch those bits again, which removes the
  621. * need for Linux to do any muxing. This works because of the way
  622. * BRDCFG1 is defined, but it's a bit hackish.
  623. *
  624. * The PHY address for the XAUI card depends on which slot it's in. The
  625. * macros we use imply that the PHY address is based on which FM, but
  626. * that's not true. On the P4080DS, FM1 could only use XAUI in slot 5,
  627. * and FM2 could only use a XAUI in slot 4. On the Hydra board, we
  628. * check the actual slot and just use the macros as-is, even though
  629. * the P3041 and P5020 only have one Fman.
  630. */
  631. lane = serdes_get_first_lane(XAUI_FM2);
  632. if (lane >= 0) {
  633. debug("FM2@TGEC1 expects XAUI in slot %u\n", lane_to_slot[lane]);
  634. mdio_mux[i].mask = BRDCFG1_EMI2_SEL_MASK;
  635. mdio_mux[i].val = BRDCFG1_EMI2_SEL_SLOT1;
  636. super_hydra_mdio_set_mux("SUPER_HYDRA_FM2_TGEC_MDIO",
  637. mdio_mux[i].mask, mdio_mux[i].val);
  638. }
  639. fm_info_set_mdio(FM2_10GEC1,
  640. miiphy_get_dev_by_name("SUPER_HYDRA_FM2_TGEC_MDIO"));
  641. #endif
  642. cpu_eth_init(bis);
  643. #endif
  644. return pci_eth_init(bis);
  645. }