From patchwork Mon Oct 16 07:25:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 734952 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 9FA49CDB482 for ; Mon, 16 Oct 2023 07:26:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232064AbjJPH0V (ORCPT ); Mon, 16 Oct 2023 03:26:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231360AbjJPH0R (ORCPT ); Mon, 16 Oct 2023 03:26:17 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30789E3; Mon, 16 Oct 2023 00:26:15 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-53de0d1dc46so7195559a12.3; Mon, 16 Oct 2023 00:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697441173; x=1698045973; 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=fOSXwcuF+GSDreunSXbhvKj4nQkeji3aVTKc3F8VpKY=; b=AGNWZ8kH/UNwTnbPwHIs28mfCtQ6Ad0G0M5MRf94rWAcBGZrL7EpK3jN61XJAkB1Sq eIkORgy6ydsE6R3WXV2whihVLGejTnZk7FgSENO6Ki9ZOsfjLBZsTFuM8j0MTqlmrXMP gZwOT+eHWJXYHhLWXINFDjNVK/e4o31+K2YlD/7rFtJSJtsZ4mE/EnzZuhT7vmGyoN9Z asoEoWqFOj22xmu7PGSCevyNgHJ/3/frIERHs2OyptgdoGBdrByKkRuS5AaDRPzFz7E+ SuctTyNZayy2UTYqVOSRNYU/6aF9YJzHO+KTRmh9XIuq4OeWjvnFQKL5Nk25lroa5F+T 4TxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697441173; x=1698045973; 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=fOSXwcuF+GSDreunSXbhvKj4nQkeji3aVTKc3F8VpKY=; b=HAIlu6/+dLIoSMYQYkPboCXpKdngylX5ah2K6WWADkSL9s9QvPqQ+0uspo7EHFLfWB CuNzTmilI/o9HHKeexcKC55FVITlL7wfyBu6KHvQPGHc/NBP3dJ8fe2kUgqkA304ilLX JgqlVWV6w3piEbjZckQPCHj+ircItFaJHARl6WHJXDx/K91t/7KsfDI/gM/ADkWi8m8F ZntwUbKcffYB1FflgmC9JrSKoVbCVAiJOYBbYrdj4EwrXYzNUfrgLGyWOnZ3naw/Qk+z kbmshY30j+dCdIJxPLLfDJ/2+1g7rgdNSZ2nTj73NX8Lvc4pPSY8RSZRLHblTPCzmBNB tjnA== X-Gm-Message-State: AOJu0YzMzE1vkT9E0jCbmPfGU5R+a7Re1FMw9n1GHFF4hCA6vA05O5/+ VYVidLoe7f/ScvUofjxuk8sFjhZroYdaKg== X-Google-Smtp-Source: AGHT+IHrIgCPnkFV+WXt1uCcBlpFFNAPTJj/iymXR4CrSQnNyTqd5IhaQPVir5ePxZNr4rgqU/rQSw== X-Received: by 2002:a17:906:3050:b0:9ad:df85:97ae with SMTP id d16-20020a170906305000b009addf8597aemr27905837ejd.66.1697441173435; Mon, 16 Oct 2023 00:26:13 -0700 (PDT) Received: from sauvignon.fi.muni.cz ([2001:718:801:22c:bdcb:518:be8f:6a76]) by smtp.gmail.com with ESMTPSA id n25-20020a17090673d900b0099297782aa9sm3399980ejl.49.2023.10.16.00.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:26:13 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, oneukum@suse.com, Milan Broz Subject: [PATCH 1/7] usb-storage: remove UNUSUAL_VENDOR_INTF macro Date: Mon, 16 Oct 2023 09:25:58 +0200 Message-ID: <20231016072604.40179-2-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016072604.40179-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> <20231016072604.40179-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 ab4b71644a26 ("USB: storage: fix Huawei mode switching regression") Fixes: ab4b71644a26 ("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 Mon Oct 16 07:25:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 734204 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 DBA77CDB465 for ; Mon, 16 Oct 2023 07:26:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232012AbjJPH0U (ORCPT ); Mon, 16 Oct 2023 03:26:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231139AbjJPH0R (ORCPT ); Mon, 16 Oct 2023 03:26:17 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 277B1AD; Mon, 16 Oct 2023 00:26:16 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-99de884ad25so670917666b.3; Mon, 16 Oct 2023 00:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697441174; x=1698045974; 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=9yn0kwXr1RVgMWT0A2+tKxIpUEAvRZLOMuNavXtkYMc=; b=nBr9a8roZ3rnMTd8GYjVANyeNO5sdgizuAM6x42mj0HnJ8yOYGNgiR0ybSEkcIa/xV fvSp3X1fNFOdD51SL8E6ItTCNZOhxL/sutfI0IPJe0n6uKhzLqoH3cTNjPUQMRWzoE1r qj1hvxP6DYT/BAOX/IeT5p9NFuDC9tiS/SqzE+MtYag9zufGanSJx6cf5N/Nuv73KUYw EQah9AGYdyloioC8olphDvoaZVzv4BONoP5M/7xG5zw699kyZ45XWQcp9ry1l0/iSY+v MknEQkcidZD7dfNpPvibP4XtmPti6vwQOtLt82A34iVgyMmEjlH4mpfu63Pdm37RxuLq 1Uag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697441174; x=1698045974; 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=9yn0kwXr1RVgMWT0A2+tKxIpUEAvRZLOMuNavXtkYMc=; b=eX5ISKpefxlqXErO9gHRIiDCCGW0eEK5Ub4671R7vU174R+yBrzZHgDVlINRn7c17I 55RfSUrRx1pRQ8sF/z5V1h+x+EhrTtT7uxqX0Wv4ZyzstIyC7G4o3tESn/sYrkro5Rff 8/2mRP02xkbLFCvf/jOflXTcKG1fp/eksA4swuRHWuRuSD5tssnoLYzB/2oqRbnNw2k2 PnvSidiQcTzCVkCfwAwmsUM9fy3wEzJ+bd6cMzr1WMhImH4X0AgTq/KXfXwzGcPkV+PI H9RUvPDhtQffDwyZLPP1gTjQPHKyTctMpftCoohTg5b+Vq/WQaTrKyG0VNtc7j5DxhGK zBCg== X-Gm-Message-State: AOJu0YyxVObHI/Bw+P7ysTceSpQ9Q8G5SxfIK2eGQG3KlnU4ziXvfOS1 yguS6dkdzOLJb3ZMw+9tdg2vX5KrqMNYiQ== X-Google-Smtp-Source: AGHT+IHIeXRmFlzDZVkQKaFpfF+F3X0Mii7YkIxxbIf/SjfUoqccK4V/i/hpsmqNcnXKU9YnjQOk+w== X-Received: by 2002:a17:907:7804:b0:9ae:5fe1:ef01 with SMTP id la4-20020a170907780400b009ae5fe1ef01mr28363422ejc.37.1697441174403; Mon, 16 Oct 2023 00:26:14 -0700 (PDT) Received: from sauvignon.fi.muni.cz ([2001:718:801:22c:bdcb:518:be8f:6a76]) by smtp.gmail.com with ESMTPSA id n25-20020a17090673d900b0099297782aa9sm3399980ejl.49.2023.10.16.00.26.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:26:14 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, oneukum@suse.com, Milan Broz Subject: [PATCH 2/7] usb-storage,uas: make internal quirks flags 64bit Date: Mon, 16 Oct 2023 09:25:59 +0200 Message-ID: <20231016072604.40179-3-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016072604.40179-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> <20231016072604.40179-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 use all 32 bits. (Following patches are needed to use driver_info with a 64-bit value properly.) Signed-off-by: Milan Broz Reviewed-by: Alan Stern --- 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 Mon Oct 16 07:26:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 734203 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 E4EE3CDB465 for ; Mon, 16 Oct 2023 07:26:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231995AbjJPH0Z (ORCPT ); Mon, 16 Oct 2023 03:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231974AbjJPH0T (ORCPT ); Mon, 16 Oct 2023 03:26:19 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DAE1C5; Mon, 16 Oct 2023 00:26:17 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9ada2e6e75fso724280166b.2; Mon, 16 Oct 2023 00:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697441175; x=1698045975; 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=MpEK+6I3PpgTQZdQO8LItkPIzXzeXnEoEvyoBxG3EVo=; b=l1KWvGubtZBzkrkOsUzbmWzHdLyIw8QsXMDfGMcU4QFtTNlF5Lgm8pXJGlUR6hohzI Vt3eFGgKgZ4LRNoatSCs9g1JRilQiUIgXeTRRXnPuaUs1Ys9pyAnb9tdNxj1QxaZBml+ I+Hqr9D2YGj38lLfif5cXKLO7PrWvBdXEsgAn6LEKb8uj1x7KEo8wBdSXxsaFkE6Z1r5 uOEvZGdIKmQeSdZuN04m9L12mATMOgaq7mLJgET1UJtmEFcQIqqnH++f18Twoz1Hqx2L GUkZzBhqE+5ddFA6xtWpbOhTmfXokbE/YoVwOc8+EaOC2ewfYahfn7ptdR8vRaBvkZye 30jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697441175; x=1698045975; 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=MpEK+6I3PpgTQZdQO8LItkPIzXzeXnEoEvyoBxG3EVo=; b=Dtm9trzRfrrUqvR0Aw++9fpTEYj7uB8pIBRBlFRhhkCxo6bBolpARsV5dzk940cNNM nPFrKPglB4BuUGX1QpoSM20HlgtBh7/AYRdX/2Xdx79uCOGZX097r2HoWTeSUWHFgxUe AwXA63hbMAsoAImk1e1wolqcq80lP4skUoPqfKWDr90Xc3v9vwpxA5RAg1B5NnNUie3b 2Ex+sRDTFBxD8F8P1FIKPPRi5+MnFDyutvg03pEF5lEY4YIk9FBADibFpLuzusph5mzz lQVwgeYK5Zs+F/5S/ztvwdzHvxI2qpY7xKVaMu31aZrpLAorTsNkAw4HU1jnJPP4CijO C1xQ== X-Gm-Message-State: AOJu0Yxy1hGDoJnpNDxC4pak4BWjmtLuxIO6ryg6YGnGWFJQtdoDajMY /JJWCOuGN2rViRZ4E6M9zMqmgeEwzVnQ7g== X-Google-Smtp-Source: AGHT+IF+QTecaI8s++ZdNtThXURHqlDpXG7ymAOWDnhf3SnjyC6yCabi85An3ZWkr/F3WDvLFIf9Zg== X-Received: by 2002:a17:906:308b:b0:9b6:50cd:a222 with SMTP id 11-20020a170906308b00b009b650cda222mr25617284ejv.54.1697441175280; Mon, 16 Oct 2023 00:26:15 -0700 (PDT) Received: from sauvignon.fi.muni.cz ([2001:718:801:22c:bdcb:518:be8f:6a76]) by smtp.gmail.com with ESMTPSA id n25-20020a17090673d900b0099297782aa9sm3399980ejl.49.2023.10.16.00.26.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:26:14 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, oneukum@suse.com, Milan Broz Subject: [PATCH 3/7] usb-storage: use fflags index only in usb-storage driver Date: Mon, 16 Oct 2023 09:26:00 +0200 Message-ID: <20231016072604.40179-4-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016072604.40179-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> <20231016072604.40179-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 Reviewed-by: Alan Stern --- 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 | 9 +++++---- drivers/usb/storage/usb.h | 3 ++- 15 files changed, 20 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..db8c4d2c8d11 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 = @@ -925,7 +925,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 +963,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 +1121,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 Mon Oct 16 07:26:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 734951 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 223FFC46CA1 for ; Mon, 16 Oct 2023 07:26:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232100AbjJPH00 (ORCPT ); Mon, 16 Oct 2023 03:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232007AbjJPH0U (ORCPT ); Mon, 16 Oct 2023 03:26:20 -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 01D24DC; Mon, 16 Oct 2023 00:26:18 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9becde9ea7bso320557766b.0; Mon, 16 Oct 2023 00:26:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697441176; x=1698045976; 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=MNA1y/mtBFn8fcsT/aV9mJEQWXJPS9oY7t41UggQAy0=; b=OyqfPzpWkye/F1GSeCIgsvObX73IheUn+hy/QWCHax54FYQ3TLrIw60xslP5hVZpsp 0Qas7yQHYvkt4oXgOd+s56nDr4eYYYQbDx8oO/qsxlRYAG/9SDCALYbxqg6J7X7g5F4Y dvKiq2WpFYCILeMJfvpHa6gzt2j0Gd1Z2iMkE13e6tRLQObGu09VydvFcKR08JNCFhNz kFpy13bABc/NeLKbyUJt2N1x2QpxS0H5hVkwmt5/2QcsKB1bfj5DML4nB4rYIfSXSkny kfij1jbcGzqLPCt9AWL2CPlhGvPGOnWkJQA8b+G73TprLvdQRfiVdogZXiKB8hPzSpvK eU9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697441176; x=1698045976; 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=MNA1y/mtBFn8fcsT/aV9mJEQWXJPS9oY7t41UggQAy0=; b=T2BTV897AYVua3aL8xyRT+tWH4W1BrU8JFZxyh+5iD+Cuu1RfolB/f4wf/BXcjpilp UAmlEOqUPDLKUpfCzLpo9Pw9pDNwW7UPz4oSYHLAeit4Opy5qDfXiZKvidU50B78w+TT 0RQfAzHiCgZhsYVmzxa/gV+z1mF+05tPQiivU6qtXpEZkcu3p8EBTlcim4yqf5mnfEcw zjFjvbYVBrFzoBIkVWKm2tTmKBffhzcOSzk7xYFdxo7W4CsC7LL5TOjD9V6nZ02IM6me OsN9nZCs7atzFWI70S+03byboszupVlGXTxnootD54+A3iLKuboyRoPdEQfqVqbCN6D5 PUlw== X-Gm-Message-State: AOJu0Yy/bCo0BCAG/0c7EZnJ8Bv8WLNTDtZFaNRd/pLvsICmCersvMEG /T7Sm4MRnuLBfTu+sBZ38oDKbP3N1QFH1w== X-Google-Smtp-Source: AGHT+IGY+22luUiXOBldZFe0qwnxCPHn5u7UX9NN8ACINN3rRpDXyZRHKRGUcpZsn/69GARAGwGKZQ== X-Received: by 2002:a17:907:1c94:b0:9bd:d405:4e8a with SMTP id nb20-20020a1709071c9400b009bdd4054e8amr5796854ejc.17.1697441176251; Mon, 16 Oct 2023 00:26:16 -0700 (PDT) Received: from sauvignon.fi.muni.cz ([2001:718:801:22c:bdcb:518:be8f:6a76]) by smtp.gmail.com with ESMTPSA id n25-20020a17090673d900b0099297782aa9sm3399980ejl.49.2023.10.16.00.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:26:15 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, oneukum@suse.com, Milan Broz Subject: [PATCH 4/7] usb-storage,uas: use host helper to generate driver info Date: Mon, 16 Oct 2023 09:26:01 +0200 Message-ID: <20231016072604.40179-5-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016072604.40179-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> <20231016072604.40179-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 can be stored in driver_info in 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 the USB list https://lore.kernel.org/linux-usb/f9e8acb5-32d5-4a30-859f-d4336a86b31a@gmail.com/ The initial solution to use a 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 an index, not the actual value. This patch adds a host-compiled program that processes unusual_devs.h (and unusual_uas.h) and generates files usb-ids.c and usb-ids-uas.c (for pre-processed USB device table with 32-bit device info). These files also contain a generated translation table for device_info to 64-bit values. The 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 in this patch. Signed-off-by: Milan Broz --- drivers/usb/storage/Makefile | 25 ++++ drivers/usb/storage/mkflags.c | 226 +++++++++++++++++++++++++++++ drivers/usb/storage/uas-detect.h | 4 +- drivers/usb/storage/uas.c | 20 +-- drivers/usb/storage/usb-ids.h | 33 +++++ drivers/usb/storage/usb.c | 10 +- drivers/usb/storage/usual-tables.c | 23 +-- 7 files changed, 301 insertions(+), 40 deletions(-) create mode 100644 drivers/usb/storage/mkflags.c create mode 100644 drivers/usb/storage/usb-ids.h diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile index 46635fa4a340..612678f108d0 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 + +# The mkflags host-compiled generator produces usb-ids.c (usb-storage) +# and usb-ids-uas.c (uas) with USB device tables. +# These tables include pre-computed 32-bit flags as USB driver device_info +# (where the value is stored) can be only 32-bit. +# The most significant bit means it is index to 64-bit flags table pre-computed +# by mkflags. Currently used only by mass-storage and UAS driver. + +$(obj)/usual-tables.o: $(obj)/usb-ids.c +$(obj)/uas.o: $(obj)/usb-ids-uas.c +clean-files := usb-ids.c usb-ids-uas.c +HOSTCFLAGS_mkflags.o := -I $(srctree)/include/ +hostprogs += mkflags + +quiet_cmd_mkflag_storage = FLAGS $@ +cmd_mkflag_storage = $(obj)/mkflags storage > $@ + +quiet_cmd_mkflag_uas = FLAGS $@ +cmd_mkflag_uas = $(obj)/mkflags uas > $@ + +$(obj)/usb-ids.c: $(obj)/mkflags FORCE + $(call if_changed,mkflag_storage) + +$(obj)/usb-ids-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..2514ffef0154 --- /dev/null +++ b/drivers/usb/storage/mkflags.c @@ -0,0 +1,226 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* + * This is host-compiled generator for usb-ids.c (usb-storage) + * and usb-ids-uas.c (uas). + * + * Generated files contain pre-computed 32-bit flags as USB driver + * device_info (where the value is stored) can be only 32-bit. + * The most significant bit means that it is index to 64-bit flags table + * named usb_stor_di_to_u64 with size stored in usb_stor_di_idx_size + * (for sanity check). + * + * Note that usb-storage driver contains also UAS devices, while UAS + * driver contains only UAS entries (so there can be duplicities). + */ + +#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 + +/* USB-atached mass storage */ +#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" +#undef UNUSUAL_DEV + +/* UAS */ +#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" +#undef UNUSUAL_DEV + +/* Terminating entry */ +{ .flags = FLAGS_END } +}; +#undef USUAL_DEV +#undef COMPLIANT_DEV +#undef IS_ENABLED + +/* Highest bit indicates it is index to usb_stor_di_to_u64 table */ +#define HI32 (uint32_t)(1UL << 31) + +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%04x, .idProduct =0x%04x, " + ".bcdDevice_lo = 0x%04x, .bcdDevice_hi = 0x%04x, .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(const char *type) +{ + int i, count; + + printf("const u64 usb_%s_di_to_u64[] = {\n", type); + for (i = 0, count = 0; vals[i].flags != FLAGS_END; i++) { + if (vals[i].set == FLAGS_SET) { + printf("\t/* 0x%02x */ 0x%llx,\n", vals[i].idx, vals[i].flags); + count++; + } + } + printf("};\n\n"); + printf("const unsigned long usb_%s_di_idx_size = %i;\n\n", type, count); +} + +static void print_usb_storage(void) +{ + printf("#include \n\n"); + + /* conversion table from 32-bit device_flags to 64-bit flags */ + print_usb_flags("stor"); + + /* 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{ } /* Terminating entry */\n};\n"); + printf("MODULE_DEVICE_TABLE(usb, usb_storage_usb_ids);\n"); +} + +static void print_usb_uas(void) +{ + printf("#include \n\n"); + + /* conversion table from 32-bit device_flags to 64-bit flags */ + print_usb_flags("uas"); + + /* 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{ } /* 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], "storage") && strcmp(argv[1], "uas"))) { + printf("Please specify output type: storage or uas.\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], "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..fbe068b138c4 100644 --- a/drivers/usb/storage/uas-detect.h +++ b/drivers/usb/storage/uas-detect.h @@ -54,12 +54,14 @@ 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, + const u64 *di_to_u64, + unsigned long di_idx_size, 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); - u64 flags = id->driver_info; + u64 flags = usb_stor_di2flags(di_to_u64, di_idx_size, 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..8a1c4449dcc9 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -26,6 +26,7 @@ #include #include +#include "usb-ids.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 "usb-ids-uas.c" static int uas_switch_interface(struct usb_device *udev, struct usb_interface *intf) @@ -990,7 +977,8 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id) struct usb_device *udev = interface_to_usbdev(intf); u64 dev_flags; - if (!uas_use_uas_driver(intf, id, &dev_flags)) + if (!uas_use_uas_driver(intf, id, usb_uas_di_to_u64, usb_uas_di_idx_size, + &dev_flags)) return -ENODEV; if (uas_switch_interface(udev, intf)) diff --git a/drivers/usb/storage/usb-ids.h b/drivers/usb/storage/usb-ids.h new file mode 100644 index 000000000000..8bfd84e07f96 --- /dev/null +++ b/drivers/usb/storage/usb-ids.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _USB_STOR_IDS_H_ +#define _USB_STOR_IDS_H_ + +#include +#include + +/* Conversion of 32-bit quirks flags for 32-bit platforms */ +extern const unsigned long usb_stor_di_idx_size; +extern const unsigned long usb_uas_di_idx_size; +extern const u64 usb_stor_di_to_u64[]; +extern const u64 usb_uas_di_to_u64[]; + +static u64 usb_stor_di2flags(const u64 *di_to_u64, + unsigned long idx_size, unsigned long idx) +{ + u64 flags = 0; + + if (idx < (1UL << 31)) + return idx; + + idx -= (1UL << 31); + + if (idx < idx_size) + flags = di_to_u64[idx]; + else + WARN_ONCE(true, "usb_stor_di_to_u64 table not updated"); + + return flags; +} + +#endif diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index db8c4d2c8d11..bb48ab1bd461 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -56,6 +56,7 @@ #include "sierra_ms.h" #include "option_ms.h" +#include "usb-ids.h" #if IS_ENABLED(CONFIG_USB_UAS) #include "uas-detect.h" #endif @@ -589,7 +590,11 @@ 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(usb_stor_di_to_u64, usb_stor_di_idx_size, + id->driver_info); + else + us->fflags = id->driver_info; usb_stor_adjust_quirks(us->pusb_dev, &us->fflags); if (us->fflags & US_FL_IGNORE_DEVICE) { @@ -1091,7 +1096,8 @@ static int storage_probe(struct usb_interface *intf, /* If uas is enabled and this device can do uas then ignore it. */ #if IS_ENABLED(CONFIG_USB_UAS) - if (uas_use_uas_driver(intf, id, NULL)) + if (uas_use_uas_driver(intf, id, usb_stor_di_to_u64, + usb_stor_di_idx_size, NULL)) return -ENXIO; #endif diff --git a/drivers/usb/storage/usual-tables.c b/drivers/usb/storage/usual-tables.c index a26029e43dfd..40ef861dbd08 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 usb-ids.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 "usb-ids.c" /* * The table of devices to ignore From patchwork Mon Oct 16 07:26:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 734202 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 9DFBFCDB465 for ; Mon, 16 Oct 2023 07:26:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232255AbjJPH0e (ORCPT ); Mon, 16 Oct 2023 03:26:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232025AbjJPH0U (ORCPT ); Mon, 16 Oct 2023 03:26:20 -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 2A5B0E1; Mon, 16 Oct 2023 00:26:19 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9bf0ac97fdeso216514166b.2; Mon, 16 Oct 2023 00:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697441177; x=1698045977; 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=xnxVJqIRdQtouvx5n5R9hP/D5oVVipLHSJQwRP3ossw=; b=TlUmt8hZ4LVdRAf781E3554vUA8EVfRwwmGzOD5eA7/8B7f4WsmPiM3YfqytxtS4YX LO3k3/nMSmnx0qh00U3dmHG6mE7wjOItSX2Sfb4tzizdQupVInJMB3G26PZ5pLfVum60 HLjhubNwo1YtVXWayYuvZceL765Gm+yZDuvHlMkrAR+ijWPmegB1M8sfVYSct1DD1aAN b8pcm4D4tZ8feAzlTeKDYYEL/O6pDM0bI0dli4sV+pQ2qvERueHCl+HQvaKlNe4ic8aS uNfQiBC5LouSln7uuoPRmg4YwkOlUhxLLBPxkP06wU+6O1NxW4ZvoqbK8rsy9McL7zup QWBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697441177; x=1698045977; 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=xnxVJqIRdQtouvx5n5R9hP/D5oVVipLHSJQwRP3ossw=; b=FA3c3f3/ifnlOzJe67tiq7bXgRhgOXDHmipYB2Q0gOmcegjETOMRGKpg0zn12jjjIA L4IL4NOfVlZYklWZ3xwC7i4XTKOtDX7MCRVN3JEHC9mOdM2Fop32JMvqW41CSxKO02WS BWefSKJ+nAhqNsF9fRm3PrhyEOAO9XugpT/ac/wbIriP59RIcF1X3mVoNTUw0Q0qumsx YdkJjdhZT6tsuW/G90e+IrqTu+d6JZ0NRlqBlj4P9SqMNSipD1tVNGiagq73bd1JNUYJ BQ+Etx9pwnccZFEuztfGRxsLzjXFU2G5AAo9VVmAsTcg/G5975NYbM38mfqKOGyN3pne AhEQ== X-Gm-Message-State: AOJu0Yw3jBKkdMUpKpJfVylP/hQImkN8U65MYvGQjxqxJA5tzmQqoAGB ZszxrxxPz9L1FaqATS2Fp0ne63gm4R5rLg== X-Google-Smtp-Source: AGHT+IH9KvZqYihmyg2FnPlR7/ZYAkszc3cWqEXIzdLn9JoffIMrIfjfZIs0poWr0ZmOjTinLnsjuA== X-Received: by 2002:a17:906:9c1:b0:9b2:89ec:d701 with SMTP id r1-20020a17090609c100b009b289ecd701mr32086734eje.27.1697441177480; Mon, 16 Oct 2023 00:26:17 -0700 (PDT) Received: from sauvignon.fi.muni.cz ([2001:718:801:22c:bdcb:518:be8f:6a76]) by smtp.gmail.com with ESMTPSA id n25-20020a17090673d900b0099297782aa9sm3399980ejl.49.2023.10.16.00.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:26:17 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, oneukum@suse.com, Milan Broz Subject: [PATCH 5/7] usb-storage,uas: do not convert device_info for 64-bit platforms Date: Mon, 16 Oct 2023 09:26:02 +0200 Message-ID: <20231016072604.40179-6-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016072604.40179-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> <20231016072604.40179-1-gmazyland@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch optimizes the previous one for 64-bit platforms, where unsigned long is 64-bit, so we do not need to convert quirk flags to 32-bit index. Signed-off-by: Milan Broz --- drivers/usb/storage/Makefile | 3 +++ drivers/usb/storage/mkflags.c | 9 +++++++++ drivers/usb/storage/usb-ids.h | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile index 612678f108d0..62ebaa76ef95 100644 --- a/drivers/usb/storage/Makefile +++ b/drivers/usb/storage/Makefile @@ -57,6 +57,9 @@ $(obj)/usual-tables.o: $(obj)/usb-ids.c $(obj)/uas.o: $(obj)/usb-ids-uas.c clean-files := usb-ids.c usb-ids-uas.c HOSTCFLAGS_mkflags.o := -I $(srctree)/include/ +ifdef CONFIG_64BIT +HOSTCFLAGS_mkflags.o += -D CONFIG_64BIT +endif hostprogs += mkflags quiet_cmd_mkflag_storage = FLAGS $@ diff --git a/drivers/usb/storage/mkflags.c b/drivers/usb/storage/mkflags.c index 2514ffef0154..08c37d2e52d6 100644 --- a/drivers/usb/storage/mkflags.c +++ b/drivers/usb/storage/mkflags.c @@ -89,11 +89,15 @@ static struct svals vals[] = { static unsigned long get_device_info(uint64_t flags, unsigned int idx) { +#ifndef CONFIG_64BIT if (flags < HI32) return (unsigned long)flags; /* Use index that will be processed in usb_stor_di2flags */ return HI32 + idx; +#else + return flags; +#endif } static void print_class(uint8_t bDeviceSubClass, uint8_t bDeviceProtocol) @@ -123,6 +127,10 @@ static void print_type(unsigned int type) static void print_usb_flags(const char *type) { +#ifdef CONFIG_64BIT + printf("const u64 usb_%s_di_to_u64[] = {};\n", type); + printf("const unsigned long usb_%s_di_idx_size = 0;\n\n", type); +#else int i, count; printf("const u64 usb_%s_di_to_u64[] = {\n", type); @@ -134,6 +142,7 @@ static void print_usb_flags(const char *type) } printf("};\n\n"); printf("const unsigned long usb_%s_di_idx_size = %i;\n\n", type, count); +#endif } static void print_usb_storage(void) diff --git a/drivers/usb/storage/usb-ids.h b/drivers/usb/storage/usb-ids.h index 8bfd84e07f96..4abe1a6d3a66 100644 --- a/drivers/usb/storage/usb-ids.h +++ b/drivers/usb/storage/usb-ids.h @@ -15,6 +15,9 @@ extern const u64 usb_uas_di_to_u64[]; static u64 usb_stor_di2flags(const u64 *di_to_u64, unsigned long idx_size, unsigned long idx) { +#if IS_ENABLED(CONFIG_64BIT) + return idx; +#else u64 flags = 0; if (idx < (1UL << 31)) @@ -28,6 +31,7 @@ static u64 usb_stor_di2flags(const u64 *di_to_u64, WARN_ONCE(true, "usb_stor_di_to_u64 table not updated"); return flags; +#endif } #endif From patchwork Mon Oct 16 07:26:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 734201 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 45EF7CDB465 for ; Mon, 16 Oct 2023 07:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232181AbjJPH0g (ORCPT ); Mon, 16 Oct 2023 03:26:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232073AbjJPH0Y (ORCPT ); Mon, 16 Oct 2023 03:26:24 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EB02E3; Mon, 16 Oct 2023 00:26:20 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9b1ebc80d0aso644385566b.0; Mon, 16 Oct 2023 00:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697441178; x=1698045978; 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=AKEonLkFv7flAIkFjaxuLAbAMwome4P+GcLKsO3pvRg=; b=LkHVELcENYEuD66PF4as0i61MUwXe0vYHeWRMDUalDBkgA6EF9TKG1Ps+hJLp+t1fd Wk7lQan00yKW9soXGBwxdHrMBvakt1YvH41Hf7XJL/cPOWJ1ewFtx6cpecddTWmh0pq9 Z+zibzdGR/G0JpPFwa+oHfhWcS6Z+pqkV3D+vYvLtxLu1tC5GciA0TBwwlducEXbxXbJ lmFYGaa5m120idt7FIIzaMyP+9nJmYefNOSl792f2nN2/24mTgtgk9RRUbU64OzCFM1n fu6rvtDK0gCHxKYPFpw20khSWKgQJM85A0RqzUma4ElAZa2yF9suF4rL18KTh7UKTjHn TAYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697441178; x=1698045978; 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=AKEonLkFv7flAIkFjaxuLAbAMwome4P+GcLKsO3pvRg=; b=MFuiHyod/aaYqii15qvf5ORWnrOOrRgzTDmP2MHDpRaOodost8WKsfy4ngp0B3j9uc d77cQGfbZJy19jcCmOOE1LMuxkQApjZzmYuZFu5aekny4nH5Jcb6/Eh/c/Kg2/UnRXFJ 9MiaDmAA0VUWen4JnYZkwp7fE3sME2WcmQ24ZqOsNT/jtrITOuLahJB0g0YOj4HNjBst 5jGj8FgNrWfGOgC+AbAZ+vDnIbZ325sY2m4/j6z/7o96e5ZxiuvNaPHhBmnfGB2YqaiW PWUyi0yV58ss/eZOG+owGMKHZNqAoY0rBnim6TGctLCmqn+i9iwPCNG7Wu10fhGH3HlR scNw== X-Gm-Message-State: AOJu0YxC7itaSf6EeLmYki0KRo7li74UUDFP2e+0tF3A8Y3VA/wPNHKG sE30uhJcFQlBdMR2uw3TP34hqdTkP9IXVQ== X-Google-Smtp-Source: AGHT+IHdmnwLce4qtarN1rGmGRlcyujEaX4lm1wqfQv8yqEMT6/tV7Pw2rgJvyZae9i6xgGyA9fHVg== X-Received: by 2002:a17:906:db08:b0:9bd:bb63:49db with SMTP id xj8-20020a170906db0800b009bdbb6349dbmr7432298ejb.7.1697441178436; Mon, 16 Oct 2023 00:26:18 -0700 (PDT) Received: from sauvignon.fi.muni.cz ([2001:718:801:22c:bdcb:518:be8f:6a76]) by smtp.gmail.com with ESMTPSA id n25-20020a17090673d900b0099297782aa9sm3399980ejl.49.2023.10.16.00.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:26:18 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, oneukum@suse.com, Milan Broz Subject: [PATCH 6/7] usb-storage,uas: enable security commands for USB-attached storage Date: Mon, 16 Oct 2023 09:26:03 +0200 Message-ID: <20231016072604.40179-7-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016072604.40179-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> <20231016072604.40179-1-gmazyland@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch enables security commands (currently mostly OPAL hardware encryption) for UAS and usb-storage drivers. The SCSI layer uses security commands for the initial OPAL support check (discovery command) and for in-kernel sed-ioctl interface. Some adapters support these commands, but firmware can be buggy or implemented incorrectly; the patch also adds a new quirk IGNORE_OPAL to disable security commands for particular devices. If adapters do not implement needed commands (ATA-12 pass-thru), the commands are rejected, and OPAL support remains disabled. (This is how it already works if OPAL command is sent from userspace directly, like in sedutils.) Signed-off-by: Milan Broz --- Documentation/admin-guide/kernel-parameters.txt | 2 ++ 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, 17 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 0a1731a0f0ef..e3f072cbb833 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6885,6 +6885,8 @@ y = ALWAYS_SYNC (issue a SYNCHRONIZE_CACHE even if the device claims no cache, not on uas) + z = IGNORE_OPAL (the device security commands + (OPAL) are broken, do not enable them); Example: quirks=0419:aaf5:rl,0421:0433:rc user_debug= [KNL,ARM] 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 8a1c4449dcc9..8967767d6753 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 bb48ab1bd461..3facc80292d7 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -477,7 +477,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) { @@ -566,6 +566,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 Mon Oct 16 07:26:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 734950 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 21342C41513 for ; Mon, 16 Oct 2023 07:26:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232327AbjJPH0f (ORCPT ); Mon, 16 Oct 2023 03:26:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231360AbjJPH0Y (ORCPT ); Mon, 16 Oct 2023 03:26:24 -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 CD437E5; Mon, 16 Oct 2023 00:26:20 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9bda758748eso384441366b.2; Mon, 16 Oct 2023 00:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697441179; x=1698045979; 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=KOS3bfRHpSjq+KjwwuTZXPYnmnU2SrY9skeV5ne/EMA=; b=LKhRg9NSpl6Hz8TVOYTB693HSn+Z1FpcTVCrocTRFU/kpN0Ztdh4cieVgP3x4ion8w aE+t7vSdJnAYusoO0IgwFZziJ8Bh1TtlptFmEtFsBQdF8RCAHLrcIxQnwtTByIlCv0eZ 3UHIyvtCUQuAAyULkcqNn8tezuMeAeJWxQyad+HaqrMNIkY1CCVTfVRoTEIjEpjt1Oo4 uhypeGKDh3jIfhhBJXE3ZonRSEgNNyDGV5/bs6MoW4sMkLOmLo0L6WSYilN00yjnzTM0 ty2UW1n7hxhQlzAgBJtM34360KAsS1C1gnywaL5QZ3f/xFt7QLUjSnFgEdvILSLeGGAr 4DVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697441179; x=1698045979; 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=KOS3bfRHpSjq+KjwwuTZXPYnmnU2SrY9skeV5ne/EMA=; b=wB10NfaJ5nerHVh9WHi2P8nMb79CXIly91cuAx+3nrdtqQ/m0yy4b0VtoHdoSNsd3d CqoRAtYpfgCeAhZtLgoHkOE4rY0OozYgc1aHmSdbfOitZIo220EaQYvleuxHiJch4o4M AJXRxMkZci0PjTbvwqUSbhvLmGz2CvR3p/1ltNocxSNdJVX2J7Ah6WMb53hE2HNYpwRj rdfnn9snB1EmUcv1YtWKCFSEaxV8KwitnQLReNIKcgvIHH/SmnyH2iZkh53O8wGA6nuf PxhZDQZYMs0OBHYnkGeeQUoKvFxUNI4nOPkMwV5yN+QS61Z9nE2Dq1P5W0N+oJrBb5S6 yDeA== X-Gm-Message-State: AOJu0YzxuM41bADEYLKuBKH5bcsIYnQp6NlZa5ZZEWFctU3f2Cm4mIjC iKm7y3zONdC44lMSintyRfWj66RLDdNhow== X-Google-Smtp-Source: AGHT+IFO4tXR9ct3VYA3BgM7fqoXA5ZDMFxuEVgLM2rzwljCBPA5fIuhT5M/dgg/hloZ1ax1XktjWg== X-Received: by 2002:a17:907:5c6:b0:9c4:6893:ccc5 with SMTP id wg6-20020a17090705c600b009c46893ccc5mr1369026ejb.57.1697441179356; Mon, 16 Oct 2023 00:26:19 -0700 (PDT) Received: from sauvignon.fi.muni.cz ([2001:718:801:22c:bdcb:518:be8f:6a76]) by smtp.gmail.com with ESMTPSA id n25-20020a17090673d900b0099297782aa9sm3399980ejl.49.2023.10.16.00.26.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:26:19 -0700 (PDT) From: Milan Broz To: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net, linux-scsi@vger.kernel.org, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, oneukum@suse.com, Milan Broz Subject: [PATCH 7/7] usb-storage,uas: disable security commands (OPAL) for RT9210 chip family Date: Mon, 16 Oct 2023 09:26:04 +0200 Message-ID: <20231016072604.40179-8-gmazyland@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016072604.40179-1-gmazyland@gmail.com> References: <20231006125445.122380-1-gmazyland@gmail.com> <20231016072604.40179-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..b32afded85ae 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 to NVMe/SATA bridge", + 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..8a32bb1654ed 100644 --- a/drivers/usb/storage/unusual_uas.h +++ b/drivers/usb/storage/unusual_uas.h @@ -83,6 +83,17 @@ UNUSUAL_DEV(0x0bc2, 0x331a, 0x0000, 0x9999, USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_NO_REPORT_LUNS), +/* + * 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 to NVMe/SATA bridge", + USB_SC_DEVICE, USB_PR_DEVICE, NULL, + US_FL_IGNORE_OPAL), + /* Reported-by: Benjamin Tissoires */ UNUSUAL_DEV(0x13fd, 0x3940, 0x0000, 0x9999, "Initio Corporation",