diff -Nurp linux-4.5/Documentation/scsi/tcm_qla2xxx.txt linux-4.5.new/Documentation/scsi/tcm_qla2xxx.txt
--- linux-4.5/Documentation/scsi/tcm_qla2xxx.txt	1969-12-31 19:00:00.000000000 -0500
+++ linux-4.5.new/Documentation/scsi/tcm_qla2xxx.txt	2016-04-02 11:36:42.693081232 -0400
@@ -0,0 +1,34 @@
+tcm_qla2xxx jammer parameter usage
+----------------------------------
+There is now a new module parameter added to the tcm_qla2xx module
+parm:           jam_host:Host to jam >=0 Enable jammer (int)
+This parameter and accompanying code is only included if the
+Kconfig parameter TCM_QLA2XXX_DEBUG is set to Y
+By default this jammer code and functionality is disabled
+
+Use this parameter to control the discarding of SCSI commands to a selected
+host.
+This may be useful for testing error handling and simulating slow drain
+and other fabric issues.
+
+Any value >=0 that matches a fc_host # will discard the commands for that host.
+Reset back to -1 to stop the jamming.
+
+Enable host 6 to be jammed
+echo 6 > /sys/module/tcm_qla2xxx/parameters/jam_host
+
+Disable jamming on host 6
+echo -1 > /sys/module/tcm_qla2xxx/parameters/jam_host
+
+Usage example script:
+
+#!/bin/bash
+sleep_time=120  ### Time to jam for
+echo 6 >  /sys/module/tcm_qla2xxx/parameters/jam_host
+host=`cat /sys/module/tcm_qla2xxx/parameters/jam_host`
+echo "We start to discard commands on SCSI host $host"
+logger "Jammer started"
+sleep $sleep_time
+echo -1 >  /sys/module/tcm_qla2xxx/parameters/jam_host
+echo "We stopped the jammer"
+logger "Jammer stopped"
diff -Nurp linux-4.5/drivers/scsi/qla2xxx/Kconfig linux-4.5.new/drivers/scsi/qla2xxx/Kconfig
--- linux-4.5/drivers/scsi/qla2xxx/Kconfig	2016-03-14 00:28:54.000000000 -0400
+++ linux-4.5.new/drivers/scsi/qla2xxx/Kconfig	2016-04-02 11:31:15.302516676 -0400
@@ -36,3 +36,13 @@ config TCM_QLA2XXX
 	default n
 	---help---
 	Say Y here to enable the TCM_QLA2XXX fabric module for QLogic 24xx+ series target mode HBAs
+
+config TCM_QLA2XXX_DEBUG
+	bool "TCM_QLA2XXX fabric module DEBUG mode for QLogic 24xx+ series target mode HBAs"
+	depends on SCSI_QLA_FC && TARGET_CORE
+	depends on LIBFC
+	select BTREE
+	default n
+	---help---
+	Say Y here to enable the TCM_QLA2XXX fabric module DEBUG for QLogic 24xx+ series target mode HBAs
+	This will include code to enable the SCSI command jammer
diff -Nurp linux-4.5/drivers/scsi/qla2xxx/tcm_qla2xxx.c linux-4.5.new/drivers/scsi/qla2xxx/tcm_qla2xxx.c
--- linux-4.5/drivers/scsi/qla2xxx/tcm_qla2xxx.c	2016-03-14 00:28:54.000000000 -0400
+++ linux-4.5.new/drivers/scsi/qla2xxx/tcm_qla2xxx.c	2016-04-02 11:32:35.317410249 -0400
@@ -48,6 +48,12 @@
 #include "qla_target.h"
 #include "tcm_qla2xxx.h"
 
+#ifdef CONFIG_TCM_QLA2XXX_DEBUG
+int jam_host = -1;
+module_param(jam_host, int, 0644);
+MODULE_PARM_DESC(jam_host, "Host to jam >=0 Enable jammer");
+#endif
+
 static struct workqueue_struct *tcm_qla2xxx_free_wq;
 static struct workqueue_struct *tcm_qla2xxx_cmd_wq;
 
@@ -477,6 +483,13 @@ static int tcm_qla2xxx_handle_cmd(scsi_q
 		return -EINVAL;
 	}
 
+#ifdef CONFIG_TCM_QLA2XXX_DEBUG
+	if (unlikely(vha->host_no == jam_host)) {
+		/* return, and dont run target_submit_cmd,discarding command */
+		return 0;
+	}
+#endif
+
 	cmd->vha->tgt_counters.qla_core_sbt_cmd++;
 	return target_submit_cmd(se_cmd, se_sess, cdb, &cmd->sense_buffer[0],
 				cmd->unpacked_lun, data_length, fcp_task_attr,
@@ -1967,6 +1980,9 @@ static void tcm_qla2xxx_deregister_confi
 static int __init tcm_qla2xxx_init(void)
 {
 	int ret;
+#ifdef CONFIG_TCM_QLA2XXX_DEBUG
+	jam_host = -1;
+#endif
 
 	ret = tcm_qla2xxx_register_configfs();
 	if (ret < 0)



----- Original Message -----
From: "Laurence Oberman" <loberman@redhat.com>
To: "Himanshu Madhani" <himanshu.madhani@qlogic.com>
Cc: "Nicholas A. Bellinger" <nab@linux-iscsi.org>, "Bart Van Assche" <bart.vanassche@sandisk.com>, "linux-scsi" <linux-scsi@vger.kernel.org>, "target-devel" <target-devel@vger.kernel.org>, "Quinn Tran" <quinn.tran@qlogic.com>
Sent: Saturday, April 2, 2016 12:04:54 PM
Subject: Re: tcm_qla2xxx Add SCSI command jammer/discard capabilty to the tcm_qla2xxx module - revision4

Hello Himanshu

This patch was reworked to only include the jammer code if the parameter TCM_QLA2XXX_DEBUG=Y is set.
The default is to not provide this functionality at all.
I looked at using attributes but this code is in the fastpath and the overhead or fetching the attribute
each time is not a good idea. 
Control of this needs to be dynamic and the module parameter allows a simple compare in the fastpath.

Patch notes
------------
I use target LIO for all my storage array test targets and customer problem resolution here at Red Hat.
This patch resulted from a requirement to mimic behavior of an expensive hardware jammer for a customer.
I have used this for some time with good success to simulate and reproduce latency and slow drain fabric issues and
for testing and validating error handling behavior  in the Emulex, Qlogic and other F/C drivers.

Works by checking new parameter jam_host if its >= 0 and matches vha->host_no , jamming is enabled when jam_host >=0
If parameter set to -1 (default) no jamming is enabled. 

Tested by: Laurence Oberman <loberman@redhat.com>
Signed-off-by: Laurence Oberman <loberman@redhat.com>

diff -Nurp linux-4.5/Documentation/scsi/tcm_qla2xxx.txt linux-4.5.new/Documentation/scsi/tcm_qla2xxx.txt
--- linux-4.5/Documentation/scsi/tcm_qla2xxx.txt	1969-12-31 19:00:00.000000000 -0500
+++ linux-4.5.new/Documentation/scsi/tcm_qla2xxx.txt	2016-04-02 11:36:42.693081232 -0400
@@ -0,0 +1,34 @@
+tcm_qla2xxx jammer parameter usage
+----------------------------------
+There is now a new module parameter added to the tcm_qla2xx module
+parm:           jam_host:Host to jam >=0 Enable jammer (int)
+This parameter and accompanying code is only included if the 
+Kconfig parameter TCM_QLA2XXX_DEBUG is set to Y
+By default this jammer code and functionality is disabled
+
+Use this parameter to control the discarding of SCSI commands to a selected
+host.
+This may be useful for testing error handling and simulating slow drain
+and other fabric issues.
+
+Any value >=0 that matches a fc_host # will discard the commands for that host.
+Reset back to -1 to stop the jamming.
+
+Enable host 6 to be jammed
+echo 6 > /sys/module/tcm_qla2xxx/parameters/jam_host
+
+Disable jamming on host 6
+echo -1 > /sys/module/tcm_qla2xxx/parameters/jam_host
+
+Usage example script:
+
+#!/bin/bash
+sleep_time=120  ### Time to jam for
+echo 6 >  /sys/module/tcm_qla2xxx/parameters/jam_host
+host=`cat /sys/module/tcm_qla2xxx/parameters/jam_host`
+echo "We start to discard commands on SCSI host $host"
+logger "Jammer started"
+sleep $sleep_time
+echo -1 >  /sys/module/tcm_qla2xxx/parameters/jam_host
+echo "We stopped the jammer"
+logger "Jammer stopped"
diff -Nurp linux-4.5/drivers/scsi/qla2xxx/Kconfig linux-4.5.new/drivers/scsi/qla2xxx/Kconfig
--- linux-4.5/drivers/scsi/qla2xxx/Kconfig	2016-03-14 00:28:54.000000000 -0400
+++ linux-4.5.new/drivers/scsi/qla2xxx/Kconfig	2016-04-02 11:31:15.302516676 -0400
@@ -36,3 +36,13 @@ config TCM_QLA2XXX
 	default n
 	---help---
 	Say Y here to enable the TCM_QLA2XXX fabric module for QLogic 24xx+ series target mode HBAs
+
+config TCM_QLA2XXX_DEBUG
+	bool "TCM_QLA2XXX fabric module DEBUG mode for QLogic 24xx+ series target mode HBAs"
+	depends on SCSI_QLA_FC && TARGET_CORE
+	depends on LIBFC
+	select BTREE
+	default n
+	---help---
+	Say Y here to enable the TCM_QLA2XXX fabric module DEBUG for QLogic 24xx+ series target mode HBAs
+	This will include code to enable the SCSI command jammer
diff -Nurp linux-4.5/drivers/scsi/qla2xxx/tcm_qla2xxx.c linux-4.5.new/drivers/scsi/qla2xxx/tcm_qla2xxx.c
--- linux-4.5/drivers/scsi/qla2xxx/tcm_qla2xxx.c	2016-03-14 00:28:54.000000000 -0400
+++ linux-4.5.new/drivers/scsi/qla2xxx/tcm_qla2xxx.c	2016-04-02 11:32:35.317410249 -0400
@@ -48,6 +48,12 @@
 #include "qla_target.h"
 #include "tcm_qla2xxx.h"
 
+#ifdef TCM_QLA2XXX_DEBUG
+int jam_host = -1;
+module_param(jam_host, int, 0644);
+MODULE_PARM_DESC(jam_host, "Host to jam >=0 Enable jammer");
+#endif
+
 static struct workqueue_struct *tcm_qla2xxx_free_wq;
 static struct workqueue_struct *tcm_qla2xxx_cmd_wq;
 
@@ -477,6 +483,13 @@ static int tcm_qla2xxx_handle_cmd(scsi_q
 		return -EINVAL;
 	}
 
+#ifdef TCM_QLA2XXX_DEBUG
+	if (unlikely(vha->host_no == jam_host)) {
+		/* return, and dont run target_submit_cmd,discarding command */
+		return 0;
+	}
+#endif
+
 	cmd->vha->tgt_counters.qla_core_sbt_cmd++;
 	return target_submit_cmd(se_cmd, se_sess, cdb, &cmd->sense_buffer[0],
 				cmd->unpacked_lun, data_length, fcp_task_attr,
@@ -1967,6 +1980,9 @@ static void tcm_qla2xxx_deregister_confi
 static int __init tcm_qla2xxx_init(void)
 {
 	int ret;
+#ifdef TCM_QLA2XXX_DEBUG
+	jam_host = -1;
+#endif
 
 	ret = tcm_qla2xxx_register_configfs();
 	if (ret < 0)
