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#define ATM_DROPPARTY _IOW('a', ATMIOC_SPECIAL+5,int)
104
105
106
107
108
109
110
111#define ATM_BACKEND_RAW 0
112#define ATM_BACKEND_PPP 1
113#define ATM_BACKEND_BR2684 2
114
115
116#define ATM_ITFTYP_LEN 8
117
118
119
120
121
122
123#define __ATM_LM_NONE 0
124#define __ATM_LM_AAL 1
125#define __ATM_LM_ATM 2
126
127#define __ATM_LM_PHY 8
128#define __ATM_LM_ANALOG 16
129
130
131#define __ATM_LM_MKLOC(n) ((n))
132#define __ATM_LM_MKRMT(n) ((n) << 8)
133
134#define __ATM_LM_XTLOC(n) ((n) & 0xff)
135#define __ATM_LM_XTRMT(n) (((n) >> 8) & 0xff)
136
137#define ATM_LM_NONE 0
138
139#define ATM_LM_LOC_AAL __ATM_LM_MKLOC(__ATM_LM_AAL)
140#define ATM_LM_LOC_ATM __ATM_LM_MKLOC(__ATM_LM_ATM)
141#define ATM_LM_LOC_PHY __ATM_LM_MKLOC(__ATM_LM_PHY)
142#define ATM_LM_LOC_ANALOG __ATM_LM_MKLOC(__ATM_LM_ANALOG)
143
144#define ATM_LM_RMT_AAL __ATM_LM_MKRMT(__ATM_LM_AAL)
145#define ATM_LM_RMT_ATM __ATM_LM_MKRMT(__ATM_LM_ATM)
146#define ATM_LM_RMT_PHY __ATM_LM_MKRMT(__ATM_LM_PHY)
147#define ATM_LM_RMT_ANALOG __ATM_LM_MKRMT(__ATM_LM_ANALOG)
148
149
150
151
152
153
154
155struct atm_iobuf {
156 int length;
157 void __user *buffer;
158};
159
160
161
162#define ATM_CI_MAX -1
163
164struct atm_cirange {
165 signed char vpi_bits;
166 signed char vci_bits;
167};
168
169
170
171#define ATM_SC_RX 1024
172#define ATM_SC_TX 2048
173
174#define ATM_BACKLOG_DEFAULT 32
175
176
177
178
179#define ATM_MF_IMMED 1
180#define ATM_MF_INC_RSV 2
181#define ATM_MF_INC_SHP 4
182#define ATM_MF_DEC_RSV 8
183#define ATM_MF_DEC_SHP 16
184#define ATM_MF_BWD 32
185
186#define ATM_MF_SET (ATM_MF_INC_RSV | ATM_MF_INC_SHP | ATM_MF_DEC_RSV | \
187 ATM_MF_DEC_SHP | ATM_MF_BWD)
188
189
190
191
192
193#define ATM_VS_IDLE 0
194#define ATM_VS_CONNECTED 1
195#define ATM_VS_CLOSING 2
196#define ATM_VS_LISTEN 3
197#define ATM_VS_INUSE 4
198#define ATM_VS_BOUND 5
199
200#define ATM_VS2TXT_MAP \
201 "IDLE", "CONNECTED", "CLOSING", "LISTEN", "INUSE", "BOUND"
202
203#define ATM_VF2TXT_MAP \
204 "ADDR", "READY", "PARTIAL", "REGIS", \
205 "RELEASED", "HASQOS", "LISTEN", "META", \
206 "256", "512", "1024", "2048", \
207 "SESSION", "HASSAP", "BOUND", "CLOSE"
208
209
210#ifdef __KERNEL__
211
212#include <linux/device.h>
213#include <linux/wait.h>
214#include <linux/time.h>
215#include <linux/net.h>
216#include <linux/skbuff.h>
217#include <linux/uio.h>
218#include <net/sock.h>
219#include <asm/atomic.h>
220
221#ifdef CONFIG_PROC_FS
222#include <linux/proc_fs.h>
223
224extern struct proc_dir_entry *atm_proc_root;
225#endif
226
227
228struct k_atm_aal_stats {
229#define __HANDLE_ITEM(i) atomic_t i
230 __AAL_STAT_ITEMS
231#undef __HANDLE_ITEM
232};
233
234
235struct k_atm_dev_stats {
236 struct k_atm_aal_stats aal0;
237 struct k_atm_aal_stats aal34;
238 struct k_atm_aal_stats aal5;
239};
240
241
242enum {
243 ATM_VF_ADDR,
244
245 ATM_VF_READY,
246
247 ATM_VF_PARTIAL,
248
249 ATM_VF_REGIS,
250
251 ATM_VF_BOUND,
252
253 ATM_VF_RELEASED,
254
255 ATM_VF_HASQOS,
256 ATM_VF_LISTEN,
257 ATM_VF_META,
258
259
260 ATM_VF_SESSION,
261 ATM_VF_HASSAP,
262 ATM_VF_CLOSE,
263 ATM_VF_WAITING,
264 ATM_VF_IS_CLIP,
265};
266
267
268#define ATM_VF2VS(flags) \
269 (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
270 test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
271 test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
272 test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
273 test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
274
275
276enum {
277 ATM_DF_REMOVED,
278};
279
280
281#define ATM_PHY_SIG_LOST 0
282#define ATM_PHY_SIG_UNKNOWN 1
283#define ATM_PHY_SIG_FOUND 2
284
285#define ATM_ATMOPT_CLP 1
286
287struct atm_vcc {
288
289 struct sock sk;
290 unsigned long flags;
291 short vpi;
292
293 int vci;
294 unsigned long aal_options;
295 unsigned long atm_options;
296 struct atm_dev *dev;
297 struct atm_qos qos;
298 struct atm_sap sap;
299 void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
300 void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb);
301 int (*push_oam)(struct atm_vcc *vcc,void *cell);
302 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
303 void *dev_data;
304 void *proto_data;
305 struct k_atm_aal_stats *stats;
306
307 short itf;
308 struct sockaddr_atmsvc local;
309 struct sockaddr_atmsvc remote;
310
311 struct atm_vcc *session;
312
313 void *user_back;
314
315
316};
317
318static inline struct atm_vcc *atm_sk(struct sock *sk)
319{
320 return (struct atm_vcc *)sk;
321}
322
323static inline struct atm_vcc *ATM_SD(struct socket *sock)
324{
325 return atm_sk(sock->sk);
326}
327
328static inline struct sock *sk_atm(struct atm_vcc *vcc)
329{
330 return (struct sock *)vcc;
331}
332
333struct atm_dev_addr {
334 struct sockaddr_atmsvc addr;
335 struct list_head entry;
336};
337
338enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
339
340struct atm_dev {
341 const struct atmdev_ops *ops;
342 const struct atmphy_ops *phy;
343
344 const char *type;
345 int number;
346 void *dev_data;
347 void *phy_data;
348 unsigned long flags;
349 struct list_head local;
350 struct list_head lecs;
351 unsigned char esi[ESI_LEN];
352 struct atm_cirange ci_range;
353 struct k_atm_dev_stats stats;
354 char signal;
355 int link_rate;
356 atomic_t refcnt;
357 spinlock_t lock;
358#ifdef CONFIG_PROC_FS
359 struct proc_dir_entry *proc_entry;
360 char *proc_name;
361#endif
362 struct device class_dev;
363 struct list_head dev_list;
364};
365
366
367
368
369#define ATM_OF_IMMED 1
370#define ATM_OF_INRATE 2
371
372
373
374
375
376
377struct atmdev_ops {
378 void (*dev_close)(struct atm_dev *dev);
379 int (*open)(struct atm_vcc *vcc);
380 void (*close)(struct atm_vcc *vcc);
381 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
382 int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
383 void __user *optval,int optlen);
384 int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
385 void __user *optval,int optlen);
386 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
387 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
388 void (*phy_put)(struct atm_dev *dev,unsigned char value,
389 unsigned long addr);
390 unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
391 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
392 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
393 struct module *owner;
394};
395
396struct atmphy_ops {
397 int (*start)(struct atm_dev *dev);
398 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
399 void (*interrupt)(struct atm_dev *dev);
400 int (*stop)(struct atm_dev *dev);
401};
402
403struct atm_skb_data {
404 struct atm_vcc *vcc;
405 unsigned long atm_options;
406};
407
408#define VCC_HTABLE_SIZE 32
409
410extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
411extern rwlock_t vcc_sklist_lock;
412
413#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
414
415struct atm_dev *atm_dev_register(const char *type,const struct atmdev_ops *ops,
416 int number,unsigned long *flags);
417struct atm_dev *atm_dev_lookup(int number);
418void atm_dev_deregister(struct atm_dev *dev);
419void vcc_insert_socket(struct sock *sk);
420
421
422
423
424
425
426
427static inline int atm_guess_pdu2truesize(int size)
428{
429 return (SKB_DATA_ALIGN(size) + sizeof(struct skb_shared_info));
430}
431
432
433static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
434{
435 atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
436}
437
438
439static inline void atm_return(struct atm_vcc *vcc,int truesize)
440{
441 atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
442}
443
444
445static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
446{
447 return (size + atomic_read(&sk_atm(vcc)->sk_wmem_alloc)) <
448 sk_atm(vcc)->sk_sndbuf;
449}
450
451
452static inline void atm_dev_hold(struct atm_dev *dev)
453{
454 atomic_inc(&dev->refcnt);
455}
456
457
458static inline void atm_dev_put(struct atm_dev *dev)
459{
460 if (atomic_dec_and_test(&dev->refcnt)) {
461 BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
462 if (dev->ops->dev_close)
463 dev->ops->dev_close(dev);
464 put_device(&dev->class_dev);
465 }
466}
467
468
469int atm_charge(struct atm_vcc *vcc,int truesize);
470struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
471 gfp_t gfp_flags);
472int atm_pcr_goal(const struct atm_trafprm *tp);
473
474void vcc_release_async(struct atm_vcc *vcc, int reply);
475
476struct atm_ioctl {
477 struct module *owner;
478
479
480 int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
481 struct list_head list;
482};
483
484
485
486
487
488
489
490
491void register_atm_ioctl(struct atm_ioctl *);
492
493
494
495
496void deregister_atm_ioctl(struct atm_ioctl *);
497
498#endif
499
500#endif
501