PERFORCE change 118862 for review

Kip Macy kmacy at FreeBSD.org
Fri Apr 27 07:09:53 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=118862

Change 118862 by kmacy at kmacy_vt-x:opentoe_init on 2007/04/27 07:08:55

	mechanical BSD-ification of toedev.c

Affected files ...

.. //depot/projects/opentoe/sys/dev/cxgb/ulp/toecore/toedev.c#2 edit

Differences ...

==== //depot/projects/opentoe/sys/dev/cxgb/ulp/toecore/toedev.c#2 (text+ko) ====

@@ -1,24 +1,37 @@
-/*
- * TOE device support infrastructure.
- *
- * Copyright (C) 2003-2006 Chelsio Communications.  All rights reserved.
- *
- * Written by Dimitris Michailidis (dm at chelsio.com)
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
+
+/**************************************************************************
+
+Copyright (c) 2007, Chelsio Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+ 3. Neither the name of the Chelsio Corporation nor the names of its
+    contributors may be used to endorse or promote products derived from
+    this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+
+***************************************************************************/
 
 #include <linux/module.h>
 #include <linux/string.h>
@@ -35,16 +48,16 @@
 #include "version.h"
 #include "toe_bonding.h"
 
-static DECLARE_MUTEX(offload_db_lock);
-static LIST_HEAD(offload_dev_list);
-static LIST_HEAD(offload_module_list);
+static struct mtx offload_db_lock;
+static TAILQ_HEAD(, toedev) offload_dev_list;
+static TAILQ_HEAD(, tom_info) offload_module_list;
 
 /*
  * Returns the entry in the given table with the given offload id, or NULL
  * if the id is not found.
  */
-static const struct offload_id *id_find(unsigned int id,
-					const struct offload_id *table)
+static const struct offload_id *
+id_find(unsigned int id, const struct offload_id *table)
 {
 	for ( ; table->id; ++table)
 		if (table->id == id)
@@ -55,7 +68,8 @@
 /*
  * Returns true if an offload device is presently attached to an offload module.
  */
-static inline int is_attached(const struct toedev *dev)
+static inline int
+is_attached(const struct toedev *dev)
 {
 	return dev->offload_mod != NULL;
 }
@@ -66,7 +80,8 @@
  *
  * Must be called with the offload_db_lock held.
  */
-static int offload_attach(struct toedev *dev)
+static int
+offload_attach(struct toedev *dev)
 {
 	struct tom_info *t;
 
@@ -79,7 +94,7 @@
 			return 0;
 		}
 	}
-	return -ENOPROTOOPT;
+	return ENOPROTOOPT;
 }
 
 /**
@@ -88,14 +103,14 @@
  *
  * Register a TCP Offload Module (TOM).
  */
-int register_tom(struct tom_info *t)
+int
+register_tom(struct tom_info *t)
 {
 	down(&offload_db_lock);
 	list_add(&t->list_node, &offload_module_list);
 	up(&offload_db_lock);
 	return 0;
 }
-EXPORT_SYMBOL(register_tom);
 
 /**
  * unregister_tom - unregister a TCP Offload Module (TOM)
@@ -111,12 +126,12 @@
 	up(&offload_db_lock);
 	return 0;
 }
-EXPORT_SYMBOL(unregister_tom);
 
 /*
  * Find an offload device by name.  Must be called with offload_db_lock held.
  */
-static struct toedev *__find_offload_dev_by_name(const char *name)
+static struct toedev *
+__find_offload_dev_by_name(const char *name)
 {
 	struct toedev *dev;
 
@@ -131,7 +146,8 @@
  * Returns true if an offload device is already registered.
  * Must be called with the offload_db_lock held.
  */
-static int is_registered(const struct toedev *dev)
+static int
+is_registered(const struct toedev *dev)
 {
 	struct toedev *d;
 
@@ -146,7 +162,8 @@
  * Finalize the name of an offload device by assigning values to any format
  * strings in its name.
  */
-static int assign_name(struct toedev *dev, const char *name, int limit)
+static int
+assign_name(struct toedev *dev, const char *name, int limit)
 {
 	int i;
 
@@ -166,14 +183,16 @@
 #ifdef CONFIG_PROC_FS
 #include <linux/proc_fs.h>
 
-static struct proc_dir_entry *offload_proc_root;
-
+/*
+ * XXX remove after implementing sysctl equivalent
+ *
+ */
 static int devices_read_proc(char *buf, char **start, off_t offset,
 			     int length, int *eof, void *data)
 {
 	int len;
 	struct toedev *dev;
-	struct net_device *ndev;
+	struct ifnet *ndev;
 
 	len = sprintf(buf,
 		      "Device           Offload Module       Interfaces\n");
@@ -240,7 +259,7 @@
 
 	offload_proc_root = proc_mkdir("net/offload", NULL);
 	if (!offload_proc_root)
-		return -ENOMEM;
+		return ENOMEM;
 	offload_proc_root->owner = THIS_MODULE;
 
 	d = create_proc_read_entry("devices", 0, offload_proc_root,
@@ -252,7 +271,7 @@
 
 cleanup:
 	offload_proc_cleanup();
-	return -ENOMEM;
+	return ENOMEM;
 }
 #else
 #define offload_proc_init() 0
@@ -270,7 +289,8 @@
  * to it.  @name is a template that may contain at most one %d format
  * specifier.
  */
-int register_toedev(struct toedev *dev, const char *name)
+int
+register_toedev(struct toedev *dev, const char *name)
 {
 	int ret;
 	const char *p;
@@ -281,15 +301,15 @@
 	 */
 	if (!name || !*name || !strcmp(name, ".") || !strcmp(name, "..") ||
 	    strchr(name, '/'))
-		return -EINVAL;
+		return EINVAL;
 
 	p = strchr(name, '%');
 	if (p && (p[1] != 'd' || strchr(p + 2, '%')))
-		return -EINVAL;
+		return EINVAL;
 
 	down(&offload_db_lock);
 	if (is_registered(dev)) {  /* device already registered */
-		ret = -EEXIST;
+		ret = EEXIST;
 		goto out;
 	}
 
@@ -303,7 +323,6 @@
 	up(&offload_db_lock);
 	return ret;
 }
-EXPORT_SYMBOL(register_toedev);
 
 /**
  * unregister_toedev - unregister a TOE device
@@ -312,17 +331,18 @@
  * Unregister a TOE device.  The device must not be attached to an offload
  * module.
  */
-int unregister_toedev(struct toedev *dev)
+int
+unregister_toedev(struct toedev *dev)
 {
 	int ret = 0;
 
 	down(&offload_db_lock);
 	if (!is_registered(dev)) {
-		ret = -ENODEV;
+		ret = ENODEV;
 		goto out;
 	}
 	if (is_attached(dev)) {
-		ret = -EBUSY;
+		ret = EBUSY;
 		goto out;
 	}
 	list_del(&dev->toe_list);
@@ -331,7 +351,6 @@
 	up(&offload_db_lock);
 	return ret;
 }
-EXPORT_SYMBOL(unregister_toedev);
 
 /**
  * activate_offload - activate an offload device
@@ -341,57 +360,51 @@
  * module.  If no module is found the operation fails and may be retried at
  * a later time.
  */
-int activate_offload(struct toedev *dev)
+int
+activate_offload(struct toedev *dev)
 {
 	int ret = 0;
 
-#ifdef CONFIG_TCP_OFFLOAD_MODULE
 	ret = prepare_tcp_for_offload();
 	if (ret)
 		return ret;
-#endif
 
 	down(&offload_db_lock);
 	if (!is_registered(dev))
-		ret = -ENODEV;
+		ret = ENODEV;
 	else if (!is_attached(dev))
 		ret = offload_attach(dev);
 	up(&offload_db_lock);
 	return ret;
 }
-EXPORT_SYMBOL(activate_offload);
 
 /**
  * toe_send - send a packet to a TOE device
  * @dev: the device
  * @skb: the packet
  *
- * Sends an sk_buff to a TOE driver after dealing with any active network taps.
+ * Sends an mbuf to a TOE driver after dealing with any active network taps.
  */
-int toe_send(struct toedev *dev, struct sk_buff *skb)
+int toe_send(struct toedev *dev, struct mbuf *skb)
 {
 	int r;
 
 	local_bh_disable();
-#if defined(CONFIG_TCP_OFFLOAD)
 	if (unlikely(netdev_nit)) {      /* deal with active taps */
 		skb->nh.raw = skb->data;
 		if (!skb->dev)
 			skb->dev = dev->lldev;
 		dev_queue_xmit_nit(skb, skb->dev);
 	}
-#endif
 	r = dev->send(dev, skb);
 	local_bh_enable();
 	return r;
 }
-EXPORT_SYMBOL(toe_send);
 
-#if defined(CONFIG_TCP_OFFLOAD)
 /**
  * toe_receive_skb - process n received TOE packets
  * @dev: the toe device
- * @skb: an array of offload packets
+ * @m: an array of offload packets
  * @n: the number of offload packets
  *
  * Process an array of ingress offload packets.  Each packet is forwarded
@@ -399,30 +412,31 @@
  * method.  We optimize passing packets to the receive method by passing
  * it the whole array at once except when there are active taps.
  */
-int toe_receive_skb(struct toedev *dev, struct sk_buff **skb, int n)
+int
+toe_receive_skb(struct toedev *dev, struct mbuf **m, int n)
 {
 	if (likely(!netdev_nit))
-		return dev->recv(dev, skb, n);
+		return dev->recv(dev, m, n);
 
-	for ( ; n; n--, skb++) {
-		skb[0]->dev = dev->lldev;
-		dev_queue_xmit_nit(skb[0], dev->lldev);
-		skb[0]->dev = NULL;
-		dev->recv(dev, skb, 1);
+	for ( ; n; n--, m++) {
+		m[0]->dev = dev->lldev;
+		dev_queue_xmit_nit(m[0], dev->lldev);
+		m[0]->dev = NULL;
+		dev->recv(dev, m, 1);
 	}
 	return 0;
 }
-EXPORT_SYMBOL(toe_receive_skb);
-#endif
 
-static inline int netdev_is_offload(const struct net_device *dev)
+static inline int
+netdev_is_offload(const struct ifnet *dev)
 {
 	return dev->features & NETIF_F_TCPIP_OFFLOAD;
 }
 
-void toe_neigh_update(struct neighbour *neigh)
+void
+toe_neigh_update(struct rtentry *neigh)
 {
-	struct net_device *dev = neigh->dev;
+	struct ifnet *dev = neigh->dev;
 
 	if (dev && netdev_is_offload(dev)) {
 		struct toedev *tdev = TOEDEV(dev);
@@ -445,8 +459,9 @@
  * considers the decisions of the bonding device given its mode to locate the
  * correct egress device.
  */
-struct net_device *offload_get_phys_egress(struct net_device *root_dev,
-					   struct sock *sk, int context)
+struct ifnet *
+offload_get_phys_egress(struct ifnet *root_dev,
+    struct socket *so, int context)
 {
 	while (root_dev && netdev_is_offload(root_dev)) {
 		if (root_dev->priv_flags & IFF_802_1Q_VLAN)
@@ -458,15 +473,14 @@
 	}
 	return root_dev;
 }
-EXPORT_SYMBOL(offload_get_phys_egress);
 
 /*
  * The following few functions define the operations of a virtual offload
- * device that is attached to virtual net_devices, such as VLAN or bonding,
+ * device that is attached to virtual ifnets, such as VLAN or bonding,
  * to endow them with offload support.  These operations simply find the
- * next net_device in a stack of net_devices and invoke the same operation on
- * the offload device associated with that net_device.  Eventually we reach
- * the physical net_device at the bottom of the stack, whose associated
+ * next ifnet in a stack of ifnets and invoke the same operation on
+ * the offload device associated with that ifnet.  Eventually we reach
+ * the physical ifnet at the bottom of the stack, whose associated
  * offload device can then complete the operation.
  */
 
@@ -474,12 +488,13 @@
  * Define a virtual offload device for VLANs that simply forwards offload
  * operations to the offload device associated with the VLAN device's child.
  */
-static int virtual_can_offload(struct toedev *tdev, struct sock *sk)
+static int
+virtual_can_offload(struct toedev *tdev, struct socket *so)
 {
-	struct net_device *root_dev = __sk_dst_get(sk)->dev;
+	struct ifnet *root_dev = __sk_dst_get(sk)->dev;
 
 	if (root_dev->priv_flags & IFF_802_1Q_VLAN) {
-		struct net_device *child = VLAN_DEV_INFO(root_dev)->real_dev;
+		struct ifnet *child = VLAN_DEV_INFO(root_dev)->real_dev;
 
 		if (netdev_is_offload(child)) {
 			struct toedev *tdev = TOEDEV(child);
@@ -492,10 +507,11 @@
 	return 0;
 }
 
-static int virtual_connect(struct toedev *dev, struct sock *sk,
-			   struct net_device *egress_dev)
+static int
+virtual_connect(struct toedev *dev, struct socket *so,
+			   struct ifnet *egress_dev)
 {
-	struct net_device *edev = offload_get_phys_egress(egress_dev, sk,
+	struct ifnet *edev = offload_get_phys_egress(egress_dev, sk,
 							  TOE_OPEN);
 
 	if (edev && netdev_is_offload(edev)) {
@@ -505,9 +521,10 @@
 	return -1;
 }
 
-static void virtual_neigh_update(struct toedev *dev, struct neighbour *neigh)
+static void
+virtual_neigh_update(struct toedev *dev, struct rtentry *neigh)
 {
-	struct net_device *child = neigh->dev;
+	struct ifnet *child = neigh->dev;
 
 	if (neigh->dev->priv_flags & IFF_802_1Q_VLAN)
 		child = VLAN_DEV_INFO(child)->real_dev;
@@ -529,13 +546,14 @@
 };
 
 /*
- * This handler monitors net_device registration and associates virtual offload
- * devices with virtual net_devices, such as VLAN and bonding devices.
+ * This handler monitors ifnet registration and associates virtual offload
+ * devices with virtual ifnets, such as VLAN and bonding devices.
  */
-static int virt_dev_notify_handler(struct notifier_block *this,
+static int
+virt_dev_notify_handler(struct notifier_block *this,
 				   unsigned long event, void *data)
 {
-	struct net_device *dev = data;
+	struct ifnet *dev = data;
 
 	if (event == NETDEV_REGISTER)
 		if (dev->priv_flags & IFF_802_1Q_VLAN) {
@@ -557,7 +575,8 @@
  *	  the same TOE device.
  *
  */
-int toe_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
+int
+toe_enslave(struct ifnet *bond_dev, struct ifnet *slave_dev)
 {
 	struct toedev *tdev;
 	int slave_count;
@@ -567,7 +586,7 @@
 		return 0;
 
 	if (!is_bmode_supported(bond_dev))
-		return -EOPNOTSUPP;
+		return EOPNOTSUPP;
 
 	tdev = toe_bond_slave_toedev(bond_dev);
 	slave_count = toe_bond_slavecnt(bond_dev);
@@ -581,15 +600,14 @@
 
 	/* Mix of TOE enabled and regular devices not supported */
 	else if (netdev_is_offload(bond_dev) ^ netdev_is_offload(slave_dev))
-		ret = -EOPNOTSUPP;
+		ret = EOPNOTSUPP;
 
 	/* TOE enabled device belongs to another adapter */
 	else if (tdev != TOEDEV(slave_dev))
-			ret = -EOPNOTSUPP;
+		ret = EOPNOTSUPP;
 
 	return ret;
 }
-EXPORT_SYMBOL(toe_enslave);
 
 /**
  * toe_failover - executes failover for offloaded connections
@@ -600,7 +618,8 @@
  * Called under bond driver locks.
  */
 
-void toe_failover(struct net_device *bond_dev, struct net_device *dev, int event)
+void
+toe_failover(struct ifnet *bond_dev, struct ifnet *dev, int event)
 {
 	if (netdev_is_offload(bond_dev)) {
 			struct toedev *tdev = toe_bond_slave_toedev(bond_dev);
@@ -609,13 +628,13 @@
 				tdev->failover(tdev, bond_dev, dev, event);
 	}
 }
-EXPORT_SYMBOL(toe_failover);
 
 static struct notifier_block virt_dev_notifier = {
 	.notifier_call = virt_dev_notify_handler
 };
 
-static int __init offload_init(void)
+static int
+offload_init(void)
 {
 	/* We tolerate proc failures */
 	if (offload_proc_init())
@@ -628,19 +647,11 @@
 	return 0;
 }
 
-static void __exit offload_cleanup(void)
+static void
+offload_cleanup(void)
 {
 	unregister_netdevice_notifier(&virt_dev_notifier);
 	offload_proc_cleanup();
-#ifdef CONFIG_TCP_OFFLOAD_MODULE
 	restore_tcp_to_nonoffload();
-#endif
 }
 
-subsys_initcall(offload_init);
-module_exit(offload_cleanup);
-
-MODULE_DESCRIPTION("Support for TCP offload devices");
-MODULE_AUTHOR("Chelsio Communications");
-MODULE_LICENSE("GPL");
-MODULE_VERSION(TOECORE_VERSION);


More information about the p4-projects mailing list