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