Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /******************************************************************************
0003  *  usbatm.h - Generic USB xDSL driver core
0004  *
0005  *  Copyright (C) 2001, Alcatel
0006  *  Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
0007  *  Copyright (C) 2004, David Woodhouse
0008  ******************************************************************************/
0009 
0010 #ifndef _USBATM_H_
0011 #define _USBATM_H_
0012 
0013 #include <linux/atm.h>
0014 #include <linux/atmdev.h>
0015 #include <linux/completion.h>
0016 #include <linux/device.h>
0017 #include <linux/kernel.h>
0018 #include <linux/kref.h>
0019 #include <linux/list.h>
0020 #include <linux/stringify.h>
0021 #include <linux/usb.h>
0022 #include <linux/mutex.h>
0023 #include <linux/ratelimit.h>
0024 
0025 /*
0026 #define VERBOSE_DEBUG
0027 */
0028 
0029 #define usb_err(instance, format, arg...)   \
0030     dev_err(&(instance)->usb_intf->dev , format , ## arg)
0031 #define usb_info(instance, format, arg...)  \
0032     dev_info(&(instance)->usb_intf->dev , format , ## arg)
0033 #define usb_warn(instance, format, arg...)  \
0034     dev_warn(&(instance)->usb_intf->dev , format , ## arg)
0035 #define usb_dbg(instance, format, arg...)   \
0036     dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
0037 
0038 /* FIXME: move to dev_* once ATM is driver model aware */
0039 #define atm_printk(level, instance, format, arg...) \
0040     printk(level "ATM dev %d: " format ,        \
0041     (instance)->atm_dev->number , ## arg)
0042 
0043 #define atm_err(instance, format, arg...)   \
0044     atm_printk(KERN_ERR, instance , format , ## arg)
0045 #define atm_info(instance, format, arg...)  \
0046     atm_printk(KERN_INFO, instance , format , ## arg)
0047 #define atm_warn(instance, format, arg...)  \
0048     atm_printk(KERN_WARNING, instance , format , ## arg)
0049 #define atm_dbg(instance, format, ...)                  \
0050     pr_debug("ATM dev %d: " format,                 \
0051          (instance)->atm_dev->number, ##__VA_ARGS__)
0052 #define atm_rldbg(instance, format, ...)                \
0053     pr_debug_ratelimited("ATM dev %d: " format,         \
0054                  (instance)->atm_dev->number, ##__VA_ARGS__)
0055 
0056 /* flags, set by mini-driver in bind() */
0057 
0058 #define UDSL_SKIP_HEAVY_INIT    (1<<0)
0059 #define UDSL_USE_ISOC       (1<<1)
0060 #define UDSL_IGNORE_EILSEQ  (1<<2)
0061 
0062 
0063 /* mini driver */
0064 
0065 struct usbatm_data;
0066 
0067 /*
0068 *  Assuming all methods exist and succeed, they are called in this order:
0069 *
0070 *   bind, heavy_init, atm_start, ..., atm_stop, unbind
0071 */
0072 
0073 struct usbatm_driver {
0074     const char *driver_name;
0075 
0076     /* init device ... can sleep, or cause probe() failure */
0077     int (*bind) (struct usbatm_data *, struct usb_interface *,
0078              const struct usb_device_id *id);
0079 
0080     /* additional device initialization that is too slow to be done in probe() */
0081     int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
0082 
0083     /* cleanup device ... can sleep, but can't fail */
0084     void (*unbind) (struct usbatm_data *, struct usb_interface *);
0085 
0086     /* init ATM device ... can sleep, or cause ATM initialization failure */
0087     int (*atm_start) (struct usbatm_data *, struct atm_dev *);
0088 
0089     /* cleanup ATM device ... can sleep, but can't fail */
0090     void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
0091 
0092     int bulk_in;    /* bulk rx endpoint */
0093     int isoc_in;    /* isochronous rx endpoint */
0094     int bulk_out;   /* bulk tx endpoint */
0095 
0096     unsigned rx_padding;
0097     unsigned tx_padding;
0098 };
0099 
0100 extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
0101         struct usbatm_driver *driver);
0102 extern void usbatm_usb_disconnect(struct usb_interface *intf);
0103 
0104 
0105 struct usbatm_channel {
0106     int endpoint;           /* usb pipe */
0107     unsigned int stride;        /* ATM cell size + padding */
0108     unsigned int buf_size;      /* urb buffer size */
0109     unsigned int packet_size;   /* endpoint maxpacket */
0110     spinlock_t lock;
0111     struct list_head list;
0112     struct tasklet_struct tasklet;
0113     struct timer_list delay;
0114     struct usbatm_data *usbatm;
0115 };
0116 
0117 /* main driver data */
0118 
0119 struct usbatm_data {
0120     /******************
0121     *  public fields  *
0122     ******************/
0123 
0124     /* mini driver */
0125     struct usbatm_driver *driver;
0126     void *driver_data;
0127     char driver_name[16];
0128     unsigned int flags; /* set by mini-driver in bind() */
0129 
0130     /* USB device */
0131     struct usb_device *usb_dev;
0132     struct usb_interface *usb_intf;
0133     char description[64];
0134 
0135     /* ATM device */
0136     struct atm_dev *atm_dev;
0137 
0138     /********************************
0139     *  private fields - do not use  *
0140     ********************************/
0141 
0142     struct kref refcount;
0143     struct mutex serialize;
0144     int disconnected;
0145 
0146     /* heavy init */
0147     struct task_struct *thread;
0148     struct completion thread_started;
0149     struct completion thread_exited;
0150 
0151     /* ATM device */
0152     struct list_head vcc_list;
0153 
0154     struct usbatm_channel rx_channel;
0155     struct usbatm_channel tx_channel;
0156 
0157     struct sk_buff_head sndqueue;
0158     struct sk_buff *current_skb;    /* being emptied */
0159 
0160     struct usbatm_vcc_data *cached_vcc;
0161     int cached_vci;
0162     short cached_vpi;
0163 
0164     unsigned char *cell_buf;    /* holds partial rx cell */
0165     unsigned int buf_usage;
0166 
0167     struct urb *urbs[];
0168 };
0169 
0170 static inline void *to_usbatm_driver_data(struct usb_interface *intf)
0171 {
0172     struct usbatm_data *usbatm_instance;
0173 
0174     if (intf == NULL)
0175         return NULL;
0176 
0177     usbatm_instance = usb_get_intfdata(intf);
0178 
0179     if (usbatm_instance == NULL) /* set NULL before unbind() */
0180         return NULL;
0181 
0182     return usbatm_instance->driver_data; /* set NULL after unbind() */
0183 }
0184 
0185 #endif  /* _USBATM_H_ */