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