eth.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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 0xFF
  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) == 0x401) {
  123. printf("DPMAC %d:PHY is ..... Configured\n", dpmac_id);
  124. miiphy_write(dev[mii_bus], riser_phy_addr[dpmac],
  125. 0x1f, 0);
  126. continue;
  127. }
  128. for (i = 0; i < 4; i++) {
  129. for (j = 0; j < 4; j++) {
  130. a = 0x18;
  131. i2c_write(i2c_addr[dpmac], 6, 1, &a, 1);
  132. a = 0x38;
  133. i2c_write(i2c_addr[dpmac], 4, 1, &a, 1);
  134. a = 0x4;
  135. i2c_write(i2c_addr[dpmac], 8, 1, &a, 1);
  136. i2c_write(i2c_addr[dpmac], 0xf, 1,
  137. &ch_a_eq[i], 1);
  138. i2c_write(i2c_addr[dpmac], 0x11, 1,
  139. &ch_a_ctl2[j], 1);
  140. i2c_write(i2c_addr[dpmac], 0x16, 1,
  141. &ch_b_eq[i], 1);
  142. i2c_write(i2c_addr[dpmac], 0x18, 1,
  143. &ch_b_ctl2[j], 1);
  144. a = 0x14;
  145. i2c_write(i2c_addr[dpmac], 0x23, 1, &a, 1);
  146. a = 0xb5;
  147. i2c_write(i2c_addr[dpmac], 0x2d, 1, &a, 1);
  148. a = 0x20;
  149. i2c_write(i2c_addr[dpmac], 4, 1, &a, 1);
  150. mdelay(100);
  151. ret = miiphy_read(dev[mii_bus],
  152. riser_phy_addr[dpmac],
  153. 0x11, &value);
  154. if (ret > 0)
  155. goto error;
  156. mdelay(100);
  157. ret = miiphy_read(dev[mii_bus],
  158. riser_phy_addr[dpmac],
  159. 0x11, &value);
  160. if (ret > 0)
  161. goto error;
  162. if ((value & 0xfff) == 0x401) {
  163. printf("DPMAC %d :PHY is configured ",
  164. dpmac_id);
  165. printf("after setting repeater 0x%x\n",
  166. value);
  167. i = 5;
  168. j = 5;
  169. } else {
  170. printf("DPMAC %d :PHY is failed to ",
  171. dpmac_id);
  172. printf("configure the repeater 0x%x\n",
  173. value);
  174. }
  175. }
  176. }
  177. miiphy_write(dev[mii_bus], riser_phy_addr[dpmac], 0x1f, 0);
  178. }
  179. error:
  180. if (ret)
  181. printf("DPMAC %d ..... FAILED to configure PHY\n", dpmac_id);
  182. return;
  183. }
  184. static void qsgmii_configure_repeater(int dpmac)
  185. {
  186. uint8_t a = 0xf;
  187. int i, j;
  188. int i2c_phy_addr = 0;
  189. int phy_addr = 0;
  190. int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
  191. uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
  192. uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
  193. uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
  194. uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
  195. const char *dev = "LS2080A_QDS_MDIO0";
  196. int ret = 0;
  197. unsigned short value;
  198. /* Set I2c to Slot 1 */
  199. i2c_write(0x77, 0, 0, &a, 1);
  200. switch (dpmac) {
  201. case 1:
  202. case 2:
  203. case 3:
  204. case 4:
  205. i2c_phy_addr = i2c_addr[0];
  206. phy_addr = 0;
  207. break;
  208. case 5:
  209. case 6:
  210. case 7:
  211. case 8:
  212. i2c_phy_addr = i2c_addr[1];
  213. phy_addr = 4;
  214. break;
  215. case 9:
  216. case 10:
  217. case 11:
  218. case 12:
  219. i2c_phy_addr = i2c_addr[2];
  220. phy_addr = 8;
  221. break;
  222. case 13:
  223. case 14:
  224. case 15:
  225. case 16:
  226. i2c_phy_addr = i2c_addr[3];
  227. phy_addr = 0xc;
  228. break;
  229. }
  230. /* Check the PHY status */
  231. ret = miiphy_set_current_dev(dev);
  232. ret = miiphy_write(dev, phy_addr, 0x1f, 3);
  233. mdelay(10);
  234. ret = miiphy_read(dev, phy_addr, 0x11, &value);
  235. mdelay(10);
  236. ret = miiphy_read(dev, phy_addr, 0x11, &value);
  237. mdelay(10);
  238. if ((value & 0xf) == 0xf) {
  239. printf("DPMAC %d :PHY is ..... Configured\n", dpmac);
  240. return;
  241. }
  242. for (i = 0; i < 4; i++) {
  243. for (j = 0; j < 4; j++) {
  244. a = 0x18;
  245. i2c_write(i2c_phy_addr, 6, 1, &a, 1);
  246. a = 0x38;
  247. i2c_write(i2c_phy_addr, 4, 1, &a, 1);
  248. a = 0x4;
  249. i2c_write(i2c_phy_addr, 8, 1, &a, 1);
  250. i2c_write(i2c_phy_addr, 0xf, 1, &ch_a_eq[i], 1);
  251. i2c_write(i2c_phy_addr, 0x11, 1, &ch_a_ctl2[j], 1);
  252. i2c_write(i2c_phy_addr, 0x16, 1, &ch_b_eq[i], 1);
  253. i2c_write(i2c_phy_addr, 0x18, 1, &ch_b_ctl2[j], 1);
  254. a = 0x14;
  255. i2c_write(i2c_phy_addr, 0x23, 1, &a, 1);
  256. a = 0xb5;
  257. i2c_write(i2c_phy_addr, 0x2d, 1, &a, 1);
  258. a = 0x20;
  259. i2c_write(i2c_phy_addr, 4, 1, &a, 1);
  260. mdelay(100);
  261. ret = miiphy_read(dev, phy_addr, 0x11, &value);
  262. if (ret > 0)
  263. goto error;
  264. mdelay(1);
  265. ret = miiphy_read(dev, phy_addr, 0x11, &value);
  266. if (ret > 0)
  267. goto error;
  268. mdelay(10);
  269. if ((value & 0xf) == 0xf) {
  270. printf("DPMAC %d :PHY is ..... Configured\n",
  271. dpmac);
  272. return;
  273. }
  274. }
  275. }
  276. error:
  277. printf("DPMAC %d :PHY ..... FAILED to configure PHY\n", dpmac);
  278. return;
  279. }
  280. static const char *ls2080a_qds_mdio_name_for_muxval(u8 muxval)
  281. {
  282. return mdio_names[muxval];
  283. }
  284. struct mii_dev *mii_dev_for_muxval(u8 muxval)
  285. {
  286. struct mii_dev *bus;
  287. const char *name = ls2080a_qds_mdio_name_for_muxval(muxval);
  288. if (!name) {
  289. printf("No bus for muxval %x\n", muxval);
  290. return NULL;
  291. }
  292. bus = miiphy_get_dev_by_name(name);
  293. if (!bus) {
  294. printf("No bus by name %s\n", name);
  295. return NULL;
  296. }
  297. return bus;
  298. }
  299. static void ls2080a_qds_enable_SFP_TX(u8 muxval)
  300. {
  301. u8 brdcfg9;
  302. brdcfg9 = QIXIS_READ(brdcfg[9]);
  303. brdcfg9 &= ~BRDCFG9_SFPTX_MASK;
  304. brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT);
  305. QIXIS_WRITE(brdcfg[9], brdcfg9);
  306. }
  307. static void ls2080a_qds_mux_mdio(u8 muxval)
  308. {
  309. u8 brdcfg4;
  310. if (muxval <= 5) {
  311. brdcfg4 = QIXIS_READ(brdcfg[4]);
  312. brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
  313. brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
  314. QIXIS_WRITE(brdcfg[4], brdcfg4);
  315. }
  316. }
  317. static int ls2080a_qds_mdio_read(struct mii_dev *bus, int addr,
  318. int devad, int regnum)
  319. {
  320. struct ls2080a_qds_mdio *priv = bus->priv;
  321. ls2080a_qds_mux_mdio(priv->muxval);
  322. return priv->realbus->read(priv->realbus, addr, devad, regnum);
  323. }
  324. static int ls2080a_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
  325. int regnum, u16 value)
  326. {
  327. struct ls2080a_qds_mdio *priv = bus->priv;
  328. ls2080a_qds_mux_mdio(priv->muxval);
  329. return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
  330. }
  331. static int ls2080a_qds_mdio_reset(struct mii_dev *bus)
  332. {
  333. struct ls2080a_qds_mdio *priv = bus->priv;
  334. return priv->realbus->reset(priv->realbus);
  335. }
  336. static int ls2080a_qds_mdio_init(char *realbusname, u8 muxval)
  337. {
  338. struct ls2080a_qds_mdio *pmdio;
  339. struct mii_dev *bus = mdio_alloc();
  340. if (!bus) {
  341. printf("Failed to allocate ls2080a_qds MDIO bus\n");
  342. return -1;
  343. }
  344. pmdio = malloc(sizeof(*pmdio));
  345. if (!pmdio) {
  346. printf("Failed to allocate ls2080a_qds private data\n");
  347. free(bus);
  348. return -1;
  349. }
  350. bus->read = ls2080a_qds_mdio_read;
  351. bus->write = ls2080a_qds_mdio_write;
  352. bus->reset = ls2080a_qds_mdio_reset;
  353. strcpy(bus->name, ls2080a_qds_mdio_name_for_muxval(muxval));
  354. pmdio->realbus = miiphy_get_dev_by_name(realbusname);
  355. if (!pmdio->realbus) {
  356. printf("No bus with name %s\n", realbusname);
  357. free(bus);
  358. free(pmdio);
  359. return -1;
  360. }
  361. pmdio->muxval = muxval;
  362. bus->priv = pmdio;
  363. return mdio_register(bus);
  364. }
  365. /*
  366. * Initialize the dpmac_info array.
  367. *
  368. */
  369. static void initialize_dpmac_to_slot(void)
  370. {
  371. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  372. int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
  373. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
  374. >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  375. int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
  376. FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
  377. >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
  378. char *env_hwconfig;
  379. env_hwconfig = getenv("hwconfig");
  380. switch (serdes1_prtcl) {
  381. case 0x07:
  382. case 0x09:
  383. case 0x33:
  384. printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
  385. serdes1_prtcl);
  386. lane_to_slot_fsm1[0] = EMI1_SLOT1;
  387. lane_to_slot_fsm1[1] = EMI1_SLOT1;
  388. lane_to_slot_fsm1[2] = EMI1_SLOT1;
  389. lane_to_slot_fsm1[3] = EMI1_SLOT1;
  390. if (hwconfig_f("xqsgmii", env_hwconfig)) {
  391. lane_to_slot_fsm1[4] = EMI1_SLOT1;
  392. lane_to_slot_fsm1[5] = EMI1_SLOT1;
  393. lane_to_slot_fsm1[6] = EMI1_SLOT1;
  394. lane_to_slot_fsm1[7] = EMI1_SLOT1;
  395. } else {
  396. lane_to_slot_fsm1[4] = EMI1_SLOT2;
  397. lane_to_slot_fsm1[5] = EMI1_SLOT2;
  398. lane_to_slot_fsm1[6] = EMI1_SLOT2;
  399. lane_to_slot_fsm1[7] = EMI1_SLOT2;
  400. }
  401. break;
  402. case 0x39:
  403. printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
  404. serdes1_prtcl);
  405. if (hwconfig_f("xqsgmii", env_hwconfig)) {
  406. lane_to_slot_fsm1[0] = EMI1_SLOT3;
  407. lane_to_slot_fsm1[1] = EMI1_SLOT3;
  408. lane_to_slot_fsm1[2] = EMI1_SLOT3;
  409. lane_to_slot_fsm1[3] = EMI_NONE;
  410. } else {
  411. lane_to_slot_fsm1[0] = EMI_NONE;
  412. lane_to_slot_fsm1[1] = EMI_NONE;
  413. lane_to_slot_fsm1[2] = EMI_NONE;
  414. lane_to_slot_fsm1[3] = EMI_NONE;
  415. }
  416. lane_to_slot_fsm1[4] = EMI1_SLOT3;
  417. lane_to_slot_fsm1[5] = EMI1_SLOT3;
  418. lane_to_slot_fsm1[6] = EMI1_SLOT3;
  419. lane_to_slot_fsm1[7] = EMI_NONE;
  420. break;
  421. case 0x4D:
  422. printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
  423. serdes1_prtcl);
  424. if (hwconfig_f("xqsgmii", env_hwconfig)) {
  425. lane_to_slot_fsm1[0] = EMI1_SLOT3;
  426. lane_to_slot_fsm1[1] = EMI1_SLOT3;
  427. lane_to_slot_fsm1[2] = EMI_NONE;
  428. lane_to_slot_fsm1[3] = EMI_NONE;
  429. } else {
  430. lane_to_slot_fsm1[0] = EMI_NONE;
  431. lane_to_slot_fsm1[1] = EMI_NONE;
  432. lane_to_slot_fsm1[2] = EMI_NONE;
  433. lane_to_slot_fsm1[3] = EMI_NONE;
  434. }
  435. lane_to_slot_fsm1[4] = EMI1_SLOT3;
  436. lane_to_slot_fsm1[5] = EMI1_SLOT3;
  437. lane_to_slot_fsm1[6] = EMI_NONE;
  438. lane_to_slot_fsm1[7] = EMI_NONE;
  439. break;
  440. case 0x2A:
  441. case 0x4B:
  442. case 0x4C:
  443. printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
  444. serdes1_prtcl);
  445. break;
  446. default:
  447. printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
  448. __func__, serdes1_prtcl);
  449. break;
  450. }
  451. switch (serdes2_prtcl) {
  452. case 0x07:
  453. case 0x08:
  454. case 0x09:
  455. case 0x49:
  456. printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n",
  457. serdes2_prtcl);
  458. lane_to_slot_fsm2[0] = EMI1_SLOT4;
  459. lane_to_slot_fsm2[1] = EMI1_SLOT4;
  460. lane_to_slot_fsm2[2] = EMI1_SLOT4;
  461. lane_to_slot_fsm2[3] = EMI1_SLOT4;
  462. if (hwconfig_f("xqsgmii", env_hwconfig)) {
  463. lane_to_slot_fsm2[4] = EMI1_SLOT4;
  464. lane_to_slot_fsm2[5] = EMI1_SLOT4;
  465. lane_to_slot_fsm2[6] = EMI1_SLOT4;
  466. lane_to_slot_fsm2[7] = EMI1_SLOT4;
  467. } else {
  468. /* No MDIO physical connection */
  469. lane_to_slot_fsm2[4] = EMI1_SLOT6;
  470. lane_to_slot_fsm2[5] = EMI1_SLOT6;
  471. lane_to_slot_fsm2[6] = EMI1_SLOT6;
  472. lane_to_slot_fsm2[7] = EMI1_SLOT6;
  473. }
  474. break;
  475. case 0x47:
  476. printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n",
  477. serdes2_prtcl);
  478. lane_to_slot_fsm2[0] = EMI_NONE;
  479. lane_to_slot_fsm2[1] = EMI1_SLOT5;
  480. lane_to_slot_fsm2[2] = EMI1_SLOT5;
  481. lane_to_slot_fsm2[3] = EMI1_SLOT5;
  482. if (hwconfig_f("xqsgmii", env_hwconfig)) {
  483. lane_to_slot_fsm2[4] = EMI_NONE;
  484. lane_to_slot_fsm2[5] = EMI1_SLOT5;
  485. lane_to_slot_fsm2[6] = EMI1_SLOT5;
  486. lane_to_slot_fsm2[7] = EMI1_SLOT5;
  487. }
  488. break;
  489. case 0x57:
  490. printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n",
  491. serdes2_prtcl);
  492. if (hwconfig_f("xqsgmii", env_hwconfig)) {
  493. lane_to_slot_fsm2[0] = EMI_NONE;
  494. lane_to_slot_fsm2[1] = EMI_NONE;
  495. lane_to_slot_fsm2[2] = EMI_NONE;
  496. lane_to_slot_fsm2[3] = EMI_NONE;
  497. }
  498. lane_to_slot_fsm2[4] = EMI_NONE;
  499. lane_to_slot_fsm2[5] = EMI_NONE;
  500. lane_to_slot_fsm2[6] = EMI1_SLOT5;
  501. lane_to_slot_fsm2[7] = EMI1_SLOT5;
  502. break;
  503. default:
  504. printf(" %s qds: WRIOP: Unsupported SerDes2 Protocol 0x%02x\n",
  505. __func__ , serdes2_prtcl);
  506. break;
  507. }
  508. }
  509. void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
  510. {
  511. int lane, slot;
  512. struct mii_dev *bus;
  513. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  514. int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
  515. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
  516. >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  517. int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
  518. FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
  519. >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
  520. int *riser_phy_addr;
  521. char *env_hwconfig = getenv("hwconfig");
  522. if (hwconfig_f("xqsgmii", env_hwconfig))
  523. riser_phy_addr = &xqsgii_riser_phy_addr[0];
  524. else
  525. riser_phy_addr = &sgmii_riser_phy_addr[0];
  526. if (dpmac_id > WRIOP1_DPMAC9)
  527. goto serdes2;
  528. switch (serdes1_prtcl) {
  529. case 0x07:
  530. case 0x39:
  531. case 0x4D:
  532. lane = serdes_get_first_lane(FSL_SRDS_1, SGMII1 + dpmac_id - 1);
  533. slot = lane_to_slot_fsm1[lane];
  534. switch (++slot) {
  535. case 1:
  536. /* Slot housing a SGMII riser card? */
  537. wriop_set_phy_address(dpmac_id,
  538. riser_phy_addr[dpmac_id - 1]);
  539. dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
  540. bus = mii_dev_for_muxval(EMI1_SLOT1);
  541. wriop_set_mdio(dpmac_id, bus);
  542. break;
  543. case 2:
  544. /* Slot housing a SGMII riser card? */
  545. wriop_set_phy_address(dpmac_id,
  546. riser_phy_addr[dpmac_id - 1]);
  547. dpmac_info[dpmac_id].board_mux = EMI1_SLOT2;
  548. bus = mii_dev_for_muxval(EMI1_SLOT2);
  549. wriop_set_mdio(dpmac_id, bus);
  550. break;
  551. case 3:
  552. if (slot == EMI_NONE)
  553. return;
  554. if (serdes1_prtcl == 0x39) {
  555. wriop_set_phy_address(dpmac_id,
  556. riser_phy_addr[dpmac_id - 2]);
  557. if (dpmac_id >= 6 && hwconfig_f("xqsgmii",
  558. env_hwconfig))
  559. wriop_set_phy_address(dpmac_id,
  560. riser_phy_addr[dpmac_id - 3]);
  561. } else {
  562. wriop_set_phy_address(dpmac_id,
  563. riser_phy_addr[dpmac_id - 2]);
  564. if (dpmac_id >= 7 && hwconfig_f("xqsgmii",
  565. env_hwconfig))
  566. wriop_set_phy_address(dpmac_id,
  567. riser_phy_addr[dpmac_id - 3]);
  568. }
  569. dpmac_info[dpmac_id].board_mux = EMI1_SLOT3;
  570. bus = mii_dev_for_muxval(EMI1_SLOT3);
  571. wriop_set_mdio(dpmac_id, bus);
  572. break;
  573. case 4:
  574. break;
  575. case 5:
  576. break;
  577. case 6:
  578. break;
  579. }
  580. break;
  581. default:
  582. printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
  583. __func__ , serdes1_prtcl);
  584. break;
  585. }
  586. serdes2:
  587. switch (serdes2_prtcl) {
  588. case 0x07:
  589. case 0x08:
  590. case 0x49:
  591. case 0x47:
  592. case 0x57:
  593. lane = serdes_get_first_lane(FSL_SRDS_2, SGMII9 +
  594. (dpmac_id - 9));
  595. slot = lane_to_slot_fsm2[lane];
  596. switch (++slot) {
  597. case 1:
  598. break;
  599. case 3:
  600. break;
  601. case 4:
  602. /* Slot housing a SGMII riser card? */
  603. wriop_set_phy_address(dpmac_id,
  604. riser_phy_addr[dpmac_id - 9]);
  605. dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
  606. bus = mii_dev_for_muxval(EMI1_SLOT4);
  607. wriop_set_mdio(dpmac_id, bus);
  608. break;
  609. case 5:
  610. if (slot == EMI_NONE)
  611. return;
  612. if (serdes2_prtcl == 0x47) {
  613. wriop_set_phy_address(dpmac_id,
  614. riser_phy_addr[dpmac_id - 10]);
  615. if (dpmac_id >= 14 && hwconfig_f("xqsgmii",
  616. env_hwconfig))
  617. wriop_set_phy_address(dpmac_id,
  618. riser_phy_addr[dpmac_id - 11]);
  619. } else {
  620. wriop_set_phy_address(dpmac_id,
  621. riser_phy_addr[dpmac_id - 11]);
  622. }
  623. dpmac_info[dpmac_id].board_mux = EMI1_SLOT5;
  624. bus = mii_dev_for_muxval(EMI1_SLOT5);
  625. wriop_set_mdio(dpmac_id, bus);
  626. break;
  627. case 6:
  628. /* Slot housing a SGMII riser card? */
  629. wriop_set_phy_address(dpmac_id,
  630. riser_phy_addr[dpmac_id - 13]);
  631. dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
  632. bus = mii_dev_for_muxval(EMI1_SLOT6);
  633. wriop_set_mdio(dpmac_id, bus);
  634. break;
  635. }
  636. break;
  637. default:
  638. printf("%s qds: WRIOP: Unsupported SerDes2 Protocol 0x%02x\n",
  639. __func__, serdes2_prtcl);
  640. break;
  641. }
  642. }
  643. void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
  644. {
  645. int lane = 0, slot;
  646. struct mii_dev *bus;
  647. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  648. int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
  649. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
  650. >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  651. switch (serdes1_prtcl) {
  652. case 0x33:
  653. switch (dpmac_id) {
  654. case 1:
  655. case 2:
  656. case 3:
  657. case 4:
  658. lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_A);
  659. break;
  660. case 5:
  661. case 6:
  662. case 7:
  663. case 8:
  664. lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_B);
  665. break;
  666. case 9:
  667. case 10:
  668. case 11:
  669. case 12:
  670. lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_C);
  671. break;
  672. case 13:
  673. case 14:
  674. case 15:
  675. case 16:
  676. lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_D);
  677. break;
  678. }
  679. slot = lane_to_slot_fsm1[lane];
  680. switch (++slot) {
  681. case 1:
  682. /* Slot housing a QSGMII riser card? */
  683. wriop_set_phy_address(dpmac_id, dpmac_id - 1);
  684. dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
  685. bus = mii_dev_for_muxval(EMI1_SLOT1);
  686. wriop_set_mdio(dpmac_id, bus);
  687. break;
  688. case 3:
  689. break;
  690. case 4:
  691. break;
  692. case 5:
  693. break;
  694. case 6:
  695. break;
  696. }
  697. break;
  698. default:
  699. printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
  700. serdes1_prtcl);
  701. break;
  702. }
  703. qsgmii_configure_repeater(dpmac_id);
  704. }
  705. void ls2080a_handle_phy_interface_xsgmii(int i)
  706. {
  707. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  708. int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
  709. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
  710. >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  711. switch (serdes1_prtcl) {
  712. case 0x2A:
  713. case 0x4B:
  714. case 0x4C:
  715. /*
  716. * XFI does not need a PHY to work, but to avoid U-Boot use
  717. * default PHY address which is zero to a MAC when it found
  718. * a MAC has no PHY address, we give a PHY address to XFI
  719. * MAC, and should not use a real XAUI PHY address, since
  720. * MDIO can access it successfully, and then MDIO thinks
  721. * the XAUI card is used for the XFI MAC, which will cause
  722. * error.
  723. */
  724. wriop_set_phy_address(i, i + 4);
  725. ls2080a_qds_enable_SFP_TX(SFP_TX);
  726. break;
  727. default:
  728. printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
  729. serdes1_prtcl);
  730. break;
  731. }
  732. }
  733. #endif
  734. int board_eth_init(bd_t *bis)
  735. {
  736. int error;
  737. char *mc_boot_env_var;
  738. #ifdef CONFIG_FSL_MC_ENET
  739. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  740. int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
  741. FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
  742. >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
  743. int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
  744. FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
  745. >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
  746. struct memac_mdio_info *memac_mdio0_info;
  747. struct memac_mdio_info *memac_mdio1_info;
  748. unsigned int i;
  749. char *env_hwconfig;
  750. env_hwconfig = getenv("hwconfig");
  751. initialize_dpmac_to_slot();
  752. memac_mdio0_info = (struct memac_mdio_info *)malloc(
  753. sizeof(struct memac_mdio_info));
  754. memac_mdio0_info->regs =
  755. (struct memac_mdio_controller *)
  756. CONFIG_SYS_FSL_WRIOP1_MDIO1;
  757. memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
  758. /* Register the real MDIO1 bus */
  759. fm_memac_mdio_init(bis, memac_mdio0_info);
  760. memac_mdio1_info = (struct memac_mdio_info *)malloc(
  761. sizeof(struct memac_mdio_info));
  762. memac_mdio1_info->regs =
  763. (struct memac_mdio_controller *)
  764. CONFIG_SYS_FSL_WRIOP1_MDIO2;
  765. memac_mdio1_info->name = DEFAULT_WRIOP_MDIO2_NAME;
  766. /* Register the real MDIO2 bus */
  767. fm_memac_mdio_init(bis, memac_mdio1_info);
  768. /* Register the muxing front-ends to the MDIO buses */
  769. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
  770. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT2);
  771. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT3);
  772. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT4);
  773. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT5);
  774. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT6);
  775. ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO2_NAME, EMI2);
  776. for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
  777. switch (wriop_get_enet_if(i)) {
  778. case PHY_INTERFACE_MODE_QSGMII:
  779. ls2080a_handle_phy_interface_qsgmii(i);
  780. break;
  781. case PHY_INTERFACE_MODE_SGMII:
  782. ls2080a_handle_phy_interface_sgmii(i);
  783. break;
  784. case PHY_INTERFACE_MODE_XGMII:
  785. ls2080a_handle_phy_interface_xsgmii(i);
  786. break;
  787. default:
  788. break;
  789. if (i == 16)
  790. i = NUM_WRIOP_PORTS;
  791. }
  792. }
  793. mc_boot_env_var = getenv(MC_BOOT_ENV_VAR);
  794. if (mc_boot_env_var)
  795. run_command_list(mc_boot_env_var, -1, 0);
  796. error = cpu_eth_init(bis);
  797. if (hwconfig_f("xqsgmii", env_hwconfig)) {
  798. if (serdes1_prtcl == 0x7)
  799. sgmii_configure_repeater(1);
  800. if (serdes2_prtcl == 0x7 || serdes2_prtcl == 0x8 ||
  801. serdes2_prtcl == 0x49)
  802. sgmii_configure_repeater(2);
  803. }
  804. #endif
  805. error = pci_eth_init(bis);
  806. return error;
  807. }
  808. #ifdef CONFIG_FSL_MC_ENET
  809. #endif