cvmx-helper-board.c 22 KB

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