[PATCH] USB: gadget: file_storage: reuse definitions from a header file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Michal Nazarewicz <mina86@xxxxxxxxxx>

This commit changes storage_common.c and file_storage.c to
reuse definitions from linux/usb/storage.h header file.

Signed-off-by: Michal Nazarewicz <mina86@xxxxxxxxxx>
Cc: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
---
 drivers/usb/gadget/file_storage.c   |   50 +++++++++++++++++-----------------
 drivers/usb/gadget/storage_common.c |   18 ++----------
 2 files changed, 28 insertions(+), 40 deletions(-)

On Tue, 28 Sep 2010 12:14:55 +0200, Matthew Wilcox <willy@xxxxxxxxxxxxxxx> wrote:
> The libusual header file is hard to use from code that isn't part
> of libusual.  As the comment suggests, these definitions are moved to
> their own header file, paralleling other USB classes.

With Matthew's patch, below patch could be applied as well as to remove
duplicated definitions from storage_common.c file.

diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a857b7a..b35839e 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -403,9 +403,9 @@ MODULE_PARM_DESC(buflen, "I/O buffer size");
 
 #ifdef CONFIG_USB_FILE_STORAGE_TEST
 
-#define transport_is_bbb()	(mod_data.transport_type == USB_PR_BULK)
-#define transport_is_cbi()	(mod_data.transport_type == USB_PR_CBI)
-#define protocol_is_scsi()	(mod_data.protocol_type == USB_SC_SCSI)
+#define transport_is_bbb()	(mod_data.transport_type == US_PR_BULK)
+#define transport_is_cbi()	(mod_data.transport_type == US_PR_CBI)
+#define protocol_is_scsi()	(mod_data.protocol_type == US_SC_SCSI)
 
 #else
 
@@ -2186,18 +2186,18 @@ static int send_status(struct fsg_dev *fsg)
 		start_transfer(fsg, fsg->bulk_in, bh->inreq,
 				&bh->inreq_busy, &bh->state);
 
-	} else if (mod_data.transport_type == USB_PR_CB) {
+	} else if (mod_data.transport_type == US_PR_CB) {
 
 		/* Control-Bulk transport has no status phase! */
 		return 0;
 
-	} else {			// USB_PR_CBI
+	} else {			// US_PR_CBI
 		struct interrupt_data	*buf = bh->buf;
 
 		/* Store and send the Interrupt data.  UFI sends the ASC
 		 * and ASCQ bytes.  Everything else sends a Type (which
 		 * is always 0) and the status Value. */
-		if (mod_data.protocol_type == USB_SC_UFI) {
+		if (mod_data.protocol_type == US_SC_UFI) {
 			buf->bType = ASC(sd);
 			buf->bValue = ASCQ(sd);
 		} else {
@@ -2239,7 +2239,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
 
 	/* There's some disagreement as to whether RBC pads commands or not.
 	 * We'll play it safe and accept either form. */
-	else if (mod_data.protocol_type == USB_SC_RBC) {
+	else if (mod_data.protocol_type == US_SC_RBC) {
 		if (fsg->cmnd_size == 12)
 			cmnd_size = 12;
 
@@ -2710,7 +2710,7 @@ static int get_next_command(struct fsg_dev *fsg)
 		rc = received_cbw(fsg, bh);
 		bh->state = BUF_STATE_EMPTY;
 
-	} else {		// USB_PR_CB or USB_PR_CBI
+	} else {		// US_PR_CB or US_PR_CBI
 
 		/* Wait for the next command to arrive */
 		while (fsg->cbbuf_cmnd_size == 0) {
@@ -3216,9 +3216,9 @@ static int __init check_parameters(struct fsg_dev *fsg)
 	int	i;
 
 	/* Store the default values */
-	mod_data.transport_type = USB_PR_BULK;
+	mod_data.transport_type = US_PR_BULK;
 	mod_data.transport_name = "Bulk-only";
-	mod_data.protocol_type = USB_SC_SCSI;
+	mod_data.protocol_type = US_SC_SCSI;
 	mod_data.protocol_name = "Transparent SCSI";
 
 	/* Some peripheral controllers are known not to be able to
@@ -3245,10 +3245,10 @@ static int __init check_parameters(struct fsg_dev *fsg)
 	if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
 		;		// Use default setting
 	} else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
-		mod_data.transport_type = USB_PR_CB;
+		mod_data.transport_type = US_PR_CB;
 		mod_data.transport_name = "Control-Bulk";
 	} else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
-		mod_data.transport_type = USB_PR_CBI;
+		mod_data.transport_type = US_PR_CBI;
 		mod_data.transport_name = "Control-Bulk-Interrupt";
 	} else {
 		ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
@@ -3256,28 +3256,28 @@ static int __init check_parameters(struct fsg_dev *fsg)
 	}
 
 	if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
-			prot == USB_SC_SCSI) {
+			prot == US_SC_SCSI) {
 		;		// Use default setting
 	} else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
-			prot == USB_SC_RBC) {
-		mod_data.protocol_type = USB_SC_RBC;
+			prot == US_SC_RBC) {
+		mod_data.protocol_type = US_SC_RBC;
 		mod_data.protocol_name = "RBC";
 	} else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
 			strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
-			prot == USB_SC_8020) {
-		mod_data.protocol_type = USB_SC_8020;
+			prot == US_SC_8020) {
+		mod_data.protocol_type = US_SC_8020;
 		mod_data.protocol_name = "8020i (ATAPI)";
 	} else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
-			prot == USB_SC_QIC) {
-		mod_data.protocol_type = USB_SC_QIC;
+			prot == US_SC_QIC) {
+		mod_data.protocol_type = US_SC_QIC;
 		mod_data.protocol_name = "QIC-157";
 	} else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
-			prot == USB_SC_UFI) {
-		mod_data.protocol_type = USB_SC_UFI;
+			prot == US_SC_UFI) {
+		mod_data.protocol_type = US_SC_UFI;
 		mod_data.protocol_name = "UFI";
 	} else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
-			prot == USB_SC_8070) {
-		mod_data.protocol_type = USB_SC_8070;
+			prot == US_SC_8070) {
+		mod_data.protocol_type = US_SC_8070;
 		mod_data.protocol_name = "8070i";
 	} else {
 		ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
@@ -3316,8 +3316,8 @@ static int __init check_parameters(struct fsg_dev *fsg)
 			}
 		}
 		if (len > 126 ||
-		    (mod_data.transport_type == USB_PR_BULK && len < 12) ||
-		    (mod_data.transport_type != USB_PR_BULK && len > 12)) {
+		    (mod_data.transport_type == US_PR_BULK && len < 12) ||
+		    (mod_data.transport_type != US_PR_BULK && len > 12)) {
 			WARNING(fsg,
 				"Invalid serial string length; "
 				"Failing back to default\n");
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 484acfb..cc63630 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -55,6 +55,7 @@
 
 
 #include <asm/unaligned.h>
+#include <linux/usb/storage.h>
 
 
 /*
@@ -157,19 +158,6 @@
 #define TYPE_DISK	0x00
 #define TYPE_CDROM	0x05
 
-/* USB protocol value = the transport method */
-#define USB_PR_CBI	0x00		/* Control/Bulk/Interrupt */
-#define USB_PR_CB	0x01		/* Control/Bulk w/o interrupt */
-#define USB_PR_BULK	0x50		/* Bulk-only */
-
-/* USB subclass value = the protocol encapsulation */
-#define USB_SC_RBC	0x01		/* Reduced Block Commands (flash) */
-#define USB_SC_8020	0x02		/* SFF-8020i, MMC-2, ATAPI (CD-ROM) */
-#define USB_SC_QIC	0x03		/* QIC-157 (tape) */
-#define USB_SC_UFI	0x04		/* UFI (floppy) */
-#define USB_SC_8070	0x05		/* SFF-8070i (removable) */
-#define USB_SC_SCSI	0x06		/* Transparent SCSI */
-
 /* Bulk-only data structures */
 
 /* Command Block Wrapper */
@@ -408,8 +396,8 @@ fsg_intf_desc = {
 
 	.bNumEndpoints =	2,		/* Adjusted during fsg_bind() */
 	.bInterfaceClass =	USB_CLASS_MASS_STORAGE,
-	.bInterfaceSubClass =	USB_SC_SCSI,	/* Adjusted during fsg_bind() */
-	.bInterfaceProtocol =	USB_PR_BULK,	/* Adjusted during fsg_bind() */
+	.bInterfaceSubClass =	US_SC_SCSI,	/* Adjusted during fsg_bind() */
+	.bInterfaceProtocol =	US_PR_BULK,	/* Adjusted during fsg_bind() */
 	.iInterface =		FSG_STRING_INTERFACE,
 };
 
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux