Skip to contentSkip to conversation

libfc, libfcoe and fcoe updates for scsi-misc

PATCH New Robert Love 1 participant 9 messages Feb 25, 2011

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

cover libfc, libfcoe and fcoe updates for scsi-misc

The following series implements a few fixes here
and there, nothing more.

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

---

Bhanu Prakash Gollapudi (3):
libfc: introduce __fc_fill_fc_hdr that accepts fc_hdr as an argument
libfcoe: Move FCOE_MTU definition from fcoe.h to libfcoe.h
libfcoe: Remove stale fcoe-netdev entries

Dan Carpenter (1):
fcoe: precedence bug in fcoe_filter_frames()

Parikh, Neerav (2):
libfc: Fixing a memory leak when destroying an interface
Revert "[SCSI] libfc: fix exchange being deleted when the abort itself is timed out"

Vasu Dev (2):
fcoe, libfc: initialize EM anchors list and then update npiv EMs
fcoe: fix broken fcoe interface reset

 drivers/scsi/fcoe/fcoe.c           |   60 ++++++++++++++++++++----------------
 drivers/scsi/fcoe/fcoe.h           |    6 ----
 drivers/scsi/fcoe/fcoe_transport.c |   46 +++++++++++++++++++++++++++-
 drivers/scsi/libfc/fc_exch.c       |    8 ++---
 drivers/scsi/libfc/fc_lport.c      |    1 +
 drivers/scsi/libfc/fc_npiv.c       |    9 +----
 drivers/scsi/libfc/fc_rport.c      |    1 +
 include/scsi/fc_encode.h           |   26 ++++++++++------
 include/scsi/libfcoe.h             |    6 ++++
 9 files changed, 108 insertions(+), 55 deletions(-)
Signature · 1 line
Thanks, //Rob
#1 lore raw

PATCH 1/8 libfc: Fixing a memory leak when destroying an interface

From: Parikh, Neerav <[email protected]>

When an fcoe interface is being destroyed; in the process the fcoe driver will try to release all the resources it had allocated for that interface including rports. But, it seems that it does not release the reference held for the name server rport in that process resulting into a memory leak. This patch fixes that memory leak.

---
 drivers/scsi/libfc/fc_rport.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/scsi/libfc/fc_rport.c +1 -0
index 59b16bb..49e1ccc 100644
@@ -357,6 +357,7 @@ static void fc_rport_work(struct work_struct *work)
 			if (port_id == FC_FID_DIR_SERV) {
 				rdata->event = RPORT_EV_NONE;
 				mutex_unlock(&rdata->rp_mutex);
+				kref_put(&rdata->kref, lport->tt.rport_destroy);
 			} else if ((rdata->flags & FC_RP_STARTED) &&
 				   rdata->major_retries <
 				   lport->max_rport_retry_count) {
#2 lore raw

PATCH 2/8 Revert "[SCSI] libfc: fix exchange being deleted when the abort itself is timed out"

In reply to Robert Love

From: Parikh, Neerav <[email protected]>

When abort for an exchange timed out it didn't release the reference to the exchange resulting in a memory leak.

After discussion with the author of the patch (CC) that introduced this bug it was suggested to revert that patch.

This reverts commit ea3e2e72eeb3e8a9440a5da965914f9b12088626.

Signed-off by: Neerav Parikh <[email protected]>

---
 drivers/scsi/libfc/fc_exch.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
drivers/scsi/libfc/fc_exch.c +2 -5
index 08bf5fa..10a5436 100644
@@ -666,13 +666,10 @@ static void fc_exch_timeout(struct work_struct *work)
 		if (e_stat & ESB_ST_ABNORMAL)
 			rc = fc_exch_done_locked(ep);
 		spin_unlock_bh(&ep->ex_lock);
+		if (!rc)
+			fc_exch_delete(ep);
 		if (resp)
 			resp(sp, ERR_PTR(-FC_EX_TIMEOUT), arg);
-		if (!rc) {
-			/* delete the exchange if it's already being aborted */
-			fc_exch_delete(ep);
-			return;
-		}
 		fc_seq_exch_abort(sp, 2 * ep->r_a_tov);
 		goto done;
 	}
#3 lore raw

PATCH 3/8 fcoe, libfc: initialize EM anchors list and then update npiv EMs

In reply to Robert Love

From: Vasu Dev <[email protected]>

EM anchors list initialization for only master port was not enough to keep npiv working as described here:-
https://lists.open-fcoe.org/pipermail/devel/2011-January/011063.html

So this patch moves fc_exch_mgr_list_clone to update npiv ports EMs once EM anchors list initialized.

Also some cleanup, no need to set lport = NULL as that always get initialized later.

---
 drivers/scsi/fcoe/fcoe.c      |   50 +++++++++++++++++++++--------------------
 drivers/scsi/libfc/fc_exch.c  |    1 +
 drivers/scsi/libfc/fc_lport.c |    1 +
 drivers/scsi/libfc/fc_npiv.c  |    9 +------
 4 files changed, 29 insertions(+), 32 deletions(-)
drivers/scsi/fcoe/fcoe.c +26 -24
index 495456f..0b5fbb8 100644
@@ -928,8 +928,9 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
 				       struct device *parent, int npiv)
 {
 	struct net_device *netdev = fcoe->netdev;
-	struct fc_lport *lport = NULL;
+	struct fc_lport *lport, *n_port;
 	struct fcoe_port *port;
+	struct Scsi_Host *shost;
 	int rc;
 	/*
 	 * parent is only a vport if npiv is 1,
@@ -939,13 +940,11 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
 
 	FCOE_NETDEV_DBG(netdev, "Create Interface\n");
 
-	if (!npiv) {
-		lport = libfc_host_alloc(&fcoe_shost_template,
-					 sizeof(struct fcoe_port));
-	} else	{
-		lport = libfc_vport_create(vport,
-					   sizeof(struct fcoe_port));
-	}
+	if (!npiv)
+		lport = libfc_host_alloc(&fcoe_shost_template, sizeof(*port));
+	else
+		lport = libfc_vport_create(vport, sizeof(*port));
+
 	if (!lport) {
 		FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n");
 		rc = -ENOMEM;
@@ -998,24 +997,27 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
 		goto out_lp_destroy;
 	}
 
-	if (!npiv) {
-		/*
-		 * fcoe_em_alloc() and fcoe_hostlist_add() both
-		 * need to be atomic with respect to other changes to the
-		 * hostlist since fcoe_em_alloc() looks for an existing EM
-		 * instance on host list updated by fcoe_hostlist_add().
-		 *
-		 * This is currently handled through the fcoe_config_mutex
-		 * begin held.
-		 */
-
+	/*
+	 * fcoe_em_alloc() and fcoe_hostlist_add() both
+	 * need to be atomic with respect to other changes to the
+	 * hostlist since fcoe_em_alloc() looks for an existing EM
+	 * instance on host list updated by fcoe_hostlist_add().
+	 *
+	 * This is currently handled through the fcoe_config_mutex
+	 * begin held.
+	 */
+	if (!npiv)
 		/* lport exch manager allocation */
 		rc = fcoe_em_config(lport);
-		if (rc) {
-			FCOE_NETDEV_DBG(netdev, "Could not configure the EM "
-					"for the interface\n");
-			goto out_lp_destroy;
-		}
+	else {
+		shost = vport_to_shost(vport);
+		n_port = shost_priv(shost);
+		rc = fc_exch_mgr_list_clone(n_port, lport);
+	}
+
+	if (rc) {
+		FCOE_NETDEV_DBG(netdev, "Could not configure the EM\n");
+		goto out_lp_destroy;
 	}
 
 	fcoe_interface_get(fcoe);
drivers/scsi/libfc/fc_exch.c +1 -0
index 10a5436..28231ba 100644
@@ -2175,6 +2175,7 @@ err:
 		fc_exch_mgr_del(ema);
 	return -ENOMEM;
 }
+EXPORT_SYMBOL(fc_exch_mgr_list_clone);
 
 /**
  * fc_exch_mgr_alloc() - Allocate an exchange manager
drivers/scsi/libfc/fc_lport.c +1 -0
index 735f1f8..8c08b21 100644
@@ -1590,6 +1590,7 @@ void fc_lport_enter_flogi(struct fc_lport *lport)
  */
 int fc_lport_config(struct fc_lport *lport)
 {
+	INIT_LIST_HEAD(&lport->ema_list);
 	INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout);
 	mutex_init(&lport->lp_mutex);
 
drivers/scsi/libfc/fc_npiv.c +1 -8
index 076cd5f..f33b897 100644
@@ -37,9 +37,7 @@ struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize)
 
 	vn_port = libfc_host_alloc(shost->hostt, privsize);
 	if (!vn_port)
-		goto err_out;
-	if (fc_exch_mgr_list_clone(n_port, vn_port))
-		goto err_put;
+		return vn_port;
 
 	vn_port->vport = vport;
 	vport->dd_data = vn_port;
@@ -49,11 +47,6 @@ struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize)
 	mutex_unlock(&n_port->lp_mutex);
 
 	return vn_port;
-
-err_put:
-	scsi_host_put(vn_port->host);
-err_out:
-	return NULL;
 }
 EXPORT_SYMBOL(libfc_vport_create);
 
#4 lore raw

PATCH 4/8 libfc: introduce __fc_fill_fc_hdr that accepts fc_hdr as an argument

In reply to Robert Love

From: Bhanu Prakash Gollapudi <[email protected]>

fc_fill_fc_hdr() expects fc_frame as an argument. Introduce __fc_fill_fc_hdr to accept fc_frame_header as an argument.

---
 include/scsi/fc_encode.h |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)
include/scsi/fc_encode.h +17 -9
index 6d293c8..be418d8 100644
@@ -46,16 +46,11 @@ struct fc_ct_req {
 	} payload;
 };
 
-/**
- * fill FC header fields in specified fc_frame
- */
-static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
-				  u32 did, u32 sid, enum fc_fh_type type,
-				  u32 f_ctl, u32 parm_offset)
+static inline void __fc_fill_fc_hdr(struct fc_frame_header *fh,
+				    enum fc_rctl r_ctl,
+				    u32 did, u32 sid, enum fc_fh_type type,
+				    u32 f_ctl, u32 parm_offset)
 {
-	struct fc_frame_header *fh;
-
-	fh = fc_frame_header_get(fp);
 	WARN_ON(r_ctl == 0);
 	fh->fh_r_ctl = r_ctl;
 	hton24(fh->fh_d_id, did);
@@ -68,6 +63,19 @@ static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
 }
 
 /**
+ * fill FC header fields in specified fc_frame
+ */
+static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
+				  u32 did, u32 sid, enum fc_fh_type type,
+				  u32 f_ctl, u32 parm_offset)
+{
+	struct fc_frame_header *fh;
+
+	fh = fc_frame_header_get(fp);
+	__fc_fill_fc_hdr(fh, r_ctl, did, sid, type, f_ctl, parm_offset);
+}
+
+/**
  * fc_adisc_fill() - Fill in adisc request frame
  * @lport: local port.
  * @fp: fc frame where payload will be placed.
#5 lore raw

PATCH 5/8 libfcoe: Move FCOE_MTU definition from fcoe.h to libfcoe.h

In reply to Robert Love

From: Bhanu Prakash Gollapudi <[email protected]>

both fcoe and bnx2fc drivers can access the common definition of FCOE_MTU.

---
 drivers/scsi/fcoe/fcoe.h |    6 ------
 include/scsi/libfcoe.h   |    6 ++++++
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/fcoe/fcoe.h +0 -6
index d775128..408a6fd 100644
@@ -40,12 +40,6 @@
 #define FCOE_MIN_XID		0x0000	/* the min xid supported by fcoe_sw */
 #define FCOE_MAX_XID		0x0FFF	/* the max xid supported by fcoe_sw */
 
-/*
- * Max MTU for FCoE: 14 (FCoE header) + 24 (FC header) + 2112 (max FC payload)
- * + 4 (FC CRC) + 4 (FCoE trailer) =  2158 bytes
- */
-#define FCOE_MTU	2158
-
 unsigned int fcoe_debug_logging;
 module_param_named(debug_logging, fcoe_debug_logging, int, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
include/scsi/libfcoe.h +6 -0
index e502463..8c1638b 100644
@@ -33,6 +33,12 @@
 #define FCOE_MAX_CMD_LEN	16	/* Supported CDB length */
 
 /*
+ * Max MTU for FCoE: 14 (FCoE header) + 24 (FC header) + 2112 (max FC payload)
+ * + 4 (FC CRC) + 4 (FCoE trailer) =  2158 bytes
+ */
+#define FCOE_MTU	2158
+
+/*
  * FIP tunable parameters.
  */
 #define FCOE_CTLR_START_DELAY	2000	/* mS after first adv. to choose FCF */
#6 lore raw

PATCH 6/8 libfcoe: Remove stale fcoe-netdev entries

In reply to Robert Love

From: Bhanu Prakash Gollapudi <[email protected]>

When L2 driver is unloaded, libfcoe_destroy tries to access the fcoe transport structure matching the netdev. However, since the netdev is unregistered by that time, it fails to do so. Hence the stale mappings exists in the fcoe-netdev list. Handle NETDEV_UREGISTER device notification mechanism to remove the stale fcoe-netdev mapping.

---
 drivers/scsi/fcoe/fcoe_transport.c |   46 +++++++++++++++++++++++++++++++++++-
 1 files changed, 45 insertions(+), 1 deletions(-)
drivers/scsi/fcoe/fcoe_transport.c +45 -1
index 745eb9a..2586841 100644
@@ -39,10 +39,13 @@ static struct fcoe_transport *fcoe_transport_lookup(struct net_device *device);
 static struct fcoe_transport *fcoe_netdev_map_lookup(struct net_device *device);
 static int fcoe_transport_enable(const char *, struct kernel_param *);
 static int fcoe_transport_disable(const char *, struct kernel_param *);
+static int libfcoe_device_notification(struct notifier_block *notifier,
+				    ulong event, void *ptr);
 
 static LIST_HEAD(fcoe_transports);
-static LIST_HEAD(fcoe_netdevs);
 static DEFINE_MUTEX(ft_mutex);
+static LIST_HEAD(fcoe_netdevs);
+static DEFINE_MUTEX(fn_mutex);
 
 unsigned int libfcoe_debug_logging;
 module_param_named(debug_logging, libfcoe_debug_logging, int, S_IRUGO|S_IWUSR);
@@ -75,6 +78,11 @@ module_param_call(disable, fcoe_transport_disable, NULL, NULL, S_IWUSR);
 __MODULE_PARM_TYPE(disable, "string");
 MODULE_PARM_DESC(disable, " Disables fcoe on a ethernet interface.");
 
+/* notification function for packets from net device */
+static struct notifier_block libfcoe_notifier = {
+	.notifier_call = libfcoe_device_notification,
+};
+
 /**
  * fcoe_fc_crc() - Calculates the CRC for a given frame
  * @fp: The frame to be checksumed
@@ -375,6 +383,7 @@ static int fcoe_transport_show(char *buffer, const struct kernel_param *kp)
 
 static int __init fcoe_transport_init(void)
 {
+	register_netdevice_notifier(&libfcoe_notifier);
 	return 0;
 }
 
@@ -382,6 +391,7 @@ static int __exit fcoe_transport_exit(void)
 {
 	struct fcoe_transport *ft;
 
+	unregister_netdevice_notifier(&libfcoe_notifier);
 	mutex_lock(&ft_mutex);
 	list_for_each_entry(ft, &fcoe_transports, list)
 		printk(KERN_ERR "FCoE transport %s is still attached!\n",
@@ -405,7 +415,9 @@ static int fcoe_add_netdev_mapping(struct net_device *netdev,
 	nm->netdev = netdev;
 	nm->ft = ft;
 
+	mutex_lock(&fn_mutex);
 	list_add(&nm->list, &fcoe_netdevs);
+	mutex_unlock(&fn_mutex);
 	return 0;
 }
 
@@ -414,13 +426,16 @@ static void fcoe_del_netdev_mapping(struct net_device *netdev)
 {
 	struct fcoe_netdev_mapping *nm = NULL, *tmp;
 
+	mutex_lock(&fn_mutex);
 	list_for_each_entry_safe(nm, tmp, &fcoe_netdevs, list) {
 		if (nm->netdev == netdev) {
 			list_del(&nm->list);
 			kfree(nm);
+			mutex_unlock(&fn_mutex);
 			return;
 		}
 	}
+	mutex_unlock(&fn_mutex);
 }
 
 
@@ -438,13 +453,16 @@ static struct fcoe_transport *fcoe_netdev_map_lookup(struct net_device *netdev)
 	struct fcoe_transport *ft = NULL;
 	struct fcoe_netdev_mapping *nm;
 
+	mutex_lock(&fn_mutex);
 	list_for_each_entry(nm, &fcoe_netdevs, list) {
 		if (netdev == nm->netdev) {
 			ft = nm->ft;
+			mutex_unlock(&fn_mutex);
 			return ft;
 		}
 	}
 
+	mutex_unlock(&fn_mutex);
 	return NULL;
 }
 
@@ -470,6 +488,32 @@ static struct net_device *fcoe_if_to_netdev(const char *buffer)
 }
 
 /**
+ * libfcoe_device_notification() - Handler for net device events
+ * @notifier: The context of the notification
+ * @event:    The type of event
+ * @ptr:      The net device that the event was on
+ *
+ * This function is called by the Ethernet driver in case of link change event.
+ *
+ * Returns: 0 for success
+ */
+static int libfcoe_device_notification(struct notifier_block *notifier,
+				    ulong event, void *ptr)
+{
+	struct net_device *netdev = ptr;
+
+	switch (event) {
+	case NETDEV_UNREGISTER:
+		printk(KERN_ERR "libfcoe_device_notification: NETDEV_UNREGISTER %s\n",
+				netdev->name);
+		fcoe_del_netdev_mapping(netdev);
+		break;
+	}
+	return NOTIFY_OK;
+}
+
+
+/**
  * fcoe_transport_create() - Create a fcoe interface
  * @buffer: The name of the Ethernet interface to create on
  * @kp:	    The associated kernel param
#7 lore raw

PATCH 7/8 fcoe: precedence bug in fcoe_filter_frames()

In reply to Robert Love

From: Dan Carpenter <[email protected]>

Negate has higher precedence than bitwise AND. FCPHF_CRC_UNCHECKED is 0x1 so the original code is equivalent to: if (!fr_flags(fp)) { ...

---
 drivers/scsi/fcoe/fcoe.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/scsi/fcoe/fcoe.c +1 -1
index 0b5fbb8..0b44d05 100644
@@ -1548,7 +1548,7 @@ static inline int fcoe_filter_frames(struct fc_lport *lport,
 		return -EINVAL;
 	}
 
-	if (!fr_flags(fp) & FCPHF_CRC_UNCHECKED ||
+	if (!(fr_flags(fp) & FCPHF_CRC_UNCHECKED) ||
 	    le32_to_cpu(fr_crc(fp)) == ~crc32(~0, skb->data, skb->len)) {
 		fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
 		return 0;
#8 lore raw

PATCH 8/8 fcoe: fix broken fcoe interface reset

In reply to Robert Love

From: Vasu Dev <[email protected]>

Reset using "fcoeadm -r" also needs to restart FIP before doing libfc lport reset, this is needed for new switch firmware requiring FIP solicitation before doing FLOGI again during reset. So this patch does this by doing fcoe_ctlr_link_down and then fcoe_ctlr_link_up to reset the interface.

The fcoe_ctlr_link_down call path also does lport reset and then fcoe_ctlr_link_up re-starts the fabric login after doing FIP solicitation first to get reset feature working again.

---
 drivers/scsi/fcoe/fcoe.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/scsi/fcoe/fcoe.c +7 -1
index 0b44d05..94fb480 100644
@@ -2130,7 +2130,13 @@ void fcoe_percpu_clean(struct fc_lport *lport)
 int fcoe_reset(struct Scsi_Host *shost)
 {
 	struct fc_lport *lport = shost_priv(shost);
-	fc_lport_reset(lport);
+	struct fcoe_port *port = lport_priv(lport);
+	struct fcoe_interface *fcoe = port->priv;
+
+	fcoe_ctlr_link_down(&fcoe->ctlr);
+	fcoe_clean_pending_queue(fcoe->ctlr.lp);
+	if (!fcoe_link_ok(fcoe->ctlr.lp))
+		fcoe_ctlr_link_up(&fcoe->ctlr);
 	return 0;
 }