Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / ieee1394 / eth1394.c
index d99ac5d..30fa0d4 100644 (file)
@@ -88,9 +88,6 @@
        printk(KERN_ERR "%s:%s[%d]: " fmt "\n", driver_name, __FUNCTION__, __LINE__, ## args)
 #define TRACE() printk(KERN_ERR "%s:%s[%d] ---- TRACE\n", driver_name, __FUNCTION__, __LINE__)
 
-static char version[] __devinitdata =
-       "$Rev: 1198 $ Ben Collins <bcollins@debian.org>";
-
 struct fragment_info {
        struct list_head list;
        int offset;
@@ -132,7 +129,7 @@ struct eth1394_node_info {
 };
 
 /* Our ieee1394 highlevel driver */
-#define ETH1394_DRIVER_NAME "ip1394"
+#define ETH1394_DRIVER_NAME "eth1394"
 static const char driver_name[] = ETH1394_DRIVER_NAME;
 
 static kmem_cache_t *packet_task_cache;
@@ -165,14 +162,13 @@ MODULE_LICENSE("GPL");
 /* The max_partial_datagrams parameter is the maximum number of fragmented
  * datagrams per node that eth1394 will keep in memory.  Providing an upper
  * bound allows us to limit the amount of memory that partial datagrams
- * consume in the event that some partial datagrams are never completed.  This
- * should probably change to a sysctl item or the like if possible.
+ * consume in the event that some partial datagrams are never completed.
  */
-MODULE_PARM(max_partial_datagrams, "i");
+static int max_partial_datagrams = 25;
+module_param(max_partial_datagrams, int, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(max_partial_datagrams,
                 "Maximum number of partially received fragmented datagrams "
                 "(default = 25).");
-static int max_partial_datagrams = 25;
 
 
 static int ether1394_header(struct sk_buff *skb, struct net_device *dev,
@@ -186,12 +182,11 @@ static void ether1394_header_cache_update(struct hh_cache *hh,
                                          unsigned char * haddr);
 static int ether1394_mac_addr(struct net_device *dev, void *p);
 
-static inline void purge_partial_datagram(struct list_head *old);
+static void purge_partial_datagram(struct list_head *old);
 static int ether1394_tx(struct sk_buff *skb, struct net_device *dev);
 static void ether1394_iso(struct hpsb_iso *iso);
 
-static int ether1394_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
-static int ether1394_ethtool_ioctl(struct net_device *dev, void *useraddr);
+static struct ethtool_ops ethtool_ops;
 
 static int ether1394_write(struct hpsb_host *host, int srcid, int destid,
                           quadlet_t *data, u64 addr, size_t len, u16 flags);
@@ -216,16 +211,14 @@ static struct hpsb_highlevel eth1394_highlevel = {
 /* This is called after an "ifup" */
 static int ether1394_open (struct net_device *dev)
 {
-       struct eth1394_priv *priv = dev->priv;
+       struct eth1394_priv *priv = netdev_priv(dev);
        int ret = 0;
 
        /* Something bad happened, don't even try */
        if (priv->bc_state == ETHER1394_BC_ERROR) {
                /* we'll try again */
                priv->iso = hpsb_iso_recv_init(priv->host,
-                                              ETHER1394_GASP_BUFFERS * 2 *
-                                              (1 << (priv->host->csr.max_rec +
-                                                     1)),
+                                              ETHER1394_ISO_BUF_SIZE,
                                               ETHER1394_GASP_BUFFERS,
                                               priv->broadcast_channel,
                                               HPSB_ISO_DMA_PACKET_PER_BUFFER,
@@ -261,7 +254,7 @@ static int ether1394_stop (struct net_device *dev)
 /* Return statistics to the caller */
 static struct net_device_stats *ether1394_stats (struct net_device *dev)
 {
-       return &(((struct eth1394_priv *)dev->priv)->stats);
+       return &(((struct eth1394_priv *)netdev_priv(dev))->stats);
 }
 
 /* What to do if we timeout. I think a host reset is probably in order, so
@@ -269,16 +262,16 @@ static struct net_device_stats *ether1394_stats (struct net_device *dev)
 static void ether1394_tx_timeout (struct net_device *dev)
 {
        ETH1394_PRINT (KERN_ERR, dev->name, "Timeout, resetting host %s\n",
-                      ((struct eth1394_priv *)(dev->priv))->host->driver->name);
+                      ((struct eth1394_priv *)netdev_priv(dev))->host->driver->name);
 
-       highlevel_host_reset (((struct eth1394_priv *)(dev->priv))->host);
+       highlevel_host_reset (((struct eth1394_priv *)netdev_priv(dev))->host);
 
        netif_wake_queue (dev);
 }
 
 static int ether1394_change_mtu(struct net_device *dev, int new_mtu)
 {
-       struct eth1394_priv *priv = dev->priv;
+       struct eth1394_priv *priv = netdev_priv(dev);
 
        if ((new_mtu < 68) ||
            (new_mtu > min(ETH1394_DATA_LEN,
@@ -290,6 +283,20 @@ static int ether1394_change_mtu(struct net_device *dev, int new_mtu)
        return 0;
 }
 
+static void purge_partial_datagram(struct list_head *old)
+{
+       struct partial_datagram *pd = list_entry(old, struct partial_datagram, list);
+       struct list_head *lh, *n;
+
+       list_for_each_safe(lh, n, &pd->frag_info) {
+               struct fragment_info *fi = list_entry(lh, struct fragment_info, list);
+               list_del(lh);
+               kfree(fi);
+       }
+       list_del(old);
+       kfree_skb(pd->skb);
+       kfree(pd);
+}
 
 /******************************************
  * 1394 bus activity functions
@@ -345,12 +352,12 @@ static int eth1394_probe(struct device *dev)
        if (!hi)
                return -ENOENT;
 
-       new_node = kmalloc(sizeof(struct eth1394_node_ref),
+       new_node = kmalloc(sizeof(*new_node),
                           in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
        if (!new_node)
                return -ENOMEM;
 
-       node_info = kmalloc(sizeof(struct eth1394_node_info),
+       node_info = kmalloc(sizeof(*node_info),
                            in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
        if (!node_info) {
                kfree(new_node);
@@ -365,7 +372,7 @@ static int eth1394_probe(struct device *dev)
        ud->device.driver_data = node_info;
        new_node->ud = ud;
 
-       priv = (struct eth1394_priv *)hi->dev->priv;
+       priv = netdev_priv(hi->dev);
        list_add_tail(&new_node->list, &priv->ip_node_list);
 
        return 0;
@@ -386,7 +393,7 @@ static int eth1394_remove(struct device *dev)
        if (!hi)
                return -ENOENT;
 
-       priv = (struct eth1394_priv *)hi->dev->priv;
+       priv = netdev_priv(hi->dev);
 
        old_node = eth1394_find_node(&priv->ip_node_list, ud);
 
@@ -421,19 +428,22 @@ static int eth1394_update(struct unit_directory *ud)
        if (!hi)
                return -ENOENT;
 
-       priv = (struct eth1394_priv *)hi->dev->priv;
+       priv = netdev_priv(hi->dev);
 
        node = eth1394_find_node(&priv->ip_node_list, ud);
 
        if (!node) {
-               node = kmalloc(sizeof(struct eth1394_node_ref),
+               node = kmalloc(sizeof(*node),
                               in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
                if (!node)
                        return -ENOMEM;
 
-
-               node_info = kmalloc(sizeof(struct eth1394_node_info),
+               node_info = kmalloc(sizeof(*node_info),
                                    in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
+               if (!node_info) {
+                       kfree(node);
+                       return -ENOMEM;
+               }
 
                spin_lock_init(&node_info->pdg.lock);
                INIT_LIST_HEAD(&node_info->pdg.list);
@@ -442,7 +452,7 @@ static int eth1394_update(struct unit_directory *ud)
                ud->device.driver_data = node_info;
                node->ud = ud;
 
-               priv = (struct eth1394_priv *)hi->dev->priv;
+               priv = netdev_priv(hi->dev);
                list_add_tail(&node->list, &priv->ip_node_list);
        }
 
@@ -479,7 +489,7 @@ static void ether1394_reset_priv (struct net_device *dev, int set_mtu)
 {
        unsigned long flags;
        int i;
-       struct eth1394_priv *priv = dev->priv;
+       struct eth1394_priv *priv = netdev_priv(dev);
        struct hpsb_host *host = priv->host;
        u64 guid = *((u64*)&(host->csr.rom->bus_info_data[3]));
        u16 maxpayload = 1 << (host->csr.max_rec + 1);
@@ -530,7 +540,7 @@ static void ether1394_init_dev (struct net_device *dev)
        dev->header_cache_update= ether1394_header_cache_update;
        dev->hard_header_parse  = ether1394_header_parse;
        dev->set_mac_address    = ether1394_mac_addr;
-       dev->do_ioctl           = ether1394_do_ioctl;
+       SET_ETHTOOL_OPS(dev, &ethtool_ops);
 
        /* Some constants */
        dev->watchdog_timeo     = ETHER1394_TIMEOUT;
@@ -553,7 +563,6 @@ static void ether1394_add_host (struct hpsb_host *host)
        struct eth1394_host_info *hi = NULL;
        struct net_device *dev = NULL;
        struct eth1394_priv *priv;
-       static int version_printed = 0;
        u64 fifo_addr;
 
        if (!(host->config_roms & HPSB_CONFIG_ROM_ENTRY_IP1394))
@@ -568,9 +577,6 @@ static void ether1394_add_host (struct hpsb_host *host)
        if (fifo_addr == ~0ULL)
                goto out;
 
-       if (version_printed++ == 0)
-               ETH1394_PRINT_G (KERN_INFO, "%s\n", version);
-
        /* We should really have our own alloc_hpsbdev() function in
         * net_init.c instead of calling the one for ethernet then hijacking
         * it for ourselves.  That way we'd be a real networking device. */
@@ -584,8 +590,9 @@ static void ether1394_add_host (struct hpsb_host *host)
         }
 
        SET_MODULE_OWNER(dev);
+       SET_NETDEV_DEV(dev, &host->device);
 
-       priv = (struct eth1394_priv *)dev->priv;
+       priv = netdev_priv(dev);
 
        INIT_LIST_HEAD(&priv->ip_node_list);
 
@@ -609,7 +616,7 @@ static void ether1394_add_host (struct hpsb_host *host)
                goto out;
        }
 
-       ETH1394_PRINT (KERN_ERR, dev->name, "IEEE-1394 IPv4 over 1394 Ethernet (fw-host%d)\n",
+       ETH1394_PRINT (KERN_INFO, dev->name, "IEEE-1394 IPv4 over 1394 Ethernet (fw-host%d)\n",
                       host->id);
 
        hi->host = host;
@@ -619,8 +626,8 @@ static void ether1394_add_host (struct hpsb_host *host)
         * be checked when the eth device is opened. */
        priv->broadcast_channel = host->csr.broadcast_channel & 0x3f;
 
-       priv->iso = hpsb_iso_recv_init(host, (ETHER1394_GASP_BUFFERS * 2 *
-                                             (1 << (host->csr.max_rec + 1))),
+       priv->iso = hpsb_iso_recv_init(host,
+                                      ETHER1394_ISO_BUF_SIZE,
                                       ETHER1394_GASP_BUFFERS,
                                       priv->broadcast_channel,
                                       HPSB_ISO_DMA_PACKET_PER_BUFFER,
@@ -655,7 +662,7 @@ static void ether1394_remove_host (struct hpsb_host *host)
 
        hi = hpsb_get_hostinfo(&eth1394_highlevel, host);
        if (hi != NULL) {
-               struct eth1394_priv *priv = (struct eth1394_priv *)hi->dev->priv;
+               struct eth1394_priv *priv = netdev_priv(hi->dev);
 
                hpsb_unregister_addrspace(&eth1394_highlevel, host,
                                          priv->local_fifo);
@@ -690,7 +697,7 @@ static void ether1394_host_reset (struct hpsb_host *host)
                return;
 
        dev = hi->dev;
-       priv = (struct eth1394_priv *)dev->priv;
+       priv = (struct eth1394_priv *)netdev_priv(dev);
 
        /* Reset our private host data, but not our mtu */
        netif_stop_queue (dev);
@@ -833,7 +840,7 @@ static inline u16 ether1394_type_trans(struct sk_buff *skb,
 
        skb->mac.raw = skb->data;
        skb_pull (skb, ETH1394_HLEN);
-       eth = (struct eth1394hdr*)skb->mac.raw;
+       eth = eth1394_hdr(skb);
 
        if (*eth->h_dest & 1) {
                if (memcmp(eth->h_dest, dev->broadcast, dev->addr_len)==0)
@@ -865,7 +872,7 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb,
                                        nodeid_t srcid, nodeid_t destid,
                                        u16 ether_type)
 {
-       struct eth1394_priv *priv = dev->priv;
+       struct eth1394_priv *priv = netdev_priv(dev);
        u64 dest_hw;
        unsigned short ret = 0;
 
@@ -1007,7 +1014,7 @@ static inline int new_fragment(struct list_head *frag_info, int offset, int len)
                }
        }
 
-       new = kmalloc(sizeof(struct fragment_info), GFP_ATOMIC);
+       new = kmalloc(sizeof(*new), GFP_ATOMIC);
        if (!new)
                return -ENOMEM;
 
@@ -1026,7 +1033,7 @@ static inline int new_partial_datagram(struct net_device *dev,
 {
        struct partial_datagram *new;
 
-       new = kmalloc(sizeof(struct partial_datagram), GFP_ATOMIC);
+       new = kmalloc(sizeof(*new), GFP_ATOMIC);
        if (!new)
                return -ENOMEM;
 
@@ -1078,21 +1085,6 @@ static inline int update_partial_datagram(struct list_head *pdgl, struct list_he
        return 0;
 }
 
-static inline void purge_partial_datagram(struct list_head *old)
-{
-       struct partial_datagram *pd = list_entry(old, struct partial_datagram, list);
-       struct list_head *lh, *n;
-
-       list_for_each_safe(lh, n, &pd->frag_info) {
-               struct fragment_info *fi = list_entry(lh, struct fragment_info, list);
-               list_del(lh);
-               kfree(fi);
-       }
-       list_del(old);
-       kfree_skb(pd->skb);
-       kfree(pd);
-}
-
 static inline int is_datagram_complete(struct list_head *lh, int dg_size)
 {
        struct partial_datagram *pd = list_entry(lh, struct partial_datagram, list);
@@ -1110,7 +1102,7 @@ static int ether1394_data_handler(struct net_device *dev, int srcid, int destid,
 {
        struct sk_buff *skb;
        unsigned long flags;
-       struct eth1394_priv *priv = (struct eth1394_priv *)dev->priv;
+       struct eth1394_priv *priv = netdev_priv(dev);
        union eth1394_hdr *hdr = (union eth1394_hdr *)buf;
        u16 ether_type = 0;  /* initialized to clear warning */
        int hdr_len;
@@ -1185,7 +1177,7 @@ static int ether1394_data_handler(struct net_device *dev, int srcid, int destid,
                lh = find_partial_datagram(pdgl, dgl);
 
                if (lh == NULL) {
-                       if (pdg->sz == max_partial_datagrams) {
+                       while (pdg->sz >= max_partial_datagrams) {
                                /* remove the oldest */
                                purge_partial_datagram(pdgl->prev);
                                pdg->sz--;
@@ -1348,7 +1340,7 @@ static void ether1394_iso(struct hpsb_iso *iso)
                                ((be32_to_cpu(data[1]) & 0xff000000) >> 24));
                source_id = be32_to_cpu(data[0]) >> 16;
 
-               priv = (struct eth1394_priv *)dev->priv;
+               priv = netdev_priv(dev);
 
                if (info->channel != (iso->host->csr.broadcast_channel & 0x3f) ||
                   specifier_id != ETHER1394_GASP_SPECIFIER_ID) {
@@ -1382,7 +1374,7 @@ static void ether1394_iso(struct hpsb_iso *iso)
 static inline void ether1394_arp_to_1394arp(struct sk_buff *skb,
                                            struct net_device *dev)
 {
-       struct eth1394_priv *priv = (struct eth1394_priv *)(dev->priv);
+       struct eth1394_priv *priv = netdev_priv(dev);
 
        struct arphdr *arp = (struct arphdr *)skb->data;
        unsigned char *arp_ptr = (unsigned char *)(arp + 1);
@@ -1580,8 +1572,8 @@ static inline void ether1394_dg_complete(struct packet_task *ptask, int fail)
 {
        struct sk_buff *skb = ptask->skb;
        struct net_device *dev = skb->dev;
-       struct eth1394_priv *priv = dev->priv;
-        unsigned long flags;
+       struct eth1394_priv *priv = netdev_priv(dev);
+       unsigned long flags;
 
        /* Statistics */
        spin_lock_irqsave(&priv->lock, flags);
@@ -1631,9 +1623,9 @@ static void ether1394_complete_cb(void *__ptask)
 /* Transmit a packet (called by kernel) */
 static int ether1394_tx (struct sk_buff *skb, struct net_device *dev)
 {
-       int kmflags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
+       gfp_t kmflags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
        struct eth1394hdr *eth;
-       struct eth1394_priv *priv = dev->priv;
+       struct eth1394_priv *priv = netdev_priv(dev);
        int proto;
        unsigned long flags;
        nodeid_t dest_node;
@@ -1766,53 +1758,16 @@ fail:
        return 0;  /* returning non-zero causes serious problems */
 }
 
-static int ether1394_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
+static void ether1394_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
 {
-       switch(cmd) {
-               case SIOCETHTOOL:
-                       return ether1394_ethtool_ioctl(dev, (void *) ifr->ifr_data);
-
-               case SIOCGMIIPHY:               /* Get address of MII PHY in use. */
-               case SIOCGMIIREG:               /* Read MII PHY register. */
-               case SIOCSMIIREG:               /* Write MII PHY register. */
-               default:
-                       return -EOPNOTSUPP;
-       }
-
-       return 0;
-}
-
-static int ether1394_ethtool_ioctl(struct net_device *dev, void *useraddr)
-{
-       u32 ethcmd;
-
-       if (get_user(ethcmd, (u32 *)useraddr))
-               return -EFAULT;
-
-       switch (ethcmd) {
-               case ETHTOOL_GDRVINFO: {
-                       struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
-                       strcpy (info.driver, driver_name);
-                       strcpy (info.version, "$Rev: 1198 $");
-                       /* FIXME XXX provide sane businfo */
-                       strcpy (info.bus_info, "ieee1394");
-                       if (copy_to_user (useraddr, &info, sizeof (info)))
-                               return -EFAULT;
-                       break;
-               }
-               case ETHTOOL_GSET:
-               case ETHTOOL_SSET:
-               case ETHTOOL_NWAY_RST:
-               case ETHTOOL_GLINK:
-               case ETHTOOL_GMSGLVL:
-               case ETHTOOL_SMSGLVL:
-               default:
-                       return -EOPNOTSUPP;
-       }
-
-       return 0;
+       strcpy (info->driver, driver_name);
+       /* FIXME XXX provide sane businfo */
+       strcpy (info->bus_info, "ieee1394");
 }
 
+static struct ethtool_ops ethtool_ops = {
+       .get_drvinfo = ether1394_get_drvinfo
+};
 
 static int __init ether1394_init_module (void)
 {