From patchwork Tue Jul 19 20:39:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9238327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B6A7860574 for ; Tue, 19 Jul 2016 20:40:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A84C720587 for ; Tue, 19 Jul 2016 20:40:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CBD92756B; Tue, 19 Jul 2016 20:40:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C32420587 for ; Tue, 19 Jul 2016 20:40:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752300AbcGSUjz (ORCPT ); Tue, 19 Jul 2016 16:39:55 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:35788 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752289AbcGSUjv (ORCPT ); Tue, 19 Jul 2016 16:39:51 -0400 Received: by mail-pa0-f67.google.com with SMTP id cf3so1899921pad.2; Tue, 19 Jul 2016 13:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:cc:subject:date:in-reply-to:references; bh=eR9GDj5UYj6EvShrl8ZV2y/8tYM/arm3qMQnX4FoZ5Q=; b=eFQeRb9/o5uOoA50T51CE01I5zIL3rSmoFyRzh9M4gOUix1q3ySzYf+eEnhTs287CQ +XjIzph9qWo3t4eenitM590VInuJrs1rK5PScWIoD11ZUENhWHl6zCEPajU+bG4KoEye CziqkbAqKmjhBYM565YrcmIhujo72vEoHi3FdW0+YnwjERLZZeoeGUEzOjuAQKazUr4C Q0TODWTRl8JjAKN/JEd1zvGAoYoeVFpZ5YvvvGsPzEJWcf1Nrzb45UjGYGkjXs5rOVYp f5kTlrWFUDaZZ8TWdlc/Ozan3W98wK9WLQOSDAA0EOE3EVz7j/A8+R7Bd53YiBCEqu3O AsmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:from:to:cc:subject:date:in-reply-to :references; bh=eR9GDj5UYj6EvShrl8ZV2y/8tYM/arm3qMQnX4FoZ5Q=; b=CC+v6NibkYzJCpTrsHKU+T24v5BS0XvQ9ND4wYRpL1NxAZtOPEo8E1eVfgIInC87Ms ln2fGk7iZW+Esq4toSDdy3vIycJaPA2d+k9VWReiqujb1upAazN0mnNsQYHLT8ARpGE6 osaSxpUQ9sUOSCbcM5vPh7X8SlpInmYFFI29RMZckYvTxHOI7JYP5fw7i0hCZTwgMo9G lEomnadmJB6CV/NzsOKmCXivt+BH8AbMAtMCR8Te9FJ9ctN12nVjjaPXV/ip2sspzYrR 6O7+DOWc8B5dnlS8T0ijGgOYamK9s/fWzC6zqlWuhEebHnWCvDOCl5bkj//Gr97fZpPo x2Lg== X-Gm-Message-State: ALyK8tK97rYzArjt/FNLFnqiiygJ0Y+ep2f+a4RDiGjSwxkRYwxJPihR0x+rNhWkUst/Zw== X-Received: by 10.66.52.11 with SMTP id p11mr68654015pao.155.1468960777775; Tue, 19 Jul 2016 13:39:37 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id 5sm6144000pac.34.2016.07.19.13.39.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jul 2016 13:39:36 -0700 (PDT) Message-ID: <578e9008.4500420a.2d828.d131@mx.google.com> X-Google-Original-Message-ID: <20160719203928.1209-1-me> From: tom.ty89@gmail.com X-Google-Original-From: me To: tj@kernel.org, sergei.shtylyov@cogentembedded.com Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, Tom Yan Subject: [PATCH v4] libata-scsi: better style in ata_msense_*() Date: Wed, 20 Jul 2016 04:39:28 +0800 X-Mailer: git-send-email 2.9.0 In-Reply-To: <5784f28c.c4d0620a.69372.3df2@mx.google.com> References: <5784f28c.c4d0620a.69372.3df2@mx.google.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tom Yan `changeable` is the "version" of mode page requested by the user. It will be less confusing/misleading if we do not check it "together" with the setting bits of the drive. Not to mention that we currently have ata_mselect_*() implemented in a way that each of them will serve exclusively a particular bit on each page. The old style will hence make the condition look even more unnecessarily arcane if the ata_msense_*() is reflecting more than one bit. Signed-off-by: Tom Yan diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index bf4cb21..b00521b 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -2424,10 +2424,12 @@ static void modecpy(u8 *dest, const u8 *src, int n, bool changeable) static unsigned int ata_msense_caching(u16 *id, u8 *buf, bool changeable) { modecpy(buf, def_cache_mpage, sizeof(def_cache_mpage), changeable); - if (changeable || ata_id_wcache_enabled(id)) - buf[2] |= (1 << 2); /* write cache enable */ - if (!changeable && !ata_id_rahead_enabled(id)) - buf[12] |= (1 << 5); /* disable read ahead */ + if (changeable) { + buf[2] |= (1 << 2); /* ata_mselect_caching() */ + } else { + buf[2] |= (ata_id_wcache_enabled(id) << 2); /* write cache enable */ + buf[12] |= (!ata_id_rahead_enabled(id) << 5); /* disable read ahead */ + } return sizeof(def_cache_mpage); } @@ -2446,8 +2448,13 @@ static unsigned int ata_msense_control(struct ata_device *dev, u8 *buf, bool changeable) { modecpy(buf, def_control_mpage, sizeof(def_control_mpage), changeable); - if (changeable || (dev->flags & ATA_DFLAG_D_SENSE)) - buf[2] |= (1 << 2); /* Descriptor sense requested */ + if (changeable) { + buf[2] |= (1 << 2); /* ata_mselect_control() */ + } else { + bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); + + buf[2] |= (d_sense << 2); /* descriptor format sense data */ + } return sizeof(def_control_mpage); }