Staging et131x: kill refcount
[safe/jmp/linux-2.6] / drivers / staging / et131x / et131x_netdev.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_netdev.c - Routines and data required by all Linux network devices.
12  *
13  *------------------------------------------------------------------------------
14  *
15  * SOFTWARE LICENSE
16  *
17  * This software is provided subject to the following terms and conditions,
18  * which you should read carefully before using the software.  Using this
19  * software indicates your acceptance of these terms and conditions.  If you do
20  * not agree with these terms and conditions, do not use the software.
21  *
22  * Copyright © 2005 Agere Systems Inc.
23  * All rights reserved.
24  *
25  * Redistribution and use in source or binary forms, with or without
26  * modifications, are permitted provided that the following conditions are met:
27  *
28  * . Redistributions of source code must retain the above copyright notice, this
29  *    list of conditions and the following Disclaimer as comments in the code as
30  *    well as in the documentation and/or other materials provided with the
31  *    distribution.
32  *
33  * . Redistributions in binary form must reproduce the above copyright notice,
34  *    this list of conditions and the following Disclaimer in the documentation
35  *    and/or other materials provided with the distribution.
36  *
37  * . Neither the name of Agere Systems Inc. nor the names of the contributors
38  *    may be used to endorse or promote products derived from this software
39  *    without specific prior written permission.
40  *
41  * Disclaimer
42  *
43  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
44  * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
45  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  ANY
46  * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
47  * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
48  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
49  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
51  * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
52  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
53  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
54  * DAMAGE.
55  *
56  */
57
58 #include "et131x_version.h"
59 #include "et131x_debug.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 <asm/system.h>
79
80 #include <linux/mii.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>
86
87 #include "et1310_phy.h"
88 #include "et1310_pm.h"
89 #include "et1310_jagcore.h"
90 #include "et1310_mac.h"
91 #include "et1310_tx.h"
92
93 #include "et131x_adapter.h"
94 #include "et131x_isr.h"
95 #include "et131x_initpci.h"
96
97 /* Data for debugging facilities */
98 #ifdef CONFIG_ET131X_DEBUG
99 extern dbg_info_t *et131x_dbginfo;
100 #endif /* CONFIG_ET131X_DEBUG */
101
102 struct net_device_stats *et131x_stats(struct net_device *netdev);
103 int et131x_open(struct net_device *netdev);
104 int et131x_close(struct net_device *netdev);
105 int et131x_ioctl(struct net_device *netdev, struct ifreq *reqbuf, int cmd);
106 void et131x_multicast(struct net_device *netdev);
107 int et131x_tx(struct sk_buff *skb, struct net_device *netdev);
108 void et131x_tx_timeout(struct net_device *netdev);
109 int et131x_change_mtu(struct net_device *netdev, int new_mtu);
110 int et131x_set_mac_addr(struct net_device *netdev, void *new_mac);
111 void et131x_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
112 void et131x_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
113 void et131x_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
114
115 static const struct net_device_ops et131x_netdev_ops = {
116         .ndo_open               = et131x_open,
117         .ndo_stop               = et131x_close,
118         .ndo_start_xmit         = et131x_tx,
119         .ndo_set_multicast_list = et131x_multicast,
120         .ndo_tx_timeout         = et131x_tx_timeout,
121         .ndo_change_mtu         = et131x_change_mtu,
122         .ndo_set_mac_address    = et131x_set_mac_addr,
123         .ndo_validate_addr      = eth_validate_addr,
124         .ndo_get_stats          = et131x_stats,
125         .ndo_do_ioctl           = et131x_ioctl,
126 };
127
128 /**
129  * et131x_device_alloc
130  *
131  * Returns pointer to the allocated and initialized net_device struct for
132  * this device.
133  *
134  * Create instances of net_device and wl_private for the new adapter and
135  * register the device's entry points in the net_device structure.
136  */
137 struct net_device *et131x_device_alloc(void)
138 {
139         struct net_device *netdev;
140
141         DBG_ENTER(et131x_dbginfo);
142
143         /* Alloc net_device and adapter structs */
144         netdev = alloc_etherdev(sizeof(struct et131x_adapter));
145
146         if (netdev == NULL) {
147                 DBG_ERROR(et131x_dbginfo,
148                           "Alloc of net_device struct failed\n");
149                 DBG_LEAVE(et131x_dbginfo);
150                 return NULL;
151         }
152
153         /* Setup the function registration table (and other data) for a
154          * net_device
155          */
156         /* netdev->init               = &et131x_init; */
157         /* netdev->set_config = &et131x_config; */
158         netdev->watchdog_timeo = ET131X_TX_TIMEOUT;
159         netdev->netdev_ops = &et131x_netdev_ops;
160
161         /* netdev->ethtool_ops        = &et131x_ethtool_ops; */
162
163         /* Poll? */
164         /* netdev->poll               = &et131x_poll; */
165         /* netdev->poll_controller    = &et131x_poll_controller; */
166
167         DBG_LEAVE(et131x_dbginfo);
168         return netdev;
169 }
170
171 /**
172  * et131x_stats - Return the current device statistics.
173  * @netdev: device whose stats are being queried
174  *
175  * Returns 0 on success, errno on failure (as defined in errno.h)
176  */
177 struct net_device_stats *et131x_stats(struct net_device *netdev)
178 {
179         struct et131x_adapter *adapter = netdev_priv(netdev);
180         struct net_device_stats *stats = &adapter->net_stats;
181         CE_STATS_t *devstat = &adapter->Stats;
182
183         DBG_ENTER(et131x_dbginfo);
184
185         stats->rx_packets = devstat->ipackets;
186         stats->tx_packets = devstat->opackets;
187         stats->rx_errors = devstat->length_err + devstat->alignment_err +
188             devstat->crc_err + devstat->code_violations + devstat->other_errors;
189         stats->tx_errors = devstat->max_pkt_error;
190         stats->multicast = devstat->multircv;
191         stats->collisions = devstat->collisions;
192
193         stats->rx_length_errors = devstat->length_err;
194         stats->rx_over_errors = devstat->rx_ov_flow;
195         stats->rx_crc_errors = devstat->crc_err;
196
197         /* NOTE: These stats don't have corresponding values in CE_STATS,
198          * so we're going to have to update these directly from within the
199          * TX/RX code
200          */
201         /* stats->rx_bytes            = 20; devstat->; */
202         /* stats->tx_bytes            = 20;  devstat->; */
203         /* stats->rx_dropped          = devstat->; */
204         /* stats->tx_dropped          = devstat->; */
205
206         /*  NOTE: Not used, can't find analogous statistics */
207         /* stats->rx_frame_errors     = devstat->; */
208         /* stats->rx_fifo_errors      = devstat->; */
209         /* stats->rx_missed_errors    = devstat->; */
210
211         /* stats->tx_aborted_errors   = devstat->; */
212         /* stats->tx_carrier_errors   = devstat->; */
213         /* stats->tx_fifo_errors      = devstat->; */
214         /* stats->tx_heartbeat_errors = devstat->; */
215         /* stats->tx_window_errors    = devstat->; */
216
217         DBG_LEAVE(et131x_dbginfo);
218         return stats;
219 }
220
221 /**
222  * et131x_open - Open the device for use.
223  * @netdev: device to be opened
224  *
225  * Returns 0 on success, errno on failure (as defined in errno.h)
226  */
227 int et131x_open(struct net_device *netdev)
228 {
229         int result = 0;
230         struct et131x_adapter *adapter = netdev_priv(netdev);
231
232         DBG_ENTER(et131x_dbginfo);
233
234         /* Start the timer to track NIC errors */
235         add_timer(&adapter->ErrorTimer);
236
237         /* Register our ISR */
238         DBG_TRACE(et131x_dbginfo, "Registering ISR...\n");
239
240         result =
241             request_irq(netdev->irq, et131x_isr, IRQF_SHARED, netdev->name,
242                         netdev);
243         if (result) {
244                 DBG_ERROR(et131x_dbginfo, "Could not register ISR\n");
245                 DBG_LEAVE(et131x_dbginfo);
246                 return result;
247         }
248
249         /* Enable the Tx and Rx DMA engines (if not already enabled) */
250         et131x_rx_dma_enable(adapter);
251         et131x_tx_dma_enable(adapter);
252
253         /* Enable device interrupts */
254         et131x_enable_interrupts(adapter);
255
256         MP_SET_FLAG(adapter, fMP_ADAPTER_INTERRUPT_IN_USE);
257
258         /* We're ready to move some data, so start the queue */
259         netif_start_queue(netdev);
260
261         DBG_LEAVE(et131x_dbginfo);
262         return result;
263 }
264
265 /**
266  * et131x_close - Close the device
267  * @netdev: device to be closed
268  *
269  * Returns 0 on success, errno on failure (as defined in errno.h)
270  */
271 int et131x_close(struct net_device *netdev)
272 {
273         struct et131x_adapter *adapter = netdev_priv(netdev);
274
275         DBG_ENTER(et131x_dbginfo);
276
277         /* First thing is to stop the queue */
278         netif_stop_queue(netdev);
279
280         /* Stop the Tx and Rx DMA engines */
281         et131x_rx_dma_disable(adapter);
282         et131x_tx_dma_disable(adapter);
283
284         /* Disable device interrupts */
285         et131x_disable_interrupts(adapter);
286
287         /* Deregistering ISR */
288         MP_CLEAR_FLAG(adapter, fMP_ADAPTER_INTERRUPT_IN_USE);
289
290         DBG_TRACE(et131x_dbginfo, "Deregistering ISR...\n");
291         free_irq(netdev->irq, netdev);
292
293         /* Stop the error timer */
294         del_timer_sync(&adapter->ErrorTimer);
295
296         DBG_LEAVE(et131x_dbginfo);
297         return 0;
298 }
299
300 /**
301  * et131x_ioctl_mii - The function which handles MII IOCTLs
302  * @netdev: device on which the query is being made
303  * @reqbuf: the request-specific data buffer
304  * @cmd: the command request code
305  *
306  * Returns 0 on success, errno on failure (as defined in errno.h)
307  */
308 int et131x_ioctl_mii(struct net_device *netdev, struct ifreq *reqbuf, int cmd)
309 {
310         int status = 0;
311         struct et131x_adapter *etdev = netdev_priv(netdev);
312         struct mii_ioctl_data *data = if_mii(reqbuf);
313
314         DBG_ENTER(et131x_dbginfo);
315
316         switch (cmd) {
317         case SIOCGMIIPHY:
318                 DBG_VERBOSE(et131x_dbginfo, "SIOCGMIIPHY\n");
319                 data->phy_id = etdev->Stats.xcvr_addr;
320                 break;
321
322         case SIOCGMIIREG:
323                 DBG_VERBOSE(et131x_dbginfo, "SIOCGMIIREG\n");
324                 if (!capable(CAP_NET_ADMIN)) {
325                         status = -EPERM;
326                 } else {
327                         status = MiRead(etdev,
328                                         data->reg_num, &data->val_out);
329                 }
330                 break;
331
332         case SIOCSMIIREG:
333                 DBG_VERBOSE(et131x_dbginfo, "SIOCSMIIREG\n");
334                 if (!capable(CAP_NET_ADMIN)) {
335                         status = -EPERM;
336                 } else {
337                         status = MiWrite(etdev, data->reg_num,
338                                          data->val_in);
339                 }
340                 break;
341
342         default:
343                 status = -EOPNOTSUPP;
344         }
345
346         DBG_LEAVE(et131x_dbginfo);
347         return status;
348 }
349
350 /**
351  * et131x_ioctl - The I/O Control handler for the driver
352  * @netdev: device on which the control request is being made
353  * @reqbuf: a pointer to the IOCTL request buffer
354  * @cmd: the IOCTL command code
355  *
356  * Returns 0 on success, errno on failure (as defined in errno.h)
357  */
358 int et131x_ioctl(struct net_device *netdev, struct ifreq *reqbuf, int cmd)
359 {
360         int status = 0;
361
362         DBG_ENTER(et131x_dbginfo);
363
364         switch (cmd) {
365         case SIOCGMIIPHY:
366         case SIOCGMIIREG:
367         case SIOCSMIIREG:
368                 status = et131x_ioctl_mii(netdev, reqbuf, cmd);
369                 break;
370
371         default:
372                 DBG_WARNING(et131x_dbginfo, "Unhandled IOCTL Code: 0x%04x\n",
373                             cmd);
374                 status = -EOPNOTSUPP;
375         }
376
377         DBG_LEAVE(et131x_dbginfo);
378         return status;
379 }
380
381 /**
382  * et131x_set_packet_filter - Configures the Rx Packet filtering on the device
383  * @adapter: pointer to our private adapter structure
384  *
385  * Returns 0 on success, errno on failure
386  */
387 int et131x_set_packet_filter(struct et131x_adapter *adapter)
388 {
389         int status = 0;
390         uint32_t filter = adapter->PacketFilter;
391         RXMAC_CTRL_t ctrl;
392         RXMAC_PF_CTRL_t pf_ctrl;
393
394         DBG_ENTER(et131x_dbginfo);
395
396         ctrl.value = readl(&adapter->CSRAddress->rxmac.ctrl.value);
397         pf_ctrl.value = readl(&adapter->CSRAddress->rxmac.pf_ctrl.value);
398
399         /* Default to disabled packet filtering.  Enable it in the individual
400          * case statements that require the device to filter something
401          */
402         ctrl.bits.pkt_filter_disable = 1;
403
404         /* Set us to be in promiscuous mode so we receive everything, this
405          * is also true when we get a packet filter of 0
406          */
407         if ((filter & ET131X_PACKET_TYPE_PROMISCUOUS) || filter == 0) {
408                 pf_ctrl.bits.filter_broad_en = 0;
409                 pf_ctrl.bits.filter_multi_en = 0;
410                 pf_ctrl.bits.filter_uni_en = 0;
411         } else {
412                 /*
413                  * Set us up with Multicast packet filtering.  Three cases are
414                  * possible - (1) we have a multi-cast list, (2) we receive ALL
415                  * multicast entries or (3) we receive none.
416                  */
417                 if (filter & ET131X_PACKET_TYPE_ALL_MULTICAST) {
418                         DBG_VERBOSE(et131x_dbginfo,
419                               "Multicast filtering OFF (Rx ALL MULTICAST)\n");
420                         pf_ctrl.bits.filter_multi_en = 0;
421                 } else {
422                         DBG_VERBOSE(et131x_dbginfo,
423                                 "Multicast filtering ON\n");
424                         SetupDeviceForMulticast(adapter);
425                         pf_ctrl.bits.filter_multi_en = 1;
426                         ctrl.bits.pkt_filter_disable = 0;
427                 }
428
429                 /* Set us up with Unicast packet filtering */
430                 if (filter & ET131X_PACKET_TYPE_DIRECTED) {
431                         DBG_VERBOSE(et131x_dbginfo, "Unicast Filtering ON\n");
432                         SetupDeviceForUnicast(adapter);
433                         pf_ctrl.bits.filter_uni_en = 1;
434                         ctrl.bits.pkt_filter_disable = 0;
435                 }
436
437                 /* Set us up with Broadcast packet filtering */
438                 if (filter & ET131X_PACKET_TYPE_BROADCAST) {
439                         DBG_VERBOSE(et131x_dbginfo, "Broadcast Filtering ON\n");
440                         pf_ctrl.bits.filter_broad_en = 1;
441                         ctrl.bits.pkt_filter_disable = 0;
442                 } else {
443                         DBG_VERBOSE(et131x_dbginfo,
444                                     "Broadcast Filtering OFF\n");
445                         pf_ctrl.bits.filter_broad_en = 0;
446                 }
447
448                 /* Setup the receive mac configuration registers - Packet
449                  * Filter control + the enable / disable for packet filter
450                  * in the control reg.
451                  */
452                 writel(pf_ctrl.value,
453                        &adapter->CSRAddress->rxmac.pf_ctrl.value);
454                 writel(ctrl.value, &adapter->CSRAddress->rxmac.ctrl.value);
455         }
456
457         DBG_LEAVE(et131x_dbginfo);
458         return status;
459 }
460
461 /**
462  * et131x_multicast - The handler to configure multicasting on the interface
463  * @netdev: a pointer to a net_device struct representing the device
464  */
465 void et131x_multicast(struct net_device *netdev)
466 {
467         struct et131x_adapter *adapter = netdev_priv(netdev);
468         uint32_t PacketFilter = 0;
469         uint32_t count;
470         unsigned long flags;
471         struct dev_mc_list *mclist = netdev->mc_list;
472
473         DBG_ENTER(et131x_dbginfo);
474
475         spin_lock_irqsave(&adapter->Lock, flags);
476
477         /* Before we modify the platform-independent filter flags, store them
478          * locally. This allows us to determine if anything's changed and if
479          * we even need to bother the hardware
480          */
481         PacketFilter = adapter->PacketFilter;
482
483         /* Clear the 'multicast' flag locally; becuase we only have a single
484          * flag to check multicast, and multiple multicast addresses can be
485          * set, this is the easiest way to determine if more than one
486          * multicast address is being set.
487          */
488         PacketFilter &= ~ET131X_PACKET_TYPE_MULTICAST;
489
490         /* Check the net_device flags and set the device independent flags
491          * accordingly
492          */
493         DBG_VERBOSE(et131x_dbginfo,
494                     "MULTICAST ADDR COUNT: %d\n", netdev->mc_count);
495
496         if (netdev->flags & IFF_PROMISC) {
497                 DBG_VERBOSE(et131x_dbginfo, "Request: PROMISCUOUS MODE ON\n");
498                 adapter->PacketFilter |= ET131X_PACKET_TYPE_PROMISCUOUS;
499         } else {
500                 DBG_VERBOSE(et131x_dbginfo, "Request: PROMISCUOUS MODE OFF\n");
501                 adapter->PacketFilter &= ~ET131X_PACKET_TYPE_PROMISCUOUS;
502         }
503
504         if (netdev->flags & IFF_ALLMULTI) {
505                 DBG_VERBOSE(et131x_dbginfo, "Request: ACCEPT ALL MULTICAST\n");
506                 adapter->PacketFilter |= ET131X_PACKET_TYPE_ALL_MULTICAST;
507         }
508
509         if (netdev->mc_count > NIC_MAX_MCAST_LIST) {
510                 DBG_WARNING(et131x_dbginfo,
511                             "ACCEPT ALL MULTICAST for now, as there's more Multicast addresses than the HW supports\n");
512                 adapter->PacketFilter |= ET131X_PACKET_TYPE_ALL_MULTICAST;
513         }
514
515         if (netdev->mc_count < 1) {
516                 DBG_VERBOSE(et131x_dbginfo, "Request: REJECT ALL MULTICAST\n");
517                 adapter->PacketFilter &= ~ET131X_PACKET_TYPE_ALL_MULTICAST;
518                 adapter->PacketFilter &= ~ET131X_PACKET_TYPE_MULTICAST;
519         } else {
520                 DBG_VERBOSE(et131x_dbginfo,
521                             "Request: SET MULTICAST FILTER(S)\n");
522                 adapter->PacketFilter |= ET131X_PACKET_TYPE_MULTICAST;
523         }
524
525         /* Set values in the private adapter struct */
526         adapter->MCAddressCount = netdev->mc_count;
527
528         if (netdev->mc_count) {
529                 if (mclist->dmi_addrlen != ETH_ALEN)
530                         DBG_WARNING(et131x_dbginfo,
531                                 "Multicast addrs are not ETH_ALEN in size\n");
532                 else {
533                         count = netdev->mc_count - 1;
534                         memcpy(adapter->MCList[count], mclist->dmi_addr,
535                                ETH_ALEN);
536                 }
537         }
538
539         /* Are the new flags different from the previous ones? If not, then no
540          * action is required
541          *
542          * NOTE - This block will always update the MCList with the hardware,
543          *        even if the addresses aren't the same.
544          */
545         if (PacketFilter != adapter->PacketFilter) {
546                 /* Call the device's filter function */
547                 DBG_VERBOSE(et131x_dbginfo, "UPDATE REQUIRED, FLAGS changed\n");
548
549                 et131x_set_packet_filter(adapter);
550         } else {
551                 DBG_VERBOSE(et131x_dbginfo,
552                             "NO UPDATE REQUIRED, FLAGS didn't change\n");
553         }
554
555         spin_unlock_irqrestore(&adapter->Lock, flags);
556
557         DBG_LEAVE(et131x_dbginfo);
558 }
559
560 /**
561  * et131x_tx - The handler to tx a packet on the device
562  * @skb: data to be Tx'd
563  * @netdev: device on which data is to be Tx'd
564  *
565  * Returns 0 on success, errno on failure (as defined in errno.h)
566  */
567 int et131x_tx(struct sk_buff *skb, struct net_device *netdev)
568 {
569         int status = 0;
570
571         DBG_TX_ENTER(et131x_dbginfo);
572
573         /* Save the timestamp for the TX timeout watchdog */
574         netdev->trans_start = jiffies;
575
576         /* Call the device-specific data Tx routine */
577         status = et131x_send_packets(skb, netdev);
578
579         /* Check status and manage the netif queue if necessary */
580         if (status != 0) {
581                 if (status == -ENOMEM) {
582                         DBG_VERBOSE(et131x_dbginfo,
583                                     "OUT OF TCBs; STOP NETIF QUEUE\n");
584
585                         /* Put the queue to sleep until resources are
586                          * available
587                          */
588                         netif_stop_queue(netdev);
589                         status = NETDEV_TX_BUSY;
590                 } else {
591                         DBG_WARNING(et131x_dbginfo,
592                                     "Misc error; drop packet\n");
593                         status = NETDEV_TX_OK;
594                 }
595         }
596
597         DBG_TX_LEAVE(et131x_dbginfo);
598         return status;
599 }
600
601 /**
602  * et131x_tx_timeout - Timeout handler
603  * @netdev: a pointer to a net_device struct representing the device
604  *
605  * The handler called when a Tx request times out. The timeout period is
606  * specified by the 'tx_timeo" element in the net_device structure (see
607  * et131x_alloc_device() to see how this value is set).
608  */
609 void et131x_tx_timeout(struct net_device *netdev)
610 {
611         struct et131x_adapter *etdev = netdev_priv(netdev);
612         PMP_TCB pMpTcb;
613         unsigned long flags;
614
615         DBG_WARNING(et131x_dbginfo, "TX TIMEOUT\n");
616
617         /* Just skip this part if the adapter is doing link detection */
618         if (MP_TEST_FLAG(etdev, fMP_ADAPTER_LINK_DETECTION)) {
619                 DBG_ERROR(et131x_dbginfo, "Still doing link detection\n");
620                 return;
621         }
622
623         /* Any nonrecoverable hardware error?
624          * Checks adapter->flags for any failure in phy reading
625          */
626         if (MP_TEST_FLAG(etdev, fMP_ADAPTER_NON_RECOVER_ERROR)) {
627                 DBG_WARNING(et131x_dbginfo, "Non recoverable error - remove\n");
628                 return;
629         }
630
631         /* Hardware failure? */
632         if (MP_TEST_FLAG(etdev, fMP_ADAPTER_HARDWARE_ERROR)) {
633                 DBG_WARNING(et131x_dbginfo, "hardware error - reset\n");
634                 return;
635         }
636
637         /* Is send stuck? */
638         spin_lock_irqsave(&etdev->TCBSendQLock, flags);
639
640         pMpTcb = etdev->TxRing.CurrSendHead;
641
642         if (pMpTcb != NULL) {
643                 pMpTcb->Count++;
644
645                 if (pMpTcb->Count > NIC_SEND_HANG_THRESHOLD) {
646 #ifdef CONFIG_ET131X_DEBUG
647                         TX_STATUS_BLOCK_t txDmaComplete =
648                             *(etdev->TxRing.pTxStatusVa);
649                         PTX_DESC_ENTRY_t pDesc =
650                             etdev->TxRing.pTxDescRingVa +
651                             pMpTcb->WrIndex.bits.val;
652 #endif
653                         TX_DESC_ENTRY_t StuckDescriptors[10];
654
655                         if (pMpTcb->WrIndex.bits.val > 7) {
656                                 memcpy(StuckDescriptors,
657                                        etdev->TxRing.pTxDescRingVa +
658                                        pMpTcb->WrIndex.bits.val - 6,
659                                        sizeof(TX_DESC_ENTRY_t) * 10);
660                         }
661
662                         spin_unlock_irqrestore(&etdev->TCBSendQLock,
663                                                flags);
664
665                         DBG_WARNING(et131x_dbginfo,
666                                 "Send stuck - reset.  pMpTcb->WrIndex %x, Flags 0x%08x\n",
667                                 pMpTcb->WrIndex.bits.val,
668                                 pMpTcb->Flags);
669
670                         DBG_WARNING(et131x_dbginfo,
671                                 "pDesc 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
672                                 pDesc->DataBufferPtrHigh,
673                                 pDesc->DataBufferPtrLow, pDesc->word2.value,
674                                 pDesc->word3.value);
675
676                         DBG_WARNING(et131x_dbginfo,
677                                     "WbStatus 0x%08x\n", txDmaComplete.value);
678
679 #ifdef CONFIG_ET131X_DEBUG
680                         DumpDeviceBlock(DBG_WARNING_ON, etdev, 0);
681                         DumpDeviceBlock(DBG_WARNING_ON, etdev, 1);
682                         DumpDeviceBlock(DBG_WARNING_ON, etdev, 3);
683                         DumpDeviceBlock(DBG_WARNING_ON, etdev, 5);
684 #endif
685                         et131x_close(netdev);
686                         et131x_open(netdev);
687
688                         return;
689                 }
690         }
691
692         spin_unlock_irqrestore(&etdev->TCBSendQLock, flags);
693 }
694
695 /**
696  * et131x_change_mtu - The handler called to change the MTU for the device
697  * @netdev: device whose MTU is to be changed
698  * @new_mtu: the desired MTU
699  *
700  * Returns 0 on success, errno on failure (as defined in errno.h)
701  */
702 int et131x_change_mtu(struct net_device *netdev, int new_mtu)
703 {
704         int result = 0;
705         struct et131x_adapter *adapter = netdev_priv(netdev);
706
707         DBG_ENTER(et131x_dbginfo);
708
709         /* Make sure the requested MTU is valid */
710         if (new_mtu == 0 || new_mtu > 9216) {
711                 DBG_LEAVE(et131x_dbginfo);
712                 return -EINVAL;
713         }
714
715         /* Stop the netif queue */
716         netif_stop_queue(netdev);
717
718         /* Stop the Tx and Rx DMA engines */
719         et131x_rx_dma_disable(adapter);
720         et131x_tx_dma_disable(adapter);
721
722         /* Disable device interrupts */
723         et131x_disable_interrupts(adapter);
724         et131x_handle_send_interrupt(adapter);
725         et131x_handle_recv_interrupt(adapter);
726
727         /* Set the new MTU */
728         netdev->mtu = new_mtu;
729
730         /* Free Rx DMA memory */
731         et131x_adapter_memory_free(adapter);
732
733         /* Set the config parameter for Jumbo Packet support */
734         adapter->RegistryJumboPacket = new_mtu + 14;
735         et131x_soft_reset(adapter);
736
737         /* Alloc and init Rx DMA memory */
738         result = et131x_adapter_memory_alloc(adapter);
739         if (result != 0) {
740                 DBG_WARNING(et131x_dbginfo,
741                         "Change MTU failed; couldn't re-alloc DMA memory\n");
742                 return result;
743         }
744
745         et131x_init_send(adapter);
746
747         et131x_setup_hardware_properties(adapter);
748         memcpy(netdev->dev_addr, adapter->CurrentAddress, ETH_ALEN);
749
750         /* Init the device with the new settings */
751         et131x_adapter_setup(adapter);
752
753         /* Enable interrupts */
754         if (MP_TEST_FLAG(adapter, fMP_ADAPTER_INTERRUPT_IN_USE))
755                 et131x_enable_interrupts(adapter);
756
757         /* Restart the Tx and Rx DMA engines */
758         et131x_rx_dma_enable(adapter);
759         et131x_tx_dma_enable(adapter);
760
761         /* Restart the netif queue */
762         netif_wake_queue(netdev);
763
764         DBG_LEAVE(et131x_dbginfo);
765         return result;
766 }
767
768 /**
769  * et131x_set_mac_addr - handler to change the MAC address for the device
770  * @netdev: device whose MAC is to be changed
771  * @new_mac: the desired MAC address
772  *
773  * Returns 0 on success, errno on failure (as defined in errno.h)
774  *
775  * IMPLEMENTED BY : blux http://berndlux.de 22.01.2007 21:14
776  */
777 int et131x_set_mac_addr(struct net_device *netdev, void *new_mac)
778 {
779         int result = 0;
780         struct et131x_adapter *adapter = netdev_priv(netdev);
781         struct sockaddr *address = new_mac;
782
783         DBG_ENTER(et131x_dbginfo);
784         /* begin blux */
785         /* DBG_VERBOSE( et131x_dbginfo, "Function not implemented!!\n" ); */
786
787         if (adapter == NULL) {
788                 DBG_LEAVE(et131x_dbginfo);
789                 return -ENODEV;
790         }
791
792         /* Make sure the requested MAC is valid */
793         if (!is_valid_ether_addr(address->sa_data)) {
794                 DBG_LEAVE(et131x_dbginfo);
795                 return -EINVAL;
796         }
797
798         /* Stop the netif queue */
799         netif_stop_queue(netdev);
800
801         /* Stop the Tx and Rx DMA engines */
802         et131x_rx_dma_disable(adapter);
803         et131x_tx_dma_disable(adapter);
804
805         /* Disable device interrupts */
806         et131x_disable_interrupts(adapter);
807         et131x_handle_send_interrupt(adapter);
808         et131x_handle_recv_interrupt(adapter);
809
810         /* Set the new MAC */
811         /* netdev->set_mac_address  = &new_mac; */
812         /* netdev->mtu = new_mtu; */
813
814         memcpy(netdev->dev_addr, address->sa_data, netdev->addr_len);
815
816         printk(KERN_INFO
817                 "%s: Setting MAC address to %02x:%02x:%02x:%02x:%02x:%02x\n",
818                         netdev->name,
819                         netdev->dev_addr[0], netdev->dev_addr[1],
820                         netdev->dev_addr[2], netdev->dev_addr[3],
821                         netdev->dev_addr[4], netdev->dev_addr[5]);
822
823         /* Free Rx DMA memory */
824         et131x_adapter_memory_free(adapter);
825
826         /* Set the config parameter for Jumbo Packet support */
827         /* adapter->RegistryJumboPacket = new_mtu + 14; */
828         /* blux: not needet here, we'll change the MAC */
829
830         et131x_soft_reset(adapter);
831
832         /* Alloc and init Rx DMA memory */
833         result = et131x_adapter_memory_alloc(adapter);
834         if (result != 0) {
835                 DBG_WARNING(et131x_dbginfo,
836                         "Change MAC failed; couldn't re-alloc DMA memory\n");
837                 return result;
838         }
839
840         et131x_init_send(adapter);
841
842         et131x_setup_hardware_properties(adapter);
843         /* memcpy( netdev->dev_addr, adapter->CurrentAddress, ETH_ALEN ); */
844         /* blux: no, do not override our nice address */
845
846         /* Init the device with the new settings */
847         et131x_adapter_setup(adapter);
848
849         /* Enable interrupts */
850         if (MP_TEST_FLAG(adapter, fMP_ADAPTER_INTERRUPT_IN_USE))
851                 et131x_enable_interrupts(adapter);
852
853         /* Restart the Tx and Rx DMA engines */
854         et131x_rx_dma_enable(adapter);
855         et131x_tx_dma_enable(adapter);
856
857         /* Restart the netif queue */
858         netif_wake_queue(netdev);
859
860         DBG_LEAVE(et131x_dbginfo);
861         return result;
862 }