blob: aca9b344bd356d5fa62cda22811d902957bb7edb [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
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 /* OC3 link rate: 155520000 bps
20 SONET overhead: /270*260 (9 section, 1 path)
21 bits per cell: /8/53
22 max cell rate: 353207.547 cells/sec */
23#define ATM_25_PCR ((25600000/8-8000)/54)
24 /* 25 Mbps ATM cell rate (59111) */
25#define ATM_OC12_PCR (622080000/1080*1040/8/53)
26 /* OC12 link rate: 622080000 bps
27 SONET overhead: /1080*1040
28 bits per cell: /8/53
29 max cell rate: 1412830.188 cells/sec */
30#define ATM_DS3_PCR (8000*12)
31 /* DS3: 12 cells in a 125 usec time slot */
32
33
34#define __AAL_STAT_ITEMS \
35 __HANDLE_ITEM(tx); /* TX okay */ \
36 __HANDLE_ITEM(tx_err); /* TX errors */ \
37 __HANDLE_ITEM(rx); /* RX okay */ \
38 __HANDLE_ITEM(rx_err); /* RX errors */ \
39 __HANDLE_ITEM(rx_drop); /* RX out of memory */
40
41struct atm_aal_stats {
42#define __HANDLE_ITEM(i) int i
43 __AAL_STAT_ITEMS
44#undef __HANDLE_ITEM
45};
46
47
48struct atm_dev_stats {
49 struct atm_aal_stats aal0;
50 struct atm_aal_stats aal34;
51 struct atm_aal_stats aal5;
52} __ATM_API_ALIGN;
53
54
55#define ATM_GETLINKRATE _IOW('a',ATMIOC_ITF+1,struct atmif_sioc)
56 /* get link rate */
57#define ATM_GETNAMES _IOW('a',ATMIOC_ITF+3,struct atm_iobuf)
58 /* get interface names (numbers) */
59#define ATM_GETTYPE _IOW('a',ATMIOC_ITF+4,struct atmif_sioc)
60 /* get interface type name */
61#define ATM_GETESI _IOW('a',ATMIOC_ITF+5,struct atmif_sioc)
62 /* get interface ESI */
63#define ATM_GETADDR _IOW('a',ATMIOC_ITF+6,struct atmif_sioc)
64 /* get itf's local ATM addr. list */
65#define ATM_RSTADDR _IOW('a',ATMIOC_ITF+7,struct atmif_sioc)
66 /* reset itf's ATM address list */
67#define ATM_ADDADDR _IOW('a',ATMIOC_ITF+8,struct atmif_sioc)
68 /* add a local ATM address */
69#define ATM_DELADDR _IOW('a',ATMIOC_ITF+9,struct atmif_sioc)
70 /* remove a local ATM address */
71#define ATM_GETCIRANGE _IOW('a',ATMIOC_ITF+10,struct atmif_sioc)
72 /* get connection identifier range */
73#define ATM_SETCIRANGE _IOW('a',ATMIOC_ITF+11,struct atmif_sioc)
74 /* set connection identifier range */
75#define ATM_SETESI _IOW('a',ATMIOC_ITF+12,struct atmif_sioc)
76 /* set interface ESI */
77#define ATM_SETESIF _IOW('a',ATMIOC_ITF+13,struct atmif_sioc)
78 /* force interface ESI */
Eric Kinzie0f21ba72005-10-06 22:19:28 -070079#define ATM_ADDLECSADDR _IOW('a', ATMIOC_ITF+14, struct atmif_sioc)
80 /* register a LECS address */
81#define ATM_DELLECSADDR _IOW('a', ATMIOC_ITF+15, struct atmif_sioc)
82 /* unregister a LECS address */
83#define ATM_GETLECSADDR _IOW('a', ATMIOC_ITF+16, struct atmif_sioc)
84 /* retrieve LECS address(es) */
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define ATM_GETSTAT _IOW('a',ATMIOC_SARCOM+0,struct atmif_sioc)
87 /* get AAL layer statistics */
88#define ATM_GETSTATZ _IOW('a',ATMIOC_SARCOM+1,struct atmif_sioc)
89 /* get AAL layer statistics and zero */
90#define ATM_GETLOOP _IOW('a',ATMIOC_SARCOM+2,struct atmif_sioc)
91 /* get loopback mode */
92#define ATM_SETLOOP _IOW('a',ATMIOC_SARCOM+3,struct atmif_sioc)
93 /* set loopback mode */
94#define ATM_QUERYLOOP _IOW('a',ATMIOC_SARCOM+4,struct atmif_sioc)
95 /* query supported loopback modes */
96#define ATM_SETSC _IOW('a',ATMIOC_SPECIAL+1,int)
97 /* enable or disable single-copy */
98#define ATM_SETBACKEND _IOW('a',ATMIOC_SPECIAL+2,atm_backend_t)
99 /* set backend handler */
100#define ATM_NEWBACKENDIF _IOW('a',ATMIOC_SPECIAL+3,atm_backend_t)
101 /* use backend to make new if */
102#define ATM_ADDPARTY _IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
103 /* add party to p2mp call */
104#define ATM_DROPPARTY _IOW('a', ATMIOC_SPECIAL+5,int)
105 /* drop party from p2mp call */
106
107/*
108 * These are backend handkers that can be set via the ATM_SETBACKEND call
109 * above. In the future we may support dynamic loading of these - for now,
110 * they're just being used to share the ATMIOC_BACKEND ioctls
111 */
112#define ATM_BACKEND_RAW 0
113#define ATM_BACKEND_PPP 1 /* PPPoATM - RFC2364 */
114#define ATM_BACKEND_BR2684 2 /* Bridged RFC1483/2684 */
115
116/* for ATM_GETTYPE */
117#define ATM_ITFTYP_LEN 8 /* maximum length of interface type name */
118
119/*
120 * Loopback modes for ATM_{PHY,SAR}_{GET,SET}LOOP
121 */
122
123/* Point of loopback CPU-->SAR-->PHY-->line--> ... */
124#define __ATM_LM_NONE 0 /* no loop back ^ ^ ^ ^ */
125#define __ATM_LM_AAL 1 /* loop back PDUs --' | | | */
126#define __ATM_LM_ATM 2 /* loop back ATM cells ---' | | */
127/* RESERVED 4 loop back on PHY side ---' */
128#define __ATM_LM_PHY 8 /* loop back bits (digital) ----' | */
129#define __ATM_LM_ANALOG 16 /* loop back the analog signal --------' */
130
131/* Direction of loopback */
132#define __ATM_LM_MKLOC(n) ((n)) /* Local (i.e. loop TX to RX) */
133#define __ATM_LM_MKRMT(n) ((n) << 8) /* Remote (i.e. loop RX to TX) */
134
135#define __ATM_LM_XTLOC(n) ((n) & 0xff)
136#define __ATM_LM_XTRMT(n) (((n) >> 8) & 0xff)
137
138#define ATM_LM_NONE 0 /* no loopback */
139
140#define ATM_LM_LOC_AAL __ATM_LM_MKLOC(__ATM_LM_AAL)
141#define ATM_LM_LOC_ATM __ATM_LM_MKLOC(__ATM_LM_ATM)
142#define ATM_LM_LOC_PHY __ATM_LM_MKLOC(__ATM_LM_PHY)
143#define ATM_LM_LOC_ANALOG __ATM_LM_MKLOC(__ATM_LM_ANALOG)
144
145#define ATM_LM_RMT_AAL __ATM_LM_MKRMT(__ATM_LM_AAL)
146#define ATM_LM_RMT_ATM __ATM_LM_MKRMT(__ATM_LM_ATM)
147#define ATM_LM_RMT_PHY __ATM_LM_MKRMT(__ATM_LM_PHY)
148#define ATM_LM_RMT_ANALOG __ATM_LM_MKRMT(__ATM_LM_ANALOG)
149
150/*
151 * Note: ATM_LM_LOC_* and ATM_LM_RMT_* can be combined, provided that
152 * __ATM_LM_XTLOC(x) <= __ATM_LM_XTRMT(x)
153 */
154
155
156struct atm_iobuf {
157 int length;
158 void __user *buffer;
159};
160
161/* for ATM_GETCIRANGE / ATM_SETCIRANGE */
162
163#define ATM_CI_MAX -1 /* use maximum range of VPI/VCI */
164
165struct atm_cirange {
166 signed char vpi_bits; /* 1..8, ATM_CI_MAX (-1) for maximum */
167 signed char vci_bits; /* 1..16, ATM_CI_MAX (-1) for maximum */
168};
169
170/* for ATM_SETSC; actually taken from the ATM_VF number space */
171
172#define ATM_SC_RX 1024 /* enable RX single-copy */
173#define ATM_SC_TX 2048 /* enable TX single-copy */
174
175#define ATM_BACKLOG_DEFAULT 32 /* if we get more, we're likely to time out
176 anyway */
177
178/* MF: change_qos (Modify) flags */
179
180#define ATM_MF_IMMED 1 /* Block until change is effective */
181#define ATM_MF_INC_RSV 2 /* Change reservation on increase */
182#define ATM_MF_INC_SHP 4 /* Change shaping on increase */
183#define ATM_MF_DEC_RSV 8 /* Change reservation on decrease */
184#define ATM_MF_DEC_SHP 16 /* Change shaping on decrease */
185#define ATM_MF_BWD 32 /* Set the backward direction parameters */
186
187#define ATM_MF_SET (ATM_MF_INC_RSV | ATM_MF_INC_SHP | ATM_MF_DEC_RSV | \
188 ATM_MF_DEC_SHP | ATM_MF_BWD)
189
190/*
191 * ATM_VS_* are used to express VC state in a human-friendly way.
192 */
193
194#define ATM_VS_IDLE 0 /* VC is not used */
195#define ATM_VS_CONNECTED 1 /* VC is connected */
196#define ATM_VS_CLOSING 2 /* VC is closing */
197#define ATM_VS_LISTEN 3 /* VC is listening for incoming setups */
198#define ATM_VS_INUSE 4 /* VC is in use (registered with atmsigd) */
199#define ATM_VS_BOUND 5 /* VC is bound */
200
201#define ATM_VS2TXT_MAP \
202 "IDLE", "CONNECTED", "CLOSING", "LISTEN", "INUSE", "BOUND"
203
204#define ATM_VF2TXT_MAP \
205 "ADDR", "READY", "PARTIAL", "REGIS", \
206 "RELEASED", "HASQOS", "LISTEN", "META", \
207 "256", "512", "1024", "2048", \
208 "SESSION", "HASSAP", "BOUND", "CLOSE"
209
210
211#ifdef __KERNEL__
212
213#include <linux/wait.h> /* wait_queue_head_t */
214#include <linux/time.h> /* struct timeval */
215#include <linux/net.h>
216#include <linux/skbuff.h> /* struct sk_buff */
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, /* Address is in use. Set by anybody, cleared
244 by device driver. */
245 ATM_VF_READY, /* VC is ready to transfer data. Set by device
246 driver, cleared by anybody. */
247 ATM_VF_PARTIAL, /* resources are bound to PVC (partial PVC
248 setup), controlled by socket layer */
249 ATM_VF_REGIS, /* registered with demon, controlled by SVC
250 socket layer */
251 ATM_VF_BOUND, /* local SAP is set, controlled by SVC socket
252 layer */
253 ATM_VF_RELEASED, /* demon has indicated/requested release,
254 controlled by SVC socket layer */
255 ATM_VF_HASQOS, /* QOS parameters have been set */
256 ATM_VF_LISTEN, /* socket is used for listening */
257 ATM_VF_META, /* SVC socket isn't used for normal data
258 traffic and doesn't depend on signaling
259 to be available */
260 ATM_VF_SESSION, /* VCC is p2mp session control descriptor */
261 ATM_VF_HASSAP, /* SAP has been set */
262 ATM_VF_CLOSE, /* asynchronous close - treat like VF_RELEASED*/
263 ATM_VF_WAITING, /* waiting for reply from sigd */
264 ATM_VF_IS_CLIP, /* in use by CLIP protocol */
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_CLOSE, /* close device when last VCC is closed */
278};
279
280
281#define ATM_PHY_SIG_LOST 0 /* no carrier/light */
282#define ATM_PHY_SIG_UNKNOWN 1 /* carrier/light status is unknown */
283#define ATM_PHY_SIG_FOUND 2 /* carrier/light okay */
284
285#define ATM_ATMOPT_CLP 1 /* set CLP bit */
286
287struct atm_vcc {
288 /* struct sock has to be the first member of atm_vcc */
289 struct sock sk;
290 unsigned long flags; /* VCC flags (ATM_VF_*) */
291 short vpi; /* VPI and VCI (types must be equal */
292 /* with sockaddr) */
293 int vci;
294 unsigned long aal_options; /* AAL layer options */
295 unsigned long atm_options; /* ATM layer options */
296 struct atm_dev *dev; /* device back pointer */
297 struct atm_qos qos; /* QOS */
298 struct atm_sap sap; /* SAP */
299 void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
300 void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
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; /* per-device data */
304 void *proto_data; /* per-protocol data */
305 struct k_atm_aal_stats *stats; /* pointer to AAL stats group */
306 /* SVC part --- may move later ------------------------------------- */
307 short itf; /* interface number */
308 struct sockaddr_atmsvc local;
309 struct sockaddr_atmsvc remote;
310 /* Multipoint part ------------------------------------------------- */
311 struct atm_vcc *session; /* session VCC descriptor */
312 /* Other stuff ----------------------------------------------------- */
313 void *user_back; /* user backlink - not touched by */
314 /* native ATM stack. Currently used */
315 /* by CLIP and sch_atm. */
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; /* ATM address */
335 struct list_head entry; /* next address */
336};
337
Eric Kinzie0f21ba72005-10-06 22:19:28 -0700338enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340struct atm_dev {
341 const struct atmdev_ops *ops; /* device operations; NULL if unused */
342 const struct atmphy_ops *phy; /* PHY operations, may be undefined */
343 /* (NULL) */
344 const char *type; /* device type name */
345 int number; /* device index */
346 void *dev_data; /* per-device data */
347 void *phy_data; /* private PHY date */
348 unsigned long flags; /* device flags (ATM_DF_*) */
349 struct list_head local; /* local ATM addresses */
Eric Kinzie0f21ba72005-10-06 22:19:28 -0700350 struct list_head lecs; /* LECS ATM addresses learned via ILMI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
352 struct atm_cirange ci_range; /* VPI/VCI range */
353 struct k_atm_dev_stats stats; /* statistics */
354 char signal; /* signal status (ATM_PHY_SIG_*) */
355 int link_rate; /* link rate (default: OC3) */
356 atomic_t refcnt; /* reference count */
357 spinlock_t lock; /* protect internal members */
358#ifdef CONFIG_PROC_FS
359 struct proc_dir_entry *proc_entry; /* proc entry */
360 char *proc_name; /* proc entry name */
361#endif
362 struct list_head dev_list; /* linkage */
363};
364
365
366/* OF: send_Oam Flags */
367
368#define ATM_OF_IMMED 1 /* Attempt immediate delivery */
369#define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
370
371
372/*
373 * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
374 */
375
376struct atmdev_ops { /* only send is required */
377 void (*dev_close)(struct atm_dev *dev);
378 int (*open)(struct atm_vcc *vcc);
379 void (*close)(struct atm_vcc *vcc);
380 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
381 int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
382 void __user *optval,int optlen);
383 int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
384 void __user *optval,int optlen);
385 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
386 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
387 void (*phy_put)(struct atm_dev *dev,unsigned char value,
388 unsigned long addr);
389 unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
390 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
391 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
392 struct module *owner;
393};
394
395struct atmphy_ops {
396 int (*start)(struct atm_dev *dev);
397 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
398 void (*interrupt)(struct atm_dev *dev);
399 int (*stop)(struct atm_dev *dev);
400};
401
402struct atm_skb_data {
403 struct atm_vcc *vcc; /* ATM VCC */
404 unsigned long atm_options; /* ATM layer options */
405};
406
407#define VCC_HTABLE_SIZE 32
408
409extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
410extern rwlock_t vcc_sklist_lock;
411
412#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
413
414struct atm_dev *atm_dev_register(const char *type,const struct atmdev_ops *ops,
415 int number,unsigned long *flags); /* number == -1: pick first available */
416struct atm_dev *atm_dev_lookup(int number);
417void atm_dev_deregister(struct atm_dev *dev);
418void shutdown_atm_dev(struct atm_dev *dev);
419void vcc_insert_socket(struct sock *sk);
420
421
422/*
423 * This is approximately the algorithm used by alloc_skb.
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 atomic_dec(&dev->refcnt);
461
462 if ((atomic_read(&dev->refcnt) == 1) &&
463 test_bit(ATM_DF_CLOSE,&dev->flags))
464 shutdown_atm_dev(dev);
465}
466
467
468int atm_charge(struct atm_vcc *vcc,int truesize);
469struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
Randy Dunlap7b5b3f32005-10-04 22:38:44 -0700470 unsigned int __nocast gfp_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471int atm_pcr_goal(struct atm_trafprm *tp);
472
473void vcc_release_async(struct atm_vcc *vcc, int reply);
474
475struct atm_ioctl {
476 struct module *owner;
477 /* A module reference is kept if appropriate over this call.
478 * Return -ENOIOCTLCMD if you don't handle it. */
479 int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
480 struct list_head list;
481};
482
483/**
484 * register_atm_ioctl - register handler for ioctl operations
485 *
486 * Special (non-device) handlers of ioctl's should
487 * register here. If you're a normal device, you should
488 * set .ioctl in your atmdev_ops instead.
489 */
490void register_atm_ioctl(struct atm_ioctl *);
491
492/**
493 * deregister_atm_ioctl - remove the ioctl handler
494 */
495void deregister_atm_ioctl(struct atm_ioctl *);
496
497#endif /* __KERNEL__ */
498
499#endif