1 /* net_init.c: Initialization for network devices. */
2 /*
3 	Written 1993,1994,1995 by Donald Becker.
4 
5 	The author may be reached as becker@scyld.com, or C/O
6 	Scyld Computing Corporation
7 	410 Severn Ave., Suite 210
8 	Annapolis MD 21403
9 
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.
15 
16 	Modifications/additions by Bjorn Ekwall <bj0rn@blox.se>:
17 		ethdev_index[MAX_ETH_CARDS]
18 		register_netdev() / unregister_netdev()
19 
20 	Modifications by Wolfgang Walter
21 		Use dev_close cleanly so we always shut things down tidily.
22 
23 	Changed 29/10/95, Alan Cox to pass sockaddr's around for mac addresses.
24 
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.
27 
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
33 
34 */
35 
36 #include <linux/config.h>
37 #include <linux/module.h>
38 #include <linux/kernel.h>
39 #include <linux/sched.h>
40 #include <linux/types.h>
41 #include <linux/fs.h>
42 #include <linux/slab.h>
43 #include <linux/if_ether.h>
44 #include <linux/string.h>
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include <linux/fddidevice.h>
48 #include <linux/hippidevice.h>
49 #include <linux/trdevice.h>
50 #include <linux/fcdevice.h>
51 #include <linux/if_arp.h>
52 #include <linux/if_ltalk.h>
53 #include <linux/rtnetlink.h>
54 #include <net/neighbour.h>
55 
56 /* The network devices currently exist only in the socket namespace, so these
57    entries are unused.  The only ones that make sense are
58     open	start the ethercard
59     close	stop  the ethercard
60     ioctl	To get statistics, perhaps set the interface port (AUI, BNC, etc.)
61    One can also imagine getting raw packets using
62     read & write
63    but this is probably better handled by a raw packet socket.
64 
65    Given that almost all of these functions are handled in the current
66    socket-based scheme, putting ethercard devices in /dev/ seems pointless.
67 
68    [Removed all support for /dev network devices. When someone adds
69     streams then by magic we get them, but otherwise they are un-needed
70 	and a space waste]
71 */
72 
73 
alloc_netdev(int sizeof_priv,const char * mask,void (* setup)(struct net_device *))74 struct net_device *alloc_netdev(int sizeof_priv, const char *mask,
75 				       void (*setup)(struct net_device *))
76 {
77 	struct net_device *dev;
78 	int alloc_size;
79 
80 	/* ensure 32-byte alignment of the private area */
81 	alloc_size = sizeof (*dev) + sizeof_priv + 31;
82 
83 	dev = (struct net_device *) kmalloc (alloc_size, GFP_KERNEL);
84 	if (dev == NULL)
85 	{
86 		printk(KERN_ERR "alloc_dev: Unable to allocate device memory.\n");
87 		return NULL;
88 	}
89 
90 	memset(dev, 0, alloc_size);
91 
92 	if (sizeof_priv)
93 		dev->priv = (void *) (((long)(dev + 1) + 31) & ~31);
94 
95 	setup(dev);
96 	strcpy(dev->name, mask);
97 
98 	return dev;
99 }
100 EXPORT_SYMBOL(alloc_netdev);
101 
init_alloc_dev(int sizeof_priv)102 static struct net_device *init_alloc_dev(int sizeof_priv)
103 {
104 	struct net_device *dev;
105 	int alloc_size;
106 
107 	/* ensure 32-byte alignment of the private area */
108 	alloc_size = sizeof (*dev) + sizeof_priv + 31;
109 
110 	dev = (struct net_device *) kmalloc (alloc_size, GFP_KERNEL);
111 	if (dev == NULL)
112 	{
113 		printk(KERN_ERR "alloc_dev: Unable to allocate device memory.\n");
114 		return NULL;
115 	}
116 
117 	memset(dev, 0, alloc_size);
118 
119 	if (sizeof_priv)
120 		dev->priv = (void *) (((long)(dev + 1) + 31) & ~31);
121 
122 	return dev;
123 }
124 
125 /*
126  *	Create and name a device from a prototype, then perform any needed
127  *	setup.
128  */
129 
init_netdev(struct net_device * dev,int sizeof_priv,char * mask,void (* setup)(struct net_device *))130 static struct net_device *init_netdev(struct net_device *dev, int sizeof_priv,
131 				      char *mask, void (*setup)(struct net_device *))
132 {
133 	int new_device = 0;
134 
135 	/*
136 	 *	Allocate a device if one is not provided.
137 	 */
138 
139 	if (dev == NULL) {
140 		dev=init_alloc_dev(sizeof_priv);
141 		if(dev==NULL)
142 			return NULL;
143 		new_device = 1;
144 	}
145 
146 	/*
147 	 *	Allocate a name
148 	 */
149 
150 	if (dev->name[0] == '\0' || dev->name[0] == ' ') {
151 		strcpy(dev->name, mask);
152 		if (dev_alloc_name(dev, mask)<0) {
153 			if (new_device)
154 				kfree(dev);
155 			return NULL;
156 		}
157 	}
158 
159 	netdev_boot_setup_check(dev);
160 
161 	/*
162 	 *	Configure via the caller provided setup function then
163 	 *	register if needed.
164 	 */
165 
166 	setup(dev);
167 
168 	if (new_device) {
169 		int err;
170 
171 		rtnl_lock();
172 		err = register_netdevice(dev);
173 		rtnl_unlock();
174 
175 		if (err < 0) {
176 			kfree(dev);
177 			dev = NULL;
178 		}
179 	}
180 	return dev;
181 }
182 
183 #if defined(CONFIG_HIPPI) || defined(CONFIG_TR) || defined(CONFIG_NET_FC)
__register_netdev(struct net_device * dev)184 static int __register_netdev(struct net_device *dev)
185 {
186 	if (dev->init && dev->init(dev) != 0) {
187 		unregister_netdev(dev);
188 		return -EIO;
189 	}
190 	return 0;
191 }
192 #endif
193 
194 /**
195  * init_etherdev - Register ethernet device
196  * @dev: An ethernet device structure to be filled in, or %NULL if a new
197  *	struct should be allocated.
198  * @sizeof_priv: Size of additional driver-private structure to be allocated
199  *	for this ethernet device
200  *
201  * Fill in the fields of the device structure with ethernet-generic values.
202  *
203  * If no device structure is passed, a new one is constructed, complete with
204  * a private data area of size @sizeof_priv.  A 32-byte (not bit)
205  * alignment is enforced for this private data area.
206  *
207  * If an empty string area is passed as dev->name, or a new structure is made,
208  * a new name string is constructed.
209  */
210 
init_etherdev(struct net_device * dev,int sizeof_priv)211 struct net_device *init_etherdev(struct net_device *dev, int sizeof_priv)
212 {
213 	return init_netdev(dev, sizeof_priv, "eth%d", ether_setup);
214 }
215 
216 /**
217  * alloc_etherdev - Allocates and sets up an ethernet device
218  * @sizeof_priv: Size of additional driver-private structure to be allocated
219  *	for this ethernet device
220  *
221  * Fill in the fields of the device structure with ethernet-generic
222  * values. Basically does everything except registering the device.
223  *
224  * Constructs a new net device, complete with a private data area of
225  * size @sizeof_priv.  A 32-byte (not bit) alignment is enforced for
226  * this private data area.
227  */
228 
alloc_etherdev(int sizeof_priv)229 struct net_device *alloc_etherdev(int sizeof_priv)
230 {
231 	return alloc_netdev(sizeof_priv, "eth%d", ether_setup);
232 }
233 
234 EXPORT_SYMBOL(init_etherdev);
235 EXPORT_SYMBOL(alloc_etherdev);
236 
eth_mac_addr(struct net_device * dev,void * p)237 static int eth_mac_addr(struct net_device *dev, void *p)
238 {
239 	struct sockaddr *addr=p;
240 	if (netif_running(dev))
241 		return -EBUSY;
242 	memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
243 	return 0;
244 }
245 
eth_change_mtu(struct net_device * dev,int new_mtu)246 static int eth_change_mtu(struct net_device *dev, int new_mtu)
247 {
248 	if ((new_mtu < 68) || (new_mtu > 1500))
249 		return -EINVAL;
250 	dev->mtu = new_mtu;
251 	return 0;
252 }
253 
254 #ifdef CONFIG_FDDI
255 
256 /**
257  * init_fddidev - Register FDDI device
258  * @dev: A FDDI device structure to be filled in, or %NULL if a new
259  *	struct should be allocated.
260  * @sizeof_priv: Size of additional driver-private structure to be allocated
261  *	for this ethernet device
262  *
263  * Fill in the fields of the device structure with FDDI-generic values.
264  *
265  * If no device structure is passed, a new one is constructed, complete with
266  * a private data area of size @sizeof_priv.  A 32-byte (not bit)
267  * alignment is enforced for this private data area.
268  *
269  * If an empty string area is passed as dev->name, or a new structure is made,
270  * a new name string is constructed.
271  */
272 
init_fddidev(struct net_device * dev,int sizeof_priv)273 struct net_device *init_fddidev(struct net_device *dev, int sizeof_priv)
274 {
275 	return init_netdev(dev, sizeof_priv, "fddi%d", fddi_setup);
276 }
277 
278 /**
279  * alloc_fddidev - Register FDDI device
280  * @sizeof_priv: Size of additional driver-private structure to be allocated
281  *	for this FDDI device
282  *
283  * Fill in the fields of the device structure with FDDI-generic values.
284  *
285  * Constructs a new net device, complete with a private data area of
286  * size @sizeof_priv.  A 32-byte (not bit) alignment is enforced for
287  * this private data area.
288  */
289 
alloc_fddidev(int sizeof_priv)290 struct net_device *alloc_fddidev(int sizeof_priv)
291 {
292 	return alloc_netdev(sizeof_priv, "fddi%d", fddi_setup);
293 }
294 
295 EXPORT_SYMBOL(init_fddidev);
296 EXPORT_SYMBOL(alloc_fddidev);
297 
fddi_change_mtu(struct net_device * dev,int new_mtu)298 static int fddi_change_mtu(struct net_device *dev, int new_mtu)
299 {
300 	if ((new_mtu < FDDI_K_SNAP_HLEN) || (new_mtu > FDDI_K_SNAP_DLEN))
301 		return(-EINVAL);
302 	dev->mtu = new_mtu;
303 	return(0);
304 }
305 
306 #endif /* CONFIG_FDDI */
307 
308 #ifdef CONFIG_HIPPI
309 
hippi_change_mtu(struct net_device * dev,int new_mtu)310 static int hippi_change_mtu(struct net_device *dev, int new_mtu)
311 {
312 	/*
313 	 * HIPPI's got these nice large MTUs.
314 	 */
315 	if ((new_mtu < 68) || (new_mtu > 65280))
316 		return -EINVAL;
317 	dev->mtu = new_mtu;
318 	return(0);
319 }
320 
321 
322 /*
323  * For HIPPI we will actually use the lower 4 bytes of the hardware
324  * address as the I-FIELD rather than the actual hardware address.
325  */
hippi_mac_addr(struct net_device * dev,void * p)326 static int hippi_mac_addr(struct net_device *dev, void *p)
327 {
328 	struct sockaddr *addr = p;
329 	if (netif_running(dev))
330 		return -EBUSY;
331 	memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
332 	return 0;
333 }
334 
335 
336 /**
337  * init_hippi_dev - Register HIPPI device
338  * @dev: A HIPPI device structure to be filled in, or %NULL if a new
339  *	struct should be allocated.
340  * @sizeof_priv: Size of additional driver-private structure to be allocated
341  *	for this ethernet device
342  *
343  * Fill in the fields of the device structure with HIPPI-generic values.
344  *
345  * If no device structure is passed, a new one is constructed, complete with
346  * a private data area of size @sizeof_priv.  A 32-byte (not bit)
347  * alignment is enforced for this private data area.
348  *
349  * If an empty string area is passed as dev->name, or a new structure is made,
350  * a new name string is constructed.
351  */
352 
init_hippi_dev(struct net_device * dev,int sizeof_priv)353 struct net_device *init_hippi_dev(struct net_device *dev, int sizeof_priv)
354 {
355 	return init_netdev(dev, sizeof_priv, "hip%d", hippi_setup);
356 }
357 
358 /**
359  * alloc_hippi_dev - Register HIPPI device
360  * @sizeof_priv: Size of additional driver-private structure to be allocated
361  *	for this HIPPI device
362  *
363  * Fill in the fields of the device structure with HIPPI-generic values.
364  *
365  * Constructs a new net device, complete with a private data area of
366  * size @sizeof_priv.  A 32-byte (not bit) alignment is enforced for
367  * this private data area.
368  */
369 
alloc_hippi_dev(int sizeof_priv)370 struct net_device *alloc_hippi_dev(int sizeof_priv)
371 {
372 	return alloc_netdev(sizeof_priv, "hip%d", hippi_setup);
373 }
374 
register_hipdev(struct net_device * dev)375 int register_hipdev(struct net_device *dev)
376 {
377 	return __register_netdev(dev);
378 }
379 
unregister_hipdev(struct net_device * dev)380 void unregister_hipdev(struct net_device *dev)
381 {
382 	unregister_netdev(dev);
383 }
384 
385 EXPORT_SYMBOL(init_hippi_dev);
386 EXPORT_SYMBOL(alloc_hippi_dev);
387 EXPORT_SYMBOL(register_hipdev);
388 EXPORT_SYMBOL(unregister_hipdev);
389 
hippi_neigh_setup_dev(struct net_device * dev,struct neigh_parms * p)390 static int hippi_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
391 {
392 	/* Never send broadcast/multicast ARP messages */
393 	p->mcast_probes = 0;
394 
395 	/* In IPv6 unicast probes are valid even on NBMA,
396 	* because they are encapsulated in normal IPv6 protocol.
397 	* Should be a generic flag.
398 	*/
399 	if (p->tbl->family != AF_INET6)
400 		p->ucast_probes = 0;
401 	return 0;
402 }
403 
404 #endif /* CONFIG_HIPPI */
405 
ether_setup(struct net_device * dev)406 void ether_setup(struct net_device *dev)
407 {
408 	/* Fill in the fields of the device structure with ethernet-generic values.
409 	   This should be in a common file instead of per-driver.  */
410 
411 	dev->change_mtu		= eth_change_mtu;
412 	dev->hard_header	= eth_header;
413 	dev->rebuild_header 	= eth_rebuild_header;
414 	dev->set_mac_address 	= eth_mac_addr;
415 	dev->hard_header_cache	= eth_header_cache;
416 	dev->header_cache_update= eth_header_cache_update;
417 	dev->hard_header_parse	= eth_header_parse;
418 
419 	dev->type		= ARPHRD_ETHER;
420 	dev->hard_header_len 	= ETH_HLEN;
421 	dev->mtu		= 1500; /* eth_mtu */
422 	dev->addr_len		= ETH_ALEN;
423 	dev->tx_queue_len	= 1000;	/* Ethernet wants good queues */
424 
425 	memset(dev->broadcast,0xFF, ETH_ALEN);
426 
427 	/* New-style flags. */
428 	dev->flags		= IFF_BROADCAST|IFF_MULTICAST;
429 }
430 EXPORT_SYMBOL(ether_setup);
431 
432 #ifdef CONFIG_FDDI
433 
fddi_setup(struct net_device * dev)434 void fddi_setup(struct net_device *dev)
435 {
436 	/*
437 	 * Fill in the fields of the device structure with FDDI-generic values.
438 	 * This should be in a common file instead of per-driver.
439 	 */
440 
441 	dev->change_mtu			= fddi_change_mtu;
442 	dev->hard_header		= fddi_header;
443 	dev->rebuild_header		= fddi_rebuild_header;
444 
445 	dev->type				= ARPHRD_FDDI;
446 	dev->hard_header_len	= FDDI_K_SNAP_HLEN+3;	/* Assume 802.2 SNAP hdr len + 3 pad bytes */
447 	dev->mtu				= FDDI_K_SNAP_DLEN;		/* Assume max payload of 802.2 SNAP frame */
448 	dev->addr_len			= FDDI_K_ALEN;
449 	dev->tx_queue_len		= 100;	/* Long queues on FDDI */
450 
451 	memset(dev->broadcast, 0xFF, FDDI_K_ALEN);
452 
453 	/* New-style flags */
454 	dev->flags		= IFF_BROADCAST | IFF_MULTICAST;
455 }
456 EXPORT_SYMBOL(fddi_setup);
457 
458 #endif /* CONFIG_FDDI */
459 
460 #ifdef CONFIG_HIPPI
hippi_setup(struct net_device * dev)461 void hippi_setup(struct net_device *dev)
462 {
463 	dev->set_multicast_list	= NULL;
464 	dev->change_mtu			= hippi_change_mtu;
465 	dev->hard_header		= hippi_header;
466 	dev->rebuild_header 		= hippi_rebuild_header;
467 	dev->set_mac_address 		= hippi_mac_addr;
468 	dev->hard_header_parse		= NULL;
469 	dev->hard_header_cache		= NULL;
470 	dev->header_cache_update	= NULL;
471 	dev->neigh_setup 		= hippi_neigh_setup_dev;
472 
473 	/*
474 	 * We don't support HIPPI `ARP' for the time being, and probably
475 	 * never will unless someone else implements it. However we
476 	 * still need a fake ARPHRD to make ifconfig and friends play ball.
477 	 */
478 	dev->type		= ARPHRD_HIPPI;
479 	dev->hard_header_len 	= HIPPI_HLEN;
480 	dev->mtu		= 65280;
481 	dev->addr_len		= HIPPI_ALEN;
482 	dev->tx_queue_len	= 25 /* 5 */;
483 	memset(dev->broadcast, 0xFF, HIPPI_ALEN);
484 
485 
486 	/*
487 	 * HIPPI doesn't support broadcast+multicast and we only use
488 	 * static ARP tables. ARP is disabled by hippi_neigh_setup_dev.
489 	 */
490 	dev->flags = 0;
491 }
492 EXPORT_SYMBOL(hippi_setup);
493 #endif /* CONFIG_HIPPI */
494 
495 #if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
496 
ltalk_change_mtu(struct net_device * dev,int mtu)497 static int ltalk_change_mtu(struct net_device *dev, int mtu)
498 {
499 	return -EINVAL;
500 }
501 
ltalk_mac_addr(struct net_device * dev,void * addr)502 static int ltalk_mac_addr(struct net_device *dev, void *addr)
503 {
504 	return -EINVAL;
505 }
506 
507 
ltalk_setup(struct net_device * dev)508 void ltalk_setup(struct net_device *dev)
509 {
510 	/* Fill in the fields of the device structure with localtalk-generic values. */
511 
512 	dev->change_mtu		= ltalk_change_mtu;
513 	dev->hard_header	= NULL;
514 	dev->rebuild_header 	= NULL;
515 	dev->set_mac_address 	= ltalk_mac_addr;
516 	dev->hard_header_cache	= NULL;
517 	dev->header_cache_update= NULL;
518 
519 	dev->type		= ARPHRD_LOCALTLK;
520 	dev->hard_header_len 	= LTALK_HLEN;
521 	dev->mtu		= LTALK_MTU;
522 	dev->addr_len		= LTALK_ALEN;
523 	dev->tx_queue_len	= 10;
524 
525 	dev->broadcast[0]	= 0xFF;
526 
527 	dev->flags		= IFF_BROADCAST|IFF_MULTICAST|IFF_NOARP;
528 }
529 EXPORT_SYMBOL(ltalk_setup);
530 
531 #endif /* CONFIG_ATALK || CONFIG_ATALK_MODULE */
532 
register_netdev(struct net_device * dev)533 int register_netdev(struct net_device *dev)
534 {
535 	int err;
536 
537 	rtnl_lock();
538 
539 	/*
540 	 *	If the name is a format string the caller wants us to
541 	 *	do a name allocation
542 	 */
543 
544 	if (strchr(dev->name, '%'))
545 	{
546 		err = dev_alloc_name(dev, dev->name);
547 		if (err < 0)
548 			goto out;
549 	}
550 
551 	/*
552 	 *	Back compatibility hook. Kill this one in 2.5
553 	 */
554 
555 	if (dev->name[0]==0 || dev->name[0]==' ')
556 	{
557 		err = dev_alloc_name(dev, "eth%d");
558 		if (err < 0)
559 			goto out;
560 	}
561 
562 	err = register_netdevice(dev);
563 
564 out:
565 	rtnl_unlock();
566 	return err;
567 }
568 
unregister_netdev(struct net_device * dev)569 void unregister_netdev(struct net_device *dev)
570 {
571 	rtnl_lock();
572 	unregister_netdevice(dev);
573 	rtnl_unlock();
574 }
575 
576 EXPORT_SYMBOL(register_netdev);
577 EXPORT_SYMBOL(unregister_netdev);
578 
579 #ifdef CONFIG_TR
580 
tr_setup(struct net_device * dev)581 void tr_setup(struct net_device *dev)
582 {
583 	/*
584 	 *	Configure and register
585 	 */
586 
587 	dev->hard_header	= tr_header;
588 	dev->rebuild_header	= tr_rebuild_header;
589 
590 	dev->type		= ARPHRD_IEEE802_TR;
591 	dev->hard_header_len	= TR_HLEN;
592 	dev->mtu		= 2000;
593 	dev->addr_len		= TR_ALEN;
594 	dev->tx_queue_len	= 100;	/* Long queues on tr */
595 
596 	memset(dev->broadcast,0xFF, TR_ALEN);
597 
598 	/* New-style flags. */
599 	dev->flags		= IFF_BROADCAST | IFF_MULTICAST ;
600 }
601 
602 /**
603  * init_trdev - Register token ring device
604  * @dev: A token ring device structure to be filled in, or %NULL if a new
605  *	struct should be allocated.
606  * @sizeof_priv: Size of additional driver-private structure to be allocated
607  *	for this ethernet device
608  *
609  * Fill in the fields of the device structure with token ring-generic values.
610  *
611  * If no device structure is passed, a new one is constructed, complete with
612  * a private data area of size @sizeof_priv.  A 32-byte (not bit)
613  * alignment is enforced for this private data area.
614  *
615  * If an empty string area is passed as dev->name, or a new structure is made,
616  * a new name string is constructed.
617  */
618 
init_trdev(struct net_device * dev,int sizeof_priv)619 struct net_device *init_trdev(struct net_device *dev, int sizeof_priv)
620 {
621 	return init_netdev(dev, sizeof_priv, "tr%d", tr_setup);
622 }
623 
624 /**
625  * alloc_trdev - Register token ring device
626  * @sizeof_priv: Size of additional driver-private structure to be allocated
627  *	for this token ring device
628  *
629  * Fill in the fields of the device structure with token ring-generic values.
630  *
631  * Constructs a new net device, complete with a private data area of
632  * size @sizeof_priv.  A 32-byte (not bit) alignment is enforced for
633  * this private data area.
634  */
635 
alloc_trdev(int sizeof_priv)636 struct net_device *alloc_trdev(int sizeof_priv)
637 {
638 	return alloc_netdev(sizeof_priv, "tr%d", tr_setup);
639 }
640 
register_trdev(struct net_device * dev)641 int register_trdev(struct net_device *dev)
642 {
643 	return __register_netdev(dev);
644 }
645 
unregister_trdev(struct net_device * dev)646 void unregister_trdev(struct net_device *dev)
647 {
648 	unregister_netdev(dev);
649 }
650 
651 EXPORT_SYMBOL(tr_setup);
652 EXPORT_SYMBOL(init_trdev);
653 EXPORT_SYMBOL(alloc_trdev);
654 EXPORT_SYMBOL(register_trdev);
655 EXPORT_SYMBOL(unregister_trdev);
656 
657 #endif /* CONFIG_TR */
658 
659 
660 #ifdef CONFIG_NET_FC
661 
fc_setup(struct net_device * dev)662 void fc_setup(struct net_device *dev)
663 {
664 	dev->hard_header        =        fc_header;
665         dev->rebuild_header  	=        fc_rebuild_header;
666 
667         dev->type               =        ARPHRD_IEEE802;
668 	dev->hard_header_len    =        FC_HLEN;
669         dev->mtu                =        2024;
670         dev->addr_len           =        FC_ALEN;
671         dev->tx_queue_len       =        100; /* Long queues on fc */
672 
673         memset(dev->broadcast,0xFF, FC_ALEN);
674 
675         /* New-style flags. */
676         dev->flags              =        IFF_BROADCAST;
677 }
678 
679 /**
680  * init_fcdev - Register fibre channel device
681  * @dev: A fibre channel device structure to be filled in, or %NULL if a new
682  *	struct should be allocated.
683  * @sizeof_priv: Size of additional driver-private structure to be allocated
684  *	for this ethernet device
685  *
686  * Fill in the fields of the device structure with fibre channel-generic values.
687  *
688  * If no device structure is passed, a new one is constructed, complete with
689  * a private data area of size @sizeof_priv.  A 32-byte (not bit)
690  * alignment is enforced for this private data area.
691  *
692  * If an empty string area is passed as dev->name, or a new structure is made,
693  * a new name string is constructed.
694  */
695 
init_fcdev(struct net_device * dev,int sizeof_priv)696 struct net_device *init_fcdev(struct net_device *dev, int sizeof_priv)
697 {
698 	return init_netdev(dev, sizeof_priv, "fc%d", fc_setup);
699 }
700 
701 /**
702  * alloc_fcdev - Register fibre channel device
703  * @sizeof_priv: Size of additional driver-private structure to be allocated
704  *	for this fibre channel device
705  *
706  * Fill in the fields of the device structure with fibre channel-generic values.
707  *
708  * Constructs a new net device, complete with a private data area of
709  * size @sizeof_priv.  A 32-byte (not bit) alignment is enforced for
710  * this private data area.
711  */
712 
alloc_fcdev(int sizeof_priv)713 struct net_device *alloc_fcdev(int sizeof_priv)
714 {
715 	return alloc_netdev(sizeof_priv, "fc%d", fc_setup);
716 }
717 
register_fcdev(struct net_device * dev)718 int register_fcdev(struct net_device *dev)
719 {
720 	return __register_netdev(dev);
721 }
722 
unregister_fcdev(struct net_device * dev)723 void unregister_fcdev(struct net_device *dev)
724 {
725 	unregister_netdev(dev);
726 }
727 
728 EXPORT_SYMBOL(fc_setup);
729 EXPORT_SYMBOL(init_fcdev);
730 EXPORT_SYMBOL(alloc_fcdev);
731 EXPORT_SYMBOL(register_fcdev);
732 EXPORT_SYMBOL(unregister_fcdev);
733 
734 #endif /* CONFIG_NET_FC */
735 
736