Академический Документы
Профессиональный Документы
Культура Документы
H IROYUKI B ESSHO
Genetec corp.
bsh@NetBSD.org
USBP Driver for the peripheral side of the USB proto- • Limitations set by non-cooperative USB interfaces
col. It handles the USB protocol on the control pipe.
This includes, for example, enumeration and con- 4.3.1 Endpoint limitations
figuration.
The USB specification defines that USB devices can have
up to 16 endpoints. The USB host connects a pipe to a
USB interface drivers Drivers for the peripheral side
device’s endpoint and use it for communication flow be-
of USB interfaces. These drivers implement the
tween the host and the device. Among the 16 endpoints,
functionality of USB devices, such as USB serial
endpoint #0 is special and used for USB device config-
adapters, communication-class devices, mass stor-
uration. A pipe to an endpoint #0 is called a control
age devices, human interface devices, audio, video,
pipe. Some USB devices use control pipes for normal
etc.
data transactions.
As USB pipes cannot be shared among interfaces1 , the
Client controller drivers Drivers for client controllers. number of total endpoints used by all interfaces in the
These drivers send USB packets to and receive USB
device must be less than 15 excluding the control pipe.
packets from the USB host through the USB client Also note that pipes are unidirectional.
controller. There are many kind of USB client con-
trollers on the market, and they vary in design. 1 except for control pipes
pxaudc0 at obio0 # USB client controller on PXA250
usbp0 at pxaudc0 # peripheral - side USB support
upftdi * at usbp0 # emulates FTDI USB serial adapter
In addition, even if the USB specification allows 16 Also, USB devices identified by class code in their de-
endpoints per device, USB client controllers may not vice descriptors are non-cooperative either.
have all of them implemented. Some controllers provide Any number of cooperative interfaces can form a com-
fewer than 16 endpoints. posite device as long as they satisfy the endpoint limita-
Some USB client controllers set specific purposes to tions.
each endpoint. For example, PXA250’s2 client controller Two or more non-cooperative interfaces cannot co-
dedicates endpoints #1, 6, 11 to bulk IN pipes, and #4, 9, exist in a single USB device, because they insist on act-
14 to isochronous OUT pipes (see Table 1). So if inter- ing as an entire USB device rather than as a single inter-
face drivers require 4 bulk IN pipes total, they can not be face in a device.
configured in one device on the platforms with PXA250, One non-cooperative USB interface and some cooper-
even though the total number of endpoints required by ative USB interfaces may be able to co-exist in one USB
USB interfaces is below 16. device, but it may require special handling in a host-side
driver.
transfer type direction endpoints
control 0
bulk IN 1, 6, 11 4.3.3 Attaching many USB interfaces to USBP
bulk OUT 2, 7, 12 Any number of USB interfaces can be attached to USBP.
isochronous IN 3, 8, 13 Because of the limitations discussed above, however,
isochronous OUT 4, 9, 14 USBP may not build up a USB device consisting of all
interrupt IN 5, 10, 15 USB interfaces attached to it. USBP selects as many
USB interfaces as possible to construct a USB device,
Table 1: Endpoints of PXA250 client controller and ignores the remaining interfaces.
Thus, priorities among attached interfaces need to be
4.3.2 Cooperative USB interfaces set. In the current implementation, an interface attached
later has higher priority.
‘Cooperative USB interface’ is not a term defined in the
USB specification. It is introduced here for this discus-
sion. 5 Transform
USB interfaces are cooperative when they:
The functionality of the USB device implemented using
• are identified by class codes in interface descriptors, USBP framework is defined by USB interface drivers at-
and tached to USBP. That can be changed by attaching/de-
taching USB interfaces while the peripheral-side plat-
• don’t require exclusive use of the control pipe (pipe
form is running. In other words, that USB device can
#0) for them.
transform to a different device without rebooting the ker-
Some USB devices, such as USB serial devices use nel with a different configuration.
bulk pipes for data transfer, and a control pipe for chang- A USB device can transform by:
ing their mode. Thus, they are ‘non-cooperative’.
USB devices that have vendor-specific class codes and • loading/unloading kernel modules for USB inter-
are identified by vendor ID and product ID are non- face drivers.
cooperative. They require a specific host-side driver.
• attaching/detaching USB interface drivers to USBP
2 ARM based SoC by Marvell, formerly Intel via drvctl
usbp0 at pxaudc ? # peripheral - side USB support
upmass * at usbp0 # mass storage
cdcef * at usbp0 # CDC ECM
side of USB.
usbd_bus usbf_bus
References
ucom for
usbd_device ucom(4) peripheral usbf_device
side [1] USB Implementers Forum, Inc. (2000). Universal
usbd_interface
Serial Bus Revision 2.0 Specification
can't use usbf_interface
usbd_device usbp_device
interface
usbd_interface usbp_interface
usbd_endpoint
ucom(4) usbd_pipe
usbp(4)
uftdi(4) usbd_xfer
usb(4)
upftdi(4)
11 Conclusion
This paper presented a new framework for NetBSD to
support peripheral-side USB. With this framework, we
can make platforms with NetBSD run as USB devices,
with fairly small amount of new source code. This will
be helpful for developing embedded systems.
Acknowledgment
I started this project by porting OpenBSD’s usbf(4) and
cdcef(4) drivers to NetBSD. They were initially written
by Uwe Stühler.
I would like to thank Taylor R. Campbell, Greg Oster,
and Masanobu Saitoh for reviewing this paper, suggest-
ing improvements, and fixing many grammatical errors.
If you still find broken English in this paper, those sen-
1 /∗
2 ∗ i n f o r m a t i o n u s e d t o b u i l d USB d e v i c e d e s c r i p t o r .
3 ∗/
4 struct usbp device info {
5 int16 t class id ;
6 int16 t subclass id ;
7 int protocol ;
8 int vendor id ;
9 int product id ;
10 int bcd device ; /∗ d e v i c e r e l e a s e number i n BCD ∗/
11 const char ∗ manufacturer name ;
12 const char ∗ product name ;
13 const char ∗ s e r i a l ; /∗ d e v i c e ’ s s e r i a l number ∗/
14 } ;
15
16 #d e f i n e USBP ID UNSPECIFIC ( −1)
17
18 /∗
19 ∗ r e q u i r e m e n t s o f an e n d p o i n t u s e d by t h e i n t e r f a c e
20 ∗/
21 s t r u c t u s b p e n d p o i n t r e q u e s t {
22 uint8 t direction ; /∗ UE DIR IN o r UE DIR OUT ∗/
23 uint8 t attributes ; /∗ T r a n s f e r t y p e :
24 UE ISOCHROMOUS , UE BULK , UE INTERRUPT ∗/
25 u int packetsize ;
26 /∗ need more f o r i s o c h r o n o u s ∗/
27 } ;
28
29 /∗
30 ∗ i n f o r m a t i o n u s e d t o b u i l d an i n t e r f a c e d e s c r i p t o r
31 ∗/
32 s t r u c t u s b p i n t e r f a c e s p e c {
33 uint8 t class id ;
34 uint8 t subclass id ;
35 uint8 t protocol ;
36 enum USBP PIPE0 USAGE {
37 USBP PIPE0 NOTUSED , /∗ t h i s i n t e r f a c e d o e s n ’ t u s e p i p e #0 ∗/
38 USBP PIPE0 SHARED , /∗ p i p e#0 i s s h a r e d among i n t e r f a c e s ,
39 by means o f i n t e r f a c e number i n t h e p a c k e t s ∗/
40 USBP PIPE0 EXCLUSIVE /∗ t h i s i n t e r f a c e r e q u i r e s an
41 e x c l u s i v e u s e o f p i p e#0 ∗/
42 } pipe0 usage ;
43 const char ∗ d e s c r i p t i o n ;
44 u i n t 8 t n u m e n d p o i n t s ; /∗ t h e number o f e n d p o i n t s u s e d by
45 t h i s i n t e r f a c e e x c l u d i n g ep0 . ∗/
46 struct usbp endpoint request endpoints [ ] ;
47 } ;
48
49 u s b d s t a t u s u s b p a d d i n t e r f a c e (
50 struct usbp device ∗ , /∗ USB d e v i c e managed by USBP ∗/
51 struct usbp interface ∗ , /∗ USB i n t e r f a c e t o add ∗/
52 const s t r u c t u s b p d e v i c e i n f o ∗ , /∗ i n f o r m a t i o n t o b u i l d a d e v i c e d e s c r i p t o r ∗/
53 c o n s t s t r u c t u s b p i n t e r f a c e s p e c ∗ , /∗ i n f o r m a t i o n t o b u i l d an i n t e r f a c e
54 d e s c r i p t o r and e n d p o i n t d e s c r i p t o r s ∗/
55 c o n s t s t r u c t u s b p i n t e r f a c e m e t h o d s ∗ ) ; /∗ c a l l b a c k f u n c t i o n s ∗/