1 /******************************************************************************
3 * Copyright (C) 2010 - 2015 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
35 * @file xemacps_intr.c
36 * @addtogroup emacps_v3_1
39 * Functions in this file implement general purpose interrupt processing related
40 * functionality. See xemacps.h for a detailed description of the driver.
43 * MODIFICATION HISTORY:
45 * Ver Who Date Changes
46 * ----- ---- -------- -------------------------------------------------------
47 * 1.00a wsy 01/10/10 First release
48 * 1.03a asa 01/24/13 Fix for CR #692702 which updates error handling for
49 * Rx errors. Under heavy Rx traffic, there will be a large
50 * number of errors related to receive buffer not available.
51 * Because of a HW bug (SI #692601), under such heavy errors,
52 * the Rx data path can become unresponsive. To reduce the
53 * probabilities for hitting this HW bug, the SW writes to
54 * bit 18 to flush a packet from Rx DPRAM immediately. The
55 * changes for it are done in the function
56 * XEmacPs_IntrHandler.
57 * 2.1 srt 07/15/14 Add support for Zynq Ultrascale Mp GEM specification
59 * 3.0 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
60 * 3.1 hk 07/27/15 Do not call error handler with '0' error code when
61 * there is no error. CR# 869403
63 ******************************************************************************/
65 /***************************** Include Files *********************************/
69 /************************** Constant Definitions *****************************/
72 /**************************** Type Definitions *******************************/
75 /***************** Macros (Inline Functions) Definitions *********************/
78 /************************** Function Prototypes ******************************/
81 /************************** Variable Definitions *****************************/
84 /*****************************************************************************/
86 * Install an asynchronious handler function for the given HandlerType:
88 * @param InstancePtr is a pointer to the instance to be worked on.
89 * @param HandlerType indicates what interrupt handler type is.
90 * XEMACPS_HANDLER_DMASEND, XEMACPS_HANDLER_DMARECV and
91 * XEMACPS_HANDLER_ERROR.
92 * @param FuncPointer is the pointer to the callback function
93 * @param CallBackRef is the upper layer callback reference passed back when
94 * when the callback function is invoked.
101 * There is no assert on the CallBackRef since the driver doesn't know what
104 *****************************************************************************/
105 LONG XEmacPs_SetHandler(XEmacPs *InstancePtr, u32 HandlerType,
106 void *FuncPointer, void *CallBackRef)
109 Xil_AssertNonvoid(InstancePtr != NULL);
110 Xil_AssertNonvoid(FuncPointer != NULL);
111 Xil_AssertNonvoid(InstancePtr->IsReady == (u32)XIL_COMPONENT_IS_READY);
113 switch (HandlerType) {
114 case XEMACPS_HANDLER_DMASEND:
115 Status = (LONG)(XST_SUCCESS);
116 InstancePtr->SendHandler = ((XEmacPs_Handler)(void *)FuncPointer);
117 InstancePtr->SendRef = CallBackRef;
119 case XEMACPS_HANDLER_DMARECV:
120 Status = (LONG)(XST_SUCCESS);
121 InstancePtr->RecvHandler = ((XEmacPs_Handler)(void *)FuncPointer);
122 InstancePtr->RecvRef = CallBackRef;
124 case XEMACPS_HANDLER_ERROR:
125 Status = (LONG)(XST_SUCCESS);
126 InstancePtr->ErrorHandler = ((XEmacPs_ErrHandler)(void *)FuncPointer);
127 InstancePtr->ErrorRef = CallBackRef;
130 Status = (LONG)(XST_INVALID_PARAM);
136 /*****************************************************************************/
138 * Master interrupt handler for EMAC driver. This routine will query the
139 * status of the device, bump statistics, and invoke user callbacks.
141 * This routine must be connected to an interrupt controller using OS/BSP
144 * @param XEmacPsPtr is a pointer to the XEMACPS instance that has caused the
147 ******************************************************************************/
148 void XEmacPs_IntrHandler(void *XEmacPsPtr)
154 XEmacPs *InstancePtr = (XEmacPs *) XEmacPsPtr;
156 Xil_AssertVoid(InstancePtr != NULL);
157 Xil_AssertVoid(InstancePtr->IsReady == (u32)XIL_COMPONENT_IS_READY);
159 /* This ISR will try to handle as many interrupts as it can in a single
160 * call. However, in most of the places where the user's error handler
161 * is called, this ISR exits because it is expected that the user will
162 * reset the device in nearly all instances.
164 RegISR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
167 /* Read Transmit Q1 ISR */
169 if (InstancePtr->Version > 2)
170 RegQ1ISR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
171 XEMACPS_INTQ1_STS_OFFSET);
173 /* Clear the interrupt status register */
174 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress, XEMACPS_ISR_OFFSET,
177 /* Receive complete interrupt */
178 if ((RegISR & XEMACPS_IXR_FRAMERX_MASK) != 0x00000000U) {
179 /* Clear RX status register RX complete indication but preserve
180 * error bits if there is any */
181 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
183 ((u32)XEMACPS_RXSR_FRAMERX_MASK |
184 (u32)XEMACPS_RXSR_BUFFNA_MASK));
185 InstancePtr->RecvHandler(InstancePtr->RecvRef);
188 /* Transmit Q1 complete interrupt */
189 if ((InstancePtr->Version > 2) &&
190 ((RegQ1ISR & XEMACPS_INTQ1SR_TXCOMPL_MASK) != 0x00000000U)) {
191 /* Clear TX status register TX complete indication but preserve
192 * error bits if there is any */
193 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
194 XEMACPS_INTQ1_STS_OFFSET,
195 XEMACPS_INTQ1SR_TXCOMPL_MASK);
196 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
198 ((u32)XEMACPS_TXSR_TXCOMPL_MASK |
199 (u32)XEMACPS_TXSR_USEDREAD_MASK));
200 InstancePtr->SendHandler(InstancePtr->SendRef);
203 /* Transmit complete interrupt */
204 if ((RegISR & XEMACPS_IXR_TXCOMPL_MASK) != 0x00000000U) {
205 /* Clear TX status register TX complete indication but preserve
206 * error bits if there is any */
207 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
209 ((u32)XEMACPS_TXSR_TXCOMPL_MASK |
210 (u32)XEMACPS_TXSR_USEDREAD_MASK));
211 InstancePtr->SendHandler(InstancePtr->SendRef);
214 /* Receive error conditions interrupt */
215 if ((RegISR & XEMACPS_IXR_RX_ERR_MASK) != 0x00000000U) {
216 /* Clear RX status register */
217 RegSR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
218 XEMACPS_RXSR_OFFSET);
219 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
220 XEMACPS_RXSR_OFFSET, RegSR);
222 /* Fix for CR # 692702. Write to bit 18 of net_ctrl
223 * register to flush a packet out of Rx SRAM upon
224 * an error for receive buffer not available. */
225 if ((RegISR & XEMACPS_IXR_RXUSED_MASK) != 0x00000000U) {
227 XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
228 XEMACPS_NWCTRL_OFFSET);
229 RegCtrl |= (u32)XEMACPS_NWCTRL_FLUSH_DPRAM_MASK;
230 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
231 XEMACPS_NWCTRL_OFFSET, RegCtrl);
235 InstancePtr->ErrorHandler(InstancePtr->ErrorRef,
236 XEMACPS_RECV, RegSR);
240 /* When XEMACPS_IXR_TXCOMPL_MASK is flaged, XEMACPS_IXR_TXUSED_MASK
241 * will be asserted the same time.
242 * Have to distinguish this bit to handle the real error condition.
244 /* Transmit Q1 error conditions interrupt */
245 if ((InstancePtr->Version > 2) &&
246 ((RegQ1ISR & XEMACPS_INTQ1SR_TXERR_MASK) != 0x00000000U) &&
247 ((RegQ1ISR & XEMACPS_INTQ1SR_TXCOMPL_MASK) != 0x00000000U)) {
248 /* Clear Interrupt Q1 status register */
249 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
250 XEMACPS_INTQ1_STS_OFFSET, RegQ1ISR);
251 InstancePtr->ErrorHandler(InstancePtr->ErrorRef, XEMACPS_SEND,
255 /* Transmit error conditions interrupt */
256 if (((RegISR & XEMACPS_IXR_TX_ERR_MASK) != 0x00000000U) &&
257 (!(RegISR & XEMACPS_IXR_TXCOMPL_MASK) != 0x00000000U)) {
258 /* Clear TX status register */
259 RegSR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
260 XEMACPS_TXSR_OFFSET);
261 XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
262 XEMACPS_TXSR_OFFSET, RegSR);
263 InstancePtr->ErrorHandler(InstancePtr->ErrorRef, XEMACPS_SEND,