1 /*******************************************************************************
2 Copyright (C) Marvell International Ltd. and its affiliates
4 This software file (the "File") is owned and distributed by Marvell
5 International Ltd. and/or its affiliates ("Marvell") under the following
6 alternative licensing terms. Once you have made an election to distribute the
7 File under one of the following license alternatives, please (i) delete this
8 introductory statement regarding license alternatives, (ii) delete the two
9 license alternatives that you have not elected to use and (iii) preserve the
10 Marvell copyright notice above.
12 ********************************************************************************
13 Marvell Commercial License Option
15 If you received this File from Marvell and you have entered into a commercial
16 license agreement (a "Commercial License") with Marvell, the File is licensed
17 to you under the terms of the applicable Commercial License.
19 ********************************************************************************
20 Marvell GPL License Option
22 If you received this File from Marvell, you may opt to use, redistribute and/or
23 modify this File in accordance with the terms and conditions of the General
24 Public License Version 2, June 1991 (the "GPL License"), a copy of which is
25 available along with the File in the license.txt file or by writing to the Free
26 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
27 on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
29 THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
30 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
31 DISCLAIMED. The GPL License provides additional details about this warranty
33 ********************************************************************************
34 Marvell BSD License Option
36 If you received this File from Marvell, you may opt to use, redistribute and/or
37 modify this File under the following licensing terms.
38 Redistribution and use in source and binary forms, with or without modification,
39 are permitted provided that the following conditions are met:
41 * Redistributions of source code must retain the above copyright notice,
42 this list of conditions and the following disclaimer.
44 * Redistributions in binary form must reproduce the above copyright
45 notice, this list of conditions and the following disclaimer in the
46 documentation and/or other materials provided with the distribution.
48 * Neither the name of Marvell nor the names of its contributors may be
49 used to endorse or promote products derived from this software without
50 specific prior written permission.
52 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
53 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
55 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
56 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
57 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
58 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
59 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
61 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *******************************************************************************/
65 /*******************************************************************************
66 * mvEth.h - Header File for : Ethernet Controller
69 * This header file contains macros typedefs and function declaration for
70 * Marvell Gigabit Ethernet Controllers.
75 *******************************************************************************/
83 #include "ctrlEnv/mvCtrlEnvLib.h"
84 #include "ctrlEnv/mvCtrlEnvAddrDec.h"
85 #include "eth/gbe/mvEthRegs.h"
86 #include "mvSysHwConfig.h"
90 #define MV_ETH_EXTRA_FRAGS_NUM 2
108 } MV_ETH_PORT_DUPLEX
;
112 MV_ETH_FC_AN_ADV_DIS
,
113 MV_ETH_FC_AN_ADV_SYM
,
121 MV_ETH_PRIO_FIXED
= 0, /* Fixed priority mode */
122 MV_ETH_PRIO_WRR
= 1 /* Weighted round robin priority mode */
125 /* Ethernet port specific infomation */
145 MV_ETH_PRIO_MODE prioMode
;
153 int txDescrNum
[MV_ETH_TX_Q_NUM
];
154 int rxDescrNum
[MV_ETH_RX_Q_NUM
];
161 MV_ETH_PORT_SPEED speed
;
162 MV_ETH_PORT_DUPLEX duplex
;
163 MV_ETH_PORT_FC flowControl
;
165 } MV_ETH_PORT_STATUS
;
169 MV_ETH_DISABLE_HEADER_MODE
= 0,
170 MV_ETH_ENABLE_HEADER_MODE_PRI_2_1
= 1,
171 MV_ETH_ENABLE_HEADER_MODE_PRI_DBNUM
= 2,
172 MV_ETH_ENABLE_HEADER_MODE_PRI_SPID
= 3
173 } MV_ETH_HEADER_MODE
;
176 /* ethernet.h API list */
177 void mvEthHalInit(void);
178 void mvEthMemAttrGet(MV_BOOL
* pIsSram
, MV_BOOL
* pIsSwCoher
);
180 /* Port Initalization routines */
181 void* mvEthPortInit (int port
, MV_ETH_PORT_INIT
*pPortInit
);
182 void ethResetTxDescRing(void* pPortHndl
, int queue
);
183 void ethResetRxDescRing(void* pPortHndl
, int queue
);
185 void* mvEthPortHndlGet(int port
);
187 void mvEthPortFinish(void* pEthPortHndl
);
188 MV_STATUS
mvEthPortDown(void* pEthPortHndl
);
189 MV_STATUS
mvEthPortDisable(void* pEthPortHndl
);
190 MV_STATUS
mvEthPortUp(void* pEthPortHndl
);
191 MV_STATUS
mvEthPortEnable(void* pEthPortHndl
);
193 /* Port data flow routines */
194 MV_PKT_INFO
*mvEthPortForceTxDone(void* pEthPortHndl
, int txQueue
);
195 MV_PKT_INFO
*mvEthPortForceRx(void* pEthPortHndl
, int rxQueue
);
197 /* Port Configuration routines */
198 MV_STATUS
mvEthDefaultsSet(void* pEthPortHndl
);
199 MV_STATUS
mvEthMaxRxSizeSet(void* pPortHndl
, int maxRxSize
);
201 /* Port RX MAC Filtering control routines */
202 MV_U8
mvEthMcastCrc8Get(MV_U8
* pAddr
);
203 MV_STATUS
mvEthRxFilterModeSet(void* pPortHndl
, MV_BOOL isPromisc
);
204 MV_STATUS
mvEthMacAddrSet(void* pPortHandle
, MV_U8
* pMacAddr
, int queue
);
205 MV_STATUS
mvEthMcastAddrSet(void* pPortHandle
, MV_U8
*pAddr
, int queue
);
207 /* MIB Counters APIs */
208 MV_U32
mvEthMibCounterRead(void* pPortHndl
, unsigned int mibOffset
,
210 void mvEthMibCountersClear(void* pPortHandle
);
212 /* TX Scheduling configuration routines */
213 MV_STATUS
mvEthTxQueueConfig(void* pPortHandle
, int txQueue
,
214 MV_ETH_PRIO_MODE txPrioMode
, int txQuota
);
216 /* RX Dispatching configuration routines */
217 MV_STATUS
mvEthBpduRxQueue(void* pPortHandle
, int bpduQueue
);
218 MV_STATUS
mvEthVlanPrioRxQueue(void* pPortHandle
, int vlanPrio
, int vlanPrioQueue
);
219 MV_STATUS
mvEthTosToRxqSet(void* pPortHandle
, int tos
, int rxq
);
220 int mvEthTosToRxqGet(void* pPortHandle
, int tos
);
222 /* Speed, Duplex, FlowControl routines */
223 MV_STATUS
mvEthSpeedDuplexSet(void* pPortHandle
, MV_ETH_PORT_SPEED speed
,
224 MV_ETH_PORT_DUPLEX duplex
);
226 MV_STATUS
mvEthFlowCtrlSet(void* pPortHandle
, MV_ETH_PORT_FC flowControl
);
228 #if (MV_ETH_VERSION >= 4)
229 MV_STATUS
mvEthEjpModeSet(void* pPortHandle
, int mode
);
230 #endif /* (MV_ETH_VERSION >= 4) */
232 void mvEthStatusGet(void* pPortHandle
, MV_ETH_PORT_STATUS
* pStatus
);
234 /* Marvell Header control */
235 MV_STATUS
mvEthHeaderModeSet(void* pPortHandle
, MV_ETH_HEADER_MODE headerMode
);
238 void mvEthPhyAddrSet(void* pPortHandle
, int phyAddr
);
239 int mvEthPhyAddrGet(void* pPortHandle
);
241 /* Power management routines */
242 void mvEthPortPowerDown(int port
);
243 void mvEthPortPowerUp(int port
);
245 /******************** ETH PRIVATE ************************/
247 /*#define UNCACHED_TX_BUFFERS*/
248 /*#define UNCACHED_RX_BUFFERS*/
251 /* Port attributes */
252 /* Size of a Tx/Rx descriptor used in chain list data structure */
253 #define ETH_RX_DESC_ALIGNED_SIZE 32
254 #define ETH_TX_DESC_ALIGNED_SIZE 32
256 #define TX_DISABLE_TIMEOUT_MSEC 1000
257 #define RX_DISABLE_TIMEOUT_MSEC 1000
258 #define TX_FIFO_EMPTY_TIMEOUT_MSEC 10000
259 #define PORT_DISABLE_WAIT_TCLOCKS 5000
261 /* Macros that save access to desc in order to find next desc pointer */
262 #define RX_NEXT_DESC_PTR(pRxDescr, pQueueCtrl) \
263 ((pRxDescr) == (pQueueCtrl)->pLastDescr) ? \
264 (ETH_RX_DESC*)((pQueueCtrl)->pFirstDescr) : \
265 (ETH_RX_DESC*)(((MV_ULONG)(pRxDescr)) + ETH_RX_DESC_ALIGNED_SIZE)
267 #define TX_NEXT_DESC_PTR(pTxDescr, pQueueCtrl) \
268 ((pTxDescr) == (pQueueCtrl)->pLastDescr) ? \
269 (ETH_TX_DESC*)((pQueueCtrl)->pFirstDescr) : \
270 (ETH_TX_DESC*)(((MV_ULONG)(pTxDescr)) + ETH_TX_DESC_ALIGNED_SIZE)
272 #define RX_PREV_DESC_PTR(pRxDescr, pQueueCtrl) \
273 ((pRxDescr) == (pQueueCtrl)->pFirstDescr) ? \
274 (ETH_RX_DESC*)((pQueueCtrl)->pLastDescr) : \
275 (ETH_RX_DESC*)(((MV_ULONG)(pRxDescr)) - ETH_RX_DESC_ALIGNED_SIZE)
277 #define TX_PREV_DESC_PTR(pTxDescr, pQueueCtrl) \
278 ((pTxDescr) == (pQueueCtrl)->pFirstDescr) ? \
279 (ETH_TX_DESC*)((pQueueCtrl)->pLastDescr) : \
280 (ETH_TX_DESC*)(((MV_ULONG)(pTxDescr)) - ETH_TX_DESC_ALIGNED_SIZE)
283 /* Queue specific information */
295 /* Ethernet port specific infomation */
296 typedef struct _ethPortCtrl
299 ETH_QUEUE_CTRL rxQueue
[MV_ETH_RX_Q_NUM
]; /* Rx ring resource */
300 ETH_QUEUE_CTRL txQueue
[MV_ETH_TX_Q_NUM
]; /* Tx ring resource */
302 MV_ETH_PORT_CFG portConfig
;
303 MV_ETH_RX_Q_CFG rxQueueConfig
[MV_ETH_RX_Q_NUM
];
304 MV_ETH_TX_Q_CFG txQueueConfig
[MV_ETH_TX_Q_NUM
];
306 /* Register images - For DP */
307 MV_U32 portTxQueueCmdReg
; /* Port active Tx queues summary */
308 MV_U32 portRxQueueCmdReg
; /* Port active Rx queues summary */
312 MV_U8 mcastCount
[256];
317 /************** MACROs ****************/
319 /* MACROs to Flush / Invalidate TX / RX Buffers */
320 #if (ETHER_DRAM_COHER == MV_CACHE_COHER_SW) && !defined(UNCACHED_TX_BUFFERS)
321 # define ETH_PACKET_CACHE_FLUSH(pAddr, size) \
322 mvOsCacheClear(NULL, (pAddr), (size)); \
325 # define ETH_PACKET_CACHE_FLUSH(pAddr, size) \
326 mvOsIoVirtToPhy(NULL, (pAddr));
327 #endif /* ETHER_DRAM_COHER == MV_CACHE_COHER_SW */
329 #if ( (ETHER_DRAM_COHER == MV_CACHE_COHER_SW) && !defined(UNCACHED_RX_BUFFERS) )
330 # define ETH_PACKET_CACHE_INVALIDATE(pAddr, size) \
331 mvOsCacheInvalidate (NULL, (pAddr), (size)); \
334 # define ETH_PACKET_CACHE_INVALIDATE(pAddr, size)
335 #endif /* ETHER_DRAM_COHER == MV_CACHE_COHER_SW && !UNCACHED_RX_BUFFERS */
337 #ifdef ETH_DESCR_UNCACHED
339 #define ETH_DESCR_FLUSH_INV(pPortCtrl, pDescr)
340 #define ETH_DESCR_INV(pPortCtrl, pDescr)
344 #define ETH_DESCR_FLUSH_INV(pPortCtrl, pDescr) \
345 mvOsCacheLineFlushInv(pPortCtrl->osHandle, (MV_ULONG)(pDescr))
347 #define ETH_DESCR_INV(pPortCtrl, pDescr) \
348 mvOsCacheLineInv(pPortCtrl->osHandle, (MV_ULONG)(pDescr))
350 #endif /* ETH_DESCR_UNCACHED */
352 #include "eth/gbe/mvEthGbe.h"
354 #endif /* __mvEth_h__ */