cvmx-helper-board.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: [email protected]
  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 <linux/bug.h>
  33. #include <asm/octeon/octeon.h>
  34. #include <asm/octeon/cvmx-bootinfo.h>
  35. #include <asm/octeon/cvmx-config.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. * Return the MII PHY address associated with the given IPD
  43. * port. A result of -1 means there isn't a MII capable PHY
  44. * connected to this port. On chips supporting multiple MII
  45. * busses the bus number is encoded in bits <15:8>.
  46. *
  47. * This function must be modified for every new Octeon board.
  48. * Internally it uses switch statements based on the cvmx_sysinfo
  49. * data to determine board types and revisions. It replies on the
  50. * fact that every Octeon board receives a unique board type
  51. * enumeration from the bootloader.
  52. *
  53. * @ipd_port: Octeon IPD port to get the MII address for.
  54. *
  55. * Returns MII PHY address and bus number or -1.
  56. */
  57. int cvmx_helper_board_get_mii_address(int ipd_port)
  58. {
  59. switch (cvmx_sysinfo_get()->board_type) {
  60. case CVMX_BOARD_TYPE_SIM:
  61. /* Simulator doesn't have MII */
  62. return -1;
  63. case CVMX_BOARD_TYPE_EBT3000:
  64. case CVMX_BOARD_TYPE_EBT5800:
  65. case CVMX_BOARD_TYPE_THUNDER:
  66. case CVMX_BOARD_TYPE_NICPRO2:
  67. /* Interface 0 is SPI4, interface 1 is RGMII */
  68. if ((ipd_port >= 16) && (ipd_port < 20))
  69. return ipd_port - 16;
  70. else
  71. return -1;
  72. case CVMX_BOARD_TYPE_KODAMA:
  73. case CVMX_BOARD_TYPE_EBH3100:
  74. case CVMX_BOARD_TYPE_HIKARI:
  75. case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
  76. case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
  77. case CVMX_BOARD_TYPE_CN3020_EVB_HS5:
  78. /*
  79. * Port 0 is WAN connected to a PHY, Port 1 is GMII
  80. * connected to a switch
  81. */
  82. if (ipd_port == 0)
  83. return 4;
  84. else if (ipd_port == 1)
  85. return 9;
  86. else
  87. return -1;
  88. case CVMX_BOARD_TYPE_NAC38:
  89. /* Board has 8 RGMII ports PHYs are 0-7 */
  90. if ((ipd_port >= 0) && (ipd_port < 4))
  91. return ipd_port;
  92. else if ((ipd_port >= 16) && (ipd_port < 20))
  93. return ipd_port - 16 + 4;
  94. else
  95. return -1;
  96. case CVMX_BOARD_TYPE_EBH3000:
  97. /* Board has dual SPI4 and no PHYs */
  98. return -1;
  99. case CVMX_BOARD_TYPE_EBH5200:
  100. case CVMX_BOARD_TYPE_EBH5201:
  101. case CVMX_BOARD_TYPE_EBT5200:
  102. /* Board has 2 management ports */
  103. if ((ipd_port >= CVMX_HELPER_BOARD_MGMT_IPD_PORT) &&
  104. (ipd_port < (CVMX_HELPER_BOARD_MGMT_IPD_PORT + 2)))
  105. return ipd_port - CVMX_HELPER_BOARD_MGMT_IPD_PORT;
  106. /*
  107. * Board has 4 SGMII ports. The PHYs start right after the MII
  108. * ports MII0 = 0, MII1 = 1, SGMII = 2-5.
  109. */
  110. if ((ipd_port >= 0) && (ipd_port < 4))
  111. return ipd_port + 2;
  112. else
  113. return -1;
  114. case CVMX_BOARD_TYPE_EBH5600:
  115. case CVMX_BOARD_TYPE_EBH5601:
  116. case CVMX_BOARD_TYPE_EBH5610:
  117. /* Board has 1 management port */
  118. if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)
  119. return 0;
  120. /*
  121. * Board has 8 SGMII ports. 4 connect out, two connect
  122. * to a switch, and 2 loop to each other
  123. */
  124. if ((ipd_port >= 0) && (ipd_port < 4))
  125. return ipd_port + 1;
  126. else
  127. return -1;
  128. case CVMX_BOARD_TYPE_CUST_NB5:
  129. if (ipd_port == 2)
  130. return 4;
  131. else
  132. return -1;
  133. case CVMX_BOARD_TYPE_NIC_XLE_4G:
  134. /* Board has 4 SGMII ports. connected QLM3(interface 1) */
  135. if ((ipd_port >= 16) && (ipd_port < 20))
  136. return ipd_port - 16 + 1;
  137. else
  138. return -1;
  139. case CVMX_BOARD_TYPE_NIC_XLE_10G:
  140. case CVMX_BOARD_TYPE_NIC10E:
  141. return -1;
  142. case CVMX_BOARD_TYPE_NIC4E:
  143. if (ipd_port >= 0 && ipd_port <= 3)
  144. return (ipd_port + 0x1f) & 0x1f;
  145. else
  146. return -1;
  147. case CVMX_BOARD_TYPE_NIC2E:
  148. if (ipd_port >= 0 && ipd_port <= 1)
  149. return ipd_port + 1;
  150. else
  151. return -1;
  152. case CVMX_BOARD_TYPE_BBGW_REF:
  153. /*
  154. * No PHYs are connected to Octeon, everything is
  155. * through switch.
  156. */
  157. return -1;
  158. case CVMX_BOARD_TYPE_CUST_WSX16:
  159. if (ipd_port >= 0 && ipd_port <= 3)
  160. return ipd_port;
  161. else if (ipd_port >= 16 && ipd_port <= 19)
  162. return ipd_port - 16 + 4;
  163. else
  164. return -1;
  165. case CVMX_BOARD_TYPE_UBNT_E100:
  166. if (ipd_port >= 0 && ipd_port <= 2)
  167. return 7 - ipd_port;
  168. else
  169. return -1;
  170. case CVMX_BOARD_TYPE_KONTRON_S1901:
  171. if (ipd_port == CVMX_HELPER_BOARD_MGMT_IPD_PORT)
  172. return 1;
  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. union cvmx_helper_link_info __cvmx_helper_board_link_get(int ipd_port)
  201. {
  202. union cvmx_helper_link_info result;
  203. WARN_ONCE(!octeon_is_simulation(),
  204. "Using deprecated link status - please update your DT");
  205. /* Unless we fix it later, all links are defaulted to down */
  206. result.u64 = 0;
  207. if (octeon_is_simulation()) {
  208. /* The simulator gives you a simulated 1Gbps full duplex link */
  209. result.s.link_up = 1;
  210. result.s.full_duplex = 1;
  211. result.s.speed = 1000;
  212. return result;
  213. }
  214. if (OCTEON_IS_MODEL(OCTEON_CN3XXX)
  215. || OCTEON_IS_MODEL(OCTEON_CN58XX)
  216. || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
  217. /*
  218. * We don't have a PHY address, so attempt to use
  219. * in-band status. It is really important that boards
  220. * not supporting in-band status never get
  221. * here. Reading broken in-band status tends to do bad
  222. * things
  223. */
  224. union cvmx_gmxx_rxx_rx_inbnd inband_status;
  225. int interface = cvmx_helper_get_interface_num(ipd_port);
  226. int index = cvmx_helper_get_interface_index_num(ipd_port);
  227. inband_status.u64 =
  228. cvmx_read_csr(CVMX_GMXX_RXX_RX_INBND(index, interface));
  229. result.s.link_up = inband_status.s.status;
  230. result.s.full_duplex = inband_status.s.duplex;
  231. switch (inband_status.s.speed) {
  232. case 0: /* 10 Mbps */
  233. result.s.speed = 10;
  234. break;
  235. case 1: /* 100 Mbps */
  236. result.s.speed = 100;
  237. break;
  238. case 2: /* 1 Gbps */
  239. result.s.speed = 1000;
  240. break;
  241. case 3: /* Illegal */
  242. result.u64 = 0;
  243. break;
  244. }
  245. } else {
  246. /*
  247. * We don't have a PHY address and we don't have
  248. * in-band status. There is no way to determine the
  249. * link speed. Return down assuming this port isn't
  250. * wired
  251. */
  252. result.u64 = 0;
  253. }
  254. /* If link is down, return all fields as zero. */
  255. if (!result.s.link_up)
  256. result.u64 = 0;
  257. return result;
  258. }
  259. /*
  260. * This function is called by cvmx_helper_interface_probe() after it
  261. * determines the number of ports Octeon can support on a specific
  262. * interface. This function is the per board location to override
  263. * this value. It is called with the number of ports Octeon might
  264. * support and should return the number of actual ports on the
  265. * board.
  266. *
  267. * This function must be modified for every new Octeon board.
  268. * Internally it uses switch statements based on the cvmx_sysinfo
  269. * data to determine board types and revisions. It relies on the
  270. * fact that every Octeon board receives a unique board type
  271. * enumeration from the bootloader.
  272. *
  273. * @interface: Interface to probe
  274. * @supported_ports:
  275. * Number of ports Octeon supports.
  276. *
  277. * Returns Number of ports the actual board supports. Many times this will
  278. * simple be "support_ports".
  279. */
  280. int __cvmx_helper_board_interface_probe(int interface, int supported_ports)
  281. {
  282. switch (cvmx_sysinfo_get()->board_type) {
  283. case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
  284. if (interface == 0)
  285. return 2;
  286. break;
  287. case CVMX_BOARD_TYPE_BBGW_REF:
  288. if (interface == 0)
  289. return 2;
  290. break;
  291. case CVMX_BOARD_TYPE_NIC_XLE_4G:
  292. if (interface == 0)
  293. return 0;
  294. break;
  295. /* The 2nd interface on the EBH5600 is connected to the Marvel switch,
  296. which we don't support. Disable ports connected to it */
  297. case CVMX_BOARD_TYPE_EBH5600:
  298. if (interface == 1)
  299. return 0;
  300. break;
  301. }
  302. return supported_ports;
  303. }
  304. /*
  305. * Get the clock type used for the USB block based on board type.
  306. * Used by the USB code for auto configuration of clock type.
  307. *
  308. * Return USB clock type enumeration
  309. */
  310. enum cvmx_helper_board_usb_clock_types __cvmx_helper_board_usb_get_clock_type(void)
  311. {
  312. switch (cvmx_sysinfo_get()->board_type) {
  313. case CVMX_BOARD_TYPE_BBGW_REF:
  314. case CVMX_BOARD_TYPE_LANAI2_A:
  315. case CVMX_BOARD_TYPE_LANAI2_U:
  316. case CVMX_BOARD_TYPE_LANAI2_G:
  317. case CVMX_BOARD_TYPE_NIC10E_66:
  318. case CVMX_BOARD_TYPE_UBNT_E100:
  319. return USB_CLOCK_TYPE_CRYSTAL_12;
  320. case CVMX_BOARD_TYPE_NIC10E:
  321. return USB_CLOCK_TYPE_REF_12;
  322. default:
  323. break;
  324. }
  325. /* Most boards except NIC10e use a 12MHz crystal */
  326. if (OCTEON_IS_OCTEON2())
  327. return USB_CLOCK_TYPE_CRYSTAL_12;
  328. return USB_CLOCK_TYPE_REF_48;
  329. }