/*** struct usb_host_endpoint - host-side endpoint descriptor and queue* @desc: descriptor forthis endpoint, wMaxPacketSize innative byteorder* @ss_ep_comp: SuperSpeed companion descriptor forthis endpoint* @urb_list: urbs queued to this endpoint; maintained by usbcore* @hcpriv: for use by HCD; typically holds hardware dma queue head (QH)* with one or more transfer descriptors (TDs) per urb* @ep_dev: ep_device for sysfs info* @extra: descriptors following this endpoint in the configuration* @extralen: how many bytes of"extra" are valid* @enabled: URBs may be submitted to this endpoint** USB requests are always queued to a given endpoint, identified by a* descriptor within an active interface in a given USB configuration.*/
struct usb_host_endpoint {struct usb_endpoint_descriptor desc;struct usb_ss_ep_comp_descriptor ss_ep_comp;struct list_head urb_list;void *hcpriv;struct ep_device *ep_dev; /* For sysfs info */unsigned char *extra; /* Extra descriptors */int extralen;int enabled;
};
usb接口
USB 端點被綁在接口中. USB 接口只處理一類 USB 邏輯連接, 例如一個鼠標, 一個鍵盤,或者一個音頻流. 一些 USB 設備有多個接口, 例如一個 USB 揚聲器可能有 2 個接口:一個 USB 鍵盤給按鈕和一個 USB 音頻流. 因為一個 USB 接口表示基本的功能, 每個USB 驅動控制一個接口; 因此, 對揚聲器的例子, Linux 需要 2 個不同的驅動給一個硬件設備。 還是在usb.h文件里面
/*** struct usb_interface - what usb device drivers talk to* @altsetting: array of interface structures, one for each alternate* setting that may be selected. Each one includes a setof* endpoint configurations. They will be in no particular order.* @cur_altsetting: the current altsetting.* @num_altsetting: numberof altsettings defined.* @intf_assoc: interface association descriptor* @minor: the minor number assigned to this interface, if this* interface is bound to a driver that uses the USB major number.* If this interface doesnot use the USB major, this field should* be unused. The driver should set this value inthe probe()* function ofthe driver, afterit has been assigned a minor* numberfromthe USB core by calling usb_register_dev().* @condition: binding state ofthe interface: not bound, binding* (in probe()), bound to a driver, or unbinding (in disconnect())* @sysfs_files_created: sysfs attributes exist* @ep_devs_created: endpoint child pseudo-devices exist* @unregistering: flag set when the interface is being unregistered* @needs_remote_wakeup: flag set when the driver requires remote-wakeup* capability during autosuspend.* @needs_altsetting0: flag set when a set-interface request for altsetting 0* has been deferred.* @needs_binding: flag set when the driver should be re-probed or unbound* following a reset or suspend operation it doesn't support.* @dev: driver model's view of this device* @usb_dev: if an interface is bound tothe USB major, this will point* tothe sysfs representation forthat device.* @pm_usage_cnt: PM usage counter for this interface* @reset_ws: Used for scheduling resets from atomic context.* @reset_running: setto1ifthe interface is currently running a* queued reset so that usb_cancel_queued_reset() doesn't tryto* remove fromthe workqueue when running inside the worker* thread. See __usb_queue_reset_device().* @resetting_device: USB core reset the device, so use alt setting 0as* current; needs bandwidth alloc after reset.** USB device drivers attach to interfaces on a physical device. Each* interface encapsulates a single high level function, such as feeding* an audio stream to a speaker or reporting a change in a volume control.* Many USB devices only have one interface. The protocol used to talk to* an interface's endpoints can be defined in a usb "class" specification,* orby a product's vendor. The (default) control endpoint is part of* every interface, butis never listed among the interface's descriptors.** The driver thatis bound tothe interface can use standard driver model* calls such as dev_get_drvdata() onthe dev member of this structure.** Each interface may have alternate settings. The initial configuration* of a device sets altsetting 0, butthe device driver can change* that setting using usb_set_interface(). Alternate settings are often* used to control the use of periodic endpoints, such asby having* different endpoints use different amounts of reserved USB bandwidth.* All standards-conformant USB devices that use isochronous endpoints* will use them in non-default settings.** The USB specification says that alternate setting numbers must runfrom* 0to one less thanthe total numberof alternate settings. But some* devices manage to mess this up, andthe structures aren't necessarily* stored in numerical order anyhow. Use usb_altnum_to_altsetting() to* look up an alternate setting inthe altsetting array based onitsnumber.*/
struct usb_interface {/* array of alternate settings for this interface,* stored in no particular order */struct usb_host_interface *altsetting;struct usb_host_interface *cur_altsetting; /* the currently* active alternate setting */unsigned num_altsetting; /* numberof alternate settings *//* If there is an interface association descriptor thenit will list* the associated interfaces */struct usb_interface_assoc_descriptor *intf_assoc;int minor; /* minor number this interface is* bound to */enum usb_interface_condition condition; /* state of binding */unsigned sysfs_files_created:1; /* the sysfs attributes exist */unsigned ep_devs_created:1; /* endpoint "devices" exist */unsigned unregistering:1; /* unregistration isin progress */unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */unsigned needs_altsetting0:1; /* switch to altsetting 0is pending */unsigned needs_binding:1; /* needs delayed unbind/rebind */unsigned reset_running:1;unsigned resetting_device:1; /* true: bandwidth alloc after reset */struct device dev; /* interface specific device info */struct device *usb_dev;atomic_t pm_usage_cnt; /* usage counter for autosuspend */struct work_struct reset_ws; /* for resets in atomic context */
};
usb配置
linux 描述 USB 配置使用結構 struct usb_host_config 和整個 USB 設備使用結構struct usb_device. USB 設備驅動通常不會需要讀寫這些結構的任何值, 因此它們在這里沒有詳細定義. 好奇的讀者可在內核源碼樹的文件 include/linux/usb.h 中找到對它們的描述
/*** struct usb_host_config - representation of a device's configuration* @desc: the device's configuration descriptor.* @string: pointer tothe cached versionofthe iConfiguration string, if* present for this configuration.* @intf_assoc: listof any interface association descriptors in this config* @interface: array of pointers to usb_interface structures, one for each* interface inthe configuration. The numberof interfaces is stored* in desc.bNumInterfaces. These pointers are valid only whilethe* the configuration is active.* @intf_cache: array of pointers to usb_interface_cache structures, one* for each interface inthe configuration. These structures exist* forthe entire life ofthe device.* @extra: pointer to buffer containing all extra descriptors associated* with this configuration (those preceding thefirst interface* descriptor).* @extralen: lengthofthe extra descriptors buffer.** USB devices may have multiple configurations, but only one can be active* at any time. Each encapsulates a different operational environment;* for example, a dual-speed device would have separate configurations for* full-speed and high-speed operation. The numberof configurations* available is stored inthe device descriptor as bNumConfigurations.** A configuration can contain multiple interfaces. Each corresponds to* a different function ofthe USB device, and all are available whenever* the configuration is active. The USB standard says that interfaces* are supposed to be numbered from0to desc.bNumInterfaces-1, but a lot* of devices get this wrong. In addition, the interface array isnot* guaranteed to be sorted in numerical order. Use usb_ifnum_to_if() to* look up an interface entry based onitsnumber.** Device drivers should not attempt toactivate configurations. The choice* of which configuration to install is a policy decision based on such* considerations as available power, functionality provided, andthe user's* desires (expressed through userspace tools). However, drivers can call* usb_reset_configuration() to reinitialize the current configuration and* all its interfaces.*/
struct usb_host_config {struct usb_config_descriptor desc;char *string; /* iConfiguration string, if present *//* List of any Interface Association Descriptors in this* configuration. */struct usb_interface_assoc_descriptor *intf_assoc[USB_MAXIADS];/* the interfaces associated with this configuration,* stored in no particular order */struct usb_interface *interface[USB_MAXINTERFACES];/* Interface information available even when this isnotthe* active configuration */struct usb_interface_cache *intf_cache[USB_MAXINTERFACES];unsigned char *extra; /* Extra descriptors */int extralen;
};