eth.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /*
  2. * Copyright 2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <netdev.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/fsl_serdes.h>
  10. #include <hwconfig.h>
  11. #include <fsl_mdio.h>
  12. #include <malloc.h>
  13. #include <fm_eth.h>
  14. #include <i2c.h>
  15. #include <miiphy.h>
  16. #include <fsl-mc/ldpaa_wriop.h>
  17. #include "../common/qixis.h"
  18. #include "ls2080aqds_qixis.h"
  19. #define MC_BOOT_ENV_VAR "mcinitcmd"
  20. #ifdef CONFIG_FSL_MC_ENET
  21. /* - In LS2080A there are only 16 SERDES lanes, spread across 2 SERDES banks.
  22. * Bank 1 -> Lanes A, B, C, D, E, F, G, H
  23. * Bank 2 -> Lanes A,B, C, D, E, F, G, H
  24. */
  25. /* Mapping of 16 SERDES lanes to LS2080A QDS board slots. A value of '0' here
  26. * means that the mapping must be determined dynamically, or that the lane
  27. * maps to something other than a board slot.
  28. */
  29. static u8 lane_to_slot_fsm1[] = {
  30. 0, 0, 0, 0, 0, 0, 0, 0
  31. };
  32. static u8 lane_to_slot_fsm2[] = {
  33. 0, 0, 0, 0, 0, 0, 0, 0
  34. };
  35. /* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs
  36. * housed.
  37. */
  38. static int xqsgii_riser_phy_addr[] = {
  39. XQSGMII_CARD_PHY1_PORT0_ADDR,
  40. XQSGMII_CARD_PHY2_PORT0_ADDR,
  41. XQSGMII_CARD_PHY3_PORT0_ADDR,
  42. XQSGMII_CARD_PHY4_PORT0_ADDR,
  43. XQSGMII_CARD_PHY3_PORT2_ADDR,
  44. XQSGMII_CARD_PHY1_PORT2_ADDR,
  45. XQSGMII_CARD_PHY4_PORT2_ADDR,
  46. XQSGMII_CARD_PHY2_PORT2_ADDR,
  47. };
  48. static int sgmii_riser_phy_addr[] = {
  49. SGMII_CARD_PORT1_PHY_ADDR,
  50. SGMII_CARD_PORT2_PHY_ADDR,
  51. SGMII_CARD_PORT3_PHY_ADDR,
  52. SGMII_CARD_PORT4_PHY_ADDR,
  53. };
  54. /* Slot2 does not have EMI connections */
  55. #define EMI_NONE 0xFFFFFFFF
  56. #define EMI1_SLOT1 0
  57. #define EMI1_SLOT2 1
  58. #define EMI1_SLOT3 2
  59. #define EMI1_SLOT4 3
  60. #define EMI1_SLOT5 4
  61. #define EMI1_SLOT6 5
  62. #define EMI2 6
  63. #define SFP_TX 0
  64. static const char * const mdio_names[] = {
  65. "LS2080A_QDS_MDIO0",
  66. "LS2080A_QDS_MDIO1",
  67. "LS2080A_QDS_MDIO2",
  68. "LS2080A_QDS_MDIO3",
  69. "LS2080A_QDS_MDIO4",
  70. "LS2080A_QDS_MDIO5",
  71. DEFAULT_WRIOP_MDIO2_NAME,
  72. };
  73. struct ls2080a_qds_mdio {
  74. u8 muxval;
  75. struct mii_dev *realbus;
  76. };
  77. static void sgmii_configure_repeater(int serdes_port)
  78. {
  79. struct mii_dev *bus;
  80. uint8_t a = 0xf;
  81. int i, j, ret;
  82. int dpmac_id = 0, dpmac, mii_bus = 0;
  83. unsigned short value;
  84. char dev[2][20] = {"LS2080A_QDS_MDIO0", "LS2080A_QDS_MDIO3"};
  85. uint8_t i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5f, 0x60};
  86. uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
  87. uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
  88. uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
  89. uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
  90. int *riser_phy_addr = &xqsgii_riser_phy_addr[0];
  91. /* Set I2c to Slot 1 */
  92. i2c_write(0x77, 0, 0, &a, 1);
  93. for (dpmac = 0; dpmac < 8; dpmac++) {
  94. /* Check the PHY status */
  95. switch (serdes_port) {
  96. case 1:
  97. mii_bus = 0;
  98. dpmac_id = dpmac + 1;
  99. break;
  100. case 2:
  101. mii_bus = 1;
  102. dpmac_id = dpmac + 9;
  103. a = 0xb;
  104. i2c_write(0x76, 0, 0, &a, 1);
  105. break;
  106. }
  107. ret = miiphy_set_current_dev(dev[mii_bus]);
  108. if (ret > 0)
  109. goto error;
  110. bus = mdio_get_current_dev();
  111. debug("Reading from bus %s\n", bus->name);
  112. ret = miiphy_write(dev[mii_bus], riser_phy_addr[dpmac], 0x1f,
  113. 3);
  114. if (ret > 0)
  115. goto error;
  116. mdelay(10);
  117. ret = miiphy_read(dev[mii_bus], riser_phy_addr[dpmac], 0x11,
  118. &value);
  119. if (ret > 0)
  120. goto error;
  121. mdelay(10);
  122. if ((value & 0xfff) == 0x40f) {
  123. printf("DPMAC %d:PHY is ..... Configured\n", dpmac_id);
  124. continue;
  125. }
  126. for (i = 0; i < 4; i++) {
  127. for (j = 0; j < 4; j++) {
  128. a = 0x18;
  129. i2c_write(i2c_addr[dpmac], 6, 1, &a, 1);
  130. a = 0x38;
  131. i2c_write(i2c_addr[dpmac], 4, 1, &a, 1);
  132. a = 0x4;
  133. i2c_write(i2c_addr[dpmac], 8, 1, &a, 1);
  134. i2c_write(i2c_addr[dpmac], 0xf, 1,
  135. &ch_a_eq[i], 1);
  136. i2c_write(i2c_addr[dpmac], 0x11, 1,
  137. &ch_a_ctl2[j], 1);
  138. i2c_write(i2c_addr[dpmac], 0x16, 1,
  139. &ch_b_eq[i], 1);
  140. i2c_write(i2c_addr[dpmac], 0x18, 1,
  141. &ch_b_ctl2[j], 1);
  142. a = 0x14;
  143. i2c_write(i2c_addr[dpmac], 0x23, 1, &a, 1);
  144. a = 0xb5;
  145. i2c_write(i2c_addr[dpmac], 0x2d, 1, &a, 1);
  146. a = 0x20;
  147. i2c_write(i2c_addr[dpmac], 4, 1, &a, 1);
  148. mdelay(100);
  149. ret = miiphy_read(dev[mii_bus],
  150. riser_phy_addr[dpmac],
  151. 0x11, &value);
  152. if (ret > 0)
  153. goto error;
  154. mdelay(1);
  155. ret = miiphy_read(dev[mii_bus],
  156. riser_phy_addr[dpmac],
  157. 0x11, &value);
  158. if (ret > 0)
  159. goto error;
  160. mdelay(10);
  161. if ((value & 0xfff) == 0x40f) {
  162. printf("DPMAC %d :PHY is configured ",
  163. dpmac_id);
  164. printf("after setting repeater 0x%x\n",
  165. value);
  166. i = 5;
  167. j = 5;
  168. } else
  169. printf("DPMAC %d :PHY is failed to ",
  170. dpmac_id);
  171. printf("configure the repeater 0x%x\n",
  172. value);
  173. }
  174. }
  175. }
  176. error:
  177. if (ret)
  178. printf("DPMAC %d ..... FAILED to configure PHY\n", dpmac_id);
  179. return;
  180. }
  181. static void qsgmii_configure_repeater(int dpmac)
  182. {
  183. uint8_t a = 0xf;
  184. int i, j;
  185. int i2c_phy_addr = 0;
  186. int phy_addr = 0;
  187. int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
  188. uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
  189. uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
  190. uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
  191. uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
  192. const char *dev = "LS2080A_QDS_MDIO0";
  193. int ret = 0;
  194. unsigned short value;
  195. /* Set I2c to Slot 1 */
  196. i2c_write(0x77, 0, 0, &a, 1);
  197. switch (dpmac) {
  198. case 1:
  199. case 2:
  200. case 3:
  201. case 4:
  202. i2c_phy_addr = i2c_addr[0];
  203. phy_addr = 0;
  204. break;
  205. case 5:
  206. case 6:
  207. case 7:
  208. case 8:
  209. i2c_phy_addr = i2c_addr[1];
  210. phy_addr = 4;
  211. break;
  212. case 9:
  213. case 10:
  214. case 11:
  215. case 12:
  216. i2c_phy_addr = i2c_addr[2];
  217. phy_addr = 8;
  218. break;
  219. case 13:
  220. case 14:
  221. case 15:
  222. case 16:
  223. i2c_phy_addr = i2c_addr[3];
  224. phy_addr = 0xc;
  225. break;
  226. }
  227. /* Check the PHY status */
  228. ret = miiphy_set_current_dev(dev);
  229. ret = miiphy_write(dev, phy_addr, 0x1f, 3);
  230. mdelay(10);
  231. ret = miiphy_read(dev, phy_addr, 0x11, &value);
  232. mdelay(10);
  233. ret = miiphy_read(dev, phy_addr, 0x11, &value);
  234. mdelay(10);
  235. if ((value & 0xf) == 0xf) {
  236. printf("DPMAC %d :PHY is ..... Configured\n", dpmac);
  237. return;
  238. }
  239. for (i = 0; i < 4; i++) {
  240. for (j = 0; j < 4; j++) {
  241. a = 0x18;
  242. i2c_write(i2c_phy_addr, 6, 1, &a, 1);
  243. a = 0x38;
  244. i2c_write(i2c_phy_addr, 4, 1, &a, 1);
  245. a = 0x4;
  246. i2c_write(i2c_phy_addr, 8, 1, &a, 1);
  247. i2c_write(i2c_phy_addr, 0xf, 1, &ch_a_eq[i], 1);
  248. i2c_write(i2c_phy_addr, 0x11, 1, &ch_a_ctl2[j], 1);
  249. i2c_write(i2c_phy_addr, 0x16, 1, &ch_b_eq[i], 1);
  250. i2c_write(i2c_phy_addr, 0x18, 1, &ch_b_ctl2[j], 1);
  251. a = 0x14;
  252. i2c_write(i2c_phy_addr, 0x23, 1, &a, 1);
  253. a = 0xb5;
  254. i2c_write(i2c_phy_addr, 0x2d, 1, &a, 1);
  255. a = 0x20;
  256. i2c_write(i2c_phy_addr, 4, 1, &a, 1);
  257. mdelay(100);
  258. ret = miiphy_read(dev, phy_addr, 0x11, &value);
  259. if (ret > 0)
  260. goto error;
  261. mdelay(1);
  262. ret = miiphy_read(dev, phy_addr, 0x11, &value);
  263. if (ret > 0)
  264. goto error;
  265. mdelay(10);
  266. if ((value & 0xf) == 0xf) {
  267. printf("DPMAC %d :PHY is ..... Configured\n",
  268. dpmac);
  269. return;
  270. }
  271. }
  272. }
  273. error:
  274. printf("DPMAC %d :PHY ..... FAILED to configure PHY\n", dpmac);
  275. return;
  276. }
  277. static const char *ls2080a_qds_mdio_name_for_muxval(u8 muxval)
  278. {
  279. return mdio_names[muxval];
  280. }
  281. struct mii_dev *mii_dev_for_muxval(u8 muxval)
  282. {
  283. struct mii_dev *bus;
  284. const char *name = ls2080a_qds_mdio_name_for_muxval(muxval);
  285. if (!name) {
  286. printf("No bus for muxval %x\n", muxval);
  287. return NULL;
  288. }
  289. bus = miiphy_get_dev_by_name(name);
  290. if (!bus) {
  291. printf("No bus by name %s\n", name);
  292. return NULL;
  293. }
  294. return bus;
  295. }
  296. static void ls2080a_qds_enable_SFP_TX(u8 muxval)
  297. {
  298. u8 brdcfg9;
  299. brdcfg9 = QIXIS_READ(brdcfg[9]);
  300. brdcfg9 &= ~BRDCFG9_SFPTX_MASK;
  301. brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT);
  302. QIXIS_WRITE(brdcfg[9], brdcfg9);
  303. }
  304. static void ls2080a_qds_mux_mdio(u8 muxval)
  305. {
  306. u8 brdcfg4;
  307. if (muxval <= 5) {
  308. brdcfg4 = QIXIS_READ(brdcfg[4]);
  309. brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
  310. brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
  311. QIXIS_WRITE(brdcfg[4], brdcfg4);
  312. }
  313. }
  314. static int ls2080a_qds_mdio_read(struct mii_dev *bus, int addr,
  315. int devad, int regnum)
  316. {
  317. struct ls2080a_qds_mdio *priv = bus->priv;
  318. ls2080a_qds_mux_mdio(priv->muxval);
  319. return priv->realbus->read(priv->realbus, addr, devad, regnum);
  320. }
  321. static int ls2080a_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
  322. int regnum, u16 value)
  323. {
  324. struct ls2080a_qds_mdio *priv = bus->priv;
  325. ls2080a_qds_mux_mdio(priv->muxval);
  326. return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
  327. }
  328. static int ls2080a_qds_mdio_reset(struct mii_dev *bus)
  329. {
  330. struct ls2080a_qds_mdio *priv = bus->priv;
  331. return priv->realbus->reset(priv->realbus);
  332. }
  333. static int ls2080a_qds_mdio_init(char *realbusname, u8 muxval)
  334. {
  335. struct ls2080a_qds_mdio *pmdio;
  336. struct mii_dev *bus = mdio_alloc();
  337. if (!bus) {
  338. printf("Failed to allocate ls2080a_qds MDIO bus\n");
  339. return -1;
  340. }
  341. pmdio = malloc(sizeof(*pmdio));
  342. if (!pmdio) {
  343. printf("Failed to allocate ls2080a_qds private data\n");
  344. free(bus);
  345. return -1;
  346. }
  347. bus->read = ls2080a_qds_mdio_read;
  348. bus->write = ls2080a_qds_mdio_write;
  349. bus->reset = ls2080a_qds_mdio_reset;
  350. strcpy(bus->name, ls2080a_qds_mdio_name_for_muxval(muxval));
  351. pmdio->realbus = miiphy_get_dev_by_name(realbusname);
  352. if (!pmdio->realbus) {
  353. printf("No bus with name %s\n", realbusname);
  354. free(bus);
  355. free(pmdio);
  356. return -1;
  357. }
  358. pmdio->muxval = muxval;
  359. bus->priv = pmdio;
  360. return mdio_register(bus);
  361. }
  362. /*
  363. * Initialize the dpmac_info array.
  364. *
  365. */
  366. static void initialize_dpmac_to_slot(void)
  367. {
  368. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  369. int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
  370. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
  371. >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  372. int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
  373. FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
  374. >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
  375. char *env_hwconfig;
  376. env_hwconfig = getenv("hwconfig");
  377. switch (serdes1_prtcl) {
  378. case 0x07:
  379. case 0x09:
  380. case 0x33:
  381. printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
  382. serdes1_prtcl);
  383. lane_to_slot_fsm1[0] = EMI1_SLOT1;
  384. lane_to_slot_fsm1[1] = EMI1_SLOT1;
  385. lane_to_slot_fsm1[2] = EMI1_SLOT1;
  386. lane_to_slot_fsm1[3] = EMI1_SLOT1;
  387. if (hwconfig_f("xqsgmii", env_hwconfig)) {
  388. lane_to_slot_fsm1[4] = EMI1_SLOT1;
  389. lane_to_slot_fsm1[5] = EMI1_SLOT1;
  390. lane_to_slot_fsm1[6] = EMI1_SLOT1;
  391. lane_to_slot_fsm1[7] = EMI1_SLOT1;
  392. } else {
  393. lane_to_slot_fsm1[4] = EMI1_SLOT2;
  394. lane_to_slot_fsm1[5] = EMI1_SLOT2;
  395. lane_to_slot_fsm1[6] = EMI1_SLOT2;
  396. lane_to_slot_fsm1[7] = EMI1_SLOT2;
  397. }
  398. break;
  399. case 0x2A:
  400. printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
  401. serdes1_prtcl);
  402. break;
  403. default:
  404. printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
  405. __func__, serdes1_prtcl);
  406. break;
  407. }
  408. switch (serdes2_prtcl) {
  409. case 0x07:
  410. case 0x08:
  411. case 0x09:
  412. case 0x49:
  413. printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n",
  414. serdes2_prtcl);
  415. lane_to_slot_fsm2[0] = EMI1_SLOT4;
  416. lane_to_slot_fsm2[1] = EMI1_SLOT4;
  417. lane_to_slot_fsm2[2] = EMI1_SLOT4;
  418. lane_to_slot_fsm2[3] = EMI1_SLOT4;
  419. if (hwconfig_f("xqsgmii", env_hwconfig)) {
  420. lane_to_slot_fsm2[4] = EMI1_SLOT4;
  421. lane_to_slot_fsm2[5] = EMI1_SLOT4;
  422. lane_to_slot_fsm2[6] = EMI1_SLOT4;
  423. lane_to_slot_fsm2[7] = EMI1_SLOT4;
  424. } else {
  425. /* No MDIO physical connection */
  426. lane_to_slot_fsm2[4] = EMI1_SLOT6;
  427. lane_to_slot_fsm2[5] = EMI1_SLOT6;
  428. lane_to_slot_fsm2[6] = EMI1_SLOT6;
  429. lane_to_slot_fsm2[7] = EMI1_SLOT6;
  430. }
  431. break;
  432. default:
  433. printf(" %s qds: WRIOP: Unsupported SerDes2 Protocol 0x%02x\n",
  434. __func__ , serdes2_prtcl);
  435. break;
  436. }
  437. }
  438. void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
  439. {
  440. int lane, slot;
  441. struct mii_dev *bus;
  442. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  443. int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
  444. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
  445. >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  446. int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
  447. FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
  448. >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
  449. int *riser_phy_addr;
  450. char *env_hwconfig = getenv("hwconfig");
  451. if (hwconfig_f("xqsgmii", env_hwconfig))
  452. riser_phy_addr = &xqsgii_riser_phy_addr[0];
  453. else
  454. riser_phy_addr = &sgmii_riser_phy_addr[0];
  455. if (dpmac_id > WRIOP1_DPMAC9)
  456. goto serdes2;
  457. switch (serdes1_prtcl) {
  458. case 0x07:
  459. lane = serdes_get_first_lane(FSL_SRDS_1, SGMII1 + dpmac_id);
  460. slot = lane_to_slot_fsm1[lane];
  461. switch (++slot) {
  462. case 1:
  463. /* Slot housing a SGMII riser card? */
  464. wriop_set_phy_address(dpmac_id,
  465. riser_phy_addr[dpmac_id - 1]);
  466. dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
  467. bus = mii_dev_for_muxval(EMI1_SLOT1);
  468. wriop_set_mdio(dpmac_id, bus);
  469. break;
  470. case 2:
  471. /* Slot housing a SGMII riser card? */
  472. wriop_set_phy_address(dpmac_id,
  473. riser_phy_addr[dpmac_id - 1]);
  474. dpmac_info[dpmac_id].board_mux = EMI1_SLOT2;
  475. bus = mii_dev_for_muxval(EMI1_SLOT2);
  476. wriop_set_mdio(dpmac_id, bus);
  477. break;
  478. case 3:
  479. break;
  480. case 4:
  481. break;
  482. case 5:
  483. break;
  484. case 6:
  485. break;
  486. }
  487. break;
  488. default:
  489. printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
  490. __func__ , serdes1_prtcl);
  491. break;
  492. }
  493. serdes2:
  494. switch (serdes2_prtcl) {
  495. case 0x07:
  496. case 0x08:
  497. case 0x49:
  498. lane = serdes_get_first_lane(FSL_SRDS_2, SGMII9 +
  499. (dpmac_id - 9));
  500. slot = lane_to_slot_fsm2[lane];
  501. switch (++slot) {
  502. case 1:
  503. break;
  504. case 3:
  505. break;
  506. case 4:
  507. /* Slot housing a SGMII riser card? */
  508. wriop_set_phy_address(dpmac_id,
  509. riser_phy_addr[dpmac_id - 9]);
  510. dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
  511. bus = mii_dev_for_muxval(EMI1_SLOT4);
  512. wriop_set_mdio(dpmac_id, bus);
  513. break;
  514. case 5:
  515. break;
  516. case 6:
  517. /* Slot housing a SGMII riser card? */
  518. wriop_set_phy_address(dpmac_id,
  519. riser_phy_addr[dpmac_id - 13]);
  520. dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
  521. bus = mii_dev_for_muxval(EMI1_SLOT6);
  522. wriop_set_mdio(dpmac_id, bus);
  523. break;
  524. }
  525. break;
  526. default:
  527. printf("%s qds: WRIOP: Unsupported SerDes2 Protocol 0x%02x\n",
  528. __func__, serdes2_prtcl);
  529. break;
  530. }
  531. }
  532. void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
  533. {
  534. int lane = 0, slot;
  535. struct mii_dev *bus;
  536. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  537. int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
  538. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
  539. >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  540. switch (serdes1_prtcl) {
  541. case 0x33:
  542. switch (dpmac_id) {
  543. case 1:
  544. case 2:
  545. case 3:
  546. case 4:
  547. lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_A);
  548. break;
  549. case 5:
  550. case 6:
  551. case 7:
  552. case 8:
  553. lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_B);
  554. break;
  555. case 9:
  556. case 10:
  557. case 11:
  558. case 12:
  559. lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_C);
  560. break;
  561. case 13:
  562. case 14:
  563. case 15:
  564. case 16:
  565. lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_D);
  566. break;
  567. }
  568. slot = lane_to_slot_fsm1[lane];
  569. switch (++slot) {
  570. case 1:
  571. /* Slot housing a QSGMII riser card? */
  572. wriop_set_phy_address(dpmac_id, dpmac_id - 1);
  573. dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
  574. bus = mii_dev_for_muxval(EMI1_SLOT1);
  575. wriop_set_mdio(dpmac_id, bus);
  576. break;
  577. case 3:
  578. break;
  579. case 4:
  580. break;
  581. case 5:
  582. break;
  583. case 6:
  584. break;
  585. }
  586. break;
  587. default:
  588. printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
  589. serdes1_prtcl);
  590. break;
  591. }
  592. qsgmii_configure_repeater(dpmac_id);
  593. }
  594. void ls2080a_handle_phy_interface_xsgmii(int i)
  595. {
  596. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  597. int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
  598. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
  599. >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  600. switch (serdes1_prtcl) {
  601. case 0x2A:
  602. /*
  603. * XFI does not need a PHY to work, but to avoid U-Boot use
  604. * default PHY address which is zero to a MAC when it found
  605. * a MAC has no PHY address, we give a PHY address to XFI
  606. * MAC, and should not use a real XAUI PHY address, since
  607. * MDIO can access it successfully, and then MDIO thinks
  608. * the XAUI card is used for the XFI MAC, which will cause
  609. * error.
  610. */
  611. wriop_set_phy_address(i, i + 4);
  612. ls2080a_qds_enable_SFP_TX(SFP_TX);
  613. break;
  614. default:
  615. printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
  616. serdes1_prtcl);
  617. break;
  618. }
  619. }
  620. #endif
  621. int board_eth_init(bd_t *bis)
  622. {
  623. int error;
  624. char *mc_boot_env_var;
  625. #ifdef CONFIG_FSL_MC_ENET
  626. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  627. int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
  628. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
  629. >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  630. int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
  631. FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
  632. >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
  633. struct memac_mdio_info *memac_mdio0_info;
  634. struct memac_mdio_info *memac_mdio1_info;
  635. unsigned int i;
  636. char *env_hwconfig;
  637. env_hwconfig = getenv("hwconfig");
  638. initialize_dpmac_to_slot();
  639. memac_mdio0_info = (struct memac_mdio_info *)malloc(
  640. sizeof(struct memac_mdio_info));
  641. memac_mdio0_info->regs =
  642. (struct memac_mdio_controller *)
  643. CONFIG_SYS_FSL_WRIOP1_MDIO1;
  644. memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
  645. /* Register the real MDIO1 bus */
  646. fm_memac_mdio_init(bis, memac_mdio0_info);
  647. memac_mdio1_info = (struct memac_mdio_info *)malloc(
  648. sizeof(struct memac_mdio_info));
  649. memac_mdio1_info->regs =
  650. (struct memac_mdio_controller *)
  651. CONFIG_SYS_FSL_WRIOP1_MDIO2;
  652. memac_mdio1_info->name = DEFAULT_WRIOP_MDIO2_NAME;
  653. /* Register the real MDIO2 bus */
  654. fm_memac_mdio_init(bis, memac_mdio1_info);
  655. /* Register the muxing front-ends to the MDIO buses */
  656. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
  657. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT2);
  658. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT3);
  659. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT4);
  660. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT5);
  661. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT6);
  662. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO2_NAME, EMI2);
  663. for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
  664. switch (wriop_get_enet_if(i)) {
  665. case PHY_INTERFACE_MODE_QSGMII:
  666. ls2080a_handle_phy_interface_qsgmii(i);
  667. break;
  668. case PHY_INTERFACE_MODE_SGMII:
  669. ls2080a_handle_phy_interface_sgmii(i);
  670. break;
  671. case PHY_INTERFACE_MODE_XGMII:
  672. ls2080a_handle_phy_interface_xsgmii(i);
  673. break;
  674. default:
  675. break;
  676. if (i == 16)
  677. i = NUM_WRIOP_PORTS;
  678. }
  679. }
  680. mc_boot_env_var = getenv(MC_BOOT_ENV_VAR);
  681. if (mc_boot_env_var)
  682. run_command_list(mc_boot_env_var, -1, 0);
  683. error = cpu_eth_init(bis);
  684. if (hwconfig_f("xqsgmii", env_hwconfig)) {
  685. if (serdes1_prtcl == 0x7)
  686. sgmii_configure_repeater(1);
  687. if (serdes2_prtcl == 0x7 || serdes2_prtcl == 0x8 ||
  688. serdes2_prtcl == 0x49)
  689. sgmii_configure_repeater(2);
  690. }
  691. #endif
  692. error = pci_eth_init(bis);
  693. return error;
  694. }
  695. #ifdef CONFIG_FSL_MC_ENET
  696. #endif