[openib-general] [PATCH] Start IPoIB cleanup

Roland Dreier roland at topspin.com
Tue Sep 14 13:06:35 PDT 2004


Start cleaning up IPoIB: use alloc_netdev and free_netdev properly,
and set the underlying device with SET_NETDEV_DEV().

 - R.

Index: infiniband/ulp/ipoib/ipoib_verbs.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_verbs.c	(revision 803)
+++ infiniband/ulp/ipoib/ipoib_verbs.c	(working copy)
@@ -29,7 +29,7 @@
 /*.. ipoib_pkey_dev_check_presence - Check for the interface P_Key presence */
 void ipoib_pkey_dev_check_presence(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	u16 pkey_index = 0;
 
 	if (ib_cached_pkey_find(priv->ca, priv->port, priv->pkey, &pkey_index))
@@ -40,7 +40,7 @@
 
 int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ib_qp_attr *qp_attr;
 	struct ib_qp_cap qp_cap;
 	int attr_mask;
@@ -85,7 +85,7 @@
 
 int ipoib_mcast_detach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int ret;
 
 	down(&priv->mcast_mutex);
@@ -101,7 +101,7 @@
 
 int ipoib_qp_create(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int ret;
 	u16 pkey_index;
 
@@ -194,7 +194,7 @@
 
 void ipoib_qp_destroy(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	if (ib_destroy_qp(priv->qp))
 		TS_REPORT_WARN(MOD_IB_NET,
@@ -205,7 +205,7 @@
 
 int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	priv->pd = ib_alloc_pd(priv->ca);
 	if (IS_ERR(priv->pd)) {
@@ -261,7 +261,7 @@
 
 void ipoib_transport_dev_cleanup(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	if (priv->qp != NULL) {
 		if (ib_destroy_qp(priv->qp))
@@ -290,14 +290,14 @@
 
 	if (record->event == IB_EVENT_PORT_ACTIVE) {
 		TS_TRACE(MOD_IB_NET, T_VERBOSE, TRACE_IB_NET_GEN,
-			 "%s: Port active event", priv->dev.name);
+			 "%s: Port active event", priv->dev->name);
 		schedule_work(&priv->flush_task);
 	}
 }
 
 int ipoib_port_monitor_dev_start(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	INIT_IB_EVENT_HANDLER(&priv->event_handler,
 			      priv->ca, ipoib_event);
@@ -312,7 +312,7 @@
 
 void ipoib_port_monitor_dev_stop(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	ib_unregister_event_handler(&priv->event_handler);
 }
Index: infiniband/ulp/ipoib/ipoib_arp.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_arp.c	(revision 803)
+++ infiniband/ulp/ipoib/ipoib_arp.c	(working copy)
@@ -24,7 +24,6 @@
 #include "ipoib.h"
 
 #include "ts_kernel_trace.h"
-#include "ts_kernel_services.h"
 
 #include "ts_ib_sa_client.h"
 
@@ -198,7 +197,7 @@
 static struct ipoib_sarp *__ipoib_sarp_find(struct net_device *dev,
 					    const uint8_t *hash)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_sarp *entry;
 
 	list_for_each_entry(entry, &priv->sarp_cache->table[hash[0]],
@@ -223,7 +222,7 @@
 static struct ipoib_sarp *_ipoib_sarp_find(struct net_device *dev,
 					   const uint8_t *hash)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_sarp *entry;
 	unsigned long flags;
 
@@ -238,7 +237,7 @@
 /*..ipoib_sarp_iter_init -- create new ARP iterator                */
 struct ipoib_sarp_iter *ipoib_sarp_iter_init(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_sarp_iter *iter;
 
 	iter = kmalloc(sizeof(*iter), GFP_KERNEL);
@@ -273,7 +272,7 @@
 /*..ipoib_sarp_iter_next -- incr. iter. -- return non-zero at end  */
 int ipoib_sarp_iter_next(struct ipoib_sarp_iter *iter)
 {
-	struct ipoib_dev_priv *priv = iter->dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(iter->dev);
 
 	while (1) {
 		iter->cur = iter->cur->next;
@@ -314,7 +313,7 @@
 struct ipoib_sarp *ipoib_sarp_add(struct net_device *dev, union ib_gid *gid,
 				  u32 qpn)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	uint8_t hash[IPOIB_ADDRESS_HASH_BYTES];
 	struct ipoib_sarp *entry;
 	unsigned long flags;
@@ -366,7 +365,7 @@
 /*..ipoib_sarp_delete -- delete shadow ARP cache entry             */
 int ipoib_sarp_delete(struct net_device *dev, const uint8_t *hash)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_sarp *entry;
 	unsigned long flags;
 
@@ -398,7 +397,7 @@
 {
 	struct ipoib_sarp *entry = entry_ptr;
 	struct net_device *dev = entry->dev;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	TS_TRACE(MOD_IB_NET, T_VERY_VERBOSE, TRACE_IB_NET_ARP,
 		 "%s: path record lookup done, status %d", dev->name, status);
@@ -474,7 +473,7 @@
 {
 	struct ipoib_sarp *entry = entry_ptr;
 	struct net_device *dev = entry->dev;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	tTS_IB_CLIENT_QUERY_TID tid;
 
 	ipoib_sarp_get(entry);
@@ -729,7 +728,7 @@
 /*..ipoib_sarp_rewrite_send -- rewrite and send ARP packet         */
 int ipoib_sarp_rewrite_send(struct net_device *dev, struct sk_buff *skb)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	unsigned char broadcast_mac_addr[] =
 	    { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 	struct sk_buff *new_skb;
@@ -961,7 +960,7 @@
 /*..ipoib_sarp_dev_init -- initialize ARP cache                    */
 int ipoib_sarp_dev_init(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int i;
 
 	priv->sarp_cache = kmalloc(sizeof(*priv->sarp_cache), GFP_KERNEL);
@@ -978,7 +977,7 @@
 /*..ipoib_sarp_dev_flush -- flush ARP cache                        */
 void ipoib_sarp_dev_flush(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_sarp *entry, *tentry;
 	LIST_HEAD(delete_list);
 	unsigned long flags;
@@ -1041,7 +1040,7 @@
 /*..ipoib_sarp_dev_destroy -- destroy ARP cache                    */
 static void ipoib_sarp_dev_destroy(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_sarp *entry, *tentry;
 	LIST_HEAD(delete_list);
 	unsigned long flags;
@@ -1072,7 +1071,7 @@
 /*..ipoib_sarp_dev_cleanup -- clean up ARP cache                   */
 void ipoib_sarp_dev_cleanup(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	TS_REPORT_CLEANUP(MOD_IB_NET, "%s: cleaning up ARP table", dev->name);
 
Index: infiniband/ulp/ipoib/ipoib_main.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_main.c	(revision 813)
+++ infiniband/ulp/ipoib/ipoib_main.c	(working copy)
@@ -23,7 +23,6 @@
 
 #include "ipoib.h"
 
-#include "ts_kernel_services.h"
 #include "ts_kernel_trace.h"
 
 #include <linux/version.h>
@@ -115,7 +114,7 @@
 int ipoib_device_handle(struct net_device *dev, struct ib_device **ca,
 			tTS_IB_PORT *port, tTS_IB_GID gid, u16 *pkey)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	*ca = priv->ca;
 	*port = priv->port;
@@ -128,7 +127,7 @@
 
 int ipoib_dev_open(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	TS_TRACE(MOD_IB_NET, T_VERBOSE, TRACE_FLOW_CONFIG,
 		 "%s: bringing up interface", dev->name);
@@ -152,11 +151,11 @@
 		list_for_each_entry(cpriv, &priv->child_intfs, list) {
 			int flags;
 
-			flags = cpriv->dev.flags;
+			flags = cpriv->dev->flags;
 			if (flags & IFF_UP)
 				continue;
 
-			ipoib_change_flags(&cpriv->dev, flags | IFF_UP);
+			ipoib_change_flags(cpriv->dev, flags | IFF_UP);
 		}
 		up(&ipoib_device_mutex);
 	}
@@ -168,7 +167,7 @@
 
 static int _ipoib_dev_stop(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	TS_TRACE(MOD_IB_NET, T_VERBOSE, TRACE_FLOW_CONFIG,
 		 "%s: stopping interface", dev->name);
@@ -188,11 +187,11 @@
 		list_for_each_entry(cpriv, &priv->child_intfs, list) {
 			int flags;
 
-			flags = cpriv->dev.flags;
+			flags = cpriv->dev->flags;
 			if (!(flags & IFF_UP))
 				continue;
 
-			ipoib_change_flags(&cpriv->dev, flags & ~IFF_UP);
+			ipoib_change_flags(cpriv->dev, flags & ~IFF_UP);
 		}
 		up(&ipoib_device_mutex);
 	}
@@ -215,7 +214,7 @@
 
 static int _ipoib_dev_change_mtu(struct net_device *dev, int new_mtu)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	if (new_mtu > IPOIB_PACKET_SIZE - IPOIB_ENCAP_LEN)
 		return -EINVAL;
@@ -234,7 +233,7 @@
 
 static int _ipoib_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	uint16_t ethertype;
 	int ret;
 
@@ -374,14 +373,14 @@
 
 struct net_device_stats *_ipoib_dev_get_stats(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	return &priv->stats;
 }
 
 static void _ipoib_dev_timeout(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	if (priv->tx_free && !test_bit(IPOIB_FLAG_TIMEOUT, &priv->flags)) {
 		char ring[IPOIB_TX_RING_SIZE + 1];
@@ -435,51 +434,15 @@
 
 static void _ipoib_dev_set_mcast_list(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	schedule_work(&priv->restart_task);
 }
 
 int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
-	TS_REPORT_INOUT(MOD_IB_NET, "%s: initializing device", dev->name);
-
-	dev->open = ipoib_dev_open;
-	dev->stop = _ipoib_dev_stop;
-	dev->do_ioctl = _ipoib_dev_ioctl;
-	dev->change_mtu = _ipoib_dev_change_mtu;
-	dev->set_config = _ipoib_dev_set_config;
-	dev->hard_start_xmit = _ipoib_dev_xmit;
-	dev->get_stats = _ipoib_dev_get_stats;
-	dev->tx_timeout = _ipoib_dev_timeout;
-	dev->hard_header = _ipoib_dev_hard_header;
-	dev->set_multicast_list = _ipoib_dev_set_mcast_list;
-	dev->watchdog_timeo = HZ;
-
-	dev->rebuild_header = NULL;
-	dev->set_mac_address = NULL;
-	dev->header_cache_update = NULL;
-
-	dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
-
-	dev->hard_header_len = ETH_HLEN;
-	dev->addr_len = IPOIB_ADDRESS_HASH_BYTES;
-	dev->type = ARPHRD_ETHER;
-	dev->tx_queue_len = IPOIB_TX_RING_SIZE * 2;
-	/* MTU will be reset when mcast join happens */
-	dev->mtu = IPOIB_PACKET_SIZE - IPOIB_ENCAP_LEN;
-	priv->mcast_mtu = priv->admin_mtu = dev->mtu;
-
-	memset(dev->broadcast, 0xff, dev->addr_len);
-
-	netif_carrier_off(dev);
-
-	SET_MODULE_OWNER(dev);
-
-	spin_lock_init(&priv->lock);
-
 	if (ipoib_sarp_dev_init(dev))
 		goto out;
 
@@ -540,14 +503,14 @@
 
 void ipoib_dev_cleanup(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv, *cpriv, *tcpriv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv, *tcpriv;
 	int i;
 
 	/* Delete any child interfaces first */
 	/* Safe since it's either protected by ipoib_device_mutex or empty */
 	list_for_each_entry_safe(cpriv, tcpriv, &priv->child_intfs, list) {
-		ipoib_dev_cleanup(&cpriv->dev);
-		unregister_netdev(&cpriv->dev);
+		ipoib_dev_cleanup(cpriv->dev);
+		unregister_netdev(cpriv->dev);
 
 		list_del(&cpriv->list);
 
@@ -585,72 +548,98 @@
 	}
 }
 
-struct ipoib_dev_priv *ipoib_intf_alloc(void)
+static void ipoib_setup(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
-	priv = kmalloc(sizeof(*priv), GFP_KERNEL);
-	if (!priv) {
-		TS_REPORT_FATAL(MOD_IB_NET,
-				"failed to allocate private struct");
-		return NULL;
-	}
+	dev->open 		 = ipoib_dev_open;
+	dev->stop 		 = _ipoib_dev_stop;
+	dev->do_ioctl 		 = _ipoib_dev_ioctl;
+	dev->change_mtu 	 = _ipoib_dev_change_mtu;
+	dev->set_config 	 = _ipoib_dev_set_config;
+	dev->hard_start_xmit 	 = _ipoib_dev_xmit;
+	dev->get_stats 		 = _ipoib_dev_get_stats;
+	dev->tx_timeout 	 = _ipoib_dev_timeout;
+	dev->hard_header 	 = _ipoib_dev_hard_header;
+	dev->set_multicast_list  = _ipoib_dev_set_mcast_list;
+	dev->watchdog_timeo 	 = HZ;
 
-	memset(priv, 0, sizeof(*priv));
+	dev->rebuild_header 	 = NULL;
+	dev->set_mac_address 	 = NULL;
+	dev->header_cache_update = NULL;
 
-	sema_init(&priv->mcast_mutex, 1);
+	dev->flags              |= IFF_BROADCAST | IFF_MULTICAST;
 
+	dev->hard_header_len 	 = ETH_HLEN;
+	dev->addr_len 		 = IPOIB_ADDRESS_HASH_BYTES;
+	dev->type 		 = ARPHRD_ETHER;
+	dev->tx_queue_len 	 = IPOIB_TX_RING_SIZE * 2;
+
+	/* MTU will be reset when mcast join happens */
+	dev->mtu 		 = IPOIB_PACKET_SIZE - IPOIB_ENCAP_LEN;
+	priv->mcast_mtu 	 = priv->admin_mtu = dev->mtu;
+
+	memset(dev->broadcast, 0xff, dev->addr_len);
+
+	netif_carrier_off(dev);
+
+	SET_MODULE_OWNER(dev);
+
+	priv->dev = dev;
+
+	spin_lock_init(&priv->lock);
+
+	sema_init(&priv->mcast_mutex, 1);
 	atomic_set(&priv->mcast_joins, 0);
 
 	INIT_LIST_HEAD(&priv->child_intfs);
 	INIT_LIST_HEAD(&priv->multicast_list);
 
-	INIT_WORK(&priv->flush_task,   ipoib_ib_dev_flush,       &priv->dev);
-	INIT_WORK(&priv->restart_task, ipoib_mcast_restart_task, &priv->dev);
+	INIT_WORK(&priv->flush_task,   ipoib_ib_dev_flush,       priv->dev);
+	INIT_WORK(&priv->restart_task, ipoib_mcast_restart_task, priv->dev);
 
-	priv->dev.priv = priv;
+}
 
-	return priv;
+struct ipoib_dev_priv *ipoib_intf_alloc(const char *name)
+{
+	struct net_device *dev;
+
+	dev = alloc_netdev((int) sizeof (struct ipoib_dev_priv), name,
+			   ipoib_setup);
+	if (!dev)
+		return NULL;
+
+	return netdev_priv(dev);
 }
 
-int ipoib_add_port(const char *format, struct ib_device *hca, tTS_IB_PORT port)
+static int ipoib_add_port(const char *format, struct ib_device *hca, u8 port)
 {
 	struct ipoib_dev_priv *priv;
 	int result = -ENOMEM;
 
-	priv = ipoib_intf_alloc();
+	priv = ipoib_intf_alloc(format);
 	if (!priv)
 		goto alloc_mem_failed;
 
-	priv->pkey = 0xffff;
+	SET_NETDEV_DEV(priv->dev, &hca->dma_device->dev);
 
-#if 0
-	/* We'll probably use something like this in the future */
-	result = ib_pkey_entry_get(hca, port, 0, &priv->pkey);
+	result = ib_query_pkey(hca, port, 0, &priv->pkey);
 	if (result) {
 		TS_REPORT_FATAL(MOD_IB_NET,
 				"%s: ib_pkey_entry_get failed (ret = %d)",
-				priv->dev.name, result);
-		goto dev_pkey_get_failed;
+				priv->dev->name, result);
+		goto alloc_mem_failed;
 	}
-#endif
 
-	result = dev_alloc_name(&priv->dev, format);
+	result = ipoib_dev_init(priv->dev, hca, port);
 	if (result < 0) {
 		TS_REPORT_FATAL(MOD_IB_NET,
-				"failed to get device name (ret = %d)", result);
-		goto dev_alloc_failed;
-	}
-
-	result = ipoib_dev_init(&priv->dev, hca, port);
-	if (result < 0) {
-		TS_REPORT_FATAL(MOD_IB_NET,
 				"failed to initialize net device %d, port %d (ret = %d)",
 				hca, port, result);
 		goto device_init_failed;
 	}
 
-	result = ipoib_port_monitor_dev_start(&priv->dev);
+	result = ipoib_port_monitor_dev_start(priv->dev);
 	if (result < 0) {
 		TS_REPORT_FATAL(MOD_IB_NET,
 				"failed to setup port monitor for device %d, "
@@ -659,11 +648,11 @@
 		goto port_monitor_failed;
 	}
 
-	result = register_netdev(&priv->dev);
+	result = register_netdev(priv->dev);
 	if (result) {
 		TS_REPORT_FATAL(MOD_IB_NET,
 				"%s: failed to initialize; error %i",
-				priv->dev.name, result);
+				priv->dev->name, result);
 		goto register_failed;
 	}
 
@@ -674,20 +663,14 @@
 	return 0;
 
 register_failed:
-	ipoib_port_monitor_dev_stop(&priv->dev);
+	ipoib_port_monitor_dev_stop(priv->dev);
 
 port_monitor_failed:
-	ipoib_dev_cleanup(&priv->dev);
+	ipoib_dev_cleanup(priv->dev);
 
 device_init_failed:
-	/*
-	 * Nothing to do since the device name only gets finally added
-	 * to the linked list in register_netdev
-	 */
+	free_netdev(priv->dev);
 
-dev_alloc_failed:
-	kfree(priv);
-
 alloc_mem_failed:
 	return result;
 }
@@ -725,10 +708,10 @@
 	up(&ipoib_device_mutex);
 
 	list_for_each_entry_safe(priv, tmp, &delete, list) {
-		unregister_netdev(&priv->dev);
-		ipoib_port_monitor_dev_stop(&priv->dev);
-		ipoib_dev_cleanup(&priv->dev);
-		kfree(priv);
+		unregister_netdev(priv->dev);
+		ipoib_port_monitor_dev_stop(priv->dev);
+		ipoib_dev_cleanup(priv->dev);
+		free_netdev(priv->dev);
 	}
 }
 
Index: infiniband/ulp/ipoib/ipoib.h
===================================================================
--- infiniband/ulp/ipoib/ipoib.h	(revision 824)
+++ infiniband/ulp/ipoib/ipoib.h	(working copy)
@@ -26,9 +26,10 @@
 
 #include <linux/list.h>
 #include <linux/skbuff.h>
-#include <linux/netdevice.h>	/* struct device, and other headers */
+#include <linux/netdevice.h>
 #include <linux/proc_fs.h>
 #include <linux/completion.h>
+#include <linux/pci.h>
 
 #include <asm/atomic.h>
 #include <asm/semaphore.h>
@@ -40,7 +41,6 @@
 
 #include <ts_ib_sa_client.h>
 
-#include <ts_kernel_services.h>
 #include <ts_kernel_thread.h>
 
 /* constants */
@@ -97,10 +97,8 @@
 
 struct ipoib_dev_priv {
 	spinlock_t lock;
-	struct net_device dev;
-	struct list_head list;
 
-	struct list_head child_intfs;
+	struct net_device *dev;
 
 	unsigned long flags;
 
@@ -156,6 +154,9 @@
 	struct ib_event_handler event_handler;
 
 	struct net_device_stats stats;
+
+	struct list_head list;
+	struct list_head child_intfs;
 };
 
 /* list of IPoIB network devices */
@@ -172,7 +173,7 @@
 		   ipoib_tx_callback_t callback,
 		   void *ptr, struct ib_ah *address, u32 qpn);
 
-struct ipoib_dev_priv *ipoib_intf_alloc(void);
+struct ipoib_dev_priv *ipoib_intf_alloc(const char *format);
 
 int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
 void ipoib_ib_dev_flush(void *dev);
@@ -251,9 +252,6 @@
 int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca);
 void ipoib_transport_dev_cleanup(struct net_device *dev);
 
-int ipoib_add_port(const char *format, struct ib_device *device,
-		   tTS_IB_PORT port);
-
 int ipoib_port_monitor_dev_start(struct net_device *dev);
 void ipoib_port_monitor_dev_stop(struct net_device *dev);
 
Index: infiniband/ulp/ipoib/ipoib_ib.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_ib.c	(revision 824)
+++ infiniband/ulp/ipoib/ipoib_ib.c	(working copy)
@@ -53,7 +53,7 @@
 /*.._ipoib_ib_post_receive -- post a receive buffer                */
 static int _ipoib_ib_post_receive(struct net_device *dev, int id)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct sk_buff *skb;
 	dma_addr_t addr;
 	int ret;
@@ -104,7 +104,7 @@
 static void ipoib_ib_handle_wc(struct net_device *dev,
 			       struct ib_wc *entry)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	unsigned int work_request_id = (unsigned int) entry->wr_id;
 
 	TS_REPORT_DATA(MOD_IB_NET,
@@ -270,7 +270,7 @@
 void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr)
 {
 	struct net_device *dev = (struct net_device *) dev_ptr;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int n, i;
 
 	ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
@@ -312,7 +312,7 @@
 		   ipoib_tx_callback_t callback, void *ptr,
 		   struct ib_ah *address, u32 qpn)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_tx_buf *tx_req;
 	dma_addr_t addr;
 
@@ -430,7 +430,7 @@
 
 int ipoib_ib_dev_up(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	set_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
 
@@ -441,7 +441,7 @@
 /*..ipoib_ib_dev_down -- remove from multicast, etc                */
 int ipoib_ib_dev_down(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int count = 0;
 
 	clear_bit(IPOIB_FLAG_OPER_UP, &priv->flags);
@@ -489,7 +489,7 @@
 /*..ipoib_ib_dev_stop -- cleanup QP and RX ring                    */
 int ipoib_ib_dev_stop(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int i;
 
 	/* Kill the existing QP and allocate a new one */
@@ -510,7 +510,7 @@
 /*..ipoib_ib_dev_init -- set up IB resources for iface             */
 int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	priv->ca = ca;
 	priv->port = port;
@@ -539,7 +539,7 @@
 void ipoib_ib_dev_flush(void *_dev)
 {
 	struct net_device *dev = (struct net_device *)_dev;
-	struct ipoib_dev_priv *priv = dev->priv, *cpriv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv;
 
 	if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
 		return;
@@ -565,7 +565,7 @@
 /*..ipoib_ib_dev_cleanup -- clean up IB resources for iface        */
 void ipoib_ib_dev_cleanup(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	TS_REPORT_CLEANUP(MOD_IB_NET,
 			  "%s: cleaning up IB resources", dev->name);
@@ -602,7 +602,7 @@
 /*..ipoib_pkey_dev_start_thread -- Start the P_Key thread          */
 int ipoib_pkey_dev_start_thread(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	char thread_name[sizeof("ibX.YYYY_pkey")];
 	int ret = 0;
 
@@ -635,7 +635,7 @@
 /*..ipoib_pkey_dev_stop_thread -- Stop the P_Key thread            */
 int ipoib_pkey_dev_stop_thread(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int ret = 0;
 
 	TS_TRACE(MOD_IB_NET, T_VERBOSE, TRACE_IB_NET_GEN,
@@ -660,7 +660,7 @@
 static void _ipoib_pkey_thread(void *dev_ptr)
 {
 	struct net_device *dev = dev_ptr;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	/* P_Key already assigned */
 	if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
@@ -689,7 +689,7 @@
 /*..ipoib_pkey_dev_delay_open -- wait for pkey to be set                    */
 int ipoib_pkey_dev_delay_open(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	/* Look for the interface pkey value in the IB Port P_Key table and */
 	/* set the interface pkey assigment flag                            */
Index: infiniband/ulp/ipoib/ipoib_vlan.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_vlan.c	(revision 803)
+++ infiniband/ulp/ipoib/ipoib_vlan.c	(working copy)
@@ -21,11 +21,6 @@
   $Id$
 */
 
-#include "ipoib.h"
-
-#include "ts_kernel_services.h"
-#include "ts_kernel_trace.h"
-
 #include <linux/version.h>
 #include <linux/module.h>
 
@@ -34,6 +29,11 @@
 
 #include <asm/uaccess.h>
 
+#include "ipoib.h"
+
+#include "ts_kernel_services.h"
+#include "ts_kernel_trace.h"
+
 struct ipoib_vlan_iter {
 	struct list_head *pintf_cur;
 	struct list_head *intf_cur;
@@ -50,7 +50,7 @@
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
 
-	ppriv = pdev->priv;
+	ppriv = netdev_priv(pdev);
 
 	/*
 	 * First ensure this isn't a duplicate. We check the parent device and
@@ -68,7 +68,7 @@
 	}
 	up(&ipoib_device_mutex);
 
-	priv = ipoib_intf_alloc();
+	priv = ipoib_intf_alloc(intf_name);
 	if (!priv)
 		goto alloc_mem_failed;
 
@@ -76,9 +76,7 @@
 
 	priv->pkey = pkey;
 
-	strncpy(priv->dev.name, intf_name, sizeof(priv->dev.name));
-
-	result = ipoib_dev_init(&priv->dev, ppriv->ca, ppriv->port);
+	result = ipoib_dev_init(priv->dev, ppriv->ca, ppriv->port);
 	if (result < 0) {
 		TS_REPORT_FATAL(MOD_IB_NET,
 				"failed to initialize net device %d, port %d",
@@ -86,11 +84,11 @@
 		goto device_init_failed;
 	}
 
-	result = register_netdev(&priv->dev);
+	result = register_netdev(priv->dev);
 	if (result) {
 		TS_REPORT_FATAL(MOD_IB_NET,
 				"%s: failed to initialize; error %i",
-				priv->dev.name, result);
+				priv->dev->name, result);
 		goto register_failed;
 	}
 
@@ -101,10 +99,10 @@
 	return 0;
 
 register_failed:
-	ipoib_dev_cleanup(&priv->dev);
+	ipoib_dev_cleanup(priv->dev);
 
 device_init_failed:
-	kfree(priv);
+	free_netdev(priv->dev);
 
 alloc_mem_failed:
 	return result;
@@ -117,18 +115,18 @@
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
 
-	ppriv = pdev->priv;
+	ppriv = netdev_priv(pdev);
 
 	down(&ipoib_device_mutex);
 	list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) {
 		if (priv->pkey == pkey) {
-			if (priv->dev.flags & IFF_UP) {
+			if (priv->dev->flags & IFF_UP) {
 				up(&ipoib_device_mutex);
 				return -EBUSY;
 			}
 
-			ipoib_dev_cleanup(&priv->dev);
-			unregister_netdev(&priv->dev);
+			ipoib_dev_cleanup(priv->dev);
+			unregister_netdev(priv->dev);
 
 			list_del(&priv->list);
 
@@ -230,7 +228,7 @@
 		ppriv = list_entry(iter->pintf_cur, struct ipoib_dev_priv, list);
 
 		if (!iter->intf_cur)
-			seq_printf(file, "%s 0x%04x\n", ppriv->dev.name,
+			seq_printf(file, "%s 0x%04x\n", ppriv->dev->name,
 				   ppriv->pkey);
 		else {
 			struct ipoib_dev_priv *priv;
@@ -238,8 +236,8 @@
 			priv = list_entry(iter->intf_cur, struct ipoib_dev_priv,
 				          list);
 
-			seq_printf(file, " %s %s 0x%04x\n", ppriv->dev.name,
-				   priv->dev.name, priv->pkey);
+			seq_printf(file, " %s %s 0x%04x\n", ppriv->dev->name,
+				   priv->dev->name, priv->pkey);
 		}
 	}
 
Index: infiniband/ulp/ipoib/ipoib_proc.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_proc.c	(revision 803)
+++ infiniband/ulp/ipoib/ipoib_proc.c	(working copy)
@@ -21,17 +21,18 @@
   $Id$
 */
 
-#include "ipoib.h"
-
-#include "ts_kernel_trace.h"
-#include "ts_kernel_services.h"
-
 #include <linux/ctype.h>
 #include <linux/module.h>
+#include <linux/seq_file.h>
 
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 
+#include "ipoib.h"
+
+#include "ts_kernel_trace.h"
+#include "ts_kernel_services.h"
+
 /*
  * ARP proc file stuff
  */
@@ -425,7 +426,7 @@
 /*..ipoib_proc_dev_init -- set up ipoib_arp in /proc               */
 int ipoib_proc_dev_init(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	char name[sizeof(ipoib_arp_proc_entry_name) + sizeof (dev->name)];
 
 	snprintf(name, sizeof(name) - 1, ipoib_arp_proc_entry_name, dev->name);
@@ -465,7 +466,7 @@
 /*..ipoib_proc_dev_cleanup -- unregister /proc file                */
 void ipoib_proc_dev_cleanup(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	char name[sizeof(ipoib_arp_proc_entry_name) + sizeof(dev->name)];
 
 	if (priv->arp_proc_entry) {
Index: infiniband/ulp/ipoib/ipoib_multicast.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_multicast.c	(revision 803)
+++ infiniband/ulp/ipoib/ipoib_multicast.c	(working copy)
@@ -25,7 +25,6 @@
 
 #include "ts_ib_sa_client.h"
 
-#include "ts_kernel_services.h"
 #include "ts_kernel_trace.h"
 
 #include <linux/rtnetlink.h>
@@ -137,7 +136,7 @@
 /*..__ipoib_mcast_find - find multicast group            */
 struct ipoib_mcast *__ipoib_mcast_find(struct net_device *dev, union ib_gid *mgid)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct rb_node *n = priv->multicast_tree.rb_node;
 
 	while (n) {
@@ -165,7 +164,7 @@
 struct ipoib_mcast *_ipoib_mcast_find(struct net_device *dev, union ib_gid *mgid)
 {
 	struct ipoib_mcast *mcast;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	unsigned long flags;
 
 	spin_lock_irqsave(&priv->lock, flags);
@@ -179,7 +178,7 @@
 /*..__ipoib_mcast_add -- add multicast group to rbtree             */
 static int __ipoib_mcast_add(struct net_device *dev, struct ipoib_mcast *mcast)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct rb_node **n = &priv->multicast_tree.rb_node, *pn = NULL;
 
 	while (*n) {
@@ -210,7 +209,7 @@
 				    struct ib_multicast_member *member_ptr)
 {
 	struct net_device *dev = mcast->dev;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int ret;
 
 	mcast->mcast_member = *member_ptr;
@@ -301,7 +300,7 @@
 {
 	struct ipoib_mcast *mcast = mcast_ptr;
 	struct net_device *dev = mcast->dev;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	mcast->tid = TS_IB_CLIENT_QUERY_TID_INVALID;
 
@@ -338,7 +337,7 @@
 static int _ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast)
 {
 	struct net_device *dev = mcast->dev;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	tTS_IB_CLIENT_QUERY_TID tid;
 	int ret = 0;
 
@@ -399,7 +398,7 @@
 {
 	struct ipoib_mcast *mcast = mcast_ptr;
 	struct net_device *dev = mcast->dev;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	priv->mcast_tid = TS_IB_CLIENT_QUERY_TID_INVALID;
 
@@ -415,7 +414,7 @@
 /*..__ipoib_mcast_join - join multicast group for iface            */
 static int __ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int status;
 
 	TS_TRACE(MOD_IB_NET, T_VERY_VERBOSE, TRACE_IB_NET_MULTICAST,
@@ -508,7 +507,7 @@
 static void _ipoib_mcast_join_thread(void *dev_ptr)
 {
 	struct net_device *dev = dev_ptr;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_sarp *entry;
 	unsigned long flags;
 	int ret = 0;
@@ -612,7 +611,7 @@
 /*..ipoib_mcast_start_thread -- start multicast thread             */
 int ipoib_mcast_start_thread(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	char thread_name[64];
 	int ret = 0;
 
@@ -646,7 +645,7 @@
 /*..ipoib_mcast_stop_thread -- stop multicast join                 */
 int ipoib_mcast_stop_thread(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int ret = 0;
 
 	TS_TRACE(MOD_IB_NET, T_VERBOSE, TRACE_IB_NET_MULTICAST,
@@ -685,7 +684,7 @@
 /*..ipoib_mcast_leave -- leave multicast group                     */
 int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	int result;
 
 	if (!test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags))
@@ -739,7 +738,7 @@
 static int _ipoib_mcast_delete(struct net_device *dev, union ib_gid *mgid)
 {
 	struct ipoib_mcast *mcast;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	unsigned long flags;
 
 	spin_lock_irqsave(&priv->lock, flags);
@@ -765,7 +764,7 @@
 				 union ib_gid *mgid,
 				 struct ipoib_mcast **mmcast)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_mcast *mcast;
 	unsigned long flags;
 	int ret = 0;
@@ -847,7 +846,7 @@
 /*..ipoib_mcast_dev_flush -- flush joins and address vectors       */
 void ipoib_mcast_dev_flush(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	LIST_HEAD(remove_list);
 	struct ipoib_mcast *mcast, *tmcast, *nmcast;
 	unsigned long flags;
@@ -914,7 +913,7 @@
 /*..ipoib_mcast_dev_down -- delete broadcast group                 */
 void ipoib_mcast_dev_down(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 
 	/* Delete broadcast since it will be recreated */
 	if (priv->broadcast) {
@@ -928,7 +927,7 @@
 void ipoib_mcast_restart_task(void *dev_ptr)
 {
 	struct net_device *dev = dev_ptr;
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct in_device *in_dev = in_dev_get(dev);
 	struct ip_mc_list *im;
 	struct ipoib_mcast *mcast, *tmcast;
@@ -1064,7 +1063,7 @@
 /*..ipoib_mcast_iter_init -- create new multicast iterator         */
 struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev)
 {
-	struct ipoib_dev_priv *priv = dev->priv;
+	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_mcast_iter *iter;
 	struct rb_node *node, *parent = NULL;
 



More information about the general mailing list