Skip to contentSkip to conversation

tcm: Add fabric and subsystem transport engine core

RFC Superseded Nicholas A. Bellinger 2 participants 3 messages Sep 22, 2010 – Oct 6, 2010

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC v2 6/21 tcm: Add fabric and subsystem transport engine core

From: Nicholas Bellinger <[email protected]>

The patch adds core generic target engine functionality including processing of struct se_cmd generation of N struct se_task, control CDB emulation, sense data, memory allocation, and and mapping from fabric module allocated memory using linked list struct scatterlist style memory based on the limitiations of the underlying TCM HBA and Device backstores.

The TCM layer sits is above Linux/SCSI, Linux/BLOCK and Linux/VFS subsystems, and communicates with these subsystems (and local RAMDISK plugins) using an API of function pointers in se_subsystem_api_t. It provides processing capabilties and emulation for SCSI logic and CDBs in a generic manner to storage object LUNs provided from Linux storage subsystems backend storage devices.

---
 drivers/target/target_core_scdb.c      |  158 +
 drivers/target/target_core_scdb.h      |   15 +
 drivers/target/target_core_transport.c | 8860 ++++++++++++++++++++++++++++++++
 include/target/target_core_transport.h |  570 ++
 4 files changed, 9603 insertions(+), 0 deletions(-)
 create mode 100644 drivers/target/target_core_scdb.c
 create mode 100644 drivers/target/target_core_scdb.h
 create mode 100644 drivers/target/target_core_transport.c
 create mode 100644 include/target/target_core_transport.h
drivers/target/target_core_scdb.c new file +158 -0
new file mode 100644
index 0000000..591ccfe
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Filename:  target_core_scdb.c
+ *
+ * This file contains the generic target engine Split CDB related functions.
+ *
+ * Copyright (c) 2004-2005 PyX Technologies, Inc.
+ * Copyright (c) 2005, 2006, 2007 SBE, Inc.
+ * Copyright (c) 2007-2010 Rising Tide Systems
+ * Copyright (c) 2008-2010 Linux-iSCSI.org
+ *
+ * Nicholas A. Bellinger <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ ******************************************************************************/
+
+#include <linux/net.h>
+#include <linux/string.h>
+#include <scsi/scsi.h>
+#include <asm/unaligned.h>
+
+#include <target/target_core_base.h>
+#include <target/target_core_transport.h>
+
+#include "target_core_scdb.h"
+
+/*	split_cdb_XX_6():
+ *
+ *      21-bit LBA w/ 8-bit SECTORS
+ */
+void split_cdb_XX_6(
+	unsigned long long lba,
+	u32 *sectors,
+	unsigned char *cdb)
+{
+	cdb[1] = (lba >> 16) & 0x1f;
+	cdb[2] = (lba >> 8) & 0xff;
+	cdb[3] = lba & 0xff;
+	cdb[4] = *sectors & 0xff;
+}
+
+void split_cdb_RW_6(
+	unsigned long long lba,
+	u32 *sectors,
+	unsigned char *cdb,
+	int rw)
+{
+	cdb[0] = (rw) ? WRITE_6 : READ_6;
+	split_cdb_XX_6(lba, sectors, &cdb[0]);
+}
+
+/*	split_cdb_XX_10():
+ *
+ *	32-bit LBA w/ 16-bit SECTORS
+ */
+void split_cdb_XX_10(
+	unsigned long long lba,
+	u32 *sectors,
+	unsigned char *cdb)
+{
+	put_unaligned_be32(lba, &cdb[2]);
+	put_unaligned_be16(*sectors, &cdb[7]);
+}
+
+void split_cdb_RW_10(
+	unsigned long long lba,
+	u32 *sectors,
+	unsigned char *cdb,
+	int rw)
+{
+	cdb[0] = (rw) ? WRITE_10 : READ_10;
+	split_cdb_XX_10(lba, sectors, &cdb[0]);
+}
+
+/*	split_cdb_XX_12():
+ *
+ *	32-bit LBA w/ 32-bit SECTORS
+ */
+void split_cdb_XX_12(
+	unsigned long long lba,
+	u32 *sectors,
+	unsigned char *cdb)
+{
+	put_unaligned_be32(lba, &cdb[2]);
+	put_unaligned_be32(*sectors, &cdb[6]);
+}
+
+void split_cdb_RW_12(
+	unsigned long long lba,
+	u32 *sectors,
+	unsigned char *cdb,
+	int rw)
+{
+	cdb[0] = (rw) ? WRITE_12 : READ_12;
+	split_cdb_XX_12(lba, sectors, &cdb[0]);
+}
+
+/*	split_cdb_XX_16():
+ *
+ *	64-bit LBA w/ 32-bit SECTORS
+ */
+void split_cdb_XX_16(
+	unsigned long long lba,
+	u32 *sectors,
+	unsigned char *cdb)
+{
+	put_unaligned_be64(lba, &cdb[2]);
+	put_unaligned_be32(*sectors, &cdb[10]);
+}
+
+void split_cdb_RW_16(
+	unsigned long long lba,
+	u32 *sectors,
+	unsigned char *cdb,
+	int rw)
+{
+	cdb[0] = (rw) ? WRITE_16 : READ_16;
+	split_cdb_XX_16(lba, sectors, &cdb[0]);
+}
+
+/*
+ *	split_cdb_XX_32():
+ *	
+ * 	64-bit LBA w/ 32-bit SECTORS such as READ_32, WRITE_32 and emulated XDWRITEREAD_32
+ */
+void split_cdb_XX_32(
+	unsigned long long lba,
+	u32 *sectors,
+	unsigned char *cdb)
+{
+	put_unaligned_be64(lba, &cdb[12]);
+	put_unaligned_be32(*sectors, &cdb[28]);
+}
+
+void split_cdb_RW_32(
+	unsigned long long lba,
+	u32 *sectors,
+	unsigned char *cdb,
+	int rw)
+{
+	/*
+	 * Set service action for VARIABLE_LENGTH_CMD
+	 */
+	cdb[9] = (rw) ? WRITE_32 : READ_32;
+	split_cdb_XX_32(lba, sectors, &cdb[0]);	
+}
drivers/target/target_core_scdb.h new file +15 -0
new file mode 100644
index 0000000..1b0dc74
@@ -0,0 +1,15 @@
+#ifndef TARGET_CORE_SCDB_H
+#define TARGET_CORE_SCDB_H
+
+extern void split_cdb_XX_6(unsigned long long, u32 *, unsigned char *);
+extern void split_cdb_RW_6(unsigned long long, u32 *, unsigned char *, int);
+extern void split_cdb_XX_10(unsigned long long, u32 *, unsigned char *);
+extern void split_cdb_RW_10(unsigned long long, u32 *, unsigned char *, int);
+extern void split_cdb_XX_12(unsigned long long, u32 *, unsigned char *);
+extern void split_cdb_RW_12(unsigned long long, u32 *, unsigned char *, int);
+extern void split_cdb_XX_16(unsigned long long, u32 *, unsigned char *);
+extern void split_cdb_RW_16(unsigned long long, u32 *, unsigned char *, int);
+extern void split_cdb_XX_32(unsigned long long, u32 *, unsigned char *);
+extern void split_cdb_RW_32(unsigned long long, u32 *, unsigned char *, int);
+
+#endif /* TARGET_CORE_SCDB_H */
drivers/target/target_core_transport.c new file +8860 -0

2,827 lines not on this page · raw message

include/target/target_core_transport.h new file +570 -0

570 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.3

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 14 lines · On Wed, 22 Sep 2010 15:49:23 -0700 "Nicholas A. Bellinger"…

From: Nicholas Bellinger <[email protected]>

The patch adds core generic target engine functionality including processing of struct se_cmd generation of N struct se_task, control CDB emulation, sense data, memory allocation, and and mapping from fabric module allocated memory using linked list struct scatterlist style memory based on the limitiations of the underlying TCM HBA and Device backstores.

The TCM layer sits is above Linux/SCSI, Linux/BLOCK and Linux/VFS subsystems, and communicates with these subsystems (and local RAMDISK plugins) using an API of function pointers in se_subsystem_api_t. It provides processing capabilties and emulation for SCSI logic and CDBs in a generic manner to storage object LUNs provided from Linux storage subsystems backend storage devices.

Quoted 10 lines
---
 drivers/target/target_core_scdb.c      |  158 +
 drivers/target/target_core_scdb.h      |   15 +
 drivers/target/target_core_transport.c | 8860 ++++++++++++++++++++++++++++++++
 include/target/target_core_transport.h |  570 ++
 4 files changed, 9603 insertions(+), 0 deletions(-)
 create mode 100644 drivers/target/target_core_scdb.c
 create mode 100644 drivers/target/target_core_scdb.h
 create mode 100644 drivers/target/target_core_transport.c
 create mode 100644 include/target/target_core_transport.h

Can a driver cleanly overwrite cmd->transport_emulate_cdb? ibmvscsi target driver needs to the specific responses for INQUIRY and REPORT_LUNS.

I guess that the driver can ignore the response buffer from tcm and create the own but it would be nice if the driver can do cleanly.

#2 lore raw
Quoted 28 lines · FUJITA Tomonori
Quoted 14 lines · On Wed, 22 Sep 2010 15:49:23 -0700 "Nicholas A. Bellinger"…

From: Nicholas Bellinger <[email protected]>

The patch adds core generic target engine functionality including processing of struct se_cmd generation of N struct se_task, control CDB emulation, sense data, memory allocation, and and mapping from fabric module allocated memory using linked list struct scatterlist style memory based on the limitiations of the underlying TCM HBA and Device backstores.

The TCM layer sits is above Linux/SCSI, Linux/BLOCK and Linux/VFS subsystems, and communicates with these subsystems (and local RAMDISK plugins) using an API of function pointers in se_subsystem_api_t. It provides processing capabilties and emulation for SCSI logic and CDBs in a generic manner to storage object LUNs provided from Linux storage subsystems backend storage devices.

Quoted 10 lines
---
 drivers/target/target_core_scdb.c      |  158 +
 drivers/target/target_core_scdb.h      |   15 +
 drivers/target/target_core_transport.c | 8860 ++++++++++++++++++++++++++++++++
 include/target/target_core_transport.h |  570 ++
 4 files changed, 9603 insertions(+), 0 deletions(-)
 create mode 100644 drivers/target/target_core_scdb.c
 create mode 100644 drivers/target/target_core_scdb.h
 create mode 100644 drivers/target/target_core_transport.c
 create mode 100644 include/target/target_core_transport.h
Quoted 4 lines

Can a driver cleanly overwrite cmd->transport_emulate_cdb? ibmvscsi target driver needs to the specific responses for INQUIRY and REPORT_LUNS.

Hmmmmmm.. Currently the optional cmd->transport_emulate_cdb() assignment is done from TCM internal code for things like PR and ALUA CDB emulation, but I cannot see a reason why something similar could not be exported out into TCM fabric module code with a bit of work.

Quoted 3 lines

I guess that the driver can ignore the response buffer from tcm and create the own but it would be nice if the driver can do cleanly. --

<nod>, makes perfect sense to me..

Also just FYI, hch has been prodding me to unify the current per subsystem backstore logic for [iblock,fd,rd,stgt]_emulate_scsi_cdb() and make any specific CDB emulation that requires non generic code use a CDB specific struct se_subsystem_api function pointer. I will be looking at doing this in the next days, and I will see what what can be done for an patch w/ example case for TCM_Loop to allow CDB context emulation to be done via the TCM fabric module struct target_core_fabric_ops API.

Thanks Tomo-san!

--nab