1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Networks nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
49 * Support functions for managing the MII management port
51 * <hr>$Revision: 49448 $<hr>
54 #ifndef __CVMX_MGMT_PORT_H__
55 #define __CVMX_MGMT_PORT_H__
57 #include "cvmx-helper.h"
58 #include "cvmx-helper-board.h"
64 #define CVMX_MGMT_PORT_NUM_PORTS 2 /* Right now we only have one mgmt port */
65 #define CVMX_MGMT_PORT_NUM_TX_BUFFERS 16 /* Number of TX ring buffer entries and buffers */
66 #define CVMX_MGMT_PORT_NUM_RX_BUFFERS 128 /* Number of RX ring buffer entries and buffers */
67 #define CVMX_MGMT_PORT_TX_BUFFER_SIZE 12288 /* Size of each TX/RX buffer */
68 #define CVMX_MGMT_PORT_RX_BUFFER_SIZE 1536 /* Size of each TX/RX buffer */
72 CVMX_MGMT_PORT_SUCCESS = 0,
73 CVMX_MGMT_PORT_NO_MEMORY = -1,
74 CVMX_MGMT_PORT_INVALID_PARAM = -2,
75 CVMX_MGMT_PORT_INIT_ERROR = -3,
76 } cvmx_mgmt_port_result_t;
79 /* Enumeration of Net Device interface flags. */
82 CVMX_IFF_PROMISC = 0x100, /* receive all packets */
83 CVMX_IFF_ALLMULTI = 0x200, /* receive all multicast packets */
84 } cvmx_mgmt_port_netdevice_flags_t;
87 * Called to initialize a management port for use. Multiple calls
88 * to this function accross applications is safe.
90 * @param port Port to initialize
92 * @return CVMX_MGMT_PORT_SUCCESS or an error code
94 extern cvmx_mgmt_port_result_t cvmx_mgmt_port_initialize(int port);
97 * Shutdown a management port. This currently disables packet IO
98 * but leaves all hardware and buffers. Another application can then
99 * call initialize() without redoing the hardware setup.
101 * @param port Management port
103 * @return CVMX_MGMT_PORT_SUCCESS or an error code
105 extern cvmx_mgmt_port_result_t cvmx_mgmt_port_shutdown(int port);
108 * Enable packet IO on a management port
110 * @param port Management port
112 * @return CVMX_MGMT_PORT_SUCCESS or an error code
114 extern cvmx_mgmt_port_result_t cvmx_mgmt_port_enable(int port);
117 * Disable packet IO on a management port
119 * @param port Management port
121 * @return CVMX_MGMT_PORT_SUCCESS or an error code
123 extern cvmx_mgmt_port_result_t cvmx_mgmt_port_disable(int port);
126 * Send a packet out the management port. The packet is copied so
127 * the input buffer isn't used after this call.
129 * @param port Management port
130 * @param packet_len Length of the packet to send. It does not include the final CRC
131 * @param buffer Packet data
133 * @return CVMX_MGMT_PORT_SUCCESS or an error code
135 extern cvmx_mgmt_port_result_t cvmx_mgmt_port_send(int port, int packet_len, void *buffer);
137 #if defined(__FreeBSD__)
139 * Send a packet out the management port. The packet is copied so
140 * the input mbuf isn't used after this call.
142 * @param port Management port
143 * @param m Packet mbuf (with pkthdr)
145 * @return CVMX_MGMT_PORT_SUCCESS or an error code
147 extern cvmx_mgmt_port_result_t cvmx_mgmt_port_sendm(int port, const struct mbuf *m);
151 * Receive a packet from the management port.
153 * @param port Management port
154 * @param buffer_len Size of the buffer to receive the packet into
155 * @param buffer Buffer to receive the packet into
157 * @return The size of the packet, or a negative erorr code on failure. Zero
158 * means that no packets were available.
160 extern int cvmx_mgmt_port_receive(int port, int buffer_len, uint8_t *buffer);
163 * Set the MAC address for a management port
165 * @param port Management port
166 * @param mac New MAC address. The lower 6 bytes are used.
168 * @return CVMX_MGMT_PORT_SUCCESS or an error code
170 extern cvmx_mgmt_port_result_t cvmx_mgmt_port_set_mac(int port, uint64_t mac);
173 * Get the MAC address for a management port
175 * @param port Management port
177 * @return MAC address
179 extern uint64_t cvmx_mgmt_port_get_mac(int port);
180 #define CVMX_MGMT_PORT_GET_MAC_ERROR ((unsigned long long)-2LL)
183 * Set the multicast list.
185 * @param port Management port
186 * @param flags Interface flags
190 extern void cvmx_mgmt_port_set_multicast_list(int port, int flags);
193 * Set the maximum packet allowed in. Size is specified
194 * including L2 but without FCS. A normal MTU would corespond
195 * to 1514 assuming the standard 14 byte L2 header.
197 * @param port Management port
198 * @param size_without_fcs
199 * Size in bytes without FCS
201 extern void cvmx_mgmt_port_set_max_packet_size(int port, int size_without_fcs);
204 * Return the link state of an RGMII/MII port as returned by
205 * auto negotiation. The result of this function may not match
206 * Octeon's link config if auto negotiation has changed since
207 * the last call to __cvmx_mgmt_port_link_set().
209 * @param port The RGMII/MII interface port to query
213 extern cvmx_helper_link_info_t cvmx_mgmt_port_link_get(int port);
216 * Configure RGMII/MII port for the specified link state. This
217 * function does not influence auto negotiation at the PHY level.
219 * @param port RGMII/MII interface port
220 * @param link_info The new link state
222 * @return Zero on success, negative on failure
224 extern int cvmx_mgmt_port_link_set(int port, cvmx_helper_link_info_t link_info);
230 #endif /* __CVMX_MGMT_PORT_H__ */