blob: c1da539f5e28a965702c39d21375923e8271f67f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* atmdev.h - ATM device driver declarations and various related items */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef LINUX_ATMDEV_H
3#define LINUX_ATMDEV_H
4
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/wait.h> /* wait_queue_head_t */
7#include <linux/time.h> /* struct timeval */
8#include <linux/net.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -05009#include <linux/bug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/skbuff.h> /* struct sk_buff */
11#include <linux/uio.h>
12#include <net/sock.h>
Arun Sharma600634972011-07-26 16:09:06 -070013#include <linux/atomic.h>
David Howells607ca462012-10-13 10:46:48 +010014#include <uapi/linux/atmdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#ifdef CONFIG_PROC_FS
17#include <linux/proc_fs.h>
18
19extern struct proc_dir_entry *atm_proc_root;
20#endif
21
David Woodhouse8865c412008-12-03 22:12:38 -080022#ifdef CONFIG_COMPAT
23#include <linux/compat.h>
24struct compat_atm_iobuf {
25 int length;
26 compat_uptr_t buffer;
27};
28#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30struct k_atm_aal_stats {
31#define __HANDLE_ITEM(i) atomic_t i
32 __AAL_STAT_ITEMS
33#undef __HANDLE_ITEM
34};
35
36
37struct 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
Paul Gortmaker313162d2012-01-30 11:46:54 -050043struct device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45enum {
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
79enum {
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -080080 ATM_DF_REMOVED, /* device was removed from atm_devs list */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
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
90struct 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 */
David Woodhousec971f082012-11-28 00:03:11 +0000102 void (*release_cb)(struct atm_vcc *vcc); /* release_sock callback */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
104 void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
105 int (*push_oam)(struct atm_vcc *vcc,void *cell);
106 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
107 void *dev_data; /* per-device data */
108 void *proto_data; /* per-protocol data */
109 struct k_atm_aal_stats *stats; /* pointer to AAL stats group */
Krzysztof Mazurec809bd2012-11-06 23:16:57 +0100110 struct module *owner; /* owner of ->push function */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 /* SVC part --- may move later ------------------------------------- */
112 short itf; /* interface number */
113 struct sockaddr_atmsvc local;
114 struct sockaddr_atmsvc remote;
115 /* Multipoint part ------------------------------------------------- */
116 struct atm_vcc *session; /* session VCC descriptor */
117 /* Other stuff ----------------------------------------------------- */
118 void *user_back; /* user backlink - not touched by */
119 /* native ATM stack. Currently used */
120 /* by CLIP and sch_atm. */
121};
122
123static inline struct atm_vcc *atm_sk(struct sock *sk)
124{
125 return (struct atm_vcc *)sk;
126}
127
128static inline struct atm_vcc *ATM_SD(struct socket *sock)
129{
130 return atm_sk(sock->sk);
131}
132
133static inline struct sock *sk_atm(struct atm_vcc *vcc)
134{
135 return (struct sock *)vcc;
136}
137
138struct atm_dev_addr {
139 struct sockaddr_atmsvc addr; /* ATM address */
140 struct list_head entry; /* next address */
141};
142
Eric Kinzie0f21ba72005-10-06 22:19:28 -0700143enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145struct atm_dev {
146 const struct atmdev_ops *ops; /* device operations; NULL if unused */
147 const struct atmphy_ops *phy; /* PHY operations, may be undefined */
148 /* (NULL) */
149 const char *type; /* device type name */
150 int number; /* device index */
151 void *dev_data; /* per-device data */
152 void *phy_data; /* private PHY date */
153 unsigned long flags; /* device flags (ATM_DF_*) */
154 struct list_head local; /* local ATM addresses */
Eric Kinzie0f21ba72005-10-06 22:19:28 -0700155 struct list_head lecs; /* LECS ATM addresses learned via ILMI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
157 struct atm_cirange ci_range; /* VPI/VCI range */
158 struct k_atm_dev_stats stats; /* statistics */
159 char signal; /* signal status (ATM_PHY_SIG_*) */
160 int link_rate; /* link rate (default: OC3) */
161 atomic_t refcnt; /* reference count */
162 spinlock_t lock; /* protect internal members */
163#ifdef CONFIG_PROC_FS
164 struct proc_dir_entry *proc_entry; /* proc entry */
165 char *proc_name; /* proc entry name */
166#endif
Kay Sieversef395922007-12-30 23:16:06 -0800167 struct device class_dev; /* sysfs device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 struct list_head dev_list; /* linkage */
169};
170
171
172/* OF: send_Oam Flags */
173
174#define ATM_OF_IMMED 1 /* Attempt immediate delivery */
175#define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
176
177
178/*
179 * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
180 */
181
182struct atmdev_ops { /* only send is required */
183 void (*dev_close)(struct atm_dev *dev);
184 int (*open)(struct atm_vcc *vcc);
185 void (*close)(struct atm_vcc *vcc);
186 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
David Woodhouse8865c412008-12-03 22:12:38 -0800187#ifdef CONFIG_COMPAT
188 int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
189 void __user *arg);
190#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
192 void __user *optval,int optlen);
193 int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700194 void __user *optval,unsigned int optlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
196 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
197 void (*phy_put)(struct atm_dev *dev,unsigned char value,
198 unsigned long addr);
199 unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
200 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
201 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
202 struct module *owner;
203};
204
205struct atmphy_ops {
206 int (*start)(struct atm_dev *dev);
207 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
208 void (*interrupt)(struct atm_dev *dev);
209 int (*stop)(struct atm_dev *dev);
210};
211
212struct atm_skb_data {
213 struct atm_vcc *vcc; /* ATM VCC */
214 unsigned long atm_options; /* ATM layer options */
215};
216
217#define VCC_HTABLE_SIZE 32
218
219extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
220extern rwlock_t vcc_sklist_lock;
221
222#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
223
Dan Williamsd9ca6762010-12-08 19:40:47 +0000224struct atm_dev *atm_dev_register(const char *type, struct device *parent,
225 const struct atmdev_ops *ops,
226 int number, /* -1 == pick first available */
227 unsigned long *flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228struct atm_dev *atm_dev_lookup(int number);
229void atm_dev_deregister(struct atm_dev *dev);
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000230
231/* atm_dev_signal_change
232 *
233 * Propagate lower layer signal change in atm_dev->signal to netdevice.
234 * The event will be sent via a notifier call chain.
235 */
236void atm_dev_signal_change(struct atm_dev *dev, char signal);
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238void vcc_insert_socket(struct sock *sk);
239
Philip A. Prindevillec0312352011-03-30 13:17:04 +0000240void atm_dev_release_vccs(struct atm_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
244{
245 atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
246}
247
248
249static inline void atm_return(struct atm_vcc *vcc,int truesize)
250{
251 atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
252}
253
254
255static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
256{
257 return (size + atomic_read(&sk_atm(vcc)->sk_wmem_alloc)) <
258 sk_atm(vcc)->sk_sndbuf;
259}
260
261
262static inline void atm_dev_hold(struct atm_dev *dev)
263{
264 atomic_inc(&dev->refcnt);
265}
266
267
268static inline void atm_dev_put(struct atm_dev *dev)
269{
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800270 if (atomic_dec_and_test(&dev->refcnt)) {
271 BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
272 if (dev->ops->dev_close)
273 dev->ops->dev_close(dev);
Kay Sieversef395922007-12-30 23:16:06 -0800274 put_device(&dev->class_dev);
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
278
279int atm_charge(struct atm_vcc *vcc,int truesize);
280struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
Al Virodd0fc662005-10-07 07:46:04 +0100281 gfp_t gfp_flags);
Mitchell Blank Jrc2197502005-11-29 16:13:55 -0800282int atm_pcr_goal(const struct atm_trafprm *tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284void vcc_release_async(struct atm_vcc *vcc, int reply);
285
286struct atm_ioctl {
287 struct module *owner;
288 /* A module reference is kept if appropriate over this call.
289 * Return -ENOIOCTLCMD if you don't handle it. */
290 int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
291 struct list_head list;
292};
293
294/**
295 * register_atm_ioctl - register handler for ioctl operations
296 *
297 * Special (non-device) handlers of ioctl's should
298 * register here. If you're a normal device, you should
299 * set .ioctl in your atmdev_ops instead.
300 */
301void register_atm_ioctl(struct atm_ioctl *);
302
303/**
304 * deregister_atm_ioctl - remove the ioctl handler
305 */
306void deregister_atm_ioctl(struct atm_ioctl *);
307
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000308
309/* register_atmdevice_notifier - register atm_dev notify events
310 *
311 * Clients like br2684 will register notify events
312 * Currently we notify of signal found/lost
313 */
314int register_atmdevice_notifier(struct notifier_block *nb);
315void unregister_atmdevice_notifier(struct notifier_block *nb);
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317#endif