cvmx-helper.h 7.4 KB

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