USB Drivers 相关结构体和宏定义记录 LDD3 学习笔记

2024-06-06 09:58

本文主要是介绍USB Drivers 相关结构体和宏定义记录 LDD3 学习笔记,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

USB Drivers 相关数据结构记录




struct usb_device_id

路径:include/linux/mod_devicetable.h

/*** struct usb_device_id - identifies USB devices for probing and hotplugging* @match_flags: Bit mask controlling of the other fields are used to match*	against new devices.  Any field except for driver_info may be used,*	although some only make sense in conjunction with other fields.*	This is usually set by a USB_DEVICE_*() macro, which sets all*	other fields in this structure except for driver_info.* @idVendor: USB vendor ID for a device; numbers are assigned*	by the USB forum to its members.* @idProduct: Vendor-assigned product ID.* @bcdDevice_lo: Low end of range of vendor-assigned product version numbers.*	This is also used to identify individual product versions, for*	a range consisting of a single device.* @bcdDevice_hi: High end of version number range.  The range of product*	versions is inclusive.* @bDeviceClass: Class of device; numbers are assigned*	by the USB forum.  Products may choose to implement classes,*	or be vendor-specific.  Device classes specify behavior of all*	the interfaces on a devices.* @bDeviceSubClass: Subclass of device; associated with bDeviceClass.* @bDeviceProtocol: Protocol of device; associated with bDeviceClass.* @bInterfaceClass: Class of interface; numbers are assigned*	by the USB forum.  Products may choose to implement classes,*	or be vendor-specific.  Interface classes specify behavior only*	of a given interface; other interfaces may support other classes.* @bInterfaceSubClass: Subclass of interface; associated with bInterfaceClass.* @bInterfaceProtocol: Protocol of interface; associated with bInterfaceClass.* @bInterfaceNumber: Number of interface; composite devices may use*	fixed interface numbers to differentiate between vendor-specific*	interfaces.* @driver_info: Holds information used by the driver.  Usually it holds*	a pointer to a descriptor understood by the driver, or perhaps*	device flags.** In most cases, drivers will create a table of device IDs by using* USB_DEVICE(), or similar macros designed for that purpose.* They will then export it to userspace using MODULE_DEVICE_TABLE(),* and provide it to the USB core through their usb_driver structure.** See the usb_match_id() function for information about how matches are* performed.  Briefly, you will normally use one of several macros to help* construct these entries.  Each entry you provide will either identify* one or more specific products, or will identify a class of products* which have agreed to behave the same.  You should put the more specific* matches towards the beginning of your table, so that driver_info can* record quirks of specific products.*/
struct usb_device_id {/* which fields to match against? */__u16		match_flags;/* Used for product specific matches; range is inclusive */__u16		idVendor;__u16		idProduct;__u16		bcdDevice_lo;__u16		bcdDevice_hi;/* Used for device class matches */__u8		bDeviceClass;__u8		bDeviceSubClass;__u8		bDeviceProtocol;/* Used for interface class matches */__u8		bInterfaceClass;__u8		bInterfaceSubClass;__u8		bInterfaceProtocol;/* Used for vendor-specific interface matches */__u8		bInterfaceNumber;/* not matched against */kernel_ulong_t	driver_info__attribute__((aligned(sizeof(kernel_ulong_t))));
};



Macro:    USB_DEVICE

include/linux/usb.h

/*** USB_DEVICE - macro used to describe a specific usb device* @vend: the 16 bit USB Vendor ID* @prod: the 16 bit USB Product ID** This macro is used to create a struct usb_device_id that matches a* specific device.*/
#define USB_DEVICE(vend, prod) \.match_flags = USB_DEVICE_ID_MATCH_DEVICE, \.idVendor = (vend), \.idProduct = (prod)





Macro:  MODULE_DEVICE_TABLE

路径:include/linux/module.h

#define MODULE_DEVICE_TABLE(type,name)		\MODULE_GENERIC_TABLE(type##_device,name)


#define MODULE_GENERIC_TABLE(gtype,name)			\
extern const struct gtype##_id __mod_##gtype##_table		\__attribute__ ((unused, alias(__stringify(name))))



struct kref

路径: include/linux/kref.h

struct kref {atomic_t refcount;
};

struct urb

path: include/linux/usb.h

/*** struct urb - USB Request Block* @urb_list: For use by current owner of the URB.* @anchor_list: membership in the list of an anchor* @anchor: to anchor URBs to a common mooring* @ep: Points to the endpoint's data structure.  Will eventually*	replace @pipe.* @pipe: Holds endpoint number, direction, type, and more.*	Create these values with the eight macros available;*	usb_{snd,rcv}TYPEpipe(dev,endpoint), where the TYPE is "ctrl"*	(control), "bulk", "int" (interrupt), or "iso" (isochronous).*	For example usb_sndbulkpipe() or usb_rcvintpipe().  Endpoint*	numbers range from zero to fifteen.  Note that "in" endpoint two*	is a different endpoint (and pipe) from "out" endpoint two.*	The current configuration controls the existence, type, and*	maximum packet size of any given endpoint.* @stream_id: the endpoint's stream ID for bulk streams* @dev: Identifies the USB device to perform the request.* @status: This is read in non-iso completion functions to get the*	status of the particular request.  ISO requests only use it*	to tell whether the URB was unlinked; detailed status for*	each frame is in the fields of the iso_frame-desc.* @transfer_flags: A variety of flags may be used to affect how URB*	submission, unlinking, or operation are handled.  Different*	kinds of URB can use different flags.* @transfer_buffer:  This identifies the buffer to (or from) which the I/O*	request will be performed unless URB_NO_TRANSFER_DMA_MAP is set*	(however, do not leave garbage in transfer_buffer even then).*	This buffer must be suitable for DMA; allocate it with*	kmalloc() or equivalent.  For transfers to "in" endpoints, contents*	of this buffer will be modified.  This buffer is used for the data*	stage of control transfers.* @transfer_dma: When transfer_flags includes URB_NO_TRANSFER_DMA_MAP,*	the device driver is saying that it provided this DMA address,*	which the host controller driver should use in preference to the*	transfer_buffer.* @sg: scatter gather buffer list, the buffer size of each element in* 	the list (except the last) must be divisible by the endpoint's* 	max packet size if no_sg_constraint isn't set in 'struct usb_bus'* 	(FIXME: scatter-gather under xHCI is broken for periodic transfers.* 	Do not use urb->sg for interrupt endpoints for now, only bulk.)* @num_mapped_sgs: (internal) number of mapped sg entries* @num_sgs: number of entries in the sg list* @transfer_buffer_length: How big is transfer_buffer.  The transfer may*	be broken up into chunks according to the current maximum packet*	size for the endpoint, which is a function of the configuration*	and is encoded in the pipe.  When the length is zero, neither*	transfer_buffer nor transfer_dma is used.* @actual_length: This is read in non-iso completion functions, and*	it tells how many bytes (out of transfer_buffer_length) were*	transferred.  It will normally be the same as requested, unless*	either an error was reported or a short read was performed.*	The URB_SHORT_NOT_OK transfer flag may be used to make such*	short reads be reported as errors.* @setup_packet: Only used for control transfers, this points to eight bytes*	of setup data.  Control transfers always start by sending this data*	to the device.  Then transfer_buffer is read or written, if needed.* @setup_dma: DMA pointer for the setup packet.  The caller must not use*	this field; setup_packet must point to a valid buffer.* @start_frame: Returns the initial frame for isochronous transfers.* @number_of_packets: Lists the number of ISO transfer buffers.* @interval: Specifies the polling interval for interrupt or isochronous*	transfers.  The units are frames (milliseconds) for full and low*	speed devices, and microframes (1/8 millisecond) for highspeed*	and SuperSpeed devices.* @error_count: Returns the number of ISO transfers that reported errors.* @context: For use in completion functions.  This normally points to*	request-specific driver context.* @complete: Completion handler. This URB is passed as the parameter to the*	completion function.  The completion function may then do what*	it likes with the URB, including resubmitting or freeing it.* @iso_frame_desc: Used to provide arrays of ISO transfer buffers and to*	collect the transfer status for each buffer.** This structure identifies USB transfer requests.  URBs must be allocated by* calling usb_alloc_urb() and freed with a call to usb_free_urb().* Initialization may be done using various usb_fill_*_urb() functions.  URBs* are submitted using usb_submit_urb(), and pending requests may be canceled* using usb_unlink_urb() or usb_kill_urb().** Data Transfer Buffers:** Normally drivers provide I/O buffers allocated with kmalloc() or otherwise* taken from the general page pool.  That is provided by transfer_buffer* (control requests also use setup_packet), and host controller drivers* perform a dma mapping (and unmapping) for each buffer transferred.  Those* mapping operations can be expensive on some platforms (perhaps using a dma* bounce buffer or talking to an IOMMU),* although they're cheap on commodity x86 and ppc hardware.** Alternatively, drivers may pass the URB_NO_TRANSFER_DMA_MAP transfer flag,* which tells the host controller driver that no such mapping is needed for* the transfer_buffer since* the device driver is DMA-aware.  For example, a device driver might* allocate a DMA buffer with usb_alloc_coherent() or call usb_buffer_map().* When this transfer flag is provided, host controller drivers will* attempt to use the dma address found in the transfer_dma* field rather than determining a dma address themselves.** Note that transfer_buffer must still be set if the controller* does not support DMA (as indicated by bus.uses_dma) and when talking* to root hub. If you have to trasfer between highmem zone and the device* on such controller, create a bounce buffer or bail out with an error.* If transfer_buffer cannot be set (is in highmem) and the controller is DMA* capable, assign NULL to it, so that usbmon knows not to use the value.* The setup_packet must always be set, so it cannot be located in highmem.** Initialization:** All URBs submitted must initialize the dev, pipe, transfer_flags (may be* zero), and complete fields.  All URBs must also initialize* transfer_buffer and transfer_buffer_length.  They may provide the* URB_SHORT_NOT_OK transfer flag, indicating that short reads are* to be treated as errors; that flag is invalid for write requests.** Bulk URBs may* use the URB_ZERO_PACKET transfer flag, indicating that bulk OUT transfers* should always terminate with a short packet, even if it means adding an* extra zero length packet.** Control URBs must provide a valid pointer in the setup_packet field.* Unlike the transfer_buffer, the setup_packet may not be mapped for DMA* beforehand.** Interrupt URBs must provide an interval, saying how often (in milliseconds* or, for highspeed devices, 125 microsecond units)* to poll for transfers.  After the URB has been submitted, the interval* field reflects how the transfer was actually scheduled.* The polling interval may be more frequent than requested.* For example, some controllers have a maximum interval of 32 milliseconds,* while others support intervals of up to 1024 milliseconds.* Isochronous URBs also have transfer intervals.  (Note that for isochronous* endpoints, as well as high speed interrupt endpoints, the encoding of* the transfer interval in the endpoint descriptor is logarithmic.* Device drivers must convert that value to linear units themselves.)** If an isochronous endpoint queue isn't already running, the host* controller will schedule a new URB to start as soon as bandwidth* utilization allows.  If the queue is running then a new URB will be* scheduled to start in the first transfer slot following the end of the* preceding URB, if that slot has not already expired.  If the slot has* expired (which can happen when IRQ delivery is delayed for a long time),* the scheduling behavior depends on the URB_ISO_ASAP flag.  If the flag* is clear then the URB will be scheduled to start in the expired slot,* implying that some of its packets will not be transferred; if the flag* is set then the URB will be scheduled in the first unexpired slot,* breaking the queue's synchronization.  Upon URB completion, the* start_frame field will be set to the (micro)frame number in which the* transfer was scheduled.  Ranges for frame counter values are HC-specific* and can go from as low as 256 to as high as 65536 frames.** Isochronous URBs have a different data transfer model, in part because* the quality of service is only "best effort".  Callers provide specially* allocated URBs, with number_of_packets worth of iso_frame_desc structures* at the end.  Each such packet is an individual ISO transfer.  Isochronous* URBs are normally queued, submitted by drivers to arrange that* transfers are at least double buffered, and then explicitly resubmitted* in completion handlers, so* that data (such as audio or video) streams at as constant a rate as the* host controller scheduler can support.** Completion Callbacks:** The completion callback is made in_interrupt(), and one of the first* things that a completion handler should do is check the status field.* The status field is provided for all URBs.  It is used to report* unlinked URBs, and status for all non-ISO transfers.  It should not* be examined before the URB is returned to the completion handler.** The context field is normally used to link URBs back to the relevant* driver or request state.** When the completion callback is invoked for non-isochronous URBs, the* actual_length field tells how many bytes were transferred.  This field* is updated even when the URB terminated with an error or was unlinked.** ISO transfer status is reported in the status and actual_length fields* of the iso_frame_desc array, and the number of errors is reported in* error_count.  Completion callbacks for ISO transfers will normally* (re)submit URBs to ensure a constant transfer rate.** Note that even fields marked "public" should not be touched by the driver* when the urb is owned by the hcd, that is, since the call to* usb_submit_urb() till the entry into the completion routine.*/
struct urb {/* private: usb core and host controller only fields in the urb */struct kref kref;		/* reference count of the URB */void *hcpriv;			/* private data for host controller */atomic_t use_count;		/* concurrent submissions counter */atomic_t reject;		/* submissions will fail */int unlinked;			/* unlink error code *//* public: documented fields in the urb that can be used by drivers */struct list_head urb_list;	/* list head for use by the urb's* current owner */struct list_head anchor_list;	/* the URB may be anchored */struct usb_anchor *anchor;struct usb_device *dev;		/* (in) pointer to associated device */struct usb_host_endpoint *ep;	/* (internal) pointer to endpoint */unsigned int pipe;		/* (in) pipe information */unsigned int stream_id;		/* (in) stream ID */int status;			/* (return) non-ISO status */unsigned int transfer_flags;	/* (in) URB_SHORT_NOT_OK | ...*/void *transfer_buffer;		/* (in) associated data buffer */dma_addr_t transfer_dma;	/* (in) dma addr for transfer_buffer */struct scatterlist *sg;		/* (in) scatter gather buffer list */int num_mapped_sgs;		/* (internal) mapped sg entries */int num_sgs;			/* (in) number of entries in the sg list */u32 transfer_buffer_length;	/* (in) data buffer length */u32 actual_length;		/* (return) actual transfer length */unsigned char *setup_packet;	/* (in) setup packet (control only) */dma_addr_t setup_dma;		/* (in) dma addr for setup_packet */int start_frame;		/* (modify) start frame (ISO) */int number_of_packets;		/* (in) number of ISO packets */int interval;			/* (modify) transfer interval* (INT/ISO) */int error_count;		/* (return) number of ISO errors */void *context;			/* (in) context for completion */usb_complete_t complete;	/* (in) completion routine */struct usb_iso_packet_descriptor iso_frame_desc[0];/* (in) ISO ONLY */
};


struct usb_interface

path: include/linux/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 set of*	endpoint configurations.  They will be in no particular order.* @cur_altsetting: the current altsetting.* @num_altsetting: number of 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 does not use the USB major, this field should*	be unused.  The driver should set this value in the probe()*	function of the driver, after it has been assigned a minor*	number from the USB core by calling usb_register_dev().* @condition: binding state of the 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 to the USB major, this will point*	to the sysfs representation for that device.* @pm_usage_cnt: PM usage counter for this interface* @reset_ws: Used for scheduling resets from atomic context.* @reset_running: set to 1 if the interface is currently running a*      queued reset so that usb_cancel_queued_reset() doesn't try to*      remove from the workqueue when running inside the worker*      thread. See __usb_queue_reset_device().* @resetting_device: USB core reset the device, so use alt setting 0 as*	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,* or by a product's vendor.  The (default) control endpoint is part of* every interface, but is never listed among the interface's descriptors.** The driver that is bound to the interface can use standard driver model* calls such as dev_get_drvdata() on the dev member of this structure.** Each interface may have alternate settings.  The initial configuration* of a device sets altsetting 0, but the device driver can change* that setting using usb_set_interface().  Alternate settings are often* used to control the use of periodic endpoints, such as by 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 run from* 0 to one less than the total number of alternate settings.  But some* devices manage to mess this up, and the structures aren't necessarily* stored in numerical order anyhow.  Use usb_altnum_to_altsetting() to* look up an alternate setting in the altsetting array based on its number.*/
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;	/* number of alternate settings *//* If there is an interface association descriptor then it 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 is in progress */unsigned needs_remote_wakeup:1;	/* driver requires remote wakeup */unsigned needs_altsetting0:1;	/* switch to altsetting 0 is 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 */
};


struct usb_device

path: include/linux/usb.h

/*** struct usb_device - kernel's representation of a USB device* @devnum: device number; address on a USB bus* @devpath: device ID string for use in messages (e.g., /port/...)* @route: tree topology hex string for use with xHCI* @state: device state: configured, not attached, etc.* @speed: device speed: high/full/low (or error)* @tt: Transaction Translator info; used with low/full speed dev, highspeed hub* @ttport: device port on that tt hub* @toggle: one bit for each endpoint, with ([0] = IN, [1] = OUT) endpoints* @parent: our hub, unless we're the root* @bus: bus we're part of* @ep0: endpoint 0 data (default control pipe)* @dev: generic device interface* @descriptor: USB device descriptor* @bos: USB device BOS descriptor set* @config: all of the device's configs* @actconfig: the active configuration* @ep_in: array of IN endpoints* @ep_out: array of OUT endpoints* @rawdescriptors: raw descriptors for each config* @bus_mA: Current available from the bus* @portnum: parent port number (origin 1)* @level: number of USB hub ancestors* @can_submit: URBs may be submitted* @persist_enabled:  USB_PERSIST enabled for this device* @have_langid: whether string_langid is valid* @authorized: policy has said we can use it;*	(user space) policy determines if we authorize this device to be*	used or not. By default, wired USB devices are authorized.*	WUSB devices are not, until we authorize them from user space.*	FIXME -- complete doc* @authenticated: Crypto authentication passed* @wusb: device is Wireless USB* @lpm_capable: device supports LPM* @usb2_hw_lpm_capable: device can perform USB2 hardware LPM* @usb2_hw_lpm_besl_capable: device can perform USB2 hardware BESL LPM* @usb2_hw_lpm_enabled: USB2 hardware LPM is enabled* @usb2_hw_lpm_allowed: Userspace allows USB 2.0 LPM to be enabled* @usb3_lpm_enabled: USB3 hardware LPM enabled* @string_langid: language ID for strings* @product: iProduct string, if present (static)* @manufacturer: iManufacturer string, if present (static)* @serial: iSerialNumber string, if present (static)* @filelist: usbfs files that are open to this device* @maxchild: number of ports if hub* @quirks: quirks of the whole device* @urbnum: number of URBs submitted for the whole device* @active_duration: total time device is not suspended* @connect_time: time device was first connected* @do_remote_wakeup:  remote wakeup should be enabled* @reset_resume: needs reset instead of resume* @port_is_suspended: the upstream port is suspended (L2 or U3)* @wusb_dev: if this is a Wireless USB device, link to the WUSB*	specific data for the device.* @slot_id: Slot ID assigned by xHCI* @removable: Device can be physically removed from this port* @l1_params: best effor service latency for USB2 L1 LPM state, and L1 timeout.* @u1_params: exit latencies for USB3 U1 LPM state, and hub-initiated timeout.* @u2_params: exit latencies for USB3 U2 LPM state, and hub-initiated timeout.* @lpm_disable_count: Ref count used by usb_disable_lpm() and usb_enable_lpm()*	to keep track of the number of functions that require USB 3.0 Link Power*	Management to be disabled for this usb_device.  This count should only*	be manipulated by those functions, with the bandwidth_mutex is held.** Notes:* Usbcore drivers should not set usbdev->state directly.  Instead use* usb_set_device_state().*/
struct usb_device {int		devnum;char		devpath[16];u32		route;enum usb_device_state	state;enum usb_device_speed	speed;struct usb_tt	*tt;int		ttport;unsigned int toggle[2];struct usb_device *parent;struct usb_bus *bus;struct usb_host_endpoint ep0;struct device dev;struct usb_device_descriptor descriptor;struct usb_host_bos *bos;struct usb_host_config *config;struct usb_host_config *actconfig;struct usb_host_endpoint *ep_in[16];struct usb_host_endpoint *ep_out[16];char **rawdescriptors;unsigned short bus_mA;u8 portnum;u8 level;unsigned can_submit:1;unsigned persist_enabled:1;unsigned have_langid:1;unsigned authorized:1;unsigned authenticated:1;unsigned wusb:1;unsigned lpm_capable:1;unsigned usb2_hw_lpm_capable:1;unsigned usb2_hw_lpm_besl_capable:1;unsigned usb2_hw_lpm_enabled:1;unsigned usb2_hw_lpm_allowed:1;unsigned usb3_lpm_enabled:1;int string_langid;/* static strings from the device */char *product;char *manufacturer;char *serial;struct list_head filelist;int maxchild;u32 quirks;atomic_t urbnum;unsigned long active_duration;#ifdef CONFIG_PMunsigned long connect_time;unsigned do_remote_wakeup:1;unsigned reset_resume:1;unsigned port_is_suspended:1;
#endifstruct wusb_dev *wusb_dev;int slot_id;enum usb_device_removable removable;struct usb2_lpm_parameters l1_params;struct usb3_lpm_parameters u1_params;struct usb3_lpm_parameters u2_params;unsigned lpm_disable_count;
};






struct usb_host_config

path: include/linux/usb.h

/*** struct usb_host_config - representation of a device's configuration* @desc: the device's configuration descriptor.* @string: pointer to the cached version of the iConfiguration string, if*	present for this configuration.* @intf_assoc: list of any interface association descriptors in this config* @interface: array of pointers to usb_interface structures, one for each*	interface in the configuration.  The number of interfaces is stored*	in desc.bNumInterfaces.  These pointers are valid only while the*	the configuration is active.* @intf_cache: array of pointers to usb_interface_cache structures, one*	for each interface in the configuration.  These structures exist*	for the entire life of the device.* @extra: pointer to buffer containing all extra descriptors associated*	with this configuration (those preceding the first interface*	descriptor).* @extralen: length of the 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 number of configurations* available is stored in the device descriptor as bNumConfigurations.** A configuration can contain multiple interfaces.  Each corresponds to* a different function of the USB device, and all are available whenever* the configuration is active.  The USB standard says that interfaces* are supposed to be numbered from 0 to desc.bNumInterfaces-1, but a lot* of devices get this wrong.  In addition, the interface array is not* guaranteed to be sorted in numerical order.  Use usb_ifnum_to_if() to* look up an interface entry based on its number.** Device drivers should not attempt to activate configurations.  The choice* of which configuration to install is a policy decision based on such* considerations as available power, functionality provided, and the 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 is not the* active configuration */struct usb_interface_cache *intf_cache[USB_MAXINTERFACES];unsigned char *extra;   /* Extra descriptors */int extralen;
};


函数iminor imajor

path :include/linux/fs.h

static inline unsigned iminor(const struct inode *inode)
{return MINOR(inode->i_rdev);
}static inline unsigned imajor(const struct inode *inode)
{return MAJOR(inode->i_rdev);
}



struct usb_class_driver

usb.h

/*** struct usb_class_driver - identifies a USB driver that wants to use the USB major number* @name: the usb class device name for this driver.  Will show up in sysfs.* @devnode: Callback to provide a naming hint for a possible*	device node to create.* @fops: pointer to the struct file_operations of this driver.* @minor_base: the start of the minor range for this driver.** This structure is used for the usb_register_dev() and* usb_unregister_dev() functions, to consolidate a number of the* parameters used for them.*/
struct usb_class_driver {char *name;char *(*devnode)(struct device *dev, umode_t *mode);const struct file_operations *fops;int minor_base;
};



struct usb_host_endpoint

/*** struct usb_host_endpoint - host-side endpoint descriptor and queue* @desc: descriptor for this endpoint, wMaxPacketSize in native byteorder* @ss_ep_comp: SuperSpeed companion descriptor for this 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;
};




struct usb_host_interface

/* host-side wrapper for one interface setting's parsed descriptors */
struct usb_host_interface {struct usb_interface_descriptor	desc;int extralen;unsigned char *extra;   /* Extra descriptors *//* array of desc.bNumEndpoint endpoints associated with this* interface setting.  these will be in no particular order.*/struct usb_host_endpoint *endpoint;char *string;		/* iInterface string, if present */
};


struct usb_device_descriptor

/* USB_DT_DEVICE: Device descriptor */
struct usb_device_descriptor {__u8  bLength;__u8  bDescriptorType;__le16 bcdUSB;__u8  bDeviceClass;__u8  bDeviceSubClass;__u8  bDeviceProtocol;__u8  bMaxPacketSize0;__le16 idVendor;__le16 idProduct;__le16 bcdDevice;__u8  iManufacturer;__u8  iProduct;__u8  iSerialNumber;__u8  bNumConfigurations;
} __attribute__ ((packed));



USB设备类型宏定义

/** Device and/or Interface Class codes* as found in bDeviceClass or bInterfaceClass* and defined by www.usb.org documents*/
#define USB_CLASS_PER_INTERFACE		0	/* for DeviceClass */
#define USB_CLASS_AUDIO			1
#define USB_CLASS_COMM			2
#define USB_CLASS_HID			        3
#define USB_CLASS_PHYSICAL		5
#define USB_CLASS_STILL_IMAGE	6
#define USB_CLASS_PRINTER		7
#define USB_CLASS_MASS_STORAGE	8
#define USB_CLASS_HUB			9
#define USB_CLASS_CDC_DATA		0x0a
#define USB_CLASS_CSCID			0x0b	/* chip+ smart card */
#define USB_CLASS_CONTENT_SEC	0x0d	/* content security */
#define USB_CLASS_VIDEO			0x0e
#define USB_CLASS_WIRELESS_CONTROLLER	0xe0
#define USB_CLASS_MISC			0xef
#define USB_CLASS_APP_SPEC		0xfe
#define USB_CLASS_VENDOR_SPEC	0xff#define USB_SUBCLASS_VENDOR_SPEC	0xff


 


struct usb_config_descriptor


/* USB_DT_CONFIG: Configuration descriptor information.** USB_DT_OTHER_SPEED_CONFIG is the same descriptor, except that the* descriptor type is different.  Highspeed-capable devices can look* different depending on what speed they're currently running.  Only* devices with a USB_DT_DEVICE_QUALIFIER have any OTHER_SPEED_CONFIG* descriptors.*/
struct usb_config_descriptor {__u8  bLength;__u8  bDescriptorType;__le16 wTotalLength;__u8  bNumInterfaces;__u8  bConfigurationValue;__u8  iConfiguration;__u8  bmAttributes;__u8  bMaxPower;
} __attribute__ ((packed));



struct usb_interface_descriptor

/* USB_DT_INTERFACE: Interface descriptor */
struct usb_interface_descriptor {__u8  bLength;__u8  bDescriptorType;__u8  bInterfaceNumber;__u8  bAlternateSetting;__u8  bNumEndpoints;__u8  bInterfaceClass;__u8  bInterfaceSubClass;__u8  bInterfaceProtocol;__u8  iInterface;
} __attribute__ ((packed));


struct usb_ss_ep_comp_descriptor

/* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */
struct usb_ss_ep_comp_descriptor {__u8  bLength;__u8  bDescriptorType;__u8  bMaxBurst;__u8  bmAttributes;__le16 wBytesPerInterval;
} __attribute__ ((packed));






函数: usb_get_dev

path : drivers/usb/core/usb.c

/*** usb_get_dev - increments the reference count of the usb device structure* @dev: the device being referenced** Each live reference to a device should be refcounted.** Drivers for USB interfaces should normally record such references in* their probe() methods, when they bind to an interface, and release* them by calling usb_put_dev(), in their disconnect() methods.** Return: A pointer to the device with the incremented reference counter.*/
struct usb_device *usb_get_dev(struct usb_device *dev)
{if (dev)get_device(&dev->dev);return dev;
}
EXPORT_SYMBOL_GPL(usb_get_dev);

函数: usb_put_dev

path : drivers/usb/core/usb.c


/*** usb_put_dev - release a use of the usb device structure* @dev: device that's been disconnected** Must be called when a user of a device is finished with it.  When the last* user of the device calls this function, the memory of the device is freed.*/
void usb_put_dev(struct usb_device *dev)
{if (dev)put_device(&dev->dev);
}
EXPORT_SYMBOL_GPL(usb_put_dev);


dev_get_drvdata

path :drivers/base/dd.c

/** These exports can't be _GPL due to .h files using this within them, and it* might break something that was previously working...*/
void *dev_get_drvdata(const struct device *dev)
{if (dev && dev->p)return dev->p->driver_data;return NULL;
}
EXPORT_SYMBOL(dev_get_drvdata);





dev_set_drvdata

path :drivers/base/dd.c



int dev_set_drvdata(struct device *dev, void *data)
{int error;if (!dev->p) {error = device_private_init(dev);if (error)return error;}dev->p->driver_data = data;return 0;
}
EXPORT_SYMBOL(dev_set_drvdata);






这篇关于USB Drivers 相关结构体和宏定义记录 LDD3 学习笔记的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1035789

相关文章

关于rpc长连接与短连接的思考记录

《关于rpc长连接与短连接的思考记录》文章总结了RPC项目中长连接和短连接的处理方式,包括RPC和HTTP的长连接与短连接的区别、TCP的保活机制、客户端与服务器的连接模式及其利弊分析,文章强调了在实... 目录rpc项目中的长连接与短连接的思考什么是rpc项目中的长连接和短连接与tcp和http的长连接短

Oracle查询优化之高效实现仅查询前10条记录的方法与实践

《Oracle查询优化之高效实现仅查询前10条记录的方法与实践》:本文主要介绍Oracle查询优化之高效实现仅查询前10条记录的相关资料,包括使用ROWNUM、ROW_NUMBER()函数、FET... 目录1. 使用 ROWNUM 查询2. 使用 ROW_NUMBER() 函数3. 使用 FETCH FI

Linux使用fdisk进行磁盘的相关操作

《Linux使用fdisk进行磁盘的相关操作》fdisk命令是Linux中用于管理磁盘分区的强大文本实用程序,这篇文章主要为大家详细介绍了如何使用fdisk进行磁盘的相关操作,需要的可以了解下... 目录简介基本语法示例用法列出所有分区查看指定磁盘的区分管理指定的磁盘进入交互式模式创建一个新的分区删除一个存

Python MySQL如何通过Binlog获取变更记录恢复数据

《PythonMySQL如何通过Binlog获取变更记录恢复数据》本文介绍了如何使用Python和pymysqlreplication库通过MySQL的二进制日志(Binlog)获取数据库的变更记录... 目录python mysql通过Binlog获取变更记录恢复数据1.安装pymysqlreplicat

关于Maven生命周期相关命令演示

《关于Maven生命周期相关命令演示》Maven的生命周期分为Clean、Default和Site三个主要阶段,每个阶段包含多个关键步骤,如清理、编译、测试、打包等,通过执行相应的Maven命令,可以... 目录1. Maven 生命周期概述1.1 Clean Lifecycle1.2 Default Li

numpy求解线性代数相关问题

《numpy求解线性代数相关问题》本文主要介绍了numpy求解线性代数相关问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 在numpy中有numpy.array类型和numpy.mat类型,前者是数组类型,后者是矩阵类型。数组

Java中switch-case结构的使用方法举例详解

《Java中switch-case结构的使用方法举例详解》:本文主要介绍Java中switch-case结构使用的相关资料,switch-case结构是Java中处理多个分支条件的一种有效方式,它... 目录前言一、switch-case结构的基本语法二、使用示例三、注意事项四、总结前言对于Java初学者

Redis的Hash类型及相关命令小结

《Redis的Hash类型及相关命令小结》edisHash是一种数据结构,用于存储字段和值的映射关系,本文就来介绍一下Redis的Hash类型及相关命令小结,具有一定的参考价值,感兴趣的可以了解一下... 目录HSETHGETHEXISTSHDELHKEYSHVALSHGETALLHMGETHLENHSET

结构体和联合体的区别及说明

《结构体和联合体的区别及说明》文章主要介绍了C语言中的结构体和联合体,结构体是一种自定义的复合数据类型,可以包含多个成员,每个成员可以是不同的数据类型,联合体是一种特殊的数据结构,可以在内存中共享同一... 目录结构体和联合体的区别1. 结构体(Struct)2. 联合体(Union)3. 联合体与结构体的

Servlet中配置和使用过滤器的步骤记录

《Servlet中配置和使用过滤器的步骤记录》:本文主要介绍在Servlet中配置和使用过滤器的方法,包括创建过滤器类、配置过滤器以及在Web应用中使用过滤器等步骤,文中通过代码介绍的非常详细,需... 目录创建过滤器类配置过滤器使用过滤器总结在Servlet中配置和使用过滤器主要包括创建过滤器类、配置过滤