Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / include / linux / atmdev.h
blobef8931cd7b5fe086733a01c5afde56a60211947d
1 /* atmdev.h - ATM device driver declarations and various related items */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
6 #ifndef LINUX_ATMDEV_H
7 #define LINUX_ATMDEV_H
10 #include <linux/config.h>
11 #include <linux/atmapi.h>
12 #include <linux/atm.h>
13 #include <linux/atmioc.h>
16 #define ESI_LEN 6
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) */
26 #define ATM_PDU_OVHD 0/* number of bytes to charge against buffer
27 quota per PDU */
29 #define ATM_SD(s) ((s)->sk->protinfo.af_atm)
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 */
39 struct atm_aal_stats {
40 #define __HANDLE_ITEM(i) int i
41 __AAL_STAT_ITEMS
42 #undef __HANDLE_ITEM
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;
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 */
90 /* for ATM_GETTYPE */
91 #define ATM_ITFTYP_LEN 8/* maximum length of interface type name */
94 * Loopback modes for ATM_{PHY,SAR}_{GET,SET}LOOP
97 /* Point of loopback CPU-->SAR-->PHY-->line--> ... */
98 #define __ATM_LM_NONE 0/* no loop back ^ ^ ^ ^ */
99 #define __ATM_LM_AAL 1/* loop back PDUs --' | | | */
100 #define __ATM_LM_ATM 2/* loop back ATM cells ---' | | */
101 /* RESERVED 4 loop back on PHY side ---' */
102 #define __ATM_LM_PHY 8/* loop back bits (digital) ----' | */
103 #define __ATM_LM_ANALOG 16/* loop back the analog signal --------' */
105 /* Direction of loopback */
106 #define __ATM_LM_MKLOC(n) ((n))/* Local (i.e. loop TX to RX) */
107 #define __ATM_LM_MKRMT(n) ((n) << 8)/* Remote (i.e. loop RX to TX) */
109 #define __ATM_LM_XTLOC(n) ((n) & 0xff)
110 #define __ATM_LM_XTRMT(n) (((n) >> 8) & 0xff)
112 #define ATM_LM_NONE 0/* no loopback */
114 #define ATM_LM_LOC_AAL __ATM_LM_MKLOC(__ATM_LM_AAL)
115 #define ATM_LM_LOC_ATM __ATM_LM_MKLOC(__ATM_LM_ATM)
116 #define ATM_LM_LOC_PHY __ATM_LM_MKLOC(__ATM_LM_PHY)
117 #define ATM_LM_LOC_ANALOG __ATM_LM_MKLOC(__ATM_LM_ANALOG)
119 #define ATM_LM_RMT_AAL __ATM_LM_MKRMT(__ATM_LM_AAL)
120 #define ATM_LM_RMT_ATM __ATM_LM_MKRMT(__ATM_LM_ATM)
121 #define ATM_LM_RMT_PHY __ATM_LM_MKRMT(__ATM_LM_PHY)
122 #define ATM_LM_RMT_ANALOG __ATM_LM_MKRMT(__ATM_LM_ANALOG)
125 * Note: ATM_LM_LOC_* and ATM_LM_RMT_* can be combined, provided that
126 * __ATM_LM_XTLOC(x) <= __ATM_LM_XTRMT(x)
130 struct atm_iobuf {
131 int length;
132 void*buffer;
135 /* for ATM_GETCIRANGE / ATM_SETCIRANGE */
137 #define ATM_CI_MAX -1/* use maximum range of VPI/VCI */
139 struct atm_cirange {
140 char vpi_bits;/* 1..8, ATM_CI_MAX (-1) for maximum */
141 char vci_bits;/* 1..16, ATM_CI_MAX (-1) for maximum */
144 /* for ATM_SETSC; actually taken from the ATM_VF number space */
146 #define ATM_SC_RX 1024/* enable RX single-copy */
147 #define ATM_SC_TX 2048/* enable TX single-copy */
149 #define ATM_BACKLOG_DEFAULT 32/* if we get more, we're likely to time out
150 anyway */
152 /* MF: change_qos (Modify) flags */
154 #define ATM_MF_IMMED 1/* Block until change is effective */
155 #define ATM_MF_INC_RSV 2/* Change reservation on increase */
156 #define ATM_MF_INC_SHP 4/* Change shaping on increase */
157 #define ATM_MF_DEC_RSV 8/* Change reservation on decrease */
158 #define ATM_MF_DEC_SHP 16/* Change shaping on decrease */
159 #define ATM_MF_BWD 32/* Set the backward direction parameters */
161 #define ATM_MF_SET (ATM_MF_INC_RSV | ATM_MF_INC_SHP | ATM_MF_DEC_RSV | \
162 ATM_MF_DEC_SHP | ATM_MF_BWD)
165 * ATM_VS_* are used to express VC state in a human-friendly way.
168 #define ATM_VS_IDLE 0/* VC is not used */
169 #define ATM_VS_CONNECTED 1/* VC is connected */
170 #define ATM_VS_CLOSING 2/* VC is closing */
171 #define ATM_VS_LISTEN 3/* VC is listening for incoming setups */
172 #define ATM_VS_INUSE 4/* VC is in use (registered with atmsigd) */
173 #define ATM_VS_BOUND 5/* VC is bound */
175 #define ATM_VS2TXT_MAP \
176 "IDLE","CONNECTED","CLOSING","LISTEN","INUSE","BOUND"
178 #define ATM_VF2TXT_MAP \
179 "ADDR","READY","PARTIAL","REGIS", \
180 "RELEASED","HASQOS","LISTEN","META", \
181 "256","512","1024","2048", \
182 "SESSION","HASSAP","BOUND","CLOSE"
185 #ifndef __KERNEL__
186 #undef __AAL_STAT_ITEMS
187 #else
189 #include <linux/sched.h>/* wait_queue_head_t */
190 #include <linux/time.h>/* struct timeval */
191 #include <linux/net.h>
192 #include <linux/skbuff.h>/* struct sk_buff */
193 #include <linux/uio.h>
194 #include <net/sock.h>
195 #include <asm/atomic.h>
197 #ifdef CONFIG_PROC_FS
198 #include <linux/proc_fs.h>
199 #endif
202 struct k_atm_aal_stats {
203 #define __HANDLE_ITEM(i) atomic_t i
204 __AAL_STAT_ITEMS
205 #undef __HANDLE_ITEM
209 struct k_atm_dev_stats {
210 struct k_atm_aal_stats aal0;
211 struct k_atm_aal_stats aal34;
212 struct k_atm_aal_stats aal5;
216 enum{
217 ATM_VF_ADDR,/* Address is in use. Set by anybody, cleared
218 by device driver. */
219 ATM_VF_READY,/* VC is ready to transfer data. Set by device
220 driver, cleared by anybody. */
221 ATM_VF_PARTIAL,/* resources are bound to PVC (partial PVC
222 setup), controlled by socket layer */
223 ATM_VF_REGIS,/* registered with demon, controlled by SVC
224 socket layer */
225 ATM_VF_BOUND,/* local SAP is set, controlled by SVC socket
226 layer */
227 ATM_VF_RELEASED,/* demon has indicated/requested release,
228 controlled by SVC socket layer */
229 ATM_VF_HASQOS,/* QOS parameters have been set */
230 ATM_VF_LISTEN,/* socket is used for listening */
231 ATM_VF_META,/* SVC socket isn't used for normal data
232 traffic and doesn't depend on signaling
233 to be available */
234 ATM_VF_SESSION,/* VCC is p2mp session control descriptor */
235 ATM_VF_HASSAP,/* SAP has been set */
236 ATM_VF_CLOSE,/* asynchronous close - treat like VF_RELEASED*/
240 #define ATM_VF2VS(flags) \
241 (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
242 test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
243 test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
244 test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
245 test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
248 enum{
249 ATM_DF_CLOSE,/* close device when last VCC is closed */
253 #define ATM_PHY_SIG_LOST 0/* no carrier/light */
254 #define ATM_PHY_SIG_UNKNOWN 1/* carrier/light status is unknown */
255 #define ATM_PHY_SIG_FOUND 2/* carrier/light okay */
257 #define ATM_ATMOPT_CLP 1/* set CLP bit */
260 typedefstruct{unsigned long bits; } atm_vcc_flags_t;
263 struct atm_vcc {
264 atm_vcc_flags_t flags;/* VCC flags (ATM_VF_*) */
265 unsigned char family;/* address family; 0 if unused */
266 short vpi;/* VPI and VCI (types must be equal */
267 /* with sockaddr) */
268 int vci;
269 unsigned long aal_options;/* AAL layer options */
270 unsigned long atm_options;/* ATM layer options */
271 struct atm_dev *dev;/* device back pointer */
272 struct atm_qos qos;/* QOS */
273 struct atm_sap sap;/* SAP */
274 atomic_t tx_inuse,rx_inuse;/* buffer space in use */
275 void(*push)(struct atm_vcc *vcc,struct sk_buff *skb);
276 void(*pop)(struct atm_vcc *vcc,struct sk_buff *skb);/* optional */
277 struct sk_buff *(*alloc_tx)(struct atm_vcc *vcc,unsigned int size);
278 /* TX allocation routine - can be */
279 /* modified by protocol or by driver.*/
280 /* NOTE: this interface will change */
281 int(*push_oam)(struct atm_vcc *vcc,void*cell);
282 int(*send)(struct atm_vcc *vcc,struct sk_buff *skb);
283 void*dev_data;/* per-device data */
284 void*proto_data;/* per-protocol data */
285 struct timeval timestamp;/* AAL timestamps */
286 struct sk_buff_head recvq;/* receive queue */
287 struct k_atm_aal_stats *stats;/* pointer to AAL stats group */
288 wait_queue_head_t sleep;/* if socket is busy */
289 struct sock *sk;/* socket backpointer */
290 struct atm_vcc *prev,*next;
291 /* SVC part --- may move later ------------------------------------- */
292 short itf;/* interface number */
293 struct sockaddr_atmsvc local;
294 struct sockaddr_atmsvc remote;
295 void(*callback)(struct atm_vcc *vcc);
296 struct sk_buff_head listenq;
297 int backlog_quota;/* number of connection requests we */
298 /* can still accept */
299 int reply;/* also used by ATMTCP */
300 /* Multipoint part ------------------------------------------------- */
301 struct atm_vcc *session;/* session VCC descriptor */
302 /* Other stuff ----------------------------------------------------- */
303 void*user_back;/* user backlink - not touched by */
304 /* native ATM stack. Currently used */
305 /* by CLIP and sch_atm. */
309 struct atm_dev_addr {
310 struct sockaddr_atmsvc addr;/* ATM address */
311 struct atm_dev_addr *next;/* next address */
315 typedefstruct{unsigned int bits; } atm_dev_flags_t;
318 struct atm_dev {
319 const struct atmdev_ops *ops;/* device operations; NULL if unused */
320 const struct atmphy_ops *phy;/* PHY operations, may be undefined */
321 /* (NULL) */
322 const char*type;/* device type name */
323 int number;/* device index */
324 struct atm_vcc *vccs;/* VCC table (or NULL) */
325 struct atm_vcc *last;/* last VCC (or undefined) */
326 void*dev_data;/* per-device data */
327 void*phy_data;/* private PHY date */
328 atm_dev_flags_t flags;/* device flags (ATM_DF_*) */
329 struct atm_dev_addr *local;/* local ATM addresses */
330 unsigned char esi[ESI_LEN];/* ESI ("MAC" addr) */
331 struct atm_cirange ci_range;/* VPI/VCI range */
332 struct k_atm_dev_stats stats;/* statistics */
333 char signal;/* signal status (ATM_PHY_SIG_*) */
334 int link_rate;/* link rate (default: OC3) */
335 #ifdef CONFIG_PROC_FS
336 struct proc_dir_entry *proc_entry;/* proc entry */
337 char*proc_name;/* proc entry name */
338 #endif
339 struct atm_dev *prev,*next;/* linkage */
344 * ioctl, getsockopt, setsockopt, and sg_send are optional and can be set to
345 * NULL. */
347 /* OF: send_Oam Flags */
349 #define ATM_OF_IMMED 1/* Attempt immediate delivery */
350 #define ATM_OF_INRATE 2/* Attempt in-rate delivery */
352 struct atmdev_ops {/* only send is required */
353 void(*dev_close)(struct atm_dev *dev);
354 int(*open)(struct atm_vcc *vcc,short vpi,int vci);
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(*sg_send)(struct atm_vcc *vcc,unsigned long start,
363 unsigned long size);
364 #if 0/* keep the current hack for now */
365 int(*send_iovec)(struct atm_vcc *vcc,struct iovec *iov,int size,
366 void(*discard)(struct atm_vcc *vcc,void*user),void*user);
367 #endif
368 int(*send_oam)(struct atm_vcc *vcc,void*cell,int flags);
369 void(*phy_put)(struct atm_dev *dev,unsigned char value,
370 unsigned long addr);
371 unsigned char(*phy_get)(struct atm_dev *dev,unsigned long addr);
372 void(*feedback)(struct atm_vcc *vcc,struct sk_buff *skb,
373 unsigned long start,unsigned long dest,int len);
374 int(*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
375 void(*free_rx_skb)(struct atm_vcc *vcc,struct sk_buff *skb);
376 /* @@@ temporary hack */
377 int(*proc_read)(struct atm_dev *dev,loff_t *pos,char*page);
378 struct module *owner;
382 struct atmphy_ops {
383 int(*start)(struct atm_dev *dev);
384 int(*ioctl)(struct atm_dev *dev,unsigned int cmd,void*arg);
385 void(*interrupt)(struct atm_dev *dev);
386 int(*stop)(struct atm_dev *dev);
389 struct atm_skb_data {
390 struct atm_vcc *vcc;/* ATM VCC */
391 int iovcnt;/* 0 for "normal" operation */
392 unsigned long atm_options;/* ATM layer options */
395 #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
397 struct atm_dev *atm_dev_register(const char*type,const struct atmdev_ops *ops,
398 int number,atm_dev_flags_t *flags);/* number == -1: pick first available */
399 struct atm_dev *atm_find_dev(int number);
400 voidatm_dev_deregister(struct atm_dev *dev);
401 voidshutdown_atm_dev(struct atm_dev *dev);
402 voidbind_vcc(struct atm_vcc *vcc,struct atm_dev *dev);
406 * This is approximately the algorithm used by alloc_skb.
410 static __inline__ intatm_guess_pdu2truesize(int pdu_size)
412 return((pdu_size+15) & ~15) +sizeof(struct sk_buff);
416 static __inline__ voidatm_force_charge(struct atm_vcc *vcc,int truesize)
418 atomic_add(truesize+ATM_PDU_OVHD,&vcc->rx_inuse);
422 static __inline__ voidatm_return(struct atm_vcc *vcc,int truesize)
424 atomic_sub(truesize+ATM_PDU_OVHD,&vcc->rx_inuse);
428 static __inline__ intatm_may_send(struct atm_vcc *vcc,unsigned int size)
430 return size+atomic_read(&vcc->tx_inuse)+ATM_PDU_OVHD < vcc->sk->sndbuf;
434 intatm_charge(struct atm_vcc *vcc,int truesize);
435 struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
436 int gfp_flags);
437 intatm_find_ci(struct atm_vcc *vcc,short*vpi,int*vci);
438 intatm_pcr_goal(struct atm_trafprm *tp);
440 voidatm_async_release_vcc(struct atm_vcc *vcc,int reply);
442 #endif/* __KERNEL__ */
444 #endif
close