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