Skip to contentSkip to conversation

libfc, libfcoe and fcoe updates for scsi-misc

PATCH Superseded Robert Love 1 participant 10 messages Jun 20, 2011

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover libfc, libfcoe and fcoe updates for scsi-misc

The following series contains target offload patches and a few bug fixes. The main change that this series presents is target mode offload support. These are the same offloads that the initiator uses, so there is no new hardware support. There is a new hook in the netdev_ops structure to setup a DDP context for an offloadable exchange. If ndo_fcoe_ddp_target is present on the netdevice the fcoe stack will make use of it. This interfce was merged at the v3.0 merge window, so all depedencies should already be complete and in-kernel.

Aside from this feature there are a few fixes to tcm_fc as well as libfc and fcoe.

All patches were tested against scsi-misc on the day of this posting.

---

Kiran Patil (8):
tcm_fc: Fix warning in file tfc_io
libfc: Enhancement to RPORT state machine applicable only for VN2VN mode
fcoe: Unable to select the exchangeID from offload pool for storage targets
fcoe: Round-robin based selection of CPU for post-processing of incoming commands
fcoe: Amends previous patch, Round-robin based selection of CPU for post processing of incoming request for FCoE target libfc:Fix for exchange/seq loopup failure when FCoE stack is used as target and connected to windows initaitor
tcm_fc: Fix ft_send_tm-bug and drop ft_get_lun_for_cmd usage
tcm_fc: Fixing reference counting problem which was causing ft_sess to be deleted.

Neerav Parikh (1):
fcoe: Rearrange fcoe port and NPIV port cleanup

Vasu Dev (1):
libfc: post reset event on lport reset

Yi Zou (2):
libfc, tcm_fc: add ddp_targ() to libfc function template to supprot FCoE DDP in target mode
fcoe: support ndo_fcoe_ddp_target() for DDP in FCoE targe

 drivers/scsi/fcoe/fcoe.c        |  174 ++++++++++++++++++++++++++++++---------
 drivers/scsi/libfc/fc_exch.c    |   26 +++++-
 drivers/scsi/libfc/fc_lport.c   |    2 
 drivers/scsi/libfc/fc_rport.c   |   14 +++
 drivers/target/tcm_fc/tcm_fc.h  |    2 
 drivers/target/tcm_fc/tfc_cmd.c |   88 +++++++++++---------
 drivers/target/tcm_fc/tfc_io.c  |    2 
 include/scsi/libfc.h            |    8 ++
 8 files changed, 233 insertions(+), 83 deletions(-)
Signature · 1 line
Thanks, //Rob
#1 lore raw

PATCH 1/12 tcm_fc: Fix warning in file tfc_io

From: Kiran Patil <[email protected]>

Printk causing warning, trying to print size_t as %x.

Fix the printk statement, to print it as %zd instead of explictly casting to (unsigned int)

---
 drivers/target/tcm_fc/tfc_io.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/target/tcm_fc/tfc_io.c +1 -1
index 4c3c0ef..702d4b8 100644
@@ -203,7 +203,7 @@ int ft_queue_data_in(struct se_cmd *se_cmd)
 			/* XXX For now, initiator will retry */
 			if (printk_ratelimit())
 				printk(KERN_ERR "%s: Failed to send frame %p, "
-						"xid <0x%x>, remaining <0x%x>, "
+						"xid <0x%x>, remaining <%zd>, "
 						"lso_max <0x%x>\n",
 						__func__, fp, ep->xid,
 						remaining, lport->lso_max);
#2 lore raw

PATCH 2/12 libfc: Enhancement to RPORT state machine applicable only for VN2VN mode

In reply to Robert Love

From: Kiran Patil <[email protected]>

Problem: Existing RPORT state machine continues witg FLOGI/PLOGI process only after it receices beacon from other end. Once claiming stage is over (either clain notify or clain repose), beacon is sent and state machine enters into operational mode where it initiates the rlogin process (FLOGI/PLOGI) to the peer but before this rlogin is initiated, exitsing implementation checks if it received beacon from other end, it beacon is not received yet, rlogin process is not initiated. Other end initiates FLOGI but peer end keeps on rejecting FLOGI, hence after 3 retries other end deletes associated rport, then sends a beacon. Once the beacon is received, peer end now initiates rlogin to the peer end but since associated rport is deleted FLOGI is neither accepted nor the reject response send out because rport is deleted. Hence unable to proceed withg FLOGI/PLOGI process and fails to establish VN2VN connection.

Fix: VN2VN spec is not standard yet but based on exitsing collateral on T11, it appears that, both end shall send beacon and enter into 'operational mode' without explictly waiting for beacon from other end. Fix is to allow the RPORT login process as long as respective RPORT is created (as part of claim notification / claim response) even though state of RPORT is INIT. Means don't wait for beacon from peer end, if peer end initiates FLOGI (means peer end exist and responding).

Notes: This patch is preparing the FCoE stack for target wrt offload. This is generic patch and harmless even if applied on storage initiator because 'else if' condition of function 'fcoe_oem_found' shall evaluate to TRUE only for targets.

Dependencies: None

---
 drivers/scsi/libfc/fc_rport.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
drivers/scsi/libfc/fc_rport.c +14 -0
index 49e1ccc..3b66937 100644
@@ -801,6 +801,20 @@ static void fc_rport_recv_flogi_req(struct fc_lport *lport,
 
 	switch (rdata->rp_state) {
 	case RPORT_ST_INIT:
+		/*
+		 * If received the FLOGI request on RPORT which is INIT state
+		 * (means not transition to FLOGI either fc_rport timeout
+		 * function didn;t trigger or this end hasn;t received
+		 * beacon yet from other end. In that case only, allow RPORT
+		 * state machine to continue, otherwise fall through which
+		 * causes the code to send reject response.
+		 * NOTE; Not checking for FIP->state such as VNMP_UP or
+		 * VNMP_CLAIM because if FIP state is not one of those,
+		 * RPORT wouldn;t have created and 'rport_lookup' would have
+		 * failed anyway in that case.
+		 */
+		if (lport->point_to_multipoint)
+			break;
 	case RPORT_ST_DELETE:
 		mutex_unlock(&rdata->rp_mutex);
 		rjt_data.reason = ELS_RJT_FIP;
#3 lore raw

PATCH 3/12 libfc, tcm_fc: add ddp_targ() to libfc function template to supprot FCoE DDP in target mode

In reply to Robert Love

From: Yi Zou <[email protected]>

The fcoe driver can implement ddp_targ() similarly to ddp_setup() when fcoe stack works with existing target frame, e.g., tcm, where the ddp_targ() would eventually point to the underlying hardware driver's implementation of ndo_fcoe_ddp_targ() through net_device_ops. This new API sets up DDP context for target appropriately by setting required bits for DDP context.

---
 drivers/target/tcm_fc/tfc_cmd.c |    5 +++--
 include/scsi/libfc.h            |    8 ++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/target/tcm_fc/tfc_cmd.c +3 -2
index c056a11..1625b48 100644
@@ -289,8 +289,9 @@ int ft_write_pending(struct se_cmd *se_cmd)
 				cmd->sg_cnt =
 					T_TASK(se_cmd)->t_tasks_sg_chained_no;
 			}
-			if (cmd->sg && lport->tt.ddp_setup(lport, ep->xid,
-						    cmd->sg, cmd->sg_cnt))
+			if (cmd->sg && lport->tt.ddp_target(lport, ep->xid,
+							    cmd->sg,
+							    cmd->sg_cnt))
 				cmd->was_ddp_setup = 1;
 		}
 	}
include/scsi/libfc.h +8 -0
index a3cbda4..7d96829 100644
@@ -511,6 +511,14 @@ struct libfc_function_template {
 	 */
 	int (*ddp_done)(struct fc_lport *, u16);
 	/*
+	 * Sets up the DDP context for a given exchange id on the given
+	 * scatterlist if LLD supports DDP for FCoE target.
+	 *
+	 * STATUS: OPTIONAL
+	 */
+	int (*ddp_target)(struct fc_lport *, u16, struct scatterlist *,
+			  unsigned int);
+	/*
 	 * Allow LLD to fill its own Link Error Status Block
 	 *
 	 * STATUS: OPTIONAL
#4 lore raw

PATCH 4/12 fcoe: support ndo_fcoe_ddp_target() for DDP in FCoE targe

In reply to Robert Love

From: Yi Zou <[email protected]>

Add ddp_target() support to the Open-FCoE sw fcoe hba driver (fcoe.ko).

---
 drivers/scsi/fcoe/fcoe.c |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)
drivers/scsi/fcoe/fcoe.c +25 -1
index 155d7b9..f76a321 100644
@@ -99,7 +99,8 @@ static void fcoe_destroy_work(struct work_struct *);
 static int fcoe_ddp_setup(struct fc_lport *, u16, struct scatterlist *,
 			  unsigned int);
 static int fcoe_ddp_done(struct fc_lport *, u16);
-
+static int fcoe_ddp_target(struct fc_lport *, u16, struct scatterlist *,
+			   unsigned int);
 static int fcoe_cpu_callback(struct notifier_block *, unsigned long, void *);
 
 static bool fcoe_match(struct net_device *netdev);
@@ -143,6 +144,7 @@ static struct libfc_function_template fcoe_libfc_fcn_templ = {
 	.frame_send = fcoe_xmit,
 	.ddp_setup = fcoe_ddp_setup,
 	.ddp_done = fcoe_ddp_done,
+	.ddp_target = fcoe_ddp_target,
 	.elsct_send = fcoe_elsct_send,
 	.get_lesb = fcoe_get_lesb,
 	.lport_set_port_id = fcoe_set_port_id,
@@ -887,6 +889,28 @@ static int fcoe_ddp_setup(struct fc_lport *lport, u16 xid,
 }
 
 /**
+ * fcoe_ddp_target() - Call a LLD's ddp_target through the net device
+ * @lport: The local port to setup DDP for
+ * @xid:   The exchange ID for this DDP transfer
+ * @sgl:   The scatterlist describing this transfer
+ * @sgc:   The number of sg items
+ *
+ * Returns: 0 if the DDP context was not configured
+ */
+static int fcoe_ddp_target(struct fc_lport *lport, u16 xid,
+			   struct scatterlist *sgl, unsigned int sgc)
+{
+	struct net_device *netdev = fcoe_netdev(lport);
+
+	if (netdev->netdev_ops->ndo_fcoe_ddp_target)
+		return netdev->netdev_ops->ndo_fcoe_ddp_target(netdev, xid,
+							       sgl, sgc);
+
+	return 0;
+}
+
+
+/**
  * fcoe_ddp_done() - Call a LLD's ddp_done through the net device
  * @lport: The local port to complete DDP on
  * @xid:   The exchange ID for this DDP transfer
#5 lore raw

PATCH 5/12 fcoe: Unable to select the exchangeID from offload pool for storage targets

In reply to Robert Love

From: Kiran Patil <[email protected]>

Problem: When initiator sends write command to target, target tries to assign new sequence. It
allocates new exchangeID (RX_ID) always from non-offloaded pool (Non-offload EMA)

Fix: Enhanced fcoe_oem_match routine to look at F_CTL flags and if it is exchange responder and
command type is WRITEDATA, then function returns TRUE instead of FALSE. This function is used to determine which pool to use (offload pool of exchange is used only if this function returns TRUE).

Technical Notes: N/A

---
 drivers/scsi/fcoe/fcoe.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
drivers/scsi/fcoe/fcoe.c +17 -2
index f76a321..6378c58 100644
@@ -751,12 +751,27 @@ static int fcoe_shost_config(struct fc_lport *lport, struct device *dev)
  * The offload EM that this routine is associated with will handle any
  * packets that are for SCSI read requests.
  *
+ * This has been enhanced to work when FCoE stack is operating in target
+ * mode.
+ *
  * Returns: True for read types I/O, otherwise returns false.
  */
 bool fcoe_oem_match(struct fc_frame *fp)
 {
-	return fc_fcp_is_read(fr_fsp(fp)) &&
-		(fr_fsp(fp)->data_len > fcoe_ddp_min);
+	struct fc_frame_header *fh = fc_frame_header_get(fp);
+	struct fcp_cmnd *fcp;
+
+	if (fc_fcp_is_read(fr_fsp(fp)) &&
+	    (fr_fsp(fp)->data_len > fcoe_ddp_min))
+		return true;
+	else if (!(ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX)) {
+		fcp = fc_frame_payload_get(fp, sizeof(*fcp));
+		if (ntohs(fh->fh_rx_id) == FC_XID_UNKNOWN &&
+		    fcp && (ntohl(fcp->fc_dl) > fcoe_ddp_min) &&
+		    (fcp->fc_flags & FCP_CFL_WRDATA))
+			return true;
+	}
+	return false;
 }
 
 /**
#6 lore raw

PATCH 6/12 fcoe: Round-robin based selection of CPU for post-processing of incoming commands

In reply to Robert Love

From: Kiran Patil <[email protected]>

Problem: Earlier mechanism of selection of CPU was, to select the same CPU which has received incoming request. Hence in case of rx_id = 0xFFFF, request was always posted to same NetRx queue, hence only 1 CPU is utilized for handling the command. It was also causing problem of "running out of exchanges from per CPU pool of exchanges (in case of DDP offload)

Fix: Implemented new algo. to select CPU for post-processing of incoming commands when rx_id is unknown. This is simple Round robin algo. for CPU selection.

Notes/Dependencies: N/A

---
 drivers/scsi/fcoe/fcoe.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)
drivers/scsi/fcoe/fcoe.c +38 -1
index 6378c58..da73115 100644
@@ -1245,6 +1245,36 @@ static int fcoe_cpu_callback(struct notifier_block *nfb,
 }
 
 /**
+ * fcoe_select_cpu() - Selects CPU to handle post-processing of incoming
+ *			command.
+ * @curr_cpu:   CPU which received request
+ *
+ * This routine selects next CPU based on cpumask.
+ *
+ * Returns: int (CPU number). Caller to verify if returned CPU is online or not.
+ */
+static unsigned int fcoe_select_cpu(unsigned int curr_cpu)
+{
+	static unsigned int selected_cpu;
+
+	if (num_online_cpus() == 1)
+		return curr_cpu;
+	/*
+	 * Doing following check, to skip "curr_cpu (smp_processor_id)"
+	 * from selection of CPU is intentional. This is to avoid same CPU
+	 * doing post-processing of command. "curr_cpu" to just receive
+	 * incoming request in case where rx_id is UNKNOWN and all other
+	 * CPU to actually process the command(s)
+	 */
+	do {
+		selected_cpu = cpumask_next(selected_cpu, cpu_online_mask);
+		if (selected_cpu >= nr_cpu_ids)
+			selected_cpu = cpumask_first(cpu_online_mask);
+	} while (selected_cpu == curr_cpu);
+	return selected_cpu;
+}
+
+/**
  * fcoe_rcv() - Receive packets from a net device
  * @skb:    The received packet
  * @netdev: The net device that the packet was received on
@@ -1320,9 +1350,16 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
 	 */
 	if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX)
 		cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask;
-	else
+	else {
 		cpu = smp_processor_id();
 
+		if ((fh->fh_type == FC_TYPE_FCP) &&
+		    (ntohs(fh->fh_rx_id) == FC_XID_UNKNOWN)) {
+			do {
+				cpu = fcoe_select_cpu(cpu);
+			} while (!cpu_online(cpu));
+		}
+	}
 	fps = &per_cpu(fcoe_percpu, cpu);
 	spin_lock_bh(&fps->fcoe_rx_list.lock);
 	if (unlikely(!fps->thread)) {
#7 lore raw

PATCH 7/12 fcoe: Amends previous patch, Round-robin based selection of CPU for post processing of incoming request for FCoE target

In reply to Robert Love

From: Kiran Patil <[email protected]>

Problem: Selection of RX queue on target is based on RX-ID. FCoE used 8 Net Rx queues. HW post the packets based on rx_id % num_rx_queue. Due to this has based filtering, only one CPU is busy servicing incoming request including post-processing of incoming request. This is gating factor because
1. Only one CPU is utilized 100% while others CPUs are not used at all.
2. CPU which received request assign "sequence' by selecting exchange from per CPU pool (num_ddp_context / num_online_cpus, approxi.). Due to which if if rate of incoming request is higher than rate of servicing request, existing code path end of sending "BUSY" response (SAM_STAT_BUSY because unable to allocate exchange).

Fix: Fan-out incoming request to all other CPUs excluding the CPU which is receiving all incoiming request. This path also addresses, selecting same CPU based on rx_id from received frame for completion of the request such as "releasing exchange to the per CPU Pool". This fix is applicable for FCoE target since initiator code path already takes care of selecting CPU to complete post-processing of request once OX_ID is assigned.

Notes: N/A

Dependencines: N/A

---
 drivers/scsi/fcoe/fcoe.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/scsi/fcoe/fcoe.c +5 -1
index da73115..522fbaa 100644
@@ -1358,7 +1358,11 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
 			do {
 				cpu = fcoe_select_cpu(cpu);
 			} while (!cpu_online(cpu));
-		}
+		} else  if ((fh->fh_type == FC_TYPE_FCP) &&
+			    (ntohs(fh->fh_rx_id) != FC_XID_UNKNOWN)) {
+			cpu = ntohs(fh->fh_rx_id) & fc_cpu_mask;
+		} else
+			cpu = smp_processor_id();
 	}
 	fps = &per_cpu(fcoe_percpu, cpu);
 	spin_lock_bh(&fps->fcoe_rx_list.lock);
#8 lore raw

PATCH 8/12 libfc:Fix for exchange/seq loopup failure when FCoE stack is used as target and connected to windows initaitor

In reply to Robert Love

From: Kiran Patil <[email protected]>

Problem: Linux based SW target (TCM) connected to windows initiator was unable to satisfy write request of size > 2K.

Fix: Existing linux implememtation of FCoE stack is expecting sequence number to match w.r.t incoming framme. When DDP is used on target in response to write request from initiator, SW stack is notified only when last data frame arrives and only the pakcket header of last data frame is posted to NetRx queue of storage. When that last packet was processed in libfc:Exchange layer, implementation was expecting sequence number to match, but in this case sequence number which is embedded in FC Header is assigned by windows initaitor, hence due to sequence number mismatch post-processing which shall result into sending RSP is not done. Enhanced the code to utilize the sequence number of incoming last frame and process the packet so that, it will eventually complete the write request by sending write response (RSP) GOOD.

Notes/Dependencies: This patch is validated using windows and linux initiator to make sure, it doesn't break anything.

---
 drivers/scsi/libfc/fc_exch.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
drivers/scsi/libfc/fc_exch.c +24 -2
index 3b8a645..f5a0665 100644
@@ -965,8 +965,30 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
 		sp = &ep->seq;
 		if (sp->id != fh->fh_seq_id) {
 			atomic_inc(&mp->stats.seq_not_found);
-			reject = FC_RJT_SEQ_ID;	/* sequence/exch should exist */
-			goto rel;
+			if (f_ctl & FC_FC_END_SEQ) {
+				/*
+				 * Update sequence_id based on incoming last
+				 * frame of sequence exchange. This is needed
+				 * for FCoE target where DDP has been used
+				 * on target where, stack is indicated only
+				 * about last frame's (payload _header) header.
+				 * Whereas "seq_id" which is part of
+				 * frame_header is allocated by initiator
+				 * which is totally different from "seq_id"
+				 * allocated when XFER_RDY was sent by target.
+				 * To avoid false -ve which results into not
+				 * sending RSP, hence write request on other
+				 * end never finishes.
+				 */
+				spin_lock_bh(&ep->ex_lock);
+				sp->ssb_stat |= SSB_ST_RESP;
+				sp->id = fh->fh_seq_id;
+				spin_unlock_bh(&ep->ex_lock);
+			} else {
+				/* sequence/exch should exist */
+				reject = FC_RJT_SEQ_ID;
+				goto rel;
+			}
 		}
 	}
 	WARN_ON(ep != fc_seq_exch(sp));
#9 lore raw
In reply to Robert Love
Quoted 64 lines

-----Original Message-----
From: [email protected] [mailto:linux-scsi- [email protected]] On Behalf Of Robert Love
Sent: Monday, June 20, 2011 4:30 PM
To: [email protected]
Subject: [PATCH 00/12] libfc, libfcoe and fcoe updates for scsi-misc

The following series contains target offload patches and a few bug fixes. The main change that this series presents is target mode offload support. These are the same offloads that the initiator uses, so there is no new hardware support. There is a new hook in the netdev_ops structure to setup a DDP context for an offloadable exchange. If ndo_fcoe_ddp_target is present on the netdevice the fcoe stack will make use of it. This interfce was merged at the v3.0 merge window, so all depedencies should already be complete and in-kernel.

Aside from this feature there are a few fixes to tcm_fc as well as libfc and fcoe.

All patches were tested against scsi-misc on the day of this posting.

---

Kiran Patil (8):
tcm_fc: Fix warning in file tfc_io
libfc: Enhancement to RPORT state machine applicable only for
VN2VN mode
fcoe: Unable to select the exchangeID from offload pool for
storage targets
fcoe: Round-robin based selection of CPU for post-processing of
incoming commands
fcoe: Amends previous patch, Round-robin based selection of CPU
for post processing of incoming request for FCoE target
libfc:Fix for exchange/seq loopup failure when FCoE stack is used
as target and connected to windows initaitor
tcm_fc: Fix ft_send_tm-bug and drop ft_get_lun_for_cmd usage
tcm_fc: Fixing reference counting problem which was causing
ft_sess to be deleted.

Neerav Parikh (1):
fcoe: Rearrange fcoe port and NPIV port cleanup

Vasu Dev (1):
libfc: post reset event on lport reset

Yi Zou (2):
libfc, tcm_fc: add ddp_targ() to libfc function template to
supprot FCoE DDP in target mode
fcoe: support ndo_fcoe_ddp_target() for DDP in FCoE targe

drivers/scsi/fcoe/fcoe.c | 174 ++++++++++++++++++++++++++++++--
-------

drivers/scsi/libfc/fc_exch.c    |   26 +++++-
drivers/scsi/libfc/fc_lport.c   |    2
drivers/scsi/libfc/fc_rport.c   |   14 +++
drivers/target/tcm_fc/tcm_fc.h  |    2
drivers/target/tcm_fc/tfc_cmd.c |   88 +++++++++++---------
drivers/target/tcm_fc/tfc_io.c  |    2
include/scsi/libfc.h            |    8 ++
8 files changed, 233 insertions(+), 83 deletions(-)
Quoted 1 line

--

There was a comma in one of the signed off lines. When I mail patches I use stgit and specifically 'stg --auto' which will CC anyone who has signed the patches. I do not use the '--auto' option when I test mail myself before mailing externally so I didn't catch this on my test mail. I guess 'stg --auto' doesn't like '<lastname>, <firstname>' for signed-off lines. On a quick glance, I didn't see anything in SubmittingPatches about last name comma first name being a format violation, although I have never seen that ordering before on signed-off lines. Stgit at least doesn't like it.

I'll resend this series as 'v2'.

Sorry for the trash, //Rob