Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* atmdev.h - ATM device driver declarations and various related items */
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,        /* Address is in use. Set by anybody, cleared
0049                    by device driver. */
0050     ATM_VF_READY,       /* VC is ready to transfer data. Set by device
0051                    driver, cleared by anybody. */
0052     ATM_VF_PARTIAL,     /* resources are bound to PVC (partial PVC
0053                    setup), controlled by socket layer */
0054     ATM_VF_REGIS,       /* registered with demon, controlled by SVC
0055                    socket layer */
0056     ATM_VF_BOUND,       /* local SAP is set, controlled by SVC socket
0057                    layer */
0058     ATM_VF_RELEASED,    /* demon has indicated/requested release,
0059                    controlled by SVC socket layer */
0060     ATM_VF_HASQOS,      /* QOS parameters have been set */
0061     ATM_VF_LISTEN,      /* socket is used for listening */
0062     ATM_VF_META,        /* SVC socket isn't used for normal data
0063                    traffic and doesn't depend on signaling
0064                    to be available */
0065     ATM_VF_SESSION,     /* VCC is p2mp session control descriptor */
0066     ATM_VF_HASSAP,      /* SAP has been set */
0067     ATM_VF_CLOSE,       /* asynchronous close - treat like VF_RELEASED*/
0068     ATM_VF_WAITING,     /* waiting for reply from sigd */
0069     ATM_VF_IS_CLIP,     /* in use by CLIP protocol */
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,     /* device was removed from atm_devs list */
0083 };
0084 
0085 
0086 #define ATM_PHY_SIG_LOST    0   /* no carrier/light */
0087 #define ATM_PHY_SIG_UNKNOWN 1   /* carrier/light status is unknown */
0088 #define ATM_PHY_SIG_FOUND   2   /* carrier/light okay */
0089 
0090 #define ATM_ATMOPT_CLP  1   /* set CLP bit */
0091 
0092 struct atm_vcc {
0093     /* struct sock has to be the first member of atm_vcc */
0094     struct sock sk;
0095     unsigned long   flags;      /* VCC flags (ATM_VF_*) */
0096     short       vpi;        /* VPI and VCI (types must be equal */
0097                     /* with sockaddr) */
0098     int         vci;
0099     unsigned long   aal_options;    /* AAL layer options */
0100     unsigned long   atm_options;    /* ATM layer options */
0101     struct atm_dev  *dev;       /* device back pointer */
0102     struct atm_qos  qos;        /* QOS */
0103     struct atm_sap  sap;        /* SAP */
0104     void (*release_cb)(struct atm_vcc *vcc); /* release_sock callback */
0105     void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
0106     void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
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;  /* per-device data */
0110     void        *proto_data;    /* per-protocol data */
0111     struct k_atm_aal_stats *stats;  /* pointer to AAL stats group */
0112     struct module *owner;       /* owner of ->push function */
0113     /* SVC part --- may move later ------------------------------------- */
0114     short       itf;        /* interface number */
0115     struct sockaddr_atmsvc local;
0116     struct sockaddr_atmsvc remote;
0117     /* Multipoint part ------------------------------------------------- */
0118     struct atm_vcc  *session;   /* session VCC descriptor */
0119     /* Other stuff ----------------------------------------------------- */
0120     void        *user_back; /* user backlink - not touched by */
0121                     /* native ATM stack. Currently used */
0122                     /* by CLIP and sch_atm. */
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;    /* ATM address */
0142     struct list_head entry;     /* next address */
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;   /* device operations; NULL if unused */
0149     const struct atmphy_ops *phy;   /* PHY operations, may be undefined */
0150                     /* (NULL) */
0151     const char  *type;      /* device type name */
0152     int     number;     /* device index */
0153     void        *dev_data;  /* per-device data */
0154     void        *phy_data;  /* private PHY data */
0155     unsigned long   flags;      /* device flags (ATM_DF_*) */
0156     struct list_head local;     /* local ATM addresses */
0157     struct list_head lecs;      /* LECS ATM addresses learned via ILMI */
0158     unsigned char   esi[ESI_LEN];   /* ESI ("MAC" addr) */
0159     struct atm_cirange ci_range;    /* VPI/VCI range */
0160     struct k_atm_dev_stats stats;   /* statistics */
0161     char        signal;     /* signal status (ATM_PHY_SIG_*) */
0162     int     link_rate;  /* link rate (default: OC3) */
0163     refcount_t  refcnt;     /* reference count */
0164     spinlock_t  lock;       /* protect internal members */
0165 #ifdef CONFIG_PROC_FS
0166     struct proc_dir_entry *proc_entry; /* proc entry */
0167     char *proc_name;        /* proc entry name */
0168 #endif
0169     struct device class_dev;    /* sysfs device */
0170     struct list_head dev_list;  /* linkage */
0171 };
0172 
0173  
0174 /* OF: send_Oam Flags */
0175 
0176 #define ATM_OF_IMMED  1     /* Attempt immediate delivery */
0177 #define ATM_OF_INRATE 2     /* Attempt in-rate delivery */
0178 
0179 struct atmdev_ops { /* only send is required */
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;       /* ATM VCC */
0208     unsigned long   atm_options;    /* ATM layer options */
0209     unsigned int    acct_truesize;  /* truesize accounted to vcc */
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, /* -1 == pick first available */
0222                  unsigned long *flags);
0223 struct atm_dev *atm_dev_lookup(int number);
0224 void atm_dev_deregister(struct atm_dev *dev);
0225 
0226 /* atm_dev_signal_change
0227  *
0228  * Propagate lower layer signal change in atm_dev->signal to netdevice.
0229  * The event will be sent via a notifier call chain.
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      * Because ATM skbs may not belong to a sock (and we don't
0241      * necessarily want to), skb->truesize may be adjusted,
0242      * escaping the hack in pskb_expand_head() which avoids
0243      * doing so for some cases. So stash the value of truesize
0244      * at the time we accounted it, and atm_pop_raw() can use
0245      * that value later, in case it changes.
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     /* A module reference is kept if appropriate over this call.
0298      * Return -ENOIOCTLCMD if you don't handle it. */
0299     int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
0300     struct list_head list;
0301 };
0302 
0303 /**
0304  * register_atm_ioctl - register handler for ioctl operations
0305  *
0306  * Special (non-device) handlers of ioctl's should
0307  * register here. If you're a normal device, you should
0308  * set .ioctl in your atmdev_ops instead.
0309  */
0310 void register_atm_ioctl(struct atm_ioctl *);
0311 
0312 /**
0313  * deregister_atm_ioctl - remove the ioctl handler
0314  */
0315 void deregister_atm_ioctl(struct atm_ioctl *);
0316 
0317 
0318 /* register_atmdevice_notifier - register atm_dev notify events
0319  *
0320  * Clients like br2684 will register notify events
0321  * Currently we notify of signal found/lost
0322  */
0323 int register_atmdevice_notifier(struct notifier_block *nb);
0324 void unregister_atmdevice_notifier(struct notifier_block *nb);
0325 
0326 #endif