1 /* net_init.c: Initialization for network devices. */
3 Written 1993,1994,1995 by Donald Becker.
5 The author may be reached as becker@scyld.com, or C/O
6 Scyld Computing Corporation
7 410 Severn Ave., Suite 210
10 This file contains the initialization for the "pl14+" style ethernet
11 drivers. It should eventually replace most of drivers/net/Space.c.
12 It's primary advantage is that it's able to allocate low-memory buffers.
13 A secondary advantage is that the dangerous NE*000 netcards can reserve
14 their I/O port region before the SCSI probes start.
16 Modifications/additions by Bjorn Ekwall <bj0rn@blox.se>:
17 ethdev_index[MAX_ETH_CARDS]
18 register_netdev() / unregister_netdev()
20 Modifications by Wolfgang Walter
21 Use dev_close cleanly so we always shut things down tidily.
23 Changed 29/10/95, Alan Cox to pass sockaddr's around for mac addresses.
25 14/06/96 - Paul Gortmaker: Add generic eth_change_mtu() function.
26 24/09/96 - Paul Norton: Add token-ring variants of the netdev functions.
28 08/11/99 - Alan Cox: Got fed up of the mess in this file and cleaned it
29 up. We now share common code and have regularised name
30 allocation setups. Abolished the 16 card limits.
31 03/19/2000 - jgarzik and Urban Widmark: init_etherdev 32-byte align
32 03/21/2001 - jgarzik: alloc_etherdev and friends
36 #include <linux/config.h>
37 #include <linux/module.h>
38 #include <linux/kernel.h>
39 #include <linux/types.h>
41 #include <linux/slab.h>
42 #include <linux/if_ether.h>
43 #include <linux/string.h>
44 #include <linux/netdevice.h>
45 #include <linux/etherdevice.h>
46 #include <linux/fddidevice.h>
47 #include <linux/hippidevice.h>
48 #include <linux/trdevice.h>
49 #include <linux/fcdevice.h>
50 #include <linux/if_arp.h>
51 #include <linux/if_ltalk.h>
52 #include <linux/rtnetlink.h>
53 #include <net/neighbour.h>
55 /* The network devices currently exist only in the socket namespace, so these
56 entries are unused. The only ones that make sense are
57 open start the ethercard
58 close stop the ethercard
59 ioctl To get statistics, perhaps set the interface port (AUI, BNC, etc.)
60 One can also imagine getting raw packets using
62 but this is probably better handled by a raw packet socket.
64 Given that almost all of these functions are handled in the current
65 socket-based scheme, putting ethercard devices in /dev/ seems pointless.
67 [Removed all support for /dev network devices. When someone adds
68 streams then by magic we get them, but otherwise they are un-needed
73 struct net_device *alloc_netdev(int sizeof_priv, const char *mask,
74 void (*setup)(struct net_device *))
77 struct net_device *dev;
80 /* ensure 32-byte alignment of both the device and private area */
82 alloc_size = (sizeof(struct net_device) + NETDEV_ALIGN_CONST)
83 & ~NETDEV_ALIGN_CONST;
84 alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
86 p = kmalloc (alloc_size, GFP_KERNEL);
88 printk(KERN_ERR "alloc_dev: Unable to allocate device.\n");
92 memset(p, 0, alloc_size);
94 dev = (struct net_device *)(((long)p + NETDEV_ALIGN_CONST)
95 & ~NETDEV_ALIGN_CONST);
96 dev->padded = (char *)dev - (char *)p;
99 dev->priv = netdev_priv(dev);
102 strcpy(dev->name, mask);
106 EXPORT_SYMBOL(alloc_netdev);
108 int register_netdev(struct net_device *dev)
115 * If the name is a format string the caller wants us to
116 * do a name allocation
119 if (strchr(dev->name, '%'))
121 err = dev_alloc_name(dev, dev->name);
127 * Back compatibility hook. Kill this one in 2.5
130 if (dev->name[0]==0 || dev->name[0]==' ')
132 err = dev_alloc_name(dev, "eth%d");
137 err = register_netdevice(dev);
144 void unregister_netdev(struct net_device *dev)
147 unregister_netdevice(dev);
151 EXPORT_SYMBOL(register_netdev);
152 EXPORT_SYMBOL(unregister_netdev);