cdc-acm.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. /*
  21. * Requests.
  22. */
  23. #define USB_RT_ACM (USB_TYPE_CLASS | USB_RECIP_INTERFACE)
  24. /*
  25. * Output control lines.
  26. */
  27. #define ACM_CTRL_DTR 0x01
  28. #define ACM_CTRL_RTS 0x02
  29. /*
  30. * Input control lines and line errors.
  31. */
  32. #define ACM_CTRL_DCD 0x01
  33. #define ACM_CTRL_DSR 0x02
  34. #define ACM_CTRL_BRK 0x04
  35. #define ACM_CTRL_RI 0x08
  36. #define ACM_CTRL_FRAMING 0x10
  37. #define ACM_CTRL_PARITY 0x20
  38. #define ACM_CTRL_OVERRUN 0x40
  39. /*
  40. * Internal driver structures.
  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. struct acm_wb {
  53. unsigned char *buf;
  54. dma_addr_t dmah;
  55. int len;
  56. int use;
  57. struct urb *urb;
  58. struct acm *instance;
  59. };
  60. struct acm_rb {
  61. int size;
  62. unsigned char *base;
  63. dma_addr_t dma;
  64. int index;
  65. struct acm *instance;
  66. };
  67. struct acm {
  68. struct usb_device *dev; /* the corresponding usb device */
  69. struct usb_interface *control; /* control interface */
  70. struct usb_interface *data; /* data interface */
  71. unsigned in, out; /* i/o pipes */
  72. struct tty_port port; /* our tty port data */
  73. struct urb *ctrlurb; /* urbs */
  74. u8 *ctrl_buffer; /* buffers of urbs */
  75. dma_addr_t ctrl_dma; /* dma handles of buffers */
  76. u8 *country_codes; /* country codes from device */
  77. unsigned int country_code_size; /* size of this buffer */
  78. unsigned int country_rel_date; /* release date of version */
  79. struct acm_wb wb[ACM_NW];
  80. unsigned long read_urbs_free;
  81. struct urb *read_urbs[ACM_NR];
  82. struct acm_rb read_buffers[ACM_NR];
  83. int rx_buflimit;
  84. spinlock_t read_lock;
  85. u8 *notification_buffer; /* to reassemble fragmented notifications */
  86. unsigned int nb_index;
  87. unsigned int nb_size;
  88. int transmitting;
  89. spinlock_t write_lock;
  90. struct mutex mutex;
  91. bool disconnected;
  92. unsigned long flags;
  93. # define EVENT_TTY_WAKEUP 0
  94. # define EVENT_RX_STALL 1
  95. struct usb_cdc_line_coding line; /* bits, stop, parity */
  96. struct work_struct work; /* work queue entry for line discipline waking up */
  97. unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */
  98. unsigned int ctrlout; /* output control lines (DTR, RTS) */
  99. struct async_icount iocount; /* counters for control line changes */
  100. struct async_icount oldcount; /* for comparison of counter */
  101. wait_queue_head_t wioctl; /* for ioctl */
  102. unsigned int writesize; /* max packet size for the output bulk endpoint */
  103. unsigned int readsize,ctrlsize; /* buffer sizes for freeing */
  104. unsigned int minor; /* acm minor number */
  105. unsigned char clocal; /* termios CLOCAL */
  106. unsigned int ctrl_caps; /* control capabilities from the class specific header */
  107. unsigned int susp_count; /* number of suspended interfaces */
  108. unsigned int combined_interfaces:1; /* control and data collapsed */
  109. unsigned int throttled:1; /* actually throttled */
  110. unsigned int throttle_req:1; /* throttle requested */
  111. u8 bInterval;
  112. struct usb_anchor delayed; /* writes queued for a device about to be woken */
  113. unsigned long quirks;
  114. };
  115. #define CDC_DATA_INTERFACE_TYPE 0x0a
  116. /* constants describing various quirks and errors */
  117. #define NO_UNION_NORMAL BIT(0)
  118. #define SINGLE_RX_URB BIT(1)
  119. #define NO_CAP_LINE BIT(2)
  120. #define NO_DATA_INTERFACE BIT(4)
  121. #define IGNORE_DEVICE BIT(5)
  122. #define QUIRK_CONTROL_LINE_STATE BIT(6)
  123. #define CLEAR_HALT_CONDITIONS BIT(7)
  124. #define SEND_ZERO_PACKET BIT(8)
  125. #define DISABLE_ECHO BIT(9)