Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* atmdev.h - ATM device driver declarations and various related items */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef LINUX_ATMDEV_H |
| 3 | #define LINUX_ATMDEV_H |
| 4 | |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/wait.h> /* wait_queue_head_t */ |
| 7 | #include <linux/time.h> /* struct timeval */ |
| 8 | #include <linux/net.h> |
Paul Gortmaker | 187f188 | 2011-11-23 20:12:59 -0500 | [diff] [blame] | 9 | #include <linux/bug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/skbuff.h> /* struct sk_buff */ |
| 11 | #include <linux/uio.h> |
| 12 | #include <net/sock.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 13 | #include <linux/atomic.h> |
Reshetova, Elena | 458bc30 | 2017-07-04 15:53:01 +0300 | [diff] [blame] | 14 | #include <linux/refcount.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 15 | #include <uapi/linux/atmdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
David Woodhouse | 8865c41 | 2008-12-03 22:12:38 -0800 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 44 | struct device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 { |
Stanislaw Gruszka | 64bf69d | 2005-11-29 16:16:41 -0800 | [diff] [blame] | 81 | ATM_DF_REMOVED, /* device was removed from atm_devs list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
David Woodhouse | c971f08 | 2012-11-28 00:03:11 +0000 | [diff] [blame] | 103 | void (*release_cb)(struct atm_vcc *vcc); /* release_sock callback */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Krzysztof Mazur | ec809bd | 2012-11-06 23:16:57 +0100 | [diff] [blame] | 111 | struct module *owner; /* owner of ->push function */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Eric Kinzie | 0f21ba7 | 2005-10-06 22:19:28 -0700 | [diff] [blame] | 144 | enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS }; |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Eric Kinzie | 0f21ba7 | 2005-10-06 22:19:28 -0700 | [diff] [blame] | 156 | struct list_head lecs; /* LECS ATM addresses learned via ILMI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) */ |
Reshetova, Elena | 458bc30 | 2017-07-04 15:53:01 +0300 | [diff] [blame] | 162 | refcount_t refcnt; /* reference count */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Kay Sievers | ef39592 | 2007-12-30 23:16:06 -0800 | [diff] [blame] | 168 | struct device class_dev; /* sysfs device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
David Woodhouse | 8865c41 | 2008-12-03 22:12:38 -0800 | [diff] [blame] | 188 | #ifdef CONFIG_COMPAT |
| 189 | int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd, |
| 190 | void __user *arg); |
| 191 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 195 | void __user *optval,unsigned int optlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Dan Williams | d9ca676 | 2010-12-08 19:40:47 +0000 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | struct atm_dev *atm_dev_lookup(int number); |
| 230 | void atm_dev_deregister(struct atm_dev *dev); |
Karl Hiramoto | 7313bb8 | 2010-07-08 20:55:30 +0000 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | void vcc_insert_socket(struct sock *sk); |
| 240 | |
Philip A. Prindeville | c031235 | 2011-03-30 13:17:04 +0000 | [diff] [blame] | 241 | void atm_dev_release_vccs(struct atm_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | { |
Reshetova, Elena | 14afee4 | 2017-06-30 13:08:00 +0300 | [diff] [blame] | 258 | return (size + refcount_read(&sk_atm(vcc)->sk_wmem_alloc)) < |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | sk_atm(vcc)->sk_sndbuf; |
| 260 | } |
| 261 | |
| 262 | |
| 263 | static inline void atm_dev_hold(struct atm_dev *dev) |
| 264 | { |
Reshetova, Elena | 458bc30 | 2017-07-04 15:53:01 +0300 | [diff] [blame] | 265 | refcount_inc(&dev->refcnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | |
| 269 | static inline void atm_dev_put(struct atm_dev *dev) |
| 270 | { |
Reshetova, Elena | 458bc30 | 2017-07-04 15:53:01 +0300 | [diff] [blame] | 271 | if (refcount_dec_and_test(&dev->refcnt)) { |
Stanislaw Gruszka | 64bf69d | 2005-11-29 16:16:41 -0800 | [diff] [blame] | 272 | BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags)); |
| 273 | if (dev->ops->dev_close) |
| 274 | dev->ops->dev_close(dev); |
Kay Sievers | ef39592 | 2007-12-30 23:16:06 -0800 | [diff] [blame] | 275 | put_device(&dev->class_dev); |
Stanislaw Gruszka | 64bf69d | 2005-11-29 16:16:41 -0800 | [diff] [blame] | 276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 282 | gfp_t gfp_flags); |
Mitchell Blank Jr | c219750 | 2005-11-29 16:13:55 -0800 | [diff] [blame] | 283 | int atm_pcr_goal(const struct atm_trafprm *tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Karl Hiramoto | 7313bb8 | 2010-07-08 20:55:30 +0000 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | #endif |