xref: /linux-6.15/include/linux/atmdev.h (revision bbb03029)
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 <linux/refcount.h>
15 #include <uapi/linux/atmdev.h>
16 
17 #ifdef CONFIG_PROC_FS
18 #include <linux/proc_fs.h>
19 
20 extern struct proc_dir_entry *atm_proc_root;
21 #endif
22 
23 #ifdef CONFIG_COMPAT
24 #include <linux/compat.h>
25 struct compat_atm_iobuf {
26 	int length;
27 	compat_uptr_t buffer;
28 };
29 #endif
30 
31 struct k_atm_aal_stats {
32 #define __HANDLE_ITEM(i) atomic_t i
33 	__AAL_STAT_ITEMS
34 #undef __HANDLE_ITEM
35 };
36 
37 
38 struct 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 
44 struct device;
45 
46 enum {
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 
80 enum {
81 	ATM_DF_REMOVED,		/* device was removed from atm_devs list */
82 };
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 
91 struct 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 */
103 	void (*release_cb)(struct atm_vcc *vcc); /* release_sock callback */
104 	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 */
111 	struct module *owner;		/* owner of ->push function */
112 	/* 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 
124 static inline struct atm_vcc *atm_sk(struct sock *sk)
125 {
126 	return (struct atm_vcc *)sk;
127 }
128 
129 static inline struct atm_vcc *ATM_SD(struct socket *sock)
130 {
131 	return atm_sk(sock->sk);
132 }
133 
134 static inline struct sock *sk_atm(struct atm_vcc *vcc)
135 {
136 	return (struct sock *)vcc;
137 }
138 
139 struct atm_dev_addr {
140 	struct sockaddr_atmsvc addr;	/* ATM address */
141 	struct list_head entry;		/* next address */
142 };
143 
144 enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
145 
146 struct 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 */
156 	struct list_head lecs;		/* LECS ATM addresses learned via ILMI */
157 	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) */
162 	refcount_t	refcnt;		/* reference count */
163 	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
168 	struct device class_dev;	/* sysfs device */
169 	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 
183 struct 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);
188 #ifdef CONFIG_COMPAT
189 	int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
190 			    void __user *arg);
191 #endif
192 	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,
195 	    void __user *optval,unsigned int optlen);
196 	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 
206 struct 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 
213 struct 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 
220 extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
221 extern rwlock_t vcc_sklist_lock;
222 
223 #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
224 
225 struct 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);
229 struct atm_dev *atm_dev_lookup(int number);
230 void atm_dev_deregister(struct atm_dev *dev);
231 
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  */
237 void atm_dev_signal_change(struct atm_dev *dev, char signal);
238 
239 void vcc_insert_socket(struct sock *sk);
240 
241 void atm_dev_release_vccs(struct atm_dev *dev);
242 
243 
244 static 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 
250 static inline void atm_return(struct atm_vcc *vcc,int truesize)
251 {
252 	atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
253 }
254 
255 
256 static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
257 {
258 	return (size + refcount_read(&sk_atm(vcc)->sk_wmem_alloc)) <
259 	       sk_atm(vcc)->sk_sndbuf;
260 }
261 
262 
263 static inline void atm_dev_hold(struct atm_dev *dev)
264 {
265 	refcount_inc(&dev->refcnt);
266 }
267 
268 
269 static inline void atm_dev_put(struct atm_dev *dev)
270 {
271 	if (refcount_dec_and_test(&dev->refcnt)) {
272 		BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
273 		if (dev->ops->dev_close)
274 			dev->ops->dev_close(dev);
275 		put_device(&dev->class_dev);
276 	}
277 }
278 
279 
280 int atm_charge(struct atm_vcc *vcc,int truesize);
281 struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
282     gfp_t gfp_flags);
283 int atm_pcr_goal(const struct atm_trafprm *tp);
284 
285 void vcc_release_async(struct atm_vcc *vcc, int reply);
286 
287 struct 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  */
302 void register_atm_ioctl(struct atm_ioctl *);
303 
304 /**
305  * deregister_atm_ioctl - remove the ioctl handler
306  */
307 void deregister_atm_ioctl(struct atm_ioctl *);
308 
309 
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  */
315 int register_atmdevice_notifier(struct notifier_block *nb);
316 void unregister_atmdevice_notifier(struct notifier_block *nb);
317 
318 #endif
319