patch-2.3.15 linux/drivers/usb/usb.h

Next file: linux/drivers/usb/usb_scsi.c
Previous file: linux/drivers/usb/usb.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.14/linux/drivers/usb/usb.h linux/drivers/usb/usb.h
@@ -12,7 +12,7 @@
 extern int usb_mouse_init(void);
 extern int usb_printer_init(void);
 
-extern void hub_cleanup(void);
+extern void usb_hub_cleanup(void);
 extern void usb_mouse_cleanup(void);
 
 static __inline__ void wait_ms(unsigned int ms)
@@ -21,14 +21,13 @@
         schedule_timeout(1 + ms * HZ / 1000);
 }
 
-
 typedef struct {
-  unsigned char requesttype;
-  unsigned char request;
-  unsigned short value;
-  unsigned short index;
-  unsigned short length;
-} devrequest;
+	__u8 requesttype;
+	__u8 request;
+	__u16 value;
+	__u16 index;
+	__u16 length;
+} devrequest __attribute__ ((packed));
 
 /*
  * Device and/or Interface Class codes
@@ -40,6 +39,7 @@
 #define USB_CLASS_PRINTER		7
 #define USB_CLASS_MASS_STORAGE		8
 #define USB_CLASS_HUB			9
+#define USB_CLASS_DATA			10
 #define USB_CLASS_VENDOR_SPEC		0xff
 
 /*
@@ -53,6 +53,8 @@
 
 #define USB_DT_HUB			0x29
 #define USB_DT_HID			0x21
+#define USB_DT_REPORT			0x22
+#define USB_DT_PHYSICAL			0x23
 
 /*
  * Descriptor sizes per descriptor type
@@ -61,7 +63,7 @@
 #define USB_DT_CONFIG_SIZE		9
 #define USB_DT_INTERFACE_SIZE		9
 #define USB_DT_ENDPOINT_SIZE		7
-#define USB_DT_AUCLSTEP_SIZE		9	/* Audio Classes are special */
+#define USB_DT_ENDPOINT_AUDIO_SIZE	9	/* Audio extension */
 #define USB_DT_HUB_NONVAR_SIZE		7
 
 /*
@@ -114,6 +116,10 @@
 #define USB_RECIP_ENDPOINT		0x02
 #define USB_RECIP_OTHER			0x03
 
+#define USB_HID_RPT_INPUT		0x01
+#define USB_HID_RPT_OUTPUT		0x02
+#define USB_HID_RPT_FEATURE		0x03
+
 /*
  * Request target types.
  */
@@ -127,7 +133,7 @@
 #define USB_RT_HIDD			(USB_TYPE_CLASS | USB_RECIP_INTERFACE)
 
 /* 
- * Status codes (these follow an OHCI controllers condition codes)
+ * Status codes (these follow OHCI controllers condition codes)
  */
 #define USB_ST_NOERROR		0x0
 #define USB_ST_CRC		0x1
@@ -151,6 +157,7 @@
 #define USB_ST_TIMEOUT		0x110
 #define USB_ST_INTERNALERROR	-1
 #define USB_ST_NOTSUPPORTED	-2
+#define USB_ST_BANDWIDTH_ERROR	-3
 
 /*
  * USB device number allocation bitmap. There's one bitmap
@@ -164,14 +171,21 @@
  * This is a USB device descriptor.
  *
  * USB device information
- *
  */
 
+/* Everything but the endpoint maximums are aribtrary */
 #define USB_MAXCONFIG		8
-#define USB_MAXALTSETTING   6   
+#define USB_MAXALTSETTING	16
 #define USB_MAXINTERFACES	32
 #define USB_MAXENDPOINTS	32
 
+/* All standard descriptors have these 2 fields in common */
+struct usb_descriptor_header {
+	__u8  bLength;
+	__u8  bDescriptorType;
+} __attribute__ ((packed));
+
+/* Device descriptor */
 struct usb_device_descriptor {
 	__u8  bLength;
 	__u8  bDescriptorType;
@@ -187,7 +201,7 @@
 	__u8  iProduct;
 	__u8  iSerialNumber;
 	__u8  bNumConfigurations;
-};
+} __attribute__ ((packed));
 
 /* Endpoint descriptor */
 struct usb_endpoint_descriptor {
@@ -199,8 +213,23 @@
 	__u8  bInterval;
 	__u8  bRefresh;
 	__u8  bSynchAddress;
-	void  *audio;
-};
+} __attribute__ ((packed));
+
+/* HID descriptor */
+struct usb_hid_class_descriptor {
+	__u8  bDescriptorType;
+	__u16 wDescriptorLength;
+} __attribute__ ((packed));
+
+struct usb_hid_descriptor {
+	__u8  bLength;
+	__u8  bDescriptorType;
+	__u16 bcdHID;
+	__u8  bCountryCode;
+	__u8  bNumDescriptors;
+
+	struct usb_hid_class_descriptor desc[1];
+} __attribute__ ((packed));
 
 /* Interface descriptor */
 struct usb_interface_descriptor {
@@ -214,14 +243,15 @@
 	__u8  bInterfaceProtocol;
 	__u8  iInterface;
 
+	struct usb_hid_descriptor *hid;
 	struct usb_endpoint_descriptor *endpoint;
-	void  *audio;
-};
+} __attribute__ ((packed));
 
 struct usb_interface {
-        struct usb_interface_descriptor *altsetting;
-        int act_altsetting;                /* active alternate setting */
-        int num_altsetting;                /* number of alternate settings */
+	struct usb_interface_descriptor *altsetting;
+
+	int act_altsetting;		/* active alternate setting */
+	int num_altsetting;		/* number of alternate settings */
 };
 
 /* Configuration descriptor information.. */
@@ -234,35 +264,25 @@
 	__u8  iConfiguration;
 	__u8  bmAttributes;
 	__u8  MaxPower;
+
 	struct usb_interface *interface;
-};
+} __attribute__ ((packed));
 
 /* String descriptor */
 struct usb_string_descriptor {
 	__u8  bLength;
 	__u8  bDescriptorType;
 	__u16 wData[1];
-};
-
-/* Hub descriptor */
-struct usb_hub_descriptor {
-	__u8  bLength;
-	__u8  bDescriptorType;
-	__u8  bNbrPorts;
-	__u8  wHubCharacteristics[2];	/* __u16 but not aligned! */
-	__u8  bPwrOn2PwrGood;
-	__u8  bHubContrCurrent;
-	/* DeviceRemovable and PortPwrCtrlMask want to be variable-length 
-	   bitmaps that hold max 256 entries, but for now they're ignored */
-	__u8  filler;
-};
+} __attribute__ ((packed));
 
 struct usb_device;
 
 struct usb_driver {
-	const char * name;
+	const char *name;
+
 	int (*probe)(struct usb_device *);
 	void (*disconnect)(struct usb_device *);
+
 	struct list_head driver_list;
 };
 
@@ -284,21 +304,97 @@
  */
 typedef int (*usb_device_irq)(int, void *, int, void *);
 
+/*
+ * Isoc. support additions
+ */
+#define START_FRAME_FUDGE      3
+
+/* for start_type: */
+enum {
+	START_ASAP = 0,
+	START_ABSOLUTE,
+	START_RELATIVE
+};
+#define START_TYPE_MAX     START_RELATIVE
+
+/*
+ * Completion/Callback routine returns an enum,
+ * which tells the interrupt handler what to do
+ * with the completed frames (TDs).
+ */
+enum {
+	CB_CONTINUE = 0,        /* OK, remove all TDs;
+				   needs to be 0 to be consistent with
+				   current callback function ret. values */
+	CB_REUSE,               /* leave descriptors as NULL, not active */
+	CB_RESTART,             /* leave descriptors as they are, alive */
+	CB_ABORT                /* kill this USB transfer request */
+};
+
+struct isoc_frame_desc {
+	int             frame_length;   /* may be 0 (i.e., allowed) */
+			/* set by driver for OUTs to devices;
+			 * set by USBD for INs from devices,
+			 * after I/O complete */
+	unsigned int    frame_status;
+			/* set by USBD after I/O complete */
+};
+
+struct usb_isoc_desc {
+	/*
+	 * The following fields are set by the usb_init_isoc() call.
+	 */
+	struct usb_device *usb_dev;
+	unsigned int    pipe;
+	int             frame_count;
+	void            *context;       /* driver context (private) ptr */
+	int             frame_size;
+	/*
+	 * The following fields are set by the driver between the
+	 * usb_init_isoc() and usb_run_isoc() calls
+	 * (along with the "frames" array for OUTput).
+	 */
+	int             start_type;
+	int             start_frame;    /* optional, depending on start_type */
+	int             frame_spacing;  /* not using (yet?) */
+	int             callback_frames; /* every # frames + last one */
+				/* 0 means no callbacks until IOC on last frame */
+	usb_device_irq  callback_fn;
+	void            *data;
+	int             buf_size;
+	/*
+	 * The following fields are set by the usb_run_isoc() call.
+	 */
+	int             end_frame;
+	void            *td;            /* UHCI or OHCI TD ptr */
+	/*
+	 * The following fields are set by the USB HCD interrupt handler
+	 * before calling the driver's callback function.
+	 */
+	int             total_completed_frames;
+	int             prev_completed_frame;   /* from the previous callback */
+	int             cur_completed_frame;    /* from this callback */
+	int             total_length;           /* accumulated */
+	int             error_count;            /* accumulated */
+	struct isoc_frame_desc frames [0];      /* variable size: [frame_count] */
+};
+
 struct usb_operations {
-	struct usb_device *(*allocate)(struct usb_device *);
+	int (*allocate)(struct usb_device *);
 	int (*deallocate)(struct usb_device *);
 	int (*control_msg)(struct usb_device *, unsigned int, devrequest *, void *, int);
 	int (*bulk_msg)(struct usb_device *, unsigned int, void *, int,unsigned long *);
-	void* (*request_irq)(struct usb_device *, unsigned int, usb_device_irq, int, void *);
-	int (*release_irq)(struct usb_device *, void* handle);
+	void *(*request_irq)(struct usb_device *, unsigned int, usb_device_irq, int, void *);
+	int (*release_irq)(struct usb_device *, void *);
 	void *(*request_bulk)(struct usb_device *, unsigned int, usb_device_irq,
  void *, int, void *);
 	int (*terminate_bulk)(struct usb_device *, void *);
-	void *(*alloc_isoc)(struct usb_device *usb_dev, unsigned int pipe, void *data, int len, int maxsze, usb_device_irq completed, void *dev_id);
-	void (*delete_isoc)(struct usb_device *dev, void *_isodesc);
-	int (*sched_isoc)(struct usb_device *usb_dev, void *_isodesc, void *_pisodesc);
-	int (*unsched_isoc)(struct usb_device *usb_dev, void *_isodesc);
-	int (*compress_isoc)(struct usb_device *usb_dev, void *_isodesc);
+	int (*get_frame_number) (struct usb_device *usb_dev);
+	int (*init_isoc) (struct usb_device *usb_dev, unsigned int pipe,
+				int frame_count, void *context, struct usb_isoc_desc **isocdesc);
+	void (*free_isoc) (struct usb_isoc_desc *isocdesc);
+	int (*run_isoc) (struct usb_isoc_desc *isocdesc, struct usb_isoc_desc *pr_isocdesc);
+	int (*kill_isoc) (struct usb_isoc_desc *isocdesc);
 };
 
 /*
@@ -310,14 +406,20 @@
 	struct usb_device *root_hub;    /* Root hub */
 	struct list_head bus_list;
 	void *hcpriv;                   /* Host Controller private data */
-};
 
+	/* procfs entry */
+	int proc_busnum;
+	struct proc_dir_entry *proc_entry;
+};
 
-#define USB_MAXCHILDREN (8)
+#define USB_MAXCHILDREN (8)	/* This is arbitrary */
 
 struct usb_device {
 	int devnum;			/* Device number on USB bus */
 	int slow;			/* Slow device? */
+
+	atomic_t refcnt;		/* Reference count */
+
 	int maxpacketsize;		/* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
 	unsigned int toggle[2];		/* one bit for each endpoint ([0] = IN, [1] = OUT) */
 	unsigned int halted[2];		/* endpoint halts; one bit per endpoint # & direction; */
@@ -326,14 +428,23 @@
 	int epmaxpacketin[16];		/* INput endpoint specific maximums */
 	int epmaxpacketout[16];		/* OUTput endpoint specific maximums */
 	int ifnum;			/* active interface number */
+
+	struct usb_device *parent;
 	struct usb_bus *bus;		/* Bus we're part of */
 	struct usb_driver *driver;	/* Driver */
+
 	struct usb_device_descriptor descriptor;/* Descriptor */
 	struct usb_config_descriptor *config;	/* All of the configs */
-	struct usb_device *parent;
+
 	char *string;			/* pointer to the last string read from the device */
 	int string_langid;		/* language ID for strings */
   
+	void *hcpriv;			/* Host Controller private data */
+	void *private;			/* Upper layer private data */
+
+	/* procfs entry */
+	struct proc_dir_entry *proc_entry;
+
 	/*
 	 * Child devices - these can be either new devices
 	 * (if this is a hub device), or different instances
@@ -344,20 +455,28 @@
 
 	int maxchild;			/* Number of ports if hub */
 	struct usb_device *children[USB_MAXCHILDREN];
-
-	void *hcpriv;			/* Host Controller private data */
-	void *private;			/* Upper layer private data */
 };
 
 extern int usb_register(struct usb_driver *);
 extern void usb_deregister(struct usb_driver *);
 
+int usb_find_driver(struct usb_device *);
+void usb_check_support(struct usb_device *);
+void usb_driver_purge(struct usb_driver *, struct usb_device *);
+
 extern struct usb_bus *usb_alloc_bus(struct usb_operations *);
 extern void usb_free_bus(struct usb_bus *);
 extern void usb_register_bus(struct usb_bus *);
 extern void usb_deregister_bus(struct usb_bus *);
 
-extern void* usb_request_irq(struct usb_device *, unsigned int, usb_device_irq, int, void *);
+extern struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *);
+extern void usb_free_dev(struct usb_device *);
+extern void usb_inc_dev_use(struct usb_device *);
+#define usb_dec_dev_use usb_free_dev
+
+extern int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, __u16 value, __u16 index, void *data, __u16 size);
+
+extern void *usb_request_irq(struct usb_device *, unsigned int, usb_device_irq, int, void *);
 extern int usb_release_irq(struct usb_device *dev, void *handle);
 
 extern void *usb_request_bulk(struct usb_device *, unsigned int, usb_device_irq, void *, int, void *);
@@ -367,10 +486,6 @@
 extern void usb_connect(struct usb_device *dev);
 extern void usb_disconnect(struct usb_device **);
 
-extern int usb_find_driver(struct usb_device *dev);
-void usb_check_support(struct usb_device *);
-void usb_driver_purge(struct usb_driver *,struct usb_device *);
-extern int  usb_parse_configuration(struct usb_device *dev, void *buf, int len);
 extern void usb_destroy_configuration(struct usb_device *dev);
 
 extern void *usb_allocate_isochronous (struct usb_device *usb_dev, unsigned int pipe, void *data, int len,
@@ -380,6 +495,21 @@
 extern int usb_unschedule_isochronous (struct usb_device *usb_dev, void *_isodesc);
 extern int usb_compress_isochronous (struct usb_device *usb_dev, void *_isodesc);
 
+int usb_get_current_frame_number (struct usb_device *usb_dev);
+
+int usb_init_isoc (struct usb_device *usb_dev,
+			unsigned int pipe,
+			int frame_count,
+			void *context,
+			struct usb_isoc_desc **isocdesc);
+
+void usb_free_isoc (struct usb_isoc_desc *isocdesc);
+
+int usb_run_isoc (struct usb_isoc_desc *isocdesc,
+			struct usb_isoc_desc *pr_isocdesc);
+
+int usb_kill_isoc (struct usb_isoc_desc *isocdesc);
+
 /*
  * Calling this entity a "pipe" is glorifying it. A USB pipe
  * is something embarrassingly simple: it basically consists
@@ -479,7 +609,7 @@
 int usb_set_idle(struct usb_device *dev, int duration, int report_id);
 int usb_set_interface(struct usb_device *dev, int interface, int alternate);
 int usb_set_configuration(struct usb_device *dev, int configuration);
-int usb_get_report(struct usb_device *dev);
+int usb_get_report(struct usb_device *dev, unsigned char type, unsigned char id, unsigned char index, void *buf, int size);
 char *usb_string(struct usb_device *dev, int index);
 int usb_clear_halt(struct usb_device *dev, int endp);
 
@@ -489,21 +619,25 @@
 void usb_show_device_descriptor(struct usb_device_descriptor *);
 void usb_show_config_descriptor(struct usb_config_descriptor *);
 void usb_show_interface_descriptor(struct usb_interface_descriptor *);
+void usb_show_hid_descriptor(struct usb_hid_descriptor * desc);
 void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *);
-void usb_show_hub_descriptor(struct usb_hub_descriptor *);
 void usb_show_device(struct usb_device *);
-void usb_show_string(struct usb_device* dev, char *id, int index);
+void usb_show_string(struct usb_device *dev, char *id, int index);
 
 /*
- * Audio parsing helpers
+ * procfs stuff
  */
 
-#ifdef CONFIG_USB_AUDIO
-void usb_audio_interface(struct usb_interface_descriptor *, u8 *);
-void usb_audio_endpoint(struct usb_endpoint_descriptor *, u8 *);
+#ifdef CONFIG_USB_PROC
+void proc_usb_add_bus(struct usb_bus *bus);
+void proc_usb_remove_bus(struct usb_bus *bus);
+void proc_usb_add_device(struct usb_device *dev);
+void proc_usb_remove_device(struct usb_device *dev);
 #else
-extern inline void usb_audio_interface(struct usb_interface_descriptor *interface, u8 *data) {}
-extern inline void usb_audio_endpoint(struct usb_endpoint_descriptor *interface, u8 *data) {}
+extern inline void proc_usb_add_bus(struct usb_bus *bus) {}
+extern inline void proc_usb_remove_bus(struct usb_bus *bus) {}
+extern inline void proc_usb_add_device(struct usb_device *dev) {}
+extern inline void proc_usb_remove_device(struct usb_device *dev) {}
 #endif
 
 #endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)