blob: 0ec9bdb1cc9f9bdcad76caae816e7c8518f272f3 [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>
Reshetova, Elena458bc302017-07-04 15:53:01 +030014#include <linux/refcount.h>
David Howells607ca462012-10-13 10:46:48 +010015#include <uapi/linux/atmdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#ifdef CONFIG_PROC_FS
18#include <linux/proc_fs.h>
19
20extern struct proc_dir_entry *atm_proc_root;
21#endif
22
David Woodhouse8865c412008-12-03 22:12:38 -080023#ifdef CONFIG_COMPAT
24#include <linux/compat.h>
25struct compat_atm_iobuf {
26 int length;
27 compat_uptr_t buffer;
28};
29#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31struct k_atm_aal_stats {
32#define __HANDLE_ITEM(i) atomic_t i
33 __AAL_STAT_ITEMS
34#undef __HANDLE_ITEM
35};
36
37
38struct k_atm_dev_stats {
39 struct k_atm_aal_stats aal0;
40 struct k_atm_aal_stats aal34;
41 struct k_atm_aal_stats aal5;
42};
43
Paul Gortmaker313162d2012-01-30 11:46:54 -050044struct device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46enum {
47 ATM_VF_ADDR, /* Address is in use. Set by anybody, cleared
48 by device driver. */
49 ATM_VF_READY, /* VC is ready to transfer data. Set by device
50 driver, cleared by anybody. */
51 ATM_VF_PARTIAL, /* resources are bound to PVC (partial PVC
52 setup), controlled by socket layer */
53 ATM_VF_REGIS, /* registered with demon, controlled by SVC
54 socket layer */
55 ATM_VF_BOUND, /* local SAP is set, controlled by SVC socket
56 layer */
57 ATM_VF_RELEASED, /* demon has indicated/requested release,
58 controlled by SVC socket layer */
59 ATM_VF_HASQOS, /* QOS parameters have been set */
60 ATM_VF_LISTEN, /* socket is used for listening */
61 ATM_VF_META, /* SVC socket isn't used for normal data
62 traffic and doesn't depend on signaling
63 to be available */
64 ATM_VF_SESSION, /* VCC is p2mp session control descriptor */
65 ATM_VF_HASSAP, /* SAP has been set */
66 ATM_VF_CLOSE, /* asynchronous close - treat like VF_RELEASED*/
67 ATM_VF_WAITING, /* waiting for reply from sigd */
68 ATM_VF_IS_CLIP, /* in use by CLIP protocol */
69};
70
71
72#define ATM_VF2VS(flags) \
73 (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
74 test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
75 test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
76 test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
77 test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
78
79
80enum {
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -080081 ATM_DF_REMOVED, /* device was removed from atm_devs list */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082};
83
84
85#define ATM_PHY_SIG_LOST 0 /* no carrier/light */
86#define ATM_PHY_SIG_UNKNOWN 1 /* carrier/light status is unknown */
87#define ATM_PHY_SIG_FOUND 2 /* carrier/light okay */
88
89#define ATM_ATMOPT_CLP 1 /* set CLP bit */
90
91struct atm_vcc {
92 /* struct sock has to be the first member of atm_vcc */
93 struct sock sk;
94 unsigned long flags; /* VCC flags (ATM_VF_*) */
95 short vpi; /* VPI and VCI (types must be equal */
96 /* with sockaddr) */
97 int vci;
98 unsigned long aal_options; /* AAL layer options */
99 unsigned long atm_options; /* ATM layer options */
100 struct atm_dev *dev; /* device back pointer */
101 struct atm_qos qos; /* QOS */
102 struct atm_sap sap; /* SAP */
David Woodhousec971f082012-11-28 00:03:11 +0000103 void (*release_cb)(struct atm_vcc *vcc); /* release_sock callback */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
105 void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
106 int (*push_oam)(struct atm_vcc *vcc,void *cell);
107 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
108 void *dev_data; /* per-device data */
109 void *proto_data; /* per-protocol data */
110 struct k_atm_aal_stats *stats; /* pointer to AAL stats group */
Krzysztof Mazurec809bd2012-11-06 23:16:57 +0100111 struct module *owner; /* owner of ->push function */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 /* SVC part --- may move later ------------------------------------- */
113 short itf; /* interface number */
114 struct sockaddr_atmsvc local;
115 struct sockaddr_atmsvc remote;
116 /* Multipoint part ------------------------------------------------- */
117 struct atm_vcc *session; /* session VCC descriptor */
118 /* Other stuff ----------------------------------------------------- */
119 void *user_back; /* user backlink - not touched by */
120 /* native ATM stack. Currently used */
121 /* by CLIP and sch_atm. */
122};
123
124static inline struct atm_vcc *atm_sk(struct sock *sk)
125{
126 return (struct atm_vcc *)sk;
127}
128
129static inline struct atm_vcc *ATM_SD(struct socket *sock)
130{
131 return atm_sk(sock->sk);
132}
133
134static inline struct sock *sk_atm(struct atm_vcc *vcc)
135{
136 return (struct sock *)vcc;
137}
138
139struct atm_dev_addr {
140 struct sockaddr_atmsvc addr; /* ATM address */
141 struct list_head entry; /* next address */
142};
143
Eric Kinzie0f21ba72005-10-06 22:19:28 -0700144enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146struct atm_dev {
147 const struct atmdev_ops *ops; /* device operations; NULL if unused */
148 const struct atmphy_ops *phy; /* PHY operations, may be undefined */
149 /* (NULL) */
150 const char *type; /* device type name */
151 int number; /* device index */
152 void *dev_data; /* per-device data */
153 void *phy_data; /* private PHY date */
154 unsigned long flags; /* device flags (ATM_DF_*) */
155 struct list_head local; /* local ATM addresses */
Eric Kinzie0f21ba72005-10-06 22:19:28 -0700156 struct list_head lecs; /* LECS ATM addresses learned via ILMI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
158 struct atm_cirange ci_range; /* VPI/VCI range */
159 struct k_atm_dev_stats stats; /* statistics */
160 char signal; /* signal status (ATM_PHY_SIG_*) */
161 int link_rate; /* link rate (default: OC3) */
Reshetova, Elena458bc302017-07-04 15:53:01 +0300162 refcount_t refcnt; /* reference count */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 spinlock_t lock; /* protect internal members */
164#ifdef CONFIG_PROC_FS
165 struct proc_dir_entry *proc_entry; /* proc entry */
166 char *proc_name; /* proc entry name */
167#endif
Kay Sieversef395922007-12-30 23:16:06 -0800168 struct device class_dev; /* sysfs device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 struct list_head dev_list; /* linkage */
170};
171
172
173/* OF: send_Oam Flags */
174
175#define ATM_OF_IMMED 1 /* Attempt immediate delivery */
176#define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
177
178
179/*
180 * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
181 */
182
183struct atmdev_ops { /* only send is required */
184 void (*dev_close)(struct atm_dev *dev);
185 int (*open)(struct atm_vcc *vcc);
186 void (*close)(struct atm_vcc *vcc);
187 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
David Woodhouse8865c412008-12-03 22:12:38 -0800188#ifdef CONFIG_COMPAT
189 int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
190 void __user *arg);
191#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
193 void __user *optval,int optlen);
194 int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700195 void __user *optval,unsigned int optlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
197 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
198 void (*phy_put)(struct atm_dev *dev,unsigned char value,
199 unsigned long addr);
200 unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
201 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
202 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
203 struct module *owner;
204};
205
206struct atmphy_ops {
207 int (*start)(struct atm_dev *dev);
208 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
209 void (*interrupt)(struct atm_dev *dev);
210 int (*stop)(struct atm_dev *dev);
211};
212
213struct atm_skb_data {
214 struct atm_vcc *vcc; /* ATM VCC */
215 unsigned long atm_options; /* ATM layer options */
216};
217
218#define VCC_HTABLE_SIZE 32
219
220extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
221extern rwlock_t vcc_sklist_lock;
222
223#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
224
Dan Williamsd9ca6762010-12-08 19:40:47 +0000225struct atm_dev *atm_dev_register(const char *type, struct device *parent,
226 const struct atmdev_ops *ops,
227 int number, /* -1 == pick first available */
228 unsigned long *flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229struct atm_dev *atm_dev_lookup(int number);
230void atm_dev_deregister(struct atm_dev *dev);
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000231
232/* atm_dev_signal_change
233 *
234 * Propagate lower layer signal change in atm_dev->signal to netdevice.
235 * The event will be sent via a notifier call chain.
236 */
237void atm_dev_signal_change(struct atm_dev *dev, char signal);
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239void vcc_insert_socket(struct sock *sk);
240
Philip A. Prindevillec0312352011-03-30 13:17:04 +0000241void atm_dev_release_vccs(struct atm_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
245{
246 atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
247}
248
249
250static inline void atm_return(struct atm_vcc *vcc,int truesize)
251{
252 atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
253}
254
255
256static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
257{
Reshetova, Elena14afee42017-06-30 13:08:00 +0300258 return (size + refcount_read(&sk_atm(vcc)->sk_wmem_alloc)) <
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 sk_atm(vcc)->sk_sndbuf;
260}
261
262
263static inline void atm_dev_hold(struct atm_dev *dev)
264{
Reshetova, Elena458bc302017-07-04 15:53:01 +0300265 refcount_inc(&dev->refcnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266}
267
268
269static inline void atm_dev_put(struct atm_dev *dev)
270{
Reshetova, Elena458bc302017-07-04 15:53:01 +0300271 if (refcount_dec_and_test(&dev->refcnt)) {
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800272 BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
273 if (dev->ops->dev_close)
274 dev->ops->dev_close(dev);
Kay Sieversef395922007-12-30 23:16:06 -0800275 put_device(&dev->class_dev);
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
279
280int atm_charge(struct atm_vcc *vcc,int truesize);
281struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
Al Virodd0fc662005-10-07 07:46:04 +0100282 gfp_t gfp_flags);
Mitchell Blank Jrc2197502005-11-29 16:13:55 -0800283int atm_pcr_goal(const struct atm_trafprm *tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285void vcc_release_async(struct atm_vcc *vcc, int reply);
286
287struct atm_ioctl {
288 struct module *owner;
289 /* A module reference is kept if appropriate over this call.
290 * Return -ENOIOCTLCMD if you don't handle it. */
291 int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
292 struct list_head list;
293};
294
295/**
296 * register_atm_ioctl - register handler for ioctl operations
297 *
298 * Special (non-device) handlers of ioctl's should
299 * register here. If you're a normal device, you should
300 * set .ioctl in your atmdev_ops instead.
301 */
302void register_atm_ioctl(struct atm_ioctl *);
303
304/**
305 * deregister_atm_ioctl - remove the ioctl handler
306 */
307void deregister_atm_ioctl(struct atm_ioctl *);
308
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000309
310/* register_atmdevice_notifier - register atm_dev notify events
311 *
312 * Clients like br2684 will register notify events
313 * Currently we notify of signal found/lost
314 */
315int register_atmdevice_notifier(struct notifier_block *nb);
316void unregister_atmdevice_notifier(struct notifier_block *nb);
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#endif