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) */
25 #define ATM_OC12_PCR (622080000/1080*1040/8/53)
26 /* OC12 link rate: 622080000 bps
27 SONET overhead: /1080*1040
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 */
33 #define atm_sk(__sk) ((struct atm_vcc *)(__sk)->sk_protinfo)
34 #define ATM_SD(s) (atm_sk((s)->sk))
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 */
44 struct atm_aal_stats
{
45 #define __HANDLE_ITEM(i) int i
51 struct atm_dev_stats
{
52 struct atm_aal_stats aal0
;
53 struct atm_aal_stats aal34
;
54 struct atm_aal_stats aal5
;
58 #define ATM_GETLINKRATE _IOW('a',ATMIOC_ITF+1,struct atmif_sioc)
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 */
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
104 #define ATM_BACKEND_RAW 0
105 #define ATM_BACKEND_PPP 1 /* PPPoATM - RFC2364 */
106 #define ATM_BACKEND_BR2684 2 /* Bridged RFC1483/2684 */
108 /* for ATM_GETTYPE */
109 #define ATM_ITFTYP_LEN 8 /* maximum length of interface type name */
112 * Loopback modes for ATM_{PHY,SAR}_{GET,SET}LOOP
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 --------' */
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) */
127 #define __ATM_LM_XTLOC(n) ((n) & 0xff)
128 #define __ATM_LM_XTRMT(n) (((n) >> 8) & 0xff)
130 #define ATM_LM_NONE 0 /* no loopback */
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)
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)
143 * Note: ATM_LM_LOC_* and ATM_LM_RMT_* can be combined, provided that
144 * __ATM_LM_XTLOC(x) <= __ATM_LM_XTRMT(x)
153 /* for ATM_GETCIRANGE / ATM_SETCIRANGE */
155 #define ATM_CI_MAX -1 /* use maximum range of VPI/VCI */
158 signed char vpi_bits
; /* 1..8, ATM_CI_MAX (-1) for maximum */
159 signed char vci_bits
; /* 1..16, ATM_CI_MAX (-1) for maximum */
162 /* for ATM_SETSC; actually taken from the ATM_VF number space */
164 #define ATM_SC_RX 1024 /* enable RX single-copy */
165 #define ATM_SC_TX 2048 /* enable TX single-copy */
167 #define ATM_BACKLOG_DEFAULT 32 /* if we get more, we're likely to time out
170 /* MF: change_qos (Modify) flags */
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 */
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)
183 * ATM_VS_* are used to express VC state in a human-friendly way.
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 */
193 #define ATM_VS2TXT_MAP \
194 "IDLE", "CONNECTED", "CLOSING", "LISTEN", "INUSE", "BOUND"
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"
205 #include <linux/wait.h> /* wait_queue_head_t */
206 #include <linux/time.h> /* struct timeval */
207 #include <linux/net.h>
208 #include <linux/skbuff.h> /* struct sk_buff */
209 #include <linux/uio.h>
210 #include <net/sock.h>
211 #include <asm/atomic.h>
213 #ifdef CONFIG_PROC_FS
214 #include <linux/proc_fs.h>
216 extern struct proc_dir_entry
*atm_proc_root
;
220 struct k_atm_aal_stats
{
221 #define __HANDLE_ITEM(i) atomic_t i
227 struct k_atm_dev_stats
{
228 struct k_atm_aal_stats aal0
;
229 struct k_atm_aal_stats aal34
;
230 struct k_atm_aal_stats aal5
;
235 ATM_VF_ADDR
, /* Address is in use. Set by anybody, cleared
237 ATM_VF_READY
, /* VC is ready to transfer data. Set by device
238 driver, cleared by anybody. */
239 ATM_VF_PARTIAL
, /* resources are bound to PVC (partial PVC
240 setup), controlled by socket layer */
241 ATM_VF_REGIS
, /* registered with demon, controlled by SVC
243 ATM_VF_BOUND
, /* local SAP is set, controlled by SVC socket
245 ATM_VF_RELEASED
, /* demon has indicated/requested release,
246 controlled by SVC socket layer */
247 ATM_VF_HASQOS
, /* QOS parameters have been set */
248 ATM_VF_LISTEN
, /* socket is used for listening */
249 ATM_VF_META
, /* SVC socket isn't used for normal data
250 traffic and doesn't depend on signaling
252 ATM_VF_SESSION
, /* VCC is p2mp session control descriptor */
253 ATM_VF_HASSAP
, /* SAP has been set */
254 ATM_VF_CLOSE
, /* asynchronous close - treat like VF_RELEASED*/
255 ATM_VF_WAITING
, /* waiting for reply from sigd */
256 ATM_VF_IS_CLIP
, /* in use by CLIP protocol */
260 #define ATM_VF2VS(flags) \
261 (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
262 test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
263 test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
264 test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
265 test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
269 ATM_DF_CLOSE
, /* close device when last VCC is closed */
273 #define ATM_PHY_SIG_LOST 0 /* no carrier/light */
274 #define ATM_PHY_SIG_UNKNOWN 1 /* carrier/light status is unknown */
275 #define ATM_PHY_SIG_FOUND 2 /* carrier/light okay */
277 #define ATM_ATMOPT_CLP 1 /* set CLP bit */
280 unsigned long flags
; /* VCC flags (ATM_VF_*) */
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 void (*push
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
);
290 void (*pop
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
); /* optional */
291 int (*push_oam
)(struct atm_vcc
*vcc
,void *cell
);
292 int (*send
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
);
293 void *dev_data
; /* per-device data */
294 void *proto_data
; /* per-protocol data */
295 struct k_atm_aal_stats
*stats
; /* pointer to AAL stats group */
296 struct sock
*sk
; /* socket backpointer */
297 /* SVC part --- may move later ------------------------------------- */
298 short itf
; /* interface number */
299 struct sockaddr_atmsvc local
;
300 struct sockaddr_atmsvc remote
;
301 /* Multipoint part ------------------------------------------------- */
302 struct atm_vcc
*session
; /* session VCC descriptor */
303 /* Other stuff ----------------------------------------------------- */
304 void *user_back
; /* user backlink - not touched by */
305 /* native ATM stack. Currently used */
306 /* by CLIP and sch_atm. */
310 struct atm_dev_addr
{
311 struct sockaddr_atmsvc addr
; /* ATM address */
312 struct atm_dev_addr
*next
; /* next address */
316 const struct atmdev_ops
*ops
; /* device operations; NULL if unused */
317 const struct atmphy_ops
*phy
; /* PHY operations, may be undefined */
319 const char *type
; /* device type name */
320 int number
; /* device index */
321 void *dev_data
; /* per-device data */
322 void *phy_data
; /* private PHY date */
323 unsigned long flags
; /* device flags (ATM_DF_*) */
324 struct atm_dev_addr
*local
; /* local ATM addresses */
325 unsigned char esi
[ESI_LEN
]; /* ESI ("MAC" addr) */
326 struct atm_cirange ci_range
; /* VPI/VCI range */
327 struct k_atm_dev_stats stats
; /* statistics */
328 char signal
; /* signal status (ATM_PHY_SIG_*) */
329 int link_rate
; /* link rate (default: OC3) */
330 atomic_t refcnt
; /* reference count */
331 spinlock_t lock
; /* protect internal members */
332 #ifdef CONFIG_PROC_FS
333 struct proc_dir_entry
*proc_entry
; /* proc entry */
334 char *proc_name
; /* proc entry name */
336 struct list_head dev_list
; /* linkage */
340 /* OF: send_Oam Flags */
342 #define ATM_OF_IMMED 1 /* Attempt immediate delivery */
343 #define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
347 * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
350 struct atmdev_ops
{ /* only send is required */
351 void (*dev_close
)(struct atm_dev
*dev
);
352 int (*open
)(struct atm_vcc
*vcc
);
353 void (*close
)(struct atm_vcc
*vcc
);
354 int (*ioctl
)(struct atm_dev
*dev
,unsigned int cmd
,void __user
*arg
);
355 int (*getsockopt
)(struct atm_vcc
*vcc
,int level
,int optname
,
356 void __user
*optval
,int optlen
);
357 int (*setsockopt
)(struct atm_vcc
*vcc
,int level
,int optname
,
358 void __user
*optval
,int optlen
);
359 int (*send
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
);
360 int (*send_oam
)(struct atm_vcc
*vcc
,void *cell
,int flags
);
361 void (*phy_put
)(struct atm_dev
*dev
,unsigned char value
,
363 unsigned char (*phy_get
)(struct atm_dev
*dev
,unsigned long addr
);
364 int (*change_qos
)(struct atm_vcc
*vcc
,struct atm_qos
*qos
,int flags
);
365 int (*proc_read
)(struct atm_dev
*dev
,loff_t
*pos
,char *page
);
366 struct module
*owner
;
370 int (*start
)(struct atm_dev
*dev
);
371 int (*ioctl
)(struct atm_dev
*dev
,unsigned int cmd
,void __user
*arg
);
372 void (*interrupt
)(struct atm_dev
*dev
);
373 int (*stop
)(struct atm_dev
*dev
);
376 struct atm_skb_data
{
377 struct atm_vcc
*vcc
; /* ATM VCC */
378 unsigned long atm_options
; /* ATM layer options */
381 #define VCC_HTABLE_SIZE 32
383 extern struct hlist_head vcc_hash
[VCC_HTABLE_SIZE
];
384 extern rwlock_t vcc_sklist_lock
;
386 #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
388 struct atm_dev
*atm_dev_register(const char *type
,const struct atmdev_ops
*ops
,
389 int number
,unsigned long *flags
); /* number == -1: pick first available */
390 struct atm_dev
*atm_dev_lookup(int number
);
391 void atm_dev_deregister(struct atm_dev
*dev
);
392 void shutdown_atm_dev(struct atm_dev
*dev
);
393 void vcc_insert_socket(struct sock
*sk
);
394 void vcc_remove_socket(struct sock
*sk
);
398 * This is approximately the algorithm used by alloc_skb.
402 static inline int atm_guess_pdu2truesize(int size
)
404 return (SKB_DATA_ALIGN(size
) + sizeof(struct skb_shared_info
));
408 static inline void atm_force_charge(struct atm_vcc
*vcc
,int truesize
)
410 atomic_add(truesize
, &vcc
->sk
->sk_rmem_alloc
);
414 static inline void atm_return(struct atm_vcc
*vcc
,int truesize
)
416 atomic_sub(truesize
, &vcc
->sk
->sk_rmem_alloc
);
420 static inline int atm_may_send(struct atm_vcc
*vcc
,unsigned int size
)
422 return (size
+ atomic_read(&vcc
->sk
->sk_wmem_alloc
)) <
427 static inline void atm_dev_hold(struct atm_dev
*dev
)
429 atomic_inc(&dev
->refcnt
);
433 static inline void atm_dev_put(struct atm_dev
*dev
)
435 atomic_dec(&dev
->refcnt
);
437 if ((atomic_read(&dev
->refcnt
) == 1) &&
438 test_bit(ATM_DF_CLOSE
,&dev
->flags
))
439 shutdown_atm_dev(dev
);
443 int atm_charge(struct atm_vcc
*vcc
,int truesize
);
444 struct sk_buff
*atm_alloc_charge(struct atm_vcc
*vcc
,int pdu_size
,
446 int atm_pcr_goal(struct atm_trafprm
*tp
);
448 void vcc_release_async(struct atm_vcc
*vcc
, int reply
);
451 struct module
*owner
;
452 /* A module reference is kept if appropriate over this call.
453 * Return -ENOIOCTLCMD if you don't handle it. */
454 int (*ioctl
)(struct socket
*, unsigned int cmd
, unsigned long arg
);
455 struct list_head list
;
459 * register_atm_ioctl - register handler for ioctl operations
461 * Special (non-device) handlers of ioctl's should
462 * register here. If you're a normal device, you should
463 * set .ioctl in your atmdev_ops instead.
465 void register_atm_ioctl(struct atm_ioctl
*);
468 * deregister_atm_ioctl - remove the ioctl handler
470 void deregister_atm_ioctl(struct atm_ioctl
*);
472 #endif /* __KERNEL__ */