Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *
0004  * Includes for cdc-acm.c
0005  *
0006  * Mainly take from usbnet's cdc-ether part
0007  *
0008  */
0009 
0010 /*
0011  * Major and minor numbers.
0012  */
0013 
0014 #define ACM_TTY_MAJOR       166
0015 #define ACM_TTY_MINORS      256
0016 
0017 #define ACM_MINOR_INVALID   ACM_TTY_MINORS
0018 
0019 /*
0020  * Requests.
0021  */
0022 
0023 #define USB_RT_ACM      (USB_TYPE_CLASS | USB_RECIP_INTERFACE)
0024 
0025 /*
0026  * Internal driver structures.
0027  */
0028 
0029 /*
0030  * The only reason to have several buffers is to accommodate assumptions
0031  * in line disciplines. They ask for empty space amount, receive our URB size,
0032  * and proceed to issue several 1-character writes, assuming they will fit.
0033  * The very first write takes a complete URB. Fortunately, this only happens
0034  * when processing onlcr, so we only need 2 buffers. These values must be
0035  * powers of 2.
0036  */
0037 #define ACM_NW  16
0038 #define ACM_NR  16
0039 
0040 struct acm_wb {
0041     u8 *buf;
0042     dma_addr_t dmah;
0043     unsigned int len;
0044     struct urb      *urb;
0045     struct acm      *instance;
0046     bool use;
0047 };
0048 
0049 struct acm_rb {
0050     int         size;
0051     unsigned char       *base;
0052     dma_addr_t      dma;
0053     int         index;
0054     struct acm      *instance;
0055 };
0056 
0057 struct acm {
0058     struct usb_device *dev;             /* the corresponding usb device */
0059     struct usb_interface *control;          /* control interface */
0060     struct usb_interface *data;         /* data interface */
0061     unsigned in, out;               /* i/o pipes */
0062     struct tty_port port;               /* our tty port data */
0063     struct urb *ctrlurb;                /* urbs */
0064     u8 *ctrl_buffer;                /* buffers of urbs */
0065     dma_addr_t ctrl_dma;                /* dma handles of buffers */
0066     u8 *country_codes;              /* country codes from device */
0067     unsigned int country_code_size;         /* size of this buffer */
0068     unsigned int country_rel_date;          /* release date of version */
0069     struct acm_wb wb[ACM_NW];
0070     unsigned long read_urbs_free;
0071     struct urb *read_urbs[ACM_NR];
0072     struct acm_rb read_buffers[ACM_NR];
0073     int rx_buflimit;
0074     spinlock_t read_lock;
0075     u8 *notification_buffer;            /* to reassemble fragmented notifications */
0076     unsigned int nb_index;
0077     unsigned int nb_size;
0078     int transmitting;
0079     spinlock_t write_lock;
0080     struct mutex mutex;
0081     bool disconnected;
0082     unsigned long flags;
0083 #       define EVENT_TTY_WAKEUP 0
0084 #       define EVENT_RX_STALL   1
0085 #       define ACM_THROTTLED    2
0086 #       define ACM_ERROR_DELAY  3
0087     unsigned long urbs_in_error_delay;      /* these need to be restarted after a delay */
0088     struct usb_cdc_line_coding line;        /* bits, stop, parity */
0089     struct delayed_work dwork;              /* work queue entry for various purposes */
0090     unsigned int ctrlin;                /* input control lines (DCD, DSR, RI, break, overruns) */
0091     unsigned int ctrlout;               /* output control lines (DTR, RTS) */
0092     struct async_icount iocount;            /* counters for control line changes */
0093     struct async_icount oldcount;           /* for comparison of counter */
0094     wait_queue_head_t wioctl;           /* for ioctl */
0095     unsigned int writesize;             /* max packet size for the output bulk endpoint */
0096     unsigned int readsize,ctrlsize;         /* buffer sizes for freeing */
0097     unsigned int minor;             /* acm minor number */
0098     unsigned char clocal;               /* termios CLOCAL */
0099     unsigned int ctrl_caps;             /* control capabilities from the class specific header */
0100     unsigned int susp_count;            /* number of suspended interfaces */
0101     unsigned int combined_interfaces:1;     /* control and data collapsed */
0102     u8 bInterval;
0103     struct usb_anchor delayed;          /* writes queued for a device about to be woken */
0104     unsigned long quirks;
0105 };
0106 
0107 /* constants describing various quirks and errors */
0108 #define NO_UNION_NORMAL         BIT(0)
0109 #define SINGLE_RX_URB           BIT(1)
0110 #define NO_CAP_LINE         BIT(2)
0111 #define IGNORE_DEVICE           BIT(3)
0112 #define QUIRK_CONTROL_LINE_STATE    BIT(4)
0113 #define CLEAR_HALT_CONDITIONS       BIT(5)
0114 #define SEND_ZERO_PACKET        BIT(6)
0115 #define DISABLE_ECHO            BIT(7)