Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 1
/* 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
#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);                  /* TX okay */ \
39
    __HANDLE_ITEM(tx_err);              /* TX errors */ \
40
    __HANDLE_ITEM(rx);                  /* RX okay */ \
41
    __HANDLE_ITEM(rx_err);              /* RX errors */ \
42
    __HANDLE_ITEM(rx_drop);             /* RX out of memory */
43
 
44
struct atm_aal_stats {
45
#define __HANDLE_ITEM(i) int i
46
        __AAL_STAT_ITEMS
47
#undef __HANDLE_ITEM
48
};
49
 
50
 
51
struct 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
                                        /* get link rate */
60
#define ATM_GETNAMES    _IOW('a',ATMIOC_ITF+3,struct atm_iobuf)
61
                                        /* get interface names (numbers) */
62
#define ATM_GETTYPE     _IOW('a',ATMIOC_ITF+4,struct atmif_sioc)
63
                                        /* get interface type name */
64
#define ATM_GETESI      _IOW('a',ATMIOC_ITF+5,struct atmif_sioc)
65
                                        /* get interface ESI */
66
#define ATM_GETADDR     _IOW('a',ATMIOC_ITF+6,struct atmif_sioc)
67
                                        /* get itf's local ATM addr. list */
68
#define ATM_RSTADDR     _IOW('a',ATMIOC_ITF+7,struct atmif_sioc)
69
                                        /* reset itf's ATM address list */
70
#define ATM_ADDADDR     _IOW('a',ATMIOC_ITF+8,struct atmif_sioc)
71
                                        /* add a local ATM address */
72
#define ATM_DELADDR     _IOW('a',ATMIOC_ITF+9,struct atmif_sioc)
73
                                        /* remove a local ATM address */
74
#define ATM_GETCIRANGE  _IOW('a',ATMIOC_ITF+10,struct atmif_sioc)
75
                                        /* get connection identifier range */
76
#define ATM_SETCIRANGE  _IOW('a',ATMIOC_ITF+11,struct atmif_sioc)
77
                                        /* set connection identifier range */
78
#define ATM_SETESI      _IOW('a',ATMIOC_ITF+12,struct atmif_sioc)
79
                                        /* set interface ESI */
80
#define ATM_SETESIF     _IOW('a',ATMIOC_ITF+13,struct atmif_sioc)
81
                                        /* force interface ESI */
82
#define ATM_GETSTAT     _IOW('a',ATMIOC_SARCOM+0,struct atmif_sioc)
83
                                        /* get AAL layer statistics */
84
#define ATM_GETSTATZ    _IOW('a',ATMIOC_SARCOM+1,struct atmif_sioc)
85
                                        /* get AAL layer statistics and zero */
86
#define ATM_GETLOOP     _IOW('a',ATMIOC_SARCOM+2,struct atmif_sioc)
87
                                        /* get loopback mode */
88
#define ATM_SETLOOP     _IOW('a',ATMIOC_SARCOM+3,struct atmif_sioc)
89
                                        /* set loopback mode */
90
#define ATM_QUERYLOOP   _IOW('a',ATMIOC_SARCOM+4,struct atmif_sioc)
91
                                        /* query supported loopback modes */
92
#define ATM_SETSC       _IOW('a',ATMIOC_SPECIAL+1,int)
93
                                        /* enable or disable single-copy */
94
#define ATM_SETBACKEND  _IOW('a',ATMIOC_SPECIAL+2,atm_backend_t)
95
                                        /* set backend handler */
96
#define ATM_NEWBACKENDIF _IOW('a',ATMIOC_SPECIAL+3,atm_backend_t)
97
                                        /* use backend to make new if */
98
 
99
/*
100
 * These are backend handkers that can be set via the ATM_SETBACKEND call
101
 * above.  In the future we may support dynamic loading of these - for now,
102
 * they're just being used to share the ATMIOC_BACKEND ioctls
103
 */
104
#define ATM_BACKEND_RAW         0       
105
#define ATM_BACKEND_PPP         1       /* PPPoATM - RFC2364 */
106
#define ATM_BACKEND_BR2684      2       /* Bridged RFC1483/2684 */
107
 
108
/* for ATM_GETTYPE */
109
#define ATM_ITFTYP_LEN  8       /* maximum length of interface type name */
110
 
111
/*
112
 * Loopback modes for ATM_{PHY,SAR}_{GET,SET}LOOP
113
 */
114
 
115
/* Point of loopback                            CPU-->SAR-->PHY-->line--> ... */
116
#define __ATM_LM_NONE   0       /* no loop back     ^     ^     ^      ^      */
117
#define __ATM_LM_AAL    1       /* loop back PDUs --'     |     |      |      */
118
#define __ATM_LM_ATM    2       /* loop back ATM cells ---'     |      |      */
119
/* RESERVED             4       loop back on PHY side  ---'                   */
120
#define __ATM_LM_PHY    8       /* loop back bits (digital) ----'      |      */
121
#define __ATM_LM_ANALOG 16      /* loop back the analog signal --------'      */
122
 
123
/* Direction of loopback */
124
#define __ATM_LM_MKLOC(n)       ((n))       /* Local (i.e. loop TX to RX) */
125
#define __ATM_LM_MKRMT(n)       ((n) << 8)  /* Remote (i.e. loop RX to TX) */
126
 
127
#define __ATM_LM_XTLOC(n)       ((n) & 0xff)
128
#define __ATM_LM_XTRMT(n)       (((n) >> 8) & 0xff)
129
 
130
#define ATM_LM_NONE     0       /* no loopback */
131
 
132
#define ATM_LM_LOC_AAL  __ATM_LM_MKLOC(__ATM_LM_AAL)
133
#define ATM_LM_LOC_ATM  __ATM_LM_MKLOC(__ATM_LM_ATM)
134
#define ATM_LM_LOC_PHY  __ATM_LM_MKLOC(__ATM_LM_PHY)
135
#define ATM_LM_LOC_ANALOG __ATM_LM_MKLOC(__ATM_LM_ANALOG)
136
 
137
#define ATM_LM_RMT_AAL  __ATM_LM_MKRMT(__ATM_LM_AAL)
138
#define ATM_LM_RMT_ATM  __ATM_LM_MKRMT(__ATM_LM_ATM)
139
#define ATM_LM_RMT_PHY  __ATM_LM_MKRMT(__ATM_LM_PHY)
140
#define ATM_LM_RMT_ANALOG __ATM_LM_MKRMT(__ATM_LM_ANALOG)
141
 
142
/*
143
 * Note: ATM_LM_LOC_* and ATM_LM_RMT_* can be combined, provided that
144
 * __ATM_LM_XTLOC(x) <= __ATM_LM_XTRMT(x)
145
 */
146
 
147
 
148
struct atm_iobuf {
149
        int length;
150
        void *buffer;
151
};
152
 
153
/* for ATM_GETCIRANGE / ATM_SETCIRANGE */
154
 
155
#define ATM_CI_MAX      -1              /* use maximum range of VPI/VCI */
156
 
157
struct atm_cirange {
158
        char    vpi_bits;               /* 1..8, ATM_CI_MAX (-1) for maximum */
159
        char    vci_bits;               /* 1..16, ATM_CI_MAX (-1) for maximum */
160
};
161
 
162
/* for ATM_SETSC; actually taken from the ATM_VF number space */
163
 
164
#define ATM_SC_RX       1024            /* enable RX single-copy */
165
#define ATM_SC_TX       2048            /* enable TX single-copy */
166
 
167
#define ATM_BACKLOG_DEFAULT 32 /* if we get more, we're likely to time out
168
                                  anyway */
169
 
170
/* MF: change_qos (Modify) flags */
171
 
172
#define ATM_MF_IMMED     1      /* Block until change is effective */
173
#define ATM_MF_INC_RSV   2      /* Change reservation on increase */
174
#define ATM_MF_INC_SHP   4      /* Change shaping on increase */
175
#define ATM_MF_DEC_RSV   8      /* Change reservation on decrease */
176
#define ATM_MF_DEC_SHP  16      /* Change shaping on decrease */
177
#define ATM_MF_BWD      32      /* Set the backward direction parameters */
178
 
179
#define ATM_MF_SET      (ATM_MF_INC_RSV | ATM_MF_INC_SHP | ATM_MF_DEC_RSV | \
180
                          ATM_MF_DEC_SHP | ATM_MF_BWD)
181
 
182
/*
183
 * ATM_VS_* are used to express VC state in a human-friendly way.
184
 */
185
 
186
#define ATM_VS_IDLE     0       /* VC is not used */
187
#define ATM_VS_CONNECTED 1      /* VC is connected */
188
#define ATM_VS_CLOSING  2       /* VC is closing */
189
#define ATM_VS_LISTEN   3       /* VC is listening for incoming setups */
190
#define ATM_VS_INUSE    4       /* VC is in use (registered with atmsigd) */
191
#define ATM_VS_BOUND    5       /* VC is bound */
192
 
193
#define ATM_VS2TXT_MAP \
194
    "IDLE", "CONNECTED", "CLOSING", "LISTEN", "INUSE", "BOUND"
195
 
196
#define ATM_VF2TXT_MAP \
197
    "ADDR",     "READY",        "PARTIAL",      "REGIS", \
198
    "RELEASED", "HASQOS",       "LISTEN",       "META", \
199
    "256",      "512",          "1024",         "2048", \
200
    "SESSION",  "HASSAP",       "BOUND",        "CLOSE"
201
 
202
 
203
#ifndef __KERNEL__
204
#undef __AAL_STAT_ITEMS
205
#else
206
 
207
#include <linux/wait.h> /* wait_queue_head_t */
208
#include <linux/time.h> /* struct timeval */
209
#include <linux/net.h>
210
#include <linux/skbuff.h> /* struct sk_buff */
211
#include <linux/uio.h>
212
#include <net/sock.h>
213
#include <asm/atomic.h>
214
 
215
#ifdef CONFIG_PROC_FS
216
#include <linux/proc_fs.h>
217
 
218
extern struct proc_dir_entry *atm_proc_root;
219
#endif
220
 
221
 
222
struct k_atm_aal_stats {
223
#define __HANDLE_ITEM(i) atomic_t i
224
        __AAL_STAT_ITEMS
225
#undef __HANDLE_ITEM
226
};
227
 
228
 
229
struct k_atm_dev_stats {
230
        struct k_atm_aal_stats aal0;
231
        struct k_atm_aal_stats aal34;
232
        struct k_atm_aal_stats aal5;
233
};
234
 
235
 
236
enum {
237
        ATM_VF_ADDR,            /* Address is in use. Set by anybody, cleared
238
                                   by device driver. */
239
        ATM_VF_READY,           /* VC is ready to transfer data. Set by device
240
                                   driver, cleared by anybody. */
241
        ATM_VF_PARTIAL,         /* resources are bound to PVC (partial PVC
242
                                   setup), controlled by socket layer */
243
        ATM_VF_REGIS,           /* registered with demon, controlled by SVC
244
                                   socket layer */
245
        ATM_VF_BOUND,           /* local SAP is set, controlled by SVC socket
246
                                   layer */
247
        ATM_VF_RELEASED,        /* demon has indicated/requested release,
248
                                   controlled by SVC socket layer */
249
        ATM_VF_HASQOS,          /* QOS parameters have been set */
250
        ATM_VF_LISTEN,          /* socket is used for listening */
251
        ATM_VF_META,            /* SVC socket isn't used for normal data
252
                                   traffic and doesn't depend on signaling
253
                                   to be available */
254
        ATM_VF_SESSION,         /* VCC is p2mp session control descriptor */
255
        ATM_VF_HASSAP,          /* SAP has been set */
256
        ATM_VF_CLOSE,           /* asynchronous close - treat like VF_RELEASED*/
257
        ATM_VF_WAITING,         /* waiting for reply from sigd */
258
        ATM_VF_IS_CLIP,         /* in use by CLIP protocol */
259
};
260
 
261
 
262
#define ATM_VF2VS(flags) \
263
    (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
264
     test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
265
     test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
266
     test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
267
     test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
268
 
269
 
270
enum {
271
        ATM_DF_CLOSE,           /* close device when last VCC is closed */
272
};
273
 
274
 
275
#define ATM_PHY_SIG_LOST    0   /* no carrier/light */
276
#define ATM_PHY_SIG_UNKNOWN 1   /* carrier/light status is unknown */
277
#define ATM_PHY_SIG_FOUND   2   /* carrier/light okay */
278
 
279
#define ATM_ATMOPT_CLP  1       /* set CLP bit */
280
 
281
struct atm_vcc {
282
        unsigned long   flags;          /* VCC flags (ATM_VF_*) */
283
        short           vpi;            /* VPI and VCI (types must be equal */
284
                                        /* with sockaddr) */
285
        int             vci;
286
        unsigned long   aal_options;    /* AAL layer options */
287
        unsigned long   atm_options;    /* ATM layer options */
288
        struct atm_dev  *dev;           /* device back pointer */
289
        struct atm_qos  qos;            /* QOS */
290
        struct atm_sap  sap;            /* SAP */
291
        void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
292
        void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
293
        int (*push_oam)(struct atm_vcc *vcc,void *cell);
294
        int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
295
        void            *dev_data;      /* per-device data */
296
        void            *proto_data;    /* per-protocol data */
297
        struct k_atm_aal_stats *stats;  /* pointer to AAL stats group */
298
        struct sock     *sk;            /* socket backpointer */
299
        /* SVC part --- may move later ------------------------------------- */
300
        short           itf;            /* interface number */
301
        struct sockaddr_atmsvc local;
302
        struct sockaddr_atmsvc remote;
303
        /* Multipoint part ------------------------------------------------- */
304
        struct atm_vcc  *session;       /* session VCC descriptor */
305
        /* Other stuff ----------------------------------------------------- */
306
        void            *user_back;     /* user backlink - not touched by */
307
                                        /* native ATM stack. Currently used */
308
                                        /* by CLIP and sch_atm. */
309
};
310
 
311
 
312
struct atm_dev_addr {
313
        struct sockaddr_atmsvc addr;    /* ATM address */
314
        struct atm_dev_addr *next;      /* next address */
315
};
316
 
317
struct atm_dev {
318
        const struct atmdev_ops *ops;   /* device operations; NULL if unused */
319
        const struct atmphy_ops *phy;   /* PHY operations, may be undefined */
320
                                        /* (NULL) */
321
        const char      *type;          /* device type name */
322
        int             number;         /* device index */
323
        void            *dev_data;      /* per-device data */
324
        void            *phy_data;      /* private PHY date */
325
        unsigned long   flags;          /* device flags (ATM_DF_*) */
326
        struct atm_dev_addr *local;     /* local ATM addresses */
327
        unsigned char   esi[ESI_LEN];   /* ESI ("MAC" addr) */
328
        struct atm_cirange ci_range;    /* VPI/VCI range */
329
        struct k_atm_dev_stats stats;   /* statistics */
330
        char            signal;         /* signal status (ATM_PHY_SIG_*) */
331
        int             link_rate;      /* link rate (default: OC3) */
332
        atomic_t        refcnt;         /* reference count */
333
        spinlock_t      lock;           /* protect internal members */
334
#ifdef CONFIG_PROC_FS
335
        struct proc_dir_entry *proc_entry; /* proc entry */
336
        char *proc_name;                /* proc entry name */
337
#endif
338
        struct list_head dev_list;      /* linkage */
339
};
340
 
341
 
342
/* OF: send_Oam Flags */
343
 
344
#define ATM_OF_IMMED  1         /* Attempt immediate delivery */
345
#define ATM_OF_INRATE 2         /* Attempt in-rate delivery */
346
 
347
 
348
/*
349
 * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
350
 */
351
 
352
struct atmdev_ops { /* only send is required */
353
        void (*dev_close)(struct atm_dev *dev);
354
        int (*open)(struct atm_vcc *vcc);
355
        void (*close)(struct atm_vcc *vcc);
356
        int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void *arg);
357
        int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
358
            void *optval,int optlen);
359
        int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
360
            void *optval,int optlen);
361
        int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
362
        int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
363
        void (*phy_put)(struct atm_dev *dev,unsigned char value,
364
            unsigned long addr);
365
        unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
366
        int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
367
        int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
368
        struct module *owner;
369
};
370
 
371
struct atmphy_ops {
372
        int (*start)(struct atm_dev *dev);
373
        int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void *arg);
374
        void (*interrupt)(struct atm_dev *dev);
375
        int (*stop)(struct atm_dev *dev);
376
};
377
 
378
struct atm_skb_data {
379
        struct atm_vcc  *vcc;           /* ATM VCC */
380
        unsigned long   atm_options;    /* ATM layer options */
381
};
382
 
383
#define VCC_HTABLE_SIZE 32
384
 
385
extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
386
extern rwlock_t vcc_sklist_lock;
387
 
388
#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
389
 
390
struct atm_dev *atm_dev_register(const char *type,const struct atmdev_ops *ops,
391
    int number,unsigned long *flags); /* number == -1: pick first available */
392
struct atm_dev *atm_dev_lookup(int number);
393
void atm_dev_deregister(struct atm_dev *dev);
394
void shutdown_atm_dev(struct atm_dev *dev);
395
void vcc_insert_socket(struct sock *sk);
396
void vcc_remove_socket(struct sock *sk);
397
 
398
 
399
/*
400
 * This is approximately the algorithm used by alloc_skb.
401
 *
402
 */
403
 
404
static inline int atm_guess_pdu2truesize(int pdu_size)
405
{
406
        return ((pdu_size+15) & ~15) + sizeof(struct sk_buff);
407
}
408
 
409
 
410
static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
411
{
412
        atomic_add(truesize, &vcc->sk->sk_rmem_alloc);
413
}
414
 
415
 
416
static inline void atm_return(struct atm_vcc *vcc,int truesize)
417
{
418
        atomic_sub(truesize, &vcc->sk->sk_rmem_alloc);
419
}
420
 
421
 
422
static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
423
{
424
        return (size + atomic_read(&vcc->sk->sk_wmem_alloc)) <
425
               vcc->sk->sk_sndbuf;
426
}
427
 
428
 
429
static inline void atm_dev_hold(struct atm_dev *dev)
430
{
431
        atomic_inc(&dev->refcnt);
432
}
433
 
434
 
435
static inline void atm_dev_put(struct atm_dev *dev)
436
{
437
        atomic_dec(&dev->refcnt);
438
 
439
        if ((atomic_read(&dev->refcnt) == 1) &&
440
            test_bit(ATM_DF_CLOSE,&dev->flags))
441
                shutdown_atm_dev(dev);
442
}
443
 
444
 
445
int atm_charge(struct atm_vcc *vcc,int truesize);
446
struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
447
    int gfp_flags);
448
int atm_pcr_goal(struct atm_trafprm *tp);
449
 
450
void vcc_release_async(struct atm_vcc *vcc, int reply);
451
 
452
struct atm_ioctl {
453
        struct module *owner;
454
        /* A module reference is kept if appropriate over this call.
455
         * Return -ENOIOCTLCMD if you don't handle it. */
456
        int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
457
        struct list_head list;
458
};
459
 
460
/**
461
 * register_atm_ioctl - register handler for ioctl operations
462
 *
463
 * Special (non-device) handlers of ioctl's should
464
 * register here. If you're a normal device, you should
465
 * set .ioctl in your atmdev_ops instead.
466
 */
467
void register_atm_ioctl(struct atm_ioctl *);
468
 
469
/**
470
 * deregister_atm_ioctl - remove the ioctl handler
471
 */
472
void deregister_atm_ioctl(struct atm_ioctl *);
473
 
474
#endif /* __KERNEL__ */
475
 
476
#endif