eth.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <command.h>
  24. #include <netdev.h>
  25. #include <asm/mmu.h>
  26. #include <asm/processor.h>
  27. #include <asm/cache.h>
  28. #include <asm/immap_85xx.h>
  29. #include <asm/fsl_law.h>
  30. #include <asm/fsl_ddr_sdram.h>
  31. #include <asm/fsl_serdes.h>
  32. #include <asm/fsl_portals.h>
  33. #include <asm/fsl_liodn.h>
  34. #include <malloc.h>
  35. #include <fm_eth.h>
  36. #include <fsl_mdio.h>
  37. #include <miiphy.h>
  38. #include <phy.h>
  39. #include <asm/fsl_dtsec.h>
  40. #include "../common/qixis.h"
  41. #include "../common/fman.h"
  42. #include "p3060qds_qixis.h"
  43. #define EMI_NONE 0xffffffff
  44. #define EMI1_RGMII1 0
  45. #define EMI1_SLOT1 1
  46. #define EMI1_SLOT2 2
  47. #define EMI1_SLOT3 3
  48. #define EMI1_RGMII2 4
  49. static int mdio_mux[NUM_FM_PORTS];
  50. static char *mdio_names[5] = {
  51. "P3060QDS_MDIO0",
  52. "P3060QDS_MDIO1",
  53. "P3060QDS_MDIO2",
  54. "P3060QDS_MDIO3",
  55. "P3060QDS_MDIO4",
  56. };
  57. /*
  58. * Mapping of all 18 SERDES lanes to board slots.
  59. * A value of '0' here means that the mapping must be determined
  60. * dynamically, Lane 8/9/16/17 map to Slot1 or Aurora debug
  61. */
  62. static u8 lane_to_slot[] = {
  63. 4, 4, 4, 4, 3, 3, 3, 3, 0, 0, 2, 2, 2, 2, 1, 1, 0, 0
  64. };
  65. static char *p3060qds_mdio_name_for_muxval(u32 muxval)
  66. {
  67. return mdio_names[muxval];
  68. }
  69. struct mii_dev *mii_dev_for_muxval(u32 muxval)
  70. {
  71. struct mii_dev *bus;
  72. char *name = p3060qds_mdio_name_for_muxval(muxval);
  73. if (!name) {
  74. printf("No bus for muxval %x\n", muxval);
  75. return NULL;
  76. }
  77. bus = miiphy_get_dev_by_name(name);
  78. if (!bus) {
  79. printf("No bus by name %s\n", name);
  80. return NULL;
  81. }
  82. return bus;
  83. }
  84. struct p3060qds_mdio {
  85. u32 muxval;
  86. struct mii_dev *realbus;
  87. };
  88. static void p3060qds_mux_mdio(u32 muxval)
  89. {
  90. u8 brdcfg4;
  91. brdcfg4 = QIXIS_READ(brdcfg[4]);
  92. brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
  93. brdcfg4 |= (muxval << 4);
  94. QIXIS_WRITE(brdcfg[4], brdcfg4);
  95. }
  96. static int p3060qds_mdio_read(struct mii_dev *bus, int addr, int devad,
  97. int regnum)
  98. {
  99. struct p3060qds_mdio *priv = bus->priv;
  100. p3060qds_mux_mdio(priv->muxval);
  101. return priv->realbus->read(priv->realbus, addr, devad, regnum);
  102. }
  103. static int p3060qds_mdio_write(struct mii_dev *bus, int addr, int devad,
  104. int regnum, u16 value)
  105. {
  106. struct p3060qds_mdio *priv = bus->priv;
  107. p3060qds_mux_mdio(priv->muxval);
  108. return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
  109. }
  110. static int p3060qds_mdio_reset(struct mii_dev *bus)
  111. {
  112. struct p3060qds_mdio *priv = bus->priv;
  113. return priv->realbus->reset(priv->realbus);
  114. }
  115. static int p3060qds_mdio_init(char *realbusname, u32 muxval)
  116. {
  117. struct p3060qds_mdio *pmdio;
  118. struct mii_dev *bus = mdio_alloc();
  119. if (!bus) {
  120. printf("Failed to allocate P3060QDS MDIO bus\n");
  121. return -1;
  122. }
  123. pmdio = malloc(sizeof(*pmdio));
  124. if (!pmdio) {
  125. printf("Failed to allocate P3060QDS private data\n");
  126. free(bus);
  127. return -1;
  128. }
  129. bus->read = p3060qds_mdio_read;
  130. bus->write = p3060qds_mdio_write;
  131. bus->reset = p3060qds_mdio_reset;
  132. sprintf(bus->name, p3060qds_mdio_name_for_muxval(muxval));
  133. pmdio->realbus = miiphy_get_dev_by_name(realbusname);
  134. if (!pmdio->realbus) {
  135. printf("No bus with name %s\n", realbusname);
  136. free(bus);
  137. free(pmdio);
  138. return -1;
  139. }
  140. pmdio->muxval = muxval;
  141. bus->priv = pmdio;
  142. return mdio_register(bus);
  143. }
  144. void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa,
  145. enum fm_port port, int offset)
  146. {
  147. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  148. int srds_prtcl = (in_be32(&gur->rcwsr[4]) &
  149. FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
  150. if (mdio_mux[port] == EMI1_RGMII1)
  151. fdt_set_phy_handle(blob, prop, pa, "phy_rgmii1");
  152. if (mdio_mux[port] == EMI1_RGMII2)
  153. fdt_set_phy_handle(blob, prop, pa, "phy_rgmii2");
  154. if ((mdio_mux[port] == EMI1_SLOT1) && ((srds_prtcl == 0x3)
  155. || (srds_prtcl == 0x6))) {
  156. switch (port) {
  157. case FM2_DTSEC4:
  158. fdt_set_phy_handle(blob, prop, pa, "phy2_slot1");
  159. break;
  160. case FM1_DTSEC4:
  161. fdt_set_phy_handle(blob, prop, pa, "phy3_slot1");
  162. break;
  163. default:
  164. break;
  165. }
  166. }
  167. if (mdio_mux[port] == EMI1_SLOT3) {
  168. switch (port) {
  169. case FM2_DTSEC3:
  170. fdt_set_phy_handle(blob, prop, pa, "phy0_slot3");
  171. break;
  172. case FM1_DTSEC3:
  173. fdt_set_phy_handle(blob, prop, pa, "phy1_slot3");
  174. break;
  175. default:
  176. break;
  177. }
  178. }
  179. }
  180. void fdt_fixup_board_enet(void *fdt)
  181. {
  182. int i, lane, idx;
  183. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  184. idx = i - FM1_DTSEC1;
  185. switch (fm_info_get_enet_if(i)) {
  186. case PHY_INTERFACE_MODE_SGMII:
  187. lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
  188. if (lane < 0)
  189. break;
  190. switch (mdio_mux[i]) {
  191. case EMI1_SLOT1:
  192. if (lane >= 14) {
  193. fdt_status_okay_by_alias(fdt,
  194. "emi1_slot1");
  195. fdt_status_disabled_by_alias(fdt,
  196. "emi1_slot1_bk1");
  197. } else {
  198. fdt_status_disabled_by_alias(fdt,
  199. "emi1_slot1");
  200. fdt_status_okay_by_alias(fdt,
  201. "emi1_slot1_bk1");
  202. }
  203. break;
  204. case EMI1_SLOT2:
  205. fdt_status_okay_by_alias(fdt, "emi1_slot2");
  206. break;
  207. case EMI1_SLOT3:
  208. fdt_status_okay_by_alias(fdt, "emi1_slot3");
  209. break;
  210. }
  211. break;
  212. case PHY_INTERFACE_MODE_RGMII:
  213. if (i == FM1_DTSEC1)
  214. fdt_status_okay_by_alias(fdt, "emi1_rgmii1");
  215. if (i == FM1_DTSEC2)
  216. fdt_status_okay_by_alias(fdt, "emi1_rgmii2");
  217. break;
  218. default:
  219. break;
  220. }
  221. }
  222. #if (CONFIG_SYS_NUM_FMAN == 2)
  223. for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
  224. idx = i - FM2_DTSEC1;
  225. switch (fm_info_get_enet_if(i)) {
  226. case PHY_INTERFACE_MODE_SGMII:
  227. lane = serdes_get_first_lane(SGMII_FM2_DTSEC1 + idx);
  228. if (lane >= 0) {
  229. switch (mdio_mux[i]) {
  230. case EMI1_SLOT1:
  231. if (lane >= 14)
  232. fdt_status_okay_by_alias(fdt,
  233. "emi1_slot1");
  234. else
  235. fdt_status_okay_by_alias(fdt,
  236. "emi1_slot1_bk1");
  237. break;
  238. case EMI1_SLOT2:
  239. fdt_status_okay_by_alias(fdt,
  240. "emi1_slot2");
  241. break;
  242. case EMI1_SLOT3:
  243. fdt_status_okay_by_alias(fdt,
  244. "emi1_slot3");
  245. break;
  246. }
  247. }
  248. break;
  249. default:
  250. break;
  251. }
  252. }
  253. #endif
  254. }
  255. static void initialize_lane_to_slot(void)
  256. {
  257. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  258. int sdprtl = (in_be32(&gur->rcwsr[4]) &
  259. FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
  260. switch (sdprtl) {
  261. case 0x03:
  262. case 0x06:
  263. lane_to_slot[8] = 1;
  264. lane_to_slot[9] = lane_to_slot[8];
  265. lane_to_slot[16] = 5;
  266. lane_to_slot[17] = lane_to_slot[16];
  267. break;
  268. case 0x16:
  269. case 0x19:
  270. case 0x1C:
  271. lane_to_slot[8] = 5;
  272. lane_to_slot[9] = lane_to_slot[8];
  273. lane_to_slot[16] = 1;
  274. lane_to_slot[17] = lane_to_slot[16];
  275. break;
  276. default:
  277. puts("Invalid SerDes protocol for P3060QDS\n");
  278. break;
  279. }
  280. }
  281. int board_eth_init(bd_t *bis)
  282. {
  283. #ifdef CONFIG_FMAN_ENET
  284. struct dtsec *tsec = (void *)CONFIG_SYS_FSL_FM1_DTSEC1_ADDR;
  285. int i;
  286. struct fsl_pq_mdio_info dtsec_mdio_info;
  287. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  288. int srds_cfg = (in_be32(&gur->rcwsr[4]) &
  289. FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
  290. initialize_lane_to_slot();
  291. /*
  292. * Set TBIPA on FM1@DTSEC1. This is needed for configurations
  293. * where FM1@DTSEC1 isn't used directly, since it provides
  294. * MDIO for other ports.
  295. */
  296. out_be32(&tsec->tbipa, CONFIG_SYS_TBIPA_VALUE);
  297. /* Initialize the mdio_mux array so we can recognize empty elements */
  298. for (i = 0; i < NUM_FM_PORTS; i++)
  299. mdio_mux[i] = EMI_NONE;
  300. dtsec_mdio_info.regs =
  301. (struct tsec_mii_mng *)CONFIG_SYS_FM1_DTSEC1_MDIO_ADDR;
  302. dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
  303. /* Register the 1G MDIO bus */
  304. fsl_pq_mdio_init(bis, &dtsec_mdio_info);
  305. /* Register the 5 muxing front-ends to the MDIO buses */
  306. if (fm_info_get_enet_if(FM1_DTSEC1) == PHY_INTERFACE_MODE_RGMII)
  307. p3060qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII1);
  308. if (fm_info_get_enet_if(FM1_DTSEC2) == PHY_INTERFACE_MODE_RGMII)
  309. p3060qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII2);
  310. p3060qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT1);
  311. p3060qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT2);
  312. p3060qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT3);
  313. if (fm_info_get_enet_if(FM1_DTSEC1) == PHY_INTERFACE_MODE_RGMII)
  314. fm_info_set_phy_address(FM1_DTSEC1, 1); /* RGMII1 */
  315. else if (fm_info_get_enet_if(FM1_DTSEC1) == PHY_INTERFACE_MODE_SGMII)
  316. fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT2_PHY_ADDR);
  317. if (fm_info_get_enet_if(FM1_DTSEC2) == PHY_INTERFACE_MODE_RGMII)
  318. fm_info_set_phy_address(FM1_DTSEC2, 2); /* RGMII2 */
  319. else if (fm_info_get_enet_if(FM1_DTSEC2) == PHY_INTERFACE_MODE_SGMII)
  320. fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
  321. fm_info_set_phy_address(FM2_DTSEC1, SGMII_CARD_PORT1_PHY_ADDR);
  322. fm_info_set_phy_address(FM2_DTSEC2, SGMII_CARD_PORT3_PHY_ADDR);
  323. switch (srds_cfg) {
  324. case 0x03:
  325. case 0x06:
  326. fm_info_set_phy_address(FM2_DTSEC3, SGMII_CARD_PORT3_PHY_ADDR);
  327. fm_info_set_phy_address(FM1_DTSEC3, SGMII_CARD_PORT4_PHY_ADDR);
  328. fm_info_set_phy_address(FM2_DTSEC4, SGMII_CARD_PORT1_PHY_ADDR);
  329. fm_info_set_phy_address(FM1_DTSEC4, SGMII_CARD_PORT2_PHY_ADDR);
  330. break;
  331. case 0x16:
  332. case 0x19:
  333. case 0x1C:
  334. fm_info_set_phy_address(FM2_DTSEC3, SGMII_CARD_PORT1_PHY_ADDR);
  335. fm_info_set_phy_address(FM1_DTSEC3, SGMII_CARD_PORT2_PHY_ADDR);
  336. fm_info_set_phy_address(FM2_DTSEC4, SGMII_CARD_PORT3_PHY_ADDR);
  337. fm_info_set_phy_address(FM1_DTSEC4, SGMII_CARD_PORT4_PHY_ADDR);
  338. break;
  339. default:
  340. puts("Invalid SerDes protocol for P3060QDS\n");
  341. break;
  342. }
  343. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  344. int idx = i - FM1_DTSEC1, lane, slot;
  345. switch (fm_info_get_enet_if(i)) {
  346. case PHY_INTERFACE_MODE_SGMII:
  347. lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
  348. if (lane < 0)
  349. break;
  350. slot = lane_to_slot[lane];
  351. if (QIXIS_READ(present) & (1 << (slot - 1)))
  352. fm_disable_port(i);
  353. switch (slot) {
  354. case 1:
  355. mdio_mux[i] = EMI1_SLOT1;
  356. fm_info_set_mdio(i,
  357. mii_dev_for_muxval(mdio_mux[i]));
  358. break;
  359. case 2:
  360. mdio_mux[i] = EMI1_SLOT2;
  361. fm_info_set_mdio(i,
  362. mii_dev_for_muxval(mdio_mux[i]));
  363. break;
  364. case 3:
  365. mdio_mux[i] = EMI1_SLOT3;
  366. fm_info_set_mdio(i,
  367. mii_dev_for_muxval(mdio_mux[i]));
  368. break;
  369. };
  370. break;
  371. case PHY_INTERFACE_MODE_RGMII:
  372. if (i == FM1_DTSEC1) {
  373. mdio_mux[i] = EMI1_RGMII1;
  374. fm_info_set_mdio(i,
  375. mii_dev_for_muxval(mdio_mux[i]));
  376. } else if (i == FM1_DTSEC2) {
  377. mdio_mux[i] = EMI1_RGMII2;
  378. fm_info_set_mdio(i,
  379. mii_dev_for_muxval(mdio_mux[i]));
  380. }
  381. break;
  382. default:
  383. break;
  384. }
  385. }
  386. #if (CONFIG_SYS_NUM_FMAN == 2)
  387. for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
  388. int idx = i - FM2_DTSEC1, lane, slot;
  389. switch (fm_info_get_enet_if(i)) {
  390. case PHY_INTERFACE_MODE_SGMII:
  391. lane = serdes_get_first_lane(SGMII_FM2_DTSEC1 + idx);
  392. if (lane < 0)
  393. break;
  394. slot = lane_to_slot[lane];
  395. if (QIXIS_READ(present) & (1 << (slot - 1)))
  396. fm_disable_port(i);
  397. switch (slot) {
  398. case 1:
  399. mdio_mux[i] = EMI1_SLOT1;
  400. fm_info_set_mdio(i,
  401. mii_dev_for_muxval(mdio_mux[i]));
  402. break;
  403. case 2:
  404. mdio_mux[i] = EMI1_SLOT2;
  405. fm_info_set_mdio(i,
  406. mii_dev_for_muxval(mdio_mux[i]));
  407. break;
  408. case 3:
  409. mdio_mux[i] = EMI1_SLOT3;
  410. fm_info_set_mdio(i,
  411. mii_dev_for_muxval(mdio_mux[i]));
  412. break;
  413. };
  414. break;
  415. default:
  416. break;
  417. }
  418. }
  419. #endif /* CONFIG_SYS_NUM_FMAN */
  420. cpu_eth_init(bis);
  421. #endif /* CONFIG_FMAN_ENET */
  422. return pci_eth_init(bis);
  423. }