blob: 1eb238affb124fe8d657cda89f55b2a627142eb8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* atmdev.h - ATM device driver declarations and various related items */
2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4
5
6#ifndef LINUX_ATMDEV_H
7#define LINUX_ATMDEV_H
8
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#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 /* OC3 link rate: 155520000 bps
19 SONET overhead: /270*260 (9 section, 1 path)
20 bits per cell: /8/53
21 max cell rate: 353207.547 cells/sec */
22#define ATM_25_PCR ((25600000/8-8000)/54)
23 /* 25 Mbps ATM cell rate (59111) */
24#define ATM_OC12_PCR (622080000/1080*1040/8/53)
25 /* OC12 link rate: 622080000 bps
26 SONET overhead: /1080*1040
27 bits per cell: /8/53
28 max cell rate: 1412830.188 cells/sec */
29#define ATM_DS3_PCR (8000*12)
30 /* DS3: 12 cells in a 125 usec time slot */
31
32
33#define __AAL_STAT_ITEMS \
34 __HANDLE_ITEM(tx); /* TX okay */ \
35 __HANDLE_ITEM(tx_err); /* TX errors */ \
36 __HANDLE_ITEM(rx); /* RX okay */ \
37 __HANDLE_ITEM(rx_err); /* RX errors */ \
38 __HANDLE_ITEM(rx_drop); /* RX out of memory */
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 /* get link rate */
56#define ATM_GETNAMES _IOW('a',ATMIOC_ITF+3,struct atm_iobuf)
57 /* get interface names (numbers) */
58#define ATM_GETTYPE _IOW('a',ATMIOC_ITF+4,struct atmif_sioc)
59 /* get interface type name */
60#define ATM_GETESI _IOW('a',ATMIOC_ITF+5,struct atmif_sioc)
61 /* get interface ESI */
62#define ATM_GETADDR _IOW('a',ATMIOC_ITF+6,struct atmif_sioc)
63 /* get itf's local ATM addr. list */
64#define ATM_RSTADDR _IOW('a',ATMIOC_ITF+7,struct atmif_sioc)
65 /* reset itf's ATM address list */
66#define ATM_ADDADDR _IOW('a',ATMIOC_ITF+8,struct atmif_sioc)
67 /* add a local ATM address */
68#define ATM_DELADDR _IOW('a',ATMIOC_ITF+9,struct atmif_sioc)
69 /* remove a local ATM address */
70#define ATM_GETCIRANGE _IOW('a',ATMIOC_ITF+10,struct atmif_sioc)
71 /* get connection identifier range */
72#define ATM_SETCIRANGE _IOW('a',ATMIOC_ITF+11,struct atmif_sioc)
73 /* set connection identifier range */
74#define ATM_SETESI _IOW('a',ATMIOC_ITF+12,struct atmif_sioc)
75 /* set interface ESI */
76#define ATM_SETESIF _IOW('a',ATMIOC_ITF+13,struct atmif_sioc)
77 /* force interface ESI */
Eric Kinzie0f21ba72005-10-06 22:19:28 -070078#define ATM_ADDLECSADDR _IOW('a', ATMIOC_ITF+14, struct atmif_sioc)
79 /* register a LECS address */
80#define ATM_DELLECSADDR _IOW('a', ATMIOC_ITF+15, struct atmif_sioc)
81 /* unregister a LECS address */
82#define ATM_GETLECSADDR _IOW('a', ATMIOC_ITF+16, struct atmif_sioc)
83 /* retrieve LECS address(es) */
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define ATM_GETSTAT _IOW('a',ATMIOC_SARCOM+0,struct atmif_sioc)
86 /* get AAL layer statistics */
87#define ATM_GETSTATZ _IOW('a',ATMIOC_SARCOM+1,struct atmif_sioc)
88 /* get AAL layer statistics and zero */
89#define ATM_GETLOOP _IOW('a',ATMIOC_SARCOM+2,struct atmif_sioc)
90 /* get loopback mode */
91#define ATM_SETLOOP _IOW('a',ATMIOC_SARCOM+3,struct atmif_sioc)
92 /* set loopback mode */
93#define ATM_QUERYLOOP _IOW('a',ATMIOC_SARCOM+4,struct atmif_sioc)
94 /* query supported loopback modes */
95#define ATM_SETSC _IOW('a',ATMIOC_SPECIAL+1,int)
96 /* enable or disable single-copy */
97#define ATM_SETBACKEND _IOW('a',ATMIOC_SPECIAL+2,atm_backend_t)
98 /* set backend handler */
99#define ATM_NEWBACKENDIF _IOW('a',ATMIOC_SPECIAL+3,atm_backend_t)
100 /* use backend to make new if */
101#define ATM_ADDPARTY _IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
102 /* add party to p2mp call */
103#define ATM_DROPPARTY _IOW('a', ATMIOC_SPECIAL+5,int)
104 /* drop party from p2mp call */
105
106/*
107 * These are backend handkers that can be set via the ATM_SETBACKEND call
108 * above. In the future we may support dynamic loading of these - for now,
109 * they're just being used to share the ATMIOC_BACKEND ioctls
110 */
111#define ATM_BACKEND_RAW 0
112#define ATM_BACKEND_PPP 1 /* PPPoATM - RFC2364 */
113#define ATM_BACKEND_BR2684 2 /* Bridged RFC1483/2684 */
114
115/* for ATM_GETTYPE */
116#define ATM_ITFTYP_LEN 8 /* maximum length of interface type name */
117
118/*
119 * Loopback modes for ATM_{PHY,SAR}_{GET,SET}LOOP
120 */
121
122/* Point of loopback CPU-->SAR-->PHY-->line--> ... */
123#define __ATM_LM_NONE 0 /* no loop back ^ ^ ^ ^ */
124#define __ATM_LM_AAL 1 /* loop back PDUs --' | | | */
125#define __ATM_LM_ATM 2 /* loop back ATM cells ---' | | */
126/* RESERVED 4 loop back on PHY side ---' */
127#define __ATM_LM_PHY 8 /* loop back bits (digital) ----' | */
128#define __ATM_LM_ANALOG 16 /* loop back the analog signal --------' */
129
130/* Direction of loopback */
131#define __ATM_LM_MKLOC(n) ((n)) /* Local (i.e. loop TX to RX) */
132#define __ATM_LM_MKRMT(n) ((n) << 8) /* Remote (i.e. loop RX to TX) */
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 /* no loopback */
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 * Note: ATM_LM_LOC_* and ATM_LM_RMT_* can be combined, provided that
151 * __ATM_LM_XTLOC(x) <= __ATM_LM_XTRMT(x)
152 */
153
154
155struct atm_iobuf {
156 int length;
157 void __user *buffer;
158};
159
160/* for ATM_GETCIRANGE / ATM_SETCIRANGE */
161
162#define ATM_CI_MAX -1 /* use maximum range of VPI/VCI */
163
164struct atm_cirange {
165 signed char vpi_bits; /* 1..8, ATM_CI_MAX (-1) for maximum */
166 signed char vci_bits; /* 1..16, ATM_CI_MAX (-1) for maximum */
167};
168
169/* for ATM_SETSC; actually taken from the ATM_VF number space */
170
171#define ATM_SC_RX 1024 /* enable RX single-copy */
172#define ATM_SC_TX 2048 /* enable TX single-copy */
173
174#define ATM_BACKLOG_DEFAULT 32 /* if we get more, we're likely to time out
175 anyway */
176
177/* MF: change_qos (Modify) flags */
178
179#define ATM_MF_IMMED 1 /* Block until change is effective */
180#define ATM_MF_INC_RSV 2 /* Change reservation on increase */
181#define ATM_MF_INC_SHP 4 /* Change shaping on increase */
182#define ATM_MF_DEC_RSV 8 /* Change reservation on decrease */
183#define ATM_MF_DEC_SHP 16 /* Change shaping on decrease */
184#define ATM_MF_BWD 32 /* Set the backward direction parameters */
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 * ATM_VS_* are used to express VC state in a human-friendly way.
191 */
192
193#define ATM_VS_IDLE 0 /* VC is not used */
194#define ATM_VS_CONNECTED 1 /* VC is connected */
195#define ATM_VS_CLOSING 2 /* VC is closing */
196#define ATM_VS_LISTEN 3 /* VC is listening for incoming setups */
197#define ATM_VS_INUSE 4 /* VC is in use (registered with atmsigd) */
198#define ATM_VS_BOUND 5 /* VC is bound */
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/wait.h> /* wait_queue_head_t */
213#include <linux/time.h> /* struct timeval */
214#include <linux/net.h>
215#include <linux/skbuff.h> /* struct sk_buff */
216#include <linux/uio.h>
217#include <net/sock.h>
218#include <asm/atomic.h>
219
220#ifdef CONFIG_PROC_FS
221#include <linux/proc_fs.h>
222
223extern struct proc_dir_entry *atm_proc_root;
224#endif
225
226
227struct k_atm_aal_stats {
228#define __HANDLE_ITEM(i) atomic_t i
229 __AAL_STAT_ITEMS
230#undef __HANDLE_ITEM
231};
232
233
234struct k_atm_dev_stats {
235 struct k_atm_aal_stats aal0;
236 struct k_atm_aal_stats aal34;
237 struct k_atm_aal_stats aal5;
238};
239
240
241enum {
242 ATM_VF_ADDR, /* Address is in use. Set by anybody, cleared
243 by device driver. */
244 ATM_VF_READY, /* VC is ready to transfer data. Set by device
245 driver, cleared by anybody. */
246 ATM_VF_PARTIAL, /* resources are bound to PVC (partial PVC
247 setup), controlled by socket layer */
248 ATM_VF_REGIS, /* registered with demon, controlled by SVC
249 socket layer */
250 ATM_VF_BOUND, /* local SAP is set, controlled by SVC socket
251 layer */
252 ATM_VF_RELEASED, /* demon has indicated/requested release,
253 controlled by SVC socket layer */
254 ATM_VF_HASQOS, /* QOS parameters have been set */
255 ATM_VF_LISTEN, /* socket is used for listening */
256 ATM_VF_META, /* SVC socket isn't used for normal data
257 traffic and doesn't depend on signaling
258 to be available */
259 ATM_VF_SESSION, /* VCC is p2mp session control descriptor */
260 ATM_VF_HASSAP, /* SAP has been set */
261 ATM_VF_CLOSE, /* asynchronous close - treat like VF_RELEASED*/
262 ATM_VF_WAITING, /* waiting for reply from sigd */
263 ATM_VF_IS_CLIP, /* in use by CLIP protocol */
264};
265
266
267#define ATM_VF2VS(flags) \
268 (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
269 test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
270 test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
271 test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
272 test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
273
274
275enum {
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800276 ATM_DF_REMOVED, /* device was removed from atm_devs list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277};
278
279
280#define ATM_PHY_SIG_LOST 0 /* no carrier/light */
281#define ATM_PHY_SIG_UNKNOWN 1 /* carrier/light status is unknown */
282#define ATM_PHY_SIG_FOUND 2 /* carrier/light okay */
283
284#define ATM_ATMOPT_CLP 1 /* set CLP bit */
285
286struct atm_vcc {
287 /* struct sock has to be the first member of atm_vcc */
288 struct sock sk;
289 unsigned long flags; /* VCC flags (ATM_VF_*) */
290 short vpi; /* VPI and VCI (types must be equal */
291 /* with sockaddr) */
292 int vci;
293 unsigned long aal_options; /* AAL layer options */
294 unsigned long atm_options; /* ATM layer options */
295 struct atm_dev *dev; /* device back pointer */
296 struct atm_qos qos; /* QOS */
297 struct atm_sap sap; /* SAP */
298 void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
299 void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
300 int (*push_oam)(struct atm_vcc *vcc,void *cell);
301 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
302 void *dev_data; /* per-device data */
303 void *proto_data; /* per-protocol data */
304 struct k_atm_aal_stats *stats; /* pointer to AAL stats group */
305 /* SVC part --- may move later ------------------------------------- */
306 short itf; /* interface number */
307 struct sockaddr_atmsvc local;
308 struct sockaddr_atmsvc remote;
309 /* Multipoint part ------------------------------------------------- */
310 struct atm_vcc *session; /* session VCC descriptor */
311 /* Other stuff ----------------------------------------------------- */
312 void *user_back; /* user backlink - not touched by */
313 /* native ATM stack. Currently used */
314 /* by CLIP and sch_atm. */
315};
316
317static inline struct atm_vcc *atm_sk(struct sock *sk)
318{
319 return (struct atm_vcc *)sk;
320}
321
322static inline struct atm_vcc *ATM_SD(struct socket *sock)
323{
324 return atm_sk(sock->sk);
325}
326
327static inline struct sock *sk_atm(struct atm_vcc *vcc)
328{
329 return (struct sock *)vcc;
330}
331
332struct atm_dev_addr {
333 struct sockaddr_atmsvc addr; /* ATM address */
334 struct list_head entry; /* next address */
335};
336
Eric Kinzie0f21ba72005-10-06 22:19:28 -0700337enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339struct atm_dev {
340 const struct atmdev_ops *ops; /* device operations; NULL if unused */
341 const struct atmphy_ops *phy; /* PHY operations, may be undefined */
342 /* (NULL) */
343 const char *type; /* device type name */
344 int number; /* device index */
345 void *dev_data; /* per-device data */
346 void *phy_data; /* private PHY date */
347 unsigned long flags; /* device flags (ATM_DF_*) */
348 struct list_head local; /* local ATM addresses */
Eric Kinzie0f21ba72005-10-06 22:19:28 -0700349 struct list_head lecs; /* LECS ATM addresses learned via ILMI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
351 struct atm_cirange ci_range; /* VPI/VCI range */
352 struct k_atm_dev_stats stats; /* statistics */
353 char signal; /* signal status (ATM_PHY_SIG_*) */
354 int link_rate; /* link rate (default: OC3) */
355 atomic_t refcnt; /* reference count */
356 spinlock_t lock; /* protect internal members */
357#ifdef CONFIG_PROC_FS
358 struct proc_dir_entry *proc_entry; /* proc entry */
359 char *proc_name; /* proc entry name */
360#endif
361 struct list_head dev_list; /* linkage */
362};
363
364
365/* OF: send_Oam Flags */
366
367#define ATM_OF_IMMED 1 /* Attempt immediate delivery */
368#define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
369
370
371/*
372 * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
373 */
374
375struct atmdev_ops { /* only send is required */
376 void (*dev_close)(struct atm_dev *dev);
377 int (*open)(struct atm_vcc *vcc);
378 void (*close)(struct atm_vcc *vcc);
379 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
380 int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
381 void __user *optval,int optlen);
382 int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
383 void __user *optval,int optlen);
384 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
385 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
386 void (*phy_put)(struct atm_dev *dev,unsigned char value,
387 unsigned long addr);
388 unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
389 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
390 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
391 struct module *owner;
392};
393
394struct atmphy_ops {
395 int (*start)(struct atm_dev *dev);
396 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
397 void (*interrupt)(struct atm_dev *dev);
398 int (*stop)(struct atm_dev *dev);
399};
400
401struct atm_skb_data {
402 struct atm_vcc *vcc; /* ATM VCC */
403 unsigned long atm_options; /* ATM layer options */
404};
405
406#define VCC_HTABLE_SIZE 32
407
408extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
409extern rwlock_t vcc_sklist_lock;
410
411#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
412
413struct atm_dev *atm_dev_register(const char *type,const struct atmdev_ops *ops,
414 int number,unsigned long *flags); /* number == -1: pick first available */
415struct atm_dev *atm_dev_lookup(int number);
416void atm_dev_deregister(struct atm_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417void vcc_insert_socket(struct sock *sk);
418
419
420/*
421 * This is approximately the algorithm used by alloc_skb.
422 *
423 */
424
425static inline int atm_guess_pdu2truesize(int size)
426{
427 return (SKB_DATA_ALIGN(size) + sizeof(struct skb_shared_info));
428}
429
430
431static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
432{
433 atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
434}
435
436
437static inline void atm_return(struct atm_vcc *vcc,int truesize)
438{
439 atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
440}
441
442
443static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
444{
445 return (size + atomic_read(&sk_atm(vcc)->sk_wmem_alloc)) <
446 sk_atm(vcc)->sk_sndbuf;
447}
448
449
450static inline void atm_dev_hold(struct atm_dev *dev)
451{
452 atomic_inc(&dev->refcnt);
453}
454
455
456static inline void atm_dev_put(struct atm_dev *dev)
457{
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800458 if (atomic_dec_and_test(&dev->refcnt)) {
459 BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
460 if (dev->ops->dev_close)
461 dev->ops->dev_close(dev);
462 kfree(dev);
463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
465
466
467int atm_charge(struct atm_vcc *vcc,int truesize);
468struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
Al Virodd0fc662005-10-07 07:46:04 +0100469 gfp_t gfp_flags);
Mitchell Blank Jrc2197502005-11-29 16:13:55 -0800470int atm_pcr_goal(const struct atm_trafprm *tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
472void vcc_release_async(struct atm_vcc *vcc, int reply);
473
474struct atm_ioctl {
475 struct module *owner;
476 /* A module reference is kept if appropriate over this call.
477 * Return -ENOIOCTLCMD if you don't handle it. */
478 int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
479 struct list_head list;
480};
481
482/**
483 * register_atm_ioctl - register handler for ioctl operations
484 *
485 * Special (non-device) handlers of ioctl's should
486 * register here. If you're a normal device, you should
487 * set .ioctl in your atmdev_ops instead.
488 */
489void register_atm_ioctl(struct atm_ioctl *);
490
491/**
492 * deregister_atm_ioctl - remove the ioctl handler
493 */
494void deregister_atm_ioctl(struct atm_ioctl *);
495
496#endif /* __KERNEL__ */
497
498#endif