linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Quinn Tran <quinn.tran@qlogic.com>
To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org
Cc: giridhar.malavali@qlogic.com, saurav.kashyap@qlogic.com,
	andrew.vasquez@qlogic.com
Subject: [PATCH 3/4] target/rd: T10-Dif: Add init/format support
Date: Fri, 28 Mar 2014 19:05:26 -0400	[thread overview]
Message-ID: <1396047927-14189-4-git-send-email-quinn.tran@qlogic.com> (raw)
In-Reply-To: <1396047927-14189-1-git-send-email-quinn.tran@qlogic.com>

This patch is borrow code from

commit 0f5e2ec46dd64579c0770f3822764f94db4fa465
Author: Nicholas Bellinger <nab@linux-iscsi.org>
Date:   Sat Jan 18 09:32:56 2014 +0000

    target/file: Add DIF protection init/format support

    This patch adds support for DIF protection init/format support into
    the FILEIO backend.

    It involves using a seperate $FILE.protection for storing PI that is
    opened via fd_init_prot() using the common pi_prot_type attribute.
    The actual formatting of the protection is done via fd_format_prot()
    using the common pi_prot_format attribute, that will populate the
    initial PI data based upon the currently configured pi_prot_type.

    Based on original FILEIO code from Sagi.

    v1 changes:
      - Fix sparse warnings in fd_init_format_buf (Fengguang)

    Cc: Martin K. Petersen <martin.petersen@oracle.com>
    Cc: Christoph Hellwig <hch@lst.de>
    Cc: Hannes Reinecke <hare@suse.de>
    Cc: Sagi Grimberg <sagig@mellanox.com>
    Cc: Or Gerlitz <ogerlitz@mellanox.com>
    Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
 drivers/target/target_core_rd.c | 64 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)

diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
index 66a5aba..01dda0b 100644
--- a/drivers/target/target_core_rd.c
+++ b/drivers/target/target_core_rd.c
@@ -603,7 +603,7 @@ static int rd_init_prot(struct se_device *dev)
 {
 	struct rd_dev *rd_dev = RD_DEV(dev);
 
-        if (!dev->dev_attrib.pi_prot_type)
+	if (!dev->dev_attrib.pi_prot_type)
 		return 0;
 
 	return rd_build_prot_space(rd_dev, dev->prot_length);
@@ -616,6 +616,67 @@ static void rd_free_prot(struct se_device *dev)
 	rd_release_prot_space(rd_dev);
 }
 
+static void rd_init_format_buf(struct se_device *dev, unsigned char *buf,
+			       u32 unit_size, u32 *ref_tag, u16 app_tag,
+			       bool inc_reftag)
+{
+	unsigned char *p = buf;
+	int i;
+
+	for (i = 0; i < unit_size; i += dev->prot_length) {
+		*((u16 *)&p[0]) = 0xffff;
+		*((__be16 *)&p[2]) = cpu_to_be16(app_tag);
+		*((__be32 *)&p[4]) = cpu_to_be32(*ref_tag);
+
+		if (inc_reftag)
+			(*ref_tag)++;
+
+		p += dev->prot_length;
+	}
+}
+
+static int rd_format_prot(struct se_device *dev)
+{
+	struct rd_dev *rd_dev = RD_DEV(dev);
+	u32 ref_tag = 0;
+	int i,j;
+	bool inc_reftag = false;
+	struct rd_dev_sg_table *pt;
+	struct scatterlist *sg;
+	void *paddr;
+
+	if (!dev->dev_attrib.pi_prot_type) {
+		pr_err("Unable to format_prot while pi_prot_type == 0\n");
+		return -ENODEV;
+	}
+
+	switch (dev->dev_attrib.pi_prot_type) {
+	case TARGET_DIF_TYPE3_PROT:
+		ref_tag = 0xffffffff;
+		break;
+	case TARGET_DIF_TYPE2_PROT:
+	case TARGET_DIF_TYPE1_PROT:
+		inc_reftag = true;
+		break;
+	default:
+		break;
+	}
+
+	for (i=0; i < rd_dev->sg_prot_count; i++) {
+		pt= &rd_dev->sg_prot_array[i];
+		for_each_sg(pt->sg_table, sg, pt->rd_sg_count, j) {
+			paddr = kmap(sg_page(sg)) + sg->offset;
+
+			rd_init_format_buf(dev, paddr, sg->length, &ref_tag,
+					0xffff, inc_reftag);
+			kunmap(paddr);
+		}
+	}
+
+	return 0;
+}
+
+
 static struct sbc_ops rd_sbc_ops = {
 	.execute_rw		= rd_execute_rw,
 };
@@ -642,6 +703,7 @@ static struct se_subsystem_api rd_mcp_template = {
 	.get_device_type	= sbc_get_device_type,
 	.get_blocks		= rd_get_blocks,
 	.init_prot		= rd_init_prot,
+	.format_prot            = rd_format_prot,
 	.free_prot		= rd_free_prot,
 };
 
-- 
1.8.4.GIT


  parent reply	other threads:[~2014-03-28 23:42 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-28 23:05 [PATCH RFC 0/4] add T10-Dif registration for tcm_qla2xxx Quinn Tran
2014-03-28 23:05 ` [PATCH 1/4] target/core: T10-Dif: check HW support capabilities Quinn Tran
2014-03-29  0:05   ` sagi grimberg
2014-03-29  0:53     ` Quinn Tran
2014-03-29  1:24       ` sagi grimberg
2014-03-31 17:53         ` Quinn Tran
2014-04-01  1:19           ` Nicholas A. Bellinger
2014-04-01  7:59             ` Sagi Grimberg
2014-04-01 17:09               ` Martin K. Petersen
2014-04-01 17:27                 ` sagi grimberg
2014-04-01 17:45                   ` Nicholas A. Bellinger
2014-04-02  6:51                     ` Sagi Grimberg
2014-04-02 18:20                       ` Nicholas A. Bellinger
2014-04-03  1:18                         ` Quinn Tran
2014-04-02 11:43                     ` sagi grimberg
2014-04-02 18:47                       ` Nicholas A. Bellinger
2014-04-01  1:03         ` Nicholas A. Bellinger
2014-03-28 23:05 ` [PATCH 2/4] tcm_qla2xxx: T10-Dif set harware capability Quinn Tran
2014-03-29  0:12   ` sagi grimberg
2014-03-31 15:38     ` Quinn Tran
2014-04-01  1:11       ` Nicholas A. Bellinger
2014-04-01  8:04         ` Sagi Grimberg
2014-04-01 17:40           ` Nicholas A. Bellinger
2014-04-02 10:26             ` sagi grimberg
2014-03-28 23:05 ` Quinn Tran [this message]
2014-03-29  0:16   ` [PATCH 3/4] target/rd: T10-Dif: Add init/format support sagi grimberg
2014-03-31 16:14     ` Quinn Tran
2014-03-28 23:05 ` [PATCH 4/4] target/rd: T10-Dif: RAM disk is allocating more space than required Quinn Tran
2014-03-29  0:22   ` sagi grimberg
2014-03-31 16:15     ` Quinn Tran
2014-04-01  0:41       ` Nicholas A. Bellinger
2014-03-28 23:48 ` [PATCH RFC 0/4] add T10-Dif registration for tcm_qla2xxx Quinn Tran
2014-03-29  0:23   ` sagi grimberg

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=1396047927-14189-4-git-send-email-quinn.tran@qlogic.com \
    --to=quinn.tran@qlogic.com \
    --cc=andrew.vasquez@qlogic.com \
    --cc=giridhar.malavali@qlogic.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=saurav.kashyap@qlogic.com \
    --cc=target-devel@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).