1 /* atmdev.h - ATM device driver declarations and various related items */
3 /* Written 1995-1999 by Werner Almesberger, EPFL LRC/ICA */
10 #include <linux/config.h>
11 #include <linux/atmioc.h>
16 #define ATM_OC3_PCR (155520000/270*260/8/53)
17 /* OC3 link rate: 155520000 bps
18 SONET overhead: /270*260 (9 section, 1 path)
20 max cell rate: 353207.547 cells/sec */
22 #define ATM_PDU_OVHD 0 /* number of bytes to charge against buffer
25 #define ATM_SD(s) ((s)->sk->protinfo.af_atm)
28 struct atm_aal_stats
{
29 long tx
,tx_err
; /* TX okay and errors */
30 long rx
,rx_err
; /* RX okay and errors */
31 long rx_drop
; /* RX out of memory */
35 struct atm_dev_stats
{
36 struct atm_aal_stats aal0
;
37 struct atm_aal_stats aal34
;
38 struct atm_aal_stats aal5
;
42 #define ATM_GETLINKRATE _IOW('a',ATMIOC_ITF+1,struct atmif_sioc)
44 #define ATM_GETNAMES _IOW('a',ATMIOC_ITF+3,struct atm_iobuf)
45 /* get interface names (numbers) */
46 #define ATM_GETTYPE _IOW('a',ATMIOC_ITF+4,struct atmif_sioc)
47 /* get interface type name */
48 #define ATM_GETESI _IOW('a',ATMIOC_ITF+5,struct atmif_sioc)
49 /* get interface ESI */
50 #define ATM_GETADDR _IOW('a',ATMIOC_ITF+6,struct atmif_sioc)
51 /* get itf's local ATM addr. list */
52 #define ATM_RSTADDR _IOW('a',ATMIOC_ITF+7,struct atmif_sioc)
53 /* reset itf's ATM address list */
54 #define ATM_ADDADDR _IOW('a',ATMIOC_ITF+8,struct atmif_sioc)
55 /* add a local ATM address */
56 #define ATM_DELADDR _IOW('a',ATMIOC_ITF+9,struct atmif_sioc)
57 /* remove a local ATM address */
58 #define ATM_GETCIRANGE _IOW('a',ATMIOC_ITF+10,struct atmif_sioc)
59 /* get connection identifier range */
60 #define ATM_SETCIRANGE _IOW('a',ATMIOC_ITF+11,struct atmif_sioc)
61 /* set connection identifier range */
62 #define ATM_SETESI _IOW('a',ATMIOC_ITF+12,struct atmif_sioc)
63 /* set interface ESI */
64 #define ATM_SETESIF _IOW('a',ATMIOC_ITF+13,struct atmif_sioc)
65 /* force interface ESI */
66 #define ATM_GETSTAT _IOW('a',ATMIOC_SARCOM+0,struct atmif_sioc)
67 /* get AAL layer statistics */
68 #define ATM_GETSTATZ _IOW('a',ATMIOC_SARCOM+1,struct atmif_sioc)
69 /* get AAL layer statistics and zero */
70 #define ATM_SETSC _IOW('a',ATMIOC_SPECIAL+1,int)
71 /* enable or disable single-copy */
74 #define ATM_ITFTYP_LEN 8 /* maximum length of interface type name */
83 /* for ATM_GETCIRANGE / ATM_SETCIRANGE */
85 #define ATM_CI_MAX -1 /* use maximum range of VPI/VCI */
88 char vpi_bits
; /* 1..8, ATM_CI_MAX (-1) for maximum */
89 char vci_bits
; /* 1..16, ATM_CI_MAX (-1) for maximum */
92 /* for ATM_SETSC; actually taken from the ATM_VF number space */
94 #define ATM_SC_RX 1024 /* enable RX single-copy */
95 #define ATM_SC_TX 2048 /* enable TX single-copy */
97 #define ATM_BACKLOG_DEFAULT 32 /* if we get more, we're likely to time out
100 /* MF: change_qos (Modify) flags */
102 #define ATM_MF_IMMED 1 /* Block until change is effective */
103 #define ATM_MF_INC_RSV 2 /* Change reservation on increase */
104 #define ATM_MF_INC_SHP 4 /* Change shaping on increase */
105 #define ATM_MF_DEC_RSV 8 /* Change reservation on decrease */
106 #define ATM_MF_DEC_SHP 16 /* Change shaping on decrease */
107 #define ATM_MF_BWD 32 /* Set the backward direction parameters */
109 #define ATM_MF_SET (ATM_MF_INC_RSV | ATM_MF_INC_SHP | ATM_MF_DEC_RSV | \
110 ATM_MF_DEC_SHP | ATM_MF_BWD)
113 * ATM_VS_* are used to express VC state in a human-friendly way.
116 #define ATM_VS_IDLE 0 /* VC is not used */
117 #define ATM_VS_CONNECTED 1 /* VC is connected */
118 #define ATM_VS_CLOSING 2 /* VC is closing */
119 #define ATM_VS_LISTEN 3 /* VC is listening for incoming setups */
120 #define ATM_VS_INUSE 4 /* VC is in use (registered with atmsigd) */
121 #define ATM_VS_BOUND 5 /* VC is bound */
123 #define ATM_VS2TXT_MAP \
124 "IDLE", "CONNECTED", "CLOSING", "LISTEN", "INUSE", "BOUND"
129 #include <linux/sched.h> /* wait_queue_head_t */
130 #include <linux/time.h> /* struct timeval */
131 #include <linux/net.h>
132 #include <linux/skbuff.h> /* struct sk_buff */
133 #include <linux/atm.h>
134 #include <linux/uio.h>
135 #include <asm/atomic.h>
137 #ifdef CONFIG_PROC_FS
138 #include <linux/proc_fs.h>
142 #define ATM_VF_ADDR 1 /* Address is in use. Set by anybody, cleared
144 #define ATM_VF_READY 2 /* VC is ready to transfer data. Set by device
145 driver, cleared by anybody. */
146 #define ATM_VF_PARTIAL 4 /* resources are bound to PVC (partial PVC
147 setup), controlled by socket layer */
148 #define ATM_VF_BOUND 16384 /* local SAP is set, controlled by SVC socket
150 #define ATM_VF_REGIS 8 /* registered with demon, controlled by SVC
152 #define ATM_VF_RELEASED 16 /* demon has indicated/requested release,
153 controlled by SVC socket layer */
154 #define ATM_VF_HASQOS 32 /* QOS parameters have been set */
155 #define ATM_VF_LISTEN 64 /* socket is used for listening */
156 #define ATM_VF_META 128 /* SVC socket isn't used for normal data
157 traffic and doesn't depend on signaling
159 #define ATM_VF_AQREL 256 /* Arequipa VC is being released */
160 #define ATM_VF_AQDANG 512 /* VC is in Arequipa's dangling list */
161 #define ATM_VF_SCRX ATM_SC_RX /* 1024; allow single-copy in the RX dir. */
162 #define ATM_VF_SCTX ATM_SC_TX /* 2048; allow single-copy in the TX dir. */
163 #define ATM_VF_SESSION 4096 /* VCC is p2mp session control descriptor */
164 #define ATM_VF_HASSAP 8192 /* SAP has been set */
165 #define ATM_VF_CLOSE 32768 /* asynchronous close - treat like VF_RELEASED*/
167 #define ATM_VF2VS(flags) \
168 ((flags) & ATM_VF_READY ? ATM_VS_CONNECTED : \
169 (flags) & ATM_VF_RELEASED ? ATM_VS_CLOSING : \
170 (flags) & ATM_VF_LISTEN ? ATM_VS_LISTEN : \
171 (flags) & ATM_VF_REGIS ? ATM_VS_INUSE : \
172 (flags) & ATM_VF_BOUND ? ATM_VS_BOUND : ATM_VS_IDLE)
174 #define ATM_DF_CLOSE 1 /* close device when last VCC is closed */
176 #define ATM_PHY_SIG_LOST 0 /* no carrier/light */
177 #define ATM_PHY_SIG_UNKNOWN 1 /* carrier/light status is unknown */
178 #define ATM_PHY_SIG_FOUND 2 /* carrier/light okay */
180 #define ATM_ATMOPT_CLP 1 /* set CLP bit */
184 unsigned short flags
; /* VCC flags (ATM_VF_*) */
185 unsigned char family
; /* address family; 0 if unused */
186 short vpi
; /* VPI and VCI (types must be equal */
189 unsigned long aal_options
; /* AAL layer options */
190 unsigned long atm_options
; /* ATM layer options */
191 struct atm_dev
*dev
; /* device back pointer */
192 struct atm_qos qos
; /* QOS */
193 struct atm_sap sap
; /* SAP */
194 unsigned long tx_quota
,rx_quota
; /* buffer quotas */
195 atomic_t tx_inuse
,rx_inuse
; /* buffer space in use */
196 void (*push
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
);
197 void (*pop
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
); /* optional */
198 struct sk_buff
*(*alloc_tx
)(struct atm_vcc
*vcc
,unsigned int size
);
199 /* TX allocation routine - can be */
200 /* modified by protocol or by driver.*/
201 /* NOTE: this interface will change */
202 int (*push_oam
)(struct atm_vcc
*vcc
,void *cell
);
203 void *dev_data
; /* per-device data */
204 void *proto_data
; /* per-protocol data */
205 struct timeval timestamp
; /* AAL timestamps */
206 struct sk_buff_head recvq
; /* receive queue */
207 struct atm_aal_stats
*stats
; /* pointer to AAL stats group */
208 wait_queue_head_t sleep
; /* if socket is busy */
209 wait_queue_head_t wsleep
; /* if waiting for write buffer space */
210 struct atm_vcc
*prev
,*next
;
211 /* SVC part --- may move later ------------------------------------- */
212 short itf
; /* interface number */
213 struct sockaddr_atmsvc local
;
214 struct sockaddr_atmsvc remote
;
215 void (*callback
)(struct atm_vcc
*vcc
);
216 struct sk_buff_head listenq
;
217 int backlog_quota
; /* number of connection requests we */
218 /* can still accept */
219 int reply
; /* also used by ATMTCP */
220 /* Multipoint part ------------------------------------------------- */
221 struct atm_vcc
*session
; /* session VCC descriptor */
222 /* Other stuff ----------------------------------------------------- */
223 void *user_back
; /* user backlink - not touched */
227 struct atm_dev_addr
{
228 struct sockaddr_atmsvc addr
; /* ATM address */
229 struct atm_dev_addr
*next
; /* next address */
234 const struct atmdev_ops
*ops
; /* device operations; NULL if unused */
235 const struct atmphy_ops
*phy
; /* PHY operations, may be undefined */
237 const char *type
; /* device type name */
238 int number
; /* device index */
239 struct atm_vcc
*vccs
; /* VCC table (or NULL) */
240 struct atm_vcc
*last
; /* last VCC (or undefined) */
241 void *dev_data
; /* per-device data */
242 void *phy_data
; /* private PHY date */
243 unsigned long flags
; /* device flags (ATM_DF_*) */
244 struct atm_dev_addr
*local
; /* local ATM addresses */
245 unsigned char esi
[ESI_LEN
]; /* ESI ("MAC" addr) */
246 struct atm_cirange ci_range
; /* VPI/VCI range */
247 struct atm_dev_stats stats
; /* statistics */
248 char signal
; /* signal status (ATM_PHY_SIG_*) */
249 int link_rate
; /* link rate (default: OC3) */
250 #ifdef CONFIG_PROC_FS
251 struct proc_dir_entry
*proc_entry
; /* proc entry */
252 char *proc_name
; /* proc entry name */
254 struct atm_dev
*prev
,*next
; /* linkage */
259 * ioctl, getsockopt, setsockopt, and sg_send are optional and can be set to
262 /* OF: send_Oam Flags */
264 #define ATM_OF_IMMED 1 /* Attempt immediate delivery */
265 #define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
267 struct atmdev_ops
{ /* only send is required */
268 void (*dev_close
)(struct atm_dev
*dev
);
269 int (*open
)(struct atm_vcc
*vcc
,short vpi
,int vci
);
270 void (*close
)(struct atm_vcc
*vcc
);
271 int (*ioctl
)(struct atm_dev
*dev
,unsigned int cmd
,void *arg
);
272 int (*getsockopt
)(struct atm_vcc
*vcc
,int level
,int optname
,
273 void *optval
,int optlen
);
274 int (*setsockopt
)(struct atm_vcc
*vcc
,int level
,int optname
,
275 void *optval
,int optlen
);
276 int (*send
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
);
277 int (*sg_send
)(struct atm_vcc
*vcc
,unsigned long start
,
279 #if 0 /* keep the current hack for now */
280 int (*send_iovec
)(struct atm_vcc
*vcc
,struct iovec
*iov
,int size
,
281 void (*discard
)(struct atm_vcc
*vcc
,void *user
),void *user
);
283 int (*send_oam
)(struct atm_vcc
*vcc
,void *cell
,int flags
);
284 void (*phy_put
)(struct atm_dev
*dev
,unsigned char value
,
286 unsigned char (*phy_get
)(struct atm_dev
*dev
,unsigned long addr
);
287 void (*feedback
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
,
288 unsigned long start
,unsigned long dest
,int len
);
289 int (*change_qos
)(struct atm_vcc
*vcc
,struct atm_qos
*qos
,int flags
);
290 void (*free_rx_skb
)(struct atm_vcc
*vcc
, struct sk_buff
*skb
);
291 /* @@@ temporary hack */
292 int (*proc_read
)(struct atm_dev
*dev
,loff_t
*pos
,char *page
);
297 int (*start
)(struct atm_dev
*dev
);
298 int (*ioctl
)(struct atm_dev
*dev
,unsigned int cmd
,void *arg
);
299 void (*interrupt
)(struct atm_dev
*dev
);
302 struct atm_skb_data
{
303 struct atm_vcc
*vcc
; /* ATM VCC */
304 int iovcnt
; /* 0 for "normal" operation */
305 unsigned long atm_options
; /* ATM layer options */
308 #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
310 struct atm_dev
*atm_dev_register(const char *type
,const struct atmdev_ops
*ops
,
311 int number
,unsigned long flags
); /* number == -1: pick first available */
312 struct atm_dev
*atm_find_dev(int number
);
313 void atm_dev_deregister(struct atm_dev
*dev
);
314 void shutdown_atm_dev(struct atm_dev
*dev
);
315 void bind_vcc(struct atm_vcc
*vcc
,struct atm_dev
*dev
);
319 * This is approximately the algorithm used by alloc_skb.
323 static __inline__
int atm_guess_pdu2truesize(int pdu_size
)
325 return ((pdu_size
+15) & ~15) + sizeof(struct sk_buff
);
329 static __inline__
void atm_force_charge(struct atm_vcc
*vcc
,int truesize
)
331 atomic_add(truesize
+ATM_PDU_OVHD
,&vcc
->rx_inuse
);
335 static __inline__
void atm_return(struct atm_vcc
*vcc
,int truesize
)
337 atomic_sub(truesize
+ATM_PDU_OVHD
,&vcc
->rx_inuse
);
341 int atm_charge(struct atm_vcc
*vcc
,int truesize
);
342 struct sk_buff
*atm_alloc_charge(struct atm_vcc
*vcc
,int pdu_size
,
344 int atm_find_ci(struct atm_vcc
*vcc
,short *vpi
,int *vci
);
345 int atm_pcr_goal(struct atm_trafprm
*tp
);
347 void atm_async_release_vcc(struct atm_vcc
*vcc
,int reply
);
349 #endif /* __KERNEL__ */