1 /* Copyright (c) 2008-2012 Freescale Semiconductor, Inc 2 * All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution. 11 * * Neither the name of Freescale Semiconductor nor the 12 * names of its contributors may be used to endorse or promote products 13 * derived from this software without specific prior written permission. 14 * 15 * 16 * ALTERNATIVELY, this software may be distributed under the terms of the 17 * GNU General Public License ("GPL") as published by the Free Software 18 * Foundation, either version 2 of that License or (at your option) any 19 * later version. 20 * 21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 34 /**************************************************************************//** 35 @File enet_ext.h 36 37 @Description Ethernet generic definitions and enums. 38 *//***************************************************************************/ 39 40 #ifndef __ENET_EXT_H 41 #define __ENET_EXT_H 42 43 #include "fsl_enet.h" 44 45 #define ENET_NUM_OCTETS_PER_ADDRESS 6 /**< Number of octets (8-bit bytes) in an ethernet address */ 46 #define ENET_GROUP_ADDR 0x01 /**< Group address mask for ethernet addresses */ 47 48 49 /**************************************************************************//** 50 @Description Ethernet Address 51 *//***************************************************************************/ 52 typedef uint8_t t_EnetAddr[ENET_NUM_OCTETS_PER_ADDRESS]; 53 54 /**************************************************************************//** 55 @Description Ethernet Address Type. 56 *//***************************************************************************/ 57 typedef enum e_EnetAddrType 58 { 59 e_ENET_ADDR_TYPE_INDIVIDUAL, /**< Individual (unicast) address */ 60 e_ENET_ADDR_TYPE_GROUP, /**< Group (multicast) address */ 61 e_ENET_ADDR_TYPE_BROADCAST /**< Broadcast address */ 62 } e_EnetAddrType; 63 64 /**************************************************************************//** 65 @Description Ethernet MAC-PHY Interface 66 *//***************************************************************************/ 67 typedef enum e_EnetInterface 68 { 69 e_ENET_IF_MII = E_ENET_IF_MII, /**< MII interface */ 70 e_ENET_IF_RMII = E_ENET_IF_RMII, /**< RMII interface */ 71 e_ENET_IF_SMII = E_ENET_IF_SMII, /**< SMII interface */ 72 e_ENET_IF_GMII = E_ENET_IF_GMII, /**< GMII interface */ 73 e_ENET_IF_RGMII = E_ENET_IF_RGMII, /**< RGMII interface */ 74 e_ENET_IF_TBI = E_ENET_IF_TBI, /**< TBI interface */ 75 e_ENET_IF_RTBI = E_ENET_IF_RTBI, /**< RTBI interface */ 76 e_ENET_IF_SGMII = E_ENET_IF_SGMII, /**< SGMII interface */ 77 e_ENET_IF_XGMII = E_ENET_IF_XGMII, /**< XGMII interface */ 78 e_ENET_IF_QSGMII= E_ENET_IF_QSGMII, /**< QSGMII interface */ 79 e_ENET_IF_XFI = E_ENET_IF_XFI /**< XFI interface */ 80 } e_EnetInterface; 81 82 #define ENET_IF_SGMII_BASEX 0x80000000 /**< SGMII/QSGII interface with 1000BaseX 83 auto-negotiation between MAC and phy 84 or backplane; 85 Note: 1000BaseX auto-negotiation relates 86 only to interface between MAC and phy/backplane, 87 SGMII phy can still synchronize with far-end phy 88 at 10Mbps, 100Mbps or 1000Mbps */ 89 90 /**************************************************************************//** 91 @Description Ethernet Duplex Mode 92 *//***************************************************************************/ 93 typedef enum e_EnetDuplexMode 94 { 95 e_ENET_HALF_DUPLEX, /**< Half-Duplex mode */ 96 e_ENET_FULL_DUPLEX /**< Full-Duplex mode */ 97 } e_EnetDuplexMode; 98 99 /**************************************************************************//** 100 @Description Ethernet Speed (nominal data rate) 101 *//***************************************************************************/ 102 typedef enum e_EnetSpeed 103 { 104 e_ENET_SPEED_10 = E_ENET_SPEED_10, /**< 10 Mbps */ 105 e_ENET_SPEED_100 = E_ENET_SPEED_100, /**< 100 Mbps */ 106 e_ENET_SPEED_1000 = E_ENET_SPEED_1000, /**< 1000 Mbps = 1 Gbps */ 107 e_ENET_SPEED_2500 = E_ENET_SPEED_2500, /**< 2500 Mbps = 2.5 Gbps */ 108 e_ENET_SPEED_10000 = E_ENET_SPEED_10000 /**< 10000 Mbps = 10 Gbps */ 109 } e_EnetSpeed; 110 111 /**************************************************************************//** 112 @Description Ethernet mode (combination of MAC-PHY interface and speed) 113 *//***************************************************************************/ 114 typedef enum e_EnetMode 115 { 116 e_ENET_MODE_INVALID = 0, /**< Invalid Ethernet mode */ 117 e_ENET_MODE_MII_10 = (e_ENET_IF_MII | e_ENET_SPEED_10), /**< 10 Mbps MII */ 118 e_ENET_MODE_MII_100 = (e_ENET_IF_MII | e_ENET_SPEED_100), /**< 100 Mbps MII */ 119 e_ENET_MODE_RMII_10 = (e_ENET_IF_RMII | e_ENET_SPEED_10), /**< 10 Mbps RMII */ 120 e_ENET_MODE_RMII_100 = (e_ENET_IF_RMII | e_ENET_SPEED_100), /**< 100 Mbps RMII */ 121 e_ENET_MODE_SMII_10 = (e_ENET_IF_SMII | e_ENET_SPEED_10), /**< 10 Mbps SMII */ 122 e_ENET_MODE_SMII_100 = (e_ENET_IF_SMII | e_ENET_SPEED_100), /**< 100 Mbps SMII */ 123 e_ENET_MODE_GMII_1000 = (e_ENET_IF_GMII | e_ENET_SPEED_1000), /**< 1000 Mbps GMII */ 124 e_ENET_MODE_RGMII_10 = (e_ENET_IF_RGMII | e_ENET_SPEED_10), /**< 10 Mbps RGMII */ 125 e_ENET_MODE_RGMII_100 = (e_ENET_IF_RGMII | e_ENET_SPEED_100), /**< 100 Mbps RGMII */ 126 e_ENET_MODE_RGMII_1000 = (e_ENET_IF_RGMII | e_ENET_SPEED_1000), /**< 1000 Mbps RGMII */ 127 e_ENET_MODE_TBI_1000 = (e_ENET_IF_TBI | e_ENET_SPEED_1000), /**< 1000 Mbps TBI */ 128 e_ENET_MODE_RTBI_1000 = (e_ENET_IF_RTBI | e_ENET_SPEED_1000), /**< 1000 Mbps RTBI */ 129 e_ENET_MODE_SGMII_10 = (e_ENET_IF_SGMII | e_ENET_SPEED_10), 130 /**< 10 Mbps SGMII with auto-negotiation between MAC and 131 SGMII phy according to Cisco SGMII specification */ 132 e_ENET_MODE_SGMII_100 = (e_ENET_IF_SGMII | e_ENET_SPEED_100), 133 /**< 100 Mbps SGMII with auto-negotiation between MAC and 134 SGMII phy according to Cisco SGMII specification */ 135 e_ENET_MODE_SGMII_1000 = (e_ENET_IF_SGMII | e_ENET_SPEED_1000), 136 /**< 1000 Mbps SGMII with auto-negotiation between MAC and 137 SGMII phy according to Cisco SGMII specification */ 138 e_ENET_MODE_SGMII_2500 = (e_ENET_IF_SGMII | e_ENET_SPEED_2500), 139 e_ENET_MODE_SGMII_BASEX_10 = (ENET_IF_SGMII_BASEX | e_ENET_IF_SGMII | e_ENET_SPEED_10), 140 /**< 10 Mbps SGMII with 1000BaseX auto-negotiation between 141 MAC and SGMII phy or backplane */ 142 e_ENET_MODE_SGMII_BASEX_100 = (ENET_IF_SGMII_BASEX | e_ENET_IF_SGMII | e_ENET_SPEED_100), 143 /**< 100 Mbps SGMII with 1000BaseX auto-negotiation between 144 MAC and SGMII phy or backplane */ 145 e_ENET_MODE_SGMII_BASEX_1000 = (ENET_IF_SGMII_BASEX | e_ENET_IF_SGMII | e_ENET_SPEED_1000), 146 /**< 1000 Mbps SGMII with 1000BaseX auto-negotiation between 147 MAC and SGMII phy or backplane */ 148 e_ENET_MODE_QSGMII_1000 = (e_ENET_IF_QSGMII| e_ENET_SPEED_1000), 149 /**< 1000 Mbps QSGMII with auto-negotiation between MAC and 150 QSGMII phy according to Cisco QSGMII specification */ 151 e_ENET_MODE_QSGMII_BASEX_1000 = (ENET_IF_SGMII_BASEX | e_ENET_IF_QSGMII| e_ENET_SPEED_1000), 152 /**< 1000 Mbps QSGMII with 1000BaseX auto-negotiation between 153 MAC and QSGMII phy or backplane */ 154 e_ENET_MODE_XGMII_10000 = (e_ENET_IF_XGMII | e_ENET_SPEED_10000), /**< 10000 Mbps XGMII */ 155 e_ENET_MODE_XFI_10000 = (e_ENET_IF_XFI | e_ENET_SPEED_10000) /**< 10000 Mbps XFI */ 156 } e_EnetMode; 157 158 159 #define IS_ENET_MODE_VALID(mode) \ 160 (((mode) == e_ENET_MODE_MII_10 ) || \ 161 ((mode) == e_ENET_MODE_MII_100 ) || \ 162 ((mode) == e_ENET_MODE_RMII_10 ) || \ 163 ((mode) == e_ENET_MODE_RMII_100 ) || \ 164 ((mode) == e_ENET_MODE_SMII_10 ) || \ 165 ((mode) == e_ENET_MODE_SMII_100 ) || \ 166 ((mode) == e_ENET_MODE_GMII_1000 ) || \ 167 ((mode) == e_ENET_MODE_RGMII_10 ) || \ 168 ((mode) == e_ENET_MODE_RGMII_100 ) || \ 169 ((mode) == e_ENET_MODE_RGMII_1000 ) || \ 170 ((mode) == e_ENET_MODE_TBI_1000 ) || \ 171 ((mode) == e_ENET_MODE_RTBI_1000 ) || \ 172 ((mode) == e_ENET_MODE_SGMII_10 ) || \ 173 ((mode) == e_ENET_MODE_SGMII_100 ) || \ 174 ((mode) == e_ENET_MODE_SGMII_1000 ) || \ 175 ((mode) == e_ENET_MODE_SGMII_BASEX_10 ) || \ 176 ((mode) == e_ENET_MODE_SGMII_BASEX_100 ) || \ 177 ((mode) == e_ENET_MODE_SGMII_BASEX_1000 ) || \ 178 ((mode) == e_ENET_MODE_XGMII_10000) || \ 179 ((mode) == e_ENET_MODE_QSGMII_1000) || \ 180 ((mode) == e_ENET_MODE_QSGMII_BASEX_1000) || \ 181 ((mode) == e_ENET_MODE_XFI_10000)) 182 183 184 #define MAKE_ENET_MODE(_interface, _speed) (e_EnetMode)((_interface) | (_speed)) 185 186 #define ENET_INTERFACE_FROM_MODE(mode) (e_EnetInterface)((mode) & 0x0FFF0000) 187 #define ENET_SPEED_FROM_MODE(mode) (e_EnetSpeed)((mode) & 0x0000FFFF) 188 189 #define ENET_ADDR_TO_UINT64(_enetAddr) \ 190 (uint64_t)(((uint64_t)(_enetAddr)[0] << 40) | \ 191 ((uint64_t)(_enetAddr)[1] << 32) | \ 192 ((uint64_t)(_enetAddr)[2] << 24) | \ 193 ((uint64_t)(_enetAddr)[3] << 16) | \ 194 ((uint64_t)(_enetAddr)[4] << 8) | \ 195 ((uint64_t)(_enetAddr)[5])) 196 197 #define MAKE_ENET_ADDR_FROM_UINT64(_addr64, _enetAddr) \ 198 do { \ 199 int i; \ 200 for (i=0; i < ENET_NUM_OCTETS_PER_ADDRESS; i++) \ 201 (_enetAddr)[i] = (uint8_t)((_addr64) >> ((5-i)*8)); \ 202 } while (0) 203 204 205 #endif /* __ENET_EXT_H */ 206