From patchwork Fri Aug 23 09:40:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Carino X-Patchwork-Id: 269406 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 117512C008C for ; Fri, 23 Aug 2013 19:42:24 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754618Ab3HWJmX (ORCPT ); Fri, 23 Aug 2013 05:42:23 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:45409 "EHLO mail-ob0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754470Ab3HWJmT (ORCPT ); Fri, 23 Aug 2013 05:42:19 -0400 Received: by mail-ob0-f173.google.com with SMTP id ta17so454913obb.32 for ; Fri, 23 Aug 2013 02:42:19 -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=mZjCIFhJtmI1BmZVNty+xX+zgv8MLMGzs2Te98pxk8U=; b=IUPofxFi0bOq3cUX/NSc+zhGIq/kiOFjYGsi+rSfYHLmqH9y57EthhjHFLTxt2bE79 Ej1uxnWg5sCduWaQULy2I1t7ymhF9b28Yc9Baopu+/ZBYDhwrXpQV9WpklxuiHAefvgJ uwuATv+2/pxFkwLndcleGnEea1XV19MTAzpZEdsRlCUBX7PNAPWpVLft/GBJNvyXawjf hMgimIG4sLlNa1fM6hdHkHx7+I3ptN82zMC9y0MYSZkBwzGDopy0sZDm2LTKTBDsC/Dd z0oCHelBndzgZA+j6lXeykcwJWwaLTcQh5jW1SCWsY+r+Vea//Kyt5k7guZxQKAAP0cp 9gjw== X-Received: by 10.182.148.8 with SMTP id to8mr19449812obb.17.1377250939471; Fri, 23 Aug 2013 02:42:19 -0700 (PDT) Received: from localhost.localdomain (ip68-231-212-75.oc.oc.cox.net. [68.231.212.75]) by mx.google.com with ESMTPSA id uz16sm24571601obc.5.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Aug 2013 02:42:18 -0700 (PDT) From: Marc C To: tj@kernel.org, linux-ide@vger.kernel.org Cc: Marc Carino Subject: [PATCH v4 3/3] libata: Add support for queued DSM TRIM Date: Fri, 23 Aug 2013 02:40:47 -0700 Message-Id: <1377250847-24132-4-git-send-email-marc.ceeeee@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1377250847-24132-1-git-send-email-marc.ceeeee@gmail.com> References: <1377250847-24132-1-git-send-email-marc.ceeeee@gmail.com> Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org From: Marc Carino Some new SSDs support the queued version of the DSM TRIM command. Let the driver use the new command if supported. Signed-off-by: Marc Carino --- drivers/ata/libata-scsi.c | 25 +++++++++++++++++++------ include/linux/libata.h | 11 +++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 83c0890..0c807a9 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3098,12 +3098,25 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) buf = page_address(sg_page(scsi_sglist(scmd))); size = ata_set_lba_range_entries(buf, 512, block, n_block); - tf->protocol = ATA_PROT_DMA; - tf->hob_feature = 0; - tf->feature = ATA_DSM_TRIM; - tf->hob_nsect = (size / 512) >> 8; - tf->nsect = size / 512; - tf->command = ATA_CMD_DSM; + if (ata_ncq_enabled(dev) && ata_fpdma_dsm_supported(dev)) { + /* Newer devices support queued TRIM commands */ + tf->protocol = ATA_PROT_NCQ; + tf->command = ATA_CMD_FPDMA_SEND; + tf->hob_nsect = ATA_SUBCMD_FPDMA_SEND_DSM & 0x1f; + tf->nsect = qc->tag << 3; + tf->hob_feature = (size / 512) >> 8; + tf->feature = size / 512; + + tf->auxiliary = 1; + } else { + tf->protocol = ATA_PROT_DMA; + tf->hob_feature = 0; + tf->feature = ATA_DSM_TRIM; + tf->hob_nsect = (size / 512) >> 8; + tf->nsect = size / 512; + tf->command = ATA_CMD_DSM; + } + tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 | ATA_TFLAG_WRITE; diff --git a/include/linux/libata.h b/include/linux/libata.h index b925504..69d1b8b 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1608,6 +1608,17 @@ static inline int ata_ncq_enabled(struct ata_device *dev) ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ; } +static inline int ata_fpdma_dsm_supported(struct ata_device *dev) +{ + if ((dev->flags & ATA_DFLAG_NCQ_SEND_RECV) && + (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET] & + ATA_LOG_NCQ_SEND_RECV_DSM_TRIM)) { + return 1; + } else { + return 0; + } +} + static inline void ata_qc_set_polling(struct ata_queued_cmd *qc) { qc->tf.ctl |= ATA_NIEN;