0001
0002
0003 #ifndef LINUX_ATMDEV_H
0004 #define LINUX_ATMDEV_H
0005
0006
0007 #include <linux/wait.h> /* wait_queue_head_t */
0008 #include <linux/time.h> /* struct timeval */
0009 #include <linux/net.h>
0010 #include <linux/bug.h>
0011 #include <linux/skbuff.h> /* struct sk_buff */
0012 #include <linux/uio.h>
0013 #include <net/sock.h>
0014 #include <linux/atomic.h>
0015 #include <linux/refcount.h>
0016 #include <uapi/linux/atmdev.h>
0017
0018 #ifdef CONFIG_PROC_FS
0019 #include <linux/proc_fs.h>
0020
0021 extern struct proc_dir_entry *atm_proc_root;
0022 #endif
0023
0024 #ifdef CONFIG_COMPAT
0025 #include <linux/compat.h>
0026 struct compat_atm_iobuf {
0027 int length;
0028 compat_uptr_t buffer;
0029 };
0030 #endif
0031
0032 struct k_atm_aal_stats {
0033 #define __HANDLE_ITEM(i) atomic_t i
0034 __AAL_STAT_ITEMS
0035 #undef __HANDLE_ITEM
0036 };
0037
0038
0039 struct k_atm_dev_stats {
0040 struct k_atm_aal_stats aal0;
0041 struct k_atm_aal_stats aal34;
0042 struct k_atm_aal_stats aal5;
0043 };
0044
0045 struct device;
0046
0047 enum {
0048 ATM_VF_ADDR,
0049
0050 ATM_VF_READY,
0051
0052 ATM_VF_PARTIAL,
0053
0054 ATM_VF_REGIS,
0055
0056 ATM_VF_BOUND,
0057
0058 ATM_VF_RELEASED,
0059
0060 ATM_VF_HASQOS,
0061 ATM_VF_LISTEN,
0062 ATM_VF_META,
0063
0064
0065 ATM_VF_SESSION,
0066 ATM_VF_HASSAP,
0067 ATM_VF_CLOSE,
0068 ATM_VF_WAITING,
0069 ATM_VF_IS_CLIP,
0070 };
0071
0072
0073 #define ATM_VF2VS(flags) \
0074 (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
0075 test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
0076 test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
0077 test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
0078 test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
0079
0080
0081 enum {
0082 ATM_DF_REMOVED,
0083 };
0084
0085
0086 #define ATM_PHY_SIG_LOST 0
0087 #define ATM_PHY_SIG_UNKNOWN 1
0088 #define ATM_PHY_SIG_FOUND 2
0089
0090 #define ATM_ATMOPT_CLP 1
0091
0092 struct atm_vcc {
0093
0094 struct sock sk;
0095 unsigned long flags;
0096 short vpi;
0097
0098 int vci;
0099 unsigned long aal_options;
0100 unsigned long atm_options;
0101 struct atm_dev *dev;
0102 struct atm_qos qos;
0103 struct atm_sap sap;
0104 void (*release_cb)(struct atm_vcc *vcc);
0105 void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
0106 void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb);
0107 int (*push_oam)(struct atm_vcc *vcc,void *cell);
0108 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
0109 void *dev_data;
0110 void *proto_data;
0111 struct k_atm_aal_stats *stats;
0112 struct module *owner;
0113
0114 short itf;
0115 struct sockaddr_atmsvc local;
0116 struct sockaddr_atmsvc remote;
0117
0118 struct atm_vcc *session;
0119
0120 void *user_back;
0121
0122
0123 };
0124
0125 static inline struct atm_vcc *atm_sk(struct sock *sk)
0126 {
0127 return (struct atm_vcc *)sk;
0128 }
0129
0130 static inline struct atm_vcc *ATM_SD(struct socket *sock)
0131 {
0132 return atm_sk(sock->sk);
0133 }
0134
0135 static inline struct sock *sk_atm(struct atm_vcc *vcc)
0136 {
0137 return (struct sock *)vcc;
0138 }
0139
0140 struct atm_dev_addr {
0141 struct sockaddr_atmsvc addr;
0142 struct list_head entry;
0143 };
0144
0145 enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
0146
0147 struct atm_dev {
0148 const struct atmdev_ops *ops;
0149 const struct atmphy_ops *phy;
0150
0151 const char *type;
0152 int number;
0153 void *dev_data;
0154 void *phy_data;
0155 unsigned long flags;
0156 struct list_head local;
0157 struct list_head lecs;
0158 unsigned char esi[ESI_LEN];
0159 struct atm_cirange ci_range;
0160 struct k_atm_dev_stats stats;
0161 char signal;
0162 int link_rate;
0163 refcount_t refcnt;
0164 spinlock_t lock;
0165 #ifdef CONFIG_PROC_FS
0166 struct proc_dir_entry *proc_entry;
0167 char *proc_name;
0168 #endif
0169 struct device class_dev;
0170 struct list_head dev_list;
0171 };
0172
0173
0174
0175
0176 #define ATM_OF_IMMED 1
0177 #define ATM_OF_INRATE 2
0178
0179 struct atmdev_ops {
0180 void (*dev_close)(struct atm_dev *dev);
0181 int (*open)(struct atm_vcc *vcc);
0182 void (*close)(struct atm_vcc *vcc);
0183 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
0184 #ifdef CONFIG_COMPAT
0185 int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
0186 void __user *arg);
0187 #endif
0188 int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
0189 int (*send_bh)(struct atm_vcc *vcc, struct sk_buff *skb);
0190 int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
0191 void (*phy_put)(struct atm_dev *dev,unsigned char value,
0192 unsigned long addr);
0193 unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
0194 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
0195 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
0196 struct module *owner;
0197 };
0198
0199 struct atmphy_ops {
0200 int (*start)(struct atm_dev *dev);
0201 int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
0202 void (*interrupt)(struct atm_dev *dev);
0203 int (*stop)(struct atm_dev *dev);
0204 };
0205
0206 struct atm_skb_data {
0207 struct atm_vcc *vcc;
0208 unsigned long atm_options;
0209 unsigned int acct_truesize;
0210 } __packed;
0211
0212 #define VCC_HTABLE_SIZE 32
0213
0214 extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
0215 extern rwlock_t vcc_sklist_lock;
0216
0217 #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
0218
0219 struct atm_dev *atm_dev_register(const char *type, struct device *parent,
0220 const struct atmdev_ops *ops,
0221 int number,
0222 unsigned long *flags);
0223 struct atm_dev *atm_dev_lookup(int number);
0224 void atm_dev_deregister(struct atm_dev *dev);
0225
0226
0227
0228
0229
0230
0231 void atm_dev_signal_change(struct atm_dev *dev, char signal);
0232
0233 void vcc_insert_socket(struct sock *sk);
0234
0235 void atm_dev_release_vccs(struct atm_dev *dev);
0236
0237 static inline void atm_account_tx(struct atm_vcc *vcc, struct sk_buff *skb)
0238 {
0239
0240
0241
0242
0243
0244
0245
0246
0247 refcount_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
0248 ATM_SKB(skb)->acct_truesize = skb->truesize;
0249 ATM_SKB(skb)->atm_options = vcc->atm_options;
0250 }
0251
0252 static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
0253 {
0254 atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
0255 }
0256
0257
0258 static inline void atm_return(struct atm_vcc *vcc,int truesize)
0259 {
0260 atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
0261 }
0262
0263
0264 static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
0265 {
0266 return (size + refcount_read(&sk_atm(vcc)->sk_wmem_alloc)) <
0267 sk_atm(vcc)->sk_sndbuf;
0268 }
0269
0270
0271 static inline void atm_dev_hold(struct atm_dev *dev)
0272 {
0273 refcount_inc(&dev->refcnt);
0274 }
0275
0276
0277 static inline void atm_dev_put(struct atm_dev *dev)
0278 {
0279 if (refcount_dec_and_test(&dev->refcnt)) {
0280 BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
0281 if (dev->ops->dev_close)
0282 dev->ops->dev_close(dev);
0283 put_device(&dev->class_dev);
0284 }
0285 }
0286
0287
0288 int atm_charge(struct atm_vcc *vcc,int truesize);
0289 struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
0290 gfp_t gfp_flags);
0291 int atm_pcr_goal(const struct atm_trafprm *tp);
0292
0293 void vcc_release_async(struct atm_vcc *vcc, int reply);
0294
0295 struct atm_ioctl {
0296 struct module *owner;
0297
0298
0299 int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
0300 struct list_head list;
0301 };
0302
0303
0304
0305
0306
0307
0308
0309
0310 void register_atm_ioctl(struct atm_ioctl *);
0311
0312
0313
0314
0315 void deregister_atm_ioctl(struct atm_ioctl *);
0316
0317
0318
0319
0320
0321
0322
0323 int register_atmdevice_notifier(struct notifier_block *nb);
0324 void unregister_atmdevice_notifier(struct notifier_block *nb);
0325
0326 #endif