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