Staging: et131x: Another typedef solely used to write 0 to a register
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / et131x / et131x_isr.c
blobf6d452dd14e27a0d7cd38b8993a818d40fce74fd
1 /*
2 * Agere Systems Inc.
3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
5 * Copyright © 2005 Agere Systems Inc.
6 * All rights reserved.
7 * http://www.agere.com
9 *------------------------------------------------------------------------------
11 * et131x_isr.c - File which contains the ISR, ISR handler, and related routines
12 * for processing interrupts from the device.
14 *------------------------------------------------------------------------------
16 * SOFTWARE LICENSE
18 * This software is provided subject to the following terms and conditions,
19 * which you should read carefully before using the software. Using this
20 * software indicates your acceptance of these terms and conditions. If you do
21 * not agree with these terms and conditions, do not use the software.
23 * Copyright © 2005 Agere Systems Inc.
24 * All rights reserved.
26 * Redistribution and use in source or binary forms, with or without
27 * modifications, are permitted provided that the following conditions are met:
29 * . Redistributions of source code must retain the above copyright notice, this
30 * list of conditions and the following Disclaimer as comments in the code as
31 * well as in the documentation and/or other materials provided with the
32 * distribution.
34 * . Redistributions in binary form must reproduce the above copyright notice,
35 * this list of conditions and the following Disclaimer in the documentation
36 * and/or other materials provided with the distribution.
38 * . Neither the name of Agere Systems Inc. nor the names of the contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
42 * Disclaimer
44 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
45 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
46 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
47 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
48 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
49 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
50 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
52 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
54 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
55 * DAMAGE.
59 #include "et131x_version.h"
60 #include "et131x_defs.h"
62 #include <linux/init.h>
63 #include <linux/module.h>
64 #include <linux/types.h>
65 #include <linux/kernel.h>
67 #include <linux/sched.h>
68 #include <linux/ptrace.h>
69 #include <linux/slab.h>
70 #include <linux/ctype.h>
71 #include <linux/string.h>
72 #include <linux/timer.h>
73 #include <linux/interrupt.h>
74 #include <linux/in.h>
75 #include <linux/delay.h>
76 #include <linux/io.h>
77 #include <linux/bitops.h>
78 #include <linux/pci.h>
79 #include <asm/system.h>
81 #include <linux/netdevice.h>
82 #include <linux/etherdevice.h>
83 #include <linux/skbuff.h>
84 #include <linux/if_arp.h>
85 #include <linux/ioport.h>
87 #include "et1310_phy.h"
88 #include "et1310_pm.h"
89 #include "et1310_jagcore.h"
90 #include "et1310_mac.h"
92 #include "et131x_adapter.h"
94 /**
95 * et131x_enable_interrupts - enable interrupt
96 * @adapter: et131x device
98 * Enable the appropriate interrupts on the ET131x according to our
99 * configuration
102 void et131x_enable_interrupts(struct et131x_adapter *adapter)
104 u32 mask;
106 /* Enable all global interrupts */
107 if (adapter->FlowControl == TxOnly || adapter->FlowControl == Both)
108 mask = INT_MASK_ENABLE;
109 else
110 mask = INT_MASK_ENABLE_NO_FLOW;
112 adapter->CachedMaskValue = mask;
113 writel(mask, &adapter->regs->global.int_mask);
117 * et131x_disable_interrupts - interrupt disable
118 * @adapter: et131x device
120 * Block all interrupts from the et131x device at the device itself
123 void et131x_disable_interrupts(struct et131x_adapter *adapter)
125 /* Disable all global interrupts */
126 adapter->CachedMaskValue = INT_MASK_DISABLE;
127 writel(INT_MASK_DISABLE, &adapter->regs->global.int_mask);
132 * et131x_isr - The Interrupt Service Routine for the driver.
133 * @irq: the IRQ on which the interrupt was received.
134 * @dev_id: device-specific info (here a pointer to a net_device struct)
136 * Returns a value indicating if the interrupt was handled.
139 irqreturn_t et131x_isr(int irq, void *dev_id)
141 bool handled = true;
142 struct net_device *netdev = (struct net_device *)dev_id;
143 struct et131x_adapter *adapter = NULL;
144 u32 status;
146 if (!netif_device_present(netdev)) {
147 handled = false;
148 goto out;
151 adapter = netdev_priv(netdev);
153 /* If the adapter is in low power state, then it should not
154 * recognize any interrupt
157 /* Disable Device Interrupts */
158 et131x_disable_interrupts(adapter);
160 /* Get a copy of the value in the interrupt status register
161 * so we can process the interrupting section
163 status = readl(&adapter->regs->global.int_status);
165 if (adapter->FlowControl == TxOnly ||
166 adapter->FlowControl == Both) {
167 status &= ~INT_MASK_ENABLE;
168 } else {
169 status &= ~INT_MASK_ENABLE_NO_FLOW;
172 /* Make sure this is our interrupt */
173 if (!status) {
174 handled = false;
175 et131x_enable_interrupts(adapter);
176 goto out;
179 /* This is our interrupt, so process accordingly */
181 if (status & ET_INTR_WATCHDOG) {
182 struct tcb *tcb = adapter->tx_ring.send_head;
184 if (tcb)
185 if (++tcb->stale > 1)
186 status |= ET_INTR_TXDMA_ISR;
188 if (adapter->RxRing.UnfinishedReceives)
189 status |= ET_INTR_RXDMA_XFR_DONE;
190 else if (tcb == NULL)
191 writel(0, &adapter->regs->global.watchdog_timer);
193 status &= ~ET_INTR_WATCHDOG;
196 if (status == 0) {
197 /* This interrupt has in some way been "handled" by
198 * the ISR. Either it was a spurious Rx interrupt, or
199 * it was a Tx interrupt that has been filtered by
200 * the ISR.
202 et131x_enable_interrupts(adapter);
203 goto out;
206 /* We need to save the interrupt status value for use in our
207 * DPC. We will clear the software copy of that in that
208 * routine.
210 adapter->Stats.InterruptStatus = status;
212 /* Schedule the ISR handler as a bottom-half task in the
213 * kernel's tq_immediate queue, and mark the queue for
214 * execution
216 schedule_work(&adapter->task);
217 out:
218 return IRQ_RETVAL(handled);
222 * et131x_isr_handler - The ISR handler
223 * @p_adapter, a pointer to the device's private adapter structure
225 * scheduled to run in a deferred context by the ISR. This is where the ISR's
226 * work actually gets done.
228 void et131x_isr_handler(struct work_struct *work)
230 struct et131x_adapter *etdev =
231 container_of(work, struct et131x_adapter, task);
232 u32 status = etdev->Stats.InterruptStatus;
233 ADDRESS_MAP_t __iomem *iomem = etdev->regs;
236 * These first two are by far the most common. Once handled, we clear
237 * their two bits in the status word. If the word is now zero, we
238 * exit.
240 /* Handle all the completed Transmit interrupts */
241 if (status & ET_INTR_TXDMA_ISR) {
242 et131x_handle_send_interrupt(etdev);
245 /* Handle all the completed Receives interrupts */
246 if (status & ET_INTR_RXDMA_XFR_DONE) {
247 et131x_handle_recv_interrupt(etdev);
250 status &= 0xffffffd7;
252 if (status) {
253 /* Handle the TXDMA Error interrupt */
254 if (status & ET_INTR_TXDMA_ERR) {
255 u32 txdma_err;
257 /* Following read also clears the register (COR) */
258 txdma_err = readl(&iomem->txdma.TxDmaError);
260 dev_warn(&etdev->pdev->dev,
261 "TXDMA_ERR interrupt, error = %d\n",
262 txdma_err);
265 /* Handle Free Buffer Ring 0 and 1 Low interrupt */
266 if (status & (ET_INTR_RXDMA_FB_R0_LOW | ET_INTR_RXDMA_FB_R1_LOW)) {
268 * This indicates the number of unused buffers in
269 * RXDMA free buffer ring 0 is <= the limit you
270 * programmed. Free buffer resources need to be
271 * returned. Free buffers are consumed as packets
272 * are passed from the network to the host. The host
273 * becomes aware of the packets from the contents of
274 * the packet status ring. This ring is queried when
275 * the packet done interrupt occurs. Packets are then
276 * passed to the OS. When the OS is done with the
277 * packets the resources can be returned to the
278 * ET1310 for re-use. This interrupt is one method of
279 * returning resources.
282 /* If the user has flow control on, then we will
283 * send a pause packet, otherwise just exit
285 if (etdev->FlowControl == TxOnly ||
286 etdev->FlowControl == Both) {
287 u32 pm_csr;
289 /* Tell the device to send a pause packet via
290 * the back pressure register (bp req and
291 * bp xon/xoff)
293 pm_csr = readl(&iomem->global.pm_csr);
294 if ((pm_csr & ET_PM_PHY_SW_COMA) == 0)
295 writel(3, &iomem->txmac.bp_ctrl);
299 /* Handle Packet Status Ring Low Interrupt */
300 if (status & ET_INTR_RXDMA_STAT_LOW) {
303 * Same idea as with the two Free Buffer Rings.
304 * Packets going from the network to the host each
305 * consume a free buffer resource and a packet status
306 * resource. These resoures are passed to the OS.
307 * When the OS is done with the resources, they need
308 * to be returned to the ET1310. This is one method
309 * of returning the resources.
313 /* Handle RXDMA Error Interrupt */
314 if (status & ET_INTR_RXDMA_ERR) {
316 * The rxdma_error interrupt is sent when a time-out
317 * on a request issued by the JAGCore has occurred or
318 * a completion is returned with an un-successful
319 * status. In both cases the request is considered
320 * complete. The JAGCore will automatically re-try the
321 * request in question. Normally information on events
322 * like these are sent to the host using the "Advanced
323 * Error Reporting" capability. This interrupt is
324 * another way of getting similar information. The
325 * only thing required is to clear the interrupt by
326 * reading the ISR in the global resources. The
327 * JAGCore will do a re-try on the request. Normally
328 * you should never see this interrupt. If you start
329 * to see this interrupt occurring frequently then
330 * something bad has occurred. A reset might be the
331 * thing to do.
333 /* TRAP();*/
335 dev_warn(&etdev->pdev->dev,
336 "RxDMA_ERR interrupt, error %x\n",
337 readl(&iomem->txmac.tx_test));
340 /* Handle the Wake on LAN Event */
341 if (status & ET_INTR_WOL) {
343 * This is a secondary interrupt for wake on LAN.
344 * The driver should never see this, if it does,
345 * something serious is wrong. We will TRAP the
346 * message when we are in DBG mode, otherwise we
347 * will ignore it.
349 dev_err(&etdev->pdev->dev, "WAKE_ON_LAN interrupt\n");
352 /* Handle the PHY interrupt */
353 if (status & ET_INTR_PHY) {
354 u32 pm_csr;
355 MI_BMSR_t BmsrInts, BmsrData;
356 MI_ISR_t myIsr;
358 /* If we are in coma mode when we get this interrupt,
359 * we need to disable it.
361 pm_csr = readl(&iomem->global.pm_csr);
362 if (pm_csr & ET_PM_PHY_SW_COMA) {
364 * Check to see if we are in coma mode and if
365 * so, disable it because we will not be able
366 * to read PHY values until we are out.
368 DisablePhyComa(etdev);
371 /* Read the PHY ISR to clear the reason for the
372 * interrupt.
374 MiRead(etdev, (uint8_t) offsetof(MI_REGS_t, isr),
375 &myIsr.value);
377 if (!etdev->ReplicaPhyLoopbk) {
378 MiRead(etdev,
379 (uint8_t) offsetof(MI_REGS_t, bmsr),
380 &BmsrData.value);
382 BmsrInts.value =
383 etdev->Bmsr.value ^ BmsrData.value;
384 etdev->Bmsr.value = BmsrData.value;
386 /* Do all the cable in / cable out stuff */
387 et131x_Mii_check(etdev, BmsrData, BmsrInts);
391 /* Let's move on to the TxMac */
392 if (status & ET_INTR_TXMAC) {
393 u32 err = readl(&iomem->txmac.err.value);
396 * When any of the errors occur and TXMAC generates
397 * an interrupt to report these errors, it usually
398 * means that TXMAC has detected an error in the data
399 * stream retrieved from the on-chip Tx Q. All of
400 * these errors are catastrophic and TXMAC won't be
401 * able to recover data when these errors occur. In
402 * a nutshell, the whole Tx path will have to be reset
403 * and re-configured afterwards.
405 dev_warn(&etdev->pdev->dev,
406 "TXMAC interrupt, error 0x%08x\n",
407 err);
409 /* If we are debugging, we want to see this error,
410 * otherwise we just want the device to be reset and
411 * continue
415 /* Handle RXMAC Interrupt */
416 if (status & ET_INTR_RXMAC) {
418 * These interrupts are catastrophic to the device,
419 * what we need to do is disable the interrupts and
420 * set the flag to cause us to reset so we can solve
421 * this issue.
423 /* MP_SET_FLAG( etdev,
424 fMP_ADAPTER_HARDWARE_ERROR); */
426 dev_warn(&etdev->pdev->dev,
427 "RXMAC interrupt, error 0x%08x. Requesting reset\n",
428 readl(&iomem->rxmac.err_reg.value));
430 dev_warn(&etdev->pdev->dev,
431 "Enable 0x%08x, Diag 0x%08x\n",
432 readl(&iomem->rxmac.ctrl.value),
433 readl(&iomem->rxmac.rxq_diag.value));
436 * If we are debugging, we want to see this error,
437 * otherwise we just want the device to be reset and
438 * continue
442 /* Handle MAC_STAT Interrupt */
443 if (status & ET_INTR_MAC_STAT) {
445 * This means at least one of the un-masked counters
446 * in the MAC_STAT block has rolled over. Use this
447 * to maintain the top, software managed bits of the
448 * counter(s).
450 HandleMacStatInterrupt(etdev);
453 /* Handle SLV Timeout Interrupt */
454 if (status & ET_INTR_SLV_TIMEOUT) {
456 * This means a timeout has occured on a read or
457 * write request to one of the JAGCore registers. The
458 * Global Resources block has terminated the request
459 * and on a read request, returned a "fake" value.
460 * The most likely reasons are: Bad Address or the
461 * addressed module is in a power-down state and
462 * can't respond.
466 et131x_enable_interrupts(etdev);