patch-2.3.27 linux/drivers/i2o/i2o_lan.c

Next file: linux/drivers/i2o/i2o_lan.h
Previous file: linux/drivers/i2o/i2o_core.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.26/linux/drivers/i2o/i2o_lan.c linux/drivers/i2o/i2o_lan.c
@@ -1,7 +1,7 @@
 /*
  *	linux/drivers/i2o/i2o_lan.c
  *
- * 	I2O LAN CLASS OSM 	Prototyping, September 17th 1999
+ * 	I2O LAN CLASS OSM 	Prototyping, November 8th 1999
  *
  *	(C) Copyright 1999 	University of Helsinki,
  *				Department of Computer Science
@@ -11,7 +11,7 @@
  *	This program is free software; you can redistribute it and/or
  *	modify it under the terms of the GNU General Public License
  *	as published by the Free Software Foundation; either version
- *	2 of the License, or (at your option) any later version.    
+ *	2 of the License, or (at your option) any later version.
  *
  *	Authors: 	Auvo Häkkinen <Auvo.Hakkinen@cs.Helsinki.FI>
  *			Juha Sievänen <Juha.Sievanen@cs.Helsinki.FI>
@@ -20,9 +20,7 @@
  *	Tested:		in FDDI environment (using SysKonnect's DDM)
  *			in Ethernet environment (using Intel 82558 DDM proto)
  *
- *	TODO:		batch mode networking
- *			- we've not been able to test batch replies and 
- *			  batch receives
+ *	TODO:		batch mode sends
  *			error checking / timeouts
  *			code / test for other LAN classes
  */
@@ -39,6 +37,7 @@
 #include <linux/trdevice.h>
 #include <linux/init.h>
 #include <linux/spinlock.h>
+#include <linux/tqueue.h>
 #include <asm/io.h>
 
 #include <linux/errno.h>
@@ -46,68 +45,65 @@
 #include <linux/i2o.h>
 #include "i2o_lan.h"
 
-//#define DRIVERDEBUG
+#define DRIVERDEBUG
 #ifdef DRIVERDEBUG
 #define dprintk(s, args...) printk(s, ## args)
 #else
 #define dprintk(s, args...)
 #endif
 
-#define MAX_LAN_CARDS 4
+/* Module params */
+
+static u32 bucketpost   = I2O_BUCKET_COUNT;
+static u32 bucketthresh = I2O_BUCKET_THRESH;
+static u32 rx_copybreak = 200;
+
+#define MAX_LAN_CARDS 16
 static struct net_device *i2o_landevs[MAX_LAN_CARDS+1];
 static int unit = -1; 			/* device unit number */
 
 struct i2o_lan_local {
 	u8 unit;
 	struct i2o_device *i2o_dev;
-	int reply_flag; 		/* needed by scalar/table queries */
-	struct fddi_statistics stats;   /* see also struct net_device_stats */ 
+	struct fddi_statistics stats;   /* see also struct net_device_stats */
 	unsigned short (*type_trans)(struct sk_buff *, struct net_device *);
-	/* 
-	 * Due to way that interrupts can pile up, we need to keep track
- 	 * of buckets ourselves.  Otherwise we'll end up flooding
-	 * the DDM with buckets.
-	 */
-	u32	bucket_count;
-
-   /*
-    * Keep track of no. of outstanding TXes
-    */
-   u32   tx_count;
-   u32   max_tx;
-   u32   tx_full;
-
-   spinlock_t lock;
+	u32 bucket_count;  		/* nbr of buckets sent to DDM */
+	u32 tx_count; 	  		/* nbr of outstanding TXes */
+	u32 max_tx;	   		/* DDM's Tx queue len */
 
+	spinlock_t lock;
 };
 
-/* function prototypes */
+static void i2o_lan_reply(struct i2o_handler *h, struct i2o_controller *iop,
+                          struct i2o_message *m); 
+static void i2o_lan_event_reply(struct net_device *dev, u32 *msg); 
 static int i2o_lan_receive_post(struct net_device *dev, u32 count);
 static int i2o_lan_receive_post_reply(struct net_device *dev, u32 *msg);
 static void i2o_lan_release_buckets(struct net_device *dev, u32 *msg);
 
-/*
- * Module params
- */
-static u32 bucketpost = I2O_BUCKET_COUNT;
-static u32 bucketthresh = I2O_BUCKET_THRESH;
-static u32 rx_copybreak = 200;
+static struct i2o_handler i2o_lan_handler = {
+	i2o_lan_reply,
+	"I2O Lan OSM",
+	0,              // context
+	I2O_CLASS_LAN
+};
+static int lan_context;  
 
-static void i2o_lan_reply(struct i2o_handler *h, struct i2o_controller *iop, 
+
+static void i2o_lan_reply(struct i2o_handler *h, struct i2o_controller *iop,
 			  struct i2o_message *m)
-{  
+{
 	u32 *msg = (u32 *)m;
 	u8 unit  = (u8)(msg[2]>>16); // InitiatorContext
 	struct net_device *dev = i2o_landevs[unit];
 
-    	if (msg[0] & (1<<13)) // Fail bit is set
- 	{
- 		printk(KERN_ERR "IOP failed to process the msg:\n");
+    	if (msg[0] & (1<<13)) { // Fail bit is set
+ 		printk(KERN_ERR "%s: IOP failed to process the msg:\n",dev->name);
 		printk(KERN_ERR "  Cmd = 0x%02X, InitiatorTid = %d, TargetTid = %d\n",
 			(msg[1] >> 24) & 0xFF, (msg[1] >> 12) & 0xFFF, msg[1] & 0xFFF);
 		printk(KERN_ERR "  FailureCode = 0x%02X\n  Severity = 0x%02X\n  "
 			"LowestVersion = 0x%02X\n  HighestVersion = 0x%02X\n",
-			 msg[4] >> 24, (msg[4] >> 16) & 0xFF, 
+			 msg[4] >> 24, (msg[4] >> 16) & 0xFF,
 			(msg[4] >> 8) & 0xFF, msg[4] & 0xFF);
 		printk(KERN_ERR "  FailingHostUnit = 0x%04X\n  FailingIOP = 0x%03X\n",
 			msg[5] >> 16, msg[5] & 0xFFF);
@@ -115,23 +111,21 @@
 	}	
 
 #ifndef DRIVERDEBUG
-	if (msg[4] >> 24) 	/* ReqStatus != SUCCESS */
+	if (msg[4] >> 24)  	/* ReqStatus != SUCCESS */
 #endif
 		i2o_report_status(KERN_INFO, dev->name, msg);
-
+	
 	switch (msg[1] >> 24) {
 	case LAN_RECEIVE_POST: 
 	{
-		if (dev->start)
-		{
-			if(!(msg[4]>>24))
-			{
+		if (dev->start) {
+			if(!(msg[4]>>24)) {
 				i2o_lan_receive_post_reply(dev,msg);
 				break;
 			}
 
 			// Something VERY wrong if this is happening
-			printk( KERN_WARNING "i2olan: Device %s rejected bucket post\n", dev->name);
+			printk( KERN_WARNING "i2olan: Device %s rejected bucket post.\n", dev->name);
 		}
 
 		// Getting unused buckets back
@@ -146,15 +140,16 @@
 		struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;	
 		u8 trl_count  = msg[3] & 0x000000FF; 	
 		
-		do { 	// The HDM has handled the outgoing packet
+		while (trl_count) {	
+	  		// The HDM has handled the outgoing packet
 			dev_kfree_skb((struct sk_buff *)msg[4 + trl_count]);
-			dprintk(KERN_INFO "%s: Request skb freed (trl_count=%d).\n",
+			printk(KERN_INFO "%s: Request skb freed (trl_count=%d).\n",
 				dev->name,trl_count);
 			priv->tx_count--;
-		} while (--trl_count);
+			trl_count--;
+		}
 		
-		if(dev->tbusy)
-		{
+		if (dev->tbusy) {
 			clear_bit(0,(void*)&dev->tbusy);
 			mark_bh(NET_BH); /* inform upper layers */
 		}
@@ -162,45 +157,135 @@
 		break;	
 	}
 
-	default: 
-		if (msg[2] & 0x80000000)  // reply to a UtilParamsGet/Set
-		{	
-	   		int *flag = (int *)msg[3]; // flag for i2o_post_wait
-			if (msg[4] >> 24) // ReqStatus != SUCCESS
-	     	 		*flag = -(msg[4] & 0xFFFF); // DetailedStatus
-	     		else
-	     			*flag = I2O_POST_WAIT_OK;
-	     	}
+	case LAN_RESET:
+	case LAN_SUSPEND:
+		break;
+
+	case I2O_CMD_UTIL_EVT_REGISTER:
+        case I2O_CMD_UTIL_EVT_ACK:
+        	i2o_lan_event_reply(dev, msg);
+        	break;
+
+	default:
+		printk(KERN_ERR "%s: Sorry, no handler for the reply.\n", dev->name);
+		i2o_report_status(KERN_INFO, dev->name, msg);		
 	}
 }
 
+
+static void i2o_lan_event_reply(struct net_device *dev, u32 *msg)
+{
+        struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;
+        struct i2o_device *i2o_dev = priv->i2o_dev;
+        struct i2o_controller *iop = i2o_dev->controller;
+        struct i2o_reply {
+                u8  version_offset;
+                u8  msg_flags;
+                u16 msg_size;
+                u32 tid:12;
+                u32 initiator:12;
+                u32 function:8;
+                u32 initiator_context;
+                u32 transaction_context;
+                u32 evt_indicator;
+                u32 evt_data[(iop->inbound_size - 20) / 4];     /* max */
+        } *evt = (struct i2o_reply *)msg;
+
+        int evt_data_len = (evt->msg_size - 5) * 4;             /* real */
+
+        if (evt->function == I2O_CMD_UTIL_EVT_REGISTER) {
+                printk(KERN_INFO "%s: I2O event - ", dev->name);
+
+                switch (evt->evt_indicator) {
+                        case I2O_EVT_IND_STATE_CHANGE:
+                                printk("State chance 0x%08X.\n",
+                                        evt->evt_data[0]);
+                                break;
+                        case I2O_EVT_IND_GENERAL_WARNING:
+                                printk("General warning 0x%02X.\n",
+                                        evt->evt_data[0]);
+                                break;
+                        case I2O_EVT_IND_CONFIGURATION_FLAG:
+                                printk("Configuration requested.\n");
+                                break;
+                        case I2O_EVT_IND_LOCK_RELEASE:
+                                printk("Lock released.\n");
+                                break;
+                        case I2O_EVT_IND_CAPABILITY_CHANGE:
+                                printk("Capability change 0x%02X.\n",
+                                        evt->evt_data[0]);
+                                break;
+                        case I2O_EVT_IND_DEVICE_RESET:
+                                printk("Device reset.\n");
+                                break;                            
+                        case I2O_EVT_IND_EVT_MASK_MODIFIED:
+                                printk("Event mask modified, 0x%08X.\n",
+                                        evt->evt_data[0]);
+                                break;
+                        case I2O_EVT_IND_FIELD_MODIFIED: {
+                                u16 *work16 = (u16 *)evt->evt_data;
+                                printk("Group 0x%04X, field %d changed.\n",
+                                        work16[0], work16[1]);
+                                break;
+                        }
+                        case I2O_EVT_IND_VENDOR_EVT: {
+                                int i;
+                                printk("Vendor event:\n");
+                                for (i = 0; i < evt_data_len / 4; i++)
+                                        printk("   0x%08X\n", evt->evt_data[i]);
+                                break;
+                        }
+                        case I2O_EVT_IND_DEVICE_STATE:
+                                printk("Device state changed 0x%08X.\n",
+                                        evt->evt_data[0]);
+                                break;
+                        case I2O_LAN_EVT_LINK_DOWN:
+                                printk("Link to the physical device is lost.\n");
+                                break;
+                        case I2O_LAN_EVT_LINK_UP:
+                                printk("Link to the physical device is (re)established.\n");
+                                break;
+                        case I2O_LAN_EVT_MEDIA_CHANGE:
+                                printk("Media change.\n");
+                                break;
+                        default:
+                                printk("Event Indicator = 0x%08X.\n",
+                                        evt->evt_indicator);
+                }
+
+                /*
+                 * EventAck necessary only for events that cause the device
+                 * to syncronize with the user
+                 *
+                 *if (i2o_event_ack(iop, i2o_dev->lct_data->tid,
+                 *               priv->unit << 16 | lan_context,
+                 *               evt->evt_indicator,
+                 *               evt->evt_data, evt_data_len) < 0)
+                 *       printk("%s: Event Acknowledge timeout.\n", dev->name);
+                 */
+        }
+
+        /* else evt->function == I2O_CMD_UTIL_EVT_ACK) */
+        /* Do we need to do something here too? */
+}   
+
+
 void i2o_lan_release_buckets(struct net_device *dev, u32 *msg)
 {
 	struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;	
 	u8 trl_count  = (u8)(msg[3] & 0x000000FF); 	
 	u32 *pskb = &msg[6];
-	
-	while (trl_count) 
-	{	
-		dprintk("%s: Releasing unused sk_buff %p\n",dev->name, 
+
+	while (trl_count) {	
+		dprintk("%s: Releasing unused sk_buff %p.\n",dev->name,
 			(struct sk_buff*)(*pskb));
-		dev_kfree_skb((struct sk_buff*)(*pskb)); 
+		dev_kfree_skb((struct sk_buff*)(*pskb));
 		pskb++;
 		priv->bucket_count--;
 		trl_count--;
 	}
 }
 
-static struct i2o_handler i2o_lan_handler =
-{
-	i2o_lan_reply,
-	"I2O Lan OSM",
-	0,		// context
-	I2O_CLASS_LAN
-};
-static int lan_context;
-
-
 static int i2o_lan_receive_post_reply(struct net_device *dev, u32 *msg)
 {
 	struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;
@@ -210,25 +295,21 @@
 	u8 trl_count  = msg[3] & 0x000000FF; 	
 	struct sk_buff *skb, *newskb;
 
-static int n_calls = 0;
-n_calls++;
-
 #if 0
 	dprintk(KERN_INFO "TrlFlags = 0x%02X, TrlElementSize = %d, TrlCount = %d\n"
-		"msgsize = %d, buckets_remaining = %d\n", 
+		"msgsize = %d, buckets_remaining = %d\n",
 		msg[3]>>24, msg[3]&0x0000FF00, trl_count, msg[0]>>16, msg[5]);	
 #endif
-
-	while (trl_count--)
-	{
+	while (trl_count--) {
 		skb = (struct sk_buff *)(bucket->context);		
 		packet = (struct i2o_packet_info *)bucket->packet_info;	
 		priv->bucket_count--;
 
+#if 0
 		dprintk(KERN_INFO "Buckets_remaining = %d, bucket_count = %d, trl_count = %d\n",
 			msg[5], priv->bucket_count, trl_count);
-#if 0
-		dprintk(KERN)INFO "flags = 0x%02X, offset = 0x%06X, status = 0x%02X, length = %d\n",
+
+		dprintk(KERN_INFO "flags = 0x%02X, offset = 0x%06X, status = 0x%02X, length = %d\n",
 			packet->flags, packet->offset, packet->status, packet->len);
 #endif
 		if (packet->len < rx_copybreak) {
@@ -241,15 +322,15 @@
 				newskb->protocol = priv->type_trans(newskb, dev);
 
 				netif_rx(newskb);
-				dev_kfree_skb(skb); // FIXME: reuse this skb? 
+				dev_kfree_skb(skb); // FIXME: reuse this skb?
 			}
 			else {
-				printk("I2OLAN-%s: Can't allocate skb.\n", dev->name);
+				printk("%s: Can't allocate skb.\n", dev->name);
 				return -ENOMEM;
 			}
 		} else {
 			skb_put(skb,packet->len);		
-			skb->dev  = dev;		
+			skb->dev = dev;		
 			skb->protocol = priv->type_trans(skb, dev);
 
 			netif_rx(skb);
@@ -260,20 +341,17 @@
 		bucket++; // to next Packet Descriptor Block
 	}
 
-	if (priv->bucket_count < bucketpost - bucketthresh)
-		i2o_lan_receive_post(dev, bucketpost - priv->bucket_count);
-
 	if ((msg[4] & 0x000000FF) == I2O_LAN_DSC_BUCKET_OVERRUN)
-	{
-		printk(KERN_INFO "%s: DDM out of buckets (count = %d)! "
-			 "Number of posts = %d\n", dev->name, msg[5], n_calls);
-		n_calls = 0;
-	}
+		printk(KERN_INFO "%s: DDM out of buckets (count = %d)!\n",
+			 dev->name, msg[5]);
+	
+	if (priv->bucket_count <= bucketpost - bucketthresh)
+		i2o_lan_receive_post(dev, bucketpost - priv->bucket_count);
 
 	return 0;
 }
 
-/* 
+/*
  * i2o_lan_receive_post(): Post buckets to receive packets.
  */
 static int i2o_lan_receive_post(struct net_device *dev, u32 count)
@@ -289,14 +367,12 @@
 	int n_elems = (iop->inbound_size - 16 ) / 12; /* msg header + SGLs */
 	u32 total = 0;
 	int i;
-
-	while (total < count)
-	{
+	
+	while (total < count) {
 		m = I2O_POST_READ32(iop);
 		if (m == 0xFFFFFFFF)
 			return -ETIMEDOUT;		
-		msg = bus_to_virt(iop->mem_offset + m);
-
+		msg = (u32 *)(iop->mem_offset + m);
 		bucket_count = (total + n_elems < count)
 			     ? n_elems
 			     : count - total;
@@ -306,8 +382,7 @@
 		msg[2] = priv->unit << 16 | lan_context; // InitiatorContext	
 		msg[3] = bucket_count;			 // BucketCount
 
-		for (i = 0; i < bucket_count; i++)
-		{
+		for (i = 0; i < bucket_count; i++) {
 			skb = dev_alloc_skb(bucket_len + 2);
 			if (skb == NULL)
 				return -ENOMEM;
@@ -331,11 +406,11 @@
 	return 0;	
 }	
 
-/* 
- * i2o_lan_reset(): Reset the LAN adapter into the operational state and 
+/*
+ * i2o_lan_reset(): Reset the LAN adapter into the operational state and
  * 	restore it to full operation.
  */
-static int i2o_lan_reset(struct net_device *dev) 
+static int i2o_lan_reset(struct net_device *dev)
 {
 	struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;	
 	struct i2o_device *i2o_dev = priv->i2o_dev;
@@ -351,12 +426,12 @@
 	if (i2o_post_this(iop, msg, sizeof(msg)) < 0)
 		return -ETIMEDOUT;		
 
-	return 0; 
+	return 0;
 }
 
-/* 
+/*
  * i2o_lan_suspend(): Put LAN adapter into a safe, non-active state.
- * 	Reply to any LAN class message with status error_no_data_transfer 
+ * 	Reply to any LAN class message with status error_no_data_transfer
  *	/ suspended.
  */
 static int i2o_lan_suspend(struct net_device *dev)
@@ -366,14 +441,14 @@
 	struct i2o_controller *iop = i2o_dev->controller;	
 	u32 msg[5];
 
-	dprintk( "%s: LAN SUSPEND MESSAGE\n", dev->name );
+	dprintk( "%s: LAN SUSPEND MESSAGE.\n", dev->name );
 	msg[0] = FIVE_WORD_MSG_SIZE | SGL_OFFSET_0;
 	msg[1] = LAN_SUSPEND<<24 | HOST_TID<<12 | i2o_dev->lct_data->tid;
 	msg[2] = priv->unit << 16 | lan_context; // InitiatorContext
 	msg[3] = 0; 				 // TransactionContext
 	msg[4] = 1 << 16; 			 // return posted buckets
 
-	if (i2o_post_this(iop, msg, sizeof(msg))< 0)
+	if (i2o_post_this(iop, msg, sizeof(msg)) < 0)
 		return -ETIMEDOUT;
 
 	return 0;
@@ -385,9 +460,9 @@
 static void i2o_set_batch_mode(struct net_device *dev)
 {
 
-/* 
+/*
  * NOTE: we have not been able to test batch mode
- * 	 since HDMs we have, don't implement it 
+ * 	 since HDMs we have, don't implement it
  */
 
 	struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;	
@@ -400,11 +475,13 @@
 	// enable batch mode, toggle automatically
 	val = 0x00000000;
 //	val = 0x00000001; // turn off batch mode
-	if (i2o_set_scalar(iop, i2o_dev->lct_data->tid, 0x0003, 0, &val, 4) < 0)
-		printk(KERN_WARNING "Unable to enter I2O LAN batch mode.\n");
-	else
+	if (i2o_set_scalar(iop, i2o_dev->lct_data->tid, 0x0003, 0, &val, sizeof(val)) <0)
+		printk(KERN_WARNING "%s: Unable to enter I2O LAN batch mode.\n",
+			dev->name);
+	else 
 		dprintk(KERN_INFO "%s: I2O LAN batch mode enabled.\n",dev->name);
 //		dprintk(KERN_INFO "%s: I2O LAN batch mode disabled.\n",dev->name);
+
 	/*
 	 * When PacketOrphanlimit is same as the maximum packet length,
 	 * the packets will never be split into two separate buckets
@@ -413,31 +490,39 @@
 	/* set LAN_OPERATION attributes */
 
 	val = dev->mtu + dev->hard_header_len; // PacketOrphanLimit
-	if (i2o_set_scalar(iop, i2o_dev->lct_data->tid, 0x0004, 2, &val, 4))
-		printk(KERN_WARNING "i2o_lan: Unable to set PacketOrphanLimit.\n");
+	if (i2o_set_scalar(iop, i2o_dev->lct_data->tid, 0x0004, 2, &val, sizeof(val)) < 0)
+		printk(KERN_WARNING "%s: Unable to set PacketOrphanLimit.\n",
+			dev->name);
 	else
-		dprintk(KERN_INFO "%s: PacketOrphanLimit set to %d\n",
+		dprintk(KERN_INFO "%s: PacketOrphanLimit set to %d.\n",
 			dev->name,val);
-
+	
 	return;	
 }
 
-/* 
- * i2o_lan_open(): Open the device to send/receive packets via 
+/*
+ * i2o_lan_open(): Open the device to send/receive packets via
  * the network device.	
  */
 static int i2o_lan_open(struct net_device *dev)
 {
 	struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;	
-	struct i2o_device *i2o_dev = priv->i2o_dev;	
+	struct i2o_device *i2o_dev = priv->i2o_dev;
+	struct i2o_controller *iop = i2o_dev->controller; 
+	u32 evt_mask =  0xFFC00007; // All generic events, all lan evenst
 
-	if(i2o_claim_device(i2o_dev, &i2o_lan_handler, I2O_CLAIM_PRIMARY))
-	{
+	if (i2o_claim_device(i2o_dev, &i2o_lan_handler, I2O_CLAIM_PRIMARY)) {
 		printk(KERN_WARNING "%s: Unable to claim the I2O LAN device.\n", dev->name);
 		return -EAGAIN;
 	}
-	dprintk(KERN_INFO "%s: I2O LAN device claimed (tid=%d).\n", dev->name, i2o_dev->lct_data->tid);
-
+	dprintk(KERN_INFO "%s: I2O LAN device claimed (tid=%d).\n", 
+		dev->name, i2o_dev->lct_data->tid);
+#if 0
+	if (i2o_event_register(iop, i2o_dev->lct_data->tid,
+				priv->unit << 16 | lan_context, evt_mask) < 0)
+		printk(KERN_WARNING "%s: Unable to set the event mask.\n", 
+			dev->name);
+#endif
 	i2o_lan_reset(dev);
 	
 	dev->tbusy = 0;
@@ -453,19 +538,26 @@
 
 /*
  * i2o_lan_close(): End the transfering.
- */ 
+ */
 static int i2o_lan_close(struct net_device *dev)
 {
 	struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;	
 	struct i2o_device *i2o_dev = priv->i2o_dev;	
+//#if 0
+	struct i2o_controller *iop = i2o_dev->controller; 
 
+	if (i2o_event_register(iop, i2o_dev->lct_data->tid,
+				priv->unit << 16 | lan_context, 0) < 0)
+		printk(KERN_WARNING "%s: Unable to clear the event mask.\n", 
+				dev->name);
+//#endif
 	dev->tbusy = 1;
 	dev->start = 0;
 	i2o_lan_suspend(dev);
 
-	if(i2o_release_device(i2o_dev, &i2o_lan_handler, I2O_CLAIM_PRIMARY))
+	if (i2o_release_device(i2o_dev, &i2o_lan_handler, I2O_CLAIM_PRIMARY))
 		printk(KERN_WARNING "%s: Unable to unclaim I2O LAN device "
-		       "(tid=%d)\n", dev->name, i2o_dev->lct_data->tid);
+		       "(tid=%d).\n", dev->name, i2o_dev->lct_data->tid);
 
 	MOD_DEC_USE_COUNT;
 
@@ -473,9 +565,9 @@
 }
 
 #if 0
-/* 
+/*
  * i2o_lan_sdu_send(): Send a packet, MAC header added by the HDM.
- * Must be supported by Fibre Channel, optional for Ethernet/802.3, 
+ * Must be supported by Fibre Channel, optional for Ethernet/802.3,
  * Token Ring, FDDI
  */
 static int i2o_lan_sdu_send(struct sk_buff *skb, struct net_device *dev)
@@ -484,12 +576,12 @@
 }
 #endif
 
-/* 
+/*
  * i2o_lan_packet_send(): Send a packet as is, including the MAC header.
- * 
- * Must be supported by Ethernet/802.3, Token Ring, FDDI, optional for 
+ *
+ * Must be supported by Ethernet/802.3, Token Ring, FDDI, optional for
  * Fibre Channel
- */ 
+ */
 static int i2o_lan_packet_send(struct sk_buff *skb, struct net_device *dev)
 {
 	struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;	
@@ -498,14 +590,13 @@
 	u32 m, *msg;
 	u32 flags = 0;
 
-	/* 
+	/*
 	 * Keep interrupt from changing dev->tbusy from underneath us
 	 * (Do we really need to do this?)
 	 */
 	spin_lock_irqsave(&priv->lock, flags);
 
-	if(test_and_set_bit(0,(void*)&dev->tbusy) != 0)
-	{
+	if(test_and_set_bit(0,(void*)&dev->tbusy) != 0) {
 		spin_unlock_irqrestore(&priv->lock, flags);
 		return 1;
 	}
@@ -515,9 +606,19 @@
 		spin_unlock_irqrestore(&priv->lock, flags);
 		dev_kfree_skb(skb);
 		return -ETIMEDOUT;
-	}    
-	msg = bus_to_virt(iop->mem_offset + m);
-	
+	}
+	msg = (u32 *)(iop->mem_offset + m);
+
+#if 0
+	__raw_writel(SEVEN_WORD_MSG_SIZE | 1<<12 | SGL_OFFSET_4,&msg[0]);
+	__raw_writel(LAN_PACKET_SEND<<24 | HOST_TID<<12 | i2o_dev->lct_data->tid, &msg[1]);
+	__raw_writel(priv->unit << 16 | lan_context, &msg[2]); // InitiatorContext
+	__raw_writel(1 << 4, &msg[3]); 			// TransmitControlWord
+	__raw_writel(0xD5000000 | skb->len, &msg[4]);	// MAC hdr included
+	__raw_writel((u32)skb, &msg[5]);		// TransactionContext
+	__raw_writel(virt_to_bus(skb->data),&msg[6]);
+#endif
+
 	msg[0] = SEVEN_WORD_MSG_SIZE | 1<<12 | SGL_OFFSET_4;
 	msg[1] = LAN_PACKET_SEND<<24 | HOST_TID<<12 | i2o_dev->lct_data->tid;	
 	msg[2] = priv->unit << 16 | lan_context; // IntiatorContext
@@ -552,8 +653,8 @@
 	u64 val64[16];
 	u64 supported_group[4] = { 0, 0, 0, 0 };
 
-        if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0100, -1, 
-        		 val64, sizeof(val64)) < 0)
+        if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0100, -1, val64, 
+        		     sizeof(val64)) < 0)
         	printk("%s: Unable to query LAN_HISTORICAL_STATS.\n",dev->name);
 	else {
         	dprintk("%s: LAN_HISTORICAL_STATS queried.\n",dev->name);
@@ -566,13 +667,13 @@
 		priv->stats.rx_dropped = val64[6];
 	}
 
-        if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0180, -1, 
+        if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0180, -1,
         		&supported_group, sizeof(supported_group)) < 0)
         	printk("%s: Unable to query LAN_SUPPORTED_OPTIONAL_HISTORICAL_STATS.\n",dev->name);
 
 	if (supported_group[2]) {
-        	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0183, -1, 
-        	 	val64, sizeof(val64) ) < 0)
+        	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0183, -1,
+        	 	val64, sizeof(val64)) < 0)
         		printk("%s: Unable to query LAN_OPTIONAL_RX_HISTORICAL_STATS.\n",dev->name);
 		else {
         		dprintk("%s: LAN_OPTIONAL_RX_HISTORICAL_STATS queried.\n",dev->name);
@@ -582,11 +683,10 @@
 		}
 	}
 
-	if (i2o_dev->lct_data->sub_class == I2O_LAN_ETHERNET)
-	{
+	if (i2o_dev->lct_data->sub_class == I2O_LAN_ETHERNET) {
 		u64 supported_stats = 0;		
 
-        	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0200, -1, 
+        	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid,  0x0200, -1,
         			 val64, sizeof(val64)) < 0)
         		printk("%s: Unable to query LAN_802_3_HISTORICAL_STATS.\n",dev->name);
 		else {
@@ -596,14 +696,15 @@
 			priv->stats.tx_carrier_errors  = val64[6];
 		}
 
-        	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0280, -1, 
-        			 &supported_stats, 8) < 0)
-        		printk("%s: Unable to query LAN_SUPPORTED_802_3_HISTORICAL_STATS\n", dev->name);
+        	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid,  0x0280, -1,
+        			 &supported_stats, sizeof(supported_stats)) < 0)
+        		printk("%s: Unable to query LAN_SUPPORTED_802_3_HISTORICAL_STATS.\n", dev->name);
 
         	if (supported_stats != 0) {
-        		if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0281, -1, 
+        		if (i2o_query_scalar(iop, i2o_dev->lct_data->tid,  0x0281, -1,
         				 val64, sizeof(val64)) < 0)
-        			printk("%s: Unable to query LAN_OPTIONAL_802_3_HISTORICAL_STATS.\n",dev->name);
+;
+//        			printk("%s: Unable to query LAN_OPTIONAL_802_3_HISTORICAL_STATS.\n",dev->name);
 			else {
         			dprintk("%s: LAN_OPTIONAL_802_3_HISTORICAL_STATS queried.\n",dev->name);
 				if (supported_stats & 0x1)
@@ -616,13 +717,12 @@
 	}
 
 #ifdef CONFIG_TR
-	if (i2o_dev->lct_data->sub_class == I2O_LAN_TR)
-	{
-        	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0300, -1, 
+	if (i2o_dev->lct_data->sub_class == I2O_LAN_TR) {
+        	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid,  0x0300, -1,
         			 val64, sizeof(val64)) < 0)
         		printk("%s: Unable to query LAN_802_5_HISTORICAL_STATS.\n",dev->name);
 		else {
-			struct tr_statistics *stats = 
+			struct tr_statistics *stats =
 					(struct tr_statistics *)&priv->stats;
 //        		dprintk("%s: LAN_802_5_HISTORICAL_STATS queried.\n",dev->name);
 
@@ -642,9 +742,8 @@
 #endif
 
 #ifdef CONFIG_FDDI
-	if (i2o_dev->lct_data->sub_class == I2O_LAN_FDDI)
-	{
-        	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0400, -1, 
+	if (i2o_dev->lct_data->sub_class == I2O_LAN_FDDI) {
+        	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid,  0x0400, -1,
         			 val64, sizeof(val64)) < 0)
         		printk("%s: Unable to query LAN_FDDI_HISTORICAL_STATS.\n",dev->name);
 		else {
@@ -666,90 +765,97 @@
 
 	return (struct net_device_stats *)&priv->stats;
 }
- 
+
 /*
- * i2o_lan_set_multicast_list(): Enable a network device to receive packets
- *	not send to the protocol address.
+ * i2o_lan_set_mc_list(): Enable a network device to receive packets
+ *      not send to the protocol address.
  */
-static void i2o_lan_set_multicast_list(struct net_device *dev)
+
+static void i2o_lan_set_mc_list(struct net_device *dev)
 {
-	struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;	
-	struct i2o_device *i2o_dev = priv->i2o_dev;
-	struct i2o_controller *iop = i2o_dev->controller;
-	u32 filter_mask;
-	u32 work32[64];
+        struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;
+        struct i2o_device *i2o_dev = priv->i2o_dev;
+        struct i2o_controller *iop = i2o_dev->controller;
+        u32 filter_mask;
+        u32 max_size_mc_table;
+        u32 mc_addr_group[64];
+
+        if (i2o_query_scalar(iop, i2o_dev->lct_data->tid,  0x0001, -1,
+                             &mc_addr_group, sizeof(mc_addr_group)) < 0 ) {
+                printk(KERN_WARNING "%s: Unable to query LAN_MAC_ADDRESS group.\n", dev->name);
+                return;
+        }
 
-	dprintk(KERN_INFO "%s: Entered i2o_lan_set_multicast_list().\n", dev->name);
+        max_size_mc_table = mc_addr_group[8];
 
-return;
+        if (dev->flags & IFF_PROMISC) {
+                filter_mask = 0x00000002;
+                dprintk(KERN_INFO "%s: Enabling promiscuous mode...\n", dev->name);
+        }
 
-/* FIXME: Why does the next call kill the interrupt handler?
- * The same piece of code works fine in function lan_open(), and in i2o_proc.c
- *
- * *because its trying to sleep in an irq - this must be async - Alan
- */
+        else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count > max_size_mc_table) {
+                filter_mask = 0x00000004;
+                dprintk(KERN_INFO "%s: Enabling all multicast mode...\n", dev->name);
+        }
 
-	if (i2o_query_scalar(iop, i2o_dev->lct_data->tid, 0x0001, -1,
-			     &work32, sizeof(work32)) < 0) 
-	{
-		printk(KERN_WARNING "i2o_lan: Unable to query "
-			" LAN_MAC_ADDRESS table.\n");	
-		return;
-	}
-	printk(KERN_INFO "capab mask = 0x%08X, filter mask = 0x%08X\n",
-		work32[7], work32[6]);
+        else if (dev->mc_count) {
+                struct dev_mc_list *mc;
+		u8 mc_table[2 + 8 * dev->mc_count]; // RowCount, Addresses
+		u64 *work64 = (u64 *)(mc_table + 2);
+
+                filter_mask = 0x00000000;
+                dprintk(KERN_INFO "%s: Enabling multicast mode...\n", dev->name);
+
+                /* Fill multicast addr table */
+
+		memset(mc_table, 0, sizeof(mc_table));
+                memcpy(mc_table, &dev->mc_count, 2);
+                for (mc = dev->mc_list; mc ; mc = mc->next, work64++ )
+                        memcpy(work64, mc->dmi_addr, mc->dmi_addrlen);
+		
+		/* Clear old mc table, copy new table to <iop,tid> */
 
-	filter_mask = work32[6];
+                if (i2o_clear_table(iop, i2o_dev->lct_data->tid,  0x0002) < 0)
+                        printk("%s: Unable to clear LAN_MULTICAST_MAC_ADDRESS table.\n",dev->name);
 
-	if (dev->flags & IFF_PROMISC)
-	{
-		filter_mask |= 0x00000002; 
-		dprintk(KERN_INFO "i2o_lan: Enabling promiscuous mode...\n");
+                if ((i2o_row_add_table(iop, i2o_dev->lct_data->tid,  0x0002, -1,
+                        mc_table, sizeof(mc_table))) < 0)
+                        printk("%s: Unable to set LAN_MULTICAST_MAC_ADDRESS table.\n",dev->name);
         }
-        
- 	else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count > work32[5])
- 	{
-		filter_mask |= 0x00000000; 
-		dprintk(KERN_INFO "i2o_lan: Enabling all multicast mode...\n");
-	}
-
-        else if (dev->mc_count)
-	{	
-		struct dev_mc_list *mclist;
-		int i;
-		u8 *work8 = (u8 *)work32;
-
-		dprintk(KERN_INFO "i2o_lan: Enabling multicast mode...\n");
-                filter_mask = 0x00000004; 
-
-		/* Fill the multicast addresses */
-		mclist = dev->mc_list;
-
-		for (i = 0; i < dev->mc_count; i++)
-		{	
-			memcpy(work8, mclist->dmi_addr, mclist->dmi_addrlen);
-			work8 += 8;
-			mclist = mclist->next;
-		} 
-
-		if (i2o_clear_table(iop, i2o_dev->lct_data->tid, 0x0002) < 0)
-			dprintk("%s: Unable to clear LAN_MULTICAST_MAC_ADDRESS table.\n",dev->name);
-
-		if (i2o_row_add_table(iop, i2o_dev->lct_data->tid, 0x0002, -1,
-			work32, dev->mc_count*8) < 0)	
-			dprintk("%s: Unable to set LAN_MULTICAST_MAC_ADDRESS table.\n",dev->name);
-	} 
-	
-	else {
-        	filter_mask |= 0x00000300; // Broadcast, Multicast disabled
-		dprintk(KERN_INFO "i2o_lan: Enabling unicast mode...\n");
+
+        else {	
+                filter_mask = 0x00000300; // Broadcast, Multicast disabled
+                printk(KERN_INFO "%s: Enabling unicast mode...\n",dev->name);
         }
 
-	if (i2o_set_scalar(iop, i2o_dev->lct_data->tid, 0x0001, 3,
-			&filter_mask, 4) < 0)
-		printk(KERN_WARNING "i2o_lan: Unable to set MAC FilterMask.\n");
+	/* Finally copy new FilterMask to <iop,tid> */
+
+        if (i2o_set_scalar(iop, i2o_dev->lct_data->tid,  0x0001, 3,
+                        &filter_mask, sizeof(filter_mask)) <0)
+                printk(KERN_WARNING "%s: Unable to set MAC FilterMask.\n",dev->name);
 
-	return;
+        return;
+}
+
+/*
+ * i2o_lan_set_multicast_list():
+ *       Queue routine i2o_lan_set_mc_list() to be called later.
+ *       Needs to be async.
+ */
+
+static void i2o_lan_set_multicast_list(struct net_device *dev)
+{
+        struct tq_struct *task;
+
+        task = (struct tq_struct *)kmalloc(sizeof(struct tq_struct), GFP_KERNEL);
+        if (task == NULL)
+                return;
+
+        task->next = NULL;
+        task->sync = 0;
+        task->routine = (void *)i2o_lan_set_mc_list;
+        task->data = (void *)dev;
+        queue_task(task, &tq_scheduler);
 }
 
 struct net_device *i2o_lan_register_device(struct i2o_device *i2o_dev)
@@ -761,24 +867,21 @@
 	unsigned short (*type_trans)(struct sk_buff *, struct net_device *);
 	void (*unregister_dev)(struct net_device *dev);
 
-	switch (i2o_dev->lct_data->sub_class)
-	{
+	switch (i2o_dev->lct_data->sub_class) {
 	case I2O_LAN_ETHERNET:
-		dev = init_etherdev(NULL, sizeof(struct i2o_lan_local));
+        	dev = init_etherdev(NULL, sizeof(struct i2o_lan_local));
 		if (dev == NULL)
 			return NULL;
 		type_trans = eth_type_trans;
 		unregister_dev = unregister_netdev;
 		break;
 
-
 #ifdef CONFIG_ANYLAN
 	case I2O_LAN_100VG:
-		printk(KERN_ERR "i2o_lan: 100base VG not yet supported\n");
+		printk(KERN_ERR "i2o_lan: 100base VG not yet supported.\n");
 		break;
 #endif
 
-
 #ifdef CONFIG_TR
 	case I2O_LAN_TR:
 		dev = init_trdev(NULL, sizeof(struct i2o_lan_local));
@@ -800,8 +903,7 @@
             	dev->priv = (void *)(dev + 1);
                 dev->name = (char *)(dev + 1) + sizeof(struct i2o_lan_local);
 
-		if (dev_alloc_name(dev,"fddi%d") < 0)
-		{
+		if (dev_alloc_name(dev,"fddi%d") < 0) {
 			printk(KERN_WARNING "i2o_lan: Too many FDDI devices.\n");
 			kfree(dev);
 			return NULL;
@@ -817,13 +919,13 @@
 
 #ifdef CONFIG_FIBRE_CHANNEL
 	case I2O_LAN_FIBRE_CHANNEL:
-		printk(KERN_INFO "i2o_lan: Fibre Channel not yet supported\n");
+		printk(KERN_INFO "i2o_lan: Fibre Channel not yet supported.\n");
 	break;
 #endif
 
 	case I2O_LAN_UNKNOWN:
 	default:
-		printk(KERN_ERR "i2o_lan: LAN type 0x%08X not supported\n",
+		printk(KERN_ERR "i2o_lan: LAN type 0x%08X not supported.\n",
 		       i2o_dev->lct_data->sub_class);
 		return NULL;
 	}
@@ -838,13 +940,12 @@
 	priv->unit = unit;
 
 	if (i2o_query_scalar(i2o_dev->controller, i2o_dev->lct_data->tid,
-			0x0001, 0, &hw_addr, 8) < 0)
-	{
-     	printk(KERN_ERR "%s: Unable to query hardware address.\n", dev->name);
+			     0x0001, 0, &hw_addr, sizeof(hw_addr)) < 0) {
+     		printk(KERN_ERR "%s: Unable to query hardware address.\n", dev->name);
 		unit--;
 		unregister_dev(dev);
 		kfree(dev);
-      		return NULL;  
+      		return NULL;
 	}
 
 	dprintk("%s: hwaddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
@@ -854,18 +955,18 @@
 	dev->addr_len = 6;
 	memcpy(dev->dev_addr, hw_addr, 6);
 
-   if (i2o_query_scalar(i2o_dev->controller, i2o_dev->lct_data->tid,
-         0x0007, 2, &max_tx, 4) < 0)
-   {
-      printk(KERN_ERR "%s: Unable to query max TX queue.\n", dev->name);
-      unit--;
-      unregister_dev(dev);
-      kfree(dev);
-         return NULL;
-   }
-   printk(KERN_INFO "%s: Max TX Outstanding = %d\n", dev->name, max_tx);
-   priv->max_tx = max_tx;
-   priv->tx_count = 0;
+	if (i2o_query_scalar(i2o_dev->controller, i2o_dev->lct_data->tid,
+         	0x0007, 2, &max_tx, sizeof(max_tx)) < 0) 
+	{
+      		printk(KERN_ERR "%s: Unable to query max TX queue.\n", dev->name);
+      		unit--;
+      		unregister_dev(dev);
+      		kfree(dev);
+         	return NULL;
+	}
+   	dprintk(KERN_INFO "%s: Max TX Outstanding = %d.\n", dev->name, max_tx);
+   	priv->max_tx = max_tx;
+   	priv->tx_count = 0;
 
 	priv->lock = SPIN_LOCK_UNLOCKED;
 
@@ -887,43 +988,41 @@
 	struct net_device *dev;
 	int i;
 
-	if (i2o_install_handler(&i2o_lan_handler) < 0)
-	{
- 		printk(KERN_ERR "Unable to register I2O LAN OSM.\n");
+	printk(KERN_INFO "Linux I2O LAN OSM (c) 1999 University of Helsinki.\n");
+ 
+	if (i2o_install_handler(&i2o_lan_handler) < 0) {
+ 		printk(KERN_ERR "i2o_lan: Unable to register I2O LAN OSM.\n");
 		return -EINVAL;
-	}   
+	}
 	lan_context = i2o_lan_handler.context;
 	
 	for(i=0; i <= MAX_LAN_CARDS; i++)
 		i2o_landevs[i] = NULL;
 
-	for (i=0; i < MAX_I2O_CONTROLLERS; i++)
-	{
+	for (i=0; i < MAX_I2O_CONTROLLERS; i++) {
 		struct i2o_controller *iop = i2o_find_controller(i);
 		struct i2o_device *i2o_dev;
 
-		if (iop==NULL)
-			continue;
+		if (iop==NULL) continue;
+
+		for (i2o_dev=iop->devices;i2o_dev != NULL;i2o_dev=i2o_dev->next) {
 
-		for (i2o_dev=iop->devices;i2o_dev != NULL;i2o_dev=i2o_dev->next)
-		{
-			if (i2o_dev->lct_data->class_id != I2O_CLASS_LAN) 
+			if (i2o_dev->lct_data->class_id != I2O_CLASS_LAN)
 				continue;
 
-			if(i2o_dev->lct_data->user_tid != 0xFFF)
+			/* Make sure device not already claimed by an ISM */
+			if (i2o_dev->lct_data->user_tid != 0xFFF)
 				continue;
 
-			if (unit == MAX_LAN_CARDS)
-			{
+			if (unit == MAX_LAN_CARDS) {
 				i2o_unlock_controller(iop);
-				printk(KERN_WARNING "Too many I2O LAN devices.\n");
+				printk(KERN_WARNING "i2o_lan: Too many I2O LAN devices.\n");
 				return -EINVAL;
 			}
 
 			dev = i2o_lan_register_device(i2o_dev);
- 			if (dev == NULL)
-			{
-				printk(KERN_ERR "Unable to register I2O LAN device\n");
+ 			if (dev == NULL) {
+				printk(KERN_ERR "i2o_lan: Unable to register I2O LAN device.\n");
 				continue; // try next one
 			}
 
@@ -947,14 +1046,12 @@
 {
 	int i;
 
-	for (i = 0; i <= unit; i++)
-	{
+	for (i = 0; i <= unit; i++) {
 		struct net_device *dev = i2o_landevs[i];
 		struct i2o_lan_local *priv = (struct i2o_lan_local *)dev->priv;	
 		struct i2o_device *i2o_dev = priv->i2o_dev;	
 
-		switch (i2o_dev->lct_data->sub_class)
-		{
+		switch (i2o_dev->lct_data->sub_class) {
 		case I2O_LAN_ETHERNET:
 			unregister_netdev(dev);
 			kfree(dev);
@@ -976,11 +1073,11 @@
 			       i2o_dev->lct_data->sub_class);
 		}
 
-		dprintk(KERN_INFO "%s: I2O LAN device unregistered.\n", 
+		dprintk(KERN_INFO "%s: I2O LAN device unregistered.\n",
 			dev->name);
 	}
 
-        i2o_remove_handler(&i2o_lan_handler);
+	i2o_remove_handler(&i2o_lan_handler);
 }
 
 EXPORT_NO_SYMBOLS;
@@ -992,4 +1089,4 @@
 MODULE_PARM(bucketthresh, "i"); // Bucket post threshold
 MODULE_PARM(rx_copybreak, "i");
 
-#endif    
+#endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)