Import 2.1.116pre2
[davej-history.git] / net / core / dev.c
blob316f6d799bfb2b473d90c6ddcddb0185db084f83
1 /*
2 * NET3 Protocol independent device support routines.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Derived from the non IP parts of dev.c 1.0.19
10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 * Mark Evans, <evansmp@uhura.aston.ac.uk>
14 * Additional Authors:
15 * Florian la Roche <rzsfl@rz.uni-sb.de>
16 * Alan Cox <gw4pts@gw4pts.ampr.org>
17 * David Hinds <dhinds@allegro.stanford.edu>
18 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
20 * Changes:
21 * Alan Cox : device private ioctl copies fields back.
22 * Alan Cox : Transmit queue code does relevant stunts to
23 * keep the queue safe.
24 * Alan Cox : Fixed double lock.
25 * Alan Cox : Fixed promisc NULL pointer trap
26 * ???????? : Support the full private ioctl range
27 * Alan Cox : Moved ioctl permission check into drivers
28 * Tim Kordas : SIOCADDMULTI/SIOCDELMULTI
29 * Alan Cox : 100 backlog just doesn't cut it when
30 * you start doing multicast video 8)
31 * Alan Cox : Rewrote net_bh and list manager.
32 * Alan Cox : Fix ETH_P_ALL echoback lengths.
33 * Alan Cox : Took out transmit every packet pass
34 * Saved a few bytes in the ioctl handler
35 * Alan Cox : Network driver sets packet type before calling netif_rx. Saves
36 * a function call a packet.
37 * Alan Cox : Hashed net_bh()
38 * Richard Kooijman: Timestamp fixes.
39 * Alan Cox : Wrong field in SIOCGIFDSTADDR
40 * Alan Cox : Device lock protection.
41 * Alan Cox : Fixed nasty side effect of device close changes.
42 * Rudi Cilibrasi : Pass the right thing to set_mac_address()
43 * Dave Miller : 32bit quantity for the device lock to make it work out
44 * on a Sparc.
45 * Bjorn Ekwall : Added KERNELD hack.
46 * Alan Cox : Cleaned up the backlog initialise.
47 * Craig Metz : SIOCGIFCONF fix if space for under
48 * 1 device.
49 * Thomas Bogendoerfer : Return ENODEV for dev_open, if there
50 * is no device open function.
51 * Andi Kleen : Fix error reporting for SIOCGIFCONF
52 * Michael Chastain : Fix signed/unsigned for SIOCGIFCONF
53 * Cyrus Durgin : Cleaned for KMOD
57 #include <asm/uaccess.h>
58 #include <asm/system.h>
59 #include <asm/bitops.h>
60 #include <linux/config.h>
61 #include <linux/types.h>
62 #include <linux/kernel.h>
63 #include <linux/sched.h>
64 #include <linux/string.h>
65 #include <linux/mm.h>
66 #include <linux/socket.h>
67 #include <linux/sockios.h>
68 #include <linux/errno.h>
69 #include <linux/interrupt.h>
70 #include <linux/if_ether.h>
71 #include <linux/netdevice.h>
72 #include <linux/etherdevice.h>
73 #include <linux/notifier.h>
74 #include <linux/skbuff.h>
75 #include <net/sock.h>
76 #include <linux/rtnetlink.h>
77 #include <net/slhc.h>
78 #include <linux/proc_fs.h>
79 #include <linux/stat.h>
80 #include <net/br.h>
81 #include <net/dst.h>
82 #include <net/pkt_sched.h>
83 #include <net/profile.h>
84 #include <linux/init.h>
85 #include <linux/kmod.h>
86 #ifdef CONFIG_NET_RADIO
87 #include <linux/wireless.h>
88 #endif /* CONFIG_NET_RADIO */
89 #ifdef CONFIG_PLIP
90 extern int plip_init(void);
91 #endif
93 NET_PROFILE_DEFINE(dev_queue_xmit)
94 NET_PROFILE_DEFINE(net_bh)
95 NET_PROFILE_DEFINE(net_bh_skb)
98 const char *if_port_text[] = {
99 "unknown",
100 "BNC",
101 "10baseT",
102 "AUI",
103 "100baseT",
104 "100baseTX",
105 "100baseFX"
109 * The list of packet types we will receive (as opposed to discard)
110 * and the routines to invoke.
112 * Why 16. Because with 16 the only overlap we get on a hash of the
113 * low nibble of the protocol value is RARP/SNAP/X.25.
115 * 0800 IP
116 * 0001 802.3
117 * 0002 AX.25
118 * 0004 802.2
119 * 8035 RARP
120 * 0005 SNAP
121 * 0805 X.25
122 * 0806 ARP
123 * 8137 IPX
124 * 0009 Localtalk
125 * 86DD IPv6
128 struct packet_type *ptype_base[16]; /* 16 way hashed list */
129 struct packet_type *ptype_all = NULL; /* Taps */
132 * Device list lock. Setting it provides that interface
133 * will not disappear unexpectedly while kernel sleeps.
136 atomic_t dev_lockct = ATOMIC_INIT(0);
139 * Our notifier list
142 static struct notifier_block *netdev_chain=NULL;
145 * Device drivers call our routines to queue packets here. We empty the
146 * queue in the bottom half handler.
149 static struct sk_buff_head backlog;
151 #ifdef CONFIG_NET_FASTROUTE
152 int netdev_fastroute;
153 int netdev_fastroute_obstacles;
154 struct net_fastroute_stats dev_fastroute_stat;
155 #endif
158 /******************************************************************************************
160 Protocol management and registration routines
162 *******************************************************************************************/
165 * For efficiency
168 int netdev_nit=0;
171 * Add a protocol ID to the list. Now that the input handler is
172 * smarter we can dispense with all the messy stuff that used to be
173 * here.
176 void dev_add_pack(struct packet_type *pt)
178 int hash;
179 #ifdef CONFIG_NET_FASTROUTE
180 /* Hack to detect packet socket */
181 if (pt->data) {
182 netdev_fastroute_obstacles++;
183 dev_clear_fastroute(pt->dev);
185 #endif
186 if(pt->type==htons(ETH_P_ALL))
188 netdev_nit++;
189 pt->next=ptype_all;
190 ptype_all=pt;
192 else
194 hash=ntohs(pt->type)&15;
195 pt->next = ptype_base[hash];
196 ptype_base[hash] = pt;
202 * Remove a protocol ID from the list.
205 void dev_remove_pack(struct packet_type *pt)
207 struct packet_type **pt1;
208 if(pt->type==htons(ETH_P_ALL))
210 netdev_nit--;
211 pt1=&ptype_all;
213 else
214 pt1=&ptype_base[ntohs(pt->type)&15];
215 for(; (*pt1)!=NULL; pt1=&((*pt1)->next))
217 if(pt==(*pt1))
219 *pt1=pt->next;
220 #ifdef CONFIG_NET_FASTROUTE
221 if (pt->data)
222 netdev_fastroute_obstacles--;
223 #endif
224 return;
227 printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt);
230 /*****************************************************************************************
232 Device Interface Subroutines
234 ******************************************************************************************/
237 * Find an interface by name.
240 struct device *dev_get(const char *name)
242 struct device *dev;
244 for (dev = dev_base; dev != NULL; dev = dev->next)
246 if (strcmp(dev->name, name) == 0)
247 return(dev);
249 return NULL;
252 struct device * dev_get_by_index(int ifindex)
254 struct device *dev;
256 for (dev = dev_base; dev != NULL; dev = dev->next)
258 if (dev->ifindex == ifindex)
259 return(dev);
261 return NULL;
264 struct device *dev_getbyhwaddr(unsigned short type, char *ha)
266 struct device *dev;
268 for (dev = dev_base; dev != NULL; dev = dev->next)
270 if (dev->type == type &&
271 memcmp(dev->dev_addr, ha, dev->addr_len) == 0)
272 return(dev);
274 return(NULL);
278 * Passed a format string - eg "lt%d" it will try and find a suitable
279 * id. Not efficient for many devices, not called a lot..
282 int dev_alloc_name(struct device *dev, const char *name)
284 int i;
286 * If you need over 100 please also fix the algorithm...
288 for(i=0;i<100;i++)
290 sprintf(dev->name,name,i);
291 if(dev_get(dev->name)==NULL)
292 return i;
294 return -ENFILE; /* Over 100 of the things .. bail out! */
297 struct device *dev_alloc(const char *name, int *err)
299 struct device *dev=kmalloc(sizeof(struct device)+16, GFP_KERNEL);
300 if(dev==NULL)
302 *err=-ENOBUFS;
303 return NULL;
305 dev->name=(char *)(dev+1); /* Name string space */
306 *err=dev_alloc_name(dev,name);
307 if(*err<0)
309 kfree(dev);
310 return NULL;
312 return dev;
317 * Find and possibly load an interface.
320 #ifdef CONFIG_KMOD
322 void dev_load(const char *name)
324 if(!dev_get(name) && capable(CAP_SYS_MODULE))
325 request_module(name);
328 #else
330 extern inline void dev_load(const char *unused){;}
332 #endif
334 static int default_rebuild_header(struct sk_buff *skb)
336 printk(KERN_DEBUG "%s: default_rebuild_header called -- BUG!\n", skb->dev ? skb->dev->name : "NULL!!!");
337 kfree_skb(skb);
338 return 1;
342 * Prepare an interface for use.
345 int dev_open(struct device *dev)
347 int ret = 0;
350 * Is it already up?
353 if (dev->flags&IFF_UP)
354 return 0;
357 * Call device private open method
360 if (dev->open)
361 ret = dev->open(dev);
364 * If it went open OK then:
367 if (ret == 0)
370 * nil rebuild_header routine,
371 * that should be never called and used as just bug trap.
374 if (dev->rebuild_header == NULL)
375 dev->rebuild_header = default_rebuild_header;
378 * Set the flags.
380 dev->flags |= (IFF_UP | IFF_RUNNING);
383 * Initialize multicasting status
385 dev_mc_upload(dev);
388 * Wakeup transmit queue engine
390 dev_activate(dev);
393 * ... and announce new interface.
395 notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
398 return(ret);
401 #ifdef CONFIG_NET_FASTROUTE
403 static __inline__ void dev_do_clear_fastroute(struct device *dev)
405 if (dev->accept_fastpath) {
406 int i;
408 for (i=0; i<=NETDEV_FASTROUTE_HMASK; i++)
409 dst_release(xchg(dev->fastpath+i, NULL));
413 void dev_clear_fastroute(struct device *dev)
415 if (dev) {
416 dev_do_clear_fastroute(dev);
417 } else {
418 for (dev = dev_base; dev; dev = dev->next)
419 dev_do_clear_fastroute(dev);
422 #endif
425 * Completely shutdown an interface.
428 int dev_close(struct device *dev)
430 if (!(dev->flags&IFF_UP))
431 return 0;
433 dev_deactivate(dev);
435 dev_lock_wait();
438 * Call the device specific close. This cannot fail.
439 * Only if device is UP
442 if (dev->stop)
443 dev->stop(dev);
445 if (dev->start)
446 printk("dev_close: bug %s still running\n", dev->name);
449 * Device is now down.
452 dev->flags&=~(IFF_UP|IFF_RUNNING);
453 #ifdef CONFIG_NET_FASTROUTE
454 dev_clear_fastroute(dev);
455 #endif
458 * Tell people we are going down
461 notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
463 return(0);
468 * Device change register/unregister. These are not inline or static
469 * as we export them to the world.
472 int register_netdevice_notifier(struct notifier_block *nb)
474 return notifier_chain_register(&netdev_chain, nb);
477 int unregister_netdevice_notifier(struct notifier_block *nb)
479 return notifier_chain_unregister(&netdev_chain,nb);
483 * Support routine. Sends outgoing frames to any network
484 * taps currently in use.
487 void dev_queue_xmit_nit(struct sk_buff *skb, struct device *dev)
489 struct packet_type *ptype;
490 get_fast_time(&skb->stamp);
492 for (ptype = ptype_all; ptype!=NULL; ptype = ptype->next)
494 /* Never send packets back to the socket
495 * they originated from - MvS (miquels@drinkel.ow.org)
497 if ((ptype->dev == dev || !ptype->dev) &&
498 ((struct sock *)ptype->data != skb->sk))
500 struct sk_buff *skb2;
501 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL)
502 break;
504 /* Code, following below is wrong.
506 The only reason, why it does work is that
507 ONLY packet sockets receive outgoing
508 packets. If such a packet will be (occasionally)
509 received by normal packet handler, which expects
510 that mac header is pulled...
513 /* More sensible variant. skb->nh should be correctly
514 set by sender, so that the second statement is
515 just protection against buggy protocols.
517 skb2->mac.raw = skb2->data;
519 if (skb2->nh.raw < skb2->data || skb2->nh.raw >= skb2->tail) {
520 if (net_ratelimit())
521 printk(KERN_DEBUG "protocol %04x is buggy, dev %s\n", skb2->protocol, dev->name);
522 skb2->nh.raw = skb2->data;
523 if (dev->hard_header)
524 skb2->nh.raw += dev->hard_header_len;
527 skb2->h.raw = skb2->nh.raw;
528 skb2->pkt_type = PACKET_OUTGOING;
529 ptype->func(skb2, skb->dev, ptype);
535 * Fast path for loopback frames.
538 void dev_loopback_xmit(struct sk_buff *skb)
540 struct sk_buff *newskb=skb_clone(skb, GFP_ATOMIC);
541 if (newskb==NULL)
542 return;
544 newskb->mac.raw = newskb->data;
545 skb_pull(newskb, newskb->nh.raw - newskb->data);
546 newskb->pkt_type = PACKET_LOOPBACK;
547 newskb->ip_summed = CHECKSUM_UNNECESSARY;
548 if (newskb->dst==NULL)
549 printk(KERN_DEBUG "BUG: packet without dst looped back 1\n");
550 netif_rx(newskb);
553 int dev_queue_xmit(struct sk_buff *skb)
555 struct device *dev = skb->dev;
556 struct Qdisc *q;
558 #ifdef CONFIG_NET_PROFILE
559 start_bh_atomic();
560 NET_PROFILE_ENTER(dev_queue_xmit);
561 #endif
563 start_bh_atomic();
564 q = dev->qdisc;
565 if (q->enqueue) {
566 q->enqueue(skb, q);
567 qdisc_wakeup(dev);
568 end_bh_atomic();
570 #ifdef CONFIG_NET_PROFILE
571 NET_PROFILE_LEAVE(dev_queue_xmit);
572 end_bh_atomic();
573 #endif
575 return 0;
578 /* The device has no queue. Common case for software devices:
579 loopback, all the sorts of tunnels...
581 Really, it is unlikely that bh protection is necessary here:
582 virtual devices do not generate EOI events.
583 However, it is possible, that they rely on bh protection
584 made by us here.
586 if (dev->flags&IFF_UP) {
587 if (netdev_nit)
588 dev_queue_xmit_nit(skb,dev);
589 if (dev->hard_start_xmit(skb, dev) == 0) {
590 end_bh_atomic();
592 #ifdef CONFIG_NET_PROFILE
593 NET_PROFILE_LEAVE(dev_queue_xmit);
594 end_bh_atomic();
595 #endif
597 return 0;
599 if (net_ratelimit())
600 printk(KERN_DEBUG "Virtual device %s asks to queue packet!\n", dev->name);
602 end_bh_atomic();
604 kfree_skb(skb);
606 #ifdef CONFIG_NET_PROFILE
607 NET_PROFILE_LEAVE(dev_queue_xmit);
608 end_bh_atomic();
609 #endif
611 return 0;
615 /*=======================================================================
616 Receiver rotutines
617 =======================================================================*/
619 int netdev_dropping = 0;
620 int netdev_max_backlog = 300;
621 atomic_t netdev_rx_dropped;
622 #ifdef CONFIG_CPU_IS_SLOW
623 int net_cpu_congestion;
624 #endif
626 #ifdef CONFIG_NET_HW_FLOWCONTROL
627 int netdev_throttle_events;
628 static unsigned long netdev_fc_mask = 1;
629 unsigned long netdev_fc_xoff = 0;
631 static struct
633 void (*stimul)(struct device *);
634 struct device *dev;
635 } netdev_fc_slots[32];
637 int netdev_register_fc(struct device *dev, void (*stimul)(struct device *dev))
639 int bit = 0;
640 unsigned long flags;
642 save_flags(flags);
643 cli();
644 if (netdev_fc_mask != ~0UL) {
645 bit = ffz(netdev_fc_mask);
646 netdev_fc_slots[bit].stimul = stimul;
647 netdev_fc_slots[bit].dev = dev;
648 set_bit(bit, &netdev_fc_mask);
649 clear_bit(bit, &netdev_fc_xoff);
651 restore_flags(flags);
652 return bit;
655 void netdev_unregister_fc(int bit)
657 unsigned long flags;
659 save_flags(flags);
660 cli();
661 if (bit > 0) {
662 netdev_fc_slots[bit].stimul = NULL;
663 netdev_fc_slots[bit].dev = NULL;
664 clear_bit(bit, &netdev_fc_mask);
665 clear_bit(bit, &netdev_fc_xoff);
667 restore_flags(flags);
670 static void netdev_wakeup(void)
672 unsigned long xoff;
674 cli();
675 xoff = netdev_fc_xoff;
676 netdev_fc_xoff = 0;
677 netdev_dropping = 0;
678 netdev_throttle_events++;
679 while (xoff) {
680 int i = ffz(~xoff);
681 xoff &= ~(1<<i);
682 netdev_fc_slots[i].stimul(netdev_fc_slots[i].dev);
684 sti();
686 #endif
690 * Receive a packet from a device driver and queue it for the upper
691 * (protocol) levels. It always succeeds.
694 void netif_rx(struct sk_buff *skb)
696 #ifndef CONFIG_CPU_IS_SLOW
697 if(skb->stamp.tv_sec==0)
698 get_fast_time(&skb->stamp);
699 #else
700 skb->stamp = xtime;
701 #endif
703 /* The code is rearranged so that the path is the most
704 short when CPU is congested, but is still operating.
707 if (backlog.qlen <= netdev_max_backlog) {
708 if (backlog.qlen) {
709 if (netdev_dropping == 0) {
710 skb_queue_tail(&backlog,skb);
711 mark_bh(NET_BH);
712 return;
714 atomic_inc(&netdev_rx_dropped);
715 kfree_skb(skb);
716 return;
718 #ifdef CONFIG_NET_HW_FLOWCONTROL
719 if (netdev_dropping)
720 netdev_wakeup();
721 #else
722 netdev_dropping = 0;
723 #endif
724 skb_queue_tail(&backlog,skb);
725 mark_bh(NET_BH);
726 return;
728 netdev_dropping = 1;
729 atomic_inc(&netdev_rx_dropped);
730 kfree_skb(skb);
733 #ifdef CONFIG_BRIDGE
734 static inline void handle_bridge(struct sk_buff *skb, unsigned short type)
736 if (br_stats.flags & BR_UP && br_protocol_ok(ntohs(type)))
739 * We pass the bridge a complete frame. This means
740 * recovering the MAC header first.
743 int offset;
745 skb=skb_clone(skb, GFP_ATOMIC);
746 if(skb==NULL)
747 return;
749 offset=skb->data-skb->mac.raw;
750 skb_push(skb,offset); /* Put header back on for bridge */
752 if(br_receive_frame(skb))
753 return;
754 kfree_skb(skb, FREE_READ);
756 return;
758 #endif
762 * When we are called the queue is ready to grab, the interrupts are
763 * on and hardware can interrupt and queue to the receive queue as we
764 * run with no problems.
765 * This is run as a bottom half after an interrupt handler that does
766 * mark_bh(NET_BH);
769 void net_bh(void)
771 struct packet_type *ptype;
772 struct packet_type *pt_prev;
773 unsigned short type;
774 unsigned long start_time = jiffies;
775 #ifdef CONFIG_CPU_IS_SLOW
776 static unsigned long start_busy = 0;
777 static unsigned long ave_busy = 0;
779 if (start_busy == 0)
780 start_busy = start_time;
781 net_cpu_congestion = ave_busy>>8;
782 #endif
784 NET_PROFILE_ENTER(net_bh);
786 * Can we send anything now? We want to clear the
787 * decks for any more sends that get done as we
788 * process the input. This also minimises the
789 * latency on a transmit interrupt bh.
792 if (qdisc_head.forw != &qdisc_head)
793 qdisc_run_queues();
796 * Any data left to process. This may occur because a
797 * mark_bh() is done after we empty the queue including
798 * that from the device which does a mark_bh() just after
802 * While the queue is not empty..
804 * Note that the queue never shrinks due to
805 * an interrupt, so we can do this test without
806 * disabling interrupts.
809 while (!skb_queue_empty(&backlog))
811 struct sk_buff * skb;
813 /* Give chance to other bottom halves to run */
814 if (jiffies - start_time > 1)
815 goto net_bh_break;
818 * We have a packet. Therefore the queue has shrunk
820 skb = skb_dequeue(&backlog);
822 #ifdef CONFIG_CPU_IS_SLOW
823 if (ave_busy > 128*16) {
824 kfree_skb(skb);
825 while ((skb = skb_dequeue(&backlog)) != NULL)
826 kfree_skb(skb);
827 break;
829 #endif
832 #if 0
833 NET_PROFILE_SKB_PASSED(skb, net_bh_skb);
834 #endif
835 #ifdef CONFIG_NET_FASTROUTE
836 if (skb->pkt_type == PACKET_FASTROUTE) {
837 dev_queue_xmit(skb);
838 continue;
840 #endif
843 * Fetch the packet protocol ID.
846 type = skb->protocol;
849 #ifdef CONFIG_BRIDGE
851 * If we are bridging then pass the frame up to the
852 * bridging code (if this protocol is to be bridged).
853 * If it is bridged then move on
855 handle_bridge(skb, type);
856 #endif
859 * Bump the pointer to the next structure.
861 * On entry to the protocol layer. skb->data and
862 * skb->nh.raw point to the MAC and encapsulated data
865 /* XXX until we figure out every place to modify.. */
866 skb->h.raw = skb->nh.raw = skb->data;
868 if (skb->mac.raw < skb->head || skb->mac.raw > skb->data) {
869 printk(KERN_CRIT "%s: wrong mac.raw ptr, proto=%04x\n", skb->dev->name, skb->protocol);
870 kfree_skb(skb);
871 continue;
875 * We got a packet ID. Now loop over the "known protocols"
876 * list. There are two lists. The ptype_all list of taps (normally empty)
877 * and the main protocol list which is hashed perfectly for normal protocols.
880 pt_prev = NULL;
881 for (ptype = ptype_all; ptype!=NULL; ptype=ptype->next)
883 if (!ptype->dev || ptype->dev == skb->dev) {
884 if(pt_prev)
886 struct sk_buff *skb2=skb_clone(skb, GFP_ATOMIC);
887 if(skb2)
888 pt_prev->func(skb2,skb->dev, pt_prev);
890 pt_prev=ptype;
894 for (ptype = ptype_base[ntohs(type)&15]; ptype != NULL; ptype = ptype->next)
896 if (ptype->type == type && (!ptype->dev || ptype->dev==skb->dev))
899 * We already have a match queued. Deliver
900 * to it and then remember the new match
902 if(pt_prev)
904 struct sk_buff *skb2;
906 skb2=skb_clone(skb, GFP_ATOMIC);
909 * Kick the protocol handler. This should be fast
910 * and efficient code.
913 if(skb2)
914 pt_prev->func(skb2, skb->dev, pt_prev);
916 /* Remember the current last to do */
917 pt_prev=ptype;
919 } /* End of protocol list loop */
922 * Is there a last item to send to ?
925 if(pt_prev)
926 pt_prev->func(skb, skb->dev, pt_prev);
928 * Has an unknown packet has been received ?
931 else {
932 kfree_skb(skb);
934 } /* End of queue loop */
937 * We have emptied the queue
941 * One last output flush.
944 if (qdisc_head.forw != &qdisc_head)
945 qdisc_run_queues();
947 #ifdef CONFIG_CPU_IS_SLOW
948 if (1) {
949 unsigned long start_idle = jiffies;
950 ave_busy += ((start_idle - start_busy)<<3) - (ave_busy>>4);
951 start_busy = 0;
953 #endif
954 #ifdef CONFIG_NET_HW_FLOWCONTROL
955 if (netdev_dropping)
956 netdev_wakeup();
957 #else
958 netdev_dropping = 0;
959 #endif
960 NET_PROFILE_LEAVE(net_bh);
961 return;
963 net_bh_break:
964 mark_bh(NET_BH);
965 NET_PROFILE_LEAVE(net_bh);
966 return;
969 /* Protocol dependent address dumping routines */
971 static gifconf_func_t * gifconf_list [NPROTO];
973 int register_gifconf(unsigned int family, gifconf_func_t * gifconf)
975 if (family>=NPROTO)
976 return -EINVAL;
977 gifconf_list[family] = gifconf;
978 return 0;
983 * Map an interface index to its name (SIOCGIFNAME)
987 * This call is useful, but I'd remove it too.
989 * The reason is purely aestetical, it is the only call
990 * from SIOC* family using struct ifreq in reversed manner.
991 * Besides that, it is pretty silly to put "drawing" facility
992 * to kernel, it is useful only to print ifindices
993 * in readable form, is not it? --ANK
995 * We need this ioctl for efficient implementation of the
996 * if_indextoname() function required by the IPv6 API. Without
997 * it, we would have to search all the interfaces to find a
998 * match. --pb
1001 static int dev_ifname(struct ifreq *arg)
1003 struct device *dev;
1004 struct ifreq ifr;
1005 int err;
1008 * Fetch the caller's info block.
1011 err = copy_from_user(&ifr, arg, sizeof(struct ifreq));
1012 if (err)
1013 return -EFAULT;
1015 dev = dev_get_by_index(ifr.ifr_ifindex);
1016 if (!dev)
1017 return -ENODEV;
1019 strcpy(ifr.ifr_name, dev->name);
1021 err = copy_to_user(arg, &ifr, sizeof(struct ifreq));
1022 return (err)?-EFAULT:0;
1026 * Perform a SIOCGIFCONF call. This structure will change
1027 * size eventually, and there is nothing I can do about it.
1028 * Thus we will need a 'compatibility mode'.
1031 static int dev_ifconf(char *arg)
1033 struct ifconf ifc;
1034 struct device *dev;
1035 char *pos;
1036 int len;
1037 int total;
1038 int i;
1041 * Fetch the caller's info block.
1044 if (copy_from_user(&ifc, arg, sizeof(struct ifconf)))
1045 return -EFAULT;
1047 pos = ifc.ifc_buf;
1048 len = ifc.ifc_len;
1051 * Loop over the interfaces, and write an info block for each.
1054 total = 0;
1055 for (dev = dev_base; dev != NULL; dev = dev->next) {
1056 for (i=0; i<NPROTO; i++) {
1057 if (gifconf_list[i]) {
1058 int done;
1059 if (pos==NULL) {
1060 done = gifconf_list[i](dev, NULL, 0);
1061 } else {
1062 done = gifconf_list[i](dev, pos+total, len-total);
1064 if (done<0)
1065 return -EFAULT;
1066 total += done;
1072 * All done. Write the updated control block back to the caller.
1074 ifc.ifc_len = total;
1076 if (copy_to_user(arg, &ifc, sizeof(struct ifconf)))
1077 return -EFAULT;
1080 * Both BSD and Solaris return 0 here, so we do too.
1082 return 0;
1086 * This is invoked by the /proc filesystem handler to display a device
1087 * in detail.
1090 #ifdef CONFIG_PROC_FS
1091 static int sprintf_stats(char *buffer, struct device *dev)
1093 struct net_device_stats *stats = (dev->get_stats ? dev->get_stats(dev): NULL);
1094 int size;
1096 if (stats)
1097 size = sprintf(buffer, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu %8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
1098 dev->name,
1099 stats->rx_bytes,
1100 stats->rx_packets, stats->rx_errors,
1101 stats->rx_dropped + stats->rx_missed_errors,
1102 stats->rx_fifo_errors,
1103 stats->rx_length_errors + stats->rx_over_errors
1104 + stats->rx_crc_errors + stats->rx_frame_errors,
1105 stats->rx_compressed, stats->multicast,
1106 stats->tx_bytes,
1107 stats->tx_packets, stats->tx_errors, stats->tx_dropped,
1108 stats->tx_fifo_errors, stats->collisions,
1109 stats->tx_carrier_errors + stats->tx_aborted_errors
1110 + stats->tx_window_errors + stats->tx_heartbeat_errors,
1111 stats->tx_compressed);
1112 else
1113 size = sprintf(buffer, "%6s: No statistics available.\n", dev->name);
1115 return size;
1119 * Called from the PROCfs module. This now uses the new arbitrary sized /proc/net interface
1120 * to create /proc/net/dev
1123 int dev_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
1125 int len=0;
1126 off_t begin=0;
1127 off_t pos=0;
1128 int size;
1130 struct device *dev;
1133 size = sprintf(buffer,
1134 "Inter-| Receive | Transmit\n"
1135 " face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n");
1137 pos+=size;
1138 len+=size;
1141 for (dev = dev_base; dev != NULL; dev = dev->next)
1143 size = sprintf_stats(buffer+len, dev);
1144 len+=size;
1145 pos=begin+len;
1147 if(pos<offset)
1149 len=0;
1150 begin=pos;
1152 if(pos>offset+length)
1153 break;
1156 *start=buffer+(offset-begin); /* Start of wanted data */
1157 len-=(offset-begin); /* Start slop */
1158 if(len>length)
1159 len=length; /* Ending slop */
1160 return len;
1163 static int dev_proc_stats(char *buffer, char **start, off_t offset,
1164 int length, int *eof, void *data)
1166 int len;
1168 len = sprintf(buffer, "%08x %08x %08x %08x %08x\n",
1169 atomic_read(&netdev_rx_dropped),
1170 #ifdef CONFIG_NET_HW_FLOWCONTROL
1171 netdev_throttle_events,
1172 #else
1174 #endif
1175 #ifdef CONFIG_NET_FASTROUTE
1176 dev_fastroute_stat.hits,
1177 dev_fastroute_stat.succeed,
1178 dev_fastroute_stat.deferred
1179 #else
1180 0, 0, 0
1181 #endif
1184 len -= offset;
1186 if (len > length)
1187 len = length;
1188 if(len < 0)
1189 len = 0;
1191 *start = buffer + offset;
1192 *eof = 1;
1194 return len;
1197 #endif /* CONFIG_PROC_FS */
1200 #ifdef CONFIG_NET_RADIO
1201 #ifdef CONFIG_PROC_FS
1204 * Print one entry of /proc/net/wireless
1205 * This is a clone of /proc/net/dev (just above)
1207 static int sprintf_wireless_stats(char *buffer, struct device *dev)
1209 /* Get stats from the driver */
1210 struct iw_statistics *stats = (dev->get_wireless_stats ?
1211 dev->get_wireless_stats(dev) :
1212 (struct iw_statistics *) NULL);
1213 int size;
1215 if(stats != (struct iw_statistics *) NULL)
1216 size = sprintf(buffer,
1217 "%6s: %02x %3d%c %3d%c %3d%c %5d %5d %5d\n",
1218 dev->name,
1219 stats->status,
1220 stats->qual.qual,
1221 stats->qual.updated & 1 ? '.' : ' ',
1222 stats->qual.level,
1223 stats->qual.updated & 2 ? '.' : ' ',
1224 stats->qual.noise,
1225 stats->qual.updated & 3 ? '.' : ' ',
1226 stats->discard.nwid,
1227 stats->discard.code,
1228 stats->discard.misc);
1229 else
1230 size = 0;
1232 return size;
1236 * Print info for /proc/net/wireless (print all entries)
1237 * This is a clone of /proc/net/dev (just above)
1239 int dev_get_wireless_info(char * buffer, char **start, off_t offset,
1240 int length, int dummy)
1242 int len = 0;
1243 off_t begin = 0;
1244 off_t pos = 0;
1245 int size;
1247 struct device * dev;
1249 size = sprintf(buffer,
1250 "Inter-|sta| Quality | Discarded packets\n"
1251 " face |tus|link level noise| nwid crypt misc\n");
1253 pos+=size;
1254 len+=size;
1256 for(dev = dev_base; dev != NULL; dev = dev->next)
1258 size = sprintf_wireless_stats(buffer+len, dev);
1259 len+=size;
1260 pos=begin+len;
1262 if(pos < offset)
1264 len=0;
1265 begin=pos;
1267 if(pos > offset + length)
1268 break;
1271 *start = buffer + (offset - begin); /* Start of wanted data */
1272 len -= (offset - begin); /* Start slop */
1273 if(len > length)
1274 len = length; /* Ending slop */
1276 return len;
1278 #endif /* CONFIG_PROC_FS */
1279 #endif /* CONFIG_NET_RADIO */
1281 void dev_set_promiscuity(struct device *dev, int inc)
1283 unsigned short old_flags = dev->flags;
1285 dev->flags |= IFF_PROMISC;
1286 if ((dev->promiscuity += inc) == 0)
1287 dev->flags &= ~IFF_PROMISC;
1288 if (dev->flags^old_flags) {
1289 #ifdef CONFIG_NET_FASTROUTE
1290 if (dev->flags&IFF_PROMISC) {
1291 netdev_fastroute_obstacles++;
1292 dev_clear_fastroute(dev);
1293 } else
1294 netdev_fastroute_obstacles--;
1295 #endif
1296 dev_mc_upload(dev);
1297 printk(KERN_INFO "device %s %s promiscuous mode\n",
1298 dev->name, (dev->flags&IFF_PROMISC) ? "entered" : "left");
1302 void dev_set_allmulti(struct device *dev, int inc)
1304 unsigned short old_flags = dev->flags;
1306 dev->flags |= IFF_ALLMULTI;
1307 if ((dev->allmulti += inc) == 0)
1308 dev->flags &= ~IFF_ALLMULTI;
1309 if (dev->flags^old_flags)
1310 dev_mc_upload(dev);
1313 int dev_change_flags(struct device *dev, unsigned flags)
1315 int ret;
1316 int old_flags = dev->flags;
1319 * Set the flags on our device.
1322 dev->flags = (flags & (IFF_DEBUG|IFF_NOTRAILERS|IFF_RUNNING|IFF_NOARP|
1323 IFF_SLAVE|IFF_MASTER|
1324 IFF_MULTICAST|IFF_PORTSEL|IFF_AUTOMEDIA)) |
1325 (dev->flags & (IFF_UP|IFF_VOLATILE|IFF_PROMISC|IFF_ALLMULTI));
1328 * Load in the correct multicast list now the flags have changed.
1331 dev_mc_upload(dev);
1334 * Have we downed the interface. We handle IFF_UP ourselves
1335 * according to user attempts to set it, rather than blindly
1336 * setting it.
1339 ret = 0;
1340 if ((old_flags^flags)&IFF_UP) /* Bit is different ? */
1342 ret = ((old_flags & IFF_UP) ? dev_close : dev_open)(dev);
1344 if (ret == 0)
1345 dev_mc_upload(dev);
1348 if (dev->flags&IFF_UP &&
1349 ((old_flags^dev->flags)&~(IFF_UP|IFF_RUNNING|IFF_PROMISC|IFF_ALLMULTI|IFF_VOLATILE)))
1350 notifier_call_chain(&netdev_chain, NETDEV_CHANGE, dev);
1352 if ((flags^dev->gflags)&IFF_PROMISC) {
1353 int inc = (flags&IFF_PROMISC) ? +1 : -1;
1354 dev->gflags ^= IFF_PROMISC;
1355 dev_set_promiscuity(dev, inc);
1358 /* NOTE: order of synchronization of IFF_PROMISC and IFF_ALLMULTI
1359 is important. Some (broken) drivers set IFF_PROMISC, when
1360 IFF_ALLMULTI is requested not asking us and not reporting.
1362 if ((flags^dev->gflags)&IFF_ALLMULTI) {
1363 int inc = (flags&IFF_ALLMULTI) ? +1 : -1;
1364 dev->gflags ^= IFF_ALLMULTI;
1365 dev_set_allmulti(dev, inc);
1368 return ret;
1372 * Perform the SIOCxIFxxx calls.
1375 static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
1377 struct device *dev;
1378 int err;
1380 if ((dev = dev_get(ifr->ifr_name)) == NULL)
1381 return -ENODEV;
1383 switch(cmd)
1385 case SIOCGIFFLAGS: /* Get interface flags */
1386 ifr->ifr_flags = (dev->flags&~(IFF_PROMISC|IFF_ALLMULTI))
1387 |(dev->gflags&(IFF_PROMISC|IFF_ALLMULTI));
1388 return 0;
1390 case SIOCSIFFLAGS: /* Set interface flags */
1391 return dev_change_flags(dev, ifr->ifr_flags);
1393 case SIOCGIFMETRIC: /* Get the metric on the interface (currently unused) */
1394 ifr->ifr_metric = dev->metric;
1395 return 0;
1397 case SIOCSIFMETRIC: /* Set the metric on the interface (currently unused) */
1398 dev->metric = ifr->ifr_metric;
1399 return 0;
1401 case SIOCGIFMTU: /* Get the MTU of a device */
1402 ifr->ifr_mtu = dev->mtu;
1403 return 0;
1405 case SIOCSIFMTU: /* Set the MTU of a device */
1406 if (ifr->ifr_mtu == dev->mtu)
1407 return 0;
1410 * MTU must be positive.
1413 if (ifr->ifr_mtu<0)
1414 return -EINVAL;
1416 if (dev->change_mtu)
1417 err = dev->change_mtu(dev, ifr->ifr_mtu);
1418 else {
1419 dev->mtu = ifr->ifr_mtu;
1420 err = 0;
1422 if (!err && dev->flags&IFF_UP) {
1423 printk(KERN_DEBUG "SIFMTU %s(%s)\n", dev->name, current->comm);
1424 notifier_call_chain(&netdev_chain, NETDEV_CHANGEMTU, dev);
1426 return err;
1428 case SIOCGIFHWADDR:
1429 memcpy(ifr->ifr_hwaddr.sa_data,dev->dev_addr, MAX_ADDR_LEN);
1430 ifr->ifr_hwaddr.sa_family=dev->type;
1431 return 0;
1433 case SIOCSIFHWADDR:
1434 if(dev->set_mac_address==NULL)
1435 return -EOPNOTSUPP;
1436 if(ifr->ifr_hwaddr.sa_family!=dev->type)
1437 return -EINVAL;
1438 err=dev->set_mac_address(dev,&ifr->ifr_hwaddr);
1439 if (!err)
1440 notifier_call_chain(&netdev_chain, NETDEV_CHANGEADDR, dev);
1441 return err;
1443 case SIOCSIFHWBROADCAST:
1444 if(ifr->ifr_hwaddr.sa_family!=dev->type)
1445 return -EINVAL;
1446 memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data, MAX_ADDR_LEN);
1447 notifier_call_chain(&netdev_chain, NETDEV_CHANGEADDR, dev);
1448 return 0;
1450 case SIOCGIFMAP:
1451 ifr->ifr_map.mem_start=dev->mem_start;
1452 ifr->ifr_map.mem_end=dev->mem_end;
1453 ifr->ifr_map.base_addr=dev->base_addr;
1454 ifr->ifr_map.irq=dev->irq;
1455 ifr->ifr_map.dma=dev->dma;
1456 ifr->ifr_map.port=dev->if_port;
1457 return 0;
1459 case SIOCSIFMAP:
1460 if (dev->set_config)
1461 return dev->set_config(dev,&ifr->ifr_map);
1462 return -EOPNOTSUPP;
1464 case SIOCADDMULTI:
1465 if(dev->set_multicast_list==NULL ||
1466 ifr->ifr_hwaddr.sa_family!=AF_UNSPEC)
1467 return -EINVAL;
1468 dev_mc_add(dev,ifr->ifr_hwaddr.sa_data, dev->addr_len, 1);
1469 return 0;
1471 case SIOCDELMULTI:
1472 if(dev->set_multicast_list==NULL ||
1473 ifr->ifr_hwaddr.sa_family!=AF_UNSPEC)
1474 return -EINVAL;
1475 dev_mc_delete(dev,ifr->ifr_hwaddr.sa_data,dev->addr_len, 1);
1476 return 0;
1478 case SIOCGIFINDEX:
1479 ifr->ifr_ifindex = dev->ifindex;
1480 return 0;
1482 case SIOCGIFTXQLEN:
1483 ifr->ifr_qlen = dev->tx_queue_len;
1484 return 0;
1486 case SIOCSIFTXQLEN:
1487 if(ifr->ifr_qlen<2 || ifr->ifr_qlen>1024)
1488 return -EINVAL;
1489 dev->tx_queue_len = ifr->ifr_qlen;
1490 return 0;
1493 * Unknown or private ioctl
1496 default:
1497 if(cmd >= SIOCDEVPRIVATE &&
1498 cmd <= SIOCDEVPRIVATE + 15) {
1499 if (dev->do_ioctl)
1500 return dev->do_ioctl(dev, ifr, cmd);
1501 return -EOPNOTSUPP;
1504 #ifdef CONFIG_NET_RADIO
1505 if(cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
1506 if (dev->do_ioctl)
1507 return dev->do_ioctl(dev, ifr, cmd);
1508 return -EOPNOTSUPP;
1510 #endif /* CONFIG_NET_RADIO */
1513 return -EINVAL;
1518 * This function handles all "interface"-type I/O control requests. The actual
1519 * 'doing' part of this is dev_ifsioc above.
1522 int dev_ioctl(unsigned int cmd, void *arg)
1524 struct ifreq ifr;
1525 int ret;
1526 char *colon;
1528 /* One special case: SIOCGIFCONF takes ifconf argument
1529 and requires shared lock, because it sleeps writing
1530 to user space.
1533 if (cmd == SIOCGIFCONF) {
1534 rtnl_shlock();
1535 ret = dev_ifconf((char *) arg);
1536 rtnl_shunlock();
1537 return ret;
1539 if (cmd == SIOCGIFNAME) {
1540 return dev_ifname((struct ifreq *)arg);
1543 if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
1544 return -EFAULT;
1546 ifr.ifr_name[IFNAMSIZ-1] = 0;
1548 colon = strchr(ifr.ifr_name, ':');
1549 if (colon)
1550 *colon = 0;
1553 * See which interface the caller is talking about.
1556 switch(cmd)
1559 * These ioctl calls:
1560 * - can be done by all.
1561 * - atomic and do not require locking.
1562 * - return a value
1565 case SIOCGIFFLAGS:
1566 case SIOCGIFMETRIC:
1567 case SIOCGIFMTU:
1568 case SIOCGIFHWADDR:
1569 case SIOCGIFSLAVE:
1570 case SIOCGIFMAP:
1571 case SIOCGIFINDEX:
1572 case SIOCGIFTXQLEN:
1573 dev_load(ifr.ifr_name);
1574 ret = dev_ifsioc(&ifr, cmd);
1575 if (!ret) {
1576 if (colon)
1577 *colon = ':';
1578 if (copy_to_user(arg, &ifr, sizeof(struct ifreq)))
1579 return -EFAULT;
1581 return ret;
1584 * These ioctl calls:
1585 * - require superuser power.
1586 * - require strict serialization.
1587 * - do not return a value
1590 case SIOCSIFFLAGS:
1591 case SIOCSIFMETRIC:
1592 case SIOCSIFMTU:
1593 case SIOCSIFMAP:
1594 case SIOCSIFHWADDR:
1595 case SIOCSIFSLAVE:
1596 case SIOCADDMULTI:
1597 case SIOCDELMULTI:
1598 case SIOCSIFHWBROADCAST:
1599 case SIOCSIFTXQLEN:
1600 if (!capable(CAP_NET_ADMIN))
1601 return -EPERM;
1602 dev_load(ifr.ifr_name);
1603 rtnl_lock();
1604 ret = dev_ifsioc(&ifr, cmd);
1605 rtnl_unlock();
1606 return ret;
1608 case SIOCGIFMEM:
1609 /* Get the per device memory space. We can add this but currently
1610 do not support it */
1611 case SIOCSIFMEM:
1612 /* Set the per device memory buffer space. Not applicable in our case */
1613 case SIOCSIFLINK:
1614 return -EINVAL;
1617 * Unknown or private ioctl.
1620 default:
1621 if (cmd >= SIOCDEVPRIVATE &&
1622 cmd <= SIOCDEVPRIVATE + 15) {
1623 dev_load(ifr.ifr_name);
1624 rtnl_lock();
1625 ret = dev_ifsioc(&ifr, cmd);
1626 rtnl_unlock();
1627 if (!ret && copy_to_user(arg, &ifr, sizeof(struct ifreq)))
1628 return -EFAULT;
1629 return ret;
1631 #ifdef CONFIG_NET_RADIO
1632 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
1633 dev_load(ifr.ifr_name);
1634 if (IW_IS_SET(cmd)) {
1635 if (!suser())
1636 return -EPERM;
1637 rtnl_lock();
1639 ret = dev_ifsioc(&ifr, cmd);
1640 if (IW_IS_SET(cmd))
1641 rtnl_unlock();
1642 if (!ret && IW_IS_GET(cmd) &&
1643 copy_to_user(arg, &ifr, sizeof(struct ifreq)))
1644 return -EFAULT;
1645 return ret;
1647 #endif /* CONFIG_NET_RADIO */
1648 return -EINVAL;
1652 int dev_new_index(void)
1654 static int ifindex;
1655 for (;;) {
1656 if (++ifindex <= 0)
1657 ifindex=1;
1658 if (dev_get_by_index(ifindex) == NULL)
1659 return ifindex;
1663 static int dev_boot_phase = 1;
1666 int register_netdevice(struct device *dev)
1668 struct device *d, **dp;
1670 if (dev_boot_phase) {
1671 printk(KERN_INFO "early initialization of device %s is deferred\n", dev->name);
1673 /* Check for existence, and append to tail of chain */
1674 for (dp=&dev_base; (d=*dp) != NULL; dp=&d->next) {
1675 if (d == dev || strcmp(d->name, dev->name) == 0)
1676 return -EEXIST;
1678 dev->next = NULL;
1679 *dp = dev;
1680 return 0;
1683 dev->iflink = -1;
1685 /* Init, if this function is available */
1686 if (dev->init && dev->init(dev) != 0)
1687 return -EIO;
1689 /* Check for existence, and append to tail of chain */
1690 for (dp=&dev_base; (d=*dp) != NULL; dp=&d->next) {
1691 if (d == dev || strcmp(d->name, dev->name) == 0)
1692 return -EEXIST;
1694 dev->next = NULL;
1695 dev_init_scheduler(dev);
1696 dev->ifindex = dev_new_index();
1697 if (dev->iflink == -1)
1698 dev->iflink = dev->ifindex;
1699 *dp = dev;
1701 /* Notify protocols, that a new device appeared. */
1702 notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
1704 return 0;
1707 int unregister_netdevice(struct device *dev)
1709 struct device *d, **dp;
1711 if (dev_boot_phase == 0) {
1712 /* If device is running, close it.
1713 It is very bad idea, really we should
1714 complain loudly here, but random hackery
1715 in linux/drivers/net likes it.
1717 if (dev->flags & IFF_UP)
1718 dev_close(dev);
1720 #ifdef CONFIG_NET_FASTROUTE
1721 dev_clear_fastroute(dev);
1722 #endif
1724 /* Shutdown queueing discipline. */
1725 dev_shutdown(dev);
1727 /* Notify protocols, that we are about to destroy
1728 this device. They should clean all the things.
1730 notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
1733 * Flush the multicast chain
1735 dev_mc_discard(dev);
1737 /* To avoid pointers looking to nowhere,
1738 we wait for end of critical section */
1739 dev_lock_wait();
1742 /* And unlink it from device chain. */
1743 for (dp = &dev_base; (d=*dp) != NULL; dp=&d->next) {
1744 if (d == dev) {
1745 *dp = d->next;
1746 d->next = NULL;
1747 if (dev->destructor)
1748 dev->destructor(dev);
1749 return 0;
1752 return -ENODEV;
1757 * Initialize the DEV module. At boot time this walks the device list and
1758 * unhooks any devices that fail to initialise (normally hardware not
1759 * present) and leaves us with a valid list of present and active devices.
1762 extern int lance_init(void);
1763 extern int bpq_init(void);
1764 extern int scc_init(void);
1765 extern void sdla_setup(void);
1766 extern void dlci_setup(void);
1767 extern int dmascc_init(void);
1768 extern int sm_init(void);
1769 extern int baycom_init(void);
1770 extern int lapbeth_init(void);
1771 extern void arcnet_init(void);
1772 extern void ip_auto_config(void);
1773 #ifdef CONFIG_8xx
1774 extern int cpm_enet_init(void);
1775 #endif /* CONFIG_8xx */
1777 #ifdef CONFIG_PROC_FS
1778 static struct proc_dir_entry proc_net_dev = {
1779 PROC_NET_DEV, 3, "dev",
1780 S_IFREG | S_IRUGO, 1, 0, 0,
1781 0, &proc_net_inode_operations,
1782 dev_get_info
1784 #endif
1786 #ifdef CONFIG_NET_RADIO
1787 #ifdef CONFIG_PROC_FS
1788 static struct proc_dir_entry proc_net_wireless = {
1789 PROC_NET_WIRELESS, 8, "wireless",
1790 S_IFREG | S_IRUGO, 1, 0, 0,
1791 0, &proc_net_inode_operations,
1792 dev_get_wireless_info
1794 #endif /* CONFIG_PROC_FS */
1795 #endif /* CONFIG_NET_RADIO */
1797 __initfunc(int net_dev_init(void))
1799 struct device *dev, **dp;
1801 #ifdef CONFIG_NET_SCHED
1802 pktsched_init();
1803 #endif
1806 * Initialise the packet receive queue.
1809 skb_queue_head_init(&backlog);
1812 * The bridge has to be up before the devices
1815 #ifdef CONFIG_BRIDGE
1816 br_init();
1817 #endif
1820 * This is Very Ugly(tm).
1822 * Some devices want to be initialized early..
1825 #if defined(CONFIG_LANCE)
1826 lance_init();
1827 #endif
1828 #if defined(CONFIG_SCC)
1829 scc_init();
1830 #endif
1831 #if defined(CONFIG_DMASCC)
1832 dmascc_init();
1833 #endif
1834 #if defined(CONFIG_BPQETHER)
1835 bpq_init();
1836 #endif
1837 #if defined(CONFIG_DLCI)
1838 dlci_setup();
1839 #endif
1840 #if defined(CONFIG_SDLA)
1841 sdla_setup();
1842 #endif
1843 #if defined(CONFIG_BAYCOM)
1844 baycom_init();
1845 #endif
1846 #if defined(CONFIG_SOUNDMODEM)
1847 sm_init();
1848 #endif
1849 #if defined(CONFIG_LAPBETHER)
1850 lapbeth_init();
1851 #endif
1852 #if defined(CONFIG_PLIP)
1853 plip_init();
1854 #endif
1855 #if defined(CONFIG_ARCNET)
1856 arcnet_init();
1857 #endif
1858 #if defined(CONFIG_8xx)
1859 cpm_enet_init();
1860 #endif
1862 * SLHC if present needs attaching so other people see it
1863 * even if not opened.
1865 #if (defined(CONFIG_SLIP) && defined(CONFIG_SLIP_COMPRESSED)) \
1866 || defined(CONFIG_PPP) \
1867 || (defined(CONFIG_ISDN) && defined(CONFIG_ISDN_PPP))
1868 slhc_install();
1869 #endif
1871 #ifdef CONFIG_NET_PROFILE
1872 net_profile_init();
1873 NET_PROFILE_REGISTER(dev_queue_xmit);
1874 NET_PROFILE_REGISTER(net_bh);
1875 #if 0
1876 NET_PROFILE_REGISTER(net_bh_skb);
1877 #endif
1878 #endif
1880 * Add the devices.
1881 * If the call to dev->init fails, the dev is removed
1882 * from the chain disconnecting the device until the
1883 * next reboot.
1886 dp = &dev_base;
1887 while ((dev = *dp) != NULL)
1889 dev->iflink = -1;
1890 if (dev->init && dev->init(dev))
1893 * It failed to come up. Unhook it.
1895 *dp = dev->next;
1897 else
1899 dp = &dev->next;
1900 dev->ifindex = dev_new_index();
1901 if (dev->iflink == -1)
1902 dev->iflink = dev->ifindex;
1903 dev_init_scheduler(dev);
1907 #ifdef CONFIG_PROC_FS
1908 proc_net_register(&proc_net_dev);
1910 struct proc_dir_entry *ent = create_proc_entry("net/dev_stat", 0, 0);
1911 ent->read_proc = dev_proc_stats;
1913 #endif
1915 #ifdef CONFIG_NET_RADIO
1916 #ifdef CONFIG_PROC_FS
1917 proc_net_register(&proc_net_wireless);
1918 #endif /* CONFIG_PROC_FS */
1919 #endif /* CONFIG_NET_RADIO */
1921 init_bh(NET_BH, net_bh);
1923 dev_boot_phase = 0;
1925 dev_mcast_init();
1927 #ifdef CONFIG_IP_PNP
1928 ip_auto_config();
1929 #endif
1931 return 0;