]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/meth.c
dm9601: Return 0 from bind() on success
[linux-2.6-omap-h63xx.git] / drivers / net / meth.c
index e1d97cdf649eeb6a8d9ac4167dfb0bd4f7dda0da..92b403bf38b0f438598c71faa9622ef9ae4cbd06 100644 (file)
@@ -8,16 +8,16 @@
  *     as published by the Free Software Foundation; either version
  *     2 of the License, or (at your option) any later version.
  */
-#include <linux/module.h>
-#include <linux/init.h>
-
-#include <linux/sched.h>
-#include <linux/kernel.h> /* printk() */
 #include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
 #include <linux/slab.h>
-#include <linux/errno.h>  /* error codes */
-#include <linux/types.h>  /* size_t */
-#include <linux/interrupt.h> /* mark_bh */
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
 
 #include <linux/in.h>
 #include <linux/in6.h>
@@ -34,7 +34,6 @@
 
 #include <asm/io.h>
 #include <asm/scatterlist.h>
-#include <linux/dma-mapping.h>
 
 #include "meth.h"
 
@@ -52,8 +51,6 @@
 
 
 static const char *meth_str="SGI O2 Fast Ethernet";
-MODULE_AUTHOR("Ilya Volynets <ilya@theIlya.com>");
-MODULE_DESCRIPTION("SGI O2 Builtin Fast Ethernet driver");
 
 #define HAVE_TX_TIMEOUT
 /* The maximum time waited (in jiffies) before assuming a Tx failed. (400ms) */
@@ -171,7 +168,7 @@ static int mdio_probe(struct meth_private *priv)
 
 static void meth_check_link(struct net_device *dev)
 {
-       struct meth_private *priv = (struct meth_private *) dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
        unsigned long mii_advertising = mdio_read(priv, 4);
        unsigned long mii_partner = mdio_read(priv, 5);
        unsigned long negotiated = mii_advertising & mii_partner;
@@ -269,7 +266,7 @@ static void meth_free_rx_ring(struct meth_private *priv)
 
 int meth_reset(struct net_device *dev)
 {
-       struct meth_private *priv = (struct meth_private *) dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
 
        /* Reset card */
        mace->eth.mac_ctrl = SGI_MAC_RESET;
@@ -311,7 +308,7 @@ int meth_reset(struct net_device *dev)
  */
 static int meth_open(struct net_device *dev)
 {
-       struct meth_private *priv = dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
        int ret;
 
        priv->phy_addr = -1;    /* No PHY is known yet... */
@@ -355,7 +352,7 @@ out_free_tx_ring:
 
 static int meth_release(struct net_device *dev)
 {
-       struct meth_private *priv = dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
 
        DPRINTK("Stopping queue\n");
        netif_stop_queue(dev); /* can't transmit any more */
@@ -377,7 +374,7 @@ static void meth_rx(struct net_device* dev, unsigned long int_status)
 {
        struct sk_buff *skb;
        unsigned long status;
-       struct meth_private *priv = (struct meth_private *) dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
        unsigned long fifo_rptr = (int_status & METH_INT_RX_RPTR_MASK) >> 8;
 
        spin_lock(&priv->meth_lock);
@@ -422,7 +419,6 @@ static void meth_rx(struct net_device* dev, unsigned long int_status)
                                        /* Write metadata, and then pass to the receive level */
                                        skb_put(skb_c, len);
                                        priv->rx_skbs[priv->rx_write] = skb;
-                                       skb_c->dev = dev;
                                        skb_c->protocol = eth_type_trans(skb_c, dev);
                                        dev->last_rx = jiffies;
                                        priv->stats.rx_packets++;
@@ -467,14 +463,14 @@ static void meth_rx(struct net_device* dev, unsigned long int_status)
 
 static int meth_tx_full(struct net_device *dev)
 {
-       struct meth_private *priv = (struct meth_private *) dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
 
        return (priv->tx_count >= TX_RING_ENTRIES - 1);
 }
 
 static void meth_tx_cleanup(struct net_device* dev, unsigned long int_status)
 {
-       struct meth_private *priv = dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
        unsigned long status;
        struct sk_buff *skb;
        unsigned long rptr = (int_status&TX_INFO_RPTR) >> 16;
@@ -537,7 +533,7 @@ static void meth_tx_cleanup(struct net_device* dev, unsigned long int_status)
 
 static void meth_error(struct net_device* dev, unsigned status)
 {
-       struct meth_private *priv = (struct meth_private *) dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
 
        printk(KERN_WARNING "meth: error status: 0x%08x\n",status);
        /* check for errors too... */
@@ -571,7 +567,7 @@ static void meth_error(struct net_device* dev, unsigned status)
 static irqreturn_t meth_interrupt(int irq, void *dev_id)
 {
        struct net_device *dev = (struct net_device *)dev_id;
-       struct meth_private *priv = (struct meth_private *) dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
        unsigned long status;
 
        status = mace->eth.int_stat;
@@ -610,7 +606,7 @@ static void meth_tx_short_prepare(struct meth_private *priv,
 
        desc->header.raw = METH_TX_CMD_INT_EN | (len-1) | ((128-len) << 16);
        /* maybe I should set whole thing to 0 first... */
-       memcpy(desc->data.dt + (120 - len), skb->data, skb->len);
+       skb_copy_from_linear_data(skb, desc->data.dt + (120 - len), skb->len);
        if (skb->len < len)
                memset(desc->data.dt + 120 - len + skb->len, 0, len-skb->len);
 }
@@ -628,8 +624,8 @@ static void meth_tx_1page_prepare(struct meth_private *priv,
 
        /* unaligned part */
        if (unaligned_len) {
-               memcpy(desc->data.dt + (120 - unaligned_len),
-                      skb->data, unaligned_len);
+               skb_copy_from_linear_data(skb, desc->data.dt + (120 - unaligned_len),
+                             unaligned_len);
                desc->header.raw |= (128 - unaligned_len) << 16;
        }
 
@@ -654,8 +650,8 @@ static void meth_tx_2page_prepare(struct meth_private *priv,
        desc->header.raw = METH_TX_CMD_INT_EN | TX_CATBUF1 | TX_CATBUF2| (skb->len - 1);
        /* unaligned part */
        if (unaligned_len){
-               memcpy(desc->data.dt + (120 - unaligned_len),
-                      skb->data, unaligned_len);
+               skb_copy_from_linear_data(skb, desc->data.dt + (120 - unaligned_len),
+                             unaligned_len);
                desc->header.raw |= (128 - unaligned_len) << 16;
        }
 
@@ -696,7 +692,7 @@ static void meth_add_to_tx_ring(struct meth_private *priv, struct sk_buff *skb)
  */
 static int meth_tx(struct sk_buff *skb, struct net_device *dev)
 {
-       struct meth_private *priv = (struct meth_private *) dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
        unsigned long flags;
 
        spin_lock_irqsave(&priv->meth_lock, flags);
@@ -727,7 +723,7 @@ static int meth_tx(struct sk_buff *skb, struct net_device *dev)
  */
 static void meth_tx_timeout(struct net_device *dev)
 {
-       struct meth_private *priv = (struct meth_private *) dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
        unsigned long flags;
 
        printk(KERN_WARNING "%s: transmit timed out\n", dev->name);
@@ -779,22 +775,22 @@ static int meth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  */
 static struct net_device_stats *meth_stats(struct net_device *dev)
 {
-       struct meth_private *priv = (struct meth_private *) dev->priv;
+       struct meth_private *priv = netdev_priv(dev);
        return &priv->stats;
 }
 
 /*
  * The init function.
  */
-static struct net_device *meth_init(void)
+static int __init meth_probe(struct platform_device *pdev)
 {
        struct net_device *dev;
        struct meth_private *priv;
-       int ret;
+       int err;
 
        dev = alloc_etherdev(sizeof(struct meth_private));
        if (!dev)
-               return ERR_PTR(-ENOMEM);
+               return -ENOMEM;
 
        dev->open            = meth_open;
        dev->stop            = meth_release;
@@ -808,13 +804,14 @@ static struct net_device *meth_init(void)
        dev->irq             = MACE_ETHERNET_IRQ;
        dev->base_addr       = (unsigned long)&mace->eth;
 
-       priv = (struct meth_private *) dev->priv;
+       priv = netdev_priv(dev);
        spin_lock_init(&priv->meth_lock);
+       SET_NETDEV_DEV(dev, &pdev->dev);
 
-       ret = register_netdev(dev);
-       if (ret) {
+       err = register_netdev(dev);
+       if (err) {
                free_netdev(dev);
-               return ERR_PTR(ret);
+               return err;
        }
 
        printk(KERN_INFO "%s: SGI MACE Ethernet rev. %d\n",
@@ -822,21 +819,44 @@ static struct net_device *meth_init(void)
        return 0;
 }
 
-static struct net_device *meth_dev;
+static int __exit meth_remove(struct platform_device *pdev)
+{
+       struct net_device *dev = platform_get_drvdata(pdev);
+
+       unregister_netdev(dev);
+       free_netdev(dev);
+       platform_set_drvdata(pdev, NULL);
+
+       return 0;
+}
+
+static struct platform_driver meth_driver = {
+       .probe  = meth_probe,
+       .remove = __devexit_p(meth_remove),
+       .driver = {
+               .name   = "meth",
+       }
+};
 
 static int __init meth_init_module(void)
 {
-       meth_dev = meth_init();
-       if (IS_ERR(meth_dev))
-               return PTR_ERR(meth_dev);
-       return 0;
+       int err;
+
+       err = platform_driver_register(&meth_driver);
+       if (err)
+               printk(KERN_ERR "Driver registration failed\n");
+
+       return err;
 }
 
 static void __exit meth_exit_module(void)
 {
-       unregister_netdev(meth_dev);
-       free_netdev(meth_dev);
+       platform_driver_unregister(&meth_driver);
 }
 
 module_init(meth_init_module);
 module_exit(meth_exit_module);
+
+MODULE_AUTHOR("Ilya Volynets <ilya@theIlya.com>");
+MODULE_DESCRIPTION("SGI O2 Builtin Fast Ethernet driver");
+MODULE_LICENSE("GPL");