fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / ieee1394 / eth1394.c
index 9b01d57..97e5c3d 100644 (file)
 #include <linux/ethtool.h>
 #include <asm/uaccess.h>
 #include <asm/delay.h>
-#include <asm/semaphore.h>
+#include <asm/unaligned.h>
 #include <net/arp.h>
 
+#include "config_roms.h"
 #include "csr1212.h"
-#include "ieee1394_types.h"
+#include "eth1394.h"
+#include "highlevel.h"
+#include "ieee1394.h"
 #include "ieee1394_core.h"
+#include "ieee1394_hotplug.h"
 #include "ieee1394_transactions.h"
-#include "ieee1394.h"
-#include "highlevel.h"
+#include "ieee1394_types.h"
 #include "iso.h"
 #include "nodemgr.h"
-#include "eth1394.h"
-#include "config_roms.h"
 
 #define ETH1394_PRINT_G(level, fmt, args...) \
        printk(level "%s: " fmt, driver_name, ## args)
@@ -88,9 +89,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: 1224 $ Ben Collins <bcollins@debian.org>";
-
 struct fragment_info {
        struct list_head list;
        int offset;
@@ -135,7 +133,7 @@ struct eth1394_node_info {
 #define ETH1394_DRIVER_NAME "eth1394"
 static const char driver_name[] = ETH1394_DRIVER_NAME;
 
-static kmem_cache_t *packet_task_cache;
+static struct kmem_cache *packet_task_cache;
 
 static struct hpsb_highlevel eth1394_highlevel;
 
@@ -165,8 +163,7 @@ 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.
  */
 static int max_partial_datagrams = 25;
 module_param(max_partial_datagrams, int, S_IRUGO | S_IWUSR);
@@ -186,7 +183,7 @@ 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);
 
@@ -222,9 +219,7 @@ static int ether1394_open (struct net_device *dev)
        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,
@@ -289,7 +284,7 @@ static int ether1394_change_mtu(struct net_device *dev, int new_mtu)
        return 0;
 }
 
-static inline void purge_partial_datagram(struct list_head *old)
+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;
@@ -358,12 +353,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);
@@ -373,7 +368,7 @@ static int eth1394_probe(struct device *dev)
        spin_lock_init(&node_info->pdg.lock);
        INIT_LIST_HEAD(&node_info->pdg.list);
        node_info->pdg.sz = 0;
-       node_info->fifo = ETHER1394_INVALID_ADDR;
+       node_info->fifo = CSR1212_INVALID_ADDR_SPACE;
 
        ud->device.driver_data = node_info;
        new_node->ud = ud;
@@ -439,17 +434,17 @@ static int eth1394_update(struct unit_directory *ud)
        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);
@@ -479,12 +474,10 @@ static struct ieee1394_device_id eth1394_id_table[] = {
 MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table);
 
 static struct hpsb_protocol_driver eth1394_proto_driver = {
-       .name           = "IPv4 over 1394 Driver",
+       .name           = ETH1394_DRIVER_NAME,
        .id_table       = eth1394_id_table,
        .update         = eth1394_update,
        .driver         = {
-               .name           = ETH1394_DRIVER_NAME,
-               .bus            = &ieee1394_bus_type,
                .probe          = eth1394_probe,
                .remove         = eth1394_remove,
        },
@@ -497,7 +490,7 @@ static void ether1394_reset_priv (struct net_device *dev, int set_mtu)
        int i;
        struct eth1394_priv *priv = netdev_priv(dev);
        struct hpsb_host *host = priv->host;
-       u64 guid = *((u64*)&(host->csr.rom->bus_info_data[3]));
+       u64 guid = get_unaligned((u64*)&(host->csr.rom->bus_info_data[3]));
        u16 maxpayload = 1 << (host->csr.max_rec + 1);
        int max_speed = IEEE1394_SPEED_MAX;
 
@@ -508,10 +501,8 @@ static void ether1394_reset_priv (struct net_device *dev, int set_mtu)
 
        /* Determine speed limit */
        for (i = 0; i < host->node_count; i++)
-               if (max_speed > host->speed_map[NODEID_TO_NODE(host->node_id) *
-                                               64 + i])
-                       max_speed = host->speed_map[NODEID_TO_NODE(host->node_id) *
-                                                   64 + i];
+               if (max_speed > host->speed[i])
+                       max_speed = host->speed[i];
        priv->bc_sspd = max_speed;
 
        /* We'll use our maxpayload as the default mtu */
@@ -522,8 +513,8 @@ static void ether1394_reset_priv (struct net_device *dev, int set_mtu)
                                      ETHER1394_GASP_OVERHEAD)));
 
                /* Set our hardware address while we're at it */
-               *(u64*)dev->dev_addr = guid;
-               *(u64*)dev->broadcast = ~0x0ULL;
+               memcpy(dev->dev_addr, &guid, sizeof(u64));
+               memset(dev->broadcast, 0xff, sizeof(u64));
        }
 
        spin_unlock_irqrestore (&priv->lock, flags);
@@ -569,24 +560,18 @@ 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))
                return;
 
-       fifo_addr = hpsb_allocate_and_register_addrspace(&eth1394_highlevel,
-                                                        host,
-                                                        &addr_ops,
-                                                        ETHER1394_REGION_ADDR_LEN,
-                                                        ETHER1394_REGION_ADDR_LEN,
-                                                        -1, -1);
-       if (fifo_addr == ~0ULL)
+       fifo_addr = hpsb_allocate_and_register_addrspace(
+                       &eth1394_highlevel, host, &addr_ops,
+                       ETHER1394_REGION_ADDR_LEN, ETHER1394_REGION_ADDR_LEN,
+                       CSR1212_INVALID_ADDR_SPACE, CSR1212_INVALID_ADDR_SPACE);
+       if (fifo_addr == CSR1212_INVALID_ADDR_SPACE)
                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. */
@@ -626,7 +611,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;
@@ -636,8 +621,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,
@@ -707,7 +692,7 @@ static void ether1394_host_reset (struct hpsb_host *host)
                return;
 
        dev = hi->dev;
-       priv = netdev_priv(dev);
+       priv = (struct eth1394_priv *)netdev_priv(dev);
 
        /* Reset our private host data, but not our mtu */
        netif_stop_queue (dev);
@@ -784,7 +769,7 @@ static int ether1394_rebuild_header(struct sk_buff *skb)
        default:
                ETH1394_PRINT(KERN_DEBUG, dev->name,
                              "unable to resolve type %04x addresses.\n",
-                             eth->h_proto);
+                             ntohs(eth->h_proto));
                break;
        }
 
@@ -806,9 +791,8 @@ static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh)
                                                      (16 - ETH1394_HLEN));
        struct net_device *dev = neigh->dev;
 
-       if (type == __constant_htons(ETH_P_802_3)) {
+       if (type == htons(ETH_P_802_3))
                return -1;
-       }
 
        eth->h_proto = type;
        memcpy(eth->h_dest, neigh->ha, dev->addr_len);
@@ -897,7 +881,7 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb,
        /* If this is an ARP packet, convert it. First, we want to make
         * use of some of the fields, since they tell us a little bit
         * about the sending machine.  */
-       if (ether_type == __constant_htons (ETH_P_ARP)) {
+       if (ether_type == htons(ETH_P_ARP)) {
                struct eth1394_arp *arp1394 = (struct eth1394_arp*)skb->data;
                struct arphdr *arp = (struct arphdr *)skb->data;
                unsigned char *arp_ptr = (unsigned char *)(arp + 1);
@@ -909,6 +893,7 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb,
                u16 maxpayload;
                struct eth1394_node_ref *node;
                struct eth1394_node_info *node_info;
+               __be64 guid;
 
                /* Sanity check. MacOSX seems to be sending us 131 in this
                 * field (atleast on my Panther G5). Not sure why. */
@@ -917,8 +902,9 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb,
 
                maxpayload = min(eth1394_speedto_maxpayload[sspd], (u16)(1 << (max_rec + 1)));
 
+               guid = get_unaligned(&arp1394->s_uniq_id);
                node = eth1394_find_node_guid(&priv->ip_node_list,
-                                             be64_to_cpu(arp1394->s_uniq_id));
+                                             be64_to_cpu(guid));
                if (!node) {
                        return 0;
                }
@@ -945,16 +931,15 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb,
                *(u32*)arp_ptr = arp1394->sip;  /* move sender IP addr */
                arp_ptr += arp->ar_pln;         /* skip over sender IP addr */
 
-               if (arp->ar_op == 1)
-                       /* just set ARP req target unique ID to 0 */
-                       *((u64*)arp_ptr) = 0;
+               if (arp->ar_op == htons(ARPOP_REQUEST))
+                       memset(arp_ptr, 0, sizeof(u64));
                else
-                       *((u64*)arp_ptr) = *((u64*)dev->dev_addr);
+                       memcpy(arp_ptr, dev->dev_addr, sizeof(u64));
        }
 
        /* Now add the ethernet header. */
-       if (dev->hard_header (skb, dev, __constant_ntohs (ether_type),
-                             &dest_hw, NULL, skb->len) >= 0)
+       if (dev->hard_header(skb, dev, ntohs(ether_type), &dest_hw, NULL,
+                            skb->len) >= 0)
                ret = ether1394_type_trans(skb, dev);
 
        return ret;
@@ -1024,7 +1009,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;
 
@@ -1043,7 +1028,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;
 
@@ -1089,8 +1074,7 @@ static inline int update_partial_datagram(struct list_head *pdgl, struct list_he
 
        /* Move list entry to beginnig of list so that oldest partial
         * datagrams percolate to the end of the list */
-       list_del(lh);
-       list_add(lh, pdgl);
+       list_move(lh, pdgl);
 
        return 0;
 }
@@ -1187,7 +1171,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--;
@@ -1405,7 +1389,7 @@ static inline void ether1394_arp_to_1394arp(struct sk_buff *skb,
 /* We need to encapsulate the standard header with our own. We use the
  * ethernet header's proto for our own. */
 static inline unsigned int ether1394_encapsulate_prep(unsigned int max_payload,
-                                                     int proto,
+                                                     __be16 proto,
                                                      union eth1394_hdr *hdr,
                                                      u16 dg_size, u16 dgl)
 {
@@ -1524,8 +1508,8 @@ static inline void ether1394_prep_gasp_packet(struct hpsb_packet *p,
        p->data = ((quadlet_t*)skb->data) - 2;
        p->data[0] = cpu_to_be32((priv->host->node_id << 16) |
                                 ETHER1394_GASP_SPECIFIER_ID_HI);
-       p->data[1] = __constant_cpu_to_be32((ETHER1394_GASP_SPECIFIER_ID_LO << 24) |
-                                           ETHER1394_GASP_VERSION);
+       p->data[1] = cpu_to_be32((ETHER1394_GASP_SPECIFIER_ID_LO << 24) |
+                                ETHER1394_GASP_VERSION);
 
        /* Setting the node id to ALL_NODES (not LOCAL_BUS | ALL_NODES)
         * prevents hpsb_send_packet() from setting the speed to an arbitrary
@@ -1583,7 +1567,7 @@ 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 = netdev_priv(dev);
-        unsigned long flags;
+       unsigned long flags;
 
        /* Statistics */
        spin_lock_irqsave(&priv->lock, flags);
@@ -1633,10 +1617,10 @@ 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 = netdev_priv(dev);
-       int proto;
+       __be16 proto;
        unsigned long flags;
        nodeid_t dest_node;
        eth1394_tx_type tx_type;
@@ -1680,9 +1664,9 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev)
        /* Set the transmission type for the packet.  ARP packets and IP
         * broadcast packets are sent via GASP. */
        if (memcmp(eth->h_dest, dev->broadcast, ETH1394_ALEN) == 0 ||
-           proto == __constant_htons(ETH_P_ARP) ||
-           (proto == __constant_htons(ETH_P_IP) &&
-            IN_MULTICAST(__constant_ntohl(skb->nh.iph->daddr)))) {
+           proto == htons(ETH_P_ARP) ||
+           (proto == htons(ETH_P_IP) &&
+            IN_MULTICAST(ntohl(skb->nh.iph->daddr)))) {
                tx_type = ETH1394_GASP;
                dest_node = LOCAL_BUS | ALL_NODES;
                max_payload = priv->bc_maxpayload - ETHER1394_GASP_OVERHEAD;
@@ -1691,14 +1675,16 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev)
                if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF])
                        priv->bc_dgl++;
        } else {
+               __be64 guid = get_unaligned((u64 *)eth->h_dest);
+
                node = eth1394_find_node_guid(&priv->ip_node_list,
-                                             be64_to_cpu(*(u64*)eth->h_dest));
+                                             be64_to_cpu(guid));
                if (!node) {
                        ret = -EAGAIN;
                        goto fail;
                }
                node_info = (struct eth1394_node_info*)node->ud->device.driver_data;
-               if (node_info->fifo == ETHER1394_INVALID_ADDR) {
+               if (node_info->fifo == CSR1212_INVALID_ADDR_SPACE) {
                        ret = -EAGAIN;
                        goto fail;
                }
@@ -1714,7 +1700,7 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev)
        }
 
        /* If this is an ARP packet, convert it */
-       if (proto == __constant_htons (ETH_P_ARP))
+       if (proto == htons(ETH_P_ARP))
                ether1394_arp_to_1394arp (skb, dev);
 
        ptask->hdr.words.word1 = 0;
@@ -1771,7 +1757,6 @@ fail:
 static void ether1394_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
 {
        strcpy (info->driver, driver_name);
-       strcpy (info->version, "$Rev: 1224 $");
        /* FIXME XXX provide sane businfo */
        strcpy (info->bus_info, "ieee1394");
 }