]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 | 2 | /* atmdev.h - ATM device driver declarations and various related items */ |
1da177e4 LT |
3 | #ifndef LINUX_ATMDEV_H |
4 | #define LINUX_ATMDEV_H | |
5 | ||
6 | ||
1da177e4 LT |
7 | #include <linux/wait.h> /* wait_queue_head_t */ |
8 | #include <linux/time.h> /* struct timeval */ | |
9 | #include <linux/net.h> | |
187f1882 | 10 | #include <linux/bug.h> |
1da177e4 LT |
11 | #include <linux/skbuff.h> /* struct sk_buff */ |
12 | #include <linux/uio.h> | |
13 | #include <net/sock.h> | |
60063497 | 14 | #include <linux/atomic.h> |
458bc30c | 15 | #include <linux/refcount.h> |
607ca46e | 16 | #include <uapi/linux/atmdev.h> |
1da177e4 LT |
17 | |
18 | #ifdef CONFIG_PROC_FS | |
19 | #include <linux/proc_fs.h> | |
20 | ||
21 | extern struct proc_dir_entry *atm_proc_root; | |
22 | #endif | |
23 | ||
8865c418 DW |
24 | #ifdef CONFIG_COMPAT |
25 | #include <linux/compat.h> | |
26 | struct compat_atm_iobuf { | |
27 | int length; | |
28 | compat_uptr_t buffer; | |
29 | }; | |
30 | #endif | |
1da177e4 LT |
31 | |
32 | struct k_atm_aal_stats { | |
33 | #define __HANDLE_ITEM(i) atomic_t i | |
34 | __AAL_STAT_ITEMS | |
35 | #undef __HANDLE_ITEM | |
36 | }; | |
37 | ||
38 | ||
39 | struct 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 | ||
313162d0 | 45 | struct device; |
1da177e4 LT |
46 | |
47 | enum { | |
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 | ||
81 | enum { | |
64bf69dd | 82 | ATM_DF_REMOVED, /* device was removed from atm_devs list */ |
1da177e4 LT |
83 | }; |
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 | ||
92 | struct 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 */ | |
c971f08c | 104 | void (*release_cb)(struct atm_vcc *vcc); /* release_sock callback */ |
1da177e4 LT |
105 | 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 */ | |
ec809bd8 | 112 | struct module *owner; /* owner of ->push function */ |
1da177e4 LT |
113 | /* 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 | ||
125 | static inline struct atm_vcc *atm_sk(struct sock *sk) | |
126 | { | |
127 | return (struct atm_vcc *)sk; | |
128 | } | |
129 | ||
130 | static inline struct atm_vcc *ATM_SD(struct socket *sock) | |
131 | { | |
132 | return atm_sk(sock->sk); | |
133 | } | |
134 | ||
135 | static inline struct sock *sk_atm(struct atm_vcc *vcc) | |
136 | { | |
137 | return (struct sock *)vcc; | |
138 | } | |
139 | ||
140 | struct atm_dev_addr { | |
141 | struct sockaddr_atmsvc addr; /* ATM address */ | |
142 | struct list_head entry; /* next address */ | |
143 | }; | |
144 | ||
0f21ba7c EK |
145 | enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS }; |
146 | ||
1da177e4 LT |
147 | struct 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 */ | |
0f21ba7c | 157 | struct list_head lecs; /* LECS ATM addresses learned via ILMI */ |
1da177e4 LT |
158 | 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) */ | |
458bc30c | 163 | refcount_t refcnt; /* reference count */ |
1da177e4 LT |
164 | 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 | |
ef39592f | 169 | struct device class_dev; /* sysfs device */ |
1da177e4 LT |
170 | 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 | ||
1da177e4 LT |
179 | struct atmdev_ops { /* only send is required */ |
180 | void (*dev_close)(struct atm_dev *dev); | |
181 | int (*open)(struct atm_vcc *vcc); | |
182 | void (*close)(struct atm_vcc *vcc); | |
183 | int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg); | |
8865c418 DW |
184 | #ifdef CONFIG_COMPAT |
185 | int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd, | |
186 | void __user *arg); | |
187 | #endif | |
1da177e4 | 188 | int (*send)(struct atm_vcc *vcc,struct sk_buff *skb); |
f2bcc2fa | 189 | int (*send_bh)(struct atm_vcc *vcc, struct sk_buff *skb); |
1da177e4 LT |
190 | int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags); |
191 | void (*phy_put)(struct atm_dev *dev,unsigned char value, | |
192 | unsigned long addr); | |
193 | unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr); | |
194 | int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags); | |
195 | int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page); | |
196 | struct module *owner; | |
197 | }; | |
198 | ||
199 | struct atmphy_ops { | |
200 | int (*start)(struct atm_dev *dev); | |
201 | int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg); | |
202 | void (*interrupt)(struct atm_dev *dev); | |
203 | int (*stop)(struct atm_dev *dev); | |
204 | }; | |
205 | ||
206 | struct atm_skb_data { | |
207 | struct atm_vcc *vcc; /* ATM VCC */ | |
208 | unsigned long atm_options; /* ATM layer options */ | |
9bbe60a6 | 209 | unsigned int acct_truesize; /* truesize accounted to vcc */ |
1da177e4 LT |
210 | }; |
211 | ||
212 | #define VCC_HTABLE_SIZE 32 | |
213 | ||
214 | extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE]; | |
215 | extern rwlock_t vcc_sklist_lock; | |
216 | ||
217 | #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb)) | |
218 | ||
d9ca676b DW |
219 | struct atm_dev *atm_dev_register(const char *type, struct device *parent, |
220 | const struct atmdev_ops *ops, | |
221 | int number, /* -1 == pick first available */ | |
222 | unsigned long *flags); | |
1da177e4 LT |
223 | struct atm_dev *atm_dev_lookup(int number); |
224 | void atm_dev_deregister(struct atm_dev *dev); | |
7313bb8f KH |
225 | |
226 | /* atm_dev_signal_change | |
227 | * | |
228 | * Propagate lower layer signal change in atm_dev->signal to netdevice. | |
229 | * The event will be sent via a notifier call chain. | |
230 | */ | |
231 | void atm_dev_signal_change(struct atm_dev *dev, char signal); | |
232 | ||
1da177e4 LT |
233 | void vcc_insert_socket(struct sock *sk); |
234 | ||
c031235b | 235 | void atm_dev_release_vccs(struct atm_dev *dev); |
1da177e4 | 236 | |
9bbe60a6 DW |
237 | static inline void atm_account_tx(struct atm_vcc *vcc, struct sk_buff *skb) |
238 | { | |
239 | /* | |
240 | * Because ATM skbs may not belong to a sock (and we don't | |
241 | * necessarily want to), skb->truesize may be adjusted, | |
242 | * escaping the hack in pskb_expand_head() which avoids | |
243 | * doing so for some cases. So stash the value of truesize | |
244 | * at the time we accounted it, and atm_pop_raw() can use | |
245 | * that value later, in case it changes. | |
246 | */ | |
247 | refcount_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); | |
248 | ATM_SKB(skb)->acct_truesize = skb->truesize; | |
249 | ATM_SKB(skb)->atm_options = vcc->atm_options; | |
250 | } | |
1da177e4 LT |
251 | |
252 | static inline void atm_force_charge(struct atm_vcc *vcc,int truesize) | |
253 | { | |
254 | atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc); | |
255 | } | |
256 | ||
257 | ||
258 | static inline void atm_return(struct atm_vcc *vcc,int truesize) | |
259 | { | |
260 | atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc); | |
261 | } | |
262 | ||
263 | ||
264 | static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size) | |
265 | { | |
14afee4b | 266 | return (size + refcount_read(&sk_atm(vcc)->sk_wmem_alloc)) < |
1da177e4 LT |
267 | sk_atm(vcc)->sk_sndbuf; |
268 | } | |
269 | ||
270 | ||
271 | static inline void atm_dev_hold(struct atm_dev *dev) | |
272 | { | |
458bc30c | 273 | refcount_inc(&dev->refcnt); |
1da177e4 LT |
274 | } |
275 | ||
276 | ||
277 | static inline void atm_dev_put(struct atm_dev *dev) | |
278 | { | |
458bc30c | 279 | if (refcount_dec_and_test(&dev->refcnt)) { |
64bf69dd SG |
280 | BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags)); |
281 | if (dev->ops->dev_close) | |
282 | dev->ops->dev_close(dev); | |
ef39592f | 283 | put_device(&dev->class_dev); |
64bf69dd | 284 | } |
1da177e4 LT |
285 | } |
286 | ||
287 | ||
288 | int atm_charge(struct atm_vcc *vcc,int truesize); | |
289 | struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size, | |
dd0fc66f | 290 | gfp_t gfp_flags); |
c219750b | 291 | int atm_pcr_goal(const struct atm_trafprm *tp); |
1da177e4 LT |
292 | |
293 | void vcc_release_async(struct atm_vcc *vcc, int reply); | |
294 | ||
295 | struct atm_ioctl { | |
296 | struct module *owner; | |
297 | /* A module reference is kept if appropriate over this call. | |
298 | * Return -ENOIOCTLCMD if you don't handle it. */ | |
299 | int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg); | |
300 | struct list_head list; | |
301 | }; | |
302 | ||
303 | /** | |
304 | * register_atm_ioctl - register handler for ioctl operations | |
305 | * | |
306 | * Special (non-device) handlers of ioctl's should | |
307 | * register here. If you're a normal device, you should | |
308 | * set .ioctl in your atmdev_ops instead. | |
309 | */ | |
310 | void register_atm_ioctl(struct atm_ioctl *); | |
311 | ||
312 | /** | |
313 | * deregister_atm_ioctl - remove the ioctl handler | |
314 | */ | |
315 | void deregister_atm_ioctl(struct atm_ioctl *); | |
316 | ||
7313bb8f KH |
317 | |
318 | /* register_atmdevice_notifier - register atm_dev notify events | |
319 | * | |
320 | * Clients like br2684 will register notify events | |
321 | * Currently we notify of signal found/lost | |
322 | */ | |
323 | int register_atmdevice_notifier(struct notifier_block *nb); | |
324 | void unregister_atmdevice_notifier(struct notifier_block *nb); | |
325 | ||
1da177e4 | 326 | #endif |