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>
Subject: [PATCH 5/5] libata: Add support for TRIM
Date: Thu,  2 Apr 2009 10:37:27 -0400	[thread overview]
Message-ID: <1238683047-13588-5-git-send-email-willy@linux.intel.com> (raw)
In-Reply-To: <1238683047-13588-4-git-send-email-willy@linux.intel.com>

Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
---
 drivers/ata/libata-scsi.c |   46 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index b9747fa..d4c8b8b 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1029,6 +1029,46 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
 	desc[11] = block;
 }
 
+static int ata_discard_fn(struct request_queue *q, struct request *req,
+							struct bio *bio)
+{
+	unsigned size;
+	struct page *page = alloc_page(GFP_KERNEL);
+	if (!page)
+		goto error;
+
+	size = ata_set_lba_range_entries(page_address(page), PAGE_SIZE / 8,
+					bio->bi_sector, bio_sectors(bio));
+	bio->bi_size = 0;
+	if (bio_add_pc_page(q, bio, page, size, 0) < size)
+		goto free_page;
+
+	req->cmd_type = REQ_TYPE_BLOCK_PC;
+	req->cmd_len = 16;
+	req->cmd[0] = ATA_16;
+	req->cmd[1] = (6 << 1) | 1;		/* dma, 48-bit */
+	req->cmd[2] = 0x6;			/* length, direction */
+	req->cmd[3] = 0;			/* feature high */
+	req->cmd[4] = ATA_DSM_TRIM;		/* feature low */
+	req->cmd[5] = (size / 512) >> 8;	/* nsect high */
+	req->cmd[6] = size / 512;		/* nsect low */
+	req->cmd[7] = 0;			/* lba */
+	req->cmd[8] = 0;			/* lba */
+	req->cmd[9] = 0;			/* lba */
+	req->cmd[10] = 0;			/* lba */
+	req->cmd[11] = 0;			/* lba */
+	req->cmd[12] = 0;			/* lba */
+	req->cmd[13] = ATA_LBA;			/* device */
+	req->cmd[14] = ATA_CMD_DSM;		/* command */
+	req->cmd[15] = 0;			/* control */
+
+	return 0;
+ free_page:
+	__free_page(page);
+ error:
+	return -ENOMEM;
+}
+
 static void ata_scsi_sdev_config(struct scsi_device *sdev)
 {
 	sdev->use_10_for_rw = 1;
@@ -1077,6 +1117,9 @@ static int ata_scsi_dev_config(struct scsi_device *sdev,
 	/* configure max sectors */
 	blk_queue_max_sectors(sdev->request_queue, dev->max_sectors);
 
+	if (ata_id_has_trim(dev->id))
+		blk_queue_set_discard(sdev->request_queue, ata_discard_fn);
+
 	if (dev->class == ATA_DEV_ATAPI) {
 		struct request_queue *q = sdev->request_queue;
 		void *buf;
@@ -2385,6 +2428,9 @@ static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf)
 		/* sector size */
 		rbuf[10] = ATA_SECT_SIZE >> 8;
 		rbuf[11] = ATA_SECT_SIZE & 0xff;
+
+		if (ata_id_has_trim(args->id))
+			rbuf[14] = 0x80;
 	}
 
 	return 0;
-- 
1.6.2.1


  reply	other threads:[~2009-04-02 14:48 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   ` [PATCH 3/5] ata: Add TRIM infrastructure Matthew Wilcox
2009-04-02 14:37     ` [PATCH 4/5] ide: Add support for TRIM Matthew Wilcox
2009-04-02 14:37       ` Matthew Wilcox [this message]
2009-04-02 17:20         ` [PATCH 5/5] libata: " 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-5-git-send-email-willy@linux.intel.com \
    --to=willy@linux.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).