From patchwork Tue Jul 12 20:31:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9226211 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 AEA2E60868 for ; Tue, 12 Jul 2016 20:32:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F3E424B48 for ; Tue, 12 Jul 2016 20:32:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91FD327D85; Tue, 12 Jul 2016 20:32:38 +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 2BD7D24B48 for ; Tue, 12 Jul 2016 20:32:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750852AbcGLUch (ORCPT ); Tue, 12 Jul 2016 16:32:37 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:35806 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750776AbcGLUcg (ORCPT ); Tue, 12 Jul 2016 16:32:36 -0400 Received: by mail-pa0-f68.google.com with SMTP id dx3so1669089pab.2; Tue, 12 Jul 2016 13:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KlNCS0jj277SUbfh4oDIGhHvscjRI7NXzC48EILf/n0=; b=W1gnyfI5Jw2pA9ZSiRTf52cWCOMTrZ2s8o6eUIA1UW1ZF+XFP6+/HvBHizlt63c8F0 0qgkXP3eVA/YaASBRPtFmv6i16EzyOJDUnO0s2vtL7L3s/gjUZhWdC+3N3ptAHpo3lDF eoCVAjTIhmo/PJJBYKJ/S/ldQkPKODu8also6rn4jTwzQcaF7bjMWtxLf/zV9TQ9R56u ncz/2eJtvXdhTR4FxE905LGTOHYMshr3RwAXyQHk2qg0Z3Wl9mujEiVLHpYwuRkIhClh ZqgVbNYNF605TNG9495r6u3gga0HTs+3474qthrPhdOLr4dZkr6794lnltK9/b2Mn2fO GPqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KlNCS0jj277SUbfh4oDIGhHvscjRI7NXzC48EILf/n0=; b=CAD6LVoIrXutsUR822z6590evEU+jjzfX8sjFK7bSJkJl3WLqejfWPNipq53l+ttap wJAA4VyTPvcLdEWgY9PlOVvFz/ofYc0bdMNAzNTnvnEIUeyuUe6JXEdCwCCHaBu0ULa3 LqtmPgcf0hv/XxqszI6UFgAx988TjPbcfyDiHoXWvbUO4fQJ6xAyPWEo4jX3kZ24VB0c JB5cvjXR7u/pOmlg/YotbbUlWF8qfhokwa5lA4BS+tSWtPpzww/HCNCfFM/ERJxoCorM P8fuEvsTEZris1P2IAKAIyl0Wrm0zntEXtIkz54LciWk8+0CQ0bYzmli8jYPbHK/iA/6 ZLlA== X-Gm-Message-State: ALyK8tJuYsT7/1mFwPGWBqYcjv9kIg1vmcg+CPUKyBrJbkU8hiwUHHAeMlPkLfzSKRTkfQ== X-Received: by 10.66.145.1 with SMTP id sq1mr7230231pab.107.1468355549586; Tue, 12 Jul 2016 13:32:29 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id e187sm7187559pfg.43.2016.07.12.13.32.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2016 13:32:29 -0700 (PDT) From: tom.ty89@gmail.com X-Google-Original-From: me To: tj@kernel.org, martin.petersen@oracle.com, sergei.shtylyov@cogentembedded.com Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, Tom Yan Subject: [PATCH v6 2/2] libata-scsi: avoid repeated calculation of number of TRIM ranges Date: Wed, 13 Jul 2016 04:31:23 +0800 Message-Id: <7f727a9fd877b2c16cd8799e1da8be71f5b8eaf3.1468354842.git.tom.ty89@gmail.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <844c07e66ad6d410029d80e6b32e8f1480fa9f47.1468354842.git.tom.ty89@gmail.com> References: <844c07e66ad6d410029d80e6b32e8f1480fa9f47.1468354842.git.tom.ty89@gmail.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 Currently libata statically allows only 1-block (512-byte) payload for each TRIM command. Each payload can carry 64 TRIM ranges since each range requires 8 bytes. It is silly to keep doing the calculation (512 / 8) in different places. Hence, define the new ATA_MAX_TRIM_RNUM for the result. Signed-off-by: Tom Yan diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 392aebb..62fb5b9 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -2314,7 +2314,7 @@ static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf) * with the unmap bit set. */ if (ata_id_has_trim(args->id)) { - put_unaligned_be64(65535 * 512 / 8, &rbuf[36]); + put_unaligned_be64(65535 * ATA_MAX_TRIM_RNUM, &rbuf[36]); put_unaligned_be32(1, &rbuf[28]); } @@ -3306,8 +3306,8 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) buf = page_address(sg_page(scsi_sglist(scmd))); - if (n_block <= 65535 * 512 / 8) { - size = ata_set_lba_range_entries(buf, 512, block, n_block); + if (n_block <= 65535 * ATA_MAX_TRIM_RNUM) { + size = ata_set_lba_range_entries(buf, ATA_MAX_TRIM_RNUM, block, n_block); } else { fp = 2; goto invalid_fld; diff --git a/include/linux/ata.h b/include/linux/ata.h index 99346be..2d2d072 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -48,6 +48,7 @@ enum { ATA_MAX_SECTORS_1024 = 1024, ATA_MAX_SECTORS_LBA48 = 65535,/* TODO: 65536? */ ATA_MAX_SECTORS_TAPE = 65535, + ATA_MAX_TRIM_RNUM = 64, /* 512-byte payload / (6-byte LBA + 2-byte range per entry) */ ATA_ID_WORDS = 256, ATA_ID_CONFIG = 0, @@ -1066,12 +1067,12 @@ static inline void ata_id_to_hd_driveid(u16 *id) * TO NV CACHE PINNED SET. */ static inline unsigned ata_set_lba_range_entries(void *_buffer, - unsigned buf_size, u64 sector, unsigned long count) + unsigned num, u64 sector, unsigned long count) { __le64 *buffer = _buffer; unsigned i = 0, used_bytes; - while (i < buf_size / 8 ) { /* 6-byte LBA + 2-byte range per entry */ + while (i < num) { u64 entry = sector | ((u64)(count > 0xffff ? 0xffff : count) << 48); buffer[i++] = __cpu_to_le64(entry);