cvmx-helper-board.c 24 KB

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