cdc-acm.h 3.5 KB

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