From e28e2f2f7c42e5b9dd4c965a0245267e44a8a7ae Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sun, 12 Oct 2014 12:19:40 +0200 Subject: uas: Make uas work with blk-mq With uas over usb-3 the tags inside the uas iu-s must match the usb-3 stream ids, and those go from 1 - qdepth. Before blk-mq calling scsi_activate_tcq(sdev, qdepth) guaranteed that we would only get cmnd->request->tag from 0 - (qdepth - 1), and we used those as uas-tags / stream-ids. With blk-mq however we are guaranteed to never get more then qdepth commands queued at the same time, but the cmnd->request->tag values may be much larger, which breaks uas. This commit fixes this by generating uas tags in the 1 - qdepth range ourselves instead of using cmnd->request->tag. While touching all involved code anyways also rename the uas_cmd_info stream field to uas_tag, because when using uas over usb-2 streams are not used. Cc: Christoph Hellwig Reported-by: Douglas Gilbert Signed-off-by: Hans de Goede Reviewed-by: Christoph Hellwig -- Changes in v2: -Remove ".disable_blk_mq = true" from uas_host_template Changes in v3: -Rebased on top of Linus' current master branch Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/uas.c | 64 +++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 41 deletions(-) (limited to 'drivers/usb/storage') diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 89b2434..004ebc1 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -66,7 +66,7 @@ enum { /* Overrides scsi_pointer */ struct uas_cmd_info { unsigned int state; - unsigned int stream; + unsigned int uas_tag; struct urb *cmd_urb; struct urb *data_in_urb; struct urb *data_out_urb; @@ -173,30 +173,15 @@ static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd) cmnd->result = sense_iu->status; } -/* - * scsi-tags go from 0 - (nr_tags - 1), uas tags need to match stream-ids, - * which go from 1 - nr_streams. And we use 1 for untagged commands. - */ -static int uas_get_tag(struct scsi_cmnd *cmnd) -{ - int tag; - - if (blk_rq_tagged(cmnd->request)) - tag = cmnd->request->tag + 2; - else - tag = 1; - - return tag; -} - static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *prefix, int status) { struct uas_cmd_info *ci = (void *)&cmnd->SCp; + struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; scmd_printk(KERN_INFO, cmnd, - "%s %d tag %d inflight:%s%s%s%s%s%s%s%s%s%s%s%s ", - prefix, status, uas_get_tag(cmnd), + "%s %d uas-tag %d inflight:%s%s%s%s%s%s%s%s%s%s%s%s ", + prefix, status, cmdinfo->uas_tag, (ci->state & SUBMIT_STATUS_URB) ? " s-st" : "", (ci->state & ALLOC_DATA_IN_URB) ? " a-in" : "", (ci->state & SUBMIT_DATA_IN_URB) ? " s-in" : "", @@ -242,7 +227,7 @@ static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller) DATA_OUT_URB_INFLIGHT | COMMAND_ABORTED)) return -EBUSY; - devinfo->cmnd[uas_get_tag(cmnd) - 1] = NULL; + devinfo->cmnd[cmdinfo->uas_tag - 1] = NULL; uas_free_unsubmitted_urbs(cmnd); cmnd->scsi_done(cmnd); return 0; @@ -289,7 +274,7 @@ static void uas_stat_cmplt(struct urb *urb) idx = be16_to_cpup(&iu->tag) - 1; if (idx >= MAX_CMNDS || !devinfo->cmnd[idx]) { dev_err(&urb->dev->dev, - "stat urb: no pending cmd for tag %d\n", idx + 1); + "stat urb: no pending cmd for uas-tag %d\n", idx + 1); goto out; } @@ -427,7 +412,8 @@ static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp, goto out; usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length, uas_data_cmplt, cmnd); - urb->stream_id = cmdinfo->stream; + if (devinfo->use_streams) + urb->stream_id = cmdinfo->uas_tag; urb->num_sgs = udev->bus->sg_tablesize ? sdb->table.nents : 0; urb->sg = sdb->table.sgl; out: @@ -451,7 +437,8 @@ static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp, usb_fill_bulk_urb(urb, udev, devinfo->status_pipe, iu, sizeof(*iu), uas_stat_cmplt, cmnd->device->host); - urb->stream_id = cmdinfo->stream; + if (devinfo->use_streams) + urb->stream_id = cmdinfo->uas_tag; urb->transfer_flags |= URB_FREE_BUFFER; out: return urb; @@ -465,6 +452,7 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp, { struct usb_device *udev = devinfo->udev; struct scsi_device *sdev = cmnd->device; + struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; struct urb *urb = usb_alloc_urb(0, gfp); struct command_iu *iu; int len; @@ -481,7 +469,7 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp, goto free; iu->iu_id = IU_ID_COMMAND; - iu->tag = cpu_to_be16(uas_get_tag(cmnd)); + iu->tag = cpu_to_be16(cmdinfo->uas_tag); iu->prio_attr = UAS_SIMPLE_TAG; iu->len = len; int_to_scsilun(sdev->lun, &iu->lun); @@ -608,8 +596,7 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd, struct uas_dev_info *devinfo = sdev->hostdata; struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; unsigned long flags; - unsigned int stream; - int err; + int idx, err; BUILD_BUG_ON(sizeof(struct uas_cmd_info) > sizeof(struct scsi_pointer)); @@ -635,8 +622,12 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd, return 0; } - stream = uas_get_tag(cmnd); - if (devinfo->cmnd[stream - 1]) { + /* Find a free uas-tag */ + for (idx = 0; idx < devinfo->qdepth; idx++) { + if (!devinfo->cmnd[idx]) + break; + } + if (idx == devinfo->qdepth) { spin_unlock_irqrestore(&devinfo->lock, flags); return SCSI_MLQUEUE_DEVICE_BUSY; } @@ -644,7 +635,7 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd, cmnd->scsi_done = done; memset(cmdinfo, 0, sizeof(*cmdinfo)); - cmdinfo->stream = stream; + cmdinfo->uas_tag = idx + 1; /* uas-tag == usb-stream-id, so 1 based */ cmdinfo->state = SUBMIT_STATUS_URB | ALLOC_CMD_URB | SUBMIT_CMD_URB; switch (cmnd->sc_data_direction) { @@ -659,10 +650,8 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd, break; } - if (!devinfo->use_streams) { + if (!devinfo->use_streams) cmdinfo->state &= ~(SUBMIT_DATA_IN_URB | SUBMIT_DATA_OUT_URB); - cmdinfo->stream = 0; - } err = uas_submit_urbs(cmnd, devinfo, GFP_ATOMIC); if (err) { @@ -674,7 +663,7 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd, uas_add_work(cmdinfo); } - devinfo->cmnd[stream - 1] = cmnd; + devinfo->cmnd[idx] = cmnd; spin_unlock_irqrestore(&devinfo->lock, flags); return 0; } @@ -702,7 +691,7 @@ static int uas_eh_abort_handler(struct scsi_cmnd *cmnd) cmdinfo->state |= COMMAND_ABORTED; /* Drop all refs to this cmnd, kill data urbs to break their ref */ - devinfo->cmnd[uas_get_tag(cmnd) - 1] = NULL; + devinfo->cmnd[cmdinfo->uas_tag - 1] = NULL; if (cmdinfo->state & DATA_IN_URB_INFLIGHT) data_in_urb = usb_get_urb(cmdinfo->data_in_urb); if (cmdinfo->state & DATA_OUT_URB_INFLIGHT) @@ -818,13 +807,6 @@ static struct scsi_host_template uas_host_template = { .cmd_per_lun = 1, /* until we override it */ .skip_settle_delay = 1, .ordered_tag = 1, - - /* - * The uas drivers expects tags not to be bigger than the maximum - * per-device queue depth, which is not true with the blk-mq tag - * allocator. - */ - .disable_blk_mq = true, }; #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ -- cgit v1.1 From e5283626f5d535c54cbcc3ec4a60a4746578a4c2 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Mon, 20 Oct 2014 20:51:00 -0700 Subject: usb: storage: Convert usb_stor_dbg to return void No caller or macro uses the return value so make it void. Signed-off-by: Joe Perches Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/debug.c | 7 ++----- drivers/usb/storage/debug.h | 10 ++++++---- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'drivers/usb/storage') diff --git a/drivers/usb/storage/debug.c b/drivers/usb/storage/debug.c index e08f647..05bc379 100644 --- a/drivers/usb/storage/debug.c +++ b/drivers/usb/storage/debug.c @@ -179,17 +179,14 @@ void usb_stor_show_sense(const struct us_data *us, US_DEBUGPX("\n"); } -int usb_stor_dbg(const struct us_data *us, const char *fmt, ...) +void usb_stor_dbg(const struct us_data *us, const char *fmt, ...) { va_list args; - int r; va_start(args, fmt); - r = dev_vprintk_emit(7, &us->pusb_dev->dev, fmt, args); + dev_vprintk_emit(7, &us->pusb_dev->dev, fmt, args); va_end(args); - - return r; } EXPORT_SYMBOL_GPL(usb_stor_dbg); diff --git a/drivers/usb/storage/debug.h b/drivers/usb/storage/debug.h index b1273f0..f525203 100644 --- a/drivers/usb/storage/debug.h +++ b/drivers/usb/storage/debug.h @@ -50,15 +50,17 @@ void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb); void usb_stor_show_sense(const struct us_data *us, unsigned char key, unsigned char asc, unsigned char ascq); -__printf(2, 3) int usb_stor_dbg(const struct us_data *us, - const char *fmt, ...); +__printf(2, 3) void usb_stor_dbg(const struct us_data *us, + const char *fmt, ...); #define US_DEBUGPX(fmt, ...) printk(fmt, ##__VA_ARGS__) #define US_DEBUG(x) x #else __printf(2, 3) -static inline int _usb_stor_dbg(const struct us_data *us, - const char *fmt, ...) {return 1;} +static inline void _usb_stor_dbg(const struct us_data *us, + const char *fmt, ...) +{ +} #define usb_stor_dbg(us, fmt, ...) \ do { if (0) _usb_stor_dbg(us, fmt, ##__VA_ARGS__); } while (0) #define US_DEBUGPX(fmt, ...) \ -- cgit v1.1 From 55dc68c012bf056880c03d9f6eb34c00880f9e88 Mon Sep 17 00:00:00 2001 From: Mark Knibbs Date: Tue, 4 Nov 2014 13:00:22 +0000 Subject: USB: storage: Reject bogus max LUN values Some mass storage devices return a bogus value in response to a Get Max LUN request. The Iomega Jaz USB Adapter responds with 0x10, hence my recent patch to use the US_FL_SINGLE_LUN quirk for it. The USB MSC Bulk Only Transport document says "The device shall return one byte of data that contains the maximum LUN supported by the device." Since the LUN field in the command block wrapper is only 4 bits wide, it might be helpful to report too-large LUN values in the kernel log, and assume max LUN is actually 0. That could get some devices which currently need the US_FL_SINGLE_LUN quirk to work. Signed-off-by: Mark Knibbs Acked-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/transport.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'drivers/usb/storage') diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c index 22c7d43..d614dee 100644 --- a/drivers/usb/storage/transport.c +++ b/drivers/usb/storage/transport.c @@ -1035,9 +1035,20 @@ int usb_stor_Bulk_max_lun(struct us_data *us) usb_stor_dbg(us, "GetMaxLUN command result is %d, data is %d\n", result, us->iobuf[0]); - /* if we have a successful request, return the result */ - if (result > 0) - return us->iobuf[0]; + /* + * If we have a successful request, return the result if valid. The + * CBW LUN field is 4 bits wide, so the value reported by the device + * should fit into that. + */ + if (result > 0) { + if (us->iobuf[0] < 16) { + return us->iobuf[0]; + } else { + dev_info(&us->pusb_intf->dev, + "Max LUN %d is not valid, using 0 instead", + us->iobuf[0]); + } + } /* * Some devices don't like GetMaxLUN. They may STALL the control -- cgit v1.1 From eab77694098469d80e1186fdda9f965045730a3e Mon Sep 17 00:00:00 2001 From: Mark Knibbs Date: Fri, 7 Nov 2014 22:02:19 +0000 Subject: storage: Enable multi-target mode as vendor driver does for SCM eUSCSI bridge usb_stor_euscsi_init() enables multi-target mode for SCM eUSB SCSI bridge devices. The control message it sends has wLength = 1 and the byte sent is 0x01. While that works, the SCM Windows driver does it with wLength = 0. We may as well match what the SCM driver does. Signed-off-by: Mark Knibbs Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/initializers.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/usb/storage') diff --git a/drivers/usb/storage/initializers.c b/drivers/usb/storage/initializers.c index 73f125e..31fa2e9 100644 --- a/drivers/usb/storage/initializers.c +++ b/drivers/usb/storage/initializers.c @@ -49,10 +49,9 @@ int usb_stor_euscsi_init(struct us_data *us) int result; usb_stor_dbg(us, "Attempting to init eUSCSI bridge...\n"); - us->iobuf[0] = 0x1; result = usb_stor_control_msg(us, us->send_ctrl_pipe, 0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR, - 0x01, 0x0, us->iobuf, 0x1, 5 * HZ); + 0x01, 0x0, NULL, 0x0, 5 * HZ); usb_stor_dbg(us, "-- result is %d\n", result); return 0; -- cgit v1.1 From 646a3843177b2ae0cb81813ec0f830fe64e81bf1 Mon Sep 17 00:00:00 2001 From: Mark Knibbs Date: Sat, 8 Nov 2014 21:39:55 +0000 Subject: storage: Fix bus scan and multi-LUN support for SCM eUSCSI devices This patch does two things for SCM eUSCSI USB-SCSI converters: 1. SCM eUSCSI bridge devices are hard-wired to use SCSI ID 7. On connecting the converter, access to that ID is attempted during the bus scan. Asking the converter to issue INQUIRY commands to itself isn't very polite and wastes time. Set this_id to 7 so __scsi_scan_target() skips it in the scan. 2. Enable multi-LUN support. eUSCSI devices don't support Get Max LUN requests, returning an error (-32). [Different targets could have different numbers of LUNs, so it wouldn't make sense to return a particular value in response to Get Max LUN.] usb_stor_scan_dwork() does this: /* For bulk-only devices, determine the max LUN value */ if (us->protocol == USB_PR_BULK && !(us->fflags & US_FL_SINGLE_LUN)) { mutex_lock(&us->dev_mutex); us->max_lun = usb_stor_Bulk_max_lun(us); mutex_unlock(&us->dev_mutex); It avoids calling usb_stor_Bulk_max_lun() if US_FL_SINGLE_LUN, but not for US_FL_SCM_MULT_TARG. Since usb_stor_Bulk_max_lun() returns 0 in the error case, us->max_lun was always set to 0. [If the user doesn't want multi-LUN support (perhaps there are SCSI devices which respond to commands on all LUNs?), the US_FL_SINGLE_LUN quirk can be specified on the kernel command line.] Signed-off-by: Mark Knibbs Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/usb.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'drivers/usb/storage') diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 9d66ce6..d468d02 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -884,7 +884,9 @@ static void usb_stor_scan_dwork(struct work_struct *work) dev_dbg(dev, "starting scan\n"); /* For bulk-only devices, determine the max LUN value */ - if (us->protocol == USB_PR_BULK && !(us->fflags & US_FL_SINGLE_LUN)) { + if (us->protocol == USB_PR_BULK && + !(us->fflags & US_FL_SINGLE_LUN) && + !(us->fflags & US_FL_SCM_MULT_TARG)) { mutex_lock(&us->dev_mutex); us->max_lun = usb_stor_Bulk_max_lun(us); mutex_unlock(&us->dev_mutex); @@ -983,21 +985,31 @@ int usb_stor_probe2(struct us_data *us) usb_stor_dbg(us, "Transport: %s\n", us->transport_name); usb_stor_dbg(us, "Protocol: %s\n", us->protocol_name); + if (us->fflags & US_FL_SCM_MULT_TARG) { + /* + * SCM eUSCSI bridge devices can have different numbers + * of LUNs on different targets; allow all to be probed. + */ + us->max_lun = 7; + /* The eUSCSI itself has ID 7, so avoid scanning that */ + us_to_host(us)->this_id = 7; + /* max_id is 8 initially, so no need to set it here */ + } else { + /* In the normal case there is only a single target */ + us_to_host(us)->max_id = 1; + /* + * Like Windows, we won't store the LUN bits in CDB[1] for + * SCSI-2 devices using the Bulk-Only transport (even though + * this violates the SCSI spec). + */ + if (us->transport == usb_stor_Bulk_transport) + us_to_host(us)->no_scsi2_lun_in_cdb = 1; + } + /* fix for single-lun devices */ if (us->fflags & US_FL_SINGLE_LUN) us->max_lun = 0; - if (!(us->fflags & US_FL_SCM_MULT_TARG)) - us_to_host(us)->max_id = 1; - - /* - * Like Windows, we won't store the LUN bits in CDB[1] for SCSI-2 - * devices using the Bulk-Only transport (even though this violates - * the SCSI spec). - */ - if (us->transport == usb_stor_Bulk_transport) - us_to_host(us)->no_scsi2_lun_in_cdb = 1; - /* Find the endpoints and calculate pipe values */ result = get_pipes(us); if (result) -- cgit v1.1