aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/storage/transport.c
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2008-05-01 15:35:18 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-07-21 18:15:53 -0400
commit7e4d6c387994294ac8198b624ee71e75de60dfd2 (patch)
tree09c8c519a6284f79c38f49347eb7fdf44d8de13e /drivers/usb/storage/transport.c
parent2742fd8899328345d97a3443fb787b051b79ebae (diff)
usb-storage: separate dynamic flags from fixed flags
This patch (as1089) separates out the dynamic atomic bitflags and the static bitfields in usb-storage. Until now the two sorts of flags have been sharing the same word; this has always been awkward. To help prevent possible confusion, the two new fields each have a different name from the original. us->fflags contains the fixed bitfields (mostly taken from the USB ID table in unusual_devs.h), and us->dflags contains the dynamic atomic bitflags (used with set_bit, test_bit, and so on). Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Cc: Matthew Dharm <mdharm-usb@one-eyed-alien.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/storage/transport.c')
-rw-r--r--drivers/usb/storage/transport.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 6610d2dd1e7..2f88bb958ba 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -75,14 +75,14 @@
75 * by a separate code path.) 75 * by a separate code path.)
76 * 76 *
77 * The abort function (usb_storage_command_abort() in scsiglue.c) first 77 * The abort function (usb_storage_command_abort() in scsiglue.c) first
78 * sets the machine state and the ABORTING bit in us->flags to prevent 78 * sets the machine state and the ABORTING bit in us->dflags to prevent
79 * new URBs from being submitted. It then calls usb_stor_stop_transport() 79 * new URBs from being submitted. It then calls usb_stor_stop_transport()
80 * below, which atomically tests-and-clears the URB_ACTIVE bit in us->flags 80 * below, which atomically tests-and-clears the URB_ACTIVE bit in us->dflags
81 * to see if the current_urb needs to be stopped. Likewise, the SG_ACTIVE 81 * to see if the current_urb needs to be stopped. Likewise, the SG_ACTIVE
82 * bit is tested to see if the current_sg scatter-gather request needs to be 82 * bit is tested to see if the current_sg scatter-gather request needs to be
83 * stopped. The timeout callback routine does much the same thing. 83 * stopped. The timeout callback routine does much the same thing.
84 * 84 *
85 * When a disconnect occurs, the DISCONNECTING bit in us->flags is set to 85 * When a disconnect occurs, the DISCONNECTING bit in us->dflags is set to
86 * prevent new URBs from being submitted, and usb_stor_stop_transport() is 86 * prevent new URBs from being submitted, and usb_stor_stop_transport() is
87 * called to stop any ongoing requests. 87 * called to stop any ongoing requests.
88 * 88 *
@@ -128,7 +128,7 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
128 int status; 128 int status;
129 129
130 /* don't submit URBs during abort/disconnect processing */ 130 /* don't submit URBs during abort/disconnect processing */
131 if (us->flags & ABORTING_OR_DISCONNECTING) 131 if (us->dflags & ABORTING_OR_DISCONNECTING)
132 return -EIO; 132 return -EIO;
133 133
134 /* set up data structures for the wakeup system */ 134 /* set up data structures for the wakeup system */
@@ -159,13 +159,13 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
159 159
160 /* since the URB has been submitted successfully, it's now okay 160 /* since the URB has been submitted successfully, it's now okay
161 * to cancel it */ 161 * to cancel it */
162 set_bit(US_FLIDX_URB_ACTIVE, &us->flags); 162 set_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
163 163
164 /* did an abort/disconnect occur during the submission? */ 164 /* did an abort/disconnect occur during the submission? */
165 if (us->flags & ABORTING_OR_DISCONNECTING) { 165 if (us->dflags & ABORTING_OR_DISCONNECTING) {
166 166
167 /* cancel the URB, if it hasn't been cancelled already */ 167 /* cancel the URB, if it hasn't been cancelled already */
168 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->flags)) { 168 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
169 US_DEBUGP("-- cancelling URB\n"); 169 US_DEBUGP("-- cancelling URB\n");
170 usb_unlink_urb(us->current_urb); 170 usb_unlink_urb(us->current_urb);
171 } 171 }
@@ -175,7 +175,7 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
175 timeleft = wait_for_completion_interruptible_timeout( 175 timeleft = wait_for_completion_interruptible_timeout(
176 &urb_done, timeout ? : MAX_SCHEDULE_TIMEOUT); 176 &urb_done, timeout ? : MAX_SCHEDULE_TIMEOUT);
177 177
178 clear_bit(US_FLIDX_URB_ACTIVE, &us->flags); 178 clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
179 179
180 if (timeleft <= 0) { 180 if (timeleft <= 0) {
181 US_DEBUGP("%s -- cancelling URB\n", 181 US_DEBUGP("%s -- cancelling URB\n",
@@ -420,7 +420,7 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
420 int result; 420 int result;
421 421
422 /* don't submit s-g requests during abort/disconnect processing */ 422 /* don't submit s-g requests during abort/disconnect processing */
423 if (us->flags & ABORTING_OR_DISCONNECTING) 423 if (us->dflags & ABORTING_OR_DISCONNECTING)
424 return USB_STOR_XFER_ERROR; 424 return USB_STOR_XFER_ERROR;
425 425
426 /* initialize the scatter-gather request block */ 426 /* initialize the scatter-gather request block */
@@ -435,13 +435,13 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
435 435
436 /* since the block has been initialized successfully, it's now 436 /* since the block has been initialized successfully, it's now
437 * okay to cancel it */ 437 * okay to cancel it */
438 set_bit(US_FLIDX_SG_ACTIVE, &us->flags); 438 set_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
439 439
440 /* did an abort/disconnect occur during the submission? */ 440 /* did an abort/disconnect occur during the submission? */
441 if (us->flags & ABORTING_OR_DISCONNECTING) { 441 if (us->dflags & ABORTING_OR_DISCONNECTING) {
442 442
443 /* cancel the request, if it hasn't been cancelled already */ 443 /* cancel the request, if it hasn't been cancelled already */
444 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->flags)) { 444 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
445 US_DEBUGP("-- cancelling sg request\n"); 445 US_DEBUGP("-- cancelling sg request\n");
446 usb_sg_cancel(&us->current_sg); 446 usb_sg_cancel(&us->current_sg);
447 } 447 }
@@ -449,7 +449,7 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
449 449
450 /* wait for the completion of the transfer */ 450 /* wait for the completion of the transfer */
451 usb_sg_wait(&us->current_sg); 451 usb_sg_wait(&us->current_sg);
452 clear_bit(US_FLIDX_SG_ACTIVE, &us->flags); 452 clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
453 453
454 result = us->current_sg.status; 454 result = us->current_sg.status;
455 if (act_len) 455 if (act_len)
@@ -530,7 +530,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
530 /* if the command gets aborted by the higher layers, we need to 530 /* if the command gets aborted by the higher layers, we need to
531 * short-circuit all other processing 531 * short-circuit all other processing
532 */ 532 */
533 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 533 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
534 US_DEBUGP("-- command was aborted\n"); 534 US_DEBUGP("-- command was aborted\n");
535 srb->result = DID_ABORT << 16; 535 srb->result = DID_ABORT << 16;
536 goto Handle_Errors; 536 goto Handle_Errors;
@@ -616,7 +616,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
616 /* let's clean up right away */ 616 /* let's clean up right away */
617 scsi_eh_restore_cmnd(srb, &ses); 617 scsi_eh_restore_cmnd(srb, &ses);
618 618
619 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 619 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
620 US_DEBUGP("-- auto-sense aborted\n"); 620 US_DEBUGP("-- auto-sense aborted\n");
621 srb->result = DID_ABORT << 16; 621 srb->result = DID_ABORT << 16;
622 goto Handle_Errors; 622 goto Handle_Errors;
@@ -629,7 +629,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
629 * auto-sense is perfectly valid 629 * auto-sense is perfectly valid
630 */ 630 */
631 srb->result = DID_ERROR << 16; 631 srb->result = DID_ERROR << 16;
632 if (!(us->flags & US_FL_SCM_MULT_TARG)) 632 if (!(us->fflags & US_FL_SCM_MULT_TARG))
633 goto Handle_Errors; 633 goto Handle_Errors;
634 return; 634 return;
635 } 635 }
@@ -679,8 +679,8 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
679 /* Set the RESETTING bit, and clear the ABORTING bit so that 679 /* Set the RESETTING bit, and clear the ABORTING bit so that
680 * the reset may proceed. */ 680 * the reset may proceed. */
681 scsi_lock(us_to_host(us)); 681 scsi_lock(us_to_host(us));
682 set_bit(US_FLIDX_RESETTING, &us->flags); 682 set_bit(US_FLIDX_RESETTING, &us->dflags);
683 clear_bit(US_FLIDX_ABORTING, &us->flags); 683 clear_bit(US_FLIDX_ABORTING, &us->dflags);
684 scsi_unlock(us_to_host(us)); 684 scsi_unlock(us_to_host(us));
685 685
686 /* We must release the device lock because the pre_reset routine 686 /* We must release the device lock because the pre_reset routine
@@ -695,7 +695,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
695 scsi_unlock(us_to_host(us)); 695 scsi_unlock(us_to_host(us));
696 us->transport_reset(us); 696 us->transport_reset(us);
697 } 697 }
698 clear_bit(US_FLIDX_RESETTING, &us->flags); 698 clear_bit(US_FLIDX_RESETTING, &us->dflags);
699} 699}
700 700
701/* Stop the current URB transfer */ 701/* Stop the current URB transfer */
@@ -707,13 +707,13 @@ void usb_stor_stop_transport(struct us_data *us)
707 * let's wake it up. The test_and_clear_bit() call 707 * let's wake it up. The test_and_clear_bit() call
708 * guarantees that if a URB has just been submitted, 708 * guarantees that if a URB has just been submitted,
709 * it won't be cancelled more than once. */ 709 * it won't be cancelled more than once. */
710 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->flags)) { 710 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
711 US_DEBUGP("-- cancelling URB\n"); 711 US_DEBUGP("-- cancelling URB\n");
712 usb_unlink_urb(us->current_urb); 712 usb_unlink_urb(us->current_urb);
713 } 713 }
714 714
715 /* If we are waiting for a scatter-gather operation, cancel it. */ 715 /* If we are waiting for a scatter-gather operation, cancel it. */
716 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->flags)) { 716 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
717 US_DEBUGP("-- cancelling sg request\n"); 717 US_DEBUGP("-- cancelling sg request\n");
718 usb_sg_cancel(&us->current_sg); 718 usb_sg_cancel(&us->current_sg);
719 } 719 }
@@ -914,7 +914,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
914 unsigned int cbwlen = US_BULK_CB_WRAP_LEN; 914 unsigned int cbwlen = US_BULK_CB_WRAP_LEN;
915 915
916 /* Take care of BULK32 devices; set extra byte to 0 */ 916 /* Take care of BULK32 devices; set extra byte to 0 */
917 if ( unlikely(us->flags & US_FL_BULK32)) { 917 if (unlikely(us->fflags & US_FL_BULK32)) {
918 cbwlen = 32; 918 cbwlen = 32;
919 us->iobuf[31] = 0; 919 us->iobuf[31] = 0;
920 } 920 }
@@ -925,7 +925,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
925 bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ? 1 << 7 : 0; 925 bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ? 1 << 7 : 0;
926 bcb->Tag = ++us->tag; 926 bcb->Tag = ++us->tag;
927 bcb->Lun = srb->device->lun; 927 bcb->Lun = srb->device->lun;
928 if (us->flags & US_FL_SCM_MULT_TARG) 928 if (us->fflags & US_FL_SCM_MULT_TARG)
929 bcb->Lun |= srb->device->id << 4; 929 bcb->Lun |= srb->device->id << 4;
930 bcb->Length = srb->cmd_len; 930 bcb->Length = srb->cmd_len;
931 931
@@ -951,7 +951,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
951 /* Some USB-IDE converter chips need a 100us delay between the 951 /* Some USB-IDE converter chips need a 100us delay between the
952 * command phase and the data phase. Some devices need a little 952 * command phase and the data phase. Some devices need a little
953 * more than that, probably because of clock rate inaccuracies. */ 953 * more than that, probably because of clock rate inaccuracies. */
954 if (unlikely(us->flags & US_FL_GO_SLOW)) 954 if (unlikely(us->fflags & US_FL_GO_SLOW))
955 udelay(125); 955 udelay(125);
956 956
957 if (transfer_length) { 957 if (transfer_length) {
@@ -1010,7 +1010,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1010 US_DEBUGP("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n", 1010 US_DEBUGP("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n",
1011 le32_to_cpu(bcs->Signature), bcs->Tag, 1011 le32_to_cpu(bcs->Signature), bcs->Tag,
1012 residue, bcs->Status); 1012 residue, bcs->Status);
1013 if (!(bcs->Tag == us->tag || (us->flags & US_FL_BULK_IGNORE_TAG)) || 1013 if (!(bcs->Tag == us->tag || (us->fflags & US_FL_BULK_IGNORE_TAG)) ||
1014 bcs->Status > US_BULK_STAT_PHASE) { 1014 bcs->Status > US_BULK_STAT_PHASE) {
1015 US_DEBUGP("Bulk logical error\n"); 1015 US_DEBUGP("Bulk logical error\n");
1016 return USB_STOR_TRANSPORT_ERROR; 1016 return USB_STOR_TRANSPORT_ERROR;
@@ -1035,7 +1035,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1035 /* try to compute the actual residue, based on how much data 1035 /* try to compute the actual residue, based on how much data
1036 * was really transferred and what the device tells us */ 1036 * was really transferred and what the device tells us */
1037 if (residue) { 1037 if (residue) {
1038 if (!(us->flags & US_FL_IGNORE_RESIDUE)) { 1038 if (!(us->fflags & US_FL_IGNORE_RESIDUE)) {
1039 residue = min(residue, transfer_length); 1039 residue = min(residue, transfer_length);
1040 scsi_set_resid(srb, max(scsi_get_resid(srb), 1040 scsi_set_resid(srb, max(scsi_get_resid(srb),
1041 (int) residue)); 1041 (int) residue));
@@ -1090,7 +1090,7 @@ static int usb_stor_reset_common(struct us_data *us,
1090 int result; 1090 int result;
1091 int result2; 1091 int result2;
1092 1092
1093 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1093 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1094 US_DEBUGP("No reset during disconnect\n"); 1094 US_DEBUGP("No reset during disconnect\n");
1095 return -EIO; 1095 return -EIO;
1096 } 1096 }
@@ -1103,12 +1103,12 @@ static int usb_stor_reset_common(struct us_data *us,
1103 return result; 1103 return result;
1104 } 1104 }
1105 1105
1106 /* Give the device some time to recover from the reset, 1106 /* Give the device some time to recover from the reset,
1107 * but don't delay disconnect processing. */ 1107 * but don't delay disconnect processing. */
1108 wait_event_interruptible_timeout(us->delay_wait, 1108 wait_event_interruptible_timeout(us->delay_wait,
1109 test_bit(US_FLIDX_DISCONNECTING, &us->flags), 1109 test_bit(US_FLIDX_DISCONNECTING, &us->dflags),
1110 HZ*6); 1110 HZ*6);
1111 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1111 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1112 US_DEBUGP("Reset interrupted by disconnect\n"); 1112 US_DEBUGP("Reset interrupted by disconnect\n");
1113 return -EIO; 1113 return -EIO;
1114 } 1114 }
@@ -1170,7 +1170,7 @@ int usb_stor_port_reset(struct us_data *us)
1170 US_DEBUGP("unable to lock device for reset: %d\n", result); 1170 US_DEBUGP("unable to lock device for reset: %d\n", result);
1171 else { 1171 else {
1172 /* Were we disconnected while waiting for the lock? */ 1172 /* Were we disconnected while waiting for the lock? */
1173 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1173 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1174 result = -EIO; 1174 result = -EIO;
1175 US_DEBUGP("No reset during disconnect\n"); 1175 US_DEBUGP("No reset during disconnect\n");
1176 } else { 1176 } else {