linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@linux.intel.com>
To: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org,
	jgarzik@redhat.com
Cc: Matthew Wilcox <willy@linux.intel.com>,
	David Woodhouse <David.Woodhouse@intel.com>
Subject: [PATCH 3/5] ata: Add TRIM infrastructure
Date: Thu,  2 Apr 2009 10:37:25 -0400	[thread overview]
Message-ID: <1238683047-13588-3-git-send-email-willy@linux.intel.com> (raw)
In-Reply-To: <1238683047-13588-2-git-send-email-willy@linux.intel.com>

This is common code shared between the IDE and libata implementations

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
---
 include/linux/ata.h |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/include/linux/ata.h b/include/linux/ata.h
index 6617c9f..cb79b7a 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -29,6 +29,8 @@
 #ifndef __LINUX_ATA_H__
 #define __LINUX_ATA_H__
 
+#include <linux/kernel.h>
+#include <linux/string.h>
 #include <linux/types.h>
 #include <asm/byteorder.h>
 
@@ -91,6 +93,7 @@ enum {
 	ATA_ID_CFA_POWER	= 160,
 	ATA_ID_CFA_KEY_MGMT	= 162,
 	ATA_ID_CFA_MODES	= 163,
+	ATA_ID_DATA_SET_MGMT	= 169,
 	ATA_ID_ROT_SPEED	= 217,
 	ATA_ID_PIO4		= (1 << 1),
 
@@ -248,6 +251,7 @@ enum {
 	ATA_CMD_SMART		= 0xB0,
 	ATA_CMD_MEDIA_LOCK	= 0xDE,
 	ATA_CMD_MEDIA_UNLOCK	= 0xDF,
+	ATA_CMD_DSM		= 0x06,
 	/* marked obsolete in the ATA/ATAPI-7 spec */
 	ATA_CMD_RESTORE		= 0x10,
 
@@ -321,6 +325,9 @@ enum {
 	ATA_SMART_READ_VALUES	= 0xD0,
 	ATA_SMART_READ_THRESHOLDS = 0xD1,
 
+	/* feature values for Data Set Management */
+	ATA_DSM_TRIM		= 0x01,
+
 	/* password used in LBA Mid / LBA High for executing SMART commands */
 	ATA_SMART_LBAM_PASS	= 0x4F,
 	ATA_SMART_LBAH_PASS	= 0xC2,
@@ -723,6 +730,14 @@ static inline int ata_id_has_unload(const u16 *id)
 	return 0;
 }
 
+static inline int ata_id_has_trim(const u16 *id)
+{
+	if (ata_id_major_version(id) >= 7 &&
+	    (id[ATA_ID_DATA_SET_MGMT] & 1))
+		return 1;
+	return 0;
+}
+
 static inline int ata_id_current_chs_valid(const u16 *id)
 {
 	/* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command
@@ -863,6 +878,32 @@ static inline void ata_id_to_hd_driveid(u16 *id)
 #endif
 }
 
+/*
+ * Write up to 'max' LBA Range Entries to the buffer that will cover the
+ * extent from sector to sector + count.  This is used for TRIM and for
+ * ADD LBA(S) TO NV CACHE PINNED SET.
+ */
+static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max,
+						u64 sector, unsigned long count)
+{
+	__le64 *buffer = _buffer;
+	unsigned i = 0;
+
+	while (i < max) {
+		u64 entry = sector |
+			((u64)(count > 0xffff ? 0xffff : count) << 48);
+		buffer[i++] = __cpu_to_le64(entry);
+		if (count <= 0xffff)
+			break;
+		count -= 0xffff;
+		sector += 0xffff;
+	}
+
+	max = ALIGN(i * 8, 512);
+	memset(buffer + i, 0, max - i * 8);
+	return max;
+}
+
 static inline int is_multi_taskfile(struct ata_taskfile *tf)
 {
 	return (tf->command == ATA_CMD_READ_MULTI) ||
-- 
1.6.2.1


  reply	other threads:[~2009-04-02 14:58 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-02 14:37 [PATCH 1/5] Block: Discard may need to allocate pages Matthew Wilcox
2009-04-02 14:37 ` [PATCH 2/5] Make DISCARD_BARRIER and DISCARD_NOBARRIER writes instead of reads Matthew Wilcox
2009-04-02 14:37   ` Matthew Wilcox [this message]
2009-04-02 14:37     ` [PATCH 4/5] ide: Add support for TRIM Matthew Wilcox
2009-04-02 14:37       ` [PATCH 5/5] libata: " Matthew Wilcox
2009-04-02 17:20         ` Mark Lord
2009-04-02 17:55           ` Matthew Wilcox
2009-04-16 20:25         ` Mark Lord
2009-04-17 19:44           ` Mark Lord
2009-04-02 15:58       ` [PATCH 4/5] ide: " Sergei Shtylyov
2009-04-02 16:28         ` Matthew Wilcox
2009-04-02 16:38           ` Sergei Shtylyov
2009-04-02 16:51             ` Matthew Wilcox
2009-04-02 19:37               ` Bartlomiej Zolnierkiewicz
2009-04-07 21:38                 ` Bartlomiej Zolnierkiewicz
2009-04-07 22:15                   ` Matthew Wilcox
2009-04-07 22:26                     ` Jeff Garzik
2009-04-07 22:35                     ` Bartlomiej Zolnierkiewicz
2009-04-07 17:20       ` Jeff Garzik
2009-04-07 17:57         ` Mark Lord
2009-04-07 18:10           ` Markus Trippelsdorf
2009-04-07 19:58             ` Mark Lord
2009-04-08  7:14               ` Markus Trippelsdorf
2009-04-08 14:25                 ` Mark Lord
2009-04-08 14:33       ` Mark Lord
2009-04-08 14:44         ` Dongjun Shin
2009-04-08 14:59         ` Jeff Garzik
2009-04-08 15:50           ` Mark Lord
2009-04-02 15:55     ` [PATCH 3/5] ata: Add TRIM infrastructure Sergei Shtylyov
2009-04-02 16:18       ` Matthew Wilcox
2009-04-02 16:32         ` Sergei Shtylyov
2009-04-02 16:47           ` Matthew Wilcox
2009-04-07  0:02     ` Jeff Garzik
2009-04-05 12:28 ` [PATCH 1/5] Block: Discard may need to allocate pages Boaz Harrosh
2009-04-06 20:34   ` Matthew Wilcox
2009-05-03  6:11   ` Matthew Wilcox
2009-05-03  7:16     ` New TRIM/UNMAP tree published (2009-05-02) Matthew Wilcox
2009-05-03 13:07       ` Hugh Dickins
2009-05-03 14:48         ` Matthew Wilcox
2009-05-03 15:02           ` Boaz Harrosh
2009-05-03 15:42             ` Matthew Wilcox
2009-05-03 16:34               ` Boaz Harrosh
2009-05-03 18:34                 ` Jeff Garzik
2009-05-03 18:40                   ` Jeff Garzik
2009-05-03 19:04                     ` James Bottomley
2009-05-03 19:20                       ` Jeff Garzik
2009-05-03 19:37                         ` James Bottomley
2009-05-04 14:03                           ` Douglas Gilbert
2009-05-04 14:40                             ` James Bottomley
2009-05-04 15:11                               ` Douglas Gilbert
2009-05-04 15:23                                 ` James Bottomley
2009-05-03 19:47                         ` James Bottomley
2009-05-03 22:47                           ` Jeff Garzik
2009-05-04 15:28                             ` Boaz Harrosh
2009-05-03 21:48                   ` Matthew Wilcox
2009-05-03 22:54                     ` Jeff Garzik
2009-05-03 18:48               ` Bartlomiej Zolnierkiewicz
2009-05-03 15:05           ` Hugh Dickins
2009-04-17 21:23 ` [PATCH 1/5] Block: Discard may need to allocate pages Mark Lord

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1238683047-13588-3-git-send-email-willy@linux.intel.com \
    --to=willy@linux.intel.com \
    --cc=David.Woodhouse@intel.com \
    --cc=jgarzik@redhat.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).