aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/storage
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2012-04-08 15:48:52 -0400
committerJiri Kosina <jkosina@suse.cz>2012-04-08 15:48:52 -0400
commite75d660672ddd11704b7f0fdb8ff21968587b266 (patch)
treeccb9c107744c10b553c0373e450bee3971d16c00 /drivers/usb/storage
parent61282f37927143e45b03153f3e7b48d6b702147a (diff)
parent0034102808e0dbbf3a2394b82b1bb40b5778de9e (diff)
Merge branch 'master' into for-next
Merge with latest Linus' tree, as I have incoming patches that fix code that is newer than current HEAD of for-next. Conflicts: drivers/net/ethernet/realtek/r8169.c
Diffstat (limited to 'drivers/usb/storage')
-rw-r--r--drivers/usb/storage/Kconfig2
-rw-r--r--drivers/usb/storage/alauda.c1
-rw-r--r--drivers/usb/storage/cypress_atacb.c1
-rw-r--r--drivers/usb/storage/datafab.c1
-rw-r--r--drivers/usb/storage/ene_ub6250.c27
-rw-r--r--drivers/usb/storage/freecom.c1
-rw-r--r--drivers/usb/storage/isd200.c1
-rw-r--r--drivers/usb/storage/jumpshot.c1
-rw-r--r--drivers/usb/storage/karma.c1
-rw-r--r--drivers/usb/storage/onetouch.c1
-rw-r--r--drivers/usb/storage/realtek_cr.c13
-rw-r--r--drivers/usb/storage/scsiglue.c55
-rw-r--r--drivers/usb/storage/sddr09.c1
-rw-r--r--drivers/usb/storage/sddr55.c1
-rw-r--r--drivers/usb/storage/shuttle_usbat.c1
-rw-r--r--drivers/usb/storage/transport.c3
-rw-r--r--drivers/usb/storage/transport.h39
-rw-r--r--drivers/usb/storage/uas.c328
-rw-r--r--drivers/usb/storage/usb.c111
-rw-r--r--drivers/usb/storage/usb.h7
20 files changed, 334 insertions, 262 deletions
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index fe2d803a6347..7691c866637b 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -222,7 +222,7 @@ config USB_LIBUSUAL
222 for usb-storage and ub drivers, and allows to switch binding 222 for usb-storage and ub drivers, and allows to switch binding
223 of these devices without rebuilding modules. 223 of these devices without rebuilding modules.
224 224
225 Typical syntax of /etc/modprobe.conf is: 225 Typical syntax of /etc/modprobe.d/*conf is:
226 226
227 options libusual bias="ub" 227 options libusual bias="ub"
228 228
diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c
index 51af2fee2efd..bab8c8fe8290 100644
--- a/drivers/usb/storage/alauda.c
+++ b/drivers/usb/storage/alauda.c
@@ -1276,6 +1276,7 @@ static struct usb_driver alauda_driver = {
1276 .post_reset = usb_stor_post_reset, 1276 .post_reset = usb_stor_post_reset,
1277 .id_table = alauda_usb_ids, 1277 .id_table = alauda_usb_ids,
1278 .soft_unbind = 1, 1278 .soft_unbind = 1,
1279 .no_dynamic_id = 1,
1279}; 1280};
1280 1281
1281module_usb_driver(alauda_driver); 1282module_usb_driver(alauda_driver);
diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c
index 387cbd47acc9..5fe451d16e68 100644
--- a/drivers/usb/storage/cypress_atacb.c
+++ b/drivers/usb/storage/cypress_atacb.c
@@ -272,6 +272,7 @@ static struct usb_driver cypress_driver = {
272 .post_reset = usb_stor_post_reset, 272 .post_reset = usb_stor_post_reset,
273 .id_table = cypress_usb_ids, 273 .id_table = cypress_usb_ids,
274 .soft_unbind = 1, 274 .soft_unbind = 1,
275 .no_dynamic_id = 1,
275}; 276};
276 277
277module_usb_driver(cypress_driver); 278module_usb_driver(cypress_driver);
diff --git a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c
index 15d41f2b3d6f..35e9c51e6696 100644
--- a/drivers/usb/storage/datafab.c
+++ b/drivers/usb/storage/datafab.c
@@ -751,6 +751,7 @@ static struct usb_driver datafab_driver = {
751 .post_reset = usb_stor_post_reset, 751 .post_reset = usb_stor_post_reset,
752 .id_table = datafab_usb_ids, 752 .id_table = datafab_usb_ids,
753 .soft_unbind = 1, 753 .soft_unbind = 1,
754 .no_dynamic_id = 1,
754}; 755};
755 756
756module_usb_driver(datafab_driver); 757module_usb_driver(datafab_driver);
diff --git a/drivers/usb/storage/ene_ub6250.c b/drivers/usb/storage/ene_ub6250.c
index a6ade4071a9a..e7e678109500 100644
--- a/drivers/usb/storage/ene_ub6250.c
+++ b/drivers/usb/storage/ene_ub6250.c
@@ -674,7 +674,7 @@ static int sd_scsi_read(struct us_data *us, struct scsi_cmnd *srb)
674 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 674 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
675 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 675 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
676 bcb->DataTransferLength = blenByte; 676 bcb->DataTransferLength = blenByte;
677 bcb->Flags = 0x80; 677 bcb->Flags = US_BULK_FLAG_IN;
678 bcb->CDB[0] = 0xF1; 678 bcb->CDB[0] = 0xF1;
679 bcb->CDB[5] = (unsigned char)(bnByte); 679 bcb->CDB[5] = (unsigned char)(bnByte);
680 bcb->CDB[4] = (unsigned char)(bnByte>>8); 680 bcb->CDB[4] = (unsigned char)(bnByte>>8);
@@ -858,7 +858,7 @@ static int ms_read_readpage(struct us_data *us, u32 PhyBlockAddr,
858 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 858 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
859 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 859 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
860 bcb->DataTransferLength = 0x200; 860 bcb->DataTransferLength = 0x200;
861 bcb->Flags = 0x80; 861 bcb->Flags = US_BULK_FLAG_IN;
862 bcb->CDB[0] = 0xF1; 862 bcb->CDB[0] = 0xF1;
863 863
864 bcb->CDB[1] = 0x02; /* in init.c ENE_MSInit() is 0x01 */ 864 bcb->CDB[1] = 0x02; /* in init.c ENE_MSInit() is 0x01 */
@@ -877,7 +877,7 @@ static int ms_read_readpage(struct us_data *us, u32 PhyBlockAddr,
877 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 877 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
878 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 878 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
879 bcb->DataTransferLength = 0x4; 879 bcb->DataTransferLength = 0x4;
880 bcb->Flags = 0x80; 880 bcb->Flags = US_BULK_FLAG_IN;
881 bcb->CDB[0] = 0xF1; 881 bcb->CDB[0] = 0xF1;
882 bcb->CDB[1] = 0x03; 882 bcb->CDB[1] = 0x03;
883 883
@@ -1170,7 +1170,7 @@ static int ms_read_eraseblock(struct us_data *us, u32 PhyBlockAddr)
1170 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 1170 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
1171 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 1171 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
1172 bcb->DataTransferLength = 0x200; 1172 bcb->DataTransferLength = 0x200;
1173 bcb->Flags = 0x80; 1173 bcb->Flags = US_BULK_FLAG_IN;
1174 bcb->CDB[0] = 0xF2; 1174 bcb->CDB[0] = 0xF2;
1175 bcb->CDB[1] = 0x06; 1175 bcb->CDB[1] = 0x06;
1176 bcb->CDB[4] = (unsigned char)(bn); 1176 bcb->CDB[4] = (unsigned char)(bn);
@@ -1249,7 +1249,7 @@ static int ms_lib_overwrite_extra(struct us_data *us, u32 PhyBlockAddr,
1249 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 1249 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
1250 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 1250 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
1251 bcb->DataTransferLength = 0x4; 1251 bcb->DataTransferLength = 0x4;
1252 bcb->Flags = 0x80; 1252 bcb->Flags = US_BULK_FLAG_IN;
1253 bcb->CDB[0] = 0xF2; 1253 bcb->CDB[0] = 0xF2;
1254 bcb->CDB[1] = 0x05; 1254 bcb->CDB[1] = 0x05;
1255 bcb->CDB[5] = (unsigned char)(PageNum); 1255 bcb->CDB[5] = (unsigned char)(PageNum);
@@ -1331,7 +1331,7 @@ static int ms_lib_read_extra(struct us_data *us, u32 PhyBlock,
1331 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 1331 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
1332 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 1332 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
1333 bcb->DataTransferLength = 0x4; 1333 bcb->DataTransferLength = 0x4;
1334 bcb->Flags = 0x80; 1334 bcb->Flags = US_BULK_FLAG_IN;
1335 bcb->CDB[0] = 0xF1; 1335 bcb->CDB[0] = 0xF1;
1336 bcb->CDB[1] = 0x03; 1336 bcb->CDB[1] = 0x03;
1337 bcb->CDB[5] = (unsigned char)(PageNum); 1337 bcb->CDB[5] = (unsigned char)(PageNum);
@@ -1533,7 +1533,7 @@ static int ms_lib_read_extrablock(struct us_data *us, u32 PhyBlock,
1533 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 1533 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
1534 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 1534 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
1535 bcb->DataTransferLength = 0x4 * blen; 1535 bcb->DataTransferLength = 0x4 * blen;
1536 bcb->Flags = 0x80; 1536 bcb->Flags = US_BULK_FLAG_IN;
1537 bcb->CDB[0] = 0xF1; 1537 bcb->CDB[0] = 0xF1;
1538 bcb->CDB[1] = 0x03; 1538 bcb->CDB[1] = 0x03;
1539 bcb->CDB[5] = (unsigned char)(PageNum); 1539 bcb->CDB[5] = (unsigned char)(PageNum);
@@ -1650,7 +1650,7 @@ static int ms_scsi_read(struct us_data *us, struct scsi_cmnd *srb)
1650 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 1650 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
1651 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 1651 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
1652 bcb->DataTransferLength = blenByte; 1652 bcb->DataTransferLength = blenByte;
1653 bcb->Flags = 0x80; 1653 bcb->Flags = US_BULK_FLAG_IN;
1654 bcb->CDB[0] = 0xF1; 1654 bcb->CDB[0] = 0xF1;
1655 bcb->CDB[1] = 0x02; 1655 bcb->CDB[1] = 0x02;
1656 bcb->CDB[5] = (unsigned char)(bn); 1656 bcb->CDB[5] = (unsigned char)(bn);
@@ -1694,7 +1694,7 @@ static int ms_scsi_read(struct us_data *us, struct scsi_cmnd *srb)
1694 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 1694 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
1695 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 1695 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
1696 bcb->DataTransferLength = 0x200 * len; 1696 bcb->DataTransferLength = 0x200 * len;
1697 bcb->Flags = 0x80; 1697 bcb->Flags = US_BULK_FLAG_IN;
1698 bcb->CDB[0] = 0xF1; 1698 bcb->CDB[0] = 0xF1;
1699 bcb->CDB[1] = 0x02; 1699 bcb->CDB[1] = 0x02;
1700 bcb->CDB[5] = (unsigned char)(blkno); 1700 bcb->CDB[5] = (unsigned char)(blkno);
@@ -1827,7 +1827,7 @@ static int ene_get_card_type(struct us_data *us, u16 index, void *buf)
1827 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 1827 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
1828 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 1828 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
1829 bcb->DataTransferLength = 0x01; 1829 bcb->DataTransferLength = 0x01;
1830 bcb->Flags = 0x80; 1830 bcb->Flags = US_BULK_FLAG_IN;
1831 bcb->CDB[0] = 0xED; 1831 bcb->CDB[0] = 0xED;
1832 bcb->CDB[2] = (unsigned char)(index>>8); 1832 bcb->CDB[2] = (unsigned char)(index>>8);
1833 bcb->CDB[3] = (unsigned char)index; 1833 bcb->CDB[3] = (unsigned char)index;
@@ -2083,7 +2083,7 @@ static int ene_ms_init(struct us_data *us)
2083 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 2083 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
2084 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 2084 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
2085 bcb->DataTransferLength = 0x200; 2085 bcb->DataTransferLength = 0x200;
2086 bcb->Flags = 0x80; 2086 bcb->Flags = US_BULK_FLAG_IN;
2087 bcb->CDB[0] = 0xF1; 2087 bcb->CDB[0] = 0xF1;
2088 bcb->CDB[1] = 0x01; 2088 bcb->CDB[1] = 0x01;
2089 2089
@@ -2134,7 +2134,7 @@ static int ene_sd_init(struct us_data *us)
2134 2134
2135 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 2135 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
2136 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 2136 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
2137 bcb->Flags = 0x80; 2137 bcb->Flags = US_BULK_FLAG_IN;
2138 bcb->CDB[0] = 0xF2; 2138 bcb->CDB[0] = 0xF2;
2139 2139
2140 result = ene_send_scsi_cmd(us, FDIR_READ, NULL, 0); 2140 result = ene_send_scsi_cmd(us, FDIR_READ, NULL, 0);
@@ -2153,7 +2153,7 @@ static int ene_sd_init(struct us_data *us)
2153 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 2153 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
2154 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 2154 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
2155 bcb->DataTransferLength = 0x200; 2155 bcb->DataTransferLength = 0x200;
2156 bcb->Flags = 0x80; 2156 bcb->Flags = US_BULK_FLAG_IN;
2157 bcb->CDB[0] = 0xF1; 2157 bcb->CDB[0] = 0xF1;
2158 2158
2159 result = ene_send_scsi_cmd(us, FDIR_READ, &buf, 0); 2159 result = ene_send_scsi_cmd(us, FDIR_READ, &buf, 0);
@@ -2407,6 +2407,7 @@ static struct usb_driver ene_ub6250_driver = {
2407 .post_reset = usb_stor_post_reset, 2407 .post_reset = usb_stor_post_reset,
2408 .id_table = ene_ub6250_usb_ids, 2408 .id_table = ene_ub6250_usb_ids,
2409 .soft_unbind = 1, 2409 .soft_unbind = 1,
2410 .no_dynamic_id = 1,
2410}; 2411};
2411 2412
2412module_usb_driver(ene_ub6250_driver); 2413module_usb_driver(ene_ub6250_driver);
diff --git a/drivers/usb/storage/freecom.c b/drivers/usb/storage/freecom.c
index fa1615748475..042cf9ef3153 100644
--- a/drivers/usb/storage/freecom.c
+++ b/drivers/usb/storage/freecom.c
@@ -553,6 +553,7 @@ static struct usb_driver freecom_driver = {
553 .post_reset = usb_stor_post_reset, 553 .post_reset = usb_stor_post_reset,
554 .id_table = freecom_usb_ids, 554 .id_table = freecom_usb_ids,
555 .soft_unbind = 1, 555 .soft_unbind = 1,
556 .no_dynamic_id = 1,
556}; 557};
557 558
558module_usb_driver(freecom_driver); 559module_usb_driver(freecom_driver);
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index bd5502700831..31fa24e7e68a 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -1566,6 +1566,7 @@ static struct usb_driver isd200_driver = {
1566 .post_reset = usb_stor_post_reset, 1566 .post_reset = usb_stor_post_reset,
1567 .id_table = isd200_usb_ids, 1567 .id_table = isd200_usb_ids,
1568 .soft_unbind = 1, 1568 .soft_unbind = 1,
1569 .no_dynamic_id = 1,
1569}; 1570};
1570 1571
1571module_usb_driver(isd200_driver); 1572module_usb_driver(isd200_driver);
diff --git a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c
index a19211b5c265..e3b97383186a 100644
--- a/drivers/usb/storage/jumpshot.c
+++ b/drivers/usb/storage/jumpshot.c
@@ -677,6 +677,7 @@ static struct usb_driver jumpshot_driver = {
677 .post_reset = usb_stor_post_reset, 677 .post_reset = usb_stor_post_reset,
678 .id_table = jumpshot_usb_ids, 678 .id_table = jumpshot_usb_ids,
679 .soft_unbind = 1, 679 .soft_unbind = 1,
680 .no_dynamic_id = 1,
680}; 681};
681 682
682module_usb_driver(jumpshot_driver); 683module_usb_driver(jumpshot_driver);
diff --git a/drivers/usb/storage/karma.c b/drivers/usb/storage/karma.c
index e720f8ebdf9f..a8708eae9788 100644
--- a/drivers/usb/storage/karma.c
+++ b/drivers/usb/storage/karma.c
@@ -230,6 +230,7 @@ static struct usb_driver karma_driver = {
230 .post_reset = usb_stor_post_reset, 230 .post_reset = usb_stor_post_reset,
231 .id_table = karma_usb_ids, 231 .id_table = karma_usb_ids,
232 .soft_unbind = 1, 232 .soft_unbind = 1,
233 .no_dynamic_id = 1,
233}; 234};
234 235
235module_usb_driver(karma_driver); 236module_usb_driver(karma_driver);
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index d75155c38200..886567a3806d 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -312,6 +312,7 @@ static struct usb_driver onetouch_driver = {
312 .post_reset = usb_stor_post_reset, 312 .post_reset = usb_stor_post_reset,
313 .id_table = onetouch_usb_ids, 313 .id_table = onetouch_usb_ids,
314 .soft_unbind = 1, 314 .soft_unbind = 1,
315 .no_dynamic_id = 1,
315}; 316};
316 317
317module_usb_driver(onetouch_driver); 318module_usb_driver(onetouch_driver);
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
index d32f72061c09..63cf2822e299 100644
--- a/drivers/usb/storage/realtek_cr.c
+++ b/drivers/usb/storage/realtek_cr.c
@@ -219,7 +219,7 @@ static int rts51x_bulk_transport(struct us_data *us, u8 lun,
219 /* set up the command wrapper */ 219 /* set up the command wrapper */
220 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 220 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
221 bcb->DataTransferLength = cpu_to_le32(buf_len); 221 bcb->DataTransferLength = cpu_to_le32(buf_len);
222 bcb->Flags = (dir == DMA_FROM_DEVICE) ? 1 << 7 : 0; 222 bcb->Flags = (dir == DMA_FROM_DEVICE) ? US_BULK_FLAG_IN : 0;
223 bcb->Tag = ++us->tag; 223 bcb->Tag = ++us->tag;
224 bcb->Lun = lun; 224 bcb->Lun = lun;
225 bcb->Length = cmd_len; 225 bcb->Length = cmd_len;
@@ -305,7 +305,7 @@ static int rts51x_bulk_transport_special(struct us_data *us, u8 lun,
305 /* set up the command wrapper */ 305 /* set up the command wrapper */
306 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 306 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
307 bcb->DataTransferLength = cpu_to_le32(buf_len); 307 bcb->DataTransferLength = cpu_to_le32(buf_len);
308 bcb->Flags = (dir == DMA_FROM_DEVICE) ? 1 << 7 : 0; 308 bcb->Flags = (dir == DMA_FROM_DEVICE) ? US_BULK_FLAG_IN : 0;
309 bcb->Tag = ++us->tag; 309 bcb->Tag = ++us->tag;
310 bcb->Lun = lun; 310 bcb->Lun = lun;
311 bcb->Length = cmd_len; 311 bcb->Length = cmd_len;
@@ -507,9 +507,14 @@ static int __do_config_autodelink(struct us_data *us, u8 *data, u16 len)
507{ 507{
508 int retval; 508 int retval;
509 u8 cmnd[12] = {0}; 509 u8 cmnd[12] = {0};
510 u8 *buf;
510 511
511 US_DEBUGP("%s, addr = 0xfe47, len = %d\n", __FUNCTION__, len); 512 US_DEBUGP("%s, addr = 0xfe47, len = %d\n", __FUNCTION__, len);
512 513
514 buf = kmemdup(data, len, GFP_NOIO);
515 if (!buf)
516 return USB_STOR_TRANSPORT_ERROR;
517
513 cmnd[0] = 0xF0; 518 cmnd[0] = 0xF0;
514 cmnd[1] = 0x0E; 519 cmnd[1] = 0x0E;
515 cmnd[2] = 0xfe; 520 cmnd[2] = 0xfe;
@@ -517,7 +522,8 @@ static int __do_config_autodelink(struct us_data *us, u8 *data, u16 len)
517 cmnd[4] = (u8)(len >> 8); 522 cmnd[4] = (u8)(len >> 8);
518 cmnd[5] = (u8)len; 523 cmnd[5] = (u8)len;
519 524
520 retval = rts51x_bulk_transport_special(us, 0, cmnd, 12, data, len, DMA_TO_DEVICE, NULL); 525 retval = rts51x_bulk_transport_special(us, 0, cmnd, 12, buf, len, DMA_TO_DEVICE, NULL);
526 kfree(buf);
521 if (retval != USB_STOR_TRANSPORT_GOOD) { 527 if (retval != USB_STOR_TRANSPORT_GOOD) {
522 return -EIO; 528 return -EIO;
523 } 529 }
@@ -1100,6 +1106,7 @@ static struct usb_driver realtek_cr_driver = {
1100 .id_table = realtek_cr_ids, 1106 .id_table = realtek_cr_ids,
1101 .soft_unbind = 1, 1107 .soft_unbind = 1,
1102 .supports_autosuspend = 1, 1108 .supports_autosuspend = 1,
1109 .no_dynamic_id = 1,
1103}; 1110};
1104 1111
1105module_usb_driver(realtek_cr_driver); 1112module_usb_driver(realtek_cr_driver);
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 13b8bcdf3dba..a324a5d21e99 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -78,8 +78,6 @@ static const char* host_info(struct Scsi_Host *host)
78 78
79static int slave_alloc (struct scsi_device *sdev) 79static int slave_alloc (struct scsi_device *sdev)
80{ 80{
81 struct us_data *us = host_to_us(sdev->host);
82
83 /* 81 /*
84 * Set the INQUIRY transfer length to 36. We don't use any of 82 * Set the INQUIRY transfer length to 36. We don't use any of
85 * the extra data and many devices choke if asked for more or 83 * the extra data and many devices choke if asked for more or
@@ -104,18 +102,6 @@ static int slave_alloc (struct scsi_device *sdev)
104 */ 102 */
105 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1)); 103 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
106 104
107 /*
108 * The UFI spec treates the Peripheral Qualifier bits in an
109 * INQUIRY result as reserved and requires devices to set them
110 * to 0. However the SCSI spec requires these bits to be set
111 * to 3 to indicate when a LUN is not present.
112 *
113 * Let the scanning code know if this target merely sets
114 * Peripheral Device Type to 0x1f to indicate no LUN.
115 */
116 if (us->subclass == USB_SC_UFI)
117 sdev->sdev_target->pdt_1f_for_no_lun = 1;
118
119 return 0; 105 return 0;
120} 106}
121 107
@@ -197,6 +183,9 @@ static int slave_configure(struct scsi_device *sdev)
197 * page x08, so we will skip it. */ 183 * page x08, so we will skip it. */
198 sdev->skip_ms_page_8 = 1; 184 sdev->skip_ms_page_8 = 1;
199 185
186 /* Some devices don't handle VPD pages correctly */
187 sdev->skip_vpd_pages = 1;
188
200 /* Some disks return the total number of blocks in response 189 /* Some disks return the total number of blocks in response
201 * to READ CAPACITY rather than the highest block number. 190 * to READ CAPACITY rather than the highest block number.
202 * If this device makes that mistake, tell the sd driver. */ 191 * If this device makes that mistake, tell the sd driver. */
@@ -217,16 +206,6 @@ static int slave_configure(struct scsi_device *sdev)
217 if (sdev->scsi_level > SCSI_SPC_2) 206 if (sdev->scsi_level > SCSI_SPC_2)
218 us->fflags |= US_FL_SANE_SENSE; 207 us->fflags |= US_FL_SANE_SENSE;
219 208
220 /* Some devices report a SCSI revision level above 2 but are
221 * unable to handle the REPORT LUNS command (for which
222 * support is mandatory at level 3). Since we already have
223 * a Get-Max-LUN request, we won't lose much by setting the
224 * revision level down to 2. The only devices that would be
225 * affected are those with sparse LUNs. */
226 if (sdev->scsi_level > SCSI_2)
227 sdev->sdev_target->scsi_level =
228 sdev->scsi_level = SCSI_2;
229
230 /* USB-IDE bridges tend to report SK = 0x04 (Non-recoverable 209 /* USB-IDE bridges tend to report SK = 0x04 (Non-recoverable
231 * Hardware Error) when any low-level error occurs, 210 * Hardware Error) when any low-level error occurs,
232 * recoverable or not. Setting this flag tells the SCSI 211 * recoverable or not. Setting this flag tells the SCSI
@@ -283,6 +262,33 @@ static int slave_configure(struct scsi_device *sdev)
283 return 0; 262 return 0;
284} 263}
285 264
265static int target_alloc(struct scsi_target *starget)
266{
267 struct us_data *us = host_to_us(dev_to_shost(starget->dev.parent));
268
269 /*
270 * Some USB drives don't support REPORT LUNS, even though they
271 * report a SCSI revision level above 2. Tell the SCSI layer
272 * not to issue that command; it will perform a normal sequential
273 * scan instead.
274 */
275 starget->no_report_luns = 1;
276
277 /*
278 * The UFI spec treats the Peripheral Qualifier bits in an
279 * INQUIRY result as reserved and requires devices to set them
280 * to 0. However the SCSI spec requires these bits to be set
281 * to 3 to indicate when a LUN is not present.
282 *
283 * Let the scanning code know if this target merely sets
284 * Peripheral Device Type to 0x1f to indicate no LUN.
285 */
286 if (us->subclass == USB_SC_UFI)
287 starget->pdt_1f_for_no_lun = 1;
288
289 return 0;
290}
291
286/* queue a command */ 292/* queue a command */
287/* This is always called with scsi_lock(host) held */ 293/* This is always called with scsi_lock(host) held */
288static int queuecommand_lck(struct scsi_cmnd *srb, 294static int queuecommand_lck(struct scsi_cmnd *srb,
@@ -546,6 +552,7 @@ struct scsi_host_template usb_stor_host_template = {
546 552
547 .slave_alloc = slave_alloc, 553 .slave_alloc = slave_alloc,
548 .slave_configure = slave_configure, 554 .slave_configure = slave_configure,
555 .target_alloc = target_alloc,
549 556
550 /* lots of sg segments can be handled */ 557 /* lots of sg segments can be handled */
551 .sg_tablesize = SCSI_MAX_SG_CHAIN_SEGMENTS, 558 .sg_tablesize = SCSI_MAX_SG_CHAIN_SEGMENTS,
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c
index 425df7df2e56..3252a62b31bc 100644
--- a/drivers/usb/storage/sddr09.c
+++ b/drivers/usb/storage/sddr09.c
@@ -1787,6 +1787,7 @@ static struct usb_driver sddr09_driver = {
1787 .post_reset = usb_stor_post_reset, 1787 .post_reset = usb_stor_post_reset,
1788 .id_table = sddr09_usb_ids, 1788 .id_table = sddr09_usb_ids,
1789 .soft_unbind = 1, 1789 .soft_unbind = 1,
1790 .no_dynamic_id = 1,
1790}; 1791};
1791 1792
1792module_usb_driver(sddr09_driver); 1793module_usb_driver(sddr09_driver);
diff --git a/drivers/usb/storage/sddr55.c b/drivers/usb/storage/sddr55.c
index e4ca5fcb7cc3..c144078065a7 100644
--- a/drivers/usb/storage/sddr55.c
+++ b/drivers/usb/storage/sddr55.c
@@ -1006,6 +1006,7 @@ static struct usb_driver sddr55_driver = {
1006 .post_reset = usb_stor_post_reset, 1006 .post_reset = usb_stor_post_reset,
1007 .id_table = sddr55_usb_ids, 1007 .id_table = sddr55_usb_ids,
1008 .soft_unbind = 1, 1008 .soft_unbind = 1,
1009 .no_dynamic_id = 1,
1009}; 1010};
1010 1011
1011module_usb_driver(sddr55_driver); 1012module_usb_driver(sddr55_driver);
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index 1369d2590616..fa1ceebc465c 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -1863,6 +1863,7 @@ static struct usb_driver usbat_driver = {
1863 .post_reset = usb_stor_post_reset, 1863 .post_reset = usb_stor_post_reset,
1864 .id_table = usbat_usb_ids, 1864 .id_table = usbat_usb_ids,
1865 .soft_unbind = 1, 1865 .soft_unbind = 1,
1866 .no_dynamic_id = 1,
1866}; 1867};
1867 1868
1868module_usb_driver(usbat_driver); 1869module_usb_driver(usbat_driver);
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 0e5c91c6187f..c70109e5d60b 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -1071,7 +1071,8 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1071 /* set up the command wrapper */ 1071 /* set up the command wrapper */
1072 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 1072 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
1073 bcb->DataTransferLength = cpu_to_le32(transfer_length); 1073 bcb->DataTransferLength = cpu_to_le32(transfer_length);
1074 bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ? 1 << 7 : 0; 1074 bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ?
1075 US_BULK_FLAG_IN : 0;
1075 bcb->Tag = ++us->tag; 1076 bcb->Tag = ++us->tag;
1076 bcb->Lun = srb->device->lun; 1077 bcb->Lun = srb->device->lun;
1077 if (us->fflags & US_FL_SCM_MULT_TARG) 1078 if (us->fflags & US_FL_SCM_MULT_TARG)
diff --git a/drivers/usb/storage/transport.h b/drivers/usb/storage/transport.h
index 242ff5e791a5..9369d752d419 100644
--- a/drivers/usb/storage/transport.h
+++ b/drivers/usb/storage/transport.h
@@ -42,45 +42,6 @@
42#include <linux/blkdev.h> 42#include <linux/blkdev.h>
43 43
44/* 44/*
45 * Bulk only data structures
46 */
47
48/* command block wrapper */
49struct bulk_cb_wrap {
50 __le32 Signature; /* contains 'USBC' */
51 __u32 Tag; /* unique per command id */
52 __le32 DataTransferLength; /* size of data */
53 __u8 Flags; /* direction in bit 0 */
54 __u8 Lun; /* LUN normally 0 */
55 __u8 Length; /* of of the CDB */
56 __u8 CDB[16]; /* max command */
57};
58
59#define US_BULK_CB_WRAP_LEN 31
60#define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */
61#define US_BULK_FLAG_IN 1
62#define US_BULK_FLAG_OUT 0
63
64/* command status wrapper */
65struct bulk_cs_wrap {
66 __le32 Signature; /* should = 'USBS' */
67 __u32 Tag; /* same as original command */
68 __le32 Residue; /* amount not transferred */
69 __u8 Status; /* see below */
70 __u8 Filler[18];
71};
72
73#define US_BULK_CS_WRAP_LEN 13
74#define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
75#define US_BULK_STAT_OK 0
76#define US_BULK_STAT_FAIL 1
77#define US_BULK_STAT_PHASE 2
78
79/* bulk-only class specific requests */
80#define US_BULK_RESET_REQUEST 0xff
81#define US_BULK_GET_MAX_LUN 0xfe
82
83/*
84 * usb_stor_bulk_transfer_xxx() return codes, in order of severity 45 * usb_stor_bulk_transfer_xxx() return codes, in order of severity
85 */ 46 */
86 47
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index a33ead5dce20..8ec8a6e66f50 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -13,7 +13,9 @@
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/usb/hcd.h>
16#include <linux/usb/storage.h> 17#include <linux/usb/storage.h>
18#include <linux/usb/uas.h>
17 19
18#include <scsi/scsi.h> 20#include <scsi/scsi.h>
19#include <scsi/scsi_dbg.h> 21#include <scsi/scsi_dbg.h>
@@ -22,49 +24,6 @@
22#include <scsi/scsi_host.h> 24#include <scsi/scsi_host.h>
23#include <scsi/scsi_tcq.h> 25#include <scsi/scsi_tcq.h>
24 26
25/* Common header for all IUs */
26struct iu {
27 __u8 iu_id;
28 __u8 rsvd1;
29 __be16 tag;
30};
31
32enum {
33 IU_ID_COMMAND = 0x01,
34 IU_ID_STATUS = 0x03,
35 IU_ID_RESPONSE = 0x04,
36 IU_ID_TASK_MGMT = 0x05,
37 IU_ID_READ_READY = 0x06,
38 IU_ID_WRITE_READY = 0x07,
39};
40
41struct command_iu {
42 __u8 iu_id;
43 __u8 rsvd1;
44 __be16 tag;
45 __u8 prio_attr;
46 __u8 rsvd5;
47 __u8 len;
48 __u8 rsvd7;
49 struct scsi_lun lun;
50 __u8 cdb[16]; /* XXX: Overflow-checking tools may misunderstand */
51};
52
53/*
54 * Also used for the Read Ready and Write Ready IUs since they have the
55 * same first four bytes
56 */
57struct sense_iu {
58 __u8 iu_id;
59 __u8 rsvd1;
60 __be16 tag;
61 __be16 status_qual;
62 __u8 status;
63 __u8 rsvd7[7];
64 __be16 len;
65 __u8 sense[SCSI_SENSE_BUFFERSIZE];
66};
67
68/* 27/*
69 * The r00-r01c specs define this version of the SENSE IU data structure. 28 * The r00-r01c specs define this version of the SENSE IU data structure.
70 * It's still in use by several different firmware releases. 29 * It's still in use by several different firmware releases.
@@ -79,18 +38,6 @@ struct sense_iu_old {
79 __u8 sense[SCSI_SENSE_BUFFERSIZE]; 38 __u8 sense[SCSI_SENSE_BUFFERSIZE];
80}; 39};
81 40
82enum {
83 CMD_PIPE_ID = 1,
84 STATUS_PIPE_ID = 2,
85 DATA_IN_PIPE_ID = 3,
86 DATA_OUT_PIPE_ID = 4,
87
88 UAS_SIMPLE_TAG = 0,
89 UAS_HEAD_TAG = 1,
90 UAS_ORDERED_TAG = 2,
91 UAS_ACA = 4,
92};
93
94struct uas_dev_info { 41struct uas_dev_info {
95 struct usb_interface *intf; 42 struct usb_interface *intf;
96 struct usb_device *udev; 43 struct usb_device *udev;
@@ -98,6 +45,8 @@ struct uas_dev_info {
98 unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe; 45 unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe;
99 unsigned use_streams:1; 46 unsigned use_streams:1;
100 unsigned uas_sense_old:1; 47 unsigned uas_sense_old:1;
48 struct scsi_cmnd *cmnd;
49 struct urb *status_urb; /* used only if stream support is available */
101}; 50};
102 51
103enum { 52enum {
@@ -109,6 +58,9 @@ enum {
109 SUBMIT_DATA_OUT_URB = (1 << 5), 58 SUBMIT_DATA_OUT_URB = (1 << 5),
110 ALLOC_CMD_URB = (1 << 6), 59 ALLOC_CMD_URB = (1 << 6),
111 SUBMIT_CMD_URB = (1 << 7), 60 SUBMIT_CMD_URB = (1 << 7),
61 COMPLETED_DATA_IN = (1 << 8),
62 COMPLETED_DATA_OUT = (1 << 9),
63 DATA_COMPLETES_CMD = (1 << 10),
112}; 64};
113 65
114/* Overrides scsi_pointer */ 66/* Overrides scsi_pointer */
@@ -116,6 +68,7 @@ struct uas_cmd_info {
116 unsigned int state; 68 unsigned int state;
117 unsigned int stream; 69 unsigned int stream;
118 struct urb *cmd_urb; 70 struct urb *cmd_urb;
71 /* status_urb is used only if stream support isn't available */
119 struct urb *status_urb; 72 struct urb *status_urb;
120 struct urb *data_in_urb; 73 struct urb *data_in_urb;
121 struct urb *data_out_urb; 74 struct urb *data_out_urb;
@@ -125,33 +78,43 @@ struct uas_cmd_info {
125/* I hate forward declarations, but I actually have a loop */ 78/* I hate forward declarations, but I actually have a loop */
126static int uas_submit_urbs(struct scsi_cmnd *cmnd, 79static int uas_submit_urbs(struct scsi_cmnd *cmnd,
127 struct uas_dev_info *devinfo, gfp_t gfp); 80 struct uas_dev_info *devinfo, gfp_t gfp);
81static void uas_do_work(struct work_struct *work);
128 82
83static DECLARE_WORK(uas_work, uas_do_work);
129static DEFINE_SPINLOCK(uas_work_lock); 84static DEFINE_SPINLOCK(uas_work_lock);
130static LIST_HEAD(uas_work_list); 85static LIST_HEAD(uas_work_list);
131 86
132static void uas_do_work(struct work_struct *work) 87static void uas_do_work(struct work_struct *work)
133{ 88{
134 struct uas_cmd_info *cmdinfo; 89 struct uas_cmd_info *cmdinfo;
90 struct uas_cmd_info *temp;
135 struct list_head list; 91 struct list_head list;
92 int err;
136 93
137 spin_lock_irq(&uas_work_lock); 94 spin_lock_irq(&uas_work_lock);
138 list_replace_init(&uas_work_list, &list); 95 list_replace_init(&uas_work_list, &list);
139 spin_unlock_irq(&uas_work_lock); 96 spin_unlock_irq(&uas_work_lock);
140 97
141 list_for_each_entry(cmdinfo, &list, list) { 98 list_for_each_entry_safe(cmdinfo, temp, &list, list) {
142 struct scsi_pointer *scp = (void *)cmdinfo; 99 struct scsi_pointer *scp = (void *)cmdinfo;
143 struct scsi_cmnd *cmnd = container_of(scp, 100 struct scsi_cmnd *cmnd = container_of(scp,
144 struct scsi_cmnd, SCp); 101 struct scsi_cmnd, SCp);
145 uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_NOIO); 102 err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_NOIO);
103 if (err) {
104 list_del(&cmdinfo->list);
105 spin_lock_irq(&uas_work_lock);
106 list_add_tail(&cmdinfo->list, &uas_work_list);
107 spin_unlock_irq(&uas_work_lock);
108 schedule_work(&uas_work);
109 }
146 } 110 }
147} 111}
148 112
149static DECLARE_WORK(uas_work, uas_do_work);
150
151static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd) 113static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd)
152{ 114{
153 struct sense_iu *sense_iu = urb->transfer_buffer; 115 struct sense_iu *sense_iu = urb->transfer_buffer;
154 struct scsi_device *sdev = cmnd->device; 116 struct scsi_device *sdev = cmnd->device;
117 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
155 118
156 if (urb->actual_length > 16) { 119 if (urb->actual_length > 16) {
157 unsigned len = be16_to_cpup(&sense_iu->len); 120 unsigned len = be16_to_cpup(&sense_iu->len);
@@ -169,16 +132,15 @@ static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd)
169 } 132 }
170 133
171 cmnd->result = sense_iu->status; 134 cmnd->result = sense_iu->status;
172 if (sdev->current_cmnd) 135 if (!(cmdinfo->state & DATA_COMPLETES_CMD))
173 sdev->current_cmnd = NULL; 136 cmnd->scsi_done(cmnd);
174 cmnd->scsi_done(cmnd);
175 usb_free_urb(urb);
176} 137}
177 138
178static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd) 139static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd)
179{ 140{
180 struct sense_iu_old *sense_iu = urb->transfer_buffer; 141 struct sense_iu_old *sense_iu = urb->transfer_buffer;
181 struct scsi_device *sdev = cmnd->device; 142 struct scsi_device *sdev = cmnd->device;
143 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
182 144
183 if (urb->actual_length > 8) { 145 if (urb->actual_length > 8) {
184 unsigned len = be16_to_cpup(&sense_iu->len) - 2; 146 unsigned len = be16_to_cpup(&sense_iu->len) - 2;
@@ -196,10 +158,8 @@ static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd)
196 } 158 }
197 159
198 cmnd->result = sense_iu->status; 160 cmnd->result = sense_iu->status;
199 if (sdev->current_cmnd) 161 if (!(cmdinfo->state & DATA_COMPLETES_CMD))
200 sdev->current_cmnd = NULL; 162 cmnd->scsi_done(cmnd);
201 cmnd->scsi_done(cmnd);
202 usb_free_urb(urb);
203} 163}
204 164
205static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd, 165static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd,
@@ -208,7 +168,7 @@ static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd,
208 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; 168 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
209 int err; 169 int err;
210 170
211 cmdinfo->state = direction | SUBMIT_STATUS_URB; 171 cmdinfo->state = direction;
212 err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_ATOMIC); 172 err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_ATOMIC);
213 if (err) { 173 if (err) {
214 spin_lock(&uas_work_lock); 174 spin_lock(&uas_work_lock);
@@ -221,27 +181,61 @@ static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd,
221static void uas_stat_cmplt(struct urb *urb) 181static void uas_stat_cmplt(struct urb *urb)
222{ 182{
223 struct iu *iu = urb->transfer_buffer; 183 struct iu *iu = urb->transfer_buffer;
224 struct scsi_device *sdev = urb->context; 184 struct Scsi_Host *shost = urb->context;
225 struct uas_dev_info *devinfo = sdev->hostdata; 185 struct uas_dev_info *devinfo = (void *)shost->hostdata[0];
226 struct scsi_cmnd *cmnd; 186 struct scsi_cmnd *cmnd;
187 struct uas_cmd_info *cmdinfo;
227 u16 tag; 188 u16 tag;
189 int ret;
228 190
229 if (urb->status) { 191 if (urb->status) {
230 dev_err(&urb->dev->dev, "URB BAD STATUS %d\n", urb->status); 192 dev_err(&urb->dev->dev, "URB BAD STATUS %d\n", urb->status);
231 usb_free_urb(urb); 193 if (devinfo->use_streams)
194 usb_free_urb(urb);
232 return; 195 return;
233 } 196 }
234 197
235 tag = be16_to_cpup(&iu->tag) - 1; 198 tag = be16_to_cpup(&iu->tag) - 1;
236 if (sdev->current_cmnd) 199 if (tag == 0)
237 cmnd = sdev->current_cmnd; 200 cmnd = devinfo->cmnd;
238 else 201 else
239 cmnd = scsi_find_tag(sdev, tag); 202 cmnd = scsi_host_find_tag(shost, tag - 1);
240 if (!cmnd) 203 if (!cmnd) {
204 if (devinfo->use_streams) {
205 usb_free_urb(urb);
206 return;
207 }
208 ret = usb_submit_urb(urb, GFP_ATOMIC);
209 if (ret)
210 dev_err(&urb->dev->dev, "failed submit status urb\n");
241 return; 211 return;
212 }
213 cmdinfo = (void *)&cmnd->SCp;
242 214
243 switch (iu->iu_id) { 215 switch (iu->iu_id) {
244 case IU_ID_STATUS: 216 case IU_ID_STATUS:
217 if (devinfo->cmnd == cmnd)
218 devinfo->cmnd = NULL;
219
220 if (!(cmdinfo->state & COMPLETED_DATA_IN) &&
221 cmdinfo->data_in_urb) {
222 if (devinfo->use_streams) {
223 cmdinfo->state |= DATA_COMPLETES_CMD;
224 usb_unlink_urb(cmdinfo->data_in_urb);
225 } else {
226 usb_free_urb(cmdinfo->data_in_urb);
227 }
228 }
229 if (!(cmdinfo->state & COMPLETED_DATA_OUT) &&
230 cmdinfo->data_out_urb) {
231 if (devinfo->use_streams) {
232 cmdinfo->state |= DATA_COMPLETES_CMD;
233 usb_unlink_urb(cmdinfo->data_in_urb);
234 } else {
235 usb_free_urb(cmdinfo->data_out_urb);
236 }
237 }
238
245 if (urb->actual_length < 16) 239 if (urb->actual_length < 16)
246 devinfo->uas_sense_old = 1; 240 devinfo->uas_sense_old = 1;
247 if (devinfo->uas_sense_old) 241 if (devinfo->uas_sense_old)
@@ -259,29 +253,70 @@ static void uas_stat_cmplt(struct urb *urb)
259 scmd_printk(KERN_ERR, cmnd, 253 scmd_printk(KERN_ERR, cmnd,
260 "Bogus IU (%d) received on status pipe\n", iu->iu_id); 254 "Bogus IU (%d) received on status pipe\n", iu->iu_id);
261 } 255 }
256
257 if (devinfo->use_streams) {
258 usb_free_urb(urb);
259 return;
260 }
261
262 ret = usb_submit_urb(urb, GFP_ATOMIC);
263 if (ret)
264 dev_err(&urb->dev->dev, "failed submit status urb\n");
262} 265}
263 266
264static void uas_data_cmplt(struct urb *urb) 267static void uas_data_out_cmplt(struct urb *urb)
265{ 268{
266 struct scsi_data_buffer *sdb = urb->context; 269 struct scsi_cmnd *cmnd = urb->context;
270 struct scsi_data_buffer *sdb = scsi_out(cmnd);
271 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
272
273 cmdinfo->state |= COMPLETED_DATA_OUT;
274
267 sdb->resid = sdb->length - urb->actual_length; 275 sdb->resid = sdb->length - urb->actual_length;
268 usb_free_urb(urb); 276 usb_free_urb(urb);
277
278 if (cmdinfo->state & DATA_COMPLETES_CMD)
279 cmnd->scsi_done(cmnd);
280}
281
282static void uas_data_in_cmplt(struct urb *urb)
283{
284 struct scsi_cmnd *cmnd = urb->context;
285 struct scsi_data_buffer *sdb = scsi_in(cmnd);
286 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
287
288 cmdinfo->state |= COMPLETED_DATA_IN;
289
290 sdb->resid = sdb->length - urb->actual_length;
291 usb_free_urb(urb);
292
293 if (cmdinfo->state & DATA_COMPLETES_CMD)
294 cmnd->scsi_done(cmnd);
269} 295}
270 296
271static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp, 297static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp,
272 unsigned int pipe, u16 stream_id, 298 unsigned int pipe, struct scsi_cmnd *cmnd,
273 struct scsi_data_buffer *sdb, 299 enum dma_data_direction dir)
274 enum dma_data_direction dir)
275{ 300{
301 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
276 struct usb_device *udev = devinfo->udev; 302 struct usb_device *udev = devinfo->udev;
277 struct urb *urb = usb_alloc_urb(0, gfp); 303 struct urb *urb = usb_alloc_urb(0, gfp);
304 struct scsi_data_buffer *sdb;
305 usb_complete_t complete_fn;
306 u16 stream_id = cmdinfo->stream;
278 307
279 if (!urb) 308 if (!urb)
280 goto out; 309 goto out;
281 usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length, uas_data_cmplt, 310 if (dir == DMA_FROM_DEVICE) {
282 sdb); 311 sdb = scsi_in(cmnd);
283 if (devinfo->use_streams) 312 complete_fn = uas_data_in_cmplt;
284 urb->stream_id = stream_id; 313 } else {
314 sdb = scsi_out(cmnd);
315 complete_fn = uas_data_out_cmplt;
316 }
317 usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length,
318 complete_fn, cmnd);
319 urb->stream_id = stream_id;
285 urb->num_sgs = udev->bus->sg_tablesize ? sdb->table.nents : 0; 320 urb->num_sgs = udev->bus->sg_tablesize ? sdb->table.nents : 0;
286 urb->sg = sdb->table.sgl; 321 urb->sg = sdb->table.sgl;
287 out: 322 out:
@@ -289,7 +324,7 @@ static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp,
289} 324}
290 325
291static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp, 326static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp,
292 struct scsi_cmnd *cmnd, u16 stream_id) 327 struct Scsi_Host *shost, u16 stream_id)
293{ 328{
294 struct usb_device *udev = devinfo->udev; 329 struct usb_device *udev = devinfo->udev;
295 struct urb *urb = usb_alloc_urb(0, gfp); 330 struct urb *urb = usb_alloc_urb(0, gfp);
@@ -303,7 +338,7 @@ static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp,
303 goto free; 338 goto free;
304 339
305 usb_fill_bulk_urb(urb, udev, devinfo->status_pipe, iu, sizeof(*iu), 340 usb_fill_bulk_urb(urb, udev, devinfo->status_pipe, iu, sizeof(*iu),
306 uas_stat_cmplt, cmnd->device); 341 uas_stat_cmplt, shost);
307 urb->stream_id = stream_id; 342 urb->stream_id = stream_id;
308 urb->transfer_flags |= URB_FREE_BUFFER; 343 urb->transfer_flags |= URB_FREE_BUFFER;
309 out: 344 out:
@@ -334,7 +369,10 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp,
334 goto free; 369 goto free;
335 370
336 iu->iu_id = IU_ID_COMMAND; 371 iu->iu_id = IU_ID_COMMAND;
337 iu->tag = cpu_to_be16(stream_id); 372 if (blk_rq_tagged(cmnd->request))
373 iu->tag = cpu_to_be16(cmnd->request->tag + 2);
374 else
375 iu->tag = cpu_to_be16(1);
338 iu->prio_attr = UAS_SIMPLE_TAG; 376 iu->prio_attr = UAS_SIMPLE_TAG;
339 iu->len = len; 377 iu->len = len;
340 int_to_scsilun(sdev->lun, &iu->lun); 378 int_to_scsilun(sdev->lun, &iu->lun);
@@ -362,8 +400,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
362 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; 400 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
363 401
364 if (cmdinfo->state & ALLOC_STATUS_URB) { 402 if (cmdinfo->state & ALLOC_STATUS_URB) {
365 cmdinfo->status_urb = uas_alloc_sense_urb(devinfo, gfp, cmnd, 403 cmdinfo->status_urb = uas_alloc_sense_urb(devinfo, gfp,
366 cmdinfo->stream); 404 cmnd->device->host, cmdinfo->stream);
367 if (!cmdinfo->status_urb) 405 if (!cmdinfo->status_urb)
368 return SCSI_MLQUEUE_DEVICE_BUSY; 406 return SCSI_MLQUEUE_DEVICE_BUSY;
369 cmdinfo->state &= ~ALLOC_STATUS_URB; 407 cmdinfo->state &= ~ALLOC_STATUS_URB;
@@ -380,8 +418,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
380 418
381 if (cmdinfo->state & ALLOC_DATA_IN_URB) { 419 if (cmdinfo->state & ALLOC_DATA_IN_URB) {
382 cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, gfp, 420 cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, gfp,
383 devinfo->data_in_pipe, cmdinfo->stream, 421 devinfo->data_in_pipe, cmnd,
384 scsi_in(cmnd), DMA_FROM_DEVICE); 422 DMA_FROM_DEVICE);
385 if (!cmdinfo->data_in_urb) 423 if (!cmdinfo->data_in_urb)
386 return SCSI_MLQUEUE_DEVICE_BUSY; 424 return SCSI_MLQUEUE_DEVICE_BUSY;
387 cmdinfo->state &= ~ALLOC_DATA_IN_URB; 425 cmdinfo->state &= ~ALLOC_DATA_IN_URB;
@@ -398,8 +436,8 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd,
398 436
399 if (cmdinfo->state & ALLOC_DATA_OUT_URB) { 437 if (cmdinfo->state & ALLOC_DATA_OUT_URB) {
400 cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, gfp, 438 cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, gfp,
401 devinfo->data_out_pipe, cmdinfo->stream, 439 devinfo->data_out_pipe, cmnd,
402 scsi_out(cmnd), DMA_TO_DEVICE); 440 DMA_TO_DEVICE);
403 if (!cmdinfo->data_out_urb) 441 if (!cmdinfo->data_out_urb)
404 return SCSI_MLQUEUE_DEVICE_BUSY; 442 return SCSI_MLQUEUE_DEVICE_BUSY;
405 cmdinfo->state &= ~ALLOC_DATA_OUT_URB; 443 cmdinfo->state &= ~ALLOC_DATA_OUT_URB;
@@ -444,13 +482,13 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
444 482
445 BUILD_BUG_ON(sizeof(struct uas_cmd_info) > sizeof(struct scsi_pointer)); 483 BUILD_BUG_ON(sizeof(struct uas_cmd_info) > sizeof(struct scsi_pointer));
446 484
447 if (!cmdinfo->status_urb && sdev->current_cmnd) 485 if (devinfo->cmnd)
448 return SCSI_MLQUEUE_DEVICE_BUSY; 486 return SCSI_MLQUEUE_DEVICE_BUSY;
449 487
450 if (blk_rq_tagged(cmnd->request)) { 488 if (blk_rq_tagged(cmnd->request)) {
451 cmdinfo->stream = cmnd->request->tag + 1; 489 cmdinfo->stream = cmnd->request->tag + 2;
452 } else { 490 } else {
453 sdev->current_cmnd = cmnd; 491 devinfo->cmnd = cmnd;
454 cmdinfo->stream = 1; 492 cmdinfo->stream = 1;
455 } 493 }
456 494
@@ -472,7 +510,8 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
472 } 510 }
473 511
474 if (!devinfo->use_streams) { 512 if (!devinfo->use_streams) {
475 cmdinfo->state &= ~(SUBMIT_DATA_IN_URB | SUBMIT_DATA_OUT_URB); 513 cmdinfo->state &= ~(SUBMIT_DATA_IN_URB | SUBMIT_DATA_OUT_URB |
514 ALLOC_STATUS_URB | SUBMIT_STATUS_URB);
476 cmdinfo->stream = 0; 515 cmdinfo->stream = 0;
477 } 516 }
478 517
@@ -551,7 +590,7 @@ static int uas_slave_configure(struct scsi_device *sdev)
551{ 590{
552 struct uas_dev_info *devinfo = sdev->hostdata; 591 struct uas_dev_info *devinfo = sdev->hostdata;
553 scsi_set_tag_type(sdev, MSG_ORDERED_TAG); 592 scsi_set_tag_type(sdev, MSG_ORDERED_TAG);
554 scsi_activate_tcq(sdev, devinfo->qdepth - 1); 593 scsi_activate_tcq(sdev, devinfo->qdepth - 2);
555 return 0; 594 return 0;
556} 595}
557 596
@@ -589,22 +628,34 @@ static int uas_is_interface(struct usb_host_interface *intf)
589 intf->desc.bInterfaceProtocol == USB_PR_UAS); 628 intf->desc.bInterfaceProtocol == USB_PR_UAS);
590} 629}
591 630
631static int uas_isnt_supported(struct usb_device *udev)
632{
633 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
634
635 dev_warn(&udev->dev, "The driver for the USB controller %s does not "
636 "support scatter-gather which is\n",
637 hcd->driver->description);
638 dev_warn(&udev->dev, "required by the UAS driver. Please try an"
639 "alternative USB controller if you wish to use UAS.\n");
640 return -ENODEV;
641}
642
592static int uas_switch_interface(struct usb_device *udev, 643static int uas_switch_interface(struct usb_device *udev,
593 struct usb_interface *intf) 644 struct usb_interface *intf)
594{ 645{
595 int i; 646 int i;
596 647 int sg_supported = udev->bus->sg_tablesize != 0;
597 if (uas_is_interface(intf->cur_altsetting))
598 return 0;
599 648
600 for (i = 0; i < intf->num_altsetting; i++) { 649 for (i = 0; i < intf->num_altsetting; i++) {
601 struct usb_host_interface *alt = &intf->altsetting[i]; 650 struct usb_host_interface *alt = &intf->altsetting[i];
602 if (alt == intf->cur_altsetting) 651
603 continue; 652 if (uas_is_interface(alt)) {
604 if (uas_is_interface(alt)) 653 if (!sg_supported)
654 return uas_isnt_supported(udev);
605 return usb_set_interface(udev, 655 return usb_set_interface(udev,
606 alt->desc.bInterfaceNumber, 656 alt->desc.bInterfaceNumber,
607 alt->desc.bAlternateSetting); 657 alt->desc.bAlternateSetting);
658 }
608 } 659 }
609 660
610 return -ENODEV; 661 return -ENODEV;
@@ -619,6 +670,7 @@ static void uas_configure_endpoints(struct uas_dev_info *devinfo)
619 unsigned i, n_endpoints = intf->cur_altsetting->desc.bNumEndpoints; 670 unsigned i, n_endpoints = intf->cur_altsetting->desc.bNumEndpoints;
620 671
621 devinfo->uas_sense_old = 0; 672 devinfo->uas_sense_old = 0;
673 devinfo->cmnd = NULL;
622 674
623 for (i = 0; i < n_endpoints; i++) { 675 for (i = 0; i < n_endpoints; i++) {
624 unsigned char *extra = endpoint[i].extra; 676 unsigned char *extra = endpoint[i].extra;
@@ -670,6 +722,40 @@ static void uas_configure_endpoints(struct uas_dev_info *devinfo)
670 } 722 }
671} 723}
672 724
725static int uas_alloc_status_urb(struct uas_dev_info *devinfo,
726 struct Scsi_Host *shost)
727{
728 if (devinfo->use_streams) {
729 devinfo->status_urb = NULL;
730 return 0;
731 }
732
733 devinfo->status_urb = uas_alloc_sense_urb(devinfo, GFP_KERNEL,
734 shost, 0);
735 if (!devinfo->status_urb)
736 goto err_s_urb;
737
738 if (usb_submit_urb(devinfo->status_urb, GFP_KERNEL))
739 goto err_submit_urb;
740
741 return 0;
742err_submit_urb:
743 usb_free_urb(devinfo->status_urb);
744err_s_urb:
745 return -ENOMEM;
746}
747
748static void uas_free_streams(struct uas_dev_info *devinfo)
749{
750 struct usb_device *udev = devinfo->udev;
751 struct usb_host_endpoint *eps[3];
752
753 eps[0] = usb_pipe_endpoint(udev, devinfo->status_pipe);
754 eps[1] = usb_pipe_endpoint(udev, devinfo->data_in_pipe);
755 eps[2] = usb_pipe_endpoint(udev, devinfo->data_out_pipe);
756 usb_free_streams(devinfo->intf, eps, 3, GFP_KERNEL);
757}
758
673/* 759/*
674 * XXX: What I'd like to do here is register a SCSI host for each USB host in 760 * XXX: What I'd like to do here is register a SCSI host for each USB host in
675 * the system. Follow usb-storage's design of registering a SCSI host for 761 * the system. Follow usb-storage's design of registering a SCSI host for
@@ -699,18 +785,33 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id)
699 shost->max_id = 1; 785 shost->max_id = 1;
700 shost->sg_tablesize = udev->bus->sg_tablesize; 786 shost->sg_tablesize = udev->bus->sg_tablesize;
701 787
702 result = scsi_add_host(shost, &intf->dev); 788 devinfo->intf = intf;
789 devinfo->udev = udev;
790 uas_configure_endpoints(devinfo);
791
792 result = scsi_init_shared_tag_map(shost, devinfo->qdepth - 2);
703 if (result) 793 if (result)
704 goto free; 794 goto free;
795
796 result = scsi_add_host(shost, &intf->dev);
797 if (result)
798 goto deconfig_eps;
799
705 shost->hostdata[0] = (unsigned long)devinfo; 800 shost->hostdata[0] = (unsigned long)devinfo;
706 801
707 devinfo->intf = intf; 802 result = uas_alloc_status_urb(devinfo, shost);
708 devinfo->udev = udev; 803 if (result)
709 uas_configure_endpoints(devinfo); 804 goto err_alloc_status;
710 805
711 scsi_scan_host(shost); 806 scsi_scan_host(shost);
712 usb_set_intfdata(intf, shost); 807 usb_set_intfdata(intf, shost);
713 return result; 808 return result;
809
810err_alloc_status:
811 scsi_remove_host(shost);
812 shost = NULL;
813deconfig_eps:
814 uas_free_streams(devinfo);
714 free: 815 free:
715 kfree(devinfo); 816 kfree(devinfo);
716 if (shost) 817 if (shost)
@@ -732,18 +833,13 @@ static int uas_post_reset(struct usb_interface *intf)
732 833
733static void uas_disconnect(struct usb_interface *intf) 834static void uas_disconnect(struct usb_interface *intf)
734{ 835{
735 struct usb_device *udev = interface_to_usbdev(intf);
736 struct usb_host_endpoint *eps[3];
737 struct Scsi_Host *shost = usb_get_intfdata(intf); 836 struct Scsi_Host *shost = usb_get_intfdata(intf);
738 struct uas_dev_info *devinfo = (void *)shost->hostdata[0]; 837 struct uas_dev_info *devinfo = (void *)shost->hostdata[0];
739 838
740 scsi_remove_host(shost); 839 scsi_remove_host(shost);
741 840 usb_kill_urb(devinfo->status_urb);
742 eps[0] = usb_pipe_endpoint(udev, devinfo->status_pipe); 841 usb_free_urb(devinfo->status_urb);
743 eps[1] = usb_pipe_endpoint(udev, devinfo->data_in_pipe); 842 uas_free_streams(devinfo);
744 eps[2] = usb_pipe_endpoint(udev, devinfo->data_out_pipe);
745 usb_free_streams(intf, eps, 3, GFP_KERNEL);
746
747 kfree(devinfo); 843 kfree(devinfo);
748} 844}
749 845
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 3dd7da9fd504..c18538e4a6db 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -125,6 +125,9 @@ static struct us_unusual_dev us_unusual_dev_list[] = {
125 { } /* Terminating entry */ 125 { } /* Terminating entry */
126}; 126};
127 127
128static struct us_unusual_dev for_dynamic_ids =
129 USUAL_DEV(USB_SC_SCSI, USB_PR_BULK, 0);
130
128#undef UNUSUAL_DEV 131#undef UNUSUAL_DEV
129#undef COMPLIANT_DEV 132#undef COMPLIANT_DEV
130#undef USUAL_DEV 133#undef USUAL_DEV
@@ -788,15 +791,19 @@ static void quiesce_and_remove_host(struct us_data *us)
788 struct Scsi_Host *host = us_to_host(us); 791 struct Scsi_Host *host = us_to_host(us);
789 792
790 /* If the device is really gone, cut short reset delays */ 793 /* If the device is really gone, cut short reset delays */
791 if (us->pusb_dev->state == USB_STATE_NOTATTACHED) 794 if (us->pusb_dev->state == USB_STATE_NOTATTACHED) {
792 set_bit(US_FLIDX_DISCONNECTING, &us->dflags); 795 set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
796 wake_up(&us->delay_wait);
797 }
793 798
794 /* Prevent SCSI-scanning (if it hasn't started yet) 799 /* Prevent SCSI scanning (if it hasn't started yet)
795 * and wait for the SCSI-scanning thread to stop. 800 * or wait for the SCSI-scanning routine to stop.
796 */ 801 */
797 set_bit(US_FLIDX_DONT_SCAN, &us->dflags); 802 cancel_delayed_work_sync(&us->scan_dwork);
798 wake_up(&us->delay_wait); 803
799 wait_for_completion(&us->scanning_done); 804 /* Balance autopm calls if scanning was cancelled */
805 if (test_bit(US_FLIDX_SCAN_PENDING, &us->dflags))
806 usb_autopm_put_interface_no_suspend(us->pusb_intf);
800 807
801 /* Removing the host will perform an orderly shutdown: caches 808 /* Removing the host will perform an orderly shutdown: caches
802 * synchronized, disks spun down, etc. 809 * synchronized, disks spun down, etc.
@@ -823,53 +830,28 @@ static void release_everything(struct us_data *us)
823 scsi_host_put(us_to_host(us)); 830 scsi_host_put(us_to_host(us));
824} 831}
825 832
826/* Thread to carry out delayed SCSI-device scanning */ 833/* Delayed-work routine to carry out SCSI-device scanning */
827static int usb_stor_scan_thread(void * __us) 834static void usb_stor_scan_dwork(struct work_struct *work)
828{ 835{
829 struct us_data *us = (struct us_data *)__us; 836 struct us_data *us = container_of(work, struct us_data,
837 scan_dwork.work);
830 struct device *dev = &us->pusb_intf->dev; 838 struct device *dev = &us->pusb_intf->dev;
831 839
832 dev_dbg(dev, "device found\n"); 840 dev_dbg(dev, "starting scan\n");
833
834 set_freezable();
835 841
836 /* 842 /* For bulk-only devices, determine the max LUN value */
837 * Wait for the timeout to expire or for a disconnect 843 if (us->protocol == USB_PR_BULK && !(us->fflags & US_FL_SINGLE_LUN)) {
838 * 844 mutex_lock(&us->dev_mutex);
839 * We can't freeze in this thread or we risk causing khubd to 845 us->max_lun = usb_stor_Bulk_max_lun(us);
840 * fail to freeze, but we can't be non-freezable either. Nor can 846 mutex_unlock(&us->dev_mutex);
841 * khubd freeze while waiting for scanning to complete as it may
842 * hold the device lock, causing a hang when suspending devices.
843 * So instead of using wait_event_freezable(), explicitly test
844 * for (DONT_SCAN || freezing) in interruptible wait and proceed
845 * if any of DONT_SCAN, freezing or timeout has happened.
846 */
847 if (delay_use > 0) {
848 dev_dbg(dev, "waiting for device to settle "
849 "before scanning\n");
850 wait_event_interruptible_timeout(us->delay_wait,
851 test_bit(US_FLIDX_DONT_SCAN, &us->dflags) ||
852 freezing(current), delay_use * HZ);
853 } 847 }
848 scsi_scan_host(us_to_host(us));
849 dev_dbg(dev, "scan complete\n");
854 850
855 /* If the device is still connected, perform the scanning */ 851 /* Should we unbind if no devices were detected? */
856 if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags)) {
857
858 /* For bulk-only devices, determine the max LUN value */
859 if (us->protocol == USB_PR_BULK &&
860 !(us->fflags & US_FL_SINGLE_LUN)) {
861 mutex_lock(&us->dev_mutex);
862 us->max_lun = usb_stor_Bulk_max_lun(us);
863 mutex_unlock(&us->dev_mutex);
864 }
865 scsi_scan_host(us_to_host(us));
866 dev_dbg(dev, "scan complete\n");
867
868 /* Should we unbind if no devices were detected? */
869 }
870 852
871 usb_autopm_put_interface(us->pusb_intf); 853 usb_autopm_put_interface(us->pusb_intf);
872 complete_and_exit(&us->scanning_done, 0); 854 clear_bit(US_FLIDX_SCAN_PENDING, &us->dflags);
873} 855}
874 856
875static unsigned int usb_stor_sg_tablesize(struct usb_interface *intf) 857static unsigned int usb_stor_sg_tablesize(struct usb_interface *intf)
@@ -916,7 +898,7 @@ int usb_stor_probe1(struct us_data **pus,
916 init_completion(&us->cmnd_ready); 898 init_completion(&us->cmnd_ready);
917 init_completion(&(us->notify)); 899 init_completion(&(us->notify));
918 init_waitqueue_head(&us->delay_wait); 900 init_waitqueue_head(&us->delay_wait);
919 init_completion(&us->scanning_done); 901 INIT_DELAYED_WORK(&us->scan_dwork, usb_stor_scan_dwork);
920 902
921 /* Associate the us_data structure with the USB device */ 903 /* Associate the us_data structure with the USB device */
922 result = associate_dev(us, intf); 904 result = associate_dev(us, intf);
@@ -947,7 +929,6 @@ EXPORT_SYMBOL_GPL(usb_stor_probe1);
947/* Second part of general USB mass-storage probing */ 929/* Second part of general USB mass-storage probing */
948int usb_stor_probe2(struct us_data *us) 930int usb_stor_probe2(struct us_data *us)
949{ 931{
950 struct task_struct *th;
951 int result; 932 int result;
952 struct device *dev = &us->pusb_intf->dev; 933 struct device *dev = &us->pusb_intf->dev;
953 934
@@ -988,20 +969,14 @@ int usb_stor_probe2(struct us_data *us)
988 goto BadDevice; 969 goto BadDevice;
989 } 970 }
990 971
991 /* Start up the thread for delayed SCSI-device scanning */ 972 /* Submit the delayed_work for SCSI-device scanning */
992 th = kthread_create(usb_stor_scan_thread, us, "usb-stor-scan");
993 if (IS_ERR(th)) {
994 dev_warn(dev,
995 "Unable to start the device-scanning thread\n");
996 complete(&us->scanning_done);
997 quiesce_and_remove_host(us);
998 result = PTR_ERR(th);
999 goto BadDevice;
1000 }
1001
1002 usb_autopm_get_interface_no_resume(us->pusb_intf); 973 usb_autopm_get_interface_no_resume(us->pusb_intf);
1003 wake_up_process(th); 974 set_bit(US_FLIDX_SCAN_PENDING, &us->dflags);
1004 975
976 if (delay_use > 0)
977 dev_dbg(dev, "waiting for device to settle before scanning\n");
978 queue_delayed_work(system_freezable_wq, &us->scan_dwork,
979 delay_use * HZ);
1005 return 0; 980 return 0;
1006 981
1007 /* We come here if there are any problems */ 982 /* We come here if there are any problems */
@@ -1027,8 +1002,10 @@ EXPORT_SYMBOL_GPL(usb_stor_disconnect);
1027static int storage_probe(struct usb_interface *intf, 1002static int storage_probe(struct usb_interface *intf,
1028 const struct usb_device_id *id) 1003 const struct usb_device_id *id)
1029{ 1004{
1005 struct us_unusual_dev *unusual_dev;
1030 struct us_data *us; 1006 struct us_data *us;
1031 int result; 1007 int result;
1008 int size;
1032 1009
1033 /* 1010 /*
1034 * If libusual is configured, let it decide whether a standard 1011 * If libusual is configured, let it decide whether a standard
@@ -1047,8 +1024,19 @@ static int storage_probe(struct usb_interface *intf,
1047 * table, so we use the index of the id entry to find the 1024 * table, so we use the index of the id entry to find the
1048 * corresponding unusual_devs entry. 1025 * corresponding unusual_devs entry.
1049 */ 1026 */
1050 result = usb_stor_probe1(&us, intf, id, 1027
1051 (id - usb_storage_usb_ids) + us_unusual_dev_list); 1028 size = ARRAY_SIZE(us_unusual_dev_list);
1029 if (id >= usb_storage_usb_ids && id < usb_storage_usb_ids + size) {
1030 unusual_dev = (id - usb_storage_usb_ids) + us_unusual_dev_list;
1031 } else {
1032 unusual_dev = &for_dynamic_ids;
1033
1034 US_DEBUGP("%s %s 0x%04x 0x%04x\n", "Use Bulk-Only transport",
1035 "with the Transparent SCSI protocol for dynamic id:",
1036 id->idVendor, id->idProduct);
1037 }
1038
1039 result = usb_stor_probe1(&us, intf, id, unusual_dev);
1052 if (result) 1040 if (result)
1053 return result; 1041 return result;
1054 1042
@@ -1074,7 +1062,6 @@ static struct usb_driver usb_storage_driver = {
1074 .id_table = usb_storage_usb_ids, 1062 .id_table = usb_storage_usb_ids,
1075 .supports_autosuspend = 1, 1063 .supports_autosuspend = 1,
1076 .soft_unbind = 1, 1064 .soft_unbind = 1,
1077 .no_dynamic_id = 1,
1078}; 1065};
1079 1066
1080static int __init usb_stor_init(void) 1067static int __init usb_stor_init(void)
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 7b0f2113632e..75f70f04f37b 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -47,6 +47,7 @@
47#include <linux/blkdev.h> 47#include <linux/blkdev.h>
48#include <linux/completion.h> 48#include <linux/completion.h>
49#include <linux/mutex.h> 49#include <linux/mutex.h>
50#include <linux/workqueue.h>
50#include <scsi/scsi_host.h> 51#include <scsi/scsi_host.h>
51 52
52struct us_data; 53struct us_data;
@@ -72,7 +73,7 @@ struct us_unusual_dev {
72#define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */ 73#define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */
73#define US_FLIDX_RESETTING 4 /* device reset in progress */ 74#define US_FLIDX_RESETTING 4 /* device reset in progress */
74#define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */ 75#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_SCAN_PENDING 6 /* scanning not yet done */
76#define US_FLIDX_REDO_READ10 7 /* redo READ(10) command */ 77#define US_FLIDX_REDO_READ10 7 /* redo READ(10) command */
77#define US_FLIDX_READ10_WORKED 8 /* previous READ(10) succeeded */ 78#define US_FLIDX_READ10_WORKED 8 /* previous READ(10) succeeded */
78 79
@@ -147,8 +148,8 @@ struct us_data {
147 /* mutual exclusion and synchronization structures */ 148 /* mutual exclusion and synchronization structures */
148 struct completion cmnd_ready; /* to sleep thread on */ 149 struct completion cmnd_ready; /* to sleep thread on */
149 struct completion notify; /* thread begin/end */ 150 struct completion notify; /* thread begin/end */
150 wait_queue_head_t delay_wait; /* wait during scan, reset */ 151 wait_queue_head_t delay_wait; /* wait during reset */
151 struct completion scanning_done; /* wait for scan thread */ 152 struct delayed_work scan_dwork; /* for async scanning */
152 153
153 /* subdriver information */ 154 /* subdriver information */
154 void *extra; /* Any extra data */ 155 void *extra; /* Any extra data */