From patchwork Wed Jul 6 16:55: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: 9216693 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 DEF5E60752 for ; Wed, 6 Jul 2016 16:55:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFB4827F10 for ; Wed, 6 Jul 2016 16:55:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3F9927F54; Wed, 6 Jul 2016 16:55: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 6CDAF27F10 for ; Wed, 6 Jul 2016 16:55:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754702AbcGFQzg (ORCPT ); Wed, 6 Jul 2016 12:55:36 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33766 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753813AbcGFQzg (ORCPT ); Wed, 6 Jul 2016 12:55:36 -0400 Received: by mail-pf0-f196.google.com with SMTP id c74so22317256pfb.0; Wed, 06 Jul 2016 09:55:35 -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=vws4BtvxCikMtwXcPdzjz3SgvSQ2UuS3WQzi8aWJEBQ=; b=KmHg9rt6Tq7kONMddyUKpaMiXfp3OrPoTFufoihuyotzaNlYCvwuCfEUnNzzNUXM0D 8c8Z3Mgc4df/Klq7HBlydtk2GgKa1b3v0lw/29sR+Toa8sovck9XJzWb6c27FCLSHrRp tEGa8+p182Msv8/VL59SYLdFsD7UvkC8s4fC4eWlKXniBVN2km/Kteauv550+aH7LGyj VaxJJDzC6SYLBn31++vwN82CZB9ieq5aAuydDi6K5oLerqdVtKadL2f7WLWShTKxDLHJ hM7GkC1fKB7M8O+L1ujDWhAe+iLVw25TxkRWom9sw3tTzEhx75k5H7knPns8bdlcn8YF CpJg== 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=vws4BtvxCikMtwXcPdzjz3SgvSQ2UuS3WQzi8aWJEBQ=; b=lb0ZUH+Fkmw2JjDABUXnEzapfkzwLysp8A9fNECWGI9ju6di1f53Fz7t8XwWz+p9VU sfgWtL8+NlMp/bebVrBl0nBigEhVbIAnPHonqGo+dP0g+3IozfxuifQJQ42UfkuHskyg UHfSJOTm54kjs5/WYEIZywlx8BE7QMc4Ix4lvsxNt0DwOAPRUeMEl08voWAjahHksSKB 1A4nFbpHzd5X8l5By562LpL4G94nZobM4sq5WAz0QFHfM6IzmCqbBodhL/O2+y8yPcE/ BfXOOTE/h9BmbtN1FfP+WuSZDlUKodoUoReJoRz0LlhIzt0Xo9CtbiPH0xf+0wlfWwT0 t/cg== X-Gm-Message-State: ALyK8tJcxo3N8iaJBkEb0yx2c4L83+1sURwImYetd5z0Q+E8V3Ewi1Vo8NXM3sCnrxO2Jg== X-Received: by 10.98.201.210 with SMTP id l79mr43297843pfk.87.1467824135309; Wed, 06 Jul 2016 09:55:35 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id p129sm5767888pfb.73.2016.07.06.09.55.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jul 2016 09:55:34 -0700 (PDT) Message-ID: <577d3806.875b620a.e1c80.ffffd002@mx.google.com> X-Google-Original-Message-ID: <20160706165523.1437-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 v4 2/2] libata-scsi: avoid repeated calculation of number of TRIM ranges Date: Thu, 7 Jul 2016 00:55:23 +0800 X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160706165523.1437-1-me> References: <20160706165523.1437-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..82739be 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 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);