cvmx-helper.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 for common, but complicated tasks.
  30. *
  31. */
  32. #ifndef __CVMX_HELPER_H__
  33. #define __CVMX_HELPER_H__
  34. #include <asm/octeon/cvmx-config.h>
  35. #include <asm/octeon/cvmx-fpa.h>
  36. #include <asm/octeon/cvmx-wqe.h>
  37. typedef enum {
  38. CVMX_HELPER_INTERFACE_MODE_DISABLED,
  39. CVMX_HELPER_INTERFACE_MODE_RGMII,
  40. CVMX_HELPER_INTERFACE_MODE_GMII,
  41. CVMX_HELPER_INTERFACE_MODE_SPI,
  42. CVMX_HELPER_INTERFACE_MODE_PCIE,
  43. CVMX_HELPER_INTERFACE_MODE_XAUI,
  44. CVMX_HELPER_INTERFACE_MODE_SGMII,
  45. CVMX_HELPER_INTERFACE_MODE_PICMG,
  46. CVMX_HELPER_INTERFACE_MODE_NPI,
  47. CVMX_HELPER_INTERFACE_MODE_LOOP,
  48. } cvmx_helper_interface_mode_t;
  49. typedef union {
  50. uint64_t u64;
  51. struct {
  52. uint64_t reserved_20_63:44;
  53. uint64_t link_up:1; /**< Is the physical link up? */
  54. uint64_t full_duplex:1; /**< 1 if the link is full duplex */
  55. uint64_t speed:18; /**< Speed of the link in Mbps */
  56. } s;
  57. } cvmx_helper_link_info_t;
  58. #include <asm/octeon/cvmx-helper-errata.h>
  59. #include <asm/octeon/cvmx-helper-loop.h>
  60. #include <asm/octeon/cvmx-helper-npi.h>
  61. #include <asm/octeon/cvmx-helper-rgmii.h>
  62. #include <asm/octeon/cvmx-helper-sgmii.h>
  63. #include <asm/octeon/cvmx-helper-spi.h>
  64. #include <asm/octeon/cvmx-helper-util.h>
  65. #include <asm/octeon/cvmx-helper-xaui.h>
  66. /**
  67. * cvmx_override_pko_queue_priority(int ipd_port, uint64_t
  68. * priorities[16]) is a function pointer. It is meant to allow
  69. * customization of the PKO queue priorities based on the port
  70. * number. Users should set this pointer to a function before
  71. * calling any cvmx-helper operations.
  72. */
  73. extern void (*cvmx_override_pko_queue_priority) (int pko_port,
  74. uint64_t priorities[16]);
  75. /**
  76. * cvmx_override_ipd_port_setup(int ipd_port) is a function
  77. * pointer. It is meant to allow customization of the IPD port
  78. * setup before packet input/output comes online. It is called
  79. * after cvmx-helper does the default IPD configuration, but
  80. * before IPD is enabled. Users should set this pointer to a
  81. * function before calling any cvmx-helper operations.
  82. */
  83. extern void (*cvmx_override_ipd_port_setup) (int ipd_port);
  84. /**
  85. * This function enables the IPD and also enables the packet interfaces.
  86. * The packet interfaces (RGMII and SPI) must be enabled after the
  87. * IPD. This should be called by the user program after any additional
  88. * IPD configuration changes are made if CVMX_HELPER_ENABLE_IPD
  89. * is not set in the executive-config.h file.
  90. *
  91. * Returns 0 on success
  92. * -1 on failure
  93. */
  94. extern int cvmx_helper_ipd_and_packet_input_enable(void);
  95. /**
  96. * Initialize the PIP, IPD, and PKO hardware to support
  97. * simple priority based queues for the ethernet ports. Each
  98. * port is configured with a number of priority queues based
  99. * on CVMX_PKO_QUEUES_PER_PORT_* where each queue is lower
  100. * priority than the previous.
  101. *
  102. * Returns Zero on success, non-zero on failure
  103. */
  104. extern int cvmx_helper_initialize_packet_io_global(void);
  105. /**
  106. * Does core local initialization for packet io
  107. *
  108. * Returns Zero on success, non-zero on failure
  109. */
  110. extern int cvmx_helper_initialize_packet_io_local(void);
  111. /**
  112. * Returns the number of ports on the given interface.
  113. * The interface must be initialized before the port count
  114. * can be returned.
  115. *
  116. * @interface: Which interface to return port count for.
  117. *
  118. * Returns Port count for interface
  119. * -1 for uninitialized interface
  120. */
  121. extern int cvmx_helper_ports_on_interface(int interface);
  122. /**
  123. * Return the number of interfaces the chip has. Each interface
  124. * may have multiple ports. Most chips support two interfaces,
  125. * but the CNX0XX and CNX1XX are exceptions. These only support
  126. * one interface.
  127. *
  128. * Returns Number of interfaces on chip
  129. */
  130. extern int cvmx_helper_get_number_of_interfaces(void);
  131. /**
  132. * Get the operating mode of an interface. Depending on the Octeon
  133. * chip and configuration, this function returns an enumeration
  134. * of the type of packet I/O supported by an interface.
  135. *
  136. * @interface: Interface to probe
  137. *
  138. * Returns Mode of the interface. Unknown or unsupported interfaces return
  139. * DISABLED.
  140. */
  141. extern cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int
  142. interface);
  143. /**
  144. * Auto configure an IPD/PKO port link state and speed. This
  145. * function basically does the equivalent of:
  146. * cvmx_helper_link_set(ipd_port, cvmx_helper_link_get(ipd_port));
  147. *
  148. * @ipd_port: IPD/PKO port to auto configure
  149. *
  150. * Returns Link state after configure
  151. */
  152. extern cvmx_helper_link_info_t cvmx_helper_link_autoconf(int ipd_port);
  153. /**
  154. * Return the link state of an IPD/PKO port as returned by
  155. * auto negotiation. The result of this function may not match
  156. * Octeon's link config if auto negotiation has changed since
  157. * the last call to cvmx_helper_link_set().
  158. *
  159. * @ipd_port: IPD/PKO port to query
  160. *
  161. * Returns Link state
  162. */
  163. extern cvmx_helper_link_info_t cvmx_helper_link_get(int ipd_port);
  164. /**
  165. * Configure an IPD/PKO port for the specified link state. This
  166. * function does not influence auto negotiation at the PHY level.
  167. * The passed link state must always match the link state returned
  168. * by cvmx_helper_link_get(). It is normally best to use
  169. * cvmx_helper_link_autoconf() instead.
  170. *
  171. * @ipd_port: IPD/PKO port to configure
  172. * @link_info: The new link state
  173. *
  174. * Returns Zero on success, negative on failure
  175. */
  176. extern int cvmx_helper_link_set(int ipd_port,
  177. cvmx_helper_link_info_t link_info);
  178. /**
  179. * This function probes an interface to determine the actual
  180. * number of hardware ports connected to it. It doesn't setup the
  181. * ports or enable them. The main goal here is to set the global
  182. * interface_port_count[interface] correctly. Hardware setup of the
  183. * ports will be performed later.
  184. *
  185. * @interface: Interface to probe
  186. *
  187. * Returns Zero on success, negative on failure
  188. */
  189. extern int cvmx_helper_interface_probe(int interface);
  190. extern int cvmx_helper_interface_enumerate(int interface);
  191. /**
  192. * Configure a port for internal and/or external loopback. Internal loopback
  193. * causes packets sent by the port to be received by Octeon. External loopback
  194. * causes packets received from the wire to sent out again.
  195. *
  196. * @ipd_port: IPD/PKO port to loopback.
  197. * @enable_internal:
  198. * Non zero if you want internal loopback
  199. * @enable_external:
  200. * Non zero if you want external loopback
  201. *
  202. * Returns Zero on success, negative on failure.
  203. */
  204. extern int cvmx_helper_configure_loopback(int ipd_port, int enable_internal,
  205. int enable_external);
  206. #endif /* __CVMX_HELPER_H__ */