blob: bbe3c1a6c24ebac024d1311d64a7295d2341ff2f [file] [log] [blame]
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001/*
2 * Agere Systems Inc.
3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
4 *
Alan Cox64f93032009-06-10 17:30:41 +01005 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07006 * All rights reserved.
7 * http://www.agere.com
8 *
9 *------------------------------------------------------------------------------
10 *
11 * et131x_isr.c - File which contains the ISR, ISR handler, and related routines
12 * for processing interrupts from the device.
13 *
14 *------------------------------------------------------------------------------
15 *
16 * SOFTWARE LICENSE
17 *
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.
22 *
Alan Cox64f93032009-06-10 17:30:41 +010023 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070024 * All rights reserved.
25 *
26 * Redistribution and use in source or binary forms, with or without
27 * modifications, are permitted provided that the following conditions are met:
28 *
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.
33 *
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.
37 *
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.
41 *
42 * Disclaimer
43 *
Alan Cox64f93032009-06-10 17:30:41 +010044 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070045 * 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.
56 *
57 */
58
59#include "et131x_version.h"
60#include "et131x_debug.h"
61#include "et131x_defs.h"
62
63#include <linux/init.h>
64#include <linux/module.h>
65#include <linux/types.h>
66#include <linux/kernel.h>
67
68#include <linux/sched.h>
69#include <linux/ptrace.h>
70#include <linux/slab.h>
71#include <linux/ctype.h>
72#include <linux/string.h>
73#include <linux/timer.h>
74#include <linux/interrupt.h>
75#include <linux/in.h>
76#include <linux/delay.h>
Alan Cox64f93032009-06-10 17:30:41 +010077#include <linux/io.h>
78#include <linux/bitops.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070079#include <asm/system.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070080
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>
86
87#include "et1310_phy.h"
88#include "et1310_pm.h"
89#include "et1310_jagcore.h"
90#include "et1310_mac.h"
91
92#include "et131x_adapter.h"
93
94/* Data for debugging facilities */
95#ifdef CONFIG_ET131X_DEBUG
96extern dbg_info_t *et131x_dbginfo;
97#endif /* CONFIG_ET131X_DEBUG */
98
99/**
100 * et131x_isr - The Interrupt Service Routine for the driver.
101 * @irq: the IRQ on which the interrupt was received.
102 * @dev_id: device-specific info (here a pointer to a net_device struct)
103 *
104 * Returns a value indicating if the interrupt was handled.
105 */
106irqreturn_t et131x_isr(int irq, void *dev_id)
107{
108 bool handled = true;
109 struct net_device *netdev = (struct net_device *)dev_id;
110 struct et131x_adapter *adapter = NULL;
111 INTERRUPT_t status;
112
113 if (netdev == NULL || !netif_device_present(netdev)) {
114 DBG_WARNING(et131x_dbginfo,
115 "No net_device struct or device not present\n");
116 handled = false;
117 goto out;
118 }
119
120 adapter = netdev_priv(netdev);
121
122 /* If the adapter is in low power state, then it should not
123 * recognize any interrupt
124 */
125
126 /* Disable Device Interrupts */
127 et131x_disable_interrupts(adapter);
128
129 /* Get a copy of the value in the interrupt status register
130 * so we can process the interrupting section
131 */
132 status.value = readl(&adapter->CSRAddress->global.int_status.value);
133
134 if (adapter->FlowControl == TxOnly ||
135 adapter->FlowControl == Both) {
136 status.value &= ~INT_MASK_ENABLE;
137 } else {
138 status.value &= ~INT_MASK_ENABLE_NO_FLOW;
139 }
140
141 /* Make sure this is our interrupt */
142 if (!status.value) {
143#ifdef CONFIG_ET131X_DEBUG
144 adapter->Stats.UnhandledInterruptsPerSec++;
145#endif
146 handled = false;
147 DBG_VERBOSE(et131x_dbginfo, "NOT OUR INTERRUPT\n");
148 et131x_enable_interrupts(adapter);
149 goto out;
150 }
151
152 /* This is our interrupt, so process accordingly */
153#ifdef CONFIG_ET131X_DEBUG
Alan Cox64f93032009-06-10 17:30:41 +0100154 if (status.bits.rxdma_xfr_done)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700155 adapter->Stats.RxDmaInterruptsPerSec++;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700156
Alan Cox64f93032009-06-10 17:30:41 +0100157 if (status.bits.txdma_isr)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700158 adapter->Stats.TxDmaInterruptsPerSec++;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700159#endif
160
161 if (status.bits.watchdog_interrupt) {
162 PMP_TCB pMpTcb = adapter->TxRing.CurrSendHead;
163
Alan Cox64f93032009-06-10 17:30:41 +0100164 if (pMpTcb)
165 if (++pMpTcb->PacketStaleCount > 1)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700166 status.bits.txdma_isr = 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700167
Alan Cox64f93032009-06-10 17:30:41 +0100168 if (adapter->RxRing.UnfinishedReceives)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700169 status.bits.rxdma_xfr_done = 1;
Alan Cox64f93032009-06-10 17:30:41 +0100170 else if (pMpTcb == NULL)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700171 writel(0, &adapter->CSRAddress->global.watchdog_timer);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700172
173 status.bits.watchdog_interrupt = 0;
174#ifdef CONFIG_ET131X_DEBUG
175 adapter->Stats.WatchDogInterruptsPerSec++;
176#endif
177 }
178
179 if (status.value == 0) {
180 /* This interrupt has in some way been "handled" by
181 * the ISR. Either it was a spurious Rx interrupt, or
182 * it was a Tx interrupt that has been filtered by
183 * the ISR.
184 */
185 et131x_enable_interrupts(adapter);
186 goto out;
187 }
188
189 /* We need to save the interrupt status value for use in our
190 * DPC. We will clear the software copy of that in that
191 * routine.
192 */
193 adapter->Stats.InterruptStatus = status;
194
195 /* Schedule the ISR handler as a bottom-half task in the
196 * kernel's tq_immediate queue, and mark the queue for
197 * execution
198 */
199 schedule_work(&adapter->task);
200
201out:
202 return IRQ_RETVAL(handled);
203}
204
205/**
206 * et131x_isr_handler - The ISR handler
207 * @p_adapter, a pointer to the device's private adapter structure
208 *
209 * scheduled to run in a deferred context by the ISR. This is where the ISR's
210 * work actually gets done.
211 */
212void et131x_isr_handler(struct work_struct *work)
213{
214 struct et131x_adapter *pAdapter =
215 container_of(work, struct et131x_adapter, task);
216 INTERRUPT_t GlobStatus = pAdapter->Stats.InterruptStatus;
217 ADDRESS_MAP_t __iomem *iomem = pAdapter->CSRAddress;
218
219 /*
220 * These first two are by far the most common. Once handled, we clear
221 * their two bits in the status word. If the word is now zero, we
222 * exit.
223 */
224 /* Handle all the completed Transmit interrupts */
225 if (GlobStatus.bits.txdma_isr) {
226 DBG_TX(et131x_dbginfo, "TXDMA_ISR interrupt\n");
227 et131x_handle_send_interrupt(pAdapter);
228 }
229
230 /* Handle all the completed Receives interrupts */
231 if (GlobStatus.bits.rxdma_xfr_done) {
232 DBG_RX(et131x_dbginfo, "RXDMA_XFR_DONE interrupt\n");
233 et131x_handle_recv_interrupt(pAdapter);
234 }
235
236 GlobStatus.value &= 0xffffffd7;
237
238 if (GlobStatus.value) {
239 /* Handle the TXDMA Error interrupt */
240 if (GlobStatus.bits.txdma_err) {
241 TXDMA_ERROR_t TxDmaErr;
242
243 /* Following read also clears the register (COR) */
244 TxDmaErr.value = readl(&iomem->txdma.TxDmaError.value);
245
246 DBG_WARNING(et131x_dbginfo,
247 "TXDMA_ERR interrupt, error = %d\n",
248 TxDmaErr.value);
249 }
250
251 /* Handle Free Buffer Ring 0 and 1 Low interrupt */
252 if (GlobStatus.bits.rxdma_fb_ring0_low ||
253 GlobStatus.bits.rxdma_fb_ring1_low) {
254 /*
255 * This indicates the number of unused buffers in
256 * RXDMA free buffer ring 0 is <= the limit you
257 * programmed. Free buffer resources need to be
258 * returned. Free buffers are consumed as packets
259 * are passed from the network to the host. The host
260 * becomes aware of the packets from the contents of
261 * the packet status ring. This ring is queried when
262 * the packet done interrupt occurs. Packets are then
263 * passed to the OS. When the OS is done with the
264 * packets the resources can be returned to the
265 * ET1310 for re-use. This interrupt is one method of
266 * returning resources.
267 */
268 DBG_WARNING(et131x_dbginfo,
269 "RXDMA_FB_RING0_LOW or "
270 "RXDMA_FB_RING1_LOW interrupt\n");
271
272 /* If the user has flow control on, then we will
273 * send a pause packet, otherwise just exit
274 */
275 if (pAdapter->FlowControl == TxOnly ||
276 pAdapter->FlowControl == Both) {
277 PM_CSR_t pm_csr;
278
279 /* Tell the device to send a pause packet via
280 * the back pressure register
281 */
Alan Cox64f93032009-06-10 17:30:41 +0100282 pm_csr.value =
283 readl(&iomem->global.pm_csr.value);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700284 if (pm_csr.bits.pm_phy_sw_coma == 0) {
285 TXMAC_BP_CTRL_t bp_ctrl = { 0 };
286
287 bp_ctrl.bits.bp_req = 1;
288 bp_ctrl.bits.bp_xonxoff = 1;
289 writel(bp_ctrl.value,
290 &iomem->txmac.bp_ctrl.value);
291 }
292 }
293 }
294
295 /* Handle Packet Status Ring Low Interrupt */
296 if (GlobStatus.bits.rxdma_pkt_stat_ring_low) {
297 DBG_WARNING(et131x_dbginfo,
298 "RXDMA_PKT_STAT_RING_LOW interrupt\n");
299
300 /*
301 * Same idea as with the two Free Buffer Rings.
302 * Packets going from the network to the host each
303 * consume a free buffer resource and a packet status
304 * resource. These resoures are passed to the OS.
305 * When the OS is done with the resources, they need
306 * to be returned to the ET1310. This is one method
307 * of returning the resources.
308 */
309 }
310
311 /* Handle RXDMA Error Interrupt */
312 if (GlobStatus.bits.rxdma_err) {
313 /*
314 * The rxdma_error interrupt is sent when a time-out
315 * on a request issued by the JAGCore has occurred or
316 * a completion is returned with an un-successful
317 * status. In both cases the request is considered
318 * complete. The JAGCore will automatically re-try the
319 * request in question. Normally information on events
320 * like these are sent to the host using the "Advanced
321 * Error Reporting" capability. This interrupt is
322 * another way of getting similar information. The
323 * only thing required is to clear the interrupt by
324 * reading the ISR in the global resources. The
325 * JAGCore will do a re-try on the request. Normally
326 * you should never see this interrupt. If you start
327 * to see this interrupt occurring frequently then
328 * something bad has occurred. A reset might be the
329 * thing to do.
330 */
Alan Cox64f93032009-06-10 17:30:41 +0100331 /* TRAP();*/
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700332
333 pAdapter->TxMacTest.value =
334 readl(&iomem->txmac.tx_test.value);
335 DBG_WARNING(et131x_dbginfo,
336 "RxDMA_ERR interrupt, error %x\n",
337 pAdapter->TxMacTest.value);
338 }
339
340 /* Handle the Wake on LAN Event */
341 if (GlobStatus.bits.wake_on_lan) {
342 /*
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.
348 */
349 DBG_ERROR(et131x_dbginfo, "WAKE_ON_LAN interrupt\n");
350 }
351
352 /* Handle the PHY interrupt */
353 if (GlobStatus.bits.phy_interrupt) {
354 PM_CSR_t pm_csr;
355 MI_BMSR_t BmsrInts, BmsrData;
356 MI_ISR_t myIsr;
357
358 DBG_VERBOSE(et131x_dbginfo, "PHY interrupt\n");
359
360 /* If we are in coma mode when we get this interrupt,
361 * we need to disable it.
362 */
363 pm_csr.value = readl(&iomem->global.pm_csr.value);
364 if (pm_csr.bits.pm_phy_sw_coma == 1) {
365 /*
366 * Check to see if we are in coma mode and if
367 * so, disable it because we will not be able
368 * to read PHY values until we are out.
369 */
370 DBG_VERBOSE(et131x_dbginfo,
371 "Device is in COMA mode, "
372 "need to wake up\n");
373 DisablePhyComa(pAdapter);
374 }
375
376 /* Read the PHY ISR to clear the reason for the
377 * interrupt.
378 */
379 MiRead(pAdapter, (uint8_t) offsetof(MI_REGS_t, isr),
380 &myIsr.value);
381
382 if (!pAdapter->ReplicaPhyLoopbk) {
383 MiRead(pAdapter,
384 (uint8_t) offsetof(MI_REGS_t, bmsr),
385 &BmsrData.value);
386
387 BmsrInts.value =
388 pAdapter->Bmsr.value ^ BmsrData.value;
389 pAdapter->Bmsr.value = BmsrData.value;
390
391 DBG_VERBOSE(et131x_dbginfo,
392 "Bmsr.value = 0x%04x,"
393 "Bmsr_ints.value = 0x%04x\n",
394 BmsrData.value, BmsrInts.value);
395
396 /* Do all the cable in / cable out stuff */
397 et131x_Mii_check(pAdapter, BmsrData, BmsrInts);
398 }
399 }
400
401 /* Let's move on to the TxMac */
402 if (GlobStatus.bits.txmac_interrupt) {
403 pAdapter->TxRing.TxMacErr.value =
404 readl(&iomem->txmac.err.value);
405
406 /*
407 * When any of the errors occur and TXMAC generates
408 * an interrupt to report these errors, it usually
409 * means that TXMAC has detected an error in the data
410 * stream retrieved from the on-chip Tx Q. All of
411 * these errors are catastrophic and TXMAC won't be
412 * able to recover data when these errors occur. In
413 * a nutshell, the whole Tx path will have to be reset
414 * and re-configured afterwards.
415 */
416 DBG_WARNING(et131x_dbginfo,
417 "TXMAC interrupt, error 0x%08x\n",
418 pAdapter->TxRing.TxMacErr.value);
419
420 /* If we are debugging, we want to see this error,
421 * otherwise we just want the device to be reset and
422 * continue
423 */
Alan Cox64f93032009-06-10 17:30:41 +0100424 /* DBG_TRAP(); */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700425 }
426
427 /* Handle RXMAC Interrupt */
428 if (GlobStatus.bits.rxmac_interrupt) {
429 /*
430 * These interrupts are catastrophic to the device,
431 * what we need to do is disable the interrupts and
432 * set the flag to cause us to reset so we can solve
433 * this issue.
434 */
Alan Cox64f93032009-06-10 17:30:41 +0100435 /* MP_SET_FLAG( pAdapter,
436 fMP_ADAPTER_HARDWARE_ERROR); */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700437
438 DBG_WARNING(et131x_dbginfo,
Alan Cox64f93032009-06-10 17:30:41 +0100439 "RXMAC interrupt, error 0x%08x. Requesting reset\n",
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700440 readl(&iomem->rxmac.err_reg.value));
441
442 DBG_WARNING(et131x_dbginfo,
443 "Enable 0x%08x, Diag 0x%08x\n",
444 readl(&iomem->rxmac.ctrl.value),
445 readl(&iomem->rxmac.rxq_diag.value));
446
447 /*
448 * If we are debugging, we want to see this error,
449 * otherwise we just want the device to be reset and
450 * continue
451 */
Alan Cox64f93032009-06-10 17:30:41 +0100452 /* TRAP(); */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700453 }
454
455 /* Handle MAC_STAT Interrupt */
456 if (GlobStatus.bits.mac_stat_interrupt) {
457 /*
458 * This means at least one of the un-masked counters
459 * in the MAC_STAT block has rolled over. Use this
460 * to maintain the top, software managed bits of the
461 * counter(s).
462 */
463 DBG_VERBOSE(et131x_dbginfo, "MAC_STAT interrupt\n");
464 HandleMacStatInterrupt(pAdapter);
465 }
466
467 /* Handle SLV Timeout Interrupt */
468 if (GlobStatus.bits.slv_timeout) {
469 /*
470 * This means a timeout has occured on a read or
471 * write request to one of the JAGCore registers. The
472 * Global Resources block has terminated the request
473 * and on a read request, returned a "fake" value.
474 * The most likely reasons are: Bad Address or the
475 * addressed module is in a power-down state and
476 * can't respond.
477 */
478 DBG_VERBOSE(et131x_dbginfo, "SLV_TIMEOUT interrupt\n");
479 }
480 }
481
Alan Cox64f93032009-06-10 17:30:41 +0100482 if (pAdapter->PoMgmt.PowerState == NdisDeviceStateD0)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700483 et131x_enable_interrupts(pAdapter);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700484}