root/net/inet/dev.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. min
  2. dev_add_pack
  3. dev_remove_pack
  4. dev_get
  5. dev_open
  6. dev_close
  7. register_netdevice_notifier
  8. unregister_netdevice_notifier
  9. dev_queue_xmit
  10. netif_rx
  11. dev_rint
  12. dev_transmit
  13. in_net_bh
  14. net_bh
  15. dev_tint
  16. dev_ifconf
  17. sprintf_stats
  18. dev_get_info
  19. bad_mask
  20. dev_ifsioc
  21. dev_ioctl
  22. dev_init

   1 /*
   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  *
  32  *      Cleaned up and recommented by Alan Cox 2nd April 1994. I hope to have
  33  *      the rest as well commented in the end.
  34  */
  35 
  36 /*
  37  *      A lot of these includes will be going walkies very soon 
  38  */
  39  
  40 #include <asm/segment.h>
  41 #include <asm/system.h>
  42 #include <asm/bitops.h>
  43 #include <linux/config.h>
  44 #include <linux/types.h>
  45 #include <linux/kernel.h>
  46 #include <linux/sched.h>
  47 #include <linux/string.h>
  48 #include <linux/mm.h>
  49 #include <linux/socket.h>
  50 #include <linux/sockios.h>
  51 #include <linux/in.h>
  52 #include <linux/errno.h>
  53 #include <linux/interrupt.h>
  54 #include <linux/if_ether.h>
  55 #include <linux/inet.h>
  56 #include <linux/netdevice.h>
  57 #include <linux/etherdevice.h>
  58 #include <linux/notifier.h>
  59 #include "ip.h"
  60 #include "route.h"
  61 #include <linux/skbuff.h>
  62 #include "sock.h"
  63 #include "arp.h"
  64 
  65 
  66 /*
  67  *      The list of packet types we will receive (as opposed to discard)
  68  *      and the routines to invoke.
  69  */
  70 
  71 struct packet_type *ptype_base = NULL;
  72 
  73 /*
  74  *      Our notifier list
  75  */
  76  
  77 struct notifier_block *netdev_chain=NULL;
  78 
  79 /*
  80  *      Device drivers call our routines to queue packets here. We empty the
  81  *      queue in the bottom half handler.
  82  */
  83 
  84 static struct sk_buff_head backlog = 
  85 {
  86         (struct sk_buff *)&backlog, (struct sk_buff *)&backlog
  87 #ifdef CONFIG_SKB_CHECK
  88         ,SK_HEAD_SKB
  89 #endif
  90 };
  91 
  92 /* 
  93  *      We don't overdo the queue or we will thrash memory badly.
  94  */
  95  
  96 static int backlog_size = 0;
  97 
  98 /*
  99  *      Return the lesser of the two values. 
 100  */
 101  
 102 static __inline__ unsigned long min(unsigned long a, unsigned long b)
     /* [previous][next][first][last][top][bottom][index][help] */
 103 {
 104   return (a < b)? a : b;
 105 }
 106 
 107 
 108 /******************************************************************************************
 109 
 110                 Protocol management and registration routines
 111 
 112 *******************************************************************************************/
 113 
 114 /*
 115  *      For efficiency
 116  */
 117 
 118 static int dev_nit=0;
 119 
 120 /*
 121  *      Add a protocol ID to the list. Now that the input handler is
 122  *      smarter we can dispense with all the messy stuff that used to be
 123  *      here.
 124  */
 125  
 126 void dev_add_pack(struct packet_type *pt)
     /* [previous][next][first][last][top][bottom][index][help] */
 127 {
 128         if(pt->type==htons(ETH_P_ALL))
 129                 dev_nit++;
 130         pt->next = ptype_base;
 131         ptype_base = pt;
 132 }
 133 
 134 
 135 /*
 136  *      Remove a protocol ID from the list.
 137  */
 138  
 139 void dev_remove_pack(struct packet_type *pt)
     /* [previous][next][first][last][top][bottom][index][help] */
 140 {
 141         struct packet_type **pt1;
 142         if(pt->type==htons(ETH_P_ALL))
 143                 dev_nit--;
 144         for(pt1=&ptype_base; (*pt1)!=NULL; pt1=&((*pt1)->next))
 145         {
 146                 if(pt==(*pt1))
 147                 {
 148                         *pt1=pt->next;
 149                         return;
 150                 }
 151         }
 152 }
 153 
 154 /*****************************************************************************************
 155 
 156                             Device Interface Subroutines
 157 
 158 ******************************************************************************************/
 159 
 160 /* 
 161  *      Find an interface by name.
 162  */
 163  
 164 struct device *dev_get(char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
 165 {
 166         struct device *dev;
 167 
 168         for (dev = dev_base; dev != NULL; dev = dev->next) 
 169         {
 170                 if (strcmp(dev->name, name) == 0)
 171                         return(dev);
 172         }
 173         return(NULL);
 174 }
 175 
 176 
 177 /*
 178  *      Prepare an interface for use. 
 179  */
 180  
 181 int dev_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 182 {
 183         int ret = 0;
 184 
 185         /*
 186          *      Call device private open method
 187          */
 188         if (dev->open) 
 189                 ret = dev->open(dev);
 190 
 191         /*
 192          *      If it went open OK then set the flags
 193          */
 194          
 195         if (ret == 0) 
 196         {
 197                 dev->flags |= (IFF_UP | IFF_RUNNING);
 198                 /*
 199                  *      Initialise multicasting status 
 200                  */
 201 #ifdef CONFIG_IP_MULTICAST
 202                 /* 
 203                  *      Join the all host group 
 204                  */
 205                 ip_mc_allhost(dev);
 206 #endif                          
 207                 dev_mc_upload(dev);
 208                 notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
 209         }
 210         return(ret);
 211 }
 212 
 213 
 214 /*
 215  *      Completely shutdown an interface.
 216  */
 217  
 218 int dev_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 219 {
 220         /*
 221          *      Only close a device if it is up.
 222          */
 223          
 224         if (dev->flags != 0) 
 225         {
 226                 int ct=0;
 227                 dev->flags = 0;
 228                 /*
 229                  *      Call the device specific close. This cannot fail.
 230                  */
 231                 if (dev->stop) 
 232                         dev->stop(dev);
 233                         
 234                 notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
 235 #if 0           
 236                 /*
 237                  *      Delete the route to the device.
 238                  */
 239 #ifdef CONFIG_INET               
 240                 ip_rt_flush(dev);
 241                 arp_device_down(dev);
 242 #endif          
 243 #ifdef CONFIG_IPX
 244                 ipxrtr_device_down(dev);
 245 #endif  
 246 #endif
 247                 /*
 248                  *      Flush the multicast chain
 249                  */
 250                 dev_mc_discard(dev);
 251                 /*
 252                  *      Blank the IP addresses
 253                  */
 254                 dev->pa_addr = 0;
 255                 dev->pa_dstaddr = 0;
 256                 dev->pa_brdaddr = 0;
 257                 dev->pa_mask = 0;
 258                 /*
 259                  *      Purge any queued packets when we down the link 
 260                  */
 261                 while(ct<DEV_NUMBUFFS)
 262                 {
 263                         struct sk_buff *skb;
 264                         while((skb=skb_dequeue(&dev->buffs[ct]))!=NULL)
 265                                 if(skb->free)
 266                                         kfree_skb(skb,FREE_WRITE);
 267                         ct++;
 268                 }
 269         }
 270         return(0);
 271 }
 272 
 273 
 274 /*
 275  *      Device change register/unregister. These are not inline or static
 276  *      as we export them to the world.
 277  */
 278 
 279 int register_netdevice_notifier(struct notifier_block *nb)
     /* [previous][next][first][last][top][bottom][index][help] */
 280 {
 281         return notifier_chain_register(&netdev_chain, nb);
 282 }
 283 
 284 int unregister_netdevice_notifier(struct notifier_block *nb)
     /* [previous][next][first][last][top][bottom][index][help] */
 285 {
 286         return notifier_chain_unregister(&netdev_chain,nb);
 287 }
 288 
 289 
 290 
 291 /*
 292  *      Send (or queue for sending) a packet. 
 293  *
 294  *      IMPORTANT: When this is called to resend frames. The caller MUST
 295  *      already have locked the sk_buff. Apart from that we do the
 296  *      rest of the magic.
 297  */
 298 
 299 void dev_queue_xmit(struct sk_buff *skb, struct device *dev, int pri)
     /* [previous][next][first][last][top][bottom][index][help] */
 300 {
 301         unsigned long flags;
 302         int nitcount;
 303         struct packet_type *ptype;
 304         int where = 0;          /* used to say if the packet should go  */
 305                                 /* at the front or the back of the      */
 306                                 /* queue - front is a retransmit try    */
 307 
 308         if (dev == NULL) 
 309         {
 310                 printk("dev.c: dev_queue_xmit: dev = NULL\n");
 311                 return;
 312         }
 313         
 314         if(pri>=0 && !skb_device_locked(skb))
 315                 skb_device_lock(skb);   /* Shove a lock on the frame */
 316 #ifdef CONFIG_SLAVE_BALANCING
 317         save_flags(flags);
 318         cli();
 319         if(dev->slave!=NULL && dev->slave->pkt_queue < dev->pkt_queue &&
 320                                 (dev->slave->flags & IFF_UP))
 321                 dev=dev->slave;
 322         restore_flags(flags);
 323 #endif          
 324 #ifdef CONFIG_SKB_CHECK 
 325         IS_SKB(skb);
 326 #endif    
 327         skb->dev = dev;
 328 
 329         /*
 330          *      This just eliminates some race conditions, but not all... 
 331          */
 332 
 333         if (skb->next != NULL) 
 334         {
 335                 /*
 336                  *      Make sure we haven't missed an interrupt. 
 337                  */
 338                 printk("dev_queue_xmit: worked around a missed interrupt\n");
 339                 dev->hard_start_xmit(NULL, dev);
 340                 return;
 341         }
 342 
 343         /*
 344          *      Negative priority is used to flag a frame that is being pulled from the
 345          *      queue front as a retransmit attempt. It therefore goes back on the queue
 346          *      start on a failure.
 347          */
 348          
 349         if (pri < 0) 
 350         {
 351                 pri = -pri-1;
 352                 where = 1;
 353         }
 354 
 355         if (pri >= DEV_NUMBUFFS) 
 356         {
 357                 printk("bad priority in dev_queue_xmit.\n");
 358                 pri = 1;
 359         }
 360 
 361         /*
 362          *      If the address has not been resolved. Call the device header rebuilder.
 363          *      This can cover all protocols and technically not just ARP either.
 364          */
 365          
 366         if (!skb->arp && dev->rebuild_header(skb->data, dev, skb->raddr, skb)) {
 367                 return;
 368         }
 369 
 370         save_flags(flags);
 371         cli();  
 372         if (!where) {
 373 #ifdef CONFIG_SLAVE_BALANCING   
 374                 skb->in_dev_queue=1;
 375 #endif          
 376                 skb_queue_tail(dev->buffs + pri,skb);
 377                 skb_device_unlock(skb);         /* Buffer is on the device queue and can be freed safely */
 378                 skb = skb_dequeue(dev->buffs + pri);
 379                 skb_device_lock(skb);           /* New buffer needs locking down */
 380 #ifdef CONFIG_SLAVE_BALANCING           
 381                 skb->in_dev_queue=0;
 382 #endif          
 383         }
 384         restore_flags(flags);
 385 
 386         /* copy outgoing packets to any sniffer packet handlers */
 387         if(!where)
 388         {
 389                 for (nitcount= dev_nit, ptype = ptype_base; nitcount > 0 && ptype != NULL; ptype = ptype->next) 
 390                 {
 391                         /* Never send packets back to the socket
 392                          * they originated from - MvS (miquels@drinkel.ow.org)
 393                          */
 394                         if (ptype->type == htons(ETH_P_ALL) &&
 395                            (ptype->dev == dev || !ptype->dev) &&
 396                            ((struct sock *)ptype->data != skb->sk))
 397                         {
 398                                 struct sk_buff *skb2;
 399                                 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL)
 400                                         break;
 401                                 ptype->func(skb2, skb->dev, ptype);
 402                                 nitcount--;
 403                         }
 404                 }
 405         }
 406         if (dev->hard_start_xmit(skb, dev) == 0) {
 407                 /*
 408                  *      Packet is now solely the responsibility of the driver
 409                  */
 410                 return;
 411         }
 412 
 413         /*
 414          *      Transmission failed, put skb back into a list. Once on the list its safe and
 415          *      no longer device locked (it can be freed safely from the device queue)
 416          */
 417         cli();
 418 #ifdef CONFIG_SLAVE_BALANCING
 419         skb->in_dev_queue=1;
 420         dev->pkt_queue++;
 421 #endif          
 422         skb_device_unlock(skb);
 423         skb_queue_head(dev->buffs + pri,skb);
 424         restore_flags(flags);
 425 }
 426 
 427 /*
 428  *      Receive a packet from a device driver and queue it for the upper
 429  *      (protocol) levels.  It always succeeds. This is the recommended 
 430  *      interface to use.
 431  */
 432 
 433 void netif_rx(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 434 {
 435         static int dropping = 0;
 436 
 437         /*
 438          *      Any received buffers are un-owned and should be discarded
 439          *      when freed. These will be updated later as the frames get
 440          *      owners.
 441          */
 442         skb->sk = NULL;
 443         skb->free = 1;
 444         if(skb->stamp.tv_sec==0)
 445                 skb->stamp = xtime;
 446 
 447         /*
 448          *      Check that we aren't overdoing things.
 449          */
 450 
 451         if (!backlog_size)
 452                 dropping = 0;
 453         else if (backlog_size > 300)
 454                 dropping = 1;
 455 
 456         if (dropping) 
 457         {
 458                 kfree_skb(skb, FREE_READ);
 459                 return;
 460         }
 461 
 462         /*
 463          *      Add it to the "backlog" queue. 
 464          */
 465 #ifdef CONFIG_SKB_CHECK
 466         IS_SKB(skb);
 467 #endif  
 468         skb_queue_tail(&backlog,skb);
 469         backlog_size++;
 470   
 471         /*
 472          *      If any packet arrived, mark it for processing after the
 473          *      hardware interrupt returns.
 474          */
 475 
 476         mark_bh(NET_BH);
 477         return;
 478 }
 479 
 480 
 481 /*
 482  *      The old interface to fetch a packet from a device driver.
 483  *      This function is the base level entry point for all drivers that
 484  *      want to send a packet to the upper (protocol) levels.  It takes
 485  *      care of de-multiplexing the packet to the various modules based
 486  *      on their protocol ID.
 487  *
 488  *      Return values:  1 <- exit I can't do any more
 489  *                      0 <- feed me more (i.e. "done", "OK"). 
 490  *
 491  *      This function is OBSOLETE and should not be used by any new
 492  *      device.
 493  */
 494 
 495 int dev_rint(unsigned char *buff, long len, int flags, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 496 {
 497         static int dropping = 0;
 498         struct sk_buff *skb = NULL;
 499         unsigned char *to;
 500         int amount, left;
 501         int len2;
 502 
 503         if (dev == NULL || buff == NULL || len <= 0) 
 504                 return(1);
 505 
 506         if (flags & IN_SKBUFF) 
 507         {
 508                 skb = (struct sk_buff *) buff;
 509         }
 510         else
 511         {
 512                 if (dropping) 
 513                 {
 514                         if (skb_peek(&backlog) != NULL)
 515                                 return(1);
 516                         printk("INET: dev_rint: no longer dropping packets.\n");
 517                         dropping = 0;
 518                 }
 519 
 520                 skb = alloc_skb(len, GFP_ATOMIC);
 521                 if (skb == NULL) 
 522                 {
 523                         printk("dev_rint: packet dropped on %s (no memory) !\n",
 524                                dev->name);
 525                         dropping = 1;
 526                         return(1);
 527                 }
 528 
 529                 /* 
 530                  *      First we copy the packet into a buffer, and save it for later. We
 531                  *      in effect handle the incoming data as if it were from a circular buffer
 532                  */
 533 
 534                 to = skb->data;
 535                 left = len;
 536 
 537                 len2 = len;
 538                 while (len2 > 0) 
 539                 {
 540                         amount = min(len2, (unsigned long) dev->rmem_end -
 541                                                 (unsigned long) buff);
 542                         memcpy(to, buff, amount);
 543                         len2 -= amount;
 544                         left -= amount;
 545                         buff += amount;
 546                         to += amount;
 547                         if ((unsigned long) buff == dev->rmem_end)
 548                                 buff = (unsigned char *) dev->rmem_start;
 549                 }
 550         }
 551 
 552         /*
 553          *      Tag the frame and kick it to the proper receive routine
 554          */
 555          
 556         skb->len = len;
 557         skb->dev = dev;
 558         skb->free = 1;
 559 
 560         netif_rx(skb);
 561         /*
 562          *      OK, all done. 
 563          */
 564         return(0);
 565 }
 566 
 567 
 568 /*
 569  *      This routine causes all interfaces to try to send some data. 
 570  */
 571  
 572 void dev_transmit(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 573 {
 574         struct device *dev;
 575 
 576         for (dev = dev_base; dev != NULL; dev = dev->next) 
 577         {
 578                 if (dev->flags != 0 && !dev->tbusy) {
 579                         /*
 580                          *      Kick the device
 581                          */
 582                         dev_tint(dev);
 583                 }
 584         }
 585 }
 586 
 587 
 588 /**********************************************************************************
 589 
 590                         Receive Queue Processor
 591                         
 592 ***********************************************************************************/
 593 
 594 /*
 595  *      This is a single non-reentrant routine which takes the received packet
 596  *      queue and throws it at the networking layers in the hope that something
 597  *      useful will emerge.
 598  */
 599  
 600 volatile char in_bh = 0;        /* Non-reentrant remember */
 601 
 602 int in_net_bh() /* Used by timer.c */
     /* [previous][next][first][last][top][bottom][index][help] */
 603 {
 604         return(in_bh==0?0:1);
 605 }
 606 
 607 /*
 608  *      When we are called the queue is ready to grab, the interrupts are
 609  *      on and hardware can interrupt and queue to the receive queue a we
 610  *      run with no problems.
 611  *      This is run as a bottom half after an interrupt handler that does
 612  *      mark_bh(NET_BH);
 613  */
 614  
 615 void net_bh(void *tmp)
     /* [previous][next][first][last][top][bottom][index][help] */
 616 {
 617         struct sk_buff *skb;
 618         struct packet_type *ptype;
 619         struct packet_type *pt_prev;
 620         unsigned short type;
 621 
 622         /*
 623          *      Atomically check and mark our BUSY state. 
 624          */
 625 
 626         if (set_bit(1, (void*)&in_bh))
 627                 return;
 628 
 629         /*
 630          *      Can we send anything now? We want to clear the
 631          *      decks for any more sends that get done as we
 632          *      process the input.
 633          */
 634 
 635         dev_transmit();
 636   
 637         /*
 638          *      Any data left to process. This may occur because a
 639          *      mark_bh() is done after we empty the queue including
 640          *      that from the device which does a mark_bh() just after
 641          */
 642 
 643         cli();
 644         
 645         /*
 646          *      While the queue is not empty
 647          */
 648          
 649         while((skb=skb_dequeue(&backlog))!=NULL)
 650         {
 651                 /*
 652                  *      We have a packet. Therefore the queue has shrunk
 653                  */
 654                 backlog_size--;
 655 
 656                 sti();
 657                 
 658                /*
 659                 *       Bump the pointer to the next structure.
 660                 *       This assumes that the basic 'skb' pointer points to
 661                 *       the MAC header, if any (as indicated by its "length"
 662                 *       field).  Take care now!
 663                 */
 664 
 665                 skb->h.raw = skb->data + skb->dev->hard_header_len;
 666                 skb->len -= skb->dev->hard_header_len;
 667 
 668                /*
 669                 *       Fetch the packet protocol ID.  This is also quite ugly, as
 670                 *       it depends on the protocol driver (the interface itself) to
 671                 *       know what the type is, or where to get it from.  The Ethernet
 672                 *       interfaces fetch the ID from the two bytes in the Ethernet MAC
 673                 *       header (the h_proto field in struct ethhdr), but other drivers
 674                 *       may either use the ethernet ID's or extra ones that do not
 675                 *       clash (eg ETH_P_AX25). We could set this before we queue the
 676                 *       frame. In fact I may change this when I have time.
 677                 */
 678                 
 679                 type = skb->dev->type_trans(skb, skb->dev);
 680 
 681                 /*
 682                  *      We got a packet ID.  Now loop over the "known protocols"
 683                  *      table (which is actually a linked list, but this will
 684                  *      change soon if I get my way- FvK), and forward the packet
 685                  *      to anyone who wants it.
 686                  *
 687                  *      [FvK didn't get his way but he is right this ought to be
 688                  *      hashed so we typically get a single hit. The speed cost
 689                  *      here is minimal but no doubt adds up at the 4,000+ pkts/second
 690                  *      rate we can hit flat out]
 691                  */
 692                 pt_prev = NULL;
 693                 for (ptype = ptype_base; ptype != NULL; ptype = ptype->next) 
 694                 {
 695                         if ((ptype->type == type || ptype->type == htons(ETH_P_ALL)) && (!ptype->dev || ptype->dev==skb->dev))
 696                         {
 697                                 /*
 698                                  *      We already have a match queued. Deliver
 699                                  *      to it and then remember the new match
 700                                  */
 701                                 if(pt_prev)
 702                                 {
 703                                         struct sk_buff *skb2;
 704 
 705                                         skb2=skb_clone(skb, GFP_ATOMIC);
 706 
 707                                         /*
 708                                          *      Kick the protocol handler. This should be fast
 709                                          *      and efficient code.
 710                                          */
 711 
 712                                         if(skb2)
 713                                                 pt_prev->func(skb2, skb->dev, pt_prev);
 714                                 }
 715                                 /* Remember the current last to do */
 716                                 pt_prev=ptype;
 717                         }
 718                 } /* End of protocol list loop */
 719                 
 720                 /*
 721                  *      Is there a last item to send to ?
 722                  */
 723 
 724                 if(pt_prev)
 725                         pt_prev->func(skb, skb->dev, pt_prev);
 726                 /*
 727                  *      Has an unknown packet has been received ?
 728                  */
 729          
 730                 else
 731                         kfree_skb(skb, FREE_WRITE);
 732 
 733                 /*
 734                  *      Again, see if we can transmit anything now. 
 735                  *      [Ought to take this out judging by tests it slows
 736                  *       us down not speeds us up]
 737                  */
 738 
 739                 dev_transmit();
 740                 cli();
 741         }       /* End of queue loop */
 742         
 743         /*
 744          *      We have emptied the queue
 745          */
 746          
 747         in_bh = 0;
 748         sti();
 749         
 750         /*
 751          *      One last output flush.
 752          */
 753          
 754         dev_transmit();
 755 }
 756 
 757 
 758 /*
 759  *      This routine is called when an device driver (i.e. an
 760  *      interface) is ready to transmit a packet.
 761  */
 762  
 763 void dev_tint(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 764 {
 765         int i;
 766         struct sk_buff *skb;
 767         unsigned long flags;
 768         
 769         save_flags(flags);      
 770         /*
 771          *      Work the queues in priority order
 772          */
 773          
 774         for(i = 0;i < DEV_NUMBUFFS; i++) 
 775         {
 776                 /*
 777                  *      Pull packets from the queue
 778                  */
 779                  
 780 
 781                 cli();
 782                 while((skb=skb_dequeue(&dev->buffs[i]))!=NULL)
 783                 {
 784                         /*
 785                          *      Stop anyone freeing the buffer while we retransmit it
 786                          */
 787                         skb_device_lock(skb);
 788                         restore_flags(flags);
 789                         /*
 790                          *      Feed them to the output stage and if it fails
 791                          *      indicate they re-queue at the front.
 792                          */
 793                         dev_queue_xmit(skb,dev,-i - 1);
 794                         /*
 795                          *      If we can take no more then stop here.
 796                          */
 797                         if (dev->tbusy)
 798                                 return;
 799                         cli();
 800                 }
 801         }
 802         restore_flags(flags);
 803 }
 804 
 805 
 806 /*
 807  *      Perform a SIOCGIFCONF call. This structure will change
 808  *      size shortly, and there is nothing I can do about it.
 809  *      Thus we will need a 'compatibility mode'.
 810  */
 811 
 812 static int dev_ifconf(char *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 813 {
 814         struct ifconf ifc;
 815         struct ifreq ifr;
 816         struct device *dev;
 817         char *pos;
 818         int len;
 819         int err;
 820 
 821         /*
 822          *      Fetch the caller's info block. 
 823          */
 824          
 825         err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifconf));
 826         if(err)
 827                 return err;
 828         memcpy_fromfs(&ifc, arg, sizeof(struct ifconf));
 829         len = ifc.ifc_len;
 830         pos = ifc.ifc_buf;
 831 
 832         /*
 833          *      We now walk the device list filling each active device
 834          *      into the array.
 835          */
 836          
 837         err=verify_area(VERIFY_WRITE,pos,len);
 838         if(err)
 839                 return err;
 840         
 841         /*
 842          *      Loop over the interfaces, and write an info block for each. 
 843          */
 844 
 845         for (dev = dev_base; dev != NULL; dev = dev->next) 
 846         {
 847                 if(!(dev->flags & IFF_UP))      /* Downed devices don't count */
 848                         continue;
 849                 memset(&ifr, 0, sizeof(struct ifreq));
 850                 strcpy(ifr.ifr_name, dev->name);
 851                 (*(struct sockaddr_in *) &ifr.ifr_addr).sin_family = dev->family;
 852                 (*(struct sockaddr_in *) &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
 853 
 854                 /*
 855                  *      Write this block to the caller's space. 
 856                  */
 857                  
 858                 memcpy_tofs(pos, &ifr, sizeof(struct ifreq));
 859                 pos += sizeof(struct ifreq);
 860                 len -= sizeof(struct ifreq);
 861                 
 862                 /*
 863                  *      Have we run out of space here ?
 864                  */
 865         
 866                 if (len < sizeof(struct ifreq)) 
 867                         break;
 868         }
 869 
 870         /*
 871          *      All done.  Write the updated control block back to the caller. 
 872          */
 873          
 874         ifc.ifc_len = (pos - ifc.ifc_buf);
 875         ifc.ifc_req = (struct ifreq *) ifc.ifc_buf;
 876         memcpy_tofs(arg, &ifc, sizeof(struct ifconf));
 877         
 878         /*
 879          *      Report how much was filled in
 880          */
 881          
 882         return(pos - arg);
 883 }
 884 
 885 
 886 /*
 887  *      This is invoked by the /proc filesystem handler to display a device
 888  *      in detail.
 889  */
 890 
 891 static int sprintf_stats(char *buffer, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 892 {
 893         struct enet_statistics *stats = (dev->get_stats ? dev->get_stats(dev): NULL);
 894         int size;
 895         
 896         if (stats)
 897                 size = sprintf(buffer, "%6s:%7d %4d %4d %4d %4d %8d %4d %4d %4d %5d %4d\n",
 898                    dev->name,
 899                    stats->rx_packets, stats->rx_errors,
 900                    stats->rx_dropped + stats->rx_missed_errors,
 901                    stats->rx_fifo_errors,
 902                    stats->rx_length_errors + stats->rx_over_errors
 903                    + stats->rx_crc_errors + stats->rx_frame_errors,
 904                    stats->tx_packets, stats->tx_errors, stats->tx_dropped,
 905                    stats->tx_fifo_errors, stats->collisions,
 906                    stats->tx_carrier_errors + stats->tx_aborted_errors
 907                    + stats->tx_window_errors + stats->tx_heartbeat_errors);
 908         else
 909                 size = sprintf(buffer, "%6s: No statistics available.\n", dev->name);
 910 
 911         return size;
 912 }
 913 
 914 /*
 915  *      Called from the PROCfs module. This now uses the new arbitrary sized /proc/net interface
 916  *      to create /proc/net/dev
 917  */
 918  
 919 int dev_get_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
 920 {
 921         int len=0;
 922         off_t begin=0;
 923         off_t pos=0;
 924         int size;
 925         
 926         struct device *dev;
 927 
 928 
 929         size = sprintf(buffer, "Inter-|   Receive                  |  Transmit\n"
 930                             " face |packets errs drop fifo frame|packets errs drop fifo colls carrier\n");
 931         
 932         pos+=size;
 933         len+=size;
 934         
 935 
 936         for (dev = dev_base; dev != NULL; dev = dev->next) 
 937         {
 938                 size = sprintf_stats(buffer+len, dev);
 939                 len+=size;
 940                 pos=begin+len;
 941                                 
 942                 if(pos<offset)
 943                 {
 944                         len=0;
 945                         begin=pos;
 946                 }
 947                 if(pos>offset+length)
 948                         break;
 949         }
 950         
 951         *start=buffer+(offset-begin);   /* Start of wanted data */
 952         len-=(offset-begin);            /* Start slop */
 953         if(len>length)
 954                 len=length;             /* Ending slop */
 955         return len;
 956 }
 957 
 958 
 959 /*
 960  *      This checks bitmasks for the ioctl calls for devices.
 961  */
 962  
 963 static inline int bad_mask(unsigned long mask, unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 964 {
 965         if (addr & (mask = ~mask))
 966                 return 1;
 967         mask = ntohl(mask);
 968         if (mask & (mask+1))
 969                 return 1;
 970         return 0;
 971 }
 972 
 973 /*
 974  *      Perform the SIOCxIFxxx calls. 
 975  *
 976  *      The socket layer has seen an ioctl the address family thinks is
 977  *      for the device. At this point we get invoked to make a decision
 978  */
 979  
 980 static int dev_ifsioc(void *arg, unsigned int getset)
     /* [previous][next][first][last][top][bottom][index][help] */
 981 {
 982         struct ifreq ifr;
 983         struct device *dev;
 984         int ret;
 985 
 986         /*
 987          *      Fetch the caller's info block into kernel space
 988          */
 989 
 990         int err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifreq));
 991         if(err)
 992                 return err;
 993         
 994         memcpy_fromfs(&ifr, arg, sizeof(struct ifreq));
 995 
 996         /*
 997          *      See which interface the caller is talking about. 
 998          */
 999          
1000         if ((dev = dev_get(ifr.ifr_name)) == NULL) 
1001                 return(-ENODEV);
1002 
1003         switch(getset) 
1004         {
1005                 case SIOCGIFFLAGS:      /* Get interface flags */
1006                         ifr.ifr_flags = dev->flags;
1007                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1008                         ret = 0;
1009                         break;
1010                 case SIOCSIFFLAGS:      /* Set interface flags */
1011                         {
1012                                 int old_flags = dev->flags;
1013 #ifdef CONFIG_SLAVE_BALANCING                           
1014                                 if(dev->flags&IFF_SLAVE)
1015                                         return -EBUSY;
1016 #endif                                  
1017                                 dev->flags = ifr.ifr_flags & (
1018                                         IFF_UP | IFF_BROADCAST | IFF_DEBUG | IFF_LOOPBACK |
1019                                         IFF_POINTOPOINT | IFF_NOTRAILERS | IFF_RUNNING |
1020                                         IFF_NOARP | IFF_PROMISC | IFF_ALLMULTI | IFF_SLAVE | IFF_MASTER
1021                                         | IFF_MULTICAST);
1022 #ifdef CONFIG_SLAVE_BALANCING                           
1023                                 if(!(dev->flags&IFF_MASTER) && dev->slave)
1024                                 {
1025                                         dev->slave->flags&=~IFF_SLAVE;
1026                                         dev->slave=NULL;
1027                                 }
1028 #endif
1029                                 /*
1030                                  *      Load in the correct multicast list now the flags have changed.
1031                                  */                             
1032 
1033                                 dev_mc_upload(dev);
1034 #if 0
1035                                 if( dev->set_multicast_list!=NULL)
1036                                 {
1037                                 
1038                                         /*
1039                                          *      Has promiscuous mode been turned off
1040                                          */     
1041                                 
1042                                         if ( (old_flags & IFF_PROMISC) && ((dev->flags & IFF_PROMISC) == 0))
1043                                                 dev->set_multicast_list(dev,0,NULL);
1044                                         
1045                                         /*
1046                                          *      Has it been turned on
1047                                          */
1048         
1049                                         if ( (dev->flags & IFF_PROMISC) && ((old_flags & IFF_PROMISC) == 0))
1050                                                 dev->set_multicast_list(dev,-1,NULL);
1051                                 }
1052 #endif                                  
1053                                 /*
1054                                  *      Have we downed the interface
1055                                  */
1056                 
1057                                 if ((old_flags & IFF_UP) && ((dev->flags & IFF_UP) == 0)) 
1058                                 {
1059                                         ret = dev_close(dev);
1060                                 }
1061                                 else
1062                                 {
1063                                         /*
1064                                          *      Have we upped the interface 
1065                                          */
1066                                          
1067                                         ret = (! (old_flags & IFF_UP) && (dev->flags & IFF_UP))
1068                                                 ? dev_open(dev) : 0;
1069                                         /* 
1070                                          *      Check the flags.
1071                                          */
1072                                         if(ret<0)
1073                                                 dev->flags&=~IFF_UP;    /* Didn't open so down the if */
1074                                 }
1075                         }
1076                         break;
1077                 
1078                 case SIOCGIFADDR:       /* Get interface address (and family) */
1079                         (*(struct sockaddr_in *)
1080                                   &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
1081                         (*(struct sockaddr_in *)
1082                                   &ifr.ifr_addr).sin_family = dev->family;
1083                         (*(struct sockaddr_in *)
1084                                   &ifr.ifr_addr).sin_port = 0;
1085                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1086                         ret = 0;
1087                         break;
1088         
1089                 case SIOCSIFADDR:       /* Set interface address (and family) */
1090                         dev->pa_addr = (*(struct sockaddr_in *)
1091                                  &ifr.ifr_addr).sin_addr.s_addr;
1092                         dev->family = ifr.ifr_addr.sa_family;
1093                         
1094 #ifdef CONFIG_INET      
1095                         /* This is naughty. When net-032e comes out It wants moving into the net032
1096                            code not the kernel. Till then it can sit here (SIGH) */             
1097                         dev->pa_mask = ip_get_mask(dev->pa_addr);
1098 #endif                  
1099                         dev->pa_brdaddr = dev->pa_addr | ~dev->pa_mask;
1100                         ret = 0;
1101                         break;
1102                         
1103                 case SIOCGIFBRDADDR:    /* Get the broadcast address */
1104                         (*(struct sockaddr_in *)
1105                                 &ifr.ifr_broadaddr).sin_addr.s_addr = dev->pa_brdaddr;
1106                         (*(struct sockaddr_in *)
1107                                 &ifr.ifr_broadaddr).sin_family = dev->family;
1108                         (*(struct sockaddr_in *)
1109                                 &ifr.ifr_broadaddr).sin_port = 0;
1110                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1111                         ret = 0;
1112                         break;
1113 
1114                 case SIOCSIFBRDADDR:    /* Set the broadcast address */
1115                         dev->pa_brdaddr = (*(struct sockaddr_in *)
1116                                 &ifr.ifr_broadaddr).sin_addr.s_addr;
1117                         ret = 0;
1118                         break;
1119                         
1120                 case SIOCGIFDSTADDR:    /* Get the destination address (for point-to-point links) */
1121                         (*(struct sockaddr_in *)
1122                                 &ifr.ifr_dstaddr).sin_addr.s_addr = dev->pa_dstaddr;
1123                         (*(struct sockaddr_in *)
1124                                 &ifr.ifr_broadaddr).sin_family = dev->family;
1125                         (*(struct sockaddr_in *)
1126                                 &ifr.ifr_broadaddr).sin_port = 0;
1127                                 memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1128                         ret = 0;
1129                         break;
1130         
1131                 case SIOCSIFDSTADDR:    /* Set the destination address (for point-to-point links) */
1132                         dev->pa_dstaddr = (*(struct sockaddr_in *)
1133                                 &ifr.ifr_dstaddr).sin_addr.s_addr;
1134                         ret = 0;
1135                         break;
1136                         
1137                 case SIOCGIFNETMASK:    /* Get the netmask for the interface */
1138                         (*(struct sockaddr_in *)
1139                                 &ifr.ifr_netmask).sin_addr.s_addr = dev->pa_mask;
1140                         (*(struct sockaddr_in *)
1141                                 &ifr.ifr_netmask).sin_family = dev->family;
1142                         (*(struct sockaddr_in *)
1143                                 &ifr.ifr_netmask).sin_port = 0;
1144                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1145                         ret = 0;
1146                         break;
1147 
1148                 case SIOCSIFNETMASK:    /* Set the netmask for the interface */
1149                         {
1150                                 unsigned long mask = (*(struct sockaddr_in *)
1151                                         &ifr.ifr_netmask).sin_addr.s_addr;
1152                                 ret = -EINVAL;
1153                                 /*
1154                                  *      The mask we set must be legal.
1155                                  */
1156                                 if (bad_mask(mask,0))
1157                                         break;
1158                                 dev->pa_mask = mask;
1159                                 ret = 0;
1160                         }
1161                         break;
1162                         
1163                 case SIOCGIFMETRIC:     /* Get the metric on the interface (currently unused) */
1164                         
1165                         ifr.ifr_metric = dev->metric;
1166                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1167                         ret = 0;
1168                         break;
1169                         
1170                 case SIOCSIFMETRIC:     /* Set the metric on the interface (currently unused) */
1171                         dev->metric = ifr.ifr_metric;
1172                         ret = 0;
1173                         break;
1174         
1175                 case SIOCGIFMTU:        /* Get the MTU of a device */
1176                         ifr.ifr_mtu = dev->mtu;
1177                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1178                         ret = 0;
1179                         break;
1180         
1181                 case SIOCSIFMTU:        /* Set the MTU of a device */
1182                 
1183                         /*
1184                          *      MTU must be positive and under the page size problem
1185                          */
1186                          
1187                         if(ifr.ifr_mtu<1 || ifr.ifr_mtu>3800)
1188                                 return -EINVAL;
1189                         dev->mtu = ifr.ifr_mtu;
1190                         ret = 0;
1191                         break;
1192         
1193                 case SIOCGIFMEM:        /* Get the per device memory space. We can add this but currently
1194                                            do not support it */
1195                         printk("NET: ioctl(SIOCGIFMEM, %p)\n", arg);
1196                         ret = -EINVAL;
1197                         break;
1198                 
1199                 case SIOCSIFMEM:        /* Set the per device memory buffer space. Not applicable in our case */
1200                         printk("NET: ioctl(SIOCSIFMEM, %p)\n", arg);
1201                         ret = -EINVAL;
1202                         break;
1203 
1204                 case OLD_SIOCGIFHWADDR: /* Get the hardware address. This will change and SIFHWADDR will be added */
1205                         memcpy(ifr.old_ifr_hwaddr,dev->dev_addr, MAX_ADDR_LEN);
1206                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1207                         ret=0;
1208                         break;
1209 
1210                 case SIOCGIFHWADDR:
1211                         memcpy(ifr.ifr_hwaddr.sa_data,dev->dev_addr, MAX_ADDR_LEN);
1212                         ifr.ifr_hwaddr.sa_family=dev->type;                     
1213                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1214                         ret=0;
1215                         break;
1216                         
1217                 case SIOCSIFHWADDR:
1218                         if(dev->set_mac_address==NULL)
1219                                 return -EOPNOTSUPP;
1220                         if(ifr.ifr_hwaddr.sa_family!=dev->type)
1221                                 return -EINVAL;
1222                         ret=dev->set_mac_address(dev,ifr.ifr_hwaddr.sa_data);
1223                         break;
1224                         
1225                 case SIOCGIFMAP:
1226                         ifr.ifr_map.mem_start=dev->mem_start;
1227                         ifr.ifr_map.mem_end=dev->mem_end;
1228                         ifr.ifr_map.base_addr=dev->base_addr;
1229                         ifr.ifr_map.irq=dev->irq;
1230                         ifr.ifr_map.dma=dev->dma;
1231                         ifr.ifr_map.port=dev->if_port;
1232                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1233                         ret=0;
1234                         break;
1235                         
1236                 case SIOCSIFMAP:
1237                         if(dev->set_config==NULL)
1238                                 return -EOPNOTSUPP;
1239                         return dev->set_config(dev,&ifr.ifr_map);
1240                         
1241                 case SIOCGIFSLAVE:
1242 #ifdef CONFIG_SLAVE_BALANCING           
1243                         if(dev->slave==NULL)
1244                                 return -ENOENT;
1245                         strncpy(ifr.ifr_name,dev->name,sizeof(ifr.ifr_name));
1246                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1247                         ret=0;
1248 #else
1249                         return -ENOENT;
1250 #endif                  
1251                         break;
1252 #ifdef CONFIG_SLAVE_BALANCING                   
1253                 case SIOCSIFSLAVE:
1254                 {
1255                 
1256                 /*
1257                  *      Fun game. Get the device up and the flags right without
1258                  *      letting some scummy user confuse us.
1259                  */
1260                         unsigned long flags;
1261                         struct device *slave=dev_get(ifr.ifr_slave);
1262                         save_flags(flags);
1263                         if(slave==NULL)
1264                         {
1265                                 return -ENODEV;
1266                         }
1267                         cli();
1268                         if((slave->flags&(IFF_UP|IFF_RUNNING))!=(IFF_UP|IFF_RUNNING))
1269                         {
1270                                 restore_flags(flags);
1271                                 return -EINVAL;
1272                         }
1273                         if(dev->flags&IFF_SLAVE)
1274                         {
1275                                 restore_flags(flags);
1276                                 return -EBUSY;
1277                         }
1278                         if(dev->slave!=NULL)
1279                         {
1280                                 restore_flags(flags);
1281                                 return -EBUSY;
1282                         }
1283                         if(slave->flags&IFF_SLAVE)
1284                         {
1285                                 restore_flags(flags);
1286                                 return -EBUSY;
1287                         }
1288                         dev->slave=slave;
1289                         slave->flags|=IFF_SLAVE;
1290                         dev->flags|=IFF_MASTER;
1291                         restore_flags(flags);
1292                         ret=0;
1293                 }
1294                 break;
1295 #endif                  
1296 
1297                 case SIOCADDMULTI:
1298                         if(dev->set_multicast_list==NULL)
1299                                 return -EINVAL;
1300                         if(ifr.ifr_hwaddr.sa_family!=AF_UNSPEC)
1301                                 return -EINVAL;
1302                         dev_mc_add(dev,ifr.ifr_hwaddr.sa_data, dev->addr_len, 1);
1303                         return 0;
1304 
1305                 case SIOCDELMULTI:
1306                         if(dev->set_multicast_list==NULL)
1307                                 return -EINVAL;
1308                         if(ifr.ifr_hwaddr.sa_family!=AF_UNSPEC)
1309                                 return -EINVAL;
1310                         dev_mc_delete(dev,ifr.ifr_hwaddr.sa_data,dev->addr_len, 1);
1311                         return 0;
1312                 /*
1313                  *      Unknown or private ioctl
1314                  */
1315 
1316                 default:
1317                         if((getset >= SIOCDEVPRIVATE) &&
1318                            (getset <= (SIOCDEVPRIVATE + 15))) {
1319                                 if(dev->do_ioctl==NULL)
1320                                         return -EOPNOTSUPP;
1321                                 ret=dev->do_ioctl(dev, &ifr, getset);
1322                                 memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1323                                 break;
1324                         }
1325                         
1326                         ret = -EINVAL;
1327         }
1328         return(ret);
1329 }
1330 
1331 
1332 /*
1333  *      This function handles all "interface"-type I/O control requests. The actual
1334  *      'doing' part of this is dev_ifsioc above.
1335  */
1336 
1337 int dev_ioctl(unsigned int cmd, void *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1338 {
1339         switch(cmd) 
1340         {
1341                 case SIOCGIFCONF:
1342                         (void) dev_ifconf((char *) arg);
1343                         return 0;
1344 
1345                 /*
1346                  *      Ioctl calls that can be done by all.
1347                  */
1348                  
1349                 case SIOCGIFFLAGS:
1350                 case SIOCGIFADDR:
1351                 case SIOCGIFDSTADDR:
1352                 case SIOCGIFBRDADDR:
1353                 case SIOCGIFNETMASK:
1354                 case SIOCGIFMETRIC:
1355                 case SIOCGIFMTU:
1356                 case SIOCGIFMEM:
1357                 case SIOCGIFHWADDR:
1358                 case SIOCSIFHWADDR:
1359                 case OLD_SIOCGIFHWADDR:
1360                 case SIOCGIFSLAVE:
1361                 case SIOCGIFMAP:
1362                         return dev_ifsioc(arg, cmd);
1363 
1364                 /*
1365                  *      Ioctl calls requiring the power of a superuser
1366                  */
1367                  
1368                 case SIOCSIFFLAGS:
1369                 case SIOCSIFADDR:
1370                 case SIOCSIFDSTADDR:
1371                 case SIOCSIFBRDADDR:
1372                 case SIOCSIFNETMASK:
1373                 case SIOCSIFMETRIC:
1374                 case SIOCSIFMTU:
1375                 case SIOCSIFMEM:
1376                 case SIOCSIFMAP:
1377                 case SIOCSIFSLAVE:
1378                 case SIOCADDMULTI:
1379                 case SIOCDELMULTI:
1380                         if (!suser())
1381                                 return -EPERM;
1382                         return dev_ifsioc(arg, cmd);
1383         
1384                 case SIOCSIFLINK:
1385                         return -EINVAL;
1386 
1387                 /*
1388                  *      Unknown or private ioctl.
1389                  */     
1390                  
1391                 default:
1392                         if((cmd >= SIOCDEVPRIVATE) &&
1393                            (cmd <= (SIOCDEVPRIVATE + 15))) {
1394                                 return dev_ifsioc(arg, cmd);
1395                         }
1396                         return -EINVAL;
1397         }
1398 }
1399 
1400 
1401 /*
1402  *      Initialize the DEV module. At boot time this walks the device list and
1403  *      unhooks any devices that fail to initialise (normally hardware not 
1404  *      present) and leaves us with a valid list of present and active devices.
1405  *
1406  *      The PCMCIA code may need to change this a little, and add a pair
1407  *      of register_inet_device() unregister_inet_device() calls. This will be
1408  *      needed for ethernet as modules support.
1409  */
1410  
1411 void dev_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1412 {
1413         struct device *dev, *dev2;
1414 
1415         /*
1416          *      Add the devices.
1417          *      If the call to dev->init fails, the dev is removed
1418          *      from the chain disconnecting the device until the
1419          *      next reboot.
1420          */
1421          
1422         dev2 = NULL;
1423         for (dev = dev_base; dev != NULL; dev=dev->next) 
1424         {
1425                 if (dev->init && dev->init(dev)) 
1426                 {
1427                         /*
1428                          *      It failed to come up. Unhook it.
1429                          */
1430                          
1431                         if (dev2 == NULL) 
1432                                 dev_base = dev->next;
1433                         else 
1434                                 dev2->next = dev->next;
1435                 } 
1436                 else
1437                 {
1438                         dev2 = dev;
1439                 }
1440         }
1441 }

/* [previous][next][first][last][top][bottom][index][help] */