blob: 8124815eb1218b5653572fc4a04f5d4d734e3469 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* atmdev.h - ATM device driver declarations and various related items */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#ifndef LINUX_ATMDEV_H
4#define LINUX_ATMDEV_H
5
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/wait.h> /* wait_queue_head_t */
8#include <linux/time.h> /* struct timeval */
9#include <linux/net.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050010#include <linux/bug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/skbuff.h> /* struct sk_buff */
12#include <linux/uio.h>
13#include <net/sock.h>
Arun Sharma600634972011-07-26 16:09:06 -070014#include <linux/atomic.h>
Reshetova, Elena458bc302017-07-04 15:53:01 +030015#include <linux/refcount.h>
David Howells607ca462012-10-13 10:46:48 +010016#include <uapi/linux/atmdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#ifdef CONFIG_PROC_FS
19#include <linux/proc_fs.h>
20
21extern struct proc_dir_entry *atm_proc_root;
22#endif
23
David Woodhouse8865c412008-12-03 22:12:38 -080024#ifdef CONFIG_COMPAT
25#include <linux/compat.h>
26struct compat_atm_iobuf {
27 int length;
28 compat_uptr_t buffer;
29};
30#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32struct k_atm_aal_stats {
33#define __HANDLE_ITEM(i) atomic_t i
34 __AAL_STAT_ITEMS
35#undef __HANDLE_ITEM
36};
37
38
39struct k_atm_dev_stats {
40 struct k_atm_aal_stats aal0;
41 struct k_atm_aal_stats aal34;
42 struct k_atm_aal_stats aal5;
43};
44
Paul Gortmaker313162d2012-01-30 11:46:54 -050045struct device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47enum {
48 ATM_VF_ADDR, /* Address is in use. Set by anybody, cleared
49 by device driver. */
50 ATM_VF_READY, /* VC is ready to transfer data. Set by device
51 driver, cleared by anybody. */
52 ATM_VF_PARTIAL, /* resources are bound to PVC (partial PVC
53 setup), controlled by socket layer */
54 ATM_VF_REGIS, /* registered with demon, controlled by SVC
55 socket layer */
56 ATM_VF_BOUND, /* local SAP is set, controlled by SVC socket
57 layer */
58 ATM_VF_RELEASED, /* demon has indicated/requested release,
59 controlled by SVC socket layer */
60 ATM_VF_HASQOS, /* QOS parameters have been set */
61 ATM_VF_LISTEN, /* socket is used for listening */
62 ATM_VF_META, /* SVC socket isn't used for normal data
63 traffic and doesn't depend on signaling
64 to be available */
65 ATM_VF_SESSION, /* VCC is p2mp session control descriptor */
66 ATM_VF_HASSAP, /* SAP has been set */
67 ATM_VF_CLOSE, /* asynchronous close - treat like VF_RELEASED*/
68 ATM_VF_WAITING, /* waiting for reply from sigd */
69 ATM_VF_IS_CLIP, /* in use by CLIP protocol */
70};
71
72
73#define ATM_VF2VS(flags) \
74 (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
75 test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
76 test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
77 test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
78 test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
79
80
81enum {
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -080082 ATM_DF_REMOVED, /* device was removed from atm_devs list */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
84
85
86#define ATM_PHY_SIG_LOST 0 /* no carrier/light */
87#define ATM_PHY_SIG_UNKNOWN 1 /* carrier/light status is unknown */
88#define ATM_PHY_SIG_FOUND 2 /* carrier/light okay */
89
90#define ATM_ATMOPT_CLP 1 /* set CLP bit */
91
92struct atm_vcc {
93 /* struct sock has to be the first member of atm_vcc */
94 struct sock sk;
95 unsigned long flags; /* VCC flags (ATM_VF_*) */
96 short vpi; /* VPI and VCI (types must be equal */
97 /* with sockaddr) */
98 int vci;
99 unsigned long aal_options; /* AAL layer options */
100 unsigned long atm_options; /* ATM layer options */
101 struct atm_dev *dev; /* device back pointer */
102 struct atm_qos qos; /* QOS */
103 struct atm_sap sap; /* SAP */
David Woodhousec971f082012-11-28 00:03:11 +0000104 void (*release_cb)(struct atm_vcc *vcc); /* release_sock callback */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
106 void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
107 int (*push_oam)(struct atm_vcc *vcc,void *cell);
108 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
109 void *dev_data; /* per-device data */
110 void *proto_data; /* per-protocol data */
111 struct k_atm_aal_stats *stats; /* pointer to AAL stats group */
Krzysztof Mazurec809bd2012-11-06 23:16:57 +0100112 struct module *owner; /* owner of ->push function */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 /* SVC part --- may move later ------------------------------------- */
114 short itf; /* interface number */
115 struct sockaddr_atmsvc local;
116 struct sockaddr_atmsvc remote;
117 /* Multipoint part ------------------------------------------------- */
118 struct atm_vcc *session; /* session VCC descriptor */
119 /* Other stuff ----------------------------------------------------- */
120 void *user_back; /* user backlink - not touched by */
121 /* native ATM stack. Currently used */
122 /* by CLIP and sch_atm. */
123};
124
125static inline struct atm_vcc *atm_sk(struct sock *sk)
126{
127 return (struct atm_vcc *)sk;
128}
129
130static inline struct atm_vcc *ATM_SD(struct socket *sock)
131{
132 return atm_sk(sock->sk);
133}
134
135static inline struct sock *sk_atm(struct atm_vcc *vcc)
136{
137 return (struct sock *)vcc;
138}
139
140struct atm_dev_addr {
141 struct sockaddr_atmsvc addr; /* ATM address */
142 struct list_head entry; /* next address */
143};
144
Eric Kinzie0f21ba72005-10-06 22:19:28 -0700145enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147struct atm_dev {
148 const struct atmdev_ops *ops; /* device operations; NULL if unused */
149 const struct atmphy_ops *phy; /* PHY operations, may be undefined */
150 /* (NULL) */
151 const char *type; /* device type name */
152 int number; /* device index */
153 void *dev_data; /* per-device data */
154 void *phy_data; /* private PHY date */
155 unsigned long flags; /* device flags (ATM_DF_*) */
156 struct list_head local; /* local ATM addresses */
Eric Kinzie0f21ba72005-10-06 22:19:28 -0700157 struct list_head lecs; /* LECS ATM addresses learned via ILMI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
159 struct atm_cirange ci_range; /* VPI/VCI range */
160 struct k_atm_dev_stats stats; /* statistics */
161 char signal; /* signal status (ATM_PHY_SIG_*) */
162 int link_rate; /* link rate (default: OC3) */
Reshetova, Elena458bc302017-07-04 15:53:01 +0300163 refcount_t refcnt; /* reference count */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 spinlock_t lock; /* protect internal members */
165#ifdef CONFIG_PROC_FS
166 struct proc_dir_entry *proc_entry; /* proc entry */
167 char *proc_name; /* proc entry name */
168#endif
Kay Sieversef395922007-12-30 23:16:06 -0800169 struct device class_dev; /* sysfs device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 struct list_head dev_list; /* linkage */
171};
172
173
174/* OF: send_Oam Flags */
175
176#define ATM_OF_IMMED 1 /* Attempt immediate delivery */
177#define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
178
179
180/*
181 * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
182 */
183
184struct atmdev_ops { /* only send is required */
185 void (*dev_close)(struct atm_dev *dev);
186 int (*open)(struct atm_vcc *vcc);
187 void (*close)(struct atm_vcc *vcc);
188 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
David Woodhouse8865c412008-12-03 22:12:38 -0800189#ifdef CONFIG_COMPAT
190 int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
191 void __user *arg);
192#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
194 void __user *optval,int optlen);
195 int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700196 void __user *optval,unsigned int optlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
198 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
199 void (*phy_put)(struct atm_dev *dev,unsigned char value,
200 unsigned long addr);
201 unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
202 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
203 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
204 struct module *owner;
205};
206
207struct atmphy_ops {
208 int (*start)(struct atm_dev *dev);
209 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
210 void (*interrupt)(struct atm_dev *dev);
211 int (*stop)(struct atm_dev *dev);
212};
213
214struct atm_skb_data {
215 struct atm_vcc *vcc; /* ATM VCC */
216 unsigned long atm_options; /* ATM layer options */
David Woodhouse9bbe60a2018-06-16 11:55:44 +0100217 unsigned int acct_truesize; /* truesize accounted to vcc */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218};
219
220#define VCC_HTABLE_SIZE 32
221
222extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
223extern rwlock_t vcc_sklist_lock;
224
225#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
226
Dan Williamsd9ca6762010-12-08 19:40:47 +0000227struct atm_dev *atm_dev_register(const char *type, struct device *parent,
228 const struct atmdev_ops *ops,
229 int number, /* -1 == pick first available */
230 unsigned long *flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231struct atm_dev *atm_dev_lookup(int number);
232void atm_dev_deregister(struct atm_dev *dev);
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000233
234/* atm_dev_signal_change
235 *
236 * Propagate lower layer signal change in atm_dev->signal to netdevice.
237 * The event will be sent via a notifier call chain.
238 */
239void atm_dev_signal_change(struct atm_dev *dev, char signal);
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241void vcc_insert_socket(struct sock *sk);
242
Philip A. Prindevillec0312352011-03-30 13:17:04 +0000243void atm_dev_release_vccs(struct atm_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
David Woodhouse9bbe60a2018-06-16 11:55:44 +0100245static inline void atm_account_tx(struct atm_vcc *vcc, struct sk_buff *skb)
246{
247 /*
248 * Because ATM skbs may not belong to a sock (and we don't
249 * necessarily want to), skb->truesize may be adjusted,
250 * escaping the hack in pskb_expand_head() which avoids
251 * doing so for some cases. So stash the value of truesize
252 * at the time we accounted it, and atm_pop_raw() can use
253 * that value later, in case it changes.
254 */
255 refcount_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
256 ATM_SKB(skb)->acct_truesize = skb->truesize;
257 ATM_SKB(skb)->atm_options = vcc->atm_options;
258}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
261{
262 atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
263}
264
265
266static inline void atm_return(struct atm_vcc *vcc,int truesize)
267{
268 atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
269}
270
271
272static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
273{
Reshetova, Elena14afee42017-06-30 13:08:00 +0300274 return (size + refcount_read(&sk_atm(vcc)->sk_wmem_alloc)) <
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 sk_atm(vcc)->sk_sndbuf;
276}
277
278
279static inline void atm_dev_hold(struct atm_dev *dev)
280{
Reshetova, Elena458bc302017-07-04 15:53:01 +0300281 refcount_inc(&dev->refcnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
284
285static inline void atm_dev_put(struct atm_dev *dev)
286{
Reshetova, Elena458bc302017-07-04 15:53:01 +0300287 if (refcount_dec_and_test(&dev->refcnt)) {
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800288 BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
289 if (dev->ops->dev_close)
290 dev->ops->dev_close(dev);
Kay Sieversef395922007-12-30 23:16:06 -0800291 put_device(&dev->class_dev);
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293}
294
295
296int atm_charge(struct atm_vcc *vcc,int truesize);
297struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
Al Virodd0fc662005-10-07 07:46:04 +0100298 gfp_t gfp_flags);
Mitchell Blank Jrc2197502005-11-29 16:13:55 -0800299int atm_pcr_goal(const struct atm_trafprm *tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301void vcc_release_async(struct atm_vcc *vcc, int reply);
302
303struct atm_ioctl {
304 struct module *owner;
305 /* A module reference is kept if appropriate over this call.
306 * Return -ENOIOCTLCMD if you don't handle it. */
307 int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
308 struct list_head list;
309};
310
311/**
312 * register_atm_ioctl - register handler for ioctl operations
313 *
314 * Special (non-device) handlers of ioctl's should
315 * register here. If you're a normal device, you should
316 * set .ioctl in your atmdev_ops instead.
317 */
318void register_atm_ioctl(struct atm_ioctl *);
319
320/**
321 * deregister_atm_ioctl - remove the ioctl handler
322 */
323void deregister_atm_ioctl(struct atm_ioctl *);
324
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000325
326/* register_atmdevice_notifier - register atm_dev notify events
327 *
328 * Clients like br2684 will register notify events
329 * Currently we notify of signal found/lost
330 */
331int register_atmdevice_notifier(struct notifier_block *nb);
332void unregister_atmdevice_notifier(struct notifier_block *nb);
333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#endif