From patchwork Wed Sep 2 00:09:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 258692 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D98AC433E6 for ; Wed, 2 Sep 2020 00:09:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6BB5215A4 for ; Wed, 2 Sep 2020 00:09:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dk3KgwNF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726292AbgIBAJt (ORCPT ); Tue, 1 Sep 2020 20:09:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbgIBAJs (ORCPT ); Tue, 1 Sep 2020 20:09:48 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B358C061244 for ; Tue, 1 Sep 2020 17:09:47 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id q1so1449444pjd.1 for ; Tue, 01 Sep 2020 17:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KmQZ2wdfhO0u5IWuWl+x6FQWkkltxJLGpdVuQWt5oHw=; b=Dk3KgwNFTVpSdGefXhZtJtH3Vda0dC/6NJVIR+DlkZ8oB2hJ0li5a3wCifRJcdjfV1 EnL6ORqTQ9jkstyEBNiH8d6W72oGWDo6X/mmsUjRWuxeaAYzJ0E3h1eqb1AAhGcS1b+D e0OTzzm4ZoDa9YIhLzXft3k2bAV5NE/SvI47YN0dP4EGwCF/XViHArwfllU/SvB/X1wb 0DkyGC70HGf1YZZjJPz/yI/uAh2it5fO38M2XeDP8T2fsHkUyzX9BJvc17g1nUsGIapY +bqQHGVtgxnNQZ/nQkAZQjBcMlWDPWV7PQaoQzX8jdF5Br4SidafBtWfiGYlpvpTf/mT Duag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KmQZ2wdfhO0u5IWuWl+x6FQWkkltxJLGpdVuQWt5oHw=; b=N8mpMK49GL3f8z9lsuTw9oBwWoF1+bPUnNpZRgLyYor2cNHFReTjJwOIeLnFWFQ/jE tLHZ/sSUhCMHSbY1bd4KIyOnLF1dsru/cRpKrdCwrjWj6ws4HT+UGw4NC7D0LvmPz+G/ sdqcy3vThglY5ZTTVgHb9ZBdMqyPa7pMk+oLi+Ocxay9do07FyYagL+neOb/HTQK+7Nq +UoFMv/Z6YQh3x9Ayb6yochmkZYNDcmxnosdoJgVxxY2Rp8yUEp4oLLkEEhnXuYSZGoB tH051BnJzmzEiitP1tX6PV6N+ZFRcF5b/oYb33F6qaULIfnMQrV8eL0f+T/gaezLxxR5 PIaQ== X-Gm-Message-State: AOAM531H6YI2C/G6eH4CsczyP+jPJwPont2YnmAgowZAs1txOJYzTkET JwF5ywLdiYqlT3vp71QoD6IlJrKis48= X-Google-Smtp-Source: ABdhPJwqhgljx/eTSJD722PxeNGnmx5m2aVdF/asAaGTRtUURUGj8urShMhmqeqzDLwUoPKAVq6VJQ== X-Received: by 2002:a17:90b:138a:: with SMTP id hr10mr4015634pjb.8.1599005386533; Tue, 01 Sep 2020 17:09:46 -0700 (PDT) Received: from localhost.localdomain ([161.81.62.213]) by smtp.gmail.com with ESMTPSA id d77sm3352630pfd.121.2020.09.01.17.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 17:09:45 -0700 (PDT) From: Tom Yan To: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, stern@rowland.harvard.edu, arnd@arndb.de Cc: cyrozap@gmail.com, yoshihiro.shimoda.uh@renesas.com, Tom Yan Subject: [PATCH v2 1/2] uas: bump hw_max_sectors to 2048 blocks for SS or faster drives Date: Wed, 2 Sep 2020 08:09:36 +0800 Message-Id: <20200902000937.2204-1-tom.ty89@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901145535.GC587030@rowland.harvard.edu> References: <20200901145535.GC587030@rowland.harvard.edu> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There's no reason for uas to use a smaller value of max_sectors than usb-storage. Also copying the dma max mapping size clamping from usb-storage. Signed-off-by: Tom Yan --- drivers/usb/storage/uas.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 08f9296431e9..813c49914b9a 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -827,11 +827,6 @@ static int uas_slave_alloc(struct scsi_device *sdev) */ blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1)); - if (devinfo->flags & US_FL_MAX_SECTORS_64) - blk_queue_max_hw_sectors(sdev->request_queue, 64); - else if (devinfo->flags & US_FL_MAX_SECTORS_240) - blk_queue_max_hw_sectors(sdev->request_queue, 240); - return 0; } @@ -839,6 +834,20 @@ static int uas_slave_configure(struct scsi_device *sdev) { struct uas_dev_info *devinfo = sdev->hostdata; + struct us_data *us = host_to_us(sdev->host); + struct device *dev = us->pusb_dev->bus->sysdev; + + if (devinfo->flags & US_FL_MAX_SECTORS_64) + blk_queue_max_hw_sectors(sdev->request_queue, 64); + else if (devinfo->flags & US_FL_MAX_SECTORS_240) + blk_queue_max_hw_sectors(sdev->request_queue, 240); + else if (us->pusb_dev->speed >= USB_SPEED_SUPER) + blk_queue_max_hw_sectors(sdev->request_queue, 2048); + + blk_queue_max_hw_sectors(sdev->request_queue, + min_t(size_t, queue_max_hw_sectors(sdev->request_queue), + dma_max_mapping_size(dev) >> SECTOR_SHIFT)); + if (devinfo->flags & US_FL_NO_REPORT_OPCODES) sdev->no_report_opcodes = 1; From patchwork Wed Sep 2 00:09:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 297773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87BC8C433E7 for ; Wed, 2 Sep 2020 00:09:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AC1820E65 for ; Wed, 2 Sep 2020 00:09:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CS7M0br4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726493AbgIBAJx (ORCPT ); Tue, 1 Sep 2020 20:09:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbgIBAJv (ORCPT ); Tue, 1 Sep 2020 20:09:51 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23691C061244 for ; Tue, 1 Sep 2020 17:09:51 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id j11so1386182plk.9 for ; Tue, 01 Sep 2020 17:09:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aCgtEkMZDS4B1B7GtT5isDDP0NFbvrH7N+BMafLPBbs=; b=CS7M0br4uxLlYTHaFR8ja9qHEhsymx9c50luvM0MexA1+EIt8TcPfy15QbHEB19DWY gCvEaLmqpzm8XE8MEYDy2Th9DS2Fs0cW++AoGWLsTada6aK8gKXeE4eQJReA+2U3GZqg Y6lNI1a2m+ucu73kFJFppU2UNWdr1W5P2RoIpt53AQLhHNRdc/ASwrWYoer9xwZPUXFS jWzs1yuFluTWCJA2BmofeaS/XyRgtFYGeV3AYDqm5kZ+weSWvD1Wg8qRuB0uyQOFy1n2 qU5ZRjgQjyxt/HE3Ve9CdFgCKvHGShOu5n2f1YrTBWaH9D6EtcOf6oQxcd9TXm9kERMn P3sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aCgtEkMZDS4B1B7GtT5isDDP0NFbvrH7N+BMafLPBbs=; b=oELNLvrzc8wmsLFZeGHfo6R3+4Oplm1nTXJypVCtMbaR6z5UjVNa8pBKXsEceEYV88 PcGRi1bpbwLjQvkqTw510TN3ajuH0Wfgdd3iDGk3hHibkcVB8t+EkY+qDkOLKW28p4oB qSu7dgU1rOA4tIM8r4hr8XCVNilbHRY4u4YYfnXnU9rVmghl97hK5glV2XAhc9BVzRtU C0uAhCnt37HxPPPVhhbYaAY04SE0rMmzIDU4qROa8L064ovdQG7EDJZp23UKGI8i+q7k PcJ4fQtmEl8R+6uqVJUE3HXU5exhxgQCHU+tsSZhKTu3ajH4lLNPvTYrHJADzxSQj/Hn UMNw== X-Gm-Message-State: AOAM533MAWLrYv2VHVOd4z6Hrb4LLQzoPheWSVJs7cRaPqfSmu7BGU3l n6q6+iSn3X66o1UlrGy3LOlH6PaC3vY= X-Google-Smtp-Source: ABdhPJz9jFJ6VsCh/otSfdncQKrqYGyqpQV2zNHR2whwShbc0Kz4BY0y+Va9OiAh+obEfYIOIeL1vA== X-Received: by 2002:a17:90a:a088:: with SMTP id r8mr3747274pjp.73.1599005390296; Tue, 01 Sep 2020 17:09:50 -0700 (PDT) Received: from localhost.localdomain ([161.81.62.213]) by smtp.gmail.com with ESMTPSA id d77sm3352630pfd.121.2020.09.01.17.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 17:09:49 -0700 (PDT) From: Tom Yan To: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, stern@rowland.harvard.edu, arnd@arndb.de Cc: cyrozap@gmail.com, yoshihiro.shimoda.uh@renesas.com, Tom Yan Subject: [PATCH v2 2/2] usb-storage: always set hw_max_sectors in slave_configure to avoid inappropriate clamping Date: Wed, 2 Sep 2020 08:09:37 +0800 Message-Id: <20200902000937.2204-2-tom.ty89@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902000937.2204-1-tom.ty89@gmail.com> References: <20200901145535.GC587030@rowland.harvard.edu> <20200902000937.2204-1-tom.ty89@gmail.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When the scsi request queue is initialized/allocated, the scsi driver clamps hw_max_sectors against the dma max mapping size of sdev->host->dma_dev. The device is currently inappriorate to use for USB drives. Therefore, always (re)set hw_max_sectors in the usb drivers to invalidate the clamping. Signed-off-by: Tom Yan --- drivers/usb/storage/scsiglue.c | 37 ++++++++++++++++------------------ drivers/usb/storage/uas.c | 2 ++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c index e5a971b83e3f..1f60d777a7e8 100644 --- a/drivers/usb/storage/scsiglue.c +++ b/drivers/usb/storage/scsiglue.c @@ -120,6 +120,23 @@ static int slave_configure(struct scsi_device *sdev) * better throughput on most devices. */ blk_queue_max_hw_sectors(sdev->request_queue, 2048); + } else { + /* + * Some devices are known to choke with anything larger. It seems like + * the problem stems from the fact that original IDE controllers had + * only an 8-bit register to hold the number of sectors in one transfer + * and even those couldn't handle a full 256 sectors. + * + * Because we want to make sure we interoperate with as many devices as + * possible, we will maintain a 240 sector transfer size limit for USB + * Mass Storage devices. + * + * Tests show that other operating have similar limits with Microsoft + * Windows 7 limiting transfers to 128 sectors for both USB2 and USB3 + * and Apple Mac OS X 10.11 limiting transfers to 256 sectors for USB2 + * and 2048 for USB3 devices. + */ + blk_queue_max_hw_sectors(sdev->request_queue, 240); } /* @@ -626,26 +643,6 @@ static const struct scsi_host_template usb_stor_host_template = { /* lots of sg segments can be handled */ .sg_tablesize = SG_MAX_SEGMENTS, - - /* - * Limit the total size of a transfer to 120 KB. - * - * Some devices are known to choke with anything larger. It seems like - * the problem stems from the fact that original IDE controllers had - * only an 8-bit register to hold the number of sectors in one transfer - * and even those couldn't handle a full 256 sectors. - * - * Because we want to make sure we interoperate with as many devices as - * possible, we will maintain a 240 sector transfer size limit for USB - * Mass Storage devices. - * - * Tests show that other operating have similar limits with Microsoft - * Windows 7 limiting transfers to 128 sectors for both USB2 and USB3 - * and Apple Mac OS X 10.11 limiting transfers to 256 sectors for USB2 - * and 2048 for USB3 devices. - */ - .max_sectors = 240, - /* emulated HBA */ .emulated = 1, diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 813c49914b9a..592e1358822e 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -843,6 +843,8 @@ static int uas_slave_configure(struct scsi_device *sdev) blk_queue_max_hw_sectors(sdev->request_queue, 240); else if (us->pusb_dev->speed >= USB_SPEED_SUPER) blk_queue_max_hw_sectors(sdev->request_queue, 2048); + else + blk_queue_max_hw_sectors(sdev->request_queue, SCSI_DEFAULT_MAX_SECTORS); blk_queue_max_hw_sectors(sdev->request_queue, min_t(size_t, queue_max_hw_sectors(sdev->request_queue),