diff options
Diffstat (limited to 'drivers/block/ub.c')
-rw-r--r-- | drivers/block/ub.c | 78 |
1 files changed, 17 insertions, 61 deletions
diff --git a/drivers/block/ub.c b/drivers/block/ub.c index c688c25992e4..60e9a9457c6b 100644 --- a/drivers/block/ub.c +++ b/drivers/block/ub.c | |||
@@ -10,17 +10,13 @@ | |||
10 | * TODO (sorted by decreasing priority) | 10 | * TODO (sorted by decreasing priority) |
11 | * -- set readonly flag for CDs, set removable flag for CF readers | 11 | * -- set readonly flag for CDs, set removable flag for CF readers |
12 | * -- do inquiry and verify we got a disk and not a tape (for LUN mismatch) | 12 | * -- do inquiry and verify we got a disk and not a tape (for LUN mismatch) |
13 | * -- special case some senses, e.g. 3a/0 -> no media present, reduce retries | ||
14 | * -- verify the 13 conditions and do bulk resets | 13 | * -- verify the 13 conditions and do bulk resets |
15 | * -- kill last_pipe and simply do two-state clearing on both pipes | ||
16 | * -- highmem | 14 | * -- highmem |
17 | * -- move top_sense and work_bcs into separate allocations (if they survive) | 15 | * -- move top_sense and work_bcs into separate allocations (if they survive) |
18 | * for cache purists and esoteric architectures. | 16 | * for cache purists and esoteric architectures. |
19 | * -- Allocate structure for LUN 0 before the first ub_sync_tur, avoid NULL. ? | 17 | * -- Allocate structure for LUN 0 before the first ub_sync_tur, avoid NULL. ? |
20 | * -- prune comments, they are too volumnous | 18 | * -- prune comments, they are too volumnous |
21 | * -- Exterminate P3 printks | ||
22 | * -- Resove XXX's | 19 | * -- Resove XXX's |
23 | * -- Redo "benh's retries", perhaps have spin-up code to handle them. V:D=? | ||
24 | * -- CLEAR, CLR2STS, CLRRS seem to be ripe for refactoring. | 20 | * -- CLEAR, CLR2STS, CLRRS seem to be ripe for refactoring. |
25 | */ | 21 | */ |
26 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
@@ -180,7 +176,6 @@ struct ub_dev; | |||
180 | #define UB_DIR_ILLEGAL2 2 | 176 | #define UB_DIR_ILLEGAL2 2 |
181 | #define UB_DIR_WRITE 3 | 177 | #define UB_DIR_WRITE 3 |
182 | 178 | ||
183 | /* P3 */ | ||
184 | #define UB_DIR_CHAR(c) (((c)==UB_DIR_WRITE)? 'w': \ | 179 | #define UB_DIR_CHAR(c) (((c)==UB_DIR_WRITE)? 'w': \ |
185 | (((c)==UB_DIR_READ)? 'r': 'n')) | 180 | (((c)==UB_DIR_READ)? 'r': 'n')) |
186 | 181 | ||
@@ -669,8 +664,9 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq) | |||
669 | */ | 664 | */ |
670 | n_elem = blk_rq_map_sg(lun->disk->queue, rq, &urq->sgv[0]); | 665 | n_elem = blk_rq_map_sg(lun->disk->queue, rq, &urq->sgv[0]); |
671 | if (n_elem < 0) { | 666 | if (n_elem < 0) { |
667 | /* Impossible, because blk_rq_map_sg should not hit ENOMEM. */ | ||
672 | printk(KERN_INFO "%s: failed request map (%d)\n", | 668 | printk(KERN_INFO "%s: failed request map (%d)\n", |
673 | lun->name, n_elem); /* P3 */ | 669 | lun->name, n_elem); |
674 | goto drop; | 670 | goto drop; |
675 | } | 671 | } |
676 | if (n_elem > UB_MAX_REQ_SG) { /* Paranoia */ | 672 | if (n_elem > UB_MAX_REQ_SG) { /* Paranoia */ |
@@ -824,7 +820,9 @@ static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun, | |||
824 | if (urq->current_try >= 3) | 820 | if (urq->current_try >= 3) |
825 | return -EIO; | 821 | return -EIO; |
826 | urq->current_try++; | 822 | urq->current_try++; |
827 | /* P3 */ printk("%s: dir %c len/act %d/%d " | 823 | |
824 | /* Remove this if anyone complains of flooding. */ | ||
825 | printk(KERN_DEBUG "%s: dir %c len/act %d/%d " | ||
828 | "[sense %x %02x %02x] retry %d\n", | 826 | "[sense %x %02x %02x] retry %d\n", |
829 | sc->name, UB_DIR_CHAR(cmd->dir), cmd->len, cmd->act_len, | 827 | sc->name, UB_DIR_CHAR(cmd->dir), cmd->len, cmd->act_len, |
830 | cmd->key, cmd->asc, cmd->ascq, urq->current_try); | 828 | cmd->key, cmd->asc, cmd->ascq, urq->current_try); |
@@ -1241,8 +1239,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1241 | * to check. But it's not all right if the device | 1239 | * to check. But it's not all right if the device |
1242 | * counts disagree with our counts. | 1240 | * counts disagree with our counts. |
1243 | */ | 1241 | */ |
1244 | /* P3 */ printk("%s: resid %d len %d act %d\n", | ||
1245 | sc->name, len, cmd->len, cmd->act_len); | ||
1246 | goto Bad_End; | 1242 | goto Bad_End; |
1247 | } | 1243 | } |
1248 | 1244 | ||
@@ -1253,7 +1249,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1253 | ub_state_sense(sc, cmd); | 1249 | ub_state_sense(sc, cmd); |
1254 | return; | 1250 | return; |
1255 | case US_BULK_STAT_PHASE: | 1251 | case US_BULK_STAT_PHASE: |
1256 | /* P3 */ printk("%s: status PHASE\n", sc->name); | ||
1257 | goto Bad_End; | 1252 | goto Bad_End; |
1258 | default: | 1253 | default: |
1259 | printk(KERN_INFO "%s: unknown CSW status 0x%x\n", | 1254 | printk(KERN_INFO "%s: unknown CSW status 0x%x\n", |
@@ -1568,16 +1563,14 @@ static void ub_reset_task(void *arg) | |||
1568 | } | 1563 | } |
1569 | 1564 | ||
1570 | if (atomic_read(&sc->poison)) { | 1565 | if (atomic_read(&sc->poison)) { |
1571 | printk(KERN_NOTICE "%s: Not resetting disconnected device\n", | 1566 | ; |
1572 | sc->name); /* P3 This floods. Remove soon. XXX */ | ||
1573 | } else if ((sc->reset & 1) == 0) { | 1567 | } else if ((sc->reset & 1) == 0) { |
1574 | ub_sync_reset(sc); | 1568 | ub_sync_reset(sc); |
1575 | msleep(700); /* usb-storage sleeps 6s (!) */ | 1569 | msleep(700); /* usb-storage sleeps 6s (!) */ |
1576 | ub_probe_clear_stall(sc, sc->recv_bulk_pipe); | 1570 | ub_probe_clear_stall(sc, sc->recv_bulk_pipe); |
1577 | ub_probe_clear_stall(sc, sc->send_bulk_pipe); | 1571 | ub_probe_clear_stall(sc, sc->send_bulk_pipe); |
1578 | } else if (sc->dev->actconfig->desc.bNumInterfaces != 1) { | 1572 | } else if (sc->dev->actconfig->desc.bNumInterfaces != 1) { |
1579 | printk(KERN_NOTICE "%s: Not resetting multi-interface device\n", | 1573 | ; |
1580 | sc->name); /* P3 This floods. Remove soon. XXX */ | ||
1581 | } else { | 1574 | } else { |
1582 | if ((lkr = usb_lock_device_for_reset(sc->dev, sc->intf)) < 0) { | 1575 | if ((lkr = usb_lock_device_for_reset(sc->dev, sc->intf)) < 0) { |
1583 | printk(KERN_NOTICE | 1576 | printk(KERN_NOTICE |
@@ -1651,15 +1644,11 @@ static void ub_revalidate(struct ub_dev *sc, struct ub_lun *lun) | |||
1651 | static int ub_bd_open(struct inode *inode, struct file *filp) | 1644 | static int ub_bd_open(struct inode *inode, struct file *filp) |
1652 | { | 1645 | { |
1653 | struct gendisk *disk = inode->i_bdev->bd_disk; | 1646 | struct gendisk *disk = inode->i_bdev->bd_disk; |
1654 | struct ub_lun *lun; | 1647 | struct ub_lun *lun = disk->private_data; |
1655 | struct ub_dev *sc; | 1648 | struct ub_dev *sc = lun->udev; |
1656 | unsigned long flags; | 1649 | unsigned long flags; |
1657 | int rc; | 1650 | int rc; |
1658 | 1651 | ||
1659 | if ((lun = disk->private_data) == NULL) | ||
1660 | return -ENXIO; | ||
1661 | sc = lun->udev; | ||
1662 | |||
1663 | spin_lock_irqsave(&ub_lock, flags); | 1652 | spin_lock_irqsave(&ub_lock, flags); |
1664 | if (atomic_read(&sc->poison)) { | 1653 | if (atomic_read(&sc->poison)) { |
1665 | spin_unlock_irqrestore(&ub_lock, flags); | 1654 | spin_unlock_irqrestore(&ub_lock, flags); |
@@ -1823,10 +1812,8 @@ static int ub_sync_tur(struct ub_dev *sc, struct ub_lun *lun) | |||
1823 | rc = ub_submit_scsi(sc, cmd); | 1812 | rc = ub_submit_scsi(sc, cmd); |
1824 | spin_unlock_irqrestore(sc->lock, flags); | 1813 | spin_unlock_irqrestore(sc->lock, flags); |
1825 | 1814 | ||
1826 | if (rc != 0) { | 1815 | if (rc != 0) |
1827 | printk("ub: testing ready: submit error (%d)\n", rc); /* P3 */ | ||
1828 | goto err_submit; | 1816 | goto err_submit; |
1829 | } | ||
1830 | 1817 | ||
1831 | wait_for_completion(&compl); | 1818 | wait_for_completion(&compl); |
1832 | 1819 | ||
@@ -1884,20 +1871,16 @@ static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun, | |||
1884 | rc = ub_submit_scsi(sc, cmd); | 1871 | rc = ub_submit_scsi(sc, cmd); |
1885 | spin_unlock_irqrestore(sc->lock, flags); | 1872 | spin_unlock_irqrestore(sc->lock, flags); |
1886 | 1873 | ||
1887 | if (rc != 0) { | 1874 | if (rc != 0) |
1888 | printk("ub: reading capacity: submit error (%d)\n", rc); /* P3 */ | ||
1889 | goto err_submit; | 1875 | goto err_submit; |
1890 | } | ||
1891 | 1876 | ||
1892 | wait_for_completion(&compl); | 1877 | wait_for_completion(&compl); |
1893 | 1878 | ||
1894 | if (cmd->error != 0) { | 1879 | if (cmd->error != 0) { |
1895 | printk("ub: reading capacity: error %d\n", cmd->error); /* P3 */ | ||
1896 | rc = -EIO; | 1880 | rc = -EIO; |
1897 | goto err_read; | 1881 | goto err_read; |
1898 | } | 1882 | } |
1899 | if (cmd->act_len != 8) { | 1883 | if (cmd->act_len != 8) { |
1900 | printk("ub: reading capacity: size %d\n", cmd->act_len); /* P3 */ | ||
1901 | rc = -EIO; | 1884 | rc = -EIO; |
1902 | goto err_read; | 1885 | goto err_read; |
1903 | } | 1886 | } |
@@ -1911,7 +1894,6 @@ static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun, | |||
1911 | case 2048: shift = 2; break; | 1894 | case 2048: shift = 2; break; |
1912 | case 4096: shift = 3; break; | 1895 | case 4096: shift = 3; break; |
1913 | default: | 1896 | default: |
1914 | printk("ub: Bad sector size %u\n", bsize); /* P3 */ | ||
1915 | rc = -EDOM; | 1897 | rc = -EDOM; |
1916 | goto err_inv_bsize; | 1898 | goto err_inv_bsize; |
1917 | } | 1899 | } |
@@ -2023,17 +2005,8 @@ static int ub_sync_getmaxlun(struct ub_dev *sc) | |||
2023 | sc->work_urb.error_count = 0; | 2005 | sc->work_urb.error_count = 0; |
2024 | sc->work_urb.status = 0; | 2006 | sc->work_urb.status = 0; |
2025 | 2007 | ||
2026 | if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) { | 2008 | if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) |
2027 | if (rc == -EPIPE) { | ||
2028 | printk("%s: Stall submitting GetMaxLUN, using 1 LUN\n", | ||
2029 | sc->name); /* P3 */ | ||
2030 | } else { | ||
2031 | printk(KERN_NOTICE | ||
2032 | "%s: Unable to submit GetMaxLUN (%d)\n", | ||
2033 | sc->name, rc); | ||
2034 | } | ||
2035 | goto err_submit; | 2009 | goto err_submit; |
2036 | } | ||
2037 | 2010 | ||
2038 | init_timer(&timer); | 2011 | init_timer(&timer); |
2039 | timer.function = ub_probe_timeout; | 2012 | timer.function = ub_probe_timeout; |
@@ -2046,21 +2019,10 @@ static int ub_sync_getmaxlun(struct ub_dev *sc) | |||
2046 | del_timer_sync(&timer); | 2019 | del_timer_sync(&timer); |
2047 | usb_kill_urb(&sc->work_urb); | 2020 | usb_kill_urb(&sc->work_urb); |
2048 | 2021 | ||
2049 | if ((rc = sc->work_urb.status) < 0) { | 2022 | if ((rc = sc->work_urb.status) < 0) |
2050 | if (rc == -EPIPE) { | ||
2051 | printk("%s: Stall at GetMaxLUN, using 1 LUN\n", | ||
2052 | sc->name); /* P3 */ | ||
2053 | } else { | ||
2054 | printk(KERN_NOTICE | ||
2055 | "%s: Error at GetMaxLUN (%d)\n", | ||
2056 | sc->name, rc); | ||
2057 | } | ||
2058 | goto err_io; | 2023 | goto err_io; |
2059 | } | ||
2060 | 2024 | ||
2061 | if (sc->work_urb.actual_length != 1) { | 2025 | if (sc->work_urb.actual_length != 1) { |
2062 | printk("%s: GetMaxLUN returned %d bytes\n", sc->name, | ||
2063 | sc->work_urb.actual_length); /* P3 */ | ||
2064 | nluns = 0; | 2026 | nluns = 0; |
2065 | } else { | 2027 | } else { |
2066 | if ((nluns = *p) == 55) { | 2028 | if ((nluns = *p) == 55) { |
@@ -2071,8 +2033,6 @@ static int ub_sync_getmaxlun(struct ub_dev *sc) | |||
2071 | if (nluns > UB_MAX_LUNS) | 2033 | if (nluns > UB_MAX_LUNS) |
2072 | nluns = UB_MAX_LUNS; | 2034 | nluns = UB_MAX_LUNS; |
2073 | } | 2035 | } |
2074 | printk("%s: GetMaxLUN returned %d, using %d LUNs\n", sc->name, | ||
2075 | *p, nluns); /* P3 */ | ||
2076 | } | 2036 | } |
2077 | 2037 | ||
2078 | kfree(p); | 2038 | kfree(p); |
@@ -2270,7 +2230,7 @@ static int ub_probe(struct usb_interface *intf, | |||
2270 | * has to succeed, so we clear checks with an additional one here. | 2230 | * has to succeed, so we clear checks with an additional one here. |
2271 | * In any case it's not our business how revaliadation is implemented. | 2231 | * In any case it's not our business how revaliadation is implemented. |
2272 | */ | 2232 | */ |
2273 | for (i = 0; i < 3; i++) { /* Retries for benh's key */ | 2233 | for (i = 0; i < 3; i++) { /* Retries for the schwag key from KS'04 */ |
2274 | if ((rc = ub_sync_tur(sc, NULL)) <= 0) break; | 2234 | if ((rc = ub_sync_tur(sc, NULL)) <= 0) break; |
2275 | if (rc != 0x6) break; | 2235 | if (rc != 0x6) break; |
2276 | msleep(10); | 2236 | msleep(10); |
@@ -2318,7 +2278,6 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum) | |||
2318 | goto err_id; | 2278 | goto err_id; |
2319 | 2279 | ||
2320 | lun->udev = sc; | 2280 | lun->udev = sc; |
2321 | list_add(&lun->link, &sc->luns); | ||
2322 | 2281 | ||
2323 | snprintf(lun->name, 16, DRV_NAME "%c(%d.%d.%d)", | 2282 | snprintf(lun->name, 16, DRV_NAME "%c(%d.%d.%d)", |
2324 | lun->id + 'a', sc->dev->bus->busnum, sc->dev->devnum, lun->num); | 2283 | lun->id + 'a', sc->dev->bus->busnum, sc->dev->devnum, lun->num); |
@@ -2331,7 +2290,6 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum) | |||
2331 | if ((disk = alloc_disk(UB_PARTS_PER_LUN)) == NULL) | 2290 | if ((disk = alloc_disk(UB_PARTS_PER_LUN)) == NULL) |
2332 | goto err_diskalloc; | 2291 | goto err_diskalloc; |
2333 | 2292 | ||
2334 | lun->disk = disk; | ||
2335 | sprintf(disk->disk_name, DRV_NAME "%c", lun->id + 'a'); | 2293 | sprintf(disk->disk_name, DRV_NAME "%c", lun->id + 'a'); |
2336 | sprintf(disk->devfs_name, DEVFS_NAME "/%c", lun->id + 'a'); | 2294 | sprintf(disk->devfs_name, DEVFS_NAME "/%c", lun->id + 'a'); |
2337 | disk->major = UB_MAJOR; | 2295 | disk->major = UB_MAJOR; |
@@ -2353,7 +2311,9 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum) | |||
2353 | blk_queue_max_sectors(q, UB_MAX_SECTORS); | 2311 | blk_queue_max_sectors(q, UB_MAX_SECTORS); |
2354 | blk_queue_hardsect_size(q, lun->capacity.bsize); | 2312 | blk_queue_hardsect_size(q, lun->capacity.bsize); |
2355 | 2313 | ||
2314 | lun->disk = disk; | ||
2356 | q->queuedata = lun; | 2315 | q->queuedata = lun; |
2316 | list_add(&lun->link, &sc->luns); | ||
2357 | 2317 | ||
2358 | set_capacity(disk, lun->capacity.nsec); | 2318 | set_capacity(disk, lun->capacity.nsec); |
2359 | if (lun->removable) | 2319 | if (lun->removable) |
@@ -2366,7 +2326,6 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum) | |||
2366 | err_blkqinit: | 2326 | err_blkqinit: |
2367 | put_disk(disk); | 2327 | put_disk(disk); |
2368 | err_diskalloc: | 2328 | err_diskalloc: |
2369 | list_del(&lun->link); | ||
2370 | ub_id_put(lun->id); | 2329 | ub_id_put(lun->id); |
2371 | err_id: | 2330 | err_id: |
2372 | kfree(lun); | 2331 | kfree(lun); |
@@ -2379,7 +2338,6 @@ static void ub_disconnect(struct usb_interface *intf) | |||
2379 | struct ub_dev *sc = usb_get_intfdata(intf); | 2338 | struct ub_dev *sc = usb_get_intfdata(intf); |
2380 | struct list_head *p; | 2339 | struct list_head *p; |
2381 | struct ub_lun *lun; | 2340 | struct ub_lun *lun; |
2382 | struct gendisk *disk; | ||
2383 | unsigned long flags; | 2341 | unsigned long flags; |
2384 | 2342 | ||
2385 | /* | 2343 | /* |
@@ -2435,9 +2393,7 @@ static void ub_disconnect(struct usb_interface *intf) | |||
2435 | */ | 2393 | */ |
2436 | list_for_each (p, &sc->luns) { | 2394 | list_for_each (p, &sc->luns) { |
2437 | lun = list_entry(p, struct ub_lun, link); | 2395 | lun = list_entry(p, struct ub_lun, link); |
2438 | disk = lun->disk; | 2396 | del_gendisk(lun->disk); |
2439 | if (disk->flags & GENHD_FL_UP) | ||
2440 | del_gendisk(disk); | ||
2441 | /* | 2397 | /* |
2442 | * I wish I could do: | 2398 | * I wish I could do: |
2443 | * set_bit(QUEUE_FLAG_DEAD, &q->queue_flags); | 2399 | * set_bit(QUEUE_FLAG_DEAD, &q->queue_flags); |