1 /******************************************************************************
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
12 * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
13 * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
14 * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,
15 * XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
16 * FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING
17 * ANY THIRD PARTY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
18 * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
19 * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
20 * WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM
21 * CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE.
25 * Xilinx hardware products are not intended for use in life support
26 * appliances, devices, or systems. Use in such applications is
27 * expressly prohibited.
30 * (c) Copyright 2002-2004 Xilinx Inc.
31 * All rights reserved.
34 * You should have received a copy of the GNU General Public License along
35 * with this program; if not, write to the Free Software Foundation, Inc.,
36 * 675 Mass Ave, Cambridge, MA 02139, USA.
38 ******************************************************************************/
39 /*****************************************************************************/
42 * @file xemac_options.c
44 * Functions in this file handle configuration of the XEmac driver.
47 * MODIFICATION HISTORY:
49 * Ver Who Date Changes
50 * ----- ---- -------- -----------------------------------------------
51 * 1.00a rpm 07/31/01 First release
52 * 1.00b rpm 02/20/02 Repartitioned files and functions
53 * 1.00c rpm 12/05/02 New version includes support for simple DMA
56 ******************************************************************************/
58 /***************************** Include Files *********************************/
60 #include "xbasic_types.h"
64 /************************** Constant Definitions *****************************/
66 #define XEM_MAX_IFG 32 /* Maximum Interframe gap value */
68 /**************************** Type Definitions *******************************/
70 /***************** Macros (Inline Functions) Definitions *********************/
72 /************************** Function Prototypes ******************************/
74 /************************** Variable Definitions *****************************/
77 * A table of options and masks. This table maps the user-visible options with
78 * the control register masks. It is used in Set/GetOptions as an alternative
79 * to a series of if/else pairs. Note that the polled options does not have a
80 * corresponding entry in the control register, so it does not exist in the
88 static OptionMap OptionsTable[] = {
89 {XEM_UNICAST_OPTION, XEM_ECR_UNICAST_ENABLE_MASK},
90 {XEM_BROADCAST_OPTION, XEM_ECR_BROAD_ENABLE_MASK},
91 {XEM_PROMISC_OPTION, XEM_ECR_PROMISC_ENABLE_MASK},
92 {XEM_FDUPLEX_OPTION, XEM_ECR_FULL_DUPLEX_MASK},
93 {XEM_LOOPBACK_OPTION, XEM_ECR_LOOPBACK_MASK},
94 {XEM_MULTICAST_OPTION, XEM_ECR_MULTI_ENABLE_MASK},
95 {XEM_FLOW_CONTROL_OPTION, XEM_ECR_PAUSE_FRAME_MASK},
96 {XEM_INSERT_PAD_OPTION, XEM_ECR_XMIT_PAD_ENABLE_MASK},
97 {XEM_INSERT_FCS_OPTION, XEM_ECR_XMIT_FCS_ENABLE_MASK},
98 {XEM_INSERT_ADDR_OPTION, XEM_ECR_XMIT_ADDR_INSERT_MASK},
99 {XEM_OVWRT_ADDR_OPTION, XEM_ECR_XMIT_ADDR_OVWRT_MASK},
100 {XEM_STRIP_PAD_FCS_OPTION, XEM_ECR_RECV_STRIP_ENABLE_MASK}
103 #define XEM_NUM_OPTIONS (sizeof(OptionsTable) / sizeof(OptionMap))
105 /*****************************************************************************/
108 * Set Ethernet driver/device options. The device must be stopped before
109 * calling this function. The options are contained within a bit-mask with each
110 * bit representing an option (i.e., you can OR the options together). A one (1)
111 * in the bit-mask turns an option on, and a zero (0) turns the option off.
113 * @param InstancePtr is a pointer to the XEmac instance to be worked on.
114 * @param OptionsFlag is a bit-mask representing the Ethernet options to turn on
115 * or off. See xemac.h for a description of the available options.
119 * - XST_SUCCESS if the options were set successfully
120 * - XST_DEVICE_IS_STARTED if the device has not yet been stopped
124 * This function is not thread-safe and makes use of internal resources that are
125 * shared between the Start, Stop, and SetOptions functions, so if one task
126 * might be setting device options while another is trying to start the device,
127 * protection of this shared data (typically using a semaphore) is required.
129 ******************************************************************************/
131 XEmac_SetOptions(XEmac * InstancePtr, u32 OptionsFlag)
136 XASSERT_NONVOID(InstancePtr != NULL);
137 XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
139 if (InstancePtr->IsStarted == XCOMPONENT_IS_STARTED) {
140 return XST_DEVICE_IS_STARTED;
143 ControlReg = XIo_In32(InstancePtr->BaseAddress + XEM_ECR_OFFSET);
146 * Loop through the options table, turning the option on or off
147 * depending on whether the bit is set in the incoming options flag.
149 for (Index = 0; Index < XEM_NUM_OPTIONS; Index++) {
150 if (OptionsFlag & OptionsTable[Index].Option) {
151 ControlReg |= OptionsTable[Index].Mask; /* turn it on */
153 ControlReg &= ~OptionsTable[Index].Mask; /* turn it off */
158 * TODO: need to validate addr-overwrite only if addr-insert?
162 * Now write the control register. Leave it to the upper layers
163 * to restart the device.
165 XIo_Out32(InstancePtr->BaseAddress + XEM_ECR_OFFSET, ControlReg);
168 * Check the polled option
170 if (OptionsFlag & XEM_POLLED_OPTION) {
171 InstancePtr->IsPolled = TRUE;
173 InstancePtr->IsPolled = FALSE;
179 /*****************************************************************************/
182 * Get Ethernet driver/device options. The 32-bit value returned is a bit-mask
183 * representing the options. A one (1) in the bit-mask means the option is on,
184 * and a zero (0) means the option is off.
186 * @param InstancePtr is a pointer to the XEmac instance to be worked on.
190 * The 32-bit value of the Ethernet options. The value is a bit-mask
191 * representing all options that are currently enabled. See xemac.h for a
192 * description of the available options.
198 ******************************************************************************/
200 XEmac_GetOptions(XEmac * InstancePtr)
206 XASSERT_NONVOID(InstancePtr != NULL);
207 XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
210 * Get the control register to determine which options are currently set.
212 ControlReg = XIo_In32(InstancePtr->BaseAddress + XEM_ECR_OFFSET);
215 * Loop through the options table to determine which options are set
217 for (Index = 0; Index < XEM_NUM_OPTIONS; Index++) {
218 if (ControlReg & OptionsTable[Index].Mask) {
219 OptionsFlag |= OptionsTable[Index].Option;
223 if (InstancePtr->IsPolled) {
224 OptionsFlag |= XEM_POLLED_OPTION;
230 /*****************************************************************************/
233 * Set the Interframe Gap (IFG), which is the time the MAC delays between
234 * transmitting frames. There are two parts required. The total interframe gap
235 * is the total of the two parts. The values provided for the Part1 and Part2
236 * parameters are multiplied by 4 to obtain the bit-time interval. The first
237 * part should be the first 2/3 of the total interframe gap. The MAC will reset
238 * the interframe gap timer if carrier sense becomes true during the period
239 * defined by interframe gap Part1. Part1 may be shorter than 2/3 the total and
240 * can be as small as zero. The second part should be the last 1/3 of the total
241 * interframe gap, but can be as large as the total interframe gap. The MAC
242 * will not reset the interframe gap timer if carrier sense becomes true during
243 * the period defined by interframe gap Part2.
245 * The device must be stopped before setting the interframe gap.
247 * @param InstancePtr is a pointer to the XEmac instance to be worked on.
248 * @param Part1 is the interframe gap part 1 (which will be multiplied by 4 to
249 * get the bit-time interval).
250 * @param Part2 is the interframe gap part 2 (which will be multiplied by 4 to
251 * get the bit-time interval).
255 * - XST_SUCCESS if the interframe gap was set successfully
256 * - XST_DEVICE_IS_STARTED if the device has not been stopped
262 ******************************************************************************/
264 XEmac_SetInterframeGap(XEmac * InstancePtr, u8 Part1, u8 Part2)
268 XASSERT_NONVOID(InstancePtr != NULL);
269 XASSERT_NONVOID(Part1 < XEM_MAX_IFG);
270 XASSERT_NONVOID(Part2 < XEM_MAX_IFG);
271 XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
274 * Be sure device has been stopped
276 if (InstancePtr->IsStarted == XCOMPONENT_IS_STARTED) {
277 return XST_DEVICE_IS_STARTED;
280 Ifg = Part1 << XEM_IFGP_PART1_SHIFT;
281 Ifg |= (Part2 << XEM_IFGP_PART2_SHIFT);
282 XIo_Out32(InstancePtr->BaseAddress + XEM_IFGP_OFFSET, Ifg);
287 /*****************************************************************************/
290 * Get the interframe gap, parts 1 and 2. See the description of interframe gap
291 * above in XEmac_SetInterframeGap().
293 * @param InstancePtr is a pointer to the XEmac instance to be worked on.
294 * @param Part1Ptr is a pointer to an 8-bit buffer into which the interframe gap
295 * part 1 value will be copied.
296 * @param Part2Ptr is a pointer to an 8-bit buffer into which the interframe gap
297 * part 2 value will be copied.
301 * None. The values of the interframe gap parts are copied into the
304 ******************************************************************************/
306 XEmac_GetInterframeGap(XEmac * InstancePtr, u8 * Part1Ptr, u8 * Part2Ptr)
310 XASSERT_VOID(InstancePtr != NULL);
311 XASSERT_VOID(Part1Ptr != NULL);
312 XASSERT_VOID(Part2Ptr != NULL);
313 XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
315 Ifg = XIo_In32(InstancePtr->BaseAddress + XEM_IFGP_OFFSET);
316 *Part1Ptr = (Ifg & XEM_IFGP_PART1_MASK) >> XEM_IFGP_PART1_SHIFT;
317 *Part2Ptr = (Ifg & XEM_IFGP_PART2_MASK) >> XEM_IFGP_PART2_SHIFT;