root/drivers/net/loopback.c

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

DEFINITIONS

This source file includes following definitions.
  1. loopback_xmit
  2. get_stats
  3. loopback_init

   1 /*
   2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3  *              operating system.  INET is implemented using the  BSD Socket
   4  *              interface as the means of communication with the user level.
   5  *
   6  *              Pseudo-driver for the loopback interface.
   7  *
   8  * Version:     @(#)loopback.c  1.0.4b  08/16/93
   9  *
  10  * Authors:     Ross Biro, <bir7@leland.Stanford.Edu>
  11  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12  *              Donald Becker, <becker@super.org>
  13  *
  14  *              This program is free software; you can redistribute it and/or
  15  *              modify it under the terms of the GNU General Public License
  16  *              as published by the Free Software Foundation; either version
  17  *              2 of the License, or (at your option) any later version.
  18  */
  19 #include <linux/config.h>
  20 #include <linux/kernel.h>
  21 #include <linux/sched.h>
  22 #include <linux/fs.h>
  23 #include <linux/types.h>
  24 #include <linux/string.h>
  25 #include <linux/socket.h>
  26 #include <linux/errno.h>
  27 #include <linux/fcntl.h>
  28 #include <linux/in.h>
  29 #include <linux/if_ether.h>     /* For the statistics structure. */
  30 
  31 #include <asm/system.h>
  32 #include <asm/segment.h>
  33 #include <asm/io.h>
  34 
  35 #include <linux/inet.h>
  36 #include <linux/netdevice.h>
  37 #include <linux/etherdevice.h>
  38 #include <linux/skbuff.h>
  39 
  40 
  41 static int
  42 loopback_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  43 {
  44   struct enet_statistics *stats = (struct enet_statistics *)dev->priv;
  45   int done;
  46 
  47   DPRINTF((DBG_LOOPB, "loopback_xmit(dev=%X, skb=%X)\n", dev, skb));
  48   if (skb == NULL || dev == NULL) return(0);
  49 
  50   cli();
  51   if (dev->tbusy != 0) {
  52         sti();
  53         stats->tx_errors++;
  54         return(1);
  55   }
  56   dev->tbusy = 1;
  57   sti();
  58 
  59   done = dev_rint(skb->data, skb->len, 0, dev);
  60   if (skb->free) kfree_skb(skb, FREE_WRITE);
  61 
  62   while (done != 1) {
  63         done = dev_rint(NULL, 0, 0, dev);
  64   }
  65   stats->tx_packets++;
  66 
  67   dev->tbusy = 0;
  68 
  69 #if 1
  70         __asm__("cmpl $0,_intr_count\n\t"
  71                 "jne 1f\n\t"
  72                 "movl _bh_active,%%eax\n\t"
  73                 "testl _bh_mask,%%eax\n\t"
  74                 "je 1f\n\t"
  75                 "incl _intr_count\n\t"
  76                 "call _do_bottom_half\n\t"
  77                 "decl _intr_count\n"
  78                 "1:"
  79                 :
  80                 :
  81                 : "ax", "dx", "cx");
  82 #endif
  83 
  84   return(0);
  85 }
  86 
  87 static struct enet_statistics *
  88 get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  89 {
  90     return (struct enet_statistics *)dev->priv;
  91 }
  92 
  93 /* Initialize the rest of the LOOPBACK device. */
  94 int
  95 loopback_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  96 {
  97   int i;
  98 
  99   dev->mtu              = 2000;                 /* MTU                  */
 100   dev->tbusy            = 0;
 101   dev->hard_start_xmit  = loopback_xmit;
 102   dev->open             = NULL;
 103 #if 1
 104   dev->hard_header      = eth_header;
 105   dev->hard_header_len  = ETH_HLEN;             /* 14                   */
 106   dev->addr_len         = ETH_ALEN;             /* 6                    */
 107   dev->type             = ARPHRD_ETHER;         /* 0x0001               */
 108   dev->type_trans       = eth_type_trans;
 109   dev->rebuild_header   = eth_rebuild_header;
 110 #else
 111   dev->hard_header_length = 0;
 112   dev->addr_len         = 0;
 113   dev->type             = 0;                    /* loopback_type (0)    */
 114   dev->hard_header      = NULL;
 115   dev->type_trans       = NULL;
 116   dev->rebuild_header   = NULL;
 117 #endif
 118 
 119   /* New-style flags. */
 120   dev->flags            = IFF_LOOPBACK;
 121   dev->family           = AF_INET;
 122   dev->pa_addr          = in_aton("127.0.0.1");
 123   dev->pa_brdaddr       = in_aton("127.255.255.255");
 124   dev->pa_mask          = in_aton("255.0.0.0");
 125   dev->pa_alen          = sizeof(unsigned long);
 126   dev->priv = kmalloc(sizeof(struct enet_statistics), GFP_KERNEL);
 127   memset(dev->priv, 0, sizeof(struct enet_statistics));
 128   dev->get_stats = get_stats;
 129 
 130   /* Fill in the generic fields of the device structure. */
 131   for (i = 0; i < DEV_NUMBUFFS; i++)
 132         skb_queue_head_init(&dev->buffs[i]);
 133   
 134   return(0);
 135 };

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