Merge branch 'for-john' of git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211
[deliverable/linux.git] / include / linux / atmdev.h
1 /* atmdev.h - ATM device driver declarations and various related items */
2 #ifndef LINUX_ATMDEV_H
3 #define LINUX_ATMDEV_H
4
5
6 #include <linux/wait.h> /* wait_queue_head_t */
7 #include <linux/time.h> /* struct timeval */
8 #include <linux/net.h>
9 #include <linux/bug.h>
10 #include <linux/skbuff.h> /* struct sk_buff */
11 #include <linux/uio.h>
12 #include <net/sock.h>
13 #include <linux/atomic.h>
14 #include <uapi/linux/atmdev.h>
15
16 #ifdef CONFIG_PROC_FS
17 #include <linux/proc_fs.h>
18
19 extern struct proc_dir_entry *atm_proc_root;
20 #endif
21
22 #ifdef CONFIG_COMPAT
23 #include <linux/compat.h>
24 struct compat_atm_iobuf {
25 int length;
26 compat_uptr_t buffer;
27 };
28 #endif
29
30 struct k_atm_aal_stats {
31 #define __HANDLE_ITEM(i) atomic_t i
32 __AAL_STAT_ITEMS
33 #undef __HANDLE_ITEM
34 };
35
36
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;
41 };
42
43 struct device;
44
45 enum {
46 ATM_VF_ADDR, /* Address is in use. Set by anybody, cleared
47 by device driver. */
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
53 socket layer */
54 ATM_VF_BOUND, /* local SAP is set, controlled by SVC socket
55 layer */
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
62 to be available */
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 */
68 };
69
70
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)
77
78
79 enum {
80 ATM_DF_REMOVED, /* device was removed from atm_devs list */
81 };
82
83
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 */
87
88 #define ATM_ATMOPT_CLP 1 /* set CLP bit */
89
90 struct atm_vcc {
91 /* struct sock has to be the first member of atm_vcc */
92 struct sock sk;
93 unsigned long flags; /* VCC flags (ATM_VF_*) */
94 short vpi; /* VPI and VCI (types must be equal */
95 /* with sockaddr) */
96 int vci;
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 /* SVC part --- may move later ------------------------------------- */
110 short itf; /* interface number */
111 struct sockaddr_atmsvc local;
112 struct sockaddr_atmsvc remote;
113 /* Multipoint part ------------------------------------------------- */
114 struct atm_vcc *session; /* session VCC descriptor */
115 /* Other stuff ----------------------------------------------------- */
116 void *user_back; /* user backlink - not touched by */
117 /* native ATM stack. Currently used */
118 /* by CLIP and sch_atm. */
119 };
120
121 static inline struct atm_vcc *atm_sk(struct sock *sk)
122 {
123 return (struct atm_vcc *)sk;
124 }
125
126 static inline struct atm_vcc *ATM_SD(struct socket *sock)
127 {
128 return atm_sk(sock->sk);
129 }
130
131 static inline struct sock *sk_atm(struct atm_vcc *vcc)
132 {
133 return (struct sock *)vcc;
134 }
135
136 struct atm_dev_addr {
137 struct sockaddr_atmsvc addr; /* ATM address */
138 struct list_head entry; /* next address */
139 };
140
141 enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
142
143 struct atm_dev {
144 const struct atmdev_ops *ops; /* device operations; NULL if unused */
145 const struct atmphy_ops *phy; /* PHY operations, may be undefined */
146 /* (NULL) */
147 const char *type; /* device type name */
148 int number; /* device index */
149 void *dev_data; /* per-device data */
150 void *phy_data; /* private PHY date */
151 unsigned long flags; /* device flags (ATM_DF_*) */
152 struct list_head local; /* local ATM addresses */
153 struct list_head lecs; /* LECS ATM addresses learned via ILMI */
154 unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
155 struct atm_cirange ci_range; /* VPI/VCI range */
156 struct k_atm_dev_stats stats; /* statistics */
157 char signal; /* signal status (ATM_PHY_SIG_*) */
158 int link_rate; /* link rate (default: OC3) */
159 atomic_t refcnt; /* reference count */
160 spinlock_t lock; /* protect internal members */
161 #ifdef CONFIG_PROC_FS
162 struct proc_dir_entry *proc_entry; /* proc entry */
163 char *proc_name; /* proc entry name */
164 #endif
165 struct device class_dev; /* sysfs device */
166 struct list_head dev_list; /* linkage */
167 };
168
169
170 /* OF: send_Oam Flags */
171
172 #define ATM_OF_IMMED 1 /* Attempt immediate delivery */
173 #define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
174
175
176 /*
177 * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
178 */
179
180 struct atmdev_ops { /* only send is required */
181 void (*dev_close)(struct atm_dev *dev);
182 int (*open)(struct atm_vcc *vcc);
183 void (*close)(struct atm_vcc *vcc);
184 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
185 #ifdef CONFIG_COMPAT
186 int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
187 void __user *arg);
188 #endif
189 int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
190 void __user *optval,int optlen);
191 int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
192 void __user *optval,unsigned int optlen);
193 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
194 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
195 void (*phy_put)(struct atm_dev *dev,unsigned char value,
196 unsigned long addr);
197 unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
198 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
199 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
200 struct module *owner;
201 };
202
203 struct atmphy_ops {
204 int (*start)(struct atm_dev *dev);
205 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
206 void (*interrupt)(struct atm_dev *dev);
207 int (*stop)(struct atm_dev *dev);
208 };
209
210 struct atm_skb_data {
211 struct atm_vcc *vcc; /* ATM VCC */
212 unsigned long atm_options; /* ATM layer options */
213 };
214
215 #define VCC_HTABLE_SIZE 32
216
217 extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
218 extern rwlock_t vcc_sklist_lock;
219
220 #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
221
222 struct atm_dev *atm_dev_register(const char *type, struct device *parent,
223 const struct atmdev_ops *ops,
224 int number, /* -1 == pick first available */
225 unsigned long *flags);
226 struct atm_dev *atm_dev_lookup(int number);
227 void atm_dev_deregister(struct atm_dev *dev);
228
229 /* atm_dev_signal_change
230 *
231 * Propagate lower layer signal change in atm_dev->signal to netdevice.
232 * The event will be sent via a notifier call chain.
233 */
234 void atm_dev_signal_change(struct atm_dev *dev, char signal);
235
236 void vcc_insert_socket(struct sock *sk);
237
238 void atm_dev_release_vccs(struct atm_dev *dev);
239
240
241 static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
242 {
243 atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
244 }
245
246
247 static inline void atm_return(struct atm_vcc *vcc,int truesize)
248 {
249 atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
250 }
251
252
253 static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
254 {
255 return (size + atomic_read(&sk_atm(vcc)->sk_wmem_alloc)) <
256 sk_atm(vcc)->sk_sndbuf;
257 }
258
259
260 static inline void atm_dev_hold(struct atm_dev *dev)
261 {
262 atomic_inc(&dev->refcnt);
263 }
264
265
266 static inline void atm_dev_put(struct atm_dev *dev)
267 {
268 if (atomic_dec_and_test(&dev->refcnt)) {
269 BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
270 if (dev->ops->dev_close)
271 dev->ops->dev_close(dev);
272 put_device(&dev->class_dev);
273 }
274 }
275
276
277 int atm_charge(struct atm_vcc *vcc,int truesize);
278 struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
279 gfp_t gfp_flags);
280 int atm_pcr_goal(const struct atm_trafprm *tp);
281
282 void vcc_release_async(struct atm_vcc *vcc, int reply);
283
284 struct atm_ioctl {
285 struct module *owner;
286 /* A module reference is kept if appropriate over this call.
287 * Return -ENOIOCTLCMD if you don't handle it. */
288 int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
289 struct list_head list;
290 };
291
292 /**
293 * register_atm_ioctl - register handler for ioctl operations
294 *
295 * Special (non-device) handlers of ioctl's should
296 * register here. If you're a normal device, you should
297 * set .ioctl in your atmdev_ops instead.
298 */
299 void register_atm_ioctl(struct atm_ioctl *);
300
301 /**
302 * deregister_atm_ioctl - remove the ioctl handler
303 */
304 void deregister_atm_ioctl(struct atm_ioctl *);
305
306
307 /* register_atmdevice_notifier - register atm_dev notify events
308 *
309 * Clients like br2684 will register notify events
310 * Currently we notify of signal found/lost
311 */
312 int register_atmdevice_notifier(struct notifier_block *nb);
313 void unregister_atmdevice_notifier(struct notifier_block *nb);
314
315 #endif
This page took 0.082602 seconds and 6 git commands to generate.