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         printk("loopback error: called by %08lx\n",
  54                 ((unsigned long *)&skb)[-1]);
  55         stats->tx_errors++;
  56         return(1);
  57   }
  58   dev->tbusy = 1;
  59   sti();
  60 
  61   start_bh_atomic();
  62   done = dev_rint(skb->data, skb->len, 0, dev);
  63   if (skb->free) kfree_skb(skb, FREE_WRITE);
  64   end_bh_atomic();
  65 
  66   while (done != 1) {
  67         start_bh_atomic();
  68         done = dev_rint(NULL, 0, 0, dev);
  69         end_bh_atomic();
  70   }
  71   stats->tx_packets++;
  72 
  73   dev->tbusy = 0;
  74 
  75 #if 1
  76         __asm__("cmpl $0,_intr_count\n\t"
  77                 "jne 1f\n\t"
  78                 "movl _bh_active,%%eax\n\t"
  79                 "testl _bh_mask,%%eax\n\t"
  80                 "je 1f\n\t"
  81                 "incl _intr_count\n\t"
  82                 "call _do_bottom_half\n\t"
  83                 "decl _intr_count\n"
  84                 "1:"
  85                 :
  86                 :
  87                 : "ax", "dx", "cx");
  88 #endif
  89 
  90   return(0);
  91 }
  92 
  93 static struct enet_statistics *
  94 get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  95 {
  96     return (struct enet_statistics *)dev->priv;
  97 }
  98 
  99 /* Initialize the rest of the LOOPBACK device. */
 100 int
 101 loopback_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 102 {
 103   int i;
 104 
 105   dev->mtu              = 2000;                 /* MTU                  */
 106   dev->tbusy            = 0;
 107   dev->hard_start_xmit  = loopback_xmit;
 108   dev->open             = NULL;
 109 #if 1
 110   dev->hard_header      = eth_header;
 111   dev->hard_header_len  = ETH_HLEN;             /* 14                   */
 112   dev->addr_len         = ETH_ALEN;             /* 6                    */
 113   dev->type             = ARPHRD_ETHER;         /* 0x0001               */
 114   dev->type_trans       = eth_type_trans;
 115   dev->rebuild_header   = eth_rebuild_header;
 116 #else
 117   dev->hard_header_length = 0;
 118   dev->addr_len         = 0;
 119   dev->type             = 0;                    /* loopback_type (0)    */
 120   dev->hard_header      = NULL;
 121   dev->type_trans       = NULL;
 122   dev->rebuild_header   = NULL;
 123 #endif
 124 
 125   /* New-style flags. */
 126   dev->flags            = IFF_LOOPBACK;
 127   dev->family           = AF_INET;
 128   dev->pa_addr          = in_aton("127.0.0.1");
 129   dev->pa_brdaddr       = in_aton("127.255.255.255");
 130   dev->pa_mask          = in_aton("255.0.0.0");
 131   dev->pa_alen          = sizeof(unsigned long);
 132   dev->priv = kmalloc(sizeof(struct enet_statistics), GFP_KERNEL);
 133   memset(dev->priv, 0, sizeof(struct enet_statistics));
 134   dev->get_stats = get_stats;
 135 
 136   /* Fill in the generic fields of the device structure. */
 137   for (i = 0; i < DEV_NUMBUFFS; i++)
 138         skb_queue_head_init(&dev->buffs[i]);
 139   
 140   return(0);
 141 };

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