1 /* atmdev.h - ATM device driver declarations and various related items */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
10 #include <linux/config.h>
11 #include <linux/atmapi.h>
12 #include <linux/atm.h>
13 #include <linux/atmioc.h>
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)
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
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
46 struct atm_dev_stats {
47 struct atm_aal_stats aal0;
48 struct atm_aal_stats aal34;
49 struct atm_aal_stats aal5;
53 #define ATM_GETLINKRATE _IOW('a',ATMIOC_ITF+1,struct atmif_sioc)
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 #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 */
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
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 */
105 /* for ATM_GETTYPE */
106 #define ATM_ITFTYP_LEN 8 /* maximum length of interface type name */
109 * Loopback modes for ATM_{PHY,SAR}_{GET,SET}LOOP
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 --------' */
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) */
124 #define __ATM_LM_XTLOC(n) ((n) & 0xff)
125 #define __ATM_LM_XTRMT(n) (((n) >> 8) & 0xff)
127 #define ATM_LM_NONE 0 /* no loopback */
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)
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)
140 * Note: ATM_LM_LOC_* and ATM_LM_RMT_* can be combined, provided that
141 * __ATM_LM_XTLOC(x) <= __ATM_LM_XTRMT(x)
150 /* for ATM_GETCIRANGE / ATM_SETCIRANGE */
152 #define ATM_CI_MAX -1 /* use maximum range of VPI/VCI */
155 char vpi_bits; /* 1..8, ATM_CI_MAX (-1) for maximum */
156 char vci_bits; /* 1..16, ATM_CI_MAX (-1) for maximum */
159 /* for ATM_SETSC; actually taken from the ATM_VF number space */
161 #define ATM_SC_RX 1024 /* enable RX single-copy */
162 #define ATM_SC_TX 2048 /* enable TX single-copy */
164 #define ATM_BACKLOG_DEFAULT 32 /* if we get more, we're likely to time out
167 /* MF: change_qos (Modify) flags */
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 */
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)
180 * ATM_VS_* are used to express VC state in a human-friendly way.
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 */
190 #define ATM_VS2TXT_MAP \
191 "IDLE", "CONNECTED", "CLOSING", "LISTEN", "INUSE", "BOUND"
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"
201 #undef __AAL_STAT_ITEMS
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>
212 #ifdef CONFIG_PROC_FS
213 #include <linux/proc_fs.h>
217 struct k_atm_aal_stats {
218 #define __HANDLE_ITEM(i) atomic_t i
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;
232 ATM_VF_ADDR, /* Address is in use. Set by anybody, cleared
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
240 ATM_VF_BOUND, /* local SAP is set, controlled by SVC socket
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
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*/
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)
264 ATM_DF_CLOSE, /* close device when last VCC is closed */
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 */
272 #define ATM_ATMOPT_CLP 1 /* set CLP bit */
275 typedef struct { unsigned long bits; } atm_vcc_flags_t;
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 */
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. */
324 struct atm_dev_addr {
325 struct sockaddr_atmsvc addr; /* ATM address */
326 struct atm_dev_addr *next; /* next address */
330 typedef struct { unsigned int bits; } atm_dev_flags_t;
334 const struct atmdev_ops *ops; /* device operations; NULL if unused */
335 const struct atmphy_ops *phy; /* PHY operations, may be undefined */
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 */
354 struct atm_dev *prev,*next; /* linkage */
359 * ioctl, getsockopt, setsockopt, and sg_send are optional and can be set to
362 /* OF: send_Oam Flags */
364 #define ATM_OF_IMMED 1 /* Attempt immediate delivery */
365 #define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
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,
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);
383 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
384 void (*phy_put)(struct atm_dev *dev,unsigned char value,
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;
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);
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 */
410 #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
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);
421 * This is approximately the algorithm used by alloc_skb.
425 static __inline__ int atm_guess_pdu2truesize(int pdu_size)
427 return ((pdu_size+15) & ~15) + sizeof(struct sk_buff);
431 static __inline__ void atm_force_charge(struct atm_vcc *vcc,int truesize)
433 atomic_add(truesize+ATM_PDU_OVHD,&vcc->rx_inuse);
437 static __inline__ void atm_return(struct atm_vcc *vcc,int truesize)
439 atomic_sub(truesize+ATM_PDU_OVHD,&vcc->rx_inuse);
443 static __inline__ int atm_may_send(struct atm_vcc *vcc,unsigned int size)
445 return size+atomic_read(&vcc->tx_inuse)+ATM_PDU_OVHD < vcc->sk->sndbuf;
449 int atm_charge(struct atm_vcc *vcc,int truesize);
450 struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
452 int atm_find_ci(struct atm_vcc *vcc,short *vpi,int *vci);
453 int atm_pcr_goal(struct atm_trafprm *tp);
455 void atm_async_release_vcc(struct atm_vcc *vcc,int reply);
457 #endif /* __KERNEL__ */