WUSB-Design-overview.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. Linux UWB + Wireless USB + WiNET
  2. (C) 2005-2006 Intel Corporation
  3. Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License version
  6. 2 as published by the Free Software Foundation.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  14. 02110-1301, USA.
  15. Please visit http://bughost.org/thewiki/Design-overview.txt-1.8 for
  16. updated content.
  17. * Design-overview.txt-1.8
  18. This code implements a Ultra Wide Band stack for Linux, as well as
  19. drivers for the the USB based UWB radio controllers defined in the
  20. Wireless USB 1.0 specification (including Wireless USB host controller
  21. and an Intel WiNET controller).
  22. 1. Introduction
  23. 1. HWA: Host Wire adapters, your Wireless USB dongle
  24. 2. DWA: Device Wired Adaptor, a Wireless USB hub for wired
  25. devices
  26. 3. WHCI: Wireless Host Controller Interface, the PCI WUSB host
  27. adapter
  28. 2. The UWB stack
  29. 1. Devices and hosts: the basic structure
  30. 2. Host Controller life cycle
  31. 3. On the air: beacons and enumerating the radio neighborhood
  32. 4. Device lists
  33. 5. Bandwidth allocation
  34. 3. Wireless USB Host Controller drivers
  35. 4. Glossary
  36. Introduction
  37. UWB is a wide-band communication protocol that is to serve also as the
  38. low-level protocol for others (much like TCP sits on IP). Currently
  39. these others are Wireless USB and TCP/IP, but seems Bluetooth and
  40. Firewire/1394 are coming along.
  41. UWB uses a band from roughly 3 to 10 GHz, transmitting at a max of
  42. ~-41dB (or 0.074 uW/MHz--geography specific data is still being
  43. negotiated w/ regulators, so watch for changes). That band is divided in
  44. a bunch of ~1.5 GHz wide channels (or band groups) composed of three
  45. subbands/subchannels (528 MHz each). Each channel is independent of each
  46. other, so you could consider them different "busses". Initially this
  47. driver considers them all a single one.
  48. Radio time is divided in 65536 us long /superframes/, each one divided
  49. in 256 256us long /MASs/ (Media Allocation Slots), which are the basic
  50. time/media allocation units for transferring data. At the beginning of
  51. each superframe there is a Beacon Period (BP), where every device
  52. transmit its beacon on a single MAS. The length of the BP depends on how
  53. many devices are present and the length of their beacons.
  54. Devices have a MAC (fixed, 48 bit address) and a device (changeable, 16
  55. bit address) and send periodic beacons to advertise themselves and pass
  56. info on what they are and do. They advertise their capabilities and a
  57. bunch of other stuff.
  58. The different logical parts of this driver are:
  59. *
  60. *UWB*: the Ultra-Wide-Band stack -- manages the radio and
  61. associated spectrum to allow for devices sharing it. Allows to
  62. control bandwidth assignment, beaconing, scanning, etc
  63. *
  64. *WUSB*: the layer that sits on top of UWB to provide Wireless USB.
  65. The Wireless USB spec defines means to control a UWB radio and to
  66. do the actual WUSB.
  67. HWA: Host Wire adapters, your Wireless USB dongle
  68. WUSB also defines a device called a Host Wire Adaptor (HWA), which in
  69. mere terms is a USB dongle that enables your PC to have UWB and Wireless
  70. USB. The Wireless USB Host Controller in a HWA looks to the host like a
  71. [Wireless] USB controller connected via USB (!)
  72. The HWA itself is broken in two or three main interfaces:
  73. *
  74. *RC*: Radio control -- this implements an interface to the
  75. Ultra-Wide-Band radio controller. The driver for this implements a
  76. USB-based UWB Radio Controller to the UWB stack.
  77. *
  78. *HC*: the wireless USB host controller. It looks like a USB host
  79. whose root port is the radio and the WUSB devices connect to it.
  80. To the system it looks like a separate USB host. The driver (will)
  81. implement a USB host controller (similar to UHCI, OHCI or EHCI)
  82. for which the root hub is the radio...To reiterate: it is a USB
  83. controller that is connected via USB instead of PCI.
  84. *
  85. *WINET*: some HW provide a WiNET interface (IP over UWB). This
  86. package provides a driver for it (it looks like a network
  87. interface, winetX). The driver detects when there is a link up for
  88. their type and kick into gear.
  89. DWA: Device Wired Adaptor, a Wireless USB hub for wired devices
  90. These are the complement to HWAs. They are a USB host for connecting
  91. wired devices, but it is connected to your PC connected via Wireless
  92. USB. To the system it looks like yet another USB host. To the untrained
  93. eye, it looks like a hub that connects upstream wirelessly.
  94. We still offer no support for this; however, it should share a lot of
  95. code with the HWA-RC driver; there is a bunch of factorization work that
  96. has been done to support that in upcoming releases.
  97. WHCI: Wireless Host Controller Interface, the PCI WUSB host adapter
  98. This is your usual PCI device that implements WHCI. Similar in concept
  99. to EHCI, it allows your wireless USB devices (including DWAs) to connect
  100. to your host via a PCI interface. As in the case of the HWA, it has a
  101. Radio Control interface and the WUSB Host Controller interface per se.
  102. There is still no driver support for this, but will be in upcoming
  103. releases.
  104. The UWB stack
  105. The main mission of the UWB stack is to keep a tally of which devices
  106. are in radio proximity to allow drivers to connect to them. As well, it
  107. provides an API for controlling the local radio controllers (RCs from
  108. now on), such as to start/stop beaconing, scan, allocate bandwidth, etc.
  109. Devices and hosts: the basic structure
  110. The main building block here is the UWB device (struct uwb_dev). For
  111. each device that pops up in radio presence (ie: the UWB host receives a
  112. beacon from it) you get a struct uwb_dev that will show up in
  113. /sys/class/uwb and in /sys/bus/uwb/devices.
  114. For each RC that is detected, a new struct uwb_rc is created. In turn, a
  115. RC is also a device, so they also show in /sys/class/uwb and
  116. /sys/bus/uwb/devices, but at the same time, only radio controllers show
  117. up in /sys/class/uwb_rc.
  118. *
  119. [*] The reason for RCs being also devices is that not only we can
  120. see them while enumerating the system device tree, but also on the
  121. radio (their beacons and stuff), so the handling has to be
  122. likewise to that of a device.
  123. Each RC driver is implemented by a separate driver that plugs into the
  124. interface that the UWB stack provides through a struct uwb_rc_ops. The
  125. spec creators have been nice enough to make the message format the same
  126. for HWA and WHCI RCs, so the driver is really a very thin transport that
  127. moves the requests from the UWB API to the device [/uwb_rc_ops->cmd()/]
  128. and sends the replies and notifications back to the API
  129. [/uwb_rc_neh_grok()/]. Notifications are handled to the UWB daemon, that
  130. is chartered, among other things, to keep the tab of how the UWB radio
  131. neighborhood looks, creating and destroying devices as they show up or
  132. disappear.
  133. Command execution is very simple: a command block is sent and a event
  134. block or reply is expected back. For sending/receiving command/events, a
  135. handle called /neh/ (Notification/Event Handle) is opened with
  136. /uwb_rc_neh_open()/.
  137. The HWA-RC (USB dongle) driver (drivers/uwb/hwa-rc.c) does this job for
  138. the USB connected HWA. Eventually, drivers/whci-rc.c will do the same
  139. for the PCI connected WHCI controller.
  140. Host Controller life cycle
  141. So let's say we connect a dongle to the system: it is detected and
  142. firmware uploaded if needed [for Intel's i1480
  143. /drivers/uwb/ptc/usb.c:ptc_usb_probe()/] and then it is reenumerated.
  144. Now we have a real HWA device connected and
  145. /drivers/uwb/hwa-rc.c:hwarc_probe()/ picks it up, that will set up the
  146. Wire-Adaptor environment and then suck it into the UWB stack's vision of
  147. the world [/drivers/uwb/lc-rc.c:uwb_rc_add()/].
  148. *
  149. [*] The stack should put a new RC to scan for devices
  150. [/uwb_rc_scan()/] so it finds what's available around and tries to
  151. connect to them, but this is policy stuff and should be driven
  152. from user space. As of now, the operator is expected to do it
  153. manually; see the release notes for documentation on the procedure.
  154. When a dongle is disconnected, /drivers/uwb/hwa-rc.c:hwarc_disconnect()/
  155. takes time of tearing everything down safely (or not...).
  156. On the air: beacons and enumerating the radio neighborhood
  157. So assuming we have devices and we have agreed for a channel to connect
  158. on (let's say 9), we put the new RC to beacon:
  159. *
  160. $ echo 9 0 > /sys/class/uwb_rc/uwb0/beacon
  161. Now it is visible. If there were other devices in the same radio channel
  162. and beacon group (that's what the zero is for), the dongle's radio
  163. control interface will send beacon notifications on its
  164. notification/event endpoint (NEEP). The beacon notifications are part of
  165. the event stream that is funneled into the API with
  166. /drivers/uwb/neh.c:uwb_rc_neh_grok()/ and delivered to the UWBD, the UWB
  167. daemon through a notification list.
  168. UWBD wakes up and scans the event list; finds a beacon and adds it to
  169. the BEACON CACHE (/uwb_beca/). If he receives a number of beacons from
  170. the same device, he considers it to be 'onair' and creates a new device
  171. [/drivers/uwb/lc-dev.c:uwbd_dev_onair()/]. Similarly, when no beacons
  172. are received in some time, the device is considered gone and wiped out
  173. [uwbd calls periodically /uwb/beacon.c:uwb_beca_purge()/ that will purge
  174. the beacon cache of dead devices].
  175. Device lists
  176. All UWB devices are kept in the list of the struct bus_type uwb_bus.
  177. Bandwidth allocation
  178. The UWB stack maintains a local copy of DRP availability through
  179. processing of incoming *DRP Availability Change* notifications. This
  180. local copy is currently used to present the current bandwidth
  181. availability to the user through the sysfs file
  182. /sys/class/uwb_rc/uwbx/bw_avail. In the future the bandwidth
  183. availability information will be used by the bandwidth reservation
  184. routines.
  185. The bandwidth reservation routines are in progress and are thus not
  186. present in the current release. When completed they will enable a user
  187. to initiate DRP reservation requests through interaction with sysfs. DRP
  188. reservation requests from remote UWB devices will also be handled. The
  189. bandwidth management done by the UWB stack will include callbacks to the
  190. higher layers will enable the higher layers to use the reservations upon
  191. completion. [Note: The bandwidth reservation work is in progress and
  192. subject to change.]
  193. Wireless USB Host Controller drivers
  194. *WARNING* This section needs a lot of work!
  195. As explained above, there are three different types of HCs in the WUSB
  196. world: HWA-HC, DWA-HC and WHCI-HC.
  197. HWA-HC and DWA-HC share that they are Wire-Adapters (USB or WUSB
  198. connected controllers), and their transfer management system is almost
  199. identical. So is their notification delivery system.
  200. HWA-HC and WHCI-HC share that they are both WUSB host controllers, so
  201. they have to deal with WUSB device life cycle and maintenance, wireless
  202. root-hub
  203. HWA exposes a Host Controller interface (HWA-HC 0xe0/02/02). This has
  204. three endpoints (Notifications, Data Transfer In and Data Transfer
  205. Out--known as NEP, DTI and DTO in the code).
  206. We reserve UWB bandwidth for our Wireless USB Cluster, create a Cluster
  207. ID and tell the HC to use all that. Then we start it. This means the HC
  208. starts sending MMCs.
  209. *
  210. The MMCs are blocks of data defined somewhere in the WUSB1.0 spec
  211. that define a stream in the UWB channel time allocated for sending
  212. WUSB IEs (host to device commands/notifications) and Device
  213. Notifications (device initiated to host). Each host defines a
  214. unique Wireless USB cluster through MMCs. Devices can connect to a
  215. single cluster at the time. The IEs are Information Elements, and
  216. among them are the bandwidth allocations that tell each device
  217. when can they transmit or receive.
  218. Now it all depends on external stimuli.
  219. *New device connection*
  220. A new device pops up, it scans the radio looking for MMCs that give out
  221. the existence of Wireless USB channels. Once one (or more) are found,
  222. selects which one to connect to. Sends a /DN_Connect/ (device
  223. notification connect) during the DNTS (Device Notification Time
  224. Slot--announced in the MMCs
  225. HC picks the /DN_Connect/ out (nep module sends to notif.c for delivery
  226. into /devconnect/). This process starts the authentication process for
  227. the device. First we allocate a /fake port/ and assign an
  228. unauthenticated address (128 to 255--what we really do is
  229. 0x80 | fake_port_idx). We fiddle with the fake port status and /khubd/
  230. sees a new connection, so he moves on to enable the fake port with a reset.
  231. So now we are in the reset path -- we know we have a non-yet enumerated
  232. device with an unauthorized address; we ask user space to authenticate
  233. (FIXME: not yet done, similar to bluetooth pairing), then we do the key
  234. exchange (FIXME: not yet done) and issue a /set address 0/ to bring the
  235. device to the default state. Device is authenticated.
  236. From here, the USB stack takes control through the usb_hcd ops. khubd
  237. has seen the port status changes, as we have been toggling them. It will
  238. start enumerating and doing transfers through usb_hcd->urb_enqueue() to
  239. read descriptors and move our data.
  240. *Device life cycle and keep alives*
  241. Every time there is a successful transfer to/from a device, we update a
  242. per-device activity timestamp. If not, every now and then we check and
  243. if the activity timestamp gets old, we ping the device by sending it a
  244. Keep Alive IE; it responds with a /DN_Alive/ pong during the DNTS (this
  245. arrives to us as a notification through
  246. devconnect.c:wusb_handle_dn_alive(). If a device times out, we
  247. disconnect it from the system (cleaning up internal information and
  248. toggling the bits in the fake hub port, which kicks khubd into removing
  249. the rest of the stuff).
  250. This is done through devconnect:__wusb_check_devs(), which will scan the
  251. device list looking for whom needs refreshing.
  252. If the device wants to disconnect, it will either die (ugly) or send a
  253. /DN_Disconnect/ that will prompt a disconnection from the system.
  254. *Sending and receiving data*
  255. Data is sent and received through /Remote Pipes/ (rpipes). An rpipe is
  256. /aimed/ at an endpoint in a WUSB device. This is the same for HWAs and
  257. DWAs.
  258. Each HC has a number of rpipes and buffers that can be assigned to them;
  259. when doing a data transfer (xfer), first the rpipe has to be aimed and
  260. prepared (buffers assigned), then we can start queueing requests for
  261. data in or out.
  262. Data buffers have to be segmented out before sending--so we send first a
  263. header (segment request) and then if there is any data, a data buffer
  264. immediately after to the DTI interface (yep, even the request). If our
  265. buffer is bigger than the max segment size, then we just do multiple
  266. requests.
  267. [This sucks, because doing USB scatter gatter in Linux is resource
  268. intensive, if any...not that the current approach is not. It just has to
  269. be cleaned up a lot :)].
  270. If reading, we don't send data buffers, just the segment headers saying
  271. we want to read segments.
  272. When the xfer is executed, we receive a notification that says data is
  273. ready in the DTI endpoint (handled through
  274. xfer.c:wa_handle_notif_xfer()). In there we read from the DTI endpoint a
  275. descriptor that gives us the status of the transfer, its identification
  276. (given when we issued it) and the segment number. If it was a data read,
  277. we issue another URB to read into the destination buffer the chunk of
  278. data coming out of the remote endpoint. Done, wait for the next guy. The
  279. callbacks for the URBs issued from here are the ones that will declare
  280. the xfer complete at some point and call its callback.
  281. Seems simple, but the implementation is not trivial.
  282. *
  283. *WARNING* Old!!
  284. The main xfer descriptor, wa_xfer (equivalent to a URB) contains an
  285. array of segments, tallys on segments and buffers and callback
  286. information. Buried in there is a lot of URBs for executing the segments
  287. and buffer transfers.
  288. For OUT xfers, there is an array of segments, one URB for each, another
  289. one of buffer URB. When submitting, we submit URBs for segment request
  290. 1, buffer 1, segment 2, buffer 2...etc. Then we wait on the DTI for xfer
  291. result data; when all the segments are complete, we call the callback to
  292. finalize the transfer.
  293. For IN xfers, we only issue URBs for the segments we want to read and
  294. then wait for the xfer result data.
  295. *URB mapping into xfers*
  296. This is done by hwahc_op_urb_[en|de]queue(). In enqueue() we aim an
  297. rpipe to the endpoint where we have to transmit, create a transfer
  298. context (wa_xfer) and submit it. When the xfer is done, our callback is
  299. called and we assign the status bits and release the xfer resources.
  300. In dequeue() we are basically cancelling/aborting the transfer. We issue
  301. a xfer abort request to the HC, cancel all the URBs we had submitted
  302. and not yet done and when all that is done, the xfer callback will be
  303. called--this will call the URB callback.
  304. Glossary
  305. *DWA* -- Device Wire Adapter
  306. USB host, wired for downstream devices, upstream connects wirelessly
  307. with Wireless USB.
  308. *EVENT* -- Response to a command on the NEEP
  309. *HWA* -- Host Wire Adapter / USB dongle for UWB and Wireless USB
  310. *NEH* -- Notification/Event Handle
  311. Handle/file descriptor for receiving notifications or events. The WA
  312. code requires you to get one of this to listen for notifications or
  313. events on the NEEP.
  314. *NEEP* -- Notification/Event EndPoint
  315. Stuff related to the management of the first endpoint of a HWA USB
  316. dongle that is used to deliver an stream of events and notifications to
  317. the host.
  318. *NOTIFICATION* -- Message coming in the NEEP as response to something.
  319. *RC* -- Radio Control
  320. Design-overview.txt-1.8 (last edited 2006-11-04 12:22:24 by
  321. InakyPerezGonzalez)