^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for USB Mass Storage compliant devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * SCSI layer glue code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Current development and maintenance by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Developed with the assistance of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * (c) 2000 Stephen J. Gowdy (SGowdy@lbl.gov)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Initial work by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * (c) 1999 Michael Gee (michael@linuxspecific.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * This driver is based on the 'USB Mass Storage Class' document. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * describes in detail the protocol used to communicate with such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * devices. Clearly, the designers had SCSI and ATAPI commands in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * mind when they created this document. The commands are all very
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * similar to commands in the SCSI-II and ATAPI specifications.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * It is important to note that in a number of cases this class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * exhibits class-specific exemptions from the USB specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Notably the usage of NAK, STALL and ACK differs from the norm, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * that they are used to communicate wait, failed and OK on commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Also, for certain devices, the interrupt endpoint is used to convey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * status of a command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <scsi/scsi_devinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <scsi/scsi_eh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "usb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/usb/hcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include "scsiglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include "transport.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include "protocol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Vendor IDs for companies that seem to include the READ CAPACITY bug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * in all their devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define VENDOR_ID_NOKIA 0x0421
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define VENDOR_ID_NIKON 0x04b0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define VENDOR_ID_PENTAX 0x0a17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define VENDOR_ID_MOTOROLA 0x22b8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /***********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * Host functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static const char* host_info(struct Scsi_Host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct us_data *us = host_to_us(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return us->scsi_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int slave_alloc (struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct us_data *us = host_to_us(sdev->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Set the INQUIRY transfer length to 36. We don't use any of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * the extra data and many devices choke if asked for more or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * less than 36 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) sdev->inquiry_len = 36;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * Some host controllers may have alignment requirements.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * We'll play it safe by requiring 512-byte alignment always.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* Tell the SCSI layer if we know there is more than one LUN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (us->protocol == USB_PR_BULK && us->max_lun > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) sdev->sdev_bflags |= BLIST_FORCELUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static int slave_configure(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct us_data *us = host_to_us(sdev->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct device *dev = us->pusb_dev->bus->sysdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Many devices have trouble transferring more than 32KB at a time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * while others have trouble with more than 64K. At this time we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * are limiting both to 32K (64 sectores).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (us->fflags & (US_FL_MAX_SECTORS_64 | US_FL_MAX_SECTORS_MIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned int max_sectors = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (le16_to_cpu(us->pusb_dev->descriptor.idVendor) == 0x05e3 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) le16_to_cpu(us->pusb_dev->descriptor.idProduct) == 0x0749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) max_sectors = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (us->fflags & US_FL_MAX_SECTORS_MIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) max_sectors = PAGE_SIZE >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (queue_max_hw_sectors(sdev->request_queue) > max_sectors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) blk_queue_max_hw_sectors(sdev->request_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) max_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) } else if (sdev->type == TYPE_TAPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Tapes need much higher max_sector limits, so just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * raise it to the maximum possible (4 GB / 512) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * let the queue segment size sort out the real limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) blk_queue_max_hw_sectors(sdev->request_queue, 0x7FFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) } else if (us->pusb_dev->speed >= USB_SPEED_SUPER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * USB3 devices will be limited to 2048 sectors. This gives us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * better throughput on most devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) blk_queue_max_hw_sectors(sdev->request_queue, 2048);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * The max_hw_sectors should be up to maximum size of a mapping for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * the device. Otherwise, a DMA API might fail on swiotlb environment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) blk_queue_max_hw_sectors(sdev->request_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) min_t(size_t, queue_max_hw_sectors(sdev->request_queue),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) dma_max_mapping_size(dev) >> SECTOR_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * Some USB host controllers can't do DMA; they have to use PIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * For such controllers we need to make sure the block layer sets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * up bounce buffers in addressable memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (!hcd_uses_dma(bus_to_hcd(us->pusb_dev->bus)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) (bus_to_hcd(us->pusb_dev->bus)->localmem_pool != NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * We can't put these settings in slave_alloc() because that gets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * called before the device type is known. Consequently these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * settings can't be overridden via the scsi devinfo mechanism.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (sdev->type == TYPE_DISK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * Some vendors seem to put the READ CAPACITY bug into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * all their devices -- primarily makers of cell phones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * and digital cameras. Since these devices always use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * flash media and can be expected to have an even number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * of sectors, we will always enable the CAPACITY_HEURISTICS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * flag unless told otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) switch (le16_to_cpu(us->pusb_dev->descriptor.idVendor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) case VENDOR_ID_NOKIA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) case VENDOR_ID_NIKON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) case VENDOR_ID_PENTAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) case VENDOR_ID_MOTOROLA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (!(us->fflags & (US_FL_FIX_CAPACITY |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) US_FL_CAPACITY_OK)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) us->fflags |= US_FL_CAPACITY_HEURISTICS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * Disk-type devices use MODE SENSE(6) if the protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * (SubClass) is Transparent SCSI, otherwise they use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * MODE SENSE(10).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (us->subclass != USB_SC_SCSI && us->subclass != USB_SC_CYP_ATACB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) sdev->use_10_for_ms = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) *Many disks only accept MODE SENSE transfer lengths of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * 192 bytes (that's what Windows uses).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) sdev->use_192_bytes_for_3f = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * Some devices don't like MODE SENSE with page=0x3f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * which is the command used for checking if a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * is write-protected. Now that we tell the sd driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * to do a 192-byte transfer with this command the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * majority of devices work fine, but a few still can't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * handle it. The sd driver will simply assume those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * devices are write-enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (us->fflags & US_FL_NO_WP_DETECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) sdev->skip_ms_page_3f = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * A number of devices have problems with MODE SENSE for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * page x08, so we will skip it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) sdev->skip_ms_page_8 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * Some devices don't handle VPD pages correctly, so skip vpd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * pages if not forced by SCSI layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) sdev->skip_vpd_pages = !sdev->try_vpd_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* Do not attempt to use REPORT SUPPORTED OPERATION CODES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) sdev->no_report_opcodes = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* Do not attempt to use WRITE SAME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) sdev->no_write_same = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * Some disks return the total number of blocks in response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * to READ CAPACITY rather than the highest block number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * If this device makes that mistake, tell the sd driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (us->fflags & US_FL_FIX_CAPACITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) sdev->fix_capacity = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * A few disks have two indistinguishable version, one of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * which reports the correct capacity and the other does not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * The sd driver has to guess which is the case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (us->fflags & US_FL_CAPACITY_HEURISTICS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) sdev->guess_capacity = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* Some devices cannot handle READ_CAPACITY_16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (us->fflags & US_FL_NO_READ_CAPACITY_16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) sdev->no_read_capacity_16 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * Many devices do not respond properly to READ_CAPACITY_16.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * Tell the SCSI layer to try READ_CAPACITY_10 first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * However some USB 3.0 drive enclosures return capacity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * modulo 2TB. Those must use READ_CAPACITY_16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (!(us->fflags & US_FL_NEEDS_CAP16))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) sdev->try_rc_10_first = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * assume SPC3 or latter devices support sense size > 18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * unless US_FL_BAD_SENSE quirk is specified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (sdev->scsi_level > SCSI_SPC_2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) !(us->fflags & US_FL_BAD_SENSE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) us->fflags |= US_FL_SANE_SENSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * USB-IDE bridges tend to report SK = 0x04 (Non-recoverable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * Hardware Error) when any low-level error occurs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * recoverable or not. Setting this flag tells the SCSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * midlayer to retry such commands, which frequently will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * succeed and fix the error. The worst this can lead to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * is an occasional series of retries that will all fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) sdev->retry_hwerror = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * USB disks should allow restart. Some drives spin down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * automatically, requiring a START-STOP UNIT command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) sdev->allow_restart = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * Some USB cardreaders have trouble reading an sdcard's last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * sector in a larger then 1 sector read, since the performance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * impact is negligible we set this flag for all USB disks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) sdev->last_sector_bug = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * Enable last-sector hacks for single-target devices using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * the Bulk-only transport, unless we already know the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * capacity will be decremented or is correct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (!(us->fflags & (US_FL_FIX_CAPACITY | US_FL_CAPACITY_OK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) US_FL_SCM_MULT_TARG)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) us->protocol == USB_PR_BULK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) us->use_last_sector_hacks = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* Check if write cache default on flag is set or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (us->fflags & US_FL_WRITE_CACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) sdev->wce_default_on = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* A few buggy USB-ATA bridges don't understand FUA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (us->fflags & US_FL_BROKEN_FUA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) sdev->broken_fua = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /* Some even totally fail to indicate a cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (us->fflags & US_FL_ALWAYS_SYNC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /* don't read caching information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) sdev->skip_ms_page_8 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) sdev->skip_ms_page_3f = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* assume sync is needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) sdev->wce_default_on = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * Non-disk-type devices don't need to ignore any pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * or to force 192-byte transfer lengths for MODE SENSE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * But they do need to use MODE SENSE(10).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) sdev->use_10_for_ms = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* Some (fake) usb cdrom devices don't like READ_DISC_INFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (us->fflags & US_FL_NO_READ_DISC_INFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) sdev->no_read_disc_info = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * The CB and CBI transports have no way to pass LUN values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * other than the bits in the second byte of a CDB. But those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * bits don't get set to the LUN value if the device reports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * scsi_level == 0 (UNKNOWN). Hence such devices must necessarily
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * be single-LUN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_CBI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) sdev->scsi_level == SCSI_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) us->max_lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * Some devices choke when they receive a PREVENT-ALLOW MEDIUM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * REMOVAL command, so suppress those commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (us->fflags & US_FL_NOT_LOCKABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) sdev->lockable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * this is to satisfy the compiler, tho I don't think the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * return code is ever checked anywhere.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int target_alloc(struct scsi_target *starget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct us_data *us = host_to_us(dev_to_shost(starget->dev.parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * Some USB drives don't support REPORT LUNS, even though they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * report a SCSI revision level above 2. Tell the SCSI layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * not to issue that command; it will perform a normal sequential
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * scan instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) starget->no_report_luns = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * The UFI spec treats the Peripheral Qualifier bits in an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * INQUIRY result as reserved and requires devices to set them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * to 0. However the SCSI spec requires these bits to be set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * to 3 to indicate when a LUN is not present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * Let the scanning code know if this target merely sets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * Peripheral Device Type to 0x1f to indicate no LUN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (us->subclass == USB_SC_UFI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) starget->pdt_1f_for_no_lun = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /* queue a command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) /* This is always called with scsi_lock(host) held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static int queuecommand_lck(struct scsi_cmnd *srb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) void (*done)(struct scsi_cmnd *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct us_data *us = host_to_us(srb->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* check for state-transition errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (us->srb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) dev_err(&us->pusb_intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) "Error in %s: us->srb = %p\n", __func__, us->srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return SCSI_MLQUEUE_HOST_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) /* fail the command if we are disconnecting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) usb_stor_dbg(us, "Fail command during disconnect\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) srb->result = DID_NO_CONNECT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) done(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if ((us->fflags & US_FL_NO_ATA_1X) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) (srb->cmnd[0] == ATA_12 || srb->cmnd[0] == ATA_16)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) memcpy(srb->sense_buffer, usb_stor_sense_invalidCDB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) sizeof(usb_stor_sense_invalidCDB));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) srb->result = SAM_STAT_CHECK_CONDITION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) done(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* enqueue the command and wake up the control thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) srb->scsi_done = done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) us->srb = srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) complete(&us->cmnd_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static DEF_SCSI_QCMD(queuecommand)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /***********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) * Error handling functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) /* Command timeout and abort */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static int command_abort(struct scsi_cmnd *srb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct us_data *us = host_to_us(srb->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) usb_stor_dbg(us, "%s called\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * us->srb together with the TIMED_OUT, RESETTING, and ABORTING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * bits are protected by the host lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) scsi_lock(us_to_host(us));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /* Is this command still active? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (us->srb != srb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) scsi_unlock(us_to_host(us));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) usb_stor_dbg(us, "-- nothing to abort\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * Set the TIMED_OUT bit. Also set the ABORTING bit, but only if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * a device reset isn't already in progress (to avoid interfering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * with the reset). Note that we must retain the host lock while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * calling usb_stor_stop_transport(); otherwise it might interfere
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * with an auto-reset that begins as soon as we release the lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) set_bit(US_FLIDX_TIMED_OUT, &us->dflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (!test_bit(US_FLIDX_RESETTING, &us->dflags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) set_bit(US_FLIDX_ABORTING, &us->dflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) usb_stor_stop_transport(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) scsi_unlock(us_to_host(us));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) /* Wait for the aborted command to finish */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) wait_for_completion(&us->notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) * This invokes the transport reset mechanism to reset the state of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static int device_reset(struct scsi_cmnd *srb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct us_data *us = host_to_us(srb->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) usb_stor_dbg(us, "%s called\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /* lock the device pointers and do the reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) mutex_lock(&(us->dev_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) result = us->transport_reset(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) mutex_unlock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return result < 0 ? FAILED : SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /* Simulate a SCSI bus reset by resetting the device's USB port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static int bus_reset(struct scsi_cmnd *srb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct us_data *us = host_to_us(srb->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) usb_stor_dbg(us, "%s called\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) result = usb_stor_port_reset(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) return result < 0 ? FAILED : SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * Report a driver-initiated device reset to the SCSI layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * Calling this for a SCSI-initiated reset is unnecessary but harmless.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * The caller must own the SCSI host lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) void usb_stor_report_device_reset(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct Scsi_Host *host = us_to_host(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) scsi_report_device_reset(host, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (us->fflags & US_FL_SCM_MULT_TARG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) for (i = 1; i < host->max_id; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) scsi_report_device_reset(host, 0, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * Report a driver-initiated bus reset to the SCSI layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * Calling this for a SCSI-initiated reset is unnecessary but harmless.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * The caller must not own the SCSI host lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) void usb_stor_report_bus_reset(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct Scsi_Host *host = us_to_host(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) scsi_lock(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) scsi_report_bus_reset(host, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) scsi_unlock(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /***********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * /proc/scsi/ functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) static int write_info(struct Scsi_Host *host, char *buffer, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /* if someone is sending us data, just throw it away */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) return length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) static int show_info (struct seq_file *m, struct Scsi_Host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct us_data *us = host_to_us(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) const char *string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* print the controller name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) seq_printf(m, " Host scsi%d: usb-storage\n", host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /* print product, vendor, and serial number strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (us->pusb_dev->manufacturer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) string = us->pusb_dev->manufacturer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) else if (us->unusual_dev->vendorName)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) string = us->unusual_dev->vendorName;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) string = "Unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) seq_printf(m, " Vendor: %s\n", string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (us->pusb_dev->product)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) string = us->pusb_dev->product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) else if (us->unusual_dev->productName)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) string = us->unusual_dev->productName;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) string = "Unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) seq_printf(m, " Product: %s\n", string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (us->pusb_dev->serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) string = us->pusb_dev->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) string = "None";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) seq_printf(m, "Serial Number: %s\n", string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) /* show the protocol and transport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) seq_printf(m, " Protocol: %s\n", us->protocol_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) seq_printf(m, " Transport: %s\n", us->transport_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /* show the device flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) seq_printf(m, " Quirks:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) #define US_FLAG(name, value) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (us->fflags & value) seq_printf(m, " " #name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) US_DO_ALL_FLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) #undef US_FLAG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) /***********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * Sysfs interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) /* Output routine for the sysfs max_sectors file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) static ssize_t max_sectors_show(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) struct scsi_device *sdev = to_scsi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return sprintf(buf, "%u\n", queue_max_hw_sectors(sdev->request_queue));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /* Input routine for the sysfs max_sectors file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static ssize_t max_sectors_store(struct device *dev, struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) struct scsi_device *sdev = to_scsi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) unsigned short ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (sscanf(buf, "%hu", &ms) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) blk_queue_max_hw_sectors(sdev->request_queue, ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static DEVICE_ATTR_RW(max_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static struct device_attribute *sysfs_device_attr_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) &dev_attr_max_sectors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) * this defines our host template, with which we'll allocate hosts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static const struct scsi_host_template usb_stor_host_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) /* basic userland interface stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) .name = "usb-storage",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) .proc_name = "usb-storage",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) .show_info = show_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) .write_info = write_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) .info = host_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) /* command interface -- queued only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) .queuecommand = queuecommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) /* error and abort handlers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) .eh_abort_handler = command_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) .eh_device_reset_handler = device_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) .eh_bus_reset_handler = bus_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /* queue commands only, only one command per LUN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) .can_queue = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /* unknown initiator id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) .this_id = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) .slave_alloc = slave_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) .slave_configure = slave_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) .target_alloc = target_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /* lots of sg segments can be handled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) .sg_tablesize = SG_MAX_SEGMENTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * Limit the total size of a transfer to 120 KB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * Some devices are known to choke with anything larger. It seems like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * the problem stems from the fact that original IDE controllers had
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * only an 8-bit register to hold the number of sectors in one transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) * and even those couldn't handle a full 256 sectors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) * Because we want to make sure we interoperate with as many devices as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) * possible, we will maintain a 240 sector transfer size limit for USB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) * Mass Storage devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * Tests show that other operating have similar limits with Microsoft
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * Windows 7 limiting transfers to 128 sectors for both USB2 and USB3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) * and Apple Mac OS X 10.11 limiting transfers to 256 sectors for USB2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) * and 2048 for USB3 devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) .max_sectors = 240,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) /* emulated HBA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) .emulated = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) /* we do our own delay after a device or bus reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) .skip_settle_delay = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) /* sysfs device attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) .sdev_attrs = sysfs_device_attr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) /* module management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) .module = THIS_MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) void usb_stor_host_template_init(struct scsi_host_template *sht,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) const char *name, struct module *owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) *sht = usb_stor_host_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) sht->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) sht->proc_name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) sht->module = owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) EXPORT_SYMBOL_GPL(usb_stor_host_template_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) /* To Report "Illegal Request: Invalid Field in CDB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) unsigned char usb_stor_sense_invalidCDB[18] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) [0] = 0x70, /* current error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) [2] = ILLEGAL_REQUEST, /* Illegal Request = 0x05 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) [7] = 0x0a, /* additional length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) [12] = 0x24 /* Invalid Field in CDB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) EXPORT_SYMBOL_GPL(usb_stor_sense_invalidCDB);