From patchwork Thu Aug 19 15:48:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Martin K. Petersen" X-Patchwork-Id: 62185 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id EBD9CB70EF for ; Fri, 20 Aug 2010 01:51:49 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751832Ab0HSPva (ORCPT ); Thu, 19 Aug 2010 11:51:30 -0400 Received: from rcsinet10.oracle.com ([148.87.113.121]:35530 "EHLO rcsinet10.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751777Ab0HSPv3 (ORCPT ); Thu, 19 Aug 2010 11:51:29 -0400 Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id o7JFpJNQ021700 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 19 Aug 2010 15:51:21 GMT Received: from acsmt354.oracle.com (acsmt354.oracle.com [141.146.40.154]) by acsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id o7J9708D024319; Thu, 19 Aug 2010 15:51:18 GMT Received: from abhmt018.oracle.com by acsmt354.oracle.com with ESMTP id 512366961282232960; Thu, 19 Aug 2010 08:49:20 -0700 Received: from groovelator.mkp.net (/209.217.122.111) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Aug 2010 08:49:17 -0700 From: "Martin K. Petersen" To: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, hch@lst.de Cc: "Martin K. Petersen" Subject: [PATCH 2/6] libata: Report supported TRIM payload size Date: Thu, 19 Aug 2010 11:48:57 -0400 Message-Id: <1282232941-9910-3-git-send-email-martin.petersen@oracle.com> X-Mailer: git-send-email 1.7.2.1 In-Reply-To: <1282232941-9910-1-git-send-email-martin.petersen@oracle.com> References: <1282232941-9910-1-git-send-email-martin.petersen@oracle.com> Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org ATA IDENTIFY DEVICE word 105 contains the number of 512-byte blocks of TRIM payload information the device can accept in one command. Use this value to enable payloads > 512 bytes. Signed-off-by: Martin K. Petersen --- drivers/ata/libata-scsi.c | 7 ++++++- include/linux/ata.h | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index e280ae6..145f099 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -2152,7 +2152,12 @@ 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_be32(65535 * 512 / 8, &rbuf[20]); + unsigned int blocks; + + /* Default to 1 if unspecified in word 105. Cap at 1 page. */ + blocks = clamp(ata_id_trim_range_blocks(args->id), 1U, 8U); + + put_unaligned_be32(65535 * 512 / 8 * blocks, &rbuf[20]); put_unaligned_be32(1, &rbuf[28]); } diff --git a/include/linux/ata.h b/include/linux/ata.h index fe6e681..5584356 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -88,6 +88,7 @@ enum { ATA_ID_HW_CONFIG = 93, ATA_ID_SPG = 98, ATA_ID_LBA_CAPACITY_2 = 100, + ATA_ID_TRIM_RANGE_BLKS = 105, ATA_ID_SECTOR_SIZE = 106, ATA_ID_LAST_LUN = 126, ATA_ID_DLF = 128, @@ -827,6 +828,14 @@ static inline int ata_id_has_zero_after_trim(const u16 *id) return 0; } +static inline unsigned int ata_id_trim_range_blocks(const u16 *id) +{ + if (ata_id_has_trim(id)) + return id[ATA_ID_TRIM_RANGE_BLKS]; + + return 0; +} + static inline int ata_id_current_chs_valid(const u16 *id) { /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command