From mboxrd@z Thu Jan 1 00:00:00 1970 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 911B4C38A2D for ; Thu, 27 Oct 2022 07:50:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234105AbiJ0Hus (ORCPT ); Thu, 27 Oct 2022 03:50:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234370AbiJ0Hug (ORCPT ); Thu, 27 Oct 2022 03:50:36 -0400 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87D7131239 for ; Thu, 27 Oct 2022 00:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1666857035; x=1698393035; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6GtqkoXaZHwgPkDlVuJHEdQqbObB4/SbwEmgzdPZM0c=; b=jD0Qe3geumlab2jiDoFiwcZntJ9K7WK+UBpFyancNEh+j2FXjXsPrMV+ lRrVbEeYtF8na0iBC/SrDeVHLAxDl8bXcTUqfutZWNa/gIQ61UJqJ43bi eP8SGUY6oWu4mvaHKd+m3D/tvKQ0gSIW6LIomhKQp792PaWsCoJq8tBWV BlV0S2kaRBsqGksE/f1ndZLsirF5ImHUJR9Q1JUkcoWbKNq4U1V4hFtvh AAEEbwx2Fm0mRsVHfhg01ygR2uXvxr0nshWDrv9vHi4nKEKsWrskXR5HQ SYwcpo66ZHfZNL/FK7KiI7kIXOMO3dMXdzCebsv+v30OlqEOZpEg6JQY4 w==; X-IronPort-AV: E=Sophos;i="5.95,217,1661788800"; d="scan'208";a="214853397" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 Oct 2022 15:50:32 +0800 IronPort-SDR: r6Q2coEB8CYDyLHVRM3QyzbYtn9uVT0cpSJJNEmqKdT4JUxm6jkz9+vFmpKmTGXpMdodlyJmz9 3RfXKO0lB/Zj949EoBQRI5AWaHmjfB1uhtF9zqMdlQ+LdyckgiGM4Iciy4wEORaQ/d/jaCRRBR /HNZh9n8tdcxf+BRCcHd6RhQIfm0irJAO2B2oSZdbKTdfQLbN4kNlUbH3B6SxbUL0rNR+W55LM +PVTyOYUMzsDVJVLA9P+NQ7IWixqDschhKQ11iDdJ8Q3dAFZDwCDFPPFqrxfiFcWo+G8eQ+2Oe CAai6XzWd0/1BZO37QA6jPnE Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Oct 2022 00:09:53 -0700 IronPort-SDR: FnriQ3Sda9TaTyY8dyZ4zyUIx7EmeuT/z+uW0hn7pFhL/NHGk2OK1lsbe4/S49ZcwoqH+9ZC9z 4+o35gGRsFHbnmP5aCrx7xtiOZ5IF656j57nSKShWU+tcwKxUzFBVr66CWDHWxEnOWksURFago fAGeusMB40ykwjT+s40UvD7Sx3p5WyyPilWrO7Dx/x/5gus0g0MMx4RFJxhbT316ey6Q/8bcT6 Pt/fTfUzchC29+UFhouX45HQK922QVfFD4rfp/KXnr3YWL9sOHVgig/keOcpadCsHC6zhCQTYp 8is= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Oct 2022 00:50:32 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4MydBv5Yxzz1RwqL for ; Thu, 27 Oct 2022 00:50:31 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1666857031; x=1669449032; bh=6GtqkoXaZHwgPkDlVu JHEdQqbObB4/SbwEmgzdPZM0c=; b=tB//I+t2dyBh/RNDd4XhEHY3LMRhw16j+X jDfcI2DnayI52Vyi6SIgOGCmqyaCmSN32u1FD8NOQCPG0MkcM5jCqKIMXcOyfb9Z X2+vyo5Zypme57/uTSgLPj8uefGMFdp03GuMi26EyFDhr8STlS4X5uOu8BOq3+8t E0WvdEHnpvGJrsP56ujoND/oTNDBdIY/QoGwhqkQSSjrZDShibQLeJ5dkhURdykj RKmDXpFdQ30gRLTCu1we+bzezloZm2rW8g3GXRPA/E5zJOLfKQnTSmkLhbPXYhYl dIb41cxjnlthhzoUFPjTB+Iey0DZDTB802MTIXJCkwqe5Mg3JEcg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id hTwrTAx9MRHO for ; Thu, 27 Oct 2022 00:50:31 -0700 (PDT) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4MydBt4MrTz1RvTp; Thu, 27 Oct 2022 00:50:30 -0700 (PDT) From: Damien Le Moal To: linux-ide@vger.kernel.org, "Maciej S . Szmigiero" Cc: Hannes Reinecke Subject: [PATCH v3 3/6] ata: libata: cleanup fua handling Date: Thu, 27 Oct 2022 16:50:23 +0900 Message-Id: <20221027075026.240017-4-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027075026.240017-1-damien.lemoal@opensource.wdc.com> References: <20221027075026.240017-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org Move the detection of a device FUA support from ata_scsiop_mode_sense()/ata_dev_supports_fua() to device scan time in ata_dev_configure(). The function ata_dev_config_fua() is introduced to detect a device FUA support and this support is indicated using the new device flag ATA_DFLAG_FUA. In order to blacklist known buggy devices, the horkage flag ATA_HORKAGE_NO_FUA is introduced. Similarly to other horkage flags, the libata.force=3D arguments "fua" and "nofua" are also introduced to allow a user to control this horkage flag through the "force" libata module parameter. The ATA_DFLAG_FUA device flag is set only and only if all the following conditions are met: * libata.fua module parameter is set to 1 * The device advertizes support for the WRITE DMA FUA EXT command, * The device is not marked with the ATA_HORKAGE_NO_FUA flag, either from the blacklist or set by the user with libata.force=3Dnofua * The device supports NCQ (while this is not mandated by the standards, this restriction is introduced to avoid problems with older non-NCQ devices). Note: Enabling or diabling libata fua support for all devices by default can now by done using either the "fua" module parameter or the "force=3D[port[.device]][no]fua" module parameter when libata.fua=3D=3D1. Signed-off-by: Damien Le Moal --- .../admin-guide/kernel-parameters.txt | 3 ++ drivers/ata/libata-core.c | 30 ++++++++++++++++++- drivers/ata/libata-scsi.c | 30 ++----------------- include/linux/libata.h | 8 +++-- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentat= ion/admin-guide/kernel-parameters.txt index a465d5242774..f9724642c703 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2786,6 +2786,9 @@ * [no]setxfer: Indicate if transfer speed mode setting should be skipped. =20 + * [no]fua: Disable or enable FUA (Force Unit Access) + support for devices supporting this feature. + * dump_id: Dump IDENTIFY data. =20 * disable: Disable this device. diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 56ddcbaa0c6f..81b20ffb1554 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2422,6 +2422,28 @@ static void ata_dev_config_chs(struct ata_device *= dev) dev->heads, dev->sectors); } =20 +static void ata_dev_config_fua(struct ata_device *dev) +{ + /* Ignore FUA support if its use is disabled globally */ + if (!libata_fua) + goto nofua; + + /* Ignore devices without support for WRITE DMA FUA EXT */ + if (!(dev->flags & ATA_DFLAG_LBA48) || !ata_id_has_fua(dev->id)) + goto nofua; + + /* Ignore known bad devices and devices that lack NCQ support */ + if (!ata_ncq_supported(dev) || (dev->horkage & ATA_HORKAGE_NO_FUA)) + goto nofua; + + dev->flags |=3D ATA_DFLAG_FUA; + + return; + +nofua: + dev->flags &=3D ~ATA_DFLAG_FUA; +} + static void ata_dev_config_devslp(struct ata_device *dev) { u8 *sata_setting =3D dev->link->ap->sector_buf; @@ -2510,7 +2532,8 @@ static void ata_dev_print_features(struct ata_devic= e *dev) return; =20 ata_dev_info(dev, - "Features:%s%s%s%s%s%s\n", + "Features:%s%s%s%s%s%s%s\n", + dev->flags & ATA_DFLAG_FUA ? " FUA" : "", dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "", dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "", dev->flags & ATA_DFLAG_DEVSLP ? " Dev-Sleep" : "", @@ -2671,6 +2694,7 @@ int ata_dev_configure(struct ata_device *dev) ata_dev_config_chs(dev); } =20 + ata_dev_config_fua(dev); ata_dev_config_devslp(dev); ata_dev_config_sense_reporting(dev); ata_dev_config_zac(dev); @@ -4105,6 +4129,9 @@ static const struct ata_blacklist_entry ata_device_= blacklist [] =3D { */ { "SATADOM-ML 3ME", NULL, ATA_HORKAGE_NO_LOG_DIR }, =20 + /* Buggy FUA */ + { "Maxtor", "BANC1G10", ATA_HORKAGE_NO_FUA }, + /* End Marker */ { } }; @@ -6216,6 +6243,7 @@ static const struct ata_force_param force_tbl[] __i= nitconst =3D { force_horkage_onoff(lpm, ATA_HORKAGE_NOLPM), force_horkage_onoff(setxfer, ATA_HORKAGE_NOSETXFER), force_horkage_on(dump_id, ATA_HORKAGE_DUMP_ID), + force_horkage_onoff(fua, ATA_HORKAGE_NO_FUA), =20 force_horkage_on(disable, ATA_HORKAGE_DISABLE), }; diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 4cb914103382..69948e2a8f6d 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -2240,30 +2240,6 @@ static unsigned int ata_msense_rw_recovery(u8 *buf= , bool changeable) return sizeof(def_rw_recovery_mpage); } =20 -/* - * We can turn this into a real blacklist if it's needed, for now just - * blacklist any Maxtor BANC1G10 revision firmware - */ -static int ata_dev_supports_fua(u16 *id) -{ - unsigned char model[ATA_ID_PROD_LEN + 1], fw[ATA_ID_FW_REV_LEN + 1]; - - if (!libata_fua) - return 0; - if (!ata_id_has_fua(id)) - return 0; - - ata_id_c_string(id, model, ATA_ID_PROD, sizeof(model)); - ata_id_c_string(id, fw, ATA_ID_FW_REV, sizeof(fw)); - - if (strcmp(model, "Maxtor")) - return 1; - if (strcmp(fw, "BANC1G10")) - return 1; - - return 0; /* blacklisted */ -} - /** * ata_scsiop_mode_sense - Simulate MODE SENSE 6, 10 commands * @args: device IDENTIFY data / SCSI command of interest. @@ -2287,7 +2263,7 @@ static unsigned int ata_scsiop_mode_sense(struct at= a_scsi_args *args, u8 *rbuf) }; u8 pg, spg; unsigned int ebd, page_control, six_byte; - u8 dpofua, bp =3D 0xff; + u8 dpofua =3D 0, bp =3D 0xff; u16 fp; =20 six_byte =3D (scsicmd[0] =3D=3D MODE_SENSE); @@ -2350,9 +2326,7 @@ static unsigned int ata_scsiop_mode_sense(struct at= a_scsi_args *args, u8 *rbuf) goto invalid_fld; } =20 - dpofua =3D 0; - if (ata_dev_supports_fua(args->id) && (dev->flags & ATA_DFLAG_LBA48) && - (!(dev->flags & ATA_DFLAG_PIO) || dev->multi_count)) + if (dev->flags & ATA_DFLAG_FUA) dpofua =3D 1 << 4; =20 if (six_byte) { diff --git a/include/linux/libata.h b/include/linux/libata.h index 58651f565b36..d30c1288504d 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -91,6 +91,7 @@ enum { ATA_DFLAG_AN =3D (1 << 7), /* AN configured */ ATA_DFLAG_TRUSTED =3D (1 << 8), /* device supports trusted send/recv */ ATA_DFLAG_DMADIR =3D (1 << 10), /* device requires DMADIR */ + ATA_DFLAG_FUA =3D (1 << 11), /* device supports FUA */ ATA_DFLAG_CFG_MASK =3D (1 << 12) - 1, =20 ATA_DFLAG_PIO =3D (1 << 12), /* device limited to PIO mode */ @@ -113,9 +114,9 @@ enum { ATA_DFLAG_D_SENSE =3D (1 << 29), /* Descriptor sense requested */ ATA_DFLAG_ZAC =3D (1 << 30), /* ZAC device */ =20 - ATA_DFLAG_FEATURES_MASK =3D ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \ - ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \ - ATA_DFLAG_NCQ_PRIO, + ATA_DFLAG_FEATURES_MASK =3D (ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \ + ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \ + ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA), =20 ATA_DEV_UNKNOWN =3D 0, /* unknown device */ ATA_DEV_ATA =3D 1, /* ATA device */ @@ -381,6 +382,7 @@ enum { ATA_HORKAGE_NO_NCQ_ON_ATI =3D (1 << 27), /* Disable NCQ on ATI chipset = */ ATA_HORKAGE_NO_ID_DEV_LOG =3D (1 << 28), /* Identify device log missing= */ ATA_HORKAGE_NO_LOG_DIR =3D (1 << 29), /* Do not read log directory */ + ATA_HORKAGE_NO_FUA =3D (1 << 30), /* Do not use FUA */ =20 /* DMA mask for user DMA control: User visible values; DO NOT renumber */ --=20 2.37.3