cvmx-helper-board.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: support@caviumnetworks.com
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2008 Cavium Networks
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this file; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * or visit http://www.gnu.org/licenses/.
  23. *
  24. * This file may also be available under a different license from Cavium.
  25. * Contact Cavium Networks for more information
  26. ***********************license end**************************************/
  27. /*
  28. *
  29. * Helper functions to abstract board specific data about
  30. * network ports from the rest of the cvmx-helper files.
  31. */
  32. #include <asm/octeon/octeon.h>
  33. #include <asm/octeon/cvmx-bootinfo.h>
  34. #include <asm/octeon/cvmx-config.h>
  35. #include <asm/octeon/cvmx-mdio.h>
  36. #include <asm/octeon/cvmx-helper.h>
  37. #include <asm/octeon/cvmx-helper-util.h>
  38. #include <asm/octeon/cvmx-helper-board.h>
  39. #include <asm/octeon/cvmx-gmxx-defs.h>
  40. #include <asm/octeon/cvmx-asxx-defs.h>
  41. /**
  42. * cvmx_override_board_link_get(int ipd_port) is a function
  43. * pointer. It is meant to allow customization of the process of
  44. * talking to a PHY to determine link speed. It is called every
  45. * time a PHY must be polled for link status. Users should set
  46. * this pointer to a function before calling any cvmx-helper
  47. * operations.
  48. */
  49. cvmx_helper_link_info_t(*cvmx_override_board_link_get) (int ipd_port) =
  50. NULL;
  51. /**
  52. * Return the MII PHY address associated with the given IPD
  53. * port. A result of -1 means there isn't a MII capable PHY
  54. * connected to this port. On chips supporting multiple MII
  55. * busses the bus number is encoded in bits <15:8>.
  56. *
  57. * This function must be modified for every new Octeon board.
  58. * Internally it uses switch statements based on the cvmx_sysinfo
  59. * data to determine board types and revisions. It replies on the
  60. * fact that every Octeon board receives a unique board type
  61. * enumeration from the bootloader.
  62. *
  63. * @ipd_port: Octeon IPD port to get the MII address for.
  64. *
  65. * Returns MII PHY address and bus number or -1.
  66. */
  67. int cvmx_helper_board_get_mii_address(int ipd_port)
  68. {
  69. switch (cvmx_sysinfo_get()->board_type) {
  70. case CVMX_BOARD_TYPE_SIM:
  71. /* Simulator doesn't have MII */
  72. return -1;
  73. case CVMX_BOARD_TYPE_EBT3000:
  74. case CVMX_BOARD_TYPE_EBT5800:
  75. case CVMX_BOARD_TYPE_THUNDER:
  76. case CVMX_BOARD_TYPE_NICPRO2:
  77. /* Interface 0 is SPI4, interface 1 is RGMII */
  78. if ((ipd_port >= 16) && (ipd_port < 20))
  79. return ipd_port - 16;
  80. else
  81. return -1;
  82. case CVMX_BOARD_TYPE_KODAMA:
  83. case CVMX_BOARD_TYPE_EBH3100:
  84. case CVMX_BOARD_TYPE_HIKARI:
  85. case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
  86. case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
  87. case CVMX_BOARD_TYPE_CN3020_EVB_HS5:
  88. /*
  89. * Port 0 is WAN connected to a PHY, Port 1 is GMII
  90. * connected to a switch
  91. */
  92. if (ipd_port == 0)
  93. return 4;
  94. else if (ipd_port == 1)
  95. return 9;
  96. else
  97. return -1;
  98. case CVMX_BOARD_TYPE_NAC38:
  99. /* Board has 8 RGMII ports PHYs are 0-7 */
  100. if ((ipd_port >= 0) && (ipd_port < 4))
  101. return ipd_port;
  102. else if ((ipd_port >= 16) && (ipd_port < 20))
  103. return ipd_port - 16 + 4;
  104. else
  105. return -1;
  106. case CVMX_BOARD_TYPE_EBH3000:
  107. /* Board has dual SPI4 and no PHYs */
  108. return -1;
  109. case CVMX_BOARD_TYPE_EBH5200:
  110. case CVMX_BOARD_TYPE_EBH5201:
  111. case CVMX_BOARD_TYPE_EBT5200:
  112. /* Board has 2 management ports */
  113. if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) &&
  114. (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2)))
  115. return ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT;
  116. /*
  117. * Board has 4 SGMII ports. The PHYs start right after the MII
  118. * ports MII0 = 0, MII1 = 1, SGMII = 2-5.
  119. */
  120. if ((ipd_port >= 0) && (ipd_port < 4))
  121. return ipd_port + 2;
  122. else
  123. return -1;
  124. case CVMX_BOARD_TYPE_EBH5600:
  125. case CVMX_BOARD_TYPE_EBH5601:
  126. case CVMX_BOARD_TYPE_EBH5610:
  127. /* Board has 1 management port */
  128. if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)
  129. return 0;
  130. /*
  131. * Board has 8 SGMII ports. 4 connect out, two connect
  132. * to a switch, and 2 loop to each other
  133. */
  134. if ((ipd_port >= 0) && (ipd_port < 4))
  135. return ipd_port + 1;
  136. else
  137. return -1;
  138. case CVMX_BOARD_TYPE_CUST_NB5:
  139. if (ipd_port == 2)
  140. return 4;
  141. else
  142. return -1;
  143. case CVMX_BOARD_TYPE_NIC_XLE_4G:
  144. /* Board has 4 SGMII ports. connected QLM3(interface 1) */
  145. if ((ipd_port >= 16) && (ipd_port < 20))
  146. return ipd_port - 16 + 1;
  147. else
  148. return -1;
  149. case CVMX_BOARD_TYPE_NIC_XLE_10G:
  150. case CVMX_BOARD_TYPE_NIC10E:
  151. return -1;
  152. case CVMX_BOARD_TYPE_NIC4E:
  153. if (ipd_port >= 0 && ipd_port <= 3)
  154. return (ipd_port + 0x1f) & 0x1f;
  155. else
  156. return -1;
  157. case CVMX_BOARD_TYPE_NIC2E:
  158. if (ipd_port >= 0 && ipd_port <= 1)
  159. return ipd_port + 1;
  160. else
  161. return -1;
  162. case CVMX_BOARD_TYPE_BBGW_REF:
  163. /*
  164. * No PHYs are connected to Octeon, everything is
  165. * through switch.
  166. */
  167. return -1;
  168. case CVMX_BOARD_TYPE_CUST_WSX16:
  169. if (ipd_port >= 0 && ipd_port <= 3)
  170. return ipd_port;
  171. else if (ipd_port >= 16 && ipd_port <= 19)
  172. return ipd_port - 16 + 4;
  173. else
  174. return -1;
  175. }
  176. /* Some unknown board. Somebody forgot to update this function... */
  177. cvmx_dprintf
  178. ("cvmx_helper_board_get_mii_address: Unknown board type %d\n",
  179. cvmx_sysinfo_get()->board_type);
  180. return -1;
  181. }
  182. /**
  183. * This function is the board specific method of determining an
  184. * ethernet ports link speed. Most Octeon boards have Marvell PHYs
  185. * and are handled by the fall through case. This function must be
  186. * updated for boards that don't have the normal Marvell PHYs.
  187. *
  188. * This function must be modified for every new Octeon board.
  189. * Internally it uses switch statements based on the cvmx_sysinfo
  190. * data to determine board types and revisions. It relies on the
  191. * fact that every Octeon board receives a unique board type
  192. * enumeration from the bootloader.
  193. *
  194. * @ipd_port: IPD input port associated with the port we want to get link
  195. * status for.
  196. *
  197. * Returns The ports link status. If the link isn't fully resolved, this must
  198. * return zero.
  199. */
  200. cvmx_helper_link_info_t __cvmx_helper_board_link_get(int ipd_port)
  201. {
  202. cvmx_helper_link_info_t result;
  203. int phy_addr;
  204. int is_broadcom_phy = 0;
  205. /* Give the user a chance to override the processing of this function */
  206. if (cvmx_override_board_link_get)
  207. return cvmx_override_board_link_get(ipd_port);
  208. /* Unless we fix it later, all links are defaulted to down */
  209. result.u64 = 0;
  210. /*
  211. * This switch statement should handle all ports that either don't use
  212. * Marvell PHYS, or don't support in-band status.
  213. */
  214. switch (cvmx_sysinfo_get()->board_type) {
  215. case CVMX_BOARD_TYPE_SIM:
  216. /* The simulator gives you a simulated 1Gbps full duplex link */
  217. result.s.link_up = 1;
  218. result.s.full_duplex = 1;
  219. result.s.speed = 1000;
  220. return result;
  221. case CVMX_BOARD_TYPE_EBH3100:
  222. case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
  223. case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
  224. case CVMX_BOARD_TYPE_CN3020_EVB_HS5:
  225. /* Port 1 on these boards is always Gigabit */
  226. if (ipd_port == 1) {
  227. result.s.link_up = 1;
  228. result.s.full_duplex = 1;
  229. result.s.speed = 1000;
  230. return result;
  231. }
  232. /* Fall through to the generic code below */
  233. break;
  234. case CVMX_BOARD_TYPE_CUST_NB5:
  235. /* Port 1 on these boards is always Gigabit */
  236. if (ipd_port == 1) {
  237. result.s.link_up = 1;
  238. result.s.full_duplex = 1;
  239. result.s.speed = 1000;
  240. return result;
  241. } else /* The other port uses a broadcom PHY */
  242. is_broadcom_phy = 1;
  243. break;
  244. case CVMX_BOARD_TYPE_BBGW_REF:
  245. /* Port 1 on these boards is always Gigabit */
  246. if (ipd_port == 2) {
  247. /* Port 2 is not hooked up */
  248. result.u64 = 0;
  249. return result;
  250. } else {
  251. /* Ports 0 and 1 connect to the switch */
  252. result.s.link_up = 1;
  253. result.s.full_duplex = 1;
  254. result.s.speed = 1000;
  255. return result;
  256. }
  257. break;
  258. }
  259. phy_addr = cvmx_helper_board_get_mii_address(ipd_port);
  260. if (phy_addr != -1) {
  261. if (is_broadcom_phy) {
  262. /*
  263. * Below we are going to read SMI/MDIO
  264. * register 0x19 which works on Broadcom
  265. * parts
  266. */
  267. int phy_status =
  268. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  269. 0x19);
  270. switch ((phy_status >> 8) & 0x7) {
  271. case 0:
  272. result.u64 = 0;
  273. break;
  274. case 1:
  275. result.s.link_up = 1;
  276. result.s.full_duplex = 0;
  277. result.s.speed = 10;
  278. break;
  279. case 2:
  280. result.s.link_up = 1;
  281. result.s.full_duplex = 1;
  282. result.s.speed = 10;
  283. break;
  284. case 3:
  285. result.s.link_up = 1;
  286. result.s.full_duplex = 0;
  287. result.s.speed = 100;
  288. break;
  289. case 4:
  290. result.s.link_up = 1;
  291. result.s.full_duplex = 1;
  292. result.s.speed = 100;
  293. break;
  294. case 5:
  295. result.s.link_up = 1;
  296. result.s.full_duplex = 1;
  297. result.s.speed = 100;
  298. break;
  299. case 6:
  300. result.s.link_up = 1;
  301. result.s.full_duplex = 0;
  302. result.s.speed = 1000;
  303. break;
  304. case 7:
  305. result.s.link_up = 1;
  306. result.s.full_duplex = 1;
  307. result.s.speed = 1000;
  308. break;
  309. }
  310. } else {
  311. /*
  312. * This code assumes we are using a Marvell
  313. * Gigabit PHY. All the speed information can
  314. * be read from register 17 in one
  315. * go. Somebody using a different PHY will
  316. * need to handle it above in the board
  317. * specific area.
  318. */
  319. int phy_status =
  320. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff, 17);
  321. /*
  322. * If the resolve bit 11 isn't set, see if
  323. * autoneg is turned off (bit 12, reg 0). The
  324. * resolve bit doesn't get set properly when
  325. * autoneg is off, so force it.
  326. */
  327. if ((phy_status & (1 << 11)) == 0) {
  328. int auto_status =
  329. cvmx_mdio_read(phy_addr >> 8,
  330. phy_addr & 0xff, 0);
  331. if ((auto_status & (1 << 12)) == 0)
  332. phy_status |= 1 << 11;
  333. }
  334. /*
  335. * Only return a link if the PHY has finished
  336. * auto negotiation and set the resolved bit
  337. * (bit 11)
  338. */
  339. if (phy_status & (1 << 11)) {
  340. result.s.link_up = 1;
  341. result.s.full_duplex = ((phy_status >> 13) & 1);
  342. switch ((phy_status >> 14) & 3) {
  343. case 0: /* 10 Mbps */
  344. result.s.speed = 10;
  345. break;
  346. case 1: /* 100 Mbps */
  347. result.s.speed = 100;
  348. break;
  349. case 2: /* 1 Gbps */
  350. result.s.speed = 1000;
  351. break;
  352. case 3: /* Illegal */
  353. result.u64 = 0;
  354. break;
  355. }
  356. }
  357. }
  358. } else if (OCTEON_IS_MODEL(OCTEON_CN3XXX)
  359. || OCTEON_IS_MODEL(OCTEON_CN58XX)
  360. || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
  361. /*
  362. * We don't have a PHY address, so attempt to use
  363. * in-band status. It is really important that boards
  364. * not supporting in-band status never get
  365. * here. Reading broken in-band status tends to do bad
  366. * things
  367. */
  368. union cvmx_gmxx_rxx_rx_inbnd inband_status;
  369. int interface = cvmx_helper_get_interface_num(ipd_port);
  370. int index = cvmx_helper_get_interface_index_num(ipd_port);
  371. inband_status.u64 =
  372. cvmx_read_csr(CVMX_GMXX_RXX_RX_INBND(index, interface));
  373. result.s.link_up = inband_status.s.status;
  374. result.s.full_duplex = inband_status.s.duplex;
  375. switch (inband_status.s.speed) {
  376. case 0: /* 10 Mbps */
  377. result.s.speed = 10;
  378. break;
  379. case 1: /* 100 Mbps */
  380. result.s.speed = 100;
  381. break;
  382. case 2: /* 1 Gbps */
  383. result.s.speed = 1000;
  384. break;
  385. case 3: /* Illegal */
  386. result.u64 = 0;
  387. break;
  388. }
  389. } else {
  390. /*
  391. * We don't have a PHY address and we don't have
  392. * in-band status. There is no way to determine the
  393. * link speed. Return down assuming this port isn't
  394. * wired
  395. */
  396. result.u64 = 0;
  397. }
  398. /* If link is down, return all fields as zero. */
  399. if (!result.s.link_up)
  400. result.u64 = 0;
  401. return result;
  402. }
  403. /**
  404. * This function as a board specific method of changing the PHY
  405. * speed, duplex, and auto-negotiation. This programs the PHY and
  406. * not Octeon. This can be used to force Octeon's links to
  407. * specific settings.
  408. *
  409. * @phy_addr: The address of the PHY to program
  410. * @enable_autoneg:
  411. * Non zero if you want to enable auto-negotiation.
  412. * @link_info: Link speed to program. If the speed is zero and auto-negotiation
  413. * is enabled, all possible negotiation speeds are advertised.
  414. *
  415. * Returns Zero on success, negative on failure
  416. */
  417. int cvmx_helper_board_link_set_phy(int phy_addr,
  418. cvmx_helper_board_set_phy_link_flags_types_t
  419. link_flags,
  420. cvmx_helper_link_info_t link_info)
  421. {
  422. /* Set the flow control settings based on link_flags */
  423. if ((link_flags & set_phy_link_flags_flow_control_mask) !=
  424. set_phy_link_flags_flow_control_dont_touch) {
  425. cvmx_mdio_phy_reg_autoneg_adver_t reg_autoneg_adver;
  426. reg_autoneg_adver.u16 =
  427. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  428. CVMX_MDIO_PHY_REG_AUTONEG_ADVER);
  429. reg_autoneg_adver.s.asymmetric_pause =
  430. (link_flags & set_phy_link_flags_flow_control_mask) ==
  431. set_phy_link_flags_flow_control_enable;
  432. reg_autoneg_adver.s.pause =
  433. (link_flags & set_phy_link_flags_flow_control_mask) ==
  434. set_phy_link_flags_flow_control_enable;
  435. cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff,
  436. CVMX_MDIO_PHY_REG_AUTONEG_ADVER,
  437. reg_autoneg_adver.u16);
  438. }
  439. /* If speed isn't set and autoneg is on advertise all supported modes */
  440. if ((link_flags & set_phy_link_flags_autoneg)
  441. && (link_info.s.speed == 0)) {
  442. cvmx_mdio_phy_reg_control_t reg_control;
  443. cvmx_mdio_phy_reg_status_t reg_status;
  444. cvmx_mdio_phy_reg_autoneg_adver_t reg_autoneg_adver;
  445. cvmx_mdio_phy_reg_extended_status_t reg_extended_status;
  446. cvmx_mdio_phy_reg_control_1000_t reg_control_1000;
  447. reg_status.u16 =
  448. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  449. CVMX_MDIO_PHY_REG_STATUS);
  450. reg_autoneg_adver.u16 =
  451. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  452. CVMX_MDIO_PHY_REG_AUTONEG_ADVER);
  453. reg_autoneg_adver.s.advert_100base_t4 =
  454. reg_status.s.capable_100base_t4;
  455. reg_autoneg_adver.s.advert_10base_tx_full =
  456. reg_status.s.capable_10_full;
  457. reg_autoneg_adver.s.advert_10base_tx_half =
  458. reg_status.s.capable_10_half;
  459. reg_autoneg_adver.s.advert_100base_tx_full =
  460. reg_status.s.capable_100base_x_full;
  461. reg_autoneg_adver.s.advert_100base_tx_half =
  462. reg_status.s.capable_100base_x_half;
  463. cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff,
  464. CVMX_MDIO_PHY_REG_AUTONEG_ADVER,
  465. reg_autoneg_adver.u16);
  466. if (reg_status.s.capable_extended_status) {
  467. reg_extended_status.u16 =
  468. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  469. CVMX_MDIO_PHY_REG_EXTENDED_STATUS);
  470. reg_control_1000.u16 =
  471. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  472. CVMX_MDIO_PHY_REG_CONTROL_1000);
  473. reg_control_1000.s.advert_1000base_t_full =
  474. reg_extended_status.s.capable_1000base_t_full;
  475. reg_control_1000.s.advert_1000base_t_half =
  476. reg_extended_status.s.capable_1000base_t_half;
  477. cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff,
  478. CVMX_MDIO_PHY_REG_CONTROL_1000,
  479. reg_control_1000.u16);
  480. }
  481. reg_control.u16 =
  482. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  483. CVMX_MDIO_PHY_REG_CONTROL);
  484. reg_control.s.autoneg_enable = 1;
  485. reg_control.s.restart_autoneg = 1;
  486. cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff,
  487. CVMX_MDIO_PHY_REG_CONTROL, reg_control.u16);
  488. } else if ((link_flags & set_phy_link_flags_autoneg)) {
  489. cvmx_mdio_phy_reg_control_t reg_control;
  490. cvmx_mdio_phy_reg_status_t reg_status;
  491. cvmx_mdio_phy_reg_autoneg_adver_t reg_autoneg_adver;
  492. cvmx_mdio_phy_reg_control_1000_t reg_control_1000;
  493. reg_status.u16 =
  494. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  495. CVMX_MDIO_PHY_REG_STATUS);
  496. reg_autoneg_adver.u16 =
  497. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  498. CVMX_MDIO_PHY_REG_AUTONEG_ADVER);
  499. reg_autoneg_adver.s.advert_100base_t4 = 0;
  500. reg_autoneg_adver.s.advert_10base_tx_full = 0;
  501. reg_autoneg_adver.s.advert_10base_tx_half = 0;
  502. reg_autoneg_adver.s.advert_100base_tx_full = 0;
  503. reg_autoneg_adver.s.advert_100base_tx_half = 0;
  504. if (reg_status.s.capable_extended_status) {
  505. reg_control_1000.u16 =
  506. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  507. CVMX_MDIO_PHY_REG_CONTROL_1000);
  508. reg_control_1000.s.advert_1000base_t_full = 0;
  509. reg_control_1000.s.advert_1000base_t_half = 0;
  510. }
  511. switch (link_info.s.speed) {
  512. case 10:
  513. reg_autoneg_adver.s.advert_10base_tx_full =
  514. link_info.s.full_duplex;
  515. reg_autoneg_adver.s.advert_10base_tx_half =
  516. !link_info.s.full_duplex;
  517. break;
  518. case 100:
  519. reg_autoneg_adver.s.advert_100base_tx_full =
  520. link_info.s.full_duplex;
  521. reg_autoneg_adver.s.advert_100base_tx_half =
  522. !link_info.s.full_duplex;
  523. break;
  524. case 1000:
  525. reg_control_1000.s.advert_1000base_t_full =
  526. link_info.s.full_duplex;
  527. reg_control_1000.s.advert_1000base_t_half =
  528. !link_info.s.full_duplex;
  529. break;
  530. }
  531. cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff,
  532. CVMX_MDIO_PHY_REG_AUTONEG_ADVER,
  533. reg_autoneg_adver.u16);
  534. if (reg_status.s.capable_extended_status)
  535. cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff,
  536. CVMX_MDIO_PHY_REG_CONTROL_1000,
  537. reg_control_1000.u16);
  538. reg_control.u16 =
  539. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  540. CVMX_MDIO_PHY_REG_CONTROL);
  541. reg_control.s.autoneg_enable = 1;
  542. reg_control.s.restart_autoneg = 1;
  543. cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff,
  544. CVMX_MDIO_PHY_REG_CONTROL, reg_control.u16);
  545. } else {
  546. cvmx_mdio_phy_reg_control_t reg_control;
  547. reg_control.u16 =
  548. cvmx_mdio_read(phy_addr >> 8, phy_addr & 0xff,
  549. CVMX_MDIO_PHY_REG_CONTROL);
  550. reg_control.s.autoneg_enable = 0;
  551. reg_control.s.restart_autoneg = 1;
  552. reg_control.s.duplex = link_info.s.full_duplex;
  553. if (link_info.s.speed == 1000) {
  554. reg_control.s.speed_msb = 1;
  555. reg_control.s.speed_lsb = 0;
  556. } else if (link_info.s.speed == 100) {
  557. reg_control.s.speed_msb = 0;
  558. reg_control.s.speed_lsb = 1;
  559. } else if (link_info.s.speed == 10) {
  560. reg_control.s.speed_msb = 0;
  561. reg_control.s.speed_lsb = 0;
  562. }
  563. cvmx_mdio_write(phy_addr >> 8, phy_addr & 0xff,
  564. CVMX_MDIO_PHY_REG_CONTROL, reg_control.u16);
  565. }
  566. return 0;
  567. }
  568. /**
  569. * This function is called by cvmx_helper_interface_probe() after it
  570. * determines the number of ports Octeon can support on a specific
  571. * interface. This function is the per board location to override
  572. * this value. It is called with the number of ports Octeon might
  573. * support and should return the number of actual ports on the
  574. * board.
  575. *
  576. * This function must be modifed for every new Octeon board.
  577. * Internally it uses switch statements based on the cvmx_sysinfo
  578. * data to determine board types and revisions. It relys on the
  579. * fact that every Octeon board receives a unique board type
  580. * enumeration from the bootloader.
  581. *
  582. * @interface: Interface to probe
  583. * @supported_ports:
  584. * Number of ports Octeon supports.
  585. *
  586. * Returns Number of ports the actual board supports. Many times this will
  587. * simple be "support_ports".
  588. */
  589. int __cvmx_helper_board_interface_probe(int interface, int supported_ports)
  590. {
  591. switch (cvmx_sysinfo_get()->board_type) {
  592. case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
  593. if (interface == 0)
  594. return 2;
  595. break;
  596. case CVMX_BOARD_TYPE_BBGW_REF:
  597. if (interface == 0)
  598. return 2;
  599. break;
  600. case CVMX_BOARD_TYPE_NIC_XLE_4G:
  601. if (interface == 0)
  602. return 0;
  603. break;
  604. /* The 2nd interface on the EBH5600 is connected to the Marvel switch,
  605. which we don't support. Disable ports connected to it */
  606. case CVMX_BOARD_TYPE_EBH5600:
  607. if (interface == 1)
  608. return 0;
  609. break;
  610. }
  611. return supported_ports;
  612. }
  613. /**
  614. * Enable packet input/output from the hardware. This function is
  615. * called after by cvmx_helper_packet_hardware_enable() to
  616. * perform board specific initialization. For most boards
  617. * nothing is needed.
  618. *
  619. * @interface: Interface to enable
  620. *
  621. * Returns Zero on success, negative on failure
  622. */
  623. int __cvmx_helper_board_hardware_enable(int interface)
  624. {
  625. if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_CN3005_EVB_HS5) {
  626. if (interface == 0) {
  627. /* Different config for switch port */
  628. cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(1, interface), 0);
  629. cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(1, interface), 0);
  630. /*
  631. * Boards with gigabit WAN ports need a
  632. * different setting that is compatible with
  633. * 100 Mbit settings
  634. */
  635. cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(0, interface),
  636. 0xc);
  637. cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(0, interface),
  638. 0xc);
  639. }
  640. } else if (cvmx_sysinfo_get()->board_type ==
  641. CVMX_BOARD_TYPE_CN3010_EVB_HS5) {
  642. /*
  643. * Broadcom PHYs require differnet ASX
  644. * clocks. Unfortunately many boards don't define a
  645. * new board Id and simply mangle the
  646. * CN3010_EVB_HS5
  647. */
  648. if (interface == 0) {
  649. /*
  650. * Some boards use a hacked up bootloader that
  651. * identifies them as CN3010_EVB_HS5
  652. * evaluation boards. This leads to all kinds
  653. * of configuration problems. Detect one
  654. * case, and print warning, while trying to do
  655. * the right thing.
  656. */
  657. int phy_addr = cvmx_helper_board_get_mii_address(0);
  658. if (phy_addr != -1) {
  659. int phy_identifier =
  660. cvmx_mdio_read(phy_addr >> 8,
  661. phy_addr & 0xff, 0x2);
  662. /* Is it a Broadcom PHY? */
  663. if (phy_identifier == 0x0143) {
  664. cvmx_dprintf("\n");
  665. cvmx_dprintf("ERROR:\n");
  666. cvmx_dprintf
  667. ("ERROR: Board type is CVMX_BOARD_TYPE_CN3010_EVB_HS5, but Broadcom PHY found.\n");
  668. cvmx_dprintf
  669. ("ERROR: The board type is mis-configured, and software malfunctions are likely.\n");
  670. cvmx_dprintf
  671. ("ERROR: All boards require a unique board type to identify them.\n");
  672. cvmx_dprintf("ERROR:\n");
  673. cvmx_dprintf("\n");
  674. cvmx_wait(1000000000);
  675. cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX
  676. (0, interface), 5);
  677. cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX
  678. (0, interface), 5);
  679. }
  680. }
  681. }
  682. }
  683. return 0;
  684. }