diff options
Diffstat (limited to 'drivers/block')
-rw-r--r-- | drivers/block/Kconfig | 8 | ||||
-rw-r--r-- | drivers/block/cciss.c | 5 | ||||
-rw-r--r-- | drivers/block/pktcdvd.c | 197 | ||||
-rw-r--r-- | drivers/block/ub.c | 139 | ||||
-rw-r--r-- | drivers/block/umem.c | 2 |
5 files changed, 204 insertions, 147 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 | ||
439 | config CDROM_PKTCDVD_WCACHE | 439 | config 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/cciss.c b/drivers/block/cciss.c index 12d7b9bdfa93..0d65394707db 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c | |||
@@ -2183,6 +2183,7 @@ static void cciss_softirq_done(struct request *rq) | |||
2183 | { | 2183 | { |
2184 | CommandList_struct *cmd = rq->completion_data; | 2184 | CommandList_struct *cmd = rq->completion_data; |
2185 | ctlr_info_t *h = hba[cmd->ctlr]; | 2185 | ctlr_info_t *h = hba[cmd->ctlr]; |
2186 | unsigned long flags; | ||
2186 | u64bit temp64; | 2187 | u64bit temp64; |
2187 | int i, ddir; | 2188 | int i, ddir; |
2188 | 2189 | ||
@@ -2205,10 +2206,10 @@ static void cciss_softirq_done(struct request *rq) | |||
2205 | printk("Done with %p\n", rq); | 2206 | printk("Done with %p\n", rq); |
2206 | #endif /* CCISS_DEBUG */ | 2207 | #endif /* CCISS_DEBUG */ |
2207 | 2208 | ||
2208 | spin_lock_irq(&h->lock); | 2209 | spin_lock_irqsave(&h->lock, flags); |
2209 | end_that_request_last(rq, rq->errors); | 2210 | end_that_request_last(rq, rq->errors); |
2210 | cmd_free(h, cmd,1); | 2211 | cmd_free(h, cmd,1); |
2211 | spin_unlock_irq(&h->lock); | 2212 | spin_unlock_irqrestore(&h->lock, flags); |
2212 | } | 2213 | } |
2213 | 2214 | ||
2214 | /* checks the status of the job and calls complete buffers to mark all | 2215 | /* checks the status of the job and calls complete buffers to mark all |
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index 93affeeef7bd..bc9b2bcd7dba 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> |
@@ -60,6 +58,7 @@ | |||
60 | #include <linux/suspend.h> | 58 | #include <linux/suspend.h> |
61 | #include <scsi/scsi_cmnd.h> | 59 | #include <scsi/scsi_cmnd.h> |
62 | #include <scsi/scsi_ioctl.h> | 60 | #include <scsi/scsi_ioctl.h> |
61 | #include <scsi/scsi.h> | ||
63 | 62 | ||
64 | #include <asm/uaccess.h> | 63 | #include <asm/uaccess.h> |
65 | 64 | ||
@@ -131,7 +130,7 @@ static struct bio *pkt_bio_alloc(int nr_iovecs) | |||
131 | /* | 130 | /* |
132 | * Allocate a packet_data struct | 131 | * Allocate a packet_data struct |
133 | */ | 132 | */ |
134 | static struct packet_data *pkt_alloc_packet_data(void) | 133 | static struct packet_data *pkt_alloc_packet_data(int frames) |
135 | { | 134 | { |
136 | int i; | 135 | int i; |
137 | struct packet_data *pkt; | 136 | struct packet_data *pkt; |
@@ -140,11 +139,12 @@ static struct packet_data *pkt_alloc_packet_data(void) | |||
140 | if (!pkt) | 139 | if (!pkt) |
141 | goto no_pkt; | 140 | goto no_pkt; |
142 | 141 | ||
143 | pkt->w_bio = pkt_bio_alloc(PACKET_MAX_SIZE); | 142 | pkt->frames = frames; |
143 | pkt->w_bio = pkt_bio_alloc(frames); | ||
144 | if (!pkt->w_bio) | 144 | if (!pkt->w_bio) |
145 | goto no_bio; | 145 | goto no_bio; |
146 | 146 | ||
147 | for (i = 0; i < PAGES_PER_PACKET; i++) { | 147 | for (i = 0; i < frames / FRAMES_PER_PAGE; i++) { |
148 | pkt->pages[i] = alloc_page(GFP_KERNEL|__GFP_ZERO); | 148 | pkt->pages[i] = alloc_page(GFP_KERNEL|__GFP_ZERO); |
149 | if (!pkt->pages[i]) | 149 | if (!pkt->pages[i]) |
150 | goto no_page; | 150 | goto no_page; |
@@ -152,7 +152,7 @@ static struct packet_data *pkt_alloc_packet_data(void) | |||
152 | 152 | ||
153 | spin_lock_init(&pkt->lock); | 153 | spin_lock_init(&pkt->lock); |
154 | 154 | ||
155 | for (i = 0; i < PACKET_MAX_SIZE; i++) { | 155 | for (i = 0; i < frames; i++) { |
156 | struct bio *bio = pkt_bio_alloc(1); | 156 | struct bio *bio = pkt_bio_alloc(1); |
157 | if (!bio) | 157 | if (!bio) |
158 | goto no_rd_bio; | 158 | goto no_rd_bio; |
@@ -162,14 +162,14 @@ static struct packet_data *pkt_alloc_packet_data(void) | |||
162 | return pkt; | 162 | return pkt; |
163 | 163 | ||
164 | no_rd_bio: | 164 | no_rd_bio: |
165 | for (i = 0; i < PACKET_MAX_SIZE; i++) { | 165 | for (i = 0; i < frames; i++) { |
166 | struct bio *bio = pkt->r_bios[i]; | 166 | struct bio *bio = pkt->r_bios[i]; |
167 | if (bio) | 167 | if (bio) |
168 | bio_put(bio); | 168 | bio_put(bio); |
169 | } | 169 | } |
170 | 170 | ||
171 | no_page: | 171 | no_page: |
172 | for (i = 0; i < PAGES_PER_PACKET; i++) | 172 | for (i = 0; i < frames / FRAMES_PER_PAGE; i++) |
173 | if (pkt->pages[i]) | 173 | if (pkt->pages[i]) |
174 | __free_page(pkt->pages[i]); | 174 | __free_page(pkt->pages[i]); |
175 | bio_put(pkt->w_bio); | 175 | bio_put(pkt->w_bio); |
@@ -186,12 +186,12 @@ static void pkt_free_packet_data(struct packet_data *pkt) | |||
186 | { | 186 | { |
187 | int i; | 187 | int i; |
188 | 188 | ||
189 | for (i = 0; i < PACKET_MAX_SIZE; i++) { | 189 | for (i = 0; i < pkt->frames; i++) { |
190 | struct bio *bio = pkt->r_bios[i]; | 190 | struct bio *bio = pkt->r_bios[i]; |
191 | if (bio) | 191 | if (bio) |
192 | bio_put(bio); | 192 | bio_put(bio); |
193 | } | 193 | } |
194 | for (i = 0; i < PAGES_PER_PACKET; i++) | 194 | for (i = 0; i < pkt->frames / FRAMES_PER_PAGE; i++) |
195 | __free_page(pkt->pages[i]); | 195 | __free_page(pkt->pages[i]); |
196 | bio_put(pkt->w_bio); | 196 | bio_put(pkt->w_bio); |
197 | kfree(pkt); | 197 | kfree(pkt); |
@@ -206,17 +206,17 @@ static void pkt_shrink_pktlist(struct pktcdvd_device *pd) | |||
206 | list_for_each_entry_safe(pkt, next, &pd->cdrw.pkt_free_list, list) { | 206 | list_for_each_entry_safe(pkt, next, &pd->cdrw.pkt_free_list, list) { |
207 | pkt_free_packet_data(pkt); | 207 | pkt_free_packet_data(pkt); |
208 | } | 208 | } |
209 | INIT_LIST_HEAD(&pd->cdrw.pkt_free_list); | ||
209 | } | 210 | } |
210 | 211 | ||
211 | static int pkt_grow_pktlist(struct pktcdvd_device *pd, int nr_packets) | 212 | static int pkt_grow_pktlist(struct pktcdvd_device *pd, int nr_packets) |
212 | { | 213 | { |
213 | struct packet_data *pkt; | 214 | struct packet_data *pkt; |
214 | 215 | ||
215 | INIT_LIST_HEAD(&pd->cdrw.pkt_free_list); | 216 | BUG_ON(!list_empty(&pd->cdrw.pkt_free_list)); |
216 | INIT_LIST_HEAD(&pd->cdrw.pkt_active_list); | 217 | |
217 | spin_lock_init(&pd->cdrw.active_list_lock); | ||
218 | while (nr_packets > 0) { | 218 | while (nr_packets > 0) { |
219 | pkt = pkt_alloc_packet_data(); | 219 | pkt = pkt_alloc_packet_data(pd->settings.size >> 2); |
220 | if (!pkt) { | 220 | if (!pkt) { |
221 | pkt_shrink_pktlist(pd); | 221 | pkt_shrink_pktlist(pd); |
222 | return 0; | 222 | return 0; |
@@ -381,6 +381,7 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command * | |||
381 | memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE); | 381 | memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE); |
382 | if (sizeof(rq->cmd) > CDROM_PACKET_SIZE) | 382 | if (sizeof(rq->cmd) > CDROM_PACKET_SIZE) |
383 | memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE); | 383 | memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE); |
384 | rq->cmd_len = COMMAND_SIZE(rq->cmd[0]); | ||
384 | 385 | ||
385 | rq->ref_count++; | 386 | rq->ref_count++; |
386 | rq->flags |= REQ_NOMERGE; | 387 | rq->flags |= REQ_NOMERGE; |
@@ -646,7 +647,7 @@ static void pkt_copy_bio_data(struct bio *src_bio, int seg, int offs, struct pag | |||
646 | * b) The data can be used as cache to avoid read requests if we receive a | 647 | * b) The data can be used as cache to avoid read requests if we receive a |
647 | * new write request for the same zone. | 648 | * new write request for the same zone. |
648 | */ | 649 | */ |
649 | static void pkt_make_local_copy(struct packet_data *pkt, struct page **pages, int *offsets) | 650 | static void pkt_make_local_copy(struct packet_data *pkt, struct bio_vec *bvec) |
650 | { | 651 | { |
651 | int f, p, offs; | 652 | int f, p, offs; |
652 | 653 | ||
@@ -654,15 +655,15 @@ static void pkt_make_local_copy(struct packet_data *pkt, struct page **pages, in | |||
654 | p = 0; | 655 | p = 0; |
655 | offs = 0; | 656 | offs = 0; |
656 | for (f = 0; f < pkt->frames; f++) { | 657 | for (f = 0; f < pkt->frames; f++) { |
657 | if (pages[f] != pkt->pages[p]) { | 658 | if (bvec[f].bv_page != pkt->pages[p]) { |
658 | void *vfrom = kmap_atomic(pages[f], KM_USER0) + offsets[f]; | 659 | void *vfrom = kmap_atomic(bvec[f].bv_page, KM_USER0) + bvec[f].bv_offset; |
659 | void *vto = page_address(pkt->pages[p]) + offs; | 660 | void *vto = page_address(pkt->pages[p]) + offs; |
660 | memcpy(vto, vfrom, CD_FRAMESIZE); | 661 | memcpy(vto, vfrom, CD_FRAMESIZE); |
661 | kunmap_atomic(vfrom, KM_USER0); | 662 | kunmap_atomic(vfrom, KM_USER0); |
662 | pages[f] = pkt->pages[p]; | 663 | bvec[f].bv_page = pkt->pages[p]; |
663 | offsets[f] = offs; | 664 | bvec[f].bv_offset = offs; |
664 | } else { | 665 | } else { |
665 | BUG_ON(offsets[f] != offs); | 666 | BUG_ON(bvec[f].bv_offset != offs); |
666 | } | 667 | } |
667 | offs += CD_FRAMESIZE; | 668 | offs += CD_FRAMESIZE; |
668 | if (offs >= PAGE_SIZE) { | 669 | if (offs >= PAGE_SIZE) { |
@@ -951,7 +952,7 @@ try_next_bio: | |||
951 | 952 | ||
952 | pd->current_sector = zone + pd->settings.size; | 953 | pd->current_sector = zone + pd->settings.size; |
953 | pkt->sector = zone; | 954 | pkt->sector = zone; |
954 | pkt->frames = pd->settings.size >> 2; | 955 | BUG_ON(pkt->frames != pd->settings.size >> 2); |
955 | pkt->write_size = 0; | 956 | pkt->write_size = 0; |
956 | 957 | ||
957 | /* | 958 | /* |
@@ -992,18 +993,17 @@ try_next_bio: | |||
992 | static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) | 993 | static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) |
993 | { | 994 | { |
994 | struct bio *bio; | 995 | struct bio *bio; |
995 | struct page *pages[PACKET_MAX_SIZE]; | ||
996 | int offsets[PACKET_MAX_SIZE]; | ||
997 | int f; | 996 | int f; |
998 | int frames_write; | 997 | int frames_write; |
998 | struct bio_vec *bvec = pkt->w_bio->bi_io_vec; | ||
999 | 999 | ||
1000 | for (f = 0; f < pkt->frames; f++) { | 1000 | for (f = 0; f < pkt->frames; f++) { |
1001 | pages[f] = pkt->pages[(f * CD_FRAMESIZE) / PAGE_SIZE]; | 1001 | bvec[f].bv_page = pkt->pages[(f * CD_FRAMESIZE) / PAGE_SIZE]; |
1002 | offsets[f] = (f * CD_FRAMESIZE) % PAGE_SIZE; | 1002 | bvec[f].bv_offset = (f * CD_FRAMESIZE) % PAGE_SIZE; |
1003 | } | 1003 | } |
1004 | 1004 | ||
1005 | /* | 1005 | /* |
1006 | * Fill-in pages[] and offsets[] with data from orig_bios. | 1006 | * Fill-in bvec with data from orig_bios. |
1007 | */ | 1007 | */ |
1008 | frames_write = 0; | 1008 | frames_write = 0; |
1009 | spin_lock(&pkt->lock); | 1009 | spin_lock(&pkt->lock); |
@@ -1025,11 +1025,11 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) | |||
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | if (src_bvl->bv_len - src_offs >= CD_FRAMESIZE) { | 1027 | if (src_bvl->bv_len - src_offs >= CD_FRAMESIZE) { |
1028 | pages[f] = src_bvl->bv_page; | 1028 | bvec[f].bv_page = src_bvl->bv_page; |
1029 | offsets[f] = src_bvl->bv_offset + src_offs; | 1029 | bvec[f].bv_offset = src_bvl->bv_offset + src_offs; |
1030 | } else { | 1030 | } else { |
1031 | pkt_copy_bio_data(bio, segment, src_offs, | 1031 | pkt_copy_bio_data(bio, segment, src_offs, |
1032 | pages[f], offsets[f]); | 1032 | bvec[f].bv_page, bvec[f].bv_offset); |
1033 | } | 1033 | } |
1034 | src_offs += CD_FRAMESIZE; | 1034 | src_offs += CD_FRAMESIZE; |
1035 | frames_write++; | 1035 | frames_write++; |
@@ -1043,7 +1043,7 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) | |||
1043 | BUG_ON(frames_write != pkt->write_size); | 1043 | BUG_ON(frames_write != pkt->write_size); |
1044 | 1044 | ||
1045 | if (test_bit(PACKET_MERGE_SEGS, &pd->flags) || (pkt->write_size < pkt->frames)) { | 1045 | if (test_bit(PACKET_MERGE_SEGS, &pd->flags) || (pkt->write_size < pkt->frames)) { |
1046 | pkt_make_local_copy(pkt, pages, offsets); | 1046 | pkt_make_local_copy(pkt, bvec); |
1047 | pkt->cache_valid = 1; | 1047 | pkt->cache_valid = 1; |
1048 | } else { | 1048 | } else { |
1049 | pkt->cache_valid = 0; | 1049 | pkt->cache_valid = 0; |
@@ -1056,17 +1056,9 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) | |||
1056 | pkt->w_bio->bi_bdev = pd->bdev; | 1056 | pkt->w_bio->bi_bdev = pd->bdev; |
1057 | pkt->w_bio->bi_end_io = pkt_end_io_packet_write; | 1057 | pkt->w_bio->bi_end_io = pkt_end_io_packet_write; |
1058 | pkt->w_bio->bi_private = pkt; | 1058 | pkt->w_bio->bi_private = pkt; |
1059 | for (f = 0; f < pkt->frames; f++) { | 1059 | for (f = 0; f < pkt->frames; f++) |
1060 | if ((f + 1 < pkt->frames) && (pages[f + 1] == pages[f]) && | 1060 | if (!bio_add_page(pkt->w_bio, bvec[f].bv_page, CD_FRAMESIZE, bvec[f].bv_offset)) |
1061 | (offsets[f + 1] = offsets[f] + CD_FRAMESIZE)) { | 1061 | BUG(); |
1062 | if (!bio_add_page(pkt->w_bio, pages[f], CD_FRAMESIZE * 2, offsets[f])) | ||
1063 | BUG(); | ||
1064 | f++; | ||
1065 | } else { | ||
1066 | if (!bio_add_page(pkt->w_bio, pages[f], CD_FRAMESIZE, offsets[f])) | ||
1067 | BUG(); | ||
1068 | } | ||
1069 | } | ||
1070 | VPRINTK("pktcdvd: vcnt=%d\n", pkt->w_bio->bi_vcnt); | 1062 | VPRINTK("pktcdvd: vcnt=%d\n", pkt->w_bio->bi_vcnt); |
1071 | 1063 | ||
1072 | atomic_set(&pkt->io_wait, 1); | 1064 | atomic_set(&pkt->io_wait, 1); |
@@ -1505,40 +1497,42 @@ static int pkt_set_write_settings(struct pktcdvd_device *pd) | |||
1505 | } | 1497 | } |
1506 | 1498 | ||
1507 | /* | 1499 | /* |
1508 | * 0 -- we can write to this track, 1 -- we can't | 1500 | * 1 -- we can write to this track, 0 -- we can't |
1509 | */ | 1501 | */ |
1510 | static int pkt_good_track(track_information *ti) | 1502 | static int pkt_writable_track(struct pktcdvd_device *pd, track_information *ti) |
1511 | { | 1503 | { |
1512 | /* | 1504 | switch (pd->mmc3_profile) { |
1513 | * only good for CD-RW at the moment, not DVD-RW | 1505 | case 0x1a: /* DVD+RW */ |
1514 | */ | 1506 | case 0x12: /* DVD-RAM */ |
1507 | /* The track is always writable on DVD+RW/DVD-RAM */ | ||
1508 | return 1; | ||
1509 | default: | ||
1510 | break; | ||
1511 | } | ||
1515 | 1512 | ||
1516 | /* | 1513 | if (!ti->packet || !ti->fp) |
1517 | * FIXME: only for FP | ||
1518 | */ | ||
1519 | if (ti->fp == 0) | ||
1520 | return 0; | 1514 | return 0; |
1521 | 1515 | ||
1522 | /* | 1516 | /* |
1523 | * "good" settings as per Mt Fuji. | 1517 | * "good" settings as per Mt Fuji. |
1524 | */ | 1518 | */ |
1525 | if (ti->rt == 0 && ti->blank == 0 && ti->packet == 1) | 1519 | if (ti->rt == 0 && ti->blank == 0) |
1526 | return 0; | 1520 | return 1; |
1527 | 1521 | ||
1528 | if (ti->rt == 0 && ti->blank == 1 && ti->packet == 1) | 1522 | if (ti->rt == 0 && ti->blank == 1) |
1529 | return 0; | 1523 | return 1; |
1530 | 1524 | ||
1531 | if (ti->rt == 1 && ti->blank == 0 && ti->packet == 1) | 1525 | if (ti->rt == 1 && ti->blank == 0) |
1532 | return 0; | 1526 | return 1; |
1533 | 1527 | ||
1534 | printk("pktcdvd: bad state %d-%d-%d\n", ti->rt, ti->blank, ti->packet); | 1528 | printk("pktcdvd: bad state %d-%d-%d\n", ti->rt, ti->blank, ti->packet); |
1535 | return 1; | 1529 | return 0; |
1536 | } | 1530 | } |
1537 | 1531 | ||
1538 | /* | 1532 | /* |
1539 | * 0 -- we can write to this disc, 1 -- we can't | 1533 | * 1 -- we can write to this disc, 0 -- we can't |
1540 | */ | 1534 | */ |
1541 | static int pkt_good_disc(struct pktcdvd_device *pd, disc_information *di) | 1535 | static int pkt_writable_disc(struct pktcdvd_device *pd, disc_information *di) |
1542 | { | 1536 | { |
1543 | switch (pd->mmc3_profile) { | 1537 | switch (pd->mmc3_profile) { |
1544 | case 0x0a: /* CD-RW */ | 1538 | case 0x0a: /* CD-RW */ |
@@ -1547,10 +1541,10 @@ static int pkt_good_disc(struct pktcdvd_device *pd, disc_information *di) | |||
1547 | case 0x1a: /* DVD+RW */ | 1541 | case 0x1a: /* DVD+RW */ |
1548 | case 0x13: /* DVD-RW */ | 1542 | case 0x13: /* DVD-RW */ |
1549 | case 0x12: /* DVD-RAM */ | 1543 | case 0x12: /* DVD-RAM */ |
1550 | return 0; | ||
1551 | default: | ||
1552 | printk("pktcdvd: Wrong disc profile (%x)\n", pd->mmc3_profile); | ||
1553 | return 1; | 1544 | return 1; |
1545 | default: | ||
1546 | VPRINTK("pktcdvd: Wrong disc profile (%x)\n", pd->mmc3_profile); | ||
1547 | return 0; | ||
1554 | } | 1548 | } |
1555 | 1549 | ||
1556 | /* | 1550 | /* |
@@ -1559,25 +1553,25 @@ static int pkt_good_disc(struct pktcdvd_device *pd, disc_information *di) | |||
1559 | */ | 1553 | */ |
1560 | if (di->disc_type == 0xff) { | 1554 | if (di->disc_type == 0xff) { |
1561 | printk("pktcdvd: Unknown disc. No track?\n"); | 1555 | printk("pktcdvd: Unknown disc. No track?\n"); |
1562 | return 1; | 1556 | return 0; |
1563 | } | 1557 | } |
1564 | 1558 | ||
1565 | if (di->disc_type != 0x20 && di->disc_type != 0) { | 1559 | if (di->disc_type != 0x20 && di->disc_type != 0) { |
1566 | printk("pktcdvd: Wrong disc type (%x)\n", di->disc_type); | 1560 | printk("pktcdvd: Wrong disc type (%x)\n", di->disc_type); |
1567 | return 1; | 1561 | return 0; |
1568 | } | 1562 | } |
1569 | 1563 | ||
1570 | if (di->erasable == 0) { | 1564 | if (di->erasable == 0) { |
1571 | printk("pktcdvd: Disc not erasable\n"); | 1565 | printk("pktcdvd: Disc not erasable\n"); |
1572 | return 1; | 1566 | return 0; |
1573 | } | 1567 | } |
1574 | 1568 | ||
1575 | if (di->border_status == PACKET_SESSION_RESERVED) { | 1569 | if (di->border_status == PACKET_SESSION_RESERVED) { |
1576 | printk("pktcdvd: Can't write to last track (reserved)\n"); | 1570 | printk("pktcdvd: Can't write to last track (reserved)\n"); |
1577 | return 1; | 1571 | return 0; |
1578 | } | 1572 | } |
1579 | 1573 | ||
1580 | return 0; | 1574 | return 1; |
1581 | } | 1575 | } |
1582 | 1576 | ||
1583 | static int pkt_probe_settings(struct pktcdvd_device *pd) | 1577 | static int pkt_probe_settings(struct pktcdvd_device *pd) |
@@ -1602,23 +1596,9 @@ static int pkt_probe_settings(struct pktcdvd_device *pd) | |||
1602 | return ret; | 1596 | return ret; |
1603 | } | 1597 | } |
1604 | 1598 | ||
1605 | if (pkt_good_disc(pd, &di)) | 1599 | if (!pkt_writable_disc(pd, &di)) |
1606 | return -ENXIO; | 1600 | return -EROFS; |
1607 | 1601 | ||
1608 | switch (pd->mmc3_profile) { | ||
1609 | case 0x1a: /* DVD+RW */ | ||
1610 | printk("pktcdvd: inserted media is DVD+RW\n"); | ||
1611 | break; | ||
1612 | case 0x13: /* DVD-RW */ | ||
1613 | printk("pktcdvd: inserted media is DVD-RW\n"); | ||
1614 | break; | ||
1615 | case 0x12: /* DVD-RAM */ | ||
1616 | printk("pktcdvd: inserted media is DVD-RAM\n"); | ||
1617 | break; | ||
1618 | default: | ||
1619 | printk("pktcdvd: inserted media is CD-R%s\n", di.erasable ? "W" : ""); | ||
1620 | break; | ||
1621 | } | ||
1622 | pd->type = di.erasable ? PACKET_CDRW : PACKET_CDR; | 1602 | pd->type = di.erasable ? PACKET_CDRW : PACKET_CDR; |
1623 | 1603 | ||
1624 | track = 1; /* (di.last_track_msb << 8) | di.last_track_lsb; */ | 1604 | track = 1; /* (di.last_track_msb << 8) | di.last_track_lsb; */ |
@@ -1627,9 +1607,9 @@ static int pkt_probe_settings(struct pktcdvd_device *pd) | |||
1627 | return ret; | 1607 | return ret; |
1628 | } | 1608 | } |
1629 | 1609 | ||
1630 | if (pkt_good_track(&ti)) { | 1610 | if (!pkt_writable_track(pd, &ti)) { |
1631 | printk("pktcdvd: can't write to this track\n"); | 1611 | printk("pktcdvd: can't write to this track\n"); |
1632 | return -ENXIO; | 1612 | return -EROFS; |
1633 | } | 1613 | } |
1634 | 1614 | ||
1635 | /* | 1615 | /* |
@@ -1639,11 +1619,11 @@ static int pkt_probe_settings(struct pktcdvd_device *pd) | |||
1639 | pd->settings.size = be32_to_cpu(ti.fixed_packet_size) << 2; | 1619 | pd->settings.size = be32_to_cpu(ti.fixed_packet_size) << 2; |
1640 | if (pd->settings.size == 0) { | 1620 | if (pd->settings.size == 0) { |
1641 | printk("pktcdvd: detected zero packet size!\n"); | 1621 | printk("pktcdvd: detected zero packet size!\n"); |
1642 | pd->settings.size = 128; | 1622 | return -ENXIO; |
1643 | } | 1623 | } |
1644 | if (pd->settings.size > PACKET_MAX_SECTORS) { | 1624 | if (pd->settings.size > PACKET_MAX_SECTORS) { |
1645 | printk("pktcdvd: packet size is too big\n"); | 1625 | printk("pktcdvd: packet size is too big\n"); |
1646 | return -ENXIO; | 1626 | return -EROFS; |
1647 | } | 1627 | } |
1648 | pd->settings.fp = ti.fp; | 1628 | pd->settings.fp = ti.fp; |
1649 | pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1); | 1629 | pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1); |
@@ -1685,7 +1665,7 @@ static int pkt_probe_settings(struct pktcdvd_device *pd) | |||
1685 | break; | 1665 | break; |
1686 | default: | 1666 | default: |
1687 | printk("pktcdvd: unknown data mode\n"); | 1667 | printk("pktcdvd: unknown data mode\n"); |
1688 | return 1; | 1668 | return -EROFS; |
1689 | } | 1669 | } |
1690 | return 0; | 1670 | return 0; |
1691 | } | 1671 | } |
@@ -1895,8 +1875,8 @@ static int pkt_open_write(struct pktcdvd_device *pd) | |||
1895 | unsigned int write_speed, media_write_speed, read_speed; | 1875 | unsigned int write_speed, media_write_speed, read_speed; |
1896 | 1876 | ||
1897 | if ((ret = pkt_probe_settings(pd))) { | 1877 | if ((ret = pkt_probe_settings(pd))) { |
1898 | DPRINTK("pktcdvd: %s failed probe\n", pd->name); | 1878 | VPRINTK("pktcdvd: %s failed probe\n", pd->name); |
1899 | return -EIO; | 1879 | return ret; |
1900 | } | 1880 | } |
1901 | 1881 | ||
1902 | if ((ret = pkt_set_write_settings(pd))) { | 1882 | if ((ret = pkt_set_write_settings(pd))) { |
@@ -1987,8 +1967,14 @@ static int pkt_open_dev(struct pktcdvd_device *pd, int write) | |||
1987 | if ((ret = pkt_set_segment_merging(pd, q))) | 1967 | if ((ret = pkt_set_segment_merging(pd, q))) |
1988 | goto out_unclaim; | 1968 | goto out_unclaim; |
1989 | 1969 | ||
1990 | if (write) | 1970 | if (write) { |
1971 | if (!pkt_grow_pktlist(pd, CONFIG_CDROM_PKTCDVD_BUFFERS)) { | ||
1972 | printk("pktcdvd: not enough memory for buffers\n"); | ||
1973 | ret = -ENOMEM; | ||
1974 | goto out_unclaim; | ||
1975 | } | ||
1991 | printk("pktcdvd: %lukB available on disc\n", lba << 1); | 1976 | printk("pktcdvd: %lukB available on disc\n", lba << 1); |
1977 | } | ||
1992 | 1978 | ||
1993 | return 0; | 1979 | return 0; |
1994 | 1980 | ||
@@ -2014,6 +2000,8 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush) | |||
2014 | pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); | 2000 | pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); |
2015 | bd_release(pd->bdev); | 2001 | bd_release(pd->bdev); |
2016 | blkdev_put(pd->bdev); | 2002 | blkdev_put(pd->bdev); |
2003 | |||
2004 | pkt_shrink_pktlist(pd); | ||
2017 | } | 2005 | } |
2018 | 2006 | ||
2019 | static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor) | 2007 | static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor) |
@@ -2046,10 +2034,9 @@ static int pkt_open(struct inode *inode, struct file *file) | |||
2046 | goto out_dec; | 2034 | goto out_dec; |
2047 | } | 2035 | } |
2048 | } else { | 2036 | } else { |
2049 | if (pkt_open_dev(pd, file->f_mode & FMODE_WRITE)) { | 2037 | ret = pkt_open_dev(pd, file->f_mode & FMODE_WRITE); |
2050 | ret = -EIO; | 2038 | if (ret) |
2051 | goto out_dec; | 2039 | goto out_dec; |
2052 | } | ||
2053 | /* | 2040 | /* |
2054 | * needed here as well, since ext2 (among others) may change | 2041 | * needed here as well, since ext2 (among others) may change |
2055 | * the blocksize at mount time | 2042 | * the blocksize at mount time |
@@ -2379,12 +2366,6 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) | |||
2379 | /* This is safe, since we have a reference from open(). */ | 2366 | /* This is safe, since we have a reference from open(). */ |
2380 | __module_get(THIS_MODULE); | 2367 | __module_get(THIS_MODULE); |
2381 | 2368 | ||
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; | 2369 | pd->bdev = bdev; |
2389 | set_blocksize(bdev, CD_FRAMESIZE); | 2370 | set_blocksize(bdev, CD_FRAMESIZE); |
2390 | 2371 | ||
@@ -2395,7 +2376,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) | |||
2395 | if (IS_ERR(pd->cdrw.thread)) { | 2376 | if (IS_ERR(pd->cdrw.thread)) { |
2396 | printk("pktcdvd: can't start kernel thread\n"); | 2377 | printk("pktcdvd: can't start kernel thread\n"); |
2397 | ret = -ENOMEM; | 2378 | ret = -ENOMEM; |
2398 | goto out_thread; | 2379 | goto out_mem; |
2399 | } | 2380 | } |
2400 | 2381 | ||
2401 | proc = create_proc_entry(pd->name, 0, pkt_proc); | 2382 | proc = create_proc_entry(pd->name, 0, pkt_proc); |
@@ -2406,8 +2387,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)); | 2387 | DPRINTK("pktcdvd: writer %s mapped to %s\n", pd->name, bdevname(bdev, b)); |
2407 | return 0; | 2388 | return 0; |
2408 | 2389 | ||
2409 | out_thread: | ||
2410 | pkt_shrink_pktlist(pd); | ||
2411 | out_mem: | 2390 | out_mem: |
2412 | blkdev_put(bdev); | 2391 | blkdev_put(bdev); |
2413 | /* This is safe: open() is still holding a reference. */ | 2392 | /* This is safe: open() is still holding a reference. */ |
@@ -2437,11 +2416,12 @@ static int pkt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u | |||
2437 | * The door gets locked when the device is opened, so we | 2416 | * The door gets locked when the device is opened, so we |
2438 | * have to unlock it or else the eject command fails. | 2417 | * have to unlock it or else the eject command fails. |
2439 | */ | 2418 | */ |
2440 | pkt_lock_door(pd, 0); | 2419 | if (pd->refcnt == 1) |
2420 | pkt_lock_door(pd, 0); | ||
2441 | return blkdev_ioctl(pd->bdev->bd_inode, file, cmd, arg); | 2421 | return blkdev_ioctl(pd->bdev->bd_inode, file, cmd, arg); |
2442 | 2422 | ||
2443 | default: | 2423 | default: |
2444 | printk("pktcdvd: Unknown ioctl for %s (%x)\n", pd->name, cmd); | 2424 | VPRINTK("pktcdvd: Unknown ioctl for %s (%x)\n", pd->name, cmd); |
2445 | return -ENOTTY; | 2425 | return -ENOTTY; |
2446 | } | 2426 | } |
2447 | 2427 | ||
@@ -2503,6 +2483,10 @@ static int pkt_setup_dev(struct pkt_ctrl_command *ctrl_cmd) | |||
2503 | goto out_mem; | 2483 | goto out_mem; |
2504 | pd->disk = disk; | 2484 | pd->disk = disk; |
2505 | 2485 | ||
2486 | INIT_LIST_HEAD(&pd->cdrw.pkt_free_list); | ||
2487 | INIT_LIST_HEAD(&pd->cdrw.pkt_active_list); | ||
2488 | spin_lock_init(&pd->cdrw.active_list_lock); | ||
2489 | |||
2506 | spin_lock_init(&pd->lock); | 2490 | spin_lock_init(&pd->lock); |
2507 | spin_lock_init(&pd->iosched.lock); | 2491 | spin_lock_init(&pd->iosched.lock); |
2508 | sprintf(pd->name, "pktcdvd%d", idx); | 2492 | sprintf(pd->name, "pktcdvd%d", idx); |
@@ -2567,8 +2551,6 @@ static int pkt_remove_dev(struct pkt_ctrl_command *ctrl_cmd) | |||
2567 | 2551 | ||
2568 | blkdev_put(pd->bdev); | 2552 | blkdev_put(pd->bdev); |
2569 | 2553 | ||
2570 | pkt_shrink_pktlist(pd); | ||
2571 | |||
2572 | remove_proc_entry(pd->name, pkt_proc); | 2554 | remove_proc_entry(pd->name, pkt_proc); |
2573 | DPRINTK("pktcdvd: writer %s unmapped\n", pd->name); | 2555 | DPRINTK("pktcdvd: writer %s unmapped\n", pd->name); |
2574 | 2556 | ||
@@ -2678,7 +2660,6 @@ static int __init pkt_init(void) | |||
2678 | 2660 | ||
2679 | pkt_proc = proc_mkdir("pktcdvd", proc_root_driver); | 2661 | pkt_proc = proc_mkdir("pktcdvd", proc_root_driver); |
2680 | 2662 | ||
2681 | DPRINTK("pktcdvd: %s\n", VERSION_CODE); | ||
2682 | return 0; | 2663 | return 0; |
2683 | 2664 | ||
2684 | out: | 2665 | out: |
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 | */ |
357 | struct ub_dev { | 356 | struct 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); | |||
420 | static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd, | 419 | static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd, |
421 | int stalled_pipe); | 420 | int stalled_pipe); |
422 | static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd); | 421 | static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd); |
423 | static void ub_reset_enter(struct ub_dev *sc); | 422 | static void ub_reset_enter(struct ub_dev *sc, int try); |
424 | static void ub_reset_task(void *arg); | 423 | static void ub_reset_task(void *arg); |
425 | static int ub_sync_tur(struct ub_dev *sc, struct ub_lun *lun); | 424 | static int ub_sync_tur(struct ub_dev *sc, struct ub_lun *lun); |
426 | static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun, | 425 | static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun, |
427 | struct ub_capacity *ret); | 426 | struct ub_capacity *ret); |
427 | static int ub_sync_reset(struct ub_dev *sc); | ||
428 | static int ub_probe_clear_stall(struct ub_dev *sc, int stalled_pipe); | ||
428 | static int ub_probe_lun(struct ub_dev *sc, int lnum); | 429 | static 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 |
453 | static char ub_hostv[UB_MAX_HOSTS]; | 454 | static char ub_hostv[UB_MAX_HOSTS]; |
454 | 455 | ||
456 | #define UB_QLOCK_NUM 5 | ||
457 | static spinlock_t ub_qlockv[UB_QLOCK_NUM]; | ||
458 | static int ub_qlock_next = 0; | ||
459 | |||
455 | static DEFINE_SPINLOCK(ub_lock); /* Locks globals and ->openc */ | 460 | static 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 | */ | ||
640 | static 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 | */ |
1003 | static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | 1024 | static 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 | ||
1117 | static void ub_scsi_dispatch(struct ub_dev *sc) | 1138 | static 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 | ||
1685 | static void ub_reset_enter(struct ub_dev *sc) | 1709 | static 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 | */ | ||
2152 | static 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 | */ |
2123 | static int ub_sync_getmaxlun(struct ub_dev *sc) | 2198 | static 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 = { | |||
2636 | static int __init ub_init(void) | 2707 | static 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 | } |