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_notifer
  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_notifer(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                         if (ptype->type == htons(ETH_P_ALL) && (ptype->dev==dev || !ptype->dev)) 
 392                         {
 393                                 struct sk_buff *skb2;
 394                                 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL)
 395                                         break;
 396                                 ptype->func(skb2, skb->dev, ptype);
 397                                 nitcount--;
 398                         }
 399                 }
 400         }
 401         if (dev->hard_start_xmit(skb, dev) == 0) {
 402                 /*
 403                  *      Packet is now solely the responsibility of the driver
 404                  */
 405                 return;
 406         }
 407 
 408         /*
 409          *      Transmission failed, put skb back into a list. Once on the list its safe and
 410          *      no longer device locked (it can be freed safely from the device queue)
 411          */
 412         cli();
 413 #ifdef CONFIG_SLAVE_BALANCING
 414         skb->in_dev_queue=1;
 415         dev->pkt_queue++;
 416 #endif          
 417         skb_device_unlock(skb);
 418         skb_queue_head(dev->buffs + pri,skb);
 419         restore_flags(flags);
 420 }
 421 
 422 /*
 423  *      Receive a packet from a device driver and queue it for the upper
 424  *      (protocol) levels.  It always succeeds. This is the recommended 
 425  *      interface to use.
 426  */
 427 
 428 void netif_rx(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 429 {
 430         static int dropping = 0;
 431 
 432         /*
 433          *      Any received buffers are un-owned and should be discarded
 434          *      when freed. These will be updated later as the frames get
 435          *      owners.
 436          */
 437         skb->sk = NULL;
 438         skb->free = 1;
 439         if(skb->stamp.tv_sec==0)
 440                 skb->stamp = xtime;
 441 
 442         /*
 443          *      Check that we aren't overdoing things.
 444          */
 445 
 446         if (!backlog_size)
 447                 dropping = 0;
 448         else if (backlog_size > 300)
 449                 dropping = 1;
 450 
 451         if (dropping) 
 452         {
 453                 kfree_skb(skb, FREE_READ);
 454                 return;
 455         }
 456 
 457         /*
 458          *      Add it to the "backlog" queue. 
 459          */
 460 #ifdef CONFIG_SKB_CHECK
 461         IS_SKB(skb);
 462 #endif  
 463         skb_queue_tail(&backlog,skb);
 464         backlog_size++;
 465   
 466         /*
 467          *      If any packet arrived, mark it for processing after the
 468          *      hardware interrupt returns.
 469          */
 470 
 471         mark_bh(NET_BH);
 472         return;
 473 }
 474 
 475 
 476 /*
 477  *      The old interface to fetch a packet from a device driver.
 478  *      This function is the base level entry point for all drivers that
 479  *      want to send a packet to the upper (protocol) levels.  It takes
 480  *      care of de-multiplexing the packet to the various modules based
 481  *      on their protocol ID.
 482  *
 483  *      Return values:  1 <- exit I can't do any more
 484  *                      0 <- feed me more (i.e. "done", "OK"). 
 485  *
 486  *      This function is OBSOLETE and should not be used by any new
 487  *      device.
 488  */
 489 
 490 int dev_rint(unsigned char *buff, long len, int flags, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 491 {
 492         static int dropping = 0;
 493         struct sk_buff *skb = NULL;
 494         unsigned char *to;
 495         int amount, left;
 496         int len2;
 497 
 498         if (dev == NULL || buff == NULL || len <= 0) 
 499                 return(1);
 500 
 501         if (flags & IN_SKBUFF) 
 502         {
 503                 skb = (struct sk_buff *) buff;
 504         }
 505         else
 506         {
 507                 if (dropping) 
 508                 {
 509                         if (skb_peek(&backlog) != NULL)
 510                                 return(1);
 511                         printk("INET: dev_rint: no longer dropping packets.\n");
 512                         dropping = 0;
 513                 }
 514 
 515                 skb = alloc_skb(len, GFP_ATOMIC);
 516                 if (skb == NULL) 
 517                 {
 518                         printk("dev_rint: packet dropped on %s (no memory) !\n",
 519                                dev->name);
 520                         dropping = 1;
 521                         return(1);
 522                 }
 523 
 524                 /* 
 525                  *      First we copy the packet into a buffer, and save it for later. We
 526                  *      in effect handle the incoming data as if it were from a circular buffer
 527                  */
 528 
 529                 to = skb->data;
 530                 left = len;
 531 
 532                 len2 = len;
 533                 while (len2 > 0) 
 534                 {
 535                         amount = min(len2, (unsigned long) dev->rmem_end -
 536                                                 (unsigned long) buff);
 537                         memcpy(to, buff, amount);
 538                         len2 -= amount;
 539                         left -= amount;
 540                         buff += amount;
 541                         to += amount;
 542                         if ((unsigned long) buff == dev->rmem_end)
 543                                 buff = (unsigned char *) dev->rmem_start;
 544                 }
 545         }
 546 
 547         /*
 548          *      Tag the frame and kick it to the proper receive routine
 549          */
 550          
 551         skb->len = len;
 552         skb->dev = dev;
 553         skb->free = 1;
 554 
 555         netif_rx(skb);
 556         /*
 557          *      OK, all done. 
 558          */
 559         return(0);
 560 }
 561 
 562 
 563 /*
 564  *      This routine causes all interfaces to try to send some data. 
 565  */
 566  
 567 void dev_transmit(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 568 {
 569         struct device *dev;
 570 
 571         for (dev = dev_base; dev != NULL; dev = dev->next) 
 572         {
 573                 if (dev->flags != 0 && !dev->tbusy) {
 574                         /*
 575                          *      Kick the device
 576                          */
 577                         dev_tint(dev);
 578                 }
 579         }
 580 }
 581 
 582 
 583 /**********************************************************************************
 584 
 585                         Receive Queue Processor
 586                         
 587 ***********************************************************************************/
 588 
 589 /*
 590  *      This is a single non-reentrant routine which takes the received packet
 591  *      queue and throws it at the networking layers in the hope that something
 592  *      useful will emerge.
 593  */
 594  
 595 volatile char in_bh = 0;        /* Non-reentrant remember */
 596 
 597 int in_net_bh() /* Used by timer.c */
     /* [previous][next][first][last][top][bottom][index][help] */
 598 {
 599         return(in_bh==0?0:1);
 600 }
 601 
 602 /*
 603  *      When we are called the queue is ready to grab, the interrupts are
 604  *      on and hardware can interrupt and queue to the receive queue a we
 605  *      run with no problems.
 606  *      This is run as a bottom half after an interrupt handler that does
 607  *      mark_bh(NET_BH);
 608  */
 609  
 610 void net_bh(void *tmp)
     /* [previous][next][first][last][top][bottom][index][help] */
 611 {
 612         struct sk_buff *skb;
 613         struct packet_type *ptype;
 614         struct packet_type *pt_prev=NULL;
 615         unsigned short type;
 616 
 617         /*
 618          *      Atomically check and mark our BUSY state. 
 619          */
 620 
 621         if (set_bit(1, (void*)&in_bh))
 622                 return;
 623 
 624         /*
 625          *      Can we send anything now? We want to clear the
 626          *      decks for any more sends that get done as we
 627          *      process the input.
 628          */
 629 
 630         dev_transmit();
 631   
 632         /*
 633          *      Any data left to process. This may occur because a
 634          *      mark_bh() is done after we empty the queue including
 635          *      that from the device which does a mark_bh() just after
 636          */
 637 
 638         cli();
 639         
 640         /*
 641          *      While the queue is not empty
 642          */
 643          
 644         while((skb=skb_dequeue(&backlog))!=NULL)
 645         {
 646                 /*
 647                  *      We have a packet. Therefore the queue has shrunk
 648                  */
 649                 backlog_size--;
 650 
 651                 sti();
 652                 
 653                /*
 654                 *       Bump the pointer to the next structure.
 655                 *       This assumes that the basic 'skb' pointer points to
 656                 *       the MAC header, if any (as indicated by its "length"
 657                 *       field).  Take care now!
 658                 */
 659 
 660                 skb->h.raw = skb->data + skb->dev->hard_header_len;
 661                 skb->len -= skb->dev->hard_header_len;
 662 
 663                /*
 664                 *       Fetch the packet protocol ID.  This is also quite ugly, as
 665                 *       it depends on the protocol driver (the interface itself) to
 666                 *       know what the type is, or where to get it from.  The Ethernet
 667                 *       interfaces fetch the ID from the two bytes in the Ethernet MAC
 668                 *       header (the h_proto field in struct ethhdr), but other drivers
 669                 *       may either use the ethernet ID's or extra ones that do not
 670                 *       clash (eg ETH_P_AX25). We could set this before we queue the
 671                 *       frame. In fact I may change this when I have time.
 672                 */
 673                 
 674                 type = skb->dev->type_trans(skb, skb->dev);
 675 
 676                 /*
 677                  *      We got a packet ID.  Now loop over the "known protocols"
 678                  *      table (which is actually a linked list, but this will
 679                  *      change soon if I get my way- FvK), and forward the packet
 680                  *      to anyone who wants it.
 681                  *
 682                  *      [FvK didn't get his way but he is right this ought to be
 683                  *      hashed so we typically get a single hit. The speed cost
 684                  *      here is minimal but no doubt adds up at the 4,000+ pkts/second
 685                  *      rate we can hit flat out]
 686                  */
 687                  
 688                 for (ptype = ptype_base; ptype != NULL; ptype = ptype->next) 
 689                 {
 690                         if ((ptype->type == type || ptype->type == htons(ETH_P_ALL)) && (!ptype->dev || ptype->dev==skb->dev))
 691                         {
 692                                 /*
 693                                  *      We already have a match queued. Deliver
 694                                  *      to it and then remember the new match
 695                                  */
 696                                 if(pt_prev)
 697                                 {
 698                                         struct sk_buff *skb2;
 699 
 700                                         skb2=skb_clone(skb, GFP_ATOMIC);
 701 
 702                                         /*
 703                                          *      Kick the protocol handler. This should be fast
 704                                          *      and efficient code.
 705                                          */
 706 
 707                                         if(skb2)
 708                                                 pt_prev->func(skb2, skb->dev, pt_prev);
 709                                 }
 710                                 /* Remember the current last to do */
 711                                 pt_prev=ptype;
 712                         }
 713                 } /* End of protocol list loop */
 714                 
 715                 /*
 716                  *      Is there a last item to send to ?
 717                  */
 718 
 719                 if(pt_prev)
 720                         pt_prev->func(skb, skb->dev, pt_prev);
 721                 /*
 722                  *      Has an unknown packet has been received ?
 723                  */
 724          
 725                 else
 726                         kfree_skb(skb, FREE_WRITE);
 727 
 728                 /*
 729                  *      Again, see if we can transmit anything now. 
 730                  *      [Ought to take this out judging by tests it slows
 731                  *       us down not speeds us up]
 732                  */
 733 
 734                 dev_transmit();
 735                 cli();
 736         }       /* End of queue loop */
 737         
 738         /*
 739          *      We have emptied the queue
 740          */
 741          
 742         in_bh = 0;
 743         sti();
 744         
 745         /*
 746          *      One last output flush.
 747          */
 748          
 749         dev_transmit();
 750 }
 751 
 752 
 753 /*
 754  *      This routine is called when an device driver (i.e. an
 755  *      interface) is ready to transmit a packet.
 756  */
 757  
 758 void dev_tint(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 759 {
 760         int i;
 761         struct sk_buff *skb;
 762         unsigned long flags;
 763         
 764         save_flags(flags);      
 765         /*
 766          *      Work the queues in priority order
 767          */
 768          
 769         for(i = 0;i < DEV_NUMBUFFS; i++) 
 770         {
 771                 /*
 772                  *      Pull packets from the queue
 773                  */
 774                  
 775 
 776                 cli();
 777                 while((skb=skb_dequeue(&dev->buffs[i]))!=NULL)
 778                 {
 779                         /*
 780                          *      Stop anyone freeing the buffer while we retransmit it
 781                          */
 782                         skb_device_lock(skb);
 783                         restore_flags(flags);
 784                         /*
 785                          *      Feed them to the output stage and if it fails
 786                          *      indicate they re-queue at the front.
 787                          */
 788                         dev_queue_xmit(skb,dev,-i - 1);
 789                         /*
 790                          *      If we can take no more then stop here.
 791                          */
 792                         if (dev->tbusy)
 793                                 return;
 794                         cli();
 795                 }
 796         }
 797         restore_flags(flags);
 798 }
 799 
 800 
 801 /*
 802  *      Perform a SIOCGIFCONF call. This structure will change
 803  *      size shortly, and there is nothing I can do about it.
 804  *      Thus we will need a 'compatibility mode'.
 805  */
 806 
 807 static int dev_ifconf(char *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 808 {
 809         struct ifconf ifc;
 810         struct ifreq ifr;
 811         struct device *dev;
 812         char *pos;
 813         int len;
 814         int err;
 815 
 816         /*
 817          *      Fetch the caller's info block. 
 818          */
 819          
 820         err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifconf));
 821         if(err)
 822                 return err;
 823         memcpy_fromfs(&ifc, arg, sizeof(struct ifconf));
 824         len = ifc.ifc_len;
 825         pos = ifc.ifc_buf;
 826 
 827         /*
 828          *      We now walk the device list filling each active device
 829          *      into the array.
 830          */
 831          
 832         err=verify_area(VERIFY_WRITE,pos,len);
 833         if(err)
 834                 return err;
 835         
 836         /*
 837          *      Loop over the interfaces, and write an info block for each. 
 838          */
 839 
 840         for (dev = dev_base; dev != NULL; dev = dev->next) 
 841         {
 842                 if(!(dev->flags & IFF_UP))      /* Downed devices don't count */
 843                         continue;
 844                 memset(&ifr, 0, sizeof(struct ifreq));
 845                 strcpy(ifr.ifr_name, dev->name);
 846                 (*(struct sockaddr_in *) &ifr.ifr_addr).sin_family = dev->family;
 847                 (*(struct sockaddr_in *) &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
 848 
 849                 /*
 850                  *      Write this block to the caller's space. 
 851                  */
 852                  
 853                 memcpy_tofs(pos, &ifr, sizeof(struct ifreq));
 854                 pos += sizeof(struct ifreq);
 855                 len -= sizeof(struct ifreq);
 856                 
 857                 /*
 858                  *      Have we run out of space here ?
 859                  */
 860         
 861                 if (len < sizeof(struct ifreq)) 
 862                         break;
 863         }
 864 
 865         /*
 866          *      All done.  Write the updated control block back to the caller. 
 867          */
 868          
 869         ifc.ifc_len = (pos - ifc.ifc_buf);
 870         ifc.ifc_req = (struct ifreq *) ifc.ifc_buf;
 871         memcpy_tofs(arg, &ifc, sizeof(struct ifconf));
 872         
 873         /*
 874          *      Report how much was filled in
 875          */
 876          
 877         return(pos - arg);
 878 }
 879 
 880 
 881 /*
 882  *      This is invoked by the /proc filesystem handler to display a device
 883  *      in detail.
 884  */
 885 
 886 static int sprintf_stats(char *buffer, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 887 {
 888         struct enet_statistics *stats = (dev->get_stats ? dev->get_stats(dev): NULL);
 889         int size;
 890         
 891         if (stats)
 892                 size = sprintf(buffer, "%6s:%7d %4d %4d %4d %4d %8d %4d %4d %4d %5d %4d\n",
 893                    dev->name,
 894                    stats->rx_packets, stats->rx_errors,
 895                    stats->rx_dropped + stats->rx_missed_errors,
 896                    stats->rx_fifo_errors,
 897                    stats->rx_length_errors + stats->rx_over_errors
 898                    + stats->rx_crc_errors + stats->rx_frame_errors,
 899                    stats->tx_packets, stats->tx_errors, stats->tx_dropped,
 900                    stats->tx_fifo_errors, stats->collisions,
 901                    stats->tx_carrier_errors + stats->tx_aborted_errors
 902                    + stats->tx_window_errors + stats->tx_heartbeat_errors);
 903         else
 904                 size = sprintf(buffer, "%6s: No statistics available.\n", dev->name);
 905 
 906         return size;
 907 }
 908 
 909 /*
 910  *      Called from the PROCfs module. This now uses the new arbitrary sized /proc/net interface
 911  *      to create /proc/net/dev
 912  */
 913  
 914 int dev_get_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
 915 {
 916         int len=0;
 917         off_t begin=0;
 918         off_t pos=0;
 919         int size;
 920         
 921         struct device *dev;
 922 
 923 
 924         size = sprintf(buffer, "Inter-|   Receive                  |  Transmit\n"
 925                             " face |packets errs drop fifo frame|packets errs drop fifo colls carrier\n");
 926         
 927         pos+=size;
 928         len+=size;
 929         
 930 
 931         for (dev = dev_base; dev != NULL; dev = dev->next) 
 932         {
 933                 size = sprintf_stats(buffer+len, dev);
 934                 len+=size;
 935                 pos=begin+len;
 936                                 
 937                 if(pos<offset)
 938                 {
 939                         len=0;
 940                         begin=pos;
 941                 }
 942                 if(pos>offset+length)
 943                         break;
 944         }
 945         
 946         *start=buffer+(offset-begin);   /* Start of wanted data */
 947         len-=(offset-begin);            /* Start slop */
 948         if(len>length)
 949                 len=length;             /* Ending slop */
 950         return len;
 951 }
 952 
 953 
 954 /*
 955  *      This checks bitmasks for the ioctl calls for devices.
 956  */
 957  
 958 static inline int bad_mask(unsigned long mask, unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 959 {
 960         if (addr & (mask = ~mask))
 961                 return 1;
 962         mask = ntohl(mask);
 963         if (mask & (mask+1))
 964                 return 1;
 965         return 0;
 966 }
 967 
 968 /*
 969  *      Perform the SIOCxIFxxx calls. 
 970  *
 971  *      The socket layer has seen an ioctl the address family thinks is
 972  *      for the device. At this point we get invoked to make a decision
 973  */
 974  
 975 static int dev_ifsioc(void *arg, unsigned int getset)
     /* [previous][next][first][last][top][bottom][index][help] */
 976 {
 977         struct ifreq ifr;
 978         struct device *dev;
 979         int ret;
 980 
 981         /*
 982          *      Fetch the caller's info block into kernel space
 983          */
 984 
 985         int err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifreq));
 986         if(err)
 987                 return err;
 988         
 989         memcpy_fromfs(&ifr, arg, sizeof(struct ifreq));
 990 
 991         /*
 992          *      See which interface the caller is talking about. 
 993          */
 994          
 995         if ((dev = dev_get(ifr.ifr_name)) == NULL) 
 996                 return(-ENODEV);
 997 
 998         switch(getset) 
 999         {
1000                 case SIOCGIFFLAGS:      /* Get interface flags */
1001                         ifr.ifr_flags = dev->flags;
1002                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1003                         ret = 0;
1004                         break;
1005                 case SIOCSIFFLAGS:      /* Set interface flags */
1006                         {
1007                                 int old_flags = dev->flags;
1008 #ifdef CONFIG_SLAVE_BALANCING                           
1009                                 if(dev->flags&IFF_SLAVE)
1010                                         return -EBUSY;
1011 #endif                                  
1012                                 dev->flags = ifr.ifr_flags & (
1013                                         IFF_UP | IFF_BROADCAST | IFF_DEBUG | IFF_LOOPBACK |
1014                                         IFF_POINTOPOINT | IFF_NOTRAILERS | IFF_RUNNING |
1015                                         IFF_NOARP | IFF_PROMISC | IFF_ALLMULTI | IFF_SLAVE | IFF_MASTER
1016                                         | IFF_MULTICAST);
1017 #ifdef CONFIG_SLAVE_BALANCING                           
1018                                 if(!(dev->flags&IFF_MASTER) && dev->slave)
1019                                 {
1020                                         dev->slave->flags&=~IFF_SLAVE;
1021                                         dev->slave=NULL;
1022                                 }
1023 #endif
1024                                 /*
1025                                  *      Load in the correct multicast list now the flags have changed.
1026                                  */                             
1027 
1028                                 dev_mc_upload(dev);
1029 #if 0
1030                                 if( dev->set_multicast_list!=NULL)
1031                                 {
1032                                 
1033                                         /*
1034                                          *      Has promiscuous mode been turned off
1035                                          */     
1036                                 
1037                                         if ( (old_flags & IFF_PROMISC) && ((dev->flags & IFF_PROMISC) == 0))
1038                                                 dev->set_multicast_list(dev,0,NULL);
1039                                         
1040                                         /*
1041                                          *      Has it been turned on
1042                                          */
1043         
1044                                         if ( (dev->flags & IFF_PROMISC) && ((old_flags & IFF_PROMISC) == 0))
1045                                                 dev->set_multicast_list(dev,-1,NULL);
1046                                 }
1047 #endif                                  
1048                                 /*
1049                                  *      Have we downed the interface
1050                                  */
1051                 
1052                                 if ((old_flags & IFF_UP) && ((dev->flags & IFF_UP) == 0)) 
1053                                 {
1054                                         ret = dev_close(dev);
1055                                 }
1056                                 else
1057                                 {
1058                                         /*
1059                                          *      Have we upped the interface 
1060                                          */
1061                                          
1062                                         ret = (! (old_flags & IFF_UP) && (dev->flags & IFF_UP))
1063                                                 ? dev_open(dev) : 0;
1064                                         /* 
1065                                          *      Check the flags.
1066                                          */
1067                                         if(ret<0)
1068                                                 dev->flags&=~IFF_UP;    /* Didn't open so down the if */
1069                                 }
1070                         }
1071                         break;
1072                 
1073                 case SIOCGIFADDR:       /* Get interface address (and family) */
1074                         (*(struct sockaddr_in *)
1075                                   &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
1076                         (*(struct sockaddr_in *)
1077                                   &ifr.ifr_addr).sin_family = dev->family;
1078                         (*(struct sockaddr_in *)
1079                                   &ifr.ifr_addr).sin_port = 0;
1080                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1081                         ret = 0;
1082                         break;
1083         
1084                 case SIOCSIFADDR:       /* Set interface address (and family) */
1085                         dev->pa_addr = (*(struct sockaddr_in *)
1086                                  &ifr.ifr_addr).sin_addr.s_addr;
1087                         dev->family = ifr.ifr_addr.sa_family;
1088                         
1089 #ifdef CONFIG_INET      
1090                         /* This is naughty. When net-032e comes out It wants moving into the net032
1091                            code not the kernel. Till then it can sit here (SIGH) */             
1092                         dev->pa_mask = ip_get_mask(dev->pa_addr);
1093 #endif                  
1094                         dev->pa_brdaddr = dev->pa_addr | ~dev->pa_mask;
1095                         ret = 0;
1096                         break;
1097                         
1098                 case SIOCGIFBRDADDR:    /* Get the broadcast address */
1099                         (*(struct sockaddr_in *)
1100                                 &ifr.ifr_broadaddr).sin_addr.s_addr = dev->pa_brdaddr;
1101                         (*(struct sockaddr_in *)
1102                                 &ifr.ifr_broadaddr).sin_family = dev->family;
1103                         (*(struct sockaddr_in *)
1104                                 &ifr.ifr_broadaddr).sin_port = 0;
1105                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1106                         ret = 0;
1107                         break;
1108 
1109                 case SIOCSIFBRDADDR:    /* Set the broadcast address */
1110                         dev->pa_brdaddr = (*(struct sockaddr_in *)
1111                                 &ifr.ifr_broadaddr).sin_addr.s_addr;
1112                         ret = 0;
1113                         break;
1114                         
1115                 case SIOCGIFDSTADDR:    /* Get the destination address (for point-to-point links) */
1116                         (*(struct sockaddr_in *)
1117                                 &ifr.ifr_dstaddr).sin_addr.s_addr = dev->pa_dstaddr;
1118                         (*(struct sockaddr_in *)
1119                                 &ifr.ifr_broadaddr).sin_family = dev->family;
1120                         (*(struct sockaddr_in *)
1121                                 &ifr.ifr_broadaddr).sin_port = 0;
1122                                 memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1123                         ret = 0;
1124                         break;
1125         
1126                 case SIOCSIFDSTADDR:    /* Set the destination address (for point-to-point links) */
1127                         dev->pa_dstaddr = (*(struct sockaddr_in *)
1128                                 &ifr.ifr_dstaddr).sin_addr.s_addr;
1129                         ret = 0;
1130                         break;
1131                         
1132                 case SIOCGIFNETMASK:    /* Get the netmask for the interface */
1133                         (*(struct sockaddr_in *)
1134                                 &ifr.ifr_netmask).sin_addr.s_addr = dev->pa_mask;
1135                         (*(struct sockaddr_in *)
1136                                 &ifr.ifr_netmask).sin_family = dev->family;
1137                         (*(struct sockaddr_in *)
1138                                 &ifr.ifr_netmask).sin_port = 0;
1139                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1140                         ret = 0;
1141                         break;
1142 
1143                 case SIOCSIFNETMASK:    /* Set the netmask for the interface */
1144                         {
1145                                 unsigned long mask = (*(struct sockaddr_in *)
1146                                         &ifr.ifr_netmask).sin_addr.s_addr;
1147                                 ret = -EINVAL;
1148                                 /*
1149                                  *      The mask we set must be legal.
1150                                  */
1151                                 if (bad_mask(mask,0))
1152                                         break;
1153                                 dev->pa_mask = mask;
1154                                 ret = 0;
1155                         }
1156                         break;
1157                         
1158                 case SIOCGIFMETRIC:     /* Get the metric on the interface (currently unused) */
1159                         
1160                         ifr.ifr_metric = dev->metric;
1161                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1162                         ret = 0;
1163                         break;
1164                         
1165                 case SIOCSIFMETRIC:     /* Set the metric on the interface (currently unused) */
1166                         dev->metric = ifr.ifr_metric;
1167                         ret = 0;
1168                         break;
1169         
1170                 case SIOCGIFMTU:        /* Get the MTU of a device */
1171                         ifr.ifr_mtu = dev->mtu;
1172                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1173                         ret = 0;
1174                         break;
1175         
1176                 case SIOCSIFMTU:        /* Set the MTU of a device */
1177                 
1178                         /*
1179                          *      MTU must be positive and under the page size problem
1180                          */
1181                          
1182                         if(ifr.ifr_mtu<1 || ifr.ifr_mtu>3800)
1183                                 return -EINVAL;
1184                         dev->mtu = ifr.ifr_mtu;
1185                         ret = 0;
1186                         break;
1187         
1188                 case SIOCGIFMEM:        /* Get the per device memory space. We can add this but currently
1189                                            do not support it */
1190                         printk("NET: ioctl(SIOCGIFMEM, %p)\n", arg);
1191                         ret = -EINVAL;
1192                         break;
1193                 
1194                 case SIOCSIFMEM:        /* Set the per device memory buffer space. Not applicable in our case */
1195                         printk("NET: ioctl(SIOCSIFMEM, %p)\n", arg);
1196                         ret = -EINVAL;
1197                         break;
1198 
1199                 case OLD_SIOCGIFHWADDR: /* Get the hardware address. This will change and SIFHWADDR will be added */
1200                         memcpy(ifr.old_ifr_hwaddr,dev->dev_addr, MAX_ADDR_LEN);
1201                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1202                         ret=0;
1203                         break;
1204 
1205                 case SIOCGIFHWADDR:
1206                         memcpy(ifr.ifr_hwaddr.sa_data,dev->dev_addr, MAX_ADDR_LEN);
1207                         ifr.ifr_hwaddr.sa_family=dev->type;                     
1208                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1209                         ret=0;
1210                         break;
1211                         
1212                 case SIOCSIFHWADDR:
1213                         if(dev->set_mac_address==NULL)
1214                                 return -EOPNOTSUPP;
1215                         if(ifr.ifr_hwaddr.sa_family!=dev->type)
1216                                 return -EINVAL;
1217                         ret=dev->set_mac_address(dev,ifr.ifr_hwaddr.sa_data);
1218                         break;
1219                         
1220                 case SIOCGIFMAP:
1221                         ifr.ifr_map.mem_start=dev->mem_start;
1222                         ifr.ifr_map.mem_end=dev->mem_end;
1223                         ifr.ifr_map.base_addr=dev->base_addr;
1224                         ifr.ifr_map.irq=dev->irq;
1225                         ifr.ifr_map.dma=dev->dma;
1226                         ifr.ifr_map.port=dev->if_port;
1227                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1228                         ret=0;
1229                         break;
1230                         
1231                 case SIOCSIFMAP:
1232                         if(dev->set_config==NULL)
1233                                 return -EOPNOTSUPP;
1234                         return dev->set_config(dev,&ifr.ifr_map);
1235                         
1236                 case SIOCGIFSLAVE:
1237 #ifdef CONFIG_SLAVE_BALANCING           
1238                         if(dev->slave==NULL)
1239                                 return -ENOENT;
1240                         strncpy(ifr.ifr_name,dev->name,sizeof(ifr.ifr_name));
1241                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1242                         ret=0;
1243 #else
1244                         return -ENOENT;
1245 #endif                  
1246                         break;
1247 #ifdef CONFIG_SLAVE_BALANCING                   
1248                 case SIOCSIFSLAVE:
1249                 {
1250                 
1251                 /*
1252                  *      Fun game. Get the device up and the flags right without
1253                  *      letting some scummy user confuse us.
1254                  */
1255                         unsigned long flags;
1256                         struct device *slave=dev_get(ifr.ifr_slave);
1257                         save_flags(flags);
1258                         if(slave==NULL)
1259                         {
1260                                 return -ENODEV;
1261                         }
1262                         cli();
1263                         if((slave->flags&(IFF_UP|IFF_RUNNING))!=(IFF_UP|IFF_RUNNING))
1264                         {
1265                                 restore_flags(flags);
1266                                 return -EINVAL;
1267                         }
1268                         if(dev->flags&IFF_SLAVE)
1269                         {
1270                                 restore_flags(flags);
1271                                 return -EBUSY;
1272                         }
1273                         if(dev->slave!=NULL)
1274                         {
1275                                 restore_flags(flags);
1276                                 return -EBUSY;
1277                         }
1278                         if(slave->flags&IFF_SLAVE)
1279                         {
1280                                 restore_flags(flags);
1281                                 return -EBUSY;
1282                         }
1283                         dev->slave=slave;
1284                         slave->flags|=IFF_SLAVE;
1285                         dev->flags|=IFF_MASTER;
1286                         restore_flags(flags);
1287                         ret=0;
1288                 }
1289                 break;
1290 #endif                  
1291 
1292                 case SIOCADDMULTI:
1293                         if(dev->set_multicast_list==NULL)
1294                                 return -EINVAL;
1295                         if(ifr.ifr_hwaddr.sa_family!=AF_UNSPEC)
1296                                 return -EINVAL;
1297                         dev_mc_add(dev,ifr.ifr_hwaddr.sa_data, dev->addr_len, 1);
1298                         return 0;
1299 
1300                 case SIOCDELMULTI:
1301                         if(dev->set_multicast_list==NULL)
1302                                 return -EINVAL;
1303                         if(ifr.ifr_hwaddr.sa_family!=AF_UNSPEC)
1304                                 return -EINVAL;
1305                         dev_mc_delete(dev,ifr.ifr_hwaddr.sa_data,dev->addr_len, 1);
1306                         return 0;
1307                 /*
1308                  *      Unknown or private ioctl
1309                  */
1310 
1311                 default:
1312                         if((getset >= SIOCDEVPRIVATE) &&
1313                            (getset <= (SIOCDEVPRIVATE + 15))) {
1314                                 if(dev->do_ioctl==NULL)
1315                                         return -EOPNOTSUPP;
1316                                 ret=dev->do_ioctl(dev, &ifr, getset);
1317                                 memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1318                                 break;
1319                         }
1320                         
1321                         ret = -EINVAL;
1322         }
1323         return(ret);
1324 }
1325 
1326 
1327 /*
1328  *      This function handles all "interface"-type I/O control requests. The actual
1329  *      'doing' part of this is dev_ifsioc above.
1330  */
1331 
1332 int dev_ioctl(unsigned int cmd, void *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1333 {
1334         switch(cmd) 
1335         {
1336                 case SIOCGIFCONF:
1337                         (void) dev_ifconf((char *) arg);
1338                         return 0;
1339 
1340                 /*
1341                  *      Ioctl calls that can be done by all.
1342                  */
1343                  
1344                 case SIOCGIFFLAGS:
1345                 case SIOCGIFADDR:
1346                 case SIOCGIFDSTADDR:
1347                 case SIOCGIFBRDADDR:
1348                 case SIOCGIFNETMASK:
1349                 case SIOCGIFMETRIC:
1350                 case SIOCGIFMTU:
1351                 case SIOCGIFMEM:
1352                 case SIOCGIFHWADDR:
1353                 case SIOCSIFHWADDR:
1354                 case OLD_SIOCGIFHWADDR:
1355                 case SIOCGIFSLAVE:
1356                 case SIOCGIFMAP:
1357                         return dev_ifsioc(arg, cmd);
1358 
1359                 /*
1360                  *      Ioctl calls requiring the power of a superuser
1361                  */
1362                  
1363                 case SIOCSIFFLAGS:
1364                 case SIOCSIFADDR:
1365                 case SIOCSIFDSTADDR:
1366                 case SIOCSIFBRDADDR:
1367                 case SIOCSIFNETMASK:
1368                 case SIOCSIFMETRIC:
1369                 case SIOCSIFMTU:
1370                 case SIOCSIFMEM:
1371                 case SIOCSIFMAP:
1372                 case SIOCSIFSLAVE:
1373                 case SIOCADDMULTI:
1374                 case SIOCDELMULTI:
1375                         if (!suser())
1376                                 return -EPERM;
1377                         return dev_ifsioc(arg, cmd);
1378         
1379                 case SIOCSIFLINK:
1380                         return -EINVAL;
1381 
1382                 /*
1383                  *      Unknown or private ioctl.
1384                  */     
1385                  
1386                 default:
1387                         if((cmd >= SIOCDEVPRIVATE) &&
1388                            (cmd <= (SIOCDEVPRIVATE + 15))) {
1389                                 return dev_ifsioc(arg, cmd);
1390                         }
1391                         return -EINVAL;
1392         }
1393 }
1394 
1395 
1396 /*
1397  *      Initialize the DEV module. At boot time this walks the device list and
1398  *      unhooks any devices that fail to initialise (normally hardware not 
1399  *      present) and leaves us with a valid list of present and active devices.
1400  *
1401  *      The PCMCIA code may need to change this a little, and add a pair
1402  *      of register_inet_device() unregister_inet_device() calls. This will be
1403  *      needed for ethernet as modules support.
1404  */
1405  
1406 void dev_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1407 {
1408         struct device *dev, *dev2;
1409 
1410         /*
1411          *      Add the devices.
1412          *      If the call to dev->init fails, the dev is removed
1413          *      from the chain disconnecting the device until the
1414          *      next reboot.
1415          */
1416          
1417         dev2 = NULL;
1418         for (dev = dev_base; dev != NULL; dev=dev->next) 
1419         {
1420                 if (dev->init && dev->init(dev)) 
1421                 {
1422                         /*
1423                          *      It failed to come up. Unhook it.
1424                          */
1425                          
1426                         if (dev2 == NULL) 
1427                                 dev_base = dev->next;
1428                         else 
1429                                 dev2->next = dev->next;
1430                 } 
1431                 else
1432                 {
1433                         dev2 = dev;
1434                 }
1435         }
1436 }

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