From patchwork Wed Jul 6 16:44:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9216689 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 83F0E60752 for ; Wed, 6 Jul 2016 16:44:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7611227E15 for ; Wed, 6 Jul 2016 16:44:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AB2C27E33; Wed, 6 Jul 2016 16:44:55 +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 F19B327E15 for ; Wed, 6 Jul 2016 16:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754649AbcGFQoy (ORCPT ); Wed, 6 Jul 2016 12:44:54 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:35668 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753813AbcGFQox (ORCPT ); Wed, 6 Jul 2016 12:44:53 -0400 Received: by mail-pa0-f67.google.com with SMTP id dx3so4827519pab.2; Wed, 06 Jul 2016 09:44:52 -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=72+OYoVIXpOdng/XHJaNTFKllNXXzrvT43cSF9DIEwk=; b=vozGqhexdXYeY9pwyyI9I7Dkrby3sCE0kTbCfBZYc9Nm+wqIV7HA0S7gxTFYAJBwOm nLfdCAijF8jHTJ9J2x6z7ie+RjVPs+Iz7i0QP/sEGlZc7lthhIKuYFfpVY/OpZCiXoYD IQ4a/hExQ3ozEbjMsXKIMt3ThVRXYWWrLPd/eFrYX1stLXQVZLe8CEz6tJbo3MlQpqHj uDUyWRWFHZhd3POfACAe0ok3gfs5iJGIZCYdWd2Yj6YvhU2UhCpEOzeILWgcKCmoxUKX txvNb/E2rJuOPyPp01JJ/HttdAbNMtODbtlQvj1yW+P4osGswxFsPRr6cx5pTbdRxLzA 4wIQ== 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=72+OYoVIXpOdng/XHJaNTFKllNXXzrvT43cSF9DIEwk=; b=mYJK4iciadUg2kFKA3wmQRn9d7/1EWm9p7ZGSbZt6H0B16GmYCLPoneNu6Aow1FOL/ F5LZK3UxDHRW7+vn+JUkNdt2BdRt3Cs53a/KIbHE/wBOz5QKhcReDVWj158WloqhqSSc 4GKoqklVMA03/GXc2dHwZJTtzyKWcz9b1IJKVKePdXrvULPJ3eDCg7n9KHy56BhpGJB1 TmgrzR/13bYVQac6n8dlSa8DhFD28OKy4D8uD5Xfw3K1d4rs186XYQnLdRCkakorSReP Ib5105nNfXqOYNLfermgbdndgWbV2Bq2RKDRkOgHnR3VbteWDJ2BcARKiSgOG/GiPlhj +gMA== X-Gm-Message-State: ALyK8tJ/oAEI5Xbk8yPeXfTEHMNL6r3a5Rr6Hfc9FbWJVu6ndYvQtldUQvxuG7Kkx/JPcg== X-Received: by 10.66.157.8 with SMTP id wi8mr44022228pab.21.1467823492229; Wed, 06 Jul 2016 09:44:52 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id x67sm4998857pff.47.2016.07.06.09.44.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jul 2016 09:44:51 -0700 (PDT) Message-ID: <577d3583.46c0620a.b8b1b.ffff9a06@mx.google.com> X-Google-Original-Message-ID: <20160706164440.1176-2-me> 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 v3 2/2] libata-scsi: avoid repeated calculation of number of TRIM ranges Date: Thu, 7 Jul 2016 00:44:40 +0800 X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160706164440.1176-1-me> References: <20160706164440.1176-1-me> 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 a1f061a..05a5f44 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -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 goto invalid_fld; diff --git a/include/linux/ata.h b/include/linux/ata.h index 99346be..ce59500 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, @@ -1071,7 +1072,7 @@ static inline unsigned ata_set_lba_range_entries(void *_buffer, __le64 *buffer = _buffer; unsigned i = 0, used_bytes; - while (i < buf_size / 8 ) { /* 6-byte LBA + 2-byte range per entry */ + while (i < buf_size) { u64 entry = sector | ((u64)(count > 0xffff ? 0xffff : count) << 48); buffer[i++] = __cpu_to_le64(entry);