patch-2.2.12 linux/drivers/net/net_init.c
Next file: linux/drivers/net/rtl8139.c
Previous file: linux/drivers/net/fc/tach_structs.h
Back to the patch index
Back to the overall index
- Lines: 140
- Date:
Wed Aug 25 17:29:48 1999
- Orig file:
v2.2.11/linux/drivers/net/net_init.c
- Orig date:
Mon Aug 9 16:05:56 1999
diff -u --recursive --new-file v2.2.11/linux/drivers/net/net_init.c linux/drivers/net/net_init.c
@@ -38,6 +38,7 @@
#include <linux/fddidevice.h>
#include <linux/hippidevice.h>
#include <linux/trdevice.h>
+#include <linux/fcdevice.h>
#include <linux/if_arp.h>
#include <linux/if_ltalk.h>
#include <linux/rtnetlink.h>
@@ -645,7 +646,130 @@
}
#endif
-
+
+#ifdef CONFIG_NET_FC
+
+#define MAX_FC_CARDS 2
+static struct device *fcdev_index[MAX_FC_CARDS];
+
+void fc_setup(struct device *dev)
+{
+int i;
+
+ /* register boot-defined "fc" devices */
+ if (dev->name && (strncmp(dev->name, "fc", 2) == 0)) {
+ i = simple_strtoul(dev->name + 2, NULL, 0);
+ if (fcdev_index[i] == NULL) {
+ fcdev_index[i] = dev;
+ }
+ else if (dev != fcdev_index[i]) {
+ /* Really shouldn't happen! */
+ printk("fc_setup: Ouch! Someone else took %s\n",
+ dev->name);
+ }
+ }
+
+ dev->hard_header = fc_header;
+ dev->rebuild_header = fc_rebuild_header;
+
+ dev->type = ARPHRD_IEEE802;
+ dev->hard_header_len = FC_HLEN;
+ dev->mtu = 2024;
+ dev->addr_len = FC_ALEN;
+ dev->tx_queue_len = 100; /* Long queues on fc */
+
+ memset(dev->broadcast,0xFF, FC_ALEN);
+
+ /* New-style flags. */
+ dev->flags = IFF_BROADCAST;
+ dev_init_buffers(dev);
+ return;
+}
+
+
+struct device *init_fcdev(struct device *dev, int sizeof_priv)
+{
+int new_device = 0;
+int i;
+ /* Use an existing correctly named device in Space.c:dev_base. */
+ if (dev == NULL) {
+ int alloc_size = sizeof(struct device) + sizeof("fc%d ") + sizeof_priv + 3;
+ struct device *cur_dev;
+ char pname[8]; /* Putative name for the device. */
+
+ for (i = 0; i < MAX_FC_CARDS; ++i)
+ if (fcdev_index[i] == NULL) {
+ sprintf(pname, "fc%d", i);
+ for (cur_dev = dev_base; cur_dev; cur_dev = cur_dev->next)
+ if (strcmp(pname, cur_dev->name) == 0) {
+ dev = cur_dev;
+ dev->init = NULL;
+ sizeof_priv = (sizeof_priv + 3) &~3;
+ dev->priv = sizeof_priv
+ ? kmalloc(sizeof_priv, GFP_KERNEL)
+ : NULL;
+ if (dev->priv) memset(dev->priv, 0, sizeof_priv);
+ goto fcfound;
+ }
+ }
+
+ alloc_size &= ~3; /* Round to dword boundary. */
+ dev = (struct device *)kmalloc(alloc_size, GFP_KERNEL);
+ memset(dev, 0, alloc_size);
+ if (sizeof_priv)
+ dev->priv = (void *) (dev + 1);
+ dev->name = sizeof_priv + (char *)(dev + 1);
+ new_device = 1;
+ }
+
+fcfound: /* From the double loop */
+
+ for (i = 0; i < MAX_FC_CARDS; ++i)
+ if (fcdev_index[i] == NULL) {
+ sprintf(dev->name, "fc%d", i);
+ fcdev_index[i] = dev;
+ break;
+ }
+
+ fc_setup(dev);
+ if (new_device)
+ register_netdevice(dev);
+
+ return dev;
+}
+
+void fc_freedev(struct device *dev)
+{
+int i;
+ for (i = 0; i < MAX_FC_CARDS; ++i) {
+ if (fcdev_index[i] == dev) {
+ fcdev_index[i] = NULL;
+ break;
+ }
+ }
+}
+
+
+int register_fcdev(struct device *dev)
+{
+ dev_init_buffers(dev);
+ if (dev->init && dev->init(dev) != 0) {
+ unregister_fcdev(dev);
+ return -EIO;
+ }
+ return 0;
+}
+
+void unregister_fcdev(struct device *dev)
+{
+ rtnl_lock();
+ unregister_netdevice(dev);
+ rtnl_unlock();
+ fc_freedev(dev);
+}
+
+#endif /* CONFIG_NET_FC */
+
/*
* Local variables:
* compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c net_init.c"
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)