Commit | Line | Data |
---|---|---|
fb296449 CW |
1 | /* |
2 | * adummy.c: a dummy ATM driver | |
3 | */ | |
4 | ||
fb296449 CW |
5 | #include <linux/module.h> |
6 | #include <linux/version.h> | |
7 | #include <linux/kernel.h> | |
8 | #include <linux/skbuff.h> | |
9 | #include <linux/pci.h> | |
10 | #include <linux/errno.h> | |
11 | #include <linux/types.h> | |
12 | #include <linux/string.h> | |
13 | #include <linux/delay.h> | |
14 | #include <linux/init.h> | |
15 | #include <linux/mm.h> | |
fb296449 CW |
16 | #include <linux/timer.h> |
17 | #include <linux/interrupt.h> | |
18 | #include <asm/io.h> | |
19 | #include <asm/byteorder.h> | |
20 | #include <asm/uaccess.h> | |
21 | ||
22 | #include <linux/atmdev.h> | |
23 | #include <linux/atm.h> | |
24 | #include <linux/sonet.h> | |
25 | ||
26 | /* version definition */ | |
27 | ||
28 | #define DRV_VERSION "1.0" | |
29 | ||
30 | #define DEV_LABEL "adummy" | |
31 | ||
32 | #define ADUMMY_DEV(dev) ((struct adummy_dev *) (dev)->dev_data) | |
33 | ||
34 | struct adummy_dev { | |
35 | struct atm_dev *atm_dev; | |
36 | ||
37 | struct list_head entry; | |
38 | }; | |
39 | ||
40 | /* globals */ | |
41 | ||
42 | static LIST_HEAD(adummy_devs); | |
43 | ||
44 | static int __init | |
45 | adummy_start(struct atm_dev *dev) | |
46 | { | |
47 | dev->ci_range.vpi_bits = 4; | |
48 | dev->ci_range.vci_bits = 12; | |
49 | ||
50 | return 0; | |
51 | } | |
52 | ||
53 | static int | |
54 | adummy_open(struct atm_vcc *vcc) | |
55 | { | |
56 | short vpi = vcc->vpi; | |
57 | int vci = vcc->vci; | |
58 | ||
59 | if (vci == ATM_VCI_UNSPEC || vpi == ATM_VPI_UNSPEC) | |
60 | return 0; | |
61 | ||
62 | set_bit(ATM_VF_ADDR, &vcc->flags); | |
63 | set_bit(ATM_VF_READY, &vcc->flags); | |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
68 | static void | |
69 | adummy_close(struct atm_vcc *vcc) | |
70 | { | |
71 | clear_bit(ATM_VF_READY, &vcc->flags); | |
72 | clear_bit(ATM_VF_ADDR, &vcc->flags); | |
73 | } | |
74 | ||
75 | static int | |
76 | adummy_send(struct atm_vcc *vcc, struct sk_buff *skb) | |
77 | { | |
78 | if (vcc->pop) | |
79 | vcc->pop(vcc, skb); | |
80 | else | |
81 | dev_kfree_skb_any(skb); | |
82 | atomic_inc(&vcc->stats->tx); | |
83 | ||
84 | return 0; | |
85 | } | |
86 | ||
87 | static int | |
88 | adummy_proc_read(struct atm_dev *dev, loff_t *pos, char *page) | |
89 | { | |
90 | int left = *pos; | |
91 | ||
92 | if (!left--) | |
93 | return sprintf(page, "version %s\n", DRV_VERSION); | |
94 | ||
95 | return 0; | |
96 | } | |
97 | ||
98 | static struct atmdev_ops adummy_ops = | |
99 | { | |
100 | .open = adummy_open, | |
101 | .close = adummy_close, | |
102 | .send = adummy_send, | |
103 | .proc_read = adummy_proc_read, | |
104 | .owner = THIS_MODULE | |
105 | }; | |
106 | ||
107 | static int __init adummy_init(void) | |
108 | { | |
109 | struct atm_dev *atm_dev; | |
110 | struct adummy_dev *adummy_dev; | |
111 | int err = 0; | |
112 | ||
113 | printk(KERN_ERR "adummy: version %s\n", DRV_VERSION); | |
114 | ||
0c1cca1d | 115 | adummy_dev = kzalloc(sizeof(struct adummy_dev), |
fb296449 CW |
116 | GFP_KERNEL); |
117 | if (!adummy_dev) { | |
0c1cca1d | 118 | printk(KERN_ERR DEV_LABEL ": kzalloc() failed\n"); |
fb296449 CW |
119 | err = -ENOMEM; |
120 | goto out; | |
121 | } | |
7877327d | 122 | atm_dev = atm_dev_register(DEV_LABEL, &adummy_ops, -1, NULL); |
fb296449 CW |
123 | if (!atm_dev) { |
124 | printk(KERN_ERR DEV_LABEL ": atm_dev_register() failed\n"); | |
125 | err = -ENODEV; | |
126 | goto out_kfree; | |
127 | } | |
128 | ||
129 | adummy_dev->atm_dev = atm_dev; | |
130 | atm_dev->dev_data = adummy_dev; | |
131 | ||
132 | if (adummy_start(atm_dev)) { | |
133 | printk(KERN_ERR DEV_LABEL ": adummy_start() failed\n"); | |
134 | err = -ENODEV; | |
135 | goto out_unregister; | |
136 | } | |
137 | ||
138 | list_add(&adummy_dev->entry, &adummy_devs); | |
139 | out: | |
140 | return err; | |
141 | ||
142 | out_unregister: | |
143 | atm_dev_deregister(atm_dev); | |
144 | out_kfree: | |
145 | kfree(adummy_dev); | |
146 | goto out; | |
147 | } | |
148 | ||
149 | static void __exit adummy_cleanup(void) | |
150 | { | |
151 | struct adummy_dev *adummy_dev, *next; | |
152 | ||
153 | list_for_each_entry_safe(adummy_dev, next, &adummy_devs, entry) { | |
154 | atm_dev_deregister(adummy_dev->atm_dev); | |
155 | kfree(adummy_dev); | |
156 | } | |
157 | } | |
158 | ||
159 | module_init(adummy_init); | |
160 | module_exit(adummy_cleanup); | |
161 | ||
162 | MODULE_AUTHOR("chas williams <chas@cmf.nrl.navy.mil>"); | |
163 | MODULE_DESCRIPTION("dummy ATM driver"); | |
164 | MODULE_LICENSE("GPL"); |