1210284Sjmallett/***********************license start***************
2232812Sjmallett * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
3215990Sjmallett * reserved.
4210284Sjmallett *
5210284Sjmallett *
6215990Sjmallett * Redistribution and use in source and binary forms, with or without
7215990Sjmallett * modification, are permitted provided that the following conditions are
8215990Sjmallett * met:
9210284Sjmallett *
10215990Sjmallett *   * Redistributions of source code must retain the above copyright
11215990Sjmallett *     notice, this list of conditions and the following disclaimer.
12210284Sjmallett *
13215990Sjmallett *   * Redistributions in binary form must reproduce the above
14215990Sjmallett *     copyright notice, this list of conditions and the following
15215990Sjmallett *     disclaimer in the documentation and/or other materials provided
16215990Sjmallett *     with the distribution.
17215990Sjmallett
18232812Sjmallett *   * Neither the name of Cavium Inc. nor the names of
19215990Sjmallett *     its contributors may be used to endorse or promote products
20215990Sjmallett *     derived from this software without specific prior written
21215990Sjmallett *     permission.
22215990Sjmallett
23215990Sjmallett * This Software, including technical data, may be subject to U.S. export  control
24215990Sjmallett * laws, including the U.S. Export Administration Act and its  associated
25215990Sjmallett * regulations, and may be subject to export or import  regulations in other
26215990Sjmallett * countries.
27215990Sjmallett
28215990Sjmallett * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29232812Sjmallett * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30215990Sjmallett * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31215990Sjmallett * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32215990Sjmallett * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33215990Sjmallett * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34215990Sjmallett * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35215990Sjmallett * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36215990Sjmallett * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37215990Sjmallett * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38210284Sjmallett ***********************license end**************************************/
39210284Sjmallett
40210284Sjmallett
41210284Sjmallett
42210284Sjmallett
43210284Sjmallett
44210284Sjmallett
45215990Sjmallett
46210284Sjmallett/**
47210284Sjmallett * @file
48210284Sjmallett *
49210284Sjmallett * Support functions for managing the MII management port
50210284Sjmallett *
51232812Sjmallett * <hr>$Revision: 70030 $<hr>
52210284Sjmallett */
53210284Sjmallett
54210284Sjmallett#ifndef __CVMX_MGMT_PORT_H__
55210284Sjmallett#define __CVMX_MGMT_PORT_H__
56210284Sjmallett
57215990Sjmallett#include "cvmx-helper.h"
58215990Sjmallett#include "cvmx-helper-board.h"
59215990Sjmallett
60215990Sjmallett#ifdef __cplusplus
61215990Sjmallettextern "C" {
62215990Sjmallett#endif
63215990Sjmallett
64210284Sjmallett#define CVMX_MGMT_PORT_NUM_PORTS        2       /* Right now we only have one mgmt port */
65210284Sjmallett#define CVMX_MGMT_PORT_NUM_TX_BUFFERS   16      /* Number of TX ring buffer entries and buffers */
66210284Sjmallett#define CVMX_MGMT_PORT_NUM_RX_BUFFERS   128     /* Number of RX ring buffer entries and buffers */
67210284Sjmallett#define CVMX_MGMT_PORT_TX_BUFFER_SIZE   12288   /* Size of each TX/RX buffer */
68210284Sjmallett#define CVMX_MGMT_PORT_RX_BUFFER_SIZE   1536    /* Size of each TX/RX buffer */
69210284Sjmallett
70210284Sjmalletttypedef enum
71210284Sjmallett{
72210284Sjmallett    CVMX_MGMT_PORT_SUCCESS = 0,
73210284Sjmallett    CVMX_MGMT_PORT_NO_MEMORY = -1,
74210284Sjmallett    CVMX_MGMT_PORT_INVALID_PARAM = -2,
75215990Sjmallett    CVMX_MGMT_PORT_INIT_ERROR = -3,
76210284Sjmallett} cvmx_mgmt_port_result_t;
77210284Sjmallett
78210284Sjmallett
79210284Sjmallett/* Enumeration of Net Device interface flags. */
80215990Sjmalletttypedef enum
81210284Sjmallett{
82210284Sjmallett    CVMX_IFF_PROMISC = 0x100, 		/* receive all packets           */
83210284Sjmallett    CVMX_IFF_ALLMULTI = 0x200, 		/* receive all multicast packets */
84210284Sjmallett} cvmx_mgmt_port_netdevice_flags_t;
85210284Sjmallett
86210284Sjmallett/**
87210284Sjmallett * Called to initialize a management port for use. Multiple calls
88210284Sjmallett * to this function accross applications is safe.
89210284Sjmallett *
90210284Sjmallett * @param port   Port to initialize
91210284Sjmallett *
92210284Sjmallett * @return CVMX_MGMT_PORT_SUCCESS or an error code
93210284Sjmallett */
94210284Sjmallettextern cvmx_mgmt_port_result_t cvmx_mgmt_port_initialize(int port);
95210284Sjmallett
96210284Sjmallett/**
97210284Sjmallett * Shutdown a management port. This currently disables packet IO
98210284Sjmallett * but leaves all hardware and buffers. Another application can then
99210284Sjmallett * call initialize() without redoing the hardware setup.
100210284Sjmallett *
101210284Sjmallett * @param port   Management port
102210284Sjmallett *
103210284Sjmallett * @return CVMX_MGMT_PORT_SUCCESS or an error code
104210284Sjmallett */
105210284Sjmallettextern cvmx_mgmt_port_result_t cvmx_mgmt_port_shutdown(int port);
106210284Sjmallett
107210284Sjmallett/**
108210284Sjmallett * Enable packet IO on a management port
109210284Sjmallett *
110210284Sjmallett * @param port   Management port
111210284Sjmallett *
112210284Sjmallett * @return CVMX_MGMT_PORT_SUCCESS or an error code
113210284Sjmallett */
114210284Sjmallettextern cvmx_mgmt_port_result_t cvmx_mgmt_port_enable(int port);
115210284Sjmallett
116210284Sjmallett/**
117210284Sjmallett * Disable packet IO on a management port
118210284Sjmallett *
119210284Sjmallett * @param port   Management port
120210284Sjmallett *
121210284Sjmallett * @return CVMX_MGMT_PORT_SUCCESS or an error code
122210284Sjmallett */
123210284Sjmallettextern cvmx_mgmt_port_result_t cvmx_mgmt_port_disable(int port);
124210284Sjmallett
125210284Sjmallett/**
126210284Sjmallett * Send a packet out the management port. The packet is copied so
127210284Sjmallett * the input buffer isn't used after this call.
128210284Sjmallett *
129210284Sjmallett * @param port       Management port
130210284Sjmallett * @param packet_len Length of the packet to send. It does not include the final CRC
131210284Sjmallett * @param buffer     Packet data
132210284Sjmallett *
133210284Sjmallett * @return CVMX_MGMT_PORT_SUCCESS or an error code
134210284Sjmallett */
135210284Sjmallettextern cvmx_mgmt_port_result_t cvmx_mgmt_port_send(int port, int packet_len, void *buffer);
136210284Sjmallett
137217214Sjmallett#if defined(__FreeBSD__)
138210284Sjmallett/**
139217214Sjmallett * Send a packet out the management port. The packet is copied so
140217214Sjmallett * the input mbuf isn't used after this call.
141217214Sjmallett *
142217214Sjmallett * @param port       Management port
143217214Sjmallett * @param m          Packet mbuf (with pkthdr)
144217214Sjmallett *
145217214Sjmallett * @return CVMX_MGMT_PORT_SUCCESS or an error code
146217214Sjmallett */
147217214Sjmallettextern cvmx_mgmt_port_result_t cvmx_mgmt_port_sendm(int port, const struct mbuf *m);
148217214Sjmallett#endif
149217214Sjmallett
150217214Sjmallett/**
151210284Sjmallett * Receive a packet from the management port.
152210284Sjmallett *
153210284Sjmallett * @param port       Management port
154210284Sjmallett * @param buffer_len Size of the buffer to receive the packet into
155210284Sjmallett * @param buffer     Buffer to receive the packet into
156210284Sjmallett *
157210284Sjmallett * @return The size of the packet, or a negative erorr code on failure. Zero
158210284Sjmallett *         means that no packets were available.
159210284Sjmallett */
160217214Sjmallettextern int cvmx_mgmt_port_receive(int port, int buffer_len, uint8_t *buffer);
161210284Sjmallett
162210284Sjmallett/**
163210284Sjmallett * Set the MAC address for a management port
164210284Sjmallett *
165210284Sjmallett * @param port   Management port
166210284Sjmallett * @param mac    New MAC address. The lower 6 bytes are used.
167210284Sjmallett *
168210284Sjmallett * @return CVMX_MGMT_PORT_SUCCESS or an error code
169210284Sjmallett */
170210284Sjmallettextern cvmx_mgmt_port_result_t cvmx_mgmt_port_set_mac(int port, uint64_t mac);
171210284Sjmallett
172210284Sjmallett/**
173210284Sjmallett * Get the MAC address for a management port
174210284Sjmallett *
175210284Sjmallett * @param port   Management port
176210284Sjmallett *
177210284Sjmallett * @return MAC address
178210284Sjmallett */
179210284Sjmallettextern uint64_t cvmx_mgmt_port_get_mac(int port);
180215990Sjmallett#define CVMX_MGMT_PORT_GET_MAC_ERROR ((unsigned long long)-2LL)
181210284Sjmallett
182210284Sjmallett/**
183210284Sjmallett * Set the multicast list.
184210284Sjmallett *
185210284Sjmallett * @param port   Management port
186210284Sjmallett * @param flags  Interface flags
187210284Sjmallett *
188210284Sjmallett * @return
189210284Sjmallett */
190210284Sjmallettextern void cvmx_mgmt_port_set_multicast_list(int port, int flags);
191210284Sjmallett
192210284Sjmallett/**
193210284Sjmallett * Set the maximum packet allowed in. Size is specified
194210284Sjmallett * including L2 but without FCS. A normal MTU would corespond
195210284Sjmallett * to 1514 assuming the standard 14 byte L2 header.
196210284Sjmallett *
197210284Sjmallett * @param port   Management port
198215990Sjmallett * @param size_without_fcs
199210284Sjmallett *               Size in bytes without FCS
200210284Sjmallett */
201210284Sjmallettextern void cvmx_mgmt_port_set_max_packet_size(int port, int size_without_fcs);
202210284Sjmallett
203215990Sjmallett/**
204215990Sjmallett * Return the link state of an RGMII/MII port as returned by
205215990Sjmallett * auto negotiation. The result of this function may not match
206215990Sjmallett * Octeon's link config if auto negotiation has changed since
207215990Sjmallett * the last call to __cvmx_mgmt_port_link_set().
208215990Sjmallett *
209215990Sjmallett * @param port     The RGMII/MII interface port to query
210215990Sjmallett *
211215990Sjmallett * @return Link state
212215990Sjmallett */
213215990Sjmallettextern cvmx_helper_link_info_t cvmx_mgmt_port_link_get(int port);
214215990Sjmallett
215215990Sjmallett/**
216215990Sjmallett * Configure RGMII/MII port for the specified link state. This
217215990Sjmallett * function does not influence auto negotiation at the PHY level.
218215990Sjmallett *
219215990Sjmallett * @param port      RGMII/MII interface port
220215990Sjmallett * @param link_info The new link state
221215990Sjmallett *
222215990Sjmallett * @return Zero on success, negative on failure
223215990Sjmallett */
224215990Sjmallettextern int cvmx_mgmt_port_link_set(int port, cvmx_helper_link_info_t link_info);
225215990Sjmallett
226250191Simp/**
227250191Simp * Return the number of management ports supported on this board.
228250191Simp *
229250191Simp * @return Number of ports
230250191Simp */
231250191Simpextern int cvmx_mgmt_port_num_ports(void);
232250191Simp
233215990Sjmallett#ifdef __cplusplus
234215990Sjmallett}
235215990Sjmallett#endif
236215990Sjmallett
237210284Sjmallett#endif /* __CVMX_MGMT_PORT_H__ */
238