Skip to contentSkip to conversation

lpfc: add target hooks

RFC PATCH In review Sebastian Herbszt 1 participant 1 message Jun 14, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 2/2 lpfc: add target hooks

Add target hooks.

---

drivers/scsi/Kconfig +6 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/Kconfig 4.1-rc7/drivers/scsi/Kconfig
@@ -1299,6 +1299,12 @@ config SCSI_LPFC_DEBUG_FS
 	  This makes debugging information from the lpfc driver
 	  available via the debugfs filesystem.
 
+config SCSI_LPFC_TARGET
+	bool "Emulex LightPulse Fibre Channel Target Support"
+	depends on SCSI_LPFC
+	help
+	  Support target mode.
+
 config SCSI_SIM710
 	tristate "Simple 53c710 SCSI support (Compaq, NCR machines)"
 	depends on (EISA || MCA) && SCSI
drivers/scsi/lpfc/Makefile +5 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/Makefile 4.1-rc7/drivers/scsi/lpfc/Makefile
@@ -31,3 +31,8 @@ obj-$(CONFIG_SCSI_LPFC) := lpfc.o
 lpfc-objs := lpfc_mem.o lpfc_sli.o lpfc_ct.o lpfc_els.o lpfc_hbadisc.o	\
 	lpfc_init.o lpfc_mbox.o lpfc_nportdisc.o lpfc_scsi.o lpfc_attr.o \
 	lpfc_vport.o lpfc_debugfs.o lpfc_bsg.o
+
+ifdef CONFIG_SCSI_LPFC_TARGET
+	ccflags-y += -DLPFC_TARGET_MODE
+	lpfc-objs += lpfc_target_api.o
+endif
drivers/scsi/lpfc/lpfc.h +12 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc.h 4.1-rc7/drivers/scsi/lpfc/lpfc.h
@@ -441,6 +441,9 @@ struct lpfc_vport {
 	unsigned long rcv_buffer_time_stamp;
 	uint32_t vport_flag;
 #define STATIC_VPORT	1
+#if defined LPFC_TARGET_MODE && defined _H_LPFC_TGT_API_BASE
+	tm_tgtport_t target_tgtport;
+#endif
 };
 
 struct hbq_s {
@@ -991,6 +994,15 @@ struct lpfc_hba {
 	spinlock_t devicelock;	/* lock for luns list */
 	mempool_t *device_data_mem_pool;
 	struct list_head luns;
+#if defined LPFC_TARGET_MODE && defined _H_LPFC_TGT_API_BASE
+	uint32_t cfg_initialize_link;
+	uint32_t cfg_fcp_mode;
+#define LPFC_FCP_MODE_INITIATOR		1
+#define LPFC_FCP_MODE_TARGET		2
+	uint32_t poll_rsp_cnt;
+	uint32_t num_targets_bound;
+	tm_sliport_t target_sliport;
+#endif
 };
 
 static inline struct Scsi_Host *
drivers/scsi/lpfc/lpfc_attr.c +67 -1

109 lines not on this page · raw message

drivers/scsi/lpfc/lpfc_ct.c +10 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc_ct.c 4.1-rc7/drivers/scsi/lpfc/lpfc_ct.c
@@ -38,6 +38,10 @@
 #include "lpfc_hw.h"
 #include "lpfc_sli.h"
 #include "lpfc_sli4.h"
+#ifdef LPFC_TARGET_MODE
+#include "lpfc_target_api.h"
+#include "lpfc_target_api_base.h"
+#endif
 #include "lpfc_nl.h"
 #include "lpfc_disc.h"
 #include "lpfc_scsi.h"
@@ -1284,7 +1288,13 @@ lpfc_ns_cmd(struct lpfc_vport *vport, in
 		CtReq->CommandResponse.bits.CmdRsp =
 		    cpu_to_be16(SLI_CTNS_RFF_ID);
 		CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
+#ifdef LPFC_TARGET_MODE
+		CtReq->un.rff.fbits = 0;
+		if (phba->cfg_fcp_mode & LPFC_FCP_MODE_INITIATOR)
+			CtReq->un.rff.fbits = FC4_FEATURE_INIT;
+#else
 		CtReq->un.rff.fbits = FC4_FEATURE_INIT;
+#endif
 		CtReq->un.rff.type_code = FC_TYPE_FCP;
 		cmpl = lpfc_cmpl_ct_cmd_rff_id;
 		break;
drivers/scsi/lpfc/lpfc_debugfs.c +4 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc_debugfs.c 4.1-rc7/drivers/scsi/lpfc/lpfc_debugfs.c
@@ -40,6 +40,10 @@
 #include "lpfc_sli.h"
 #include "lpfc_sli4.h"
 #include "lpfc_nl.h"
+#ifdef LPFC_TARGET_MODE
+#include "lpfc_target_api.h"
+#include "lpfc_target_api_base.h"
+#endif
 #include "lpfc_disc.h"
 #include "lpfc_scsi.h"
 #include "lpfc.h"
drivers/scsi/lpfc/lpfc_disc.h +12 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc_disc.h 4.1-rc7/drivers/scsi/lpfc/lpfc_disc.h
@@ -119,6 +119,15 @@ struct lpfc_nodelist {
 	unsigned long last_change_time;
 	unsigned long *active_rrqs_xri_bitmap;
 	struct lpfc_scsicmd_bkt *lat_data;	/* Latency data */
+#if defined LPFC_TARGET_MODE && defined _H_LPFC_TGT_API
+	tm_login_info_t      tm_login_info;
+	tm_login_handle_t    login_handle;
+	uint32_t             tm_check_login_result;
+	uint8_t              tm_check_login_called;
+	uint8_t              login_handle_valid;
+	uint16_t             tm_login_flags;
+#define NLP_TM_DELAYED_LOGIN   0x1
+#endif
 };
 struct lpfc_node_rrq {
 	struct list_head list;
@@ -147,6 +156,9 @@ struct lpfc_node_rrq {
 #define NLP_LOGO_ACC       0x00100000	/* Process LOGO after ACC completes */
 #define NLP_TGT_NO_SCSIID  0x00200000	/* good PRLI but no binding for scsid */
 #define NLP_ISSUE_LOGO     0x00400000	/* waiting to issue a LOGO */
+#ifdef LPFC_TARGET_MODE
+#define NLP_NEED_PRLI      0x00800000   /* Need PRLI to determine capability */
+#endif
 #define NLP_ACC_REGLOGIN   0x01000000	/* Issue Reg Login after successful
 					   ACC */
 #define NLP_NPR_ADISC      0x02000000	/* Issue ADISC when dq'ed from
drivers/scsi/lpfc/lpfc_els.c +97 -3

178 lines not on this page · raw message

drivers/scsi/lpfc/lpfc_hbadisc.c +52 -0

105 lines not on this page · raw message

drivers/scsi/lpfc/lpfc_hw.h +42 -1

80 lines not on this page · raw message

drivers/scsi/lpfc/lpfc_init.c +17 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc_init.c 4.1-rc7/drivers/scsi/lpfc/lpfc_init.c
@@ -44,6 +44,10 @@
 #include "lpfc_hw.h"
 #include "lpfc_sli.h"
 #include "lpfc_sli4.h"
+#ifdef LPFC_TARGET_MODE
+#include "lpfc_target_api.h"
+#include "lpfc_target_api_base.h"
+#endif
 #include "lpfc_nl.h"
 #include "lpfc_disc.h"
 #include "lpfc_scsi.h"
@@ -570,6 +574,11 @@ lpfc_config_port_post(struct lpfc_hba *p
 	mod_timer(&phba->eratt_poll,
 		  jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
 
+#ifdef LPFC_TARGET_MODE
+	if (phba->cfg_initialize_link)
+		lpfc_init_link(phba, pmb, phba->cfg_topology,
+				phba->cfg_link_speed);
+#endif
 	if (phba->hba_flag & LINK_DISABLED) {
 		lpfc_printf_log(phba,
 			KERN_ERR, LOG_INIT,
@@ -6296,6 +6305,14 @@ lpfc_post_init_setup(struct lpfc_hba *ph
 		spin_unlock_irq(shost->host_lock);
 	}
 
+#ifdef LPFC_TARGET_MODE
+	if (!phba->cfg_initialize_link) {
+		/* After initialization, this should always be set */
+		phba->cfg_initialize_link = 1;
+		return;
+	}
+#endif
+
 	lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
 			"0428 Perform SCSI scan\n");
 	/* Send board arrival event to upper layer */
drivers/scsi/lpfc/lpfc_mbox.c +10 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc_mbox.c 4.1-rc7/drivers/scsi/lpfc/lpfc_mbox.c
@@ -33,6 +33,10 @@
 #include "lpfc_hw.h"
 #include "lpfc_sli.h"
 #include "lpfc_sli4.h"
+#ifdef LPFC_TARGET_MODE
+#include "lpfc_target_api.h"
+#include "lpfc_target_api_base.h"
+#endif
 #include "lpfc_nl.h"
 #include "lpfc_disc.h"
 #include "lpfc_scsi.h"
@@ -553,6 +557,12 @@ lpfc_init_link(struct lpfc_hba * phba,
 	else
 		mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
 
+#ifdef LPFC_TARGET_MODE
+	if (phba->cfg_fcp_mode & LPFC_FCP_MODE_TARGET) {
+		mb->un.varInitLnk.link_flags |=
+			(FLAGS_DISABLE_TGT_ABTS | FLAGS_DISABLE_TGT_ABTS);
+	}
+#endif
 	mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
 	mb->mbxOwner = OWN_HOST;
 	mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
drivers/scsi/lpfc/lpfc_mem.c +7 -1
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc_mem.c 4.1-rc7/drivers/scsi/lpfc/lpfc_mem.c
@@ -34,6 +34,10 @@
 #include "lpfc_sli.h"
 #include "lpfc_sli4.h"
 #include "lpfc_nl.h"
+#ifdef LPFC_TARGET_MODE
+#include "lpfc_target_api.h"
+#include "lpfc_target_api_base.h"
+#endif
 #include "lpfc_disc.h"
 #include "lpfc_scsi.h"
 #include "lpfc.h"
@@ -560,6 +564,7 @@ lpfc_in_buf_free(struct lpfc_hba *phba,
 {
 	struct hbq_dmabuf *hbq_entry;
 	unsigned long flags;
+	uint32_t hbqno;
 
 	if (!mp)
 		return;
@@ -573,7 +578,8 @@ lpfc_in_buf_free(struct lpfc_hba *phba,
 		}
 		hbq_entry = container_of(mp, struct hbq_dmabuf, dbuf);
 		list_del(&hbq_entry->dbuf.list);
-		if (hbq_entry->tag == -1) {
+		hbqno = lpfc_hbqno_get(hbq_entry->tag);
+		if (hbqno >= LPFC_MAX_HBQS) {
 			(phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
 				(phba, hbq_entry);
 		} else {
drivers/scsi/lpfc/lpfc_nportdisc.c +105 -1

166 lines not on this page · raw message

drivers/scsi/lpfc/lpfc_scsi.c +4 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc_scsi.c 4.1-rc7/drivers/scsi/lpfc/lpfc_scsi.c
@@ -40,6 +40,10 @@
 #include "lpfc_sli.h"
 #include "lpfc_sli4.h"
 #include "lpfc_nl.h"
+#ifdef LPFC_TARGET_MODE
+#include "lpfc_target_api.h"
+#include "lpfc_target_api_base.h"
+#endif
 #include "lpfc_disc.h"
 #include "lpfc.h"
 #include "lpfc_scsi.h"
drivers/scsi/lpfc/lpfc_sli.c +186 -11

360 lines not on this page · raw message

drivers/scsi/lpfc/lpfc_sli.h +31 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc_sli.h 4.1-rc7/drivers/scsi/lpfc/lpfc_sli.h
@@ -321,6 +321,37 @@ struct lpfc_sli {
 	struct lpfc_lnk_stat lnk_stat_offsets;
 };
 
+/*
+ * Functions to build or extract fields for HBQ buffer tags.
+ * The applications tag is in bits 30:16, the hbqno in 15:12,
+ * the hbq entry index is in bits 11:0 The high order bit (31)
+ * is reserved for non-hbq buffer use.
+ */
+static inline uint32_t
+lpfc_build_hbq_tag(uint16_t hbqno, uint16_t hbqidx, uint16_t app_tag)
+{
+	return ((app_tag & 0x7fff) << 16) |
+		((hbqno & 0xf) << 12) | (hbqidx & 0xfff);
+}
+
+static inline uint16_t
+lpfc_hbq_app_tag_get(uint32_t tag)
+{
+	return (tag >> 16) & 0x7fff;
+}
+
+static inline uint16_t
+lpfc_hbq_idx_get(uint32_t tag)
+{
+	return tag & 0xfff;
+}
+
+static inline uint16_t
+lpfc_hbqno_get(uint32_t tag)
+{
+	return (tag >> 12) & 0xf;
+}
+
 /* Timeout for normal outstanding mbox command (Seconds) */
 #define LPFC_MBOX_TMO				30
 /* Timeout for non-flash-based outstanding sli_config mbox command (Seconds) */
drivers/scsi/lpfc/lpfc_version.h +1 -1
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc_version.h 4.1-rc7/drivers/scsi/lpfc/lpfc_version.h
@@ -18,7 +18,7 @@
  * included with this package.                                     *
  *******************************************************************/
 
-#define LPFC_DRIVER_VERSION "10.5.0.0."
+#define LPFC_DRIVER_VERSION "10.5.0.0_tm_10.0.0."
 #define LPFC_DRIVER_NAME		"lpfc"
 
 /* Used for SLI 2/3 */
drivers/scsi/lpfc/lpfc_vport.c +17 -0
diff -upNr 4.1-rc7.orig/drivers/scsi/lpfc/lpfc_vport.c 4.1-rc7/drivers/scsi/lpfc/lpfc_vport.c
@@ -37,6 +37,10 @@
 #include "lpfc_hw.h"
 #include "lpfc_sli.h"
 #include "lpfc_sli4.h"
+#ifdef LPFC_TARGET_MODE
+#include "lpfc_target_api.h"
+#include "lpfc_target_api_base.h"
+#endif
 #include "lpfc_nl.h"
 #include "lpfc_disc.h"
 #include "lpfc_scsi.h"
@@ -45,6 +49,9 @@
 #include "lpfc_crtn.h"
 #include "lpfc_version.h"
 #include "lpfc_vport.h"
+#ifdef LPFC_TARGET_MODE
+#include "lpfc_target_protos.h"
+#endif
 
 inline void lpfc_vport_set_state(struct lpfc_vport *vport,
 				 enum fc_vport_state new_state)
@@ -419,6 +426,11 @@ lpfc_vport_create(struct fc_vport *fc_vp
 		goto out;
 	}
 
+#ifdef LPFC_TARGET_MODE
+	if (phba->cfg_fcp_mode & LPFC_FCP_MODE_TARGET)
+		lpfc_target_new_tgtport(vport);
+#endif
+
 	if ((phba->link_state < LPFC_LINK_UP) ||
 	    (pport->port_state < LPFC_FABRIC_CFG_LINK) ||
 	    (phba->fc_topology == LPFC_TOPOLOGY_LOOP)) {
@@ -777,6 +789,11 @@ skip_logo:
 	} else
 		scsi_host_put(shost);
 
+#ifdef LPFC_TARGET_MODE
+	if (phba->cfg_fcp_mode & LPFC_FCP_MODE_TARGET)
+		lpfc_target_rm_tgtport(vport);
+#endif
+
 	lpfc_free_vpi(phba, vport->vpi);
 	vport->work_port_events = 0;
 	spin_lock_irq(&phba->hbalock);