OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [net/] [dummy.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/* dummy.c: a dummy net driver
2
 
3
        The purpose of this driver is to provide a device to point a
4
        route through, but not to actually transmit packets.
5
 
6
        Why?  If you have a machine whose only connection is an occasional
7
        PPP/SLIP/PLIP link, you can only connect to your own hostname
8
        when the link is up.  Otherwise you have to use localhost.
9
        This isn't very consistent.
10
 
11
        One solution is to set up a dummy link using PPP/SLIP/PLIP,
12
        but this seems (to me) too much overhead for too little gain.
13
        This driver provides a small alternative. Thus you can do
14
 
15
        [when not running slip]
16
                ifconfig dummy slip.addr.ess.here up
17
        [to go to slip]
18
                ifconfig dummy down
19
                dip whatever
20
 
21
        This was written by looking at Donald Becker's skeleton driver
22
        and the loopback driver.  I then threw away anything that didn't
23
        apply!  Thanks to Alan Cox for the key clue on what to do with
24
        misguided packets.
25
 
26
                        Nick Holloway, 27th May 1994
27
        [I tweaked this explanation a little but that's all]
28
                        Alan Cox, 30th May 1994
29
*/
30
 
31
/* To have statistics (just packets sent) define this */
32
#undef DUMMY_STATS
33
 
34
#include <linux/module.h>
35
 
36
#include <linux/kernel.h>
37
#include <linux/sched.h>
38
#include <linux/types.h>
39
#include <linux/fcntl.h>
40
#include <linux/interrupt.h>
41
#include <linux/ptrace.h>
42
#include <linux/ioport.h>
43
#include <linux/in.h>
44
#include <linux/malloc.h>
45
#include <linux/string.h>
46
#include <asm/system.h>
47
#include <asm/bitops.h>
48
#include <asm/io.h>
49
#include <asm/dma.h>
50
#include <linux/errno.h>
51
 
52
#include <linux/netdevice.h>
53
#include <linux/etherdevice.h>
54
#include <linux/skbuff.h>
55
 
56
static int dummy_xmit(struct sk_buff *skb, struct device *dev);
57
#ifdef DUMMY_STATS
58
static struct enet_statistics *dummy_get_stats(struct device *dev);
59
#endif
60
 
61
static int dummy_open(struct device *dev)
62
{
63
        MOD_INC_USE_COUNT;
64
        return 0;
65
}
66
 
67
static int dummy_close(struct device *dev)
68
{
69
        MOD_DEC_USE_COUNT;
70
        return 0;
71
}
72
 
73
static int dummy_rebuild(void *eth, struct device *dev, unsigned long raddr, struct sk_buff *skb)
74
{
75
        return 0;
76
}
77
 
78
int dummy_init(struct device *dev)
79
{
80
/* I commented this out as bootup is noisy enough anyway and this driver
81
   seems pretty reliable 8) 8) 8) */
82
/*      printk ( KERN_INFO "Dummy net driver (94/05/27 v1.0)\n" ); */
83
 
84
        /* Initialize the device structure. */
85
        dev->hard_start_xmit    = dummy_xmit;
86
 
87
#if DUMMY_STATS
88
        dev->priv = kmalloc(sizeof(struct enet_statistics), GFP_KERNEL);
89
        if (dev->priv == NULL)
90
                return -ENOMEM;
91
        memset(dev->priv, 0, sizeof(struct enet_statistics));
92
        dev->get_stats          = dummy_get_stats;
93
#endif
94
 
95
        dev->open = dummy_open;
96
        dev->stop = dummy_close;
97
 
98
        /* Fill in the fields of the device structure with ethernet-generic values. */
99
        ether_setup(dev);
100
        dev->flags |= IFF_NOARP;
101
        dev->rebuild_header = dummy_rebuild;
102
 
103
        return 0;
104
}
105
 
106
static int
107
dummy_xmit(struct sk_buff *skb, struct device *dev)
108
{
109
#if DUMMY_STATS
110
        struct enet_statistics *stats;
111
#endif
112
 
113
        if (skb == NULL || dev == NULL)
114
                return 0;
115
 
116
        dev_kfree_skb(skb, FREE_WRITE);
117
 
118
#if DUMMY_STATS
119
        stats = (struct enet_statistics *)dev->priv;
120
        stats->tx_packets++;
121
#endif
122
 
123
        return 0;
124
}
125
 
126
#if DUMMY_STATS
127
static struct enet_statistics *
128
dummy_get_stats(struct device *dev)
129
{
130
        struct enet_statistics *stats = (struct enet_statistics*) dev->priv;
131
        return stats;
132
}
133
#endif
134
 
135
#ifdef MODULE
136
 
137
static int dummy_probe(struct device *dev)
138
{
139
        dummy_init(dev);
140
        return 0;
141
}
142
 
143
static struct device dev_dummy = {
144
        "dummy0\0   ",
145
                0, 0, 0, 0,
146
                0x0, 0,
147
                0, 0, 0, NULL, dummy_probe };
148
 
149
int init_module(void)
150
{
151
        /* Find a name for this unit */
152
        int ct= 1;
153
 
154
        while(dev_get(dev_dummy.name)!=NULL && ct<100)
155
        {
156
                sprintf(dev_dummy.name,"dummy%d",ct);
157
                ct++;
158
        }
159
        if(ct==100)
160
                return -ENFILE;
161
 
162
        if (register_netdev(&dev_dummy) != 0)
163
                return -EIO;
164
        return 0;
165
}
166
 
167
void cleanup_module(void)
168
{
169
        unregister_netdev(&dev_dummy);
170
        kfree(dev_dummy.priv);
171
        dev_dummy.priv = NULL;
172
}
173
#endif /* MODULE */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.