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