📄 usb.h
字号:
int bandwidth; /* bandwidth for INT/ISO request */ atomic_t use_count; /* concurrent submissions counter */ u8 reject; /* submissions will fail */ /* 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 usb_device *dev; /* (in) pointer to associated device */ unsigned int pipe; /* (in) pipe information */ 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 */ int transfer_buffer_length; /* (in) data buffer length */ int 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 */};/* ----------------------------------------------------------------------- *//** * usb_fill_control_urb - initializes a control urb * @urb: pointer to the urb to initialize. * @dev: pointer to the struct usb_device for this urb. * @pipe: the endpoint pipe * @setup_packet: pointer to the setup_packet buffer * @transfer_buffer: pointer to the transfer buffer * @buffer_length: length of the transfer buffer * @complete_fn: pointer to the usb_complete_t function * @context: what to set the urb context to. * * Initializes a control urb with the proper information needed to submit * it to a device. */static inline void usb_fill_control_urb (struct urb *urb, struct usb_device *dev, unsigned int pipe, unsigned char *setup_packet, void *transfer_buffer, int buffer_length, usb_complete_t complete_fn, void *context){ spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->setup_packet = setup_packet; urb->transfer_buffer = transfer_buffer; urb->transfer_buffer_length = buffer_length; urb->complete = complete_fn; urb->context = context;}/** * usb_fill_bulk_urb - macro to help initialize a bulk urb * @urb: pointer to the urb to initialize. * @dev: pointer to the struct usb_device for this urb. * @pipe: the endpoint pipe * @transfer_buffer: pointer to the transfer buffer * @buffer_length: length of the transfer buffer * @complete_fn: pointer to the usb_complete_t function * @context: what to set the urb context to. * * Initializes a bulk urb with the proper information needed to submit it * to a device. */static inline void usb_fill_bulk_urb (struct urb *urb, struct usb_device *dev, unsigned int pipe, void *transfer_buffer, int buffer_length, usb_complete_t complete_fn, void *context){ spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->transfer_buffer = transfer_buffer; urb->transfer_buffer_length = buffer_length; urb->complete = complete_fn; urb->context = context;}/** * usb_fill_int_urb - macro to help initialize a interrupt urb * @urb: pointer to the urb to initialize. * @dev: pointer to the struct usb_device for this urb. * @pipe: the endpoint pipe * @transfer_buffer: pointer to the transfer buffer * @buffer_length: length of the transfer buffer * @complete_fn: pointer to the usb_complete_t function * @context: what to set the urb context to. * @interval: what to set the urb interval to, encoded like * the endpoint descriptor's bInterval value. * * Initializes a interrupt urb with the proper information needed to submit * it to a device. * Note that high speed interrupt endpoints use a logarithmic encoding of * the endpoint interval, and express polling intervals in microframes * (eight per millisecond) rather than in frames (one per millisecond). */static inline void usb_fill_int_urb (struct urb *urb, struct usb_device *dev, unsigned int pipe, void *transfer_buffer, int buffer_length, usb_complete_t complete_fn, void *context, int interval){ spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->transfer_buffer = transfer_buffer; urb->transfer_buffer_length = buffer_length; urb->complete = complete_fn; urb->context = context; if (dev->speed == USB_SPEED_HIGH) urb->interval = 1 << (interval - 1); else urb->interval = interval; urb->start_frame = -1;}#if 0struct urb *usb_buffer_map (struct urb *urb);void usb_buffer_dmasync (struct urb *urb);void usb_buffer_unmap (struct urb *urb);#endifstruct scatterlist;int usb_buffer_map_sg(const struct usb_device *dev, unsigned pipe, struct scatterlist *sg, int nents);#if 0void usb_buffer_dmasync_sg(const struct usb_device *dev, unsigned pipe, struct scatterlist *sg, int n_hw_ents);#endifvoid usb_buffer_unmap_sg(const struct usb_device *dev, unsigned pipe, struct scatterlist *sg, int n_hw_ents);/*-------------------------------------------------------------------* * SYNCHRONOUS CALL SUPPORT * *-------------------------------------------------------------------*/extern int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, __u16 value, __u16 index, void *data, __u16 size, int timeout);extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout);extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout);/* wrappers around usb_control_msg() for the most common standard requests */extern int usb_get_descriptor(struct usb_device *dev, unsigned char desctype, unsigned char descindex, void *buf, int size);extern int usb_get_status(struct usb_device *dev, int type, int target, void *data);extern int usb_string(struct usb_device *dev, int index, char *buf, int size);/* wrappers that also update important state inside usbcore */extern int usb_clear_halt(struct usb_device *dev, int pipe);extern int usb_reset_configuration(struct usb_device *dev);extern int usb_set_interface(struct usb_device *dev, int ifnum, int alternate);/* this request isn't really synchronous, but it belongs with the others */extern int usb_driver_set_configuration(struct usb_device *udev, int config);/* * timeouts, in milliseconds, used for sending/receiving control messages * they typically complete within a few frames (msec) after they're issued * USB identifies 5 second timeouts, maybe more in a few cases, and a few * slow devices (like some MGE Ellipse UPSes) actually push that limit. */#define USB_CTRL_GET_TIMEOUT 5000#define USB_CTRL_SET_TIMEOUT 5000/** * struct usb_sg_request - support for scatter/gather I/O * @status: zero indicates success, else negative errno * @bytes: counts bytes transferred. * * These requests are initialized using usb_sg_init(), and then are used * as request handles passed to usb_sg_wait() or usb_sg_cancel(). Most * members of the request object aren't for driver access. * * The status and bytecount values are valid only after usb_sg_wait() * returns. If the status is zero, then the bytecount matches the total * from the request. * * After an error completion, drivers may need to clear a halt condition * on the endpoint. */struct usb_sg_request { int status; int bytes; /* * members below are private: to usbcore, * and are not provided for driver access! */ spinlock_t lock; struct usb_device *dev; int pipe; struct scatterlist *sg; int nents; int entries; struct urb **urbs; int count;/// struct completion complete;};void usb_sg_cancel (struct usb_sg_request *io);void usb_sg_wait (struct usb_sg_request *io);/* ----------------------------------------------------------------------- *//* * For various legacy reasons, Linux has a small cookie that's paired with * a struct usb_device to identify an endpoint queue. Queue characteristics * are defined by the endpoint's descriptor. This cookie is called a "pipe", * an unsigned int encoded as: * * - direction: bit 7 (0 = Host-to-Device [Out], * 1 = Device-to-Host [In] ... * like endpoint bEndpointAddress) * - device address: bits 8-14 ... bit positions known to uhci-hcd * - endpoint: bits 15-18 ... bit positions known to uhci-hcd * - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt, * 10 = control, 11 = bulk) * * Given the device address and endpoint descriptor, pipes are redundant. *//* NOTE: these are not the standard USB_ENDPOINT_XFER_* values!! *//* (yet ... they're the values used by usbfs) */#define PIPE_ISOCHRONOUS 0#define PIPE_INTERRUPT 1#define PIPE_CONTROL 2#define PIPE_BULK 3#define usb_pipein(pipe) ((pipe) & USB_DIR_IN)#define usb_pipeout(pipe) (!usb_pipein(pipe))#define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)#define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)#define usb_pipetype(pipe) (((pipe) >> 30) & 3)#define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)#define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)#define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)#define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)/* The D0/D1 toggle bits ... USE WITH CAUTION (they're almost hcd-internal) */#define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> (ep)) & 1)#define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << (ep)))#define usb_settoggle(dev, ep, out, bit) \ ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << (ep))) | \ ((bit) << (ep)))static inline unsigned int __create_pipe(struct usb_device *dev, unsigned int endpoint){ return (dev->devnum << 8) | (endpoint << 15);}/* Create various pipes... */#define usb_sndctrlpipe(dev,endpoint) \ ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))#define usb_rcvctrlpipe(dev,endpoint) \ ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)#define usb_sndisocpipe(dev,endpoint) \ ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))#define usb_rcvisocpipe(dev,endpoint) \ ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)#define usb_sndbulkpipe(dev,endpoint) \ ((PIPE_BULK << 30) | __create_pipe(dev,endpoint))#define usb_rcvbulkpipe(dev,endpoint) \ ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)#define usb_sndintpipe(dev,endpoint) \ ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))#define usb_rcvintpipe(dev,endpoint) \ ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)/*-------------------------------------------------------------------------*/static inline __u16usb_maxpacket(struct usb_device *udev, int pipe, int is_out){ struct usb_host_endpoint *ep; unsigned epnum = usb_pipeendpoint(pipe); if (is_out) { WARN_ON(usb_pipein(pipe)); ep = udev->ep_out[epnum]; } else { WARN_ON(usb_pipeout(pipe)); ep = udev->ep_in[epnum]; } if (!ep) return 0; /* NOTE: only 0x07ff bits are for packet size... */ return le16_to_cpu(ep->desc.wMaxPacketSize);}/* ----------------------------------------------------------------------- *//* Events from the usb core */#define USB_DEVICE_ADD 0x0001#define USB_DEVICE_REMOVE 0x0002#define USB_BUS_ADD 0x0003#define USB_BUS_REMOVE 0x0004extern void usb_register_notify(struct notifier_block *nb);extern void usb_unregister_notify(struct notifier_block *nb);#ifdef DEBUG#define dbg(format, arg...) printk(KERN_DEBUG "%s: " format "\n" , \ __FILE__ , ## arg)#else#define dbg(format, arg...) do {} while (0)#endif#define err(format, arg...) printk(KERN_ERR "%s: " format "\n" , \ __FILE__ , ## arg)#define info(format, arg...) printk(KERN_INFO "%s: " format "\n" , \ __FILE__ , ## arg)#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n" , \ __FILE__ , ## arg)#endif /* __KERNEL__ */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -