cvmx-helper-board.c 21 KB

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