2943178a7a3653de2c572e81d3572fbf2e0f87ff
[safe/jmp/linux-2.6] / drivers / staging / et131x / et131x_isr.c
1 /*
2  * Agere Systems Inc.
3  * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
4  *
5  * Copyright © 2005 Agere Systems Inc.
6  * 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  *
23  * Copyright © 2005 Agere Systems Inc.
24  * 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  *
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.
56  *
57  */
58
59 #include "et131x_version.h"
60 #include "et131x_defs.h"
61
62 #include <linux/init.h>
63 #include <linux/module.h>
64 #include <linux/types.h>
65 #include <linux/kernel.h>
66
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>
80
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 /**
95  *      et131x_enable_interrupts        -       enable interrupt
96  *      @adapter: et131x device
97  *
98  *      Enable the appropriate interrupts on the ET131x according to our
99  *      configuration
100  */
101
102 void et131x_enable_interrupts(struct et131x_adapter *adapter)
103 {
104         u32 mask;
105
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;
111
112         if (adapter->DriverNoPhyAccess)
113                 mask |= ET_INTR_PHY;
114
115         adapter->CachedMaskValue = mask;
116         writel(mask, &adapter->regs->global.int_mask);
117 }
118
119 /**
120  *      et131x_disable_interrupts       -       interrupt disable
121  *      @adapter: et131x device
122  *
123  *      Block all interrupts from the et131x device at the device itself
124  */
125
126 void et131x_disable_interrupts(struct et131x_adapter *adapter)
127 {
128         /* Disable all global interrupts */
129         adapter->CachedMaskValue = INT_MASK_DISABLE;
130         writel(INT_MASK_DISABLE, &adapter->regs->global.int_mask);
131 }
132
133
134 /**
135  * et131x_isr - The Interrupt Service Routine for the driver.
136  * @irq: the IRQ on which the interrupt was received.
137  * @dev_id: device-specific info (here a pointer to a net_device struct)
138  *
139  * Returns a value indicating if the interrupt was handled.
140  */
141
142 irqreturn_t et131x_isr(int irq, void *dev_id)
143 {
144         bool handled = true;
145         struct net_device *netdev = (struct net_device *)dev_id;
146         struct et131x_adapter *adapter = NULL;
147         u32 status;
148
149         if (!netif_device_present(netdev)) {
150                 handled = false;
151                 goto out;
152         }
153
154         adapter = netdev_priv(netdev);
155
156         /* If the adapter is in low power state, then it should not
157          * recognize any interrupt
158          */
159
160         /* Disable Device Interrupts */
161         et131x_disable_interrupts(adapter);
162
163         /* Get a copy of the value in the interrupt status register
164          * so we can process the interrupting section
165          */
166         status = readl(&adapter->regs->global.int_status);
167
168         if (adapter->FlowControl == TxOnly ||
169             adapter->FlowControl == Both) {
170                 status &= ~INT_MASK_ENABLE;
171         } else {
172                 status &= ~INT_MASK_ENABLE_NO_FLOW;
173         }
174
175         /* Make sure this is our interrupt */
176         if (!status) {
177                 handled = false;
178                 et131x_enable_interrupts(adapter);
179                 goto out;
180         }
181
182         /* This is our interrupt, so process accordingly */
183
184         if (status & ET_INTR_WATCHDOG) {
185                 PMP_TCB pMpTcb = adapter->TxRing.CurrSendHead;
186
187                 if (pMpTcb)
188                         if (++pMpTcb->PacketStaleCount > 1)
189                                 status |= ET_INTR_TXDMA_ISR;
190
191                 if (adapter->RxRing.UnfinishedReceives)
192                         status |= ET_INTR_RXDMA_XFR_DONE;
193                 else if (pMpTcb == NULL)
194                         writel(0, &adapter->regs->global.watchdog_timer);
195
196                 status &= ~ET_INTR_WATCHDOG;
197         }
198
199         if (status == 0) {
200                 /* This interrupt has in some way been "handled" by
201                  * the ISR. Either it was a spurious Rx interrupt, or
202                  * it was a Tx interrupt that has been filtered by
203                  * the ISR.
204                  */
205                 et131x_enable_interrupts(adapter);
206                 goto out;
207         }
208
209         /* We need to save the interrupt status value for use in our
210          * DPC. We will clear the software copy of that in that
211          * routine.
212          */
213         adapter->Stats.InterruptStatus = status;
214
215         /* Schedule the ISR handler as a bottom-half task in the
216          * kernel's tq_immediate queue, and mark the queue for
217          * execution
218          */
219         schedule_work(&adapter->task);
220 out:
221         return IRQ_RETVAL(handled);
222 }
223
224 /**
225  * et131x_isr_handler - The ISR handler
226  * @p_adapter, a pointer to the device's private adapter structure
227  *
228  * scheduled to run in a deferred context by the ISR. This is where the ISR's
229  * work actually gets done.
230  */
231 void et131x_isr_handler(struct work_struct *work)
232 {
233         struct et131x_adapter *etdev =
234                 container_of(work, struct et131x_adapter, task);
235         u32 status = etdev->Stats.InterruptStatus;
236         ADDRESS_MAP_t __iomem *iomem = etdev->regs;
237
238         /*
239          * These first two are by far the most common.  Once handled, we clear
240          * their two bits in the status word.  If the word is now zero, we
241          * exit.
242          */
243         /* Handle all the completed Transmit interrupts */
244         if (status & ET_INTR_TXDMA_ISR) {
245                 et131x_handle_send_interrupt(etdev);
246         }
247
248         /* Handle all the completed Receives interrupts */
249         if (status & ET_INTR_RXDMA_XFR_DONE) {
250                 et131x_handle_recv_interrupt(etdev);
251         }
252
253         status &= 0xffffffd7;
254
255         if (status) {
256                 /* Handle the TXDMA Error interrupt */
257                 if (status & ET_INTR_TXDMA_ERR) {
258                         TXDMA_ERROR_t TxDmaErr;
259
260                         /* Following read also clears the register (COR) */
261                         TxDmaErr.value = readl(&iomem->txdma.TxDmaError.value);
262
263                         dev_warn(&etdev->pdev->dev,
264                                     "TXDMA_ERR interrupt, error = %d\n",
265                                     TxDmaErr.value);
266                 }
267
268                 /* Handle Free Buffer Ring 0 and 1 Low interrupt */
269                 if (status & (ET_INTR_RXDMA_FB_R0_LOW | ET_INTR_RXDMA_FB_R1_LOW)) {
270                         /*
271                          * This indicates the number of unused buffers in
272                          * RXDMA free buffer ring 0 is <= the limit you
273                          * programmed. Free buffer resources need to be
274                          * returned.  Free buffers are consumed as packets
275                          * are passed from the network to the host. The host
276                          * becomes aware of the packets from the contents of
277                          * the packet status ring. This ring is queried when
278                          * the packet done interrupt occurs. Packets are then
279                          * passed to the OS. When the OS is done with the
280                          * packets the resources can be returned to the
281                          * ET1310 for re-use. This interrupt is one method of
282                          * returning resources.
283                          */
284
285                         /* If the user has flow control on, then we will
286                          * send a pause packet, otherwise just exit
287                          */
288                         if (etdev->FlowControl == TxOnly ||
289                             etdev->FlowControl == Both) {
290                                 u32 pm_csr;
291
292                                 /* Tell the device to send a pause packet via
293                                  * the back pressure register
294                                  */
295                                 pm_csr = readl(&iomem->global.pm_csr);
296                                 if ((pm_csr & ET_PM_PHY_SW_COMA) == 0) {
297                                         TXMAC_BP_CTRL_t bp_ctrl = { 0 };
298
299                                         bp_ctrl.bits.bp_req = 1;
300                                         bp_ctrl.bits.bp_xonxoff = 1;
301                                         writel(bp_ctrl.value,
302                                                &iomem->txmac.bp_ctrl.value);
303                                 }
304                         }
305                 }
306
307                 /* Handle Packet Status Ring Low Interrupt */
308                 if (status & ET_INTR_RXDMA_STAT_LOW) {
309
310                         /*
311                          * Same idea as with the two Free Buffer Rings.
312                          * Packets going from the network to the host each
313                          * consume a free buffer resource and a packet status
314                          * resource.  These resoures are passed to the OS.
315                          * When the OS is done with the resources, they need
316                          * to be returned to the ET1310. This is one method
317                          * of returning the resources.
318                          */
319                 }
320
321                 /* Handle RXDMA Error Interrupt */
322                 if (status & ET_INTR_RXDMA_ERR) {
323                         /*
324                          * The rxdma_error interrupt is sent when a time-out
325                          * on a request issued by the JAGCore has occurred or
326                          * a completion is returned with an un-successful
327                          * status.  In both cases the request is considered
328                          * complete. The JAGCore will automatically re-try the
329                          * request in question. Normally information on events
330                          * like these are sent to the host using the "Advanced
331                          * Error Reporting" capability. This interrupt is
332                          * another way of getting similar information. The
333                          * only thing required is to clear the interrupt by
334                          * reading the ISR in the global resources. The
335                          * JAGCore will do a re-try on the request.  Normally
336                          * you should never see this interrupt. If you start
337                          * to see this interrupt occurring frequently then
338                          * something bad has occurred. A reset might be the
339                          * thing to do.
340                          */
341                         /* TRAP();*/
342
343                         etdev->TxMacTest.value =
344                                 readl(&iomem->txmac.tx_test.value);
345                         dev_warn(&etdev->pdev->dev,
346                                     "RxDMA_ERR interrupt, error %x\n",
347                                     etdev->TxMacTest.value);
348                 }
349
350                 /* Handle the Wake on LAN Event */
351                 if (status & ET_INTR_WOL) {
352                         /*
353                          * This is a secondary interrupt for wake on LAN.
354                          * The driver should never see this, if it does,
355                          * something serious is wrong. We will TRAP the
356                          * message when we are in DBG mode, otherwise we
357                          * will ignore it.
358                          */
359                         dev_err(&etdev->pdev->dev, "WAKE_ON_LAN interrupt\n");
360                 }
361
362                 /* Handle the PHY interrupt */
363                 if (status & ET_INTR_PHY) {
364                         u32 pm_csr;
365                         MI_BMSR_t BmsrInts, BmsrData;
366                         MI_ISR_t myIsr;
367
368                         /* If we are in coma mode when we get this interrupt,
369                          * we need to disable it.
370                          */
371                         pm_csr = readl(&iomem->global.pm_csr);
372                         if (pm_csr & ET_PM_PHY_SW_COMA) {
373                                 /*
374                                  * Check to see if we are in coma mode and if
375                                  * so, disable it because we will not be able
376                                  * to read PHY values until we are out.
377                                  */
378                                 DisablePhyComa(etdev);
379                         }
380
381                         /* Read the PHY ISR to clear the reason for the
382                          * interrupt.
383                          */
384                         MiRead(etdev, (uint8_t) offsetof(MI_REGS_t, isr),
385                                &myIsr.value);
386
387                         if (!etdev->ReplicaPhyLoopbk) {
388                                 MiRead(etdev,
389                                        (uint8_t) offsetof(MI_REGS_t, bmsr),
390                                        &BmsrData.value);
391
392                                 BmsrInts.value =
393                                     etdev->Bmsr.value ^ BmsrData.value;
394                                 etdev->Bmsr.value = BmsrData.value;
395
396                                 /* Do all the cable in / cable out stuff */
397                                 et131x_Mii_check(etdev, BmsrData, BmsrInts);
398                         }
399                 }
400
401                 /* Let's move on to the TxMac */
402                 if (status & ET_INTR_TXMAC) {
403                         etdev->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                         dev_warn(&etdev->pdev->dev,
417                                     "TXMAC interrupt, error 0x%08x\n",
418                                     etdev->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                          */
424                 }
425
426                 /* Handle RXMAC Interrupt */
427                 if (status & ET_INTR_RXMAC) {
428                         /*
429                          * These interrupts are catastrophic to the device,
430                          * what we need to do is disable the interrupts and
431                          * set the flag to cause us to reset so we can solve
432                          * this issue.
433                          */
434                         /* MP_SET_FLAG( etdev,
435                                                 fMP_ADAPTER_HARDWARE_ERROR); */
436
437                         dev_warn(&etdev->pdev->dev,
438                           "RXMAC interrupt, error 0x%08x.  Requesting reset\n",
439                                     readl(&iomem->rxmac.err_reg.value));
440
441                         dev_warn(&etdev->pdev->dev,
442                                     "Enable 0x%08x, Diag 0x%08x\n",
443                                     readl(&iomem->rxmac.ctrl.value),
444                                     readl(&iomem->rxmac.rxq_diag.value));
445
446                         /*
447                          * If we are debugging, we want to see this error,
448                          * otherwise we just want the device to be reset and
449                          * continue
450                          */
451                 }
452
453                 /* Handle MAC_STAT Interrupt */
454                 if (status & ET_INTR_MAC_STAT) {
455                         /*
456                          * This means at least one of the un-masked counters
457                          * in the MAC_STAT block has rolled over.  Use this
458                          * to maintain the top, software managed bits of the
459                          * counter(s).
460                          */
461                         HandleMacStatInterrupt(etdev);
462                 }
463
464                 /* Handle SLV Timeout Interrupt */
465                 if (status & ET_INTR_SLV_TIMEOUT) {
466                         /*
467                          * This means a timeout has occured on a read or
468                          * write request to one of the JAGCore registers. The
469                          * Global Resources block has terminated the request
470                          * and on a read request, returned a "fake" value.
471                          * The most likely reasons are: Bad Address or the
472                          * addressed module is in a power-down state and
473                          * can't respond.
474                          */
475                 }
476         }
477         et131x_enable_interrupts(etdev);
478 }