Staging: add cowloop driver
[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_defs.h"
60
61 #include <linux/init.h>
62 #include <linux/module.h>
63 #include <linux/types.h>
64 #include <linux/kernel.h>
65
66 #include <linux/sched.h>
67 #include <linux/ptrace.h>
68 #include <linux/slab.h>
69 #include <linux/ctype.h>
70 #include <linux/string.h>
71 #include <linux/timer.h>
72 #include <linux/interrupt.h>
73 #include <linux/in.h>
74 #include <linux/delay.h>
75 #include <linux/io.h>
76 #include <linux/bitops.h>
77 #include <linux/pci.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 struct net_device_stats *et131x_stats(struct net_device *netdev);
98 int et131x_open(struct net_device *netdev);
99 int et131x_close(struct net_device *netdev);
100 int et131x_ioctl(struct net_device *netdev, struct ifreq *reqbuf, int cmd);
101 void et131x_multicast(struct net_device *netdev);
102 int et131x_tx(struct sk_buff *skb, struct net_device *netdev);
103 void et131x_tx_timeout(struct net_device *netdev);
104 int et131x_change_mtu(struct net_device *netdev, int new_mtu);
105 int et131x_set_mac_addr(struct net_device *netdev, void *new_mac);
106 void et131x_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
107 void et131x_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
108 void et131x_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
109
110 static const struct net_device_ops et131x_netdev_ops = {
111         .ndo_open               = et131x_open,
112         .ndo_stop               = et131x_close,
113         .ndo_start_xmit         = et131x_tx,
114         .ndo_set_multicast_list = et131x_multicast,
115         .ndo_tx_timeout         = et131x_tx_timeout,
116         .ndo_change_mtu         = et131x_change_mtu,
117         .ndo_set_mac_address    = et131x_set_mac_addr,
118         .ndo_validate_addr      = eth_validate_addr,
119         .ndo_get_stats          = et131x_stats,
120         .ndo_do_ioctl           = et131x_ioctl,
121 };
122
123 /**
124  * et131x_device_alloc
125  *
126  * Returns pointer to the allocated and initialized net_device struct for
127  * this device.
128  *
129  * Create instances of net_device and wl_private for the new adapter and
130  * register the device's entry points in the net_device structure.
131  */
132 struct net_device *et131x_device_alloc(void)
133 {
134         struct net_device *netdev;
135
136         /* Alloc net_device and adapter structs */
137         netdev = alloc_etherdev(sizeof(struct et131x_adapter));
138
139         if (netdev == NULL) {
140                 printk(KERN_ERR "et131x: Alloc of net_device struct failed\n");
141                 return NULL;
142         }
143
144         /* Setup the function registration table (and other data) for a
145          * net_device
146          */
147         /* netdev->init               = &et131x_init; */
148         /* netdev->set_config = &et131x_config; */
149         netdev->watchdog_timeo = ET131X_TX_TIMEOUT;
150         netdev->netdev_ops = &et131x_netdev_ops;
151
152         /* netdev->ethtool_ops        = &et131x_ethtool_ops; */
153
154         /* Poll? */
155         /* netdev->poll               = &et131x_poll; */
156         /* netdev->poll_controller    = &et131x_poll_controller; */
157         return netdev;
158 }
159
160 /**
161  * et131x_stats - Return the current device statistics.
162  * @netdev: device whose stats are being queried
163  *
164  * Returns 0 on success, errno on failure (as defined in errno.h)
165  */
166 struct net_device_stats *et131x_stats(struct net_device *netdev)
167 {
168         struct et131x_adapter *adapter = netdev_priv(netdev);
169         struct net_device_stats *stats = &adapter->net_stats;
170         CE_STATS_t *devstat = &adapter->Stats;
171
172         stats->rx_packets = devstat->ipackets;
173         stats->tx_packets = devstat->opackets;
174         stats->rx_errors = devstat->length_err + devstat->alignment_err +
175             devstat->crc_err + devstat->code_violations + devstat->other_errors;
176         stats->tx_errors = devstat->max_pkt_error;
177         stats->multicast = devstat->multircv;
178         stats->collisions = devstat->collisions;
179
180         stats->rx_length_errors = devstat->length_err;
181         stats->rx_over_errors = devstat->rx_ov_flow;
182         stats->rx_crc_errors = devstat->crc_err;
183
184         /* NOTE: These stats don't have corresponding values in CE_STATS,
185          * so we're going to have to update these directly from within the
186          * TX/RX code
187          */
188         /* stats->rx_bytes            = 20; devstat->; */
189         /* stats->tx_bytes            = 20;  devstat->; */
190         /* stats->rx_dropped          = devstat->; */
191         /* stats->tx_dropped          = devstat->; */
192
193         /*  NOTE: Not used, can't find analogous statistics */
194         /* stats->rx_frame_errors     = devstat->; */
195         /* stats->rx_fifo_errors      = devstat->; */
196         /* stats->rx_missed_errors    = devstat->; */
197
198         /* stats->tx_aborted_errors   = devstat->; */
199         /* stats->tx_carrier_errors   = devstat->; */
200         /* stats->tx_fifo_errors      = devstat->; */
201         /* stats->tx_heartbeat_errors = devstat->; */
202         /* stats->tx_window_errors    = devstat->; */
203         return stats;
204 }
205
206 /**
207  * et131x_open - Open the device for use.
208  * @netdev: device to be opened
209  *
210  * Returns 0 on success, errno on failure (as defined in errno.h)
211  */
212 int et131x_open(struct net_device *netdev)
213 {
214         int result = 0;
215         struct et131x_adapter *adapter = netdev_priv(netdev);
216
217         /* Start the timer to track NIC errors */
218         add_timer(&adapter->ErrorTimer);
219
220         /* Register our IRQ */
221         result = request_irq(netdev->irq, et131x_isr, IRQF_SHARED,
222                                         netdev->name, netdev);
223         if (result) {
224                 dev_err(&adapter->pdev->dev, "c ould not register IRQ %d\n",
225                         netdev->irq);
226                 return result;
227         }
228
229         /* Enable the Tx and Rx DMA engines (if not already enabled) */
230         et131x_rx_dma_enable(adapter);
231         et131x_tx_dma_enable(adapter);
232
233         /* Enable device interrupts */
234         et131x_enable_interrupts(adapter);
235
236         adapter->Flags |= fMP_ADAPTER_INTERRUPT_IN_USE;
237
238         /* We're ready to move some data, so start the queue */
239         netif_start_queue(netdev);
240         return result;
241 }
242
243 /**
244  * et131x_close - Close the device
245  * @netdev: device to be closed
246  *
247  * Returns 0 on success, errno on failure (as defined in errno.h)
248  */
249 int et131x_close(struct net_device *netdev)
250 {
251         struct et131x_adapter *adapter = netdev_priv(netdev);
252
253         /* First thing is to stop the queue */
254         netif_stop_queue(netdev);
255
256         /* Stop the Tx and Rx DMA engines */
257         et131x_rx_dma_disable(adapter);
258         et131x_tx_dma_disable(adapter);
259
260         /* Disable device interrupts */
261         et131x_disable_interrupts(adapter);
262
263         /* Deregistering ISR */
264         adapter->Flags &= ~fMP_ADAPTER_INTERRUPT_IN_USE;
265         free_irq(netdev->irq, netdev);
266
267         /* Stop the error timer */
268         del_timer_sync(&adapter->ErrorTimer);
269         return 0;
270 }
271
272 /**
273  * et131x_ioctl_mii - The function which handles MII IOCTLs
274  * @netdev: device on which the query is being made
275  * @reqbuf: the request-specific data buffer
276  * @cmd: the command request code
277  *
278  * Returns 0 on success, errno on failure (as defined in errno.h)
279  */
280 int et131x_ioctl_mii(struct net_device *netdev, struct ifreq *reqbuf, int cmd)
281 {
282         int status = 0;
283         struct et131x_adapter *etdev = netdev_priv(netdev);
284         struct mii_ioctl_data *data = if_mii(reqbuf);
285
286         switch (cmd) {
287         case SIOCGMIIPHY:
288                 data->phy_id = etdev->Stats.xcvr_addr;
289                 break;
290
291         case SIOCGMIIREG:
292                 if (!capable(CAP_NET_ADMIN))
293                         status = -EPERM;
294                 else
295                         status = MiRead(etdev,
296                                         data->reg_num, &data->val_out);
297                 break;
298
299         case SIOCSMIIREG:
300                 if (!capable(CAP_NET_ADMIN))
301                         status = -EPERM;
302                 else
303                         status = MiWrite(etdev, data->reg_num,
304                                          data->val_in);
305                 break;
306
307         default:
308                 status = -EOPNOTSUPP;
309         }
310         return status;
311 }
312
313 /**
314  * et131x_ioctl - The I/O Control handler for the driver
315  * @netdev: device on which the control request is being made
316  * @reqbuf: a pointer to the IOCTL request buffer
317  * @cmd: the IOCTL command code
318  *
319  * Returns 0 on success, errno on failure (as defined in errno.h)
320  */
321 int et131x_ioctl(struct net_device *netdev, struct ifreq *reqbuf, int cmd)
322 {
323         int status = 0;
324
325         switch (cmd) {
326         case SIOCGMIIPHY:
327         case SIOCGMIIREG:
328         case SIOCSMIIREG:
329                 status = et131x_ioctl_mii(netdev, reqbuf, cmd);
330                 break;
331
332         default:
333                 status = -EOPNOTSUPP;
334         }
335         return status;
336 }
337
338 /**
339  * et131x_set_packet_filter - Configures the Rx Packet filtering on the device
340  * @adapter: pointer to our private adapter structure
341  *
342  * Returns 0 on success, errno on failure
343  */
344 int et131x_set_packet_filter(struct et131x_adapter *adapter)
345 {
346         int status = 0;
347         uint32_t filter = adapter->PacketFilter;
348         RXMAC_CTRL_t ctrl;
349         RXMAC_PF_CTRL_t pf_ctrl;
350
351         ctrl.value = readl(&adapter->regs->rxmac.ctrl.value);
352         pf_ctrl.value = readl(&adapter->regs->rxmac.pf_ctrl.value);
353
354         /* Default to disabled packet filtering.  Enable it in the individual
355          * case statements that require the device to filter something
356          */
357         ctrl.bits.pkt_filter_disable = 1;
358
359         /* Set us to be in promiscuous mode so we receive everything, this
360          * is also true when we get a packet filter of 0
361          */
362         if ((filter & ET131X_PACKET_TYPE_PROMISCUOUS) || filter == 0) {
363                 pf_ctrl.bits.filter_broad_en = 0;
364                 pf_ctrl.bits.filter_multi_en = 0;
365                 pf_ctrl.bits.filter_uni_en = 0;
366         } else {
367                 /*
368                  * Set us up with Multicast packet filtering.  Three cases are
369                  * possible - (1) we have a multi-cast list, (2) we receive ALL
370                  * multicast entries or (3) we receive none.
371                  */
372                 if (filter & ET131X_PACKET_TYPE_ALL_MULTICAST) {
373                         pf_ctrl.bits.filter_multi_en = 0;
374                 } else {
375                         SetupDeviceForMulticast(adapter);
376                         pf_ctrl.bits.filter_multi_en = 1;
377                         ctrl.bits.pkt_filter_disable = 0;
378                 }
379
380                 /* Set us up with Unicast packet filtering */
381                 if (filter & ET131X_PACKET_TYPE_DIRECTED) {
382                         SetupDeviceForUnicast(adapter);
383                         pf_ctrl.bits.filter_uni_en = 1;
384                         ctrl.bits.pkt_filter_disable = 0;
385                 }
386
387                 /* Set us up with Broadcast packet filtering */
388                 if (filter & ET131X_PACKET_TYPE_BROADCAST) {
389                         pf_ctrl.bits.filter_broad_en = 1;
390                         ctrl.bits.pkt_filter_disable = 0;
391                 } else {
392                         pf_ctrl.bits.filter_broad_en = 0;
393                 }
394
395                 /* Setup the receive mac configuration registers - Packet
396                  * Filter control + the enable / disable for packet filter
397                  * in the control reg.
398                  */
399                 writel(pf_ctrl.value,
400                        &adapter->regs->rxmac.pf_ctrl.value);
401                 writel(ctrl.value, &adapter->regs->rxmac.ctrl.value);
402         }
403         return status;
404 }
405
406 /**
407  * et131x_multicast - The handler to configure multicasting on the interface
408  * @netdev: a pointer to a net_device struct representing the device
409  */
410 void et131x_multicast(struct net_device *netdev)
411 {
412         struct et131x_adapter *adapter = netdev_priv(netdev);
413         uint32_t PacketFilter = 0;
414         uint32_t count;
415         unsigned long flags;
416         struct dev_mc_list *mclist = netdev->mc_list;
417
418         spin_lock_irqsave(&adapter->Lock, flags);
419
420         /* Before we modify the platform-independent filter flags, store them
421          * locally. This allows us to determine if anything's changed and if
422          * we even need to bother the hardware
423          */
424         PacketFilter = adapter->PacketFilter;
425
426         /* Clear the 'multicast' flag locally; becuase we only have a single
427          * flag to check multicast, and multiple multicast addresses can be
428          * set, this is the easiest way to determine if more than one
429          * multicast address is being set.
430          */
431         PacketFilter &= ~ET131X_PACKET_TYPE_MULTICAST;
432
433         /* Check the net_device flags and set the device independent flags
434          * accordingly
435          */
436
437         if (netdev->flags & IFF_PROMISC) {
438                 adapter->PacketFilter |= ET131X_PACKET_TYPE_PROMISCUOUS;
439         } else {
440                 adapter->PacketFilter &= ~ET131X_PACKET_TYPE_PROMISCUOUS;
441         }
442
443         if (netdev->flags & IFF_ALLMULTI) {
444                 adapter->PacketFilter |= ET131X_PACKET_TYPE_ALL_MULTICAST;
445         }
446
447         if (netdev->mc_count > NIC_MAX_MCAST_LIST) {
448                 adapter->PacketFilter |= ET131X_PACKET_TYPE_ALL_MULTICAST;
449         }
450
451         if (netdev->mc_count < 1) {
452                 adapter->PacketFilter &= ~ET131X_PACKET_TYPE_ALL_MULTICAST;
453                 adapter->PacketFilter &= ~ET131X_PACKET_TYPE_MULTICAST;
454         } else {
455                 adapter->PacketFilter |= ET131X_PACKET_TYPE_MULTICAST;
456         }
457
458         /* Set values in the private adapter struct */
459         adapter->MCAddressCount = netdev->mc_count;
460
461         if (netdev->mc_count) {
462                 count = netdev->mc_count - 1;
463                 memcpy(adapter->MCList[count], mclist->dmi_addr, ETH_ALEN);
464         }
465
466         /* Are the new flags different from the previous ones? If not, then no
467          * action is required
468          *
469          * NOTE - This block will always update the MCList with the hardware,
470          *        even if the addresses aren't the same.
471          */
472         if (PacketFilter != adapter->PacketFilter) {
473                 /* Call the device's filter function */
474                 et131x_set_packet_filter(adapter);
475         }
476         spin_unlock_irqrestore(&adapter->Lock, flags);
477 }
478
479 /**
480  * et131x_tx - The handler to tx a packet on the device
481  * @skb: data to be Tx'd
482  * @netdev: device on which data is to be Tx'd
483  *
484  * Returns 0 on success, errno on failure (as defined in errno.h)
485  */
486 int et131x_tx(struct sk_buff *skb, struct net_device *netdev)
487 {
488         int status = 0;
489
490         /* Save the timestamp for the TX timeout watchdog */
491         netdev->trans_start = jiffies;
492
493         /* Call the device-specific data Tx routine */
494         status = et131x_send_packets(skb, netdev);
495
496         /* Check status and manage the netif queue if necessary */
497         if (status != 0) {
498                 if (status == -ENOMEM) {
499                         /* Put the queue to sleep until resources are
500                          * available
501                          */
502                         netif_stop_queue(netdev);
503                         status = NETDEV_TX_BUSY;
504                 } else {
505                         status = NETDEV_TX_OK;
506                 }
507         }
508         return status;
509 }
510
511 /**
512  * et131x_tx_timeout - Timeout handler
513  * @netdev: a pointer to a net_device struct representing the device
514  *
515  * The handler called when a Tx request times out. The timeout period is
516  * specified by the 'tx_timeo" element in the net_device structure (see
517  * et131x_alloc_device() to see how this value is set).
518  */
519 void et131x_tx_timeout(struct net_device *netdev)
520 {
521         struct et131x_adapter *etdev = netdev_priv(netdev);
522         PMP_TCB pMpTcb;
523         unsigned long flags;
524
525         /* Just skip this part if the adapter is doing link detection */
526         if (etdev->Flags & fMP_ADAPTER_LINK_DETECTION)
527                 return;
528
529         /* Any nonrecoverable hardware error?
530          * Checks adapter->flags for any failure in phy reading
531          */
532         if (etdev->Flags & fMP_ADAPTER_NON_RECOVER_ERROR)
533                 return;
534
535         /* Hardware failure? */
536         if (etdev->Flags & fMP_ADAPTER_HARDWARE_ERROR) {
537                 dev_err(&etdev->pdev->dev, "hardware error - reset\n");
538                 return;
539         }
540
541         /* Is send stuck? */
542         spin_lock_irqsave(&etdev->TCBSendQLock, flags);
543
544         pMpTcb = etdev->TxRing.CurrSendHead;
545
546         if (pMpTcb != NULL) {
547                 pMpTcb->Count++;
548
549                 if (pMpTcb->Count > NIC_SEND_HANG_THRESHOLD) {
550                         TX_DESC_ENTRY_t StuckDescriptors[10];
551
552                         if (INDEX10(pMpTcb->WrIndex) > 7) {
553                                 memcpy(StuckDescriptors,
554                                        etdev->TxRing.pTxDescRingVa +
555                                        INDEX10(pMpTcb->WrIndex) - 6,
556                                        sizeof(TX_DESC_ENTRY_t) * 10);
557                         }
558
559                         spin_unlock_irqrestore(&etdev->TCBSendQLock,
560                                                flags);
561
562                         dev_warn(&etdev->pdev->dev,
563                                 "Send stuck - reset.  pMpTcb->WrIndex %x, Flags 0x%08x\n",
564                                 pMpTcb->WrIndex,
565                                 pMpTcb->Flags);
566
567                         et131x_close(netdev);
568                         et131x_open(netdev);
569
570                         return;
571                 }
572         }
573
574         spin_unlock_irqrestore(&etdev->TCBSendQLock, flags);
575 }
576
577 /**
578  * et131x_change_mtu - The handler called to change the MTU for the device
579  * @netdev: device whose MTU is to be changed
580  * @new_mtu: the desired MTU
581  *
582  * Returns 0 on success, errno on failure (as defined in errno.h)
583  */
584 int et131x_change_mtu(struct net_device *netdev, int new_mtu)
585 {
586         int result = 0;
587         struct et131x_adapter *adapter = netdev_priv(netdev);
588
589         /* Make sure the requested MTU is valid */
590         if (new_mtu < 64 || new_mtu > 9216)
591                 return -EINVAL;
592
593         /* Stop the netif queue */
594         netif_stop_queue(netdev);
595
596         /* Stop the Tx and Rx DMA engines */
597         et131x_rx_dma_disable(adapter);
598         et131x_tx_dma_disable(adapter);
599
600         /* Disable device interrupts */
601         et131x_disable_interrupts(adapter);
602         et131x_handle_send_interrupt(adapter);
603         et131x_handle_recv_interrupt(adapter);
604
605         /* Set the new MTU */
606         netdev->mtu = new_mtu;
607
608         /* Free Rx DMA memory */
609         et131x_adapter_memory_free(adapter);
610
611         /* Set the config parameter for Jumbo Packet support */
612         adapter->RegistryJumboPacket = new_mtu + 14;
613         et131x_soft_reset(adapter);
614
615         /* Alloc and init Rx DMA memory */
616         result = et131x_adapter_memory_alloc(adapter);
617         if (result != 0) {
618                 dev_warn(&adapter->pdev->dev,
619                         "Change MTU failed; couldn't re-alloc DMA memory\n");
620                 return result;
621         }
622
623         et131x_init_send(adapter);
624
625         et131x_setup_hardware_properties(adapter);
626         memcpy(netdev->dev_addr, adapter->CurrentAddress, ETH_ALEN);
627
628         /* Init the device with the new settings */
629         et131x_adapter_setup(adapter);
630
631         /* Enable interrupts */
632         if (adapter->Flags & fMP_ADAPTER_INTERRUPT_IN_USE)
633                 et131x_enable_interrupts(adapter);
634
635         /* Restart the Tx and Rx DMA engines */
636         et131x_rx_dma_enable(adapter);
637         et131x_tx_dma_enable(adapter);
638
639         /* Restart the netif queue */
640         netif_wake_queue(netdev);
641         return result;
642 }
643
644 /**
645  * et131x_set_mac_addr - handler to change the MAC address for the device
646  * @netdev: device whose MAC is to be changed
647  * @new_mac: the desired MAC address
648  *
649  * Returns 0 on success, errno on failure (as defined in errno.h)
650  *
651  * IMPLEMENTED BY : blux http://berndlux.de 22.01.2007 21:14
652  */
653 int et131x_set_mac_addr(struct net_device *netdev, void *new_mac)
654 {
655         int result = 0;
656         struct et131x_adapter *adapter = netdev_priv(netdev);
657         struct sockaddr *address = new_mac;
658
659         /* begin blux */
660
661         if (adapter == NULL)
662                 return -ENODEV;
663
664         /* Make sure the requested MAC is valid */
665         if (!is_valid_ether_addr(address->sa_data))
666                 return -EINVAL;
667
668         /* Stop the netif queue */
669         netif_stop_queue(netdev);
670
671         /* Stop the Tx and Rx DMA engines */
672         et131x_rx_dma_disable(adapter);
673         et131x_tx_dma_disable(adapter);
674
675         /* Disable device interrupts */
676         et131x_disable_interrupts(adapter);
677         et131x_handle_send_interrupt(adapter);
678         et131x_handle_recv_interrupt(adapter);
679
680         /* Set the new MAC */
681         /* netdev->set_mac_address  = &new_mac; */
682         /* netdev->mtu = new_mtu; */
683
684         memcpy(netdev->dev_addr, address->sa_data, netdev->addr_len);
685
686         printk(KERN_INFO
687                 "%s: Setting MAC address to %02x:%02x:%02x:%02x:%02x:%02x\n",
688                         netdev->name,
689                         netdev->dev_addr[0], netdev->dev_addr[1],
690                         netdev->dev_addr[2], netdev->dev_addr[3],
691                         netdev->dev_addr[4], netdev->dev_addr[5]);
692
693         /* Free Rx DMA memory */
694         et131x_adapter_memory_free(adapter);
695
696         /* Set the config parameter for Jumbo Packet support */
697         /* adapter->RegistryJumboPacket = new_mtu + 14; */
698         /* blux: not needet here, we'll change the MAC */
699
700         et131x_soft_reset(adapter);
701
702         /* Alloc and init Rx DMA memory */
703         result = et131x_adapter_memory_alloc(adapter);
704         if (result != 0) {
705                 dev_err(&adapter->pdev->dev,
706                         "Change MAC failed; couldn't re-alloc DMA memory\n");
707                 return result;
708         }
709
710         et131x_init_send(adapter);
711
712         et131x_setup_hardware_properties(adapter);
713         /* memcpy( netdev->dev_addr, adapter->CurrentAddress, ETH_ALEN ); */
714         /* blux: no, do not override our nice address */
715
716         /* Init the device with the new settings */
717         et131x_adapter_setup(adapter);
718
719         /* Enable interrupts */
720         if (adapter->Flags & fMP_ADAPTER_INTERRUPT_IN_USE)
721                 et131x_enable_interrupts(adapter);
722
723         /* Restart the Tx and Rx DMA engines */
724         et131x_rx_dma_enable(adapter);
725         et131x_tx_dma_enable(adapter);
726
727         /* Restart the netif queue */
728         netif_wake_queue(netdev);
729         return result;
730 }