cvmx-mgmt-port.h revision 259065
1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights 3 * reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 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. 17 18 * * Neither the name of Cavium Inc. nor the names of 19 * its contributors may be used to endorse or promote products 20 * derived from this software without specific prior written 21 * permission. 22 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 26 * countries. 27 28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 29 * AND WITH ALL FAULTS AND CAVIUM INC. 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**************************************/ 39 40 41 42 43 44 45 46/** 47 * @file 48 * 49 * Support functions for managing the MII management port 50 * 51 * <hr>$Revision: 70030 $<hr> 52 */ 53 54#ifndef __CVMX_MGMT_PORT_H__ 55#define __CVMX_MGMT_PORT_H__ 56 57#include "cvmx-helper.h" 58#include "cvmx-helper-board.h" 59 60#ifdef __cplusplus 61extern "C" { 62#endif 63 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 */ 69 70typedef enum 71{ 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; 77 78 79/* Enumeration of Net Device interface flags. */ 80typedef enum 81{ 82 CVMX_IFF_PROMISC = 0x100, /* receive all packets */ 83 CVMX_IFF_ALLMULTI = 0x200, /* receive all multicast packets */ 84} cvmx_mgmt_port_netdevice_flags_t; 85 86/** 87 * Called to initialize a management port for use. Multiple calls 88 * to this function accross applications is safe. 89 * 90 * @param port Port to initialize 91 * 92 * @return CVMX_MGMT_PORT_SUCCESS or an error code 93 */ 94extern cvmx_mgmt_port_result_t cvmx_mgmt_port_initialize(int port); 95 96/** 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. 100 * 101 * @param port Management port 102 * 103 * @return CVMX_MGMT_PORT_SUCCESS or an error code 104 */ 105extern cvmx_mgmt_port_result_t cvmx_mgmt_port_shutdown(int port); 106 107/** 108 * Enable packet IO on a management port 109 * 110 * @param port Management port 111 * 112 * @return CVMX_MGMT_PORT_SUCCESS or an error code 113 */ 114extern cvmx_mgmt_port_result_t cvmx_mgmt_port_enable(int port); 115 116/** 117 * Disable packet IO on a management port 118 * 119 * @param port Management port 120 * 121 * @return CVMX_MGMT_PORT_SUCCESS or an error code 122 */ 123extern cvmx_mgmt_port_result_t cvmx_mgmt_port_disable(int port); 124 125/** 126 * Send a packet out the management port. The packet is copied so 127 * the input buffer isn't used after this call. 128 * 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 132 * 133 * @return CVMX_MGMT_PORT_SUCCESS or an error code 134 */ 135extern cvmx_mgmt_port_result_t cvmx_mgmt_port_send(int port, int packet_len, void *buffer); 136 137#if defined(__FreeBSD__) 138/** 139 * Send a packet out the management port. The packet is copied so 140 * the input mbuf isn't used after this call. 141 * 142 * @param port Management port 143 * @param m Packet mbuf (with pkthdr) 144 * 145 * @return CVMX_MGMT_PORT_SUCCESS or an error code 146 */ 147extern cvmx_mgmt_port_result_t cvmx_mgmt_port_sendm(int port, const struct mbuf *m); 148#endif 149 150/** 151 * Receive a packet from the management port. 152 * 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 156 * 157 * @return The size of the packet, or a negative erorr code on failure. Zero 158 * means that no packets were available. 159 */ 160extern int cvmx_mgmt_port_receive(int port, int buffer_len, uint8_t *buffer); 161 162/** 163 * Set the MAC address for a management port 164 * 165 * @param port Management port 166 * @param mac New MAC address. The lower 6 bytes are used. 167 * 168 * @return CVMX_MGMT_PORT_SUCCESS or an error code 169 */ 170extern cvmx_mgmt_port_result_t cvmx_mgmt_port_set_mac(int port, uint64_t mac); 171 172/** 173 * Get the MAC address for a management port 174 * 175 * @param port Management port 176 * 177 * @return MAC address 178 */ 179extern uint64_t cvmx_mgmt_port_get_mac(int port); 180#define CVMX_MGMT_PORT_GET_MAC_ERROR ((unsigned long long)-2LL) 181 182/** 183 * Set the multicast list. 184 * 185 * @param port Management port 186 * @param flags Interface flags 187 * 188 * @return 189 */ 190extern void cvmx_mgmt_port_set_multicast_list(int port, int flags); 191 192/** 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. 196 * 197 * @param port Management port 198 * @param size_without_fcs 199 * Size in bytes without FCS 200 */ 201extern void cvmx_mgmt_port_set_max_packet_size(int port, int size_without_fcs); 202 203/** 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(). 208 * 209 * @param port The RGMII/MII interface port to query 210 * 211 * @return Link state 212 */ 213extern cvmx_helper_link_info_t cvmx_mgmt_port_link_get(int port); 214 215/** 216 * Configure RGMII/MII port for the specified link state. This 217 * function does not influence auto negotiation at the PHY level. 218 * 219 * @param port RGMII/MII interface port 220 * @param link_info The new link state 221 * 222 * @return Zero on success, negative on failure 223 */ 224extern int cvmx_mgmt_port_link_set(int port, cvmx_helper_link_info_t link_info); 225 226/** 227 * Return the number of management ports supported on this board. 228 * 229 * @return Number of ports 230 */ 231extern int cvmx_mgmt_port_num_ports(void); 232 233#ifdef __cplusplus 234} 235#endif 236 237#endif /* __CVMX_MGMT_PORT_H__ */ 238