1
2
3
4
5
6#ifndef LINUX_ATMDEV_H
7#define LINUX_ATMDEV_H
8
9
10#include <linux/atmapi.h>
11#include <linux/atm.h>
12#include <linux/atmioc.h>
13
14
15#define ESI_LEN 6
16
17#define ATM_OC3_PCR (155520000/270*260/8/53)
18
19
20
21
22#define ATM_25_PCR ((25600000/8-8000)/54)
23
24#define ATM_OC12_PCR (622080000/1080*1040/8/53)
25
26
27
28
29#define ATM_DS3_PCR (8000*12)
30
31
32
33#define __AAL_STAT_ITEMS \
34 __HANDLE_ITEM(tx); \
35 __HANDLE_ITEM(tx_err); \
36 __HANDLE_ITEM(rx); \
37 __HANDLE_ITEM(rx_err); \
38 __HANDLE_ITEM(rx_drop);
39
40struct atm_aal_stats {
41#define __HANDLE_ITEM(i) int i
42 __AAL_STAT_ITEMS
43#undef __HANDLE_ITEM
44};
45
46
47struct atm_dev_stats {
48 struct atm_aal_stats aal0;
49 struct atm_aal_stats aal34;
50 struct atm_aal_stats aal5;
51} __ATM_API_ALIGN;
52
53
54#define ATM_GETLINKRATE _IOW('a',ATMIOC_ITF+1,struct atmif_sioc)
55
56#define ATM_GETNAMES _IOW('a',ATMIOC_ITF+3,struct atm_iobuf)
57
58#define ATM_GETTYPE _IOW('a',ATMIOC_ITF+4,struct atmif_sioc)
59
60#define ATM_GETESI _IOW('a',ATMIOC_ITF+5,struct atmif_sioc)
61
62#define ATM_GETADDR _IOW('a',ATMIOC_ITF+6,struct atmif_sioc)
63
64#define ATM_RSTADDR _IOW('a',ATMIOC_ITF+7,struct atmif_sioc)
65
66#define ATM_ADDADDR _IOW('a',ATMIOC_ITF+8,struct atmif_sioc)
67
68#define ATM_DELADDR _IOW('a',ATMIOC_ITF+9,struct atmif_sioc)
69
70#define ATM_GETCIRANGE _IOW('a',ATMIOC_ITF+10,struct atmif_sioc)
71
72#define ATM_SETCIRANGE _IOW('a',ATMIOC_ITF+11,struct atmif_sioc)
73
74#define ATM_SETESI _IOW('a',ATMIOC_ITF+12,struct atmif_sioc)
75
76#define ATM_SETESIF _IOW('a',ATMIOC_ITF+13,struct atmif_sioc)
77
78#define ATM_ADDLECSADDR _IOW('a', ATMIOC_ITF+14, struct atmif_sioc)
79
80#define ATM_DELLECSADDR _IOW('a', ATMIOC_ITF+15, struct atmif_sioc)
81
82#define ATM_GETLECSADDR _IOW('a', ATMIOC_ITF+16, struct atmif_sioc)
83
84
85#define ATM_GETSTAT _IOW('a',ATMIOC_SARCOM+0,struct atmif_sioc)
86
87#define ATM_GETSTATZ _IOW('a',ATMIOC_SARCOM+1,struct atmif_sioc)
88
89#define ATM_GETLOOP _IOW('a',ATMIOC_SARCOM+2,struct atmif_sioc)
90
91#define ATM_SETLOOP _IOW('a',ATMIOC_SARCOM+3,struct atmif_sioc)
92
93#define ATM_QUERYLOOP _IOW('a',ATMIOC_SARCOM+4,struct atmif_sioc)
94
95#define ATM_SETSC _IOW('a',ATMIOC_SPECIAL+1,int)
96
97#define ATM_SETBACKEND _IOW('a',ATMIOC_SPECIAL+2,atm_backend_t)
98
99#define ATM_NEWBACKENDIF _IOW('a',ATMIOC_SPECIAL+3,atm_backend_t)
100
101#define ATM_ADDPARTY _IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
102
103#ifdef CONFIG_COMPAT
104
105#define COMPAT_ATM_ADDPARTY _IOW('a', ATMIOC_SPECIAL+4,struct compat_atm_iobuf)
106#endif
107#define ATM_DROPPARTY _IOW('a', ATMIOC_SPECIAL+5,int)
108
109
110
111
112
113
114
115#define ATM_BACKEND_RAW 0
116#define ATM_BACKEND_PPP 1
117#define ATM_BACKEND_BR2684 2
118
119
120#define ATM_ITFTYP_LEN 8
121
122
123
124
125
126
127#define __ATM_LM_NONE 0
128#define __ATM_LM_AAL 1
129#define __ATM_LM_ATM 2
130
131#define __ATM_LM_PHY 8
132#define __ATM_LM_ANALOG 16
133
134
135#define __ATM_LM_MKLOC(n) ((n))
136#define __ATM_LM_MKRMT(n) ((n) << 8)
137
138#define __ATM_LM_XTLOC(n) ((n) & 0xff)
139#define __ATM_LM_XTRMT(n) (((n) >> 8) & 0xff)
140
141#define ATM_LM_NONE 0
142
143#define ATM_LM_LOC_AAL __ATM_LM_MKLOC(__ATM_LM_AAL)
144#define ATM_LM_LOC_ATM __ATM_LM_MKLOC(__ATM_LM_ATM)
145#define ATM_LM_LOC_PHY __ATM_LM_MKLOC(__ATM_LM_PHY)
146#define ATM_LM_LOC_ANALOG __ATM_LM_MKLOC(__ATM_LM_ANALOG)
147
148#define ATM_LM_RMT_AAL __ATM_LM_MKRMT(__ATM_LM_AAL)
149#define ATM_LM_RMT_ATM __ATM_LM_MKRMT(__ATM_LM_ATM)
150#define ATM_LM_RMT_PHY __ATM_LM_MKRMT(__ATM_LM_PHY)
151#define ATM_LM_RMT_ANALOG __ATM_LM_MKRMT(__ATM_LM_ANALOG)
152
153
154
155
156
157
158
159struct atm_iobuf {
160 int length;
161 void __user *buffer;
162};
163
164
165
166#define ATM_CI_MAX -1
167
168struct atm_cirange {
169 signed char vpi_bits;
170 signed char vci_bits;
171};
172
173
174
175#define ATM_SC_RX 1024
176#define ATM_SC_TX 2048
177
178#define ATM_BACKLOG_DEFAULT 32
179
180
181
182
183#define ATM_MF_IMMED 1
184#define ATM_MF_INC_RSV 2
185#define ATM_MF_INC_SHP 4
186#define ATM_MF_DEC_RSV 8
187#define ATM_MF_DEC_SHP 16
188#define ATM_MF_BWD 32
189
190#define ATM_MF_SET (ATM_MF_INC_RSV | ATM_MF_INC_SHP | ATM_MF_DEC_RSV | \
191 ATM_MF_DEC_SHP | ATM_MF_BWD)
192
193
194
195
196
197#define ATM_VS_IDLE 0
198#define ATM_VS_CONNECTED 1
199#define ATM_VS_CLOSING 2
200#define ATM_VS_LISTEN 3
201#define ATM_VS_INUSE 4
202#define ATM_VS_BOUND 5
203
204#define ATM_VS2TXT_MAP \
205 "IDLE", "CONNECTED", "CLOSING", "LISTEN", "INUSE", "BOUND"
206
207#define ATM_VF2TXT_MAP \
208 "ADDR", "READY", "PARTIAL", "REGIS", \
209 "RELEASED", "HASQOS", "LISTEN", "META", \
210 "256", "512", "1024", "2048", \
211 "SESSION", "HASSAP", "BOUND", "CLOSE"
212
213
214#ifdef __KERNEL__
215
216#include <linux/device.h>
217#include <linux/wait.h>
218#include <linux/time.h>
219#include <linux/net.h>
220#include <linux/skbuff.h>
221#include <linux/uio.h>
222#include <net/sock.h>
223#include <linux/atomic.h>
224
225#ifdef CONFIG_PROC_FS
226#include <linux/proc_fs.h>
227
228extern struct proc_dir_entry *atm_proc_root;
229#endif
230
231#ifdef CONFIG_COMPAT
232#include <linux/compat.h>
233struct compat_atm_iobuf {
234 int length;
235 compat_uptr_t buffer;
236};
237#endif
238
239struct k_atm_aal_stats {
240#define __HANDLE_ITEM(i) atomic_t i
241 __AAL_STAT_ITEMS
242#undef __HANDLE_ITEM
243};
244
245
246struct k_atm_dev_stats {
247 struct k_atm_aal_stats aal0;
248 struct k_atm_aal_stats aal34;
249 struct k_atm_aal_stats aal5;
250};
251
252
253enum {
254 ATM_VF_ADDR,
255
256 ATM_VF_READY,
257
258 ATM_VF_PARTIAL,
259
260 ATM_VF_REGIS,
261
262 ATM_VF_BOUND,
263
264 ATM_VF_RELEASED,
265
266 ATM_VF_HASQOS,
267 ATM_VF_LISTEN,
268 ATM_VF_META,
269
270
271 ATM_VF_SESSION,
272 ATM_VF_HASSAP,
273 ATM_VF_CLOSE,
274 ATM_VF_WAITING,
275 ATM_VF_IS_CLIP,
276};
277
278
279#define ATM_VF2VS(flags) \
280 (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
281 test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
282 test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
283 test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
284 test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
285
286
287enum {
288 ATM_DF_REMOVED,
289};
290
291
292#define ATM_PHY_SIG_LOST 0
293#define ATM_PHY_SIG_UNKNOWN 1
294#define ATM_PHY_SIG_FOUND 2
295
296#define ATM_ATMOPT_CLP 1
297
298struct atm_vcc {
299
300 struct sock sk;
301 unsigned long flags;
302 short vpi;
303
304 int vci;
305 unsigned long aal_options;
306 unsigned long atm_options;
307 struct atm_dev *dev;
308 struct atm_qos qos;
309 struct atm_sap sap;
310 void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
311 void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb);
312 int (*push_oam)(struct atm_vcc *vcc,void *cell);
313 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
314 void *dev_data;
315 void *proto_data;
316 struct k_atm_aal_stats *stats;
317
318 short itf;
319 struct sockaddr_atmsvc local;
320 struct sockaddr_atmsvc remote;
321
322 struct atm_vcc *session;
323
324 void *user_back;
325
326
327};
328
329static inline struct atm_vcc *atm_sk(struct sock *sk)
330{
331 return (struct atm_vcc *)sk;
332}
333
334static inline struct atm_vcc *ATM_SD(struct socket *sock)
335{
336 return atm_sk(sock->sk);
337}
338
339static inline struct sock *sk_atm(struct atm_vcc *vcc)
340{
341 return (struct sock *)vcc;
342}
343
344struct atm_dev_addr {
345 struct sockaddr_atmsvc addr;
346 struct list_head entry;
347};
348
349enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
350
351struct atm_dev {
352 const struct atmdev_ops *ops;
353 const struct atmphy_ops *phy;
354
355 const char *type;
356 int number;
357 void *dev_data;
358 void *phy_data;
359 unsigned long flags;
360 struct list_head local;
361 struct list_head lecs;
362 unsigned char esi[ESI_LEN];
363 struct atm_cirange ci_range;
364 struct k_atm_dev_stats stats;
365 char signal;
366 int link_rate;
367 atomic_t refcnt;
368 spinlock_t lock;
369#ifdef CONFIG_PROC_FS
370 struct proc_dir_entry *proc_entry;
371 char *proc_name;
372#endif
373 struct device class_dev;
374 struct list_head dev_list;
375};
376
377
378
379
380#define ATM_OF_IMMED 1
381#define ATM_OF_INRATE 2
382
383
384
385
386
387
388struct atmdev_ops {
389 void (*dev_close)(struct atm_dev *dev);
390 int (*open)(struct atm_vcc *vcc);
391 void (*close)(struct atm_vcc *vcc);
392 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
393#ifdef CONFIG_COMPAT
394 int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
395 void __user *arg);
396#endif
397 int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
398 void __user *optval,int optlen);
399 int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
400 void __user *optval,unsigned int optlen);
401 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
402 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
403 void (*phy_put)(struct atm_dev *dev,unsigned char value,
404 unsigned long addr);
405 unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
406 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
407 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
408 struct module *owner;
409};
410
411struct atmphy_ops {
412 int (*start)(struct atm_dev *dev);
413 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
414 void (*interrupt)(struct atm_dev *dev);
415 int (*stop)(struct atm_dev *dev);
416};
417
418struct atm_skb_data {
419 struct atm_vcc *vcc;
420 unsigned long atm_options;
421};
422
423#define VCC_HTABLE_SIZE 32
424
425extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
426extern rwlock_t vcc_sklist_lock;
427
428#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
429
430struct atm_dev *atm_dev_register(const char *type, struct device *parent,
431 const struct atmdev_ops *ops,
432 int number,
433 unsigned long *flags);
434struct atm_dev *atm_dev_lookup(int number);
435void atm_dev_deregister(struct atm_dev *dev);
436
437
438
439
440
441
442void atm_dev_signal_change(struct atm_dev *dev, char signal);
443
444void vcc_insert_socket(struct sock *sk);
445
446void atm_dev_release_vccs(struct atm_dev *dev);
447
448
449
450
451
452
453static inline int atm_guess_pdu2truesize(int size)
454{
455 return SKB_DATA_ALIGN(size) + sizeof(struct skb_shared_info);
456}
457
458
459static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
460{
461 atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
462}
463
464
465static inline void atm_return(struct atm_vcc *vcc,int truesize)
466{
467 atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
468}
469
470
471static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
472{
473 return (size + atomic_read(&sk_atm(vcc)->sk_wmem_alloc)) <
474 sk_atm(vcc)->sk_sndbuf;
475}
476
477
478static inline void atm_dev_hold(struct atm_dev *dev)
479{
480 atomic_inc(&dev->refcnt);
481}
482
483
484static inline void atm_dev_put(struct atm_dev *dev)
485{
486 if (atomic_dec_and_test(&dev->refcnt)) {
487 BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
488 if (dev->ops->dev_close)
489 dev->ops->dev_close(dev);
490 put_device(&dev->class_dev);
491 }
492}
493
494
495int atm_charge(struct atm_vcc *vcc,int truesize);
496struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
497 gfp_t gfp_flags);
498int atm_pcr_goal(const struct atm_trafprm *tp);
499
500void vcc_release_async(struct atm_vcc *vcc, int reply);
501
502struct atm_ioctl {
503 struct module *owner;
504
505
506 int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
507 struct list_head list;
508};
509
510
511
512
513
514
515
516
517void register_atm_ioctl(struct atm_ioctl *);
518
519
520
521
522void deregister_atm_ioctl(struct atm_ioctl *);
523
524
525
526
527
528
529
530int register_atmdevice_notifier(struct notifier_block *nb);
531void unregister_atmdevice_notifier(struct notifier_block *nb);
532
533#endif
534
535#endif
536