OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [net/] [core/] [dev.c] - Blame information for rev 1772

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1629 jcastillo
/*
2
 *      NET3    Protocol independent device support routines.
3
 *
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.
8
 *
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>
13
 *
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
 *
19
 *      Changes:
20
 *              Alan Cox        :       device private ioctl copies fields back.
21
 *              Alan Cox        :       Transmit queue code does relevant stunts to
22
 *                                      keep the queue safe.
23
 *              Alan Cox        :       Fixed double lock.
24
 *              Alan Cox        :       Fixed promisc NULL pointer trap
25
 *              ????????        :       Support the full private ioctl range
26
 *              Alan Cox        :       Moved ioctl permission check into drivers
27
 *              Tim Kordas      :       SIOCADDMULTI/SIOCDELMULTI
28
 *              Alan Cox        :       100 backlog just doesn't cut it when
29
 *                                      you start doing multicast video 8)
30
 *              Alan Cox        :       Rewrote net_bh and list manager.
31
 *              Alan Cox        :       Fix ETH_P_ALL echoback lengths.
32
 *              Alan Cox        :       Took out transmit every packet pass
33
 *                                      Saved a few bytes in the ioctl handler
34
 *              Alan Cox        :       Network driver sets packet type before calling netif_rx. Saves
35
 *                                      a function call a packet.
36
 *              Alan Cox        :       Hashed net_bh()
37
 *              Richard Kooijman:       Timestamp fixes.
38
 *              Alan Cox        :       Wrong field in SIOCGIFDSTADDR
39
 *              Alan Cox        :       Device lock protection.
40
 *              Alan Cox        :       Fixed nasty side effect of device close changes.
41
 *              Rudi Cilibrasi  :       Pass the right thing to set_mac_address()
42
 *              Dave Miller     :       32bit quantity for the device lock to make it work out
43
 *                                      on a Sparc.
44
 *              Bjorn Ekwall    :       Added KERNELD hack.
45
 *              Alan Cox        :       Cleaned up the backlog initialise.
46
 *              Craig Metz      :       SIOCGIFCONF fix if space for under
47
 *                                      1 device.
48
 *          Thomas Bogendoerfer :       Return ENODEV for dev_open, if there
49
 *                                      is no device open function.
50
 *          Lawrence V. Stefani :       Changed set MTU ioctl to not assume
51
 *                                      min MTU of 68 bytes for devices
52
 *                                      that have change MTU functions.
53
 *
54
 */
55
 
56
#include <asm/segment.h>
57
#include <asm/system.h>
58
#include <asm/bitops.h>
59
#include <linux/config.h>
60
#include <linux/types.h>
61
#include <linux/kernel.h>
62
#include <linux/sched.h>
63
#include <linux/string.h>
64
#include <linux/mm.h>
65
#include <linux/socket.h>
66
#include <linux/sockios.h>
67
#include <linux/in.h>
68
#include <linux/errno.h>
69
#include <linux/interrupt.h>
70
#include <linux/if_ether.h>
71
#include <linux/inet.h>
72
#include <linux/netdevice.h>
73
#include <linux/etherdevice.h>
74
#include <linux/notifier.h>
75
#include <net/ip.h>
76
#include <net/route.h>
77
#include <linux/skbuff.h>
78
#include <net/sock.h>
79
#include <net/arp.h>
80
#include <net/slhc.h>
81
#include <linux/proc_fs.h>
82
#include <linux/stat.h>
83
#include <net/br.h>
84
#ifdef CONFIG_NET_ALIAS
85
#include <linux/net_alias.h>
86
#endif
87
#ifdef CONFIG_KERNELD
88
#include <linux/kerneld.h>
89
#endif
90
#ifdef CONFIG_NET_RADIO
91
#include <linux/wireless.h>
92
#endif  /* CONFIG_NET_RADIO */
93
 
94
/*
95
 *      The list of packet types we will receive (as opposed to discard)
96
 *      and the routines to invoke.
97
 */
98
 
99
struct packet_type *ptype_base[16];
100
struct packet_type *ptype_all = NULL;           /* Taps */
101
 
102
/*
103
 *      Device list lock
104
 */
105
 
106
int dev_lockct=0;
107
 
108
/*
109
 *      Our notifier list
110
 */
111
 
112
struct notifier_block *netdev_chain=NULL;
113
 
114
/*
115
 *      Device drivers call our routines to queue packets here. We empty the
116
 *      queue in the bottom half handler.
117
 */
118
 
119
static struct sk_buff_head backlog;
120
 
121
/*
122
 *      We don't overdo the queue or we will thrash memory badly.
123
 */
124
 
125
static int backlog_size = 0;
126
 
127
/*
128
 *      Return the lesser of the two values.
129
 */
130
 
131
static __inline__ unsigned long min(unsigned long a, unsigned long b)
132
{
133
        return (a < b)? a : b;
134
}
135
 
136
 
137
/******************************************************************************************
138
 
139
                Protocol management and registration routines
140
 
141
*******************************************************************************************/
142
 
143
/*
144
 *      For efficiency
145
 */
146
 
147
static int dev_nit=0;
148
 
149
/*
150
 *      Add a protocol ID to the list. Now that the input handler is
151
 *      smarter we can dispense with all the messy stuff that used to be
152
 *      here.
153
 */
154
 
155
void dev_add_pack(struct packet_type *pt)
156
{
157
        int hash;
158
        if(pt->type==htons(ETH_P_ALL))
159
        {
160
                dev_nit++;
161
                pt->next=ptype_all;
162
                ptype_all=pt;
163
        }
164
        else
165
        {
166
                hash=ntohs(pt->type)&15;
167
                pt->next = ptype_base[hash];
168
                ptype_base[hash] = pt;
169
        }
170
}
171
 
172
 
173
/*
174
 *      Remove a protocol ID from the list.
175
 */
176
 
177
void dev_remove_pack(struct packet_type *pt)
178
{
179
        struct packet_type **pt1;
180
        if(pt->type==htons(ETH_P_ALL))
181
        {
182
                dev_nit--;
183
                pt1=&ptype_all;
184
        }
185
        else
186
                pt1=&ptype_base[ntohs(pt->type)&15];
187
        for(; (*pt1)!=NULL; pt1=&((*pt1)->next))
188
        {
189
                if(pt==(*pt1))
190
                {
191
                        *pt1=pt->next;
192
                        return;
193
                }
194
        }
195
        printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt);
196
}
197
 
198
/*****************************************************************************************
199
 
200
                            Device Interface Subroutines
201
 
202
******************************************************************************************/
203
 
204
/*
205
 *      Find an interface by name.
206
 */
207
 
208
struct device *dev_get(const char *name)
209
{
210
        struct device *dev;
211
 
212
        for (dev = dev_base; dev != NULL; dev = dev->next)
213
        {
214
                if (strcmp(dev->name, name) == 0)
215
                        return(dev);
216
        }
217
        return NULL;
218
}
219
 
220
/*
221
 *      Find and possibly load an interface.
222
 */
223
 
224
#ifdef CONFIG_KERNELD
225
 
226
extern __inline__ void dev_load(const char *name)
227
{
228
        if(!dev_get(name) && suser()) {
229
#ifdef CONFIG_NET_ALIAS
230
                const char *sptr;
231
 
232
                for (sptr=name ; *sptr ; sptr++) if(*sptr==':') break;
233
                if (!(*sptr && *(sptr+1)))
234
#endif
235
                request_module(name);
236
        }
237
}
238
 
239
#endif
240
 
241
/*
242
 *      Prepare an interface for use.
243
 */
244
 
245
int dev_open(struct device *dev)
246
{
247
        int ret = -ENODEV;
248
 
249
        /*
250
         *      Call device private open method
251
         */
252
        if (dev->open)
253
                ret = dev->open(dev);
254
 
255
        /*
256
         *      If it went open OK then set the flags
257
         */
258
 
259
        if (ret == 0)
260
        {
261
                dev->flags |= (IFF_UP | IFF_RUNNING);
262
                /*
263
                 *      Initialise multicasting status
264
                 */
265
                dev_mc_upload(dev);
266
                notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
267
        }
268
        return(ret);
269
}
270
 
271
 
272
/*
273
 *      Completely shutdown an interface.
274
 */
275
 
276
int dev_close(struct device *dev)
277
{
278
        int ct=0;
279
 
280
        /*
281
         *      Call the device specific close. This cannot fail.
282
         *      Only if device is UP
283
         */
284
 
285
        if ((dev->flags & IFF_UP) && dev->stop)
286
                dev->stop(dev);
287
 
288
        /*
289
         *      Device is now down.
290
         */
291
 
292
        dev->flags&=~(IFF_UP|IFF_RUNNING);
293
 
294
        /*
295
         *      Tell people we are going down
296
         */
297
        notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
298
        /*
299
         *      Flush the multicast chain
300
         */
301
        dev_mc_discard(dev);
302
 
303
        /*
304
         *      Purge any queued packets when we down the link
305
         */
306
        while(ct<DEV_NUMBUFFS)
307
        {
308
                struct sk_buff *skb;
309
                while((skb=skb_dequeue(&dev->buffs[ct]))!=NULL)
310
                        if(skb->free)
311
                                kfree_skb(skb,FREE_WRITE);
312
                ct++;
313
        }
314
        return(0);
315
}
316
 
317
 
318
/*
319
 *      Device change register/unregister. These are not inline or static
320
 *      as we export them to the world.
321
 */
322
 
323
int register_netdevice_notifier(struct notifier_block *nb)
324
{
325
        return notifier_chain_register(&netdev_chain, nb);
326
}
327
 
328
int unregister_netdevice_notifier(struct notifier_block *nb)
329
{
330
        return notifier_chain_unregister(&netdev_chain,nb);
331
}
332
 
333
/*
334
 *      Send (or queue for sending) a packet.
335
 *
336
 *      IMPORTANT: When this is called to resend frames. The caller MUST
337
 *      already have locked the sk_buff. Apart from that we do the
338
 *      rest of the magic.
339
 */
340
 
341
static void do_dev_queue_xmit(struct sk_buff *skb, struct device *dev, int pri)
342
{
343
        unsigned long flags;
344
        struct sk_buff_head *list;
345
        int retransmission = 0;  /* used to say if the packet should go  */
346
                                /* at the front or the back of the      */
347
                                /* queue - front is a retransmit try    */
348
 
349
        if(pri>=0 && !skb_device_locked(skb))
350
                skb_device_lock(skb);   /* Shove a lock on the frame */
351
#if CONFIG_SKB_CHECK 
352
        IS_SKB(skb);
353
#endif    
354
        skb->dev = dev;
355
 
356
        /*
357
         *      Negative priority is used to flag a frame that is being pulled from the
358
         *      queue front as a retransmit attempt. It therefore goes back on the queue
359
         *      start on a failure.
360
         */
361
 
362
        if (pri < 0)
363
        {
364
                pri = -pri-1;
365
                retransmission = 1;
366
        }
367
 
368
#ifdef CONFIG_NET_DEBUG
369
        if (pri >= DEV_NUMBUFFS)
370
        {
371
                printk(KERN_WARNING "bad priority in dev_queue_xmit.\n");
372
                pri = 1;
373
        }
374
#endif
375
 
376
        /*
377
         *      If the address has not been resolved. Call the device header rebuilder.
378
         *      This can cover all protocols and technically not just ARP either.
379
         */
380
 
381
        if (!skb->arp && dev->rebuild_header(skb->data, dev, skb->raddr, skb)) {
382
                return;
383
        }
384
 
385
        /*
386
         *
387
         *      If dev is an alias, switch to its main device.
388
         *      "arp" resolution has been made with alias device, so
389
         *      arp entries refer to alias, not main.
390
         *
391
         */
392
 
393
#ifdef CONFIG_NET_ALIAS
394
        if (net_alias_is(dev))
395
                skb->dev = dev = net_alias_dev_tx(dev);
396
#endif
397
 
398
        /*
399
         *      If we are bridging and this is directly generated output
400
         *      pass the frame via the bridge.
401
         */
402
 
403
#ifdef CONFIG_BRIDGE
404
        if(skb->pkt_bridged!=IS_BRIDGED && br_stats.flags & BR_UP)
405
        {
406
                if(br_tx_frame(skb))
407
                        return;
408
        }
409
#endif
410
 
411
        list = dev->buffs + pri;
412
 
413
        save_flags(flags);
414
        /* if this isn't a retransmission, use the first packet instead... */
415
        if (!retransmission) {
416
                if (skb_queue_len(list)) {
417
                        /* avoid overrunning the device queue.. */
418
                        if (skb_queue_len(list) > dev->tx_queue_len) {
419
                                dev_kfree_skb(skb, FREE_WRITE);
420
                                return;
421
                        }
422
                }
423
 
424
                /* copy outgoing packets to any sniffer packet handlers */
425
                if (dev_nit) {
426
                        struct packet_type *ptype;
427
                        skb->stamp=xtime;
428
                        for (ptype = ptype_all; ptype!=NULL; ptype = ptype->next)
429
                        {
430
                                /* Never send packets back to the socket
431
                                 * they originated from - MvS (miquels@drinkel.ow.org)
432
                                 */
433
                                if ((ptype->dev == dev || !ptype->dev) &&
434
                                   ((struct sock *)ptype->data != skb->sk))
435
                                {
436
                                        struct sk_buff *skb2;
437
                                        if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL)
438
                                                break;
439
                                        /* FIXME?: Wrong when the hard_header_len
440
                                         * is an upper bound. Is this even
441
                                         * used anywhere?
442
                                         */
443
                                        skb2->h.raw = skb2->data + dev->hard_header_len;
444
                                        /* On soft header devices we
445
                                         * yank the header before mac.raw
446
                                         * back off. This is set by
447
                                         * dev->hard_header().
448
                                         */
449
                                        if (dev->flags&IFF_SOFTHEADERS)
450
                                                skb_pull(skb2,skb2->mac.raw-skb2->data);
451
                                        skb2->mac.raw = skb2->data;
452
                                        ptype->func(skb2, skb->dev, ptype);
453
                                }
454
                        }
455
                }
456
 
457
                if (skb_queue_len(list)) {
458
                        cli();
459
                        skb_device_unlock(skb);         /* Buffer is on the device queue and can be freed safely */
460
                        __skb_queue_tail(list, skb);
461
                        skb = __skb_dequeue(list);
462
                        skb_device_lock(skb);           /* New buffer needs locking down */
463
                        restore_flags(flags);
464
                }
465
        }
466
        if (dev->hard_start_xmit(skb, dev) == 0) {
467
                /*
468
                 *      Packet is now solely the responsibility of the driver
469
                 */
470
                return;
471
        }
472
 
473
        /*
474
         *      Transmission failed, put skb back into a list. Once on the list it's safe and
475
         *      no longer device locked (it can be freed safely from the device queue)
476
         */
477
        cli();
478
        skb_device_unlock(skb);
479
        __skb_queue_head(list,skb);
480
        restore_flags(flags);
481
}
482
 
483
void dev_queue_xmit(struct sk_buff *skb, struct device *dev, int pri)
484
{
485
        start_bh_atomic();
486
        do_dev_queue_xmit(skb, dev, pri);
487
        end_bh_atomic();
488
}
489
 
490
/*
491
 *      Receive a packet from a device driver and queue it for the upper
492
 *      (protocol) levels.  It always succeeds. This is the recommended
493
 *      interface to use.
494
 */
495
 
496
void netif_rx(struct sk_buff *skb)
497
{
498
        static int dropping = 0;
499
 
500
        /*
501
         *      Any received buffers are un-owned and should be discarded
502
         *      when freed. These will be updated later as the frames get
503
         *      owners.
504
         */
505
 
506
        skb->sk = NULL;
507
        skb->free = 1;
508
        if(skb->stamp.tv_sec==0)
509
                skb->stamp = xtime;
510
 
511
        /*
512
         *      Check that we aren't overdoing things.
513
         */
514
 
515
        if (!backlog_size)
516
                dropping = 0;
517
        else if (backlog_size > 300)
518
                dropping = 1;
519
 
520
        if (dropping)
521
        {
522
                kfree_skb(skb, FREE_READ);
523
                return;
524
        }
525
 
526
        /*
527
         *      Add it to the "backlog" queue.
528
         */
529
#if CONFIG_SKB_CHECK
530
        IS_SKB(skb);
531
#endif  
532
        skb_queue_tail(&backlog,skb);
533
        backlog_size++;
534
 
535
        /*
536
         *      If any packet arrived, mark it for processing after the
537
         *      hardware interrupt returns.
538
         */
539
 
540
        mark_bh(NET_BH);
541
        return;
542
}
543
 
544
/*
545
 *      This routine causes all interfaces to try to send some data.
546
 */
547
 
548
static void dev_transmit(void)
549
{
550
        struct device *dev;
551
 
552
        for (dev = dev_base; dev != NULL; dev = dev->next)
553
        {
554
                if (dev->flags != 0 && !dev->tbusy) {
555
                        /*
556
                         *      Kick the device
557
                         */
558
                        dev_tint(dev);
559
                }
560
        }
561
}
562
 
563
 
564
/**********************************************************************************
565
 
566
                        Receive Queue Processor
567
 
568
***********************************************************************************/
569
 
570
/*
571
 *      When we are called the queue is ready to grab, the interrupts are
572
 *      on and hardware can interrupt and queue to the receive queue as we
573
 *      run with no problems.
574
 *      This is run as a bottom half after an interrupt handler that does
575
 *      mark_bh(NET_BH);
576
 */
577
 
578
void net_bh(void)
579
{
580
        struct packet_type *ptype;
581
        struct packet_type *pt_prev;
582
        unsigned short type;
583
 
584
        /*
585
         *      Can we send anything now? We want to clear the
586
         *      decks for any more sends that get done as we
587
         *      process the input. This also minimises the
588
         *      latency on a transmit interrupt bh.
589
         */
590
 
591
        dev_transmit();
592
 
593
        /*
594
         *      Any data left to process. This may occur because a
595
         *      mark_bh() is done after we empty the queue including
596
         *      that from the device which does a mark_bh() just after
597
         */
598
 
599
        /*
600
         *      While the queue is not empty..
601
         *
602
         *      Note that the queue never shrinks due to
603
         *      an interrupt, so we can do this test without
604
         *      disabling interrupts.
605
         */
606
 
607
        while (!skb_queue_empty(&backlog)) {
608
                struct sk_buff * skb = backlog.next;
609
 
610
                /*
611
                 *      We have a packet. Therefore the queue has shrunk
612
                 */
613
                cli();
614
                __skb_unlink(skb, &backlog);
615
                backlog_size--;
616
                sti();
617
 
618
 
619
#ifdef CONFIG_BRIDGE
620
 
621
                /*
622
                 *      If we are bridging then pass the frame up to the
623
                 *      bridging code. If it is bridged then move on
624
                 */
625
 
626
                if (br_stats.flags & BR_UP)
627
                {
628
                        /*
629
                         *      We pass the bridge a complete frame. This means
630
                         *      recovering the MAC header first.
631
                         */
632
 
633
                        int offset=skb->data-skb->mac.raw;
634
                        cli();
635
                        skb_push(skb,offset);   /* Put header back on for bridge */
636
                        if(br_receive_frame(skb))
637
                        {
638
                                sti();
639
                                continue;
640
                        }
641
                        /*
642
                         *      Pull the MAC header off for the copy going to
643
                         *      the upper layers.
644
                         */
645
                        skb_pull(skb,offset);
646
                        sti();
647
                }
648
#endif
649
 
650
                /*
651
                 *      Bump the pointer to the next structure.
652
                 *
653
                 *      On entry to the protocol layer. skb->data and
654
                 *      skb->h.raw point to the MAC and encapsulated data
655
                 */
656
 
657
                skb->h.raw = skb->data;
658
 
659
                /*
660
                 *      Fetch the packet protocol ID.
661
                 */
662
 
663
                type = skb->protocol;
664
 
665
                /*
666
                 *      We got a packet ID.  Now loop over the "known protocols"
667
                 *      list. There are two lists. The ptype_all list of taps (normally empty)
668
                 *      and the main protocol list which is hashed perfectly for normal protocols.
669
                 */
670
 
671
                pt_prev = NULL;
672
                for (ptype = ptype_all; ptype!=NULL; ptype=ptype->next)
673
                {
674
                        if(!ptype->dev || ptype->dev == skb->dev) {
675
                                if(pt_prev) {
676
                                        struct sk_buff *skb2=skb_clone(skb, GFP_ATOMIC);
677
                                        if(skb2)
678
                                                pt_prev->func(skb2,skb->dev, pt_prev);
679
                                }
680
                                pt_prev=ptype;
681
                        }
682
                }
683
 
684
                for (ptype = ptype_base[ntohs(type)&15]; ptype != NULL; ptype = ptype->next)
685
                {
686
                        if (ptype->type == type && (!ptype->dev || ptype->dev==skb->dev))
687
                        {
688
                                /*
689
                                 *      We already have a match queued. Deliver
690
                                 *      to it and then remember the new match
691
                                 */
692
                                if(pt_prev)
693
                                {
694
                                        struct sk_buff *skb2;
695
 
696
                                        skb2=skb_clone(skb, GFP_ATOMIC);
697
 
698
                                        /*
699
                                         *      Kick the protocol handler. This should be fast
700
                                         *      and efficient code.
701
                                         */
702
 
703
                                        if(skb2)
704
                                                pt_prev->func(skb2, skb->dev, pt_prev);
705
                                }
706
                                /* Remember the current last to do */
707
                                pt_prev=ptype;
708
                        }
709
                } /* End of protocol list loop */
710
 
711
                /*
712
                 *      Is there a last item to send to ?
713
                 */
714
 
715
                if(pt_prev)
716
                        pt_prev->func(skb, skb->dev, pt_prev);
717
                /*
718
                 *      Has an unknown packet has been received ?
719
                 */
720
 
721
                else
722
                        kfree_skb(skb, FREE_WRITE);
723
                /*
724
                 *      Again, see if we can transmit anything now.
725
                 *      [Ought to take this out judging by tests it slows
726
                 *       us down not speeds us up]
727
                 */
728
#ifdef XMIT_EVERY
729
                dev_transmit();
730
#endif          
731
        }       /* End of queue loop */
732
 
733
        /*
734
         *      We have emptied the queue
735
         */
736
 
737
        /*
738
         *      One last output flush.
739
         */
740
 
741
#ifdef XMIT_AFTER        
742
        dev_transmit();
743
#endif
744
}
745
 
746
 
747
/*
748
 *      This routine is called when an device driver (i.e. an
749
 *      interface) is ready to transmit a packet.
750
 */
751
 
752
void dev_tint(struct device *dev)
753
{
754
        int i;
755
        unsigned long flags;
756
        struct sk_buff_head * head;
757
 
758
        /*
759
         * aliases do not transmit (for now :) )
760
         */
761
 
762
#ifdef CONFIG_NET_ALIAS
763
        if (net_alias_is(dev)) return;
764
#endif
765
        head = dev->buffs;
766
        save_flags(flags);
767
        cli();
768
 
769
        /*
770
         *      Work the queues in priority order
771
         */
772
        for(i = 0;i < DEV_NUMBUFFS; i++,head++)
773
        {
774
 
775
                while (!skb_queue_empty(head)) {
776
                        struct sk_buff *skb;
777
 
778
                        skb = head->next;
779
                        __skb_unlink(skb, head);
780
                        /*
781
                         *      Stop anyone freeing the buffer while we retransmit it
782
                         */
783
                        skb_device_lock(skb);
784
                        restore_flags(flags);
785
                        /*
786
                         *      Feed them to the output stage and if it fails
787
                         *      indicate they re-queue at the front.
788
                         */
789
                        do_dev_queue_xmit(skb,dev,-i - 1);
790
                        /*
791
                         *      If we can take no more then stop here.
792
                         */
793
                        if (dev->tbusy)
794
                                return;
795
                        cli();
796
                }
797
        }
798
        restore_flags(flags);
799
}
800
 
801
 
802
/*
803
 *      Perform a SIOCGIFCONF call. This structure will change
804
 *      size shortly, and there is nothing I can do about it.
805
 *      Thus we will need a 'compatibility mode'.
806
 */
807
 
808
static int dev_ifconf(char *arg)
809
{
810
        struct ifconf ifc;
811
        struct ifreq ifr;
812
        struct device *dev;
813
        char *pos;
814
        int len;
815
        int err;
816
 
817
        /*
818
         *      Fetch the caller's info block.
819
         */
820
 
821
        err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifconf));
822
        if(err)
823
                return err;
824
        memcpy_fromfs(&ifc, arg, sizeof(struct ifconf));
825
        len = ifc.ifc_len;
826
        pos = ifc.ifc_buf;
827
 
828
        /*
829
         *      We now walk the device list filling each active device
830
         *      into the array.
831
         */
832
 
833
        err=verify_area(VERIFY_WRITE,pos,len);
834
        if(err)
835
                return err;
836
 
837
        /*
838
         *      Loop over the interfaces, and write an info block for each.
839
         */
840
 
841
        for (dev = dev_base; dev != NULL; dev = dev->next)
842
        {
843
                if(!(dev->flags & IFF_UP))      /* Downed devices don't count */
844
                        continue;
845
                /*
846
                 *      Have we run out of space here ?
847
                 */
848
 
849
                if (len < sizeof(struct ifreq))
850
                        break;
851
 
852
                memset(&ifr, 0, sizeof(struct ifreq));
853
                strcpy(ifr.ifr_name, dev->name);
854
                (*(struct sockaddr_in *) &ifr.ifr_addr).sin_family = dev->family;
855
                (*(struct sockaddr_in *) &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
856
 
857
 
858
                /*
859
                 *      Write this block to the caller's space.
860
                 */
861
 
862
                memcpy_tofs(pos, &ifr, sizeof(struct ifreq));
863
                pos += sizeof(struct ifreq);
864
                len -= sizeof(struct ifreq);
865
        }
866
 
867
        /*
868
         *      All done.  Write the updated control block back to the caller.
869
         */
870
 
871
        ifc.ifc_len = (pos - ifc.ifc_buf);
872
        ifc.ifc_req = (struct ifreq *) ifc.ifc_buf;
873
        memcpy_tofs(arg, &ifc, sizeof(struct ifconf));
874
 
875
        /*
876
         *      Report how much was filled in
877
         */
878
 
879
        return(pos - arg);
880
}
881
 
882
 
883
/*
884
 *      This is invoked by the /proc filesystem handler to display a device
885
 *      in detail.
886
 */
887
 
888
#ifdef CONFIG_PROC_FS
889
static int sprintf_stats(char *buffer, struct device *dev)
890
{
891
        struct enet_statistics *stats = (dev->get_stats ? dev->get_stats(dev): NULL);
892
        int size;
893
 
894
        if (stats)
895
                size = sprintf(buffer, "%6s:%7d %4d %4d %4d %4d %8d %4d %4d %4d %5d %4d\n",
896
                   dev->name,
897
                   stats->rx_packets, stats->rx_errors,
898
                   stats->rx_dropped + stats->rx_missed_errors,
899
                   stats->rx_fifo_errors,
900
                   stats->rx_length_errors + stats->rx_over_errors
901
                   + stats->rx_crc_errors + stats->rx_frame_errors,
902
                   stats->tx_packets, stats->tx_errors, stats->tx_dropped,
903
                   stats->tx_fifo_errors, stats->collisions,
904
                   stats->tx_carrier_errors + stats->tx_aborted_errors
905
                   + stats->tx_window_errors + stats->tx_heartbeat_errors);
906
        else
907
                size = sprintf(buffer, "%6s: No statistics available.\n", dev->name);
908
 
909
        return size;
910
}
911
 
912
/*
913
 *      Called from the PROCfs module. This now uses the new arbitrary sized /proc/net interface
914
 *      to create /proc/net/dev
915
 */
916
 
917
int dev_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
918
{
919
        int len=0;
920
        off_t begin=0;
921
        off_t pos=0;
922
        int size;
923
 
924
        struct device *dev;
925
 
926
 
927
        size = sprintf(buffer, "Inter-|   Receive                  |  Transmit\n"
928
                            " face |packets errs drop fifo frame|packets errs drop fifo colls carrier\n");
929
 
930
        pos+=size;
931
        len+=size;
932
 
933
 
934
        for (dev = dev_base; dev != NULL; dev = dev->next)
935
        {
936
                size = sprintf_stats(buffer+len, dev);
937
                len+=size;
938
                pos=begin+len;
939
 
940
                if(pos<offset)
941
                {
942
                        len=0;
943
                        begin=pos;
944
                }
945
                if(pos>offset+length)
946
                        break;
947
        }
948
 
949
        *start=buffer+(offset-begin);   /* Start of wanted data */
950
        len-=(offset-begin);            /* Start slop */
951
        if(len>length)
952
                len=length;             /* Ending slop */
953
        return len;
954
}
955
#endif  /* CONFIG_PROC_FS */
956
 
957
 
958
#ifdef CONFIG_NET_RADIO
959
#ifdef CONFIG_PROC_FS
960
 
961
/*
962
 * Print one entry of /proc/net/wireless
963
 * This is a clone of /proc/net/dev (just above)
964
 */
965
static int
966
sprintf_wireless_stats(char *           buffer,
967
                       struct device *  dev)
968
{
969
        /* Get stats from the driver */
970
        struct iw_statistics *stats = (dev->get_wireless_stats ?
971
                                       dev->get_wireless_stats(dev) :
972
                                       (struct iw_statistics *) NULL);
973
        int size;
974
 
975
        if(stats != (struct iw_statistics *) NULL)
976
                size = sprintf(buffer,
977
                               "%6s: %02x  %3d%c %3d%c  %3d%c %5d %5d %5d\n",
978
                               dev->name,
979
                               stats->status,
980
                               stats->qual.qual,
981
                               stats->qual.updated & 1 ? '.' : ' ',
982
                               stats->qual.level,
983
                               stats->qual.updated & 2 ? '.' : ' ',
984
                               stats->qual.noise,
985
                               stats->qual.updated & 3 ? '.' : ' ',
986
                               stats->discard.nwid,
987
                               stats->discard.code,
988
                               stats->discard.misc);
989
        else
990
                size = 0;
991
 
992
        return size;
993
}
994
 
995
/*
996
 * Print info for /proc/net/wireless (print all entries)
997
 * This is a clone of /proc/net/dev (just above)
998
 */
999
int
1000
dev_get_wireless_info(char *    buffer,
1001
                      char **   start,
1002
                      off_t     offset,
1003
                      int       length,
1004
                      int       dummy)
1005
{
1006
        int             len = 0;
1007
        off_t           begin = 0;
1008
        off_t           pos = 0;
1009
        int             size;
1010
 
1011
        struct device * dev;
1012
 
1013
        size = sprintf(buffer,
1014
                       "Inter-|sta|  Quality       |  Discarded packets\n"
1015
                       " face |tus|link level noise| nwid crypt  misc\n");
1016
 
1017
        pos+=size;
1018
        len+=size;
1019
 
1020
 
1021
        for(dev = dev_base; dev != NULL; dev = dev->next)
1022
        {
1023
                size = sprintf_wireless_stats(buffer+len, dev);
1024
                len+=size;
1025
                pos=begin+len;
1026
 
1027
                if(pos < offset)
1028
                {
1029
                        len=0;
1030
                        begin=pos;
1031
                }
1032
                if(pos > offset + length)
1033
                        break;
1034
        }
1035
 
1036
        *start = buffer + (offset - begin);     /* Start of wanted data */
1037
        len -= (offset - begin);                /* Start slop */
1038
        if(len > length)
1039
                len = length;           /* Ending slop */
1040
 
1041
        return len;
1042
}
1043
#endif  /* CONFIG_PROC_FS */
1044
#endif  /* CONFIG_NET_RADIO */
1045
 
1046
 
1047
/*
1048
 *      This checks bitmasks for the ioctl calls for devices.
1049
 */
1050
 
1051
static inline int bad_mask(unsigned long mask, unsigned long addr)
1052
{
1053
        if (addr & (mask = ~mask))
1054
                return 1;
1055
        mask = ntohl(mask);
1056
        if (mask & (mask+1))
1057
                return 1;
1058
        return 0;
1059
}
1060
 
1061
/*
1062
 *      Perform the SIOCxIFxxx calls.
1063
 *
1064
 *      The socket layer has seen an ioctl the address family thinks is
1065
 *      for the device. At this point we get invoked to make a decision
1066
 */
1067
 
1068
static int dev_ifsioc(void *arg, unsigned int getset)
1069
{
1070
        struct ifreq ifr;
1071
        struct device *dev;
1072
        int ret;
1073
 
1074
        /*
1075
         *      Fetch the caller's info block into kernel space
1076
         */
1077
 
1078
        int err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifreq));
1079
        if(err)
1080
                return err;
1081
 
1082
        memcpy_fromfs(&ifr, arg, sizeof(struct ifreq));
1083
 
1084
        /*
1085
         *      See which interface the caller is talking about.
1086
         */
1087
 
1088
        /*
1089
         *
1090
         *      net_alias_dev_get(): dev_get() with added alias naming magic.
1091
         *      only allow alias creation/deletion if (getset==SIOCSIFADDR)
1092
         *
1093
         */
1094
 
1095
#ifdef CONFIG_KERNELD
1096
        dev_load(ifr.ifr_name);
1097
#endif  
1098
 
1099
#ifdef CONFIG_NET_ALIAS
1100
        if ((dev = net_alias_dev_get(ifr.ifr_name, getset == SIOCSIFADDR, &err, NULL, NULL)) == NULL)
1101
                return(err);
1102
#else
1103
        if ((dev = dev_get(ifr.ifr_name)) == NULL)
1104
                return(-ENODEV);
1105
#endif
1106
        switch(getset)
1107
        {
1108
                case SIOCGIFFLAGS:      /* Get interface flags */
1109
                        ifr.ifr_flags = (dev->flags & ~IFF_SOFTHEADERS);
1110
                        goto rarok;
1111
 
1112
                case SIOCSIFFLAGS:      /* Set interface flags */
1113
                        {
1114
                                int old_flags = dev->flags;
1115
 
1116
                                if(securelevel>0)
1117
                                        ifr.ifr_flags&=~IFF_PROMISC;
1118
                                /*
1119
                                 *      We are not allowed to potentially close/unload
1120
                                 *      a device until we get this lock.
1121
                                 */
1122
 
1123
                                dev_lock_wait();
1124
 
1125
                                /*
1126
                                 *      Set the flags on our device.
1127
                                 */
1128
 
1129
                                dev->flags = (ifr.ifr_flags & (
1130
                                        IFF_BROADCAST | IFF_DEBUG | IFF_LOOPBACK |
1131
                                        IFF_POINTOPOINT | IFF_NOTRAILERS | IFF_RUNNING |
1132
                                        IFF_NOARP | IFF_PROMISC | IFF_ALLMULTI | IFF_SLAVE | IFF_MASTER
1133
                                        | IFF_MULTICAST)) | (dev->flags & (IFF_SOFTHEADERS|IFF_UP));
1134
                                /*
1135
                                 *      Load in the correct multicast list now the flags have changed.
1136
                                 */
1137
 
1138
                                dev_mc_upload(dev);
1139
 
1140
                                /*
1141
                                 *      Have we downed the interface. We handle IFF_UP ourselves
1142
                                 *      according to user attempts to set it, rather than blindly
1143
                                 *      setting it.
1144
                                 */
1145
 
1146
                                if ((old_flags^ifr.ifr_flags)&IFF_UP)   /* Bit is different  ? */
1147
                                {
1148
                                        if(old_flags&IFF_UP)            /* Gone down */
1149
                                                ret=dev_close(dev);
1150
                                        else                            /* Come up */
1151
                                        {
1152
                                                ret=dev_open(dev);
1153
                                                if(ret<0)
1154
                                                        dev->flags&=~IFF_UP;    /* Open failed */
1155
                                        }
1156
                                }
1157
                                else
1158
                                        ret=0;
1159
                                /*
1160
                                 *      Load in the correct multicast list now the flags have changed.
1161
                                 */
1162
 
1163
                                dev_mc_upload(dev);
1164
                        }
1165
                        break;
1166
 
1167
                case SIOCGIFADDR:       /* Get interface address (and family) */
1168
                        if(ifr.ifr_addr.sa_family==AF_UNSPEC)
1169
                        {
1170
                                memcpy(ifr.ifr_hwaddr.sa_data,dev->dev_addr, MAX_ADDR_LEN);
1171
                                ifr.ifr_hwaddr.sa_family=dev->type;
1172
                                goto rarok;
1173
                        }
1174
                        else
1175
                        {
1176
                                (*(struct sockaddr_in *)
1177
                                          &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
1178
                                (*(struct sockaddr_in *)
1179
                                          &ifr.ifr_addr).sin_family = dev->family;
1180
                                (*(struct sockaddr_in *)
1181
                                          &ifr.ifr_addr).sin_port = 0;
1182
                        }
1183
                        goto rarok;
1184
 
1185
                case SIOCSIFADDR:       /* Set interface address (and family) */
1186
 
1187
                        /*
1188
                         *      BSDism. SIOCSIFADDR family=AF_UNSPEC sets the
1189
                         *      physical address. We can cope with this now.
1190
                         */
1191
 
1192
                        if(ifr.ifr_addr.sa_family==AF_UNSPEC)
1193
                        {
1194
                                if(dev->set_mac_address==NULL)
1195
                                        return -EOPNOTSUPP;
1196
                                if(securelevel>0)
1197
                                        return -EPERM;
1198
                                ret=dev->set_mac_address(dev,&ifr.ifr_addr);
1199
                        }
1200
                        else
1201
                        {
1202
                                u32 new_pa_addr = (*(struct sockaddr_in *)
1203
                                         &ifr.ifr_addr).sin_addr.s_addr;
1204
                                u16 new_family = ifr.ifr_addr.sa_family;
1205
 
1206
                                if (new_family == dev->family &&
1207
                                    new_pa_addr == dev->pa_addr) {
1208
                                        ret =0;
1209
                                        break;
1210
                                }
1211
                                if (dev->flags & IFF_UP)
1212
                                        notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
1213
 
1214
                                /*
1215
                                 *      if dev is an alias, must rehash to update
1216
                                 *      address change
1217
                                 */
1218
 
1219
#ifdef CONFIG_NET_ALIAS
1220
                                if (net_alias_is(dev))
1221
                                        net_alias_dev_rehash(dev ,&ifr.ifr_addr);
1222
#endif
1223
                                dev->pa_addr = new_pa_addr;
1224
                                dev->family = new_family;
1225
 
1226
#ifdef CONFIG_INET      
1227
                                /* This is naughty. When net-032e comes out It wants moving into the net032
1228
                                   code not the kernel. Till then it can sit here (SIGH) */
1229
                                if (!dev->pa_mask)
1230
                                        dev->pa_mask = ip_get_mask(dev->pa_addr);
1231
#endif                  
1232
                                if (!dev->pa_brdaddr)
1233
                                        dev->pa_brdaddr = dev->pa_addr | ~dev->pa_mask;
1234
                                if (dev->flags & IFF_UP)
1235
                                        notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
1236
                                ret = 0;
1237
                        }
1238
                        break;
1239
 
1240
                case SIOCGIFBRDADDR:    /* Get the broadcast address */
1241
                        (*(struct sockaddr_in *)
1242
                                &ifr.ifr_broadaddr).sin_addr.s_addr = dev->pa_brdaddr;
1243
                        (*(struct sockaddr_in *)
1244
                                &ifr.ifr_broadaddr).sin_family = dev->family;
1245
                        (*(struct sockaddr_in *)
1246
                                &ifr.ifr_broadaddr).sin_port = 0;
1247
                        goto rarok;
1248
 
1249
                case SIOCSIFBRDADDR:    /* Set the broadcast address */
1250
                        dev->pa_brdaddr = (*(struct sockaddr_in *)
1251
                                &ifr.ifr_broadaddr).sin_addr.s_addr;
1252
                        ret = 0;
1253
                        break;
1254
 
1255
                case SIOCGIFDSTADDR:    /* Get the destination address (for point-to-point links) */
1256
                        (*(struct sockaddr_in *)
1257
                                &ifr.ifr_dstaddr).sin_addr.s_addr = dev->pa_dstaddr;
1258
                        (*(struct sockaddr_in *)
1259
                                &ifr.ifr_dstaddr).sin_family = dev->family;
1260
                        (*(struct sockaddr_in *)
1261
                                &ifr.ifr_dstaddr).sin_port = 0;
1262
                        goto rarok;
1263
 
1264
                case SIOCSIFDSTADDR:    /* Set the destination address (for point-to-point links) */
1265
                        dev->pa_dstaddr = (*(struct sockaddr_in *)
1266
                                &ifr.ifr_dstaddr).sin_addr.s_addr;
1267
                        ret = 0;
1268
                        break;
1269
 
1270
                case SIOCGIFNETMASK:    /* Get the netmask for the interface */
1271
                        (*(struct sockaddr_in *)
1272
                                &ifr.ifr_netmask).sin_addr.s_addr = dev->pa_mask;
1273
                        (*(struct sockaddr_in *)
1274
                                &ifr.ifr_netmask).sin_family = dev->family;
1275
                        (*(struct sockaddr_in *)
1276
                                &ifr.ifr_netmask).sin_port = 0;
1277
                        goto rarok;
1278
 
1279
                case SIOCSIFNETMASK:    /* Set the netmask for the interface */
1280
                        {
1281
                                unsigned long mask = (*(struct sockaddr_in *)
1282
                                        &ifr.ifr_netmask).sin_addr.s_addr;
1283
                                ret = -EINVAL;
1284
                                /*
1285
                                 *      The mask we set must be legal.
1286
                                 */
1287
                                if (bad_mask(mask,0))
1288
                                        break;
1289
                                dev->pa_mask = mask;
1290
                                ret = 0;
1291
                        }
1292
                        break;
1293
 
1294
                case SIOCGIFMETRIC:     /* Get the metric on the interface (currently unused) */
1295
 
1296
                        ifr.ifr_metric = dev->metric;
1297
                        goto  rarok;
1298
 
1299
                case SIOCSIFMETRIC:     /* Set the metric on the interface (currently unused) */
1300
                        dev->metric = ifr.ifr_metric;
1301
                        ret=0;
1302
                        break;
1303
 
1304
                case SIOCGIFMTU:        /* Get the MTU of a device */
1305
                        ifr.ifr_mtu = dev->mtu;
1306
                        goto rarok;
1307
 
1308
                case SIOCSIFMTU:        /* Set the MTU of a device */
1309
 
1310
                        if (dev->change_mtu)
1311
                                ret = dev->change_mtu(dev, ifr.ifr_mtu);
1312
                        else
1313
                        {
1314
                                /*
1315
                                 *      MTU must be positive.
1316
                                 */
1317
 
1318
                                if(ifr.ifr_mtu<68)
1319
                                        return -EINVAL;
1320
 
1321
                                dev->mtu = ifr.ifr_mtu;
1322
                                ret = 0;
1323
                        }
1324
                        break;
1325
 
1326
                case SIOCGIFMEM:        /* Get the per device memory space. We can add this but currently
1327
                                           do not support it */
1328
                        ret = -EINVAL;
1329
                        break;
1330
 
1331
                case SIOCSIFMEM:        /* Set the per device memory buffer space. Not applicable in our case */
1332
                        ret = -EINVAL;
1333
                        break;
1334
 
1335
                case SIOCGIFHWADDR:
1336
                        memcpy(ifr.ifr_hwaddr.sa_data,dev->dev_addr, MAX_ADDR_LEN);
1337
                        ifr.ifr_hwaddr.sa_family=dev->type;
1338
                        goto rarok;
1339
 
1340
                case SIOCSIFHWADDR:
1341
                        if(dev->set_mac_address==NULL)
1342
                                return -EOPNOTSUPP;
1343
                        if(securelevel > 0)
1344
                                return -EPERM;
1345
                        if(ifr.ifr_hwaddr.sa_family!=dev->type)
1346
                                return -EINVAL;
1347
                        ret=dev->set_mac_address(dev,&ifr.ifr_hwaddr);
1348
                        break;
1349
 
1350
                case SIOCGIFMAP:
1351
                        ifr.ifr_map.mem_start=dev->mem_start;
1352
                        ifr.ifr_map.mem_end=dev->mem_end;
1353
                        ifr.ifr_map.base_addr=dev->base_addr;
1354
                        ifr.ifr_map.irq=dev->irq;
1355
                        ifr.ifr_map.dma=dev->dma;
1356
                        ifr.ifr_map.port=dev->if_port;
1357
                        goto rarok;
1358
 
1359
                case SIOCSIFMAP:
1360
                        if(dev->set_config==NULL)
1361
                                return -EOPNOTSUPP;
1362
                        return dev->set_config(dev,&ifr.ifr_map);
1363
 
1364
                case SIOCADDMULTI:
1365
                        if(dev->set_multicast_list==NULL)
1366
                                return -EINVAL;
1367
                        if(ifr.ifr_hwaddr.sa_family!=AF_UNSPEC)
1368
                                return -EINVAL;
1369
                        dev_mc_add(dev,ifr.ifr_hwaddr.sa_data, dev->addr_len, 1);
1370
                        return 0;
1371
 
1372
                case SIOCDELMULTI:
1373
                        if(dev->set_multicast_list==NULL)
1374
                                return -EINVAL;
1375
                        if(ifr.ifr_hwaddr.sa_family!=AF_UNSPEC)
1376
                                return -EINVAL;
1377
                        dev_mc_delete(dev,ifr.ifr_hwaddr.sa_data,dev->addr_len, 1);
1378
                        return 0;
1379
                /*
1380
                 *      Unknown or private ioctl
1381
                 */
1382
 
1383
                default:
1384
                        if((getset >= SIOCDEVPRIVATE) &&
1385
                           (getset <= (SIOCDEVPRIVATE + 15))) {
1386
                                if(dev->do_ioctl==NULL)
1387
                                        return -EOPNOTSUPP;
1388
                                ret=dev->do_ioctl(dev, &ifr, getset);
1389
                                memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1390
                                break;
1391
                        }
1392
 
1393
#ifdef CONFIG_NET_RADIO
1394
                        if((getset >= SIOCIWFIRST) &&
1395
                           (getset <= SIOCIWLAST))
1396
                        {
1397
                                if(dev->do_ioctl==NULL)
1398
                                        return -EOPNOTSUPP;
1399
                                /* Perform the ioctl */
1400
                                ret=dev->do_ioctl(dev, &ifr, getset);
1401
                                /* If return args... */
1402
                                if(IW_IS_GET(getset))
1403
                                        memcpy_tofs(arg, &ifr,
1404
                                                    sizeof(struct ifreq));
1405
                                break;
1406
                        }
1407
#endif  /* CONFIG_NET_RADIO */
1408
 
1409
                        ret = -EINVAL;
1410
        }
1411
        return(ret);
1412
/*
1413
 *      The load of calls that return an ifreq and ok (saves memory).
1414
 */
1415
rarok:
1416
        memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1417
        return 0;
1418
}
1419
 
1420
 
1421
/*
1422
 *      This function handles all "interface"-type I/O control requests. The actual
1423
 *      'doing' part of this is dev_ifsioc above.
1424
 */
1425
 
1426
int dev_ioctl(unsigned int cmd, void *arg)
1427
{
1428
        switch(cmd)
1429
        {
1430
                case SIOCGIFCONF:
1431
                        (void) dev_ifconf((char *) arg);
1432
                        return 0;
1433
 
1434
                /*
1435
                 *      Ioctl calls that can be done by all.
1436
                 */
1437
 
1438
                case SIOCGIFFLAGS:
1439
                case SIOCGIFADDR:
1440
                case SIOCGIFDSTADDR:
1441
                case SIOCGIFBRDADDR:
1442
                case SIOCGIFNETMASK:
1443
                case SIOCGIFMETRIC:
1444
                case SIOCGIFMTU:
1445
                case SIOCGIFMEM:
1446
                case SIOCGIFHWADDR:
1447
                case SIOCGIFSLAVE:
1448
                case SIOCGIFMAP:
1449
                        return dev_ifsioc(arg, cmd);
1450
 
1451
                /*
1452
                 *      Ioctl calls requiring the power of a superuser
1453
                 */
1454
 
1455
                case SIOCSIFFLAGS:
1456
                case SIOCSIFADDR:
1457
                case SIOCSIFDSTADDR:
1458
                case SIOCSIFBRDADDR:
1459
                case SIOCSIFNETMASK:
1460
                case SIOCSIFMETRIC:
1461
                case SIOCSIFMTU:
1462
                case SIOCSIFMEM:
1463
                case SIOCSIFHWADDR:
1464
                case SIOCSIFMAP:
1465
                case SIOCSIFSLAVE:
1466
                case SIOCADDMULTI:
1467
                case SIOCDELMULTI:
1468
                        if (!suser())
1469
                                return -EPERM;
1470
                        return dev_ifsioc(arg, cmd);
1471
 
1472
                case SIOCSIFLINK:
1473
                        return -EINVAL;
1474
 
1475
                /*
1476
                 *      Unknown or private ioctl.
1477
                 */
1478
 
1479
                default:
1480
                        if((cmd >= SIOCDEVPRIVATE) &&
1481
                           (cmd <= (SIOCDEVPRIVATE + 15))) {
1482
                                return dev_ifsioc(arg, cmd);
1483
                        }
1484
#ifdef CONFIG_NET_RADIO
1485
                        if((cmd >= SIOCIWFIRST) &&
1486
                           (cmd <= SIOCIWLAST))
1487
                        {
1488
                                if((IW_IS_SET(cmd)) && (!suser()))
1489
                                        return -EPERM;
1490
                                return dev_ifsioc(arg, cmd);
1491
                        }
1492
#endif  /* CONFIG_NET_RADIO */
1493
                        return -EINVAL;
1494
        }
1495
}
1496
 
1497
 
1498
/*
1499
 *      Initialize the DEV module. At boot time this walks the device list and
1500
 *      unhooks any devices that fail to initialise (normally hardware not
1501
 *      present) and leaves us with a valid list of present and active devices.
1502
 *
1503
 */
1504
extern int lance_init(void);
1505
extern int pi_init(void);
1506
extern int pt_init(void);
1507
extern int bpq_init(void);
1508
extern void sdla_setup(void);
1509
extern int dlci_setup(void);
1510
extern int sm_init(void);
1511
extern int baycom_init(void);
1512
 
1513
#ifdef CONFIG_PROC_FS
1514
static struct proc_dir_entry pde1 = {
1515
                PROC_NET_DEV, 3, "dev",
1516
                S_IFREG | S_IRUGO, 1, 0, 0,
1517
                0, &proc_net_inode_operations,
1518
                dev_get_info
1519
        };
1520
#endif
1521
 
1522
#ifdef CONFIG_NET_RADIO
1523
#ifdef CONFIG_PROC_FS
1524
static struct proc_dir_entry pde2 = {
1525
                PROC_NET_WIRELESS, 8, "wireless",
1526
                S_IFREG | S_IRUGO, 1, 0, 0,
1527
                0, &proc_net_inode_operations,
1528
                dev_get_wireless_info
1529
        };
1530
#endif  /* CONFIG_PROC_FS */
1531
#endif  /* CONFIG_NET_RADIO */
1532
 
1533
 
1534
int net_dev_init(void)
1535
{
1536
        struct device *dev, **dp;
1537
 
1538
        /*
1539
         *      Initialise the packet receive queue.
1540
         */
1541
 
1542
        skb_queue_head_init(&backlog);
1543
 
1544
        /*
1545
         *      The bridge has to be up before the devices
1546
         */
1547
 
1548
#ifdef CONFIG_BRIDGE     
1549
        br_init();
1550
#endif  
1551
 
1552
        /*
1553
         * This is Very Ugly(tm).
1554
         *
1555
         * Some devices want to be initialized early..
1556
         */
1557
#if defined(CONFIG_PI)
1558
        pi_init();
1559
#endif  
1560
#if defined(CONFIG_PT)
1561
        pt_init();
1562
#endif
1563
#if defined(CONFIG_BPQETHER)
1564
        bpq_init();
1565
#endif
1566
#if defined(CONFIG_DLCI)
1567
        dlci_setup();
1568
#endif
1569
#if defined(CONFIG_SDLA)
1570
        sdla_setup();
1571
#endif
1572
#if defined(CONFIG_BAYCOM)
1573
        baycom_init();
1574
#endif
1575
#if defined(CONFIG_SOUNDMODEM)
1576
        sm_init();
1577
#endif
1578
        /*
1579
         *      SLHC if present needs attaching so other people see it
1580
         *      even if not opened.
1581
         */
1582
#if (defined(CONFIG_SLIP) && defined(CONFIG_SLIP_COMPRESSED)) \
1583
         || defined(CONFIG_PPP) \
1584
    || (defined(CONFIG_ISDN) && defined(CONFIG_ISDN_PPP))
1585
        slhc_install();
1586
#endif  
1587
 
1588
        /*
1589
         *      Add the devices.
1590
         *      If the call to dev->init fails, the dev is removed
1591
         *      from the chain disconnecting the device until the
1592
         *      next reboot.
1593
         */
1594
 
1595
        dp = &dev_base;
1596
        while ((dev = *dp) != NULL)
1597
        {
1598
                int i;
1599
                for (i = 0; i < DEV_NUMBUFFS; i++)  {
1600
                        skb_queue_head_init(dev->buffs + i);
1601
                }
1602
 
1603
                if (dev->init && dev->init(dev))
1604
                {
1605
                        /*
1606
                         *      It failed to come up. Unhook it.
1607
                         */
1608
                        *dp = dev->next;
1609
                }
1610
                else
1611
                {
1612
                        dp = &dev->next;
1613
                }
1614
        }
1615
 
1616
#ifdef CONFIG_PROC_FS
1617
        proc_net_register(&pde1);
1618
#endif
1619
 
1620
#ifdef CONFIG_NET_RADIO
1621
#ifdef CONFIG_PROC_FS
1622
        proc_net_register(&pde2);
1623
#endif  /* CONFIG_PROC_FS */
1624
#endif  /* CONFIG_NET_RADIO */
1625
 
1626
        /*
1627
         *      Initialise net_alias engine
1628
         *
1629
         *              - register net_alias device notifier
1630
         *              - register proc entries:        /proc/net/alias_types
1631
         *                                                                      /proc/net/aliases
1632
         */
1633
 
1634
#ifdef CONFIG_NET_ALIAS
1635
        net_alias_init();
1636
#endif
1637
 
1638
        init_bh(NET_BH, net_bh);
1639
        return 0;
1640
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.