1
2
3#ifndef LINUX_ATMDEV_H
4#define LINUX_ATMDEV_H
5
6
7#include <linux/wait.h>
8#include <linux/time.h>
9#include <linux/net.h>
10#include <linux/bug.h>
11#include <linux/skbuff.h>
12#include <linux/uio.h>
13#include <net/sock.h>
14#include <linux/atomic.h>
15#include <linux/refcount.h>
16#include <uapi/linux/atmdev.h>
17
18#ifdef CONFIG_PROC_FS
19#include <linux/proc_fs.h>
20
21extern struct proc_dir_entry *atm_proc_root;
22#endif
23
24#ifdef CONFIG_COMPAT
25#include <linux/compat.h>
26struct compat_atm_iobuf {
27 int length;
28 compat_uptr_t buffer;
29};
30#endif
31
32struct k_atm_aal_stats {
33#define __HANDLE_ITEM(i) atomic_t i
34 __AAL_STAT_ITEMS
35#undef __HANDLE_ITEM
36};
37
38
39struct k_atm_dev_stats {
40 struct k_atm_aal_stats aal0;
41 struct k_atm_aal_stats aal34;
42 struct k_atm_aal_stats aal5;
43};
44
45struct device;
46
47enum {
48 ATM_VF_ADDR,
49
50 ATM_VF_READY,
51
52 ATM_VF_PARTIAL,
53
54 ATM_VF_REGIS,
55
56 ATM_VF_BOUND,
57
58 ATM_VF_RELEASED,
59
60 ATM_VF_HASQOS,
61 ATM_VF_LISTEN,
62 ATM_VF_META,
63
64
65 ATM_VF_SESSION,
66 ATM_VF_HASSAP,
67 ATM_VF_CLOSE,
68 ATM_VF_WAITING,
69 ATM_VF_IS_CLIP,
70};
71
72
73#define ATM_VF2VS(flags) \
74 (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
75 test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
76 test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
77 test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
78 test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
79
80
81enum {
82 ATM_DF_REMOVED,
83};
84
85
86#define ATM_PHY_SIG_LOST 0
87#define ATM_PHY_SIG_UNKNOWN 1
88#define ATM_PHY_SIG_FOUND 2
89
90#define ATM_ATMOPT_CLP 1
91
92struct atm_vcc {
93
94 struct sock sk;
95 unsigned long flags;
96 short vpi;
97
98 int vci;
99 unsigned long aal_options;
100 unsigned long atm_options;
101 struct atm_dev *dev;
102 struct atm_qos qos;
103 struct atm_sap sap;
104 void (*release_cb)(struct atm_vcc *vcc);
105 void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
106 void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb);
107 int (*push_oam)(struct atm_vcc *vcc,void *cell);
108 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
109 void *dev_data;
110 void *proto_data;
111 struct k_atm_aal_stats *stats;
112 struct module *owner;
113
114 short itf;
115 struct sockaddr_atmsvc local;
116 struct sockaddr_atmsvc remote;
117
118 struct atm_vcc *session;
119
120 void *user_back;
121
122
123};
124
125static inline struct atm_vcc *atm_sk(struct sock *sk)
126{
127 return (struct atm_vcc *)sk;
128}
129
130static inline struct atm_vcc *ATM_SD(struct socket *sock)
131{
132 return atm_sk(sock->sk);
133}
134
135static inline struct sock *sk_atm(struct atm_vcc *vcc)
136{
137 return (struct sock *)vcc;
138}
139
140struct atm_dev_addr {
141 struct sockaddr_atmsvc addr;
142 struct list_head entry;
143};
144
145enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
146
147struct atm_dev {
148 const struct atmdev_ops *ops;
149 const struct atmphy_ops *phy;
150
151 const char *type;
152 int number;
153 void *dev_data;
154 void *phy_data;
155 unsigned long flags;
156 struct list_head local;
157 struct list_head lecs;
158 unsigned char esi[ESI_LEN];
159 struct atm_cirange ci_range;
160 struct k_atm_dev_stats stats;
161 char signal;
162 int link_rate;
163 refcount_t refcnt;
164 spinlock_t lock;
165#ifdef CONFIG_PROC_FS
166 struct proc_dir_entry *proc_entry;
167 char *proc_name;
168#endif
169 struct device class_dev;
170 struct list_head dev_list;
171};
172
173
174
175
176#define ATM_OF_IMMED 1
177#define ATM_OF_INRATE 2
178
179
180
181
182
183
184struct atmdev_ops {
185 void (*dev_close)(struct atm_dev *dev);
186 int (*open)(struct atm_vcc *vcc);
187 void (*close)(struct atm_vcc *vcc);
188 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
189#ifdef CONFIG_COMPAT
190 int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
191 void __user *arg);
192#endif
193 int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
194 void __user *optval,int optlen);
195 int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
196 void __user *optval,unsigned int optlen);
197 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
198 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
199 void (*phy_put)(struct atm_dev *dev,unsigned char value,
200 unsigned long addr);
201 unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
202 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
203 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
204 struct module *owner;
205};
206
207struct atmphy_ops {
208 int (*start)(struct atm_dev *dev);
209 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
210 void (*interrupt)(struct atm_dev *dev);
211 int (*stop)(struct atm_dev *dev);
212};
213
214struct atm_skb_data {
215 struct atm_vcc *vcc;
216 unsigned long atm_options;
217};
218
219#define VCC_HTABLE_SIZE 32
220
221extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
222extern rwlock_t vcc_sklist_lock;
223
224#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
225
226struct atm_dev *atm_dev_register(const char *type, struct device *parent,
227 const struct atmdev_ops *ops,
228 int number,
229 unsigned long *flags);
230struct atm_dev *atm_dev_lookup(int number);
231void atm_dev_deregister(struct atm_dev *dev);
232
233
234
235
236
237
238void atm_dev_signal_change(struct atm_dev *dev, char signal);
239
240void vcc_insert_socket(struct sock *sk);
241
242void atm_dev_release_vccs(struct atm_dev *dev);
243
244
245static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
246{
247 atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
248}
249
250
251static inline void atm_return(struct atm_vcc *vcc,int truesize)
252{
253 atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
254}
255
256
257static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
258{
259 return (size + refcount_read(&sk_atm(vcc)->sk_wmem_alloc)) <
260 sk_atm(vcc)->sk_sndbuf;
261}
262
263
264static inline void atm_dev_hold(struct atm_dev *dev)
265{
266 refcount_inc(&dev->refcnt);
267}
268
269
270static inline void atm_dev_put(struct atm_dev *dev)
271{
272 if (refcount_dec_and_test(&dev->refcnt)) {
273 BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
274 if (dev->ops->dev_close)
275 dev->ops->dev_close(dev);
276 put_device(&dev->class_dev);
277 }
278}
279
280
281int atm_charge(struct atm_vcc *vcc,int truesize);
282struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
283 gfp_t gfp_flags);
284int atm_pcr_goal(const struct atm_trafprm *tp);
285
286void vcc_release_async(struct atm_vcc *vcc, int reply);
287
288struct atm_ioctl {
289 struct module *owner;
290
291
292 int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
293 struct list_head list;
294};
295
296
297
298
299
300
301
302
303void register_atm_ioctl(struct atm_ioctl *);
304
305
306
307
308void deregister_atm_ioctl(struct atm_ioctl *);
309
310
311
312
313
314
315
316int register_atmdevice_notifier(struct notifier_block *nb);
317void unregister_atmdevice_notifier(struct notifier_block *nb);
318
319#endif
320