cvmx-mgmt-port.h revision 217214
1118611Snjl/***********************license start***************
2118611Snjl * Copyright (c) 2003-2010  Cavium Networks (support@cavium.com). All rights
3118611Snjl * reserved.
4118611Snjl *
5118611Snjl *
6118611Snjl * Redistribution and use in source and binary forms, with or without
7217365Sjkim * modification, are permitted provided that the following conditions are
8245582Sjkim * met:
9118611Snjl *
10118611Snjl *   * Redistributions of source code must retain the above copyright
11217365Sjkim *     notice, this list of conditions and the following disclaimer.
12217365Sjkim *
13217365Sjkim *   * Redistributions in binary form must reproduce the above
14217365Sjkim *     copyright notice, this list of conditions and the following
15217365Sjkim *     disclaimer in the documentation and/or other materials provided
16217365Sjkim *     with the distribution.
17217365Sjkim
18217365Sjkim *   * Neither the name of Cavium Networks nor the names of
19217365Sjkim *     its contributors may be used to endorse or promote products
20217365Sjkim *     derived from this software without specific prior written
21217365Sjkim *     permission.
22217365Sjkim
23217365Sjkim * This Software, including technical data, may be subject to U.S. export  control
24217365Sjkim * laws, including the U.S. Export Administration Act and its  associated
25118611Snjl * regulations, and may be subject to export or import  regulations in other
26217365Sjkim * countries.
27217365Sjkim
28217365Sjkim * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29118611Snjl * AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30217365Sjkim * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31217365Sjkim * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32217365Sjkim * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33217365Sjkim * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34217365Sjkim * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35217365Sjkim * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36217365Sjkim * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37217365Sjkim * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38217365Sjkim ***********************license end**************************************/
39217365Sjkim
40217365Sjkim
41217365Sjkim
42217365Sjkim
43118611Snjl
44151937Sjkim
45193529Sjkim
46193529Sjkim/**
47118611Snjl * @file
48118611Snjl *
49118611Snjl * Support functions for managing the MII management port
50118611Snjl *
51118611Snjl * <hr>$Revision: 49448 $<hr>
52118611Snjl */
53118611Snjl
54118611Snjl#ifndef __CVMX_MGMT_PORT_H__
55118611Snjl#define __CVMX_MGMT_PORT_H__
56118611Snjl
57118611Snjl#include "cvmx-helper.h"
58118611Snjl#include "cvmx-helper-board.h"
59118611Snjl
60118611Snjl#ifdef __cplusplus
61118611Snjlextern "C" {
62118611Snjl#endif
63118611Snjl
64118611Snjl#define CVMX_MGMT_PORT_NUM_PORTS        2       /* Right now we only have one mgmt port */
65118611Snjl#define CVMX_MGMT_PORT_NUM_TX_BUFFERS   16      /* Number of TX ring buffer entries and buffers */
66118611Snjl#define CVMX_MGMT_PORT_NUM_RX_BUFFERS   128     /* Number of RX ring buffer entries and buffers */
67118611Snjl#define CVMX_MGMT_PORT_TX_BUFFER_SIZE   12288   /* Size of each TX/RX buffer */
68118611Snjl#define CVMX_MGMT_PORT_RX_BUFFER_SIZE   1536    /* Size of each TX/RX buffer */
69118611Snjl
70118611Snjltypedef enum
71118611Snjl{
72118611Snjl    CVMX_MGMT_PORT_SUCCESS = 0,
73118611Snjl    CVMX_MGMT_PORT_NO_MEMORY = -1,
74118611Snjl    CVMX_MGMT_PORT_INVALID_PARAM = -2,
75118611Snjl    CVMX_MGMT_PORT_INIT_ERROR = -3,
76118611Snjl} cvmx_mgmt_port_result_t;
77118611Snjl
78118611Snjl
79118611Snjl/* Enumeration of Net Device interface flags. */
80118611Snjltypedef enum
81118611Snjl{
82118611Snjl    CVMX_IFF_PROMISC = 0x100, 		/* receive all packets           */
83118611Snjl    CVMX_IFF_ALLMULTI = 0x200, 		/* receive all multicast packets */
84118611Snjl} cvmx_mgmt_port_netdevice_flags_t;
85118611Snjl
86118611Snjl/**
87118611Snjl * Called to initialize a management port for use. Multiple calls
88118611Snjl * to this function accross applications is safe.
89118611Snjl *
90118611Snjl * @param port   Port to initialize
91118611Snjl *
92118611Snjl * @return CVMX_MGMT_PORT_SUCCESS or an error code
93118611Snjl */
94118611Snjlextern cvmx_mgmt_port_result_t cvmx_mgmt_port_initialize(int port);
95118611Snjl
96118611Snjl/**
97118611Snjl * Shutdown a management port. This currently disables packet IO
98118611Snjl * but leaves all hardware and buffers. Another application can then
99118611Snjl * call initialize() without redoing the hardware setup.
100118611Snjl *
101118611Snjl * @param port   Management port
102241973Sjkim *
103118611Snjl * @return CVMX_MGMT_PORT_SUCCESS or an error code
104118611Snjl */
105118611Snjlextern cvmx_mgmt_port_result_t cvmx_mgmt_port_shutdown(int port);
106118611Snjl
107118611Snjl/**
108118611Snjl * Enable packet IO on a management port
109118611Snjl *
110118611Snjl * @param port   Management port
111118611Snjl *
112118611Snjl * @return CVMX_MGMT_PORT_SUCCESS or an error code
113118611Snjl */
114118611Snjlextern cvmx_mgmt_port_result_t cvmx_mgmt_port_enable(int port);
115118611Snjl
116118611Snjl/**
117118611Snjl * Disable packet IO on a management port
118118611Snjl *
119118611Snjl * @param port   Management port
120118611Snjl *
121118611Snjl * @return CVMX_MGMT_PORT_SUCCESS or an error code
122118611Snjl */
123118611Snjlextern cvmx_mgmt_port_result_t cvmx_mgmt_port_disable(int port);
124118611Snjl
125118611Snjl/**
126118611Snjl * Send a packet out the management port. The packet is copied so
127118611Snjl * the input buffer isn't used after this call.
128228110Sjkim *
129228110Sjkim * @param port       Management port
130228110Sjkim * @param packet_len Length of the packet to send. It does not include the final CRC
131228110Sjkim * @param buffer     Packet data
132228110Sjkim *
133228110Sjkim * @return CVMX_MGMT_PORT_SUCCESS or an error code
134228110Sjkim */
135228110Sjkimextern cvmx_mgmt_port_result_t cvmx_mgmt_port_send(int port, int packet_len, void *buffer);
136228110Sjkim
137228110Sjkim#if defined(__FreeBSD__)
138118611Snjl/**
139118611Snjl * Send a packet out the management port. The packet is copied so
140118611Snjl * the input mbuf isn't used after this call.
141118611Snjl *
142118611Snjl * @param port       Management port
143118611Snjl * @param m          Packet mbuf (with pkthdr)
144118611Snjl *
145118611Snjl * @return CVMX_MGMT_PORT_SUCCESS or an error code
146228110Sjkim */
147228110Sjkimextern cvmx_mgmt_port_result_t cvmx_mgmt_port_sendm(int port, const struct mbuf *m);
148118611Snjl#endif
149118611Snjl
150118611Snjl/**
151118611Snjl * Receive a packet from the management port.
152118611Snjl *
153118611Snjl * @param port       Management port
154118611Snjl * @param buffer_len Size of the buffer to receive the packet into
155118611Snjl * @param buffer     Buffer to receive the packet into
156118611Snjl *
157118611Snjl * @return The size of the packet, or a negative erorr code on failure. Zero
158118611Snjl *         means that no packets were available.
159118611Snjl */
160118611Snjlextern int cvmx_mgmt_port_receive(int port, int buffer_len, uint8_t *buffer);
161118611Snjl
162228110Sjkim/**
163228110Sjkim * Set the MAC address for a management port
164228110Sjkim *
165228110Sjkim * @param port   Management port
166228110Sjkim * @param mac    New MAC address. The lower 6 bytes are used.
167118611Snjl *
168118611Snjl * @return CVMX_MGMT_PORT_SUCCESS or an error code
169118611Snjl */
170118611Snjlextern cvmx_mgmt_port_result_t cvmx_mgmt_port_set_mac(int port, uint64_t mac);
171118611Snjl
172118611Snjl/**
173118611Snjl * Get the MAC address for a management port
174228110Sjkim *
175228110Sjkim * @param port   Management port
176228110Sjkim *
177228110Sjkim * @return MAC address
178118611Snjl */
179118611Snjlextern uint64_t cvmx_mgmt_port_get_mac(int port);
180118611Snjl#define CVMX_MGMT_PORT_GET_MAC_ERROR ((unsigned long long)-2LL)
181228110Sjkim
182118611Snjl/**
183118611Snjl * Set the multicast list.
184118611Snjl *
185118611Snjl * @param port   Management port
186118611Snjl * @param flags  Interface flags
187118611Snjl *
188118611Snjl * @return
189118611Snjl */
190228110Sjkimextern void cvmx_mgmt_port_set_multicast_list(int port, int flags);
191118611Snjl
192118611Snjl/**
193118611Snjl * Set the maximum packet allowed in. Size is specified
194118611Snjl * including L2 but without FCS. A normal MTU would corespond
195118611Snjl * to 1514 assuming the standard 14 byte L2 header.
196118611Snjl *
197118611Snjl * @param port   Management port
198118611Snjl * @param size_without_fcs
199118611Snjl *               Size in bytes without FCS
200118611Snjl */
201228110Sjkimextern void cvmx_mgmt_port_set_max_packet_size(int port, int size_without_fcs);
202228110Sjkim
203118611Snjl/**
204118611Snjl * Return the link state of an RGMII/MII port as returned by
205118611Snjl * auto negotiation. The result of this function may not match
206118611Snjl * Octeon's link config if auto negotiation has changed since
207118611Snjl * the last call to __cvmx_mgmt_port_link_set().
208118611Snjl *
209118611Snjl * @param port     The RGMII/MII interface port to query
210118611Snjl *
211118611Snjl * @return Link state
212138287Smarks */
213118611Snjlextern cvmx_helper_link_info_t cvmx_mgmt_port_link_get(int port);
214118611Snjl
215118611Snjl/**
216118611Snjl * Configure RGMII/MII port for the specified link state. This
217228110Sjkim * function does not influence auto negotiation at the PHY level.
218228110Sjkim *
219167802Sjkim * @param port      RGMII/MII interface port
220118611Snjl * @param link_info The new link state
221118611Snjl *
222138287Smarks * @return Zero on success, negative on failure
223138287Smarks */
224138287Smarksextern int cvmx_mgmt_port_link_set(int port, cvmx_helper_link_info_t link_info);
225118611Snjl
226118611Snjl#ifdef __cplusplus
227118611Snjl}
228118611Snjl#endif
229118611Snjl
230228110Sjkim#endif /* __CVMX_MGMT_PORT_H__ */
231118611Snjl