irda-usb.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*****************************************************************************
  2. *
  3. * Filename: irda-usb.h
  4. * Version: 0.10
  5. * Description: IrDA-USB Driver
  6. * Status: Experimental
  7. * Author: Dag Brattli <dag@brattli.net>
  8. *
  9. * Copyright (C) 2001, Roman Weissgaerber <weissg@vienna.at>
  10. * Copyright (C) 2000, Dag Brattli <dag@brattli.net>
  11. * Copyright (C) 2001, Jean Tourrilhes <jt@hpl.hp.com>
  12. * Copyright (C) 2004, SigmaTel, Inc. <irquality@sigmatel.com>
  13. * Copyright (C) 2005, Milan Beno <beno@pobox.sk>
  14. * Copyright (C) 2006, Nick FEdchik <nick@fedchik.org.ua>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. *
  30. *****************************************************************************/
  31. #include <linux/ktime.h>
  32. #include <net/irda/irda.h>
  33. #include <net/irda/irda_device.h> /* struct irlap_cb */
  34. #define RX_COPY_THRESHOLD 200
  35. #define IRDA_USB_MAX_MTU 2051
  36. #define IRDA_USB_SPEED_MTU 64 /* Weird, but work like this */
  37. /* Maximum number of active URB on the Rx path
  38. * This is the amount of buffers the we keep between the USB harware and the
  39. * IrDA stack.
  40. *
  41. * Note : the network layer does also queue the packets between us and the
  42. * IrDA stack, and is actually pretty fast and efficient in doing that.
  43. * Therefore, we don't need to have a large number of URBs, and we can
  44. * perfectly live happy with only one. We certainly don't need to keep the
  45. * full IrTTP window around here...
  46. * I repeat for those who have trouble to understand : 1 URB is plenty
  47. * good enough to handle back-to-back (brickwalled) frames. I tried it,
  48. * it works (it's the hardware that has trouble doing it).
  49. *
  50. * Having 2 URBs would allow the USB stack to process one URB while we take
  51. * care of the other and then swap the URBs...
  52. * On the other hand, increasing the number of URB will have penalities
  53. * in term of latency and will interact with the link management in IrLAP...
  54. * Jean II */
  55. #define IU_MAX_ACTIVE_RX_URBS 1 /* Don't touch !!! */
  56. /* When a Rx URB is passed back to us, we can't reuse it immediately,
  57. * because it may still be referenced by the USB layer. Therefore we
  58. * need to keep one extra URB in the Rx path.
  59. * Jean II */
  60. #define IU_MAX_RX_URBS (IU_MAX_ACTIVE_RX_URBS + 1)
  61. /* Various ugly stuff to try to workaround generic problems */
  62. /* Send speed command in case of timeout, just for trying to get things sane */
  63. #define IU_BUG_KICK_TIMEOUT
  64. /* Show the USB class descriptor */
  65. #undef IU_DUMP_CLASS_DESC
  66. /* Assume a minimum round trip latency for USB transfer (in us)...
  67. * USB transfer are done in the next USB slot if there is no traffic
  68. * (1/19 msec) and is done at 12 Mb/s :
  69. * Waiting for slot + tx = (53us + 16us) * 2 = 137us minimum.
  70. * Rx notification will only be done at the end of the USB frame period :
  71. * OHCI : frame period = 1ms
  72. * UHCI : frame period = 1ms, but notification can take 2 or 3 ms :-(
  73. * EHCI : frame period = 125us */
  74. #define IU_USB_MIN_RTT 500 /* This should be safe in most cases */
  75. /* Inbound header */
  76. #define MEDIA_BUSY 0x80
  77. #define SPEED_2400 0x01
  78. #define SPEED_9600 0x02
  79. #define SPEED_19200 0x03
  80. #define SPEED_38400 0x04
  81. #define SPEED_57600 0x05
  82. #define SPEED_115200 0x06
  83. #define SPEED_576000 0x07
  84. #define SPEED_1152000 0x08
  85. #define SPEED_4000000 0x09
  86. #define SPEED_16000000 0x0a
  87. /* Basic capabilities */
  88. #define IUC_DEFAULT 0x00 /* Basic device compliant with 1.0 spec */
  89. /* Main bugs */
  90. #define IUC_SPEED_BUG 0x01 /* Device doesn't set speed after the frame */
  91. #define IUC_NO_WINDOW 0x02 /* Device doesn't behave with big Rx window */
  92. #define IUC_NO_TURN 0x04 /* Device doesn't do turnaround by itself */
  93. /* Not currently used */
  94. #define IUC_SIR_ONLY 0x08 /* Device doesn't behave at FIR speeds */
  95. #define IUC_SMALL_PKT 0x10 /* Device doesn't behave with big Rx packets */
  96. #define IUC_MAX_WINDOW 0x20 /* Device underestimate the Rx window */
  97. #define IUC_MAX_XBOFS 0x40 /* Device need more xbofs than advertised */
  98. #define IUC_STIR421X 0x80 /* SigmaTel 4210/4220/4116 VFIR */
  99. /* USB class definitions */
  100. #define USB_IRDA_HEADER 0x01
  101. #define USB_CLASS_IRDA 0x02 /* USB_CLASS_APP_SPEC subclass */
  102. #define USB_DT_IRDA 0x21
  103. #define USB_IRDA_STIR421X_HEADER 0x03
  104. #define IU_SIGMATEL_MAX_RX_URBS (IU_MAX_ACTIVE_RX_URBS + \
  105. USB_IRDA_STIR421X_HEADER)
  106. struct irda_class_desc {
  107. __u8 bLength;
  108. __u8 bDescriptorType;
  109. __le16 bcdSpecRevision;
  110. __u8 bmDataSize;
  111. __u8 bmWindowSize;
  112. __u8 bmMinTurnaroundTime;
  113. __le16 wBaudRate;
  114. __u8 bmAdditionalBOFs;
  115. __u8 bIrdaRateSniff;
  116. __u8 bMaxUnicastList;
  117. } __packed;
  118. /* class specific interface request to get the IrDA-USB class descriptor
  119. * (6.2.5, USB-IrDA class spec 1.0) */
  120. #define IU_REQ_GET_CLASS_DESC 0x06
  121. #define STIR421X_MAX_PATCH_DOWNLOAD_SIZE 1023
  122. struct irda_usb_cb {
  123. struct irda_class_desc *irda_desc;
  124. struct usb_device *usbdev; /* init: probe_irda */
  125. struct usb_interface *usbintf; /* init: probe_irda */
  126. int netopen; /* Device is active for network */
  127. int present; /* Device is present on the bus */
  128. __u32 capability; /* Capability of the hardware */
  129. __u8 bulk_in_ep; /* Rx Endpoint assignments */
  130. __u8 bulk_out_ep; /* Tx Endpoint assignments */
  131. __u16 bulk_out_mtu; /* Max Tx packet size in bytes */
  132. __u8 bulk_int_ep; /* Interrupt Endpoint assignments */
  133. __u8 max_rx_urb;
  134. struct urb **rx_urb; /* URBs used to receive data frames */
  135. struct urb *idle_rx_urb; /* Pointer to idle URB in Rx path */
  136. struct urb *tx_urb; /* URB used to send data frames */
  137. struct urb *speed_urb; /* URB used to send speed commands */
  138. struct net_device *netdev; /* Yes! we are some kind of netdev. */
  139. struct irlap_cb *irlap; /* The link layer we are binded to */
  140. struct qos_info qos;
  141. char *speed_buff; /* Buffer for speed changes */
  142. char *tx_buff;
  143. ktime_t stamp;
  144. spinlock_t lock; /* For serializing Tx operations */
  145. __u16 xbofs; /* Current xbofs setting */
  146. __s16 new_xbofs; /* xbofs we need to set */
  147. __u32 speed; /* Current speed */
  148. __s32 new_speed; /* speed we need to set */
  149. __u8 header_length; /* USB-IrDA frame header size */
  150. int needspatch; /* device needs firmware patch */
  151. struct timer_list rx_defer_timer; /* Wait for Rx error to clear */
  152. };