| 1 |
|
| 2 | #ifndef LINUX_ATMDEV_H
|
| 3 | #define LINUX_ATMDEV_H
|
| 4 |
|
| 5 |
|
| 6 | #include <linux/wait.h>
|
| 7 | #include <linux/time.h>
|
| 8 | #include <linux/net.h>
|
| 9 | #include <linux/bug.h>
|
| 10 | #include <linux/skbuff.h>
|
| 11 | #include <linux/uio.h>
|
| 12 | #include <net/sock.h>
|
| 13 | #include <linux/atomic.h>
|
| 14 | #include <uapi/linux/atmdev.h>
|
| 15 |
|
| 16 | #ifdef CONFIG_PROC_FS
|
| 17 | #include <linux/proc_fs.h>
|
| 18 |
|
| 19 | extern struct proc_dir_entry *atm_proc_root;
|
| 20 | #endif
|
| 21 |
|
| 22 | #ifdef CONFIG_COMPAT
|
| 23 | #include <linux/compat.h>
|
| 24 | struct compat_atm_iobuf {
|
| 25 | int length;
|
| 26 | compat_uptr_t buffer;
|
| 27 | };
|
| 28 | #endif
|
| 29 |
|
| 30 | struct k_atm_aal_stats {
|
| 31 | #define __HANDLE_ITEM(i) atomic_t i
|
| 32 | __AAL_STAT_ITEMS
|
| 33 | #undef __HANDLE_ITEM
|
| 34 | };
|
| 35 |
|
| 36 |
|
| 37 | struct 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 |
|
| 43 | struct device;
|
| 44 |
|
| 45 | enum {
|
| 46 | ATM_VF_ADDR, |
| 47 | by device driver.
|
| 48 | ATM_VF_READY, |
| 49 | driver, cleared by anybody.
|
| 50 | ATM_VF_PARTIAL, |
| 51 | setup), controlled by socket layer
|
| 52 | ATM_VF_REGIS, |
| 53 | socket layer
|
| 54 | ATM_VF_BOUND, |
| 55 | layer
|
| 56 | ATM_VF_RELEASED, |
| 57 | controlled by SVC socket layer
|
| 58 | ATM_VF_HASQOS,
|
| 59 | ATM_VF_LISTEN,
|
| 60 | ATM_VF_META, |
| 61 | traffic and doesn't depend on signaling
|
| 62 | to be available
|
| 63 | ATM_VF_SESSION,
|
| 64 | ATM_VF_HASSAP,
|
| 65 | ATM_VF_CLOSE,
|
| 66 | ATM_VF_WAITING,
|
| 67 | ATM_VF_IS_CLIP,
|
| 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 |
|
| 79 | enum {
|
| 80 | ATM_DF_REMOVED,
|
| 81 | };
|
| 82 |
|
| 83 |
|
| 84 | #define ATM_PHY_SIG_LOST 0
|
| 85 | #define ATM_PHY_SIG_UNKNOWN 1
|
| 86 | #define ATM_PHY_SIG_FOUND 2
|
| 87 |
|
| 88 | #define ATM_ATMOPT_CLP 1
|
| 89 |
|
| 90 | struct atm_vcc {
|
| 91 |
|
| 92 | struct sock sk;
|
| 93 | unsigned long flags;
|
| 94 | short vpi;
|
| 95 |
|
| 96 | int vci;
|
| 97 | unsigned long aal_options;
|
| 98 | unsigned long atm_options;
|
| 99 | struct atm_dev *dev;
|
| 100 | struct atm_qos qos;
|
| 101 | struct atm_sap sap;
|
| 102 | void (*release_cb)(struct atm_vcc *vcc);
|
| 103 | void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
|
| 104 | void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb);
|
| 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;
|
| 108 | void *proto_data;
|
| 109 | struct k_atm_aal_stats *stats;
|
| 110 | struct module *owner;
|
| 111 |
|
| 112 | short itf;
|
| 113 | struct sockaddr_atmsvc local;
|
| 114 | struct sockaddr_atmsvc remote;
|
| 115 |
|
| 116 | struct atm_vcc *session;
|
| 117 |
|
| 118 | void *user_back;
|
| 119 |
|
| 120 |
|
| 121 | };
|
| 122 |
|
| 123 | static inline struct atm_vcc *atm_sk(struct sock *sk)
|
| 124 | {
|
| 125 | return (struct atm_vcc *)sk;
|
| 126 | }
|
| 127 |
|
| 128 | static inline struct atm_vcc *ATM_SD(struct socket *sock)
|
| 129 | {
|
| 130 | return atm_sk(sock->sk);
|
| 131 | }
|
| 132 |
|
| 133 | static inline struct sock *sk_atm(struct atm_vcc *vcc)
|
| 134 | {
|
| 135 | return (struct sock *)vcc;
|
| 136 | }
|
| 137 |
|
| 138 | struct atm_dev_addr {
|
| 139 | struct sockaddr_atmsvc addr;
|
| 140 | struct list_head entry;
|
| 141 | };
|
| 142 |
|
| 143 | enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
|
| 144 |
|
| 145 | struct atm_dev {
|
| 146 | const struct atmdev_ops *ops;
|
| 147 | const struct atmphy_ops *phy;
|
| 148 |
|
| 149 | const char *type;
|
| 150 | int number;
|
| 151 | void *dev_data;
|
| 152 | void *phy_data;
|
| 153 | unsigned long flags;
|
| 154 | struct list_head local;
|
| 155 | struct list_head lecs;
|
| 156 | unsigned char esi[ESI_LEN];
|
| 157 | struct atm_cirange ci_range;
|
| 158 | struct k_atm_dev_stats stats;
|
| 159 | char signal;
|
| 160 | int link_rate;
|
| 161 | atomic_t refcnt;
|
| 162 | spinlock_t lock;
|
| 163 | #ifdef CONFIG_PROC_FS
|
| 164 | struct proc_dir_entry *proc_entry;
|
| 165 | char *proc_name;
|
| 166 | #endif
|
| 167 | struct device class_dev;
|
| 168 | struct list_head dev_list;
|
| 169 | };
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 | #define ATM_OF_IMMED 1
|
| 175 | #define ATM_OF_INRATE 2
|
| 176 |
|
| 177 |
|
| 178 | |
| 179 | * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
|
| 180 |
|
| 181 |
|
| 182 | struct atmdev_ops {
|
| 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);
|
| 187 | #ifdef CONFIG_COMPAT
|
| 188 | int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
|
| 189 | void __user *arg);
|
| 190 | #endif
|
| 191 | 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,
|
| 194 | void __user *optval,unsigned int optlen);
|
| 195 | 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 |
|
| 205 | struct 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 |
|
| 212 | struct atm_skb_data {
|
| 213 | struct atm_vcc *vcc;
|
| 214 | unsigned long atm_options;
|
| 215 | };
|
| 216 |
|
| 217 | #define VCC_HTABLE_SIZE 32
|
| 218 |
|
| 219 | extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
|
| 220 | extern rwlock_t vcc_sklist_lock;
|
| 221 |
|
| 222 | #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
|
| 223 |
|
| 224 | struct atm_dev *atm_dev_register(const char *type, struct device *parent,
|
| 225 | const struct atmdev_ops *ops,
|
| 226 | int number,
|
| 227 | unsigned long *flags);
|
| 228 | struct atm_dev *atm_dev_lookup(int number);
|
| 229 | void atm_dev_deregister(struct atm_dev *dev);
|
| 230 |
|
| 231 | |
| 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 |
|
| 236 | void atm_dev_signal_change(struct atm_dev *dev, char signal);
|
| 237 |
|
| 238 | void vcc_insert_socket(struct sock *sk);
|
| 239 |
|
| 240 | void atm_dev_release_vccs(struct atm_dev *dev);
|
| 241 |
|
| 242 |
|
| 243 | static 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 |
|
| 249 | static inline void atm_return(struct atm_vcc *vcc,int truesize)
|
| 250 | {
|
| 251 | atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
|
| 252 | }
|
| 253 |
|
| 254 |
|
| 255 | static 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 |
|
| 262 | static inline void atm_dev_hold(struct atm_dev *dev)
|
| 263 | {
|
| 264 | atomic_inc(&dev->refcnt);
|
| 265 | }
|
| 266 |
|
| 267 |
|
| 268 | static inline void atm_dev_put(struct atm_dev *dev)
|
| 269 | {
|
| 270 | 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);
|
| 274 | put_device(&dev->class_dev);
|
| 275 | }
|
| 276 | }
|
| 277 |
|
| 278 |
|
| 279 | int atm_charge(struct atm_vcc *vcc,int truesize);
|
| 280 | struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
|
| 281 | gfp_t gfp_flags);
|
| 282 | int atm_pcr_goal(const struct atm_trafprm *tp);
|
| 283 |
|
| 284 | void vcc_release_async(struct atm_vcc *vcc, int reply);
|
| 285 |
|
| 286 | struct atm_ioctl {
|
| 287 | struct module *owner;
|
| 288 | |
| 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 |
|
| 301 | void register_atm_ioctl(struct atm_ioctl *);
|
| 302 |
|
| 303 | |
| 304 | * deregister_atm_ioctl - remove the ioctl handler
|
| 305 |
|
| 306 | void deregister_atm_ioctl(struct atm_ioctl *);
|
| 307 |
|
| 308 |
|
| 309 | |
| 310 | *
|
| 311 | * Clients like br2684 will register notify events
|
| 312 | * Currently we notify of signal found/lost
|
| 313 |
|
| 314 | int register_atmdevice_notifier(struct notifier_block *nb);
|
| 315 | void unregister_atmdevice_notifier(struct notifier_block *nb);
|
| 316 |
|
| 317 | #endif
|