# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.627   -> 1.628  
#	drivers/usb/storage/usb.c	1.27    -> 1.28   
#	drivers/usb/storage/transport.c	1.22    -> 1.23   
#	drivers/usb/storage/scsiglue.c	1.22    -> 1.23   
#	drivers/usb/storage/usb.h	1.12    -> 1.13   
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/07/07	mdharm-usb@one-eyed-alien.net	1.628
# [PATCH] PATCH: usb-storage: merge bitfields into a unified system
# 
# This patch unifies all the bit tests and various flags into a single,
# unified system.
# 
# Matt
# --------------------------------------------
#
diff -Nru a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
--- a/drivers/usb/storage/scsiglue.c	Sun Jul  7 12:35:52 2002
+++ b/drivers/usb/storage/scsiglue.c	Sun Jul  7 12:35:52 2002
@@ -198,7 +198,7 @@
 	US_DEBUGP("device_reset() called\n" );
 
 	/* if the device was removed, then we're already reset */
-	if (!test_bit(DEV_ATTACHED, &us->bitflags))
+	if (!(us->flags & US_FL_DEV_ATTACHED))
 		return SUCCESS;
 
 	scsi_unlock(srb->host);
@@ -229,7 +229,7 @@
 	US_DEBUGP("bus_reset() called\n");
 
 	/* if the device has been removed, this worked */
-	if (!test_bit(DEV_ATTACHED, &us->bitflags)) {
+	if (!(us->flags & US_FL_DEV_ATTACHED)) {
 		US_DEBUGP("-- device removed already\n");
 		return SUCCESS;
 	}
@@ -331,8 +331,8 @@
 
 	/* show the GUID of the device */
 	SPRINTF("         GUID: " GUID_FORMAT "\n", GUID_ARGS(us->guid));
-	SPRINTF("     Attached: %s\n", (test_bit(DEV_ATTACHED, &us->bitflags)
-			? "Yes" : "No"));
+	SPRINTF("     Attached: %s\n", (us->flags & US_FL_DEV_ATTACHED ?
+			"Yes" : "No"));
 
 	/*
 	 * Calculate start of next buffer, and return value.
diff -Nru a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
--- a/drivers/usb/storage/transport.c	Sun Jul  7 12:35:52 2002
+++ b/drivers/usb/storage/transport.c	Sun Jul  7 12:35:52 2002
@@ -878,7 +878,7 @@
 	up(&(us->current_urb_sem));
 
 	/* If we are waiting for an IRQ, simulate it */
-	if (test_bit(IP_WANTED, &us->bitflags)) {
+	if (test_bit(US_FLIDX_IP_WANTED, &us->flags)) {
 		US_DEBUGP("-- simulating missing IRQ\n");
 		usb_stor_CBI_irq(us->irq_urb);
 	}
@@ -903,7 +903,7 @@
 	if (atomic_read(&us->sm_state) == US_STATE_ABORTING) {
 
 		/* was this a wanted interrupt? */
-		if (!test_and_clear_bit(IP_WANTED, &us->bitflags)) {
+		if (!test_and_clear_bit(US_FLIDX_IP_WANTED, &us->flags)) {
 			US_DEBUGP("ERROR: Unwanted interrupt received!\n");
 			return;
 		}
@@ -919,7 +919,7 @@
 		US_DEBUGP("-- device has been removed\n");
 
 		/* was this a wanted interrupt? */
-		if (!test_and_clear_bit(IP_WANTED, &us->bitflags))
+		if (!test_and_clear_bit(US_FLIDX_IP_WANTED, &us->flags))
 			return;
 
 		/* indicate a transport error -- this is the best we can do */
@@ -943,7 +943,7 @@
 	}
 
 	/* was this a wanted interrupt? */
-	if (!test_and_clear_bit(IP_WANTED, &us->bitflags)) {
+	if (!test_and_clear_bit(US_FLIDX_IP_WANTED, &us->flags)) {
 		US_DEBUGP("ERROR: Unwanted interrupt received!\n");
 		return;
 	}
@@ -965,7 +965,7 @@
 	init_MUTEX_LOCKED(&(us->ip_waitq));
 
 	/* Set up for status notification */
-	set_bit(IP_WANTED, &us->bitflags);
+	set_bit(US_FLIDX_IP_WANTED, &us->flags);
 
 	/* COMMAND STAGE */
 	/* let's send the command via the control pipe */
@@ -978,7 +978,7 @@
 	US_DEBUGP("Call to usb_stor_control_msg() returned %d\n", result);
 	if (result < 0) {
 		/* Reset flag for status notification */
-		clear_bit(IP_WANTED, &us->bitflags);
+		clear_bit(US_FLIDX_IP_WANTED, &us->flags);
 	}
 
 	/* did we abort this command? */
@@ -1016,11 +1016,11 @@
 
 		/* report any errors */
 		if (result == US_BULK_TRANSFER_ABORTED) {
-			clear_bit(IP_WANTED, &us->bitflags);
+			clear_bit(US_FLIDX_IP_WANTED, &us->flags);
 			return USB_STOR_TRANSPORT_ABORTED;
 		}
 		if (result == US_BULK_TRANSFER_FAILED) {
-			clear_bit(IP_WANTED, &us->bitflags);
+			clear_bit(US_FLIDX_IP_WANTED, &us->flags);
 			return USB_STOR_TRANSPORT_FAILED;
 		}
 	}
diff -Nru a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
--- a/drivers/usb/storage/usb.c	Sun Jul  7 12:35:52 2002
+++ b/drivers/usb/storage/usb.c	Sun Jul  7 12:35:52 2002
@@ -396,7 +396,7 @@
 		}
 
 		/* our device has gone - pretend not ready */
-		else if (!test_bit(DEV_ATTACHED, &us->bitflags)) {
+		else if (!(us->flags & US_FL_DEV_ATTACHED)) {
 			US_DEBUGP("Request is for removed device\n");
 			/* For REQUEST_SENSE, it's the data.  But
 			 * for anything else, it should look like
@@ -420,7 +420,7 @@
 				       sizeof(usb_stor_sense_notready));
 				us->srb->result = CHECK_CONDITION << 1;
 			}
-		}  /* test_bit(DEV_ATTACHED, &us->bitflags) */
+		}  /* !(us->flags & US_FL_DEV_ATTACHED) */
 
 		/* Handle those devices which need us to fake 
 		 * their inquiry data */
@@ -570,7 +570,7 @@
 	}
 
 	/* mark the device as gone */
-	clear_bit(DEV_ATTACHED, &ss->bitflags);
+	ss->flags &= ~ US_FL_DEV_ATTACHED;
 	usb_put_dev(ss->pusb_dev);
 	ss->pusb_dev = NULL;
 }
@@ -726,7 +726,7 @@
 	 */
 	ss = us_list;
 	while ((ss != NULL) && 
-	           (test_bit(DEV_ATTACHED, &ss->bitflags) ||
+	           ((ss->flags & US_FL_DEV_ATTACHED) ||
 		    !GUID_EQUAL(guid, ss->guid)))
 		ss = ss->next;
 
@@ -741,7 +741,7 @@
 		/* establish the connection to the new device upon reconnect */
 		ss->ifnum = ifnum;
 		ss->pusb_dev = dev;
-		set_bit(DEV_ATTACHED, &ss->bitflags);
+		ss->flags |= US_FL_DEV_ATTACHED;
 
 		/* copy over the endpoint data */
 		ss->ep_in = ep_in->bEndpointAddress & 
@@ -785,7 +785,7 @@
 		/* copy over the subclass and protocol data */
 		ss->subclass = subclass;
 		ss->protocol = protocol;
-		ss->flags = flags;
+		ss->flags = flags | US_FL_DEV_ATTACHED;
 		ss->unusual_dev = unusual_dev;
 
 		/* copy over the endpoint data */
@@ -1000,7 +1000,6 @@
 
 		/* start up our control thread */
 		atomic_set(&ss->sm_state, US_STATE_IDLE);
-		set_bit(DEV_ATTACHED, &ss->bitflags);
 		ss->pid = kernel_thread(usb_stor_control_thread, ss,
 					CLONE_VM);
 		if (ss->pid < 0) {
diff -Nru a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
--- a/drivers/usb/storage/usb.h	Sun Jul  7 12:35:52 2002
+++ b/drivers/usb/storage/usb.h	Sun Jul  7 12:35:52 2002
@@ -100,8 +100,11 @@
 						    Win/MacOS compatibility */
 #define US_FL_START_STOP      0x00000004 /* ignore START_STOP commands	    */
 #define US_FL_IGNORE_SER      0x00000010 /* Ignore the serial number given  */
-#define US_FL_SCM_MULT_TARG   0x00000020 /* supports multiple targets */
-#define US_FL_FIX_INQUIRY     0x00000040 /* INQUIRY response needs fixing */
+#define US_FL_SCM_MULT_TARG   0x00000020 /* supports multiple targets	    */
+#define US_FL_FIX_INQUIRY     0x00000040 /* INQUIRY response needs fixing   */
+
+#define US_FL_DEV_ATTACHED    0x00010000 /* is the device attached?	    */
+#define US_FLIDX_IP_WANTED   17  /* 0x00020000	is an IRQ expected?	    */
 
 
 /* kernel thread actions */
@@ -128,12 +131,12 @@
 	/* The device we're working with
 	 * It's important to note:
 	 *    (o) you must hold dev_semaphore to change pusb_dev
-	 *    (o) DEV_ATTACHED in bitflags should change whenever pusb_dev does
+	 *    (o) DEV_ATTACHED in flags should change whenever pusb_dev does
 	 */
 	struct semaphore	dev_semaphore;	 /* protect pusb_dev */
 	struct usb_device	*pusb_dev;	 /* this usb_device */
 
-	unsigned int		flags;		 /* from filter initially */
+	unsigned long		flags;		 /* from filter initially */
 
 	/* information about the device -- always good */
 	char			vendor[USB_STOR_STRING_LEN];
@@ -172,9 +175,6 @@
 
 	/* interrupt info for CBI devices -- only good if attached */
 	struct semaphore	ip_waitq;	 /* for CBI interrupts	 */
-	unsigned long		bitflags;	 /* single-bit flags:	 */
-#define IP_WANTED	1			 /* is an IRQ expected?	 */
-#define DEV_ATTACHED	2			 /* is the dev. attached?*/
 
 	/* interrupt communications data */
 	struct semaphore	irq_urb_sem;	 /* to protect irq_urb	 */
