[PATCH] defxx: Big-endian hosts support
[safe/jmp/linux-2.6] / drivers / net / iseries_veth.c
index 2e54c85..2284e2c 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) 2001 Kyle A. Lucke (klucke@us.ibm.com), IBM Corp.
  * Substantially cleaned up by:
  * Copyright (C) 2003 David Gibson <dwg@au1.ibm.com>, IBM Corporation.
+ * Copyright (C) 2004-2005 Michael Ellerman, IBM Corporation.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -55,9 +56,7 @@
  * number of packets outstanding to a remote partition at a time.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
-#include <linux/version.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/ioport.h>
 #include <linux/delay.h>
 #include <linux/mm.h>
 #include <linux/ethtool.h>
-#include <asm/iSeries/mf.h>
-#include <asm/iSeries/iSeries_pci.h>
+#include <linux/if_ether.h>
+
+#include <asm/abs_addr.h>
+#include <asm/iseries/mf.h>
 #include <asm/uaccess.h>
 
-#include <asm/iSeries/HvLpConfig.h>
-#include <asm/iSeries/HvTypes.h>
-#include <asm/iSeries/HvLpEvent.h>
+#include <asm/iseries/hv_lp_config.h>
+#include <asm/iseries/hv_types.h>
+#include <asm/iseries/hv_lp_event.h>
 #include <asm/iommu.h>
 #include <asm/vio.h>
 
@@ -85,26 +86,26 @@ MODULE_AUTHOR("Kyle Lucke <klucke@us.ibm.com>");
 MODULE_DESCRIPTION("iSeries Virtual ethernet driver");
 MODULE_LICENSE("GPL");
 
-#define VethEventTypeCap       (0)
-#define VethEventTypeFrames    (1)
-#define VethEventTypeMonitor   (2)
-#define VethEventTypeFramesAck (3)
+#define VETH_EVENT_CAP (0)
+#define VETH_EVENT_FRAMES      (1)
+#define VETH_EVENT_MONITOR     (2)
+#define VETH_EVENT_FRAMES_ACK  (3)
 
 #define VETH_MAX_ACKS_PER_MSG  (20)
 #define VETH_MAX_FRAMES_PER_MSG        (6)
 
-struct VethFramesData {
+struct veth_frames_data {
        u32 addr[VETH_MAX_FRAMES_PER_MSG];
        u16 len[VETH_MAX_FRAMES_PER_MSG];
        u32 eofmask;
 };
 #define VETH_EOF_SHIFT         (32-VETH_MAX_FRAMES_PER_MSG)
 
-struct VethFramesAckData {
+struct veth_frames_ack_data {
        u16 token[VETH_MAX_ACKS_PER_MSG];
 };
 
-struct VethCapData {
+struct veth_cap_data {
        u8 caps_version;
        u8 rsvd1;
        u16 num_buffers;
@@ -115,16 +116,19 @@ struct VethCapData {
        u64 rsvd4[3];
 };
 
-struct VethLpEvent {
+struct veth_lpevent {
        struct HvLpEvent base_event;
        union {
-               struct VethCapData caps_data;
-               struct VethFramesData frames_data;
-               struct VethFramesAckData frames_ack_data;
+               struct veth_cap_data caps_data;
+               struct veth_frames_data frames_data;
+               struct veth_frames_ack_data frames_ack_data;
        } u;
 
 };
 
+#define DRV_NAME       "iseries_veth"
+#define DRV_VERSION    "2.0"
+
 #define VETH_NUMBUFFERS                (120)
 #define VETH_ACKTIMEOUT        (1000000) /* microseconds */
 #define VETH_MAX_MCAST         (12)
@@ -153,7 +157,7 @@ struct VethLpEvent {
 
 struct veth_msg {
        struct veth_msg *next;
-       struct VethFramesData data;
+       struct veth_frames_data data;
        int token;
        int in_use;
        struct sk_buff *skb;
@@ -165,7 +169,7 @@ struct veth_lpar_connection {
        struct work_struct statemachine_wq;
        struct veth_msg *msgs;
        int num_events;
-       struct VethCapData local_caps;
+       struct veth_cap_data local_caps;
 
        struct kobject kobject;
        struct timer_list ack_timer;
@@ -179,12 +183,12 @@ struct veth_lpar_connection {
        unsigned long state;
        HvLpInstanceId src_inst;
        HvLpInstanceId dst_inst;
-       struct VethLpEvent cap_event, cap_ack_event;
+       struct veth_lpevent cap_event, cap_ack_event;
        u16 pending_acks[VETH_MAX_ACKS_PER_MSG];
        u32 num_pending_acks;
 
        int num_ack_events;
-       struct VethCapData remote_caps;
+       struct veth_cap_data remote_caps;
        u32 ack_timeout;
 
        struct veth_msg *msg_stack_head;
@@ -217,7 +221,7 @@ static int veth_start_xmit(struct sk_buff *skb, struct net_device *dev);
 static void veth_recycle_msg(struct veth_lpar_connection *, struct veth_msg *);
 static void veth_wake_queues(struct veth_lpar_connection *cnx);
 static void veth_stop_queues(struct veth_lpar_connection *cnx);
-static void veth_receive(struct veth_lpar_connection *, struct VethLpEvent *);
+static void veth_receive(struct veth_lpar_connection *, struct veth_lpevent *);
 static void veth_release_connection(struct kobject *kobject);
 static void veth_timed_ack(unsigned long ptr);
 static void veth_timed_reset(unsigned long ptr);
@@ -227,14 +231,14 @@ static void veth_timed_reset(unsigned long ptr);
  */
 
 #define veth_info(fmt, args...) \
-       printk(KERN_INFO "iseries_veth: " fmt, ## args)
+       printk(KERN_INFO DRV_NAME ": " fmt, ## args)
 
 #define veth_error(fmt, args...) \
-       printk(KERN_ERR "iseries_veth: Error: " fmt, ## args)
+       printk(KERN_ERR DRV_NAME ": Error: " fmt, ## args)
 
 #ifdef DEBUG
 #define veth_debug(fmt, args...) \
-       printk(KERN_DEBUG "iseries_veth: " fmt, ## args)
+       printk(KERN_DEBUG DRV_NAME ": " fmt, ## args)
 #else
 #define veth_debug(fmt, args...) do {} while (0)
 #endif
@@ -308,7 +312,7 @@ static int veth_allocate_events(HvLpIndex rlp, int number)
        struct veth_allocation vc = { COMPLETION_INITIALIZER(vc.c), 0 };
 
        mf_allocate_lp_events(rlp, HvLpEvent_Type_VirtualLan,
-                           sizeof(struct VethLpEvent), number,
+                           sizeof(struct veth_lpevent), number,
                            &veth_complete_allocation, &vc);
        wait_for_completion(&vc.c);
 
@@ -456,7 +460,7 @@ static inline void veth_kick_statemachine(struct veth_lpar_connection *cnx)
 }
 
 static void veth_take_cap(struct veth_lpar_connection *cnx,
-                         struct VethLpEvent *event)
+                         struct veth_lpevent *event)
 {
        unsigned long flags;
 
@@ -481,7 +485,7 @@ static void veth_take_cap(struct veth_lpar_connection *cnx,
 }
 
 static void veth_take_cap_ack(struct veth_lpar_connection *cnx,
-                             struct VethLpEvent *event)
+                             struct veth_lpevent *event)
 {
        unsigned long flags;
 
@@ -499,7 +503,7 @@ static void veth_take_cap_ack(struct veth_lpar_connection *cnx,
 }
 
 static void veth_take_monitor_ack(struct veth_lpar_connection *cnx,
-                                 struct VethLpEvent *event)
+                                 struct veth_lpevent *event)
 {
        unsigned long flags;
 
@@ -516,7 +520,7 @@ static void veth_take_monitor_ack(struct veth_lpar_connection *cnx,
        spin_unlock_irqrestore(&cnx->lock, flags);
 }
 
-static void veth_handle_ack(struct VethLpEvent *event)
+static void veth_handle_ack(struct veth_lpevent *event)
 {
        HvLpIndex rlp = event->base_event.xTargetLp;
        struct veth_lpar_connection *cnx = veth_cnx[rlp];
@@ -524,10 +528,10 @@ static void veth_handle_ack(struct VethLpEvent *event)
        BUG_ON(! cnx);
 
        switch (event->base_event.xSubtype) {
-       case VethEventTypeCap:
+       case VETH_EVENT_CAP:
                veth_take_cap_ack(cnx, event);
                break;
-       case VethEventTypeMonitor:
+       case VETH_EVENT_MONITOR:
                veth_take_monitor_ack(cnx, event);
                break;
        default:
@@ -536,7 +540,7 @@ static void veth_handle_ack(struct VethLpEvent *event)
        };
 }
 
-static void veth_handle_int(struct VethLpEvent *event)
+static void veth_handle_int(struct veth_lpevent *event)
 {
        HvLpIndex rlp = event->base_event.xSourceLp;
        struct veth_lpar_connection *cnx = veth_cnx[rlp];
@@ -546,14 +550,14 @@ static void veth_handle_int(struct VethLpEvent *event)
        BUG_ON(! cnx);
 
        switch (event->base_event.xSubtype) {
-       case VethEventTypeCap:
+       case VETH_EVENT_CAP:
                veth_take_cap(cnx, event);
                break;
-       case VethEventTypeMonitor:
+       case VETH_EVENT_MONITOR:
                /* do nothing... this'll hang out here til we're dead,
                 * and the hypervisor will return it for us. */
                break;
-       case VethEventTypeFramesAck:
+       case VETH_EVENT_FRAMES_ACK:
                spin_lock_irqsave(&cnx->lock, flags);
 
                for (i = 0; i < VETH_MAX_ACKS_PER_MSG; ++i) {
@@ -573,7 +577,7 @@ static void veth_handle_int(struct VethLpEvent *event)
 
                spin_unlock_irqrestore(&cnx->lock, flags);
                break;
-       case VethEventTypeFrames:
+       case VETH_EVENT_FRAMES:
                veth_receive(cnx, event);
                break;
        default:
@@ -582,19 +586,19 @@ static void veth_handle_int(struct VethLpEvent *event)
        };
 }
 
-static void veth_handle_event(struct HvLpEvent *event, struct pt_regs *regs)
+static void veth_handle_event(struct HvLpEvent *event)
 {
-       struct VethLpEvent *veth_event = (struct VethLpEvent *)event;
+       struct veth_lpevent *veth_event = (struct veth_lpevent *)event;
 
-       if (event->xFlags.xFunction == HvLpEvent_Function_Ack)
+       if (hvlpevent_is_ack(event))
                veth_handle_ack(veth_event);
-       else if (event->xFlags.xFunction == HvLpEvent_Function_Int)
+       else
                veth_handle_int(veth_event);
 }
 
 static int veth_process_caps(struct veth_lpar_connection *cnx)
 {
-       struct VethCapData *remote_caps = &cnx->remote_caps;
+       struct veth_cap_data *remote_caps = &cnx->remote_caps;
        int num_acks_needed;
 
        /* Convert timer to jiffies */
@@ -710,7 +714,7 @@ static void veth_statemachine(void *p)
 
        if ( (cnx->state & VETH_STATE_OPEN)
             && !(cnx->state & VETH_STATE_SENTMON) ) {
-               rc = veth_signalevent(cnx, VethEventTypeMonitor,
+               rc = veth_signalevent(cnx, VETH_EVENT_MONITOR,
                                      HvLpEvent_AckInd_DoAck,
                                      HvLpEvent_AckType_DeferredAck,
                                      0, 0, 0, 0, 0, 0);
@@ -733,7 +737,7 @@ static void veth_statemachine(void *p)
             && !(cnx->state & VETH_STATE_SENTCAPS)) {
                u64 *rawcap = (u64 *)&cnx->local_caps;
 
-               rc = veth_signalevent(cnx, VethEventTypeCap,
+               rc = veth_signalevent(cnx, VETH_EVENT_CAP,
                                      HvLpEvent_AckInd_DoAck,
                                      HvLpEvent_AckType_ImmediateAck,
                                      0, rawcap[0], rawcap[1], rawcap[2],
@@ -755,7 +759,7 @@ static void veth_statemachine(void *p)
 
        if ((cnx->state & VETH_STATE_GOTCAPS)
            && !(cnx->state & VETH_STATE_SENTCAPACK)) {
-               struct VethCapData *remote_caps = &cnx->remote_caps;
+               struct veth_cap_data *remote_caps = &cnx->remote_caps;
 
                memcpy(remote_caps, &cnx->cap_event.u.caps_data,
                       sizeof(*remote_caps));
@@ -997,9 +1001,10 @@ static void veth_set_multicast_list(struct net_device *dev)
 
 static void veth_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
 {
-       strncpy(info->driver, "veth", sizeof(info->driver) - 1);
+       strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1);
        info->driver[sizeof(info->driver) - 1] = '\0';
-       strncpy(info->version, "1.0", sizeof(info->version) - 1);
+       strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1);
+       info->version[sizeof(info->version) - 1] = '\0';
 }
 
 static int veth_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
@@ -1024,17 +1029,28 @@ static u32 veth_get_link(struct net_device *dev)
        return 1;
 }
 
-static struct ethtool_ops ops = {
+static const struct ethtool_ops ops = {
        .get_drvinfo = veth_get_drvinfo,
        .get_settings = veth_get_settings,
        .get_link = veth_get_link,
 };
 
-static struct net_device * __init veth_probe_one(int vlan, struct device *vdev)
+static struct net_device * __init veth_probe_one(int vlan,
+               struct vio_dev *vio_dev)
 {
        struct net_device *dev;
        struct veth_port *port;
+       struct device *vdev = &vio_dev->dev;
        int i, rc;
+       const unsigned char *mac_addr;
+
+       mac_addr = vio_get_attribute(vio_dev, "local-mac-address", NULL);
+       if (mac_addr == NULL)
+               mac_addr = vio_get_attribute(vio_dev, "mac-address", NULL);
+       if (mac_addr == NULL) {
+               veth_error("Unable to fetch MAC address from device tree.\n");
+               return NULL;
+       }
 
        dev = alloc_etherdev(sizeof (struct veth_port));
        if (! dev) {
@@ -1059,16 +1075,11 @@ static struct net_device * __init veth_probe_one(int vlan, struct device *vdev)
        }
        port->dev = vdev;
 
-       dev->dev_addr[0] = 0x02;
-       dev->dev_addr[1] = 0x01;
-       dev->dev_addr[2] = 0xff;
-       dev->dev_addr[3] = vlan;
-       dev->dev_addr[4] = 0xff;
-       dev->dev_addr[5] = this_lp;
+       memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
 
        dev->mtu = VETH_MAX_MTU;
 
-       memcpy(&port->mac_addr, dev->dev_addr, 6);
+       memcpy(&port->mac_addr, mac_addr, ETH_ALEN);
 
        dev->open = veth_open;
        dev->hard_start_xmit = veth_start_xmit;
@@ -1142,7 +1153,7 @@ static int veth_transmit_to_one(struct sk_buff *skb, HvLpIndex rlp,
        msg->data.len[0] = skb->len;
        msg->data.eofmask = 1 << VETH_EOF_SHIFT;
 
-       rc = veth_signaldata(cnx, VethEventTypeFrames, msg->token, &msg->data);
+       rc = veth_signaldata(cnx, VETH_EVENT_FRAMES, msg->token, &msg->data);
 
        if (rc != HvLpEvent_Rc_Good)
                goto recycle_and_drop;
@@ -1392,13 +1403,13 @@ static inline void veth_build_dma_list(struct dma_chunk *list,
         * it just at the granularity of iSeries real->absolute
         * mapping?  Indeed, given the way the allocator works, can we
         * count on them being absolutely contiguous? */
-       list[0].addr = ISERIES_HV_ADDR(p);
+       list[0].addr = iseries_hv_addr(p);
        list[0].size = min(length,
                           PAGE_SIZE - ((unsigned long)p & ~PAGE_MASK));
 
        done = list[0].size;
        while (done < length) {
-               list[i].addr = ISERIES_HV_ADDR(p + done);
+               list[i].addr = iseries_hv_addr(p + done);
                list[i].size = min(length-done, PAGE_SIZE);
                done += list[i].size;
                i++;
@@ -1409,7 +1420,7 @@ static void veth_flush_acks(struct veth_lpar_connection *cnx)
 {
        HvLpEvent_Rc rc;
 
-       rc = veth_signaldata(cnx, VethEventTypeFramesAck,
+       rc = veth_signaldata(cnx, VETH_EVENT_FRAMES_ACK,
                             0, &cnx->pending_acks);
 
        if (rc != HvLpEvent_Rc_Good)
@@ -1421,9 +1432,9 @@ static void veth_flush_acks(struct veth_lpar_connection *cnx)
 }
 
 static void veth_receive(struct veth_lpar_connection *cnx,
-                        struct VethLpEvent *event)
+                        struct veth_lpevent *event)
 {
-       struct VethFramesData *senddata = &event->u.frames_data;
+       struct veth_frames_data *senddata = &event->u.frames_data;
        int startchunk = 0;
        int nchunks;
        unsigned long flags;
@@ -1491,8 +1502,8 @@ static void veth_receive(struct veth_lpar_connection *cnx,
                                            cnx->dst_inst,
                                            HvLpDma_AddressType_RealAddress,
                                            HvLpDma_AddressType_TceIndex,
-                                           ISERIES_HV_ADDR(&local_list),
-                                           ISERIES_HV_ADDR(&remote_list),
+                                           iseries_hv_addr(&local_list),
+                                           iseries_hv_addr(&remote_list),
                                            length);
                if (rc != HvLpDma_Rc_Good) {
                        dev_kfree_skb_irq(skb);
@@ -1603,7 +1614,7 @@ static int veth_probe(struct vio_dev *vdev, const struct vio_device_id *id)
        struct net_device *dev;
        struct veth_port *port;
 
-       dev = veth_probe_one(i, &vdev->dev);
+       dev = veth_probe_one(i, vdev);
        if (dev == NULL) {
                veth_remove(vdev);
                return 1;
@@ -1636,16 +1647,19 @@ static int veth_probe(struct vio_dev *vdev, const struct vio_device_id *id)
  * support.
  */
 static struct vio_device_id veth_device_table[] __devinitdata = {
-       { "vlan", "" },
+       { "network", "IBM,iSeries-l-lan" },
        { "", "" }
 };
 MODULE_DEVICE_TABLE(vio, veth_device_table);
 
 static struct vio_driver veth_driver = {
-       .name = "iseries_veth",
        .id_table = veth_device_table,
        .probe = veth_probe,
-       .remove = veth_remove
+       .remove = veth_remove,
+       .driver = {
+               .name = DRV_NAME,
+               .owner = THIS_MODULE,
+       }
 };
 
 /*