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