This source file includes following definitions.
- loopback_xmit
- get_stats
- loopback_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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>
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)
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)
95 {
96 return (struct enet_statistics *)dev->priv;
97 }
98
99
100 int
101 loopback_init(struct device *dev)
102 {
103 int i;
104
105 dev->mtu = 2000;
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;
112 dev->addr_len = ETH_ALEN;
113 dev->type = ARPHRD_ETHER;
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;
120 dev->hard_header = NULL;
121 dev->type_trans = NULL;
122 dev->rebuild_header = NULL;
123 #endif
124
125
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
137 for (i = 0; i < DEV_NUMBUFFS; i++)
138 skb_queue_head_init(&dev->buffs[i]);
139
140 return(0);
141 };