eth_b4860qds.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /*
  2. * Copyright 2012 Freescale Semiconductor, Inc.
  3. * Author: Sandeep Kumar Singh <sandeep@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. /* This file is based on board/freescale/corenet_ds/eth_superhydra.c */
  24. /*
  25. * This file handles the board muxing between the Fman Ethernet MACs and
  26. * the RGMII/SGMII/XGMII PHYs on a Freescale B4860 "Centaur". The SGMII
  27. * PHYs are the two on-board 1Gb ports. There are no RGMII PHY on board.
  28. * The 10Gb XGMII PHY is provided via the XAUI riser card. There is only
  29. * one Fman device on B4860. The SERDES configuration is used to determine
  30. * where the SGMII and XAUI cards exist, and also which Fman MACs are routed
  31. * to which PHYs. So for a given Fman MAC, there is one and only PHY it
  32. * connects to. MACs cannot be routed to PHYs dynamically. This configuration
  33. * is done at boot time by reading SERDES protocol from RCW.
  34. */
  35. #include <common.h>
  36. #include <netdev.h>
  37. #include <asm/fsl_serdes.h>
  38. #include <fm_eth.h>
  39. #include <fsl_mdio.h>
  40. #include <malloc.h>
  41. #include <fdt_support.h>
  42. #include <asm/fsl_dtsec.h>
  43. #include "../common/ngpixis.h"
  44. #include "../common/fman.h"
  45. #include "../common/qixis.h"
  46. #include "b4860qds_qixis.h"
  47. #define EMI_NONE 0xFFFFFFFF
  48. #ifdef CONFIG_FMAN_ENET
  49. /*
  50. * Mapping of all 16 SERDES lanes to board slots. A value n(>0) will mean that
  51. * lane at index is mapped to slot number n. A value of '0' will mean
  52. * that the mapping must be determined dynamically, or that the lane maps to
  53. * something other than a board slot
  54. */
  55. static u8 lane_to_slot[] = {
  56. 0, 0, 0, 0,
  57. 0, 0, 0, 0,
  58. 1, 1, 1, 1,
  59. 0, 0, 0, 0
  60. };
  61. /*
  62. * This function initializes the lane_to_slot[] array. It reads RCW to check
  63. * if Serdes2{E,F,G,H} is configured as slot 2 or as SFP and initializes
  64. * lane_to_slot[] accordingly
  65. */
  66. static void initialize_lane_to_slot(void)
  67. {
  68. unsigned int serdes2_prtcl;
  69. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  70. serdes2_prtcl = in_be32(&gur->rcwsr[4]) &
  71. FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
  72. serdes2_prtcl >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
  73. debug("Initializing lane to slot: Serdes2 protocol: %x\n",
  74. serdes2_prtcl);
  75. switch (serdes2_prtcl) {
  76. case 0x18:
  77. /*
  78. * Configuration:
  79. * SERDES: 2
  80. * Lanes: A,B,C,D: SGMII
  81. * Lanes: E,F: Aur
  82. * Lanes: G,H: SRIO
  83. */
  84. case 0x91:
  85. /*
  86. * Configuration:
  87. * SERDES: 2
  88. * Lanes: A,B: SGMII
  89. * Lanes: C,D: SRIO2
  90. * Lanes: E,F,G,H: XAUI2
  91. */
  92. case 0x93:
  93. /*
  94. * Configuration:
  95. * SERDES: 2
  96. * Lanes: A,B,C,D: SGMII
  97. * Lanes: E,F,G,H: XAUI2
  98. */
  99. case 0x98:
  100. /*
  101. * Configuration:
  102. * SERDES: 2
  103. * Lanes: A,B,C,D: XAUI2
  104. * Lanes: E,F,G,H: XAUI2
  105. */
  106. case 0x9a:
  107. /*
  108. * Configuration:
  109. * SERDES: 2
  110. * Lanes: A,B: PCI
  111. * Lanes: C,D: SGMII
  112. * Lanes: E,F,G,H: XAUI2
  113. */
  114. case 0x9e:
  115. /*
  116. * Configuration:
  117. * SERDES: 2
  118. * Lanes: A,B,C,D: PCI
  119. * Lanes: E,F,G,H: XAUI2
  120. */
  121. case 0xb2:
  122. /*
  123. * Configuration:
  124. * SERDES: 2
  125. * Lanes: A,B,C,D: PCI
  126. * Lanes: E,F: SGMII 3&4
  127. * Lanes: G,H: XFI
  128. */
  129. case 0xc2:
  130. /*
  131. * Configuration:
  132. * SERDES: 2
  133. * Lanes: A,B: SGMII
  134. * Lanes: C,D: SRIO2
  135. * Lanes: E,F,G,H: XAUI2
  136. */
  137. lane_to_slot[12] = 2;
  138. lane_to_slot[13] = lane_to_slot[12];
  139. lane_to_slot[14] = lane_to_slot[12];
  140. lane_to_slot[15] = lane_to_slot[12];
  141. break;
  142. default:
  143. printf("Fman: Unsupported SerDes2 Protocol 0x%02x\n",
  144. serdes2_prtcl);
  145. break;
  146. }
  147. return;
  148. }
  149. #endif /* #ifdef CONFIG_FMAN_ENET */
  150. int board_eth_init(bd_t *bis)
  151. {
  152. #ifdef CONFIG_FMAN_ENET
  153. struct memac_mdio_info memac_mdio_info;
  154. struct memac_mdio_info tg_memac_mdio_info;
  155. unsigned int i;
  156. unsigned int serdes1_prtcl, serdes2_prtcl;
  157. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  158. serdes1_prtcl = in_be32(&gur->rcwsr[4]) &
  159. FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
  160. if (!serdes1_prtcl) {
  161. printf("SERDES1 is not enabled\n");
  162. return 0;
  163. }
  164. serdes1_prtcl >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
  165. debug("Using SERDES1 Protocol: 0x%x:\n", serdes1_prtcl);
  166. serdes2_prtcl = in_be32(&gur->rcwsr[4]) &
  167. FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
  168. if (!serdes2_prtcl) {
  169. printf("SERDES2 is not enabled\n");
  170. return 0;
  171. }
  172. serdes2_prtcl >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
  173. debug("Using SERDES2 Protocol: 0x%x:\n", serdes2_prtcl);
  174. printf("Initializing Fman\n");
  175. initialize_lane_to_slot();
  176. memac_mdio_info.regs =
  177. (struct memac_mdio_controller *)CONFIG_SYS_FM1_DTSEC_MDIO_ADDR;
  178. memac_mdio_info.name = DEFAULT_FM_MDIO_NAME;
  179. /* Register the real 1G MDIO bus */
  180. fm_memac_mdio_init(bis, &memac_mdio_info);
  181. tg_memac_mdio_info.regs =
  182. (struct memac_mdio_controller *)CONFIG_SYS_FM1_TGEC_MDIO_ADDR;
  183. tg_memac_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
  184. /* Register the real 10G MDIO bus */
  185. fm_memac_mdio_init(bis, &tg_memac_mdio_info);
  186. /*
  187. * Program the two on board DTSEC PHY addresses assuming that they are
  188. * all SGMII. RGMII is not supported on this board. Setting SGMII 5 and
  189. * 6 to on board SGMII phys
  190. */
  191. fm_info_set_phy_address(FM1_DTSEC5, CONFIG_SYS_FM1_DTSEC5_PHY_ADDR);
  192. fm_info_set_phy_address(FM1_DTSEC6, CONFIG_SYS_FM1_DTSEC6_PHY_ADDR);
  193. switch (serdes1_prtcl) {
  194. case 0x2a:
  195. /* Serdes 1: A-B SGMII, Configuring DTSEC 5 and 6 */
  196. debug("Setting phy addresses for FM1_DTSEC5: %x and"
  197. "FM1_DTSEC6: %x\n", CONFIG_SYS_FM1_DTSEC5_PHY_ADDR,
  198. CONFIG_SYS_FM1_DTSEC6_PHY_ADDR);
  199. /* Fixing Serdes clock by programming FPGA register */
  200. QIXIS_WRITE(brdcfg[4], QIXIS_SRDS1CLK_125);
  201. fm_info_set_phy_address(FM1_DTSEC5,
  202. CONFIG_SYS_FM1_DTSEC5_PHY_ADDR);
  203. fm_info_set_phy_address(FM1_DTSEC6,
  204. CONFIG_SYS_FM1_DTSEC6_PHY_ADDR);
  205. break;
  206. #ifdef CONFIG_PPC_B4420
  207. case 0x18:
  208. /* Serdes 1: A-D SGMII, Configuring on board dual SGMII Phy */
  209. debug("Setting phy addresses for FM1_DTSEC3: %x and"
  210. "FM1_DTSEC4: %x\n", CONFIG_SYS_FM1_DTSEC5_PHY_ADDR,
  211. CONFIG_SYS_FM1_DTSEC6_PHY_ADDR);
  212. /* Fixing Serdes clock by programming FPGA register */
  213. QIXIS_WRITE(brdcfg[4], QIXIS_SRDS1CLK_125);
  214. fm_info_set_phy_address(FM1_DTSEC3,
  215. CONFIG_SYS_FM1_DTSEC5_PHY_ADDR);
  216. fm_info_set_phy_address(FM1_DTSEC4,
  217. CONFIG_SYS_FM1_DTSEC6_PHY_ADDR);
  218. break;
  219. #endif
  220. default:
  221. printf("Fman: Unsupported SerDes1 Protocol 0x%02x\n",
  222. serdes1_prtcl);
  223. break;
  224. }
  225. switch (serdes2_prtcl) {
  226. case 0x18:
  227. debug("Setting phy addresses on SGMII Riser card for"
  228. "FM1_DTSEC ports: \n");
  229. fm_info_set_phy_address(FM1_DTSEC1,
  230. CONFIG_SYS_FM1_DTSEC1_RISER_PHY_ADDR);
  231. fm_info_set_phy_address(FM1_DTSEC2,
  232. CONFIG_SYS_FM1_DTSEC2_RISER_PHY_ADDR);
  233. fm_info_set_phy_address(FM1_DTSEC3,
  234. CONFIG_SYS_FM1_DTSEC3_RISER_PHY_ADDR);
  235. fm_info_set_phy_address(FM1_DTSEC4,
  236. CONFIG_SYS_FM1_DTSEC4_RISER_PHY_ADDR);
  237. break;
  238. case 0x49:
  239. debug("Setting phy addresses on SGMII Riser card for"
  240. "FM1_DTSEC ports: \n");
  241. fm_info_set_phy_address(FM1_DTSEC1,
  242. CONFIG_SYS_FM1_DTSEC1_RISER_PHY_ADDR);
  243. fm_info_set_phy_address(FM1_DTSEC2,
  244. CONFIG_SYS_FM1_DTSEC2_RISER_PHY_ADDR);
  245. fm_info_set_phy_address(FM1_DTSEC3,
  246. CONFIG_SYS_FM1_DTSEC3_RISER_PHY_ADDR);
  247. break;
  248. case 0x8d:
  249. case 0xb2:
  250. debug("Setting phy addresses on SGMII Riser card for"
  251. "FM1_DTSEC ports: \n");
  252. fm_info_set_phy_address(FM1_DTSEC3,
  253. CONFIG_SYS_FM1_DTSEC1_RISER_PHY_ADDR);
  254. fm_info_set_phy_address(FM1_DTSEC4,
  255. CONFIG_SYS_FM1_DTSEC2_RISER_PHY_ADDR);
  256. break;
  257. case 0x98:
  258. /* XAUI in Slot1 and Slot2 */
  259. debug("Setting phy addresses on B4860 QDS AMC2PEX-2S for FM1_10GEC1: %x\n",
  260. CONFIG_SYS_FM1_10GEC1_PHY_ADDR);
  261. fm_info_set_phy_address(FM1_10GEC1,
  262. CONFIG_SYS_FM1_10GEC1_PHY_ADDR);
  263. debug("Setting phy addresses on B4860 QDS AMC2PEX-2S for FM1_10GEC2: %x\n",
  264. CONFIG_SYS_FM1_10GEC2_PHY_ADDR);
  265. fm_info_set_phy_address(FM1_10GEC2,
  266. CONFIG_SYS_FM1_10GEC2_PHY_ADDR);
  267. break;
  268. case 0x9E:
  269. /* XAUI in Slot2 */
  270. debug("Setting phy addresses on B4860 QDS AMC2PEX-2S for FM1_10GEC2: %x\n",
  271. CONFIG_SYS_FM1_10GEC2_PHY_ADDR);
  272. fm_info_set_phy_address(FM1_10GEC2,
  273. CONFIG_SYS_FM1_10GEC2_PHY_ADDR);
  274. break;
  275. default:
  276. printf("Fman: Unsupported SerDes2 Protocol 0x%02x\n",
  277. serdes2_prtcl);
  278. break;
  279. }
  280. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  281. int idx = i - FM1_DTSEC1;
  282. switch (fm_info_get_enet_if(i)) {
  283. case PHY_INTERFACE_MODE_SGMII:
  284. fm_info_set_mdio(i,
  285. miiphy_get_dev_by_name(DEFAULT_FM_MDIO_NAME));
  286. break;
  287. case PHY_INTERFACE_MODE_NONE:
  288. fm_info_set_phy_address(i, 0);
  289. break;
  290. default:
  291. printf("Fman1: DTSEC%u set to unknown interface %i\n",
  292. idx + 1, fm_info_get_enet_if(i));
  293. fm_info_set_phy_address(i, 0);
  294. break;
  295. }
  296. }
  297. for (i = FM1_10GEC1; i < FM1_10GEC1 + CONFIG_SYS_NUM_FM1_10GEC; i++) {
  298. int idx = i - FM1_10GEC1;
  299. switch (fm_info_get_enet_if(i)) {
  300. case PHY_INTERFACE_MODE_XGMII:
  301. fm_info_set_mdio(i,
  302. miiphy_get_dev_by_name(DEFAULT_FM_TGEC_MDIO_NAME));
  303. break;
  304. default:
  305. printf("Fman1: 10GSEC%u set to unknown interface %i\n",
  306. idx + 1, fm_info_get_enet_if(i));
  307. fm_info_set_phy_address(i, 0);
  308. break;
  309. }
  310. }
  311. cpu_eth_init(bis);
  312. #endif
  313. return pci_eth_init(bis);
  314. }
  315. void board_ft_fman_fixup_port(void *fdt, char *compat, phys_addr_t addr,
  316. enum fm_port port, int offset)
  317. {
  318. int phy;
  319. char alias[32];
  320. if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_SGMII) {
  321. phy = fm_info_get_phy_address(port);
  322. sprintf(alias, "phy_sgmii_%x", phy);
  323. fdt_set_phy_handle(fdt, compat, addr, alias);
  324. }
  325. }
  326. void fdt_fixup_board_enet(void *fdt)
  327. {
  328. int i;
  329. char alias[32];
  330. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  331. switch (fm_info_get_enet_if(i)) {
  332. case PHY_INTERFACE_MODE_NONE:
  333. sprintf(alias, "ethernet%u", i);
  334. fdt_status_disabled_by_alias(fdt, alias);
  335. break;
  336. default:
  337. break;
  338. }
  339. }
  340. }