cdc-acm.h 4.0 KB

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