From patchwork Mon Oct 24 07:26:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 1693715 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ide-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=GmaTsstA; dkim=pass (2048-bit key; unprotected) header.d=opensource.wdc.com header.i=@opensource.wdc.com header.a=rsa-sha256 header.s=dkim header.b=iDVfoaYk; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4MwmpQ50fwz23kR for ; Mon, 24 Oct 2022 18:26:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229515AbiJXH0T (ORCPT ); Mon, 24 Oct 2022 03:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbiJXH0R (ORCPT ); Mon, 24 Oct 2022 03:26:17 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28C1D5FDEB for ; Mon, 24 Oct 2022 00:26:15 -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=1666596374; x=1698132374; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/jQp45RxuOsbMZdjNzay6DtHnPenFZq4MA9GTnKFfZY=; b=GmaTsstA9VMKX7+ZxNl0OeV+9f/lc2aZTV8ZVSp3pT/4lFT8ebo3AKsq a3m9LCnaFjY7ohemzUkEGcXJHhKPvfPnh26b1vemfMiFwstTgA9O2lmjr RZIpmc3HMZfU8GTedsDQXPQhsESypOcrtMLnZbUdgomldWw4csFZPhGeW pvAh+bI1B4WGbGvH6a8ZnPoByURjI1OCqIygMZ2NQdQMnY7Mk7V4hS9LT 7ZOGgebiw/0uLMQjjBJ38W0Y4FL9MT5Kl99iIUKdYLAnxvGN8wekHUPl6 h64EMhAAkcHb712T1NyETSOeYwNoznY7NK3dvLcv6NqzZBPW9fxQDA4Rk A==; X-IronPort-AV: E=Sophos;i="5.95,207,1661788800"; d="scan'208";a="318901544" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 Oct 2022 15:26:13 +0800 IronPort-SDR: AGjyDWhvYdzTvChFJO3tDMFqMRqs404Nz6VF8JuzY+wxmkvqBVK1Q7TnYpz2pRcJj6kHxWp1dw NlrbKatSY1vLbUdQPw9UCA2utT6PjRtyl6Cbmv6f+uPTGxLuukB3FsvQpCO47HWZoNIC/X3xCq BD9WWtqGenkW+OtjPWBsz5FWFUDX5loHDdfxtlUSbL7jTjHz1aJC3TttnISgpx/7ZY02T6fu+y WeYZ3VXcWP+UULXNsqBgx1eqjFXUfUmpvdGvgEBg3bWjZL+0zr0KRzkmO49/npq+FvaPtTNivo gviHM/CyipqdxwzN8nRuSCAP Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 23 Oct 2022 23:39:57 -0700 IronPort-SDR: riSCTKHa6vb+5gWAj+2UcK2VMR04iQPa0MROTGdEkltI6bTQ3nFJAAM35ezZqK1lu7Hq/kjIZL /LYOdtpyNUeUnI8q3ju3smCZ7kwN/LLvKMj4XQA2Sk4iLkbkE/KEeBmVV2wAta4B2o9tExqEWv HVzyPiRr8hinFipVDVpfv4Q1bxnum1hH77/vD6S/RtQZzQRf01yJeGS36qr0X9lNIulG7FhdUD lNyWASptZjHXXD4plVOKrsUPHS/99luIqArb0B8OeYCtJd2EAhwOp9fLJkYpX8wJkv+JvFarJP zgs= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Oct 2022 00:26:13 -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 4MwmpF1bpNz1RwqL for ; Mon, 24 Oct 2022 00:26:13 -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=1666596372; x=1669188373; bh=/jQp45RxuOsbMZdjNz ay6DtHnPenFZq4MA9GTnKFfZY=; b=iDVfoaYkKdcqOTbTxgGMDPA54HBYUU8F0B ieo7DByvMRzYgAX3rnom5U4Hz4OIxHccMwU1Uq0dcUjAO0m7TEJmUDZ++MeY9tKa WlV3rB3HLfDtDN03aBlFXo+PfOfwFUlJrGW7alea4bqr9jGUaXItODoMdGSN8Tgq 46TWrCkwdRTfXiUfzur+0TbIlNHigtJeKQ0VT6NpOupcsOMlm55UYOmN1CHKl2Is P4HSuU1zu5yTq9Iv2gKvVqfgS0GCWy0A4TjWmnVDYe1YbMExVFKs/m4WO5TP7sCu NWeo6r68s1f1OZ8AvRwm6ePxEkUpzaSHUhRPoNJIz/bY7Ij/X+bQ== 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 xAky8MKBlcPe for ; Mon, 24 Oct 2022 00:26:12 -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 4MwmpD018Qz1RvTp; Mon, 24 Oct 2022 00:26:11 -0700 (PDT) From: Damien Le Moal To: linux-ide@vger.kernel.org, "Maciej S . Szmigiero" Cc: Hannes Reinecke Subject: [PATCH v2 1/3] ata: libata: cleanup fua handling Date: Mon, 24 Oct 2022 16:26:07 +0900 Message-Id: <20221024072609.346502-2-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221024072609.346502-1-damien.lemoal@opensource.wdc.com> References: <20221024072609.346502-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 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 is not marked with the ATA_HORKAGE_NO_FUA flag, either from the blacklist or set by the user with libata.force=nofua * The device advertizes support for the WRITE DMA FUA EXT command, * The device supports LBA48 and is not restricted to single block PIO 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=[port[.device]][no]fua" module parameter when libata.fua==1. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- .../admin-guide/kernel-parameters.txt | 3 ++ drivers/ata/libata-core.c | 29 +++++++++++++++++- drivers/ata/libata-scsi.c | 30 ++----------------- include/linux/libata.h | 8 +++-- 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/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. + * [no]fua: Disable or enable FUA (Force Unit Access) + support for devices supporting this feature. + * dump_id: Dump IDENTIFY data. * disable: Disable this device. diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 884ae73b11ea..6008f7ed1c42 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2420,6 +2420,27 @@ static void ata_dev_config_chs(struct ata_device *dev) dev->heads, dev->sectors); } +static void ata_dev_config_fua(struct ata_device *dev) +{ + /* Ignore FUA support if its use is globally disabled */ + if (!libata_fua) + goto nofua; + + /* Ignore devices without support and known bad devices */ + if (!ata_id_has_fua(dev->id) || (dev->horkage & ATA_HORKAGE_NO_FUA)) + goto nofua; + + /* Limit FUA support to LBA48 without PIO restriction */ + if ((dev->flags & ATA_DFLAG_LBA48) && + (!(dev->flags & ATA_DFLAG_PIO) || dev->multi_count)) { + dev->flags |= ATA_DFLAG_FUA; + return; + } + +nofua: + dev->flags &= ~ATA_DFLAG_FUA; +} + static void ata_dev_config_devslp(struct ata_device *dev) { u8 *sata_setting = dev->link->ap->sector_buf; @@ -2508,7 +2529,8 @@ static void ata_dev_print_features(struct ata_device *dev) return; 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" : "", @@ -2669,6 +2691,7 @@ int ata_dev_configure(struct ata_device *dev) ata_dev_config_chs(dev); } + ata_dev_config_fua(dev); ata_dev_config_devslp(dev); ata_dev_config_sense_reporting(dev); ata_dev_config_zac(dev); @@ -4103,6 +4126,9 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = { */ { "SATADOM-ML 3ME", NULL, ATA_HORKAGE_NO_LOG_DIR }, + /* Buggy FUA */ + { "Maxtor", "BANC1G10", ATA_HORKAGE_NO_FUA }, + /* End Marker */ { } }; @@ -6214,6 +6240,7 @@ static const struct ata_force_param force_tbl[] __initconst = { 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), 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); } -/* - * 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 ata_scsi_args *args, u8 *rbuf) }; u8 pg, spg; unsigned int ebd, page_control, six_byte; - u8 dpofua, bp = 0xff; + u8 dpofua = 0, bp = 0xff; u16 fp; six_byte = (scsicmd[0] == MODE_SENSE); @@ -2350,9 +2326,7 @@ static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf) goto invalid_fld; } - dpofua = 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 = 1 << 4; if (six_byte) { diff --git a/include/linux/libata.h b/include/linux/libata.h index af4953b95f76..81d863d751e1 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -91,6 +91,7 @@ enum { ATA_DFLAG_AN = (1 << 7), /* AN configured */ ATA_DFLAG_TRUSTED = (1 << 8), /* device supports trusted send/recv */ ATA_DFLAG_DMADIR = (1 << 10), /* device requires DMADIR */ + ATA_DFLAG_FUA = (1 << 11), /* device supports FUA */ ATA_DFLAG_CFG_MASK = (1 << 12) - 1, ATA_DFLAG_PIO = (1 << 12), /* device limited to PIO mode */ @@ -113,9 +114,9 @@ enum { ATA_DFLAG_D_SENSE = (1 << 29), /* Descriptor sense requested */ ATA_DFLAG_ZAC = (1 << 30), /* ZAC device */ - ATA_DFLAG_FEATURES_MASK = ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \ - ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \ - ATA_DFLAG_NCQ_PRIO, + ATA_DFLAG_FEATURES_MASK = (ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \ + ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \ + ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA), ATA_DEV_UNKNOWN = 0, /* unknown device */ ATA_DEV_ATA = 1, /* ATA device */ @@ -381,6 +382,7 @@ enum { ATA_HORKAGE_NO_NCQ_ON_ATI = (1 << 27), /* Disable NCQ on ATI chipset */ ATA_HORKAGE_NO_ID_DEV_LOG = (1 << 28), /* Identify device log missing */ ATA_HORKAGE_NO_LOG_DIR = (1 << 29), /* Do not read log directory */ + ATA_HORKAGE_NO_FUA = (1 << 30), /* Do not use FUA */ /* DMA mask for user DMA control: User visible values; DO NOT renumber */