From patchwork Fri Oct 6 12:54:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 730231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EE04E81DF4 for ; Fri, 6 Oct 2023 12:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232276AbjJFMzB (ORCPT ); Fri, 6 Oct 2023 08:55:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232269AbjJFMy6 (ORCPT ); Fri, 6 Oct 2023 08:54:58 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 404E6CA; Fri, 6 Oct 2023 05:54:57 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-99bf3f59905so371091166b.3; Fri, 06 Oct 2023 05:54:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696596896; x=1697201696; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q9jys0TJCo2/tcWQSVAiB+IlHESLf7hj3/oGQc7ywDY=; b=P0+g9ECEl5cBk8/ghkznkdqnDXGWazSyPHpItEXlFAushzuahDSoiqwOBNb1nPbvcU AaXHZ5Nh6ueHkoh3zIVI9L+oS1RfX8yKA+TY7UMotDQcDgkMrvCPR3/DAJEHwvmp/jNr uMVEMKldMK/t2B7a7DB49y0Ac3Cw7bWAK/rsF0QhUouGoqFK7WUwou6sqeypNJ1ItQWD 0HYKpTjPYrtIBv/WIKP+PuIBufNVWBZOGmbNbsG2TXAC2GBtToVy7jD6t3pfnUsZTNt/ vi6SKmOmz/U0Y8Se4OMzkC8O6qOXdDCUNyNNGZ0RlHo2foVlrkVgv96Xp2Kio95QHxYQ gptQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696596896; x=1697201696; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q9jys0TJCo2/tcWQSVAiB+IlHESLf7hj3/oGQc7ywDY=; b=nOMbqOlDKOGBLTAw+Pc182HGe5pXycDHV7zDVgNIg8dNFYcdhtT20moouUTywTiRaK 2s21MHD4tSATtFfyUd4augceF7JWhRtSvRCCoACwAyMI+JmyKBRIWJPo/06j8Ih3vG0w 83IF7SwcgcU5kLvY/9T1FtFBT1dw8dZEyzxYI+gHJ3dy6cvK274GO35ASXsRxCNKZa4c XoouPRKwbWahpgomTE9Fr2xV7ptav1Nq9Uvjz3hjn7lxe/6QJ0eYgPaLF8o4yQ/5oTO7 2lB56RDhUpS4HdaxyLpjaPdl6p62xOQhZZccMMfjsiDalJstd5prPoWFSfAVk7TCssS+ ne4Q== X-Gm-Message-State: AOJu0Yzwh8bCPit4g6ZuCQrnQL1Bc81ers5yAx5+nhCoNyemQ0zkefnJ Rmx3/xf8r876b7wpcUiZzIG/E9NWt0q7Tw== X-Google-Smtp-Source: AGHT+IGFdGngbd1+tUlLnkoAP9KgiPhUpj1Yd7RXurTsLdGC6wspYcT+NU7wEd4NPM2T059p/BFJIQ== X-Received: by 2002:a17:906:30db:b0:9b2:f941:6916 with SMTP id b27-20020a17090630db00b009b2f9416916mr7683708ejb.17.1696596895393; Fri, 06 Oct 2023 05:54:55 -0700 (PDT) Received: from sauvignon.fi.muni.cz (laomedon.fi.muni.cz. [147.251.42.107]) by smtp.gmail.com with ESMTPSA id p26-20020a1709060dda00b0099bc08862b6sm2894660eji.171.2023.10.06.05.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 05:54:55 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, stern@rowland.harvard.edu, oneukum@suse.com, jonathan.derrick@linux.dev, Milan Broz Subject: [RFC PATCH 1/6] usb-storage: remove UNUSUAL_VENDOR_INTF macro Date: Fri, 6 Oct 2023 14:54:40 +0200 Message-ID: <20231006125445.122380-2-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231006125445.122380-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch removes macro that was used only by commit that was reverted in commit ab4b71644a26d1ab92b987b2fd30e17c25e89f85 USB: storage: fix Huawei mode switching regression Signed-off-by: Milan Broz Reviewed-by: Alan Stern --- drivers/usb/storage/usb.c | 12 ------------ drivers/usb/storage/usual-tables.c | 15 --------------- 2 files changed, 27 deletions(-) diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 7b36a3334fb3..bb1fbeddc5aa 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -110,17 +110,6 @@ MODULE_PARM_DESC(quirks, "supplemental list of device IDs and their quirks"); .useTransport = use_transport, \ } -#define UNUSUAL_VENDOR_INTF(idVendor, cl, sc, pr, \ - vendor_name, product_name, use_protocol, use_transport, \ - init_function, Flags) \ -{ \ - .vendorName = vendor_name, \ - .productName = product_name, \ - .useProtocol = use_protocol, \ - .useTransport = use_transport, \ - .initFunction = init_function, \ -} - static const struct us_unusual_dev us_unusual_dev_list[] = { # include "unusual_devs.h" { } /* Terminating entry */ @@ -132,7 +121,6 @@ static const struct us_unusual_dev for_dynamic_ids = #undef UNUSUAL_DEV #undef COMPLIANT_DEV #undef USUAL_DEV -#undef UNUSUAL_VENDOR_INTF #ifdef CONFIG_LOCKDEP diff --git a/drivers/usb/storage/usual-tables.c b/drivers/usb/storage/usual-tables.c index 529512827d8f..b3c3ea04c11c 100644 --- a/drivers/usb/storage/usual-tables.c +++ b/drivers/usb/storage/usual-tables.c @@ -26,20 +26,6 @@ #define USUAL_DEV(useProto, useTrans) \ { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans) } -/* Define the device is matched with Vendor ID and interface descriptors */ -#define UNUSUAL_VENDOR_INTF(id_vendor, cl, sc, pr, \ - vendorName, productName, useProtocol, useTransport, \ - initFunction, flags) \ -{ \ - .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \ - | USB_DEVICE_ID_MATCH_VENDOR, \ - .idVendor = (id_vendor), \ - .bInterfaceClass = (cl), \ - .bInterfaceSubClass = (sc), \ - .bInterfaceProtocol = (pr), \ - .driver_info = (flags) \ -} - const struct usb_device_id usb_storage_usb_ids[] = { # include "unusual_devs.h" { } /* Terminating entry */ @@ -49,7 +35,6 @@ MODULE_DEVICE_TABLE(usb, usb_storage_usb_ids); #undef UNUSUAL_DEV #undef COMPLIANT_DEV #undef USUAL_DEV -#undef UNUSUAL_VENDOR_INTF /* * The table of devices to ignore From patchwork Fri Oct 6 12:54:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 731351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D82AFE81DF1 for ; Fri, 6 Oct 2023 12:55:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232277AbjJFMzC (ORCPT ); Fri, 6 Oct 2023 08:55:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232273AbjJFMy7 (ORCPT ); Fri, 6 Oct 2023 08:54:59 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 146B3C6; Fri, 6 Oct 2023 05:54:58 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9a58dbd5daeso378458666b.2; Fri, 06 Oct 2023 05:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696596896; x=1697201696; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iVEBic25aUxGUy5ujTcVQWFLs4hInZ0DtZ5uFx3eQBw=; b=Piz7xi4dx9riosmImJQtX85tntsnnr/YKWnzv+h672mUjnqhV7sP6QzYMCXKsYUYRb NXIYLv4hgodZ0KJVU1dE25aGgrf4V0guM88G41FH4UewZyWLLUOI5omFU5jWxwxgKIAu Fea4RTefUF4Wby3PVs+CkdxkNKa67X5CdxKCtTQdXBGoIl7Achx2sMe+lGMTv1qW+br6 yrkkSoiO8NlSDLTQOGpQe1Tkx7j/jzLeH0GNY3ZfktMiwg2OwD78unP3QNSV/LynIE0G ClfCFOqHJkjrVm9G5W0FmjZSbOa+DtZwVwW9GKtn9CacbKIMJK51Air4ZWXKG07TASQP qEug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696596896; x=1697201696; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iVEBic25aUxGUy5ujTcVQWFLs4hInZ0DtZ5uFx3eQBw=; b=Jpfdf+hdhyxJwv1LezWx1a5m9IqLWjreEqtqgyfiHXH/cKkW2EuVEO/ZAsw07gsJs9 F23/MrE6hBQTKbK8uGhSnZ+B4EzWAFVh820MoknuFfzbHTSf5PzPGZ7hX97ORPguBfG0 o8E/nT4XqZua47P1Rr+93xBaay7VljuzFHrHcqrrRRaTONJAtADcEpYvsrpKGyEhAj6Z Mm2pGEg5ISZrGc/qpxJbxY0urBg/2alrIBx2mPzVnEJUEcYAlv0Maszyl9d6yM6Xg2I4 yF/olKaJBPj5WlER2m5yFw41UANgGVFzJjnaL4HscZFwckZc6Nk3EtdJY+2uUfuHry7/ Qw3g== X-Gm-Message-State: AOJu0Yz4FWd3AbWsVhliQp8R0fbM7g1fGwKrrgKoZdTIRQZYBobTs88m HMcVtTD/uOdqU4bQzPpXGaTpcAzzBfp7sA== X-Google-Smtp-Source: AGHT+IELASzROS9gm5vlgmGbgZDoAt5b+dAWxa8cfya9HLV/DhrKF8xImqR7aNoIu5VJmYawaRILNA== X-Received: by 2002:a17:906:8a59:b0:9b2:e26f:3636 with SMTP id gx25-20020a1709068a5900b009b2e26f3636mr6928491ejc.13.1696596896246; Fri, 06 Oct 2023 05:54:56 -0700 (PDT) Received: from sauvignon.fi.muni.cz (laomedon.fi.muni.cz. [147.251.42.107]) by smtp.gmail.com with ESMTPSA id p26-20020a1709060dda00b0099bc08862b6sm2894660eji.171.2023.10.06.05.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 05:54:55 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, stern@rowland.harvard.edu, oneukum@suse.com, jonathan.derrick@linux.dev, Milan Broz Subject: [RFC PATCH 2/6] usb-storage: make internal quirks flags 64bit Date: Fri, 6 Oct 2023 14:54:41 +0200 Message-ID: <20231006125445.122380-3-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231006125445.122380-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Switch internal usb-storage quirk value to 64-bit as quirks currently already use all 32 bits. (Following patches are needed to properly use driver_info for 64-bit value.) Signed-off-by: Milan Broz --- drivers/usb/storage/uas-detect.h | 4 ++-- drivers/usb/storage/uas.c | 4 ++-- drivers/usb/storage/usb.c | 8 ++++---- drivers/usb/storage/usb.h | 4 ++-- drivers/usb/storage/usual-tables.c | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/usb/storage/uas-detect.h b/drivers/usb/storage/uas-detect.h index d73282c0ec50..4d3b49e5b87a 100644 --- a/drivers/usb/storage/uas-detect.h +++ b/drivers/usb/storage/uas-detect.h @@ -54,12 +54,12 @@ static int uas_find_endpoints(struct usb_host_interface *alt, static int uas_use_uas_driver(struct usb_interface *intf, const struct usb_device_id *id, - unsigned long *flags_ret) + u64 *flags_ret) { struct usb_host_endpoint *eps[4] = { }; struct usb_device *udev = interface_to_usbdev(intf); struct usb_hcd *hcd = bus_to_hcd(udev->bus); - unsigned long flags = id->driver_info; + u64 flags = id->driver_info; struct usb_host_interface *alt; int r; diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 2583ee9815c5..696bb0b23599 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -37,7 +37,7 @@ struct uas_dev_info { struct usb_anchor cmd_urbs; struct usb_anchor sense_urbs; struct usb_anchor data_urbs; - unsigned long flags; + u64 flags; int qdepth, resetting; unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe; unsigned use_streams:1; @@ -988,7 +988,7 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id) struct Scsi_Host *shost = NULL; struct uas_dev_info *devinfo; struct usb_device *udev = interface_to_usbdev(intf); - unsigned long dev_flags; + u64 dev_flags; if (!uas_use_uas_driver(intf, id, &dev_flags)) return -ENODEV; diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index bb1fbeddc5aa..d1ad6a2509ab 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -460,13 +460,13 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf) #define TOLOWER(x) ((x) | 0x20) /* Adjust device flags based on the "quirks=" module parameter */ -void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags) +void usb_stor_adjust_quirks(struct usb_device *udev, u64 *fflags) { char *p; u16 vid = le16_to_cpu(udev->descriptor.idVendor); u16 pid = le16_to_cpu(udev->descriptor.idProduct); - unsigned f = 0; - unsigned int mask = (US_FL_SANE_SENSE | US_FL_BAD_SENSE | + u64 f = 0; + u64 mask = (US_FL_SANE_SENSE | US_FL_BAD_SENSE | US_FL_FIX_CAPACITY | US_FL_IGNORE_UAS | US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE | US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 | @@ -605,7 +605,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id, us->fflags &= ~US_FL_GO_SLOW; if (us->fflags) - dev_info(pdev, "Quirks match for vid %04x pid %04x: %lx\n", + dev_info(pdev, "Quirks match for vid %04x pid %04x: %llx\n", le16_to_cpu(dev->descriptor.idVendor), le16_to_cpu(dev->descriptor.idProduct), us->fflags); diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h index fd3f32670873..97c6196d639b 100644 --- a/drivers/usb/storage/usb.h +++ b/drivers/usb/storage/usb.h @@ -95,7 +95,7 @@ struct us_data { struct usb_interface *pusb_intf; /* this interface */ const struct us_unusual_dev *unusual_dev; /* device-filter entry */ - unsigned long fflags; /* fixed flags from filter */ + u64 fflags; /* fixed flags from filter */ unsigned long dflags; /* dynamic atomic bitflags */ unsigned int send_bulk_pipe; /* cached pipe values */ unsigned int recv_bulk_pipe; @@ -192,7 +192,7 @@ extern int usb_stor_probe2(struct us_data *us); extern void usb_stor_disconnect(struct usb_interface *intf); extern void usb_stor_adjust_quirks(struct usb_device *dev, - unsigned long *fflags); + u64 *fflags); #define module_usb_stor_driver(__driver, __sht, __name) \ static int __init __driver##_init(void) \ diff --git a/drivers/usb/storage/usual-tables.c b/drivers/usb/storage/usual-tables.c index b3c3ea04c11c..a26029e43dfd 100644 --- a/drivers/usb/storage/usual-tables.c +++ b/drivers/usb/storage/usual-tables.c @@ -19,7 +19,7 @@ vendorName, productName, useProtocol, useTransport, \ initFunction, flags) \ { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ - .driver_info = (flags) } + .driver_info = (kernel_ulong_t)(flags) } #define COMPLIANT_DEV UNUSUAL_DEV From patchwork Fri Oct 6 12:54:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 731349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87CC6E81DE9 for ; Fri, 6 Oct 2023 12:55:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232317AbjJFMzN (ORCPT ); Fri, 6 Oct 2023 08:55:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232278AbjJFMzD (ORCPT ); Fri, 6 Oct 2023 08:55:03 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14163EA; Fri, 6 Oct 2023 05:54:58 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9adb9fa7200so468121466b.0; Fri, 06 Oct 2023 05:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696596897; x=1697201697; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WkJhAB2yyx4/iH5CKVtjye33dMpHhtPi+8GMajEKlxw=; b=ZSH79vWn7Eo6aUYnrpB1VHpw0wFF7TBvIagxIDpW8iMFqJNeozlftOfOsOPG+Cb8Ma qOxhS6Zm9DLVhhtj96f1+pyAlsjlMAUFp9/+E0XR4Xw1Pnk7DjRtgpIIvQglYkD+Dcq8 Sfm/lbLSwMQswWYk4hMHJXW1E2ZN+vgeQY/bhg8pfwRASM/0xVrYFTKhkAz49cH303Es nAkVsArVvv6JSM3EVl6ShAeStFNYiq+KzH6+yADh0mzSG9+HVMmP8OrUm+rQdK/siVXR fRBm6ZAeqx0juZsitKxuDv9ZvE4biMMFj8TBBVJDdHb/xpRIhztUCEpFqYMt3F3h+16F 2LpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696596897; x=1697201697; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WkJhAB2yyx4/iH5CKVtjye33dMpHhtPi+8GMajEKlxw=; b=CXp6RVWU9BkRO2Tgd3af5xTngrKRTKXYPvqNq21/6D9ffQlwn7Ie2kS2nMu9Oa4kYB /rE/pjplSBIwM3sYaknGmJ2lud5HWYR4ktrPczPCRHUrw93ttW4myctfd7Br7J8QSwed oRbz48B8IAOmCITmzGQ0qwg+rznGCLJ4uEfX9rFlQeIFuRAGIRDSDnVaZllbhcgtPK1W B1HmbeVkeX7YuDOpwh735UlFu8OJ9wWul3kcK7X24Ts/m2NDXeGVeX6GtF/0nMh+S3rE 5BYFZsz6/518Kw+Pf1qgmoj1lIydmbxc/JfH8i2mZw7HOkdq18ISIIRcCkQ2945duF2T jFpw== X-Gm-Message-State: AOJu0YxGxA08lXABWIJgb2CSn3/eAc2nVg1c2usaSxpFOUE585DM/tJV X789+lSV+jqLicdaXPr0iP3eRxT1L92B0Q== X-Google-Smtp-Source: AGHT+IGiuupZohH4zO/6GZ4LcEqf3PlRb+zDkvgDQ/6lZeXN28SuZojk5PGwd8T4TMSZr7VGRzyvqw== X-Received: by 2002:a17:906:6a28:b0:9ad:cbc0:9f47 with SMTP id qw40-20020a1709066a2800b009adcbc09f47mr3914024ejc.12.1696596897128; Fri, 06 Oct 2023 05:54:57 -0700 (PDT) Received: from sauvignon.fi.muni.cz (laomedon.fi.muni.cz. [147.251.42.107]) by smtp.gmail.com with ESMTPSA id p26-20020a1709060dda00b0099bc08862b6sm2894660eji.171.2023.10.06.05.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 05:54:56 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, stern@rowland.harvard.edu, oneukum@suse.com, jonathan.derrick@linux.dev, Milan Broz Subject: [RFC PATCH 3/6] usb-storage: use fflags index only in usb-storage driver Date: Fri, 6 Oct 2023 14:54:42 +0200 Message-ID: <20231006125445.122380-4-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231006125445.122380-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch adds a parameter to use driver_info translation function (which will be defined in the following patch). Only USB storage driver will use it, as other drivers do not need more than 32-bit quirk flags. Signed-off-by: Milan Broz --- drivers/usb/storage/alauda.c | 2 +- drivers/usb/storage/cypress_atacb.c | 2 +- drivers/usb/storage/datafab.c | 2 +- drivers/usb/storage/ene_ub6250.c | 2 +- drivers/usb/storage/freecom.c | 2 +- drivers/usb/storage/isd200.c | 2 +- drivers/usb/storage/jumpshot.c | 2 +- drivers/usb/storage/karma.c | 2 +- drivers/usb/storage/onetouch.c | 2 +- drivers/usb/storage/realtek_cr.c | 2 +- drivers/usb/storage/sddr09.c | 2 +- drivers/usb/storage/sddr55.c | 2 +- drivers/usb/storage/shuttle_usbat.c | 2 +- drivers/usb/storage/usb.c | 10 ++++++---- drivers/usb/storage/usb.h | 3 ++- 15 files changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c index 115f05a6201a..74e293981ab1 100644 --- a/drivers/usb/storage/alauda.c +++ b/drivers/usb/storage/alauda.c @@ -1241,7 +1241,7 @@ static int alauda_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - alauda_usb_ids) + alauda_unusual_dev_list, - &alauda_host_template); + &alauda_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c index 98b3ec352a13..2fc939f709b0 100644 --- a/drivers/usb/storage/cypress_atacb.c +++ b/drivers/usb/storage/cypress_atacb.c @@ -246,7 +246,7 @@ static int cypress_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - cypress_usb_ids) + cypress_unusual_dev_list, - &cypress_host_template); + &cypress_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c index bcc4a2fad863..fad9eca3cad9 100644 --- a/drivers/usb/storage/datafab.c +++ b/drivers/usb/storage/datafab.c @@ -727,7 +727,7 @@ static int datafab_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - datafab_usb_ids) + datafab_unusual_dev_list, - &datafab_host_template); + &datafab_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/ene_ub6250.c b/drivers/usb/storage/ene_ub6250.c index 97c66c0d91f4..6985d3419b3c 100644 --- a/drivers/usb/storage/ene_ub6250.c +++ b/drivers/usb/storage/ene_ub6250.c @@ -2331,7 +2331,7 @@ static int ene_ub6250_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - ene_ub6250_usb_ids) + ene_ub6250_unusual_dev_list, - &ene_ub6250_host_template); + &ene_ub6250_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/freecom.c b/drivers/usb/storage/freecom.c index 2b098b55c4cb..6d971bd711d8 100644 --- a/drivers/usb/storage/freecom.c +++ b/drivers/usb/storage/freecom.c @@ -548,7 +548,7 @@ static int freecom_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - freecom_usb_ids) + freecom_unusual_dev_list, - &freecom_host_template); + &freecom_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c index 4e0eef1440b7..ecdc494756a2 100644 --- a/drivers/usb/storage/isd200.c +++ b/drivers/usb/storage/isd200.c @@ -1545,7 +1545,7 @@ static int isd200_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - isd200_usb_ids) + isd200_unusual_dev_list, - &isd200_host_template); + &isd200_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c index 229bf0c1afc9..1ade1e45c81d 100644 --- a/drivers/usb/storage/jumpshot.c +++ b/drivers/usb/storage/jumpshot.c @@ -653,7 +653,7 @@ static int jumpshot_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - jumpshot_usb_ids) + jumpshot_unusual_dev_list, - &jumpshot_host_template); + &jumpshot_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/karma.c b/drivers/usb/storage/karma.c index 38ddfedef629..60868be0e38c 100644 --- a/drivers/usb/storage/karma.c +++ b/drivers/usb/storage/karma.c @@ -205,7 +205,7 @@ static int karma_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - karma_usb_ids) + karma_unusual_dev_list, - &karma_host_template); + &karma_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c index 01f3c2779ccf..fe34f20cce03 100644 --- a/drivers/usb/storage/onetouch.c +++ b/drivers/usb/storage/onetouch.c @@ -280,7 +280,7 @@ static int onetouch_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - onetouch_usb_ids) + onetouch_unusual_dev_list, - &onetouch_host_template); + &onetouch_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c index 0c423916d7bf..892b26714b5f 100644 --- a/drivers/usb/storage/realtek_cr.c +++ b/drivers/usb/storage/realtek_cr.c @@ -1041,7 +1041,7 @@ static int realtek_cr_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - realtek_cr_ids) + realtek_cr_unusual_dev_list, - &realtek_cr_host_template); + &realtek_cr_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c index 51bcd4a43690..107eeb7fda04 100644 --- a/drivers/usb/storage/sddr09.c +++ b/drivers/usb/storage/sddr09.c @@ -1753,7 +1753,7 @@ static int sddr09_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - sddr09_usb_ids) + sddr09_unusual_dev_list, - &sddr09_host_template); + &sddr09_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/sddr55.c b/drivers/usb/storage/sddr55.c index 15dc25801cdc..c64b72de453f 100644 --- a/drivers/usb/storage/sddr55.c +++ b/drivers/usb/storage/sddr55.c @@ -985,7 +985,7 @@ static int sddr55_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - sddr55_usb_ids) + sddr55_unusual_dev_list, - &sddr55_host_template); + &sddr55_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c index f0d0ca37163d..3ac82f49401c 100644 --- a/drivers/usb/storage/shuttle_usbat.c +++ b/drivers/usb/storage/shuttle_usbat.c @@ -1838,7 +1838,7 @@ static int usbat_probe(struct usb_interface *intf, result = usb_stor_probe1(&us, intf, id, (id - usbat_usb_ids) + usbat_unusual_dev_list, - &usbat_host_template); + &usbat_host_template, 0); if (result) return result; diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index d1ad6a2509ab..72b48b94aa5f 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -574,7 +574,7 @@ EXPORT_SYMBOL_GPL(usb_stor_adjust_quirks); /* Get the unusual_devs entries and the string descriptors */ static int get_device_info(struct us_data *us, const struct usb_device_id *id, - const struct us_unusual_dev *unusual_dev) + const struct us_unusual_dev *unusual_dev, int fflags_use_index) { struct usb_device *dev = us->pusb_dev; struct usb_interface_descriptor *idesc = @@ -590,6 +590,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id, idesc->bInterfaceProtocol : unusual_dev->useTransport; us->fflags = id->driver_info; + usb_stor_adjust_quirks(us->pusb_dev, &us->fflags); if (us->fflags & US_FL_IGNORE_DEVICE) { @@ -925,7 +926,8 @@ int usb_stor_probe1(struct us_data **pus, struct usb_interface *intf, const struct usb_device_id *id, const struct us_unusual_dev *unusual_dev, - const struct scsi_host_template *sht) + const struct scsi_host_template *sht, + int fflags_use_index) { struct Scsi_Host *host; struct us_data *us; @@ -962,7 +964,7 @@ int usb_stor_probe1(struct us_data **pus, goto BadDevice; /* Get the unusual_devs entries and the descriptors */ - result = get_device_info(us, id, unusual_dev); + result = get_device_info(us, id, unusual_dev, fflags_use_index); if (result) goto BadDevice; @@ -1120,7 +1122,7 @@ static int storage_probe(struct usb_interface *intf, } result = usb_stor_probe1(&us, intf, id, unusual_dev, - &usb_stor_host_template); + &usb_stor_host_template, 1); if (result) return result; diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h index 97c6196d639b..975c47efcce7 100644 --- a/drivers/usb/storage/usb.h +++ b/drivers/usb/storage/usb.h @@ -187,7 +187,8 @@ extern int usb_stor_probe1(struct us_data **pus, struct usb_interface *intf, const struct usb_device_id *id, const struct us_unusual_dev *unusual_dev, - const struct scsi_host_template *sht); + const struct scsi_host_template *sht, + int fflags_use_index); extern int usb_stor_probe2(struct us_data *us); extern void usb_stor_disconnect(struct usb_interface *intf); From patchwork Fri Oct 6 12:54:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 730230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA076E81DE9 for ; Fri, 6 Oct 2023 12:55:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232301AbjJFMzJ (ORCPT ); Fri, 6 Oct 2023 08:55:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232269AbjJFMzC (ORCPT ); Fri, 6 Oct 2023 08:55:02 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93480ED; Fri, 6 Oct 2023 05:54:59 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-9936b3d0286so385214666b.0; Fri, 06 Oct 2023 05:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696596898; x=1697201698; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1+Xk47edy3U3XgclyVuRlA6zu+d2RpKkXSanUVJr3n8=; b=gogvsfruc0iY23YzXiiiXH5Yc42sLN4qf7YrxTSl1kWI/k23ziGflM1h1Jp0U+UA/W 2EsyCWE9mfBAeMjXoBy5YMZLypgrEwgbyNwhKjdPx742WxichR6aXYp/7eeEdI520TmH V0fUCgbTWckaOTp8oeZ4BBOuak/Gb/skwu4uLnkVN/F7rjfThIhWfJX61xhtLg/vtWpZ dCQRwVG6Gz4QLU7NXU1/2+HbHv7wH1S1OYA3LfdbcaCYSwtZoDXOKXGqgtL5O/cQVUyf r66TvpBrYejWYca1IHV2fFc5gbepXBSFU/867fU8cxrsYloVi7bIHo2snXqP9fSaI903 ojIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696596898; x=1697201698; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1+Xk47edy3U3XgclyVuRlA6zu+d2RpKkXSanUVJr3n8=; b=Fj6X4tSiPk90nUr0O3zSoHReSWAagHBQlqAE6E4rw9PSQpoQWxhwBb5jvPrIm9yJos ABoK5ZjmRms8oXwfQhfjmEHykmRJiIZ+7jtO+8lH9cG+5VG2wSxPwiXjd61NP7rs6t6z u5gs+jiV0IajyW6QJUl+xqF84JDS6yZ07ltTVVJVVsdHw/tZfKRGy1P8DNFsCHXXOupS zWno+SeZINWXcmNlyGv0hhhZATWmzjHWEqaqQj3F3xuuW9SSLAHZQqfbjQSPfI75TUHj m/Rd/9s+Anj/jyKOadYBYDSXQgEJMwk+tsunrb1p6+xNRELS1XOoD2ujH1RItTqrcitA Jbwg== X-Gm-Message-State: AOJu0YwWXXfHezVtOhs57cipCBBChSk0F8IWSfdYzUtNSBKzUkg+zV7F o6/ahCKK9rhHS4JvhZwShsrTNtfryIZejQ== X-Google-Smtp-Source: AGHT+IFScyObCql+CcCjtA9ASt0X0HYsIditF3TA7p2on5zVtMI0Qh3jyvbOtk9cOr4NaG1w40JKOA== X-Received: by 2002:a17:906:210a:b0:9ae:56da:6068 with SMTP id 10-20020a170906210a00b009ae56da6068mr7408282ejt.57.1696596897956; Fri, 06 Oct 2023 05:54:57 -0700 (PDT) Received: from sauvignon.fi.muni.cz (laomedon.fi.muni.cz. [147.251.42.107]) by smtp.gmail.com with ESMTPSA id p26-20020a1709060dda00b0099bc08862b6sm2894660eji.171.2023.10.06.05.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 05:54:57 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, stern@rowland.harvard.edu, oneukum@suse.com, jonathan.derrick@linux.dev, Milan Broz Subject: [RFC PATCH 4/6] usb-storage,uas: use host helper to generate driver info Date: Fri, 6 Oct 2023 14:54:43 +0200 Message-ID: <20231006125445.122380-5-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231006125445.122380-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The USB mass storage quirks flags are stored in driver_info, a 32-bit integer (unsigned long on 32-bit platforms). As this attribute cannot be enlarged, we need to use some form of translation of 64-bit quirk bits. This problem was discussed on USB list https://lore.kernel.org/linux-usb/f9e8acb5-32d5-4a30-859f-d4336a86b31a@gmail.com/ The initial solution to use static array extensively increased the size of the kernel module, so I decided to try the second suggested solution: generate a table by host-compiled program and use bit 31 to indicate that the value is index and not actual value. This patch adds a host-compiled program that processes unusual_devs.h (and unusual_uas.h) and generates files unusual-flags.c and unusual-flags-uas.c (for pre-processed USB device table with 32 bit device info) and unusual-flags.h with function to translate flags to 64-bits from device-info. The separate generated header file is needed as storage and UAS drivers headers are tightly bound together and any ohter solution seems to be more pervasive. Translation function is used only in usb-storage and uas modules; all other USB storage modules store flags directly, using only 32-bit integers. This translation is unnecessary for a 64-bit system, but I keep it in place for simplicity. (Also, I did not find a reliable way a host-compiled program can detect that the target platform has 32-bit unsigned long (usual macros do not work here!). Signed-off-by: Milan Broz --- drivers/usb/storage/Makefile | 25 ++++ drivers/usb/storage/mkflags.c | 212 +++++++++++++++++++++++++++++ drivers/usb/storage/uas-detect.h | 2 +- drivers/usb/storage/uas.c | 17 +-- drivers/usb/storage/usb.c | 7 +- drivers/usb/storage/usual-tables.c | 23 +--- 6 files changed, 248 insertions(+), 38 deletions(-) create mode 100644 drivers/usb/storage/mkflags.c diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile index 46635fa4a340..1eacdbb387cd 100644 --- a/drivers/usb/storage/Makefile +++ b/drivers/usb/storage/Makefile @@ -45,3 +45,28 @@ ums-realtek-y := realtek_cr.o ums-sddr09-y := sddr09.o ums-sddr55-y := sddr55.o ums-usbat-y := shuttle_usbat.o + +$(obj)/usb.o: $(obj)/unusual-flags.h +$(obj)/usual-tables.o: $(obj)/unusual-flags.c +$(obj)/uas.o: $(obj)/unusual-flags.h $(obj)/unusual-flags-uas.c +clean-files := unusual-flags.h unusual-flags.c unusual-flags-uas.c +HOSTCFLAGS_mkflags.o := -I $(srctree)/include/ +hostprogs += mkflags + +quiet_cmd_mkflag_flags = FLAGS $@ + cmd_mkflag_flags = $(obj)/mkflags flags > $@ + +quiet_cmd_mkflag_storage = FLAGS $@ + cmd_mkflag_storage = $(obj)/mkflags storage > $@ + +quiet_cmd_mkflag_uas = FLAGS $@ + cmd_mkflag_uas = $(obj)/mkflags uas > $@ + +$(obj)/unusual-flags.h: $(obj)/mkflags FORCE + $(call if_changed,mkflag_flags) + +$(obj)/unusual-flags.c: $(obj)/mkflags FORCE + $(call if_changed,mkflag_storage) + +$(obj)/unusual-flags-uas.c: $(obj)/mkflags FORCE + $(call if_changed,mkflag_uas) diff --git a/drivers/usb/storage/mkflags.c b/drivers/usb/storage/mkflags.c new file mode 100644 index 000000000000..11aa6579e7e1 --- /dev/null +++ b/drivers/usb/storage/mkflags.c @@ -0,0 +1,212 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include + +/* + * Cannot use userspace as code below + * processes internal kernel headers + */ +#include + +/* + * Silence warning for definitions in headers we do not use + */ +struct usb_device_id {}; +struct usb_interface; + +#include + +struct svals { + unsigned int type; + + /*interface */ + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + + /* device */ + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice_lo; + uint16_t bcdDevice_hi; + + uint64_t flags; + unsigned int set; + unsigned int idx; +}; + +enum { TYPE_DEVICE_STORAGE, TYPE_DEVICE_UAS, TYPE_CLASS }; +enum { FLAGS_NOT_SET, FLAGS_SET, FLAGS_DUPLICATE }; +#define FLAGS_END (uint64_t)-1 + +#define IS_ENABLED(x) 0 + +static struct svals vals[] = { +#define USUAL_DEV(useProto, useTrans) \ +{ TYPE_CLASS, useProto, useTrans, 0, 0, 0, 0, 0, FLAGS_NOT_SET, 0 } + +#define COMPLIANT_DEV UNUSUAL_DEV +#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ + vendorName, productName, useProtocol, useTransport, \ + initFunction, flags) \ +{ TYPE_DEVICE_STORAGE, 0, 0, id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, flags, FLAGS_NOT_SET, 0 } + +#include "unusual_devs.h" + +/* UAS */ +#undef UNUSUAL_DEV +#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ + vendorName, productName, useProtocol, useTransport, \ + initFunction, flags) \ +{ TYPE_DEVICE_UAS, 0, 0, id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, flags, FLAGS_NOT_SET, 0 } + +#include "unusual_uas.h" + +{ .flags = FLAGS_END } +}; +#undef UNUSUAL_DEV +#undef USUAL_DEV +#undef COMPLIANT_DEV +#undef IS_ENABLED + +#define HI32 (uint32_t)0x80000000 + +static unsigned long get_device_info(uint64_t flags, unsigned int idx) +{ + if (flags < HI32) + return (unsigned long)flags; + + /* Use index that will be processed in usb_stor_di2flags */ + return HI32 + idx; +} + +static void print_class(uint8_t bDeviceSubClass, uint8_t bDeviceProtocol) +{ + printf("\t{ .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, "); + printf(".bInterfaceClass = USB_CLASS_MASS_STORAGE, "); + printf(".bInterfaceSubClass = 0x%x, .bInterfaceProtocol = 0x%x },\n", + bDeviceSubClass, bDeviceProtocol); +} +static void print_type(unsigned int type) +{ + for (int i = 0; vals[i].flags != FLAGS_END; i++) { + if (vals[i].type != type) + continue; + + if (type == TYPE_DEVICE_STORAGE || type == TYPE_DEVICE_UAS) { + printf("\t{ .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, "); + printf(".idVendor = 0x%x, .idProduct =0x%x, " + ".bcdDevice_lo = 0x%x, .bcdDevice_hi = 0x%x, .driver_info = 0x%lx },\n", + vals[i].idVendor, vals[i].idProduct, + vals[i].bcdDevice_lo, vals[i].bcdDevice_hi, + get_device_info(vals[i].flags, vals[i].idx)); + } else if (type == TYPE_CLASS) + print_class(vals[i].bDeviceSubClass, vals[i].bDeviceProtocol); + } +} + +static void print_usb_flags(void) +{ + int i; + + printf("#include \n\n"); + + /* usb_stor_di2flags */ + printf("static u64 usb_stor_di2flags(unsigned long idx)\n{\n"); + printf("\tu64 flags = 0;\n\n"); + printf("\tif (idx < 0x%x) \n\t\treturn idx;\n\n", HI32); + printf("\tswitch(idx - 0x%x) {\n", HI32); + for (i = 0; vals[i].flags != FLAGS_END; i++) { + if (vals[i].set == FLAGS_SET) + printf("\tcase %u: flags = 0x%llx; break;\n", vals[i].idx, vals[i].flags); + } + printf("\t}\n\n"); + printf("\treturn flags;\n"); + printf("}\n"); +} + +static void print_usb_storage(void) +{ + printf("#include \n\n"); + + /* usb_storage_usb_ids */ + printf("const struct usb_device_id usb_storage_usb_ids[] = {\n"); + + /* USB storage devices */ + print_type(TYPE_DEVICE_STORAGE); + + /* UAS storage devices */ + printf("#if IS_ENABLED(CONFIG_USB_UAS)\n"); + print_type(TYPE_DEVICE_UAS); + printf("#endif\n"); + + /* transport subclasses */ + print_type(TYPE_CLASS); + + printf("\t{ }\t\t/* Terminating entry */\n};\n"); + printf("MODULE_DEVICE_TABLE(usb, usb_storage_usb_ids);\n"); +} + +static void print_usb_uas(void) +{ + printf("#include \n\n"); + + /* uas_usb_ids */ + printf("const struct usb_device_id uas_usb_ids[] = {\n"); + + /* UAS storage devices */ + print_type(TYPE_DEVICE_UAS); + + /* transport subclasses */ + print_class(USB_SC_SCSI, USB_PR_BULK); + print_class(USB_SC_SCSI, USB_PR_UAS); + + printf("\t{ }\t\t/* Terminating entry */\n};\n"); + printf("MODULE_DEVICE_TABLE(usb, uas_usb_ids);\n"); +} + +int main(int argc, char *argv[]) +{ + int i, j, idx = 0, idx_old, skip = 0; + + if (argc != 2 || (strcmp(argv[1], "flags") && + strcmp(argv[1], "storage") && strcmp(argv[1], "uas"))) { + printf("Please specify type: storage, uas or flags.\n"); + return 1; + } + + for (i = 0; vals[i].flags != FLAGS_END; i++) { + if (vals[i].type == TYPE_CLASS) + continue; + skip = 0; + if (vals[i].flags >= HI32) { + for (j = 0; j < i; j++) { + if (vals[j].flags == vals[i].flags && + vals[j].set == FLAGS_SET) { + skip = 1; + idx_old = vals[j].idx; + break; + } + } + if (skip) { + vals[i].idx = idx_old; + vals[i].set = FLAGS_DUPLICATE; + } else { + vals[i].idx = idx; + vals[i].set = FLAGS_SET; + idx++; + } + } + } + + if (!strcmp(argv[1], "flags")) + print_usb_flags(); + else if (!strcmp(argv[1], "storage")) + print_usb_storage(); + else if (!strcmp(argv[1], "uas")) + print_usb_uas(); + else + return 1; + + return 0; +} diff --git a/drivers/usb/storage/uas-detect.h b/drivers/usb/storage/uas-detect.h index 4d3b49e5b87a..701621aaa9e7 100644 --- a/drivers/usb/storage/uas-detect.h +++ b/drivers/usb/storage/uas-detect.h @@ -59,7 +59,7 @@ static int uas_use_uas_driver(struct usb_interface *intf, struct usb_host_endpoint *eps[4] = { }; struct usb_device *udev = interface_to_usbdev(intf); struct usb_hcd *hcd = bus_to_hcd(udev->bus); - u64 flags = id->driver_info; + u64 flags = usb_stor_di2flags(id->driver_info); struct usb_host_interface *alt; int r; diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 696bb0b23599..f6e293daabf4 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -26,6 +26,7 @@ #include #include +#include "unusual-flags.h" #include "uas-detect.h" #include "scsiglue.h" @@ -909,21 +910,7 @@ static const struct scsi_host_template uas_host_template = { .cmd_size = sizeof(struct uas_cmd_info), }; -#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ - vendorName, productName, useProtocol, useTransport, \ - initFunction, flags) \ -{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ - .driver_info = (flags) } - -static struct usb_device_id uas_usb_ids[] = { -# include "unusual_uas.h" - { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_BULK) }, - { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_UAS) }, - { } -}; -MODULE_DEVICE_TABLE(usb, uas_usb_ids); - -#undef UNUSUAL_DEV +#include "unusual-flags-uas.c" static int uas_switch_interface(struct usb_device *udev, struct usb_interface *intf) diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 72b48b94aa5f..f3a53c3eeb45 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -56,6 +56,8 @@ #include "sierra_ms.h" #include "option_ms.h" +#include "unusual-flags.h" + #if IS_ENABLED(CONFIG_USB_UAS) #include "uas-detect.h" #endif @@ -589,7 +591,10 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id, us->protocol = (unusual_dev->useTransport == USB_PR_DEVICE) ? idesc->bInterfaceProtocol : unusual_dev->useTransport; - us->fflags = id->driver_info; + if (fflags_use_index) + us->fflags = usb_stor_di2flags(id->driver_info); + else + us->fflags = id->driver_info; usb_stor_adjust_quirks(us->pusb_dev, &us->fflags); diff --git a/drivers/usb/storage/usual-tables.c b/drivers/usb/storage/usual-tables.c index a26029e43dfd..c5871c1c3915 100644 --- a/drivers/usb/storage/usual-tables.c +++ b/drivers/usb/storage/usual-tables.c @@ -13,28 +13,9 @@ /* - * The table of devices + * The table of devices is pre-generated in unusual-flags.c */ -#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ - vendorName, productName, useProtocol, useTransport, \ - initFunction, flags) \ -{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ - .driver_info = (kernel_ulong_t)(flags) } - -#define COMPLIANT_DEV UNUSUAL_DEV - -#define USUAL_DEV(useProto, useTrans) \ -{ USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans) } - -const struct usb_device_id usb_storage_usb_ids[] = { -# include "unusual_devs.h" - { } /* Terminating entry */ -}; -MODULE_DEVICE_TABLE(usb, usb_storage_usb_ids); - -#undef UNUSUAL_DEV -#undef COMPLIANT_DEV -#undef USUAL_DEV +#include "unusual-flags.c" /* * The table of devices to ignore From patchwork Fri Oct 6 12:54:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 731350 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DB3BE81DF4 for ; Fri, 6 Oct 2023 12:55:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232307AbjJFMzK (ORCPT ); Fri, 6 Oct 2023 08:55:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232272AbjJFMzC (ORCPT ); Fri, 6 Oct 2023 08:55:02 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70665D6; Fri, 6 Oct 2023 05:55:00 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9b64b98656bso364999366b.0; Fri, 06 Oct 2023 05:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696596899; x=1697201699; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JvlLVhV61yey8O8YpbEqG2hEVjESCumTPs4mXO+vIE0=; b=Q+JD/vVv6FQnbQ+Ayo7EBpkxEgAkFpuHB7d2F1/Q17TYXxiTvlAXXqM4FuvRnM4vfE wvRP1oRjiN12I0CljIwfSkwktd1Wb3rw5ms3mzCgm25bloDe1WrVObPRmP58EQ+srj6f zzdqYbEYlbDwBDUyKjl2BZG45WhnVc5OUHSnSOD9GnuzSn9eiX7I+tBcFcdSInW6jYXN uSjlvMdCOy9Il3dePctAlolXzuirMbNQQchds0somXlTp/bc+8ituIOjoTdY5CMnOYrg iSuzCB4Jlmyg+1/VfwFbvrgGzB+fG0thWfzLVhdlyPXx1bm13mD/qh29jAWL5tcBrIWE 2xTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696596899; x=1697201699; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JvlLVhV61yey8O8YpbEqG2hEVjESCumTPs4mXO+vIE0=; b=vXGYYomkiS+q4jT6NaUzGo80Va0bksd3AzudQA6K+lkjA7wkuTmqNyKpb3Lwu2LI0n l0n3nDnoJKeUuEuKeY5makUsh+yoPUAX6V8lMntaoFNYdn6SqBqHxNjYVIfXXu+GAWm0 b64Wnvdse3jdSe6ltAsVvmyFh+4Uo6lOYbw3eHPTas71FePHaSmMr+vzWVYzsSV4XELq UNRA2dNnPC50ulv8dUPeRwQfT0Ca1N/bvk6m1XKha2nf6+BadhYtIFTwPS8dGVI43kAb oOrUckW5/w2hNZETjfTn78x/I9Nc3o+vBSKyLCIJglowmFe72Nmld4tEbH+oLoQ8jQoS TLnA== X-Gm-Message-State: AOJu0Ywn7VaM42NYDq7xZGuzjPWTCSj3uRFmL6UnSFejPlanb+vr+eqF XjWzaT5jMPL2ouhXzYKDnXCeGe+l4RVCrg== X-Google-Smtp-Source: AGHT+IG2DczT846X90UrkoQRLIR8aD+eEYxqRpvEe0St1vVFd5QVZDc6TeKn/2cRHHcxpBsoSArQOQ== X-Received: by 2002:a17:906:5349:b0:9b2:8b14:7a20 with SMTP id j9-20020a170906534900b009b28b147a20mr7520029ejo.45.1696596898716; Fri, 06 Oct 2023 05:54:58 -0700 (PDT) Received: from sauvignon.fi.muni.cz (laomedon.fi.muni.cz. [147.251.42.107]) by smtp.gmail.com with ESMTPSA id p26-20020a1709060dda00b0099bc08862b6sm2894660eji.171.2023.10.06.05.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 05:54:58 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, stern@rowland.harvard.edu, oneukum@suse.com, jonathan.derrick@linux.dev, Milan Broz Subject: [RFC PATCH 5/6] usb-storage, uas, scsi: allow to pass through security commands (OPAL) Date: Fri, 6 Oct 2023 14:54:44 +0200 Message-ID: <20231006125445.122380-6-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231006125445.122380-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch enables pass-through OPAL command for USB-attached storage (which does not support UAS or SCSI security commands). All common USB/SATA or USB/NVMe adapters I tested need this patch. USB mass storage devices that do not support SECURITY IN/OUT SCSI commands can support ATA12 pass-thru command. Internal kernel implementation for OPAL interface currently supports only SCSI SECURITY IN/OUT wrapper. USB mass storage also turns off SCSI command enumeration, so SECURITY IN/OUT in the SCSI layer will be disabled. Note: sedutils and some other OPAL tools already use ATA-12 pass-thru. This patch - enables SCSI security flag for USB mass storage and UAS device by default. - adds an optional wrapper to the SCSI layer for the ATA-12 pass-thru command as an alternative if SECURITY IN/OUT is unavailable. In short, the patch runs these steps: 1) USB drives (mass-storage, UAS) enables security driver flag by default if not disabled by quirk 2) SCSI device enumerates SECURITY IN/OUT support. If detected, SECURITY ON/OUT wrapper is used (as in the current code). If not, new ATA12 pass-thru wrapper is used instead. 3) SED OPAL code tries OPAL discovery command for device. If it receives correct reply, OPAL is enabled for the device. With the changes above, the TCG OPAL support works with USB adapters that support the ATA-12 command. As kernel OPAL code runs discover commands on initialization, on devices that do not support pass-through, OPAL remains disabled. The patch also adds a quirk flag to disable security commands for particular devices if firmware is buggy. Signed-off-by: Milan Broz --- drivers/scsi/sd.c | 33 +++++++++++++++++++++++++++++++-- drivers/usb/storage/scsiglue.c | 4 ++++ drivers/usb/storage/uas.c | 5 +++++ drivers/usb/storage/usb.c | 5 ++++- include/linux/usb_usual.h | 2 ++ 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 83b6a3f3863b..3782556cb461 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -686,6 +686,32 @@ static int sd_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, &exec_args); return ret <= 0 ? ret : -EIO; } + +static int sd_ata12_submit(void *data, u16 spsp, u8 secp, void *buffer, + size_t len, bool send) +{ + struct scsi_disk *sdkp = data; + struct scsi_device *sdev = sdkp->device; + u8 cdb[12] = { 0, }; + const struct scsi_exec_args exec_args = { + .req_flags = BLK_MQ_REQ_PM, + }; + int ret; + + cdb[0] = ATA_12; + cdb[1] = (send ? 5 /* ATA_PROTOCOL_PIO_DATA_IN */ : 4 /* ATA_PROTOCOL_PIO_DATA_OUT */) << 1; + cdb[2] = 2 /* t_length */ | (1 << 2) /* byt_blok */ | ((send ? 0 : 1) << 3) /* t_dir */; + cdb[3] = secp; + put_unaligned_le16(len / 512, &cdb[4]); + put_unaligned_le16(spsp, &cdb[6]); + cdb[9] = send ? 0x5e /* ATA_CMD_TRUSTED_SND */: 0x5c /* ATA_CMD_TRUSTED_RCV */; + + ret = scsi_execute_cmd(sdev, cdb, send ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN, + buffer, len, SD_TIMEOUT, sdkp->max_retries, + &exec_args); + return ret <= 0 ? ret : -EIO; +} + #endif /* CONFIG_BLK_SED_OPAL */ /* @@ -3699,8 +3725,11 @@ static int sd_probe(struct device *dev) goto out; } - if (sdkp->security) { - sdkp->opal_dev = init_opal_dev(sdkp, &sd_sec_submit); + if (sdp->security_supported) { + if (sdkp->security) + sdkp->opal_dev = init_opal_dev(sdkp, &sd_sec_submit); + else + sdkp->opal_dev = init_opal_dev(sdkp, &sd_ata12_submit); if (sdkp->opal_dev) sd_printk(KERN_NOTICE, sdkp, "supports TCG Opal\n"); } diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c index c54e9805da53..ef93813a2049 100644 --- a/drivers/usb/storage/scsiglue.c +++ b/drivers/usb/storage/scsiglue.c @@ -209,6 +209,10 @@ static int slave_configure(struct scsi_device *sdev) /* Do not attempt to use WRITE SAME */ sdev->no_write_same = 1; + /* Allow security commands (OPAL) passthrough */ + if (!(us->fflags & US_FL_IGNORE_OPAL)) + sdev->security_supported = 1; + /* * Some disks return the total number of blocks in response * to READ CAPACITY rather than the highest block number. diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index f6e293daabf4..9dfe8ea20134 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -865,6 +865,11 @@ static int uas_slave_configure(struct scsi_device *sdev) /* Some disks cannot handle WRITE_SAME */ if (devinfo->flags & US_FL_NO_SAME) sdev->no_write_same = 1; + + /* Allow security commands (OPAL) passthrough */ + if (!(devinfo->flags & US_FL_IGNORE_OPAL)) + sdev->security_supported = 1; + /* * Some disks return the total number of blocks in response * to READ CAPACITY rather than the highest block number. diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index f3a53c3eeb45..04211ac803e4 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -478,7 +478,7 @@ void usb_stor_adjust_quirks(struct usb_device *udev, u64 *fflags) US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE | US_FL_NO_ATA_1X | US_FL_NO_REPORT_OPCODES | US_FL_MAX_SECTORS_240 | US_FL_NO_REPORT_LUNS | - US_FL_ALWAYS_SYNC); + US_FL_ALWAYS_SYNC | US_FL_IGNORE_OPAL); p = quirks; while (*p) { @@ -567,6 +567,9 @@ void usb_stor_adjust_quirks(struct usb_device *udev, u64 *fflags) case 'y': f |= US_FL_ALWAYS_SYNC; break; + case 'z': + f |= US_FL_IGNORE_OPAL; + break; /* Ignore unrecognized flag characters */ } } diff --git a/include/linux/usb_usual.h b/include/linux/usb_usual.h index 712363c7a2e8..0181c94d7d91 100644 --- a/include/linux/usb_usual.h +++ b/include/linux/usb_usual.h @@ -88,6 +88,8 @@ /* Cannot handle WRITE_SAME */ \ US_FLAG(SENSE_AFTER_SYNC, 0x80000000) \ /* Do REQUEST_SENSE after SYNCHRONIZE_CACHE */ \ + US_FLAG(IGNORE_OPAL, 0x100000000) \ + /* Security commands (OPAL) are broken */ \ #define US_FLAG(name, value) US_FL_##name = value , enum { US_DO_ALL_FLAGS }; From patchwork Fri Oct 6 12:54:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 730229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AC25E81DF5 for ; Fri, 6 Oct 2023 12:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232305AbjJFMzL (ORCPT ); Fri, 6 Oct 2023 08:55:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232273AbjJFMzD (ORCPT ); Fri, 6 Oct 2023 08:55:03 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74223E9; Fri, 6 Oct 2023 05:55:01 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-99bdeae1d0aso399746866b.1; Fri, 06 Oct 2023 05:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696596900; x=1697201700; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1hGVnjdGEOumYZe081/NvT5dGB2xwJn4Ju//yjOVJPI=; b=Y9UaCvO4K/mYbFVG5kkGA0sJq+68VnCZ6MF+7oBn0jqraCFUJ30itNjSPHoGIPkrl8 Hd/9qEw7iyQ2tDs0+UyRA0AwKjXy/DTqVCiugtxhj+NWcHx1xtJxsC4/+Q5VIf1vNWlj NvXz+wvyQhThApvIjMTSFCwdP1DzGS22N63iFNV+j4zUxxKD5sbQVfogpXhLfVMb2Mqi J1EPgRSqjSOo31NVNDeRVe4w00+kSBL2aNHr1y9VMos/0+zTramYEhx2SyR8bLimAZ18 T9I/+2iFT9FZi6e9VvFW7lR2lU7Xz1zWutTP0SG2hJTm8O74A/m3EMdDoI3gDTJWc5X6 cTeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696596900; x=1697201700; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1hGVnjdGEOumYZe081/NvT5dGB2xwJn4Ju//yjOVJPI=; b=L7uVi4eOAzhvkzAMooQuW4i5PnYBfWiz3P7fULGDxs5ZO4m951QWCLFhqGnlvGGfyD rf+wU5tirhSQciNcWdCl7BcoMUMIl7FUZGCLGGLA/E+OPAxgxt6MyOR9HZj6EAtu22fk tw2XKa0IqdBkoc9QwvPEDveMcgV9P6kl3d3FNIM3VLXFVwowQ6bW9ANsJwG+Dln98/LX fBWNh5TaP5WIArqA28dDw7AWYhWvpfWQgtPTgOwdSDQKPJPL0GArGdlKldLhSlauLrEy XpNdWPaTN9hJ93Ir0W/xNDqcxxZdhmTqtahAx3PBUfQx9EDZms8gZiZWQV1a0A+aS8c3 nEbA== X-Gm-Message-State: AOJu0YzYtQrR06udWeh2NdWzMhgRutDAy2xfTTJqxPAVvkMjIZgqVfDB qW5GpRQu/gDP//Iq3Vyn3oL7PMUw8NGunw== X-Google-Smtp-Source: AGHT+IGA2SkMIhhjl5o3xK0Cgzq/nu9xewMEnyg1G2kSMo60FMhO8VSwk2kxX++tiRWPSK2sFhQgzA== X-Received: by 2002:a17:907:1dd8:b0:9ad:f143:e554 with SMTP id og24-20020a1709071dd800b009adf143e554mr6590860ejc.30.1696596899617; Fri, 06 Oct 2023 05:54:59 -0700 (PDT) Received: from sauvignon.fi.muni.cz (laomedon.fi.muni.cz. [147.251.42.107]) by smtp.gmail.com with ESMTPSA id p26-20020a1709060dda00b0099bc08862b6sm2894660eji.171.2023.10.06.05.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 05:54:59 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, stern@rowland.harvard.edu, oneukum@suse.com, jonathan.derrick@linux.dev, Milan Broz Subject: [RFC PATCH 6/6] usb-storage, uas: Disable security commands (OPAL) for RT9210 chip family Date: Fri, 6 Oct 2023 14:54:45 +0200 Message-ID: <20231006125445.122380-7-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231006125445.122380-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Realtek 9210 family (NVME to USB bridge) adapters always set the write-protected bit for the whole drive if an OPAL locking range is defined (even if the OPAL locking range just covers part of the disk). The only way to recover is PSID reset and physical reconnection of the device. This looks like a wrong implementation of OPAL standard (and I will try to report it to Realtek as it happens for all firmware versions I have), but for now, these adapters are unusable for OPAL. Signed-off-by: Milan Broz --- drivers/usb/storage/unusual_devs.h | 11 +++++++++++ drivers/usb/storage/unusual_uas.h | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h index 20dcbccb290b..b7c0df180e5d 100644 --- a/drivers/usb/storage/unusual_devs.h +++ b/drivers/usb/storage/unusual_devs.h @@ -1476,6 +1476,17 @@ UNUSUAL_DEV( 0x0bc2, 0x3332, 0x0000, 0x9999, USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_NO_WP_DETECT ), +/* + * Realtek 9210 family set global write-protection flag + * for any OPAL locking range making device unusable + * Reported-by: Milan Broz + */ +UNUSUAL_DEV( 0x0bda, 0x9210, 0x0000, 0xffff, + "Realtek", + "", + USB_SC_DEVICE, USB_PR_DEVICE, NULL, + US_FL_IGNORE_OPAL), + UNUSUAL_DEV( 0x0d49, 0x7310, 0x0000, 0x9999, "Maxtor", "USB to SATA", diff --git a/drivers/usb/storage/unusual_uas.h b/drivers/usb/storage/unusual_uas.h index 1f8c9b16a0fb..71ab824bfb32 100644 --- a/drivers/usb/storage/unusual_uas.h +++ b/drivers/usb/storage/unusual_uas.h @@ -185,3 +185,14 @@ UNUSUAL_DEV(0x4971, 0x8024, 0x0000, 0x9999, "External HDD", USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_ALWAYS_SYNC), + +/* + * Realtek 9210 family set global write-protection flag + * for any OPAL locking range making device unusable + * Reported-by: Milan Broz + */ +UNUSUAL_DEV(0x0bda, 0x9210, 0x0000, 0xffff, + "Realtek", + "", + USB_SC_DEVICE, USB_PR_DEVICE, NULL, + US_FL_IGNORE_OPAL),