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