1 /* $Id: xemacps_intr.c,v 1.1.2.1 2011/01/20 03:39:02 sadanan Exp $ */
2 /******************************************************************************
4 * (c) Copyright 2010 Xilinx, Inc. All rights reserved.
6 * This file contains confidential and proprietary information of Xilinx, Inc.
7 * and is protected under U.S. and international copyright and other
8 * intellectual property laws.
11 * This disclaimer is not a license and does not grant any rights to the
12 * materials distributed herewith. Except as otherwise provided in a valid
13 * license issued to you by Xilinx, and to the maximum extent permitted by
14 * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
15 * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
16 * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
17 * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
18 * and (2) Xilinx shall not be liable (whether in contract or tort, including
19 * negligence, or under any other theory of liability) for any loss or damage
20 * of any kind or nature related to, arising under or in connection with these
21 * materials, including for any direct, or any indirect, special, incidental,
22 * or consequential loss or damage (including loss of data, profits, goodwill,
23 * or any type of loss or damage suffered as a result of any action brought by
24 * a third party) even if such damage or loss was reasonably foreseeable or
25 * Xilinx had been advised of the possibility of the same.
27 * CRITICAL APPLICATIONS
28 * Xilinx products are not designed or intended to be fail-safe, or for use in
29 * any application requiring fail-safe performance, such as life-support or
30 * safety devices or systems, Class III medical devices, nuclear facilities,
31 * applications related to the deployment of airbags, or any other applications
32 * that could lead to death, personal injury, or severe property or
33 * environmental damage (individually and collectively, "Critical
34 * Applications"). Customer assumes the sole risk and liability of any use of
35 * Xilinx products in Critical Applications, subject only to applicable laws
36 * and regulations governing limitations on product liability.
38 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
41 ******************************************************************************/
42 /*****************************************************************************/
45 * @file xemacps_intr.c
47 * Functions in this file implement general purpose interrupt processing related
48 * functionality. See xemacps.h for a detailed description of the driver.
51 * MODIFICATION HISTORY:
53 * Ver Who Date Changes
54 * ----- ---- -------- -------------------------------------------------------
55 * 1.00a wsy 01/10/10 First release
56 * 1.03a asa 01/24/13 Fix for CR #692702 which updates error handling for
57 * Rx errors. Under heavy Rx traffic, there will be a large
58 * number of errors related to receive buffer not available.
59 * Because of a HW bug (SI #692601), under such heavy errors,
60 * the Rx data path can become unresponsive. To reduce the
61 * probabilities for hitting this HW bug, the SW writes to
62 * bit 18 to flush a packet from Rx DPRAM immediately. The
63 * changes for it are done in the function
64 * XEmacPs_IntrHandler.
66 ******************************************************************************/
68 /***************************** Include Files *********************************/
72 /************************** Constant Definitions *****************************/
75 /**************************** Type Definitions *******************************/
78 /***************** Macros (Inline Functions) Definitions *********************/
81 /************************** Function Prototypes ******************************/
84 /************************** Variable Definitions *****************************/
87 /*****************************************************************************/
89 * Install an asynchronious handler function for the given HandlerType:
91 * @param InstancePtr is a pointer to the instance to be worked on.
92 * @param HandlerType indicates what interrupt handler type is.
93 * XEMACPS_HANDLER_DMASEND, XEMACPS_HANDLER_DMARECV and
94 * XEMACPS_HANDLER_ERROR.
95 * @param FuncPtr is the pointer to the callback function
96 * @param CallBackRef is the upper layer callback reference passed back when
97 * when the callback function is invoked.
104 * There is no assert on the CallBackRef since the driver doesn't know what
107 *****************************************************************************/
108 int XEmacPs_SetHandler(XEmacPs *InstancePtr, u32 HandlerType,
109 void *FuncPtr, void *CallBackRef)
111 Xil_AssertNonvoid(InstancePtr != NULL);
112 Xil_AssertNonvoid(FuncPtr != NULL);
113 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
115 switch (HandlerType) {
116 case XEMACPS_HANDLER_DMASEND:
117 InstancePtr->SendHandler = (XEmacPs_Handler) FuncPtr;
118 InstancePtr->SendRef = CallBackRef;
120 case XEMACPS_HANDLER_DMARECV:
121 InstancePtr->RecvHandler = (XEmacPs_Handler) FuncPtr;
122 InstancePtr->RecvRef = CallBackRef;
124 case XEMACPS_HANDLER_ERROR:
125 InstancePtr->ErrorHandler = (XEmacPs_ErrHandler) FuncPtr;
126 InstancePtr->ErrorRef = CallBackRef;
129 return (XST_INVALID_PARAM);
131 return (XST_SUCCESS);
134 /*****************************************************************************/
136 * Master interrupt handler for EMAC driver. This routine will query the
137 * status of the device, bump statistics, and invoke user callbacks.
139 * This routine must be connected to an interrupt controller using OS/BSP
142 * @param XEmacPsPtr is a pointer to the XEMACPS instance that has caused the
145 ******************************************************************************/
146 void XEmacPs_IntrHandler(void *XEmacPsPtr)
151 XEmacPs *InstancePtr = (XEmacPs *) XEmacPsPtr;
153 Xil_AssertVoid(InstancePtr != NULL);
154 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
156 /* This ISR will try to handle as many interrupts as it can in a single
157 * call. However, in most of the places where the user's error handler
158 * is called, this ISR exits because it is expected that the user will
159 * reset the device in nearly all instances.
161 RegISR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
164 /* Clear the interrupt status register */
165 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress, XEMACPS_ISR_OFFSET,
168 /* Receive complete interrupt */
169 if (RegISR & (XEMACPS_IXR_FRAMERX_MASK)) {
170 /* Clear RX status register RX complete indication but preserve
171 * error bits if there is any */
172 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
174 XEMACPS_RXSR_FRAMERX_MASK |
175 XEMACPS_RXSR_BUFFNA_MASK);
176 InstancePtr->RecvHandler(InstancePtr->RecvRef);
179 /* Transmit complete interrupt */
180 if (RegISR & (XEMACPS_IXR_TXCOMPL_MASK)) {
181 /* Clear TX status register TX complete indication but preserve
182 * error bits if there is any */
183 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
185 XEMACPS_TXSR_TXCOMPL_MASK |
186 XEMACPS_TXSR_USEDREAD_MASK);
187 InstancePtr->SendHandler(InstancePtr->SendRef);
190 /* Receive error conditions interrupt */
191 if (RegISR & (XEMACPS_IXR_RX_ERR_MASK)) {
192 /* Clear RX status register */
193 RegSR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
194 XEMACPS_RXSR_OFFSET);
195 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
196 XEMACPS_RXSR_OFFSET, RegSR);
198 /* Fix for CR # 692702. Write to bit 18 of net_ctrl
199 * register to flush a packet out of Rx SRAM upon
200 * an error for receive buffer not available. */
201 if (RegISR & XEMACPS_IXR_RXUSED_MASK) {
203 XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
204 XEMACPS_NWCTRL_OFFSET);
205 RegCtrl |= XEMACPS_NWCTRL_FLUSH_DPRAM_MASK;
206 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
207 XEMACPS_NWCTRL_OFFSET, RegCtrl);
209 InstancePtr->ErrorHandler(InstancePtr->ErrorRef, XEMACPS_RECV,
213 /* When XEMACPS_IXR_TXCOMPL_MASK is flaged, XEMACPS_IXR_TXUSED_MASK
214 * will be asserted the same time.
215 * Have to distinguish this bit to handle the real error condition.
217 /* Transmit error conditions interrupt */
218 if (RegISR & (XEMACPS_IXR_TX_ERR_MASK) &&
219 !(RegISR & (XEMACPS_IXR_TXCOMPL_MASK))) {
220 /* Clear TX status register */
221 RegSR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
222 XEMACPS_TXSR_OFFSET);
223 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
224 XEMACPS_TXSR_OFFSET, RegSR);
225 InstancePtr->ErrorHandler(InstancePtr->ErrorRef, XEMACPS_SEND,