1 /* atmdev.h - ATM device driver declarations and various related items */
6 #include <linux/wait.h> /* wait_queue_head_t */
7 #include <linux/time.h> /* struct timeval */
10 #include <linux/skbuff.h> /* struct sk_buff */
11 #include <linux/uio.h>
13 #include <linux/atomic.h>
14 #include <uapi/linux/atmdev.h>
17 #include <linux/proc_fs.h>
19 extern struct proc_dir_entry
*atm_proc_root
;
23 #include <linux/compat.h>
24 struct compat_atm_iobuf
{
30 struct k_atm_aal_stats
{
31 #define __HANDLE_ITEM(i) atomic_t i
37 struct k_atm_dev_stats
{
38 struct k_atm_aal_stats aal0
;
39 struct k_atm_aal_stats aal34
;
40 struct k_atm_aal_stats aal5
;
46 ATM_VF_ADDR
, /* Address is in use. Set by anybody, cleared
48 ATM_VF_READY
, /* VC is ready to transfer data. Set by device
49 driver, cleared by anybody. */
50 ATM_VF_PARTIAL
, /* resources are bound to PVC (partial PVC
51 setup), controlled by socket layer */
52 ATM_VF_REGIS
, /* registered with demon, controlled by SVC
54 ATM_VF_BOUND
, /* local SAP is set, controlled by SVC socket
56 ATM_VF_RELEASED
, /* demon has indicated/requested release,
57 controlled by SVC socket layer */
58 ATM_VF_HASQOS
, /* QOS parameters have been set */
59 ATM_VF_LISTEN
, /* socket is used for listening */
60 ATM_VF_META
, /* SVC socket isn't used for normal data
61 traffic and doesn't depend on signaling
63 ATM_VF_SESSION
, /* VCC is p2mp session control descriptor */
64 ATM_VF_HASSAP
, /* SAP has been set */
65 ATM_VF_CLOSE
, /* asynchronous close - treat like VF_RELEASED*/
66 ATM_VF_WAITING
, /* waiting for reply from sigd */
67 ATM_VF_IS_CLIP
, /* in use by CLIP protocol */
71 #define ATM_VF2VS(flags) \
72 (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
73 test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
74 test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
75 test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
76 test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
80 ATM_DF_REMOVED
, /* device was removed from atm_devs list */
84 #define ATM_PHY_SIG_LOST 0 /* no carrier/light */
85 #define ATM_PHY_SIG_UNKNOWN 1 /* carrier/light status is unknown */
86 #define ATM_PHY_SIG_FOUND 2 /* carrier/light okay */
88 #define ATM_ATMOPT_CLP 1 /* set CLP bit */
91 /* struct sock has to be the first member of atm_vcc */
93 unsigned long flags
; /* VCC flags (ATM_VF_*) */
94 short vpi
; /* VPI and VCI (types must be equal */
97 unsigned long aal_options
; /* AAL layer options */
98 unsigned long atm_options
; /* ATM layer options */
99 struct atm_dev
*dev
; /* device back pointer */
100 struct atm_qos qos
; /* QOS */
101 struct atm_sap sap
; /* SAP */
102 void (*push
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
);
103 void (*pop
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
); /* optional */
104 int (*push_oam
)(struct atm_vcc
*vcc
,void *cell
);
105 int (*send
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
);
106 void *dev_data
; /* per-device data */
107 void *proto_data
; /* per-protocol data */
108 struct k_atm_aal_stats
*stats
; /* pointer to AAL stats group */
109 struct module
*owner
; /* owner of ->push function */
110 /* SVC part --- may move later ------------------------------------- */
111 short itf
; /* interface number */
112 struct sockaddr_atmsvc local
;
113 struct sockaddr_atmsvc remote
;
114 /* Multipoint part ------------------------------------------------- */
115 struct atm_vcc
*session
; /* session VCC descriptor */
116 /* Other stuff ----------------------------------------------------- */
117 void *user_back
; /* user backlink - not touched by */
118 /* native ATM stack. Currently used */
119 /* by CLIP and sch_atm. */
122 static inline struct atm_vcc
*atm_sk(struct sock
*sk
)
124 return (struct atm_vcc
*)sk
;
127 static inline struct atm_vcc
*ATM_SD(struct socket
*sock
)
129 return atm_sk(sock
->sk
);
132 static inline struct sock
*sk_atm(struct atm_vcc
*vcc
)
134 return (struct sock
*)vcc
;
137 struct atm_dev_addr
{
138 struct sockaddr_atmsvc addr
; /* ATM address */
139 struct list_head entry
; /* next address */
142 enum atm_addr_type_t
{ ATM_ADDR_LOCAL
, ATM_ADDR_LECS
};
145 const struct atmdev_ops
*ops
; /* device operations; NULL if unused */
146 const struct atmphy_ops
*phy
; /* PHY operations, may be undefined */
148 const char *type
; /* device type name */
149 int number
; /* device index */
150 void *dev_data
; /* per-device data */
151 void *phy_data
; /* private PHY date */
152 unsigned long flags
; /* device flags (ATM_DF_*) */
153 struct list_head local
; /* local ATM addresses */
154 struct list_head lecs
; /* LECS ATM addresses learned via ILMI */
155 unsigned char esi
[ESI_LEN
]; /* ESI ("MAC" addr) */
156 struct atm_cirange ci_range
; /* VPI/VCI range */
157 struct k_atm_dev_stats stats
; /* statistics */
158 char signal
; /* signal status (ATM_PHY_SIG_*) */
159 int link_rate
; /* link rate (default: OC3) */
160 atomic_t refcnt
; /* reference count */
161 spinlock_t lock
; /* protect internal members */
162 #ifdef CONFIG_PROC_FS
163 struct proc_dir_entry
*proc_entry
; /* proc entry */
164 char *proc_name
; /* proc entry name */
166 struct device class_dev
; /* sysfs device */
167 struct list_head dev_list
; /* linkage */
171 /* OF: send_Oam Flags */
173 #define ATM_OF_IMMED 1 /* Attempt immediate delivery */
174 #define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
178 * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
181 struct atmdev_ops
{ /* only send is required */
182 void (*dev_close
)(struct atm_dev
*dev
);
183 int (*open
)(struct atm_vcc
*vcc
);
184 void (*close
)(struct atm_vcc
*vcc
);
185 int (*ioctl
)(struct atm_dev
*dev
,unsigned int cmd
,void __user
*arg
);
187 int (*compat_ioctl
)(struct atm_dev
*dev
,unsigned int cmd
,
190 int (*getsockopt
)(struct atm_vcc
*vcc
,int level
,int optname
,
191 void __user
*optval
,int optlen
);
192 int (*setsockopt
)(struct atm_vcc
*vcc
,int level
,int optname
,
193 void __user
*optval
,unsigned int optlen
);
194 int (*send
)(struct atm_vcc
*vcc
,struct sk_buff
*skb
);
195 int (*send_oam
)(struct atm_vcc
*vcc
,void *cell
,int flags
);
196 void (*phy_put
)(struct atm_dev
*dev
,unsigned char value
,
198 unsigned char (*phy_get
)(struct atm_dev
*dev
,unsigned long addr
);
199 int (*change_qos
)(struct atm_vcc
*vcc
,struct atm_qos
*qos
,int flags
);
200 int (*proc_read
)(struct atm_dev
*dev
,loff_t
*pos
,char *page
);
201 struct module
*owner
;
205 int (*start
)(struct atm_dev
*dev
);
206 int (*ioctl
)(struct atm_dev
*dev
,unsigned int cmd
,void __user
*arg
);
207 void (*interrupt
)(struct atm_dev
*dev
);
208 int (*stop
)(struct atm_dev
*dev
);
211 struct atm_skb_data
{
212 struct atm_vcc
*vcc
; /* ATM VCC */
213 unsigned long atm_options
; /* ATM layer options */
216 #define VCC_HTABLE_SIZE 32
218 extern struct hlist_head vcc_hash
[VCC_HTABLE_SIZE
];
219 extern rwlock_t vcc_sklist_lock
;
221 #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
223 struct atm_dev
*atm_dev_register(const char *type
, struct device
*parent
,
224 const struct atmdev_ops
*ops
,
225 int number
, /* -1 == pick first available */
226 unsigned long *flags
);
227 struct atm_dev
*atm_dev_lookup(int number
);
228 void atm_dev_deregister(struct atm_dev
*dev
);
230 /* atm_dev_signal_change
232 * Propagate lower layer signal change in atm_dev->signal to netdevice.
233 * The event will be sent via a notifier call chain.
235 void atm_dev_signal_change(struct atm_dev
*dev
, char signal
);
237 void vcc_insert_socket(struct sock
*sk
);
239 void atm_dev_release_vccs(struct atm_dev
*dev
);
242 static inline void atm_force_charge(struct atm_vcc
*vcc
,int truesize
)
244 atomic_add(truesize
, &sk_atm(vcc
)->sk_rmem_alloc
);
248 static inline void atm_return(struct atm_vcc
*vcc
,int truesize
)
250 atomic_sub(truesize
, &sk_atm(vcc
)->sk_rmem_alloc
);
254 static inline int atm_may_send(struct atm_vcc
*vcc
,unsigned int size
)
256 return (size
+ atomic_read(&sk_atm(vcc
)->sk_wmem_alloc
)) <
257 sk_atm(vcc
)->sk_sndbuf
;
261 static inline void atm_dev_hold(struct atm_dev
*dev
)
263 atomic_inc(&dev
->refcnt
);
267 static inline void atm_dev_put(struct atm_dev
*dev
)
269 if (atomic_dec_and_test(&dev
->refcnt
)) {
270 BUG_ON(!test_bit(ATM_DF_REMOVED
, &dev
->flags
));
271 if (dev
->ops
->dev_close
)
272 dev
->ops
->dev_close(dev
);
273 put_device(&dev
->class_dev
);
278 int atm_charge(struct atm_vcc
*vcc
,int truesize
);
279 struct sk_buff
*atm_alloc_charge(struct atm_vcc
*vcc
,int pdu_size
,
281 int atm_pcr_goal(const struct atm_trafprm
*tp
);
283 void vcc_release_async(struct atm_vcc
*vcc
, int reply
);
286 struct module
*owner
;
287 /* A module reference is kept if appropriate over this call.
288 * Return -ENOIOCTLCMD if you don't handle it. */
289 int (*ioctl
)(struct socket
*, unsigned int cmd
, unsigned long arg
);
290 struct list_head list
;
294 * register_atm_ioctl - register handler for ioctl operations
296 * Special (non-device) handlers of ioctl's should
297 * register here. If you're a normal device, you should
298 * set .ioctl in your atmdev_ops instead.
300 void register_atm_ioctl(struct atm_ioctl
*);
303 * deregister_atm_ioctl - remove the ioctl handler
305 void deregister_atm_ioctl(struct atm_ioctl
*);
308 /* register_atmdevice_notifier - register atm_dev notify events
310 * Clients like br2684 will register notify events
311 * Currently we notify of signal found/lost
313 int register_atmdevice_notifier(struct notifier_block
*nb
);
314 void unregister_atmdevice_notifier(struct notifier_block
*nb
);