Linux Audio

Check our new training course

Embedded Linux training

Mar 31-Apr 8, 2025
Register
Loading...
v6.9.4
  1/* SPDX-License-Identifier: GPL-2.0+ */
  2/*
  3 * Driver for USB Mass Storage compliant devices
  4 * Main Header File
  5 *
  6 * Current development and maintenance by:
  7 *   (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
  8 *
  9 * Initial work by:
 10 *   (c) 1999 Michael Gee (michael@linuxspecific.com)
 11 *
 12 * This driver is based on the 'USB Mass Storage Class' document. This
 13 * describes in detail the protocol used to communicate with such
 14 * devices.  Clearly, the designers had SCSI and ATAPI commands in
 15 * mind when they created this document.  The commands are all very
 16 * similar to commands in the SCSI-II and ATAPI specifications.
 17 *
 18 * It is important to note that in a number of cases this class
 19 * exhibits class-specific exemptions from the USB specification.
 20 * Notably the usage of NAK, STALL and ACK differs from the norm, in
 21 * that they are used to communicate wait, failed and OK on commands.
 22 *
 23 * Also, for certain devices, the interrupt endpoint is used to convey
 24 * status of a command.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 25 */
 26
 27#ifndef _USB_H_
 28#define _USB_H_
 29
 30#include <linux/usb.h>
 31#include <linux/usb_usual.h>
 32#include <linux/blkdev.h>
 33#include <linux/completion.h>
 34#include <linux/mutex.h>
 35#include <linux/workqueue.h>
 36#include <scsi/scsi_host.h>
 37
 38struct us_data;
 39struct scsi_cmnd;
 40
 41/*
 42 * Unusual device list definitions 
 43 */
 44
 45struct us_unusual_dev {
 46	const char* vendorName;
 47	const char* productName;
 48	__u8  useProtocol;
 49	__u8  useTransport;
 50	int (*initFunction)(struct us_data *);
 51};
 52
 53
 54/* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
 55#define US_FLIDX_URB_ACTIVE	0	/* current_urb is in use    */
 56#define US_FLIDX_SG_ACTIVE	1	/* current_sg is in use     */
 57#define US_FLIDX_ABORTING	2	/* abort is in progress     */
 58#define US_FLIDX_DISCONNECTING	3	/* disconnect in progress   */
 59#define US_FLIDX_RESETTING	4	/* device reset in progress */
 60#define US_FLIDX_TIMED_OUT	5	/* SCSI midlayer timed out  */
 61#define US_FLIDX_SCAN_PENDING	6	/* scanning not yet done    */
 62#define US_FLIDX_REDO_READ10	7	/* redo READ(10) command    */
 63#define US_FLIDX_READ10_WORKED	8	/* previous READ(10) succeeded */
 64
 65#define USB_STOR_STRING_LEN 32
 66
 67/*
 68 * We provide a DMA-mapped I/O buffer for use with small USB transfers.
 69 * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
 70 * 31-byte buffer.  But Freecom needs a 64-byte buffer, so that's the
 71 * size we'll allocate.
 72 */
 73
 74#define US_IOBUF_SIZE		64	/* Size of the DMA-mapped I/O buffer */
 75#define US_SENSE_SIZE		18	/* Size of the autosense data buffer */
 76
 77typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
 78typedef int (*trans_reset)(struct us_data*);
 79typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
 80typedef void (*extra_data_destructor)(void *);	/* extra data destructor */
 81typedef void (*pm_hook)(struct us_data *, int);	/* power management hook */
 82
 83#define US_SUSPEND	0
 84#define US_RESUME	1
 85
 86/* we allocate one of these for every device that we remember */
 87struct us_data {
 88	/*
 89	 * The device we're working with
 90	 * It's important to note:
 91	 *    (o) you must hold dev_mutex to change pusb_dev
 92	 */
 93	struct mutex		dev_mutex;	 /* protect pusb_dev */
 94	struct usb_device	*pusb_dev;	 /* this usb_device */
 95	struct usb_interface	*pusb_intf;	 /* this interface */
 96	const struct us_unusual_dev   *unusual_dev;
 97						/* device-filter entry     */
 98	u64			fflags;		 /* fixed flags from filter */
 99	unsigned long		dflags;		 /* dynamic atomic bitflags */
100	unsigned int		send_bulk_pipe;	 /* cached pipe values */
101	unsigned int		recv_bulk_pipe;
102	unsigned int		send_ctrl_pipe;
103	unsigned int		recv_ctrl_pipe;
104	unsigned int		recv_intr_pipe;
105
106	/* information about the device */
107	char			*transport_name;
108	char			*protocol_name;
109	__le32			bcs_signature;
110	u8			subclass;
111	u8			protocol;
112	u8			max_lun;
113
114	u8			ifnum;		 /* interface number   */
115	u8			ep_bInterval;	 /* interrupt interval */
116
117	/* function pointers for this device */
118	trans_cmnd		transport;	 /* transport function	   */
119	trans_reset		transport_reset; /* transport device reset */
120	proto_cmnd		proto_handler;	 /* protocol handler	   */
121
122	/* SCSI interfaces */
123	struct scsi_cmnd	*srb;		 /* current srb		*/
124	unsigned int		tag;		 /* current dCBWTag	*/
125	char			scsi_name[32];	 /* scsi_host name	*/
126
127	/* control and bulk communications data */
128	struct urb		*current_urb;	 /* USB requests	 */
129	struct usb_ctrlrequest	*cr;		 /* control requests	 */
130	struct usb_sg_request	current_sg;	 /* scatter-gather req.  */
131	unsigned char		*iobuf;		 /* I/O buffer		 */
132	dma_addr_t		iobuf_dma;	 /* buffer DMA addresses */
133	struct task_struct	*ctl_thread;	 /* the control thread   */
134
135	/* mutual exclusion and synchronization structures */
136	struct completion	cmnd_ready;	 /* to sleep thread on	    */
137	struct completion	notify;		 /* thread begin/end	    */
138	wait_queue_head_t	delay_wait;	 /* wait during reset	    */
139	struct delayed_work	scan_dwork;	 /* for async scanning      */
140
141	/* subdriver information */
142	void			*extra;		 /* Any extra data          */
143	extra_data_destructor	extra_destructor;/* extra data destructor   */
144#ifdef CONFIG_PM
145	pm_hook			suspend_resume_hook;
146#endif
147
148	/* hacks for READ CAPACITY bug handling */
149	int			use_last_sector_hacks;
150	int			last_sector_retries;
151};
152
153/* Convert between us_data and the corresponding Scsi_Host */
154static inline struct Scsi_Host *us_to_host(struct us_data *us) {
155	return container_of((void *) us, struct Scsi_Host, hostdata);
156}
157static inline struct us_data *host_to_us(struct Scsi_Host *host) {
158	return (struct us_data *) host->hostdata;
159}
160
161/* Function to fill an inquiry response. See usb.c for details */
162extern void fill_inquiry_response(struct us_data *us,
163	unsigned char *data, unsigned int data_len);
164
165/*
166 * The scsi_lock() and scsi_unlock() macros protect the sm_state and the
167 * single queue element srb for write access
168 */
169#define scsi_unlock(host)	spin_unlock_irq(host->host_lock)
170#define scsi_lock(host)		spin_lock_irq(host->host_lock)
171
172/* General routines provided by the usb-storage standard core */
173#ifdef CONFIG_PM
174extern int usb_stor_suspend(struct usb_interface *iface, pm_message_t message);
175extern int usb_stor_resume(struct usb_interface *iface);
176extern int usb_stor_reset_resume(struct usb_interface *iface);
177#else
178#define usb_stor_suspend	NULL
179#define usb_stor_resume		NULL
180#define usb_stor_reset_resume	NULL
181#endif
182
183extern int usb_stor_pre_reset(struct usb_interface *iface);
184extern int usb_stor_post_reset(struct usb_interface *iface);
185
186extern int usb_stor_probe1(struct us_data **pus,
187		struct usb_interface *intf,
188		const struct usb_device_id *id,
189		const struct us_unusual_dev *unusual_dev,
190		const struct scsi_host_template *sht);
191extern int usb_stor_probe2(struct us_data *us);
192extern void usb_stor_disconnect(struct usb_interface *intf);
193
194extern void usb_stor_adjust_quirks(struct usb_device *dev,
195		u64 *fflags);
196
197#define module_usb_stor_driver(__driver, __sht, __name) \
198static int __init __driver##_init(void) \
199{ \
200	usb_stor_host_template_init(&(__sht), __name, THIS_MODULE); \
201	return usb_register(&(__driver)); \
202} \
203module_init(__driver##_init); \
204static void __exit __driver##_exit(void) \
205{ \
206	usb_deregister(&(__driver)); \
207} \
208module_exit(__driver##_exit)
209
210#endif
v3.1
  1/* Driver for USB Mass Storage compliant devices
 
 
  2 * Main Header File
  3 *
  4 * Current development and maintenance by:
  5 *   (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
  6 *
  7 * Initial work by:
  8 *   (c) 1999 Michael Gee (michael@linuxspecific.com)
  9 *
 10 * This driver is based on the 'USB Mass Storage Class' document. This
 11 * describes in detail the protocol used to communicate with such
 12 * devices.  Clearly, the designers had SCSI and ATAPI commands in
 13 * mind when they created this document.  The commands are all very
 14 * similar to commands in the SCSI-II and ATAPI specifications.
 15 *
 16 * It is important to note that in a number of cases this class
 17 * exhibits class-specific exemptions from the USB specification.
 18 * Notably the usage of NAK, STALL and ACK differs from the norm, in
 19 * that they are used to communicate wait, failed and OK on commands.
 20 *
 21 * Also, for certain devices, the interrupt endpoint is used to convey
 22 * status of a command.
 23 *
 24 * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
 25 * information about this driver.
 26 *
 27 * This program is free software; you can redistribute it and/or modify it
 28 * under the terms of the GNU General Public License as published by the
 29 * Free Software Foundation; either version 2, or (at your option) any
 30 * later version.
 31 *
 32 * This program is distributed in the hope that it will be useful, but
 33 * WITHOUT ANY WARRANTY; without even the implied warranty of
 34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 35 * General Public License for more details.
 36 *
 37 * You should have received a copy of the GNU General Public License along
 38 * with this program; if not, write to the Free Software Foundation, Inc.,
 39 * 675 Mass Ave, Cambridge, MA 02139, USA.
 40 */
 41
 42#ifndef _USB_H_
 43#define _USB_H_
 44
 45#include <linux/usb.h>
 46#include <linux/usb_usual.h>
 47#include <linux/blkdev.h>
 48#include <linux/completion.h>
 49#include <linux/mutex.h>
 
 50#include <scsi/scsi_host.h>
 51
 52struct us_data;
 53struct scsi_cmnd;
 54
 55/*
 56 * Unusual device list definitions 
 57 */
 58
 59struct us_unusual_dev {
 60	const char* vendorName;
 61	const char* productName;
 62	__u8  useProtocol;
 63	__u8  useTransport;
 64	int (*initFunction)(struct us_data *);
 65};
 66
 67
 68/* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
 69#define US_FLIDX_URB_ACTIVE	0	/* current_urb is in use    */
 70#define US_FLIDX_SG_ACTIVE	1	/* current_sg is in use     */
 71#define US_FLIDX_ABORTING	2	/* abort is in progress     */
 72#define US_FLIDX_DISCONNECTING	3	/* disconnect in progress   */
 73#define US_FLIDX_RESETTING	4	/* device reset in progress */
 74#define US_FLIDX_TIMED_OUT	5	/* SCSI midlayer timed out  */
 75#define US_FLIDX_DONT_SCAN	6	/* don't scan (disconnect)  */
 76#define US_FLIDX_REDO_READ10	7	/* redo READ(10) command    */
 77#define US_FLIDX_READ10_WORKED	8	/* previous READ(10) succeeded */
 78
 79#define USB_STOR_STRING_LEN 32
 80
 81/*
 82 * We provide a DMA-mapped I/O buffer for use with small USB transfers.
 83 * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
 84 * 31-byte buffer.  But Freecom needs a 64-byte buffer, so that's the
 85 * size we'll allocate.
 86 */
 87
 88#define US_IOBUF_SIZE		64	/* Size of the DMA-mapped I/O buffer */
 89#define US_SENSE_SIZE		18	/* Size of the autosense data buffer */
 90
 91typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
 92typedef int (*trans_reset)(struct us_data*);
 93typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
 94typedef void (*extra_data_destructor)(void *);	/* extra data destructor */
 95typedef void (*pm_hook)(struct us_data *, int);	/* power management hook */
 96
 97#define US_SUSPEND	0
 98#define US_RESUME	1
 99
100/* we allocate one of these for every device that we remember */
101struct us_data {
102	/* The device we're working with
 
103	 * It's important to note:
104	 *    (o) you must hold dev_mutex to change pusb_dev
105	 */
106	struct mutex		dev_mutex;	 /* protect pusb_dev */
107	struct usb_device	*pusb_dev;	 /* this usb_device */
108	struct usb_interface	*pusb_intf;	 /* this interface */
109	struct us_unusual_dev   *unusual_dev;	 /* device-filter entry     */
110	unsigned long		fflags;		 /* fixed flags from filter */
 
111	unsigned long		dflags;		 /* dynamic atomic bitflags */
112	unsigned int		send_bulk_pipe;	 /* cached pipe values */
113	unsigned int		recv_bulk_pipe;
114	unsigned int		send_ctrl_pipe;
115	unsigned int		recv_ctrl_pipe;
116	unsigned int		recv_intr_pipe;
117
118	/* information about the device */
119	char			*transport_name;
120	char			*protocol_name;
121	__le32			bcs_signature;
122	u8			subclass;
123	u8			protocol;
124	u8			max_lun;
125
126	u8			ifnum;		 /* interface number   */
127	u8			ep_bInterval;	 /* interrupt interval */ 
128
129	/* function pointers for this device */
130	trans_cmnd		transport;	 /* transport function	   */
131	trans_reset		transport_reset; /* transport device reset */
132	proto_cmnd		proto_handler;	 /* protocol handler	   */
133
134	/* SCSI interfaces */
135	struct scsi_cmnd	*srb;		 /* current srb		*/
136	unsigned int		tag;		 /* current dCBWTag	*/
137	char			scsi_name[32];	 /* scsi_host name	*/
138
139	/* control and bulk communications data */
140	struct urb		*current_urb;	 /* USB requests	 */
141	struct usb_ctrlrequest	*cr;		 /* control requests	 */
142	struct usb_sg_request	current_sg;	 /* scatter-gather req.  */
143	unsigned char		*iobuf;		 /* I/O buffer		 */
144	dma_addr_t		iobuf_dma;	 /* buffer DMA addresses */
145	struct task_struct	*ctl_thread;	 /* the control thread   */
146
147	/* mutual exclusion and synchronization structures */
148	struct completion	cmnd_ready;	 /* to sleep thread on	    */
149	struct completion	notify;		 /* thread begin/end	    */
150	wait_queue_head_t	delay_wait;	 /* wait during scan, reset */
151	struct completion	scanning_done;	 /* wait for scan thread    */
152
153	/* subdriver information */
154	void			*extra;		 /* Any extra data          */
155	extra_data_destructor	extra_destructor;/* extra data destructor   */
156#ifdef CONFIG_PM
157	pm_hook			suspend_resume_hook;
158#endif
159
160	/* hacks for READ CAPACITY bug handling */
161	int			use_last_sector_hacks;
162	int			last_sector_retries;
163};
164
165/* Convert between us_data and the corresponding Scsi_Host */
166static inline struct Scsi_Host *us_to_host(struct us_data *us) {
167	return container_of((void *) us, struct Scsi_Host, hostdata);
168}
169static inline struct us_data *host_to_us(struct Scsi_Host *host) {
170	return (struct us_data *) host->hostdata;
171}
172
173/* Function to fill an inquiry response. See usb.c for details */
174extern void fill_inquiry_response(struct us_data *us,
175	unsigned char *data, unsigned int data_len);
176
177/* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
178 * single queue element srb for write access */
 
 
179#define scsi_unlock(host)	spin_unlock_irq(host->host_lock)
180#define scsi_lock(host)		spin_lock_irq(host->host_lock)
181
182/* General routines provided by the usb-storage standard core */
183#ifdef CONFIG_PM
184extern int usb_stor_suspend(struct usb_interface *iface, pm_message_t message);
185extern int usb_stor_resume(struct usb_interface *iface);
186extern int usb_stor_reset_resume(struct usb_interface *iface);
187#else
188#define usb_stor_suspend	NULL
189#define usb_stor_resume		NULL
190#define usb_stor_reset_resume	NULL
191#endif
192
193extern int usb_stor_pre_reset(struct usb_interface *iface);
194extern int usb_stor_post_reset(struct usb_interface *iface);
195
196extern int usb_stor_probe1(struct us_data **pus,
197		struct usb_interface *intf,
198		const struct usb_device_id *id,
199		struct us_unusual_dev *unusual_dev);
 
200extern int usb_stor_probe2(struct us_data *us);
201extern void usb_stor_disconnect(struct usb_interface *intf);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
203#endif