1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * 4 * Includes for cdc-acm.c 5 * 6 * Mainly take from usbnet's cdc-ether part 7 * 8 */ 9 10 /* 11 * Major and minor numbers. 12 */ 13 14 #define ACM_TTY_MAJOR 166 15 #define ACM_TTY_MINORS 256 16 17 #define ACM_MINOR_INVALID ACM_TTY_MINORS 18 19 /* 20 * Requests. 21 */ 22 23 #define USB_RT_ACM (USB_TYPE_CLASS | USB_RECIP_INTERFACE) 24 25 /* 26 * Input control lines and line errors. 27 */ 28 29 #define ACM_CTRL_DCD 0x01 30 #define ACM_CTRL_DSR 0x02 31 #define ACM_CTRL_BRK 0x04 32 #define ACM_CTRL_RI 0x08 33 34 #define ACM_CTRL_FRAMING 0x10 35 #define ACM_CTRL_PARITY 0x20 36 #define ACM_CTRL_OVERRUN 0x40 37 38 /* 39 * Internal driver structures. 40 */ 41 42 /* 43 * The only reason to have several buffers is to accommodate assumptions 44 * in line disciplines. They ask for empty space amount, receive our URB size, 45 * and proceed to issue several 1-character writes, assuming they will fit. 46 * The very first write takes a complete URB. Fortunately, this only happens 47 * when processing onlcr, so we only need 2 buffers. These values must be 48 * powers of 2. 49 */ 50 #define ACM_NW 16 51 #define ACM_NR 16 52 53 struct acm_wb { 54 u8 *buf; 55 dma_addr_t dmah; 56 unsigned int len; 57 struct urb *urb; 58 struct acm *instance; 59 bool use; 60 }; 61 62 struct acm_rb { 63 int size; 64 unsigned char *base; 65 dma_addr_t dma; 66 int index; 67 struct acm *instance; 68 }; 69 70 struct acm { 71 struct usb_device *dev; /* the corresponding usb device */ 72 struct usb_interface *control; /* control interface */ 73 struct usb_interface *data; /* data interface */ 74 unsigned in, out; /* i/o pipes */ 75 struct tty_port port; /* our tty port data */ 76 struct urb *ctrlurb; /* urbs */ 77 u8 *ctrl_buffer; /* buffers of urbs */ 78 dma_addr_t ctrl_dma; /* dma handles of buffers */ 79 u8 *country_codes; /* country codes from device */ 80 unsigned int country_code_size; /* size of this buffer */ 81 unsigned int country_rel_date; /* release date of version */ 82 struct acm_wb wb[ACM_NW]; 83 unsigned long read_urbs_free; 84 struct urb *read_urbs[ACM_NR]; 85 struct acm_rb read_buffers[ACM_NR]; 86 int rx_buflimit; 87 spinlock_t read_lock; 88 u8 *notification_buffer; /* to reassemble fragmented notifications */ 89 unsigned int nb_index; 90 unsigned int nb_size; 91 int transmitting; 92 spinlock_t write_lock; 93 struct mutex mutex; 94 bool disconnected; 95 unsigned long flags; 96 # define EVENT_TTY_WAKEUP 0 97 # define EVENT_RX_STALL 1 98 # define ACM_THROTTLED 2 99 # define ACM_ERROR_DELAY 3 100 unsigned long urbs_in_error_delay; /* these need to be restarted after a delay */ 101 struct usb_cdc_line_coding line; /* bits, stop, parity */ 102 struct delayed_work dwork; /* work queue entry for various purposes */ 103 unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */ 104 unsigned int ctrlout; /* output control lines (DTR, RTS) */ 105 struct async_icount iocount; /* counters for control line changes */ 106 struct async_icount oldcount; /* for comparison of counter */ 107 wait_queue_head_t wioctl; /* for ioctl */ 108 unsigned int writesize; /* max packet size for the output bulk endpoint */ 109 unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ 110 unsigned int minor; /* acm minor number */ 111 unsigned char clocal; /* termios CLOCAL */ 112 unsigned int ctrl_caps; /* control capabilities from the class specific header */ 113 unsigned int susp_count; /* number of suspended interfaces */ 114 unsigned int combined_interfaces:1; /* control and data collapsed */ 115 u8 bInterval; 116 struct usb_anchor delayed; /* writes queued for a device about to be woken */ 117 unsigned long quirks; 118 }; 119 120 /* constants describing various quirks and errors */ 121 #define NO_UNION_NORMAL BIT(0) 122 #define SINGLE_RX_URB BIT(1) 123 #define NO_CAP_LINE BIT(2) 124 #define IGNORE_DEVICE BIT(3) 125 #define QUIRK_CONTROL_LINE_STATE BIT(4) 126 #define CLEAR_HALT_CONDITIONS BIT(5) 127 #define SEND_ZERO_PACKET BIT(6) 128 #define DISABLE_ECHO BIT(7) 129