aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/Kconfig8
-rw-r--r--drivers/block/pktcdvd.c58
-rw-r--r--drivers/block/ub.c139
-rw-r--r--drivers/block/umem.c2
4 files changed, 141 insertions, 66 deletions
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 139cbba76180..8b1331677407 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -433,12 +433,12 @@ config CDROM_PKTCDVD_BUFFERS
433 This controls the maximum number of active concurrent packets. More 433 This controls the maximum number of active concurrent packets. More
434 concurrent packets can increase write performance, but also require 434 concurrent packets can increase write performance, but also require
435 more memory. Each concurrent packet will require approximately 64Kb 435 more memory. Each concurrent packet will require approximately 64Kb
436 of non-swappable kernel memory, memory which will be allocated at 436 of non-swappable kernel memory, memory which will be allocated when
437 pktsetup time. 437 a disc is opened for writing.
438 438
439config CDROM_PKTCDVD_WCACHE 439config CDROM_PKTCDVD_WCACHE
440 bool "Enable write caching" 440 bool "Enable write caching (EXPERIMENTAL)"
441 depends on CDROM_PKTCDVD 441 depends on CDROM_PKTCDVD && EXPERIMENTAL
442 help 442 help
443 If enabled, write caching will be set for the CD-R/W device. For now 443 If enabled, write caching will be set for the CD-R/W device. For now
444 this option is dangerous unless the CD-RW media is known good, as we 444 this option is dangerous unless the CD-RW media is known good, as we
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 93affeeef7bd..4e7dbcc425ff 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -43,8 +43,6 @@
43 * 43 *
44 *************************************************************************/ 44 *************************************************************************/
45 45
46#define VERSION_CODE "v0.2.0a 2004-07-14 Jens Axboe (axboe@suse.de) and petero2@telia.com"
47
48#include <linux/pktcdvd.h> 46#include <linux/pktcdvd.h>
49#include <linux/config.h> 47#include <linux/config.h>
50#include <linux/module.h> 48#include <linux/module.h>
@@ -131,7 +129,7 @@ static struct bio *pkt_bio_alloc(int nr_iovecs)
131/* 129/*
132 * Allocate a packet_data struct 130 * Allocate a packet_data struct
133 */ 131 */
134static struct packet_data *pkt_alloc_packet_data(void) 132static struct packet_data *pkt_alloc_packet_data(int frames)
135{ 133{
136 int i; 134 int i;
137 struct packet_data *pkt; 135 struct packet_data *pkt;
@@ -140,11 +138,12 @@ static struct packet_data *pkt_alloc_packet_data(void)
140 if (!pkt) 138 if (!pkt)
141 goto no_pkt; 139 goto no_pkt;
142 140
143 pkt->w_bio = pkt_bio_alloc(PACKET_MAX_SIZE); 141 pkt->frames = frames;
142 pkt->w_bio = pkt_bio_alloc(frames);
144 if (!pkt->w_bio) 143 if (!pkt->w_bio)
145 goto no_bio; 144 goto no_bio;
146 145
147 for (i = 0; i < PAGES_PER_PACKET; i++) { 146 for (i = 0; i < frames / FRAMES_PER_PAGE; i++) {
148 pkt->pages[i] = alloc_page(GFP_KERNEL|__GFP_ZERO); 147 pkt->pages[i] = alloc_page(GFP_KERNEL|__GFP_ZERO);
149 if (!pkt->pages[i]) 148 if (!pkt->pages[i])
150 goto no_page; 149 goto no_page;
@@ -152,7 +151,7 @@ static struct packet_data *pkt_alloc_packet_data(void)
152 151
153 spin_lock_init(&pkt->lock); 152 spin_lock_init(&pkt->lock);
154 153
155 for (i = 0; i < PACKET_MAX_SIZE; i++) { 154 for (i = 0; i < frames; i++) {
156 struct bio *bio = pkt_bio_alloc(1); 155 struct bio *bio = pkt_bio_alloc(1);
157 if (!bio) 156 if (!bio)
158 goto no_rd_bio; 157 goto no_rd_bio;
@@ -162,14 +161,14 @@ static struct packet_data *pkt_alloc_packet_data(void)
162 return pkt; 161 return pkt;
163 162
164no_rd_bio: 163no_rd_bio:
165 for (i = 0; i < PACKET_MAX_SIZE; i++) { 164 for (i = 0; i < frames; i++) {
166 struct bio *bio = pkt->r_bios[i]; 165 struct bio *bio = pkt->r_bios[i];
167 if (bio) 166 if (bio)
168 bio_put(bio); 167 bio_put(bio);
169 } 168 }
170 169
171no_page: 170no_page:
172 for (i = 0; i < PAGES_PER_PACKET; i++) 171 for (i = 0; i < frames / FRAMES_PER_PAGE; i++)
173 if (pkt->pages[i]) 172 if (pkt->pages[i])
174 __free_page(pkt->pages[i]); 173 __free_page(pkt->pages[i]);
175 bio_put(pkt->w_bio); 174 bio_put(pkt->w_bio);
@@ -186,12 +185,12 @@ static void pkt_free_packet_data(struct packet_data *pkt)
186{ 185{
187 int i; 186 int i;
188 187
189 for (i = 0; i < PACKET_MAX_SIZE; i++) { 188 for (i = 0; i < pkt->frames; i++) {
190 struct bio *bio = pkt->r_bios[i]; 189 struct bio *bio = pkt->r_bios[i];
191 if (bio) 190 if (bio)
192 bio_put(bio); 191 bio_put(bio);
193 } 192 }
194 for (i = 0; i < PAGES_PER_PACKET; i++) 193 for (i = 0; i < pkt->frames / FRAMES_PER_PAGE; i++)
195 __free_page(pkt->pages[i]); 194 __free_page(pkt->pages[i]);
196 bio_put(pkt->w_bio); 195 bio_put(pkt->w_bio);
197 kfree(pkt); 196 kfree(pkt);
@@ -206,17 +205,17 @@ static void pkt_shrink_pktlist(struct pktcdvd_device *pd)
206 list_for_each_entry_safe(pkt, next, &pd->cdrw.pkt_free_list, list) { 205 list_for_each_entry_safe(pkt, next, &pd->cdrw.pkt_free_list, list) {
207 pkt_free_packet_data(pkt); 206 pkt_free_packet_data(pkt);
208 } 207 }
208 INIT_LIST_HEAD(&pd->cdrw.pkt_free_list);
209} 209}
210 210
211static int pkt_grow_pktlist(struct pktcdvd_device *pd, int nr_packets) 211static int pkt_grow_pktlist(struct pktcdvd_device *pd, int nr_packets)
212{ 212{
213 struct packet_data *pkt; 213 struct packet_data *pkt;
214 214
215 INIT_LIST_HEAD(&pd->cdrw.pkt_free_list); 215 BUG_ON(!list_empty(&pd->cdrw.pkt_free_list));
216 INIT_LIST_HEAD(&pd->cdrw.pkt_active_list); 216
217 spin_lock_init(&pd->cdrw.active_list_lock);
218 while (nr_packets > 0) { 217 while (nr_packets > 0) {
219 pkt = pkt_alloc_packet_data(); 218 pkt = pkt_alloc_packet_data(pd->settings.size >> 2);
220 if (!pkt) { 219 if (!pkt) {
221 pkt_shrink_pktlist(pd); 220 pkt_shrink_pktlist(pd);
222 return 0; 221 return 0;
@@ -951,7 +950,7 @@ try_next_bio:
951 950
952 pd->current_sector = zone + pd->settings.size; 951 pd->current_sector = zone + pd->settings.size;
953 pkt->sector = zone; 952 pkt->sector = zone;
954 pkt->frames = pd->settings.size >> 2; 953 BUG_ON(pkt->frames != pd->settings.size >> 2);
955 pkt->write_size = 0; 954 pkt->write_size = 0;
956 955
957 /* 956 /*
@@ -1639,7 +1638,7 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
1639 pd->settings.size = be32_to_cpu(ti.fixed_packet_size) << 2; 1638 pd->settings.size = be32_to_cpu(ti.fixed_packet_size) << 2;
1640 if (pd->settings.size == 0) { 1639 if (pd->settings.size == 0) {
1641 printk("pktcdvd: detected zero packet size!\n"); 1640 printk("pktcdvd: detected zero packet size!\n");
1642 pd->settings.size = 128; 1641 return -ENXIO;
1643 } 1642 }
1644 if (pd->settings.size > PACKET_MAX_SECTORS) { 1643 if (pd->settings.size > PACKET_MAX_SECTORS) {
1645 printk("pktcdvd: packet size is too big\n"); 1644 printk("pktcdvd: packet size is too big\n");
@@ -1987,8 +1986,14 @@ static int pkt_open_dev(struct pktcdvd_device *pd, int write)
1987 if ((ret = pkt_set_segment_merging(pd, q))) 1986 if ((ret = pkt_set_segment_merging(pd, q)))
1988 goto out_unclaim; 1987 goto out_unclaim;
1989 1988
1990 if (write) 1989 if (write) {
1990 if (!pkt_grow_pktlist(pd, CONFIG_CDROM_PKTCDVD_BUFFERS)) {
1991 printk("pktcdvd: not enough memory for buffers\n");
1992 ret = -ENOMEM;
1993 goto out_unclaim;
1994 }
1991 printk("pktcdvd: %lukB available on disc\n", lba << 1); 1995 printk("pktcdvd: %lukB available on disc\n", lba << 1);
1996 }
1992 1997
1993 return 0; 1998 return 0;
1994 1999
@@ -2014,6 +2019,8 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush)
2014 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); 2019 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED);
2015 bd_release(pd->bdev); 2020 bd_release(pd->bdev);
2016 blkdev_put(pd->bdev); 2021 blkdev_put(pd->bdev);
2022
2023 pkt_shrink_pktlist(pd);
2017} 2024}
2018 2025
2019static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor) 2026static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor)
@@ -2379,12 +2386,6 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
2379 /* This is safe, since we have a reference from open(). */ 2386 /* This is safe, since we have a reference from open(). */
2380 __module_get(THIS_MODULE); 2387 __module_get(THIS_MODULE);
2381 2388
2382 if (!pkt_grow_pktlist(pd, CONFIG_CDROM_PKTCDVD_BUFFERS)) {
2383 printk("pktcdvd: not enough memory for buffers\n");
2384 ret = -ENOMEM;
2385 goto out_mem;
2386 }
2387
2388 pd->bdev = bdev; 2389 pd->bdev = bdev;
2389 set_blocksize(bdev, CD_FRAMESIZE); 2390 set_blocksize(bdev, CD_FRAMESIZE);
2390 2391
@@ -2395,7 +2396,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
2395 if (IS_ERR(pd->cdrw.thread)) { 2396 if (IS_ERR(pd->cdrw.thread)) {
2396 printk("pktcdvd: can't start kernel thread\n"); 2397 printk("pktcdvd: can't start kernel thread\n");
2397 ret = -ENOMEM; 2398 ret = -ENOMEM;
2398 goto out_thread; 2399 goto out_mem;
2399 } 2400 }
2400 2401
2401 proc = create_proc_entry(pd->name, 0, pkt_proc); 2402 proc = create_proc_entry(pd->name, 0, pkt_proc);
@@ -2406,8 +2407,6 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
2406 DPRINTK("pktcdvd: writer %s mapped to %s\n", pd->name, bdevname(bdev, b)); 2407 DPRINTK("pktcdvd: writer %s mapped to %s\n", pd->name, bdevname(bdev, b));
2407 return 0; 2408 return 0;
2408 2409
2409out_thread:
2410 pkt_shrink_pktlist(pd);
2411out_mem: 2410out_mem:
2412 blkdev_put(bdev); 2411 blkdev_put(bdev);
2413 /* This is safe: open() is still holding a reference. */ 2412 /* This is safe: open() is still holding a reference. */
@@ -2503,6 +2502,10 @@ static int pkt_setup_dev(struct pkt_ctrl_command *ctrl_cmd)
2503 goto out_mem; 2502 goto out_mem;
2504 pd->disk = disk; 2503 pd->disk = disk;
2505 2504
2505 INIT_LIST_HEAD(&pd->cdrw.pkt_free_list);
2506 INIT_LIST_HEAD(&pd->cdrw.pkt_active_list);
2507 spin_lock_init(&pd->cdrw.active_list_lock);
2508
2506 spin_lock_init(&pd->lock); 2509 spin_lock_init(&pd->lock);
2507 spin_lock_init(&pd->iosched.lock); 2510 spin_lock_init(&pd->iosched.lock);
2508 sprintf(pd->name, "pktcdvd%d", idx); 2511 sprintf(pd->name, "pktcdvd%d", idx);
@@ -2567,8 +2570,6 @@ static int pkt_remove_dev(struct pkt_ctrl_command *ctrl_cmd)
2567 2570
2568 blkdev_put(pd->bdev); 2571 blkdev_put(pd->bdev);
2569 2572
2570 pkt_shrink_pktlist(pd);
2571
2572 remove_proc_entry(pd->name, pkt_proc); 2573 remove_proc_entry(pd->name, pkt_proc);
2573 DPRINTK("pktcdvd: writer %s unmapped\n", pd->name); 2574 DPRINTK("pktcdvd: writer %s unmapped\n", pd->name);
2574 2575
@@ -2678,7 +2679,6 @@ static int __init pkt_init(void)
2678 2679
2679 pkt_proc = proc_mkdir("pktcdvd", proc_root_driver); 2680 pkt_proc = proc_mkdir("pktcdvd", proc_root_driver);
2680 2681
2681 DPRINTK("pktcdvd: %s\n", VERSION_CODE);
2682 return 0; 2682 return 0;
2683 2683
2684out: 2684out:
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index a05fe5843e6c..f04d864770ad 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -14,7 +14,6 @@
14 * -- special case some senses, e.g. 3a/0 -> no media present, reduce retries 14 * -- special case some senses, e.g. 3a/0 -> no media present, reduce retries
15 * -- verify the 13 conditions and do bulk resets 15 * -- verify the 13 conditions and do bulk resets
16 * -- kill last_pipe and simply do two-state clearing on both pipes 16 * -- kill last_pipe and simply do two-state clearing on both pipes
17 * -- verify protocol (bulk) from USB descriptors (maybe...)
18 * -- highmem 17 * -- highmem
19 * -- move top_sense and work_bcs into separate allocations (if they survive) 18 * -- move top_sense and work_bcs into separate allocations (if they survive)
20 * for cache purists and esoteric architectures. 19 * for cache purists and esoteric architectures.
@@ -355,7 +354,7 @@ struct ub_lun {
355 * The USB device instance. 354 * The USB device instance.
356 */ 355 */
357struct ub_dev { 356struct ub_dev {
358 spinlock_t lock; 357 spinlock_t *lock;
359 atomic_t poison; /* The USB device is disconnected */ 358 atomic_t poison; /* The USB device is disconnected */
360 int openc; /* protected by ub_lock! */ 359 int openc; /* protected by ub_lock! */
361 /* kref is too implicit for our taste */ 360 /* kref is too implicit for our taste */
@@ -420,11 +419,13 @@ static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
420static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd, 419static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
421 int stalled_pipe); 420 int stalled_pipe);
422static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd); 421static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd);
423static void ub_reset_enter(struct ub_dev *sc); 422static void ub_reset_enter(struct ub_dev *sc, int try);
424static void ub_reset_task(void *arg); 423static void ub_reset_task(void *arg);
425static int ub_sync_tur(struct ub_dev *sc, struct ub_lun *lun); 424static int ub_sync_tur(struct ub_dev *sc, struct ub_lun *lun);
426static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun, 425static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun,
427 struct ub_capacity *ret); 426 struct ub_capacity *ret);
427static int ub_sync_reset(struct ub_dev *sc);
428static int ub_probe_clear_stall(struct ub_dev *sc, int stalled_pipe);
428static int ub_probe_lun(struct ub_dev *sc, int lnum); 429static int ub_probe_lun(struct ub_dev *sc, int lnum);
429 430
430/* 431/*
@@ -452,6 +453,10 @@ MODULE_DEVICE_TABLE(usb, ub_usb_ids);
452#define UB_MAX_HOSTS 26 453#define UB_MAX_HOSTS 26
453static char ub_hostv[UB_MAX_HOSTS]; 454static char ub_hostv[UB_MAX_HOSTS];
454 455
456#define UB_QLOCK_NUM 5
457static spinlock_t ub_qlockv[UB_QLOCK_NUM];
458static int ub_qlock_next = 0;
459
455static DEFINE_SPINLOCK(ub_lock); /* Locks globals and ->openc */ 460static DEFINE_SPINLOCK(ub_lock); /* Locks globals and ->openc */
456 461
457/* 462/*
@@ -531,7 +536,7 @@ static ssize_t ub_diag_show(struct device *dev, struct device_attribute *attr,
531 return 0; 536 return 0;
532 537
533 cnt = 0; 538 cnt = 0;
534 spin_lock_irqsave(&sc->lock, flags); 539 spin_lock_irqsave(sc->lock, flags);
535 540
536 cnt += sprintf(page + cnt, 541 cnt += sprintf(page + cnt,
537 "poison %d reset %d\n", 542 "poison %d reset %d\n",
@@ -579,7 +584,7 @@ static ssize_t ub_diag_show(struct device *dev, struct device_attribute *attr,
579 if (++nc == SCMD_TRACE_SZ) nc = 0; 584 if (++nc == SCMD_TRACE_SZ) nc = 0;
580 } 585 }
581 586
582 spin_unlock_irqrestore(&sc->lock, flags); 587 spin_unlock_irqrestore(sc->lock, flags);
583 return cnt; 588 return cnt;
584} 589}
585 590
@@ -627,6 +632,24 @@ static void ub_id_put(int id)
627} 632}
628 633
629/* 634/*
635 * This is necessitated by the fact that blk_cleanup_queue does not
636 * necesserily destroy the queue. Instead, it may merely decrease q->refcnt.
637 * Since our blk_init_queue() passes a spinlock common with ub_dev,
638 * we have life time issues when ub_cleanup frees ub_dev.
639 */
640static spinlock_t *ub_next_lock(void)
641{
642 unsigned long flags;
643 spinlock_t *ret;
644
645 spin_lock_irqsave(&ub_lock, flags);
646 ret = &ub_qlockv[ub_qlock_next];
647 ub_qlock_next = (ub_qlock_next + 1) % UB_QLOCK_NUM;
648 spin_unlock_irqrestore(&ub_lock, flags);
649 return ret;
650}
651
652/*
630 * Downcount for deallocation. This rides on two assumptions: 653 * Downcount for deallocation. This rides on two assumptions:
631 * - once something is poisoned, its refcount cannot grow 654 * - once something is poisoned, its refcount cannot grow
632 * - opens cannot happen at this time (del_gendisk was done) 655 * - opens cannot happen at this time (del_gendisk was done)
@@ -961,7 +984,7 @@ static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun,
961 if (atomic_read(&sc->poison)) 984 if (atomic_read(&sc->poison))
962 return -ENXIO; 985 return -ENXIO;
963 986
964 ub_reset_enter(sc); 987 ub_reset_enter(sc, urq->current_try);
965 988
966 if (urq->current_try >= 3) 989 if (urq->current_try >= 3)
967 return -EIO; 990 return -EIO;
@@ -997,8 +1020,6 @@ static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun,
997 * No exceptions. 1020 * No exceptions.
998 * 1021 *
999 * Host is assumed locked. 1022 * Host is assumed locked.
1000 *
1001 * XXX We only support Bulk for the moment.
1002 */ 1023 */
1003static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd) 1024static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1004{ 1025{
@@ -1083,9 +1104,10 @@ static void ub_urb_timeout(unsigned long arg)
1083 struct ub_dev *sc = (struct ub_dev *) arg; 1104 struct ub_dev *sc = (struct ub_dev *) arg;
1084 unsigned long flags; 1105 unsigned long flags;
1085 1106
1086 spin_lock_irqsave(&sc->lock, flags); 1107 spin_lock_irqsave(sc->lock, flags);
1087 usb_unlink_urb(&sc->work_urb); 1108 if (!ub_is_completed(&sc->work_done))
1088 spin_unlock_irqrestore(&sc->lock, flags); 1109 usb_unlink_urb(&sc->work_urb);
1110 spin_unlock_irqrestore(sc->lock, flags);
1089} 1111}
1090 1112
1091/* 1113/*
@@ -1108,10 +1130,9 @@ static void ub_scsi_action(unsigned long _dev)
1108 struct ub_dev *sc = (struct ub_dev *) _dev; 1130 struct ub_dev *sc = (struct ub_dev *) _dev;
1109 unsigned long flags; 1131 unsigned long flags;
1110 1132
1111 spin_lock_irqsave(&sc->lock, flags); 1133 spin_lock_irqsave(sc->lock, flags);
1112 del_timer(&sc->work_timer);
1113 ub_scsi_dispatch(sc); 1134 ub_scsi_dispatch(sc);
1114 spin_unlock_irqrestore(&sc->lock, flags); 1135 spin_unlock_irqrestore(sc->lock, flags);
1115} 1136}
1116 1137
1117static void ub_scsi_dispatch(struct ub_dev *sc) 1138static void ub_scsi_dispatch(struct ub_dev *sc)
@@ -1133,6 +1154,7 @@ static void ub_scsi_dispatch(struct ub_dev *sc)
1133 } else { 1154 } else {
1134 if (!ub_is_completed(&sc->work_done)) 1155 if (!ub_is_completed(&sc->work_done))
1135 break; 1156 break;
1157 del_timer(&sc->work_timer);
1136 ub_scsi_urb_compl(sc, cmd); 1158 ub_scsi_urb_compl(sc, cmd);
1137 } 1159 }
1138 } 1160 }
@@ -1680,16 +1702,18 @@ static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd)
1680 1702
1681/* 1703/*
1682 * Reset management 1704 * Reset management
1705 * XXX Move usb_reset_device to khubd. Hogging kevent is not a good thing.
1706 * XXX Make usb_sync_reset asynchronous.
1683 */ 1707 */
1684 1708
1685static void ub_reset_enter(struct ub_dev *sc) 1709static void ub_reset_enter(struct ub_dev *sc, int try)
1686{ 1710{
1687 1711
1688 if (sc->reset) { 1712 if (sc->reset) {
1689 /* This happens often on multi-LUN devices. */ 1713 /* This happens often on multi-LUN devices. */
1690 return; 1714 return;
1691 } 1715 }
1692 sc->reset = 1; 1716 sc->reset = try + 1;
1693 1717
1694#if 0 /* Not needed because the disconnect waits for us. */ 1718#if 0 /* Not needed because the disconnect waits for us. */
1695 unsigned long flags; 1719 unsigned long flags;
@@ -1727,6 +1751,11 @@ static void ub_reset_task(void *arg)
1727 if (atomic_read(&sc->poison)) { 1751 if (atomic_read(&sc->poison)) {
1728 printk(KERN_NOTICE "%s: Not resetting disconnected device\n", 1752 printk(KERN_NOTICE "%s: Not resetting disconnected device\n",
1729 sc->name); /* P3 This floods. Remove soon. XXX */ 1753 sc->name); /* P3 This floods. Remove soon. XXX */
1754 } else if ((sc->reset & 1) == 0) {
1755 ub_sync_reset(sc);
1756 msleep(700); /* usb-storage sleeps 6s (!) */
1757 ub_probe_clear_stall(sc, sc->recv_bulk_pipe);
1758 ub_probe_clear_stall(sc, sc->send_bulk_pipe);
1730 } else if (sc->dev->actconfig->desc.bNumInterfaces != 1) { 1759 } else if (sc->dev->actconfig->desc.bNumInterfaces != 1) {
1731 printk(KERN_NOTICE "%s: Not resetting multi-interface device\n", 1760 printk(KERN_NOTICE "%s: Not resetting multi-interface device\n",
1732 sc->name); /* P3 This floods. Remove soon. XXX */ 1761 sc->name); /* P3 This floods. Remove soon. XXX */
@@ -1754,7 +1783,7 @@ static void ub_reset_task(void *arg)
1754 * queues of resets or anything. We do need a spinlock though, 1783 * queues of resets or anything. We do need a spinlock though,
1755 * to interact with block layer. 1784 * to interact with block layer.
1756 */ 1785 */
1757 spin_lock_irqsave(&sc->lock, flags); 1786 spin_lock_irqsave(sc->lock, flags);
1758 sc->reset = 0; 1787 sc->reset = 0;
1759 tasklet_schedule(&sc->tasklet); 1788 tasklet_schedule(&sc->tasklet);
1760 list_for_each(p, &sc->luns) { 1789 list_for_each(p, &sc->luns) {
@@ -1762,7 +1791,7 @@ static void ub_reset_task(void *arg)
1762 blk_start_queue(lun->disk->queue); 1791 blk_start_queue(lun->disk->queue);
1763 } 1792 }
1764 wake_up(&sc->reset_wait); 1793 wake_up(&sc->reset_wait);
1765 spin_unlock_irqrestore(&sc->lock, flags); 1794 spin_unlock_irqrestore(sc->lock, flags);
1766} 1795}
1767 1796
1768/* 1797/*
@@ -1990,11 +2019,11 @@ static int ub_sync_tur(struct ub_dev *sc, struct ub_lun *lun)
1990 cmd->done = ub_probe_done; 2019 cmd->done = ub_probe_done;
1991 cmd->back = &compl; 2020 cmd->back = &compl;
1992 2021
1993 spin_lock_irqsave(&sc->lock, flags); 2022 spin_lock_irqsave(sc->lock, flags);
1994 cmd->tag = sc->tagcnt++; 2023 cmd->tag = sc->tagcnt++;
1995 2024
1996 rc = ub_submit_scsi(sc, cmd); 2025 rc = ub_submit_scsi(sc, cmd);
1997 spin_unlock_irqrestore(&sc->lock, flags); 2026 spin_unlock_irqrestore(sc->lock, flags);
1998 2027
1999 if (rc != 0) { 2028 if (rc != 0) {
2000 printk("ub: testing ready: submit error (%d)\n", rc); /* P3 */ 2029 printk("ub: testing ready: submit error (%d)\n", rc); /* P3 */
@@ -2052,11 +2081,11 @@ static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun,
2052 cmd->done = ub_probe_done; 2081 cmd->done = ub_probe_done;
2053 cmd->back = &compl; 2082 cmd->back = &compl;
2054 2083
2055 spin_lock_irqsave(&sc->lock, flags); 2084 spin_lock_irqsave(sc->lock, flags);
2056 cmd->tag = sc->tagcnt++; 2085 cmd->tag = sc->tagcnt++;
2057 2086
2058 rc = ub_submit_scsi(sc, cmd); 2087 rc = ub_submit_scsi(sc, cmd);
2059 spin_unlock_irqrestore(&sc->lock, flags); 2088 spin_unlock_irqrestore(sc->lock, flags);
2060 2089
2061 if (rc != 0) { 2090 if (rc != 0) {
2062 printk("ub: reading capacity: submit error (%d)\n", rc); /* P3 */ 2091 printk("ub: reading capacity: submit error (%d)\n", rc); /* P3 */
@@ -2118,6 +2147,52 @@ static void ub_probe_timeout(unsigned long arg)
2118} 2147}
2119 2148
2120/* 2149/*
2150 * Reset with a Bulk reset.
2151 */
2152static int ub_sync_reset(struct ub_dev *sc)
2153{
2154 int ifnum = sc->intf->cur_altsetting->desc.bInterfaceNumber;
2155 struct usb_ctrlrequest *cr;
2156 struct completion compl;
2157 struct timer_list timer;
2158 int rc;
2159
2160 init_completion(&compl);
2161
2162 cr = &sc->work_cr;
2163 cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
2164 cr->bRequest = US_BULK_RESET_REQUEST;
2165 cr->wValue = cpu_to_le16(0);
2166 cr->wIndex = cpu_to_le16(ifnum);
2167 cr->wLength = cpu_to_le16(0);
2168
2169 usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe,
2170 (unsigned char*) cr, NULL, 0, ub_probe_urb_complete, &compl);
2171 sc->work_urb.actual_length = 0;
2172 sc->work_urb.error_count = 0;
2173 sc->work_urb.status = 0;
2174
2175 if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) {
2176 printk(KERN_WARNING
2177 "%s: Unable to submit a bulk reset (%d)\n", sc->name, rc);
2178 return rc;
2179 }
2180
2181 init_timer(&timer);
2182 timer.function = ub_probe_timeout;
2183 timer.data = (unsigned long) &compl;
2184 timer.expires = jiffies + UB_CTRL_TIMEOUT;
2185 add_timer(&timer);
2186
2187 wait_for_completion(&compl);
2188
2189 del_timer_sync(&timer);
2190 usb_kill_urb(&sc->work_urb);
2191
2192 return sc->work_urb.status;
2193}
2194
2195/*
2121 * Get number of LUNs by the way of Bulk GetMaxLUN command. 2196 * Get number of LUNs by the way of Bulk GetMaxLUN command.
2122 */ 2197 */
2123static int ub_sync_getmaxlun(struct ub_dev *sc) 2198static int ub_sync_getmaxlun(struct ub_dev *sc)
@@ -2333,7 +2408,7 @@ static int ub_probe(struct usb_interface *intf,
2333 if ((sc = kmalloc(sizeof(struct ub_dev), GFP_KERNEL)) == NULL) 2408 if ((sc = kmalloc(sizeof(struct ub_dev), GFP_KERNEL)) == NULL)
2334 goto err_core; 2409 goto err_core;
2335 memset(sc, 0, sizeof(struct ub_dev)); 2410 memset(sc, 0, sizeof(struct ub_dev));
2336 spin_lock_init(&sc->lock); 2411 sc->lock = ub_next_lock();
2337 INIT_LIST_HEAD(&sc->luns); 2412 INIT_LIST_HEAD(&sc->luns);
2338 usb_init_urb(&sc->work_urb); 2413 usb_init_urb(&sc->work_urb);
2339 tasklet_init(&sc->tasklet, ub_scsi_action, (unsigned long)sc); 2414 tasklet_init(&sc->tasklet, ub_scsi_action, (unsigned long)sc);
@@ -2483,7 +2558,7 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum)
2483 disk->driverfs_dev = &sc->intf->dev; 2558 disk->driverfs_dev = &sc->intf->dev;
2484 2559
2485 rc = -ENOMEM; 2560 rc = -ENOMEM;
2486 if ((q = blk_init_queue(ub_request_fn, &sc->lock)) == NULL) 2561 if ((q = blk_init_queue(ub_request_fn, sc->lock)) == NULL)
2487 goto err_blkqinit; 2562 goto err_blkqinit;
2488 2563
2489 disk->queue = q; 2564 disk->queue = q;
@@ -2554,7 +2629,7 @@ static void ub_disconnect(struct usb_interface *intf)
2554 * and the whole queue drains. So, we just use this code to 2629 * and the whole queue drains. So, we just use this code to
2555 * print warnings. 2630 * print warnings.
2556 */ 2631 */
2557 spin_lock_irqsave(&sc->lock, flags); 2632 spin_lock_irqsave(sc->lock, flags);
2558 { 2633 {
2559 struct ub_scsi_cmd *cmd; 2634 struct ub_scsi_cmd *cmd;
2560 int cnt = 0; 2635 int cnt = 0;
@@ -2571,7 +2646,7 @@ static void ub_disconnect(struct usb_interface *intf)
2571 "%d was queued after shutdown\n", sc->name, cnt); 2646 "%d was queued after shutdown\n", sc->name, cnt);
2572 } 2647 }
2573 } 2648 }
2574 spin_unlock_irqrestore(&sc->lock, flags); 2649 spin_unlock_irqrestore(sc->lock, flags);
2575 2650
2576 /* 2651 /*
2577 * Unregister the upper layer. 2652 * Unregister the upper layer.
@@ -2590,19 +2665,15 @@ static void ub_disconnect(struct usb_interface *intf)
2590 } 2665 }
2591 2666
2592 /* 2667 /*
2593 * Taking a lock on a structure which is about to be freed
2594 * is very nonsensual. Here it is largely a way to do a debug freeze,
2595 * and a bracket which shows where the nonsensual code segment ends.
2596 *
2597 * Testing for -EINPROGRESS is always a bug, so we are bending 2668 * Testing for -EINPROGRESS is always a bug, so we are bending
2598 * the rules a little. 2669 * the rules a little.
2599 */ 2670 */
2600 spin_lock_irqsave(&sc->lock, flags); 2671 spin_lock_irqsave(sc->lock, flags);
2601 if (sc->work_urb.status == -EINPROGRESS) { /* janitors: ignore */ 2672 if (sc->work_urb.status == -EINPROGRESS) { /* janitors: ignore */
2602 printk(KERN_WARNING "%s: " 2673 printk(KERN_WARNING "%s: "
2603 "URB is active after disconnect\n", sc->name); 2674 "URB is active after disconnect\n", sc->name);
2604 } 2675 }
2605 spin_unlock_irqrestore(&sc->lock, flags); 2676 spin_unlock_irqrestore(sc->lock, flags);
2606 2677
2607 /* 2678 /*
2608 * There is virtually no chance that other CPU runs times so long 2679 * There is virtually no chance that other CPU runs times so long
@@ -2636,6 +2707,10 @@ static struct usb_driver ub_driver = {
2636static int __init ub_init(void) 2707static int __init ub_init(void)
2637{ 2708{
2638 int rc; 2709 int rc;
2710 int i;
2711
2712 for (i = 0; i < UB_QLOCK_NUM; i++)
2713 spin_lock_init(&ub_qlockv[i]);
2639 2714
2640 if ((rc = register_blkdev(UB_MAJOR, DRV_NAME)) != 0) 2715 if ((rc = register_blkdev(UB_MAJOR, DRV_NAME)) != 0)
2641 goto err_regblkdev; 2716 goto err_regblkdev;
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index a3614e6a68d0..4ada1268b40d 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -882,7 +882,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
882 card->card_number, dev->bus->number, dev->devfn); 882 card->card_number, dev->bus->number, dev->devfn);
883 883
884 if (pci_set_dma_mask(dev, 0xffffffffffffffffLL) && 884 if (pci_set_dma_mask(dev, 0xffffffffffffffffLL) &&
885 !pci_set_dma_mask(dev, 0xffffffffLL)) { 885 pci_set_dma_mask(dev, 0xffffffffLL)) {
886 printk(KERN_WARNING "MM%d: NO suitable DMA found\n",num_cards); 886 printk(KERN_WARNING "MM%d: NO suitable DMA found\n",num_cards);
887 return -ENOMEM; 887 return -ENOMEM;
888 } 888 }